@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.
- package/README.md +33 -0
- package/dist/browser/js/address.d.ts +8 -0
- package/dist/browser/js/address.js +7 -0
- package/dist/browser/js/ast/formatNode.d.ts +88 -0
- package/dist/browser/js/ast/formatNode.js +36 -0
- package/dist/browser/js/ast/fromWasmNode.d.ts +4 -0
- package/dist/browser/js/ast/fromWasmNode.js +120 -0
- package/dist/browser/js/ast/index.d.ts +2 -0
- package/dist/browser/js/ast/index.js +2 -0
- package/dist/browser/js/coinName.d.ts +1 -0
- package/dist/browser/js/coinName.js +1 -0
- package/dist/browser/js/fixedScriptWallet.d.ts +86 -0
- package/dist/browser/js/fixedScriptWallet.js +61 -0
- package/dist/browser/js/index.d.ts +37 -0
- package/dist/browser/js/index.js +11 -0
- package/dist/browser/js/triple.d.ts +1 -0
- package/dist/browser/js/triple.js +1 -0
- package/dist/browser/js/utxolibCompat.d.ts +32 -0
- package/dist/browser/js/utxolibCompat.js +7 -0
- package/dist/browser/js/wasm/wasm_utxo.d.ts +94 -0
- package/dist/browser/js/wasm/wasm_utxo.js +4 -0
- package/dist/browser/js/wasm/wasm_utxo_bg.js +1274 -0
- package/dist/browser/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/browser/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -0
- package/dist/node/js/address.d.ts +8 -0
- package/dist/node/js/address.js +11 -0
- package/dist/node/js/ast/formatNode.d.ts +88 -0
- package/dist/node/js/ast/formatNode.js +39 -0
- package/dist/node/js/ast/fromWasmNode.d.ts +4 -0
- package/dist/node/js/ast/fromWasmNode.js +124 -0
- package/dist/node/js/ast/index.d.ts +2 -0
- package/dist/node/js/ast/index.js +18 -0
- package/dist/node/js/coinName.d.ts +1 -0
- package/dist/node/js/coinName.js +2 -0
- package/dist/node/js/fixedScriptWallet.d.ts +86 -0
- package/dist/node/js/fixedScriptWallet.js +68 -0
- package/dist/node/js/index.d.ts +37 -0
- package/dist/node/js/index.js +50 -0
- package/dist/node/js/triple.d.ts +1 -0
- package/dist/node/js/triple.js +2 -0
- package/dist/node/js/utxolibCompat.d.ts +32 -0
- package/dist/node/js/utxolibCompat.js +11 -0
- package/dist/node/js/wasm/wasm_utxo.d.ts +94 -0
- package/dist/node/js/wasm/wasm_utxo.js +1283 -0
- package/dist/node/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/node/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -0
- package/package.json +52 -5
|
Binary file
|
|
@@ -0,0 +1,53 @@
|
|
|
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_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
7
|
+
export const __wbg_wrapminiscript_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 utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
11
|
+
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
12
|
+
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
13
|
+
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
14
|
+
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
15
|
+
export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
16
|
+
export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
|
|
17
|
+
export const wrapdescriptor_hasWildcard: (a: number) => number;
|
|
18
|
+
export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
|
|
19
|
+
export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
20
|
+
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
21
|
+
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
22
|
+
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
23
|
+
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
24
|
+
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
25
|
+
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
26
|
+
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
27
|
+
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
28
|
+
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
29
|
+
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
30
|
+
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
31
|
+
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
32
|
+
export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
33
|
+
export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number) => void;
|
|
34
|
+
export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number) => void;
|
|
35
|
+
export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
36
|
+
export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
37
|
+
export const wrappsbt_clone: (a: number) => number;
|
|
38
|
+
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
39
|
+
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
40
|
+
export const wrappsbt_serialize: (a: number, b: number) => void;
|
|
41
|
+
export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
|
|
42
|
+
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
43
|
+
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
44
|
+
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
45
|
+
export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
|
|
46
|
+
export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
|
|
47
|
+
export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
|
|
48
|
+
export const rustsecp256k1_v0_10_0_default_illegal_callback_fn: (a: number, b: number) => void;
|
|
49
|
+
export const __wbindgen_export_0: (a: number) => void;
|
|
50
|
+
export const __wbindgen_export_1: (a: number, b: number) => number;
|
|
51
|
+
export const __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
|
|
52
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
53
|
+
export const __wbindgen_export_3: (a: number, b: number, c: number) => void;
|
|
@@ -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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toOutputScriptWithCoin = toOutputScriptWithCoin;
|
|
4
|
+
exports.fromOutputScriptWithCoin = fromOutputScriptWithCoin;
|
|
5
|
+
const wasm_utxo_1 = require("./wasm/wasm_utxo");
|
|
6
|
+
function toOutputScriptWithCoin(address, coin) {
|
|
7
|
+
return wasm_utxo_1.AddressNamespace.to_output_script_with_coin(address, coin);
|
|
8
|
+
}
|
|
9
|
+
function fromOutputScriptWithCoin(script, coin, format) {
|
|
10
|
+
return wasm_utxo_1.AddressNamespace.from_output_script_with_coin(script, coin, format);
|
|
11
|
+
}
|
|
@@ -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,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,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 @@
|
|
|
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,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,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitGoPsbt = void 0;
|
|
4
|
+
exports.outputScript = outputScript;
|
|
5
|
+
exports.address = address;
|
|
6
|
+
const wasm_utxo_1 = require("./wasm/wasm_utxo");
|
|
7
|
+
/**
|
|
8
|
+
* Create the output script for a given wallet keys and chain and index
|
|
9
|
+
*/
|
|
10
|
+
function outputScript(keys, chain, index, network) {
|
|
11
|
+
return wasm_utxo_1.FixedScriptWalletNamespace.output_script(keys, chain, index, network);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create the address for a given wallet keys and chain and index and network.
|
|
15
|
+
* Wrapper for outputScript that also encodes the script to an address.
|
|
16
|
+
* @param keys - The wallet keys to use.
|
|
17
|
+
* @param chain - The chain to use.
|
|
18
|
+
* @param index - The index to use.
|
|
19
|
+
* @param network - The network to use.
|
|
20
|
+
* @param addressFormat - The address format to use.
|
|
21
|
+
* Only relevant for Bitcoin Cash and eCash networks, where:
|
|
22
|
+
* - "default" means base58check,
|
|
23
|
+
* - "cashaddr" means cashaddr.
|
|
24
|
+
*/
|
|
25
|
+
function address(keys, chain, index, network, addressFormat) {
|
|
26
|
+
return wasm_utxo_1.FixedScriptWalletNamespace.address(keys, chain, index, network, addressFormat);
|
|
27
|
+
}
|
|
28
|
+
const wasm_utxo_2 = require("./wasm/wasm_utxo");
|
|
29
|
+
class BitGoPsbt {
|
|
30
|
+
wasm;
|
|
31
|
+
constructor(wasm) {
|
|
32
|
+
this.wasm = wasm;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Deserialize a PSBT from bytes
|
|
36
|
+
* @param bytes - The PSBT bytes
|
|
37
|
+
* @param network - The network to use for deserialization (either utxolib name like "bitcoin" or coin name like "btc")
|
|
38
|
+
* @returns A BitGoPsbt instance
|
|
39
|
+
*/
|
|
40
|
+
static fromBytes(bytes, network) {
|
|
41
|
+
const wasm = wasm_utxo_2.BitGoPsbt.from_bytes(bytes, network);
|
|
42
|
+
return new BitGoPsbt(wasm);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
46
|
+
* @param walletKeys - The wallet keys to use for identification
|
|
47
|
+
* @param replayProtection - Scripts that are allowed as inputs without wallet validation
|
|
48
|
+
* @returns Parsed transaction information
|
|
49
|
+
*/
|
|
50
|
+
parseTransactionWithWalletKeys(walletKeys, replayProtection) {
|
|
51
|
+
return this.wasm.parse_transaction_with_wallet_keys(walletKeys, replayProtection);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
55
|
+
* with the given wallet keys.
|
|
56
|
+
*
|
|
57
|
+
* This is useful in cases where we want to identify outputs that belong to a different
|
|
58
|
+
* wallet than the inputs.
|
|
59
|
+
*
|
|
60
|
+
* @param walletKeys - The wallet keys to use for identification
|
|
61
|
+
* @returns Array of parsed outputs
|
|
62
|
+
* @note This method does NOT validate wallet inputs. It only parses outputs.
|
|
63
|
+
*/
|
|
64
|
+
parseOutputsWithWalletKeys(walletKeys) {
|
|
65
|
+
return this.wasm.parse_outputs_with_wallet_keys(walletKeys);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.BitGoPsbt = BitGoPsbt;
|
|
@@ -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 @@
|
|
|
1
|
+
export type Triple<T> = [T, T, T];
|
|
@@ -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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromOutputScript = fromOutputScript;
|
|
4
|
+
exports.toOutputScript = toOutputScript;
|
|
5
|
+
const wasm_utxo_1 = require("./wasm/wasm_utxo");
|
|
6
|
+
function fromOutputScript(script, network, format) {
|
|
7
|
+
return wasm_utxo_1.UtxolibCompatNamespace.from_output_script(script, network, format);
|
|
8
|
+
}
|
|
9
|
+
function toOutputScript(address, network, format) {
|
|
10
|
+
return wasm_utxo_1.UtxolibCompatNamespace.to_output_script(address, network, format);
|
|
11
|
+
}
|