hd: rename testing methods.

This commit is contained in:
Christopher Jeffrey 2016-10-10 01:00:24 -07:00
parent 6761122580
commit 25ac6b70de
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
5 changed files with 22 additions and 19 deletions

View File

@ -26,7 +26,7 @@ var HD = exports;
*/
HD.fromBase58 = function fromBase58(xkey) {
if (HDPrivateKey.isExtended(xkey))
if (HDPrivateKey.isBase58(xkey))
return HDPrivateKey.fromBase58(xkey);
return HDPublicKey.fromBase58(xkey);
};
@ -86,7 +86,7 @@ HD.fromJSON = function fromJSON(json) {
*/
HD.fromRaw = function fromRaw(data) {
if (HDPrivateKey.hasPrefix(data))
if (HDPrivateKey.isRaw(data))
return HDPrivateKey.fromRaw(data);
return HDPublicKey.fromRaw(data);
};
@ -98,7 +98,7 @@ HD.fromRaw = function fromRaw(data) {
*/
HD.fromExtended = function fromExtended(data) {
if (HDPrivateKey.hasPrefix(data))
if (HDPrivateKey.isRaw(data))
return HDPrivateKey.fromExtended(data);
return HDPublicKey.fromRaw(data);
};
@ -117,10 +117,10 @@ HD.from = function from(options, network) {
if (HD.isHD(options))
return options;
if (HD.isExtended(options))
if (HD.isBase58(options))
return HD.fromBase58(options);
if (HD.hasPrefix(options))
if (HD.isRaw(options))
return HD.fromRaw(options);
if (options && typeof options === 'object')
@ -135,9 +135,9 @@ HD.from = function from(options, network) {
* @returns {Boolean}
*/
HD.isExtended = function isExtended(data) {
return HDPrivateKey.isExtended(data)
|| HDPublicKey.isExtended(data);
HD.isBase58 = function isBase58(data) {
return HDPrivateKey.isBase58(data)
|| HDPublicKey.isBase58(data);
};
/**
@ -146,9 +146,9 @@ HD.isExtended = function isExtended(data) {
* @returns {NetworkType}
*/
HD.hasPrefix = function hasPrefix(data) {
return HDPrivateKey.hasPrefix(data)
|| HDPublicKey.hasPrefix(data);
HD.isRaw = function isRaw(data) {
return HDPrivateKey.isRaw(data)
|| HDPublicKey.isRaw(data);
};
/**

View File

@ -339,7 +339,7 @@ HDPrivateKey.prototype.isPurpose45 = function isPurpose45() {
* @returns {Boolean}
*/
HDPrivateKey.isExtended = function isExtended(data) {
HDPrivateKey.isBase58 = function isBase58(data) {
var i, type, prefix;
if (typeof data !== 'string')
@ -361,12 +361,15 @@ HDPrivateKey.isExtended = function isExtended(data) {
* @returns {NetworkType}
*/
HDPrivateKey.hasPrefix = function hasPrefix(data) {
HDPrivateKey.isRaw = function isRaw(data) {
var i, version, prefix, type;
if (!Buffer.isBuffer(data))
return false;
if (data.length < 4)
return false;
version = data.readUInt32BE(0, true);
for (i = 0; i < networks.types.length; i++) {

View File

@ -406,7 +406,7 @@ HDPublicKey.fromJSON = function fromJSON(json) {
* @returns {Boolean}
*/
HDPublicKey.isExtended = function isExtended(data) {
HDPublicKey.isBase58 = function isBase58(data) {
var i, type, prefix;
if (typeof data !== 'string')
@ -428,7 +428,7 @@ HDPublicKey.isExtended = function isExtended(data) {
* @returns {NetworkType}
*/
HDPublicKey.hasPrefix = function hasPrefix(data) {
HDPublicKey.isRaw = function isRaw(data) {
var i, version, prefix, type;
if (!Buffer.isBuffer(data))

View File

@ -269,7 +269,7 @@ Account.prototype.open = function open() {
Account.prototype.pushKey = function pushKey(key) {
var index;
if (HD.isExtended(key))
if (HD.isBase58(key))
key = HD.fromBase58(key);
assert(key.network === this.network,
@ -306,7 +306,7 @@ Account.prototype.pushKey = function pushKey(key) {
*/
Account.prototype.spliceKey = function spliceKey(key) {
if (HD.isExtended(key))
if (HD.isBase58(key))
key = HD.fromBase58(key);
assert(key.network === this.network,

View File

@ -108,7 +108,7 @@ Wallet.prototype.fromOptions = function fromOptions(options) {
if (!key)
key = HD.fromMnemonic(null, this.network);
if (HD.isExtended(key))
if (HD.isBase58(key))
key = HD.fromBase58(key);
assert(HD.isPrivate(key),
@ -701,7 +701,7 @@ Wallet.prototype._createAccount = co(function* createAccount(options) {
if (this.watchOnly && options.accountKey) {
key = options.accountKey;
if (HD.isExtended(key))
if (HD.isBase58(key))
key = HD.fromBase58(key);
if (!HD.isPublic(key))