wallet/http: fixes for deserialization.

This commit is contained in:
Christopher Jeffrey 2017-07-31 18:54:46 -07:00
parent c7ce985648
commit f58feb0035
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -20,6 +20,8 @@ const random = require('../crypto/random');
const ccmp = require('../crypto/ccmp');
const Network = require('../protocol/network');
const Validator = require('../utils/validator');
const Address = require('../primitives/address');
const KeyRing = require('../primitives/keyring');
const common = require('./common');
/**
@ -275,11 +277,6 @@ HTTPServer.prototype.initRouter = function initRouter() {
const account = await req.wallet.createAccount(options, passphrase);
if (!account) {
res.send(404);
return;
}
res.send(200, account.toJSON());
});
@ -301,11 +298,6 @@ HTTPServer.prototype.initRouter = function initRouter() {
const account = await req.wallet.createAccount(options, passphrase);
if (!account) {
res.send(404);
return;
}
res.send(200, account.toJSON());
});
@ -345,24 +337,27 @@ HTTPServer.prototype.initRouter = function initRouter() {
this.post('/:id/import', async (req, res) => {
const valid = req.valid();
const acct = valid.str('account');
const pub = valid.str('publicKey');
const pub = valid.buf('publicKey');
const priv = valid.str('privateKey');
const address = valid.str('address');
const b58 = valid.str('address');
if (pub) {
await req.wallet.importKey(acct, pub);
const key = KeyRing.fromPublic(pub, this.network);
await req.wallet.importKey(acct, key);
res.send(200, { success: true });
return;
}
if (priv) {
await req.wallet.importKey(acct, priv);
const key = KeyRing.fromSecret(priv, this.network);
await req.wallet.importKey(acct, key);
res.send(200, { success: true });
return;
}
if (address) {
await req.wallet.importAddress(acct, address);
if (b58) {
const addr = Address.fromString(b58, this.network);
await req.wallet.importAddress(acct, addr);
res.send(200, { success: true });
return;
}
@ -375,7 +370,10 @@ HTTPServer.prototype.initRouter = function initRouter() {
const valid = req.valid();
const passphrase = valid.str('passphrase');
const token = await req.wallet.retoken(passphrase);
res.send(200, { token: token.toString('hex') });
res.send(200, {
token: token.toString('hex')
});
});
// Send TX