@tinycloud/cli 1.5.0-beta.26 → 1.5.0-beta.28

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.js CHANGED
@@ -932,6 +932,12 @@ function abytes(b, ...lengths) {
932
932
  if (lengths.length > 0 && !lengths.includes(b.length))
933
933
  throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
934
934
  }
935
+ function ahash(h) {
936
+ if (typeof h !== "function" || typeof h.create !== "function")
937
+ throw new Error("Hash should be wrapped by utils.createHasher");
938
+ anumber(h.outputLen);
939
+ anumber(h.blockLen);
940
+ }
935
941
  function aexists(instance, checkFinished = true) {
936
942
  if (instance.destroyed)
937
943
  throw new Error("Hash instance has been destroyed");
@@ -1100,7 +1106,7 @@ function Chi(a, b, c) {
1100
1106
  function Maj(a, b, c) {
1101
1107
  return a & b ^ a & c ^ b & c;
1102
1108
  }
1103
- var HashMD, SHA256_IV, SHA512_IV;
1109
+ var HashMD, SHA256_IV, SHA384_IV, SHA512_IV;
1104
1110
  var init_md = __esm({
1105
1111
  "../../node_modules/@noble/hashes/esm/_md.js"() {
1106
1112
  "use strict";
@@ -1205,6 +1211,24 @@ var init_md = __esm({
1205
1211
  528734635,
1206
1212
  1541459225
1207
1213
  ]);
1214
+ SHA384_IV = /* @__PURE__ */ Uint32Array.from([
1215
+ 3418070365,
1216
+ 3238371032,
1217
+ 1654270250,
1218
+ 914150663,
1219
+ 2438529370,
1220
+ 812702999,
1221
+ 355462360,
1222
+ 4144912697,
1223
+ 1731405415,
1224
+ 4290775857,
1225
+ 2394180231,
1226
+ 1750603025,
1227
+ 3675008525,
1228
+ 1694076839,
1229
+ 1203062813,
1230
+ 3204075428
1231
+ ]);
1208
1232
  SHA512_IV = /* @__PURE__ */ Uint32Array.from([
1209
1233
  1779033703,
1210
1234
  4089235720,
@@ -1227,7 +1251,7 @@ var init_md = __esm({
1227
1251
  });
1228
1252
 
1229
1253
  // ../../node_modules/@noble/hashes/esm/sha2.js
1230
- var SHA256_K, SHA256_W, SHA256, K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, sha256, sha512;
1254
+ var SHA256_K, SHA256_W, SHA256, K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, SHA384, sha256, sha512, sha384;
1231
1255
  var init_sha2 = __esm({
1232
1256
  "../../node_modules/@noble/hashes/esm/sha2.js"() {
1233
1257
  "use strict";
@@ -1568,8 +1592,30 @@ var init_sha2 = __esm({
1568
1592
  this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1569
1593
  }
1570
1594
  };
1595
+ SHA384 = class extends SHA512 {
1596
+ constructor() {
1597
+ super(48);
1598
+ this.Ah = SHA384_IV[0] | 0;
1599
+ this.Al = SHA384_IV[1] | 0;
1600
+ this.Bh = SHA384_IV[2] | 0;
1601
+ this.Bl = SHA384_IV[3] | 0;
1602
+ this.Ch = SHA384_IV[4] | 0;
1603
+ this.Cl = SHA384_IV[5] | 0;
1604
+ this.Dh = SHA384_IV[6] | 0;
1605
+ this.Dl = SHA384_IV[7] | 0;
1606
+ this.Eh = SHA384_IV[8] | 0;
1607
+ this.El = SHA384_IV[9] | 0;
1608
+ this.Fh = SHA384_IV[10] | 0;
1609
+ this.Fl = SHA384_IV[11] | 0;
1610
+ this.Gh = SHA384_IV[12] | 0;
1611
+ this.Gl = SHA384_IV[13] | 0;
1612
+ this.Hh = SHA384_IV[14] | 0;
1613
+ this.Hl = SHA384_IV[15] | 0;
1614
+ }
1615
+ };
1571
1616
  sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
1572
1617
  sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
1618
+ sha384 = /* @__PURE__ */ createHasher(() => new SHA384());
1573
1619
  }
1574
1620
  });
1575
1621
 
@@ -1583,6 +1629,81 @@ var init_sha256 = __esm({
1583
1629
  }
1584
1630
  });
1585
1631
 
1632
+ // ../../node_modules/@noble/hashes/esm/hmac.js
1633
+ var HMAC, hmac;
1634
+ var init_hmac = __esm({
1635
+ "../../node_modules/@noble/hashes/esm/hmac.js"() {
1636
+ "use strict";
1637
+ init_utils();
1638
+ HMAC = class extends Hash {
1639
+ constructor(hash, _key) {
1640
+ super();
1641
+ this.finished = false;
1642
+ this.destroyed = false;
1643
+ ahash(hash);
1644
+ const key = toBytes(_key);
1645
+ this.iHash = hash.create();
1646
+ if (typeof this.iHash.update !== "function")
1647
+ throw new Error("Expected instance of class which extends utils.Hash");
1648
+ this.blockLen = this.iHash.blockLen;
1649
+ this.outputLen = this.iHash.outputLen;
1650
+ const blockLen = this.blockLen;
1651
+ const pad = new Uint8Array(blockLen);
1652
+ pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
1653
+ for (let i = 0; i < pad.length; i++)
1654
+ pad[i] ^= 54;
1655
+ this.iHash.update(pad);
1656
+ this.oHash = hash.create();
1657
+ for (let i = 0; i < pad.length; i++)
1658
+ pad[i] ^= 54 ^ 92;
1659
+ this.oHash.update(pad);
1660
+ clean(pad);
1661
+ }
1662
+ update(buf) {
1663
+ aexists(this);
1664
+ this.iHash.update(buf);
1665
+ return this;
1666
+ }
1667
+ digestInto(out) {
1668
+ aexists(this);
1669
+ abytes(out, this.outputLen);
1670
+ this.finished = true;
1671
+ this.iHash.digestInto(out);
1672
+ this.oHash.update(out);
1673
+ this.oHash.digestInto(out);
1674
+ this.destroy();
1675
+ }
1676
+ digest() {
1677
+ const out = new Uint8Array(this.oHash.outputLen);
1678
+ this.digestInto(out);
1679
+ return out;
1680
+ }
1681
+ _cloneInto(to) {
1682
+ to || (to = Object.create(Object.getPrototypeOf(this), {}));
1683
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
1684
+ to = to;
1685
+ to.finished = finished;
1686
+ to.destroyed = destroyed;
1687
+ to.blockLen = blockLen;
1688
+ to.outputLen = outputLen;
1689
+ to.oHash = oHash._cloneInto(to.oHash);
1690
+ to.iHash = iHash._cloneInto(to.iHash);
1691
+ return to;
1692
+ }
1693
+ clone() {
1694
+ return this._cloneInto();
1695
+ }
1696
+ destroy() {
1697
+ this.destroyed = true;
1698
+ this.oHash.destroy();
1699
+ this.iHash.destroy();
1700
+ }
1701
+ };
1702
+ hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
1703
+ hmac.create = (hash, key) => new HMAC(hash, key);
1704
+ }
1705
+ });
1706
+
1586
1707
  // src/lib/raw-encryption.ts
1587
1708
  var init_raw_encryption = __esm({
1588
1709
  "src/lib/raw-encryption.ts"() {
@@ -1782,8 +1903,8 @@ function createReplicationEventSink(profileRoot, options) {
1782
1903
  `);
1783
1904
  } else if (event.type === "replication.sync") {
1784
1905
  const pending = event.pendingCleared === void 0 ? "" : ` pendingCleared:${event.pendingCleared}`;
1785
- const origin = event.origin === void 0 ? "" : ` origin:${event.origin}`;
1786
- process.stderr.write(`[replication] sync ${event.replica} ${event.outcome}${event.code ? ` ${event.code}` : ""}${pending}${origin}
1906
+ const origin2 = event.origin === void 0 ? "" : ` origin:${event.origin}`;
1907
+ process.stderr.write(`[replication] sync ${event.replica} ${event.outcome}${event.code ? ` ${event.code}` : ""}${pending}${origin2}
1787
1908
  `);
1788
1909
  } else if (event.type === "replication.grant") {
1789
1910
  process.stderr.write(`[replication] grant ${event.replicaId} ${event.action}${event.code ? ` ${event.code}` : ""}${event.effectiveExpiresAt ? ` effectiveExpiresAt:${event.effectiveExpiresAt}` : ""}
@@ -2188,6 +2309,10 @@ function _abytes2(value, length5, title = "") {
2188
2309
  }
2189
2310
  return value;
2190
2311
  }
2312
+ function numberToHexUnpadded(num) {
2313
+ const hex3 = num.toString(16);
2314
+ return hex3.length & 1 ? "0" + hex3 : hex3;
2315
+ }
2191
2316
  function hexToNumber(hex3) {
2192
2317
  if (typeof hex3 !== "string")
2193
2318
  throw new Error("hex string expected, got " + typeof hex3);
@@ -2248,6 +2373,56 @@ function bitLen(n) {
2248
2373
  ;
2249
2374
  return len;
2250
2375
  }
2376
+ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
2377
+ if (typeof hashLen !== "number" || hashLen < 2)
2378
+ throw new Error("hashLen must be a number");
2379
+ if (typeof qByteLen !== "number" || qByteLen < 2)
2380
+ throw new Error("qByteLen must be a number");
2381
+ if (typeof hmacFn !== "function")
2382
+ throw new Error("hmacFn must be a function");
2383
+ const u8n = (len) => new Uint8Array(len);
2384
+ const u8of = (byte) => Uint8Array.of(byte);
2385
+ let v = u8n(hashLen);
2386
+ let k = u8n(hashLen);
2387
+ let i = 0;
2388
+ const reset = () => {
2389
+ v.fill(1);
2390
+ k.fill(0);
2391
+ i = 0;
2392
+ };
2393
+ const h = (...b) => hmacFn(k, v, ...b);
2394
+ const reseed = (seed = u8n(0)) => {
2395
+ k = h(u8of(0), seed);
2396
+ v = h();
2397
+ if (seed.length === 0)
2398
+ return;
2399
+ k = h(u8of(1), seed);
2400
+ v = h();
2401
+ };
2402
+ const gen = () => {
2403
+ if (i++ >= 1e3)
2404
+ throw new Error("drbg: tried 1000 values");
2405
+ let len = 0;
2406
+ const out = [];
2407
+ while (len < qByteLen) {
2408
+ v = h();
2409
+ const sl = v.slice();
2410
+ out.push(sl);
2411
+ len += v.length;
2412
+ }
2413
+ return concatBytes(...out);
2414
+ };
2415
+ const genUntil = (seed, pred) => {
2416
+ reset();
2417
+ reseed(seed);
2418
+ let res = void 0;
2419
+ while (!(res = pred(gen())))
2420
+ reseed();
2421
+ reset();
2422
+ return res;
2423
+ };
2424
+ return genUntil;
2425
+ }
2251
2426
  function _validateObject(object3, fields, optFields = {}) {
2252
2427
  if (!object3 || typeof object3 !== "object")
2253
2428
  throw new Error("expected valid options object");
@@ -2584,6 +2759,26 @@ function Field(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
2584
2759
  });
2585
2760
  return Object.freeze(f);
2586
2761
  }
2762
+ function getFieldBytesLength(fieldOrder) {
2763
+ if (typeof fieldOrder !== "bigint")
2764
+ throw new Error("field order must be bigint");
2765
+ const bitLength = fieldOrder.toString(2).length;
2766
+ return Math.ceil(bitLength / 8);
2767
+ }
2768
+ function getMinHashLength(fieldOrder) {
2769
+ const length5 = getFieldBytesLength(fieldOrder);
2770
+ return length5 + Math.ceil(length5 / 2);
2771
+ }
2772
+ function mapHashToField(key, fieldOrder, isLE2 = false) {
2773
+ const len = key.length;
2774
+ const fieldLen = getFieldBytesLength(fieldOrder);
2775
+ const minLen = getMinHashLength(fieldOrder);
2776
+ if (len < 16 || len < minLen || len > 1024)
2777
+ throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
2778
+ const num = isLE2 ? bytesToNumberLE(key) : bytesToNumberBE(key);
2779
+ const reduced = mod(num, fieldOrder - _1n2) + _1n2;
2780
+ return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
2781
+ }
2587
2782
  var _0n2, _1n2, _2n, _3n, _4n, _5n, _7n, _8n, _9n, _16n, isNegativeLE, FIELD_FIELDS;
2588
2783
  var init_modular = __esm({
2589
2784
  "../../node_modules/@noble/curves/esm/abstract/modular.js"() {
@@ -2683,6 +2878,21 @@ function assert0(n) {
2683
2878
  if (n !== _0n3)
2684
2879
  throw new Error("invalid wNAF");
2685
2880
  }
2881
+ function mulEndoUnsafe(Point, point, k1, k2) {
2882
+ let acc = point;
2883
+ let p1 = Point.ZERO;
2884
+ let p2 = Point.ZERO;
2885
+ while (k1 > _0n3 || k2 > _0n3) {
2886
+ if (k1 & _1n3)
2887
+ p1 = p1.add(acc);
2888
+ if (k2 & _1n3)
2889
+ p2 = p2.add(acc);
2890
+ acc = acc.double();
2891
+ k1 >>= _1n3;
2892
+ k2 >>= _1n3;
2893
+ }
2894
+ return { p1, p2 };
2895
+ }
2686
2896
  function pippenger(c, fieldN, points, scalars) {
2687
2897
  validateMSMPoints(points, c);
2688
2898
  validateMSMScalars(scalars, fieldN);
@@ -6592,7 +6802,7 @@ var init_profile_replicas = __esm({
6592
6802
  });
6593
6803
 
6594
6804
  // src/lib/logout-pending.ts
6595
- import { lstat as lstat4, open as open5, readFile as readFile5 } from "fs/promises";
6805
+ import { lstat as lstat4, open as open5, readFile as readFile5, rm as rm4 } from "fs/promises";
6596
6806
  import { join as join9 } from "path";
6597
6807
  import { createProfileReplicaPurge, logoutPrincipalDigest, REPLICA_LOGOUT_PENDING_FILE as REPLICA_LOGOUT_PENDING_FILE2, RESTORED_GATE_MESSAGE } from "@tinycloud/node-sdk";
6598
6808
  import { namedProfilePath, profilePath as profilePath4 } from "@tinycloud/operations/state";
@@ -6673,32 +6883,35 @@ async function assertPendingRemoteLogoutSession(name, expected) {
6673
6883
  }, { requireProfile: true });
6674
6884
  }
6675
6885
  async function clearProfileCredentials(name, syncDirectory = false, legacyCleanup = false) {
6676
- const profile = await ProfileManager.getProfile(name);
6677
- const { namedKeys: _namedKeys, ...signedOutProfile } = profile;
6678
- await ProfileManager.setProfileDurable(name, { ...signedOutProfile, authSignedOut: true, ...legacyCleanup ? { legacyReplicaCleanup: true } : {} });
6679
- let failed = false;
6680
- let error;
6681
- try {
6682
- await ProfileManager.removeKey(name);
6683
- } catch (cause) {
6684
- failed = true;
6685
- error = cause;
6686
- }
6687
- try {
6688
- await ProfileManager.clearSession(name);
6689
- } catch (cause) {
6690
- if (!failed) error = cause;
6691
- failed = true;
6692
- }
6693
- if (failed) throw error;
6694
- if (syncDirectory) {
6695
- const directory = await open5(profilePath4(name), "r");
6886
+ await ProfileManager.withLock(name, async () => {
6887
+ const profile = await ProfileManager.getProfile(name);
6888
+ const { namedKeys: _namedKeys, ...signedOutProfile } = profile;
6889
+ await rm4(join9(profilePath4(name), "approval-pending.json"), { force: true });
6890
+ await ProfileManager.setProfileDurable(name, { ...signedOutProfile, authSignedOut: true, ...legacyCleanup ? { legacyReplicaCleanup: true } : {} });
6891
+ let failed = false;
6892
+ let error;
6696
6893
  try {
6697
- await directory.sync();
6698
- } finally {
6699
- await directory.close();
6894
+ await ProfileManager.removeKey(name);
6895
+ } catch (cause) {
6896
+ failed = true;
6897
+ error = cause;
6700
6898
  }
6701
- }
6899
+ try {
6900
+ await ProfileManager.clearSession(name);
6901
+ } catch (cause) {
6902
+ if (!failed) error = cause;
6903
+ failed = true;
6904
+ }
6905
+ if (failed) throw error;
6906
+ if (syncDirectory) {
6907
+ const directory = await open5(profilePath4(name), "r");
6908
+ try {
6909
+ await directory.sync();
6910
+ } finally {
6911
+ await directory.close();
6912
+ }
6913
+ }
6914
+ }, { requireProfile: true });
6702
6915
  }
6703
6916
  async function finishSignedOutCredentialRemoval(name) {
6704
6917
  const profile = await ProfileManager.getProfile(name).catch((error) => {
@@ -7363,7 +7576,7 @@ var init_host = __esm({
7363
7576
  });
7364
7577
 
7365
7578
  // src/config/profiles.ts
7366
- import { chmod as chmod3, lstat as lstat5, readdir as readdir5, rm as rm4 } from "fs/promises";
7579
+ import { chmod as chmod3, lstat as lstat5, readdir as readdir5, rm as rm5 } from "fs/promises";
7367
7580
  import { CLI_NAME as CLI_NAME11 } from "@tinycloud/operations/cli-name";
7368
7581
  import { join as join10 } from "path";
7369
7582
  import {
@@ -7482,7 +7695,7 @@ var init_profiles = __esm({
7482
7695
  }
7483
7696
  /** Removes profile.json under the profile lock (rollback of a profile a failed login created). */
7484
7697
  static async removeProfileConfig(name) {
7485
- await _ProfileManager.withLock(name, () => rm4(join10(profilePath5(name), "profile.json"), { force: true }));
7698
+ await _ProfileManager.withLock(name, () => rm5(join10(profilePath5(name), "profile.json"), { force: true }));
7486
7699
  }
7487
7700
  /**
7488
7701
  * Returns true if a profile directory exists.
@@ -7533,16 +7746,16 @@ var init_profiles = __esm({
7533
7746
  });
7534
7747
  if (kind === "missing") return;
7535
7748
  if (kind === "link") {
7536
- await rm4(profileDir, { force: true });
7749
+ await rm5(profileDir, { force: true });
7537
7750
  return;
7538
7751
  }
7539
7752
  await _ProfileManager.withLock(name, async () => {
7540
7753
  const directory = profilePath5(name);
7541
- for (const file of ["session.json", "key.json"]) await rm4(join10(directory, file), { force: true });
7754
+ for (const file of ["session.json", "key.json"]) await rm5(join10(directory, file), { force: true });
7542
7755
  for (const entry of await readdir5(directory)) {
7543
- if (entry !== ".lock" && entry !== "profile.json") await rm4(join10(directory, entry), { recursive: true, force: true });
7756
+ if (entry !== ".lock" && entry !== "profile.json") await rm5(join10(directory, entry), { recursive: true, force: true });
7544
7757
  }
7545
- await rm4(join10(directory, "profile.json"), { force: true });
7758
+ await rm5(join10(directory, "profile.json"), { force: true });
7546
7759
  await recordProfileDeletion(name);
7547
7760
  });
7548
7761
  }
@@ -7572,7 +7785,7 @@ var init_profiles = __esm({
7572
7785
  }
7573
7786
  /** Removes key.json under the profile lock (rollback of a key a failed login created). */
7574
7787
  static async removeKey(name) {
7575
- await _ProfileManager.withLock(name, () => rm4(join10(profilePath5(name), "key.json"), { force: true }));
7788
+ await _ProfileManager.withLock(name, () => rm5(join10(profilePath5(name), "key.json"), { force: true }));
7576
7789
  }
7577
7790
  // ── Session management ──────────────────────────────────────────────
7578
7791
  /**
@@ -12789,6 +13002,1097 @@ var init_raw = __esm({
12789
13002
  }
12790
13003
  });
12791
13004
 
13005
+ // ../../node_modules/@noble/curves/esm/abstract/weierstrass.js
13006
+ function _splitEndoScalar(k, basis, n) {
13007
+ const [[a1, b1], [a2, b2]] = basis;
13008
+ const c1 = divNearest(b2 * k, n);
13009
+ const c2 = divNearest(-b1 * k, n);
13010
+ let k1 = k - c1 * a1 - c2 * a2;
13011
+ let k2 = -c1 * b1 - c2 * b2;
13012
+ const k1neg = k1 < _0n6;
13013
+ const k2neg = k2 < _0n6;
13014
+ if (k1neg)
13015
+ k1 = -k1;
13016
+ if (k2neg)
13017
+ k2 = -k2;
13018
+ const MAX_NUM = bitMask(Math.ceil(bitLen(n) / 2)) + _1n6;
13019
+ if (k1 < _0n6 || k1 >= MAX_NUM || k2 < _0n6 || k2 >= MAX_NUM) {
13020
+ throw new Error("splitScalar (endomorphism): failed, k=" + k);
13021
+ }
13022
+ return { k1neg, k1, k2neg, k2 };
13023
+ }
13024
+ function validateSigFormat(format5) {
13025
+ if (!["compact", "recovered", "der"].includes(format5))
13026
+ throw new Error('Signature format must be "compact", "recovered", or "der"');
13027
+ return format5;
13028
+ }
13029
+ function validateSigOpts(opts, def) {
13030
+ const optsn = {};
13031
+ for (let optName of Object.keys(def)) {
13032
+ optsn[optName] = opts[optName] === void 0 ? def[optName] : opts[optName];
13033
+ }
13034
+ _abool2(optsn.lowS, "lowS");
13035
+ _abool2(optsn.prehash, "prehash");
13036
+ if (optsn.format !== void 0)
13037
+ validateSigFormat(optsn.format);
13038
+ return optsn;
13039
+ }
13040
+ function _normFnElement(Fn2, key) {
13041
+ const { BYTES: expected } = Fn2;
13042
+ let num;
13043
+ if (typeof key === "bigint") {
13044
+ num = key;
13045
+ } else {
13046
+ let bytes = ensureBytes("private key", key);
13047
+ try {
13048
+ num = Fn2.fromBytes(bytes);
13049
+ } catch (error) {
13050
+ throw new Error(`invalid private key: expected ui8a of size ${expected}, got ${typeof key}`);
13051
+ }
13052
+ }
13053
+ if (!Fn2.isValidNot0(num))
13054
+ throw new Error("invalid private key: out of range [1..N-1]");
13055
+ return num;
13056
+ }
13057
+ function weierstrassN(params, extraOpts = {}) {
13058
+ const validated = _createCurveFields("weierstrass", params, extraOpts);
13059
+ const { Fp: Fp2, Fn: Fn2 } = validated;
13060
+ let CURVE = validated.CURVE;
13061
+ const { h: cofactor, n: CURVE_ORDER } = CURVE;
13062
+ _validateObject(extraOpts, {}, {
13063
+ allowInfinityPoint: "boolean",
13064
+ clearCofactor: "function",
13065
+ isTorsionFree: "function",
13066
+ fromBytes: "function",
13067
+ toBytes: "function",
13068
+ endo: "object",
13069
+ wrapPrivateKey: "boolean"
13070
+ });
13071
+ const { endo } = extraOpts;
13072
+ if (endo) {
13073
+ if (!Fp2.is0(CURVE.a) || typeof endo.beta !== "bigint" || !Array.isArray(endo.basises)) {
13074
+ throw new Error('invalid endo: expected "beta": bigint and "basises": array');
13075
+ }
13076
+ }
13077
+ const lengths = getWLengths(Fp2, Fn2);
13078
+ function assertCompressionIsSupported() {
13079
+ if (!Fp2.isOdd)
13080
+ throw new Error("compression is not supported: Field does not have .isOdd()");
13081
+ }
13082
+ function pointToBytes(_c, point, isCompressed) {
13083
+ const { x, y } = point.toAffine();
13084
+ const bx = Fp2.toBytes(x);
13085
+ _abool2(isCompressed, "isCompressed");
13086
+ if (isCompressed) {
13087
+ assertCompressionIsSupported();
13088
+ const hasEvenY = !Fp2.isOdd(y);
13089
+ return concatBytes(pprefix(hasEvenY), bx);
13090
+ } else {
13091
+ return concatBytes(Uint8Array.of(4), bx, Fp2.toBytes(y));
13092
+ }
13093
+ }
13094
+ function pointFromBytes(bytes) {
13095
+ _abytes2(bytes, void 0, "Point");
13096
+ const { publicKey: comp, publicKeyUncompressed: uncomp } = lengths;
13097
+ const length5 = bytes.length;
13098
+ const head = bytes[0];
13099
+ const tail = bytes.subarray(1);
13100
+ if (length5 === comp && (head === 2 || head === 3)) {
13101
+ const x = Fp2.fromBytes(tail);
13102
+ if (!Fp2.isValid(x))
13103
+ throw new Error("bad point: is not on curve, wrong x");
13104
+ const y2 = weierstrassEquation(x);
13105
+ let y;
13106
+ try {
13107
+ y = Fp2.sqrt(y2);
13108
+ } catch (sqrtError) {
13109
+ const err = sqrtError instanceof Error ? ": " + sqrtError.message : "";
13110
+ throw new Error("bad point: is not on curve, sqrt error" + err);
13111
+ }
13112
+ assertCompressionIsSupported();
13113
+ const isYOdd = Fp2.isOdd(y);
13114
+ const isHeadOdd = (head & 1) === 1;
13115
+ if (isHeadOdd !== isYOdd)
13116
+ y = Fp2.neg(y);
13117
+ return { x, y };
13118
+ } else if (length5 === uncomp && head === 4) {
13119
+ const L = Fp2.BYTES;
13120
+ const x = Fp2.fromBytes(tail.subarray(0, L));
13121
+ const y = Fp2.fromBytes(tail.subarray(L, L * 2));
13122
+ if (!isValidXY(x, y))
13123
+ throw new Error("bad point: is not on curve");
13124
+ return { x, y };
13125
+ } else {
13126
+ throw new Error(`bad point: got length ${length5}, expected compressed=${comp} or uncompressed=${uncomp}`);
13127
+ }
13128
+ }
13129
+ const encodePoint = extraOpts.toBytes || pointToBytes;
13130
+ const decodePoint2 = extraOpts.fromBytes || pointFromBytes;
13131
+ function weierstrassEquation(x) {
13132
+ const x2 = Fp2.sqr(x);
13133
+ const x3 = Fp2.mul(x2, x);
13134
+ return Fp2.add(Fp2.add(x3, Fp2.mul(x, CURVE.a)), CURVE.b);
13135
+ }
13136
+ function isValidXY(x, y) {
13137
+ const left = Fp2.sqr(y);
13138
+ const right = weierstrassEquation(x);
13139
+ return Fp2.eql(left, right);
13140
+ }
13141
+ if (!isValidXY(CURVE.Gx, CURVE.Gy))
13142
+ throw new Error("bad curve params: generator point");
13143
+ const _4a3 = Fp2.mul(Fp2.pow(CURVE.a, _3n3), _4n2);
13144
+ const _27b2 = Fp2.mul(Fp2.sqr(CURVE.b), BigInt(27));
13145
+ if (Fp2.is0(Fp2.add(_4a3, _27b2)))
13146
+ throw new Error("bad curve params: a or b");
13147
+ function acoord(title, n, banZero = false) {
13148
+ if (!Fp2.isValid(n) || banZero && Fp2.is0(n))
13149
+ throw new Error(`bad point coordinate ${title}`);
13150
+ return n;
13151
+ }
13152
+ function aprjpoint(other) {
13153
+ if (!(other instanceof Point))
13154
+ throw new Error("ProjectivePoint expected");
13155
+ }
13156
+ function splitEndoScalarN(k) {
13157
+ if (!endo || !endo.basises)
13158
+ throw new Error("no endo");
13159
+ return _splitEndoScalar(k, endo.basises, Fn2.ORDER);
13160
+ }
13161
+ const toAffineMemo = memoized((p, iz) => {
13162
+ const { X, Y, Z } = p;
13163
+ if (Fp2.eql(Z, Fp2.ONE))
13164
+ return { x: X, y: Y };
13165
+ const is0 = p.is0();
13166
+ if (iz == null)
13167
+ iz = is0 ? Fp2.ONE : Fp2.inv(Z);
13168
+ const x = Fp2.mul(X, iz);
13169
+ const y = Fp2.mul(Y, iz);
13170
+ const zz = Fp2.mul(Z, iz);
13171
+ if (is0)
13172
+ return { x: Fp2.ZERO, y: Fp2.ZERO };
13173
+ if (!Fp2.eql(zz, Fp2.ONE))
13174
+ throw new Error("invZ was invalid");
13175
+ return { x, y };
13176
+ });
13177
+ const assertValidMemo = memoized((p) => {
13178
+ if (p.is0()) {
13179
+ if (extraOpts.allowInfinityPoint && !Fp2.is0(p.Y))
13180
+ return;
13181
+ throw new Error("bad point: ZERO");
13182
+ }
13183
+ const { x, y } = p.toAffine();
13184
+ if (!Fp2.isValid(x) || !Fp2.isValid(y))
13185
+ throw new Error("bad point: x or y not field elements");
13186
+ if (!isValidXY(x, y))
13187
+ throw new Error("bad point: equation left != right");
13188
+ if (!p.isTorsionFree())
13189
+ throw new Error("bad point: not in prime-order subgroup");
13190
+ return true;
13191
+ });
13192
+ function finishEndo(endoBeta, k1p, k2p, k1neg, k2neg) {
13193
+ k2p = new Point(Fp2.mul(k2p.X, endoBeta), k2p.Y, k2p.Z);
13194
+ k1p = negateCt(k1neg, k1p);
13195
+ k2p = negateCt(k2neg, k2p);
13196
+ return k1p.add(k2p);
13197
+ }
13198
+ class Point {
13199
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
13200
+ constructor(X, Y, Z) {
13201
+ this.X = acoord("x", X);
13202
+ this.Y = acoord("y", Y, true);
13203
+ this.Z = acoord("z", Z);
13204
+ Object.freeze(this);
13205
+ }
13206
+ static CURVE() {
13207
+ return CURVE;
13208
+ }
13209
+ /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
13210
+ static fromAffine(p) {
13211
+ const { x, y } = p || {};
13212
+ if (!p || !Fp2.isValid(x) || !Fp2.isValid(y))
13213
+ throw new Error("invalid affine point");
13214
+ if (p instanceof Point)
13215
+ throw new Error("projective point not allowed");
13216
+ if (Fp2.is0(x) && Fp2.is0(y))
13217
+ return Point.ZERO;
13218
+ return new Point(x, y, Fp2.ONE);
13219
+ }
13220
+ static fromBytes(bytes) {
13221
+ const P = Point.fromAffine(decodePoint2(_abytes2(bytes, void 0, "point")));
13222
+ P.assertValidity();
13223
+ return P;
13224
+ }
13225
+ static fromHex(hex3) {
13226
+ return Point.fromBytes(ensureBytes("pointHex", hex3));
13227
+ }
13228
+ get x() {
13229
+ return this.toAffine().x;
13230
+ }
13231
+ get y() {
13232
+ return this.toAffine().y;
13233
+ }
13234
+ /**
13235
+ *
13236
+ * @param windowSize
13237
+ * @param isLazy true will defer table computation until the first multiplication
13238
+ * @returns
13239
+ */
13240
+ precompute(windowSize = 8, isLazy = true) {
13241
+ wnaf.createCache(this, windowSize);
13242
+ if (!isLazy)
13243
+ this.multiply(_3n3);
13244
+ return this;
13245
+ }
13246
+ // TODO: return `this`
13247
+ /** A point on curve is valid if it conforms to equation. */
13248
+ assertValidity() {
13249
+ assertValidMemo(this);
13250
+ }
13251
+ hasEvenY() {
13252
+ const { y } = this.toAffine();
13253
+ if (!Fp2.isOdd)
13254
+ throw new Error("Field doesn't support isOdd");
13255
+ return !Fp2.isOdd(y);
13256
+ }
13257
+ /** Compare one point to another. */
13258
+ equals(other) {
13259
+ aprjpoint(other);
13260
+ const { X: X1, Y: Y1, Z: Z1 } = this;
13261
+ const { X: X2, Y: Y2, Z: Z2 } = other;
13262
+ const U1 = Fp2.eql(Fp2.mul(X1, Z2), Fp2.mul(X2, Z1));
13263
+ const U2 = Fp2.eql(Fp2.mul(Y1, Z2), Fp2.mul(Y2, Z1));
13264
+ return U1 && U2;
13265
+ }
13266
+ /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
13267
+ negate() {
13268
+ return new Point(this.X, Fp2.neg(this.Y), this.Z);
13269
+ }
13270
+ // Renes-Costello-Batina exception-free doubling formula.
13271
+ // There is 30% faster Jacobian formula, but it is not complete.
13272
+ // https://eprint.iacr.org/2015/1060, algorithm 3
13273
+ // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
13274
+ double() {
13275
+ const { a, b } = CURVE;
13276
+ const b3 = Fp2.mul(b, _3n3);
13277
+ const { X: X1, Y: Y1, Z: Z1 } = this;
13278
+ let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
13279
+ let t0 = Fp2.mul(X1, X1);
13280
+ let t1 = Fp2.mul(Y1, Y1);
13281
+ let t2 = Fp2.mul(Z1, Z1);
13282
+ let t3 = Fp2.mul(X1, Y1);
13283
+ t3 = Fp2.add(t3, t3);
13284
+ Z3 = Fp2.mul(X1, Z1);
13285
+ Z3 = Fp2.add(Z3, Z3);
13286
+ X3 = Fp2.mul(a, Z3);
13287
+ Y3 = Fp2.mul(b3, t2);
13288
+ Y3 = Fp2.add(X3, Y3);
13289
+ X3 = Fp2.sub(t1, Y3);
13290
+ Y3 = Fp2.add(t1, Y3);
13291
+ Y3 = Fp2.mul(X3, Y3);
13292
+ X3 = Fp2.mul(t3, X3);
13293
+ Z3 = Fp2.mul(b3, Z3);
13294
+ t2 = Fp2.mul(a, t2);
13295
+ t3 = Fp2.sub(t0, t2);
13296
+ t3 = Fp2.mul(a, t3);
13297
+ t3 = Fp2.add(t3, Z3);
13298
+ Z3 = Fp2.add(t0, t0);
13299
+ t0 = Fp2.add(Z3, t0);
13300
+ t0 = Fp2.add(t0, t2);
13301
+ t0 = Fp2.mul(t0, t3);
13302
+ Y3 = Fp2.add(Y3, t0);
13303
+ t2 = Fp2.mul(Y1, Z1);
13304
+ t2 = Fp2.add(t2, t2);
13305
+ t0 = Fp2.mul(t2, t3);
13306
+ X3 = Fp2.sub(X3, t0);
13307
+ Z3 = Fp2.mul(t2, t1);
13308
+ Z3 = Fp2.add(Z3, Z3);
13309
+ Z3 = Fp2.add(Z3, Z3);
13310
+ return new Point(X3, Y3, Z3);
13311
+ }
13312
+ // Renes-Costello-Batina exception-free addition formula.
13313
+ // There is 30% faster Jacobian formula, but it is not complete.
13314
+ // https://eprint.iacr.org/2015/1060, algorithm 1
13315
+ // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
13316
+ add(other) {
13317
+ aprjpoint(other);
13318
+ const { X: X1, Y: Y1, Z: Z1 } = this;
13319
+ const { X: X2, Y: Y2, Z: Z2 } = other;
13320
+ let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
13321
+ const a = CURVE.a;
13322
+ const b3 = Fp2.mul(CURVE.b, _3n3);
13323
+ let t0 = Fp2.mul(X1, X2);
13324
+ let t1 = Fp2.mul(Y1, Y2);
13325
+ let t2 = Fp2.mul(Z1, Z2);
13326
+ let t3 = Fp2.add(X1, Y1);
13327
+ let t4 = Fp2.add(X2, Y2);
13328
+ t3 = Fp2.mul(t3, t4);
13329
+ t4 = Fp2.add(t0, t1);
13330
+ t3 = Fp2.sub(t3, t4);
13331
+ t4 = Fp2.add(X1, Z1);
13332
+ let t5 = Fp2.add(X2, Z2);
13333
+ t4 = Fp2.mul(t4, t5);
13334
+ t5 = Fp2.add(t0, t2);
13335
+ t4 = Fp2.sub(t4, t5);
13336
+ t5 = Fp2.add(Y1, Z1);
13337
+ X3 = Fp2.add(Y2, Z2);
13338
+ t5 = Fp2.mul(t5, X3);
13339
+ X3 = Fp2.add(t1, t2);
13340
+ t5 = Fp2.sub(t5, X3);
13341
+ Z3 = Fp2.mul(a, t4);
13342
+ X3 = Fp2.mul(b3, t2);
13343
+ Z3 = Fp2.add(X3, Z3);
13344
+ X3 = Fp2.sub(t1, Z3);
13345
+ Z3 = Fp2.add(t1, Z3);
13346
+ Y3 = Fp2.mul(X3, Z3);
13347
+ t1 = Fp2.add(t0, t0);
13348
+ t1 = Fp2.add(t1, t0);
13349
+ t2 = Fp2.mul(a, t2);
13350
+ t4 = Fp2.mul(b3, t4);
13351
+ t1 = Fp2.add(t1, t2);
13352
+ t2 = Fp2.sub(t0, t2);
13353
+ t2 = Fp2.mul(a, t2);
13354
+ t4 = Fp2.add(t4, t2);
13355
+ t0 = Fp2.mul(t1, t4);
13356
+ Y3 = Fp2.add(Y3, t0);
13357
+ t0 = Fp2.mul(t5, t4);
13358
+ X3 = Fp2.mul(t3, X3);
13359
+ X3 = Fp2.sub(X3, t0);
13360
+ t0 = Fp2.mul(t3, t1);
13361
+ Z3 = Fp2.mul(t5, Z3);
13362
+ Z3 = Fp2.add(Z3, t0);
13363
+ return new Point(X3, Y3, Z3);
13364
+ }
13365
+ subtract(other) {
13366
+ return this.add(other.negate());
13367
+ }
13368
+ is0() {
13369
+ return this.equals(Point.ZERO);
13370
+ }
13371
+ /**
13372
+ * Constant time multiplication.
13373
+ * Uses wNAF method. Windowed method may be 10% faster,
13374
+ * but takes 2x longer to generate and consumes 2x memory.
13375
+ * Uses precomputes when available.
13376
+ * Uses endomorphism for Koblitz curves.
13377
+ * @param scalar by which the point would be multiplied
13378
+ * @returns New point
13379
+ */
13380
+ multiply(scalar) {
13381
+ const { endo: endo2 } = extraOpts;
13382
+ if (!Fn2.isValidNot0(scalar))
13383
+ throw new Error("invalid scalar: out of range");
13384
+ let point, fake;
13385
+ const mul = (n) => wnaf.cached(this, n, (p) => normalizeZ(Point, p));
13386
+ if (endo2) {
13387
+ const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(scalar);
13388
+ const { p: k1p, f: k1f } = mul(k1);
13389
+ const { p: k2p, f: k2f } = mul(k2);
13390
+ fake = k1f.add(k2f);
13391
+ point = finishEndo(endo2.beta, k1p, k2p, k1neg, k2neg);
13392
+ } else {
13393
+ const { p, f } = mul(scalar);
13394
+ point = p;
13395
+ fake = f;
13396
+ }
13397
+ return normalizeZ(Point, [point, fake])[0];
13398
+ }
13399
+ /**
13400
+ * Non-constant-time multiplication. Uses double-and-add algorithm.
13401
+ * It's faster, but should only be used when you don't care about
13402
+ * an exposed secret key e.g. sig verification, which works over *public* keys.
13403
+ */
13404
+ multiplyUnsafe(sc) {
13405
+ const { endo: endo2 } = extraOpts;
13406
+ const p = this;
13407
+ if (!Fn2.isValid(sc))
13408
+ throw new Error("invalid scalar: out of range");
13409
+ if (sc === _0n6 || p.is0())
13410
+ return Point.ZERO;
13411
+ if (sc === _1n6)
13412
+ return p;
13413
+ if (wnaf.hasCache(this))
13414
+ return this.multiply(sc);
13415
+ if (endo2) {
13416
+ const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(sc);
13417
+ const { p1, p2 } = mulEndoUnsafe(Point, p, k1, k2);
13418
+ return finishEndo(endo2.beta, p1, p2, k1neg, k2neg);
13419
+ } else {
13420
+ return wnaf.unsafe(p, sc);
13421
+ }
13422
+ }
13423
+ multiplyAndAddUnsafe(Q, a, b) {
13424
+ const sum = this.multiplyUnsafe(a).add(Q.multiplyUnsafe(b));
13425
+ return sum.is0() ? void 0 : sum;
13426
+ }
13427
+ /**
13428
+ * Converts Projective point to affine (x, y) coordinates.
13429
+ * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
13430
+ */
13431
+ toAffine(invertedZ) {
13432
+ return toAffineMemo(this, invertedZ);
13433
+ }
13434
+ /**
13435
+ * Checks whether Point is free of torsion elements (is in prime subgroup).
13436
+ * Always torsion-free for cofactor=1 curves.
13437
+ */
13438
+ isTorsionFree() {
13439
+ const { isTorsionFree } = extraOpts;
13440
+ if (cofactor === _1n6)
13441
+ return true;
13442
+ if (isTorsionFree)
13443
+ return isTorsionFree(Point, this);
13444
+ return wnaf.unsafe(this, CURVE_ORDER).is0();
13445
+ }
13446
+ clearCofactor() {
13447
+ const { clearCofactor } = extraOpts;
13448
+ if (cofactor === _1n6)
13449
+ return this;
13450
+ if (clearCofactor)
13451
+ return clearCofactor(Point, this);
13452
+ return this.multiplyUnsafe(cofactor);
13453
+ }
13454
+ isSmallOrder() {
13455
+ return this.multiplyUnsafe(cofactor).is0();
13456
+ }
13457
+ toBytes(isCompressed = true) {
13458
+ _abool2(isCompressed, "isCompressed");
13459
+ this.assertValidity();
13460
+ return encodePoint(Point, this, isCompressed);
13461
+ }
13462
+ toHex(isCompressed = true) {
13463
+ return bytesToHex(this.toBytes(isCompressed));
13464
+ }
13465
+ toString() {
13466
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
13467
+ }
13468
+ // TODO: remove
13469
+ get px() {
13470
+ return this.X;
13471
+ }
13472
+ get py() {
13473
+ return this.X;
13474
+ }
13475
+ get pz() {
13476
+ return this.Z;
13477
+ }
13478
+ toRawBytes(isCompressed = true) {
13479
+ return this.toBytes(isCompressed);
13480
+ }
13481
+ _setWindowSize(windowSize) {
13482
+ this.precompute(windowSize);
13483
+ }
13484
+ static normalizeZ(points) {
13485
+ return normalizeZ(Point, points);
13486
+ }
13487
+ static msm(points, scalars) {
13488
+ return pippenger(Point, Fn2, points, scalars);
13489
+ }
13490
+ static fromPrivateKey(privateKey) {
13491
+ return Point.BASE.multiply(_normFnElement(Fn2, privateKey));
13492
+ }
13493
+ }
13494
+ Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp2.ONE);
13495
+ Point.ZERO = new Point(Fp2.ZERO, Fp2.ONE, Fp2.ZERO);
13496
+ Point.Fp = Fp2;
13497
+ Point.Fn = Fn2;
13498
+ const bits = Fn2.BITS;
13499
+ const wnaf = new wNAF(Point, extraOpts.endo ? Math.ceil(bits / 2) : bits);
13500
+ Point.BASE.precompute(8);
13501
+ return Point;
13502
+ }
13503
+ function pprefix(hasEvenY) {
13504
+ return Uint8Array.of(hasEvenY ? 2 : 3);
13505
+ }
13506
+ function getWLengths(Fp2, Fn2) {
13507
+ return {
13508
+ secretKey: Fn2.BYTES,
13509
+ publicKey: 1 + Fp2.BYTES,
13510
+ publicKeyUncompressed: 1 + 2 * Fp2.BYTES,
13511
+ publicKeyHasPrefix: true,
13512
+ signature: 2 * Fn2.BYTES
13513
+ };
13514
+ }
13515
+ function ecdh(Point, ecdhOpts = {}) {
13516
+ const { Fn: Fn2 } = Point;
13517
+ const randomBytes_ = ecdhOpts.randomBytes || randomBytes;
13518
+ const lengths = Object.assign(getWLengths(Point.Fp, Fn2), { seed: getMinHashLength(Fn2.ORDER) });
13519
+ function isValidSecretKey(secretKey) {
13520
+ try {
13521
+ return !!_normFnElement(Fn2, secretKey);
13522
+ } catch (error) {
13523
+ return false;
13524
+ }
13525
+ }
13526
+ function isValidPublicKey(publicKey, isCompressed) {
13527
+ const { publicKey: comp, publicKeyUncompressed } = lengths;
13528
+ try {
13529
+ const l = publicKey.length;
13530
+ if (isCompressed === true && l !== comp)
13531
+ return false;
13532
+ if (isCompressed === false && l !== publicKeyUncompressed)
13533
+ return false;
13534
+ return !!Point.fromBytes(publicKey);
13535
+ } catch (error) {
13536
+ return false;
13537
+ }
13538
+ }
13539
+ function randomSecretKey(seed = randomBytes_(lengths.seed)) {
13540
+ return mapHashToField(_abytes2(seed, lengths.seed, "seed"), Fn2.ORDER);
13541
+ }
13542
+ function getPublicKey(secretKey, isCompressed = true) {
13543
+ return Point.BASE.multiply(_normFnElement(Fn2, secretKey)).toBytes(isCompressed);
13544
+ }
13545
+ function keygen(seed) {
13546
+ const secretKey = randomSecretKey(seed);
13547
+ return { secretKey, publicKey: getPublicKey(secretKey) };
13548
+ }
13549
+ function isProbPub(item) {
13550
+ if (typeof item === "bigint")
13551
+ return false;
13552
+ if (item instanceof Point)
13553
+ return true;
13554
+ const { secretKey, publicKey, publicKeyUncompressed } = lengths;
13555
+ if (Fn2.allowedLengths || secretKey === publicKey)
13556
+ return void 0;
13557
+ const l = ensureBytes("key", item).length;
13558
+ return l === publicKey || l === publicKeyUncompressed;
13559
+ }
13560
+ function getSharedSecret(secretKeyA, publicKeyB, isCompressed = true) {
13561
+ if (isProbPub(secretKeyA) === true)
13562
+ throw new Error("first arg must be private key");
13563
+ if (isProbPub(publicKeyB) === false)
13564
+ throw new Error("second arg must be public key");
13565
+ const s = _normFnElement(Fn2, secretKeyA);
13566
+ const b = Point.fromHex(publicKeyB);
13567
+ return b.multiply(s).toBytes(isCompressed);
13568
+ }
13569
+ const utils = {
13570
+ isValidSecretKey,
13571
+ isValidPublicKey,
13572
+ randomSecretKey,
13573
+ // TODO: remove
13574
+ isValidPrivateKey: isValidSecretKey,
13575
+ randomPrivateKey: randomSecretKey,
13576
+ normPrivateKeyToScalar: (key) => _normFnElement(Fn2, key),
13577
+ precompute(windowSize = 8, point = Point.BASE) {
13578
+ return point.precompute(windowSize, false);
13579
+ }
13580
+ };
13581
+ return Object.freeze({ getPublicKey, getSharedSecret, keygen, Point, utils, lengths });
13582
+ }
13583
+ function ecdsa(Point, hash, ecdsaOpts = {}) {
13584
+ ahash(hash);
13585
+ _validateObject(ecdsaOpts, {}, {
13586
+ hmac: "function",
13587
+ lowS: "boolean",
13588
+ randomBytes: "function",
13589
+ bits2int: "function",
13590
+ bits2int_modN: "function"
13591
+ });
13592
+ const randomBytes4 = ecdsaOpts.randomBytes || randomBytes;
13593
+ const hmac2 = ecdsaOpts.hmac || ((key, ...msgs) => hmac(hash, key, concatBytes(...msgs)));
13594
+ const { Fp: Fp2, Fn: Fn2 } = Point;
13595
+ const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn2;
13596
+ const { keygen, getPublicKey, getSharedSecret, utils, lengths } = ecdh(Point, ecdsaOpts);
13597
+ const defaultSigOpts = {
13598
+ prehash: false,
13599
+ lowS: typeof ecdsaOpts.lowS === "boolean" ? ecdsaOpts.lowS : false,
13600
+ format: void 0,
13601
+ //'compact' as ECDSASigFormat,
13602
+ extraEntropy: false
13603
+ };
13604
+ const defaultSigOpts_format = "compact";
13605
+ function isBiggerThanHalfOrder(number) {
13606
+ const HALF = CURVE_ORDER >> _1n6;
13607
+ return number > HALF;
13608
+ }
13609
+ function validateRS(title, num) {
13610
+ if (!Fn2.isValidNot0(num))
13611
+ throw new Error(`invalid signature ${title}: out of range 1..Point.Fn.ORDER`);
13612
+ return num;
13613
+ }
13614
+ function validateSigLength(bytes, format5) {
13615
+ validateSigFormat(format5);
13616
+ const size = lengths.signature;
13617
+ const sizer = format5 === "compact" ? size : format5 === "recovered" ? size + 1 : void 0;
13618
+ return _abytes2(bytes, sizer, `${format5} signature`);
13619
+ }
13620
+ class Signature {
13621
+ constructor(r, s, recovery) {
13622
+ this.r = validateRS("r", r);
13623
+ this.s = validateRS("s", s);
13624
+ if (recovery != null)
13625
+ this.recovery = recovery;
13626
+ Object.freeze(this);
13627
+ }
13628
+ static fromBytes(bytes, format5 = defaultSigOpts_format) {
13629
+ validateSigLength(bytes, format5);
13630
+ let recid;
13631
+ if (format5 === "der") {
13632
+ const { r: r2, s: s2 } = DER.toSig(_abytes2(bytes));
13633
+ return new Signature(r2, s2);
13634
+ }
13635
+ if (format5 === "recovered") {
13636
+ recid = bytes[0];
13637
+ format5 = "compact";
13638
+ bytes = bytes.subarray(1);
13639
+ }
13640
+ const L = Fn2.BYTES;
13641
+ const r = bytes.subarray(0, L);
13642
+ const s = bytes.subarray(L, L * 2);
13643
+ return new Signature(Fn2.fromBytes(r), Fn2.fromBytes(s), recid);
13644
+ }
13645
+ static fromHex(hex3, format5) {
13646
+ return this.fromBytes(hexToBytes(hex3), format5);
13647
+ }
13648
+ addRecoveryBit(recovery) {
13649
+ return new Signature(this.r, this.s, recovery);
13650
+ }
13651
+ recoverPublicKey(messageHash) {
13652
+ const FIELD_ORDER = Fp2.ORDER;
13653
+ const { r, s, recovery: rec } = this;
13654
+ if (rec == null || ![0, 1, 2, 3].includes(rec))
13655
+ throw new Error("recovery id invalid");
13656
+ const hasCofactor = CURVE_ORDER * _2n4 < FIELD_ORDER;
13657
+ if (hasCofactor && rec > 1)
13658
+ throw new Error("recovery id is ambiguous for h>1 curve");
13659
+ const radj = rec === 2 || rec === 3 ? r + CURVE_ORDER : r;
13660
+ if (!Fp2.isValid(radj))
13661
+ throw new Error("recovery id 2 or 3 invalid");
13662
+ const x = Fp2.toBytes(radj);
13663
+ const R = Point.fromBytes(concatBytes(pprefix((rec & 1) === 0), x));
13664
+ const ir = Fn2.inv(radj);
13665
+ const h = bits2int_modN(ensureBytes("msgHash", messageHash));
13666
+ const u1 = Fn2.create(-h * ir);
13667
+ const u2 = Fn2.create(s * ir);
13668
+ const Q = Point.BASE.multiplyUnsafe(u1).add(R.multiplyUnsafe(u2));
13669
+ if (Q.is0())
13670
+ throw new Error("point at infinify");
13671
+ Q.assertValidity();
13672
+ return Q;
13673
+ }
13674
+ // Signatures should be low-s, to prevent malleability.
13675
+ hasHighS() {
13676
+ return isBiggerThanHalfOrder(this.s);
13677
+ }
13678
+ toBytes(format5 = defaultSigOpts_format) {
13679
+ validateSigFormat(format5);
13680
+ if (format5 === "der")
13681
+ return hexToBytes(DER.hexFromSig(this));
13682
+ const r = Fn2.toBytes(this.r);
13683
+ const s = Fn2.toBytes(this.s);
13684
+ if (format5 === "recovered") {
13685
+ if (this.recovery == null)
13686
+ throw new Error("recovery bit must be present");
13687
+ return concatBytes(Uint8Array.of(this.recovery), r, s);
13688
+ }
13689
+ return concatBytes(r, s);
13690
+ }
13691
+ toHex(format5) {
13692
+ return bytesToHex(this.toBytes(format5));
13693
+ }
13694
+ // TODO: remove
13695
+ assertValidity() {
13696
+ }
13697
+ static fromCompact(hex3) {
13698
+ return Signature.fromBytes(ensureBytes("sig", hex3), "compact");
13699
+ }
13700
+ static fromDER(hex3) {
13701
+ return Signature.fromBytes(ensureBytes("sig", hex3), "der");
13702
+ }
13703
+ normalizeS() {
13704
+ return this.hasHighS() ? new Signature(this.r, Fn2.neg(this.s), this.recovery) : this;
13705
+ }
13706
+ toDERRawBytes() {
13707
+ return this.toBytes("der");
13708
+ }
13709
+ toDERHex() {
13710
+ return bytesToHex(this.toBytes("der"));
13711
+ }
13712
+ toCompactRawBytes() {
13713
+ return this.toBytes("compact");
13714
+ }
13715
+ toCompactHex() {
13716
+ return bytesToHex(this.toBytes("compact"));
13717
+ }
13718
+ }
13719
+ const bits2int = ecdsaOpts.bits2int || function bits2int_def(bytes) {
13720
+ if (bytes.length > 8192)
13721
+ throw new Error("input is too large");
13722
+ const num = bytesToNumberBE(bytes);
13723
+ const delta = bytes.length * 8 - fnBits;
13724
+ return delta > 0 ? num >> BigInt(delta) : num;
13725
+ };
13726
+ const bits2int_modN = ecdsaOpts.bits2int_modN || function bits2int_modN_def(bytes) {
13727
+ return Fn2.create(bits2int(bytes));
13728
+ };
13729
+ const ORDER_MASK = bitMask(fnBits);
13730
+ function int2octets(num) {
13731
+ aInRange("num < 2^" + fnBits, num, _0n6, ORDER_MASK);
13732
+ return Fn2.toBytes(num);
13733
+ }
13734
+ function validateMsgAndHash(message, prehash) {
13735
+ _abytes2(message, void 0, "message");
13736
+ return prehash ? _abytes2(hash(message), void 0, "prehashed message") : message;
13737
+ }
13738
+ function prepSig(message, privateKey, opts) {
13739
+ if (["recovered", "canonical"].some((k) => k in opts))
13740
+ throw new Error("sign() legacy options not supported");
13741
+ const { lowS, prehash, extraEntropy } = validateSigOpts(opts, defaultSigOpts);
13742
+ message = validateMsgAndHash(message, prehash);
13743
+ const h1int = bits2int_modN(message);
13744
+ const d = _normFnElement(Fn2, privateKey);
13745
+ const seedArgs = [int2octets(d), int2octets(h1int)];
13746
+ if (extraEntropy != null && extraEntropy !== false) {
13747
+ const e = extraEntropy === true ? randomBytes4(lengths.secretKey) : extraEntropy;
13748
+ seedArgs.push(ensureBytes("extraEntropy", e));
13749
+ }
13750
+ const seed = concatBytes(...seedArgs);
13751
+ const m = h1int;
13752
+ function k2sig(kBytes) {
13753
+ const k = bits2int(kBytes);
13754
+ if (!Fn2.isValidNot0(k))
13755
+ return;
13756
+ const ik = Fn2.inv(k);
13757
+ const q = Point.BASE.multiply(k).toAffine();
13758
+ const r = Fn2.create(q.x);
13759
+ if (r === _0n6)
13760
+ return;
13761
+ const s = Fn2.create(ik * Fn2.create(m + r * d));
13762
+ if (s === _0n6)
13763
+ return;
13764
+ let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n6);
13765
+ let normS = s;
13766
+ if (lowS && isBiggerThanHalfOrder(s)) {
13767
+ normS = Fn2.neg(s);
13768
+ recovery ^= 1;
13769
+ }
13770
+ return new Signature(r, normS, recovery);
13771
+ }
13772
+ return { seed, k2sig };
13773
+ }
13774
+ function sign(message, secretKey, opts = {}) {
13775
+ message = ensureBytes("message", message);
13776
+ const { seed, k2sig } = prepSig(message, secretKey, opts);
13777
+ const drbg = createHmacDrbg(hash.outputLen, Fn2.BYTES, hmac2);
13778
+ const sig = drbg(seed, k2sig);
13779
+ return sig;
13780
+ }
13781
+ function tryParsingSig(sg) {
13782
+ let sig = void 0;
13783
+ const isHex = typeof sg === "string" || isBytes(sg);
13784
+ const isObj = !isHex && sg !== null && typeof sg === "object" && typeof sg.r === "bigint" && typeof sg.s === "bigint";
13785
+ if (!isHex && !isObj)
13786
+ throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
13787
+ if (isObj) {
13788
+ sig = new Signature(sg.r, sg.s);
13789
+ } else if (isHex) {
13790
+ try {
13791
+ sig = Signature.fromBytes(ensureBytes("sig", sg), "der");
13792
+ } catch (derError) {
13793
+ if (!(derError instanceof DER.Err))
13794
+ throw derError;
13795
+ }
13796
+ if (!sig) {
13797
+ try {
13798
+ sig = Signature.fromBytes(ensureBytes("sig", sg), "compact");
13799
+ } catch (error) {
13800
+ return false;
13801
+ }
13802
+ }
13803
+ }
13804
+ if (!sig)
13805
+ return false;
13806
+ return sig;
13807
+ }
13808
+ function verify(signature, message, publicKey, opts = {}) {
13809
+ const { lowS, prehash, format: format5 } = validateSigOpts(opts, defaultSigOpts);
13810
+ publicKey = ensureBytes("publicKey", publicKey);
13811
+ message = validateMsgAndHash(ensureBytes("message", message), prehash);
13812
+ if ("strict" in opts)
13813
+ throw new Error("options.strict was renamed to lowS");
13814
+ const sig = format5 === void 0 ? tryParsingSig(signature) : Signature.fromBytes(ensureBytes("sig", signature), format5);
13815
+ if (sig === false)
13816
+ return false;
13817
+ try {
13818
+ const P = Point.fromBytes(publicKey);
13819
+ if (lowS && sig.hasHighS())
13820
+ return false;
13821
+ const { r, s } = sig;
13822
+ const h = bits2int_modN(message);
13823
+ const is = Fn2.inv(s);
13824
+ const u1 = Fn2.create(h * is);
13825
+ const u2 = Fn2.create(r * is);
13826
+ const R = Point.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
13827
+ if (R.is0())
13828
+ return false;
13829
+ const v = Fn2.create(R.x);
13830
+ return v === r;
13831
+ } catch (e) {
13832
+ return false;
13833
+ }
13834
+ }
13835
+ function recoverPublicKey(signature, message, opts = {}) {
13836
+ const { prehash } = validateSigOpts(opts, defaultSigOpts);
13837
+ message = validateMsgAndHash(message, prehash);
13838
+ return Signature.fromBytes(signature, "recovered").recoverPublicKey(message).toBytes();
13839
+ }
13840
+ return Object.freeze({
13841
+ keygen,
13842
+ getPublicKey,
13843
+ getSharedSecret,
13844
+ utils,
13845
+ lengths,
13846
+ Point,
13847
+ sign,
13848
+ verify,
13849
+ recoverPublicKey,
13850
+ Signature,
13851
+ hash
13852
+ });
13853
+ }
13854
+ function _weierstrass_legacy_opts_to_new(c) {
13855
+ const CURVE = {
13856
+ a: c.a,
13857
+ b: c.b,
13858
+ p: c.Fp.ORDER,
13859
+ n: c.n,
13860
+ h: c.h,
13861
+ Gx: c.Gx,
13862
+ Gy: c.Gy
13863
+ };
13864
+ const Fp2 = c.Fp;
13865
+ let allowedLengths = c.allowedPrivateKeyLengths ? Array.from(new Set(c.allowedPrivateKeyLengths.map((l) => Math.ceil(l / 2)))) : void 0;
13866
+ const Fn2 = Field(CURVE.n, {
13867
+ BITS: c.nBitLength,
13868
+ allowedLengths,
13869
+ modFromBytes: c.wrapPrivateKey
13870
+ });
13871
+ const curveOpts = {
13872
+ Fp: Fp2,
13873
+ Fn: Fn2,
13874
+ allowInfinityPoint: c.allowInfinityPoint,
13875
+ endo: c.endo,
13876
+ isTorsionFree: c.isTorsionFree,
13877
+ clearCofactor: c.clearCofactor,
13878
+ fromBytes: c.fromBytes,
13879
+ toBytes: c.toBytes
13880
+ };
13881
+ return { CURVE, curveOpts };
13882
+ }
13883
+ function _ecdsa_legacy_opts_to_new(c) {
13884
+ const { CURVE, curveOpts } = _weierstrass_legacy_opts_to_new(c);
13885
+ const ecdsaOpts = {
13886
+ hmac: c.hmac,
13887
+ randomBytes: c.randomBytes,
13888
+ lowS: c.lowS,
13889
+ bits2int: c.bits2int,
13890
+ bits2int_modN: c.bits2int_modN
13891
+ };
13892
+ return { CURVE, curveOpts, hash: c.hash, ecdsaOpts };
13893
+ }
13894
+ function _ecdsa_new_output_to_legacy(c, _ecdsa) {
13895
+ const Point = _ecdsa.Point;
13896
+ return Object.assign({}, _ecdsa, {
13897
+ ProjectivePoint: Point,
13898
+ CURVE: Object.assign({}, c, nLength(Point.Fn.ORDER, Point.Fn.BITS))
13899
+ });
13900
+ }
13901
+ function weierstrass(c) {
13902
+ const { CURVE, curveOpts, hash, ecdsaOpts } = _ecdsa_legacy_opts_to_new(c);
13903
+ const Point = weierstrassN(CURVE, curveOpts);
13904
+ const signs = ecdsa(Point, hash, ecdsaOpts);
13905
+ return _ecdsa_new_output_to_legacy(c, signs);
13906
+ }
13907
+ var divNearest, DERErr, DER, _0n6, _1n6, _2n4, _3n3, _4n2;
13908
+ var init_weierstrass = __esm({
13909
+ "../../node_modules/@noble/curves/esm/abstract/weierstrass.js"() {
13910
+ "use strict";
13911
+ init_hmac();
13912
+ init_utils();
13913
+ init_utils2();
13914
+ init_curve();
13915
+ init_modular();
13916
+ divNearest = (num, den) => (num + (num >= 0 ? den : -den) / _2n4) / den;
13917
+ DERErr = class extends Error {
13918
+ constructor(m = "") {
13919
+ super(m);
13920
+ }
13921
+ };
13922
+ DER = {
13923
+ // asn.1 DER encoding utils
13924
+ Err: DERErr,
13925
+ // Basic building block is TLV (Tag-Length-Value)
13926
+ _tlv: {
13927
+ encode: (tag, data) => {
13928
+ const { Err: E } = DER;
13929
+ if (tag < 0 || tag > 256)
13930
+ throw new E("tlv.encode: wrong tag");
13931
+ if (data.length & 1)
13932
+ throw new E("tlv.encode: unpadded data");
13933
+ const dataLen = data.length / 2;
13934
+ const len = numberToHexUnpadded(dataLen);
13935
+ if (len.length / 2 & 128)
13936
+ throw new E("tlv.encode: long form length too big");
13937
+ const lenLen = dataLen > 127 ? numberToHexUnpadded(len.length / 2 | 128) : "";
13938
+ const t = numberToHexUnpadded(tag);
13939
+ return t + lenLen + len + data;
13940
+ },
13941
+ // v - value, l - left bytes (unparsed)
13942
+ decode(tag, data) {
13943
+ const { Err: E } = DER;
13944
+ let pos = 0;
13945
+ if (tag < 0 || tag > 256)
13946
+ throw new E("tlv.encode: wrong tag");
13947
+ if (data.length < 2 || data[pos++] !== tag)
13948
+ throw new E("tlv.decode: wrong tlv");
13949
+ const first = data[pos++];
13950
+ const isLong = !!(first & 128);
13951
+ let length5 = 0;
13952
+ if (!isLong)
13953
+ length5 = first;
13954
+ else {
13955
+ const lenLen = first & 127;
13956
+ if (!lenLen)
13957
+ throw new E("tlv.decode(long): indefinite length not supported");
13958
+ if (lenLen > 4)
13959
+ throw new E("tlv.decode(long): byte length is too big");
13960
+ const lengthBytes = data.subarray(pos, pos + lenLen);
13961
+ if (lengthBytes.length !== lenLen)
13962
+ throw new E("tlv.decode: length bytes not complete");
13963
+ if (lengthBytes[0] === 0)
13964
+ throw new E("tlv.decode(long): zero leftmost byte");
13965
+ for (const b of lengthBytes)
13966
+ length5 = length5 << 8 | b;
13967
+ pos += lenLen;
13968
+ if (length5 < 128)
13969
+ throw new E("tlv.decode(long): not minimal encoding");
13970
+ }
13971
+ const v = data.subarray(pos, pos + length5);
13972
+ if (v.length !== length5)
13973
+ throw new E("tlv.decode: wrong value length");
13974
+ return { v, l: data.subarray(pos + length5) };
13975
+ }
13976
+ },
13977
+ // https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
13978
+ // since we always use positive integers here. It must always be empty:
13979
+ // - add zero byte if exists
13980
+ // - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
13981
+ _int: {
13982
+ encode(num) {
13983
+ const { Err: E } = DER;
13984
+ if (num < _0n6)
13985
+ throw new E("integer: negative integers are not allowed");
13986
+ let hex3 = numberToHexUnpadded(num);
13987
+ if (Number.parseInt(hex3[0], 16) & 8)
13988
+ hex3 = "00" + hex3;
13989
+ if (hex3.length & 1)
13990
+ throw new E("unexpected DER parsing assertion: unpadded hex");
13991
+ return hex3;
13992
+ },
13993
+ decode(data) {
13994
+ const { Err: E } = DER;
13995
+ if (data[0] & 128)
13996
+ throw new E("invalid signature integer: negative");
13997
+ if (data[0] === 0 && !(data[1] & 128))
13998
+ throw new E("invalid signature integer: unnecessary leading zero");
13999
+ return bytesToNumberBE(data);
14000
+ }
14001
+ },
14002
+ toSig(hex3) {
14003
+ const { Err: E, _int: int, _tlv: tlv } = DER;
14004
+ const data = ensureBytes("signature", hex3);
14005
+ const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
14006
+ if (seqLeftBytes.length)
14007
+ throw new E("invalid signature: left bytes after parsing");
14008
+ const { v: rBytes, l: rLeftBytes } = tlv.decode(2, seqBytes);
14009
+ const { v: sBytes, l: sLeftBytes } = tlv.decode(2, rLeftBytes);
14010
+ if (sLeftBytes.length)
14011
+ throw new E("invalid signature: left bytes after parsing");
14012
+ return { r: int.decode(rBytes), s: int.decode(sBytes) };
14013
+ },
14014
+ hexFromSig(sig) {
14015
+ const { _tlv: tlv, _int: int } = DER;
14016
+ const rs = tlv.encode(2, int.encode(sig.r));
14017
+ const ss = tlv.encode(2, int.encode(sig.s));
14018
+ const seq = rs + ss;
14019
+ return tlv.encode(48, seq);
14020
+ }
14021
+ };
14022
+ _0n6 = BigInt(0);
14023
+ _1n6 = BigInt(1);
14024
+ _2n4 = BigInt(2);
14025
+ _3n3 = BigInt(3);
14026
+ _4n2 = BigInt(4);
14027
+ }
14028
+ });
14029
+
14030
+ // ../../node_modules/@noble/curves/esm/_shortw_utils.js
14031
+ function createCurve(curveDef, defHash) {
14032
+ const create5 = (hash) => weierstrass({ ...curveDef, hash });
14033
+ return { ...create5(defHash), create: create5 };
14034
+ }
14035
+ var init_shortw_utils = __esm({
14036
+ "../../node_modules/@noble/curves/esm/_shortw_utils.js"() {
14037
+ "use strict";
14038
+ init_weierstrass();
14039
+ }
14040
+ });
14041
+
14042
+ // ../../node_modules/@noble/curves/esm/nist.js
14043
+ var p256_CURVE, p384_CURVE, p521_CURVE, Fp256, Fp384, Fp521, p256, p384, p521;
14044
+ var init_nist = __esm({
14045
+ "../../node_modules/@noble/curves/esm/nist.js"() {
14046
+ "use strict";
14047
+ init_sha2();
14048
+ init_shortw_utils();
14049
+ init_modular();
14050
+ p256_CURVE = {
14051
+ p: BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),
14052
+ n: BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),
14053
+ h: BigInt(1),
14054
+ a: BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),
14055
+ b: BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),
14056
+ Gx: BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),
14057
+ Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")
14058
+ };
14059
+ p384_CURVE = {
14060
+ p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),
14061
+ n: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),
14062
+ h: BigInt(1),
14063
+ a: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),
14064
+ b: BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),
14065
+ Gx: BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),
14066
+ Gy: BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")
14067
+ };
14068
+ p521_CURVE = {
14069
+ p: BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
14070
+ n: BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),
14071
+ h: BigInt(1),
14072
+ a: BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),
14073
+ b: BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),
14074
+ Gx: BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),
14075
+ Gy: BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")
14076
+ };
14077
+ Fp256 = Field(p256_CURVE.p);
14078
+ Fp384 = Field(p384_CURVE.p);
14079
+ Fp521 = Field(p521_CURVE.p);
14080
+ p256 = createCurve({ ...p256_CURVE, Fp: Fp256, lowS: false }, sha256);
14081
+ p384 = createCurve({ ...p384_CURVE, Fp: Fp384, lowS: false }, sha384);
14082
+ p521 = createCurve({ ...p521_CURVE, Fp: Fp521, lowS: false, allowedPrivateKeyLengths: [130, 131, 132] }, sha512);
14083
+ }
14084
+ });
14085
+
14086
+ // ../../node_modules/@noble/curves/esm/p256.js
14087
+ var p2562;
14088
+ var init_p256 = __esm({
14089
+ "../../node_modules/@noble/curves/esm/p256.js"() {
14090
+ "use strict";
14091
+ init_nist();
14092
+ p2562 = p256;
14093
+ }
14094
+ });
14095
+
12792
14096
  // ../share-envelope/dist/links.js
12793
14097
  var links_exports = {};
12794
14098
  __export(links_exports, {
@@ -12815,6 +14119,7 @@ __export(links_exports, {
12815
14119
  checkLinkBody: () => checkLinkBody,
12816
14120
  checkLinkHeaderLife: () => checkLinkHeaderLife,
12817
14121
  checkLinkRecord: () => checkLinkRecord,
14122
+ createApprovalRequest: () => createApprovalRequest,
12818
14123
  createLink: () => createLink,
12819
14124
  deleteLink: () => deleteLink,
12820
14125
  ed25519KeyProblem: () => ed25519KeyProblem,
@@ -12828,11 +14133,13 @@ __export(links_exports, {
12828
14133
  linkTypeSchema: () => linkTypeSchema,
12829
14134
  normalizeLinkId: () => normalizeLinkId,
12830
14135
  openLinkRecord: () => openLinkRecord,
14136
+ parseApprovalRequest: () => parseApprovalRequest,
12831
14137
  parseLink: () => parseLink,
12832
14138
  parseLinkTimestamp: () => parseLinkTimestamp,
12833
14139
  prepareLinkRecord: () => prepareLinkRecord,
12834
14140
  randomLinkNonce: () => randomLinkNonce,
12835
14141
  redactLink: () => redactLink,
14142
+ resolveApprovalRequest: () => resolveApprovalRequest,
12836
14143
  resolveLink: () => resolveLink,
12837
14144
  shortShareLinkCid: () => shortShareLinkCid,
12838
14145
  signDelete: () => signDelete,
@@ -13207,14 +14514,14 @@ function linkTypeForPathLetter(letter) {
13207
14514
  function normalizeLinkId(id) {
13208
14515
  return /^[A-Za-z2-7]{26}$/.test(id) ? id.toLowerCase() : null;
13209
14516
  }
13210
- function canonicalHttpsOrigin(origin) {
14517
+ function canonicalHttpsOrigin(origin2) {
13211
14518
  let url;
13212
14519
  try {
13213
- url = new URL(origin);
14520
+ url = new URL(origin2);
13214
14521
  } catch {
13215
14522
  return false;
13216
14523
  }
13217
- return url.protocol === "https:" && url.username === "" && url.password === "" && url.origin === origin;
14524
+ return url.protocol === "https:" && url.username === "" && url.password === "" && url.origin === origin2;
13218
14525
  }
13219
14526
  function assertKey2(key) {
13220
14527
  if (key.length !== 32) throw new LinkError("invalid_argument", "a link key is 32 bytes");
@@ -13347,9 +14654,19 @@ async function openLinkRecord(record2, key, options = {}) {
13347
14654
  await runBodyValidator(opened, options.validateBody);
13348
14655
  return opened;
13349
14656
  }
13350
- function checkApiOrigin(origin) {
13351
- if (!AUDIENCE_ORIGIN.test(origin)) throw new LinkError("invalid_argument", "the API origin is not a canonical https origin");
13352
- return origin;
14657
+ function parseApprovalRequest(value, options = {}) {
14658
+ const parsed = requestSchema.safeParse(value);
14659
+ if (!parsed.success) throw new LinkError("body_validation_failed", "invalid approval request");
14660
+ const request = parsed.data;
14661
+ const publicKey = decodeStrictBase64Url(request.targetPublicJwk.x);
14662
+ if (ed25519KeyProblem(publicKey) !== null || didKeyFromEd25519PublicKey(publicKey) !== request.targetDid || request.issuer !== request.targetDid || options.issuer !== void 0 && request.issuer !== options.issuer) {
14663
+ throw new LinkError("issuer_binding_mismatch");
14664
+ }
14665
+ return request;
14666
+ }
14667
+ function checkApiOrigin(origin2) {
14668
+ if (!AUDIENCE_ORIGIN.test(origin2)) throw new LinkError("invalid_argument", "the API origin is not a canonical https origin");
14669
+ return origin2;
13353
14670
  }
13354
14671
  function requestSignal(options) {
13355
14672
  const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
@@ -13462,6 +14779,34 @@ async function createLink(input) {
13462
14779
  const { id } = created.data;
13463
14780
  return { link: buildShortLink({ origin: input.linkOrigin, type: input.type, id, key, bodyCid }), id, expiresAt: record2.header.expiresAt, bodyCid };
13464
14781
  }
14782
+ async function createApprovalRequest(input) {
14783
+ const request = parseApprovalRequest(input.request, { issuer: input.issuerKey.did });
14784
+ const now = toEpochMs(input.now);
14785
+ const prepared = await prepareLinkRecord({
14786
+ type: "openkey-approval-request",
14787
+ issuerKey: input.issuerKey,
14788
+ apiOrigin: input.apiOrigin,
14789
+ now,
14790
+ expiresAt: input.expiresAt ?? new Date(now + LINK_TYPE_SPECS["openkey-approval-request"].defaultLifeSeconds * 1e3),
14791
+ plaintext: new TextEncoder().encode(canonicalize2(request))
14792
+ });
14793
+ const response = await send(
14794
+ `${checkApiOrigin(input.apiOrigin)}/v1/links`,
14795
+ { method: "POST", body: JSON.stringify(prepared.record) },
14796
+ input,
14797
+ "application/json"
14798
+ );
14799
+ if (response.status !== 201) throw await refusal(response);
14800
+ const created = createdSchema.safeParse(await readJson2(response));
14801
+ if (!created.success || !LINK_ID_PATTERN.test(created.data.id) || created.data.expiresAt !== prepared.record.header.expiresAt) throw new LinkError("invalid_response");
14802
+ return {
14803
+ id: created.data.id,
14804
+ expiresAt: prepared.record.header.expiresAt,
14805
+ bodyCid: prepared.bodyCid,
14806
+ record: prepared.record,
14807
+ link: buildShortLink({ origin: input.openkeyOrigin, type: "openkey-approval-request", id: created.data.id, key: prepared.key, bodyCid: prepared.bodyCid })
14808
+ };
14809
+ }
13465
14810
  async function deleteLink(input) {
13466
14811
  const apiOrigin = checkApiOrigin(input.apiOrigin);
13467
14812
  const id = normalizeLinkId(input.id);
@@ -13526,9 +14871,20 @@ async function resolveLink(link4, input) {
13526
14871
  } else if (opened.type !== "share") {
13527
14872
  throw new LinkError("full_non_share");
13528
14873
  }
14874
+ if (opened.type === "openkey-approval-request") {
14875
+ if (opened.header.audience !== input.apiOrigin) throw new LinkError("audience_mismatch");
14876
+ parseApprovalRequest(opened.value, { issuer: opened.header.issuer });
14877
+ }
13529
14878
  await runBodyValidator(opened, input.validateBody);
13530
14879
  return { ...opened, form: parsed.form, id: parsed.form === "short" ? parsed.id : void 0 };
13531
14880
  }
14881
+ async function resolveApprovalRequest(link4, input) {
14882
+ const opened = await resolveLink(link4, input);
14883
+ if (opened.type !== "openkey-approval-request") throw new LinkError("type_path_mismatch");
14884
+ if (opened.header.audience !== input.apiOrigin) throw new LinkError("audience_mismatch");
14885
+ const request = parseApprovalRequest(opened.value, { issuer: opened.header.issuer });
14886
+ return { ...opened, request };
14887
+ }
13532
14888
  function shortShareLinkCid(href, options) {
13533
14889
  try {
13534
14890
  const parsed = parseLink(href, { trustedOrigins: options.trustedOrigins });
@@ -13571,7 +14927,7 @@ function signerFromJwk(jwk) {
13571
14927
  if (signer.did !== didKeyFromEd25519PublicKey(publicKey)) throw new LinkError("invalid_argument", "the JWK public key does not match its private key");
13572
14928
  return signer;
13573
14929
  }
13574
- var SHA256_CODE2, ENVELOPE_AAD_LABEL2, SEALED_BLOB_VERSION, AAD2, KEY_LENGTH, NONCE_LENGTH, TAG_LENGTH, HEADER_LENGTH, LINK_TYPES, MAX_LINK_BODY_BYTES, MAX_LINK_REQUEST_BYTES, LINK_TYPE_SPECS, LINK_HEADER_DOMAIN, LINK_DELETE_DOMAIN, LINK_WINDOW_SECONDS, LINK_MIN_LIFE_SECONDS, LINK_MIN_BODY_BYTES, LINK_SEAL_OVERHEAD_BYTES, LINK_MAX_RECORD_HEADER_BYTES, DEFAULT_LINKS_API_ORIGIN, FULL_LINK_PATH, LINK_ID_PATTERN, LinkError, ED25519_MULTICODEC_PREFIX2, PUBLIC_KEY_LENGTH, ExtendedPoint, GROUP_ORDER, FIELD_PRIME, DID_KEY_PATTERN, SERVICE_ISSUER_PATTERN, AUDIENCE_PATTERN, TIMESTAMP_PATTERN, NONCE_PATTERN, CID_PATTERN, HEADER_KEYS, DELETE_KEYS, ed25519DidKey, linkTypeSchema, linkHeaderV1Schema, linkSignatureV1Schema, linkDeleteRequestV1Schema, LINK_FRAGMENT_VERSION, SHORT_PATH, SHORT_FRAGMENT, FULL_FRAGMENT, REMOVED_FRAGMENT, MAX_FULL_RECORD_JSON_BYTES, jsonObject, DEFAULT_TIMEOUT_MS, MAX_JSON_RESPONSE_BYTES, AUDIENCE_ORIGIN, createdSchema, errorBodySchema, KEY_PARAMETER, DEFAULT_SHARE_ORIGINS;
14930
+ var SHA256_CODE2, ENVELOPE_AAD_LABEL2, SEALED_BLOB_VERSION, AAD2, KEY_LENGTH, NONCE_LENGTH, TAG_LENGTH, HEADER_LENGTH, LINK_TYPES, MAX_LINK_BODY_BYTES, MAX_LINK_REQUEST_BYTES, LINK_TYPE_SPECS, LINK_HEADER_DOMAIN, LINK_DELETE_DOMAIN, LINK_WINDOW_SECONDS, LINK_MIN_LIFE_SECONDS, LINK_MIN_BODY_BYTES, LINK_SEAL_OVERHEAD_BYTES, LINK_MAX_RECORD_HEADER_BYTES, DEFAULT_LINKS_API_ORIGIN, FULL_LINK_PATH, LINK_ID_PATTERN, LinkError, ED25519_MULTICODEC_PREFIX2, PUBLIC_KEY_LENGTH, ExtendedPoint, GROUP_ORDER, FIELD_PRIME, DID_KEY_PATTERN, SERVICE_ISSUER_PATTERN, AUDIENCE_PATTERN, TIMESTAMP_PATTERN, NONCE_PATTERN, CID_PATTERN, HEADER_KEYS, DELETE_KEYS, ed25519DidKey, linkTypeSchema, linkHeaderV1Schema, linkSignatureV1Schema, linkDeleteRequestV1Schema, LINK_FRAGMENT_VERSION, SHORT_PATH, SHORT_FRAGMENT, FULL_FRAGMENT, REMOVED_FRAGMENT, MAX_FULL_RECORD_JSON_BYTES, jsonObject, bytes32, ed25519Jwk, p256Jwk, origin, permission, requestSchema, DEFAULT_TIMEOUT_MS, MAX_JSON_RESPONSE_BYTES, AUDIENCE_ORIGIN, createdSchema, errorBodySchema, KEY_PARAMETER, DEFAULT_SHARE_ORIGINS;
13575
14931
  var init_links = __esm({
13576
14932
  "../share-envelope/dist/links.js"() {
13577
14933
  "use strict";
@@ -13586,6 +14942,8 @@ var init_links = __esm({
13586
14942
  init_base58();
13587
14943
  init_ed25519();
13588
14944
  init_zod();
14945
+ init_p256();
14946
+ init_zod();
13589
14947
  init_ed25519();
13590
14948
  SHA256_CODE2 = 18;
13591
14949
  ENVELOPE_AAD_LABEL2 = "tinycloud-share-envelope-v1";
@@ -13595,11 +14953,12 @@ var init_links = __esm({
13595
14953
  NONCE_LENGTH = 12;
13596
14954
  TAG_LENGTH = 16;
13597
14955
  HEADER_LENGTH = 1;
13598
- LINK_TYPES = ["openkey-login", "courier", "share"];
14956
+ LINK_TYPES = ["openkey-login", "openkey-approval-request", "courier", "share"];
13599
14957
  MAX_LINK_BODY_BYTES = 65536;
13600
14958
  MAX_LINK_REQUEST_BYTES = Math.ceil(MAX_LINK_BODY_BYTES * 4 / 3) + 3072;
13601
14959
  LINK_TYPE_SPECS = {
13602
14960
  "openkey-login": { maxLifeSeconds: 600, defaultLifeSeconds: 600, pathLetter: "l", readOnce: true },
14961
+ "openkey-approval-request": { maxLifeSeconds: 86400, defaultLifeSeconds: 3600, pathLetter: "a", readOnce: false },
13603
14962
  courier: { maxLifeSeconds: 604800, defaultLifeSeconds: 86400, pathLetter: "c", readOnce: false },
13604
14963
  share: { maxLifeSeconds: 2592e3, defaultLifeSeconds: 2592e3, pathLetter: "s", readOnce: false }
13605
14964
  };
@@ -13670,12 +15029,52 @@ var init_links = __esm({
13670
15029
  nonce: external_exports2.string()
13671
15030
  }).strict();
13672
15031
  LINK_FRAGMENT_VERSION = 4;
13673
- SHORT_PATH = /^\/(s|c|l)\/([A-Za-z2-7]{26})$/;
15032
+ SHORT_PATH = /^\/(s|c|l|a)\/([A-Za-z2-7]{26})$/;
13674
15033
  SHORT_FRAGMENT = /^#v=4&k=([A-Za-z0-9_-]{43})&c=(bafkrei[a-z2-7]{52})$/;
13675
15034
  FULL_FRAGMENT = /^#v=4&k=([A-Za-z0-9_-]{43})&r=([A-Za-z0-9_-]+)$/;
13676
15035
  REMOVED_FRAGMENT = /^#v=[23](&|$)/;
13677
15036
  MAX_FULL_RECORD_JSON_BYTES = MAX_LINK_REQUEST_BYTES;
13678
15037
  jsonObject = external_exports2.record(external_exports2.unknown());
15038
+ bytes32 = external_exports2.string().refine((value) => decodeStrictBase64Url(value)?.length === 32);
15039
+ ed25519Jwk = external_exports2.object({ kty: external_exports2.literal("OKP"), crv: external_exports2.literal("Ed25519"), x: bytes32 }).strict();
15040
+ p256Jwk = external_exports2.object({ kty: external_exports2.literal("EC"), crv: external_exports2.literal("P-256"), x: bytes32, y: bytes32 }).strict().refine((key) => {
15041
+ try {
15042
+ const point = new Uint8Array(65);
15043
+ point[0] = 4;
15044
+ point.set(decodeStrictBase64Url(key.x), 1);
15045
+ point.set(decodeStrictBase64Url(key.y), 33);
15046
+ p2562.ProjectivePoint.fromHex(point).assertValidity();
15047
+ return true;
15048
+ } catch {
15049
+ return false;
15050
+ }
15051
+ });
15052
+ origin = external_exports2.string().refine((value) => {
15053
+ try {
15054
+ const url = new URL(value);
15055
+ return url.origin === value && (url.protocol === "https:" || url.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname));
15056
+ } catch {
15057
+ return false;
15058
+ }
15059
+ });
15060
+ permission = external_exports2.object({
15061
+ service: external_exports2.string().min(1),
15062
+ space: external_exports2.string().min(1),
15063
+ path: external_exports2.string(),
15064
+ actions: external_exports2.array(external_exports2.string().min(1)).min(1),
15065
+ caveats: external_exports2.array(external_exports2.unknown()).optional()
15066
+ }).strict();
15067
+ requestSchema = external_exports2.object({
15068
+ issuer: external_exports2.string(),
15069
+ requestVersion: external_exports2.literal(1),
15070
+ targetDid: external_exports2.string(),
15071
+ targetPublicJwk: ed25519Jwk,
15072
+ nodeOrigin: origin,
15073
+ permissions: external_exports2.array(permission).min(1),
15074
+ reason: external_exports2.string().optional(),
15075
+ grantLifetimeSeconds: external_exports2.number().int().positive(),
15076
+ resultEncryptionPublicJwk: p256Jwk
15077
+ }).strict();
13679
15078
  DEFAULT_TIMEOUT_MS = 1e4;
13680
15079
  MAX_JSON_RESPONSE_BYTES = 4096;
13681
15080
  AUDIENCE_ORIGIN = /^https:\/\/[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]{1,5})?$/;
@@ -25277,13 +26676,13 @@ var ShareReceiveError = class extends Error {
25277
26676
  return { protocol: "tinycloud-share", version: SHARE_RESULT_VERSION, error: { code: this.code } };
25278
26677
  }
25279
26678
  };
25280
- function metadataFor(envelope, origin) {
26679
+ function metadataFor(envelope, origin2) {
25281
26680
  const kind = envelope.recipientMatcher.kind === "recipientDid" ? "recipientDid" : envelope.recipientMatcher.kind === "exactEmail" ? "email" : envelope.recipientMatcher.kind === "emailDomain" ? "emailDomain" : "bearer";
25282
26681
  return {
25283
26682
  protocol: "tinycloud-share",
25284
26683
  version: 1,
25285
26684
  shareId: envelope.shareId,
25286
- origin,
26685
+ origin: origin2,
25287
26686
  target: { ...envelope.target, kind },
25288
26687
  resource: { ...envelope.resource },
25289
26688
  actions: [...envelope.actions],
@@ -25400,13 +26799,13 @@ async function resolveLegacyV2(link4, options) {
25400
26799
  }
25401
26800
  try {
25402
26801
  options.signal?.throwIfAborted();
25403
- const origin = new URL(link4).origin;
26802
+ const origin2 = new URL(link4).origin;
25404
26803
  const limit = options.maxSealedBlobBytes ?? DEFAULT_MAX_SEALED_BLOB_BYTES;
25405
26804
  if (!Number.isSafeInteger(limit) || limit <= 0) throw new ShareReceiveError("max-bytes-exceeded", "sealed envelope limit is invalid");
25406
26805
  let sealed;
25407
26806
  if (options.fetchBlob !== void 0) {
25408
26807
  try {
25409
- sealed = await options.fetchBlob({ origin, cid: parsed.ciphertextCid, ...options.signal === void 0 ? {} : { signal: options.signal } });
26808
+ sealed = await options.fetchBlob({ origin: origin2, cid: parsed.ciphertextCid, ...options.signal === void 0 ? {} : { signal: options.signal } });
25410
26809
  } catch {
25411
26810
  throw new ShareReceiveError("fetch-failed", "legacy registry unavailable");
25412
26811
  }
@@ -25458,7 +26857,7 @@ async function resolveLegacyV2(link4, options) {
25458
26857
  } catch {
25459
26858
  throw new ShareReceiveError("envelope-invalid", "legacy envelope is invalid");
25460
26859
  }
25461
- return { envelope, origin, cid: parsed.ciphertextCid };
26860
+ return { envelope, origin: origin2, cid: parsed.ciphertextCid };
25462
26861
  } finally {
25463
26862
  parsed.key32.fill(0);
25464
26863
  }
@@ -27171,9 +28570,9 @@ async function validateReceipt(receipt, shareUrl) {
27171
28570
  }
27172
28571
  const links = await Promise.resolve().then(() => (init_links(), links_exports));
27173
28572
  try {
27174
- const origin = new URL(shareUrl).origin;
27175
- const parsed = links.parseLink(shareUrl, { trustedOrigins: [origin] });
27176
- if (parsed.form !== "short" || parsed.pathType !== "share" || shareUrl.length > MAX_INVITATION_LINK_BYTES || shareUrl !== links.buildShortLink({ origin, type: "share", id: parsed.id, key: parsed.key, bodyCid: parsed.c })) {
28573
+ const origin2 = new URL(shareUrl).origin;
28574
+ const parsed = links.parseLink(shareUrl, { trustedOrigins: [origin2] });
28575
+ if (parsed.form !== "short" || parsed.pathType !== "share" || shareUrl.length > MAX_INVITATION_LINK_BYTES || shareUrl !== links.buildShortLink({ origin: origin2, type: "share", id: parsed.id, key: parsed.key, bodyCid: parsed.c })) {
27177
28576
  throw new Error("not a short share link");
27178
28577
  }
27179
28578
  } catch {
@@ -28874,7 +30273,7 @@ function receiveJson(result, path) {
28874
30273
 
28875
30274
  // src/share/io.ts
28876
30275
  import { constants } from "fs";
28877
- import { lstat as lstat6, mkdir as mkdir4, mkdtemp, open as open8, readFile as readFile6, realpath as realpath2, stat as stat4, link as link2, rename as rename3, rm as rm5, unlink as unlink4 } from "fs/promises";
30276
+ import { lstat as lstat6, mkdir as mkdir4, mkdtemp, open as open8, readFile as readFile6, realpath as realpath2, stat as stat4, link as link2, rename as rename3, rm as rm6, unlink as unlink4 } from "fs/promises";
28878
30277
  import { randomBytes as randomBytes3 } from "crypto";
28879
30278
  import { basename as basename2, join as join11, resolve as resolve4, sep as sep3 } from "path";
28880
30279
  init_errors();
@@ -28996,7 +30395,7 @@ async function writeShareOutput(directory, filename, bytes, force) {
28996
30395
  if (temporaryPath !== void 0) await unlink4(temporaryPath);
28997
30396
  } catch {
28998
30397
  }
28999
- await rm5(stagingDirectory, { recursive: true, force: true });
30398
+ await rm6(stagingDirectory, { recursive: true, force: true });
29000
30399
  await directoryHandle.close();
29001
30400
  }
29002
30401
  return join11(outputDirectory, safeName);
@@ -29622,7 +31021,7 @@ function quarantineUnreadableProfileHistory(profileName) {
29622
31021
  return createEncryptedProfileHistory(async () => profileName, signShareHistoryBytes).quarantineUnreadable();
29623
31022
  }
29624
31023
  function createShareAuthorityAdapters(input = {}) {
29625
- const origin = input.origin ?? DEFAULT_SHARE_ORIGIN;
31024
+ const origin2 = input.origin ?? DEFAULT_SHARE_ORIGIN;
29626
31025
  const fetchFn = input.fetchFn ?? globalThis.fetch;
29627
31026
  let selectedProfile;
29628
31027
  const profileName = () => selectedProfile ??= input.profileName?.() ?? selectedProfileName();
@@ -29637,7 +31036,7 @@ function createShareAuthorityAdapters(input = {}) {
29637
31036
  const publicConfig = async () => configPromise ??= (async () => {
29638
31037
  let response;
29639
31038
  try {
29640
- response = await fetchFn(`${origin}/.well-known/tinycloud-share/config.json`, {
31039
+ response = await fetchFn(`${origin2}/.well-known/tinycloud-share/config.json`, {
29641
31040
  headers: { accept: "application/json" },
29642
31041
  credentials: "omit",
29643
31042
  redirect: "error",
@@ -29645,9 +31044,9 @@ function createShareAuthorityAdapters(input = {}) {
29645
31044
  signal: AbortSignal.timeout(1e4)
29646
31045
  });
29647
31046
  } catch (error) {
29648
- throw new SharePublishAuthorityError({ kind: "share-service-unavailable", origin }, { cause: error });
31047
+ throw new SharePublishAuthorityError({ kind: "share-service-unavailable", origin: origin2 }, { cause: error });
29649
31048
  }
29650
- if (!response.ok) throw new SharePublishAuthorityError({ kind: "share-service-unavailable", origin });
31049
+ if (!response.ok) throw new SharePublishAuthorityError({ kind: "share-service-unavailable", origin: origin2 });
29651
31050
  const value = await response.json();
29652
31051
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("share public config is invalid");
29653
31052
  const object3 = value;
@@ -32122,6 +33521,10 @@ if (argv[0] === "courier") {
32122
33521
  @noble/curves/esm/abstract/curve.js:
32123
33522
  @noble/curves/esm/abstract/edwards.js:
32124
33523
  @noble/curves/esm/ed25519.js:
33524
+ @noble/curves/esm/abstract/weierstrass.js:
33525
+ @noble/curves/esm/_shortw_utils.js:
33526
+ @noble/curves/esm/nist.js:
33527
+ @noble/curves/esm/p256.js:
32125
33528
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
32126
33529
  */
32127
33530
  //# sourceMappingURL=index.js.map