Skip to content

Commit a71a702

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): simplify interface, use wasm types
Simplify FixedScriptAddressCoinSpecific by removing redeem and witness script fields, which are no longer needed with the WASM implementation. Also update parameter type to use WalletKeysArg from wasm-utxo instead of the deprecated bitgo.RootWalletKeys. Issue: BTC-2916 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 0d339d9 commit a71a702

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

modules/abstract-utxo/src/address/fixedScript.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ import {
1212
isTriple,
1313
Triple,
1414
} from '@bitgo/sdk-core';
15-
import { bitgo } from '@bitgo/utxo-lib';
1615
import { fixedScriptWallet } from '@bitgo/wasm-utxo';
1716

18-
import { getNetworkFromCoinName, UtxoCoinName } from '../names';
17+
import { UtxoCoinName } from '../names';
1918

2019
type ScriptType2Of3 = fixedScriptWallet.OutputScriptType;
2120
type ChainCode = fixedScriptWallet.ChainCode;
2221

2322
export interface FixedScriptAddressCoinSpecific {
2423
outputScript?: string;
25-
redeemScript?: string;
26-
witnessScript?: string;
2724
}
2825

2926
export interface GenerateAddressOptions {
@@ -43,18 +40,24 @@ function supportsAddressType(coinName: UtxoCoinName, addressType: ScriptType2Of3
4340
return fixedScriptWallet.supportsScriptType(coinName, addressType);
4441
}
4542

43+
/**
44+
* Normalize script type aliases. "p2tr" is an alias for "p2trLegacy".
45+
*/
46+
function normalizeScriptType(scriptType: ScriptType2Of3 | 'p2tr'): ScriptType2Of3 {
47+
return scriptType === 'p2tr' ? 'p2trLegacy' : scriptType;
48+
}
49+
4650
export function generateAddressWithChainAndIndex(
4751
coinName: UtxoCoinName,
48-
keychains: fixedScriptWallet.RootWalletKeys | bitgo.RootWalletKeys | Triple<string>,
52+
keychains: fixedScriptWallet.WalletKeysArg | Triple<string>,
4953
chain: ChainCode,
5054
index: number,
5155
format: CreateAddressFormat | undefined
5256
): string {
5357
// Convert CreateAddressFormat to AddressFormat for wasm-utxo
5458
// 'base58' -> 'default', 'cashaddr' -> 'cashaddr'
5559
const wasmFormat = format === 'base58' ? 'default' : format;
56-
const network = getNetworkFromCoinName(coinName);
57-
return fixedScriptWallet.address(keychains, chain, index, network, wasmFormat);
60+
return fixedScriptWallet.address(keychains, chain, index, coinName, wasmFormat);
5861
}
5962

6063
/**
@@ -95,7 +98,7 @@ export function generateAddress(coinName: UtxoCoinName, params: GenerateFixedScr
9598
}
9699
}
97100

98-
const addressType = params.addressType || convertFlagsToAddressType();
101+
const addressType = normalizeScriptType(params.addressType || convertFlagsToAddressType());
99102

100103
if (addressType !== fixedScriptWallet.ChainCode.scriptType(derivationChain)) {
101104
throw new AddressTypeChainMismatchError(addressType, derivationChain);
@@ -110,6 +113,7 @@ export function generateAddress(coinName: UtxoCoinName, params: GenerateFixedScr
110113
case 'p2wsh':
111114
throw new P2wshUnsupportedError();
112115
case 'p2tr':
116+
case 'p2trLegacy':
113117
throw new P2trUnsupportedError();
114118
case 'p2trMusig2':
115119
throw new P2trMusig2UnsupportedError();

0 commit comments

Comments
 (0)