@bitgo/wasm-utxo 1.34.0 → 1.36.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 (44) hide show
  1. package/dist/cjs/js/bip32.d.ts +19 -0
  2. package/dist/cjs/js/bip32.js +29 -0
  3. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +8 -6
  4. package/dist/cjs/js/index.d.ts +7 -1
  5. package/dist/cjs/js/index.js +2 -2
  6. package/dist/cjs/js/message.d.ts +36 -0
  7. package/dist/cjs/js/message.js +47 -0
  8. package/dist/cjs/js/testutils/descriptor/descriptors.d.ts +27 -0
  9. package/dist/cjs/js/testutils/descriptor/descriptors.js +163 -0
  10. package/dist/cjs/js/testutils/descriptor/index.d.ts +2 -0
  11. package/dist/cjs/js/testutils/descriptor/index.js +18 -0
  12. package/dist/cjs/js/testutils/descriptor/mockPsbt.d.ts +41 -0
  13. package/dist/cjs/js/testutils/descriptor/mockPsbt.js +62 -0
  14. package/dist/cjs/js/testutils/fixtures.d.ts +35 -0
  15. package/dist/cjs/js/testutils/fixtures.js +244 -0
  16. package/dist/cjs/js/testutils/index.d.ts +2 -0
  17. package/dist/cjs/js/testutils/index.js +25 -0
  18. package/dist/cjs/js/wasm/wasm_utxo.d.ts +1417 -1331
  19. package/dist/cjs/js/wasm/wasm_utxo.js +2093 -1996
  20. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  21. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +114 -108
  22. package/dist/esm/js/bip32.d.ts +19 -0
  23. package/dist/esm/js/bip32.js +29 -0
  24. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +8 -6
  25. package/dist/esm/js/index.d.ts +7 -1
  26. package/dist/esm/js/index.js +1 -1
  27. package/dist/esm/js/message.d.ts +36 -0
  28. package/dist/esm/js/message.js +43 -0
  29. package/dist/esm/js/testutils/descriptor/descriptors.d.ts +27 -0
  30. package/dist/esm/js/testutils/descriptor/descriptors.js +150 -0
  31. package/dist/esm/js/testutils/descriptor/index.d.ts +2 -0
  32. package/dist/esm/js/testutils/descriptor/index.js +2 -0
  33. package/dist/esm/js/testutils/descriptor/mockPsbt.d.ts +41 -0
  34. package/dist/esm/js/testutils/descriptor/mockPsbt.js +56 -0
  35. package/dist/esm/js/testutils/fixtures.d.ts +35 -0
  36. package/dist/esm/js/testutils/fixtures.js +205 -0
  37. package/dist/esm/js/testutils/index.d.ts +2 -0
  38. package/dist/esm/js/testutils/index.js +2 -0
  39. package/dist/esm/js/wasm/wasm_utxo.d.ts +1417 -1331
  40. package/dist/esm/js/wasm/wasm_utxo.js +7 -2
  41. package/dist/esm/js/wasm/wasm_utxo_bg.js +2096 -2008
  42. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  43. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +114 -108
  44. package/package.json +11 -1
