From edebc51d18868d075a77e399f54e1b550c5705b3 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 9 Aug 2017 15:25:01 -0700 Subject: [PATCH] primitives: use `equals` instead of `equal` for consistency. --- lib/hd/private.js | 5 ++--- lib/hd/public.js | 5 ++--- lib/primitives/address.js | 15 +++++++++++++++ lib/script/sigcache.js | 4 ++-- lib/wallet/account.js | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/hd/private.js b/lib/hd/private.js index 56a3cee2..12bb4d99 100644 --- a/lib/hd/private.js +++ b/lib/hd/private.js @@ -393,9 +393,8 @@ HDPrivateKey.prototype.derivePath = function derivePath(path) { * @returns {Boolean} */ -HDPrivateKey.prototype.equal = function equal(obj) { - if (!HDPrivateKey.isHDPrivateKey(obj)) - return false; +HDPrivateKey.prototype.equals = function equals(obj) { + assert(HDPrivateKey.isHDPrivateKey(obj)); return this.network === obj.network && this.depth === obj.depth diff --git a/lib/hd/public.js b/lib/hd/public.js index acf262c1..4c5603a1 100644 --- a/lib/hd/public.js +++ b/lib/hd/public.js @@ -315,9 +315,8 @@ HDPublicKey.prototype.derivePath = function derivePath(path) { * @returns {Boolean} */ -HDPublicKey.prototype.equal = function equal(obj) { - if (!HDPublicKey.isHDPublicKey(obj)) - return false; +HDPublicKey.prototype.equals = function equals(obj) { + assert(HDPublicKey.isHDPublicKey(obj)); return this.network === obj.network && this.depth === obj.depth diff --git a/lib/primitives/address.js b/lib/primitives/address.js index 4a7f2927..8ba984a2 100644 --- a/lib/primitives/address.js +++ b/lib/primitives/address.js @@ -119,6 +119,21 @@ Address.prototype.isNull = function isNull() { return true; }; +/** + * Test equality against another address. + * @param {Address} addr + * @returns {Boolean} + */ + +Address.prototype.equals = function equals(addr) { + assert(addr instanceof Address); + + return this.network === addr.network + && this.type === addr.type + && this.version === addr.version + && this.hash.equals(addr.hash); +}; + /** * Get the address type as a string. * @returns {String} diff --git a/lib/script/sigcache.js b/lib/script/sigcache.js index 4e44c855..378613bd 100644 --- a/lib/script/sigcache.js +++ b/lib/script/sigcache.js @@ -85,7 +85,7 @@ SigCache.prototype.has = function has(hash, sig, key) { if (!entry) return false; - return entry.equal(sig, key); + return entry.equals(sig, key); }; /** @@ -138,7 +138,7 @@ function SigCacheEntry(sig, key) { * @returns {Boolean} */ -SigCacheEntry.prototype.equal = function equal(sig, key) { +SigCacheEntry.prototype.equals = function equals(sig, key) { return this.sig.equals(sig) && this.key.equals(key); }; diff --git a/lib/wallet/account.js b/lib/wallet/account.js index 38dbda7f..5670b2e0 100644 --- a/lib/wallet/account.js +++ b/lib/wallet/account.js @@ -289,7 +289,7 @@ Account.prototype.pushKey = function pushKey(key) { if (this.type !== Account.types.MULTISIG) throw new Error('Cannot add keys to non-multisig wallet.'); - if (key.equal(this.accountKey)) + if (key.equals(this.accountKey)) throw new Error('Cannot add own key.'); const index = util.binaryInsert(this.keys, key, cmp, true);