11import { FixedScriptWalletNamespace } from "../wasm/wasm_utxo.js" ;
22import { type WalletKeysArg , RootWalletKeys } from "./RootWalletKeys.js" ;
33import type { UtxolibNetwork } from "../utxolibCompat.js" ;
4+ import type { UtxolibName } from "../utxolibCompat.js" ;
5+ import type { CoinName } from "../coinName.js" ;
46import { AddressFormat } from "../address.js" ;
57
8+ export type NetworkName = UtxolibName | CoinName ;
9+
610/**
711 * Create the output script for a given wallet keys and chain and index
12+ * @param keys - The wallet keys to use
13+ * @param chain - The chain to use
14+ * @param index - The index to use
15+ * @param network - The network to use. Can be a network name string (e.g., "btc", "bitcoin", "testnet") or a UtxolibNetwork object
816 */
917export function outputScript (
1018 keys : WalletKeysArg ,
1119 chain : number ,
1220 index : number ,
13- network : UtxolibNetwork ,
21+ network : NetworkName | UtxolibNetwork ,
1422) : Uint8Array {
1523 const walletKeys = RootWalletKeys . from ( keys ) ;
16- return FixedScriptWalletNamespace . output_script ( walletKeys . wasm , chain , index , network ) ;
24+ if ( typeof network === "string" ) {
25+ return FixedScriptWalletNamespace . output_script_with_network_str (
26+ walletKeys . wasm ,
27+ chain ,
28+ index ,
29+ network ,
30+ ) ;
31+ } else {
32+ return FixedScriptWalletNamespace . output_script ( walletKeys . wasm , chain , index , network ) ;
33+ }
1734}
1835
1936/**
@@ -22,7 +39,7 @@ export function outputScript(
2239 * @param keys - The wallet keys to use.
2340 * @param chain - The chain to use.
2441 * @param index - The index to use.
25- * @param network - The network to use.
42+ * @param network - The network to use. Can be a network name string (e.g., "btc", "bitcoin", "testnet") or a UtxolibNetwork object
2643 * @param addressFormat - The address format to use.
2744 * Only relevant for Bitcoin Cash and eCash networks, where:
2845 * - "default" means base58check,
@@ -32,9 +49,25 @@ export function address(
3249 keys : WalletKeysArg ,
3350 chain : number ,
3451 index : number ,
35- network : UtxolibNetwork ,
52+ network : NetworkName | UtxolibNetwork ,
3653 addressFormat ?: AddressFormat ,
3754) : string {
3855 const walletKeys = RootWalletKeys . from ( keys ) ;
39- return FixedScriptWalletNamespace . address ( walletKeys . wasm , chain , index , network , addressFormat ) ;
56+ if ( typeof network === "string" ) {
57+ return FixedScriptWalletNamespace . address_with_network_str (
58+ walletKeys . wasm ,
59+ chain ,
60+ index ,
61+ network ,
62+ addressFormat ,
63+ ) ;
64+ } else {
65+ return FixedScriptWalletNamespace . address (
66+ walletKeys . wasm ,
67+ chain ,
68+ index ,
69+ network ,
70+ addressFormat ,
71+ ) ;
72+ }
4073}
0 commit comments