@@ -0,0 +1,244 @@
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.getFixture = getFixture;
37
+ exports.jsonNormalize = jsonNormalize;
38
+ exports.matchPath = matchPath;
39
+ exports.toPlainObject = toPlainObject;
40
+ /// <reference types="node" />
41
+ /**
42
+ * Generic test fixture and serialization utilities.
43
+ * Ported from @bitgo/utxo-core/testutil/fixtures.utils.ts
44
+ * and @bitgo/utxo-core/testutil/toPlainObject.utils.ts.
45
+ *
46
+ * NOTE: getFixture requires Node.js (fs, process.env).
47
+ * The toPlainObject / jsonNormalize utilities are platform-independent.
48
+ */
49
+ const fs = __importStar(require("fs"));
50
+ const mpath = __importStar(require("path"));
51
+ function isNodeJsError(e) {
52
+ return e instanceof Error && typeof e.code === "string";
53
+ }
54
+ function fixtureEncoding(path) {
55
+ if (path.endsWith(".json")) {
56
+ return "json";
57
+ }
58
+ if (path.endsWith(".hex")) {
59
+ return "hex";
60
+ }
61
+ if (path.endsWith(".txt")) {
62
+ return "txt";
63
+ }
64
+ throw new Error(`unknown fixture encoding for ${path}`);
65
+ }
66
+ function hexToBytes(hex) {
67
+ const bytes = new Uint8Array(hex.length / 2);
68
+ for (let i = 0; i < hex.length; i += 2) {
69
+ bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
70
+ }
71
+ return bytes;
72
+ }
73
+ function bytesToHex(bytes) {
74
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
75
+ }
76
+ function decodeFixture(raw, encoding) {
77
+ switch (encoding) {
78
+ case "json":
79
+ return JSON.parse(raw);
80
+ case "hex":
81
+ return hexToBytes(raw);
82
+ case "txt":
83
+ return raw;
84
+ }
85
+ }
86
+ function encodeFixture(value, encoding) {
87
+ switch (encoding) {
88
+ case "json":
89
+ return JSON.stringify(value, null, 2) + "\n";
90
+ case "hex":
91
+ if (!(value instanceof Uint8Array)) {
92
+ throw new Error(`expected Uint8Array, got ${typeof value}`);
93
+ }
94
+ return bytesToHex(value);
95
+ case "txt":
96
+ if (typeof value !== "string") {
97
+ throw new Error(`expected string, got ${typeof value}`);
98
+ }
99
+ return value;
100
+ }
101
+ }
102
+ /**
103
+ * Return fixture described in `path`.
104
+ *
105
+ * If the file does not exist and `defaultValue` is provided,
106
+ * writes defaultValue to `path` and throws an error prompting
107
+ * the developer to inspect and re-run.
108
+ *
109
+ * @param path - Path to the fixture file (.json, .hex, or .txt)
110
+ * @param defaultValue - Default value to write if fixture is missing
111
+ * @returns The fixture content
112
+ */
113
+ async function getFixture(path, defaultValue) {
114
+ try {
115
+ await fs.promises.stat(mpath.dirname(path));
116
+ }
117
+ catch (e) {
118
+ if (isNodeJsError(e) && e.code === "ENOENT") {
119
+ throw new Error(`fixture directory ${mpath.dirname(path)} not found, please create it first`);
120
+ }
121
+ throw e;
122
+ }
123
+ const encoding = fixtureEncoding(path);
124
+ try {
125
+ return decodeFixture(await fs.promises.readFile(path, "utf8"), encoding);
126
+ }
127
+ catch (e) {
128
+ if (isNodeJsError(e) && e.code === "ENOENT") {
129
+ // eslint-disable-next-line no-restricted-globals
130
+ if (process.env.WRITE_FIXTURES === "0") {
131
+ throw new Error(`fixture ${path} not found, WRITE_FIXTURES=0`);
132
+ }
133
+ if (defaultValue === undefined) {
134
+ throw new Error(`fixture ${path} not found and no default value given`);
135
+ }
136
+ if (typeof defaultValue === "function") {
137
+ defaultValue = await defaultValue();
138
+ }
139
+ await fs.promises.writeFile(path, encodeFixture(defaultValue, encoding));
140
+ throw new Error(`wrote default value for ${path}, please inspect and restart test`);
141
+ }
142
+ throw e;
143
+ }
144
+ }
145
+ /**
146
+ * JSON round-trip normalization.
147
+ * Converts a value to JSON and back, stripping non-serializable properties
148
+ * and normalizing types (e.g. undefined -> null in arrays).
149
+ */
150
+ function jsonNormalize(v) {
151
+ return JSON.parse(JSON.stringify(v));
152
+ }
153
+ function matchPath(a, b) {
154
+ return a.length === b.length && a.every((e, i) => e === b[i]);
155
+ }
156
+ function includePath(opts, path) {
157
+ if (!opts.ignorePaths) {
158
+ return true;
159
+ }
160
+ if (typeof opts.ignorePaths === "function") {
161
+ return !opts.ignorePaths(path);
162
+ }
163
+ return !opts.ignorePaths.some((ignorePath) => matchPath(path, ignorePath.split(".")));
164
+ }
165
+ function toPlainEntries(key, value, opts, path) {
166
+ if (!includePath(opts, [...path, key])) {
167
+ return [];
168
+ }
169
+ if (value === undefined && (opts.skipUndefinedValues ?? true)) {
170
+ return [];
171
+ }
172
+ return [[key, toPlainObject(value, opts, [...path, key])]];
173
+ }
174
+ function getAllPropertyDescriptors(v) {
175
+ if (v === null || typeof v !== "object") {
176
+ return {};
177
+ }
178
+ const descriptors = Object.getOwnPropertyDescriptors(v);
179
+ const proto = Object.getPrototypeOf(v);
180
+ if (proto) {
181
+ Object.assign(descriptors, getAllPropertyDescriptors(proto));
182
+ }
183
+ return descriptors;
184
+ }
185
+ function toPlainObjectFromPropertyDescriptors(v, opts, path) {
186
+ const descriptors = getAllPropertyDescriptors(v);
187
+ return Object.fromEntries(Object.entries(descriptors).flatMap(([key, descriptor]) => {
188
+ if (typeof descriptor.value === "function") {
189
+ return [];
190
+ }
191
+ if (descriptor.value !== undefined) {
192
+ return toPlainEntries(key, descriptor.value, opts, path);
193
+ }
194
+ if (typeof descriptor.get === "function") {
195
+ return toPlainEntries(key, descriptor.get.call(v), opts, path);
196
+ }
197
+ return [];
198
+ }));
199
+ }
200
+ /**
201
+ * Recursively convert a value to a plain JSON-serializable object.
202
+ * Handles Uint8Array (to hex), bigint (to string), Buffer, and more.
203
+ *
204
+ * @param v - The value to convert
205
+ * @param opts - Options for customizing the conversion
206
+ * @param path - Current property path (used for ignorePaths)
207
+ */
208
+ function toPlainObject(v, opts = {}, path = []) {
209
+ if (opts.apply) {
210
+ const result = opts.apply(v, path);
211
+ if (result !== undefined) {
212
+ return result;
213
+ }
214
+ }
215
+ switch (typeof v) {
216
+ case "string":
217
+ case "number":
218
+ case "boolean":
219
+ case "undefined":
220
+ return v;
221
+ case "bigint":
222
+ return v.toString();
223
+ case "function":
224
+ case "symbol":
225
+ return undefined;
226
+ }
227
+ if (v === null) {
228
+ return v;
229
+ }
230
+ if (v instanceof Uint8Array) {
231
+ return Array.from(v, (b) => b.toString(16).padStart(2, "0")).join("");
232
+ }
233
+ if (Array.isArray(v)) {
234
+ return v.map((e, i) => toPlainObject(e, opts, [...path, i]));
235
+ }
236
+ if (typeof v === "object") {
237
+ const result = Object.fromEntries(Object.entries(v).flatMap(([key, value]) => toPlainEntries(key, value, opts, path)));
238
+ if (opts.propertyDescriptors) {
239
+ Object.assign(result, toPlainObjectFromPropertyDescriptors(v, opts, path));
240
+ }
241
+ return result;
242
+ }
243
+ throw new Error(`unknown v ${typeof v}`);
244
+ }
@@ -1,2 +1,4 @@
1
1
  export * from "./keys.js";
2
2
  export * from "./AcidTest.js";
3
+ export * from "./fixtures.js";
4
+ export * as descriptor from "./descriptor/index.js";
@@ -10,9 +10,34 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
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
+ });
13
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
20
  };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
16
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.descriptor = void 0;
17
40
  __exportStar(require("./keys.js"), exports);
18
41
  __exportStar(require("./AcidTest.js"), exports);
42
+ __exportStar(require("./fixtures.js"), exports);
43
+ exports.descriptor = __importStar(require("./descriptor/index.js"));