|
|
@ -5,20 +5,30 @@ var networks = require('./networks'); |
|
|
|
var Hash = require('./crypto/hash'); |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* Bitcore Address |
|
|
|
* |
|
|
|
* Instantiate an address from an address String or Buffer, a public key or script hash Buffer, |
|
|
|
* or an instance of PublicKey or Script. |
|
|
|
* |
|
|
|
* @example |
|
|
|
* |
|
|
|
* var address = new Address(keypair.pubkey, 'testnet').toString(); |
|
|
|
* // validate that an input field is valid
|
|
|
|
* var error = Address.getValidationError(input, 'testnet'); |
|
|
|
* if (!error) { |
|
|
|
* var address = Address(input, 'testnet'); |
|
|
|
* } else { |
|
|
|
* // invalid network or checksum (typo?)
|
|
|
|
* var message = error.messsage; |
|
|
|
* } |
|
|
|
* |
|
|
|
* // get an address from a public key
|
|
|
|
* var address = Address(publicKey, 'testnet').toString(); |
|
|
|
* |
|
|
|
* |
|
|
|
* @param {String} data - The encoded data in various formats |
|
|
|
* @param {String} [network] - The network: 'mainnet' or 'testnet' |
|
|
|
* @param {String} [type] - The type of address: 'script' or 'pubkey' |
|
|
|
* @returns {Address} A new valid and frozen instance of an Address |
|
|
|
* @constructor |
|
|
|
*/ |
|
|
|
function Address(data, network, type) { |
|
|
|
|
|
|
@ -74,6 +84,7 @@ function Address(data, network, type) { |
|
|
|
* |
|
|
|
* @param {Buffer} hash - An instance of a hash Buffer |
|
|
|
* @returns {Object} An object with keys: hashBuffer |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformHash = function(hash){ |
|
|
|
var info = {}; |
|
|
@ -95,6 +106,7 @@ Address._transformHash = function(hash){ |
|
|
|
* @param {String} [network] - The network: 'mainnet' or 'testnet' |
|
|
|
* @param {String} [type] - The type: 'pubkeyhash' or 'scripthash' |
|
|
|
* @returns {Object} An object with keys: hashBuffer, network and type |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformBuffer = function(buffer, network, type){ |
|
|
|
var info = {}; |
|
|
@ -150,6 +162,7 @@ Address._transformBuffer = function(buffer, network, type){ |
|
|
|
* |
|
|
|
* @param {PublicKey} pubkey - An instance of PublicKey |
|
|
|
* @returns {Object} An object with keys: hashBuffer, type |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformPublicKey = function(pubkey){ |
|
|
|
var info = {}; |
|
|
@ -167,6 +180,7 @@ Address._transformPublicKey = function(pubkey){ |
|
|
|
* |
|
|
|
* @param {Script} script - An instance of Script |
|
|
|
* @returns {Object} An object with keys: hashBuffer, type |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformScript = function(script){ |
|
|
|
var info = {}; |
|
|
@ -186,6 +200,7 @@ Address._transformScript = function(script){ |
|
|
|
* @param {String} [network] - The network: 'mainnet' or 'testnet' |
|
|
|
* @param {String} [type] - The type: 'pubkeyhash' or 'scripthash' |
|
|
|
* @returns {Object} An object with keys: hashBuffer, network and type |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformString = function(data, network, type){ |
|
|
|
if( typeof(data) !== 'string' ) { |
|
|
@ -348,6 +363,6 @@ Address.prototype.toString = function() { |
|
|
|
*/ |
|
|
|
Address.prototype.inspect = function() { |
|
|
|
return '<Address: ' + this.toString() + ', type: '+this.type+', network: '+this.network+'>'; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = Address; |
|
|
|