Skip to content

Commit ef88bda

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): move signTransaction away from abstract coin
Move signTransaction function to standalone module that doesn't depend on AbstractUtxoCoin. Move DecodedTransaction type to types.ts to break dependency cycle. Issue: BTC-2806 Co-authored-by: llm-git <[email protected]>
1 parent 7809170 commit ef88bda

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { isReplayProtectionUnspent } from './transaction/fixedScript/replayProte
5959
import { supportedCrossChainRecoveries } from './config';
6060
import {
6161
assertValidTransactionRecipient,
62+
DecodedTransaction,
6263
explainTx,
6364
fromExtendedAddressFormat,
6465
isScriptRecipient,
@@ -178,9 +179,7 @@ function convertValidationErrorToTxIntentMismatch(
178179
return txIntentError;
179180
}
180181

181-
export type DecodedTransaction<TNumber extends number | bigint> =
182-
| utxolib.bitgo.UtxoTransaction<TNumber>
183-
| utxolib.bitgo.UtxoPsbt;
182+
export type { DecodedTransaction } from './transaction/types';
184183

185184
export type RootWalletKeys = bitgo.RootWalletKeys;
186185

modules/abstract-utxo/src/transaction/fixedScript/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ export { explainPsbtWasm } from './explainPsbtWasm';
33
export { parseTransaction } from './parseTransaction';
44
export { CustomChangeOptions } from './parseOutput';
55
export { verifyTransaction } from './verifyTransaction';
6-
export { signTransaction } from './signTransaction';
6+
export { signTransaction, Musig2Participant } from './signTransaction';
77
export * from './sign';
88
export * from './replayProtection';

modules/abstract-utxo/src/transaction/fixedScript/signTransaction.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import { bitgo } from '@bitgo/utxo-lib';
66
import * as utxolib from '@bitgo/utxo-lib';
77
import { isTriple, Triple } from '@bitgo/sdk-core';
88

9-
import { AbstractUtxoCoin, DecodedTransaction } from '../../abstractUtxoCoin';
9+
import { DecodedTransaction } from '../types';
1010

1111
import { signAndVerifyPsbt, signAndVerifyWalletTransaction } from './sign';
1212

1313
type RootWalletKeys = bitgo.RootWalletKeys;
1414

15+
export interface Musig2Participant {
16+
getMusig2Nonces(psbtHex: string, walletId: string): Promise<{ psbt: string }>;
17+
}
18+
1519
/**
1620
* Key Value: Unsigned tx id => PSBT
1721
* It is used to cache PSBTs with taproot key path (MuSig2) inputs during external express signer is activated.
@@ -23,9 +27,10 @@ type RootWalletKeys = bitgo.RootWalletKeys;
2327
const PSBT_CACHE = new Map<string, utxolib.bitgo.UtxoPsbt>();
2428

2529
export async function signTransaction<TNumber extends number | bigint>(
26-
coin: AbstractUtxoCoin,
30+
coin: Musig2Participant,
2731
tx: DecodedTransaction<TNumber>,
2832
signerKeychain: BIP32Interface | undefined,
33+
network: utxolib.Network,
2934
params: {
3035
walletId: string | undefined;
3136
txInfo: { unspents?: utxolib.bitgo.Unspent<TNumber>[] } | undefined;
@@ -79,7 +84,7 @@ export async function signTransaction<TNumber extends number | bigint>(
7984
assert(signerKeychain);
8085
tx.setAllInputsMusig2NonceHD(signerKeychain);
8186
const response = await coin.getMusig2Nonces(tx.toHex(), params.walletId);
82-
tx.combine(bitgo.createPsbtFromHex(response.psbt, coin.network));
87+
tx.combine(bitgo.createPsbtFromHex(response.psbt, network));
8388
break;
8489
}
8590
} else {

modules/abstract-utxo/src/transaction/signTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function signTransaction<TNumber extends number | bigint>(
6363
throw new Error('expected a UtxoPsbt object');
6464
}
6565
} else {
66-
return fixedScript.signTransaction(coin, tx, getSignerKeychain(params.prv), {
66+
return fixedScript.signTransaction(coin, tx, getSignerKeychain(params.prv), coin.network, {
6767
walletId: params.txPrebuild.walletId,
6868
txInfo: params.txPrebuild.txInfo,
6969
isLastSignature: params.isLastSignature ?? false,

modules/abstract-utxo/src/transaction/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import * as utxolib from '@bitgo/utxo-lib';
2+
13
import type { UtxoNamedKeychains } from '../keychains';
24

35
import type { CustomChangeOptions } from './fixedScript';
46

7+
export type DecodedTransaction<TNumber extends number | bigint> =
8+
| utxolib.bitgo.UtxoTransaction<TNumber>
9+
| utxolib.bitgo.UtxoPsbt;
10+
511
export interface BaseOutput<TAmount = string | number> {
612
address: string;
713
amount: TAmount;

0 commit comments

Comments
 (0)