network references.

This commit is contained in:
Christopher Jeffrey 2016-07-02 05:02:32 -07:00
parent 503cbfc886
commit 33ed409529
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 22 additions and 18 deletions

View File

@ -30,7 +30,7 @@ var scriptTypes = constants.scriptTypes;
* @property {Buffer} hash * @property {Buffer} hash
* @property {AddressType} type * @property {AddressType} type
* @property {Number} version * @property {Number} version
* @property {NetworkType} network * @property {Network} network
*/ */
function Address(options) { function Address(options) {
@ -40,7 +40,7 @@ function Address(options) {
this.hash = constants.ZERO_HASH160; this.hash = constants.ZERO_HASH160;
this.type = scriptTypes.PUBKEYHASH; this.type = scriptTypes.PUBKEYHASH;
this.version = -1; this.version = -1;
this.network = bcoin.network.get().type; this.network = bcoin.network.get();
if (options) if (options)
this.fromOptions(options); this.fromOptions(options);
@ -205,7 +205,7 @@ Address.prototype.fromRaw = function fromRaw(data) {
p.verifyChecksum(); 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.hash = hash;
this.type = type; this.type = type;
this.version = version; this.version = version;
this.network = network.type; this.network = network;
return this; return this;
}; };

View File

@ -822,7 +822,7 @@ HD.isHD = function isHD(obj) {
* @param {Number?} options.childIndex * @param {Number?} options.childIndex
* @param {Buffer?} options.chainCode * @param {Buffer?} options.chainCode
* @param {Buffer?} options.privateKey * @param {Buffer?} options.privateKey
* @property {String} network * @property {Network} network
* @property {Base58String} xprivkey * @property {Base58String} xprivkey
* @property {Base58String} xpubkey * @property {Base58String} xpubkey
* @property {Mnemonic?} mnemonic * @property {Mnemonic?} mnemonic
@ -838,7 +838,7 @@ function HDPrivateKey(options) {
if (!(this instanceof HDPrivateKey)) if (!(this instanceof HDPrivateKey))
return new HDPrivateKey(options); return new HDPrivateKey(options);
this.network = bcoin.network.get().type; this.network = bcoin.network.get();
this.depth = 0; this.depth = 0;
this.parentFingerPrint = FINGER_PRINT; this.parentFingerPrint = FINGER_PRINT;
this.childIndex = 0; this.childIndex = 0;
@ -877,7 +877,7 @@ HDPrivateKey.prototype.fromOptions = function fromOptions(options) {
assert(options.depth <= 0xff, 'Depth is too high.'); assert(options.depth <= 0xff, 'Depth is too high.');
if (options.network) if (options.network)
this.network = bcoin.network.get(options.network).type; this.network = bcoin.network.get(options.network);
this.depth = options.depth; this.depth = options.depth;
this.parentFingerPrint = options.parentFingerPrint; this.parentFingerPrint = options.parentFingerPrint;
@ -1021,7 +1021,7 @@ HDPrivateKey.prototype.deriveAccount44 = function deriveAccount44(accountIndex)
assert(this.isMaster(), 'Cannot derive account index.'); assert(this.isMaster(), 'Cannot derive account index.');
return this return this
.derive(44, true) .derive(44, true)
.derive(this.network === 'main' ? 0 : 1, true) .derive(this.network.type === 'main' ? 0 : 1, true)
.derive(accountIndex, true); .derive(accountIndex, true);
}; };
@ -1196,7 +1196,7 @@ HDPrivateKey.prototype.fromSeed = function fromSeed(seed, network) {
if (!ec.privateKeyVerify(privateKey)) if (!ec.privateKeyVerify(privateKey))
throw new Error('Master private key is invalid.'); 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.depth = 0;
this.parentFingerPrint = new Buffer([0, 0, 0, 0]); this.parentFingerPrint = new Buffer([0, 0, 0, 0]);
this.childIndex = 0; this.childIndex = 0;
@ -1269,7 +1269,7 @@ HDPrivateKey.prototype.generate = function _generate(options, network) {
if (!entropy) if (!entropy)
entropy = ec.random(32); entropy = ec.random(32);
this.network = bcoin.network.get(network).type; this.network = bcoin.network.get(network);
this.depth = 0; this.depth = 0;
this.parentFingerPrint = new Buffer([0, 0, 0, 0]); this.parentFingerPrint = new Buffer([0, 0, 0, 0]);
this.childIndex = 0; this.childIndex = 0;
@ -1334,7 +1334,7 @@ HDPrivateKey.prototype.fromRaw = function fromRaw(raw) {
assert(i < networks.types.length, 'Network not found.'); assert(i < networks.types.length, 'Network not found.');
this.publicKey = ec.publicKeyCreate(this.privateKey, true); this.publicKey = ec.publicKeyCreate(this.privateKey, true);
this.network = type; this.network = bcoin.network.get(type);
return this; return this;
}; };
@ -1510,7 +1510,7 @@ HDPrivateKey.isHDPrivateKey = function isHDPrivateKey(obj) {
* @param {Number?} options.childIndex * @param {Number?} options.childIndex
* @param {Buffer?} options.chainCode * @param {Buffer?} options.chainCode
* @param {Buffer?} options.publicKey * @param {Buffer?} options.publicKey
* @property {String} network * @property {Network} network
* @property {Base58String} xpubkey * @property {Base58String} xpubkey
* @property {Number} depth * @property {Number} depth
* @property {Buffer} parentFingerPrint * @property {Buffer} parentFingerPrint
@ -1523,7 +1523,7 @@ function HDPublicKey(options) {
if (!(this instanceof HDPublicKey)) if (!(this instanceof HDPublicKey))
return new HDPublicKey(options); return new HDPublicKey(options);
this.network = bcoin.network.get().type; this.network = bcoin.network.get();
this.depth = 0; this.depth = 0;
this.parentFingerPrint = FINGER_PRINT; this.parentFingerPrint = FINGER_PRINT;
this.childIndex = 0; this.childIndex = 0;
@ -1558,7 +1558,7 @@ HDPublicKey.prototype.fromOptions = function fromOptions(options) {
assert(Buffer.isBuffer(options.publicKey)); assert(Buffer.isBuffer(options.publicKey));
if (options.network) if (options.network)
this.network = bcoin.network.get(options.network).type; this.network = bcoin.network.get(options.network);
this.depth = options.depth; this.depth = options.depth;
this.parentFingerPrint = options.parentFingerPrint; this.parentFingerPrint = options.parentFingerPrint;
@ -1877,7 +1877,7 @@ HDPublicKey.prototype.fromRaw = function fromRaw(raw) {
assert(i < networks.types.length, 'Network not found.'); assert(i < networks.types.length, 'Network not found.');
this.network = type; this.network = bcoin.network.get(type);
return this; return this;
}; };
@ -2019,7 +2019,7 @@ HDPrivateKey.prototype.toKeyPair = function toKeyPair() {
* @returns {Base58String} * @returns {Base58String}
*/ */
HDPrivateKey.prototype.toSecret = function toSecret(network) { HDPrivateKey.prototype.toSecret = function toSecret() {
return this.toKeyPair().toSecret(); return this.toKeyPair().toSecret();
}; };

View File

@ -21,15 +21,19 @@ var BufferReader = require('./reader');
* @param {Object} options * @param {Object} options
* @param {Buffer?} options.privateKey * @param {Buffer?} options.privateKey
* @param {Buffer?} options.publicKey * @param {Buffer?} options.publicKey
* @property {Buffer?} privateKey * @param {Boolean?} options.compressed
* @param {(Network|NetworkType)?} options.network
* @property {Buffer} privateKey
* @property {Buffer} publicKey * @property {Buffer} publicKey
* @property {Boolean} compressed
* @property {Network} network
*/ */
function KeyPair(options) { function KeyPair(options) {
if (!(this instanceof KeyPair)) if (!(this instanceof KeyPair))
return new KeyPair(options); return new KeyPair(options);
this.network = bcoin.network.get().type; this.network = bcoin.network.get();
this.compressed = true; this.compressed = true;
this.privateKey = null; this.privateKey = null;
this.publicKey = null; this.publicKey = null;