Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip p2sh if multisig #399

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions sdk/src/wallet/utxo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Transaction, Script, selectUTXO, TEST_NETWORK, NETWORK, p2wpkh, p2sh } from '@scure/btc-signer';
import { Transaction, Script, selectUTXO, TEST_NETWORK, NETWORK, p2wpkh, p2sh, OutScript } from '@scure/btc-signer';
import { hex, base64 } from '@scure/base';
import { AddressType, getAddressInfo, Network } from 'bitcoin-address-validation';
import { EsploraClient, UTXO } from '../esplora';
import { ripemd160, sha256 } from 'bitcoinjs-lib/src/crypto';

export type BitcoinNetworkName = Exclude<Network, 'regtest'>;

Expand Down Expand Up @@ -185,7 +186,14 @@ export function getInputFromUtxoAndTx(
throw new Error('Bitcoin P2SH not supported without public key');
}
const inner = p2wpkh(Buffer.from(publicKey!, 'hex'), getBtcNetwork(network));
redeemScript = p2sh(inner);

// p2sh throws errors if multisig address is used
const hash = ripemd160(sha256(Buffer.from(inner.script)));
const script = OutScript.encode({ type: 'sh', hash });
if (script) {
const s = OutScript.decode(script);
if (s.type !== 'ms') redeemScript = p2sh(inner);
}
}

// For the redeem and witness script, we need to construct the script mixin
Expand Down
Loading