Skip to content

Commit c259e2d

Browse files
Merge pull request #5441 from BitGo/BTC-1801.fix-presign-for-descriptor-wallets
fix(abstract-utxo): presign for descriptor wallets
2 parents 2195803 + 2702580 commit c259e2d

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ import { toBip32Triple, UtxoKeychain, UtxoNamedKeychains } from './keychains';
7474
import { verifyKeySignature, verifyUserPublicKey } from './verifyKey';
7575
import { getPolicyForEnv } from './descriptor/validatePolicy';
7676
import { signTransaction } from './transaction/signTransaction';
77-
import { UtxoWallet } from './wallet';
77+
import { isUtxoWalletData, UtxoWallet } from './wallet';
78+
import { isDescriptorWalletData } from './descriptor/descriptorWallet';
7879

7980
import ScriptType2Of3 = utxolib.bitgo.outputScripts.ScriptType2Of3;
8081

@@ -1094,6 +1095,9 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
10941095
}
10951096

10961097
async presignTransaction(params: PresignTransactionOptions): Promise<any> {
1098+
if (params.walletData && isUtxoWalletData(params.walletData) && isDescriptorWalletData(params.walletData)) {
1099+
return params;
1100+
}
10971101
// In the case that we have a 'psbt-lite' transaction format, we want to indicate in signing to not fail
10981102
const txHex = (params.txHex ?? params.txPrebuild?.txHex) as string;
10991103
if (

modules/abstract-utxo/src/names.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
import * as utxolib from '@bitgo/utxo-lib';
22

3+
export const utxoCoinsMainnet = ['btc', 'bch', 'bcha', 'bsv', 'btg', 'dash', 'doge', 'ltc', 'zec'] as const;
4+
export const utxoCoinsTestnet = [
5+
'tbtc',
6+
'tbch',
7+
'tbsv',
8+
'tdash',
9+
'tdoge',
10+
'tltc',
11+
'tzec',
12+
'tbtcsig',
13+
'tbtc4',
14+
'tbtcbgsig',
15+
] as const;
16+
17+
export type UtxoCoinNameMainnet = (typeof utxoCoinsMainnet)[number];
18+
export type UtxoCoinNameTestnet = (typeof utxoCoinsTestnet)[number];
19+
export type UtxoCoinName = UtxoCoinNameMainnet | UtxoCoinNameTestnet;
20+
21+
export function isUtxoCoinNameMainnet(coinName: string): coinName is UtxoCoinNameMainnet {
22+
return utxoCoinsMainnet.includes(coinName as UtxoCoinNameMainnet);
23+
}
24+
25+
export function isUtxoCoinNameTestnet(coinName: string): coinName is UtxoCoinNameTestnet {
26+
return utxoCoinsTestnet.includes(coinName as UtxoCoinNameTestnet);
27+
}
28+
29+
export function isUtxoCoinName(coinName: string): coinName is UtxoCoinName {
30+
return isUtxoCoinNameMainnet(coinName) || isUtxoCoinNameTestnet(coinName);
31+
}
32+
333
function getNetworkName(n: utxolib.Network): utxolib.NetworkName {
434
const name = utxolib.getNetworkName(n);
535
if (!name) {
@@ -12,7 +42,7 @@ function getNetworkName(n: utxolib.Network): utxolib.NetworkName {
1242
* @param n
1343
* @returns the family name for a network. Testnets and mainnets of the same coin share the same family name.
1444
*/
15-
export function getFamilyFromNetwork(n: utxolib.Network): string {
45+
export function getFamilyFromNetwork(n: utxolib.Network): UtxoCoinNameMainnet {
1646
switch (getNetworkName(n)) {
1747
case 'bitcoin':
1848
case 'testnet':

modules/abstract-utxo/src/wallet.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { Wallet, WalletData } from '@bitgo/sdk-core';
22

3+
import { isUtxoCoinName, UtxoCoinName } from './names';
4+
35
// parseTransactions' return type makes use of WalletData's type but with customChangeKeySignatures as required.
46
export interface UtxoWalletData extends WalletData {
7+
coin: UtxoCoinName;
58
customChangeKeySignatures: {
69
user: string;
710
backup: string;
811
bitgo: string;
912
};
1013
}
1114

15+
export function isUtxoWalletData(obj: WalletData): obj is UtxoWalletData {
16+
return isUtxoCoinName(obj.coin);
17+
}
18+
1219
export interface UtxoWallet extends Wallet {
1320
_wallet: UtxoWalletData;
1421
}

0 commit comments

Comments
 (0)