keyring: add derive method.
This commit is contained in:
parent
1e98ce25d9
commit
0a5fcad5e8
@ -2577,8 +2577,7 @@ RPC.prototype.dumpprivkey = function dumpprivkey(args, callback) {
|
||||
if (!key)
|
||||
return callback(new RPCError('Wallet is locked.'));
|
||||
|
||||
key = key.deriveAccount44(ring.account);
|
||||
key = key.derive(ring.change).derive(ring.index);
|
||||
key = ring.derive(key);
|
||||
|
||||
callback(null, key.toSecret());
|
||||
});
|
||||
@ -2620,8 +2619,7 @@ RPC.prototype.dumpwallet = function dumpwallet(args, callback) {
|
||||
if (!key)
|
||||
return callback(new RPCError('Wallet is locked.'));
|
||||
|
||||
key = key.deriveAccount44(ring.account);
|
||||
key = key.derive(ring.change).derive(ring.index);
|
||||
key = ring.derive(key);
|
||||
address = ring.getAddress('base58');
|
||||
fmt = '%s %s label= addr=%s';
|
||||
|
||||
@ -3554,11 +3552,11 @@ RPC.prototype.signmessage = function signmessage(args, callback) {
|
||||
if (!address)
|
||||
return callback(new RPCError('Invalid address.'));
|
||||
|
||||
this.wallet.getKeyring(address, function(err, address) {
|
||||
this.wallet.getKeyring(address, function(err, ring) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!address)
|
||||
if (!ring)
|
||||
return callback(new RPCError('Address not found.'));
|
||||
|
||||
key = self.wallet.master.key;
|
||||
@ -3566,8 +3564,7 @@ RPC.prototype.signmessage = function signmessage(args, callback) {
|
||||
if (!key)
|
||||
return callback(new RPCError('Wallet is locked.'));
|
||||
|
||||
key = key.deriveAccount44(address.account);
|
||||
key = key.derive(address.change).derive(address.index);
|
||||
key = ring.derive(key);
|
||||
|
||||
msg = new Buffer(RPC.magic + msg, 'utf8');
|
||||
msg = utils.hash256(msg);
|
||||
|
||||
@ -579,6 +579,18 @@ KeyRing.prototype.sign = function sign(tx, key, index, type) {
|
||||
return total;
|
||||
};
|
||||
|
||||
/**
|
||||
* Derive to address index.
|
||||
* @param {HDPrivateKey} key
|
||||
* @returns {HDPrivateKey}
|
||||
*/
|
||||
|
||||
KeyRing.prototype.derive = function derive(key) {
|
||||
if (key.isMaster())
|
||||
key = key.deriveAccount44(this.account);
|
||||
return key.derive(this.change).derive(this.index);
|
||||
};
|
||||
|
||||
KeyRing.prototype.__defineGetter__('publicKey', function() {
|
||||
return this.getPublicKey();
|
||||
});
|
||||
|
||||
@ -1350,8 +1350,7 @@ Wallet.sign = function sign(addresses, master, tx, index, type) {
|
||||
|
||||
for (i = 0; i < addresses.length; i++) {
|
||||
address = addresses[i];
|
||||
key = master.deriveAccount44(address.account);
|
||||
key = key.derive(address.change).derive(address.index);
|
||||
key = address.derive(master);
|
||||
assert(utils.equal(key.getPublicKey(), address.key));
|
||||
total += address.sign(tx, key, index, type);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user