@covia/covia-sdk 1.21.0 → 1.21.1

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