Skip to content

Commit 7782b3c

Browse files
refactor(abstract-utxo): replace utxolib.bitgo helpers and drop dead branches
- isChainCode / scriptTypeForChain -> ChainCode.is / ChainCode.scriptType (wasm-utxo) - hasKeyPathSpendInput: drop unreachable utxolib.bitgo.UtxoPsbt branch and isTransactionWithKeyPathSpendInput call (DecodedTransaction is now BitGoPsbt only) - validAddressTypes: inline the 2-of-3 list instead of utxolib.outputScripts.scriptTypes2Of3 - Drop unused RootWalletKeys / UtxoNetwork type re-exports and the now-empty utxolib bitgo import Three utxolib references remain in abstractUtxoCoin: the ScriptType2Of3 type re-export, the deprecated network getter (still used by tests), and the top-level utxolib import that backs both. Refs: T1-3279
1 parent 0bcd397 commit 7782b3c

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { randomBytes } from 'crypto';
44
import _ from 'lodash';
55
import * as utxolib from '@bitgo/utxo-lib';
66
import { address as wasmAddress, BIP32, fixedScriptWallet, hasPsbtMagic } from '@bitgo/wasm-utxo';
7-
import { bitgo } from '@bitgo/utxo-lib';
87
import {
98
AddressCoinSpecific,
109
BaseCoin,
@@ -62,7 +61,6 @@ import { getReplayProtectionPubkeys, isReplayProtectionUnspent } from './transac
6261
import { supportedCrossChainRecoveries } from './config';
6362
import {
6463
assertValidTransactionRecipient,
65-
DecodedTransaction,
6664
explainTx,
6765
fromExtendedAddressFormat,
6866
isScriptRecipient,
@@ -142,28 +140,21 @@ type UtxoCustomSigningFunction<TNumber extends number | bigint> = {
142140
}): Promise<SignedTransaction>;
143141
};
144142

145-
const { isChainCode, scriptTypeForChain, outputScripts } = bitgo;
143+
const { ChainCode } = fixedScriptWallet;
146144

147145
/**
148146
* Check if a decoded transaction has at least one taproot key path spend (MuSig2) input.
149-
* Works for both utxolib UtxoPsbt and wasm-utxo BitGoPsbt.
150147
*/
151-
function hasKeyPathSpendInput<TNumber extends number | bigint>(
152-
tx: DecodedTransaction<TNumber>,
148+
function hasKeyPathSpendInput(
149+
tx: fixedScriptWallet.BitGoPsbt,
153150
pubs: string[] | undefined,
154151
coinName: UtxoCoinName
155152
): boolean {
156-
if (tx instanceof bitgo.UtxoPsbt) {
157-
return bitgo.isTransactionWithKeyPathSpendInput(tx);
158-
}
159-
if (tx instanceof fixedScriptWallet.BitGoPsbt) {
160-
assert(pubs && isTriple(pubs), 'pub triple is required to check for key path spend inputs in wasm-utxo PSBT');
161-
const rootWalletKeys = fixedScriptWallet.RootWalletKeys.fromXpubs(pubs);
162-
const replayProtection = { publicKeys: getReplayProtectionPubkeys(coinName) };
163-
const parsed = tx.parseTransactionWithWalletKeys(rootWalletKeys, { replayProtection });
164-
return parsed.inputs.some((input) => input.scriptType === 'p2trMusig2KeyPath');
165-
}
166-
return false;
153+
assert(pubs && isTriple(pubs), 'pub triple is required to check for key path spend inputs in wasm-utxo PSBT');
154+
const rootWalletKeys = fixedScriptWallet.RootWalletKeys.fromXpubs(pubs);
155+
const replayProtection = { publicKeys: getReplayProtectionPubkeys(coinName) };
156+
const parsed = tx.parseTransactionWithWalletKeys(rootWalletKeys, { replayProtection });
157+
return parsed.inputs.some((input) => input.scriptType === 'p2trMusig2KeyPath');
167158
}
168159

169160
/**
@@ -216,8 +207,6 @@ function convertValidationErrorToTxIntentMismatch(
216207

217208
export type { DecodedTransaction } from './transaction/types';
218209

219-
export type RootWalletKeys = bitgo.RootWalletKeys;
220-
221210
export type UtxoCoinSpecific = AddressCoinSpecific | DescriptorAddressCoinSpecific;
222211

223212
export interface VerifyAddressOptions<TCoinSpecific extends UtxoCoinSpecific> extends BaseVerifyAddressOptions {
@@ -252,8 +241,6 @@ export interface DecoratedExplainTransactionOptions<TNumber extends number | big
252241
changeInfo?: { address: string; chain: number; index: number }[];
253242
}
254243

255-
export type UtxoNetwork = utxolib.Network;
256-
257244
export interface TransactionPrebuild<TNumber extends number | bigint = number> extends BaseTransactionPrebuild {
258245
txInfo?: TransactionInfo<TNumber>;
259246
blockHeight?: number;
@@ -459,7 +446,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin implements Musig2Partici
459446

460447
/** @deprecated */
461448
static get validAddressTypes(): ScriptType2Of3[] {
462-
return [...outputScripts.scriptTypes2Of3];
449+
return ['p2sh', 'p2shP2wsh', 'p2wsh', 'p2tr', 'p2trMusig2'];
463450
}
464451

465452
/**
@@ -590,7 +577,9 @@ export abstract class AbstractUtxoCoin extends BaseCoin implements Musig2Partici
590577
* @param addressDetails
591578
*/
592579
static inferAddressType(addressDetails: { chain: number }): ScriptType2Of3 | null {
593-
return isChainCode(addressDetails.chain) ? scriptTypeForChain(addressDetails.chain) : null;
580+
return fixedScriptWallet.ChainCode.is(addressDetails.chain)
581+
? (fixedScriptWallet.ChainCode.scriptType(addressDetails.chain) as ScriptType2Of3)
582+
: null;
594583
}
595584

596585
decodeTransaction(input: Buffer | string): fixedScriptWallet.BitGoPsbt {
@@ -755,7 +744,10 @@ export abstract class AbstractUtxoCoin extends BaseCoin implements Musig2Partici
755744
* @return true iff coin supports spending from chain
756745
*/
757746
supportsAddressChain(chain: number): boolean {
758-
return isChainCode(chain) && this.supportsAddressType(utxolib.bitgo.scriptTypeForChain(chain));
747+
return (
748+
fixedScriptWallet.ChainCode.is(chain) &&
749+
this.supportsAddressType(fixedScriptWallet.ChainCode.scriptType(chain) as ScriptType2Of3)
750+
);
759751
}
760752

761753
keyIdsForSigning(): number[] {

0 commit comments

Comments
 (0)