-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathOfflineVaultHalfSigned.ts
More file actions
35 lines (30 loc) · 1.07 KB
/
OfflineVaultHalfSigned.ts
File metadata and controls
35 lines (30 loc) · 1.07 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
import { BIP32Interface, bip32 } from '@bitgo/secp256k1';
import * as utxolib from '@bitgo/utxo-lib';
import { BaseCoin } from '@bitgo/sdk-core';
import { UtxoCoinName } from '../names';
import { OfflineVaultSignable } from './OfflineVaultSignable';
import { DescriptorTransaction, getHalfSignedPsbt } from './descriptor';
export type OfflineVaultHalfSigned = {
halfSigned: { txHex: string };
};
function createHalfSignedFromPsbt(psbt: utxolib.Psbt): OfflineVaultHalfSigned {
return { halfSigned: { txHex: psbt.toHex() } };
}
export function createHalfSigned(
coinName: UtxoCoinName,
prv: string | BIP32Interface,
derivationId: string,
tx: unknown
): OfflineVaultHalfSigned {
if (typeof prv === 'string') {
prv = bip32.fromBase58(prv);
}
prv = BaseCoin.deriveKeyWithSeedBip32(prv, derivationId).key;
if (!OfflineVaultSignable.is(tx)) {
throw new Error('unsupported transaction type');
}
if (DescriptorTransaction.is(tx)) {
return createHalfSignedFromPsbt(getHalfSignedPsbt(tx, prv, coinName));
}
throw new Error('unsupported transaction type');
}