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/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) { diff --git a/modules/abstract-utxo/src/wasmUtil.ts b/modules/abstract-utxo/src/wasmUtil.ts deleted file mode 100644 index f22e4fcf50..0000000000 --- a/modules/abstract-utxo/src/wasmUtil.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { BIP32, bip32, ECPair, 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; - -/** - * 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 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; - } - if (psbt instanceof Uint8Array) { - return Psbt.deserialize(psbt); - } - if (isUtxoLibPsbt(psbt)) { - return Psbt.deserialize(psbt.toBuffer()); - } - throw new Error('Unsupported PSBT type'); -} - -/** - * 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)); -}