@tinycloud/cli 1.5.1-beta.7 → 1.5.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -887,7 +887,7 @@ function add(Ah, Al, Bh, Bl) {
887
887
  const l = (Al >>> 0) + (Bl >>> 0);
888
888
  return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
889
889
  }
890
- var U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, add3L, add3H, add4L, add4H, add5L, add5H;
890
+ var U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, rotlSH, rotlSL, rotlBH, rotlBL, add3L, add3H, add4L, add4H, add5L, add5H;
891
891
  var init_u64 = __esm({
892
892
  "../../node_modules/@noble/hashes/esm/_u64.js"() {
893
893
  "use strict";
@@ -899,6 +899,10 @@ var init_u64 = __esm({
899
899
  rotrSL = (h, l, s) => h << 32 - s | l >>> s;
900
900
  rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
901
901
  rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
902
+ rotlSH = (h, l, s) => h << s | l >>> 32 - s;
903
+ rotlSL = (h, l, s) => l << s | h >>> 32 - s;
904
+ rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
905
+ rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
902
906
  add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
903
907
  add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
904
908
  add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
@@ -981,11 +985,11 @@ function bytesToHex(bytes) {
981
985
  abytes(bytes);
982
986
  if (hasHexBuiltin)
983
987
  return bytes.toHex();
984
- let hex3 = "";
988
+ let hex4 = "";
985
989
  for (let i = 0; i < bytes.length; i++) {
986
- hex3 += hexes[bytes[i]];
990
+ hex4 += hexes[bytes[i]];
987
991
  }
988
- return hex3;
992
+ return hex4;
989
993
  }
990
994
  function asciiToBase16(ch) {
991
995
  if (ch >= asciis._0 && ch <= asciis._9)
@@ -996,21 +1000,21 @@ function asciiToBase16(ch) {
996
1000
  return ch - (asciis.a - 10);
997
1001
  return;
998
1002
  }
999
- function hexToBytes(hex3) {
1000
- if (typeof hex3 !== "string")
1001
- throw new Error("hex string expected, got " + typeof hex3);
1003
+ function hexToBytes(hex4) {
1004
+ if (typeof hex4 !== "string")
1005
+ throw new Error("hex string expected, got " + typeof hex4);
1002
1006
  if (hasHexBuiltin)
1003
- return Uint8Array.fromHex(hex3);
1004
- const hl = hex3.length;
1007
+ return Uint8Array.fromHex(hex4);
1008
+ const hl = hex4.length;
1005
1009
  const al = hl / 2;
1006
1010
  if (hl % 2)
1007
1011
  throw new Error("hex string expected, got unpadded hex of length " + hl);
1008
1012
  const array = new Uint8Array(al);
1009
1013
  for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
1010
- const n1 = asciiToBase16(hex3.charCodeAt(hi));
1011
- const n2 = asciiToBase16(hex3.charCodeAt(hi + 1));
1014
+ const n1 = asciiToBase16(hex4.charCodeAt(hi));
1015
+ const n2 = asciiToBase16(hex4.charCodeAt(hi + 1));
1012
1016
  if (n1 === void 0 || n2 === void 0) {
1013
- const char = hex3[hi] + hex3[hi + 1];
1017
+ const char = hex4[hi] + hex4[hi + 1];
1014
1018
  throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
1015
1019
  }
1016
1020
  array[ai] = n1 * 16 + n2;
@@ -1087,6 +1091,195 @@ var init_utils = __esm({
1087
1091
  }
1088
1092
  });
1089
1093
 
1094
+ // ../../node_modules/@noble/hashes/esm/sha3.js
1095
+ function keccakP(s, rounds = 24) {
1096
+ const B = new Uint32Array(5 * 2);
1097
+ for (let round = 24 - rounds; round < 24; round++) {
1098
+ for (let x = 0; x < 10; x++)
1099
+ B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
1100
+ for (let x = 0; x < 10; x += 2) {
1101
+ const idx1 = (x + 8) % 10;
1102
+ const idx0 = (x + 2) % 10;
1103
+ const B0 = B[idx0];
1104
+ const B1 = B[idx0 + 1];
1105
+ const Th = rotlH(B0, B1, 1) ^ B[idx1];
1106
+ const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
1107
+ for (let y = 0; y < 50; y += 10) {
1108
+ s[x + y] ^= Th;
1109
+ s[x + y + 1] ^= Tl;
1110
+ }
1111
+ }
1112
+ let curH = s[2];
1113
+ let curL = s[3];
1114
+ for (let t = 0; t < 24; t++) {
1115
+ const shift = SHA3_ROTL[t];
1116
+ const Th = rotlH(curH, curL, shift);
1117
+ const Tl = rotlL(curH, curL, shift);
1118
+ const PI = SHA3_PI[t];
1119
+ curH = s[PI];
1120
+ curL = s[PI + 1];
1121
+ s[PI] = Th;
1122
+ s[PI + 1] = Tl;
1123
+ }
1124
+ for (let y = 0; y < 50; y += 10) {
1125
+ for (let x = 0; x < 10; x++)
1126
+ B[x] = s[y + x];
1127
+ for (let x = 0; x < 10; x++)
1128
+ s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
1129
+ }
1130
+ s[0] ^= SHA3_IOTA_H[round];
1131
+ s[1] ^= SHA3_IOTA_L[round];
1132
+ }
1133
+ clean(B);
1134
+ }
1135
+ var _0n, _1n, _2n, _7n, _256n, _0x71n, SHA3_PI, SHA3_ROTL, _SHA3_IOTA, IOTAS, SHA3_IOTA_H, SHA3_IOTA_L, rotlH, rotlL, Keccak, gen, keccak_256;
1136
+ var init_sha3 = __esm({
1137
+ "../../node_modules/@noble/hashes/esm/sha3.js"() {
1138
+ "use strict";
1139
+ init_u64();
1140
+ init_utils();
1141
+ _0n = BigInt(0);
1142
+ _1n = BigInt(1);
1143
+ _2n = BigInt(2);
1144
+ _7n = BigInt(7);
1145
+ _256n = BigInt(256);
1146
+ _0x71n = BigInt(113);
1147
+ SHA3_PI = [];
1148
+ SHA3_ROTL = [];
1149
+ _SHA3_IOTA = [];
1150
+ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
1151
+ [x, y] = [y, (2 * x + 3 * y) % 5];
1152
+ SHA3_PI.push(2 * (5 * y + x));
1153
+ SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
1154
+ let t = _0n;
1155
+ for (let j = 0; j < 7; j++) {
1156
+ R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
1157
+ if (R & _2n)
1158
+ t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
1159
+ }
1160
+ _SHA3_IOTA.push(t);
1161
+ }
1162
+ IOTAS = split(_SHA3_IOTA, true);
1163
+ SHA3_IOTA_H = IOTAS[0];
1164
+ SHA3_IOTA_L = IOTAS[1];
1165
+ rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
1166
+ rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
1167
+ Keccak = class _Keccak extends Hash {
1168
+ // NOTE: we accept arguments in bytes instead of bits here.
1169
+ constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
1170
+ super();
1171
+ this.pos = 0;
1172
+ this.posOut = 0;
1173
+ this.finished = false;
1174
+ this.destroyed = false;
1175
+ this.enableXOF = false;
1176
+ this.blockLen = blockLen;
1177
+ this.suffix = suffix;
1178
+ this.outputLen = outputLen;
1179
+ this.enableXOF = enableXOF;
1180
+ this.rounds = rounds;
1181
+ anumber(outputLen);
1182
+ if (!(0 < blockLen && blockLen < 200))
1183
+ throw new Error("only keccak-f1600 function is supported");
1184
+ this.state = new Uint8Array(200);
1185
+ this.state32 = u32(this.state);
1186
+ }
1187
+ clone() {
1188
+ return this._cloneInto();
1189
+ }
1190
+ keccak() {
1191
+ swap32IfBE(this.state32);
1192
+ keccakP(this.state32, this.rounds);
1193
+ swap32IfBE(this.state32);
1194
+ this.posOut = 0;
1195
+ this.pos = 0;
1196
+ }
1197
+ update(data) {
1198
+ aexists(this);
1199
+ data = toBytes(data);
1200
+ abytes(data);
1201
+ const { blockLen, state: state2 } = this;
1202
+ const len = data.length;
1203
+ for (let pos = 0; pos < len; ) {
1204
+ const take = Math.min(blockLen - this.pos, len - pos);
1205
+ for (let i = 0; i < take; i++)
1206
+ state2[this.pos++] ^= data[pos++];
1207
+ if (this.pos === blockLen)
1208
+ this.keccak();
1209
+ }
1210
+ return this;
1211
+ }
1212
+ finish() {
1213
+ if (this.finished)
1214
+ return;
1215
+ this.finished = true;
1216
+ const { state: state2, suffix, pos, blockLen } = this;
1217
+ state2[pos] ^= suffix;
1218
+ if ((suffix & 128) !== 0 && pos === blockLen - 1)
1219
+ this.keccak();
1220
+ state2[blockLen - 1] ^= 128;
1221
+ this.keccak();
1222
+ }
1223
+ writeInto(out) {
1224
+ aexists(this, false);
1225
+ abytes(out);
1226
+ this.finish();
1227
+ const bufferOut = this.state;
1228
+ const { blockLen } = this;
1229
+ for (let pos = 0, len = out.length; pos < len; ) {
1230
+ if (this.posOut >= blockLen)
1231
+ this.keccak();
1232
+ const take = Math.min(blockLen - this.posOut, len - pos);
1233
+ out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
1234
+ this.posOut += take;
1235
+ pos += take;
1236
+ }
1237
+ return out;
1238
+ }
1239
+ xofInto(out) {
1240
+ if (!this.enableXOF)
1241
+ throw new Error("XOF is not possible for this instance");
1242
+ return this.writeInto(out);
1243
+ }
1244
+ xof(bytes) {
1245
+ anumber(bytes);
1246
+ return this.xofInto(new Uint8Array(bytes));
1247
+ }
1248
+ digestInto(out) {
1249
+ aoutput(out, this);
1250
+ if (this.finished)
1251
+ throw new Error("digest() was already called");
1252
+ this.writeInto(out);
1253
+ this.destroy();
1254
+ return out;
1255
+ }
1256
+ digest() {
1257
+ return this.digestInto(new Uint8Array(this.outputLen));
1258
+ }
1259
+ destroy() {
1260
+ this.destroyed = true;
1261
+ clean(this.state);
1262
+ }
1263
+ _cloneInto(to) {
1264
+ const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
1265
+ to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
1266
+ to.state32.set(this.state32);
1267
+ to.pos = this.pos;
1268
+ to.posOut = this.posOut;
1269
+ to.finished = this.finished;
1270
+ to.rounds = rounds;
1271
+ to.suffix = suffix;
1272
+ to.outputLen = outputLen;
1273
+ to.enableXOF = enableXOF;
1274
+ to.destroyed = this.destroyed;
1275
+ return to;
1276
+ }
1277
+ };
1278
+ gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
1279
+ keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
1280
+ }
1281
+ });
1282
+
1090
1283
  // ../../node_modules/@noble/hashes/esm/_md.js
1091
1284
  function setBigUint64(view, byteOffset, value, isLE2) {
1092
1285
  if (typeof view.setBigUint64 === "function")
@@ -2310,13 +2503,13 @@ function _abytes2(value, length5, title = "") {
2310
2503
  return value;
2311
2504
  }
2312
2505
  function numberToHexUnpadded(num) {
2313
- const hex3 = num.toString(16);
2314
- return hex3.length & 1 ? "0" + hex3 : hex3;
2506
+ const hex4 = num.toString(16);
2507
+ return hex4.length & 1 ? "0" + hex4 : hex4;
2315
2508
  }
2316
- function hexToNumber(hex3) {
2317
- if (typeof hex3 !== "string")
2318
- throw new Error("hex string expected, got " + typeof hex3);
2319
- return hex3 === "" ? _0n : BigInt("0x" + hex3);
2509
+ function hexToNumber(hex4) {
2510
+ if (typeof hex4 !== "string")
2511
+ throw new Error("hex string expected, got " + typeof hex4);
2512
+ return hex4 === "" ? _0n2 : BigInt("0x" + hex4);
2320
2513
  }
2321
2514
  function bytesToNumberBE(bytes) {
2322
2515
  return hexToNumber(bytesToHex(bytes));
@@ -2331,16 +2524,16 @@ function numberToBytesBE(n, len) {
2331
2524
  function numberToBytesLE(n, len) {
2332
2525
  return numberToBytesBE(n, len).reverse();
2333
2526
  }
2334
- function ensureBytes(title, hex3, expectedLength) {
2527
+ function ensureBytes(title, hex4, expectedLength) {
2335
2528
  let res;
2336
- if (typeof hex3 === "string") {
2529
+ if (typeof hex4 === "string") {
2337
2530
  try {
2338
- res = hexToBytes(hex3);
2531
+ res = hexToBytes(hex4);
2339
2532
  } catch (e) {
2340
2533
  throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
2341
2534
  }
2342
- } else if (isBytes(hex3)) {
2343
- res = Uint8Array.from(hex3);
2535
+ } else if (isBytes(hex4)) {
2536
+ res = Uint8Array.from(hex4);
2344
2537
  } else {
2345
2538
  throw new Error(title + " must be hex string or Uint8Array");
2346
2539
  }
@@ -2369,7 +2562,7 @@ function aInRange(title, n, min, max) {
2369
2562
  }
2370
2563
  function bitLen(n) {
2371
2564
  let len;
2372
- for (len = 0; n > _0n; n >>= _1n, len += 1)
2565
+ for (len = 0; n > _0n2; n >>= _1n2, len += 1)
2373
2566
  ;
2374
2567
  return len;
2375
2568
  }
@@ -2399,7 +2592,7 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
2399
2592
  k = h(u8of(1), seed);
2400
2593
  v = h();
2401
2594
  };
2402
- const gen = () => {
2595
+ const gen2 = () => {
2403
2596
  if (i++ >= 1e3)
2404
2597
  throw new Error("drbg: tried 1000 values");
2405
2598
  let len = 0;
@@ -2416,7 +2609,7 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
2416
2609
  reset();
2417
2610
  reseed(seed);
2418
2611
  let res = void 0;
2419
- while (!(res = pred(gen())))
2612
+ while (!(res = pred(gen2())))
2420
2613
  reseed();
2421
2614
  reset();
2422
2615
  return res;
@@ -2448,16 +2641,16 @@ function memoized(fn) {
2448
2641
  return computed;
2449
2642
  };
2450
2643
  }
2451
- var _0n, _1n, isPosBig, bitMask, notImplemented;
2644
+ var _0n2, _1n2, isPosBig, bitMask, notImplemented;
2452
2645
  var init_utils2 = __esm({
2453
2646
  "../../node_modules/@noble/curves/esm/utils.js"() {
2454
2647
  "use strict";
2455
2648
  init_utils();
2456
2649
  init_utils();
2457
- _0n = /* @__PURE__ */ BigInt(0);
2458
- _1n = /* @__PURE__ */ BigInt(1);
2459
- isPosBig = (n) => typeof n === "bigint" && _0n <= n;
2460
- bitMask = (n) => (_1n << BigInt(n)) - _1n;
2650
+ _0n2 = /* @__PURE__ */ BigInt(0);
2651
+ _1n2 = /* @__PURE__ */ BigInt(1);
2652
+ isPosBig = (n) => typeof n === "bigint" && _0n2 <= n;
2653
+ bitMask = (n) => (_1n2 << BigInt(n)) - _1n2;
2461
2654
  notImplemented = () => {
2462
2655
  throw new Error("not implemented");
2463
2656
  };
@@ -2467,25 +2660,25 @@ var init_utils2 = __esm({
2467
2660
  // ../../node_modules/@noble/curves/esm/abstract/modular.js
2468
2661
  function mod(a, b) {
2469
2662
  const result = a % b;
2470
- return result >= _0n2 ? result : b + result;
2663
+ return result >= _0n3 ? result : b + result;
2471
2664
  }
2472
2665
  function pow2(x, power, modulo) {
2473
2666
  let res = x;
2474
- while (power-- > _0n2) {
2667
+ while (power-- > _0n3) {
2475
2668
  res *= res;
2476
2669
  res %= modulo;
2477
2670
  }
2478
2671
  return res;
2479
2672
  }
2480
2673
  function invert(number, modulo) {
2481
- if (number === _0n2)
2674
+ if (number === _0n3)
2482
2675
  throw new Error("invert: expected non-zero number");
2483
- if (modulo <= _0n2)
2676
+ if (modulo <= _0n3)
2484
2677
  throw new Error("invert: expected positive modulus, got " + modulo);
2485
2678
  let a = mod(number, modulo);
2486
2679
  let b = modulo;
2487
- let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
2488
- while (a !== _0n2) {
2680
+ let x = _0n3, y = _1n3, u = _1n3, v = _0n3;
2681
+ while (a !== _0n3) {
2489
2682
  const q = b / a;
2490
2683
  const r = b % a;
2491
2684
  const m = x - u * q;
@@ -2493,7 +2686,7 @@ function invert(number, modulo) {
2493
2686
  b = a, a = r, x = u, y = v, u = m, v = n;
2494
2687
  }
2495
2688
  const gcd = b;
2496
- if (gcd !== _1n2)
2689
+ if (gcd !== _1n3)
2497
2690
  throw new Error("invert: does not exist");
2498
2691
  return mod(x, modulo);
2499
2692
  }
@@ -2502,17 +2695,17 @@ function assertIsSquare(Fp2, root, n) {
2502
2695
  throw new Error("Cannot find square root");
2503
2696
  }
2504
2697
  function sqrt3mod4(Fp2, n) {
2505
- const p1div4 = (Fp2.ORDER + _1n2) / _4n;
2698
+ const p1div4 = (Fp2.ORDER + _1n3) / _4n;
2506
2699
  const root = Fp2.pow(n, p1div4);
2507
2700
  assertIsSquare(Fp2, root, n);
2508
2701
  return root;
2509
2702
  }
2510
2703
  function sqrt5mod8(Fp2, n) {
2511
2704
  const p5div8 = (Fp2.ORDER - _5n) / _8n;
2512
- const n2 = Fp2.mul(n, _2n);
2705
+ const n2 = Fp2.mul(n, _2n2);
2513
2706
  const v = Fp2.pow(n2, p5div8);
2514
2707
  const nv = Fp2.mul(n, v);
2515
- const i = Fp2.mul(Fp2.mul(nv, _2n), v);
2708
+ const i = Fp2.mul(Fp2.mul(nv, _2n2), v);
2516
2709
  const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
2517
2710
  assertIsSquare(Fp2, root, n);
2518
2711
  return root;
@@ -2523,7 +2716,7 @@ function sqrt9mod16(P) {
2523
2716
  const c1 = tn(Fp_, Fp_.neg(Fp_.ONE));
2524
2717
  const c2 = tn(Fp_, c1);
2525
2718
  const c3 = tn(Fp_, Fp_.neg(c1));
2526
- const c4 = (P + _7n) / _16n;
2719
+ const c4 = (P + _7n2) / _16n;
2527
2720
  return (Fp2, n) => {
2528
2721
  let tv1 = Fp2.pow(n, c4);
2529
2722
  let tv2 = Fp2.mul(tv1, c1);
@@ -2542,13 +2735,13 @@ function sqrt9mod16(P) {
2542
2735
  function tonelliShanks(P) {
2543
2736
  if (P < _3n)
2544
2737
  throw new Error("sqrt is not defined for small field");
2545
- let Q = P - _1n2;
2738
+ let Q = P - _1n3;
2546
2739
  let S = 0;
2547
- while (Q % _2n === _0n2) {
2548
- Q /= _2n;
2740
+ while (Q % _2n2 === _0n3) {
2741
+ Q /= _2n2;
2549
2742
  S++;
2550
2743
  }
2551
- let Z = _2n;
2744
+ let Z = _2n2;
2552
2745
  const _Fp = Field(P);
2553
2746
  while (FpLegendre(_Fp, Z) === 1) {
2554
2747
  if (Z++ > 1e3)
@@ -2557,7 +2750,7 @@ function tonelliShanks(P) {
2557
2750
  if (S === 1)
2558
2751
  return sqrt3mod4;
2559
2752
  let cc = _Fp.pow(Z, Q);
2560
- const Q1div2 = (Q + _1n2) / _2n;
2753
+ const Q1div2 = (Q + _1n3) / _2n2;
2561
2754
  return function tonelliSlow(Fp2, n) {
2562
2755
  if (Fp2.is0(n))
2563
2756
  return n;
@@ -2578,7 +2771,7 @@ function tonelliShanks(P) {
2578
2771
  if (i === M)
2579
2772
  throw new Error("Cannot find square root");
2580
2773
  }
2581
- const exponent = _1n2 << BigInt(M - i - 1);
2774
+ const exponent = _1n3 << BigInt(M - i - 1);
2582
2775
  const b = Fp2.pow(c, exponent);
2583
2776
  M = i;
2584
2777
  c = Fp2.sqr(b);
@@ -2612,19 +2805,19 @@ function validateField(field) {
2612
2805
  return field;
2613
2806
  }
2614
2807
  function FpPow(Fp2, num, power) {
2615
- if (power < _0n2)
2808
+ if (power < _0n3)
2616
2809
  throw new Error("invalid exponent, negatives unsupported");
2617
- if (power === _0n2)
2810
+ if (power === _0n3)
2618
2811
  return Fp2.ONE;
2619
- if (power === _1n2)
2812
+ if (power === _1n3)
2620
2813
  return num;
2621
2814
  let p = Fp2.ONE;
2622
2815
  let d = num;
2623
- while (power > _0n2) {
2624
- if (power & _1n2)
2816
+ while (power > _0n3) {
2817
+ if (power & _1n3)
2625
2818
  p = Fp2.mul(p, d);
2626
2819
  d = Fp2.sqr(d);
2627
- power >>= _1n2;
2820
+ power >>= _1n3;
2628
2821
  }
2629
2822
  return p;
2630
2823
  }
@@ -2646,7 +2839,7 @@ function FpInvertBatch(Fp2, nums, passZero = false) {
2646
2839
  return inverted;
2647
2840
  }
2648
2841
  function FpLegendre(Fp2, n) {
2649
- const p1mod2 = (Fp2.ORDER - _1n2) / _2n;
2842
+ const p1mod2 = (Fp2.ORDER - _1n3) / _2n2;
2650
2843
  const powered = Fp2.pow(n, p1mod2);
2651
2844
  const yes = Fp2.eql(powered, Fp2.ONE);
2652
2845
  const zero = Fp2.eql(powered, Fp2.ZERO);
@@ -2663,7 +2856,7 @@ function nLength(n, nBitLength) {
2663
2856
  return { nBitLength: _nBitLength, nByteLength };
2664
2857
  }
2665
2858
  function Field(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
2666
- if (ORDER <= _0n2)
2859
+ if (ORDER <= _0n3)
2667
2860
  throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
2668
2861
  let _nbitLength = void 0;
2669
2862
  let _sqrt = void 0;
@@ -2698,19 +2891,19 @@ function Field(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
2698
2891
  BITS,
2699
2892
  BYTES,
2700
2893
  MASK: bitMask(BITS),
2701
- ZERO: _0n2,
2702
- ONE: _1n2,
2894
+ ZERO: _0n3,
2895
+ ONE: _1n3,
2703
2896
  allowedLengths,
2704
2897
  create: (num) => mod(num, ORDER),
2705
2898
  isValid: (num) => {
2706
2899
  if (typeof num !== "bigint")
2707
2900
  throw new Error("invalid field element: expected bigint, got " + typeof num);
2708
- return _0n2 <= num && num < ORDER;
2901
+ return _0n3 <= num && num < ORDER;
2709
2902
  },
2710
- is0: (num) => num === _0n2,
2903
+ is0: (num) => num === _0n3,
2711
2904
  // is valid and invertible
2712
2905
  isValidNot0: (num) => !f.is0(num) && f.isValid(num),
2713
- isOdd: (num) => (num & _1n2) === _1n2,
2906
+ isOdd: (num) => (num & _1n3) === _1n3,
2714
2907
  neg: (num) => mod(-num, ORDER),
2715
2908
  eql: (lhs, rhs) => lhs === rhs,
2716
2909
  sqr: (num) => mod(num * num, ORDER),
@@ -2776,25 +2969,25 @@ function mapHashToField(key, fieldOrder, isLE2 = false) {
2776
2969
  if (len < 16 || len < minLen || len > 1024)
2777
2970
  throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
2778
2971
  const num = isLE2 ? bytesToNumberLE(key) : bytesToNumberBE(key);
2779
- const reduced = mod(num, fieldOrder - _1n2) + _1n2;
2972
+ const reduced = mod(num, fieldOrder - _1n3) + _1n3;
2780
2973
  return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
2781
2974
  }
2782
- var _0n2, _1n2, _2n, _3n, _4n, _5n, _7n, _8n, _9n, _16n, isNegativeLE, FIELD_FIELDS;
2975
+ var _0n3, _1n3, _2n2, _3n, _4n, _5n, _7n2, _8n, _9n, _16n, isNegativeLE, FIELD_FIELDS;
2783
2976
  var init_modular = __esm({
2784
2977
  "../../node_modules/@noble/curves/esm/abstract/modular.js"() {
2785
2978
  "use strict";
2786
2979
  init_utils2();
2787
- _0n2 = BigInt(0);
2788
- _1n2 = BigInt(1);
2789
- _2n = /* @__PURE__ */ BigInt(2);
2980
+ _0n3 = BigInt(0);
2981
+ _1n3 = BigInt(1);
2982
+ _2n2 = /* @__PURE__ */ BigInt(2);
2790
2983
  _3n = /* @__PURE__ */ BigInt(3);
2791
2984
  _4n = /* @__PURE__ */ BigInt(4);
2792
2985
  _5n = /* @__PURE__ */ BigInt(5);
2793
- _7n = /* @__PURE__ */ BigInt(7);
2986
+ _7n2 = /* @__PURE__ */ BigInt(7);
2794
2987
  _8n = /* @__PURE__ */ BigInt(8);
2795
2988
  _9n = /* @__PURE__ */ BigInt(9);
2796
2989
  _16n = /* @__PURE__ */ BigInt(16);
2797
- isNegativeLE = (num, modulo) => (mod(num, modulo) & _1n2) === _1n2;
2990
+ isNegativeLE = (num, modulo) => (mod(num, modulo) & _1n3) === _1n3;
2798
2991
  FIELD_FIELDS = [
2799
2992
  "create",
2800
2993
  "isValid",
@@ -2845,7 +3038,7 @@ function calcOffsets(n, window, wOpts) {
2845
3038
  let nextN = n >> shiftBy;
2846
3039
  if (wbits > windowSize) {
2847
3040
  wbits -= maxNumber;
2848
- nextN += _1n3;
3041
+ nextN += _1n4;
2849
3042
  }
2850
3043
  const offsetStart = window * windowSize;
2851
3044
  const offset = offsetStart + Math.abs(wbits) - 1;
@@ -2875,21 +3068,21 @@ function getW(P) {
2875
3068
  return pointWindowSizes.get(P) || 1;
2876
3069
  }
2877
3070
  function assert0(n) {
2878
- if (n !== _0n3)
3071
+ if (n !== _0n4)
2879
3072
  throw new Error("invalid wNAF");
2880
3073
  }
2881
3074
  function mulEndoUnsafe(Point, point, k1, k2) {
2882
3075
  let acc = point;
2883
3076
  let p1 = Point.ZERO;
2884
3077
  let p2 = Point.ZERO;
2885
- while (k1 > _0n3 || k2 > _0n3) {
2886
- if (k1 & _1n3)
3078
+ while (k1 > _0n4 || k2 > _0n4) {
3079
+ if (k1 & _1n4)
2887
3080
  p1 = p1.add(acc);
2888
- if (k2 & _1n3)
3081
+ if (k2 & _1n4)
2889
3082
  p2 = p2.add(acc);
2890
3083
  acc = acc.double();
2891
- k1 >>= _1n3;
2892
- k2 >>= _1n3;
3084
+ k1 >>= _1n4;
3085
+ k2 >>= _1n4;
2893
3086
  }
2894
3087
  return { p1, p2 };
2895
3088
  }
@@ -2949,7 +3142,7 @@ function _createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
2949
3142
  throw new Error(`expected valid ${type} CURVE object`);
2950
3143
  for (const p of ["p", "n", "h"]) {
2951
3144
  const val = CURVE[p];
2952
- if (!(typeof val === "bigint" && val > _0n3))
3145
+ if (!(typeof val === "bigint" && val > _0n4))
2953
3146
  throw new Error(`CURVE.${p} must be positive bigint`);
2954
3147
  }
2955
3148
  const Fp2 = createField(CURVE.p, curveOpts.Fp, FpFnLE);
@@ -2963,14 +3156,14 @@ function _createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
2963
3156
  CURVE = Object.freeze(Object.assign({}, CURVE));
2964
3157
  return { CURVE, Fp: Fp2, Fn: Fn2 };
2965
3158
  }
2966
- var _0n3, _1n3, pointPrecomputes, pointWindowSizes, wNAF;
3159
+ var _0n4, _1n4, pointPrecomputes, pointWindowSizes, wNAF;
2967
3160
  var init_curve = __esm({
2968
3161
  "../../node_modules/@noble/curves/esm/abstract/curve.js"() {
2969
3162
  "use strict";
2970
3163
  init_utils2();
2971
3164
  init_modular();
2972
- _0n3 = BigInt(0);
2973
- _1n3 = BigInt(1);
3165
+ _0n4 = BigInt(0);
3166
+ _1n4 = BigInt(1);
2974
3167
  pointPrecomputes = /* @__PURE__ */ new WeakMap();
2975
3168
  pointWindowSizes = /* @__PURE__ */ new WeakMap();
2976
3169
  wNAF = class {
@@ -2984,11 +3177,11 @@ var init_curve = __esm({
2984
3177
  // non-const time multiplication ladder
2985
3178
  _unsafeLadder(elm, n, p = this.ZERO) {
2986
3179
  let d = elm;
2987
- while (n > _0n3) {
2988
- if (n & _1n3)
3180
+ while (n > _0n4) {
3181
+ if (n & _1n4)
2989
3182
  p = p.add(d);
2990
3183
  d = d.double();
2991
- n >>= _1n3;
3184
+ n >>= _1n4;
2992
3185
  }
2993
3186
  return p;
2994
3187
  }
@@ -3052,7 +3245,7 @@ var init_curve = __esm({
3052
3245
  wNAFUnsafe(W, precomputes, n, acc = this.ZERO) {
3053
3246
  const wo = calcWOpts(W, this.bits);
3054
3247
  for (let window = 0; window < wo.windows; window++) {
3055
- if (n === _0n3)
3248
+ if (n === _0n4)
3056
3249
  break;
3057
3250
  const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
3058
3251
  n = nextN;
@@ -3117,19 +3310,19 @@ function edwards(params, extraOpts = {}) {
3117
3310
  let CURVE = validated.CURVE;
3118
3311
  const { h: cofactor } = CURVE;
3119
3312
  _validateObject(extraOpts, {}, { uvRatio: "function" });
3120
- const MASK = _2n2 << BigInt(Fn2.BYTES * 8) - _1n4;
3313
+ const MASK = _2n3 << BigInt(Fn2.BYTES * 8) - _1n5;
3121
3314
  const modP = (n) => Fp2.create(n);
3122
3315
  const uvRatio2 = extraOpts.uvRatio || ((u, v) => {
3123
3316
  try {
3124
3317
  return { isValid: true, value: Fp2.sqrt(Fp2.div(u, v)) };
3125
3318
  } catch (e) {
3126
- return { isValid: false, value: _0n4 };
3319
+ return { isValid: false, value: _0n5 };
3127
3320
  }
3128
3321
  });
3129
3322
  if (!isEdValidXY(Fp2, CURVE, CURVE.Gx, CURVE.Gy))
3130
3323
  throw new Error("bad curve params: generator point");
3131
3324
  function acoord(title, n, banZero = false) {
3132
- const min = banZero ? _1n4 : _0n4;
3325
+ const min = banZero ? _1n5 : _0n5;
3133
3326
  aInRange("coordinate " + title, n, min, MASK);
3134
3327
  return n;
3135
3328
  }
@@ -3146,8 +3339,8 @@ function edwards(params, extraOpts = {}) {
3146
3339
  const y = modP(Y * iz);
3147
3340
  const zz = Fp2.mul(Z, iz);
3148
3341
  if (is0)
3149
- return { x: _0n4, y: _1n4 };
3150
- if (zz !== _1n4)
3342
+ return { x: _0n5, y: _1n5 };
3343
+ if (zz !== _1n5)
3151
3344
  throw new Error("invZ was invalid");
3152
3345
  return { x, y };
3153
3346
  });
@@ -3188,7 +3381,7 @@ function edwards(params, extraOpts = {}) {
3188
3381
  const { x, y } = p || {};
3189
3382
  acoord("x", x);
3190
3383
  acoord("y", y);
3191
- return new Point(x, y, _1n4, modP(x * y));
3384
+ return new Point(x, y, _1n5, modP(x * y));
3192
3385
  }
3193
3386
  // Uses algo from RFC8032 5.1.3.
3194
3387
  static fromBytes(bytes, zip215 = false) {
@@ -3201,16 +3394,16 @@ function edwards(params, extraOpts = {}) {
3201
3394
  normed[len - 1] = lastByte & ~128;
3202
3395
  const y = bytesToNumberLE(normed);
3203
3396
  const max = zip215 ? MASK : Fp2.ORDER;
3204
- aInRange("point.y", y, _0n4, max);
3397
+ aInRange("point.y", y, _0n5, max);
3205
3398
  const y2 = modP(y * y);
3206
- const u = modP(y2 - _1n4);
3399
+ const u = modP(y2 - _1n5);
3207
3400
  const v = modP(d * y2 - a);
3208
3401
  let { isValid: isValid4, value: x } = uvRatio2(u, v);
3209
3402
  if (!isValid4)
3210
3403
  throw new Error("bad point: invalid y coordinate");
3211
- const isXOdd = (x & _1n4) === _1n4;
3404
+ const isXOdd = (x & _1n5) === _1n5;
3212
3405
  const isLastByteOdd = (lastByte & 128) !== 0;
3213
- if (!zip215 && x === _0n4 && isLastByteOdd)
3406
+ if (!zip215 && x === _0n5 && isLastByteOdd)
3214
3407
  throw new Error("bad point: x=0 and x_0=1");
3215
3408
  if (isLastByteOdd !== isXOdd)
3216
3409
  x = modP(-x);
@@ -3228,7 +3421,7 @@ function edwards(params, extraOpts = {}) {
3228
3421
  precompute(windowSize = 8, isLazy = true) {
3229
3422
  wnaf.createCache(this, windowSize);
3230
3423
  if (!isLazy)
3231
- this.multiply(_2n2);
3424
+ this.multiply(_2n3);
3232
3425
  return this;
3233
3426
  }
3234
3427
  // Useful in fromAffine() - not for fromBytes(), which always created valid points.
@@ -3260,7 +3453,7 @@ function edwards(params, extraOpts = {}) {
3260
3453
  const { X: X1, Y: Y1, Z: Z1 } = this;
3261
3454
  const A = modP(X1 * X1);
3262
3455
  const B = modP(Y1 * Y1);
3263
- const C = modP(_2n2 * modP(Z1 * Z1));
3456
+ const C = modP(_2n3 * modP(Z1 * Z1));
3264
3457
  const D = modP(a * A);
3265
3458
  const x1y1 = X1 + Y1;
3266
3459
  const E = modP(modP(x1y1 * x1y1) - A - B);
@@ -3313,9 +3506,9 @@ function edwards(params, extraOpts = {}) {
3313
3506
  multiplyUnsafe(scalar, acc = Point.ZERO) {
3314
3507
  if (!Fn2.isValid(scalar))
3315
3508
  throw new Error("invalid scalar: expected 0 <= sc < curve.n");
3316
- if (scalar === _0n4)
3509
+ if (scalar === _0n5)
3317
3510
  return Point.ZERO;
3318
- if (this.is0() || scalar === _1n4)
3511
+ if (this.is0() || scalar === _1n5)
3319
3512
  return this;
3320
3513
  return wnaf.unsafe(this, scalar, (p) => normalizeZ(Point, p), acc);
3321
3514
  }
@@ -3337,14 +3530,14 @@ function edwards(params, extraOpts = {}) {
3337
3530
  return toAffineMemo(this, invertedZ);
3338
3531
  }
3339
3532
  clearCofactor() {
3340
- if (cofactor === _1n4)
3533
+ if (cofactor === _1n5)
3341
3534
  return this;
3342
3535
  return this.multiplyUnsafe(cofactor);
3343
3536
  }
3344
3537
  toBytes() {
3345
3538
  const { x, y } = this.toAffine();
3346
3539
  const bytes = Fp2.toBytes(y);
3347
- bytes[bytes.length - 1] |= x & _1n4 ? 128 : 0;
3540
+ bytes[bytes.length - 1] |= x & _1n5 ? 128 : 0;
3348
3541
  return bytes;
3349
3542
  }
3350
3543
  toHex() {
@@ -3379,8 +3572,8 @@ function edwards(params, extraOpts = {}) {
3379
3572
  return this.toBytes();
3380
3573
  }
3381
3574
  }
3382
- Point.BASE = new Point(CURVE.Gx, CURVE.Gy, _1n4, modP(CURVE.Gx * CURVE.Gy));
3383
- Point.ZERO = new Point(_0n4, _1n4, _1n4, _0n4);
3575
+ Point.BASE = new Point(CURVE.Gx, CURVE.Gy, _1n5, modP(CURVE.Gx * CURVE.Gy));
3576
+ Point.ZERO = new Point(_0n5, _1n5, _1n5, _0n5);
3384
3577
  Point.Fp = Fp2;
3385
3578
  Point.Fn = Fn2;
3386
3579
  const wnaf = new wNAF(Point, Fn2.BITS);
@@ -3518,7 +3711,7 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
3518
3711
  const is25519 = size === 32;
3519
3712
  if (!is25519 && size !== 57)
3520
3713
  throw new Error("only defined for 25519 and 448");
3521
- const u = is25519 ? Fp2.div(_1n4 + y, _1n4 - y) : Fp2.div(y - _1n4, y + _1n4);
3714
+ const u = is25519 ? Fp2.div(_1n5 + y, _1n5 - y) : Fp2.div(y - _1n5, y + _1n5);
3522
3715
  return Fp2.toBytes(u);
3523
3716
  },
3524
3717
  toMontgomerySecret(secretKey) {
@@ -3582,16 +3775,16 @@ function twistedEdwards(c) {
3582
3775
  const EDDSA = eddsa(Point, hash, eddsaOpts);
3583
3776
  return _eddsa_new_output_to_legacy(c, EDDSA);
3584
3777
  }
3585
- var _0n4, _1n4, _2n2, _8n2, PrimeEdwardsPoint;
3778
+ var _0n5, _1n5, _2n3, _8n2, PrimeEdwardsPoint;
3586
3779
  var init_edwards = __esm({
3587
3780
  "../../node_modules/@noble/curves/esm/abstract/edwards.js"() {
3588
3781
  "use strict";
3589
3782
  init_utils2();
3590
3783
  init_curve();
3591
3784
  init_modular();
3592
- _0n4 = BigInt(0);
3593
- _1n4 = BigInt(1);
3594
- _2n2 = BigInt(2);
3785
+ _0n5 = BigInt(0);
3786
+ _1n5 = BigInt(1);
3787
+ _2n3 = BigInt(2);
3595
3788
  _8n2 = BigInt(8);
3596
3789
  PrimeEdwardsPoint = class {
3597
3790
  constructor(ep) {
@@ -3669,8 +3862,8 @@ function ed25519_pow_2_252_3(x) {
3669
3862
  const P = ed25519_CURVE_p;
3670
3863
  const x2 = x * x % P;
3671
3864
  const b2 = x2 * x % P;
3672
- const b4 = pow2(b2, _2n3, P) * b2 % P;
3673
- const b5 = pow2(b4, _1n5, P) * x % P;
3865
+ const b4 = pow2(b2, _2n4, P) * b2 % P;
3866
+ const b5 = pow2(b4, _1n6, P) * x % P;
3674
3867
  const b10 = pow2(b5, _5n2, P) * b5 % P;
3675
3868
  const b20 = pow2(b10, _10n, P) * b10 % P;
3676
3869
  const b40 = pow2(b20, _20n, P) * b20 % P;
@@ -3678,7 +3871,7 @@ function ed25519_pow_2_252_3(x) {
3678
3871
  const b160 = pow2(b80, _80n, P) * b80 % P;
3679
3872
  const b240 = pow2(b160, _80n, P) * b80 % P;
3680
3873
  const b250 = pow2(b240, _10n, P) * b10 % P;
3681
- const pow_p_5_8 = pow2(b250, _2n3, P) * x % P;
3874
+ const pow_p_5_8 = pow2(b250, _2n4, P) * x % P;
3682
3875
  return { pow_p_5_8, b2 };
3683
3876
  }
3684
3877
  function adjustScalarBytes(bytes) {
@@ -3712,7 +3905,7 @@ function calcElligatorRistrettoMap(r0) {
3712
3905
  const P = ed25519_CURVE_p;
3713
3906
  const mod2 = (n) => Fp.create(n);
3714
3907
  const r = mod2(SQRT_M1 * r0 * r0);
3715
- const Ns = mod2((r + _1n5) * ONE_MINUS_D_SQ);
3908
+ const Ns = mod2((r + _1n6) * ONE_MINUS_D_SQ);
3716
3909
  let c = BigInt(-1);
3717
3910
  const D = mod2((c - d * r) * mod2(r + d));
3718
3911
  let { isValid: Ns_D_is_sq, value: s } = uvRatio(Ns, D);
@@ -3723,12 +3916,12 @@ function calcElligatorRistrettoMap(r0) {
3723
3916
  s = s_;
3724
3917
  if (!Ns_D_is_sq)
3725
3918
  c = r;
3726
- const Nt = mod2(c * (r - _1n5) * D_MINUS_ONE_SQ - D);
3919
+ const Nt = mod2(c * (r - _1n6) * D_MINUS_ONE_SQ - D);
3727
3920
  const s2 = s * s;
3728
3921
  const W0 = mod2((s + s) * D);
3729
3922
  const W1 = mod2(Nt * SQRT_AD_MINUS_ONE);
3730
- const W2 = mod2(_1n5 - s2);
3731
- const W3 = mod2(_1n5 + s2);
3923
+ const W2 = mod2(_1n6 - s2);
3924
+ const W3 = mod2(_1n6 + s2);
3732
3925
  return new ed25519.Point(mod2(W0 * W3), mod2(W2 * W1), mod2(W1 * W3), mod2(W0 * W2));
3733
3926
  }
3734
3927
  function ristretto255_map(bytes) {
@@ -3739,7 +3932,7 @@ function ristretto255_map(bytes) {
3739
3932
  const R2 = calcElligatorRistrettoMap(r2);
3740
3933
  return new _RistrettoPoint(R1.add(R2));
3741
3934
  }
3742
- var _0n5, _1n5, _2n3, _3n2, _5n2, _8n3, ed25519_CURVE_p, ed25519_CURVE, ED25519_SQRT_M1, Fp, Fn, ed25519Defaults, ed25519, SQRT_M1, SQRT_AD_MINUS_ONE, INVSQRT_A_MINUS_D, ONE_MINUS_D_SQ, D_MINUS_ONE_SQ, invertSqrt, MAX_255B, bytes255ToNumberLE, _RistrettoPoint;
3935
+ var _0n6, _1n6, _2n4, _3n2, _5n2, _8n3, ed25519_CURVE_p, ed25519_CURVE, ED25519_SQRT_M1, Fp, Fn, ed25519Defaults, ed25519, SQRT_M1, SQRT_AD_MINUS_ONE, INVSQRT_A_MINUS_D, ONE_MINUS_D_SQ, D_MINUS_ONE_SQ, invertSqrt, MAX_255B, bytes255ToNumberLE, _RistrettoPoint;
3743
3936
  var init_ed25519 = __esm({
3744
3937
  "../../node_modules/@noble/curves/esm/ed25519.js"() {
3745
3938
  "use strict";
@@ -3749,9 +3942,9 @@ var init_ed25519 = __esm({
3749
3942
  init_edwards();
3750
3943
  init_modular();
3751
3944
  init_utils2();
3752
- _0n5 = /* @__PURE__ */ BigInt(0);
3753
- _1n5 = BigInt(1);
3754
- _2n3 = BigInt(2);
3945
+ _0n6 = /* @__PURE__ */ BigInt(0);
3946
+ _1n6 = BigInt(1);
3947
+ _2n4 = BigInt(2);
3755
3948
  _3n2 = BigInt(3);
3756
3949
  _5n2 = BigInt(5);
3757
3950
  _8n3 = BigInt(8);
@@ -3784,7 +3977,7 @@ var init_ed25519 = __esm({
3784
3977
  INVSQRT_A_MINUS_D = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");
3785
3978
  ONE_MINUS_D_SQ = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");
3786
3979
  D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");
3787
- invertSqrt = (number) => uvRatio(_1n5, number);
3980
+ invertSqrt = (number) => uvRatio(_1n6, number);
3788
3981
  MAX_255B = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
3789
3982
  bytes255ToNumberLE = (bytes) => ed25519.Point.Fp.create(bytesToNumberLE(bytes) & MAX_255B);
3790
3983
  _RistrettoPoint = class __RistrettoPoint extends PrimeEdwardsPoint {
@@ -3802,8 +3995,8 @@ var init_ed25519 = __esm({
3802
3995
  return new __RistrettoPoint(ep);
3803
3996
  }
3804
3997
  /** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
3805
- static hashToCurve(hex3) {
3806
- return ristretto255_map(ensureBytes("ristrettoHash", hex3, 64));
3998
+ static hashToCurve(hex4) {
3999
+ return ristretto255_map(ensureBytes("ristrettoHash", hex4, 64));
3807
4000
  }
3808
4001
  static fromBytes(bytes) {
3809
4002
  abytes(bytes, 32);
@@ -3814,8 +4007,8 @@ var init_ed25519 = __esm({
3814
4007
  if (!equalBytes(Fp.toBytes(s), bytes) || isNegativeLE(s, P))
3815
4008
  throw new Error("invalid ristretto255 encoding 1");
3816
4009
  const s2 = mod2(s * s);
3817
- const u1 = mod2(_1n5 + a * s2);
3818
- const u2 = mod2(_1n5 - a * s2);
4010
+ const u1 = mod2(_1n6 + a * s2);
4011
+ const u2 = mod2(_1n6 - a * s2);
3819
4012
  const u1_2 = mod2(u1 * u1);
3820
4013
  const u2_2 = mod2(u2 * u2);
3821
4014
  const v = mod2(a * d * u1_2 - u2_2);
@@ -3827,17 +4020,17 @@ var init_ed25519 = __esm({
3827
4020
  x = mod2(-x);
3828
4021
  const y = mod2(u1 * Dy);
3829
4022
  const t = mod2(x * y);
3830
- if (!isValid4 || isNegativeLE(t, P) || y === _0n5)
4023
+ if (!isValid4 || isNegativeLE(t, P) || y === _0n6)
3831
4024
  throw new Error("invalid ristretto255 encoding 2");
3832
- return new __RistrettoPoint(new ed25519.Point(x, y, _1n5, t));
4025
+ return new __RistrettoPoint(new ed25519.Point(x, y, _1n6, t));
3833
4026
  }
3834
4027
  /**
3835
4028
  * Converts ristretto-encoded string to ristretto point.
3836
4029
  * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
3837
4030
  * @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
3838
4031
  */
3839
- static fromHex(hex3) {
3840
- return __RistrettoPoint.fromBytes(ensureBytes("ristrettoHex", hex3, 32));
4032
+ static fromHex(hex4) {
4033
+ return __RistrettoPoint.fromBytes(ensureBytes("ristrettoHex", hex4, 32));
3841
4034
  }
3842
4035
  static msm(points, scalars) {
3843
4036
  return pippenger(__RistrettoPoint, ed25519.Point.Fn, points, scalars);
@@ -13009,14 +13202,14 @@ function _splitEndoScalar(k, basis, n) {
13009
13202
  const c2 = divNearest(-b1 * k, n);
13010
13203
  let k1 = k - c1 * a1 - c2 * a2;
13011
13204
  let k2 = -c1 * b1 - c2 * b2;
13012
- const k1neg = k1 < _0n6;
13013
- const k2neg = k2 < _0n6;
13205
+ const k1neg = k1 < _0n7;
13206
+ const k2neg = k2 < _0n7;
13014
13207
  if (k1neg)
13015
13208
  k1 = -k1;
13016
13209
  if (k2neg)
13017
13210
  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) {
13211
+ const MAX_NUM = bitMask(Math.ceil(bitLen(n) / 2)) + _1n7;
13212
+ if (k1 < _0n7 || k1 >= MAX_NUM || k2 < _0n7 || k2 >= MAX_NUM) {
13020
13213
  throw new Error("splitScalar (endomorphism): failed, k=" + k);
13021
13214
  }
13022
13215
  return { k1neg, k1, k2neg, k2 };
@@ -13222,8 +13415,8 @@ function weierstrassN(params, extraOpts = {}) {
13222
13415
  P.assertValidity();
13223
13416
  return P;
13224
13417
  }
13225
- static fromHex(hex3) {
13226
- return Point.fromBytes(ensureBytes("pointHex", hex3));
13418
+ static fromHex(hex4) {
13419
+ return Point.fromBytes(ensureBytes("pointHex", hex4));
13227
13420
  }
13228
13421
  get x() {
13229
13422
  return this.toAffine().x;
@@ -13406,9 +13599,9 @@ function weierstrassN(params, extraOpts = {}) {
13406
13599
  const p = this;
13407
13600
  if (!Fn2.isValid(sc))
13408
13601
  throw new Error("invalid scalar: out of range");
13409
- if (sc === _0n6 || p.is0())
13602
+ if (sc === _0n7 || p.is0())
13410
13603
  return Point.ZERO;
13411
- if (sc === _1n6)
13604
+ if (sc === _1n7)
13412
13605
  return p;
13413
13606
  if (wnaf.hasCache(this))
13414
13607
  return this.multiply(sc);
@@ -13437,7 +13630,7 @@ function weierstrassN(params, extraOpts = {}) {
13437
13630
  */
13438
13631
  isTorsionFree() {
13439
13632
  const { isTorsionFree } = extraOpts;
13440
- if (cofactor === _1n6)
13633
+ if (cofactor === _1n7)
13441
13634
  return true;
13442
13635
  if (isTorsionFree)
13443
13636
  return isTorsionFree(Point, this);
@@ -13445,7 +13638,7 @@ function weierstrassN(params, extraOpts = {}) {
13445
13638
  }
13446
13639
  clearCofactor() {
13447
13640
  const { clearCofactor } = extraOpts;
13448
- if (cofactor === _1n6)
13641
+ if (cofactor === _1n7)
13449
13642
  return this;
13450
13643
  if (clearCofactor)
13451
13644
  return clearCofactor(Point, this);
@@ -13603,7 +13796,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
13603
13796
  };
13604
13797
  const defaultSigOpts_format = "compact";
13605
13798
  function isBiggerThanHalfOrder(number) {
13606
- const HALF = CURVE_ORDER >> _1n6;
13799
+ const HALF = CURVE_ORDER >> _1n7;
13607
13800
  return number > HALF;
13608
13801
  }
13609
13802
  function validateRS(title, num) {
@@ -13642,8 +13835,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
13642
13835
  const s = bytes.subarray(L, L * 2);
13643
13836
  return new Signature(Fn2.fromBytes(r), Fn2.fromBytes(s), recid);
13644
13837
  }
13645
- static fromHex(hex3, format5) {
13646
- return this.fromBytes(hexToBytes(hex3), format5);
13838
+ static fromHex(hex4, format5) {
13839
+ return this.fromBytes(hexToBytes(hex4), format5);
13647
13840
  }
13648
13841
  addRecoveryBit(recovery) {
13649
13842
  return new Signature(this.r, this.s, recovery);
@@ -13653,7 +13846,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
13653
13846
  const { r, s, recovery: rec } = this;
13654
13847
  if (rec == null || ![0, 1, 2, 3].includes(rec))
13655
13848
  throw new Error("recovery id invalid");
13656
- const hasCofactor = CURVE_ORDER * _2n4 < FIELD_ORDER;
13849
+ const hasCofactor = CURVE_ORDER * _2n5 < FIELD_ORDER;
13657
13850
  if (hasCofactor && rec > 1)
13658
13851
  throw new Error("recovery id is ambiguous for h>1 curve");
13659
13852
  const radj = rec === 2 || rec === 3 ? r + CURVE_ORDER : r;
@@ -13694,11 +13887,11 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
13694
13887
  // TODO: remove
13695
13888
  assertValidity() {
13696
13889
  }
13697
- static fromCompact(hex3) {
13698
- return Signature.fromBytes(ensureBytes("sig", hex3), "compact");
13890
+ static fromCompact(hex4) {
13891
+ return Signature.fromBytes(ensureBytes("sig", hex4), "compact");
13699
13892
  }
13700
- static fromDER(hex3) {
13701
- return Signature.fromBytes(ensureBytes("sig", hex3), "der");
13893
+ static fromDER(hex4) {
13894
+ return Signature.fromBytes(ensureBytes("sig", hex4), "der");
13702
13895
  }
13703
13896
  normalizeS() {
13704
13897
  return this.hasHighS() ? new Signature(this.r, Fn2.neg(this.s), this.recovery) : this;
@@ -13728,7 +13921,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
13728
13921
  };
13729
13922
  const ORDER_MASK = bitMask(fnBits);
13730
13923
  function int2octets(num) {
13731
- aInRange("num < 2^" + fnBits, num, _0n6, ORDER_MASK);
13924
+ aInRange("num < 2^" + fnBits, num, _0n7, ORDER_MASK);
13732
13925
  return Fn2.toBytes(num);
13733
13926
  }
13734
13927
  function validateMsgAndHash(message, prehash) {
@@ -13756,12 +13949,12 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
13756
13949
  const ik = Fn2.inv(k);
13757
13950
  const q = Point.BASE.multiply(k).toAffine();
13758
13951
  const r = Fn2.create(q.x);
13759
- if (r === _0n6)
13952
+ if (r === _0n7)
13760
13953
  return;
13761
13954
  const s = Fn2.create(ik * Fn2.create(m + r * d));
13762
- if (s === _0n6)
13955
+ if (s === _0n7)
13763
13956
  return;
13764
- let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n6);
13957
+ let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n7);
13765
13958
  let normS = s;
13766
13959
  if (lowS && isBiggerThanHalfOrder(s)) {
13767
13960
  normS = Fn2.neg(s);
@@ -13904,7 +14097,7 @@ function weierstrass(c) {
13904
14097
  const signs = ecdsa(Point, hash, ecdsaOpts);
13905
14098
  return _ecdsa_new_output_to_legacy(c, signs);
13906
14099
  }
13907
- var divNearest, DERErr, DER, _0n6, _1n6, _2n4, _3n3, _4n2;
14100
+ var divNearest, DERErr, DER, _0n7, _1n7, _2n5, _3n3, _4n2;
13908
14101
  var init_weierstrass = __esm({
13909
14102
  "../../node_modules/@noble/curves/esm/abstract/weierstrass.js"() {
13910
14103
  "use strict";
@@ -13913,7 +14106,7 @@ var init_weierstrass = __esm({
13913
14106
  init_utils2();
13914
14107
  init_curve();
13915
14108
  init_modular();
13916
- divNearest = (num, den) => (num + (num >= 0 ? den : -den) / _2n4) / den;
14109
+ divNearest = (num, den) => (num + (num >= 0 ? den : -den) / _2n5) / den;
13917
14110
  DERErr = class extends Error {
13918
14111
  constructor(m = "") {
13919
14112
  super(m);
@@ -13981,14 +14174,14 @@ var init_weierstrass = __esm({
13981
14174
  _int: {
13982
14175
  encode(num) {
13983
14176
  const { Err: E } = DER;
13984
- if (num < _0n6)
14177
+ if (num < _0n7)
13985
14178
  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)
14179
+ let hex4 = numberToHexUnpadded(num);
14180
+ if (Number.parseInt(hex4[0], 16) & 8)
14181
+ hex4 = "00" + hex4;
14182
+ if (hex4.length & 1)
13990
14183
  throw new E("unexpected DER parsing assertion: unpadded hex");
13991
- return hex3;
14184
+ return hex4;
13992
14185
  },
13993
14186
  decode(data) {
13994
14187
  const { Err: E } = DER;
@@ -13999,9 +14192,9 @@ var init_weierstrass = __esm({
13999
14192
  return bytesToNumberBE(data);
14000
14193
  }
14001
14194
  },
14002
- toSig(hex3) {
14195
+ toSig(hex4) {
14003
14196
  const { Err: E, _int: int, _tlv: tlv } = DER;
14004
- const data = ensureBytes("signature", hex3);
14197
+ const data = ensureBytes("signature", hex4);
14005
14198
  const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
14006
14199
  if (seqLeftBytes.length)
14007
14200
  throw new E("invalid signature: left bytes after parsing");
@@ -14019,9 +14212,9 @@ var init_weierstrass = __esm({
14019
14212
  return tlv.encode(48, seq);
14020
14213
  }
14021
14214
  };
14022
- _0n6 = BigInt(0);
14023
- _1n6 = BigInt(1);
14024
- _2n4 = BigInt(2);
14215
+ _0n7 = BigInt(0);
14216
+ _1n7 = BigInt(1);
14217
+ _2n5 = BigInt(2);
14025
14218
  _3n3 = BigInt(3);
14026
14219
  _4n2 = BigInt(4);
14027
14220
  }
@@ -20849,6 +21042,8 @@ init_blake3();
20849
21042
  init_ed25519();
20850
21043
  init_sha256();
20851
21044
  init_sha256();
21045
+ init_sha256();
21046
+ init_sha3();
20852
21047
  var __defProp3 = Object.defineProperty;
20853
21048
  var __export3 = (target, all) => {
20854
21049
  for (var name in all)
@@ -26983,6 +27178,197 @@ var SharePublishError = class extends Error {
26983
27178
  this.code = code32;
26984
27179
  }
26985
27180
  };
27181
+ var AddressedContentSourceError = class extends TypeError {
27182
+ code;
27183
+ constructor(code32, message) {
27184
+ super(message);
27185
+ this.name = "AddressedContentSourceError";
27186
+ this.code = code32;
27187
+ }
27188
+ };
27189
+ var SHARE_ID = /^[a-z0-9][a-z0-9_-]{15,63}$/;
27190
+ var NETWORK = /^urn:tinycloud:encryption:(.+):default$/;
27191
+ var OWNER_PKH = /^did:pkh:eip155:([1-9][0-9]*):(0x[0-9a-fA-F]{40})$/;
27192
+ var OWNER_KEY = /^did:key:[A-Za-z0-9]+$/;
27193
+ var ENVELOPE_FIELDS = ["v", "networkId", "keyPath", "alg", "keyVersion", "encryptedSymmetricKey", "encryptedSymmetricKeyHash", "ciphertext", "aad", "metadata"];
27194
+ var ENVELOPE_ALG = "x25519-aes256gcm/v1";
27195
+ var HEX_DIGEST = /^[0-9a-f]{64}$/;
27196
+ var BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
27197
+ var textEncoder = new TextEncoder();
27198
+ function hex2(bytes3) {
27199
+ return [...bytes3].map((byte) => byte.toString(16).padStart(2, "0")).join("");
27200
+ }
27201
+ function checksumAddress(address) {
27202
+ const lower = address.toLowerCase().slice(2);
27203
+ const hash = keccak_256(textEncoder.encode(lower));
27204
+ let out = "0x";
27205
+ for (let index = 0; index < lower.length; index++) {
27206
+ const nibble = hash[index >> 1] >> (index % 2 === 0 ? 4 : 0) & 15;
27207
+ out += nibble >= 8 ? lower[index].toUpperCase() : lower[index];
27208
+ }
27209
+ return out;
27210
+ }
27211
+ function pathBoundKeyPath(shareId) {
27212
+ if (typeof shareId !== "string" || !SHARE_ID.test(shareId)) {
27213
+ throw new AddressedContentSourceError("share-id-invalid", "addressed share id is invalid: 16 to 64 characters from lowercase letters, digits, '_' and '-', starting with a letter or digit (a lowercase UUID, hyphens included, is valid)");
27214
+ }
27215
+ return `share/${shareId}`;
27216
+ }
27217
+ function assertEncryptionNetwork(network) {
27218
+ const match = typeof network === "string" ? NETWORK.exec(network) : null;
27219
+ if (match === null) {
27220
+ throw new AddressedContentSourceError("network-invalid", "encryption network must be the owner's default network: urn:tinycloud:encryption:<did>:default");
27221
+ }
27222
+ const owner = match[1];
27223
+ const pkh = OWNER_PKH.exec(owner);
27224
+ if (pkh !== null) {
27225
+ if (pkh[2] !== checksumAddress(pkh[2])) {
27226
+ throw new AddressedContentSourceError("network-not-checksummed", "encryption network address must be EIP-55 checksummed; use defaultEncryptionNetworkForOwner(ownerDid)");
27227
+ }
27228
+ } else if (!OWNER_KEY.test(owner)) {
27229
+ throw new AddressedContentSourceError("network-invalid", "encryption network owner must be a did:pkh:eip155 address or a did:key");
27230
+ }
27231
+ return network;
27232
+ }
27233
+ var assertNetwork = assertEncryptionNetwork;
27234
+ function decodeWrappedKey(encryptedSymmetricKey) {
27235
+ if (typeof encryptedSymmetricKey !== "string" || !BASE64.test(encryptedSymmetricKey)) {
27236
+ throw new AddressedContentSourceError("envelope-invalid", "wrapped content key is not strict base64");
27237
+ }
27238
+ try {
27239
+ return fromBase64Url3(encryptedSymmetricKey.replace(/=+$/, "").replace(/\+/g, "-").replace(/\//g, "_"));
27240
+ } catch {
27241
+ throw new AddressedContentSourceError("envelope-invalid", "wrapped content key is not strict base64");
27242
+ }
27243
+ }
27244
+ function decodeBase64(value) {
27245
+ try {
27246
+ return fromBase64Url3(value.replace(/=+$/, "").replace(/\+/g, "-").replace(/\//g, "_"));
27247
+ } catch {
27248
+ throw new AddressedContentSourceError("envelope-invalid", "envelope field is not strict base64");
27249
+ }
27250
+ }
27251
+ function wrappedKeyDigestHex(encryptedSymmetricKey) {
27252
+ return hex2(sha2562(decodeWrappedKey(encryptedSymmetricKey)));
27253
+ }
27254
+ function canonicalKeyHashHex(encryptedSymmetricKey) {
27255
+ return hex2(sha2562(textEncoder.encode(canonicalize3(encryptedSymmetricKey))));
27256
+ }
27257
+ function pathBoundSessionPermissions(input) {
27258
+ const encryptionNetwork = assertNetwork(input.encryptionNetwork);
27259
+ return [{ service: "tinycloud.encryption", path: `${encryptionNetwork}/share/`, actions: ["tinycloud.encryption/decrypt", "tinycloud.encryption/key.create"] }];
27260
+ }
27261
+ function planPathBoundShare(input) {
27262
+ const keyPath = pathBoundKeyPath(input.shareId);
27263
+ const encryptionNetwork = assertNetwork(input.encryptionNetwork);
27264
+ const keyResource = `${encryptionNetwork}/${keyPath}`;
27265
+ return {
27266
+ shareId: input.shareId,
27267
+ encryptionNetwork,
27268
+ keyPath,
27269
+ keyResource,
27270
+ requiredPermissions: [{ service: "tinycloud.encryption", path: keyResource, actions: ["tinycloud.encryption/key.create"] }],
27271
+ sessionPermissions: pathBoundSessionPermissions({ encryptionNetwork }),
27272
+ registrationPermissions: [{ service: "tinycloud.encryption", path: `${encryptionNetwork}/share/`, actions: ["tinycloud.encryption/decrypt"] }],
27273
+ encryptOptions: (extra) => ({ networkId: encryptionNetwork, ...extra?.metadata === void 0 ? {} : { metadata: { ...extra.metadata } } })
27274
+ };
27275
+ }
27276
+ function pathBoundStoredBytes(envelope) {
27277
+ return textEncoder.encode(canonicalize3(envelope));
27278
+ }
27279
+ function assertEnvelope(plan, envelope) {
27280
+ if (envelope === null || typeof envelope !== "object" || envelope.v !== 2) {
27281
+ throw new AddressedContentSourceError("envelope-invalid", "path-bound content must be a v2 named-key envelope (encrypt with keys.encrypt, not encryptToNetwork)");
27282
+ }
27283
+ if (envelope.networkId !== plan.encryptionNetwork || envelope.keyPath !== plan.keyPath) {
27284
+ throw new AddressedContentSourceError("key-path-mismatch", "envelope network or key path does not match the share's plan");
27285
+ }
27286
+ if (!Number.isSafeInteger(envelope.keyVersion) || envelope.keyVersion < 1) {
27287
+ throw new AddressedContentSourceError("envelope-invalid", "envelope key version is invalid");
27288
+ }
27289
+ wrappedKeyDigestHex(envelope.encryptedSymmetricKey);
27290
+ if (envelope.encryptedSymmetricKeyHash !== canonicalKeyHashHex(envelope.encryptedSymmetricKey)) {
27291
+ throw new AddressedContentSourceError("envelope-invalid", "envelope key hash does not match its wrapped key");
27292
+ }
27293
+ const record2 = envelope;
27294
+ if (Object.keys(record2).some((key) => !ENVELOPE_FIELDS.includes(key)) || record2.alg !== ENVELOPE_ALG) {
27295
+ throw new AddressedContentSourceError("envelope-invalid", "envelope has a field or algorithm the recipient does not accept");
27296
+ }
27297
+ if (typeof record2.ciphertext !== "string" || !BASE64.test(record2.ciphertext) || decodeBase64(record2.ciphertext).length < 28) {
27298
+ throw new AddressedContentSourceError("envelope-invalid", "envelope ciphertext is not strict base64 of at least 28 bytes");
27299
+ }
27300
+ if (record2.aad !== void 0 && (typeof record2.aad !== "string" || !BASE64.test(record2.aad))) {
27301
+ throw new AddressedContentSourceError("envelope-invalid", "envelope aad is not strict base64");
27302
+ }
27303
+ if (record2.metadata !== void 0 && (record2.metadata === null || typeof record2.metadata !== "object" || Array.isArray(record2.metadata) || Object.values(record2.metadata).some((entry) => typeof entry !== "string"))) {
27304
+ throw new AddressedContentSourceError("envelope-invalid", "envelope metadata must be an object of strings");
27305
+ }
27306
+ }
27307
+ function bindPathBoundContentSource(input) {
27308
+ const { plan, envelope } = input;
27309
+ assertEnvelope(plan, envelope);
27310
+ const expected = pathBoundStoredBytes(envelope);
27311
+ if (input.storedBytes.length !== expected.length || input.storedBytes.some((byte, index) => byte !== expected[index])) {
27312
+ throw new AddressedContentSourceError("stored-bytes-mismatch", "uploaded bytes are not the canonical v2 envelope; upload pathBoundStoredBytes(envelope)");
27313
+ }
27314
+ return {
27315
+ shareId: plan.shareId,
27316
+ kvResource: input.kvResource,
27317
+ selector: input.selector,
27318
+ encryptionNetwork: plan.encryptionNetwork,
27319
+ encryptionKeyPath: plan.keyPath,
27320
+ encryptedSymmetricKeyDigestHex: wrappedKeyDigestHex(envelope.encryptedSymmetricKey),
27321
+ keyVersion: envelope.keyVersion,
27322
+ mode: "immutable",
27323
+ initialCiphertextDigestHex: hex2(sha2562(expected))
27324
+ };
27325
+ }
27326
+ function isUnauthorized(error) {
27327
+ const value = error;
27328
+ return value !== null && typeof value === "object" && (value.status === 401 || value.status === 403 || value.code === "PERMISSION_DENIED" || value.code === "AUTH_UNAUTHORIZED");
27329
+ }
27330
+ async function encryptAddressedShareContent(input) {
27331
+ const { plan, keys } = input;
27332
+ const byteLength = input.plaintext.byteLength;
27333
+ let receipt;
27334
+ try {
27335
+ receipt = await keys.createKey(plan.keyPath, { networkId: plan.encryptionNetwork });
27336
+ } catch (error) {
27337
+ if (isUnauthorized(error)) {
27338
+ const status = error.status;
27339
+ throw new AddressedContentSourceError(
27340
+ "key-not-authorized",
27341
+ `the owner session does not hold tinycloud.encryption/key.create on ${plan.keyResource} (the node answers "Unauthorized Action: ${plan.keyResource} / tinycloud.encryption/key.create"); hold it either at sign-in (put plan.sessionPermissions in the manifest: key.create on ${plan.encryptionNetwork}/share/) or per share (requestPermissions(plan.requiredPermissions)) before creating the key` + (status === 403 ? "; if the owner signs in through OpenKey, the request must come from a first-party TinyCloud origin" : "")
27342
+ );
27343
+ }
27344
+ throw error;
27345
+ }
27346
+ if (receipt.networkId !== plan.encryptionNetwork || receipt.keyPath !== plan.keyPath || receipt.state !== void 0 && receipt.state !== "active") {
27347
+ throw new AddressedContentSourceError("key-receipt-mismatch", "the created key does not match this share");
27348
+ }
27349
+ const envelope = await keys.encrypt(plan.keyPath, input.plaintext, plan.encryptOptions(input.metadata === void 0 ? void 0 : { metadata: input.metadata }));
27350
+ assertEnvelope(plan, envelope);
27351
+ if (receipt.keyVersion !== void 0 && envelope.keyVersion !== receipt.keyVersion) {
27352
+ throw new AddressedContentSourceError("key-receipt-mismatch", "the envelope key version does not match the created key");
27353
+ }
27354
+ const storedBytes = pathBoundStoredBytes(envelope);
27355
+ return { envelope, storedBytes, byteLength };
27356
+ }
27357
+ function assertPathBoundContentSource(source, shareId) {
27358
+ if (source === void 0 || source === null || typeof source !== "object") {
27359
+ throw new AddressedContentSourceError("key-path-required", "addressed content source is missing");
27360
+ }
27361
+ if (source.encryptionKeyPath === void 0) {
27362
+ throw new AddressedContentSourceError("key-path-required", "addressed content source must name its key (encryptionKeyPath: share/<shareId>); a network-wide source is not accepted");
27363
+ }
27364
+ if (source.encryptionKeyPath !== pathBoundKeyPath(shareId)) {
27365
+ throw new AddressedContentSourceError("key-path-mismatch", "addressed content source key path must be share/<shareId> of this share");
27366
+ }
27367
+ if (typeof source.encryptedSymmetricKeyDigestHex !== "string" || !HEX_DIGEST.test(source.encryptedSymmetricKeyDigestHex)) {
27368
+ throw new AddressedContentSourceError("digest-invalid", "addressed content source needs encryptedSymmetricKeyDigestHex: 64 lowercase hex characters");
27369
+ }
27370
+ assertEncryptionNetwork(source.encryptionNetwork);
27371
+ }
26986
27372
  function authorizationMethodForTarget(target) {
26987
27373
  if (target.kind === "recipientDid") return "openkey-device";
26988
27374
  if (target.kind === "email") return "email-claim";
@@ -27452,7 +27838,7 @@ var POLICY_CAPABILITY_V1_DOMAIN2 = "xyz.tinycloud.policy/PolicyCapability/v1\0";
27452
27838
  var CONTENT_SOURCE_V1_DOMAIN2 = "xyz.tinycloud.policy/ContentSource/v1\0";
27453
27839
  var NATIVE_PROJECTION_V1_DOMAIN2 = "xyz.tinycloud.policy/NativeProjection/v1\0";
27454
27840
  var ENVELOPE_V3_DOMAIN = "xyz.tinycloud.share/envelope/v3\0";
27455
- var textEncoder = new TextEncoder();
27841
+ var textEncoder2 = new TextEncoder();
27456
27842
  function targetMatcher(target) {
27457
27843
  if (target.kind === "recipientDid") return { kind: "recipientDid", value: target.did };
27458
27844
  if (target.kind === "email") return { kind: "exactEmail", value: target.address };
@@ -27463,17 +27849,18 @@ function targetKind(target) {
27463
27849
  }
27464
27850
  var OWNER_SHARE_ACTIONS = /* @__PURE__ */ new Set(["tinycloud.kv/get", "tinycloud.kv/list", "tinycloud.kv/metadata", "tinycloud.kv/put"]);
27465
27851
  function assertSafeInput(input) {
27466
- if (!/^[A-Za-z0-9_-]{16,128}$/.test(input.shareId)) throw new TypeError("addressed share id is invalid");
27852
+ pathBoundKeyPath(input.shareId);
27853
+ assertPathBoundContentSource(input.contentSource, input.shareId);
27467
27854
  if (!Number.isSafeInteger(input.byteLength) || input.byteLength < 0 || input.byteLength > SHARE_CONTENT_LIMIT) throw new TypeError("addressed content length is invalid");
27468
27855
  if (!Number.isFinite(input.expiresAt.getTime()) || input.expiresAt.getTime() <= Date.now()) throw new TypeError("addressed share expiry must be in the future");
27469
27856
  if (input.artifact === "html" && (input.resource.kind !== "prefix" || !input.actions.includes("read") || !input.actions.includes("list"))) throw new TypeError("html artifacts require a readable prefix");
27470
27857
  if (input.contentSource.shareId !== input.shareId || input.contentSource.selector !== input.resource.kind) throw new TypeError("addressed content source is not bound to the share");
27471
27858
  }
27472
- function hex2(bytes3) {
27859
+ function hex3(bytes3) {
27473
27860
  return [...bytes3].map((byte) => byte.toString(16).padStart(2, "0")).join("");
27474
27861
  }
27475
27862
  function digestHex(value, domain) {
27476
- return hex2(sha2562(textEncoder.encode(`${domain}${canonicalize3(value)}`)));
27863
+ return hex3(sha2562(textEncoder2.encode(`${domain}${canonicalize3(value)}`)));
27477
27864
  }
27478
27865
  function sortCanonical(values) {
27479
27866
  return [...values].sort((left, right) => canonicalize3(left).localeCompare(canonicalize3(right)));
@@ -27517,19 +27904,20 @@ async function createPolicy(options, capabilities) {
27517
27904
  const unsigned = options.credentialRequirement === void 0 ? { schema: "xyz.tinycloud.policy/policy/v1", ...fields } : { schema: "xyz.tinycloud.policy/policy/v2", ...fields, credentialRequirement: options.credentialRequirement };
27518
27905
  const domain = options.credentialRequirement === void 0 ? POLICY_V1_DOMAIN : POLICY_V2_DOMAIN;
27519
27906
  const policyDigestHex = digestHex(unsigned, domain);
27520
- const signature = await options.authority.sign(sha2562(textEncoder.encode(`${domain}${canonicalize3(unsigned)}`)));
27907
+ const signature = await options.authority.sign(sha2562(textEncoder2.encode(`${domain}${canonicalize3(unsigned)}`)));
27521
27908
  if (signature.byteLength !== 64) throw new TypeError("policy signature must be Ed25519");
27522
27909
  const policy = {
27523
27910
  ...unsigned,
27524
27911
  policyId: `pol_${base32Lower2(Uint8Array.from(policyDigestHex.match(/../g), (byte) => Number.parseInt(byte, 16)))}`,
27525
27912
  signature: { suite: "Ed25519", signerDid: options.authority.ownerDid, value: toBase64Url2(signature) }
27526
27913
  };
27527
- return { policy, policyCid: await computeCid2(textEncoder.encode(canonicalize3(policy))), policyDigestHex };
27914
+ return { policy, policyCid: await computeCid2(textEncoder2.encode(canonicalize3(policy))), policyDigestHex };
27528
27915
  }
27529
27916
  function addressedPlan(options) {
27530
27917
  const capabilities = sortCanonical([
27531
27918
  { kind: "kv", resource: options.contentSource.kvResource, selector: options.resource.kind, actions: [...options.policyActions] },
27532
- { kind: "encryption", resource: options.contentSource.encryptionKeyPath === void 0 ? options.contentSource.encryptionNetwork : `${options.contentSource.encryptionNetwork}/${options.contentSource.encryptionKeyPath}`, action: "tinycloud.encryption/decrypt" }
27919
+ // Only this share's one key: there is no network-scope capability.
27920
+ { kind: "encryption", resource: `${options.contentSource.encryptionNetwork}/${options.contentSource.encryptionKeyPath}`, action: "tinycloud.encryption/decrypt" }
27533
27921
  ]);
27534
27922
  return {
27535
27923
  expiry: rfc3339Seconds(options.expiresAt),
@@ -27617,7 +28005,7 @@ function mailboxCredentialCommitment(target) {
27617
28005
  return {
27618
28006
  type: "TinyCloudPolicyCredentialRequirement",
27619
28007
  version: 1,
27620
- requirementDigest: toBase64Url2(sha2562(textEncoder.encode(canonicalize3(requirement)))),
28008
+ requirementDigest: toBase64Url2(sha2562(textEncoder2.encode(canonicalize3(requirement)))),
27621
28009
  descriptorDigest: target.kind === "email" ? EMAIL_DESCRIPTOR_DIGEST : EMAIL_DOMAIN_DESCRIPTOR_DIGEST,
27622
28010
  issuerDid: EMAIL_CREDENTIAL_ISSUER_DID,
27623
28011
  issuerKid: EMAIL_CREDENTIAL_ISSUER_KID,
@@ -27707,11 +28095,11 @@ async function publishAddressedShare(input) {
27707
28095
  expiry
27708
28096
  });
27709
28097
  unsignedShareEnvelopeV3Schema2.parse(unsigned);
27710
- const envelopeSignature = await options.authority.sign(sha2562(textEncoder.encode(`${ENVELOPE_V3_DOMAIN}${canonicalize3(unsigned)}`)));
28098
+ const envelopeSignature = await options.authority.sign(sha2562(textEncoder2.encode(`${ENVELOPE_V3_DOMAIN}${canonicalize3(unsigned)}`)));
27711
28099
  if (envelopeSignature.byteLength !== 64) throw new TypeError("v3 envelope signature must be Ed25519");
27712
28100
  const envelope = signedAddressedEnvelope(unsigned, options.authority.ownerDid, envelopeSignature);
27713
28101
  shareEnvelopeV3Schema2.parse(envelope);
27714
- const envelopeBytes = textEncoder.encode(canonicalize3(envelope));
28102
+ const envelopeBytes = textEncoder2.encode(canonicalize3(envelope));
27715
28103
  const envelopeKeyBytes = generateKey2();
27716
28104
  const sealed = await seal2(envelopeBytes, envelopeKeyBytes);
27717
28105
  const envelopeKey = toBase64Url2(envelopeKeyBytes);
@@ -27791,7 +28179,7 @@ function rootAuthorizationBound(input) {
27791
28179
  nnc: "A".repeat(36),
27792
28180
  prf: []
27793
28181
  };
27794
- return `${toBase64Url2(textEncoder.encode(canonicalize3(header)))}.${toBase64Url2(textEncoder.encode(canonicalize3(payload)))}.${"A".repeat(86)}`;
28182
+ return `${toBase64Url2(textEncoder2.encode(canonicalize3(header)))}.${toBase64Url2(textEncoder2.encode(canonicalize3(payload)))}.${"A".repeat(86)}`;
27795
28183
  }
27796
28184
  async function sealedBodyUpperBound(options) {
27797
28185
  const plan = addressedPlan(options);
@@ -27839,7 +28227,7 @@ async function sealedBodyUpperBound(options) {
27839
28227
  expiry: plan.expiry
27840
28228
  });
27841
28229
  const envelope = signedAddressedEnvelope(unsigned, options.ownerDid, signature);
27842
- return (await seal2(textEncoder.encode(canonicalize3(envelope)), generateKey2())).blob.length;
28230
+ return (await seal2(textEncoder2.encode(canonicalize3(envelope)), generateKey2())).blob.length;
27843
28231
  }
27844
28232
  async function assertSealedBodyFits(options) {
27845
28233
  if (await sealedBodyUpperBound(options) > await linkBodyLimit()) throw new SharePublishError("max-bytes-exceeded", ADDRESSED_SHARE_TOO_LARGE_MESSAGE);
@@ -27849,12 +28237,15 @@ async function addressedShareBodyUpperBound(input) {
27849
28237
  const deliveryEmail = input.deliveryEmail ?? (target.kind === "email" && isEnvelopeDeliveryEmail(target.address) ? target.address : void 0);
27850
28238
  const artifactStorage = "artifactId" in input.storage ? input.storage : void 0;
27851
28239
  const path = "path" in input.storage ? input.storage.path : `${ARTIFACT_ROOT2}/${input.storage.artifactId}/versions/${Number.MAX_SAFE_INTEGER}/${input.storage.storageName}`;
28240
+ const keyPath = pathBoundKeyPath(input.shareId);
28241
+ assertEncryptionNetwork(input.encryptionNetwork);
28242
+ if (input.encryptionKeyPath !== void 0 && input.encryptionKeyPath !== keyPath) throw new AddressedContentSourceError("key-path-mismatch", "addressed content source key path must be share/<shareId> of this share");
27852
28243
  const contentSource = {
27853
28244
  shareId: input.shareId,
27854
28245
  kvResource: `${input.spaceId}/kv/${path}`,
27855
28246
  selector: input.resource.kind,
27856
28247
  encryptionNetwork: input.encryptionNetwork,
27857
- ...input.encryptionKeyPath === void 0 ? {} : { encryptionKeyPath: input.encryptionKeyPath },
28248
+ encryptionKeyPath: keyPath,
27858
28249
  encryptedSymmetricKeyDigestHex: "f".repeat(64),
27859
28250
  keyVersion: Number.MAX_SAFE_INTEGER,
27860
28251
  mode: "immutable",
@@ -30077,68 +30468,6 @@ var unsignedShareEnvelopeV3Schema3 = unsignedShareEnvelopeV3BaseSchema3.superRef
30077
30468
  var shareEnvelopeV3Schema3 = unsignedShareEnvelopeV3BaseSchema3.extend({ signature: signatureSchema3 }).strict().superRefine(validateV3Invariants3);
30078
30469
  var ENVELOPE_AAD_LABEL4 = "tinycloud-share-envelope-v1";
30079
30470
  var AAD4 = utf8Bytes4(ENVELOPE_AAD_LABEL4);
30080
- function isPlainRecord4(value) {
30081
- const proto = Object.getPrototypeOf(value);
30082
- return proto === Object.prototype || proto === null;
30083
- }
30084
- function assertNoLoneSurrogates4(text) {
30085
- for (let i = 0; i < text.length; i++) {
30086
- const unit = text.charCodeAt(i);
30087
- if (unit >= 56320 && unit <= 57343) {
30088
- throw new TypeError(
30089
- `cannot canonicalize string with unpaired low surrogate at index ${i}`
30090
- );
30091
- }
30092
- if (unit >= 55296 && unit <= 56319) {
30093
- const next = text.charCodeAt(i + 1);
30094
- if (!(next >= 56320 && next <= 57343)) {
30095
- throw new TypeError(
30096
- `cannot canonicalize string with unpaired high surrogate at index ${i}`
30097
- );
30098
- }
30099
- i++;
30100
- }
30101
- }
30102
- }
30103
- function serializeString4(text) {
30104
- assertNoLoneSurrogates4(text);
30105
- return JSON.stringify(text);
30106
- }
30107
- function serialize4(value) {
30108
- if (value === null) return "null";
30109
- switch (typeof value) {
30110
- case "boolean":
30111
- return JSON.stringify(value);
30112
- case "string":
30113
- return serializeString4(value);
30114
- case "number":
30115
- if (!Number.isFinite(value)) {
30116
- throw new TypeError(`cannot canonicalize non-finite number: ${value}`);
30117
- }
30118
- return JSON.stringify(value);
30119
- case "object":
30120
- break;
30121
- default:
30122
- throw new TypeError(`cannot canonicalize value of type ${typeof value}`);
30123
- }
30124
- if (Array.isArray(value)) {
30125
- return `[${value.map((item) => serialize4(item)).join(",")}]`;
30126
- }
30127
- if (!isPlainRecord4(value)) {
30128
- throw new TypeError("cannot canonicalize non-plain object");
30129
- }
30130
- const keys = Object.keys(value).sort();
30131
- const members = [];
30132
- for (const key of keys) {
30133
- const member = value[key];
30134
- if (member === void 0) continue;
30135
- members.push(`${serializeString4(key)}:${serialize4(member)}`);
30136
- }
30137
- return `{${members.join(",")}}`;
30138
- }
30139
- function canonicalize4(value) {
30140
- return serialize4(value);
30141
- }
30142
30471
  var LABEL2 = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
30143
30472
  function isCanonicalEmailDomain2(value) {
30144
30473
  if (value.length === 0 || value.length > 253) return false;
@@ -31187,11 +31516,9 @@ function createShareAuthorityAdapters(input = {}) {
31187
31516
  throw new TypeError("email credential descriptor and issuer are required");
31188
31517
  }
31189
31518
  const addressedEncryptionNetwork = targetInput.target.kind === "bearer" ? void 0 : targetInput.target.kind === "email" ? node.getDefaultEncryptionNetworkId() : node.getEncryptionNetworkIdForSpace(ownerSpaceId);
31190
- const emailKeyPath = targetInput.target.kind === "email" ? `share/${crypto.randomUUID().replaceAll("-", "")}` : void 0;
31191
- if (addressedEncryptionNetwork !== void 0 && node.isSessionOnly && !sessionHoldsEncryptionDecrypt(
31192
- node,
31193
- emailKeyPath === void 0 ? addressedEncryptionNetwork : `${addressedEncryptionNetwork}/${emailKeyPath}`
31194
- )) {
31519
+ const shareId = crypto.randomUUID().replaceAll("-", "");
31520
+ const pathPlan = addressedEncryptionNetwork === void 0 ? void 0 : planPathBoundShare({ shareId, encryptionNetwork: addressedEncryptionNetwork });
31521
+ if (pathPlan !== void 0 && node.isSessionOnly && !sessionHoldsEncryptionDecrypt(node, pathPlan.keyResource)) {
31195
31522
  throw new SharePublishAuthorityError({ kind: "decrypt-not-held" });
31196
31523
  }
31197
31524
  const config = await publicConfig();
@@ -31200,7 +31527,6 @@ function createShareAuthorityAdapters(input = {}) {
31200
31527
  if (targetInput.notify === true && targetInput.target.kind === "emailDomain") {
31201
31528
  await assertDomainDeliveryForOrigin(activeNode.origin, "publish");
31202
31529
  }
31203
- const shareId = emailKeyPath?.slice("share/".length) ?? crypto.randomUUID().replaceAll("-", "");
31204
31530
  const files = targetInput.files === void 0 || targetInput.files.length === 0 ? [{ bytes: targetInput.source, filename: targetInput.filename, mediaType: targetInput.mediaType }] : targetInput.files;
31205
31531
  const resourceKind = targetInput.resourceKind ?? "exact";
31206
31532
  if (targetInput.target.kind === "bearer") {
@@ -31322,7 +31648,6 @@ function createShareAuthorityAdapters(input = {}) {
31322
31648
  resource: { kind: resourceKind },
31323
31649
  storage: artifact === void 0 ? { path: resourcePath } : { artifactId: artifact.id, storageName },
31324
31650
  encryptionNetwork: addressedEncryptionNetwork,
31325
- ...emailKeyPath === void 0 ? {} : { encryptionKeyPath: emailKeyPath },
31326
31651
  actions,
31327
31652
  policyActions,
31328
31653
  ...deliveryEmail === void 0 ? {} : { deliveryEmail },
@@ -31337,16 +31662,14 @@ function createShareAuthorityAdapters(input = {}) {
31337
31662
  const rejected = error instanceof LocationRecordValidationError || error instanceof LocationRegistryHttpError && error.status >= 400 && error.status < 500 && error.status !== 408 && error.status !== 429;
31338
31663
  throw new SharePublishAuthorityError({ kind: rejected ? "registry-rejected" : "registry-unavailable" });
31339
31664
  }
31340
- const encryptionNetwork = addressedEncryptionNetwork;
31341
- const encrypted = await node.encryption.encryptToNetwork(encryptionNetwork, file.bytes, {
31342
- ...emailKeyPath === void 0 ? {} : { keyPath: emailKeyPath },
31665
+ const pathPlanForShare = pathPlan;
31666
+ const encrypted = await encryptAddressedShareContent({
31667
+ plan: pathPlanForShare,
31668
+ keys: node.keys,
31669
+ plaintext: file.bytes,
31343
31670
  metadata: { contentType: mediaType }
31344
31671
  });
31345
- if (!encrypted.ok) throw new Error("addressed source encryption was rejected");
31346
- if (emailKeyPath !== void 0 && (encrypted.data.networkId !== encryptionNetwork || encrypted.data.keyPath !== emailKeyPath)) {
31347
- throw new Error("email share encryption was rejected");
31348
- }
31349
- const storedBytes = new TextEncoder().encode(canonicalize4(encrypted.data));
31672
+ const storedBytes = encrypted.storedBytes;
31350
31673
  let artifactVersion;
31351
31674
  if (artifact !== void 0) {
31352
31675
  artifactVersion = await storeArtifactVersion(node.kvForSpace(ownerSpaceId), {
@@ -31373,17 +31696,13 @@ function createShareAuthorityAdapters(input = {}) {
31373
31696
  throwKvUploadFailure(stored.error);
31374
31697
  }
31375
31698
  }
31376
- const contentSource = {
31377
- shareId,
31699
+ const contentSource = bindPathBoundContentSource({
31700
+ plan: pathPlanForShare,
31701
+ envelope: encrypted.envelope,
31702
+ storedBytes,
31378
31703
  kvResource: `${ownerSpaceId}/kv/${resourcePath}`,
31379
- selector: resourceKind,
31380
- encryptionNetwork: encrypted.data.networkId,
31381
- ...emailKeyPath === void 0 ? {} : { encryptionKeyPath: emailKeyPath },
31382
- encryptedSymmetricKeyDigestHex: encrypted.data.encryptedSymmetricKeyHash,
31383
- keyVersion: encrypted.data.keyVersion,
31384
- mode: "immutable",
31385
- initialCiphertextDigestHex: createHash("sha256").update(storedBytes).digest("hex")
31386
- };
31704
+ selector: resourceKind
31705
+ });
31387
31706
  const addressedOptions = {
31388
31707
  shareId,
31389
31708
  shareOrigin: config.shareOrigin,
@@ -31915,9 +32234,9 @@ var NAMED_CHARACTERS = {
31915
32234
  newline: "\n"
31916
32235
  };
31917
32236
  function decodeAttributeValue(value) {
31918
- return value.replace(/&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([A-Za-z]{2,8}));?/g, (whole, hex3, decimal, name) => {
32237
+ return value.replace(/&(?:#[xX]([0-9a-fA-F]{1,6})|#([0-9]{1,7})|([A-Za-z]{2,8}));?/g, (whole, hex4, decimal, name) => {
31919
32238
  if (name !== void 0) return NAMED_CHARACTERS[name.toLowerCase()] ?? whole;
31920
- const point = Number.parseInt(hex3 ?? decimal ?? "", hex3 === void 0 ? 10 : 16);
32239
+ const point = Number.parseInt(hex4 ?? decimal ?? "", hex4 === void 0 ? 10 : 16);
31921
32240
  return point > 0 && point <= 1114111 && !(point >= 55296 && point <= 57343) ? String.fromCodePoint(point) : "\uFFFD";
31922
32241
  });
31923
32242
  }
@@ -32224,10 +32543,10 @@ function normalizeCssEscapes(source) {
32224
32543
  }
32225
32544
  if (next === "\n" || next === "\r" || next === "\f") break;
32226
32545
  escaped = true;
32227
- const hex3 = /^[0-9a-fA-F]{1,6}/.exec(source.slice(cursor + 1, cursor + 7));
32228
- if (hex3 !== null) {
32229
- const point = Number.parseInt(hex3[0], 16);
32230
- cursor += 1 + hex3[0].length;
32546
+ const hex4 = /^[0-9a-fA-F]{1,6}/.exec(source.slice(cursor + 1, cursor + 7));
32547
+ if (hex4 !== null) {
32548
+ const point = Number.parseInt(hex4[0], 16);
32549
+ cursor += 1 + hex4[0].length;
32231
32550
  if (source[cursor] === "\r" && source[cursor + 1] === "\n") cursor += 2;
32232
32551
  else if (/[ \t\n\r\f]/.test(source[cursor] ?? "")) cursor += 1;
32233
32552
  decoded += point === 0 || point > 1114111 || point >= 55296 && point <= 57343 ? "\uFFFD" : String.fromCodePoint(point);