@bitgo/wasm-utxo 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +5 -0
  2. package/dist/cjs/js/wasm/wasm_utxo.js +14 -14
  3. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  4. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +25 -25
  5. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +5 -0
  6. package/dist/esm/js/wasm/wasm_utxo_bg.js +14 -14
  7. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  8. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +25 -25
  9. package/package.json +3 -3
  10. package/dist/cjs/package.json +0 -1
  11. package/dist/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  12. package/dist/esm/test/address/utxolibCompat.d.ts +0 -1
  13. package/dist/esm/test/address/utxolibCompat.js +0 -107
  14. package/dist/esm/test/ast/formatNode.d.ts +0 -1
  15. package/dist/esm/test/ast/formatNode.js +0 -15
  16. package/dist/esm/test/bip32.d.ts +0 -1
  17. package/dist/esm/test/bip32.js +0 -242
  18. package/dist/esm/test/descriptorFixtures.d.ts +0 -25
  19. package/dist/esm/test/descriptorFixtures.js +0 -605
  20. package/dist/esm/test/descriptorUtil.d.ts +0 -13
  21. package/dist/esm/test/descriptorUtil.js +0 -52
  22. package/dist/esm/test/ecpair.d.ts +0 -1
  23. package/dist/esm/test/ecpair.js +0 -137
  24. package/dist/esm/test/fixedScript/address.d.ts +0 -1
  25. package/dist/esm/test/fixedScript/address.js +0 -66
  26. package/dist/esm/test/fixedScript/finalizeExtract.d.ts +0 -1
  27. package/dist/esm/test/fixedScript/finalizeExtract.js +0 -66
  28. package/dist/esm/test/fixedScript/fixtureUtil.d.ts +0 -103
  29. package/dist/esm/test/fixedScript/fixtureUtil.js +0 -65
  30. package/dist/esm/test/fixedScript/musig2Nonces.d.ts +0 -1
  31. package/dist/esm/test/fixedScript/musig2Nonces.js +0 -77
  32. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.d.ts +0 -1
  33. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +0 -168
  34. package/dist/esm/test/fixedScript/signAndVerifySignature.d.ts +0 -1
  35. package/dist/esm/test/fixedScript/signAndVerifySignature.js +0 -268
  36. package/dist/esm/test/fixedScript/walletKeys.util.d.ts +0 -12
  37. package/dist/esm/test/fixedScript/walletKeys.util.js +0 -17
  38. package/dist/esm/test/fixedScriptToDescriptor.d.ts +0 -1
  39. package/dist/esm/test/fixedScriptToDescriptor.js +0 -93
  40. package/dist/esm/test/fixtures.d.ts +0 -1
  41. package/dist/esm/test/fixtures.js +0 -16
  42. package/dist/esm/test/opdrop.d.ts +0 -1
  43. package/dist/esm/test/opdrop.js +0 -85
  44. package/dist/esm/test/psbt.util.d.ts +0 -8
  45. package/dist/esm/test/psbt.util.js +0 -113
  46. package/dist/esm/test/psbtFixedScriptCompat.d.ts +0 -1
  47. package/dist/esm/test/psbtFixedScriptCompat.js +0 -116
  48. package/dist/esm/test/psbtFixedScriptCompatFixtures.d.ts +0 -10
  49. package/dist/esm/test/psbtFixedScriptCompatFixtures.js +0 -53
  50. package/dist/esm/test/psbtFromDescriptor.d.ts +0 -1
  51. package/dist/esm/test/psbtFromDescriptor.js +0 -104
  52. package/dist/esm/test/psbtFromDescriptor.util.d.ts +0 -63
  53. package/dist/esm/test/psbtFromDescriptor.util.js +0 -101
  54. package/dist/esm/test/test.d.ts +0 -1
  55. package/dist/esm/test/test.js +0 -123
  56. package/dist/esm/tsconfig.tsbuildinfo +0 -1
