|
|
@ -4,6 +4,7 @@ var base58check = require('./encoding/base58check'); |
|
|
|
var networks = require('./networks'); |
|
|
|
var Hash = require('./crypto/hash'); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* Bitcore Address |
|
|
@ -51,7 +52,7 @@ function Address(data, network, type) { |
|
|
|
throw new Error('Unrecognized data format'); |
|
|
|
} |
|
|
|
|
|
|
|
// set defaults is not set
|
|
|
|
// set defaults if not set
|
|
|
|
info.network = info.network || network || 'mainnet'; |
|
|
|
info.type = info.type || type || 'pubkeyhash'; |
|
|
|
|
|
|
@ -105,25 +106,25 @@ Address._transformBuffer = function(buffer, network, type){ |
|
|
|
var bufType = false; |
|
|
|
|
|
|
|
switch(buffer[0]){ // the version byte
|
|
|
|
case networks.mainnet.pubkeyhash: |
|
|
|
bufNetwork = 'mainnet'; |
|
|
|
bufType = 'pubkeyhash'; |
|
|
|
break; |
|
|
|
|
|
|
|
case networks.mainnet.scripthash: |
|
|
|
bufNetwork = 'mainnet'; |
|
|
|
bufType = 'scripthash'; |
|
|
|
break; |
|
|
|
case networks.mainnet.pubkeyhash: |
|
|
|
bufNetwork = 'mainnet'; |
|
|
|
bufType = 'pubkeyhash'; |
|
|
|
break; |
|
|
|
|
|
|
|
case networks.mainnet.scripthash: |
|
|
|
bufNetwork = 'mainnet'; |
|
|
|
bufType = 'scripthash'; |
|
|
|
break; |
|
|
|
|
|
|
|
case networks.testnet.pubkeyhash: |
|
|
|
bufNetwork = 'testnet'; |
|
|
|
bufType = 'pubkeyhash'; |
|
|
|
break; |
|
|
|
|
|
|
|
case networks.testnet.scripthash: |
|
|
|
bufNetwork = 'testnet'; |
|
|
|
bufType = 'scripthash'; |
|
|
|
break; |
|
|
|
case networks.testnet.pubkeyhash: |
|
|
|
bufNetwork = 'testnet'; |
|
|
|
bufType = 'pubkeyhash'; |
|
|
|
break; |
|
|
|
|
|
|
|
case networks.testnet.scripthash: |
|
|
|
bufNetwork = 'testnet'; |
|
|
|
bufType = 'scripthash'; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (!bufNetwork || (network && network !== bufNetwork)) { |
|
|
@ -311,12 +312,7 @@ Address.getValidationError = function(data, network, type) { |
|
|
|
* @returns {null|Error} The corresponding error message |
|
|
|
*/ |
|
|
|
Address.isValid = function(data, network, type) { |
|
|
|
var error = Address.getValidationError(data, network, type); |
|
|
|
if (error) { |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return !Address.getValidationError(data, network, type); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|