Skip to content

Commit e39f820

Browse files
committed
Fix address generation for multisig
1 parent 73e42fa commit e39f820

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

js/coin.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@
106106
return coinjs.base58encode(r.concat(checksum));
107107
}
108108

109+
/* provide a redeemscript and return address */
110+
coinjs.redeemscript2address = function(h){
111+
var r = ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(h), {asBytes: true}));
112+
r.unshift(coinjs.multisig);
113+
var hash = Crypto.SHA256(Crypto.SHA256(r, {asBytes: true}), {asBytes: true});
114+
var checksum = hash.slice(0, 4);
115+
return coinjs.base58encode(r.concat(checksum));
116+
}
117+
109118
/* provide a scripthash and return address */
110119
coinjs.scripthash2address = function(h){
111120
var x = Crypto.util.hexToBytes(h);
@@ -1037,7 +1046,7 @@
10371046
if (utxo_script['type'] == 'scriptpubkey') {
10381047
address = coinjs.scripthash2address(utxo_script['script'].slice(6, 46));
10391048
} else if (utxo_script['type'] == 'multisig') {
1040-
address = coinjs.pubkey2address(utxo_script['script']); // hash the redeemscript
1049+
address = coinjs.redeemscript2address(utxo_script['script']); // hash the redeemscript
10411050
} else if (utxo_script['type'] == 'hodl') {
10421051
alert('Bitcoin Cash hodl addresses not supported yet. Sorry.');
10431052
return false;

0 commit comments

Comments
 (0)