Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ type UtxoBaseSignTransactionOptions<TNumber extends number | bigint = number> =
* When false, return finalized PSBT. Useful for testing to keep transactions in PSBT format.
*/
extractTransaction?: boolean;
/** When true, embeds WASM-UTXO version metadata into the signed PSBT. Defaults to false. */
writeSignedWith?: boolean;
};

export type SignTransactionOptions<TNumber extends number | bigint = number> = UtxoBaseSignTransactionOptions<TNumber> &
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert';

import { BIP32, bip32, ECPair, fixedScriptWallet } from '@bitgo/wasm-utxo';
import { BIP32, bip32, ECPair, fixedScriptWallet, getWasmUtxoVersion } from '@bitgo/wasm-utxo';

import { toWasmBIP32 } from '../../wasmUtil';

Expand Down Expand Up @@ -37,7 +37,8 @@ export function signAndVerifyPsbtWasm(
tx: fixedScriptWallet.BitGoPsbt,
signerKeychain: bip32.BIP32Interface | BIP32,
rootWalletKeys: fixedScriptWallet.RootWalletKeys,
replayProtection: ReplayProtectionKeys
replayProtection: ReplayProtectionKeys,
{ writeSignedWith = false }: { writeSignedWith?: boolean } = {}
): fixedScriptWallet.BitGoPsbt {
const wasmSigner = toWasmBIP32(signerKeychain);

Expand Down Expand Up @@ -74,6 +75,17 @@ export function signAndVerifyPsbtWasm(
throw new TransactionSigningError([], verifyErrors);
}

if (writeSignedWith) {
const versionInfo = getWasmUtxoVersion();
const versionPayload = new TextEncoder().encode(
JSON.stringify({
version: versionInfo.version,
gitHash: versionInfo.gitHash,
})
);
tx.setKV({ type: 'bitgo', subtype: fixedScriptWallet.BitGoKeySubtype.WasmUtxoSignedWith }, versionPayload);
}

return tx;
}

Expand All @@ -86,6 +98,7 @@ export async function signPsbtWithMusig2ParticipantWasm(
replayProtection: ReplayProtectionKeys;
signingStep: 'signerNonce' | 'cosignerNonce' | 'signerSignature' | undefined;
walletId: string | undefined;
writeSignedWith?: boolean;
}
): Promise<fixedScriptWallet.BitGoPsbt> {
const wasmSigner = signerKeychain ? toWasmBIP32(signerKeychain) : undefined;
Expand Down Expand Up @@ -135,5 +148,7 @@ export async function signPsbtWithMusig2ParticipantWasm(
}

assert(signerKeychain);
return signAndVerifyPsbtWasm(tx, signerKeychain, rootWalletKeys, params.replayProtection);
return signAndVerifyPsbtWasm(tx, signerKeychain, rootWalletKeys, params.replayProtection, {
writeSignedWith: params.writeSignedWith,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,36 @@ export function signAndVerifyPsbt(
psbt: utxolib.bitgo.UtxoPsbt,
signerKeychain: bip32.BIP32Interface | BIP32,
rootWalletKeys: fixedScriptWallet.RootWalletKeys | undefined,
replayProtection: ReplayProtectionKeys | undefined
replayProtection: ReplayProtectionKeys | undefined,
options?: { writeSignedWith?: boolean }
): utxolib.bitgo.UtxoPsbt;
export function signAndVerifyPsbt(
psbt: fixedScriptWallet.BitGoPsbt,
signerKeychain: bip32.BIP32Interface | BIP32,
rootWalletKeys: fixedScriptWallet.RootWalletKeys,
replayProtection: ReplayProtectionKeys
replayProtection: ReplayProtectionKeys,
options?: { writeSignedWith?: boolean }
): fixedScriptWallet.BitGoPsbt;
export function signAndVerifyPsbt(
psbt: utxolib.bitgo.UtxoPsbt | fixedScriptWallet.BitGoPsbt,
signerKeychain: bip32.BIP32Interface | BIP32,
rootWalletKeys: fixedScriptWallet.RootWalletKeys,
replayProtection: ReplayProtectionKeys
replayProtection: ReplayProtectionKeys,
options?: { writeSignedWith?: boolean }
): utxolib.bitgo.UtxoPsbt | fixedScriptWallet.BitGoPsbt;
export function signAndVerifyPsbt(
psbt: utxolib.bitgo.UtxoPsbt | fixedScriptWallet.BitGoPsbt,
signerKeychain: bip32.BIP32Interface | BIP32,
rootWalletKeys: fixedScriptWallet.RootWalletKeys | undefined,
replayProtection: ReplayProtectionKeys | undefined
replayProtection: ReplayProtectionKeys | undefined,
options: { writeSignedWith?: boolean } = {}
): utxolib.bitgo.UtxoPsbt | fixedScriptWallet.BitGoPsbt {
if (psbt instanceof bitgo.UtxoPsbt) {
return signAndVerifyPsbtUtxolib(psbt, toUtxolibBIP32(signerKeychain));
}
assert(rootWalletKeys, 'rootWalletKeys required for wasm-utxo signing');
assert(replayProtection, 'replayProtection required for wasm-utxo signing');
return signAndVerifyPsbtWasm(psbt, signerKeychain, rootWalletKeys, replayProtection);
return signAndVerifyPsbtWasm(psbt, signerKeychain, rootWalletKeys, replayProtection, options);
}

export async function signTransaction<
Expand All @@ -69,6 +73,7 @@ export async function signTransaction<
cosignerPub: string | undefined;
/** When true (default), extract finalized PSBT to legacy transaction format. When false, return finalized PSBT. */
extractTransaction?: boolean;
writeSignedWith?: boolean;
}
): Promise<
utxolib.bitgo.UtxoPsbt | utxolib.bitgo.UtxoTransaction<bigint | number> | fixedScriptWallet.BitGoPsbt | Buffer
Expand Down Expand Up @@ -115,6 +120,7 @@ export async function signTransaction<
},
signingStep: params.signingStep,
walletId: params.walletId,
writeSignedWith: params.writeSignedWith,
}
);
if (isLastSignature) {
Expand Down
1 change: 1 addition & 0 deletions modules/abstract-utxo/src/transaction/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export async function signTransaction<TNumber extends number | bigint>(
pubs: params.pubs,
cosignerPub: params.cosignerPub,
extractTransaction: params.extractTransaction,
writeSignedWith: params.writeSignedWith,
});

// Convert half-signed PSBT to legacy format when the caller explicitly requested txFormat: 'legacy'
Expand Down
Loading