@covia/covia-sdk 1.21.0 → 1.22.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/index.mjs CHANGED
@@ -137,134 +137,127 @@ var AgentSessionNotFoundError = class extends CoviaError {
137
137
  }
138
138
  };
139
139
 
140
- // node_modules/.pnpm/@noble+ed25519@3.1.0/node_modules/@noble/ed25519/index.js
141
- var ed25519_CURVE = Object.freeze({
142
- p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
143
- n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
140
+ // node_modules/.pnpm/@noble+ed25519@3.2.0/node_modules/@noble/ed25519/index.js
141
+ var freeze = Object.freeze;
142
+ var P = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn;
143
+ var N = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn;
144
+ var _d = 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n;
145
+ var Gx = 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an;
146
+ var Gy = 0x6666666666666666666666666666666666666666666666666666666666666658n;
147
+ var _a = P - 1n;
148
+ var ed25519_CURVE = freeze({
149
+ p: P,
150
+ n: N,
144
151
  h: 8n,
145
- a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
146
- d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
147
- Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
148
- Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
152
+ a: _a,
153
+ d: _d,
154
+ Gx,
155
+ Gy
149
156
  });
150
- var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
151
- var L = 32;
152
- var captureTrace = (...args) => {
153
- if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
154
- Error.captureStackTrace(...args);
155
- }
156
- };
157
- var err = (message = "") => {
158
- const e = new Error(message);
159
- captureTrace(e, err);
160
- throw e;
157
+ var LEN = 32;
158
+ var isBytes = (a) => {
159
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && a.BYTES_PER_ELEMENT === 1;
161
160
  };
162
- var isBig = (n) => typeof n === "bigint";
163
- var isStr = (s) => typeof s === "string";
164
- var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
165
161
  var abytes = (value, length, title = "") => {
162
+ if (isBytes(value) && (length === void 0 || value.length === length))
163
+ return value;
166
164
  const bytes2 = isBytes(value);
167
- const len = value?.length;
168
- const needsLen = length !== void 0;
169
- if (!bytes2 || needsLen && len !== length) {
170
- const prefix = title && `"${title}" `;
171
- const ofLen = needsLen ? ` of length ${length}` : "";
172
- const got = bytes2 ? `length=${len}` : `type=${typeof value}`;
173
- const msg = prefix + "expected Uint8Array" + ofLen + ", got " + got;
174
- throw bytes2 ? new RangeError(msg) : new TypeError(msg);
175
- }
176
- return value;
165
+ const ofLen = length !== void 0 ? ` of length ${length}` : "";
166
+ const got = bytes2 ? `length=${value.length}` : `type=${typeof value}`;
167
+ const message = (title ? `"${title}" ` : "") + "expected Uint8Array" + ofLen + ", got " + got;
168
+ if (!bytes2)
169
+ throw new TypeError(message);
170
+ throw new RangeError(message);
177
171
  };
178
- var u8n = (len) => new Uint8Array(len);
179
- var u8fr = (buf) => Uint8Array.from(buf);
172
+ var snapshotBytes = (value, title = "", length) => Uint8Array.from(abytes(value, length, title));
180
173
  var padh = (n, pad) => n.toString(16).padStart(pad, "0");
181
- var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
182
- var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
183
- var _ch = (ch) => {
184
- if (ch >= C._0 && ch <= C._9)
185
- return ch - C._0;
186
- if (ch >= C.A && ch <= C.F)
187
- return ch - (C.A - 10);
188
- if (ch >= C.a && ch <= C.f)
189
- return ch - (C.a - 10);
190
- return;
174
+ var bytesToHex = (bytes2) => {
175
+ let hex = "";
176
+ for (const byte of abytes(bytes2))
177
+ hex += padh(byte, 2);
178
+ return hex;
191
179
  };
192
180
  var hexToBytes = (hex) => {
193
181
  const e = "hex invalid";
194
- if (!isStr(hex))
195
- return err(e);
196
- const hl = hex.length;
197
- const al = hl / 2;
198
- if (hl % 2)
199
- return err(e);
200
- const array = u8n(al);
201
- for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
202
- const n1 = _ch(hex.charCodeAt(hi));
203
- const n2 = _ch(hex.charCodeAt(hi + 1));
204
- if (n1 === void 0 || n2 === void 0)
205
- return err(e);
206
- array[ai] = n1 * 16 + n2;
182
+ if (typeof hex !== "string")
183
+ throw new TypeError(e);
184
+ if (hex.length % 2 || !/^[\da-f]*$/i.test(hex))
185
+ throw new RangeError(e);
186
+ const array = new Uint8Array(hex.length / 2);
187
+ for (let ai = 0, hi = 0; ai < array.length; ai++, hi += 2) {
188
+ const n1 = hex.charCodeAt(hi);
189
+ const n2 = hex.charCodeAt(hi + 1);
190
+ array[ai] = ((n1 & 15) + (n1 >> 6) * 9) * 16 + (n2 & 15) + (n2 >> 6) * 9;
207
191
  }
208
192
  return array;
209
193
  };
210
- var cr = () => globalThis?.crypto;
211
- var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
212
- var concatBytes = (...arrs) => {
213
- let len = 0;
214
- for (const a of arrs)
215
- len += abytes(a).length;
216
- const r = u8n(len);
194
+ var concatBytes = (...arrays) => {
195
+ let sum = 0;
196
+ for (const a of arrays)
197
+ sum += abytes(a).length;
198
+ const res = new Uint8Array(sum);
217
199
  let pad = 0;
218
- arrs.forEach((a) => {
219
- r.set(a, pad);
200
+ for (const a of arrays) {
201
+ res.set(a, pad);
220
202
  pad += a.length;
221
- });
222
- return r;
203
+ }
204
+ return res;
223
205
  };
224
- var randomBytes = (len = L) => {
225
- const c = cr();
226
- return c.getRandomValues(u8n(len));
206
+ var randomBytes = (len = LEN) => {
207
+ const c = globalThis?.crypto;
208
+ if (typeof c?.getRandomValues !== "function")
209
+ throw new Error("crypto.getRandomValues must be defined, consider polyfill");
210
+ return c.getRandomValues(new Uint8Array(len));
227
211
  };
228
- var big = BigInt;
229
- var assertRange = (n, min, max, msg = "bad number: out of range") => {
230
- if (!isBig(n))
212
+ var arange = (n, min, max, msg = "bad number: out of range") => {
213
+ if (typeof n !== "bigint")
231
214
  throw new TypeError(msg);
232
215
  if (min <= n && n < max)
233
216
  return n;
234
217
  throw new RangeError(msg);
235
218
  };
236
- var M = (a, b = P) => {
237
- const r = a % b;
238
- return r >= 0n ? r : b + r;
239
- };
219
+ var mod = (a, b = P) => (a %= b) >= 0n ? a : b + a;
240
220
  var P_MASK = (1n << 255n) - 1n;
241
221
  var modP = (num) => {
242
222
  if (num < 0n)
243
- err("negative coordinate");
223
+ throw new RangeError("negative coordinate");
244
224
  let r = (num >> 255n) * 19n + (num & P_MASK);
245
225
  r = (r >> 255n) * 19n + (r & P_MASK);
246
226
  return r % P;
247
227
  };
248
- var modN = (a) => M(a, N);
249
- var invert = (num, md) => {
250
- if (num === 0n || md <= 0n)
251
- err("no inverse n=" + num + " mod=" + md);
252
- let a = M(num, md), b = md, x = 0n, u = 1n;
228
+ var modN = (a) => mod(a, N);
229
+ var invert = (number, modulo) => {
230
+ if (number === 0n)
231
+ throw new Error("invert: expected non-zero number");
232
+ if (modulo <= 1n)
233
+ throw new Error("invert: expected modulus > 1, got " + modulo);
234
+ let a = mod(number, modulo);
235
+ let b = modulo;
236
+ let x = 0n, u = 1n;
253
237
  while (a !== 0n) {
254
- const q = b / a, r = b % a;
238
+ const q = b / a;
239
+ const r = b - a * q;
255
240
  const m = x - u * q;
256
241
  b = a, a = r, x = u, u = m;
257
242
  }
258
- return b === 1n ? M(x, md) : err("no inverse");
243
+ const gcd = b;
244
+ if (gcd !== 1n)
245
+ throw new Error("invert: does not exist");
246
+ return mod(x, modulo);
259
247
  };
260
- var callHash = (name) => {
248
+ var _hash = (name) => {
261
249
  const fn = hashes[name];
262
250
  if (typeof fn !== "function")
263
- err("hashes." + name + " not set");
251
+ throw new Error("hashes." + name + " not set");
264
252
  return fn;
265
253
  };
266
- var checkDigest = (value) => abytes(value, 64, "digest");
267
- var apoint = (p) => p instanceof Point ? p : err("Point expected");
254
+ var callHash = (name, ...m) => abytes(_hash(name)(concatBytes(...m)), 64, "digest");
255
+ var callHashAsync = async (name, ...m) => abytes(await _hash(name)(concatBytes(...m)), 64, "digest");
256
+ var apoint = (p) => {
257
+ if (p instanceof Point)
258
+ return p;
259
+ throw new TypeError("Point expected");
260
+ };
268
261
  var B256 = 2n ** 256n;
269
262
  var _Point = class _Point {
270
263
  // Constructor only bounds-checks and freezes XYZT coordinates; it does not prove the point is
@@ -275,11 +268,11 @@ var _Point = class _Point {
275
268
  __publicField(this, "Z");
276
269
  __publicField(this, "T");
277
270
  const max = B256;
278
- this.X = assertRange(X, 0n, max);
279
- this.Y = assertRange(Y, 0n, max);
280
- this.Z = assertRange(Z, 1n, max);
281
- this.T = assertRange(T, 0n, max);
282
- Object.freeze(this);
271
+ this.X = arange(X, 0n, max);
272
+ this.Y = arange(Y, 0n, max);
273
+ this.Z = arange(Z, 1n, max);
274
+ this.T = arange(T, 0n, max);
275
+ freeze(this);
283
276
  }
284
277
  static CURVE() {
285
278
  return ed25519_CURVE;
@@ -287,27 +280,25 @@ var _Point = class _Point {
287
280
  static fromAffine(p) {
288
281
  return new _Point(p.x, p.y, 1n, modP(p.x * p.y));
289
282
  }
290
- /** RFC8032 5.1.3: Bytes to Point. */
291
- static fromBytes(hex, zip215 = false) {
292
- const d = _d;
293
- const normed = u8fr(abytes(hex, L));
294
- const lastByte = hex[31];
283
+ /** RFC8032 5.1.3: Uint8Array to Point. */
284
+ static fromBytes(bytes2, zip215 = false) {
285
+ const normed = snapshotBytes(bytes2, "point", LEN);
286
+ const lastByte = normed[31];
295
287
  normed[31] = lastByte & -129;
296
288
  const y = bytesToNumberLE(normed);
297
- const max = zip215 ? B256 : P;
298
- assertRange(y, 0n, max);
289
+ if (!zip215)
290
+ arange(y, 0n, P);
299
291
  const y2 = modP(y * y);
300
- const u = M(y2 - 1n);
301
- const v = modP(d * y2 + 1n);
292
+ const u = mod(y2 - 1n);
293
+ const v = modP(_d * y2 + 1n);
302
294
  let { isValid, value: x } = uvRatio(u, v);
303
295
  if (!isValid)
304
- err("bad point: y not sqrt");
305
- const isXOdd = (x & 1n) === 1n;
306
- const isLastByteOdd = (lastByte & 128) !== 0;
296
+ throw new Error("bad point: y not sqrt");
297
+ const isLastByteOdd = !!(lastByte & 128);
307
298
  if (!zip215 && x === 0n && isLastByteOdd)
308
- err("bad point: x==0, isLastByteOdd");
309
- if (isLastByteOdd !== isXOdd)
310
- x = M(-x);
299
+ throw new Error("bad point: x==0, isLastByteOdd");
300
+ if (isLastByteOdd !== !!(x & 1n))
301
+ x = mod(-x);
311
302
  return new _Point(x, y, 1n, modP(x * y));
312
303
  }
313
304
  static fromHex(hex, zip215) {
@@ -325,7 +316,7 @@ var _Point = class _Point {
325
316
  const d = _d;
326
317
  const p = this;
327
318
  if (p.is0())
328
- return err("bad point: ZERO");
319
+ throw new Error("bad point: ZERO");
329
320
  const { X, Y, Z, T } = p;
330
321
  const X2 = modP(X * X);
331
322
  const Y2 = modP(Y * Y);
@@ -333,31 +324,27 @@ var _Point = class _Point {
333
324
  const Z4 = modP(Z2 * Z2);
334
325
  const aX2 = modP(X2 * a);
335
326
  const left = modP(Z2 * (aX2 + Y2));
336
- const right = M(Z4 + modP(d * modP(X2 * Y2)));
327
+ const right = mod(Z4 + modP(d * modP(X2 * Y2)));
337
328
  if (left !== right)
338
- return err("bad point: equation left != right (1)");
329
+ throw new Error("bad point: equation left != right (1)");
339
330
  const XY = modP(X * Y);
340
331
  const ZT = modP(Z * T);
341
332
  if (XY !== ZT)
342
- return err("bad point: equation left != right (2)");
333
+ throw new Error("bad point: equation left != right (2)");
343
334
  return this;
344
335
  }
345
336
  /** Equality check: compare points P&Q. */
346
337
  equals(other) {
347
338
  const { X: X1, Y: Y1, Z: Z1 } = this;
348
339
  const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
349
- const X1Z2 = modP(X1 * Z2);
350
- const X2Z1 = modP(X2 * Z1);
351
- const Y1Z2 = modP(Y1 * Z2);
352
- const Y2Z1 = modP(Y2 * Z1);
353
- return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
340
+ return modP(X1 * Z2) === modP(X2 * Z1) && modP(Y1 * Z2) === modP(Y2 * Z1);
354
341
  }
355
342
  is0() {
356
343
  return this.equals(I);
357
344
  }
358
345
  /** Flip point over y coordinate. */
359
346
  negate() {
360
- return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
347
+ return new _Point(mod(-this.X), this.Y, this.Z, mod(-this.T));
361
348
  }
362
349
  /** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
363
350
  double() {
@@ -365,20 +352,20 @@ var _Point = class _Point {
365
352
  const a = _a;
366
353
  const A = modP(X1 * X1);
367
354
  const B = modP(Y1 * Y1);
368
- const C2 = modP(2n * Z1 * Z1);
355
+ const C = modP(2n * Z1 * Z1);
369
356
  const D = modP(a * A);
370
- const x1y1 = M(X1 + Y1);
371
- const E = M(modP(x1y1 * x1y1) - A - B);
372
- const G2 = M(D + B);
373
- const F = M(G2 - C2);
374
- const H = M(D - B);
357
+ const x1y1 = mod(X1 + Y1);
358
+ const E = mod(modP(x1y1 * x1y1) - A - B);
359
+ const G2 = mod(D + B);
360
+ const F = mod(G2 - C);
361
+ const H = mod(D - B);
375
362
  const X3 = modP(E * F);
376
363
  const Y3 = modP(G2 * H);
377
364
  const T3 = modP(E * H);
378
365
  const Z3 = modP(F * G2);
379
366
  return new _Point(X3, Y3, Z3, T3);
380
367
  }
381
- /** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
368
+ /** Point addition. Complete formula. Cost: `9M + 1*a + 1*d + 7add`. */
382
369
  add(other) {
383
370
  const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
384
371
  const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
@@ -386,12 +373,12 @@ var _Point = class _Point {
386
373
  const d = _d;
387
374
  const A = modP(X1 * X2);
388
375
  const B = modP(Y1 * Y2);
389
- const C2 = modP(modP(T1 * d) * T2);
376
+ const C = modP(modP(T1 * d) * T2);
390
377
  const D = modP(Z1 * Z2);
391
- const E = M(modP(M(X1 + Y1) * M(X2 + Y2)) - A - B);
392
- const F = M(D - C2);
393
- const G2 = M(D + C2);
394
- const H = M(B - modP(a * A));
378
+ const E = mod(modP(mod(X1 + Y1) * mod(X2 + Y2)) - A - B);
379
+ const F = mod(D - C);
380
+ const G2 = mod(D + C);
381
+ const H = mod(B - modP(a * A));
395
382
  const X3 = modP(E * F);
396
383
  const Y3 = modP(G2 * H);
397
384
  const T3 = modP(E * H);
@@ -412,7 +399,7 @@ var _Point = class _Point {
412
399
  multiply(n, safe = true) {
413
400
  if (!safe && n === 0n)
414
401
  return I;
415
- assertRange(n, 1n, N);
402
+ arange(n, 1n, N);
416
403
  if (!safe && this.is0())
417
404
  return I;
418
405
  if (n === 1n)
@@ -421,11 +408,14 @@ var _Point = class _Point {
421
408
  return wNAF(n).p;
422
409
  let p = I;
423
410
  let f = G;
424
- for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
411
+ let d = this;
412
+ for (let i = 0; safe ? i < 256 : n > 0n; i++) {
425
413
  if (n & 1n)
426
414
  p = p.add(d);
427
415
  else if (safe)
428
416
  f = f.add(d);
417
+ d = d.double();
418
+ n >>= 1n;
429
419
  }
430
420
  return p;
431
421
  }
@@ -439,10 +429,8 @@ var _Point = class _Point {
439
429
  return { x: 0n, y: 1n };
440
430
  const iz = invert(Z, P);
441
431
  if (modP(Z * iz) !== 1n)
442
- err("invalid inverse");
443
- const x = modP(X * iz);
444
- const y = modP(Y * iz);
445
- return { x, y };
432
+ throw new Error("invalid inverse");
433
+ return { x: modP(X * iz), y: modP(Y * iz) };
446
434
  }
447
435
  toBytes() {
448
436
  const { x, y } = this.toAffine();
@@ -454,30 +442,27 @@ var _Point = class _Point {
454
442
  return bytesToHex(this.toBytes());
455
443
  }
456
444
  clearCofactor() {
457
- return this.multiply(big(h), false);
445
+ return this.multiply(8n, false);
458
446
  }
459
447
  isSmallOrder() {
460
448
  return this.clearCofactor().is0();
461
449
  }
462
450
  isTorsionFree() {
463
- let p = this.multiply(N / 2n, false).double();
464
- if (N % 2n)
465
- p = p.add(this);
466
- return p.is0();
451
+ return this.multiply(N / 2n, false).double().add(this).is0();
467
452
  }
468
453
  };
469
454
  __publicField(_Point, "BASE");
470
455
  __publicField(_Point, "ZERO");
471
456
  var Point = _Point;
472
- var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
457
+ var G = new Point(Gx, Gy, 1n, mod(Gx * Gy));
473
458
  var I = new Point(0n, 1n, 1n, 0n);
474
459
  Point.BASE = G;
475
460
  Point.ZERO = I;
476
- var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), 64)).reverse();
477
- var bytesToNumberLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
461
+ var numTo32bLE = (num) => hexToBytes(padh(arange(num, 0n, B256), 64)).reverse();
462
+ var bytesToNumberLE = (b) => BigInt("0x" + bytesToHex(Uint8Array.from(abytes(b)).reverse()));
478
463
  var pow2 = (x, power) => {
479
464
  let r = x;
480
- while (power-- > 0n) {
465
+ while (power-- > 0) {
481
466
  r = modP(r * r);
482
467
  }
483
468
  return r;
@@ -485,103 +470,95 @@ var pow2 = (x, power) => {
485
470
  var pow_2_252_3 = (x) => {
486
471
  const x2 = modP(x * x);
487
472
  const b2 = modP(x2 * x);
488
- const b4 = modP(pow2(b2, 2n) * b2);
489
- const b5 = modP(pow2(b4, 1n) * x);
490
- const b10 = modP(pow2(b5, 5n) * b5);
491
- const b20 = modP(pow2(b10, 10n) * b10);
492
- const b40 = modP(pow2(b20, 20n) * b20);
493
- const b80 = modP(pow2(b40, 40n) * b40);
494
- const b160 = modP(pow2(b80, 80n) * b80);
495
- const b240 = modP(pow2(b160, 80n) * b80);
496
- const b250 = modP(pow2(b240, 10n) * b10);
497
- const pow_p_5_8 = modP(pow2(b250, 2n) * x);
498
- return { pow_p_5_8, b2 };
473
+ const b4 = modP(pow2(b2, 2) * b2);
474
+ const b5 = modP(pow2(b4, 1) * x);
475
+ const b10 = modP(pow2(b5, 5) * b5);
476
+ const b20 = modP(pow2(b10, 10) * b10);
477
+ const b40 = modP(pow2(b20, 20) * b20);
478
+ const b80 = modP(pow2(b40, 40) * b40);
479
+ const b160 = modP(pow2(b80, 80) * b80);
480
+ const b240 = modP(pow2(b160, 80) * b80);
481
+ const b250 = modP(pow2(b240, 10) * b10);
482
+ return modP(pow2(b250, 2) * x);
499
483
  };
500
484
  var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
501
485
  var uvRatio = (u, v) => {
502
486
  const v3 = modP(v * modP(v * v));
503
487
  const v7 = modP(modP(v3 * v3) * v);
504
- const pow = pow_2_252_3(modP(u * v7)).pow_p_5_8;
488
+ const pow = pow_2_252_3(modP(u * v7));
505
489
  let x = modP(u * modP(v3 * pow));
506
490
  const vx2 = modP(v * modP(x * x));
507
491
  const root1 = x;
508
492
  const root2 = modP(x * RM1);
509
493
  const useRoot1 = vx2 === u;
510
- const useRoot2 = vx2 === M(-u);
511
- const noRoot = vx2 === M(-u * RM1);
494
+ const useRoot2 = vx2 === mod(-u);
495
+ const noRoot = vx2 === mod(-u * RM1);
512
496
  if (useRoot1)
513
497
  x = root1;
514
498
  if (useRoot2 || noRoot)
515
499
  x = root2;
516
- if ((M(x) & 1n) === 1n)
517
- x = M(-x);
500
+ if ((mod(x) & 1n) === 1n)
501
+ x = mod(-x);
518
502
  return { isValid: useRoot1 || useRoot2, value: x };
519
503
  };
520
504
  var modL_LE = (hash) => modN(bytesToNumberLE(hash));
521
- var sha512a = (...m) => Promise.resolve(callHash("sha512Async")(concatBytes(...m))).then(checkDigest);
522
- var sha512s = (...m) => checkDigest(callHash("sha512")(concatBytes(...m)));
523
- var hash2extK = (hashed) => {
524
- const copy = u8fr(hashed);
505
+ var hashedToExtK = (hashed) => {
506
+ const copy = snapshotBytes(hashed);
525
507
  const head = copy.slice(0, 32);
526
508
  head[0] &= 248;
527
509
  head[31] &= 127;
528
510
  head[31] |= 64;
529
- const prefix = copy.slice(32, 64);
511
+ const prefix = copy.slice(32);
530
512
  const scalar = modL_LE(head);
531
513
  const point = G.multiply(scalar);
532
514
  const pointBytes = point.toBytes();
533
515
  return { head, prefix, scalar, point, pointBytes };
534
516
  };
535
- var getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes(secretKey, L)).then(hash2extK);
536
- var getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes(secretKey, L)));
537
- var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
538
- var hashFinishS = (res) => res.finish(sha512s(res.hashable));
517
+ var getExtendedPublicKeyAsync = (secretKey) => callHashAsync("sha512Async", abytes(secretKey, LEN, "secretKey")).then(hashedToExtK);
518
+ var getExtendedPublicKey = (secretKey) => hashedToExtK(callHash("sha512", abytes(secretKey, LEN, "secretKey")));
519
+ var getPublicKey = (secretKey) => getExtendedPublicKey(secretKey).pointBytes;
520
+ var hashFinishSync = (res) => res[1](callHash("sha512", res[0]));
539
521
  var _sign = (e, rBytes, msg) => {
540
- const { pointBytes: P2, scalar: s } = e;
522
+ const { pointBytes: A, scalar: s } = e;
541
523
  const r = modL_LE(rBytes);
542
524
  const R = G.multiply(r).toBytes();
543
- const hashable = concatBytes(R, P2, msg);
525
+ const hashable = concatBytes(R, A, msg);
544
526
  const finish = (hashed) => {
545
527
  const S = modN(r + modL_LE(hashed) * s);
546
528
  return abytes(concatBytes(R, numTo32bLE(S)), 64);
547
529
  };
548
- return { hashable, finish };
530
+ return [hashable, finish];
549
531
  };
550
532
  var sign = (message, secretKey) => {
551
- const m = abytes(message);
533
+ const m = snapshotBytes(message, "message");
552
534
  const e = getExtendedPublicKey(secretKey);
553
- const rBytes = sha512s(e.prefix, m);
554
- return hashFinishS(_sign(e, rBytes, m));
535
+ return hashFinishSync(_sign(e, callHash("sha512", e.prefix, m), m));
555
536
  };
556
537
  var hashes = {
557
538
  sha512Async: async (message) => {
558
- const s = subtle();
559
- const m = concatBytes(message);
560
- return u8n(await s.digest("SHA-512", m.buffer));
539
+ const s = globalThis?.crypto?.subtle;
540
+ if (!s)
541
+ throw new Error("crypto.subtle must be defined, consider polyfill");
542
+ return new Uint8Array(await s.digest("SHA-512", concatBytes(message)));
561
543
  },
562
544
  sha512: void 0
563
545
  };
564
546
  var randomSecretKey = (seed) => {
565
- seed = seed === void 0 ? randomBytes(L) : seed;
566
- return abytes(seed, L);
547
+ return abytes(seed === void 0 ? randomBytes() : seed, LEN, "seed");
567
548
  };
568
- var utils = /* @__PURE__ */ Object.freeze({
549
+ var utils = /* @__PURE__ */ freeze({
569
550
  getExtendedPublicKeyAsync,
570
551
  getExtendedPublicKey,
571
552
  randomSecretKey
572
553
  });
573
- var W = 8;
574
- var scalarBits = 256;
575
- var pwindows = Math.ceil(scalarBits / W) + 1;
576
- var pwindowSize = 2 ** (W - 1);
577
554
  var precompute = () => {
578
555
  const points = [];
579
556
  let p = G;
580
- let b = p;
581
- for (let w = 0; w < pwindows; w++) {
557
+ let b;
558
+ for (let w = 0; w < 33; w++) {
582
559
  b = p;
583
560
  points.push(b);
584
- for (let i = 1; i < pwindowSize; i++) {
561
+ for (let i = 1; i < 128; i++) {
585
562
  b = b.add(p);
586
563
  points.push(b);
587
564
  }
@@ -598,63 +575,110 @@ var wNAF = (n) => {
598
575
  const comp = Gpows || (Gpows = precompute());
599
576
  let p = I;
600
577
  let f = G;
601
- const pow_2_w = 2 ** W;
602
- const maxNum = pow_2_w;
603
- const mask = big(pow_2_w - 1);
604
- const shiftBy = big(W);
605
- for (let w = 0; w < pwindows; w++) {
606
- let wbits = Number(n & mask);
607
- n >>= shiftBy;
608
- if (wbits > pwindowSize) {
609
- wbits -= maxNum;
578
+ for (let w = 0; w < 33; w++) {
579
+ let wbits = Number(n & 255n);
580
+ n >>= 8n;
581
+ if (wbits > 128) {
582
+ wbits -= 256;
610
583
  n += 1n;
611
584
  }
612
- const off = w * pwindowSize;
613
- const offF = off;
585
+ const off = w * 128;
614
586
  const offP = off + Math.abs(wbits) - 1;
615
- const isEven = w % 2 !== 0;
587
+ const isOddW = w % 2 !== 0;
616
588
  const isNeg = wbits < 0;
617
589
  if (wbits === 0) {
618
- f = f.add(ctneg(isEven, comp[offF]));
590
+ f = f.add(ctneg(isOddW, comp[off]));
619
591
  } else {
620
592
  p = p.add(ctneg(isNeg, comp[offP]));
621
593
  }
622
594
  }
623
595
  if (n !== 0n)
624
- err("invalid wnaf");
596
+ throw new Error("invalid wnaf");
625
597
  return { p, f };
626
598
  };
627
599
 
628
- // node_modules/.pnpm/@noble+hashes@2.2.0/node_modules/@noble/hashes/utils.js
600
+ // node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_u64.js
601
+ var U32_MASK64 = /* @__PURE__ */ (() => BigInt(2 ** 32 - 1))();
602
+ var _32n = /* @__PURE__ */ BigInt(32);
603
+ function fromBig(n, le = false) {
604
+ if (le)
605
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
606
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
607
+ }
608
+ function split(lst, le = false) {
609
+ const len = lst.length;
610
+ let Ah = new Uint32Array(len);
611
+ let Al = new Uint32Array(len);
612
+ for (let i = 0; i < len; i++) {
613
+ const { h, l } = fromBig(lst[i], le);
614
+ [Ah[i], Al[i]] = [h, l];
615
+ }
616
+ return [Ah, Al];
617
+ }
618
+ var fromNumH = (n) => n / 2 ** 32 | 0;
619
+ var fromNumL = (n) => n >>> 0;
620
+ function setU64FromNum(view, byteOffset, n, isLE) {
621
+ const h = fromNumH(n);
622
+ const l = fromNumL(n);
623
+ view.setUint32(byteOffset, isLE ? l : h, isLE);
624
+ view.setUint32(byteOffset + 4, isLE ? h : l, isLE);
625
+ }
626
+ var shrSH = (h, _l, s) => h >>> s;
627
+ var shrSL = (h, l, s) => h << 32 - s | l >>> s;
628
+ var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
629
+ var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
630
+ var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
631
+ var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
632
+ function add(Ah, Al, Bh, Bl) {
633
+ const l = (Al >>> 0) + (Bl >>> 0);
634
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
635
+ }
636
+ var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
637
+ var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
638
+ var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
639
+ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
640
+ var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
641
+ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
642
+
643
+ // node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/utils.js
629
644
  function isBytes2(a) {
630
645
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
631
646
  }
647
+ var atitle = (title) => title ? `"${title}" ` : "";
632
648
  function abytes2(value, length, title = "") {
649
+ if (isBytes2(value) && (length === void 0))
650
+ return value;
633
651
  const bytes2 = isBytes2(value);
634
- const len = value?.length;
635
- const needsLen = length !== void 0;
636
- if (!bytes2 || needsLen) {
637
- const prefix = title && `"${title}" `;
638
- const ofLen = "";
639
- const got = bytes2 ? `length=${len}` : `type=${typeof value}`;
640
- const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
641
- if (!bytes2)
642
- throw new TypeError(message);
643
- throw new RangeError(message);
644
- }
645
- return value;
652
+ const ofLen = "";
653
+ const got = bytes2 ? `length=${value.length}` : `type=${typeof value}`;
654
+ const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
655
+ if (!bytes2)
656
+ throw new TypeError(message);
657
+ throw new RangeError(message);
646
658
  }
659
+ var aobject = (value, label) => {
660
+ if (value === null || typeof value !== "object" || Array.isArray(value))
661
+ throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
662
+ };
663
+ var aopts = (value, label) => {
664
+ aobject(value, label);
665
+ const proto = Object.getPrototypeOf(value);
666
+ if (proto !== Object.prototype && proto !== null)
667
+ throw new TypeError(`"${label}" expected plain object`);
668
+ if (Object.hasOwn(value, "__proto__"))
669
+ throw new TypeError(`"${label}.__proto__" is not allowed`);
670
+ };
647
671
  function aexists(instance, checkFinished = true) {
648
672
  if (instance.destroyed)
649
- throw new Error("Hash instance has been destroyed");
673
+ throw new Error("hash was destroyed");
650
674
  if (checkFinished && instance.finished)
651
- throw new Error("Hash#digest() has already been called");
675
+ throw new Error("digest() was already called");
652
676
  }
653
677
  function aoutput(out, instance) {
654
- abytes2(out, void 0, "digestInto() output");
678
+ abytes2(out, void 0, "output");
655
679
  const min = instance.outputLen;
656
- if (out.length < min) {
657
- throw new RangeError('"digestInto() output" expected to be of length >=' + min);
680
+ if (!(out.length >= min)) {
681
+ throw new RangeError('"output" expected length >= ' + min);
658
682
  }
659
683
  }
660
684
  function clean(...arrays) {
@@ -665,7 +689,17 @@ function clean(...arrays) {
665
689
  function createView(arr) {
666
690
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
667
691
  }
692
+ function checkOpts(defaults, opts, title = "opts") {
693
+ aopts(defaults, "defaults");
694
+ if (opts !== void 0)
695
+ aopts(opts, title);
696
+ const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts);
697
+ return merged;
698
+ }
668
699
  function createHasher(hashCons, info = {}) {
700
+ if (typeof hashCons !== "function")
701
+ throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
702
+ info = checkOpts({}, info, "info");
669
703
  const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
670
704
  const tmp = hashCons(void 0);
671
705
  hashC.outputLen = tmp.outputLen;
@@ -681,7 +715,7 @@ var oidNist = (suffix) => ({
681
715
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
682
716
  });
683
717
 
684
- // node_modules/.pnpm/@noble+hashes@2.2.0/node_modules/@noble/hashes/_md.js
718
+ // node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js
685
719
  var HashMD = class {
686
720
  constructor(blockLen, outputLen, padOffset, isLE) {
687
721
  __publicField(this, "blockLen");
@@ -708,24 +742,28 @@ var HashMD = class {
708
742
  abytes2(data);
709
743
  const { view, buffer, blockLen } = this;
710
744
  const len = data.length;
745
+ let processed = false;
711
746
  for (let pos = 0; pos < len; ) {
712
747
  const take = Math.min(blockLen - this.pos, len - pos);
713
748
  if (take === blockLen) {
714
749
  const dataView = createView(data);
715
750
  for (; blockLen <= len - pos; pos += blockLen)
716
751
  this.process(dataView, pos);
752
+ processed = true;
717
753
  continue;
718
754
  }
719
- buffer.set(data.subarray(pos, pos + take), this.pos);
755
+ buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
720
756
  this.pos += take;
721
757
  pos += take;
722
758
  if (this.pos === blockLen) {
723
759
  this.process(view, 0);
724
760
  this.pos = 0;
761
+ processed = true;
725
762
  }
726
763
  }
727
764
  this.length += data.length;
728
- this.roundClean();
765
+ if (processed)
766
+ this.roundClean();
729
767
  return this;
730
768
  }
731
769
  digestInto(out) {
@@ -735,23 +773,20 @@ var HashMD = class {
735
773
  const { buffer, view, blockLen, isLE } = this;
736
774
  let { pos } = this;
737
775
  buffer[pos++] = 128;
738
- clean(this.buffer.subarray(pos));
776
+ buffer.fill(0, pos);
739
777
  if (this.padOffset > blockLen - pos) {
740
778
  this.process(view, 0);
741
- pos = 0;
779
+ buffer.fill(0);
742
780
  }
743
- for (let i = pos; i < blockLen; i++)
744
- buffer[i] = 0;
745
- view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
781
+ setU64FromNum(view, blockLen - 8, this.length * 8, isLE);
746
782
  this.process(view, 0);
747
- const oview = createView(out);
783
+ this.roundClean();
784
+ const oview = out === buffer ? view : createView(out);
748
785
  const len = this.outputLen;
749
- if (len % 4)
750
- throw new Error("_sha2: outputLen must be aligned to 32bit");
751
786
  const outLen = len / 4;
752
787
  const state = this.get();
753
- if (outLen > state.length)
754
- throw new Error("_sha2: outputLen bigger than state");
788
+ if (len % 4 || outLen > state.length)
789
+ throw new Error("invalid outputLen");
755
790
  for (let i = 0; i < outLen; i++)
756
791
  oview.setUint32(4 * i, state[i], isLE);
757
792
  }
@@ -762,15 +797,13 @@ var HashMD = class {
762
797
  this.destroy();
763
798
  return res;
764
799
  }
765
- _cloneInto(to) {
766
- to || (to = new this.constructor());
767
- to.set(...this.get());
768
- const { blockLen, buffer, length, finished, destroyed, pos } = this;
800
+ _cloneIntoMeta(to) {
801
+ const { buffer, length, finished, destroyed, pos } = this;
769
802
  to.destroyed = destroyed;
770
803
  to.finished = finished;
771
804
  to.length = length;
772
805
  to.pos = pos;
773
- if (length % blockLen)
806
+ if (pos)
774
807
  to.buffer.set(buffer);
775
808
  return to;
776
809
  }
@@ -797,42 +830,7 @@ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
797
830
  327033209
798
831
  ]);
799
832
 
800
- // node_modules/.pnpm/@noble+hashes@2.2.0/node_modules/@noble/hashes/_u64.js
801
- var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
802
- var _32n = /* @__PURE__ */ BigInt(32);
803
- function fromBig(n, le = false) {
804
- if (le)
805
- return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
806
- return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
807
- }
808
- function split(lst, le = false) {
809
- const len = lst.length;
810
- let Ah = new Uint32Array(len);
811
- let Al = new Uint32Array(len);
812
- for (let i = 0; i < len; i++) {
813
- const { h: h2, l } = fromBig(lst[i], le);
814
- [Ah[i], Al[i]] = [h2, l];
815
- }
816
- return [Ah, Al];
817
- }
818
- var shrSH = (h2, _l, s) => h2 >>> s;
819
- var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
820
- var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
821
- var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
822
- var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
823
- var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
824
- function add(Ah, Al, Bh, Bl) {
825
- const l = (Al >>> 0) + (Bl >>> 0);
826
- return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
827
- }
828
- var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
829
- var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
830
- var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
831
- var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
832
- var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
833
- var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
834
-
835
- // node_modules/.pnpm/@noble+hashes@2.2.0/node_modules/@noble/hashes/sha2.js
833
+ // node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/sha2.js
836
834
  var K512 = /* @__PURE__ */ (() => split([
837
835
  "0x428a2f98d728ae22",
838
836
  "0x7137449123ef65cd",
@@ -920,8 +918,45 @@ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
920
918
  var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
921
919
  var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
922
920
  var SHA2_64B = class extends HashMD {
923
- constructor(outputLen) {
921
+ constructor(outputLen, IV) {
924
922
  super(128, outputLen, 16, false);
923
+ // We cannot use array here since array allows indexing by variable
924
+ // which means optimizer/compiler cannot use registers.
925
+ // h -- high 32 bits, l -- low 32 bits
926
+ // Numeric initializers matter: starting the fields as `undefined` changes
927
+ // V8's field representation and slows hashing down (measured on sha256).
928
+ __publicField(this, "Ah", 0);
929
+ __publicField(this, "Al", 0);
930
+ __publicField(this, "Bh", 0);
931
+ __publicField(this, "Bl", 0);
932
+ __publicField(this, "Ch", 0);
933
+ __publicField(this, "Cl", 0);
934
+ __publicField(this, "Dh", 0);
935
+ __publicField(this, "Dl", 0);
936
+ __publicField(this, "Eh", 0);
937
+ __publicField(this, "El", 0);
938
+ __publicField(this, "Fh", 0);
939
+ __publicField(this, "Fl", 0);
940
+ __publicField(this, "Gh", 0);
941
+ __publicField(this, "Gl", 0);
942
+ __publicField(this, "Hh", 0);
943
+ __publicField(this, "Hl", 0);
944
+ this.Ah = IV[0] | 0;
945
+ this.Al = IV[1] | 0;
946
+ this.Bh = IV[2] | 0;
947
+ this.Bl = IV[3] | 0;
948
+ this.Ch = IV[4] | 0;
949
+ this.Cl = IV[5] | 0;
950
+ this.Dh = IV[6] | 0;
951
+ this.Dl = IV[7] | 0;
952
+ this.Eh = IV[8] | 0;
953
+ this.El = IV[9] | 0;
954
+ this.Fh = IV[10] | 0;
955
+ this.Fl = IV[11] | 0;
956
+ this.Gh = IV[12] | 0;
957
+ this.Gl = IV[13] | 0;
958
+ this.Hh = IV[14] | 0;
959
+ this.Hl = IV[15] | 0;
925
960
  }
926
961
  // prettier-ignore
927
962
  get() {
@@ -947,6 +982,10 @@ var SHA2_64B = class extends HashMD {
947
982
  this.Hh = Hh | 0;
948
983
  this.Hl = Hl | 0;
949
984
  }
985
+ _cloneInto(to) {
986
+ (to || (to = new this.constructor())).set(...this.get());
987
+ return this._cloneIntoMeta(to);
988
+ }
950
989
  process(view, offset) {
951
990
  for (let i = 0; i < 16; i++, offset += 4) {
952
991
  SHA512_W_H[i] = view.getUint32(offset);
@@ -1017,23 +1056,7 @@ var SHA2_64B = class extends HashMD {
1017
1056
  };
1018
1057
  var _SHA512 = class extends SHA2_64B {
1019
1058
  constructor() {
1020
- super(64);
1021
- __publicField(this, "Ah", SHA512_IV[0] | 0);
1022
- __publicField(this, "Al", SHA512_IV[1] | 0);
1023
- __publicField(this, "Bh", SHA512_IV[2] | 0);
1024
- __publicField(this, "Bl", SHA512_IV[3] | 0);
1025
- __publicField(this, "Ch", SHA512_IV[4] | 0);
1026
- __publicField(this, "Cl", SHA512_IV[5] | 0);
1027
- __publicField(this, "Dh", SHA512_IV[6] | 0);
1028
- __publicField(this, "Dl", SHA512_IV[7] | 0);
1029
- __publicField(this, "Eh", SHA512_IV[8] | 0);
1030
- __publicField(this, "El", SHA512_IV[9] | 0);
1031
- __publicField(this, "Fh", SHA512_IV[10] | 0);
1032
- __publicField(this, "Fl", SHA512_IV[11] | 0);
1033
- __publicField(this, "Gh", SHA512_IV[12] | 0);
1034
- __publicField(this, "Gl", SHA512_IV[13] | 0);
1035
- __publicField(this, "Hh", SHA512_IV[14] | 0);
1036
- __publicField(this, "Hl", SHA512_IV[15] | 0);
1059
+ super(64, SHA512_IV);
1037
1060
  }
1038
1061
  };
1039
1062
  var sha512 = /* @__PURE__ */ createHasher(
@@ -1203,7 +1226,7 @@ var PKCS8_ED25519_PREFIX = new Uint8Array([
1203
1226
  4,
1204
1227
  32
1205
1228
  ]);
1206
- function subtle2() {
1229
+ function subtle() {
1207
1230
  const s = globalThis.crypto?.subtle;
1208
1231
  if (!s) {
1209
1232
  throw new Error("WebCrypto is unavailable: crypto.subtle requires a secure context (HTTPS or localhost)");
@@ -1221,15 +1244,15 @@ function rawKeySigner(privateKey) {
1221
1244
  };
1222
1245
  }
1223
1246
  async function webCryptoSigner(keyPair) {
1224
- const publicKey = new Uint8Array(await subtle2().exportKey("raw", keyPair.publicKey));
1247
+ const publicKey = new Uint8Array(await subtle().exportKey("raw", keyPair.publicKey));
1225
1248
  const privateKey = keyPair.privateKey;
1226
1249
  return {
1227
1250
  publicKey,
1228
- sign: async (data) => new Uint8Array(await subtle2().sign(ED25519, privateKey, bytes(data)))
1251
+ sign: async (data) => new Uint8Array(await subtle().sign(ED25519, privateKey, bytes(data)))
1229
1252
  };
1230
1253
  }
1231
1254
  async function generateNonExtractableKeyPair() {
1232
- return subtle2().generateKey(ED25519, false, ["sign", "verify"]);
1255
+ return subtle().generateKey(ED25519, false, ["sign", "verify"]);
1233
1256
  }
1234
1257
  async function importNonExtractableKey(privateKey) {
1235
1258
  if (privateKey.length !== 32) {
@@ -1239,7 +1262,7 @@ async function importNonExtractableKey(privateKey) {
1239
1262
  pkcs8.set(PKCS8_ED25519_PREFIX, 0);
1240
1263
  pkcs8.set(privateKey, PKCS8_ED25519_PREFIX.length);
1241
1264
  try {
1242
- const s = subtle2();
1265
+ const s = subtle();
1243
1266
  const [priv, pub] = await Promise.all([
1244
1267
  s.importKey("pkcs8", pkcs8, ED25519, false, ["sign"]),
1245
1268
  s.importKey("raw", bytes(getPublicKey2(privateKey)), ED25519, true, ["verify"])
@@ -1254,7 +1277,7 @@ function isWebCryptoEd25519Supported() {
1254
1277
  supported ?? (supported = (async () => {
1255
1278
  try {
1256
1279
  const kp = await generateNonExtractableKeyPair();
1257
- await subtle2().sign(ED25519, kp.privateKey, new Uint8Array(1));
1280
+ await subtle().sign(ED25519, kp.privateKey, new Uint8Array(1));
1258
1281
  return true;
1259
1282
  } catch {
1260
1283
  return false;
@@ -1502,8 +1525,8 @@ async function parseErrorBody(response) {
1502
1525
  body = await response.json();
1503
1526
  }
1504
1527
  if (body && typeof body === "object" && "error" in body) {
1505
- const err2 = body.error;
1506
- if (typeof err2 === "string") message = err2;
1528
+ const err = body.error;
1529
+ if (typeof err === "string") message = err;
1507
1530
  }
1508
1531
  } catch {
1509
1532
  }
@@ -1662,9 +1685,9 @@ async function* parseSSEStream(response, options) {
1662
1685
  let result;
1663
1686
  try {
1664
1687
  result = await reader.read();
1665
- } catch (err2) {
1688
+ } catch (err) {
1666
1689
  if (signal?.aborted) break;
1667
- throw err2;
1690
+ throw err;
1668
1691
  }
1669
1692
  const { done, value } = result;
1670
1693
  if (done) break;
@@ -3761,14 +3784,14 @@ function stripTrailingSlash(value) {
3761
3784
  return value.endsWith("/") ? value.slice(0, -1) : value;
3762
3785
  }
3763
3786
  function hostIsLocal(host) {
3764
- const h2 = host.toLowerCase();
3765
- if (h2 === "localhost" || h2.endsWith(".localhost") || h2.endsWith(".local")) return true;
3766
- if (h2 === "::1" || h2 === "0.0.0.0") return true;
3767
- if (/^127\./.test(h2)) return true;
3768
- if (/^10\./.test(h2)) return true;
3769
- if (/^192\.168\./.test(h2)) return true;
3770
- if (/^172\.(1[6-9]|2\d|3[01])\./.test(h2)) return true;
3771
- if (/^169\.254\./.test(h2)) return true;
3787
+ const h = host.toLowerCase();
3788
+ if (h === "localhost" || h.endsWith(".localhost") || h.endsWith(".local")) return true;
3789
+ if (h === "::1" || h === "0.0.0.0") return true;
3790
+ if (/^127\./.test(h)) return true;
3791
+ if (/^10\./.test(h)) return true;
3792
+ if (/^192\.168\./.test(h)) return true;
3793
+ if (/^172\.(1[6-9]|2\d|3[01])\./.test(h)) return true;
3794
+ if (/^169\.254\./.test(h)) return true;
3772
3795
  return false;
3773
3796
  }
3774
3797
  function schemelessVenueCandidates(venueId) {