@bitgo/wasm-utxo 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +33 -0
  2. package/dist/browser/js/address.d.ts +8 -0
  3. package/dist/browser/js/address.js +7 -0
  4. package/dist/browser/js/ast/formatNode.d.ts +88 -0
  5. package/dist/browser/js/ast/formatNode.js +36 -0
  6. package/dist/browser/js/ast/fromWasmNode.d.ts +4 -0
  7. package/dist/browser/js/ast/fromWasmNode.js +120 -0
  8. package/dist/browser/js/ast/index.d.ts +2 -0
  9. package/dist/browser/js/ast/index.js +2 -0
  10. package/dist/browser/js/coinName.d.ts +1 -0
  11. package/dist/browser/js/coinName.js +1 -0
  12. package/dist/browser/js/fixedScriptWallet.d.ts +86 -0
  13. package/dist/browser/js/fixedScriptWallet.js +61 -0
  14. package/dist/browser/js/index.d.ts +37 -0
  15. package/dist/browser/js/index.js +11 -0
  16. package/dist/browser/js/triple.d.ts +1 -0
  17. package/dist/browser/js/triple.js +1 -0
  18. package/dist/browser/js/utxolibCompat.d.ts +32 -0
  19. package/dist/browser/js/utxolibCompat.js +7 -0
  20. package/dist/browser/js/wasm/wasm_utxo.d.ts +94 -0
  21. package/dist/browser/js/wasm/wasm_utxo.js +4 -0
  22. package/dist/browser/js/wasm/wasm_utxo_bg.js +1274 -0
  23. package/dist/browser/js/wasm/wasm_utxo_bg.wasm +0 -0
  24. package/dist/browser/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -0
  25. package/dist/node/js/address.d.ts +8 -0
  26. package/dist/node/js/address.js +11 -0
  27. package/dist/node/js/ast/formatNode.d.ts +88 -0
  28. package/dist/node/js/ast/formatNode.js +39 -0
  29. package/dist/node/js/ast/fromWasmNode.d.ts +4 -0
  30. package/dist/node/js/ast/fromWasmNode.js +124 -0
  31. package/dist/node/js/ast/index.d.ts +2 -0
  32. package/dist/node/js/ast/index.js +18 -0
  33. package/dist/node/js/coinName.d.ts +1 -0
  34. package/dist/node/js/coinName.js +2 -0
  35. package/dist/node/js/fixedScriptWallet.d.ts +86 -0
  36. package/dist/node/js/fixedScriptWallet.js +68 -0
  37. package/dist/node/js/index.d.ts +37 -0
  38. package/dist/node/js/index.js +50 -0
  39. package/dist/node/js/triple.d.ts +1 -0
  40. package/dist/node/js/triple.js +2 -0
  41. package/dist/node/js/utxolibCompat.d.ts +32 -0
  42. package/dist/node/js/utxolibCompat.js +11 -0
  43. package/dist/node/js/wasm/wasm_utxo.d.ts +94 -0
  44. package/dist/node/js/wasm/wasm_utxo.js +1283 -0
  45. package/dist/node/js/wasm/wasm_utxo_bg.wasm +0 -0
  46. package/dist/node/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -0
  47. package/package.json +52 -5
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # wasm-utxo
2
+
3
+ This project is the successor of the Javascript `utxo-lib` package.
4
+
5
+ It provides WASM bindings for the `rust-bitcoin` and `rust-miniscript` crates
6
+ that help verify and co-sign transactions built by the BitGo Wallet Platform API.
7
+
8
+ ## Documentation
9
+
10
+ - **[`src/wasm-bindgen.md`](src/wasm-bindgen.md)** - Guide for creating WASM bindings using the namespace pattern
11
+ - **[`js/README.md`](js/README.md)** - TypeScript wrapper layer architecture and best practices
12
+ - **[`cli/README.md`](cli/README.md)** - Command-line interface for address and PSBT operations
13
+
14
+ ## Status
15
+
16
+ This project is under active development.
17
+
18
+ | Feature | Bitcoin | BitcoinCash | BitcoinGold | Dash | Doge | Litecoin | Zcash |
19
+ | --------------------------------------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- |
20
+ | Descriptor Wallet: Address Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
21
+ | Descriptor Wallet: Transaction Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
22
+ | FixedScript Wallet: Address Generation | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete |
23
+ | FixedScript Wallet: Transaction Support | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO | ⏳ TODO |
24
+
25
+ ## Building
26
+
27
+ If your system has problems with `wasm-pack` (Mac M1), you can use the `Container.mk` Makefile to build the wasm files:
28
+
29
+ ```bash
30
+ cd packages/wasm-utxo
31
+ make -f Container.mk build-image
32
+ make -f Container.mk build-wasm
33
+ ```
@@ -0,0 +1,8 @@
1
+ import type { CoinName } from "./coinName";
2
+ /**
3
+ * Most coins only have one unambiguous address format (base58check and bech32/bech32m)
4
+ * For Bitcoin Cash and eCash, we can select between base58check and cashaddr.
5
+ */
6
+ export type AddressFormat = "default" | "cashaddr";
7
+ export declare function toOutputScriptWithCoin(address: string, coin: CoinName): Uint8Array;
8
+ export declare function fromOutputScriptWithCoin(script: Uint8Array, coin: CoinName, format?: AddressFormat): string;
@@ -0,0 +1,7 @@
1
+ import { AddressNamespace } from "./wasm/wasm_utxo";
2
+ export function toOutputScriptWithCoin(address, coin) {
3
+ return AddressNamespace.to_output_script_with_coin(address, coin);
4
+ }
5
+ export function fromOutputScriptWithCoin(script, coin, format) {
6
+ return AddressNamespace.from_output_script_with_coin(script, coin, format);
7
+ }
@@ -0,0 +1,88 @@
1
+ type Key = string;
2
+ type Identities = "a" | "s" | "c" | "t" | "d" | "v" | "j" | "n" | "l" | "u" | "r";
3
+ type PrefixWith<T, P extends string> = {
4
+ [K in keyof T & string as `${P}:${K}`]: T[K];
5
+ };
6
+ type PrefixIdUnion<T> = {
7
+ [P in Identities]: PrefixWith<T, P>;
8
+ }[Identities];
9
+ type Wrap<T> = T | PrefixIdUnion<T>;
10
+ type Miniscript = Wrap<{
11
+ pk: Key;
12
+ }> | Wrap<{
13
+ pkh: Key;
14
+ }> | Wrap<{
15
+ wpkh: Key;
16
+ }> | Wrap<{
17
+ multi: [number, ...Key[]];
18
+ }> | Wrap<{
19
+ sortedmulti: [number, ...Key[]];
20
+ }> | Wrap<{
21
+ multi_a: [number, ...Key[]];
22
+ }> | Wrap<{
23
+ sortedmulti_a: [number, ...Key[]];
24
+ }> | Wrap<{
25
+ tr: Key | [Key, Miniscript];
26
+ }> | Wrap<{
27
+ sh: Miniscript;
28
+ }> | Wrap<{
29
+ wsh: Miniscript;
30
+ }> | Wrap<{
31
+ and_v: [Miniscript, Miniscript];
32
+ }> | Wrap<{
33
+ and_b: [Miniscript, Miniscript];
34
+ }> | Wrap<{
35
+ andor: [Miniscript, Miniscript, Miniscript];
36
+ }> | Wrap<{
37
+ or_b: [Miniscript, Miniscript];
38
+ }> | Wrap<{
39
+ or_c: [Miniscript, Miniscript];
40
+ }> | Wrap<{
41
+ or_d: [Miniscript, Miniscript];
42
+ }> | Wrap<{
43
+ or_i: [Miniscript, Miniscript];
44
+ }> | Wrap<{
45
+ thresh: [number, ...Miniscript[]];
46
+ }> | Wrap<{
47
+ sha256: string;
48
+ }> | Wrap<{
49
+ ripemd160: string;
50
+ }> | Wrap<{
51
+ hash256: string;
52
+ }> | Wrap<{
53
+ hash160: string;
54
+ }> | Wrap<{
55
+ older: number;
56
+ }> | Wrap<{
57
+ after: number;
58
+ }>;
59
+ type TapTree = [TapTree, TapTree] | Miniscript;
60
+ type Descriptor = {
61
+ sh: Miniscript | {
62
+ wsh: Miniscript;
63
+ };
64
+ } | {
65
+ wsh: Miniscript;
66
+ } | {
67
+ pk: Key;
68
+ } | {
69
+ pkh: Key;
70
+ } | {
71
+ wpkh: Key;
72
+ } | {
73
+ combo: Key;
74
+ } | {
75
+ tr: [Key, TapTree];
76
+ } | {
77
+ addr: string;
78
+ } | {
79
+ raw: string;
80
+ } | {
81
+ rawtr: string;
82
+ };
83
+ export type TapTreeNode = TapTree;
84
+ export type MiniscriptNode = Miniscript;
85
+ export type DescriptorNode = Descriptor;
86
+ /** Format a Miniscript or Descriptor node as a descriptor string (without checksum) */
87
+ export declare function formatNode(n: MiniscriptNode | DescriptorNode): string;
88
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Format a TapTree as a string
3
+ * If the argument is an array, descend recursively with formatTr and wrap result in curly braces
4
+ * Otherwise, format the node with formatN
5
+ */
6
+ function formatTr(tree) {
7
+ return Array.isArray(tree) ? `{` + tree.map(formatTr).join(",") + `}` : formatN(tree);
8
+ }
9
+ function formatN(n) {
10
+ if (typeof n === "string") {
11
+ return n;
12
+ }
13
+ if (typeof n === "number") {
14
+ return String(n);
15
+ }
16
+ if (Array.isArray(n)) {
17
+ return n.map(formatN).join(",");
18
+ }
19
+ if (n && typeof n === "object") {
20
+ const entries = Object.entries(n);
21
+ if (entries.length !== 1) {
22
+ throw new Error(`Invalid node: ${n}`);
23
+ }
24
+ const [name, value] = entries[0];
25
+ if (name === "tr" && Array.isArray(value)) {
26
+ const [key, tree] = value;
27
+ return formatN({ tr: formatN([key, formatTr(tree)]) });
28
+ }
29
+ return `${name}(${formatN(value)})`;
30
+ }
31
+ throw new Error(`Invalid node: ${n}`);
32
+ }
33
+ /** Format a Miniscript or Descriptor node as a descriptor string (without checksum) */
34
+ export function formatNode(n) {
35
+ return formatN(n);
36
+ }
@@ -0,0 +1,4 @@
1
+ import { DescriptorNode, MiniscriptNode } from "./formatNode";
2
+ import { Descriptor, Miniscript } from "../index";
3
+ export declare function fromDescriptor(d: Descriptor): DescriptorNode;
4
+ export declare function fromMiniscript(m: Miniscript): MiniscriptNode;
@@ -0,0 +1,120 @@
1
+ function getSingleEntry(v) {
2
+ if (typeof v === "object" && v) {
3
+ const entries = Object.entries(v);
4
+ if (entries.length === 1) {
5
+ return entries[0];
6
+ }
7
+ }
8
+ throw new Error("Expected single entry object");
9
+ }
10
+ function node(type, value) {
11
+ return { [type]: fromUnknown(value) };
12
+ }
13
+ function wrap(type, value) {
14
+ const n = fromWasmNode(value);
15
+ const [name, inner] = getSingleEntry(n);
16
+ return { [`${type}:${name}`]: inner };
17
+ }
18
+ function fromUnknown(v) {
19
+ if (typeof v === "number" || typeof v === "string") {
20
+ return v;
21
+ }
22
+ if (Array.isArray(v)) {
23
+ return v.map(fromUnknown);
24
+ }
25
+ if (typeof v === "object" && v) {
26
+ const [type, value] = getSingleEntry(v);
27
+ switch (type) {
28
+ case "Bare":
29
+ case "Single":
30
+ case "Ms":
31
+ case "XPub":
32
+ case "relLockTime":
33
+ case "absLockTime":
34
+ return fromUnknown(value);
35
+ case "Sh":
36
+ case "Wsh":
37
+ case "Tr":
38
+ case "Pk":
39
+ case "Pkh":
40
+ case "PkH":
41
+ case "Wpkh":
42
+ case "Combo":
43
+ case "SortedMulti":
44
+ case "Addr":
45
+ case "Raw":
46
+ case "RawTr":
47
+ case "After":
48
+ case "Older":
49
+ case "Sha256":
50
+ case "Hash256":
51
+ case "Ripemd160":
52
+ case "Hash160":
53
+ return node(type.toLocaleLowerCase(), value);
54
+ case "PkK":
55
+ return node("pk", value);
56
+ case "RawPkH":
57
+ return node("raw_pkh", value);
58
+ // Wrappers
59
+ case "Alt":
60
+ return wrap("a", value);
61
+ case "Swap":
62
+ return wrap("s", value);
63
+ case "Check":
64
+ return fromUnknown(value);
65
+ case "DupIf":
66
+ return wrap("d", value);
67
+ case "Verify":
68
+ return wrap("v", value);
69
+ case "ZeroNotEqual":
70
+ return wrap("n", value);
71
+ case "Drop":
72
+ return wrap("r", value);
73
+ // Conjunctions
74
+ case "AndV":
75
+ return node("and_v", value);
76
+ case "AndB":
77
+ return node("and_b", value);
78
+ case "AndOr":
79
+ if (!Array.isArray(value)) {
80
+ throw new Error(`Invalid AndOr node: ${JSON.stringify(value)}`);
81
+ }
82
+ const [cond, success, failure] = value;
83
+ if (failure === false) {
84
+ return node("and_n", [cond, success]);
85
+ }
86
+ return node("andor", [cond, success, failure]);
87
+ // Disjunctions
88
+ case "OrB":
89
+ return node("or_b", value);
90
+ case "OrD":
91
+ return node("or_d", value);
92
+ case "OrC":
93
+ return node("or_c", value);
94
+ case "OrI":
95
+ return node("or_i", value);
96
+ // Thresholds
97
+ case "Thresh":
98
+ return node("thresh", value);
99
+ case "Multi":
100
+ return node("multi", value);
101
+ case "MultiA":
102
+ return node("multi_a", value);
103
+ case "Tree":
104
+ if (!Array.isArray(value) || value.length !== 2) {
105
+ throw new Error(`Invalid Tree node: ${JSON.stringify(value)}`);
106
+ }
107
+ return [fromUnknown(value[0]), fromUnknown(value[1])];
108
+ }
109
+ }
110
+ throw new Error(`Unknown node ${JSON.stringify(v)}`);
111
+ }
112
+ function fromWasmNode(v) {
113
+ return fromUnknown(v);
114
+ }
115
+ export function fromDescriptor(d) {
116
+ return fromWasmNode(d.node());
117
+ }
118
+ export function fromMiniscript(m) {
119
+ return fromWasmNode(m.node());
120
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./formatNode";
2
+ export * from "./fromWasmNode";
@@ -0,0 +1,2 @@
1
+ export * from "./formatNode";
2
+ export * from "./fromWasmNode";
@@ -0,0 +1 @@
1
+ export type CoinName = "btc" | "tbtc" | "tbtc4" | "tbtcsig" | "tbtcbgsig" | "bch" | "tbch" | "bcha" | "tbcha" | "btg" | "tbtg" | "bsv" | "tbsv" | "dash" | "tdash" | "doge" | "tdoge" | "ltc" | "tltc" | "zec" | "tzec";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,86 @@
1
+ import type { UtxolibName, UtxolibNetwork, UtxolibRootWalletKeys } from "./utxolibCompat";
2
+ import type { CoinName } from "./coinName";
3
+ import { Triple } from "./triple";
4
+ import { AddressFormat } from "./address";
5
+ export type NetworkName = UtxolibName | CoinName;
6
+ export type WalletKeys =
7
+ /** Just an xpub triple, will assume default derivation prefixes */
8
+ Triple<string>
9
+ /** Compatible with utxolib RootWalletKeys */
10
+ | UtxolibRootWalletKeys;
11
+ /**
12
+ * Create the output script for a given wallet keys and chain and index
13
+ */
14
+ export declare function outputScript(keys: WalletKeys, chain: number, index: number, network: UtxolibNetwork): Uint8Array;
15
+ /**
16
+ * Create the address for a given wallet keys and chain and index and network.
17
+ * Wrapper for outputScript that also encodes the script to an address.
18
+ * @param keys - The wallet keys to use.
19
+ * @param chain - The chain to use.
20
+ * @param index - The index to use.
21
+ * @param network - The network to use.
22
+ * @param addressFormat - The address format to use.
23
+ * Only relevant for Bitcoin Cash and eCash networks, where:
24
+ * - "default" means base58check,
25
+ * - "cashaddr" means cashaddr.
26
+ */
27
+ export declare function address(keys: WalletKeys, chain: number, index: number, network: UtxolibNetwork, addressFormat?: AddressFormat): string;
28
+ type ReplayProtection = {
29
+ outputScripts: Uint8Array[];
30
+ } | {
31
+ addresses: string[];
32
+ };
33
+ export type ScriptId = {
34
+ chain: number;
35
+ index: number;
36
+ };
37
+ export type ParsedInput = {
38
+ address: string;
39
+ script: Uint8Array;
40
+ value: bigint;
41
+ scriptId: ScriptId | null;
42
+ };
43
+ export type ParsedOutput = {
44
+ address: string | null;
45
+ script: Uint8Array;
46
+ value: bigint;
47
+ scriptId: ScriptId | null;
48
+ };
49
+ export type ParsedTransaction = {
50
+ inputs: ParsedInput[];
51
+ outputs: ParsedOutput[];
52
+ spendAmount: bigint;
53
+ minerFee: bigint;
54
+ virtualSize: number;
55
+ };
56
+ export declare class BitGoPsbt {
57
+ private wasm;
58
+ private constructor();
59
+ /**
60
+ * Deserialize a PSBT from bytes
61
+ * @param bytes - The PSBT bytes
62
+ * @param network - The network to use for deserialization (either utxolib name like "bitcoin" or coin name like "btc")
63
+ * @returns A BitGoPsbt instance
64
+ */
65
+ static fromBytes(bytes: Uint8Array, network: NetworkName): BitGoPsbt;
66
+ /**
67
+ * Parse transaction with wallet keys to identify wallet inputs/outputs
68
+ * @param walletKeys - The wallet keys to use for identification
69
+ * @param replayProtection - Scripts that are allowed as inputs without wallet validation
70
+ * @returns Parsed transaction information
71
+ */
72
+ parseTransactionWithWalletKeys(walletKeys: WalletKeys, replayProtection: ReplayProtection): ParsedTransaction;
73
+ /**
74
+ * Parse outputs with wallet keys to identify which outputs belong to a wallet
75
+ * with the given wallet keys.
76
+ *
77
+ * This is useful in cases where we want to identify outputs that belong to a different
78
+ * wallet than the inputs.
79
+ *
80
+ * @param walletKeys - The wallet keys to use for identification
81
+ * @returns Array of parsed outputs
82
+ * @note This method does NOT validate wallet inputs. It only parses outputs.
83
+ */
84
+ parseOutputsWithWalletKeys(walletKeys: WalletKeys): ParsedOutput[];
85
+ }
86
+ export {};
@@ -0,0 +1,61 @@
1
+ import { FixedScriptWalletNamespace } from "./wasm/wasm_utxo";
2
+ /**
3
+ * Create the output script for a given wallet keys and chain and index
4
+ */
5
+ export function outputScript(keys, chain, index, network) {
6
+ return FixedScriptWalletNamespace.output_script(keys, chain, index, network);
7
+ }
8
+ /**
9
+ * Create the address for a given wallet keys and chain and index and network.
10
+ * Wrapper for outputScript that also encodes the script to an address.
11
+ * @param keys - The wallet keys to use.
12
+ * @param chain - The chain to use.
13
+ * @param index - The index to use.
14
+ * @param network - The network to use.
15
+ * @param addressFormat - The address format to use.
16
+ * Only relevant for Bitcoin Cash and eCash networks, where:
17
+ * - "default" means base58check,
18
+ * - "cashaddr" means cashaddr.
19
+ */
20
+ export function address(keys, chain, index, network, addressFormat) {
21
+ return FixedScriptWalletNamespace.address(keys, chain, index, network, addressFormat);
22
+ }
23
+ import { BitGoPsbt as WasmBitGoPsbt } from "./wasm/wasm_utxo";
24
+ export class BitGoPsbt {
25
+ constructor(wasm) {
26
+ this.wasm = wasm;
27
+ }
28
+ /**
29
+ * Deserialize a PSBT from bytes
30
+ * @param bytes - The PSBT bytes
31
+ * @param network - The network to use for deserialization (either utxolib name like "bitcoin" or coin name like "btc")
32
+ * @returns A BitGoPsbt instance
33
+ */
34
+ static fromBytes(bytes, network) {
35
+ const wasm = WasmBitGoPsbt.from_bytes(bytes, network);
36
+ return new BitGoPsbt(wasm);
37
+ }
38
+ /**
39
+ * Parse transaction with wallet keys to identify wallet inputs/outputs
40
+ * @param walletKeys - The wallet keys to use for identification
41
+ * @param replayProtection - Scripts that are allowed as inputs without wallet validation
42
+ * @returns Parsed transaction information
43
+ */
44
+ parseTransactionWithWalletKeys(walletKeys, replayProtection) {
45
+ return this.wasm.parse_transaction_with_wallet_keys(walletKeys, replayProtection);
46
+ }
47
+ /**
48
+ * Parse outputs with wallet keys to identify which outputs belong to a wallet
49
+ * with the given wallet keys.
50
+ *
51
+ * This is useful in cases where we want to identify outputs that belong to a different
52
+ * wallet than the inputs.
53
+ *
54
+ * @param walletKeys - The wallet keys to use for identification
55
+ * @returns Array of parsed outputs
56
+ * @note This method does NOT validate wallet inputs. It only parses outputs.
57
+ */
58
+ parseOutputsWithWalletKeys(walletKeys) {
59
+ return this.wasm.parse_outputs_with_wallet_keys(walletKeys);
60
+ }
61
+ }
@@ -0,0 +1,37 @@
1
+ export * as address from "./address";
2
+ export * as ast from "./ast";
3
+ export * as utxolibCompat from "./utxolibCompat";
4
+ export * as fixedScriptWallet from "./fixedScriptWallet";
5
+ export type { CoinName } from "./coinName";
6
+ export type { Triple } from "./triple";
7
+ export type { AddressFormat } from "./address";
8
+ export type DescriptorPkType = "derivable" | "definite" | "string";
9
+ export type ScriptContext = "tap" | "segwitv0" | "legacy";
10
+ export type SignPsbtResult = {
11
+ [inputIndex: number]: [pubkey: string][];
12
+ };
13
+ declare module "./wasm/wasm_utxo" {
14
+ interface WrapDescriptor {
15
+ /** These are not the same types of nodes as in the ast module */
16
+ node(): unknown;
17
+ }
18
+ namespace WrapDescriptor {
19
+ function fromString(descriptor: string, pkType: DescriptorPkType): WrapDescriptor;
20
+ function fromStringDetectType(descriptor: string): WrapDescriptor;
21
+ }
22
+ interface WrapMiniscript {
23
+ /** These are not the same types of nodes as in the ast module */
24
+ node(): unknown;
25
+ }
26
+ namespace WrapMiniscript {
27
+ function fromString(miniscript: string, ctx: ScriptContext): WrapMiniscript;
28
+ function fromBitcoinScript(script: Uint8Array, ctx: ScriptContext): WrapMiniscript;
29
+ }
30
+ interface WrapPsbt {
31
+ signWithXprv(this: WrapPsbt, xprv: string): SignPsbtResult;
32
+ signWithPrv(this: WrapPsbt, prv: Uint8Array): SignPsbtResult;
33
+ }
34
+ }
35
+ export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo";
36
+ export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo";
37
+ export { WrapPsbt as Psbt } from "./wasm/wasm_utxo";
@@ -0,0 +1,11 @@
1
+ import * as wasm from "./wasm/wasm_utxo";
2
+ // we need to access the wasm module here, otherwise webpack gets all weird
3
+ // and forgets to include it in the bundle
4
+ void wasm;
5
+ export * as address from "./address";
6
+ export * as ast from "./ast";
7
+ export * as utxolibCompat from "./utxolibCompat";
8
+ export * as fixedScriptWallet from "./fixedScriptWallet";
9
+ export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo";
10
+ export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo";
11
+ export { WrapPsbt as Psbt } from "./wasm/wasm_utxo";
@@ -0,0 +1 @@
1
+ export type Triple<T> = [T, T, T];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { AddressFormat } from "./address";
2
+ import { Triple } from "./triple";
3
+ export type UtxolibName = "bitcoin" | "testnet" | "bitcoinTestnet4" | "bitcoinPublicSignet" | "bitcoinBitGoSignet" | "bitcoincash" | "bitcoincashTestnet" | "ecash" | "ecashTest" | "bitcoingold" | "bitcoingoldTestnet" | "bitcoinsv" | "bitcoinsvTestnet" | "dash" | "dashTest" | "dogecoin" | "dogecoinTest" | "litecoin" | "litecoinTest" | "zcash" | "zcashTest";
4
+ export type BIP32Interface = {
5
+ network: {
6
+ bip32: {
7
+ public: number;
8
+ };
9
+ };
10
+ depth: number;
11
+ parentFingerprint: number;
12
+ index: number;
13
+ chainCode: Uint8Array;
14
+ publicKey: Uint8Array;
15
+ toBase58?(): string;
16
+ };
17
+ export type UtxolibRootWalletKeys = {
18
+ triple: Triple<BIP32Interface>;
19
+ derivationPrefixes: Triple<string>;
20
+ };
21
+ export type UtxolibNetwork = {
22
+ pubKeyHash: number;
23
+ scriptHash: number;
24
+ cashAddr?: {
25
+ prefix: string;
26
+ pubKeyHash: number;
27
+ scriptHash: number;
28
+ };
29
+ bech32?: string;
30
+ };
31
+ export declare function fromOutputScript(script: Uint8Array, network: UtxolibNetwork, format?: AddressFormat): string;
32
+ export declare function toOutputScript(address: string, network: UtxolibNetwork, format?: AddressFormat): Uint8Array;
@@ -0,0 +1,7 @@
1
+ import { UtxolibCompatNamespace } from "./wasm/wasm_utxo";
2
+ export function fromOutputScript(script, network, format) {
3
+ return UtxolibCompatNamespace.from_output_script(script, network, format);
4
+ }
5
+ export function toOutputScript(address, network, format) {
6
+ return UtxolibCompatNamespace.to_output_script(address, network, format);
7
+ }
@@ -0,0 +1,94 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export class AddressNamespace {
4
+ private constructor();
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ static to_output_script_with_coin(address: string, coin: string): Uint8Array;
8
+ static from_output_script_with_coin(script: Uint8Array, coin: string, format?: string | null): string;
9
+ }
10
+ export class BitGoPsbt {
11
+ private constructor();
12
+ free(): void;
13
+ [Symbol.dispose](): void;
14
+ /**
15
+ * Deserialize a PSBT from bytes with network-specific logic
16
+ */
17
+ static from_bytes(bytes: Uint8Array, network: string): BitGoPsbt;
18
+ /**
19
+ * Parse outputs with wallet keys to identify which outputs belong to a wallet
20
+ *
21
+ * Note: This method does NOT validate wallet inputs. It only parses outputs.
22
+ */
23
+ parse_outputs_with_wallet_keys(wallet_keys: any): any;
24
+ /**
25
+ * Parse transaction with wallet keys to identify wallet inputs/outputs
26
+ */
27
+ parse_transaction_with_wallet_keys(wallet_keys: any, replay_protection: any): any;
28
+ }
29
+ export class FixedScriptWalletNamespace {
30
+ private constructor();
31
+ free(): void;
32
+ [Symbol.dispose](): void;
33
+ static output_script(keys: any, chain: number, index: number, network: any): Uint8Array;
34
+ static address(keys: any, chain: number, index: number, network: any, address_format?: string | null): string;
35
+ }
36
+ export class UtxolibCompatNamespace {
37
+ private constructor();
38
+ free(): void;
39
+ [Symbol.dispose](): void;
40
+ /**
41
+ * Convert address string to output script
42
+ *
43
+ * # Arguments
44
+ * * `address` - The address string
45
+ * * `network` - The UtxolibNetwork object from JavaScript
46
+ * * `format` - Optional address format (currently unused for decoding as all formats are accepted)
47
+ */
48
+ static to_output_script(address: string, network: any, format?: string | null): Uint8Array;
49
+ /**
50
+ * Convert output script to address string
51
+ *
52
+ * # Arguments
53
+ * * `script` - The output script as a byte array
54
+ * * `network` - The UtxolibNetwork object from JavaScript
55
+ * * `format` - Optional address format: "default" or "cashaddr" (only applicable for Bitcoin Cash and eCash)
56
+ */
57
+ static from_output_script(script: Uint8Array, network: any, format?: string | null): string;
58
+ }
59
+ export class WrapDescriptor {
60
+ private constructor();
61
+ free(): void;
62
+ [Symbol.dispose](): void;
63
+ hasWildcard(): boolean;
64
+ scriptPubkey(): Uint8Array;
65
+ toAsmString(): string;
66
+ atDerivationIndex(index: number): WrapDescriptor;
67
+ maxWeightToSatisfy(): number;
68
+ node(): any;
69
+ encode(): Uint8Array;
70
+ descType(): any;
71
+ toString(): string;
72
+ }
73
+ export class WrapMiniscript {
74
+ private constructor();
75
+ free(): void;
76
+ [Symbol.dispose](): void;
77
+ toAsmString(): string;
78
+ node(): any;
79
+ encode(): Uint8Array;
80
+ toString(): string;
81
+ }
82
+ export class WrapPsbt {
83
+ private constructor();
84
+ free(): void;
85
+ [Symbol.dispose](): void;
86
+ static deserialize(psbt: Uint8Array): WrapPsbt;
87
+ finalize(): void;
88
+ signWithPrv(prv: Uint8Array): any;
89
+ signWithXprv(xprv: string): any;
90
+ updateInputWithDescriptor(input_index: number, descriptor: WrapDescriptor): void;
91
+ updateOutputWithDescriptor(output_index: number, descriptor: WrapDescriptor): void;
92
+ clone(): WrapPsbt;
93
+ serialize(): Uint8Array;
94
+ }
@@ -0,0 +1,4 @@
1
+ import * as wasm from "./wasm_utxo_bg.wasm";
2
+ export * from "./wasm_utxo_bg.js";
3
+ import { __wbg_set_wasm } from "./wasm_utxo_bg.js";
4
+ __wbg_set_wasm(wasm);