From ae271f709e07a9f165a7bcc3b8ead4fdc9107a12 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Fri, 22 May 2026 15:15:05 +0200 Subject: [PATCH 1/3] refactor(abstract-utxo): drop utxolib RootWalletKeys from keychains.ts Switch the instanceof check and Triple conversion path to use fixedScriptWallet.RootWalletKeys from wasm-utxo. The other input shapes (UtxoNamedKeychains, Triple<{pub}>, string[]) continue to work via the existing toKeychainTriple/string-array branches. Refs: T1-3279 --- modules/abstract-utxo/src/keychains.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/abstract-utxo/src/keychains.ts b/modules/abstract-utxo/src/keychains.ts index 073b40a848..2903a556bf 100644 --- a/modules/abstract-utxo/src/keychains.ts +++ b/modules/abstract-utxo/src/keychains.ts @@ -1,7 +1,6 @@ import assert from 'assert'; import * as t from 'io-ts'; -import { bitgo } from '@bitgo/utxo-lib'; import { IRequestTracer, IWallet, KeyIndices, promiseProps, Triple } from '@bitgo/sdk-core'; import { BIP32, bip32, fixedScriptWallet } from '@bitgo/wasm-utxo'; @@ -48,10 +47,10 @@ export function toKeychainTriple(keychains: UtxoNamedKeychains): Triple | string[] + keychains: fixedScriptWallet.RootWalletKeys | UtxoNamedKeychains | Triple<{ pub: string }> | string[] ): Triple { - if (keychains instanceof bitgo.RootWalletKeys) { - return keychains.triple.map((k) => BIP32.fromBase58(k.toBase58())) as Triple; + if (keychains instanceof fixedScriptWallet.RootWalletKeys) { + return [keychains.userKey(), keychains.backupKey(), keychains.bitgoKey()]; } if (Array.isArray(keychains)) { if (keychains.length !== 3) { From 0b6356af6d8e80ffc923761c4d843213c553b8d9 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Fri, 22 May 2026 15:16:33 +0200 Subject: [PATCH 2/3] refactor(abstract-utxo): drop unused exports from wasmUtil MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the unused toWasmECPair / ECPairKey helper (no src callers) and inline the isUtxoLibPsbt type guard into toWasmPsbt's narrowing branch. The file remains a bridge between utxolib and wasm-utxo types — its remaining callers (offlineVault/OfflineVaultHalfSigned.ts, impl/btc/inscriptionBuilder.ts, transaction/descriptor/parse.ts, transaction/fixedScript/signPsbtWasm.ts) still pass utxolib instances. Refs: T1-3279 --- modules/abstract-utxo/src/wasmUtil.ts | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/modules/abstract-utxo/src/wasmUtil.ts b/modules/abstract-utxo/src/wasmUtil.ts index f22e4fcf50..035ba82613 100644 --- a/modules/abstract-utxo/src/wasmUtil.ts +++ b/modules/abstract-utxo/src/wasmUtil.ts @@ -1,8 +1,7 @@ -import { BIP32, bip32, ECPair, Psbt, descriptorWallet } from '@bitgo/wasm-utxo'; +import { BIP32, bip32, Psbt, descriptorWallet } from '@bitgo/wasm-utxo'; import * as utxolib from '@bitgo/utxo-lib'; export type BIP32Key = BIP32 | bip32.BIP32Interface | utxolib.BIP32Interface; -export type ECPairKey = ECPair | utxolib.ECPairInterface | Uint8Array; export type UtxoLibPsbt = utxolib.Psbt | utxolib.bitgo.UtxoPsbt; /** @@ -36,23 +35,6 @@ export function toUtxolibBIP32(key: BIP32Key): utxolib.BIP32Interface { return utxolib.bip32.fromBase58(key.toBase58()); } -export function toWasmECPair(key: ECPairKey): ECPair { - if (key instanceof ECPair) { - return key; - } - if (key instanceof Uint8Array) { - return ECPair.from(key); - } - if (key.privateKey) { - return ECPair.fromPrivateKey(key.privateKey); - } - return ECPair.fromPublicKey(key.publicKey); -} - -export function isUtxoLibPsbt(psbt: unknown): psbt is UtxoLibPsbt { - return psbt instanceof utxolib.Psbt || psbt instanceof utxolib.bitgo.UtxoPsbt; -} - export function toWasmPsbt(psbt: Psbt | UtxoLibPsbt | Uint8Array): Psbt { if (psbt instanceof Psbt) { return psbt; @@ -60,10 +42,7 @@ export function toWasmPsbt(psbt: Psbt | UtxoLibPsbt | Uint8Array): Psbt { if (psbt instanceof Uint8Array) { return Psbt.deserialize(psbt); } - if (isUtxoLibPsbt(psbt)) { - return Psbt.deserialize(psbt.toBuffer()); - } - throw new Error('Unsupported PSBT type'); + return Psbt.deserialize(psbt.toBuffer()); } /** From 45f03387937f6d832e68133f51a169411b7c7ec3 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Fri, 22 May 2026 15:56:27 +0200 Subject: [PATCH 3/3] refactor(abstract-utxo): delete wasmUtil.ts and drop utxolib from runtime deps All callers have been migrated off the wasmUtil bridge. Delete the file and move @bitgo/utxo-lib from dependencies to devDependencies in package.json. The dep is still required for tests (utxolib.testutil.AcidTest, network constants, BIP32 helpers). Refs: T1-3279 --- modules/abstract-utxo/package.json | 2 +- modules/abstract-utxo/src/wasmUtil.ts | 53 --------------------------- 2 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 modules/abstract-utxo/src/wasmUtil.ts diff --git a/modules/abstract-utxo/package.json b/modules/abstract-utxo/package.json index 6e0acbd80c..169fffdf81 100644 --- a/modules/abstract-utxo/package.json +++ b/modules/abstract-utxo/package.json @@ -65,7 +65,6 @@ "@bitgo/sdk-core": "^37.3.0", "@bitgo/utxo-core": "^1.39.0", "@bitgo/utxo-descriptors": "^1.3.0", - "@bitgo/utxo-lib": "^11.22.1", "@bitgo/utxo-ord": "^1.32.0", "@bitgo/wasm-utxo": "^4.16.0", "@types/lodash": "^4.14.121", @@ -78,6 +77,7 @@ }, "devDependencies": { "@bitgo/sdk-test": "^9.1.46", + "@bitgo/utxo-lib": "^11.22.1", "mocha": "^10.2.0" }, "gitHead": "18e460ddf02de2dbf13c2aa243478188fb539f0c" diff --git a/modules/abstract-utxo/src/wasmUtil.ts b/modules/abstract-utxo/src/wasmUtil.ts deleted file mode 100644 index 035ba82613..0000000000 --- a/modules/abstract-utxo/src/wasmUtil.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { BIP32, bip32, Psbt, descriptorWallet } from '@bitgo/wasm-utxo'; -import * as utxolib from '@bitgo/utxo-lib'; - -export type BIP32Key = BIP32 | bip32.BIP32Interface | utxolib.BIP32Interface; -export type UtxoLibPsbt = utxolib.Psbt | utxolib.bitgo.UtxoPsbt; - -/** - * Map of descriptor name to Descriptor instance. - * Re-exported from wasm-utxo for consistency. - */ -export type DescriptorMap = descriptorWallet.DescriptorMap; - -/** - * Key type accepted by descriptorWallet.signWithKey - */ -export type SignerKey = Parameters[1]; - -/** - * Convert a utxo-lib BIP32Interface to a wasm-utxo BIP32 instance. - * Preserves private key by using base58 serialization. - */ -export function toWasmBIP32(key: BIP32Key): BIP32 { - if (key instanceof BIP32) { - return key; - } - // All utxo-lib BIP32Interface instances have toBase58 - return BIP32.fromBase58(key.toBase58()); -} - -/** - * Convert a wasm-utxo BIP32 to a utxo-lib BIP32Interface. - * Used at boundaries where utxo-lib APIs require their own BIP32Interface type. - */ -export function toUtxolibBIP32(key: BIP32Key): utxolib.BIP32Interface { - return utxolib.bip32.fromBase58(key.toBase58()); -} - -export function toWasmPsbt(psbt: Psbt | UtxoLibPsbt | Uint8Array): Psbt { - if (psbt instanceof Psbt) { - return psbt; - } - if (psbt instanceof Uint8Array) { - return Psbt.deserialize(psbt); - } - return Psbt.deserialize(psbt.toBuffer()); -} - -/** - * Sum the `value` property of an array of objects. - */ -export function sumValues(arr: { value: bigint }[]): bigint { - return arr.reduce((sum, e) => sum + e.value, BigInt(0)); -}