|
|
@ -100,15 +100,17 @@ function Address(data, network, type) { |
|
|
|
* @returns {Object} An "info" object with "type", "network", and "hashBuffer" |
|
|
|
*/ |
|
|
|
Address.prototype._classifyArguments = function(data, network, type) { |
|
|
|
var PublicKey = require('./publickey'); |
|
|
|
var Script = require('./script'); |
|
|
|
/* jshint maxcomplexity: 10 */ |
|
|
|
// transform and validate input data
|
|
|
|
if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 20) { |
|
|
|
return Address._transformHash(data); |
|
|
|
} else if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 21) { |
|
|
|
return Address._transformBuffer(data, network, type); |
|
|
|
} else if (data.constructor && (data.constructor.name && data.constructor.name === 'PublicKey')) { |
|
|
|
} else if (data instanceof PublicKey) { |
|
|
|
return Address._transformPublicKey(data); |
|
|
|
} else if (data.constructor && (data.constructor.name && data.constructor.name === 'Script')) { |
|
|
|
} else if (data instanceof Script) { |
|
|
|
return Address._transformScript(data, network); |
|
|
|
} else if (typeof(data) === 'string') { |
|
|
|
return Address._transformString(data, network, type); |
|
|
@ -213,8 +215,9 @@ Address._transformBuffer = function(buffer, network, type){ |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformPublicKey = function(pubkey){ |
|
|
|
var PublicKey = require('./publickey'); |
|
|
|
var info = {}; |
|
|
|
if (!pubkey.constructor || (pubkey.constructor.name && pubkey.constructor.name !== 'PublicKey')) { |
|
|
|
if (!(pubkey instanceof PublicKey)) { |
|
|
|
throw new TypeError('Address must be an instance of PublicKey.'); |
|
|
|
} |
|
|
|
info.hashBuffer = Hash.sha256ripemd160(pubkey.toBuffer()); |
|
|
@ -230,8 +233,9 @@ Address._transformPublicKey = function(pubkey){ |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformScript = function(script, network){ |
|
|
|
var Script = require('./script'); |
|
|
|
var info = {}; |
|
|
|
if (!script.constructor || (script.constructor.name && script.constructor.name !== 'Script')) { |
|
|
|
if (!(script instanceof Script)) { |
|
|
|
throw new TypeError('Address must be an instance of Script.'); |
|
|
|
} |
|
|
|
if (script.isScriptHashOut()) { |
|
|
|