|
|
@ -244,28 +244,11 @@ Address._transformPublicKey = function(pubkey) { |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Address._transformScript = function(script, network) { |
|
|
|
var info = {}; |
|
|
|
if (!(script instanceof Script)) { |
|
|
|
throw new TypeError('script must be an instance of Script.'); |
|
|
|
} |
|
|
|
if (script.isScriptHashOut()) { |
|
|
|
info.hashBuffer = script.getData(); |
|
|
|
info.type = Address.PayToScriptHash; |
|
|
|
} else if (script.isPublicKeyHashOut()) { |
|
|
|
info.hashBuffer = script.getData(); |
|
|
|
info.type = Address.PayToPublicKeyHash; |
|
|
|
} else if (script.isPublicKeyHashIn()) { |
|
|
|
// hash the publickey found in the scriptSig
|
|
|
|
info.hashBuffer = Hash.sha256ripemd160(script.chunks[1].buf); |
|
|
|
info.type = Address.PayToPublicKeyHash; |
|
|
|
} else if (script.isScriptHashIn()) { |
|
|
|
// hash the redeemscript found at the end of the scriptSig
|
|
|
|
info.hashBuffer = Hash.sha256ripemd160(script.chunks[script.chunks.length - 1].buf); |
|
|
|
info.type = Address.PayToScriptHash; |
|
|
|
} else { |
|
|
|
$.checkArgument(script instanceof Script, 'script must be a Script instance'); |
|
|
|
var info = script.getAddressInfo(network); |
|
|
|
if (!info) { |
|
|
|
throw new errors.Script.CantDeriveAddress(script); |
|
|
|
} |
|
|
|
info.network = Networks.get(network) || Networks.defaultNetwork; |
|
|
|
return info; |
|
|
|
}; |
|
|
|
|
|
|
@ -297,7 +280,7 @@ Address.createMultisig = function(publicKeys, threshold, network) { |
|
|
|
*/ |
|
|
|
Address._transformString = function(data, network, type) { |
|
|
|
if (typeof(data) !== 'string') { |
|
|
|
throw new TypeError('Address supplied is not a string.'); |
|
|
|
throw new TypeError('data parameter supplied is not a string.'); |
|
|
|
} |
|
|
|
var addressBuffer = Base58Check.decode(data); |
|
|
|
var info = Address._transformBuffer(addressBuffer, network, type); |
|
|
@ -372,6 +355,7 @@ Address.payingTo = function(script, network) { |
|
|
|
* @returns {Address} A new valid and frozen instance of an Address |
|
|
|
*/ |
|
|
|
Address.fromScript = function(script, network) { |
|
|
|
$.checkArgument(script instanceof Script, 'script must be a Script instance'); |
|
|
|
var info = Address._transformScript(script, network); |
|
|
|
return new Address(info.hashBuffer, network, info.type); |
|
|
|
}; |
|
|
|