Skip to content

Commit

Permalink
fix: psbt bare utxo signing
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Jul 27, 2023
1 parent 0519dcf commit 3ae0dc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
19 changes: 5 additions & 14 deletions src/shared/crypto/bitcoin/bitcoin.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,16 @@ export function decodeBitcoinTx(tx: string) {
export function getAddressFromOutScript(script: Uint8Array, bitcoinNetwork: BtcSignerNetwork) {
const outputScript = btc.OutScript.decode(script);

if (outputScript.type === 'pk' || outputScript.type === 'tr') {
if (outputScript.type === 'ms') return btc.p2ms(outputScript.m, outputScript.pubkeys).address;
if (outputScript.type === 'pk') return btc.p2pk(outputScript.pubkey, bitcoinNetwork).address;
if (outputScript.type === 'tr') {
return btc.Address(bitcoinNetwork).encode({
type: outputScript.type,
pubkey: outputScript.pubkey,
});
}
if (outputScript.type === 'ms' || outputScript.type === 'tr_ms') {
return btc.Address(bitcoinNetwork).encode({
type: outputScript.type,
pubkeys: outputScript.pubkeys,
m: outputScript.m,
});
}
if (outputScript.type === 'tr_ns') {
return btc.Address(bitcoinNetwork).encode({
type: outputScript.type,
pubkeys: outputScript.pubkeys,
});
}
if (outputScript.type === 'tr_ms') throw new Error('Cannot currently handle script type tr_ms');
if (outputScript.type === 'tr_ns') throw new Error('Cannot currently handle script type tr_ns');
if (outputScript.type === 'unknown') {
return btc.Address(bitcoinNetwork).encode({
type: outputScript.type,
Expand Down
14 changes: 7 additions & 7 deletions test-app/src/components/bitcoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ function getTaprootPayment(publicKey: Uint8Array) {
return btc.p2tr(ecdsaPublicKeyToSchnorr(publicKey), undefined, bitcoinTestnet);
}

let bareMultiSigLockingScript =
'512102dc054e58b755f233295d2a8759a3e4cbf678619d8e75379e7989046dbce16be32102932b35a45d21395ac8bb54b8f9dae3fd2dbc309c24e550cf2211fe6aa897e5ca2102020202020202020202020202020202020202020202020202020202020202020253ae';

function buildTestNativeSegwitPsbtRequest(pubKey: Uint8Array): PsbtRequestOptions {
const p2wpkh = btc.p2wpkh(pubKey, bitcoinTestnet);

const tx = new btc.Transaction();
const tx = new btc.Transaction({ disableScriptCheck: true });

tx.addInput({
index: 0,
Expand All @@ -64,16 +67,13 @@ function buildTestNativeSegwitPsbtRequest(pubKey: Uint8Array): PsbtRequestOption
script: p2wpkh.script,
},
});
tx.addOutput({
amount: BigInt(5000),
script: p2wpkh.script,
});
tx.addOutput({ amount: BigInt(796), script: bareMultiSigLockingScript });

const psbt = tx.toPSBT();

// For testing mainnet
return { hex: tempHex };
// return { hex: bytesToHex(psbt) };
// return { hex: tempHex };
return { hex: bytesToHex(psbt) };
}

function buildTestNativeSegwitPsbtRequestWithIndexes(pubKey: Uint8Array): PsbtRequestOptions {
Expand Down

0 comments on commit 3ae0dc4

Please sign in to comment.