@@ -1,242 +0,0 @@
1
- import * as assert from "assert";
2
- import { bip32 as utxolibBip32 } from "@bitgo/utxo-lib";
3
- import { BIP32 } from "../js/bip32.js";
4
- const bip32 = { BIP32 };
5
- describe("WasmBIP32", () => {
6
- it("should create from base58 xpub", () => {
7
- const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
8
- const key = bip32.BIP32.fromBase58(xpub);
9
- assert.strictEqual(key.isNeutered(), true);
10
- assert.strictEqual(key.depth, 3);
11
- assert.strictEqual(key.toBase58(), xpub);
12
- // Verify properties exist
13
- assert.ok(key.chainCode instanceof Uint8Array);
14
- assert.ok(key.publicKey instanceof Uint8Array);
15
- assert.ok(key.identifier instanceof Uint8Array);
16
- assert.ok(key.fingerprint instanceof Uint8Array);
17
- assert.strictEqual(key.privateKey, undefined);
18
- });
19
- it("should create from base58 xprv", () => {
20
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
21
- const key = bip32.BIP32.fromBase58(xprv);
22
- assert.strictEqual(key.isNeutered(), false);
23
- assert.strictEqual(key.depth, 0);
24
- assert.strictEqual(key.toBase58(), xprv);
25
- // Verify properties exist
26
- assert.ok(key.chainCode instanceof Uint8Array);
27
- assert.ok(key.publicKey instanceof Uint8Array);
28
- assert.ok(key.privateKey instanceof Uint8Array);
29
- assert.ok(key.identifier instanceof Uint8Array);
30
- assert.ok(key.fingerprint instanceof Uint8Array);
31
- });
32
- it("should derive child keys", () => {
33
- const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
34
- const key = bip32.BIP32.fromBase58(xpub);
35
- const child = key.derive(0);
36
- assert.strictEqual(child.depth, 4);
37
- assert.strictEqual(child.isNeutered(), true);
38
- });
39
- it("should derive using path", () => {
40
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
41
- const key = bip32.BIP32.fromBase58(xprv);
42
- const derived1 = key.derivePath("0/1/2");
43
- assert.strictEqual(derived1.depth, 3);
44
- const derived2 = key.derivePath("m/0/1/2");
45
- assert.strictEqual(derived2.depth, 3);
46
- // Both should produce the same result
47
- assert.strictEqual(derived1.toBase58(), derived2.toBase58());
48
- });
49
- it("should neutered a private key", () => {
50
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
51
- const key = bip32.BIP32.fromBase58(xprv);
52
- const neuteredKey = key.neutered();
53
- assert.strictEqual(neuteredKey.isNeutered(), true);
54
- assert.strictEqual(neuteredKey.privateKey, undefined);
55
- assert.ok(neuteredKey.publicKey instanceof Uint8Array);
56
- });
57
- it("should derive hardened keys from private key", () => {
58
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
59
- const key = bip32.BIP32.fromBase58(xprv);
60
- const hardened = key.deriveHardened(0);
61
- assert.strictEqual(hardened.depth, 1);
62
- assert.strictEqual(hardened.isNeutered(), false);
63
- });
64
- it("should fail to derive hardened from public key", () => {
65
- const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
66
- const key = bip32.BIP32.fromBase58(xpub);
67
- assert.throws(() => {
68
- key.deriveHardened(0);
69
- });
70
- });
71
- it("should export to WIF", () => {
72
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
73
- const key = bip32.BIP32.fromBase58(xprv);
74
- const wif = key.toWIF();
75
- assert.ok(typeof wif === "string");
76
- assert.ok(wif.length > 0);
77
- });
78
- it("should fail to export WIF from public key", () => {
79
- const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
80
- const key = bip32.BIP32.fromBase58(xpub);
81
- assert.throws(() => {
82
- key.toWIF();
83
- });
84
- });
85
- it("should create from seed", () => {
86
- const seed = new Uint8Array(32);
87
- for (let i = 0; i < 32; i++) {
88
- seed[i] = i;
89
- }
90
- const key = bip32.BIP32.fromSeed(seed);
91
- assert.strictEqual(key.depth, 0);
92
- assert.strictEqual(key.isNeutered(), false);
93
- assert.ok(key.privateKey instanceof Uint8Array);
94
- });
95
- it("should create from seed with network", () => {
96
- const seed = new Uint8Array(32);
97
- for (let i = 0; i < 32; i++) {
98
- seed[i] = i;
99
- }
100
- const key = bip32.BIP32.fromSeed(seed, "BitcoinTestnet3");
101
- assert.strictEqual(key.depth, 0);
102
- assert.strictEqual(key.isNeutered(), false);
103
- assert.ok(key.toBase58().startsWith("tprv"));
104
- });
105
- });
106
- describe("WasmBIP32 parity with utxolib", () => {
107
- function bufferEqual(a, b) {
108
- if (a.length !== b.length)
109
- return false;
110
- for (let i = 0; i < a.length; i++) {
111
- if (a[i] !== b[i])
112
- return false;
113
- }
114
- return true;
115
- }
116
- it("should match utxolib when creating from base58 xpub", () => {
117
- const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
118
- const wasmKey = bip32.BIP32.fromBase58(xpub);
119
- const utxolibKey = utxolibBip32.fromBase58(xpub);
120
- // Compare all properties
121
- assert.strictEqual(wasmKey.toBase58(), utxolibKey.toBase58());
122
- assert.strictEqual(wasmKey.depth, utxolibKey.depth);
123
- assert.strictEqual(wasmKey.index, utxolibKey.index);
124
- assert.strictEqual(wasmKey.parentFingerprint, utxolibKey.parentFingerprint);
125
- assert.strictEqual(wasmKey.isNeutered(), utxolibKey.isNeutered());
126
- assert.ok(bufferEqual(wasmKey.chainCode, utxolibKey.chainCode));
127
- assert.ok(bufferEqual(wasmKey.publicKey, utxolibKey.publicKey));
128
- assert.ok(bufferEqual(wasmKey.identifier, utxolibKey.identifier));
129
- assert.ok(bufferEqual(wasmKey.fingerprint, utxolibKey.fingerprint));
130
- });
131
- it("should match utxolib when creating from base58 xprv", () => {
132
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
133
- const wasmKey = bip32.BIP32.fromBase58(xprv);
134
- const utxolibKey = utxolibBip32.fromBase58(xprv);
135
- // Compare all properties
136
- assert.strictEqual(wasmKey.toBase58(), utxolibKey.toBase58());
137
- assert.strictEqual(wasmKey.depth, utxolibKey.depth);
138
- assert.strictEqual(wasmKey.index, utxolibKey.index);
139
- assert.strictEqual(wasmKey.parentFingerprint, utxolibKey.parentFingerprint);
140
- assert.strictEqual(wasmKey.isNeutered(), utxolibKey.isNeutered());
141
- assert.ok(bufferEqual(wasmKey.chainCode, utxolibKey.chainCode));
142
- assert.ok(bufferEqual(wasmKey.publicKey, utxolibKey.publicKey));
143
- assert.ok(bufferEqual(wasmKey.identifier, utxolibKey.identifier));
144
- assert.ok(bufferEqual(wasmKey.fingerprint, utxolibKey.fingerprint));
145
- assert.ok(wasmKey.privateKey &&
146
- utxolibKey.privateKey &&
147
- bufferEqual(wasmKey.privateKey, utxolibKey.privateKey));
148
- });
149
- it("should match utxolib when deriving normal child keys", () => {
150
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
151
- const wasmKey = bip32.BIP32.fromBase58(xprv);
152
- const utxolibKey = utxolibBip32.fromBase58(xprv);
153
- // Derive several children and compare
154
- for (const index of [0, 1, 10, 100, 2147483647]) {
155
- const wasmChild = wasmKey.derive(index);
156
- const utxolibChild = utxolibKey.derive(index);
157
- assert.strictEqual(wasmChild.toBase58(), utxolibChild.toBase58(), `Failed at index ${index}`);
158
- assert.ok(bufferEqual(wasmChild.publicKey, utxolibChild.publicKey));
159
- assert.ok(bufferEqual(wasmChild.chainCode, utxolibChild.chainCode));
160
- }
161
- });
162
- it("should match utxolib when deriving hardened child keys", () => {
163
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
164
- const wasmKey = bip32.BIP32.fromBase58(xprv);
165
- const utxolibKey = utxolibBip32.fromBase58(xprv);
166
- // Derive several hardened children and compare
167
- for (const index of [0, 1, 10, 2147483647]) {
168
- const wasmChild = wasmKey.deriveHardened(index);
169
- const utxolibChild = utxolibKey.deriveHardened(index);
170
- assert.strictEqual(wasmChild.toBase58(), utxolibChild.toBase58(), `Failed at hardened index ${index}`);
171
- assert.ok(bufferEqual(wasmChild.publicKey, utxolibChild.publicKey));
172
- assert.ok(bufferEqual(wasmChild.chainCode, utxolibChild.chainCode));
173
- }
174
- });
175
- it("should match utxolib when deriving using paths", () => {
176
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
177
- const wasmKey = bip32.BIP32.fromBase58(xprv);
178
- const utxolibKey = utxolibBip32.fromBase58(xprv);
179
- const paths = ["0", "0/1", "0/1/2", "m/0/1/2", "0'/1", "m/44'/0'/0'", "m/44'/0'/0'/0/0"];
180
- for (const path of paths) {
181
- const wasmDerived = wasmKey.derivePath(path);
182
- const utxolibDerived = utxolibKey.derivePath(path);
183
- assert.strictEqual(wasmDerived.toBase58(), utxolibDerived.toBase58(), `Failed at path ${path}`);
184
- assert.ok(bufferEqual(wasmDerived.publicKey, utxolibDerived.publicKey));
185
- assert.ok(bufferEqual(wasmDerived.chainCode, utxolibDerived.chainCode));
186
- }
187
- });
188
- it("should match utxolib when deriving from public keys", () => {
189
- const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
190
- const wasmKey = bip32.BIP32.fromBase58(xpub);
191
- const utxolibKey = utxolibBip32.fromBase58(xpub);
192
- // Derive several children from public key
193
- for (const index of [0, 1, 10, 100]) {
194
- const wasmChild = wasmKey.derive(index);
195
- const utxolibChild = utxolibKey.derive(index);
196
- assert.strictEqual(wasmChild.toBase58(), utxolibChild.toBase58());
197
- assert.ok(bufferEqual(wasmChild.publicKey, utxolibChild.publicKey));
198
- }
199
- });
200
- it("should match utxolib when neutering", () => {
201
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
202
- const wasmKey = bip32.BIP32.fromBase58(xprv);
203
- const utxolibKey = utxolibBip32.fromBase58(xprv);
204
- const wasmNeutered = wasmKey.neutered();
205
- const utxolibNeutered = utxolibKey.neutered();
206
- assert.strictEqual(wasmNeutered.toBase58(), utxolibNeutered.toBase58());
207
- assert.ok(bufferEqual(wasmNeutered.publicKey, utxolibNeutered.publicKey));
208
- assert.ok(bufferEqual(wasmNeutered.chainCode, utxolibNeutered.chainCode));
209
- assert.strictEqual(wasmNeutered.privateKey, undefined);
210
- });
211
- it("should match utxolib when exporting to WIF", () => {
212
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
213
- const wasmKey = bip32.BIP32.fromBase58(xprv);
214
- const utxolibKey = utxolibBip32.fromBase58(xprv);
215
- assert.strictEqual(wasmKey.toWIF(), utxolibKey.toWIF());
216
- });
217
- it("should match utxolib for BIP44 wallet derivation (m/44'/0'/0'/0/0)", () => {
218
- const seed = Buffer.from("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542", "hex");
219
- const wasmMaster = bip32.BIP32.fromSeed(seed);
220
- const utxolibMaster = utxolibBip32.fromSeed(seed);
221
- // Standard BIP44 path for Bitcoin: m/44'/0'/0'/0/0
222
- const path = "m/44'/0'/0'/0/0";
223
- const wasmDerived = wasmMaster.derivePath(path);
224
- const utxolibDerived = utxolibMaster.derivePath(path);
225
- assert.strictEqual(wasmDerived.toBase58(), utxolibDerived.toBase58());
226
- assert.ok(bufferEqual(wasmDerived.publicKey, utxolibDerived.publicKey));
227
- assert.ok(bufferEqual(wasmDerived.chainCode, utxolibDerived.chainCode));
228
- });
229
- it("should produce same fingerprint for derived keys", () => {
230
- const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
231
- const wasmKey = bip32.BIP32.fromBase58(xprv);
232
- const utxolibKey = utxolibBip32.fromBase58(xprv);
233
- // Derive a child and check its parent fingerprint matches the parent's fingerprint
234
- const wasmChild = wasmKey.derive(0);
235
- const utxolibChild = utxolibKey.derive(0);
236
- // Parent fingerprints should match
237
- assert.strictEqual(wasmChild.parentFingerprint, utxolibChild.parentFingerprint);
238
- // The parent fingerprint should match the parent's fingerprint
239
- const wasmParentFp = new DataView(wasmKey.fingerprint.buffer).getUint32(0, false);
240
- assert.strictEqual(wasmChild.parentFingerprint, wasmParentFp);
241
- });
242
- });
@@ -1,25 +0,0 @@
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
- };