@bitgo/wasm-utxo 0.0.2 → 1.1.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.
@@ -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 @@
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 @@
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
+ }
@@ -7,6 +7,25 @@ export class AddressNamespace {
7
7
  static to_output_script_with_coin(address: string, coin: string): Uint8Array;
8
8
  static from_output_script_with_coin(script: Uint8Array, coin: string, format?: string | null): string;
9
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
+ }
10
29
  export class FixedScriptWalletNamespace {
11
30
  private constructor();
12
31
  free(): void;
@@ -239,6 +239,102 @@ export class AddressNamespace {
239
239
  }
240
240
  if (Symbol.dispose) AddressNamespace.prototype[Symbol.dispose] = AddressNamespace.prototype.free;
241
241
 
242
+ const BitGoPsbtFinalization = (typeof FinalizationRegistry === 'undefined')
243
+ ? { register: () => {}, unregister: () => {} }
244
+ : new FinalizationRegistry(ptr => wasm.__wbg_bitgopsbt_free(ptr >>> 0, 1));
245
+
246
+ export class BitGoPsbt {
247
+
248
+ static __wrap(ptr) {
249
+ ptr = ptr >>> 0;
250
+ const obj = Object.create(BitGoPsbt.prototype);
251
+ obj.__wbg_ptr = ptr;
252
+ BitGoPsbtFinalization.register(obj, obj.__wbg_ptr, obj);
253
+ return obj;
254
+ }
255
+
256
+ __destroy_into_raw() {
257
+ const ptr = this.__wbg_ptr;
258
+ this.__wbg_ptr = 0;
259
+ BitGoPsbtFinalization.unregister(this);
260
+ return ptr;
261
+ }
262
+
263
+ free() {
264
+ const ptr = this.__destroy_into_raw();
265
+ wasm.__wbg_bitgopsbt_free(ptr, 0);
266
+ }
267
+ /**
268
+ * Deserialize a PSBT from bytes with network-specific logic
269
+ * @param {Uint8Array} bytes
270
+ * @param {string} network
271
+ * @returns {BitGoPsbt}
272
+ */
273
+ static from_bytes(bytes, network) {
274
+ try {
275
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
276
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export_1);
277
+ const len0 = WASM_VECTOR_LEN;
278
+ const ptr1 = passStringToWasm0(network, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
279
+ const len1 = WASM_VECTOR_LEN;
280
+ wasm.bitgopsbt_from_bytes(retptr, ptr0, len0, ptr1, len1);
281
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
282
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
283
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
284
+ if (r2) {
285
+ throw takeObject(r1);
286
+ }
287
+ return BitGoPsbt.__wrap(r0);
288
+ } finally {
289
+ wasm.__wbindgen_add_to_stack_pointer(16);
290
+ }
291
+ }
292
+ /**
293
+ * Parse outputs with wallet keys to identify which outputs belong to a wallet
294
+ *
295
+ * Note: This method does NOT validate wallet inputs. It only parses outputs.
296
+ * @param {any} wallet_keys
297
+ * @returns {any}
298
+ */
299
+ parse_outputs_with_wallet_keys(wallet_keys) {
300
+ try {
301
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
302
+ wasm.bitgopsbt_parse_outputs_with_wallet_keys(retptr, this.__wbg_ptr, addHeapObject(wallet_keys));
303
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
304
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
305
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
306
+ if (r2) {
307
+ throw takeObject(r1);
308
+ }
309
+ return takeObject(r0);
310
+ } finally {
311
+ wasm.__wbindgen_add_to_stack_pointer(16);
312
+ }
313
+ }
314
+ /**
315
+ * Parse transaction with wallet keys to identify wallet inputs/outputs
316
+ * @param {any} wallet_keys
317
+ * @param {any} replay_protection
318
+ * @returns {any}
319
+ */
320
+ parse_transaction_with_wallet_keys(wallet_keys, replay_protection) {
321
+ try {
322
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
323
+ wasm.bitgopsbt_parse_transaction_with_wallet_keys(retptr, this.__wbg_ptr, addHeapObject(wallet_keys), addHeapObject(replay_protection));
324
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
325
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
326
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
327
+ if (r2) {
328
+ throw takeObject(r1);
329
+ }
330
+ return takeObject(r0);
331
+ } finally {
332
+ wasm.__wbindgen_add_to_stack_pointer(16);
333
+ }
334
+ }
335
+ }
336
+ if (Symbol.dispose) BitGoPsbt.prototype[Symbol.dispose] = BitGoPsbt.prototype.free;
337
+
242
338
  const FixedScriptWalletNamespaceFinalization = (typeof FinalizationRegistry === 'undefined')
243
339
  ? { register: () => {}, unregister: () => {} }
244
340
  : new FinalizationRegistry(ptr => wasm.__wbg_fixedscriptwalletnamespace_free(ptr >>> 0, 1));
@@ -1043,6 +1139,17 @@ export function __wbg_get_458e874b43b18b25() { return handleError(function (arg0
1043
1139
  return addHeapObject(ret);
1044
1140
  }, arguments) };
1045
1141
 
1142
+ export function __wbg_instanceof_Uint8Array_9a8378d955933db7(arg0) {
1143
+ let result;
1144
+ try {
1145
+ result = getObject(arg0) instanceof Uint8Array;
1146
+ } catch (_) {
1147
+ result = false;
1148
+ }
1149
+ const ret = result;
1150
+ return ret;
1151
+ };
1152
+
1046
1153
  export function __wbg_isArray_030cce220591fb41(arg0) {
1047
1154
  const ret = Array.isArray(getObject(arg0));
1048
1155
  return ret;
@@ -1078,6 +1185,11 @@ export function __wbg_new_da9dc54c5db29dfa(arg0, arg1) {
1078
1185
  return addHeapObject(ret);
1079
1186
  };
1080
1187
 
1188
+ export function __wbg_newfromslice_074c56947bd43469(arg0, arg1) {
1189
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
1190
+ return addHeapObject(ret);
1191
+ };
1192
+
1081
1193
  export function __wbg_prototypesetcall_3d4a26c1ed734349(arg0, arg1, arg2) {
1082
1194
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
1083
1195
  };
@@ -1139,6 +1251,12 @@ export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
1139
1251
  return addHeapObject(ret);
1140
1252
  };
1141
1253
 
1254
+ export function __wbindgen_cast_4625c577ab2ec9ee(arg0) {
1255
+ // Cast intrinsic for `U64 -> Externref`.
1256
+ const ret = BigInt.asUintN(64, arg0);
1257
+ return addHeapObject(ret);
1258
+ };
1259
+
1142
1260
  export function __wbindgen_cast_d6cd19b81560fd6e(arg0) {
1143
1261
  // Cast intrinsic for `F64 -> Externref`.
1144
1262
  const ret = arg0;
@@ -2,13 +2,11 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_addressnamespace_free: (a: number, b: number) => void;
5
- export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
6
5
  export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
7
6
  export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
7
+ export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
8
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
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
10
  export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
13
11
  export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
14
12
  export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
@@ -22,14 +20,20 @@ export const wrapdescriptor_node: (a: number, b: number) => void;
22
20
  export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
23
21
  export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
24
22
  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
23
  export const wrapminiscript_encode: (a: number, b: number) => void;
28
24
  export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
29
25
  export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
30
26
  export const wrapminiscript_node: (a: number, b: number) => void;
31
27
  export const wrapminiscript_toAsmString: (a: number, b: number) => void;
32
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;
33
37
  export const wrappsbt_clone: (a: number) => number;
34
38
  export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
35
39
  export const wrappsbt_finalize: (a: number, b: 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 @@
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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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 @@
1
+ export type Triple<T> = [T, T, T];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
+ }
@@ -7,6 +7,25 @@ export class AddressNamespace {
7
7
  static to_output_script_with_coin(address: string, coin: string): Uint8Array;
8
8
  static from_output_script_with_coin(script: Uint8Array, coin: string, format?: string | null): string;
9
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
+ }
10
29
  export class FixedScriptWalletNamespace {
11
30
  private constructor();
12
31
  free(): void;
@@ -231,6 +231,104 @@ if (Symbol.dispose) AddressNamespace.prototype[Symbol.dispose] = AddressNamespac
231
231
 
232
232
  exports.AddressNamespace = AddressNamespace;
233
233
 
234
+ const BitGoPsbtFinalization = (typeof FinalizationRegistry === 'undefined')
235
+ ? { register: () => {}, unregister: () => {} }
236
+ : new FinalizationRegistry(ptr => wasm.__wbg_bitgopsbt_free(ptr >>> 0, 1));
237
+
238
+ class BitGoPsbt {
239
+
240
+ static __wrap(ptr) {
241
+ ptr = ptr >>> 0;
242
+ const obj = Object.create(BitGoPsbt.prototype);
243
+ obj.__wbg_ptr = ptr;
244
+ BitGoPsbtFinalization.register(obj, obj.__wbg_ptr, obj);
245
+ return obj;
246
+ }
247
+
248
+ __destroy_into_raw() {
249
+ const ptr = this.__wbg_ptr;
250
+ this.__wbg_ptr = 0;
251
+ BitGoPsbtFinalization.unregister(this);
252
+ return ptr;
253
+ }
254
+
255
+ free() {
256
+ const ptr = this.__destroy_into_raw();
257
+ wasm.__wbg_bitgopsbt_free(ptr, 0);
258
+ }
259
+ /**
260
+ * Deserialize a PSBT from bytes with network-specific logic
261
+ * @param {Uint8Array} bytes
262
+ * @param {string} network
263
+ * @returns {BitGoPsbt}
264
+ */
265
+ static from_bytes(bytes, network) {
266
+ try {
267
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
268
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export_1);
269
+ const len0 = WASM_VECTOR_LEN;
270
+ const ptr1 = passStringToWasm0(network, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
271
+ const len1 = WASM_VECTOR_LEN;
272
+ wasm.bitgopsbt_from_bytes(retptr, ptr0, len0, ptr1, len1);
273
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
274
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
275
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
276
+ if (r2) {
277
+ throw takeObject(r1);
278
+ }
279
+ return BitGoPsbt.__wrap(r0);
280
+ } finally {
281
+ wasm.__wbindgen_add_to_stack_pointer(16);
282
+ }
283
+ }
284
+ /**
285
+ * Parse outputs with wallet keys to identify which outputs belong to a wallet
286
+ *
287
+ * Note: This method does NOT validate wallet inputs. It only parses outputs.
288
+ * @param {any} wallet_keys
289
+ * @returns {any}
290
+ */
291
+ parse_outputs_with_wallet_keys(wallet_keys) {
292
+ try {
293
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
294
+ wasm.bitgopsbt_parse_outputs_with_wallet_keys(retptr, this.__wbg_ptr, addHeapObject(wallet_keys));
295
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
296
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
297
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
298
+ if (r2) {
299
+ throw takeObject(r1);
300
+ }
301
+ return takeObject(r0);
302
+ } finally {
303
+ wasm.__wbindgen_add_to_stack_pointer(16);
304
+ }
305
+ }
306
+ /**
307
+ * Parse transaction with wallet keys to identify wallet inputs/outputs
308
+ * @param {any} wallet_keys
309
+ * @param {any} replay_protection
310
+ * @returns {any}
311
+ */
312
+ parse_transaction_with_wallet_keys(wallet_keys, replay_protection) {
313
+ try {
314
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
315
+ wasm.bitgopsbt_parse_transaction_with_wallet_keys(retptr, this.__wbg_ptr, addHeapObject(wallet_keys), addHeapObject(replay_protection));
316
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
317
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
318
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
319
+ if (r2) {
320
+ throw takeObject(r1);
321
+ }
322
+ return takeObject(r0);
323
+ } finally {
324
+ wasm.__wbindgen_add_to_stack_pointer(16);
325
+ }
326
+ }
327
+ }
328
+ if (Symbol.dispose) BitGoPsbt.prototype[Symbol.dispose] = BitGoPsbt.prototype.free;
329
+
330
+ exports.BitGoPsbt = BitGoPsbt;
331
+
234
332
  const FixedScriptWalletNamespaceFinalization = (typeof FinalizationRegistry === 'undefined')
235
333
  ? { register: () => {}, unregister: () => {} }
236
334
  : new FinalizationRegistry(ptr => wasm.__wbg_fixedscriptwalletnamespace_free(ptr >>> 0, 1));
@@ -1045,6 +1143,17 @@ exports.__wbg_get_458e874b43b18b25 = function() { return handleError(function (a
1045
1143
  return addHeapObject(ret);
1046
1144
  }, arguments) };
1047
1145
 
1146
+ exports.__wbg_instanceof_Uint8Array_9a8378d955933db7 = function(arg0) {
1147
+ let result;
1148
+ try {
1149
+ result = getObject(arg0) instanceof Uint8Array;
1150
+ } catch (_) {
1151
+ result = false;
1152
+ }
1153
+ const ret = result;
1154
+ return ret;
1155
+ };
1156
+
1048
1157
  exports.__wbg_isArray_030cce220591fb41 = function(arg0) {
1049
1158
  const ret = Array.isArray(getObject(arg0));
1050
1159
  return ret;
@@ -1080,6 +1189,11 @@ exports.__wbg_new_da9dc54c5db29dfa = function(arg0, arg1) {
1080
1189
  return addHeapObject(ret);
1081
1190
  };
1082
1191
 
1192
+ exports.__wbg_newfromslice_074c56947bd43469 = function(arg0, arg1) {
1193
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
1194
+ return addHeapObject(ret);
1195
+ };
1196
+
1083
1197
  exports.__wbg_prototypesetcall_3d4a26c1ed734349 = function(arg0, arg1, arg2) {
1084
1198
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
1085
1199
  };
@@ -1141,6 +1255,12 @@ exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
1141
1255
  return addHeapObject(ret);
1142
1256
  };
1143
1257
 
1258
+ exports.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
1259
+ // Cast intrinsic for `U64 -> Externref`.
1260
+ const ret = BigInt.asUintN(64, arg0);
1261
+ return addHeapObject(ret);
1262
+ };
1263
+
1144
1264
  exports.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
1145
1265
  // Cast intrinsic for `F64 -> Externref`.
1146
1266
  const ret = arg0;
Binary file
@@ -2,13 +2,11 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_addressnamespace_free: (a: number, b: number) => void;
5
- export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
6
5
  export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
7
6
  export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
7
+ export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
8
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
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
10
  export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
13
11
  export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
14
12
  export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
@@ -22,14 +20,20 @@ export const wrapdescriptor_node: (a: number, b: number) => void;
22
20
  export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
23
21
  export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
24
22
  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
23
  export const wrapminiscript_encode: (a: number, b: number) => void;
28
24
  export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
29
25
  export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
30
26
  export const wrapminiscript_node: (a: number, b: number) => void;
31
27
  export const wrapminiscript_toAsmString: (a: number, b: number) => void;
32
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;
33
37
  export const wrappsbt_clone: (a: number) => number;
34
38
  export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
35
39
  export const wrappsbt_finalize: (a: number, b: number) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitgo/wasm-utxo",
3
3
  "description": "WebAssembly wrapper for rust-bitcoin (beta)",
4
- "version": "0.0.2",
4
+ "version": "1.1.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/BitGo/BitGoWASM"
@@ -14,10 +14,42 @@
14
14
  "dist/*/js/wasm/wasm_utxo_bg.wasm",
15
15
  "dist/*/js/wasm/wasm_utxo_bg.wasm.d.ts",
16
16
  "dist/*/js/ast/*",
17
- "dist/*/js/index.*"
17
+ "dist/*/js/index.*",
18
+ "dist/*/js/address.*",
19
+ "dist/*/js/utxolibCompat.*",
20
+ "dist/*/js/fixedScriptWallet.*",
21
+ "dist/*/js/coinName.*",
22
+ "dist/*/js/triple.*"
18
23
  ],
19
24
  "main": "dist/node/js/index.js",
20
25
  "types": "dist/node/js/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/node/js/index.d.ts",
29
+ "browser": "./dist/browser/js/index.js",
30
+ "default": "./dist/node/js/index.js"
31
+ },
32
+ "./address": {
33
+ "types": "./dist/node/js/address.d.ts",
34
+ "browser": "./dist/browser/js/address.js",
35
+ "default": "./dist/node/js/address.js"
36
+ },
37
+ "./ast": {
38
+ "types": "./dist/node/js/ast/index.d.ts",
39
+ "browser": "./dist/browser/js/ast/index.js",
40
+ "default": "./dist/node/js/ast/index.js"
41
+ },
42
+ "./fixedScriptWallet": {
43
+ "types": "./dist/node/js/fixedScriptWallet.d.ts",
44
+ "browser": "./dist/browser/js/fixedScriptWallet.js",
45
+ "default": "./dist/node/js/fixedScriptWallet.js"
46
+ },
47
+ "./utxolibCompat": {
48
+ "types": "./dist/node/js/utxolibCompat.d.ts",
49
+ "browser": "./dist/browser/js/utxolibCompat.js",
50
+ "default": "./dist/node/js/utxolibCompat.js"
51
+ }
52
+ },
21
53
  "sideEffects": [
22
54
  "./dist/node/js/wasm/wasm_utxo.js",
23
55
  "./dist/browser/js/wasm/wasm_utxo.js"