@bitgo/wasm-utxo 0.0.1 → 0.0.2

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.
@@ -0,0 +1,49 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_addressnamespace_free: (a: number, b: number) => void;
5
+ export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
6
+ export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
7
+ export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
8
+ export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
9
+ export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
10
+ export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
11
+ export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
12
+ export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
13
+ export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
14
+ export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
15
+ export const wrapdescriptor_descType: (a: number, b: number) => void;
16
+ export const wrapdescriptor_encode: (a: number, b: number) => void;
17
+ export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
18
+ export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
19
+ export const wrapdescriptor_hasWildcard: (a: number) => number;
20
+ export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
21
+ export const wrapdescriptor_node: (a: number, b: number) => void;
22
+ export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
23
+ export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
24
+ export const wrapdescriptor_toString: (a: number, b: number) => void;
25
+ export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
26
+ export const __wbg_wrappsbt_free: (a: number, b: number) => void;
27
+ export const wrapminiscript_encode: (a: number, b: number) => void;
28
+ export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
29
+ export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
30
+ export const wrapminiscript_node: (a: number, b: number) => void;
31
+ export const wrapminiscript_toAsmString: (a: number, b: number) => void;
32
+ export const wrapminiscript_toString: (a: number, b: number) => void;
33
+ export const wrappsbt_clone: (a: number) => number;
34
+ export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
35
+ export const wrappsbt_finalize: (a: number, b: number) => void;
36
+ export const wrappsbt_serialize: (a: number, b: number) => void;
37
+ export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
38
+ export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
39
+ export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
40
+ export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
41
+ export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
42
+ export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
43
+ export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
44
+ export const rustsecp256k1_v0_10_0_default_illegal_callback_fn: (a: number, b: number) => void;
45
+ export const __wbindgen_export_0: (a: number) => void;
46
+ export const __wbindgen_export_1: (a: number, b: number) => number;
47
+ export const __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
48
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
49
+ export const __wbindgen_export_3: (a: number, b: number, c: number) => void;
@@ -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,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatNode = formatNode;
4
+ /**
5
+ * Format a TapTree as a string
6
+ * If the argument is an array, descend recursively with formatTr and wrap result in curly braces
7
+ * Otherwise, format the node with formatN
8
+ */
9
+ function formatTr(tree) {
10
+ return Array.isArray(tree) ? `{` + tree.map(formatTr).join(",") + `}` : formatN(tree);
11
+ }
12
+ function formatN(n) {
13
+ if (typeof n === "string") {
14
+ return n;
15
+ }
16
+ if (typeof n === "number") {
17
+ return String(n);
18
+ }
19
+ if (Array.isArray(n)) {
20
+ return n.map(formatN).join(",");
21
+ }
22
+ if (n && typeof n === "object") {
23
+ const entries = Object.entries(n);
24
+ if (entries.length !== 1) {
25
+ throw new Error(`Invalid node: ${n}`);
26
+ }
27
+ const [name, value] = entries[0];
28
+ if (name === "tr" && Array.isArray(value)) {
29
+ const [key, tree] = value;
30
+ return formatN({ tr: formatN([key, formatTr(tree)]) });
31
+ }
32
+ return `${name}(${formatN(value)})`;
33
+ }
34
+ throw new Error(`Invalid node: ${n}`);
35
+ }
36
+ /** Format a Miniscript or Descriptor node as a descriptor string (without checksum) */
37
+ function formatNode(n) {
38
+ return formatN(n);
39
+ }
@@ -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,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromDescriptor = fromDescriptor;
4
+ exports.fromMiniscript = fromMiniscript;
5
+ function getSingleEntry(v) {
6
+ if (typeof v === "object" && v) {
7
+ const entries = Object.entries(v);
8
+ if (entries.length === 1) {
9
+ return entries[0];
10
+ }
11
+ }
12
+ throw new Error("Expected single entry object");
13
+ }
14
+ function node(type, value) {
15
+ return { [type]: fromUnknown(value) };
16
+ }
17
+ function wrap(type, value) {
18
+ const n = fromWasmNode(value);
19
+ const [name, inner] = getSingleEntry(n);
20
+ return { [`${type}:${name}`]: inner };
21
+ }
22
+ function fromUnknown(v) {
23
+ if (typeof v === "number" || typeof v === "string") {
24
+ return v;
25
+ }
26
+ if (Array.isArray(v)) {
27
+ return v.map(fromUnknown);
28
+ }
29
+ if (typeof v === "object" && v) {
30
+ const [type, value] = getSingleEntry(v);
31
+ switch (type) {
32
+ case "Bare":
33
+ case "Single":
34
+ case "Ms":
35
+ case "XPub":
36
+ case "relLockTime":
37
+ case "absLockTime":
38
+ return fromUnknown(value);
39
+ case "Sh":
40
+ case "Wsh":
41
+ case "Tr":
42
+ case "Pk":
43
+ case "Pkh":
44
+ case "PkH":
45
+ case "Wpkh":
46
+ case "Combo":
47
+ case "SortedMulti":
48
+ case "Addr":
49
+ case "Raw":
50
+ case "RawTr":
51
+ case "After":
52
+ case "Older":
53
+ case "Sha256":
54
+ case "Hash256":
55
+ case "Ripemd160":
56
+ case "Hash160":
57
+ return node(type.toLocaleLowerCase(), value);
58
+ case "PkK":
59
+ return node("pk", value);
60
+ case "RawPkH":
61
+ return node("raw_pkh", value);
62
+ // Wrappers
63
+ case "Alt":
64
+ return wrap("a", value);
65
+ case "Swap":
66
+ return wrap("s", value);
67
+ case "Check":
68
+ return fromUnknown(value);
69
+ case "DupIf":
70
+ return wrap("d", value);
71
+ case "Verify":
72
+ return wrap("v", value);
73
+ case "ZeroNotEqual":
74
+ return wrap("n", value);
75
+ case "Drop":
76
+ return wrap("r", value);
77
+ // Conjunctions
78
+ case "AndV":
79
+ return node("and_v", value);
80
+ case "AndB":
81
+ return node("and_b", value);
82
+ case "AndOr":
83
+ if (!Array.isArray(value)) {
84
+ throw new Error(`Invalid AndOr node: ${JSON.stringify(value)}`);
85
+ }
86
+ const [cond, success, failure] = value;
87
+ if (failure === false) {
88
+ return node("and_n", [cond, success]);
89
+ }
90
+ return node("andor", [cond, success, failure]);
91
+ // Disjunctions
92
+ case "OrB":
93
+ return node("or_b", value);
94
+ case "OrD":
95
+ return node("or_d", value);
96
+ case "OrC":
97
+ return node("or_c", value);
98
+ case "OrI":
99
+ return node("or_i", value);
100
+ // Thresholds
101
+ case "Thresh":
102
+ return node("thresh", value);
103
+ case "Multi":
104
+ return node("multi", value);
105
+ case "MultiA":
106
+ return node("multi_a", value);
107
+ case "Tree":
108
+ if (!Array.isArray(value) || value.length !== 2) {
109
+ throw new Error(`Invalid Tree node: ${JSON.stringify(value)}`);
110
+ }
111
+ return [fromUnknown(value[0]), fromUnknown(value[1])];
112
+ }
113
+ }
114
+ throw new Error(`Unknown node ${JSON.stringify(v)}`);
115
+ }
116
+ function fromWasmNode(v) {
117
+ return fromUnknown(v);
118
+ }
119
+ function fromDescriptor(d) {
120
+ return fromWasmNode(d.node());
121
+ }
122
+ function fromMiniscript(m) {
123
+ return fromWasmNode(m.node());
124
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./formatNode";
2
+ export * from "./fromWasmNode";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./formatNode"), exports);
18
+ __exportStar(require("./fromWasmNode"), exports);
@@ -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,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Psbt = exports.Miniscript = exports.Descriptor = exports.fixedScriptWallet = exports.utxolibCompat = exports.ast = exports.address = void 0;
37
+ const wasm = __importStar(require("./wasm/wasm_utxo"));
38
+ // we need to access the wasm module here, otherwise webpack gets all weird
39
+ // and forgets to include it in the bundle
40
+ void wasm;
41
+ exports.address = __importStar(require("./address"));
42
+ exports.ast = __importStar(require("./ast"));
43
+ exports.utxolibCompat = __importStar(require("./utxolibCompat"));
44
+ exports.fixedScriptWallet = __importStar(require("./fixedScriptWallet"));
45
+ var wasm_utxo_1 = require("./wasm/wasm_utxo");
46
+ Object.defineProperty(exports, "Descriptor", { enumerable: true, get: function () { return wasm_utxo_1.WrapDescriptor; } });
47
+ var wasm_utxo_2 = require("./wasm/wasm_utxo");
48
+ Object.defineProperty(exports, "Miniscript", { enumerable: true, get: function () { return wasm_utxo_2.WrapMiniscript; } });
49
+ var wasm_utxo_3 = require("./wasm/wasm_utxo");
50
+ Object.defineProperty(exports, "Psbt", { enumerable: true, get: function () { return wasm_utxo_3.WrapPsbt; } });
@@ -0,0 +1,75 @@
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 FixedScriptWalletNamespace {
11
+ private constructor();
12
+ free(): void;
13
+ [Symbol.dispose](): void;
14
+ static output_script(keys: any, chain: number, index: number, network: any): Uint8Array;
15
+ static address(keys: any, chain: number, index: number, network: any, address_format?: string | null): string;
16
+ }
17
+ export class UtxolibCompatNamespace {
18
+ private constructor();
19
+ free(): void;
20
+ [Symbol.dispose](): void;
21
+ /**
22
+ * Convert address string to output script
23
+ *
24
+ * # Arguments
25
+ * * `address` - The address string
26
+ * * `network` - The UtxolibNetwork object from JavaScript
27
+ * * `format` - Optional address format (currently unused for decoding as all formats are accepted)
28
+ */
29
+ static to_output_script(address: string, network: any, format?: string | null): Uint8Array;
30
+ /**
31
+ * Convert output script to address string
32
+ *
33
+ * # Arguments
34
+ * * `script` - The output script as a byte array
35
+ * * `network` - The UtxolibNetwork object from JavaScript
36
+ * * `format` - Optional address format: "default" or "cashaddr" (only applicable for Bitcoin Cash and eCash)
37
+ */
38
+ static from_output_script(script: Uint8Array, network: any, format?: string | null): string;
39
+ }
40
+ export class WrapDescriptor {
41
+ private constructor();
42
+ free(): void;
43
+ [Symbol.dispose](): void;
44
+ hasWildcard(): boolean;
45
+ scriptPubkey(): Uint8Array;
46
+ toAsmString(): string;
47
+ atDerivationIndex(index: number): WrapDescriptor;
48
+ maxWeightToSatisfy(): number;
49
+ node(): any;
50
+ encode(): Uint8Array;
51
+ descType(): any;
52
+ toString(): string;
53
+ }
54
+ export class WrapMiniscript {
55
+ private constructor();
56
+ free(): void;
57
+ [Symbol.dispose](): void;
58
+ toAsmString(): string;
59
+ node(): any;
60
+ encode(): Uint8Array;
61
+ toString(): string;
62
+ }
63
+ export class WrapPsbt {
64
+ private constructor();
65
+ free(): void;
66
+ [Symbol.dispose](): void;
67
+ static deserialize(psbt: Uint8Array): WrapPsbt;
68
+ finalize(): void;
69
+ signWithPrv(prv: Uint8Array): any;
70
+ signWithXprv(xprv: string): any;
71
+ updateInputWithDescriptor(input_index: number, descriptor: WrapDescriptor): void;
72
+ updateOutputWithDescriptor(output_index: number, descriptor: WrapDescriptor): void;
73
+ clone(): WrapPsbt;
74
+ serialize(): Uint8Array;
75
+ }