add bip32: to error messages
...to be consistent with the rest of the library
This commit is contained in:
parent
efbebb3528
commit
cc310fbc23
17
lib/bip32.js
17
lib/bip32.js
|
@ -35,14 +35,14 @@ BIP32.prototype.fromRandom = function(network) {
|
||||||
BIP32.prototype.fromString = function(str) {
|
BIP32.prototype.fromString = function(str) {
|
||||||
var decoded = base58.decode(str);
|
var decoded = base58.decode(str);
|
||||||
if (decoded.length != 82)
|
if (decoded.length != 82)
|
||||||
throw new Error('Not enough data, expected 82 and received ' + decoded.length);
|
throw new Error('bip32: Not enough data, expected 82 and received ' + decoded.length);
|
||||||
var checksum = decoded.slice(78, 82);
|
var checksum = decoded.slice(78, 82);
|
||||||
var bytes = decoded.slice(0, 78);
|
var bytes = decoded.slice(0, 78);
|
||||||
|
|
||||||
var hash = Hash.sha256sha256(bytes);
|
var hash = Hash.sha256sha256(bytes);
|
||||||
|
|
||||||
if (hash[0] != checksum[0] || hash[1] != checksum[1] || hash[2] != checksum[2] || hash[3] != checksum[3])
|
if (hash[0] != checksum[0] || hash[1] != checksum[1] || hash[2] != checksum[2] || hash[3] != checksum[3])
|
||||||
throw new Error('Invalid checksum');
|
throw new Error('bip32: Invalid checksum');
|
||||||
|
|
||||||
if (bytes !== undefined && bytes !== null)
|
if (bytes !== undefined && bytes !== null)
|
||||||
this.initFromBytes(bytes);
|
this.initFromBytes(bytes);
|
||||||
|
@ -110,7 +110,7 @@ BIP32.prototype.initFromBytes = function(bytes) {
|
||||||
this.pubKeyHash = Hash.sha256ripemd160(this.key.pubkey.toBuffer());
|
this.pubKeyHash = Hash.sha256ripemd160(this.key.pubkey.toBuffer());
|
||||||
this.hasPrivateKey = false;
|
this.hasPrivateKey = false;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid key');
|
throw new Error('bip32: Invalid key');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.buildExtendedPublicKey();
|
this.buildExtendedPublicKey();
|
||||||
|
@ -162,7 +162,7 @@ BIP32.prototype.extendedPublicKeyString = function(format) {
|
||||||
} else if (format === 'hex') {
|
} else if (format === 'hex') {
|
||||||
return this.extendedPublicKey.toString('hex');;
|
return this.extendedPublicKey.toString('hex');;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('bad format');
|
throw new Error('bip32: bad format');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ BIP32.prototype.extendedPrivateKeyString = function(format) {
|
||||||
} else if (format === 'hex') {
|
} else if (format === 'hex') {
|
||||||
return this.extendedPrivateKey.toString('hex');
|
return this.extendedPrivateKey.toString('hex');
|
||||||
} else {
|
} else {
|
||||||
throw new Error('bad format');
|
throw new Error('bip32: bad format');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +235,9 @@ BIP32.prototype.derive = function(path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BIP32.prototype.deriveChild = function(i) {
|
BIP32.prototype.deriveChild = function(i) {
|
||||||
|
if (typeof i !== 'number')
|
||||||
|
throw new Error('bip32: i must be a number');
|
||||||
|
|
||||||
var ib = [];
|
var ib = [];
|
||||||
ib.push((i >> 24) & 0xff);
|
ib.push((i >> 24) & 0xff);
|
||||||
ib.push((i >> 16) & 0xff);
|
ib.push((i >> 16) & 0xff);
|
||||||
|
@ -249,7 +252,7 @@ BIP32.prototype.deriveChild = function(i) {
|
||||||
this.version == constants.testnet.bip32privkey);
|
this.version == constants.testnet.bip32privkey);
|
||||||
|
|
||||||
if (usePrivate && (!this.hasPrivateKey || !isPrivate))
|
if (usePrivate && (!this.hasPrivateKey || !isPrivate))
|
||||||
throw new Error('Cannot do private key derivation without private key');
|
throw new Error('bip32: Cannot do private key derivation without private key');
|
||||||
|
|
||||||
var ret = null;
|
var ret = null;
|
||||||
if (this.hasPrivateKey) {
|
if (this.hasPrivateKey) {
|
||||||
|
@ -324,7 +327,7 @@ BIP32.prototype.toString = function() {
|
||||||
|
|
||||||
function uint(f, size) {
|
function uint(f, size) {
|
||||||
if (f.length < size)
|
if (f.length < size)
|
||||||
throw new Error('not enough data');
|
throw new Error('bip32: not enough data');
|
||||||
var n = 0;
|
var n = 0;
|
||||||
for (var i = 0; i < size; i++) {
|
for (var i = 0; i < size; i++) {
|
||||||
n *= 256;
|
n *= 256;
|
||||||
|
|
Loading…
Reference in New Issue