wallet: more specific hd key functions.

This commit is contained in:
Christopher Jeffrey 2017-05-13 20:04:23 -07:00
parent 7496cf8d47
commit 5ff46dd36d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 17 additions and 17 deletions

View File

@ -279,10 +279,10 @@ Account.prototype.open = function open() {
Account.prototype.pushKey = function pushKey(key) { Account.prototype.pushKey = function pushKey(key) {
var index; var index;
if (HD.isBase58(key)) if (typeof key === 'string')
key = HD.fromBase58(key, this.network); key = HD.PublicKey.fromBase58(key, this.network);
assert(key.verifyNetwork(this.network), assert(key.network === this.network,
'Network mismatch for account key.'); 'Network mismatch for account key.');
if (!HD.isPublic(key)) if (!HD.isPublic(key))
@ -319,13 +319,13 @@ Account.prototype.pushKey = function pushKey(key) {
*/ */
Account.prototype.spliceKey = function spliceKey(key) { Account.prototype.spliceKey = function spliceKey(key) {
if (HD.isBase58(key)) if (typeof key === 'string')
key = HD.fromBase58(key, this.network); key = HD.PublicKey.fromBase58(key, this.network);
assert(key.verifyNetwork(this.network), assert(key.network === this.network,
'Network mismatch for account key.'); 'Network mismatch for account key.');
if (!HD.isHDPublicKey(key)) if (!HD.isPublic(key))
throw new Error('Must add HD keys to wallet.'); throw new Error('Must add HD keys to wallet.');
if (!key.isAccount44()) if (!key.isAccount44())
@ -973,14 +973,14 @@ Account.prototype.fromRaw = function fromRaw(data) {
this.changeDepth = br.readU32(); this.changeDepth = br.readU32();
this.nestedDepth = br.readU32(); this.nestedDepth = br.readU32();
this.lookahead = br.readU8(); this.lookahead = br.readU8();
this.accountKey = HD.fromRaw(br.readBytes(82)); this.accountKey = HD.PublicKey.fromRaw(br.readBytes(82));
assert(Account.typesByVal[this.type]); assert(Account.typesByVal[this.type]);
count = br.readU8(); count = br.readU8();
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
key = HD.fromRaw(br.readBytes(82)); key = HD.PublicKey.fromRaw(br.readBytes(82));
this.pushKey(key); this.pushKey(key);
} }

View File

@ -600,7 +600,7 @@ MasterKey.prototype.fromRaw = function fromRaw(raw) {
// NOTE: useless varint // NOTE: useless varint
br.skipVarint(); br.skipVarint();
this.key = HD.fromRaw(br.readBytes(82)); this.key = HD.PrivateKey.fromRaw(br.readBytes(82));
if (br.readU8() === 1) if (br.readU8() === 1)
this.mnemonic = Mnemonic.fromReader(br); this.mnemonic = Mnemonic.fromReader(br);

View File

@ -107,7 +107,7 @@ Wallet.prototype.fromOptions = function fromOptions(options) {
if (key) { if (key) {
if (typeof key === 'string') if (typeof key === 'string')
key = HD.fromBase58(key, this.network); key = HD.PrivateKey.fromBase58(key, this.network);
assert(HD.isPrivate(key), assert(HD.isPrivate(key),
'Must create wallet with hd private key.'); 'Must create wallet with hd private key.');
@ -116,7 +116,7 @@ Wallet.prototype.fromOptions = function fromOptions(options) {
key = HD.fromMnemonic(mnemonic, this.network); key = HD.fromMnemonic(mnemonic, this.network);
} }
assert(key.verifyNetwork(this.network), assert(key.network === this.network,
'Network mismatch for master key.'); 'Network mismatch for master key.');
this.master.fromKey(key, mnemonic); this.master.fromKey(key, mnemonic);
@ -695,13 +695,13 @@ Wallet.prototype._createAccount = co(function* createAccount(options, passphrase
if (this.watchOnly && options.accountKey) { if (this.watchOnly && options.accountKey) {
key = options.accountKey; key = options.accountKey;
if (HD.isBase58(key)) if (typeof key === 'string')
key = HD.fromBase58(key, this.network); key = HD.PublicKey.fromBase58(key, this.network);
if (!HD.isPublic(key)) if (!HD.isPublic(key))
throw new Error('Must add HD public keys to watch only wallet.'); throw new Error('Must add HD public keys to watch only wallet.');
assert(key.verifyNetwork(this.network), assert(key.network === this.network,
'Network mismatch for watch only key.'); 'Network mismatch for watch only key.');
} else { } else {
assert(this.master.key); assert(this.master.key);
@ -1239,7 +1239,7 @@ Wallet.prototype._importKey = co(function* importKey(acct, ring, passphrase) {
if (acct == null) if (acct == null)
acct = 0; acct = 0;
assert(ring.verifyNetwork(this.network), assert(ring.network === this.network,
'Network mismatch for key.'); 'Network mismatch for key.');
if (!this.watchOnly) { if (!this.watchOnly) {
@ -1324,7 +1324,7 @@ Wallet.prototype._importAddress = co(function* importAddress(acct, address) {
if (acct == null) if (acct == null)
acct = 0; acct = 0;
assert(address.verifyNetwork(this.network), assert(address.network === this.network,
'Network mismatch for address.'); 'Network mismatch for address.');
if (!this.watchOnly) if (!this.watchOnly)