Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/wasm-utxo/js/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { AddressNamespace } from "./wasm/wasm_utxo";
import type { CoinName } from "./coinName";

/**
* Most coins only have one unambiguous address format (base58check and bech32/bech32m)
* For Bitcoin Cash and eCash, we can select between base58check and cashaddr.
*/
Comment on lines +4 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be a good idea for us to migrate to only cashaddr for descriptor wallets

export type AddressFormat = "default" | "cashaddr";

export function toOutputScriptWithCoin(address: string, coin: CoinName): Uint8Array {
Expand Down
21 changes: 18 additions & 3 deletions packages/wasm-utxo/js/fixedScriptWallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FixedScriptWalletNamespace } from "./wasm/wasm_utxo";
import type { UtxolibNetwork, UtxolibRootWalletKeys } from "./utxolibCompat";
import { Triple } from "./triple";
import { AddressFormat } from "./address";

export type WalletKeys =
/** Just an xpub triple, will assume default derivation prefixes */
Expand All @@ -11,19 +12,33 @@ export type WalletKeys =
/**
* Create the output script for a given wallet keys and chain and index
*/
export function outputScript(keys: WalletKeys, chain: number, index: number): Uint8Array {
return FixedScriptWalletNamespace.output_script(keys, chain, index);
export function outputScript(
keys: WalletKeys,
chain: number,
index: number,
network: UtxolibNetwork,
): Uint8Array {
return FixedScriptWalletNamespace.output_script(keys, chain, index, network);
}

/**
* Create the address for a given wallet keys and chain and index and network.
* Wrapper for outputScript that also encodes the script to an address.
* @param keys - The wallet keys to use.
* @param chain - The chain to use.
* @param index - The index to use.
* @param network - The network to use.
* @param addressFormat - The address format to use.
* Only relevant for Bitcoin Cash and eCash networks, where:
* - "default" means base58check,
* - "cashaddr" means cashaddr.
*/
export function address(
keys: WalletKeys,
chain: number,
index: number,
network: UtxolibNetwork,
addressFormat?: AddressFormat,
): string {
return FixedScriptWalletNamespace.address(keys, chain, index, network);
return FixedScriptWalletNamespace.address(keys, chain, index, network, addressFormat);
}
Loading