Network: Replaced all instances of mainnet with livenet for consistency
This commit is contained in:
parent
6519888f7b
commit
4adf1fcb14
@ -25,7 +25,7 @@ var Hash = require('./crypto/hash');
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param {String} data - The encoded data in various formats
|
* @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'
|
* @param {String} [type] - The type of address: 'script' or 'pubkey'
|
||||||
* @returns {Address} A new valid and frozen instance of an Address
|
* @returns {Address} A new valid and frozen instance of an Address
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -40,8 +40,8 @@ function Address(data, network, type) {
|
|||||||
throw new TypeError('First argument is required, please include address data.');
|
throw new TypeError('First argument is required, please include address data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network && (network !== 'mainnet' && network !== 'testnet')) {
|
if (network && (network !== 'livenet' && network !== 'testnet')) {
|
||||||
throw new TypeError('Second argument must be "mainnet" or "testnet".');
|
throw new TypeError('Second argument must be "livenet" or "testnet".');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type && (type !== 'pubkeyhash' && type !== 'scripthash')) {
|
if (type && (type !== 'pubkeyhash' && type !== 'scripthash')) {
|
||||||
@ -66,7 +66,7 @@ function Address(data, network, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set defaults if not set
|
// set defaults if not set
|
||||||
info.network = info.network || network || 'mainnet';
|
info.network = info.network || network || 'livenet';
|
||||||
info.type = info.type || type || 'pubkeyhash';
|
info.type = info.type || type || 'pubkeyhash';
|
||||||
|
|
||||||
// set the validated values
|
// set the validated values
|
||||||
@ -103,7 +103,7 @@ Address._transformHash = function(hash){
|
|||||||
* Internal function to transform a bitcoin address buffer
|
* Internal function to transform a bitcoin address buffer
|
||||||
*
|
*
|
||||||
* @param {Buffer} buffer - An instance of a hex encoded 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'
|
* @param {String} [type] - The type: 'pubkeyhash' or 'scripthash'
|
||||||
* @returns {Object} An object with keys: hashBuffer, network and type
|
* @returns {Object} An object with keys: hashBuffer, network and type
|
||||||
* @private
|
* @private
|
||||||
@ -121,13 +121,13 @@ Address._transformBuffer = function(buffer, network, type){
|
|||||||
var bufType = false;
|
var bufType = false;
|
||||||
|
|
||||||
switch(buffer[0]){ // the version byte
|
switch(buffer[0]){ // the version byte
|
||||||
case networks.mainnet.pubkeyhash:
|
case networks.livenet.pubkeyhash:
|
||||||
bufNetwork = 'mainnet';
|
bufNetwork = 'livenet';
|
||||||
bufType = 'pubkeyhash';
|
bufType = 'pubkeyhash';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case networks.mainnet.scripthash:
|
case networks.livenet.scripthash:
|
||||||
bufNetwork = 'mainnet';
|
bufNetwork = 'livenet';
|
||||||
bufType = 'scripthash';
|
bufType = 'scripthash';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ Address._transformScript = function(script){
|
|||||||
* Internal function to transform a bitcoin address string
|
* Internal function to transform a bitcoin address string
|
||||||
*
|
*
|
||||||
* @param {String} data - An instance of PublicKey
|
* @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'
|
* @param {String} [type] - The type: 'pubkeyhash' or 'scripthash'
|
||||||
* @returns {Object} An object with keys: hashBuffer, network and type
|
* @returns {Object} An object with keys: hashBuffer, network and type
|
||||||
* @private
|
* @private
|
||||||
@ -216,7 +216,7 @@ Address._transformString = function(data, network, type){
|
|||||||
* Instantiate an address from a PublicKey instance
|
* Instantiate an address from a PublicKey instance
|
||||||
*
|
*
|
||||||
* @param {String} data - An instance of PublicKey
|
* @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
|
* @returns {Address} A new valid and frozen instance of an Address
|
||||||
*/
|
*/
|
||||||
Address.fromPublicKey = function(data, network){
|
Address.fromPublicKey = function(data, network){
|
||||||
@ -229,7 +229,7 @@ Address.fromPublicKey = function(data, network){
|
|||||||
* Instantiate an address from a ripemd160 public key hash
|
* Instantiate an address from a ripemd160 public key hash
|
||||||
*
|
*
|
||||||
* @param {Buffer} hash - An instance of buffer of the 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
|
* @returns {Address} A new valid and frozen instance of an Address
|
||||||
*/
|
*/
|
||||||
Address.fromPublicKeyHash = function(hash, network) {
|
Address.fromPublicKeyHash = function(hash, network) {
|
||||||
@ -242,7 +242,7 @@ Address.fromPublicKeyHash = function(hash, network) {
|
|||||||
* Instantiate an address from a ripemd160 script hash
|
* Instantiate an address from a ripemd160 script hash
|
||||||
*
|
*
|
||||||
* @param {Buffer} hash - An instance of buffer of the 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
|
* @returns {Address} A new valid and frozen instance of an Address
|
||||||
*/
|
*/
|
||||||
Address.fromScriptHash = function(hash, network) {
|
Address.fromScriptHash = function(hash, network) {
|
||||||
@ -255,7 +255,7 @@ Address.fromScriptHash = function(hash, network) {
|
|||||||
* Instantiate an address from a Script
|
* Instantiate an address from a Script
|
||||||
*
|
*
|
||||||
* @param {Script} script - An instance of 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
|
* @returns {Address} A new valid and frozen instance of an Address
|
||||||
*/
|
*/
|
||||||
Address.fromScript = function(script, network) {
|
Address.fromScript = function(script, network) {
|
||||||
@ -268,7 +268,7 @@ Address.fromScript = function(script, network) {
|
|||||||
* Instantiate an address from a buffer of the address
|
* Instantiate an address from a buffer of the address
|
||||||
*
|
*
|
||||||
* @param {Buffer} buffer - An instance of 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'
|
* @param {String} [type] - The type of address: 'script' or 'pubkey'
|
||||||
* @returns {Address} A new valid and frozen instance of an Address
|
* @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
|
* Instantiate an address from an address string
|
||||||
*
|
*
|
||||||
* @param {String} str - An string of the bitcoin address
|
* @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'
|
* @param {String} [type] - The type of address: 'script' or 'pubkey'
|
||||||
* @returns {Address} A new valid and frozen instance of an Address
|
* @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
|
* // a network mismatch error
|
||||||
*
|
*
|
||||||
* @param {String} data - The encoded data
|
* @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'
|
* @param {String} type - The type of address: 'script' or 'pubkey'
|
||||||
* @returns {null|Error} The corresponding error message
|
* @returns {null|Error} The corresponding error message
|
||||||
*/
|
*/
|
||||||
@ -321,11 +321,11 @@ Address.getValidationError = function(data, network, type) {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var valid = Address.isValid('15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2', 'mainnet');
|
* var valid = Address.isValid('15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2', 'livenet');
|
||||||
* // true
|
* // true
|
||||||
*
|
*
|
||||||
* @param {String} data - The encoded data
|
* @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'
|
* @param {String} type - The type of address: 'script' or 'pubkey'
|
||||||
* @returns {null|Error} The corresponding error message
|
* @returns {null|Error} The corresponding error message
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -27,7 +27,7 @@ var PublicKey = require('./publickey');
|
|||||||
* var imported = PrivateKey.fromWIF(exported);
|
* var imported = PrivateKey.fromWIF(exported);
|
||||||
*
|
*
|
||||||
* @param {String} data - The encoded data in various formats
|
* @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
|
* @param {Boolean} [compressed] - If the key is in compressed format
|
||||||
* @returns {PrivateKey} A new valid instance of an PrivateKey
|
* @returns {PrivateKey} A new valid instance of an PrivateKey
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -40,7 +40,7 @@ var PrivateKey = function PrivateKey(data, network, compressed) {
|
|||||||
|
|
||||||
var info = {
|
var info = {
|
||||||
compressed: typeof(compressed) !== 'undefined' ? compressed : true,
|
compressed: typeof(compressed) !== 'undefined' ? compressed : true,
|
||||||
network: network || 'mainnet'
|
network: network || 'livenet'
|
||||||
};
|
};
|
||||||
|
|
||||||
// detect type of data
|
// detect type of data
|
||||||
@ -61,7 +61,7 @@ var PrivateKey = function PrivateKey(data, network, compressed) {
|
|||||||
throw new TypeError('Number must be less than N');
|
throw new TypeError('Number must be less than N');
|
||||||
}
|
}
|
||||||
if (typeof(networks[info.network]) === 'undefined') {
|
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') {
|
if (typeof(info.compressed) !== 'boolean') {
|
||||||
throw new TypeError('Must specify whether the corresponding public key is compressed or not (true or false)');
|
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
|
* Internal function to transform a WIF Buffer into a private key
|
||||||
*
|
*
|
||||||
* @param {Buffer} buf - An WIF string
|
* @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
|
* @param {String} [compressed] - If the private key is compressed
|
||||||
* @returns {Object} An object with keys: bn, network and compressed
|
* @returns {Object} An object with keys: bn, network and compressed
|
||||||
* @private
|
* @private
|
||||||
@ -115,8 +115,8 @@ PrivateKey._transformBuffer = function(buf, network, compressed) {
|
|||||||
throw new Error('Length of buffer must be 33 (uncompressed) or 34 (compressed)');
|
throw new Error('Length of buffer must be 33 (uncompressed) or 34 (compressed)');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === networks.mainnet.privatekey) {
|
if (buf[0] === networks.livenet.privatekey) {
|
||||||
info.network = 'mainnet';
|
info.network = 'livenet';
|
||||||
} else if (buf[0] === networks.testnet.privatekey) {
|
} else if (buf[0] === networks.testnet.privatekey) {
|
||||||
info.network = 'testnet';
|
info.network = 'testnet';
|
||||||
} else {
|
} else {
|
||||||
@ -177,7 +177,7 @@ PrivateKey.fromJSON = function(json) {
|
|||||||
*
|
*
|
||||||
* Instantiate a PrivateKey from random bytes
|
* 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
|
* @param {String} [compressed] - If the private key is compressed
|
||||||
* @returns {PrivateKey} A new valid instance of PrivateKey
|
* @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
|
* Check if there would be any errors when initializing a PrivateKey
|
||||||
*
|
*
|
||||||
* @param {String} data - The encoded data in various formats
|
* @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
|
* @param {String} [compressed] - If the private key is compressed
|
||||||
* @returns {null|Error} An error if exists
|
* @returns {null|Error} An error if exists
|
||||||
*/
|
*/
|
||||||
@ -223,7 +223,7 @@ PrivateKey.getValidationError = function(data, network, compressed) {
|
|||||||
* Check if the parameters are valid
|
* Check if the parameters are valid
|
||||||
*
|
*
|
||||||
* @param {String} data - The encoded data in various formats
|
* @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
|
* @param {String} [compressed] - If the private key is compressed
|
||||||
* @returns {Boolean} If the private key is would be valid
|
* @returns {Boolean} If the private key is would be valid
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -23,17 +23,17 @@ describe('Address', function() {
|
|||||||
it('should throw an error because of bad network param', function() {
|
it('should throw an error because of bad network param', function() {
|
||||||
(function(){
|
(function(){
|
||||||
var a = new Address(validAddresses[0], 'main', 'pubkeyhash');
|
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() {
|
it('should throw an error because of bad type param', function() {
|
||||||
(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"');
|
}).should.throw('Third argument must be "pubkeyhash" or "scripthash"');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// mainnet valid
|
// livenet valid
|
||||||
var validAddresses = [
|
var validAddresses = [
|
||||||
'15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2',
|
'15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2',
|
||||||
'1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT',
|
'1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT',
|
||||||
@ -41,7 +41,7 @@ describe('Address', function() {
|
|||||||
'1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7'
|
'1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7'
|
||||||
];
|
];
|
||||||
|
|
||||||
// mainnet p2sh
|
// livenet p2sh
|
||||||
var validp2shAddresses = [
|
var validp2shAddresses = [
|
||||||
'342ftSRCvFHfCeFFBuz4xwbeqnDw6BGUey',
|
'342ftSRCvFHfCeFFBuz4xwbeqnDw6BGUey',
|
||||||
'33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk',
|
'33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk',
|
||||||
@ -57,7 +57,7 @@ describe('Address', function() {
|
|||||||
'2NB72XtkjpnATMggui83aEtPawyyKvnbX2o'
|
'2NB72XtkjpnATMggui83aEtPawyyKvnbX2o'
|
||||||
];
|
];
|
||||||
|
|
||||||
//mainnet bad checksums
|
//livenet bad checksums
|
||||||
var badChecksums = [
|
var badChecksums = [
|
||||||
'15vkcKf7gB23wLAnZLmbVuMiiVDc3nq4a2',
|
'15vkcKf7gB23wLAnZLmbVuMiiVDc3nq4a2',
|
||||||
'1A6ut1tWnUq1SEQLMr4ttDh24wcbj4w2TT',
|
'1A6ut1tWnUq1SEQLMr4ttDh24wcbj4w2TT',
|
||||||
@ -65,7 +65,7 @@ describe('Address', function() {
|
|||||||
'1Jz2yCRd5ST1p2gUqFB5wsSQfdmEJaffg7'
|
'1Jz2yCRd5ST1p2gUqFB5wsSQfdmEJaffg7'
|
||||||
];
|
];
|
||||||
|
|
||||||
//mainnet non-base58
|
//livenet non-base58
|
||||||
var nonBase58 = [
|
var nonBase58 = [
|
||||||
'15vkcKf7g#23wLAnZLmb$uMiiVDc3nq4a2',
|
'15vkcKf7g#23wLAnZLmb$uMiiVDc3nq4a2',
|
||||||
'1A601ttWnUq1SEQLMr4ttDh24wcbj4w2TT',
|
'1A601ttWnUq1SEQLMr4ttDh24wcbj4w2TT',
|
||||||
@ -83,13 +83,13 @@ describe('Address', function() {
|
|||||||
|
|
||||||
describe('validation', 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');
|
var error = Address.getValidationError('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'testnet');
|
||||||
should.exist(error);
|
should.exist(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should should return a true boolean', function(){
|
it('should should return a true boolean', function(){
|
||||||
var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'mainnet');
|
var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'livenet');
|
||||||
valid.should.equal(true);
|
valid.should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -128,14 +128,14 @@ describe('Address', function() {
|
|||||||
|
|
||||||
it('should validate addresses with params', function() {
|
it('should validate addresses with params', function() {
|
||||||
for(var i=0;i<validAddresses.length;i++){
|
for(var i=0;i<validAddresses.length;i++){
|
||||||
var error = Address.getValidationError(validAddresses[i], 'mainnet');
|
var error = Address.getValidationError(validAddresses[i], 'livenet');
|
||||||
should.not.exist(error);
|
should.not.exist(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not validate because of an invalid checksum', function() {
|
it('should not validate because of an invalid checksum', function() {
|
||||||
for(var i=0;i<badChecksums.length;i++){
|
for(var i=0;i<badChecksums.length;i++){
|
||||||
var error = Address.getValidationError(badChecksums[i], 'mainnet', 'pubkeyhash');
|
var error = Address.getValidationError(badChecksums[i], 'livenet', 'pubkeyhash');
|
||||||
should.exist(error);
|
should.exist(error);
|
||||||
error.message.should.equal('Checksum mismatch');
|
error.message.should.equal('Checksum mismatch');
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ describe('Address', function() {
|
|||||||
|
|
||||||
it('should not validate because of a mismatched type', function() {
|
it('should not validate because of a mismatched type', function() {
|
||||||
for(var i=0;i<validAddresses.length;i++){
|
for(var i=0;i<validAddresses.length;i++){
|
||||||
var error = Address.getValidationError(validAddresses[i], 'mainnet', 'scripthash');
|
var error = Address.getValidationError(validAddresses[i], 'livenet', 'scripthash');
|
||||||
should.exist(error);
|
should.exist(error);
|
||||||
error.message.should.equal('Address has mismatched type.');
|
error.message.should.equal('Address has mismatched type.');
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ describe('Address', function() {
|
|||||||
|
|
||||||
it('should not validate because of non-base58 characters', function() {
|
it('should not validate because of non-base58 characters', function() {
|
||||||
for(var i=0;i<nonBase58.length;i++){
|
for(var i=0;i<nonBase58.length;i++){
|
||||||
var error = Address.getValidationError(nonBase58[i], 'mainnet', 'pubkeyhash');
|
var error = Address.getValidationError(nonBase58[i], 'livenet', 'pubkeyhash');
|
||||||
should.exist(error);
|
should.exist(error);
|
||||||
error.message.should.equal('Non-base58 character');
|
error.message.should.equal('Non-base58 character');
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ describe('Address', function() {
|
|||||||
|
|
||||||
it('should not validate testnet addresses because of mismatched network', function() {
|
it('should not validate testnet addresses because of mismatched network', function() {
|
||||||
for(var i=0;i<testValidAddresses.length;i++){
|
for(var i=0;i<testValidAddresses.length;i++){
|
||||||
var error = Address.getValidationError(testValidAddresses[i], 'mainnet', 'pubkeyhash');
|
var error = Address.getValidationError(testValidAddresses[i], 'livenet', 'pubkeyhash');
|
||||||
should.exist(error);
|
should.exist(error);
|
||||||
error.message.should.equal('Address has mismatched network type.');
|
error.message.should.equal('Address has mismatched network type.');
|
||||||
}
|
}
|
||||||
@ -274,9 +274,9 @@ describe('Address', function() {
|
|||||||
|
|
||||||
it('should make this address from an uncompressed pubkey', function() {
|
it('should make this address from an uncompressed pubkey', function() {
|
||||||
var pubkey = PublicKey.fromDER(new Buffer('0485e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b004833fef26c8be4c4823754869ff4e46755b85d851077771c220e2610496a29d98', 'hex'));
|
var pubkey = PublicKey.fromDER(new Buffer('0485e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b004833fef26c8be4c4823754869ff4e46755b85d851077771c220e2610496a29d98', 'hex'));
|
||||||
var a = Address.fromPublicKey(pubkey, 'mainnet');
|
var a = Address.fromPublicKey(pubkey, 'livenet');
|
||||||
a.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX');
|
a.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX');
|
||||||
var b = new Address(pubkey, 'mainnet', 'pubkeyhash');
|
var b = new Address(pubkey, 'livenet', 'pubkeyhash');
|
||||||
b.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX');
|
b.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ describe('Address', function() {
|
|||||||
b.toString().should.equal('347iRqVwks5r493N1rsLN4k9J7Ljg488W7');
|
b.toString().should.equal('347iRqVwks5r493N1rsLN4k9J7Ljg488W7');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should derive from this known address string mainnet', function() {
|
it('should derive from this known address string livenet', function() {
|
||||||
var address = new Address(str);
|
var address = new Address(str);
|
||||||
var buffer = address.toBuffer();
|
var buffer = address.toBuffer();
|
||||||
var slice = buffer.slice(1);
|
var slice = buffer.slice(1);
|
||||||
@ -314,8 +314,8 @@ describe('Address', function() {
|
|||||||
b.network.should.equal('testnet');
|
b.network.should.equal('testnet');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should derive from this known address string mainnet scripthash', function() {
|
it('should derive from this known address string livenet scripthash', function() {
|
||||||
var a = new Address(validp2shAddresses[0], 'mainnet', 'scripthash');
|
var a = new Address(validp2shAddresses[0], 'livenet', 'scripthash');
|
||||||
var b = new Address(a.toString());
|
var b = new Address(a.toString());
|
||||||
b.toString().should.equal(validp2shAddresses[0]);
|
b.toString().should.equal(validp2shAddresses[0]);
|
||||||
});
|
});
|
||||||
@ -339,7 +339,7 @@ describe('Address', function() {
|
|||||||
|
|
||||||
describe('#toString', function() {
|
describe('#toString', function() {
|
||||||
|
|
||||||
it('should output a mainnet pubkeyhash address', function() {
|
it('should output a livenet pubkeyhash address', function() {
|
||||||
var address = new Address(str);
|
var address = new Address(str);
|
||||||
address.toString().should.equal(str);
|
address.toString().should.equal(str);
|
||||||
});
|
});
|
||||||
@ -365,7 +365,7 @@ describe('Address', function() {
|
|||||||
|
|
||||||
it('should output formatted output correctly', function() {
|
it('should output formatted output correctly', function() {
|
||||||
var address = new Address(str);
|
var address = new Address(str);
|
||||||
var output = '<Address: 16VZnHwRhwrExfeHFHGjwrgEMq8VcYPs9r, type: pubkeyhash, network: mainnet>';
|
var output = '<Address: 16VZnHwRhwrExfeHFHGjwrgEMq8VcYPs9r, type: pubkeyhash, network: livenet>';
|
||||||
address.inspect().should.equal(output);
|
address.inspect().should.equal(output);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ describe('PrivateKey', function() {
|
|||||||
var buf = new Buffer(hex, 'hex');
|
var buf = new Buffer(hex, 'hex');
|
||||||
var enctestnet = 'cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG';
|
var enctestnet = 'cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG';
|
||||||
var enctu = '92jJzK4tbURm1C7udQXxeCBvXHoHJstDXRxAMouPG1k1XUaXdsu';
|
var enctu = '92jJzK4tbURm1C7udQXxeCBvXHoHJstDXRxAMouPG1k1XUaXdsu';
|
||||||
var encmainnet = 'L2Gkw3kKJ6N24QcDuH4XDqt9cTqsKTVNDGz1CRZhk9cq4auDUbJy';
|
var enclivenet = 'L2Gkw3kKJ6N24QcDuH4XDqt9cTqsKTVNDGz1CRZhk9cq4auDUbJy';
|
||||||
var encmu = '5JxgQaFM1FMd38cd14e3mbdxsdSa9iM2BV6DHBYsvGzxkTNQ7Un';
|
var encmu = '5JxgQaFM1FMd38cd14e3mbdxsdSa9iM2BV6DHBYsvGzxkTNQ7Un';
|
||||||
|
|
||||||
it('should create a new random private key', function() {
|
it('should create a new random private key', function() {
|
||||||
@ -51,7 +51,7 @@ describe('PrivateKey', function() {
|
|||||||
|
|
||||||
it('should not be able to instantiate private key because of compression mismatch', function() {
|
it('should not be able to instantiate private key because of compression mismatch', function() {
|
||||||
(function() {
|
(function() {
|
||||||
var a = new PrivateKey('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m', 'mainnet', false);
|
var a = new PrivateKey('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m', 'livenet', false);
|
||||||
}).should.throw('Private key compression mismatch');
|
}).should.throw('Private key compression mismatch');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ describe('PrivateKey', function() {
|
|||||||
it('should not be able to instantiate with unknown network', function() {
|
it('should not be able to instantiate with unknown network', function() {
|
||||||
(function() {
|
(function() {
|
||||||
var a = new PrivateKey(null, 'unknown');
|
var a = new PrivateKey(null, 'unknown');
|
||||||
}).should.throw('Must specify the network ("mainnet" or "testnet")');
|
}).should.throw('Must specify the network ("livenet" or "testnet")');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a 0 private key with this convenience method', function() {
|
it('should create a 0 private key with this convenience method', function() {
|
||||||
@ -95,9 +95,9 @@ describe('PrivateKey', function() {
|
|||||||
privkey.bn.toString().should.equal(bn.toString());
|
privkey.bn.toString().should.equal(bn.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a mainnet private key', function() {
|
it('should create a livenet private key', function() {
|
||||||
var privkey = new PrivateKey(BN.fromBuffer(buf), 'mainnet', true);
|
var privkey = new PrivateKey(BN.fromBuffer(buf), 'livenet', true);
|
||||||
privkey.toString().should.equal(encmainnet);
|
privkey.toString().should.equal(enclivenet);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an uncompressed testnet private key', function() {
|
it('should create an uncompressed testnet private key', function() {
|
||||||
@ -105,8 +105,8 @@ describe('PrivateKey', function() {
|
|||||||
privkey.toString().should.equal(enctu);
|
privkey.toString().should.equal(enctu);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an uncompressed mainnet private key', function() {
|
it('should create an uncompressed livenet private key', function() {
|
||||||
var privkey = new PrivateKey(BN.fromBuffer(buf), 'mainnet', false);
|
var privkey = new PrivateKey(BN.fromBuffer(buf), 'livenet', false);
|
||||||
privkey.toString().should.equal(encmu);
|
privkey.toString().should.equal(encmu);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ describe('PrivateKey', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#toAddress', function() {
|
describe('#toAddress', function() {
|
||||||
it('should output this known mainnet address correctly', function() {
|
it('should output this known livenet address correctly', function() {
|
||||||
var privkey = PrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
|
var privkey = PrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
|
||||||
var address = privkey.toAddress();
|
var address = privkey.toAddress();
|
||||||
address.toString().should.equal('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT');
|
address.toString().should.equal('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT');
|
||||||
@ -144,9 +144,9 @@ describe('PrivateKey', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#inspect', function() {
|
describe('#inspect', function() {
|
||||||
it('should output known mainnet address for console', function() {
|
it('should output known livenet address for console', function() {
|
||||||
var privkey = PrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
|
var privkey = PrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
|
||||||
privkey.inspect().should.equal('<PrivateKey: L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m, compressed: true, network: mainnet>');
|
privkey.inspect().should.equal('<PrivateKey: L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m, compressed: true, network: livenet>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should output known testnet address for console', function() {
|
it('should output known testnet address for console', function() {
|
||||||
@ -178,7 +178,7 @@ describe('PrivateKey', function() {
|
|||||||
|
|
||||||
describe('#toBuffer', function() {
|
describe('#toBuffer', function() {
|
||||||
it('should output known buffer', 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'));
|
var b = privkey.toBuffer().toString('hex').should.equal(buf.toString('hex'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -186,7 +186,7 @@ describe('PrivateKey', function() {
|
|||||||
describe('#toBigNumber', function() {
|
describe('#toBigNumber', function() {
|
||||||
it('should output known BN', function() {
|
it('should output known BN', function() {
|
||||||
var a = BN.fromBuffer(buf);
|
var a = BN.fromBuffer(buf);
|
||||||
var privkey = new PrivateKey(a, 'mainnet', true);
|
var privkey = new PrivateKey(a, 'livenet', true);
|
||||||
var b = privkey.toBigNumber();
|
var b = privkey.toBigNumber();
|
||||||
b.toString('hex').should.equal(a.toString('hex'));
|
b.toString('hex').should.equal(a.toString('hex'));
|
||||||
});
|
});
|
||||||
@ -206,8 +206,8 @@ describe('PrivateKey', function() {
|
|||||||
describe('#fromWIF', function() {
|
describe('#fromWIF', function() {
|
||||||
|
|
||||||
it('should parse this compressed testnet address correctly', function() {
|
it('should parse this compressed testnet address correctly', function() {
|
||||||
var privkey = PrivateKey.fromWIF(encmainnet);
|
var privkey = PrivateKey.fromWIF(enclivenet);
|
||||||
privkey.toWIF().should.equal(encmainnet);
|
privkey.toWIF().should.equal(enclivenet);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -232,7 +232,7 @@ describe('PrivateKey', function() {
|
|||||||
|
|
||||||
describe('#toString', 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);
|
var privkey = PrivateKey.fromString(encmu);
|
||||||
privkey.toString().should.equal(encmu);
|
privkey.toString().should.equal(encmu);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user