-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathsignTransaction.ts
More file actions
49 lines (44 loc) · 1.67 KB
/
signTransaction.ts
File metadata and controls
49 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import _ from 'lodash';
import { BIP32Interface } from '@bitgo/secp256k1';
import { bitgo } from '@bitgo/utxo-lib';
import * as utxolib from '@bitgo/utxo-lib';
import { DecodedTransaction } from '../types';
import { Musig2Participant } from './musig2';
import { signLegacyTransaction } from './signLegacyTransaction';
import { signPsbtWithMusig2Participant } from './signPsbt';
export async function signTransaction(
coin: Musig2Participant<utxolib.bitgo.UtxoPsbt>,
tx: DecodedTransaction<bigint | number>,
signerKeychain: BIP32Interface | undefined,
network: utxolib.Network,
params: {
walletId: string | undefined;
txInfo: { unspents?: utxolib.bitgo.Unspent<bigint | number>[] } | undefined;
isLastSignature: boolean;
signingStep: 'signerNonce' | 'cosignerNonce' | 'signerSignature' | undefined;
/** deprecated */
allowNonSegwitSigningWithoutPrevTx: boolean;
pubs: string[] | undefined;
cosignerPub: string | undefined;
}
): Promise<utxolib.bitgo.UtxoPsbt | utxolib.bitgo.UtxoTransaction<bigint | number>> {
let isLastSignature = false;
if (_.isBoolean(params.isLastSignature)) {
// if build is called instead of buildIncomplete, no signature placeholders are left in the sig script
isLastSignature = params.isLastSignature;
}
if (tx instanceof bitgo.UtxoPsbt) {
return signPsbtWithMusig2Participant(coin, tx, signerKeychain, {
isLastSignature,
signingStep: params.signingStep,
walletId: params.walletId,
});
}
return signLegacyTransaction(tx, signerKeychain, {
isLastSignature,
signingStep: params.signingStep,
txInfo: params.txInfo,
pubs: params.pubs,
cosignerPub: params.cosignerPub,
});
}