@bitgo/wasm-utxo 1.3.0 → 1.5.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/dist/{browser → cjs}/js/address.d.ts +1 -1
- package/dist/{node → cjs}/js/address.js +3 -3
- package/dist/{browser → cjs}/js/ast/fromWasmNode.d.ts +2 -2
- package/dist/cjs/js/ast/index.d.ts +2 -0
- package/dist/{node → cjs}/js/ast/index.js +2 -2
- package/dist/{node → cjs}/js/fixedScriptWallet.d.ts +23 -4
- package/dist/{node → cjs}/js/fixedScriptWallet.js +30 -5
- package/dist/{node → cjs}/js/index.d.ts +11 -11
- package/dist/{node → cjs}/js/index.js +11 -11
- package/dist/{browser → cjs}/js/utxolibCompat.d.ts +2 -2
- package/dist/{node → cjs}/js/utxolibCompat.js +3 -3
- package/dist/{node → cjs}/js/wasm/wasm_utxo.d.ts +29 -0
- package/dist/{node → cjs}/js/wasm/wasm_utxo.js +77 -0
- package/dist/{node → cjs}/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/{browser → cjs}/js/wasm/wasm_utxo_bg.wasm.d.ts +19 -16
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/{node → esm}/js/address.d.ts +1 -1
- package/dist/{browser → esm}/js/address.js +1 -1
- package/dist/{node → esm}/js/ast/fromWasmNode.d.ts +2 -2
- package/dist/esm/js/ast/index.d.ts +2 -0
- package/dist/esm/js/ast/index.js +2 -0
- package/dist/{browser → esm}/js/fixedScriptWallet.d.ts +23 -4
- package/dist/{browser → esm}/js/fixedScriptWallet.js +28 -2
- package/dist/{browser → esm}/js/index.d.ts +11 -11
- package/dist/esm/js/index.js +11 -0
- package/dist/{node → esm}/js/utxolibCompat.d.ts +2 -2
- package/dist/{browser → esm}/js/utxolibCompat.js +1 -1
- package/dist/{browser → esm}/js/wasm/wasm_utxo.d.ts +29 -0
- package/dist/{browser → esm}/js/wasm/wasm_utxo_bg.js +77 -0
- package/dist/{browser → esm}/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/{node → esm}/js/wasm/wasm_utxo_bg.wasm.d.ts +19 -16
- package/dist/esm/test/address/utxolibCompat.d.ts +1 -0
- package/dist/esm/test/address/utxolibCompat.js +105 -0
- package/dist/esm/test/ast/formatNode.d.ts +1 -0
- package/dist/esm/test/ast/formatNode.js +15 -0
- package/dist/esm/test/descriptorFixtures.d.ts +25 -0
- package/dist/esm/test/descriptorFixtures.js +605 -0
- package/dist/esm/test/descriptorUtil.d.ts +13 -0
- package/dist/esm/test/descriptorUtil.js +52 -0
- package/dist/esm/test/fixedScript/address.d.ts +1 -0
- package/dist/esm/test/fixedScript/address.js +64 -0
- package/dist/esm/test/fixedScript/finalizeExtract.d.ts +1 -0
- package/dist/esm/test/fixedScript/finalizeExtract.js +66 -0
- package/dist/esm/test/fixedScript/fixtureUtil.d.ts +93 -0
- package/dist/esm/test/fixedScript/fixtureUtil.js +44 -0
- package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.d.ts +1 -0
- package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +140 -0
- package/dist/esm/test/fixedScript/verifySignature.d.ts +1 -0
- package/dist/esm/test/fixedScript/verifySignature.js +141 -0
- package/dist/esm/test/fixedScriptToDescriptor.d.ts +1 -0
- package/dist/esm/test/fixedScriptToDescriptor.js +91 -0
- package/dist/esm/test/fixtures.d.ts +1 -0
- package/dist/esm/test/fixtures.js +12 -0
- package/dist/esm/test/opdrop.d.ts +1 -0
- package/dist/esm/test/opdrop.js +85 -0
- package/dist/esm/test/psbt.util.d.ts +8 -0
- package/dist/esm/test/psbt.util.js +116 -0
- package/dist/esm/test/psbtFixedScriptCompat.d.ts +1 -0
- package/dist/esm/test/psbtFixedScriptCompat.js +114 -0
- package/dist/esm/test/psbtFixedScriptCompatFixtures.d.ts +10 -0
- package/dist/esm/test/psbtFixedScriptCompatFixtures.js +53 -0
- package/dist/esm/test/psbtFromDescriptor.d.ts +1 -0
- package/dist/esm/test/psbtFromDescriptor.js +107 -0
- package/dist/esm/test/psbtFromDescriptor.util.d.ts +63 -0
- package/dist/esm/test/psbtFromDescriptor.util.js +101 -0
- package/dist/esm/test/test.d.ts +1 -0
- package/dist/esm/test/test.js +122 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +31 -26
- package/dist/browser/js/ast/index.d.ts +0 -2
- package/dist/browser/js/ast/index.js +0 -2
- package/dist/browser/js/index.js +0 -11
- package/dist/node/js/ast/index.d.ts +0 -2
- /package/dist/{browser → cjs}/js/ast/formatNode.d.ts +0 -0
- /package/dist/{node → cjs}/js/ast/formatNode.js +0 -0
- /package/dist/{node → cjs}/js/ast/fromWasmNode.js +0 -0
- /package/dist/{browser → cjs}/js/coinName.d.ts +0 -0
- /package/dist/{node → cjs}/js/coinName.js +0 -0
- /package/dist/{browser → cjs}/js/triple.d.ts +0 -0
- /package/dist/{node → cjs}/js/triple.js +0 -0
- /package/dist/{node → esm}/js/ast/formatNode.d.ts +0 -0
- /package/dist/{browser → esm}/js/ast/formatNode.js +0 -0
- /package/dist/{browser → esm}/js/ast/fromWasmNode.js +0 -0
- /package/dist/{node → esm}/js/coinName.d.ts +0 -0
- /package/dist/{browser → esm}/js/coinName.js +0 -0
- /package/dist/{node → esm}/js/triple.d.ts +0 -0
- /package/dist/{browser → esm}/js/triple.js +0 -0
- /package/dist/{browser → esm}/js/wasm/wasm_utxo.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { UtxolibName, UtxolibNetwork, UtxolibRootWalletKeys } from "./utxolibCompat";
|
|
2
|
-
import type { CoinName } from "./coinName";
|
|
3
|
-
import { Triple } from "./triple";
|
|
4
|
-
import { AddressFormat } from "./address";
|
|
1
|
+
import type { UtxolibName, UtxolibNetwork, UtxolibRootWalletKeys } from "./utxolibCompat.js";
|
|
2
|
+
import type { CoinName } from "./coinName.js";
|
|
3
|
+
import { Triple } from "./triple.js";
|
|
4
|
+
import { AddressFormat } from "./address.js";
|
|
5
5
|
export type NetworkName = UtxolibName | CoinName;
|
|
6
6
|
export type WalletKeys =
|
|
7
7
|
/** Just an xpub triple, will assume default derivation prefixes */
|
|
@@ -121,5 +121,24 @@ export declare class BitGoPsbt {
|
|
|
121
121
|
* @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
|
|
122
122
|
*/
|
|
123
123
|
verifyReplayProtectionSignature(inputIndex: number, replayProtection: ReplayProtection): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Serialize the PSBT to bytes
|
|
126
|
+
*
|
|
127
|
+
* @returns The serialized PSBT as a byte array
|
|
128
|
+
*/
|
|
129
|
+
serialize(): Uint8Array;
|
|
130
|
+
/**
|
|
131
|
+
* Finalize all inputs in the PSBT
|
|
132
|
+
*
|
|
133
|
+
* @throws Error if any input failed to finalize
|
|
134
|
+
*/
|
|
135
|
+
finalizeAllInputs(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Extract the final transaction from a finalized PSBT
|
|
138
|
+
*
|
|
139
|
+
* @returns The serialized transaction bytes
|
|
140
|
+
* @throws Error if the PSBT is not fully finalized or extraction fails
|
|
141
|
+
*/
|
|
142
|
+
extractTransaction(): Uint8Array;
|
|
124
143
|
}
|
|
125
144
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FixedScriptWalletNamespace } from "./wasm/wasm_utxo";
|
|
1
|
+
import { FixedScriptWalletNamespace } from "./wasm/wasm_utxo.js";
|
|
2
2
|
/**
|
|
3
3
|
* Create the output script for a given wallet keys and chain and index
|
|
4
4
|
*/
|
|
@@ -20,8 +20,9 @@ export function outputScript(keys, chain, index, network) {
|
|
|
20
20
|
export function address(keys, chain, index, network, addressFormat) {
|
|
21
21
|
return FixedScriptWalletNamespace.address(keys, chain, index, network, addressFormat);
|
|
22
22
|
}
|
|
23
|
-
import { BitGoPsbt as WasmBitGoPsbt } from "./wasm/wasm_utxo";
|
|
23
|
+
import { BitGoPsbt as WasmBitGoPsbt } from "./wasm/wasm_utxo.js";
|
|
24
24
|
export class BitGoPsbt {
|
|
25
|
+
wasm;
|
|
25
26
|
constructor(wasm) {
|
|
26
27
|
this.wasm = wasm;
|
|
27
28
|
}
|
|
@@ -103,4 +104,29 @@ export class BitGoPsbt {
|
|
|
103
104
|
verifyReplayProtectionSignature(inputIndex, replayProtection) {
|
|
104
105
|
return this.wasm.verify_replay_protection_signature(inputIndex, replayProtection);
|
|
105
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Serialize the PSBT to bytes
|
|
109
|
+
*
|
|
110
|
+
* @returns The serialized PSBT as a byte array
|
|
111
|
+
*/
|
|
112
|
+
serialize() {
|
|
113
|
+
return this.wasm.serialize();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Finalize all inputs in the PSBT
|
|
117
|
+
*
|
|
118
|
+
* @throws Error if any input failed to finalize
|
|
119
|
+
*/
|
|
120
|
+
finalizeAllInputs() {
|
|
121
|
+
this.wasm.finalize_all_inputs();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Extract the final transaction from a finalized PSBT
|
|
125
|
+
*
|
|
126
|
+
* @returns The serialized transaction bytes
|
|
127
|
+
* @throws Error if the PSBT is not fully finalized or extraction fails
|
|
128
|
+
*/
|
|
129
|
+
extractTransaction() {
|
|
130
|
+
return this.wasm.extract_transaction();
|
|
131
|
+
}
|
|
106
132
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
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";
|
|
1
|
+
export * as address from "./address.js";
|
|
2
|
+
export * as ast from "./ast/index.js";
|
|
3
|
+
export * as utxolibCompat from "./utxolibCompat.js";
|
|
4
|
+
export * as fixedScriptWallet from "./fixedScriptWallet.js";
|
|
5
|
+
export type { CoinName } from "./coinName.js";
|
|
6
|
+
export type { Triple } from "./triple.js";
|
|
7
|
+
export type { AddressFormat } from "./address.js";
|
|
8
8
|
export type DescriptorPkType = "derivable" | "definite" | "string";
|
|
9
9
|
export type ScriptContext = "tap" | "segwitv0" | "legacy";
|
|
10
10
|
export type SignPsbtResult = {
|
|
11
11
|
[inputIndex: number]: [pubkey: string][];
|
|
12
12
|
};
|
|
13
|
-
declare module "./wasm/wasm_utxo" {
|
|
13
|
+
declare module "./wasm/wasm_utxo.js" {
|
|
14
14
|
interface WrapDescriptor {
|
|
15
15
|
/** These are not the same types of nodes as in the ast module */
|
|
16
16
|
node(): unknown;
|
|
@@ -32,6 +32,6 @@ declare module "./wasm/wasm_utxo" {
|
|
|
32
32
|
signWithPrv(this: WrapPsbt, prv: Uint8Array): SignPsbtResult;
|
|
33
33
|
}
|
|
34
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";
|
|
35
|
+
export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo.js";
|
|
36
|
+
export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo.js";
|
|
37
|
+
export { WrapPsbt as Psbt } from "./wasm/wasm_utxo.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as wasm from "./wasm/wasm_utxo.js";
|
|
2
|
+
// we need to access the wasm module here, otherwise webpack gets all weird
|
|
3
|
+
// and forgets to include it in the bundle
|
|
4
|
+
void wasm;
|
|
5
|
+
export * as address from "./address.js";
|
|
6
|
+
export * as ast from "./ast/index.js";
|
|
7
|
+
export * as utxolibCompat from "./utxolibCompat.js";
|
|
8
|
+
export * as fixedScriptWallet from "./fixedScriptWallet.js";
|
|
9
|
+
export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo.js";
|
|
10
|
+
export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo.js";
|
|
11
|
+
export { WrapPsbt as Psbt } from "./wasm/wasm_utxo.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AddressFormat } from "./address";
|
|
2
|
-
import { Triple } from "./triple";
|
|
1
|
+
import type { AddressFormat } from "./address.js";
|
|
2
|
+
import { Triple } from "./triple.js";
|
|
3
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
4
|
export type BIP32Interface = {
|
|
5
5
|
network: {
|
|
@@ -36,6 +36,28 @@ export class BitGoPsbt {
|
|
|
36
36
|
* - `Err(WasmUtxoError)` if the input index is out of bounds, xpub is invalid, derivation fails, or verification fails
|
|
37
37
|
*/
|
|
38
38
|
verify_signature(input_index: number, xpub_str: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Extract the final transaction from a finalized PSBT
|
|
41
|
+
*
|
|
42
|
+
* This method should be called after all inputs have been finalized.
|
|
43
|
+
* It extracts the fully signed transaction.
|
|
44
|
+
*
|
|
45
|
+
* # Returns
|
|
46
|
+
* - `Ok(Vec<u8>)` containing the serialized transaction bytes
|
|
47
|
+
* - `Err(WasmUtxoError)` if the PSBT is not fully finalized or extraction fails
|
|
48
|
+
*/
|
|
49
|
+
extract_transaction(): Uint8Array;
|
|
50
|
+
/**
|
|
51
|
+
* Finalize all inputs in the PSBT
|
|
52
|
+
*
|
|
53
|
+
* This method attempts to finalize all inputs in the PSBT, computing the final
|
|
54
|
+
* scriptSig and witness data for each input.
|
|
55
|
+
*
|
|
56
|
+
* # Returns
|
|
57
|
+
* - `Ok(())` if all inputs were successfully finalized
|
|
58
|
+
* - `Err(WasmUtxoError)` if any input failed to finalize
|
|
59
|
+
*/
|
|
60
|
+
finalize_all_inputs(): void;
|
|
39
61
|
/**
|
|
40
62
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
41
63
|
*
|
|
@@ -64,6 +86,13 @@ export class BitGoPsbt {
|
|
|
64
86
|
* - `Err(WasmUtxoError)` if the input is not a replay protection input, index is out of bounds, or configuration is invalid
|
|
65
87
|
*/
|
|
66
88
|
verify_replay_protection_signature(input_index: number, replay_protection: any): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Serialize the PSBT to bytes
|
|
91
|
+
*
|
|
92
|
+
* # Returns
|
|
93
|
+
* The serialized PSBT as a byte array
|
|
94
|
+
*/
|
|
95
|
+
serialize(): Uint8Array;
|
|
67
96
|
}
|
|
68
97
|
export class FixedScriptWalletNamespace {
|
|
69
98
|
private constructor();
|
|
@@ -345,6 +345,58 @@ export class BitGoPsbt {
|
|
|
345
345
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Extract the final transaction from a finalized PSBT
|
|
350
|
+
*
|
|
351
|
+
* This method should be called after all inputs have been finalized.
|
|
352
|
+
* It extracts the fully signed transaction.
|
|
353
|
+
*
|
|
354
|
+
* # Returns
|
|
355
|
+
* - `Ok(Vec<u8>)` containing the serialized transaction bytes
|
|
356
|
+
* - `Err(WasmUtxoError)` if the PSBT is not fully finalized or extraction fails
|
|
357
|
+
* @returns {Uint8Array}
|
|
358
|
+
*/
|
|
359
|
+
extract_transaction() {
|
|
360
|
+
try {
|
|
361
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
362
|
+
wasm.bitgopsbt_extract_transaction(retptr, this.__wbg_ptr);
|
|
363
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
364
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
365
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
366
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
367
|
+
if (r3) {
|
|
368
|
+
throw takeObject(r2);
|
|
369
|
+
}
|
|
370
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
371
|
+
wasm.__wbindgen_export_3(r0, r1 * 1, 1);
|
|
372
|
+
return v1;
|
|
373
|
+
} finally {
|
|
374
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Finalize all inputs in the PSBT
|
|
379
|
+
*
|
|
380
|
+
* This method attempts to finalize all inputs in the PSBT, computing the final
|
|
381
|
+
* scriptSig and witness data for each input.
|
|
382
|
+
*
|
|
383
|
+
* # Returns
|
|
384
|
+
* - `Ok(())` if all inputs were successfully finalized
|
|
385
|
+
* - `Err(WasmUtxoError)` if any input failed to finalize
|
|
386
|
+
*/
|
|
387
|
+
finalize_all_inputs() {
|
|
388
|
+
try {
|
|
389
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
390
|
+
wasm.bitgopsbt_finalize_all_inputs(retptr, this.__wbg_ptr);
|
|
391
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
392
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
393
|
+
if (r1) {
|
|
394
|
+
throw takeObject(r0);
|
|
395
|
+
}
|
|
396
|
+
} finally {
|
|
397
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
348
400
|
/**
|
|
349
401
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
350
402
|
*
|
|
@@ -423,6 +475,31 @@ export class BitGoPsbt {
|
|
|
423
475
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
424
476
|
}
|
|
425
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* Serialize the PSBT to bytes
|
|
480
|
+
*
|
|
481
|
+
* # Returns
|
|
482
|
+
* The serialized PSBT as a byte array
|
|
483
|
+
* @returns {Uint8Array}
|
|
484
|
+
*/
|
|
485
|
+
serialize() {
|
|
486
|
+
try {
|
|
487
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
488
|
+
wasm.bitgopsbt_serialize(retptr, this.__wbg_ptr);
|
|
489
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
490
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
491
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
492
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
493
|
+
if (r3) {
|
|
494
|
+
throw takeObject(r2);
|
|
495
|
+
}
|
|
496
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
497
|
+
wasm.__wbindgen_export_3(r0, r1 * 1, 1);
|
|
498
|
+
return v1;
|
|
499
|
+
} finally {
|
|
500
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
426
503
|
}
|
|
427
504
|
if (Symbol.dispose) BitGoPsbt.prototype[Symbol.dispose] = BitGoPsbt.prototype.free;
|
|
428
505
|
|
|
Binary file
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
4
5
|
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
5
6
|
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
6
|
-
export const
|
|
7
|
+
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
8
|
+
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
9
|
+
export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
|
|
10
|
+
export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
|
|
7
11
|
export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
8
12
|
export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number) => void;
|
|
9
13
|
export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number) => void;
|
|
14
|
+
export const bitgopsbt_serialize: (a: number, b: number) => void;
|
|
10
15
|
export const bitgopsbt_unsigned_txid: (a: number, b: number) => void;
|
|
11
16
|
export const bitgopsbt_verify_replay_protection_signature: (a: number, b: number, c: number, d: number) => void;
|
|
12
17
|
export const bitgopsbt_verify_signature: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
13
18
|
export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
14
19
|
export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
15
|
-
export const
|
|
16
|
-
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
17
|
-
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
18
|
-
export const wrappsbt_serialize: (a: number, b: number) => void;
|
|
19
|
-
export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
|
|
20
|
-
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
21
|
-
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
22
|
-
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
23
|
-
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
24
|
-
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
25
|
-
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
20
|
+
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
26
21
|
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
22
|
+
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
23
|
+
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
24
|
+
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
25
|
+
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
27
26
|
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
28
27
|
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
29
28
|
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
@@ -35,16 +34,20 @@ export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
|
35
34
|
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
36
35
|
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
37
36
|
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
38
|
-
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
39
|
-
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
40
|
-
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
41
|
-
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
42
37
|
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
43
38
|
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
44
39
|
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
45
40
|
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
46
41
|
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
47
42
|
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
43
|
+
export const wrappsbt_clone: (a: number) => number;
|
|
44
|
+
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
45
|
+
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
46
|
+
export const wrappsbt_serialize: (a: number, b: number) => void;
|
|
47
|
+
export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
|
|
48
|
+
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
49
|
+
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
50
|
+
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
48
51
|
export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
|
|
49
52
|
export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
|
|
50
53
|
export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname } from "node:path";
|
|
5
|
+
import * as utxolib from "@bitgo/utxo-lib";
|
|
6
|
+
import assert from "node:assert";
|
|
7
|
+
import { utxolibCompat, address as addressNs, } from "../../js/index.js";
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
function getCoinNameForNetwork(name) {
|
|
11
|
+
switch (name) {
|
|
12
|
+
case "bitcoin":
|
|
13
|
+
return "btc";
|
|
14
|
+
case "testnet":
|
|
15
|
+
return "tbtc";
|
|
16
|
+
case "bitcoinTestnet4":
|
|
17
|
+
return "tbtc4";
|
|
18
|
+
case "bitcoinPublicSignet":
|
|
19
|
+
return "tbtcsig";
|
|
20
|
+
case "bitcoinBitGoSignet":
|
|
21
|
+
return "tbtcbgsig";
|
|
22
|
+
case "bitcoincash":
|
|
23
|
+
return "bch";
|
|
24
|
+
case "bitcoincashTestnet":
|
|
25
|
+
return "tbch";
|
|
26
|
+
case "ecash":
|
|
27
|
+
return "bcha";
|
|
28
|
+
case "ecashTest":
|
|
29
|
+
return "tbcha";
|
|
30
|
+
case "bitcoingold":
|
|
31
|
+
return "btg";
|
|
32
|
+
case "bitcoingoldTestnet":
|
|
33
|
+
return "tbtg";
|
|
34
|
+
case "bitcoinsv":
|
|
35
|
+
return "bsv";
|
|
36
|
+
case "bitcoinsvTestnet":
|
|
37
|
+
return "tbsv";
|
|
38
|
+
case "dash":
|
|
39
|
+
return "dash";
|
|
40
|
+
case "dashTest":
|
|
41
|
+
return "tdash";
|
|
42
|
+
case "dogecoin":
|
|
43
|
+
return "doge";
|
|
44
|
+
case "dogecoinTest":
|
|
45
|
+
return "tdoge";
|
|
46
|
+
case "litecoin":
|
|
47
|
+
return "ltc";
|
|
48
|
+
case "litecoinTest":
|
|
49
|
+
return "tltc";
|
|
50
|
+
case "zcash":
|
|
51
|
+
return "zec";
|
|
52
|
+
case "zcashTest":
|
|
53
|
+
return "tzec";
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`Unknown network: ${name}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function getFixtures(name, addressFormat) {
|
|
59
|
+
if (name === "bitcoinBitGoSignet") {
|
|
60
|
+
name = "bitcoinPublicSignet";
|
|
61
|
+
}
|
|
62
|
+
const filename = addressFormat ? `${name}-${addressFormat}` : name;
|
|
63
|
+
const fixturePath = path.join(__dirname, "..", "fixtures", "address", `${filename}.json`);
|
|
64
|
+
const fixtures = await fs.readFile(fixturePath, "utf8");
|
|
65
|
+
return JSON.parse(fixtures);
|
|
66
|
+
}
|
|
67
|
+
function runTest(network, addressFormat) {
|
|
68
|
+
const name = utxolib.getNetworkName(network);
|
|
69
|
+
describe(`utxolibCompat ${name} ${addressFormat ?? "default"}`, function () {
|
|
70
|
+
let fixtures;
|
|
71
|
+
before(async function () {
|
|
72
|
+
fixtures = await getFixtures(name, addressFormat);
|
|
73
|
+
});
|
|
74
|
+
it("should convert to utxolib compatible network", async function () {
|
|
75
|
+
for (const fixture of fixtures) {
|
|
76
|
+
const [_type, script, addressRef] = fixture;
|
|
77
|
+
const scriptBuf = Buffer.from(script, "hex");
|
|
78
|
+
const address = utxolibCompat.fromOutputScript(scriptBuf, network, addressFormat);
|
|
79
|
+
assert.strictEqual(address, addressRef);
|
|
80
|
+
const scriptFromAddress = utxolibCompat.toOutputScript(address, network, addressFormat);
|
|
81
|
+
assert.deepStrictEqual(Buffer.from(scriptFromAddress), scriptBuf);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
it("should convert using coin name", async function () {
|
|
85
|
+
const coinName = getCoinNameForNetwork(name);
|
|
86
|
+
for (const fixture of fixtures) {
|
|
87
|
+
const [_type, script, addressRef] = fixture;
|
|
88
|
+
const scriptBuf = Buffer.from(script, "hex");
|
|
89
|
+
// Test encoding (script -> address)
|
|
90
|
+
const address = addressNs.fromOutputScriptWithCoin(scriptBuf, coinName, addressFormat);
|
|
91
|
+
assert.strictEqual(address, addressRef);
|
|
92
|
+
// Test decoding (address -> script)
|
|
93
|
+
const scriptFromAddress = addressNs.toOutputScriptWithCoin(addressRef, coinName);
|
|
94
|
+
assert.deepStrictEqual(Buffer.from(scriptFromAddress), scriptBuf);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
utxolib.getNetworkList().forEach((network) => {
|
|
100
|
+
runTest(network);
|
|
101
|
+
const mainnet = utxolib.getMainnet(network);
|
|
102
|
+
if (mainnet === utxolib.networks.bitcoincash || mainnet === utxolib.networks.ecash) {
|
|
103
|
+
runTest(network, "cashaddr");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import { formatNode } from "../../js/ast/index.js";
|
|
3
|
+
describe("formatNode", function () {
|
|
4
|
+
it("formats simple nodes", function () {
|
|
5
|
+
assert.strictEqual(formatNode({ pk: "lol" }), "pk(lol)");
|
|
6
|
+
assert.strictEqual(formatNode({ after: 1 }), "after(1)");
|
|
7
|
+
assert.strictEqual(formatNode({ and_v: [{ after: 1 }, { after: 1 }] }), "and_v(after(1),after(1))");
|
|
8
|
+
// taproot single key
|
|
9
|
+
assert.strictEqual(formatNode({ tr: "k" }), "tr(k)");
|
|
10
|
+
// key with single-node taproot tree
|
|
11
|
+
assert.strictEqual(formatNode({ tr: ["k", { pk: "k1" }] }), "tr(k,pk(k1))");
|
|
12
|
+
// key with multi-node taproot tree
|
|
13
|
+
assert.strictEqual(formatNode({ tr: ["k", [{ pk: "k1" }, { pk: "k2" }]] }), "tr(k,{pk(k1),pk(k2)})");
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const fixtures: {
|
|
2
|
+
valid: ({
|
|
3
|
+
descriptor: string;
|
|
4
|
+
script: string;
|
|
5
|
+
checksumRequired: boolean;
|
|
6
|
+
index?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
descriptor: string;
|
|
9
|
+
script: string;
|
|
10
|
+
index: number;
|
|
11
|
+
checksumRequired: boolean;
|
|
12
|
+
} | {
|
|
13
|
+
descriptor: string;
|
|
14
|
+
script: string;
|
|
15
|
+
checksumRequired?: undefined;
|
|
16
|
+
index?: undefined;
|
|
17
|
+
})[];
|
|
18
|
+
invalid: ({
|
|
19
|
+
descriptor: string;
|
|
20
|
+
checksumRequired: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
descriptor: string;
|
|
23
|
+
checksumRequired?: undefined;
|
|
24
|
+
})[];
|
|
25
|
+
};
|