zeldwallet 0.1.6 → 0.1.8

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.
@@ -5,7 +5,7 @@
5
5
  "Ouziel Slama <ouziel@gmail.com>"
6
6
  ],
7
7
  "description": "WASM bindings for the Zeldhash miner with optional WebGPU acceleration",
8
- "version": "0.2.2",
8
+ "version": "0.2.3",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/dist/worker.js CHANGED
@@ -1,152 +1,4 @@
1
- var u = /* @__PURE__ */ ((t) => (t.INVALID_ADDRESS = "INVALID_ADDRESS", t.UNSUPPORTED_ADDRESS_TYPE = "UNSUPPORTED_ADDRESS_TYPE", t.INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS", t.NO_CHANGE_OUTPUT = "NO_CHANGE_OUTPUT", t.MULTIPLE_CHANGE_OUTPUTS = "MULTIPLE_CHANGE_OUTPUTS", t.INVALID_INPUT = "INVALID_INPUT", t.WEBGPU_NOT_AVAILABLE = "WEBGPU_NOT_AVAILABLE", t.WORKER_ERROR = "WORKER_ERROR", t.MINING_ABORTED = "MINING_ABORTED", t.DUST_OUTPUT = "DUST_OUTPUT", t))(u || {});
2
- const R = (1n << 64n) - 1n, K = (t) => {
3
- if (t < 0n)
4
- throw new Error("nonce must be non-negative");
5
- if (t === 0n) return 1;
6
- let e = 0, n = t;
7
- for (; n > 0n; )
8
- e += 1, n >>= 8n;
9
- return e;
10
- }, H = (t) => {
11
- if (t < 0n)
12
- throw new Error("nonce must be non-negative");
13
- if (t <= 23n) return 1;
14
- if (t <= 0xffn) return 2;
15
- if (t <= 0xffffn) return 3;
16
- if (t <= 0xffffffffn) return 5;
17
- if (t <= R) return 9;
18
- throw new Error("nonce range exceeds u64");
19
- }, X = (t) => {
20
- if (!Number.isInteger(t) || t <= 0 || t > 8)
21
- throw new Error("nonceLength must be between 1 and 8");
22
- return (1n << BigInt(t * 8)) - 1n;
23
- }, j = (t) => {
24
- switch (t) {
25
- case 1:
26
- return 23n;
27
- case 2:
28
- return 0xffn;
29
- case 3:
30
- return 0xffffn;
31
- case 5:
32
- return 0xffffffffn;
33
- case 9:
34
- return R;
35
- default:
36
- throw new Error("cbor nonceLength must be one of 1, 2, 3, 5, 9");
37
- }
38
- }, Y = (t, e) => {
39
- if (t < 0n)
40
- throw new Error("startNonce must be non-negative");
41
- if (!Number.isInteger(e) || e <= 0)
42
- throw new Error("batchSize must be a positive integer");
43
- const n = t + BigInt(e - 1);
44
- if (n > R)
45
- throw new Error("nonce range exceeds u64");
46
- const i = [];
47
- let r = t;
48
- for (; r <= n; ) {
49
- const s = K(r), o = X(s), a = n < o ? n : o, l = a - r + 1n;
50
- if (l > BigInt(Number.MAX_SAFE_INTEGER))
51
- throw new Error("segment size exceeds safe integer range");
52
- if (i.push({
53
- start: r,
54
- size: Number(l),
55
- nonceLength: s
56
- }), a === n)
57
- break;
58
- r = a + 1n;
59
- }
60
- return i;
61
- }, J = (t, e) => {
62
- if (t < 0n)
63
- throw new Error("startNonce must be non-negative");
64
- if (!Number.isInteger(e) || e <= 0)
65
- throw new Error("batchSize must be a positive integer");
66
- const n = t + BigInt(e - 1);
67
- if (n > R)
68
- throw new Error("nonce range exceeds u64");
69
- const i = [];
70
- let r = t;
71
- for (; r <= n; ) {
72
- const s = H(r), o = j(s), a = n < o ? n : o, l = a - r + 1n;
73
- if (l > BigInt(Number.MAX_SAFE_INTEGER))
74
- throw new Error("segment size exceeds safe integer range");
75
- if (i.push({
76
- start: r,
77
- size: Number(l),
78
- nonceLength: s
79
- }), a === n)
80
- break;
81
- r = a + 1n;
82
- }
83
- return i;
84
- }, Q = {};
85
- if (typeof globalThis.__ZELDMINER_WASM_BASE__ > "u")
86
- try {
87
- const t = typeof window < "u" && window.location?.origin ? window.location.origin : typeof self < "u" && self.location?.origin ? self.location.origin : "http://localhost";
88
- globalThis.__ZELDMINER_WASM_BASE__ = new URL("/wasm/", t).href;
89
- } catch {
90
- globalThis.__ZELDMINER_WASM_BASE__ = "/wasm/";
91
- }
92
- let y = null, d = null, O = !1;
93
- const Z = () => {
94
- if (O) return;
95
- O = !0;
96
- const t = globalThis.GPUAdapter?.prototype, e = t?.requestDevice;
97
- !t || typeof e != "function" || (t.requestDevice = function(i) {
98
- if (i?.requiredLimits && typeof this.limits == "object") {
99
- const r = i.requiredLimits, s = this.limits;
100
- for (const o of Object.keys(r))
101
- (!(o in s) || s[o] === void 0) && delete r[o];
102
- }
103
- return e.call(this, i);
104
- });
105
- }, U = (t) => t.endsWith("/") ? t : `${t}/`, A = (t) => {
106
- const e = t.trim();
107
- return e && (typeof window < "u" && typeof window.location?.origin == "string" ? U(new URL(e, window.location.origin).href) : U(new URL(e, import.meta.url).href));
108
- }, tt = () => {
109
- const t = globalThis.__ZELDMINER_WASM_BASE__;
110
- if (typeof t == "string" && t.trim())
111
- return A(t);
112
- const e = Q?.VITE_ZELDMINER_WASM_BASE;
113
- if (typeof e == "string" && e.trim())
114
- return A(e);
115
- const n = "./";
116
- return n.trim() ? A(`${U(n.trim())}wasm/`) : A("/wasm/");
117
- }, z = tt(), W = `${z}zeldhash_miner_wasm.js`, et = `${z}zeldhash_miner_wasm_bg.wasm`, x = (t) => t instanceof Error ? t.message : String(t), nt = async () => {
118
- Z();
119
- let t;
120
- try {
121
- t = await import(
122
- /* @vite-ignore */
123
- W
124
- );
125
- } catch (i) {
126
- throw new Error(
127
- `Failed to import WASM bundle (${W}). Did you run ./scripts/build-wasm.sh? (${x(i)})`
128
- );
129
- }
130
- const e = t.default;
131
- if (typeof e != "function")
132
- throw new Error("WASM init function is missing from the bundle.");
133
- try {
134
- const i = new URL(et, import.meta.url);
135
- await e({ module_or_path: i });
136
- } catch (i) {
137
- throw new Error(
138
- `Failed to initialize WASM bundle: ${x(i)}`
139
- );
140
- }
141
- const n = t;
142
- try {
143
- n.init_panic_hook?.();
144
- } catch {
145
- }
146
- return n;
147
- }, it = async () => y || (d || (d = nt().then((t) => (y = t, t)).catch((t) => {
148
- throw d = null, t;
149
- })), d);
1
+ import { Z as r, l as C, s as U, a as V } from "./nonce.js";
150
2
  if (typeof globalThis.__ZELDMINER_WASM_BASE__ > "u")
151
3
  try {
152
4
  const t = typeof self < "u" && self.location?.origin ? self.location.origin : "http://localhost";
@@ -154,200 +6,200 @@ if (typeof globalThis.__ZELDMINER_WASM_BASE__ > "u")
154
6
  } catch {
155
7
  globalThis.__ZELDMINER_WASM_BASE__ = "/wasm/";
156
8
  }
157
- const B = self, rt = B.name ?? void 0, I = (t) => t instanceof Error ? t.message : String(t);
158
- let N = "cpu", b = null;
159
- const w = (t) => {
160
- B.postMessage({ ...t, workerId: rt });
161
- }, h = (t, e = u.WORKER_ERROR, n) => {
162
- w({ type: "error", message: t, code: e, details: n });
163
- }, ot = (t) => typeof t == "object" && t !== null && "ok" in t, st = (t) => typeof t == "object" && t !== null && "nonce" in t && "txid" in t, at = (t) => {
9
+ const w = self, G = w.name ?? void 0, R = (t) => t instanceof Error ? t.message : String(t);
10
+ let m = "cpu", f = null;
11
+ const g = (t) => {
12
+ w.postMessage({ ...t, workerId: G });
13
+ }, b = (t, e = r.WORKER_ERROR, n) => {
14
+ g({ type: "error", message: t, code: e, details: n });
15
+ }, D = (t) => typeof t == "object" && t !== null && "ok" in t, F = (t) => typeof t == "object" && t !== null && "nonce" in t && "txid" in t, K = (t) => {
164
16
  const e = BigInt(Number.MAX_SAFE_INTEGER);
165
17
  return t > e ? Number.MAX_SAFE_INTEGER : t < -e ? -Number.MAX_SAFE_INTEGER : Number(t);
166
- }, ct = (t) => ({
18
+ }, Z = (t) => ({
167
19
  nonceLength: t.nonceLength,
168
20
  prefix: new Uint8Array(t.prefix),
169
21
  suffix: new Uint8Array(t.suffix),
170
22
  useCborNonce: t.useCborNonce
171
- }), F = (t, e) => {
172
- t.set(e.nonceLength, ct(e));
173
- }, ut = async (t, e, n, i, r) => {
174
- const s = t.get(i.nonceLength);
175
- if (s)
176
- return s;
177
- const o = e.build_mining_template(
23
+ }), M = (t, e) => {
24
+ t.set(e.nonceLength, Z(e));
25
+ }, $ = async (t, e, n, s, i) => {
26
+ const u = t.get(s.nonceLength);
27
+ if (u)
28
+ return u;
29
+ const p = e.build_mining_template(
178
30
  n.inputs,
179
31
  n.outputs,
180
- r,
32
+ i,
181
33
  BigInt(n.satsPerVbyte),
182
- i.start,
183
- i.size,
34
+ s.start,
35
+ s.size,
184
36
  n.distribution ?? null
185
37
  ), a = {
186
- ...o,
187
- nonceLength: i.nonceLength,
188
- useCborNonce: o.useCborNonce ?? n.useCborNonce
38
+ ...p,
39
+ nonceLength: s.nonceLength,
40
+ useCborNonce: p.useCborNonce ?? n.useCborNonce
189
41
  };
190
- return F(t, a), a;
191
- }, lt = async (t, e, n, i, r, s, o, a) => {
42
+ return M(t, a), a;
43
+ }, X = async (t, e, n, s, i, u, p, a) => {
192
44
  if (e === "gpu") {
193
45
  if (!t.mine_batch_gpu)
194
46
  throw new Error("GPU mining requested but mine_batch_gpu is unavailable");
195
47
  return t.mine_batch_gpu(
196
48
  n,
197
- i,
198
- r,
199
49
  s,
200
- o,
50
+ i,
51
+ u,
52
+ p,
201
53
  a
202
54
  );
203
55
  }
204
56
  return t.mine_batch_wasm(
205
57
  n,
206
- i,
207
- r,
208
58
  s,
209
- o,
59
+ i,
60
+ u,
61
+ p,
210
62
  a
211
63
  );
212
- }, ft = async (t, e) => {
64
+ }, j = async (t, e) => {
213
65
  let n;
214
66
  try {
215
- if (n = await it(), N === "gpu") {
67
+ if (n = await C(), m === "gpu") {
216
68
  if (!n.mine_batch_gpu) {
217
- h(
69
+ b(
218
70
  "GPU mining requested but mine_batch_gpu is unavailable",
219
- u.WEBGPU_NOT_AVAILABLE
71
+ r.WEBGPU_NOT_AVAILABLE
220
72
  );
221
73
  return;
222
74
  }
223
75
  n.init_gpu && await n.init_gpu();
224
76
  }
225
- } catch (m) {
226
- const g = I(m), E = N === "gpu" ? u.WEBGPU_NOT_AVAILABLE : u.WORKER_ERROR;
227
- h(`Failed to initialize WASM: ${g}`, E);
77
+ } catch (d) {
78
+ const _ = R(d), h = m === "gpu" ? r.WEBGPU_NOT_AVAILABLE : r.WORKER_ERROR;
79
+ b(`Failed to initialize WASM: ${_}`, h);
228
80
  return;
229
81
  }
230
- const i = /* @__PURE__ */ new Map(), r = t.template.useCborNonce ?? !!(t.distribution && t.distribution.length > 0);
231
- F(i, { ...t.template, useCborNonce: r });
232
- const s = t.nonceStep ?? BigInt(t.batchSize), o = t.network === "signet" ? "testnet" : t.network;
233
- let a = t.startNonce, l = 0n;
234
- const G = performance.now();
82
+ const s = /* @__PURE__ */ new Map(), i = t.template.useCborNonce ?? !!(t.distribution && t.distribution.length > 0);
83
+ M(s, { ...t.template, useCborNonce: i });
84
+ const u = t.nonceStep ?? BigInt(t.batchSize), p = t.network === "signet" ? "testnet" : t.network;
85
+ let a = t.startNonce, N = 0n;
86
+ const T = performance.now();
235
87
  for (; !e.signal.aborted; ) {
236
- const m = a;
237
- let g = t.batchSize, E = 0n;
238
- for (; g > 0 && !e.signal.aborted; ) {
239
- const D = m + E;
240
- let c;
88
+ const d = a;
89
+ let _ = t.batchSize, h = 0n;
90
+ for (; _ > 0 && !e.signal.aborted; ) {
91
+ const B = d + h;
92
+ let o;
241
93
  try {
242
- c = (r ? J(D, g) : Y(D, g))[0];
243
- } catch (_) {
244
- h(
245
- `Invalid nonce range: ${I(_)}`,
246
- u.INVALID_INPUT
94
+ o = (i ? U(B, _) : V(B, _))[0];
95
+ } catch (l) {
96
+ b(
97
+ `Invalid nonce range: ${R(l)}`,
98
+ r.INVALID_INPUT
247
99
  ), e.abort();
248
100
  return;
249
101
  }
250
- let S;
102
+ let I;
251
103
  try {
252
- S = await ut(
253
- i,
104
+ I = await $(
105
+ s,
254
106
  n,
255
107
  {
256
108
  inputs: t.inputs,
257
109
  outputs: t.outputs,
258
110
  satsPerVbyte: t.satsPerVbyte,
259
111
  distribution: t.distribution,
260
- useCborNonce: r
112
+ useCborNonce: i
261
113
  },
262
- c,
263
- o
114
+ o,
115
+ p
264
116
  );
265
- } catch (_) {
266
- h(
267
- `Failed to build mining template: ${I(_)}`,
268
- u.WORKER_ERROR
117
+ } catch (l) {
118
+ b(
119
+ `Failed to build mining template: ${R(l)}`,
120
+ r.WORKER_ERROR
269
121
  ), e.abort();
270
122
  return;
271
123
  }
272
- let f;
273
- const k = performance.now();
124
+ let c;
125
+ const O = performance.now();
274
126
  try {
275
- f = await lt(
127
+ c = await X(
276
128
  n,
277
- N,
278
- S.prefix,
279
- S.suffix,
280
- c.start,
281
- c.size,
129
+ m,
130
+ I.prefix,
131
+ I.suffix,
132
+ o.start,
133
+ o.size,
282
134
  t.targetZeros,
283
- r
135
+ i
284
136
  );
285
- } catch (_) {
286
- const p = I(_);
287
- h(
288
- `Batch mining failed: ${p}`,
289
- u.WORKER_ERROR
137
+ } catch (l) {
138
+ const E = R(l);
139
+ b(
140
+ `Batch mining failed: ${E}`,
141
+ r.WORKER_ERROR
290
142
  ), e.abort();
291
143
  return;
292
144
  }
293
- const P = performance.now() - k;
294
- if (ot(f)) {
295
- if (!f.ok) {
296
- h(
297
- f.error ?? "Validation failed",
298
- u.INVALID_INPUT
145
+ const S = performance.now() - O;
146
+ if (D(c)) {
147
+ if (!c.ok) {
148
+ b(
149
+ c.error ?? "Validation failed",
150
+ r.INVALID_INPUT
299
151
  ), e.abort();
300
152
  return;
301
153
  }
302
- } else if (st(f)) {
303
- const _ = l + E, p = BigInt(f.nonce) - c.start + 1n, L = _ + p, T = performance.now() - G, M = T > 0 ? at(L) / (T / 1e3) : 0, q = c.start + p - 1n, C = {
154
+ } else if (F(c)) {
155
+ const l = N + h, E = BigInt(c.nonce) - o.start + 1n, A = l + E, y = performance.now() - T, L = y > 0 ? K(A) / (y / 1e3) : 0, P = o.start + E - 1n, x = {
304
156
  psbt: "",
305
- txid: f.txid,
306
- nonce: BigInt(f.nonce),
307
- attempts: L,
308
- duration: T,
309
- hashRate: M
157
+ txid: c.txid,
158
+ nonce: BigInt(c.nonce),
159
+ attempts: A,
160
+ duration: y,
161
+ hashRate: L
310
162
  };
311
- w({
163
+ g({
312
164
  type: "found",
313
- result: C,
314
- hashesProcessed: L,
315
- hashRate: M,
316
- lastNonce: q
165
+ result: x,
166
+ hashesProcessed: A,
167
+ hashRate: L,
168
+ lastNonce: P
317
169
  }), e.abort();
318
170
  return;
319
171
  }
320
- l += BigInt(c.size), E += BigInt(c.size), g -= c.size;
321
- const v = P > 0 ? c.size / (P / 1e3) : c.size, $ = c.start + BigInt(c.size) - 1n;
322
- w({ type: "progress", hashesProcessed: l, hashRate: v, lastNonce: $ });
172
+ N += BigInt(o.size), h += BigInt(o.size), _ -= o.size;
173
+ const W = S > 0 ? o.size / (S / 1e3) : o.size, k = o.start + BigInt(o.size) - 1n;
174
+ g({ type: "progress", hashesProcessed: N, hashRate: W, lastNonce: k });
323
175
  }
324
176
  if (e.signal.aborted)
325
177
  break;
326
- const V = m + BigInt(t.batchSize) - 1n;
327
- w({ type: "batch_complete", lastNonce: V }), a = m + s;
178
+ const z = d + BigInt(t.batchSize) - 1n;
179
+ g({ type: "batch_complete", lastNonce: z }), a = d + u;
328
180
  }
329
- }, _t = (t) => {
181
+ }, q = (t) => {
330
182
  const e = new AbortController();
331
- b?.abort(), b = e, ft(t, e).finally(() => {
332
- b === e && (b = null);
183
+ f?.abort(), f = e, j(t, e).finally(() => {
184
+ f === e && (f = null);
333
185
  });
334
186
  };
335
- B.addEventListener("message", (t) => {
187
+ w.addEventListener("message", (t) => {
336
188
  const e = t.data;
337
189
  switch (e.type) {
338
190
  case "init":
339
- N = e.mode, w({ type: "ready" });
191
+ m = e.mode, g({ type: "ready" });
340
192
  break;
341
193
  case "mine":
342
- _t(e);
194
+ q(e);
343
195
  break;
344
196
  case "stop":
345
- b?.abort();
197
+ f?.abort();
346
198
  break;
347
199
  default:
348
- h(
200
+ b(
349
201
  `Unknown message type: ${e.type}`,
350
- u.WORKER_ERROR
202
+ r.WORKER_ERROR
351
203
  );
352
204
  }
353
205
  });
@@ -15476,7 +15476,7 @@ class UC {
15476
15476
  `, document.head.appendChild(t);
15477
15477
  }
15478
15478
  }
15479
- const OC = "0.1.6", zC = {
15479
+ const OC = "0.1.8", zC = {
15480
15480
  version: OC
15481
15481
  }, LC = zC.version, gg = ["getInfo", "getAddresses", "signMessage", "signPsbt"], qC = ["WBIP004", "WBIP005", "WBIP006"];
15482
15482
  class KC {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "overrides": {
4
4
  "valibot": "^1.2.0"
5
5
  },
6
- "version": "0.1.6",
6
+ "version": "0.1.8",
7
7
  "description": "Lightweight JavaScript library for creating a Bitcoin wallet directly in the browser",
8
8
  "type": "module",
9
9
  "main": "./dist/zeldwallet.es.js",
@@ -25,7 +25,7 @@
25
25
  "peerDependencies": {
26
26
  "react": "^18.2.0 || ^19.0.0",
27
27
  "react-dom": "^18.2.0 || ^19.0.0",
28
- "zeldhash-miner": "0.2.2"
28
+ "zeldhash-miner": "0.2.4"
29
29
  },
30
30
  "peerDependenciesMeta": {
31
31
  "react": {
@@ -101,6 +101,6 @@
101
101
  "vite-plugin-top-level-await": "^1.6.0",
102
102
  "vite-plugin-wasm": "^3.5.0",
103
103
  "vitest": "^4.0.16",
104
- "zeldhash-miner": "^0.2.2"
104
+ "zeldhash-miner": "^0.2.4"
105
105
  }
106
106
  }