bitpay / bitcore-lib

A pure and powerful JavaScript Bitcoin library
https://bitcore.io/
Other
611 stars 1.03k forks source link

MultiSig Address not matched with bitcoinjs #222

Closed thackerronak closed 6 years ago

thackerronak commented 6 years ago

var bitcore = require('bitcore-lib'); var network = bitcore.Networks.testnet; var adds1 = ['036ab181020a6d194b93f0468ef1dcec2725c9d62f985e5c44204eccdf7ea7f7bc', '0212cfec75f672d79feaf9352ba3bb9ef12254db25fd3382672aff45a799d0a283', '03908d80a38995dee0182072368155456f075e4ea23752f9be188d35aa3b154430' ]; var p2shAddress = new bitcore.Address.createMultisig(adds1, 2,network); console.log(p2shAddress); <Address: 2MtGfpGS51zby2PusgGmM2o6PaaGy76dvxn, type: scripthash, network: testnet>

var bitcoin = require('bitcoinjs-lib'); var network1 = bitcoin.networks.testnet; var pubKeys = adds1.map(function (hex) { return Buffer.from(hex, 'hex') }) var redeemScript = bitcoin.script.multisig.output.encode(2, pubKeys) var scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(redeemScript)) var address = bitcoin.address.fromOutputScript(scriptPubKey, network1); console.log(address); 2MsJoX4iTns4rfJ4xXs5VoLo6Ba153VdxPm

Bitcore using the same algo. for Multisig ? or any way to get same address as bitcoinjs ?

gabegattis commented 6 years ago

I haven't looked into this much, but my first instinct would be to check if one is using compressed pubkeys and the other using uncompressed.

matiu commented 6 years ago

Iirc bitcore sorts the pubs keys. Try feeding bitcoinjs with the sorted keys.

Alternatively i think there is a flag to noSort.

On Wed, Apr 4, 2018, 3:49 PM Gabe Gattis notifications@github.com wrote:

I haven't looked into this much, but my first instinct would be to check if one is using compressed pubkeys and the other using uncompressed.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bitpay/bitcore-lib/issues/222#issuecomment-378706100, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGCHB51sIMf9B8fwPuqvURnmP3Itlnuks5tlRXRgaJpZM4TFpdL .

fanatid commented 6 years ago

noSort => noSorting, but it is not possible pass it to Address.createMultisig, so valid code:

var p2shAddress = bitcore.Address.payingTo(bitcore.Script.buildMultisigOut(adds1, 2, { noSorting: true }), network)
thackerronak commented 6 years ago

@fanatid Thanks. It's working.