diff --git a/lib/address.js b/lib/address.js index e199a295d..a7ccddf04 100644 --- a/lib/address.js +++ b/lib/address.js @@ -25,7 +25,7 @@ var Hash = require('./crypto/hash'); * * * @param {String} data - The encoded data in various formats - * @param {String} [network] - The network: 'mainnet' or 'testnet' + * @param {String} [network] - The network: 'livenet' or 'testnet' * @param {String} [type] - The type of address: 'script' or 'pubkey' * @returns {Address} A new valid and frozen instance of an Address * @constructor @@ -40,8 +40,8 @@ function Address(data, network, type) { throw new TypeError('First argument is required, please include address data.'); } - if (network && (network !== 'mainnet' && network !== 'testnet')) { - throw new TypeError('Second argument must be "mainnet" or "testnet".'); + if (network && (network !== 'livenet' && network !== 'testnet')) { + throw new TypeError('Second argument must be "livenet" or "testnet".'); } if (type && (type !== 'pubkeyhash' && type !== 'scripthash')) { @@ -66,7 +66,7 @@ function Address(data, network, type) { } // set defaults if not set - info.network = info.network || network || 'mainnet'; + info.network = info.network || network || 'livenet'; info.type = info.type || type || 'pubkeyhash'; // set the validated values @@ -103,7 +103,7 @@ Address._transformHash = function(hash){ * Internal function to transform a bitcoin address buffer * * @param {Buffer} buffer - An instance of a hex encoded address Buffer - * @param {String} [network] - The network: 'mainnet' or 'testnet' + * @param {String} [network] - The network: 'livenet' or 'testnet' * @param {String} [type] - The type: 'pubkeyhash' or 'scripthash' * @returns {Object} An object with keys: hashBuffer, network and type * @private @@ -121,13 +121,13 @@ Address._transformBuffer = function(buffer, network, type){ var bufType = false; switch(buffer[0]){ // the version byte - case networks.mainnet.pubkeyhash: - bufNetwork = 'mainnet'; + case networks.livenet.pubkeyhash: + bufNetwork = 'livenet'; bufType = 'pubkeyhash'; break; - case networks.mainnet.scripthash: - bufNetwork = 'mainnet'; + case networks.livenet.scripthash: + bufNetwork = 'livenet'; bufType = 'scripthash'; break; @@ -197,7 +197,7 @@ Address._transformScript = function(script){ * Internal function to transform a bitcoin address string * * @param {String} data - An instance of PublicKey - * @param {String} [network] - The network: 'mainnet' or 'testnet' + * @param {String} [network] - The network: 'livenet' or 'testnet' * @param {String} [type] - The type: 'pubkeyhash' or 'scripthash' * @returns {Object} An object with keys: hashBuffer, network and type * @private @@ -216,7 +216,7 @@ Address._transformString = function(data, network, type){ * Instantiate an address from a PublicKey instance * * @param {String} data - An instance of PublicKey - * @param {String} network - The network: 'mainnet' or 'testnet' + * @param {String} network - The network: 'livenet' or 'testnet' * @returns {Address} A new valid and frozen instance of an Address */ Address.fromPublicKey = function(data, network){ @@ -229,7 +229,7 @@ Address.fromPublicKey = function(data, network){ * Instantiate an address from a ripemd160 public key hash * * @param {Buffer} hash - An instance of buffer of the hash - * @param {String} network - The network: 'mainnet' or 'testnet' + * @param {String} network - The network: 'livenet' or 'testnet' * @returns {Address} A new valid and frozen instance of an Address */ Address.fromPublicKeyHash = function(hash, network) { @@ -242,7 +242,7 @@ Address.fromPublicKeyHash = function(hash, network) { * Instantiate an address from a ripemd160 script hash * * @param {Buffer} hash - An instance of buffer of the hash - * @param {String} network - The network: 'mainnet' or 'testnet' + * @param {String} network - The network: 'livenet' or 'testnet' * @returns {Address} A new valid and frozen instance of an Address */ Address.fromScriptHash = function(hash, network) { @@ -255,7 +255,7 @@ Address.fromScriptHash = function(hash, network) { * Instantiate an address from a Script * * @param {Script} script - An instance of Script - * @param {String} network - The network: 'mainnet' or 'testnet' + * @param {String} network - The network: 'livenet' or 'testnet' * @returns {Address} A new valid and frozen instance of an Address */ Address.fromScript = function(script, network) { @@ -268,7 +268,7 @@ Address.fromScript = function(script, network) { * Instantiate an address from a buffer of the address * * @param {Buffer} buffer - An instance of buffer of the address - * @param {String} [network] - The network: 'mainnet' or 'testnet' + * @param {String} [network] - The network: 'livenet' or 'testnet' * @param {String} [type] - The type of address: 'script' or 'pubkey' * @returns {Address} A new valid and frozen instance of an Address */ @@ -282,7 +282,7 @@ Address.fromBuffer = function(buffer, network, type) { * Instantiate an address from an address string * * @param {String} str - An string of the bitcoin address - * @param {String} [network] - The network: 'mainnet' or 'testnet' + * @param {String} [network] - The network: 'livenet' or 'testnet' * @param {String} [type] - The type of address: 'script' or 'pubkey' * @returns {Address} A new valid and frozen instance of an Address */ @@ -301,7 +301,7 @@ Address.fromString = function(str, network, type) { * // a network mismatch error * * @param {String} data - The encoded data - * @param {String} network - The network: 'mainnet' or 'testnet' + * @param {String} network - The network: 'livenet' or 'testnet' * @param {String} type - The type of address: 'script' or 'pubkey' * @returns {null|Error} The corresponding error message */ @@ -321,11 +321,11 @@ Address.getValidationError = function(data, network, type) { * * @example * - * var valid = Address.isValid('15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2', 'mainnet'); + * var valid = Address.isValid('15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2', 'livenet'); * // true * * @param {String} data - The encoded data - * @param {String} network - The network: 'mainnet' or 'testnet' + * @param {String} network - The network: 'livenet' or 'testnet' * @param {String} type - The type of address: 'script' or 'pubkey' * @returns {null|Error} The corresponding error message */ diff --git a/lib/privatekey.js b/lib/privatekey.js index eb9a4dbd8..6cf53e788 100644 --- a/lib/privatekey.js +++ b/lib/privatekey.js @@ -27,7 +27,7 @@ var PublicKey = require('./publickey'); * var imported = PrivateKey.fromWIF(exported); * * @param {String} data - The encoded data in various formats - * @param {String} [network] - Either "mainnet" or "testnet" + * @param {String} [network] - Either "livenet" or "testnet" * @param {Boolean} [compressed] - If the key is in compressed format * @returns {PrivateKey} A new valid instance of an PrivateKey * @constructor @@ -40,7 +40,7 @@ var PrivateKey = function PrivateKey(data, network, compressed) { var info = { compressed: typeof(compressed) !== 'undefined' ? compressed : true, - network: network || 'mainnet' + network: network || 'livenet' }; // detect type of data @@ -61,7 +61,7 @@ var PrivateKey = function PrivateKey(data, network, compressed) { throw new TypeError('Number must be less than N'); } if (typeof(networks[info.network]) === 'undefined') { - throw new TypeError('Must specify the network ("mainnet" or "testnet")'); + throw new TypeError('Must specify the network ("livenet" or "testnet")'); } if (typeof(info.compressed) !== 'boolean') { throw new TypeError('Must specify whether the corresponding public key is compressed or not (true or false)'); @@ -98,7 +98,7 @@ PrivateKey._getRandomBN = function(){ * Internal function to transform a WIF Buffer into a private key * * @param {Buffer} buf - An WIF string - * @param {String} [network] - Either "mainnet" or "testnet" + * @param {String} [network] - Either "livenet" or "testnet" * @param {String} [compressed] - If the private key is compressed * @returns {Object} An object with keys: bn, network and compressed * @private @@ -115,8 +115,8 @@ PrivateKey._transformBuffer = function(buf, network, compressed) { throw new Error('Length of buffer must be 33 (uncompressed) or 34 (compressed)'); } - if (buf[0] === networks.mainnet.privatekey) { - info.network = 'mainnet'; + if (buf[0] === networks.livenet.privatekey) { + info.network = 'livenet'; } else if (buf[0] === networks.testnet.privatekey) { info.network = 'testnet'; } else { @@ -177,7 +177,7 @@ PrivateKey.fromJSON = function(json) { * * Instantiate a PrivateKey from random bytes * - * @param {String} [network] - Either "mainnet" or "testnet" + * @param {String} [network] - Either "livenet" or "testnet" * @param {String} [compressed] - If the private key is compressed * @returns {PrivateKey} A new valid instance of PrivateKey */ @@ -203,7 +203,7 @@ PrivateKey.fromString = function(str) { * Check if there would be any errors when initializing a PrivateKey * * @param {String} data - The encoded data in various formats - * @param {String} [network] - Either "mainnet" or "testnet" + * @param {String} [network] - Either "livenet" or "testnet" * @param {String} [compressed] - If the private key is compressed * @returns {null|Error} An error if exists */ @@ -223,7 +223,7 @@ PrivateKey.getValidationError = function(data, network, compressed) { * Check if the parameters are valid * * @param {String} data - The encoded data in various formats - * @param {String} [network] - Either "mainnet" or "testnet" + * @param {String} [network] - Either "livenet" or "testnet" * @param {String} [compressed] - If the private key is compressed * @returns {Boolean} If the private key is would be valid */ diff --git a/test/address.js b/test/address.js index 80f363f5c..00ed0b0de 100644 --- a/test/address.js +++ b/test/address.js @@ -23,17 +23,17 @@ describe('Address', function() { it('should throw an error because of bad network param', function() { (function(){ var a = new Address(validAddresses[0], 'main', 'pubkeyhash'); - }).should.throw('Second argument must be "mainnet" or "testnet".'); + }).should.throw('Second argument must be "livenet" or "testnet".'); }); it('should throw an error because of bad type param', function() { (function() { - var a = new Address(validAddresses[0], 'mainnet', 'pubkey'); + var a = new Address(validAddresses[0], 'livenet', 'pubkey'); }).should.throw('Third argument must be "pubkeyhash" or "scripthash"'); }); - // mainnet valid + // livenet valid var validAddresses = [ '15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2', '1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT', @@ -41,7 +41,7 @@ describe('Address', function() { '1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7' ]; - // mainnet p2sh + // livenet p2sh var validp2shAddresses = [ '342ftSRCvFHfCeFFBuz4xwbeqnDw6BGUey', '33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk', @@ -57,7 +57,7 @@ describe('Address', function() { '2NB72XtkjpnATMggui83aEtPawyyKvnbX2o' ]; - //mainnet bad checksums + //livenet bad checksums var badChecksums = [ '15vkcKf7gB23wLAnZLmbVuMiiVDc3nq4a2', '1A6ut1tWnUq1SEQLMr4ttDh24wcbj4w2TT', @@ -65,7 +65,7 @@ describe('Address', function() { '1Jz2yCRd5ST1p2gUqFB5wsSQfdmEJaffg7' ]; - //mainnet non-base58 + //livenet non-base58 var nonBase58 = [ '15vkcKf7g#23wLAnZLmb$uMiiVDc3nq4a2', '1A601ttWnUq1SEQLMr4ttDh24wcbj4w2TT', @@ -83,13 +83,13 @@ describe('Address', function() { describe('validation', function() { - it('should describe this mainnet address as an invalid testnet address', function() { + it('should describe this livenet address as an invalid testnet address', function() { var error = Address.getValidationError('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'testnet'); should.exist(error); }); it('should should return a true boolean', function(){ - var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'mainnet'); + var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'livenet'); valid.should.equal(true); }); @@ -128,14 +128,14 @@ describe('Address', function() { it('should validate addresses with params', function() { for(var i=0;i'); + privkey.inspect().should.equal(''); }); it('should output known testnet address for console', function() { @@ -178,7 +178,7 @@ describe('PrivateKey', function() { describe('#toBuffer', function() { it('should output known buffer', function() { - var privkey = new PrivateKey(BN.fromBuffer(buf), 'mainnet', true); + var privkey = new PrivateKey(BN.fromBuffer(buf), 'livenet', true); var b = privkey.toBuffer().toString('hex').should.equal(buf.toString('hex')); }); }); @@ -186,7 +186,7 @@ describe('PrivateKey', function() { describe('#toBigNumber', function() { it('should output known BN', function() { var a = BN.fromBuffer(buf); - var privkey = new PrivateKey(a, 'mainnet', true); + var privkey = new PrivateKey(a, 'livenet', true); var b = privkey.toBigNumber(); b.toString('hex').should.equal(a.toString('hex')); }); @@ -206,8 +206,8 @@ describe('PrivateKey', function() { describe('#fromWIF', function() { it('should parse this compressed testnet address correctly', function() { - var privkey = PrivateKey.fromWIF(encmainnet); - privkey.toWIF().should.equal(encmainnet); + var privkey = PrivateKey.fromWIF(enclivenet); + privkey.toWIF().should.equal(enclivenet); }); }); @@ -232,7 +232,7 @@ describe('PrivateKey', function() { describe('#toString', function() { - it('should parse this uncompressed mainnet address correctly', function() { + it('should parse this uncompressed livenet address correctly', function() { var privkey = PrivateKey.fromString(encmu); privkey.toString().should.equal(encmu); });