From 33ed40952966419bb2e93ae017ec9184bc425d84 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 2 Jul 2016 05:02:32 -0700 Subject: [PATCH] network references. --- lib/bcoin/address.js | 8 ++++---- lib/bcoin/hd.js | 24 ++++++++++++------------ lib/bcoin/keypair.js | 8 ++++++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/bcoin/address.js b/lib/bcoin/address.js index 801c820b..ddf51cd7 100644 --- a/lib/bcoin/address.js +++ b/lib/bcoin/address.js @@ -30,7 +30,7 @@ var scriptTypes = constants.scriptTypes; * @property {Buffer} hash * @property {AddressType} type * @property {Number} version - * @property {NetworkType} network + * @property {Network} network */ function Address(options) { @@ -40,7 +40,7 @@ function Address(options) { this.hash = constants.ZERO_HASH160; this.type = scriptTypes.PUBKEYHASH; this.version = -1; - this.network = bcoin.network.get().type; + this.network = bcoin.network.get(); if (options) this.fromOptions(options); @@ -205,7 +205,7 @@ Address.prototype.fromRaw = function fromRaw(data) { p.verifyChecksum(); - return this.fromHash(hash, type, version, network.type); + return this.fromHash(hash, type, version, network); }; /** @@ -430,7 +430,7 @@ Address.prototype.fromHash = function fromHash(hash, type, version, network) { this.hash = hash; this.type = type; this.version = version; - this.network = network.type; + this.network = network; return this; }; diff --git a/lib/bcoin/hd.js b/lib/bcoin/hd.js index b08298bf..263aca86 100644 --- a/lib/bcoin/hd.js +++ b/lib/bcoin/hd.js @@ -822,7 +822,7 @@ HD.isHD = function isHD(obj) { * @param {Number?} options.childIndex * @param {Buffer?} options.chainCode * @param {Buffer?} options.privateKey - * @property {String} network + * @property {Network} network * @property {Base58String} xprivkey * @property {Base58String} xpubkey * @property {Mnemonic?} mnemonic @@ -838,7 +838,7 @@ function HDPrivateKey(options) { if (!(this instanceof HDPrivateKey)) return new HDPrivateKey(options); - this.network = bcoin.network.get().type; + this.network = bcoin.network.get(); this.depth = 0; this.parentFingerPrint = FINGER_PRINT; this.childIndex = 0; @@ -877,7 +877,7 @@ HDPrivateKey.prototype.fromOptions = function fromOptions(options) { assert(options.depth <= 0xff, 'Depth is too high.'); if (options.network) - this.network = bcoin.network.get(options.network).type; + this.network = bcoin.network.get(options.network); this.depth = options.depth; this.parentFingerPrint = options.parentFingerPrint; @@ -1021,7 +1021,7 @@ HDPrivateKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex) assert(this.isMaster(), 'Cannot derive account index.'); return this .derive(44, true) - .derive(this.network === 'main' ? 0 : 1, true) + .derive(this.network.type === 'main' ? 0 : 1, true) .derive(accountIndex, true); }; @@ -1196,7 +1196,7 @@ HDPrivateKey.prototype.fromSeed = function fromSeed(seed, network) { if (!ec.privateKeyVerify(privateKey)) throw new Error('Master private key is invalid.'); - this.network = bcoin.network.get(network).type; + this.network = bcoin.network.get(network); this.depth = 0; this.parentFingerPrint = new Buffer([0, 0, 0, 0]); this.childIndex = 0; @@ -1269,7 +1269,7 @@ HDPrivateKey.prototype.generate = function _generate(options, network) { if (!entropy) entropy = ec.random(32); - this.network = bcoin.network.get(network).type; + this.network = bcoin.network.get(network); this.depth = 0; this.parentFingerPrint = new Buffer([0, 0, 0, 0]); this.childIndex = 0; @@ -1334,7 +1334,7 @@ HDPrivateKey.prototype.fromRaw = function fromRaw(raw) { assert(i < networks.types.length, 'Network not found.'); this.publicKey = ec.publicKeyCreate(this.privateKey, true); - this.network = type; + this.network = bcoin.network.get(type); return this; }; @@ -1510,7 +1510,7 @@ HDPrivateKey.isHDPrivateKey = function isHDPrivateKey(obj) { * @param {Number?} options.childIndex * @param {Buffer?} options.chainCode * @param {Buffer?} options.publicKey - * @property {String} network + * @property {Network} network * @property {Base58String} xpubkey * @property {Number} depth * @property {Buffer} parentFingerPrint @@ -1523,7 +1523,7 @@ function HDPublicKey(options) { if (!(this instanceof HDPublicKey)) return new HDPublicKey(options); - this.network = bcoin.network.get().type; + this.network = bcoin.network.get(); this.depth = 0; this.parentFingerPrint = FINGER_PRINT; this.childIndex = 0; @@ -1558,7 +1558,7 @@ HDPublicKey.prototype.fromOptions = function fromOptions(options) { assert(Buffer.isBuffer(options.publicKey)); if (options.network) - this.network = bcoin.network.get(options.network).type; + this.network = bcoin.network.get(options.network); this.depth = options.depth; this.parentFingerPrint = options.parentFingerPrint; @@ -1877,7 +1877,7 @@ HDPublicKey.prototype.fromRaw = function fromRaw(raw) { assert(i < networks.types.length, 'Network not found.'); - this.network = type; + this.network = bcoin.network.get(type); return this; }; @@ -2019,7 +2019,7 @@ HDPrivateKey.prototype.toKeyPair = function toKeyPair() { * @returns {Base58String} */ -HDPrivateKey.prototype.toSecret = function toSecret(network) { +HDPrivateKey.prototype.toSecret = function toSecret() { return this.toKeyPair().toSecret(); }; diff --git a/lib/bcoin/keypair.js b/lib/bcoin/keypair.js index b59b159c..25f4571a 100644 --- a/lib/bcoin/keypair.js +++ b/lib/bcoin/keypair.js @@ -21,15 +21,19 @@ var BufferReader = require('./reader'); * @param {Object} options * @param {Buffer?} options.privateKey * @param {Buffer?} options.publicKey - * @property {Buffer?} privateKey + * @param {Boolean?} options.compressed + * @param {(Network|NetworkType)?} options.network + * @property {Buffer} privateKey * @property {Buffer} publicKey + * @property {Boolean} compressed + * @property {Network} network */ function KeyPair(options) { if (!(this instanceof KeyPair)) return new KeyPair(options); - this.network = bcoin.network.get().type; + this.network = bcoin.network.get(); this.compressed = true; this.privateKey = null; this.publicKey = null;