terminalhire 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -259,19 +259,19 @@ function validateGraph(nodes) {
259
259
  }
260
260
  function buildAdjacency(nodes) {
261
261
  const adj = /* @__PURE__ */ new Map();
262
- const add = (from, to, w) => {
262
+ const add2 = (from, to, w) => {
263
263
  let m = adj.get(from);
264
264
  if (!m) adj.set(from, m = /* @__PURE__ */ new Map());
265
265
  if (w > (m.get(to) ?? 0)) m.set(to, w);
266
266
  };
267
267
  for (const n of nodes) {
268
268
  for (const p of n.parents ?? []) {
269
- add(n.id, p, PARENT_UP);
270
- add(p, n.id, PARENT_DOWN);
269
+ add2(n.id, p, PARENT_UP);
270
+ add2(p, n.id, PARENT_DOWN);
271
271
  }
272
272
  for (const e of n.related ?? []) {
273
- add(n.id, e.to, e.w);
274
- add(e.to, n.id, e.w);
273
+ add2(n.id, e.to, e.w);
274
+ add2(e.to, n.id, e.w);
275
275
  }
276
276
  }
277
277
  return adj;
@@ -2809,6 +2809,3037 @@ var init_directoryThreshold = __esm({
2809
2809
  }
2810
2810
  });
2811
2811
 
2812
+ // ../../node_modules/@noble/hashes/esm/cryptoNode.js
2813
+ import * as nc from "crypto";
2814
+ var crypto;
2815
+ var init_cryptoNode = __esm({
2816
+ "../../node_modules/@noble/hashes/esm/cryptoNode.js"() {
2817
+ "use strict";
2818
+ crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
2819
+ }
2820
+ });
2821
+
2822
+ // ../../node_modules/@noble/hashes/esm/utils.js
2823
+ function isBytes(a) {
2824
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
2825
+ }
2826
+ function anumber(n) {
2827
+ if (!Number.isSafeInteger(n) || n < 0)
2828
+ throw new Error("positive integer expected, got " + n);
2829
+ }
2830
+ function abytes(b, ...lengths) {
2831
+ if (!isBytes(b))
2832
+ throw new Error("Uint8Array expected");
2833
+ if (lengths.length > 0 && !lengths.includes(b.length))
2834
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
2835
+ }
2836
+ function aexists(instance, checkFinished = true) {
2837
+ if (instance.destroyed)
2838
+ throw new Error("Hash instance has been destroyed");
2839
+ if (checkFinished && instance.finished)
2840
+ throw new Error("Hash#digest() has already been called");
2841
+ }
2842
+ function aoutput(out, instance) {
2843
+ abytes(out);
2844
+ const min = instance.outputLen;
2845
+ if (out.length < min) {
2846
+ throw new Error("digestInto() expects output buffer of length at least " + min);
2847
+ }
2848
+ }
2849
+ function clean(...arrays) {
2850
+ for (let i = 0; i < arrays.length; i++) {
2851
+ arrays[i].fill(0);
2852
+ }
2853
+ }
2854
+ function createView(arr) {
2855
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2856
+ }
2857
+ function bytesToHex(bytes) {
2858
+ abytes(bytes);
2859
+ if (hasHexBuiltin)
2860
+ return bytes.toHex();
2861
+ let hex = "";
2862
+ for (let i = 0; i < bytes.length; i++) {
2863
+ hex += hexes[bytes[i]];
2864
+ }
2865
+ return hex;
2866
+ }
2867
+ function asciiToBase16(ch) {
2868
+ if (ch >= asciis._0 && ch <= asciis._9)
2869
+ return ch - asciis._0;
2870
+ if (ch >= asciis.A && ch <= asciis.F)
2871
+ return ch - (asciis.A - 10);
2872
+ if (ch >= asciis.a && ch <= asciis.f)
2873
+ return ch - (asciis.a - 10);
2874
+ return;
2875
+ }
2876
+ function hexToBytes(hex) {
2877
+ if (typeof hex !== "string")
2878
+ throw new Error("hex string expected, got " + typeof hex);
2879
+ if (hasHexBuiltin)
2880
+ return Uint8Array.fromHex(hex);
2881
+ const hl = hex.length;
2882
+ const al = hl / 2;
2883
+ if (hl % 2)
2884
+ throw new Error("hex string expected, got unpadded hex of length " + hl);
2885
+ const array = new Uint8Array(al);
2886
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
2887
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
2888
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
2889
+ if (n1 === void 0 || n2 === void 0) {
2890
+ const char = hex[hi] + hex[hi + 1];
2891
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
2892
+ }
2893
+ array[ai] = n1 * 16 + n2;
2894
+ }
2895
+ return array;
2896
+ }
2897
+ function utf8ToBytes(str) {
2898
+ if (typeof str !== "string")
2899
+ throw new Error("string expected");
2900
+ return new Uint8Array(new TextEncoder().encode(str));
2901
+ }
2902
+ function toBytes(data) {
2903
+ if (typeof data === "string")
2904
+ data = utf8ToBytes(data);
2905
+ abytes(data);
2906
+ return data;
2907
+ }
2908
+ function concatBytes(...arrays) {
2909
+ let sum = 0;
2910
+ for (let i = 0; i < arrays.length; i++) {
2911
+ const a = arrays[i];
2912
+ abytes(a);
2913
+ sum += a.length;
2914
+ }
2915
+ const res = new Uint8Array(sum);
2916
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
2917
+ const a = arrays[i];
2918
+ res.set(a, pad);
2919
+ pad += a.length;
2920
+ }
2921
+ return res;
2922
+ }
2923
+ function createHasher(hashCons) {
2924
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
2925
+ const tmp = hashCons();
2926
+ hashC.outputLen = tmp.outputLen;
2927
+ hashC.blockLen = tmp.blockLen;
2928
+ hashC.create = () => hashCons();
2929
+ return hashC;
2930
+ }
2931
+ function randomBytes(bytesLength = 32) {
2932
+ if (crypto && typeof crypto.getRandomValues === "function") {
2933
+ return crypto.getRandomValues(new Uint8Array(bytesLength));
2934
+ }
2935
+ if (crypto && typeof crypto.randomBytes === "function") {
2936
+ return Uint8Array.from(crypto.randomBytes(bytesLength));
2937
+ }
2938
+ throw new Error("crypto.getRandomValues must be defined");
2939
+ }
2940
+ var hasHexBuiltin, hexes, asciis, Hash;
2941
+ var init_utils = __esm({
2942
+ "../../node_modules/@noble/hashes/esm/utils.js"() {
2943
+ "use strict";
2944
+ init_cryptoNode();
2945
+ hasHexBuiltin = /* @__PURE__ */ (() => (
2946
+ // @ts-ignore
2947
+ typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
2948
+ ))();
2949
+ hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
2950
+ asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
2951
+ Hash = class {
2952
+ };
2953
+ }
2954
+ });
2955
+
2956
+ // ../../node_modules/@noble/hashes/esm/_md.js
2957
+ function setBigUint64(view, byteOffset, value, isLE2) {
2958
+ if (typeof view.setBigUint64 === "function")
2959
+ return view.setBigUint64(byteOffset, value, isLE2);
2960
+ const _32n2 = BigInt(32);
2961
+ const _u32_max = BigInt(4294967295);
2962
+ const wh = Number(value >> _32n2 & _u32_max);
2963
+ const wl = Number(value & _u32_max);
2964
+ const h = isLE2 ? 4 : 0;
2965
+ const l = isLE2 ? 0 : 4;
2966
+ view.setUint32(byteOffset + h, wh, isLE2);
2967
+ view.setUint32(byteOffset + l, wl, isLE2);
2968
+ }
2969
+ var HashMD, SHA512_IV;
2970
+ var init_md = __esm({
2971
+ "../../node_modules/@noble/hashes/esm/_md.js"() {
2972
+ "use strict";
2973
+ init_utils();
2974
+ HashMD = class extends Hash {
2975
+ constructor(blockLen, outputLen, padOffset, isLE2) {
2976
+ super();
2977
+ this.finished = false;
2978
+ this.length = 0;
2979
+ this.pos = 0;
2980
+ this.destroyed = false;
2981
+ this.blockLen = blockLen;
2982
+ this.outputLen = outputLen;
2983
+ this.padOffset = padOffset;
2984
+ this.isLE = isLE2;
2985
+ this.buffer = new Uint8Array(blockLen);
2986
+ this.view = createView(this.buffer);
2987
+ }
2988
+ update(data) {
2989
+ aexists(this);
2990
+ data = toBytes(data);
2991
+ abytes(data);
2992
+ const { view, buffer, blockLen } = this;
2993
+ const len = data.length;
2994
+ for (let pos = 0; pos < len; ) {
2995
+ const take = Math.min(blockLen - this.pos, len - pos);
2996
+ if (take === blockLen) {
2997
+ const dataView = createView(data);
2998
+ for (; blockLen <= len - pos; pos += blockLen)
2999
+ this.process(dataView, pos);
3000
+ continue;
3001
+ }
3002
+ buffer.set(data.subarray(pos, pos + take), this.pos);
3003
+ this.pos += take;
3004
+ pos += take;
3005
+ if (this.pos === blockLen) {
3006
+ this.process(view, 0);
3007
+ this.pos = 0;
3008
+ }
3009
+ }
3010
+ this.length += data.length;
3011
+ this.roundClean();
3012
+ return this;
3013
+ }
3014
+ digestInto(out) {
3015
+ aexists(this);
3016
+ aoutput(out, this);
3017
+ this.finished = true;
3018
+ const { buffer, view, blockLen, isLE: isLE2 } = this;
3019
+ let { pos } = this;
3020
+ buffer[pos++] = 128;
3021
+ clean(this.buffer.subarray(pos));
3022
+ if (this.padOffset > blockLen - pos) {
3023
+ this.process(view, 0);
3024
+ pos = 0;
3025
+ }
3026
+ for (let i = pos; i < blockLen; i++)
3027
+ buffer[i] = 0;
3028
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
3029
+ this.process(view, 0);
3030
+ const oview = createView(out);
3031
+ const len = this.outputLen;
3032
+ if (len % 4)
3033
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
3034
+ const outLen = len / 4;
3035
+ const state = this.get();
3036
+ if (outLen > state.length)
3037
+ throw new Error("_sha2: outputLen bigger than state");
3038
+ for (let i = 0; i < outLen; i++)
3039
+ oview.setUint32(4 * i, state[i], isLE2);
3040
+ }
3041
+ digest() {
3042
+ const { buffer, outputLen } = this;
3043
+ this.digestInto(buffer);
3044
+ const res = buffer.slice(0, outputLen);
3045
+ this.destroy();
3046
+ return res;
3047
+ }
3048
+ _cloneInto(to) {
3049
+ to || (to = new this.constructor());
3050
+ to.set(...this.get());
3051
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
3052
+ to.destroyed = destroyed;
3053
+ to.finished = finished;
3054
+ to.length = length;
3055
+ to.pos = pos;
3056
+ if (length % blockLen)
3057
+ to.buffer.set(buffer);
3058
+ return to;
3059
+ }
3060
+ clone() {
3061
+ return this._cloneInto();
3062
+ }
3063
+ };
3064
+ SHA512_IV = /* @__PURE__ */ Uint32Array.from([
3065
+ 1779033703,
3066
+ 4089235720,
3067
+ 3144134277,
3068
+ 2227873595,
3069
+ 1013904242,
3070
+ 4271175723,
3071
+ 2773480762,
3072
+ 1595750129,
3073
+ 1359893119,
3074
+ 2917565137,
3075
+ 2600822924,
3076
+ 725511199,
3077
+ 528734635,
3078
+ 4215389547,
3079
+ 1541459225,
3080
+ 327033209
3081
+ ]);
3082
+ }
3083
+ });
3084
+
3085
+ // ../../node_modules/@noble/hashes/esm/_u64.js
3086
+ function fromBig(n, le = false) {
3087
+ if (le)
3088
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
3089
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
3090
+ }
3091
+ function split(lst, le = false) {
3092
+ const len = lst.length;
3093
+ let Ah = new Uint32Array(len);
3094
+ let Al = new Uint32Array(len);
3095
+ for (let i = 0; i < len; i++) {
3096
+ const { h, l } = fromBig(lst[i], le);
3097
+ [Ah[i], Al[i]] = [h, l];
3098
+ }
3099
+ return [Ah, Al];
3100
+ }
3101
+ function add(Ah, Al, Bh, Bl) {
3102
+ const l = (Al >>> 0) + (Bl >>> 0);
3103
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
3104
+ }
3105
+ var U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, add3L, add3H, add4L, add4H, add5L, add5H;
3106
+ var init_u64 = __esm({
3107
+ "../../node_modules/@noble/hashes/esm/_u64.js"() {
3108
+ "use strict";
3109
+ U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
3110
+ _32n = /* @__PURE__ */ BigInt(32);
3111
+ shrSH = (h, _l, s) => h >>> s;
3112
+ shrSL = (h, l, s) => h << 32 - s | l >>> s;
3113
+ rotrSH = (h, l, s) => h >>> s | l << 32 - s;
3114
+ rotrSL = (h, l, s) => h << 32 - s | l >>> s;
3115
+ rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
3116
+ rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
3117
+ add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
3118
+ add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
3119
+ add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
3120
+ add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
3121
+ add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
3122
+ add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
3123
+ }
3124
+ });
3125
+
3126
+ // ../../node_modules/@noble/hashes/esm/sha2.js
3127
+ var K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, sha512;
3128
+ var init_sha2 = __esm({
3129
+ "../../node_modules/@noble/hashes/esm/sha2.js"() {
3130
+ "use strict";
3131
+ init_md();
3132
+ init_u64();
3133
+ init_utils();
3134
+ K512 = /* @__PURE__ */ (() => split([
3135
+ "0x428a2f98d728ae22",
3136
+ "0x7137449123ef65cd",
3137
+ "0xb5c0fbcfec4d3b2f",
3138
+ "0xe9b5dba58189dbbc",
3139
+ "0x3956c25bf348b538",
3140
+ "0x59f111f1b605d019",
3141
+ "0x923f82a4af194f9b",
3142
+ "0xab1c5ed5da6d8118",
3143
+ "0xd807aa98a3030242",
3144
+ "0x12835b0145706fbe",
3145
+ "0x243185be4ee4b28c",
3146
+ "0x550c7dc3d5ffb4e2",
3147
+ "0x72be5d74f27b896f",
3148
+ "0x80deb1fe3b1696b1",
3149
+ "0x9bdc06a725c71235",
3150
+ "0xc19bf174cf692694",
3151
+ "0xe49b69c19ef14ad2",
3152
+ "0xefbe4786384f25e3",
3153
+ "0x0fc19dc68b8cd5b5",
3154
+ "0x240ca1cc77ac9c65",
3155
+ "0x2de92c6f592b0275",
3156
+ "0x4a7484aa6ea6e483",
3157
+ "0x5cb0a9dcbd41fbd4",
3158
+ "0x76f988da831153b5",
3159
+ "0x983e5152ee66dfab",
3160
+ "0xa831c66d2db43210",
3161
+ "0xb00327c898fb213f",
3162
+ "0xbf597fc7beef0ee4",
3163
+ "0xc6e00bf33da88fc2",
3164
+ "0xd5a79147930aa725",
3165
+ "0x06ca6351e003826f",
3166
+ "0x142929670a0e6e70",
3167
+ "0x27b70a8546d22ffc",
3168
+ "0x2e1b21385c26c926",
3169
+ "0x4d2c6dfc5ac42aed",
3170
+ "0x53380d139d95b3df",
3171
+ "0x650a73548baf63de",
3172
+ "0x766a0abb3c77b2a8",
3173
+ "0x81c2c92e47edaee6",
3174
+ "0x92722c851482353b",
3175
+ "0xa2bfe8a14cf10364",
3176
+ "0xa81a664bbc423001",
3177
+ "0xc24b8b70d0f89791",
3178
+ "0xc76c51a30654be30",
3179
+ "0xd192e819d6ef5218",
3180
+ "0xd69906245565a910",
3181
+ "0xf40e35855771202a",
3182
+ "0x106aa07032bbd1b8",
3183
+ "0x19a4c116b8d2d0c8",
3184
+ "0x1e376c085141ab53",
3185
+ "0x2748774cdf8eeb99",
3186
+ "0x34b0bcb5e19b48a8",
3187
+ "0x391c0cb3c5c95a63",
3188
+ "0x4ed8aa4ae3418acb",
3189
+ "0x5b9cca4f7763e373",
3190
+ "0x682e6ff3d6b2b8a3",
3191
+ "0x748f82ee5defb2fc",
3192
+ "0x78a5636f43172f60",
3193
+ "0x84c87814a1f0ab72",
3194
+ "0x8cc702081a6439ec",
3195
+ "0x90befffa23631e28",
3196
+ "0xa4506cebde82bde9",
3197
+ "0xbef9a3f7b2c67915",
3198
+ "0xc67178f2e372532b",
3199
+ "0xca273eceea26619c",
3200
+ "0xd186b8c721c0c207",
3201
+ "0xeada7dd6cde0eb1e",
3202
+ "0xf57d4f7fee6ed178",
3203
+ "0x06f067aa72176fba",
3204
+ "0x0a637dc5a2c898a6",
3205
+ "0x113f9804bef90dae",
3206
+ "0x1b710b35131c471b",
3207
+ "0x28db77f523047d84",
3208
+ "0x32caab7b40c72493",
3209
+ "0x3c9ebe0a15c9bebc",
3210
+ "0x431d67c49c100d4c",
3211
+ "0x4cc5d4becb3e42b6",
3212
+ "0x597f299cfc657e2a",
3213
+ "0x5fcb6fab3ad6faec",
3214
+ "0x6c44198c4a475817"
3215
+ ].map((n) => BigInt(n))))();
3216
+ SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
3217
+ SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
3218
+ SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
3219
+ SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
3220
+ SHA512 = class extends HashMD {
3221
+ constructor(outputLen = 64) {
3222
+ super(128, outputLen, 16, false);
3223
+ this.Ah = SHA512_IV[0] | 0;
3224
+ this.Al = SHA512_IV[1] | 0;
3225
+ this.Bh = SHA512_IV[2] | 0;
3226
+ this.Bl = SHA512_IV[3] | 0;
3227
+ this.Ch = SHA512_IV[4] | 0;
3228
+ this.Cl = SHA512_IV[5] | 0;
3229
+ this.Dh = SHA512_IV[6] | 0;
3230
+ this.Dl = SHA512_IV[7] | 0;
3231
+ this.Eh = SHA512_IV[8] | 0;
3232
+ this.El = SHA512_IV[9] | 0;
3233
+ this.Fh = SHA512_IV[10] | 0;
3234
+ this.Fl = SHA512_IV[11] | 0;
3235
+ this.Gh = SHA512_IV[12] | 0;
3236
+ this.Gl = SHA512_IV[13] | 0;
3237
+ this.Hh = SHA512_IV[14] | 0;
3238
+ this.Hl = SHA512_IV[15] | 0;
3239
+ }
3240
+ // prettier-ignore
3241
+ get() {
3242
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
3243
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
3244
+ }
3245
+ // prettier-ignore
3246
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
3247
+ this.Ah = Ah | 0;
3248
+ this.Al = Al | 0;
3249
+ this.Bh = Bh | 0;
3250
+ this.Bl = Bl | 0;
3251
+ this.Ch = Ch | 0;
3252
+ this.Cl = Cl | 0;
3253
+ this.Dh = Dh | 0;
3254
+ this.Dl = Dl | 0;
3255
+ this.Eh = Eh | 0;
3256
+ this.El = El | 0;
3257
+ this.Fh = Fh | 0;
3258
+ this.Fl = Fl | 0;
3259
+ this.Gh = Gh | 0;
3260
+ this.Gl = Gl | 0;
3261
+ this.Hh = Hh | 0;
3262
+ this.Hl = Hl | 0;
3263
+ }
3264
+ process(view, offset) {
3265
+ for (let i = 0; i < 16; i++, offset += 4) {
3266
+ SHA512_W_H[i] = view.getUint32(offset);
3267
+ SHA512_W_L[i] = view.getUint32(offset += 4);
3268
+ }
3269
+ for (let i = 16; i < 80; i++) {
3270
+ const W15h = SHA512_W_H[i - 15] | 0;
3271
+ const W15l = SHA512_W_L[i - 15] | 0;
3272
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
3273
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
3274
+ const W2h = SHA512_W_H[i - 2] | 0;
3275
+ const W2l = SHA512_W_L[i - 2] | 0;
3276
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
3277
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
3278
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
3279
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
3280
+ SHA512_W_H[i] = SUMh | 0;
3281
+ SHA512_W_L[i] = SUMl | 0;
3282
+ }
3283
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
3284
+ for (let i = 0; i < 80; i++) {
3285
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
3286
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
3287
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
3288
+ const CHIl = El & Fl ^ ~El & Gl;
3289
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
3290
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
3291
+ const T1l = T1ll | 0;
3292
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
3293
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
3294
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
3295
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
3296
+ Hh = Gh | 0;
3297
+ Hl = Gl | 0;
3298
+ Gh = Fh | 0;
3299
+ Gl = Fl | 0;
3300
+ Fh = Eh | 0;
3301
+ Fl = El | 0;
3302
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
3303
+ Dh = Ch | 0;
3304
+ Dl = Cl | 0;
3305
+ Ch = Bh | 0;
3306
+ Cl = Bl | 0;
3307
+ Bh = Ah | 0;
3308
+ Bl = Al | 0;
3309
+ const All = add3L(T1l, sigma0l, MAJl);
3310
+ Ah = add3H(All, T1h, sigma0h, MAJh);
3311
+ Al = All | 0;
3312
+ }
3313
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
3314
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
3315
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
3316
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
3317
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
3318
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
3319
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
3320
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
3321
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
3322
+ }
3323
+ roundClean() {
3324
+ clean(SHA512_W_H, SHA512_W_L);
3325
+ }
3326
+ destroy() {
3327
+ clean(this.buffer);
3328
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
3329
+ }
3330
+ };
3331
+ sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
3332
+ }
3333
+ });
3334
+
3335
+ // ../../node_modules/@noble/curves/esm/utils.js
3336
+ function _abool2(value, title = "") {
3337
+ if (typeof value !== "boolean") {
3338
+ const prefix = title && `"${title}"`;
3339
+ throw new Error(prefix + "expected boolean, got type=" + typeof value);
3340
+ }
3341
+ return value;
3342
+ }
3343
+ function _abytes2(value, length, title = "") {
3344
+ const bytes = isBytes(value);
3345
+ const len = value?.length;
3346
+ const needsLen = length !== void 0;
3347
+ if (!bytes || needsLen && len !== length) {
3348
+ const prefix = title && `"${title}" `;
3349
+ const ofLen = needsLen ? ` of length ${length}` : "";
3350
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
3351
+ throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
3352
+ }
3353
+ return value;
3354
+ }
3355
+ function hexToNumber(hex) {
3356
+ if (typeof hex !== "string")
3357
+ throw new Error("hex string expected, got " + typeof hex);
3358
+ return hex === "" ? _0n : BigInt("0x" + hex);
3359
+ }
3360
+ function bytesToNumberBE(bytes) {
3361
+ return hexToNumber(bytesToHex(bytes));
3362
+ }
3363
+ function bytesToNumberLE(bytes) {
3364
+ abytes(bytes);
3365
+ return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
3366
+ }
3367
+ function numberToBytesBE(n, len) {
3368
+ return hexToBytes(n.toString(16).padStart(len * 2, "0"));
3369
+ }
3370
+ function numberToBytesLE(n, len) {
3371
+ return numberToBytesBE(n, len).reverse();
3372
+ }
3373
+ function ensureBytes(title, hex, expectedLength) {
3374
+ let res;
3375
+ if (typeof hex === "string") {
3376
+ try {
3377
+ res = hexToBytes(hex);
3378
+ } catch (e) {
3379
+ throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
3380
+ }
3381
+ } else if (isBytes(hex)) {
3382
+ res = Uint8Array.from(hex);
3383
+ } else {
3384
+ throw new Error(title + " must be hex string or Uint8Array");
3385
+ }
3386
+ const len = res.length;
3387
+ if (typeof expectedLength === "number" && len !== expectedLength)
3388
+ throw new Error(title + " of length " + expectedLength + " expected, got " + len);
3389
+ return res;
3390
+ }
3391
+ function equalBytes(a, b) {
3392
+ if (a.length !== b.length)
3393
+ return false;
3394
+ let diff = 0;
3395
+ for (let i = 0; i < a.length; i++)
3396
+ diff |= a[i] ^ b[i];
3397
+ return diff === 0;
3398
+ }
3399
+ function copyBytes(bytes) {
3400
+ return Uint8Array.from(bytes);
3401
+ }
3402
+ function inRange(n, min, max) {
3403
+ return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
3404
+ }
3405
+ function aInRange(title, n, min, max) {
3406
+ if (!inRange(n, min, max))
3407
+ throw new Error("expected valid " + title + ": " + min + " <= n < " + max + ", got " + n);
3408
+ }
3409
+ function bitLen(n) {
3410
+ let len;
3411
+ for (len = 0; n > _0n; n >>= _1n, len += 1)
3412
+ ;
3413
+ return len;
3414
+ }
3415
+ function _validateObject(object, fields, optFields = {}) {
3416
+ if (!object || typeof object !== "object")
3417
+ throw new Error("expected valid options object");
3418
+ function checkField(fieldName, expectedType, isOpt) {
3419
+ const val = object[fieldName];
3420
+ if (isOpt && val === void 0)
3421
+ return;
3422
+ const current = typeof val;
3423
+ if (current !== expectedType || val === null)
3424
+ throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
3425
+ }
3426
+ Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
3427
+ Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
3428
+ }
3429
+ function memoized(fn) {
3430
+ const map = /* @__PURE__ */ new WeakMap();
3431
+ return (arg, ...args2) => {
3432
+ const val = map.get(arg);
3433
+ if (val !== void 0)
3434
+ return val;
3435
+ const computed = fn(arg, ...args2);
3436
+ map.set(arg, computed);
3437
+ return computed;
3438
+ };
3439
+ }
3440
+ var _0n, _1n, isPosBig, bitMask, notImplemented;
3441
+ var init_utils2 = __esm({
3442
+ "../../node_modules/@noble/curves/esm/utils.js"() {
3443
+ "use strict";
3444
+ init_utils();
3445
+ init_utils();
3446
+ _0n = /* @__PURE__ */ BigInt(0);
3447
+ _1n = /* @__PURE__ */ BigInt(1);
3448
+ isPosBig = (n) => typeof n === "bigint" && _0n <= n;
3449
+ bitMask = (n) => (_1n << BigInt(n)) - _1n;
3450
+ notImplemented = () => {
3451
+ throw new Error("not implemented");
3452
+ };
3453
+ }
3454
+ });
3455
+
3456
+ // ../../node_modules/@noble/curves/esm/abstract/modular.js
3457
+ function mod(a, b) {
3458
+ const result = a % b;
3459
+ return result >= _0n2 ? result : b + result;
3460
+ }
3461
+ function pow2(x, power, modulo) {
3462
+ let res = x;
3463
+ while (power-- > _0n2) {
3464
+ res *= res;
3465
+ res %= modulo;
3466
+ }
3467
+ return res;
3468
+ }
3469
+ function invert(number, modulo) {
3470
+ if (number === _0n2)
3471
+ throw new Error("invert: expected non-zero number");
3472
+ if (modulo <= _0n2)
3473
+ throw new Error("invert: expected positive modulus, got " + modulo);
3474
+ let a = mod(number, modulo);
3475
+ let b = modulo;
3476
+ let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
3477
+ while (a !== _0n2) {
3478
+ const q = b / a;
3479
+ const r = b % a;
3480
+ const m = x - u * q;
3481
+ const n = y - v * q;
3482
+ b = a, a = r, x = u, y = v, u = m, v = n;
3483
+ }
3484
+ const gcd = b;
3485
+ if (gcd !== _1n2)
3486
+ throw new Error("invert: does not exist");
3487
+ return mod(x, modulo);
3488
+ }
3489
+ function assertIsSquare(Fp2, root, n) {
3490
+ if (!Fp2.eql(Fp2.sqr(root), n))
3491
+ throw new Error("Cannot find square root");
3492
+ }
3493
+ function sqrt3mod4(Fp2, n) {
3494
+ const p1div4 = (Fp2.ORDER + _1n2) / _4n;
3495
+ const root = Fp2.pow(n, p1div4);
3496
+ assertIsSquare(Fp2, root, n);
3497
+ return root;
3498
+ }
3499
+ function sqrt5mod8(Fp2, n) {
3500
+ const p5div8 = (Fp2.ORDER - _5n) / _8n;
3501
+ const n2 = Fp2.mul(n, _2n);
3502
+ const v = Fp2.pow(n2, p5div8);
3503
+ const nv = Fp2.mul(n, v);
3504
+ const i = Fp2.mul(Fp2.mul(nv, _2n), v);
3505
+ const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
3506
+ assertIsSquare(Fp2, root, n);
3507
+ return root;
3508
+ }
3509
+ function sqrt9mod16(P) {
3510
+ const Fp_ = Field(P);
3511
+ const tn = tonelliShanks(P);
3512
+ const c1 = tn(Fp_, Fp_.neg(Fp_.ONE));
3513
+ const c2 = tn(Fp_, c1);
3514
+ const c3 = tn(Fp_, Fp_.neg(c1));
3515
+ const c4 = (P + _7n) / _16n;
3516
+ return (Fp2, n) => {
3517
+ let tv1 = Fp2.pow(n, c4);
3518
+ let tv2 = Fp2.mul(tv1, c1);
3519
+ const tv3 = Fp2.mul(tv1, c2);
3520
+ const tv4 = Fp2.mul(tv1, c3);
3521
+ const e1 = Fp2.eql(Fp2.sqr(tv2), n);
3522
+ const e2 = Fp2.eql(Fp2.sqr(tv3), n);
3523
+ tv1 = Fp2.cmov(tv1, tv2, e1);
3524
+ tv2 = Fp2.cmov(tv4, tv3, e2);
3525
+ const e3 = Fp2.eql(Fp2.sqr(tv2), n);
3526
+ const root = Fp2.cmov(tv1, tv2, e3);
3527
+ assertIsSquare(Fp2, root, n);
3528
+ return root;
3529
+ };
3530
+ }
3531
+ function tonelliShanks(P) {
3532
+ if (P < _3n)
3533
+ throw new Error("sqrt is not defined for small field");
3534
+ let Q = P - _1n2;
3535
+ let S = 0;
3536
+ while (Q % _2n === _0n2) {
3537
+ Q /= _2n;
3538
+ S++;
3539
+ }
3540
+ let Z = _2n;
3541
+ const _Fp = Field(P);
3542
+ while (FpLegendre(_Fp, Z) === 1) {
3543
+ if (Z++ > 1e3)
3544
+ throw new Error("Cannot find square root: probably non-prime P");
3545
+ }
3546
+ if (S === 1)
3547
+ return sqrt3mod4;
3548
+ let cc = _Fp.pow(Z, Q);
3549
+ const Q1div2 = (Q + _1n2) / _2n;
3550
+ return function tonelliSlow(Fp2, n) {
3551
+ if (Fp2.is0(n))
3552
+ return n;
3553
+ if (FpLegendre(Fp2, n) !== 1)
3554
+ throw new Error("Cannot find square root");
3555
+ let M = S;
3556
+ let c = Fp2.mul(Fp2.ONE, cc);
3557
+ let t = Fp2.pow(n, Q);
3558
+ let R = Fp2.pow(n, Q1div2);
3559
+ while (!Fp2.eql(t, Fp2.ONE)) {
3560
+ if (Fp2.is0(t))
3561
+ return Fp2.ZERO;
3562
+ let i = 1;
3563
+ let t_tmp = Fp2.sqr(t);
3564
+ while (!Fp2.eql(t_tmp, Fp2.ONE)) {
3565
+ i++;
3566
+ t_tmp = Fp2.sqr(t_tmp);
3567
+ if (i === M)
3568
+ throw new Error("Cannot find square root");
3569
+ }
3570
+ const exponent = _1n2 << BigInt(M - i - 1);
3571
+ const b = Fp2.pow(c, exponent);
3572
+ M = i;
3573
+ c = Fp2.sqr(b);
3574
+ t = Fp2.mul(t, c);
3575
+ R = Fp2.mul(R, b);
3576
+ }
3577
+ return R;
3578
+ };
3579
+ }
3580
+ function FpSqrt(P) {
3581
+ if (P % _4n === _3n)
3582
+ return sqrt3mod4;
3583
+ if (P % _8n === _5n)
3584
+ return sqrt5mod8;
3585
+ if (P % _16n === _9n)
3586
+ return sqrt9mod16(P);
3587
+ return tonelliShanks(P);
3588
+ }
3589
+ function validateField(field) {
3590
+ const initial = {
3591
+ ORDER: "bigint",
3592
+ MASK: "bigint",
3593
+ BYTES: "number",
3594
+ BITS: "number"
3595
+ };
3596
+ const opts = FIELD_FIELDS.reduce((map, val) => {
3597
+ map[val] = "function";
3598
+ return map;
3599
+ }, initial);
3600
+ _validateObject(field, opts);
3601
+ return field;
3602
+ }
3603
+ function FpPow(Fp2, num, power) {
3604
+ if (power < _0n2)
3605
+ throw new Error("invalid exponent, negatives unsupported");
3606
+ if (power === _0n2)
3607
+ return Fp2.ONE;
3608
+ if (power === _1n2)
3609
+ return num;
3610
+ let p = Fp2.ONE;
3611
+ let d = num;
3612
+ while (power > _0n2) {
3613
+ if (power & _1n2)
3614
+ p = Fp2.mul(p, d);
3615
+ d = Fp2.sqr(d);
3616
+ power >>= _1n2;
3617
+ }
3618
+ return p;
3619
+ }
3620
+ function FpInvertBatch(Fp2, nums, passZero = false) {
3621
+ const inverted = new Array(nums.length).fill(passZero ? Fp2.ZERO : void 0);
3622
+ const multipliedAcc = nums.reduce((acc, num, i) => {
3623
+ if (Fp2.is0(num))
3624
+ return acc;
3625
+ inverted[i] = acc;
3626
+ return Fp2.mul(acc, num);
3627
+ }, Fp2.ONE);
3628
+ const invertedAcc = Fp2.inv(multipliedAcc);
3629
+ nums.reduceRight((acc, num, i) => {
3630
+ if (Fp2.is0(num))
3631
+ return acc;
3632
+ inverted[i] = Fp2.mul(acc, inverted[i]);
3633
+ return Fp2.mul(acc, num);
3634
+ }, invertedAcc);
3635
+ return inverted;
3636
+ }
3637
+ function FpLegendre(Fp2, n) {
3638
+ const p1mod2 = (Fp2.ORDER - _1n2) / _2n;
3639
+ const powered = Fp2.pow(n, p1mod2);
3640
+ const yes = Fp2.eql(powered, Fp2.ONE);
3641
+ const zero = Fp2.eql(powered, Fp2.ZERO);
3642
+ const no = Fp2.eql(powered, Fp2.neg(Fp2.ONE));
3643
+ if (!yes && !zero && !no)
3644
+ throw new Error("invalid Legendre symbol result");
3645
+ return yes ? 1 : zero ? 0 : -1;
3646
+ }
3647
+ function nLength(n, nBitLength) {
3648
+ if (nBitLength !== void 0)
3649
+ anumber(nBitLength);
3650
+ const _nBitLength = nBitLength !== void 0 ? nBitLength : n.toString(2).length;
3651
+ const nByteLength = Math.ceil(_nBitLength / 8);
3652
+ return { nBitLength: _nBitLength, nByteLength };
3653
+ }
3654
+ function Field(ORDER, bitLenOrOpts, isLE2 = false, opts = {}) {
3655
+ if (ORDER <= _0n2)
3656
+ throw new Error("invalid field: expected ORDER > 0, got " + ORDER);
3657
+ let _nbitLength = void 0;
3658
+ let _sqrt = void 0;
3659
+ let modFromBytes = false;
3660
+ let allowedLengths = void 0;
3661
+ if (typeof bitLenOrOpts === "object" && bitLenOrOpts != null) {
3662
+ if (opts.sqrt || isLE2)
3663
+ throw new Error("cannot specify opts in two arguments");
3664
+ const _opts = bitLenOrOpts;
3665
+ if (_opts.BITS)
3666
+ _nbitLength = _opts.BITS;
3667
+ if (_opts.sqrt)
3668
+ _sqrt = _opts.sqrt;
3669
+ if (typeof _opts.isLE === "boolean")
3670
+ isLE2 = _opts.isLE;
3671
+ if (typeof _opts.modFromBytes === "boolean")
3672
+ modFromBytes = _opts.modFromBytes;
3673
+ allowedLengths = _opts.allowedLengths;
3674
+ } else {
3675
+ if (typeof bitLenOrOpts === "number")
3676
+ _nbitLength = bitLenOrOpts;
3677
+ if (opts.sqrt)
3678
+ _sqrt = opts.sqrt;
3679
+ }
3680
+ const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, _nbitLength);
3681
+ if (BYTES > 2048)
3682
+ throw new Error("invalid field: expected ORDER of <= 2048 bytes");
3683
+ let sqrtP;
3684
+ const f = Object.freeze({
3685
+ ORDER,
3686
+ isLE: isLE2,
3687
+ BITS,
3688
+ BYTES,
3689
+ MASK: bitMask(BITS),
3690
+ ZERO: _0n2,
3691
+ ONE: _1n2,
3692
+ allowedLengths,
3693
+ create: (num) => mod(num, ORDER),
3694
+ isValid: (num) => {
3695
+ if (typeof num !== "bigint")
3696
+ throw new Error("invalid field element: expected bigint, got " + typeof num);
3697
+ return _0n2 <= num && num < ORDER;
3698
+ },
3699
+ is0: (num) => num === _0n2,
3700
+ // is valid and invertible
3701
+ isValidNot0: (num) => !f.is0(num) && f.isValid(num),
3702
+ isOdd: (num) => (num & _1n2) === _1n2,
3703
+ neg: (num) => mod(-num, ORDER),
3704
+ eql: (lhs, rhs) => lhs === rhs,
3705
+ sqr: (num) => mod(num * num, ORDER),
3706
+ add: (lhs, rhs) => mod(lhs + rhs, ORDER),
3707
+ sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
3708
+ mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
3709
+ pow: (num, power) => FpPow(f, num, power),
3710
+ div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
3711
+ // Same as above, but doesn't normalize
3712
+ sqrN: (num) => num * num,
3713
+ addN: (lhs, rhs) => lhs + rhs,
3714
+ subN: (lhs, rhs) => lhs - rhs,
3715
+ mulN: (lhs, rhs) => lhs * rhs,
3716
+ inv: (num) => invert(num, ORDER),
3717
+ sqrt: _sqrt || ((n) => {
3718
+ if (!sqrtP)
3719
+ sqrtP = FpSqrt(ORDER);
3720
+ return sqrtP(f, n);
3721
+ }),
3722
+ toBytes: (num) => isLE2 ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES),
3723
+ fromBytes: (bytes, skipValidation = true) => {
3724
+ if (allowedLengths) {
3725
+ if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
3726
+ throw new Error("Field.fromBytes: expected " + allowedLengths + " bytes, got " + bytes.length);
3727
+ }
3728
+ const padded = new Uint8Array(BYTES);
3729
+ padded.set(bytes, isLE2 ? 0 : padded.length - bytes.length);
3730
+ bytes = padded;
3731
+ }
3732
+ if (bytes.length !== BYTES)
3733
+ throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
3734
+ let scalar = isLE2 ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
3735
+ if (modFromBytes)
3736
+ scalar = mod(scalar, ORDER);
3737
+ if (!skipValidation) {
3738
+ if (!f.isValid(scalar))
3739
+ throw new Error("invalid field element: outside of range 0..ORDER");
3740
+ }
3741
+ return scalar;
3742
+ },
3743
+ // TODO: we don't need it here, move out to separate fn
3744
+ invertBatch: (lst) => FpInvertBatch(f, lst),
3745
+ // We can't move this out because Fp6, Fp12 implement it
3746
+ // and it's unclear what to return in there.
3747
+ cmov: (a, b, c) => c ? b : a
3748
+ });
3749
+ return Object.freeze(f);
3750
+ }
3751
+ var _0n2, _1n2, _2n, _3n, _4n, _5n, _7n, _8n, _9n, _16n, isNegativeLE, FIELD_FIELDS;
3752
+ var init_modular = __esm({
3753
+ "../../node_modules/@noble/curves/esm/abstract/modular.js"() {
3754
+ "use strict";
3755
+ init_utils2();
3756
+ _0n2 = BigInt(0);
3757
+ _1n2 = BigInt(1);
3758
+ _2n = /* @__PURE__ */ BigInt(2);
3759
+ _3n = /* @__PURE__ */ BigInt(3);
3760
+ _4n = /* @__PURE__ */ BigInt(4);
3761
+ _5n = /* @__PURE__ */ BigInt(5);
3762
+ _7n = /* @__PURE__ */ BigInt(7);
3763
+ _8n = /* @__PURE__ */ BigInt(8);
3764
+ _9n = /* @__PURE__ */ BigInt(9);
3765
+ _16n = /* @__PURE__ */ BigInt(16);
3766
+ isNegativeLE = (num, modulo) => (mod(num, modulo) & _1n2) === _1n2;
3767
+ FIELD_FIELDS = [
3768
+ "create",
3769
+ "isValid",
3770
+ "is0",
3771
+ "neg",
3772
+ "inv",
3773
+ "sqrt",
3774
+ "sqr",
3775
+ "eql",
3776
+ "add",
3777
+ "sub",
3778
+ "mul",
3779
+ "pow",
3780
+ "div",
3781
+ "addN",
3782
+ "subN",
3783
+ "mulN",
3784
+ "sqrN"
3785
+ ];
3786
+ }
3787
+ });
3788
+
3789
+ // ../../node_modules/@noble/curves/esm/abstract/curve.js
3790
+ function negateCt(condition, item) {
3791
+ const neg = item.negate();
3792
+ return condition ? neg : item;
3793
+ }
3794
+ function normalizeZ(c, points) {
3795
+ const invertedZs = FpInvertBatch(c.Fp, points.map((p) => p.Z));
3796
+ return points.map((p, i) => c.fromAffine(p.toAffine(invertedZs[i])));
3797
+ }
3798
+ function validateW(W, bits) {
3799
+ if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
3800
+ throw new Error("invalid window size, expected [1.." + bits + "], got W=" + W);
3801
+ }
3802
+ function calcWOpts(W, scalarBits) {
3803
+ validateW(W, scalarBits);
3804
+ const windows = Math.ceil(scalarBits / W) + 1;
3805
+ const windowSize = 2 ** (W - 1);
3806
+ const maxNumber = 2 ** W;
3807
+ const mask = bitMask(W);
3808
+ const shiftBy = BigInt(W);
3809
+ return { windows, windowSize, mask, maxNumber, shiftBy };
3810
+ }
3811
+ function calcOffsets(n, window, wOpts) {
3812
+ const { windowSize, mask, maxNumber, shiftBy } = wOpts;
3813
+ let wbits = Number(n & mask);
3814
+ let nextN = n >> shiftBy;
3815
+ if (wbits > windowSize) {
3816
+ wbits -= maxNumber;
3817
+ nextN += _1n3;
3818
+ }
3819
+ const offsetStart = window * windowSize;
3820
+ const offset = offsetStart + Math.abs(wbits) - 1;
3821
+ const isZero = wbits === 0;
3822
+ const isNeg = wbits < 0;
3823
+ const isNegF = window % 2 !== 0;
3824
+ const offsetF = offsetStart;
3825
+ return { nextN, offset, isZero, isNeg, isNegF, offsetF };
3826
+ }
3827
+ function validateMSMPoints(points, c) {
3828
+ if (!Array.isArray(points))
3829
+ throw new Error("array expected");
3830
+ points.forEach((p, i) => {
3831
+ if (!(p instanceof c))
3832
+ throw new Error("invalid point at index " + i);
3833
+ });
3834
+ }
3835
+ function validateMSMScalars(scalars, field) {
3836
+ if (!Array.isArray(scalars))
3837
+ throw new Error("array of scalars expected");
3838
+ scalars.forEach((s, i) => {
3839
+ if (!field.isValid(s))
3840
+ throw new Error("invalid scalar at index " + i);
3841
+ });
3842
+ }
3843
+ function getW(P) {
3844
+ return pointWindowSizes.get(P) || 1;
3845
+ }
3846
+ function assert0(n) {
3847
+ if (n !== _0n3)
3848
+ throw new Error("invalid wNAF");
3849
+ }
3850
+ function pippenger(c, fieldN, points, scalars) {
3851
+ validateMSMPoints(points, c);
3852
+ validateMSMScalars(scalars, fieldN);
3853
+ const plength = points.length;
3854
+ const slength = scalars.length;
3855
+ if (plength !== slength)
3856
+ throw new Error("arrays of points and scalars must have equal length");
3857
+ const zero = c.ZERO;
3858
+ const wbits = bitLen(BigInt(plength));
3859
+ let windowSize = 1;
3860
+ if (wbits > 12)
3861
+ windowSize = wbits - 3;
3862
+ else if (wbits > 4)
3863
+ windowSize = wbits - 2;
3864
+ else if (wbits > 0)
3865
+ windowSize = 2;
3866
+ const MASK = bitMask(windowSize);
3867
+ const buckets = new Array(Number(MASK) + 1).fill(zero);
3868
+ const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
3869
+ let sum = zero;
3870
+ for (let i = lastBits; i >= 0; i -= windowSize) {
3871
+ buckets.fill(zero);
3872
+ for (let j = 0; j < slength; j++) {
3873
+ const scalar = scalars[j];
3874
+ const wbits2 = Number(scalar >> BigInt(i) & MASK);
3875
+ buckets[wbits2] = buckets[wbits2].add(points[j]);
3876
+ }
3877
+ let resI = zero;
3878
+ for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
3879
+ sumI = sumI.add(buckets[j]);
3880
+ resI = resI.add(sumI);
3881
+ }
3882
+ sum = sum.add(resI);
3883
+ if (i !== 0)
3884
+ for (let j = 0; j < windowSize; j++)
3885
+ sum = sum.double();
3886
+ }
3887
+ return sum;
3888
+ }
3889
+ function createField(order, field, isLE2) {
3890
+ if (field) {
3891
+ if (field.ORDER !== order)
3892
+ throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
3893
+ validateField(field);
3894
+ return field;
3895
+ } else {
3896
+ return Field(order, { isLE: isLE2 });
3897
+ }
3898
+ }
3899
+ function _createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
3900
+ if (FpFnLE === void 0)
3901
+ FpFnLE = type === "edwards";
3902
+ if (!CURVE || typeof CURVE !== "object")
3903
+ throw new Error(`expected valid ${type} CURVE object`);
3904
+ for (const p of ["p", "n", "h"]) {
3905
+ const val = CURVE[p];
3906
+ if (!(typeof val === "bigint" && val > _0n3))
3907
+ throw new Error(`CURVE.${p} must be positive bigint`);
3908
+ }
3909
+ const Fp2 = createField(CURVE.p, curveOpts.Fp, FpFnLE);
3910
+ const Fn2 = createField(CURVE.n, curveOpts.Fn, FpFnLE);
3911
+ const _b = type === "weierstrass" ? "b" : "d";
3912
+ const params = ["Gx", "Gy", "a", _b];
3913
+ for (const p of params) {
3914
+ if (!Fp2.isValid(CURVE[p]))
3915
+ throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
3916
+ }
3917
+ CURVE = Object.freeze(Object.assign({}, CURVE));
3918
+ return { CURVE, Fp: Fp2, Fn: Fn2 };
3919
+ }
3920
+ var _0n3, _1n3, pointPrecomputes, pointWindowSizes, wNAF;
3921
+ var init_curve = __esm({
3922
+ "../../node_modules/@noble/curves/esm/abstract/curve.js"() {
3923
+ "use strict";
3924
+ init_utils2();
3925
+ init_modular();
3926
+ _0n3 = BigInt(0);
3927
+ _1n3 = BigInt(1);
3928
+ pointPrecomputes = /* @__PURE__ */ new WeakMap();
3929
+ pointWindowSizes = /* @__PURE__ */ new WeakMap();
3930
+ wNAF = class {
3931
+ // Parametrized with a given Point class (not individual point)
3932
+ constructor(Point, bits) {
3933
+ this.BASE = Point.BASE;
3934
+ this.ZERO = Point.ZERO;
3935
+ this.Fn = Point.Fn;
3936
+ this.bits = bits;
3937
+ }
3938
+ // non-const time multiplication ladder
3939
+ _unsafeLadder(elm, n, p = this.ZERO) {
3940
+ let d = elm;
3941
+ while (n > _0n3) {
3942
+ if (n & _1n3)
3943
+ p = p.add(d);
3944
+ d = d.double();
3945
+ n >>= _1n3;
3946
+ }
3947
+ return p;
3948
+ }
3949
+ /**
3950
+ * Creates a wNAF precomputation window. Used for caching.
3951
+ * Default window size is set by `utils.precompute()` and is equal to 8.
3952
+ * Number of precomputed points depends on the curve size:
3953
+ * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
3954
+ * - 𝑊 is the window size
3955
+ * - 𝑛 is the bitlength of the curve order.
3956
+ * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
3957
+ * @param point Point instance
3958
+ * @param W window size
3959
+ * @returns precomputed point tables flattened to a single array
3960
+ */
3961
+ precomputeWindow(point, W) {
3962
+ const { windows, windowSize } = calcWOpts(W, this.bits);
3963
+ const points = [];
3964
+ let p = point;
3965
+ let base = p;
3966
+ for (let window = 0; window < windows; window++) {
3967
+ base = p;
3968
+ points.push(base);
3969
+ for (let i = 1; i < windowSize; i++) {
3970
+ base = base.add(p);
3971
+ points.push(base);
3972
+ }
3973
+ p = base.double();
3974
+ }
3975
+ return points;
3976
+ }
3977
+ /**
3978
+ * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
3979
+ * More compact implementation:
3980
+ * https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
3981
+ * @returns real and fake (for const-time) points
3982
+ */
3983
+ wNAF(W, precomputes, n) {
3984
+ if (!this.Fn.isValid(n))
3985
+ throw new Error("invalid scalar");
3986
+ let p = this.ZERO;
3987
+ let f = this.BASE;
3988
+ const wo = calcWOpts(W, this.bits);
3989
+ for (let window = 0; window < wo.windows; window++) {
3990
+ const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window, wo);
3991
+ n = nextN;
3992
+ if (isZero) {
3993
+ f = f.add(negateCt(isNegF, precomputes[offsetF]));
3994
+ } else {
3995
+ p = p.add(negateCt(isNeg, precomputes[offset]));
3996
+ }
3997
+ }
3998
+ assert0(n);
3999
+ return { p, f };
4000
+ }
4001
+ /**
4002
+ * Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
4003
+ * @param acc accumulator point to add result of multiplication
4004
+ * @returns point
4005
+ */
4006
+ wNAFUnsafe(W, precomputes, n, acc = this.ZERO) {
4007
+ const wo = calcWOpts(W, this.bits);
4008
+ for (let window = 0; window < wo.windows; window++) {
4009
+ if (n === _0n3)
4010
+ break;
4011
+ const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
4012
+ n = nextN;
4013
+ if (isZero) {
4014
+ continue;
4015
+ } else {
4016
+ const item = precomputes[offset];
4017
+ acc = acc.add(isNeg ? item.negate() : item);
4018
+ }
4019
+ }
4020
+ assert0(n);
4021
+ return acc;
4022
+ }
4023
+ getPrecomputes(W, point, transform) {
4024
+ let comp = pointPrecomputes.get(point);
4025
+ if (!comp) {
4026
+ comp = this.precomputeWindow(point, W);
4027
+ if (W !== 1) {
4028
+ if (typeof transform === "function")
4029
+ comp = transform(comp);
4030
+ pointPrecomputes.set(point, comp);
4031
+ }
4032
+ }
4033
+ return comp;
4034
+ }
4035
+ cached(point, scalar, transform) {
4036
+ const W = getW(point);
4037
+ return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
4038
+ }
4039
+ unsafe(point, scalar, transform, prev) {
4040
+ const W = getW(point);
4041
+ if (W === 1)
4042
+ return this._unsafeLadder(point, scalar, prev);
4043
+ return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
4044
+ }
4045
+ // We calculate precomputes for elliptic curve point multiplication
4046
+ // using windowed method. This specifies window size and
4047
+ // stores precomputed values. Usually only base point would be precomputed.
4048
+ createCache(P, W) {
4049
+ validateW(W, this.bits);
4050
+ pointWindowSizes.set(P, W);
4051
+ pointPrecomputes.delete(P);
4052
+ }
4053
+ hasCache(elm) {
4054
+ return getW(elm) !== 1;
4055
+ }
4056
+ };
4057
+ }
4058
+ });
4059
+
4060
+ // ../../node_modules/@noble/curves/esm/abstract/edwards.js
4061
+ function isEdValidXY(Fp2, CURVE, x, y) {
4062
+ const x2 = Fp2.sqr(x);
4063
+ const y2 = Fp2.sqr(y);
4064
+ const left = Fp2.add(Fp2.mul(CURVE.a, x2), y2);
4065
+ const right = Fp2.add(Fp2.ONE, Fp2.mul(CURVE.d, Fp2.mul(x2, y2)));
4066
+ return Fp2.eql(left, right);
4067
+ }
4068
+ function edwards(params, extraOpts = {}) {
4069
+ const validated = _createCurveFields("edwards", params, extraOpts, extraOpts.FpFnLE);
4070
+ const { Fp: Fp2, Fn: Fn2 } = validated;
4071
+ let CURVE = validated.CURVE;
4072
+ const { h: cofactor } = CURVE;
4073
+ _validateObject(extraOpts, {}, { uvRatio: "function" });
4074
+ const MASK = _2n2 << BigInt(Fn2.BYTES * 8) - _1n4;
4075
+ const modP = (n) => Fp2.create(n);
4076
+ const uvRatio2 = extraOpts.uvRatio || ((u, v) => {
4077
+ try {
4078
+ return { isValid: true, value: Fp2.sqrt(Fp2.div(u, v)) };
4079
+ } catch (e) {
4080
+ return { isValid: false, value: _0n4 };
4081
+ }
4082
+ });
4083
+ if (!isEdValidXY(Fp2, CURVE, CURVE.Gx, CURVE.Gy))
4084
+ throw new Error("bad curve params: generator point");
4085
+ function acoord(title, n, banZero = false) {
4086
+ const min = banZero ? _1n4 : _0n4;
4087
+ aInRange("coordinate " + title, n, min, MASK);
4088
+ return n;
4089
+ }
4090
+ function aextpoint(other) {
4091
+ if (!(other instanceof Point))
4092
+ throw new Error("ExtendedPoint expected");
4093
+ }
4094
+ const toAffineMemo = memoized((p, iz) => {
4095
+ const { X, Y, Z } = p;
4096
+ const is0 = p.is0();
4097
+ if (iz == null)
4098
+ iz = is0 ? _8n2 : Fp2.inv(Z);
4099
+ const x = modP(X * iz);
4100
+ const y = modP(Y * iz);
4101
+ const zz = Fp2.mul(Z, iz);
4102
+ if (is0)
4103
+ return { x: _0n4, y: _1n4 };
4104
+ if (zz !== _1n4)
4105
+ throw new Error("invZ was invalid");
4106
+ return { x, y };
4107
+ });
4108
+ const assertValidMemo = memoized((p) => {
4109
+ const { a, d } = CURVE;
4110
+ if (p.is0())
4111
+ throw new Error("bad point: ZERO");
4112
+ const { X, Y, Z, T } = p;
4113
+ const X2 = modP(X * X);
4114
+ const Y2 = modP(Y * Y);
4115
+ const Z2 = modP(Z * Z);
4116
+ const Z4 = modP(Z2 * Z2);
4117
+ const aX2 = modP(X2 * a);
4118
+ const left = modP(Z2 * modP(aX2 + Y2));
4119
+ const right = modP(Z4 + modP(d * modP(X2 * Y2)));
4120
+ if (left !== right)
4121
+ throw new Error("bad point: equation left != right (1)");
4122
+ const XY = modP(X * Y);
4123
+ const ZT = modP(Z * T);
4124
+ if (XY !== ZT)
4125
+ throw new Error("bad point: equation left != right (2)");
4126
+ return true;
4127
+ });
4128
+ class Point {
4129
+ constructor(X, Y, Z, T) {
4130
+ this.X = acoord("x", X);
4131
+ this.Y = acoord("y", Y);
4132
+ this.Z = acoord("z", Z, true);
4133
+ this.T = acoord("t", T);
4134
+ Object.freeze(this);
4135
+ }
4136
+ static CURVE() {
4137
+ return CURVE;
4138
+ }
4139
+ static fromAffine(p) {
4140
+ if (p instanceof Point)
4141
+ throw new Error("extended point not allowed");
4142
+ const { x, y } = p || {};
4143
+ acoord("x", x);
4144
+ acoord("y", y);
4145
+ return new Point(x, y, _1n4, modP(x * y));
4146
+ }
4147
+ // Uses algo from RFC8032 5.1.3.
4148
+ static fromBytes(bytes, zip215 = false) {
4149
+ const len = Fp2.BYTES;
4150
+ const { a, d } = CURVE;
4151
+ bytes = copyBytes(_abytes2(bytes, len, "point"));
4152
+ _abool2(zip215, "zip215");
4153
+ const normed = copyBytes(bytes);
4154
+ const lastByte = bytes[len - 1];
4155
+ normed[len - 1] = lastByte & ~128;
4156
+ const y = bytesToNumberLE(normed);
4157
+ const max = zip215 ? MASK : Fp2.ORDER;
4158
+ aInRange("point.y", y, _0n4, max);
4159
+ const y2 = modP(y * y);
4160
+ const u = modP(y2 - _1n4);
4161
+ const v = modP(d * y2 - a);
4162
+ let { isValid, value: x } = uvRatio2(u, v);
4163
+ if (!isValid)
4164
+ throw new Error("bad point: invalid y coordinate");
4165
+ const isXOdd = (x & _1n4) === _1n4;
4166
+ const isLastByteOdd = (lastByte & 128) !== 0;
4167
+ if (!zip215 && x === _0n4 && isLastByteOdd)
4168
+ throw new Error("bad point: x=0 and x_0=1");
4169
+ if (isLastByteOdd !== isXOdd)
4170
+ x = modP(-x);
4171
+ return Point.fromAffine({ x, y });
4172
+ }
4173
+ static fromHex(bytes, zip215 = false) {
4174
+ return Point.fromBytes(ensureBytes("point", bytes), zip215);
4175
+ }
4176
+ get x() {
4177
+ return this.toAffine().x;
4178
+ }
4179
+ get y() {
4180
+ return this.toAffine().y;
4181
+ }
4182
+ precompute(windowSize = 8, isLazy = true) {
4183
+ wnaf.createCache(this, windowSize);
4184
+ if (!isLazy)
4185
+ this.multiply(_2n2);
4186
+ return this;
4187
+ }
4188
+ // Useful in fromAffine() - not for fromBytes(), which always created valid points.
4189
+ assertValidity() {
4190
+ assertValidMemo(this);
4191
+ }
4192
+ // Compare one point to another.
4193
+ equals(other) {
4194
+ aextpoint(other);
4195
+ const { X: X1, Y: Y1, Z: Z1 } = this;
4196
+ const { X: X2, Y: Y2, Z: Z2 } = other;
4197
+ const X1Z2 = modP(X1 * Z2);
4198
+ const X2Z1 = modP(X2 * Z1);
4199
+ const Y1Z2 = modP(Y1 * Z2);
4200
+ const Y2Z1 = modP(Y2 * Z1);
4201
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
4202
+ }
4203
+ is0() {
4204
+ return this.equals(Point.ZERO);
4205
+ }
4206
+ negate() {
4207
+ return new Point(modP(-this.X), this.Y, this.Z, modP(-this.T));
4208
+ }
4209
+ // Fast algo for doubling Extended Point.
4210
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
4211
+ // Cost: 4M + 4S + 1*a + 6add + 1*2.
4212
+ double() {
4213
+ const { a } = CURVE;
4214
+ const { X: X1, Y: Y1, Z: Z1 } = this;
4215
+ const A = modP(X1 * X1);
4216
+ const B = modP(Y1 * Y1);
4217
+ const C = modP(_2n2 * modP(Z1 * Z1));
4218
+ const D = modP(a * A);
4219
+ const x1y1 = X1 + Y1;
4220
+ const E = modP(modP(x1y1 * x1y1) - A - B);
4221
+ const G = D + B;
4222
+ const F = G - C;
4223
+ const H = D - B;
4224
+ const X3 = modP(E * F);
4225
+ const Y3 = modP(G * H);
4226
+ const T3 = modP(E * H);
4227
+ const Z3 = modP(F * G);
4228
+ return new Point(X3, Y3, Z3, T3);
4229
+ }
4230
+ // Fast algo for adding 2 Extended Points.
4231
+ // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
4232
+ // Cost: 9M + 1*a + 1*d + 7add.
4233
+ add(other) {
4234
+ aextpoint(other);
4235
+ const { a, d } = CURVE;
4236
+ const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
4237
+ const { X: X2, Y: Y2, Z: Z2, T: T2 } = other;
4238
+ const A = modP(X1 * X2);
4239
+ const B = modP(Y1 * Y2);
4240
+ const C = modP(T1 * d * T2);
4241
+ const D = modP(Z1 * Z2);
4242
+ const E = modP((X1 + Y1) * (X2 + Y2) - A - B);
4243
+ const F = D - C;
4244
+ const G = D + C;
4245
+ const H = modP(B - a * A);
4246
+ const X3 = modP(E * F);
4247
+ const Y3 = modP(G * H);
4248
+ const T3 = modP(E * H);
4249
+ const Z3 = modP(F * G);
4250
+ return new Point(X3, Y3, Z3, T3);
4251
+ }
4252
+ subtract(other) {
4253
+ return this.add(other.negate());
4254
+ }
4255
+ // Constant-time multiplication.
4256
+ multiply(scalar) {
4257
+ if (!Fn2.isValidNot0(scalar))
4258
+ throw new Error("invalid scalar: expected 1 <= sc < curve.n");
4259
+ const { p, f } = wnaf.cached(this, scalar, (p2) => normalizeZ(Point, p2));
4260
+ return normalizeZ(Point, [p, f])[0];
4261
+ }
4262
+ // Non-constant-time multiplication. Uses double-and-add algorithm.
4263
+ // It's faster, but should only be used when you don't care about
4264
+ // an exposed private key e.g. sig verification.
4265
+ // Does NOT allow scalars higher than CURVE.n.
4266
+ // Accepts optional accumulator to merge with multiply (important for sparse scalars)
4267
+ multiplyUnsafe(scalar, acc = Point.ZERO) {
4268
+ if (!Fn2.isValid(scalar))
4269
+ throw new Error("invalid scalar: expected 0 <= sc < curve.n");
4270
+ if (scalar === _0n4)
4271
+ return Point.ZERO;
4272
+ if (this.is0() || scalar === _1n4)
4273
+ return this;
4274
+ return wnaf.unsafe(this, scalar, (p) => normalizeZ(Point, p), acc);
4275
+ }
4276
+ // Checks if point is of small order.
4277
+ // If you add something to small order point, you will have "dirty"
4278
+ // point with torsion component.
4279
+ // Multiplies point by cofactor and checks if the result is 0.
4280
+ isSmallOrder() {
4281
+ return this.multiplyUnsafe(cofactor).is0();
4282
+ }
4283
+ // Multiplies point by curve order and checks if the result is 0.
4284
+ // Returns `false` is the point is dirty.
4285
+ isTorsionFree() {
4286
+ return wnaf.unsafe(this, CURVE.n).is0();
4287
+ }
4288
+ // Converts Extended point to default (x, y) coordinates.
4289
+ // Can accept precomputed Z^-1 - for example, from invertBatch.
4290
+ toAffine(invertedZ) {
4291
+ return toAffineMemo(this, invertedZ);
4292
+ }
4293
+ clearCofactor() {
4294
+ if (cofactor === _1n4)
4295
+ return this;
4296
+ return this.multiplyUnsafe(cofactor);
4297
+ }
4298
+ toBytes() {
4299
+ const { x, y } = this.toAffine();
4300
+ const bytes = Fp2.toBytes(y);
4301
+ bytes[bytes.length - 1] |= x & _1n4 ? 128 : 0;
4302
+ return bytes;
4303
+ }
4304
+ toHex() {
4305
+ return bytesToHex(this.toBytes());
4306
+ }
4307
+ toString() {
4308
+ return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
4309
+ }
4310
+ // TODO: remove
4311
+ get ex() {
4312
+ return this.X;
4313
+ }
4314
+ get ey() {
4315
+ return this.Y;
4316
+ }
4317
+ get ez() {
4318
+ return this.Z;
4319
+ }
4320
+ get et() {
4321
+ return this.T;
4322
+ }
4323
+ static normalizeZ(points) {
4324
+ return normalizeZ(Point, points);
4325
+ }
4326
+ static msm(points, scalars) {
4327
+ return pippenger(Point, Fn2, points, scalars);
4328
+ }
4329
+ _setWindowSize(windowSize) {
4330
+ this.precompute(windowSize);
4331
+ }
4332
+ toRawBytes() {
4333
+ return this.toBytes();
4334
+ }
4335
+ }
4336
+ Point.BASE = new Point(CURVE.Gx, CURVE.Gy, _1n4, modP(CURVE.Gx * CURVE.Gy));
4337
+ Point.ZERO = new Point(_0n4, _1n4, _1n4, _0n4);
4338
+ Point.Fp = Fp2;
4339
+ Point.Fn = Fn2;
4340
+ const wnaf = new wNAF(Point, Fn2.BITS);
4341
+ Point.BASE.precompute(8);
4342
+ return Point;
4343
+ }
4344
+ function eddsa(Point, cHash, eddsaOpts = {}) {
4345
+ if (typeof cHash !== "function")
4346
+ throw new Error('"hash" function param is required');
4347
+ _validateObject(eddsaOpts, {}, {
4348
+ adjustScalarBytes: "function",
4349
+ randomBytes: "function",
4350
+ domain: "function",
4351
+ prehash: "function",
4352
+ mapToCurve: "function"
4353
+ });
4354
+ const { prehash } = eddsaOpts;
4355
+ const { BASE, Fp: Fp2, Fn: Fn2 } = Point;
4356
+ const randomBytes4 = eddsaOpts.randomBytes || randomBytes;
4357
+ const adjustScalarBytes2 = eddsaOpts.adjustScalarBytes || ((bytes) => bytes);
4358
+ const domain = eddsaOpts.domain || ((data, ctx, phflag) => {
4359
+ _abool2(phflag, "phflag");
4360
+ if (ctx.length || phflag)
4361
+ throw new Error("Contexts/pre-hash are not supported");
4362
+ return data;
4363
+ });
4364
+ function modN_LE(hash) {
4365
+ return Fn2.create(bytesToNumberLE(hash));
4366
+ }
4367
+ function getPrivateScalar(key) {
4368
+ const len = lengths.secretKey;
4369
+ key = ensureBytes("private key", key, len);
4370
+ const hashed = ensureBytes("hashed private key", cHash(key), 2 * len);
4371
+ const head = adjustScalarBytes2(hashed.slice(0, len));
4372
+ const prefix = hashed.slice(len, 2 * len);
4373
+ const scalar = modN_LE(head);
4374
+ return { head, prefix, scalar };
4375
+ }
4376
+ function getExtendedPublicKey(secretKey) {
4377
+ const { head, prefix, scalar } = getPrivateScalar(secretKey);
4378
+ const point = BASE.multiply(scalar);
4379
+ const pointBytes = point.toBytes();
4380
+ return { head, prefix, scalar, point, pointBytes };
4381
+ }
4382
+ function getPublicKey(secretKey) {
4383
+ return getExtendedPublicKey(secretKey).pointBytes;
4384
+ }
4385
+ function hashDomainToScalar(context = Uint8Array.of(), ...msgs) {
4386
+ const msg = concatBytes(...msgs);
4387
+ return modN_LE(cHash(domain(msg, ensureBytes("context", context), !!prehash)));
4388
+ }
4389
+ function sign(msg, secretKey, options = {}) {
4390
+ msg = ensureBytes("message", msg);
4391
+ if (prehash)
4392
+ msg = prehash(msg);
4393
+ const { prefix, scalar, pointBytes } = getExtendedPublicKey(secretKey);
4394
+ const r = hashDomainToScalar(options.context, prefix, msg);
4395
+ const R = BASE.multiply(r).toBytes();
4396
+ const k = hashDomainToScalar(options.context, R, pointBytes, msg);
4397
+ const s = Fn2.create(r + k * scalar);
4398
+ if (!Fn2.isValid(s))
4399
+ throw new Error("sign failed: invalid s");
4400
+ const rs = concatBytes(R, Fn2.toBytes(s));
4401
+ return _abytes2(rs, lengths.signature, "result");
4402
+ }
4403
+ const verifyOpts = { zip215: true };
4404
+ function verify(sig, msg, publicKey, options = verifyOpts) {
4405
+ const { context, zip215 } = options;
4406
+ const len = lengths.signature;
4407
+ sig = ensureBytes("signature", sig, len);
4408
+ msg = ensureBytes("message", msg);
4409
+ publicKey = ensureBytes("publicKey", publicKey, lengths.publicKey);
4410
+ if (zip215 !== void 0)
4411
+ _abool2(zip215, "zip215");
4412
+ if (prehash)
4413
+ msg = prehash(msg);
4414
+ const mid = len / 2;
4415
+ const r = sig.subarray(0, mid);
4416
+ const s = bytesToNumberLE(sig.subarray(mid, len));
4417
+ let A, R, SB;
4418
+ try {
4419
+ A = Point.fromBytes(publicKey, zip215);
4420
+ R = Point.fromBytes(r, zip215);
4421
+ SB = BASE.multiplyUnsafe(s);
4422
+ } catch (error) {
4423
+ return false;
4424
+ }
4425
+ if (!zip215 && A.isSmallOrder())
4426
+ return false;
4427
+ const k = hashDomainToScalar(context, R.toBytes(), A.toBytes(), msg);
4428
+ const RkA = R.add(A.multiplyUnsafe(k));
4429
+ return RkA.subtract(SB).clearCofactor().is0();
4430
+ }
4431
+ const _size = Fp2.BYTES;
4432
+ const lengths = {
4433
+ secretKey: _size,
4434
+ publicKey: _size,
4435
+ signature: 2 * _size,
4436
+ seed: _size
4437
+ };
4438
+ function randomSecretKey(seed = randomBytes4(lengths.seed)) {
4439
+ return _abytes2(seed, lengths.seed, "seed");
4440
+ }
4441
+ function keygen(seed) {
4442
+ const secretKey = utils.randomSecretKey(seed);
4443
+ return { secretKey, publicKey: getPublicKey(secretKey) };
4444
+ }
4445
+ function isValidSecretKey(key) {
4446
+ return isBytes(key) && key.length === Fn2.BYTES;
4447
+ }
4448
+ function isValidPublicKey(key, zip215) {
4449
+ try {
4450
+ return !!Point.fromBytes(key, zip215);
4451
+ } catch (error) {
4452
+ return false;
4453
+ }
4454
+ }
4455
+ const utils = {
4456
+ getExtendedPublicKey,
4457
+ randomSecretKey,
4458
+ isValidSecretKey,
4459
+ isValidPublicKey,
4460
+ /**
4461
+ * Converts ed public key to x public key. Uses formula:
4462
+ * - ed25519:
4463
+ * - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
4464
+ * - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
4465
+ * - ed448:
4466
+ * - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
4467
+ * - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
4468
+ */
4469
+ toMontgomery(publicKey) {
4470
+ const { y } = Point.fromBytes(publicKey);
4471
+ const size = lengths.publicKey;
4472
+ const is25519 = size === 32;
4473
+ if (!is25519 && size !== 57)
4474
+ throw new Error("only defined for 25519 and 448");
4475
+ const u = is25519 ? Fp2.div(_1n4 + y, _1n4 - y) : Fp2.div(y - _1n4, y + _1n4);
4476
+ return Fp2.toBytes(u);
4477
+ },
4478
+ toMontgomerySecret(secretKey) {
4479
+ const size = lengths.secretKey;
4480
+ _abytes2(secretKey, size);
4481
+ const hashed = cHash(secretKey.subarray(0, size));
4482
+ return adjustScalarBytes2(hashed).subarray(0, size);
4483
+ },
4484
+ /** @deprecated */
4485
+ randomPrivateKey: randomSecretKey,
4486
+ /** @deprecated */
4487
+ precompute(windowSize = 8, point = Point.BASE) {
4488
+ return point.precompute(windowSize, false);
4489
+ }
4490
+ };
4491
+ return Object.freeze({
4492
+ keygen,
4493
+ getPublicKey,
4494
+ sign,
4495
+ verify,
4496
+ utils,
4497
+ Point,
4498
+ lengths
4499
+ });
4500
+ }
4501
+ function _eddsa_legacy_opts_to_new(c) {
4502
+ const CURVE = {
4503
+ a: c.a,
4504
+ d: c.d,
4505
+ p: c.Fp.ORDER,
4506
+ n: c.n,
4507
+ h: c.h,
4508
+ Gx: c.Gx,
4509
+ Gy: c.Gy
4510
+ };
4511
+ const Fp2 = c.Fp;
4512
+ const Fn2 = Field(CURVE.n, c.nBitLength, true);
4513
+ const curveOpts = { Fp: Fp2, Fn: Fn2, uvRatio: c.uvRatio };
4514
+ const eddsaOpts = {
4515
+ randomBytes: c.randomBytes,
4516
+ adjustScalarBytes: c.adjustScalarBytes,
4517
+ domain: c.domain,
4518
+ prehash: c.prehash,
4519
+ mapToCurve: c.mapToCurve
4520
+ };
4521
+ return { CURVE, curveOpts, hash: c.hash, eddsaOpts };
4522
+ }
4523
+ function _eddsa_new_output_to_legacy(c, eddsa2) {
4524
+ const Point = eddsa2.Point;
4525
+ const legacy = Object.assign({}, eddsa2, {
4526
+ ExtendedPoint: Point,
4527
+ CURVE: c,
4528
+ nBitLength: Point.Fn.BITS,
4529
+ nByteLength: Point.Fn.BYTES
4530
+ });
4531
+ return legacy;
4532
+ }
4533
+ function twistedEdwards(c) {
4534
+ const { CURVE, curveOpts, hash, eddsaOpts } = _eddsa_legacy_opts_to_new(c);
4535
+ const Point = edwards(CURVE, curveOpts);
4536
+ const EDDSA = eddsa(Point, hash, eddsaOpts);
4537
+ return _eddsa_new_output_to_legacy(c, EDDSA);
4538
+ }
4539
+ var _0n4, _1n4, _2n2, _8n2, PrimeEdwardsPoint;
4540
+ var init_edwards = __esm({
4541
+ "../../node_modules/@noble/curves/esm/abstract/edwards.js"() {
4542
+ "use strict";
4543
+ init_utils2();
4544
+ init_curve();
4545
+ init_modular();
4546
+ _0n4 = BigInt(0);
4547
+ _1n4 = BigInt(1);
4548
+ _2n2 = BigInt(2);
4549
+ _8n2 = BigInt(8);
4550
+ PrimeEdwardsPoint = class {
4551
+ constructor(ep) {
4552
+ this.ep = ep;
4553
+ }
4554
+ // Static methods that must be implemented by subclasses
4555
+ static fromBytes(_bytes) {
4556
+ notImplemented();
4557
+ }
4558
+ static fromHex(_hex) {
4559
+ notImplemented();
4560
+ }
4561
+ get x() {
4562
+ return this.toAffine().x;
4563
+ }
4564
+ get y() {
4565
+ return this.toAffine().y;
4566
+ }
4567
+ // Common implementations
4568
+ clearCofactor() {
4569
+ return this;
4570
+ }
4571
+ assertValidity() {
4572
+ this.ep.assertValidity();
4573
+ }
4574
+ toAffine(invertedZ) {
4575
+ return this.ep.toAffine(invertedZ);
4576
+ }
4577
+ toHex() {
4578
+ return bytesToHex(this.toBytes());
4579
+ }
4580
+ toString() {
4581
+ return this.toHex();
4582
+ }
4583
+ isTorsionFree() {
4584
+ return true;
4585
+ }
4586
+ isSmallOrder() {
4587
+ return false;
4588
+ }
4589
+ add(other) {
4590
+ this.assertSame(other);
4591
+ return this.init(this.ep.add(other.ep));
4592
+ }
4593
+ subtract(other) {
4594
+ this.assertSame(other);
4595
+ return this.init(this.ep.subtract(other.ep));
4596
+ }
4597
+ multiply(scalar) {
4598
+ return this.init(this.ep.multiply(scalar));
4599
+ }
4600
+ multiplyUnsafe(scalar) {
4601
+ return this.init(this.ep.multiplyUnsafe(scalar));
4602
+ }
4603
+ double() {
4604
+ return this.init(this.ep.double());
4605
+ }
4606
+ negate() {
4607
+ return this.init(this.ep.negate());
4608
+ }
4609
+ precompute(windowSize, isLazy) {
4610
+ return this.init(this.ep.precompute(windowSize, isLazy));
4611
+ }
4612
+ /** @deprecated use `toBytes` */
4613
+ toRawBytes() {
4614
+ return this.toBytes();
4615
+ }
4616
+ };
4617
+ }
4618
+ });
4619
+
4620
+ // ../../node_modules/@noble/curves/esm/abstract/montgomery.js
4621
+ function validateOpts(curve) {
4622
+ _validateObject(curve, {
4623
+ adjustScalarBytes: "function",
4624
+ powPminus2: "function"
4625
+ });
4626
+ return Object.freeze({ ...curve });
4627
+ }
4628
+ function montgomery(curveDef) {
4629
+ const CURVE = validateOpts(curveDef);
4630
+ const { P, type, adjustScalarBytes: adjustScalarBytes2, powPminus2, randomBytes: rand } = CURVE;
4631
+ const is25519 = type === "x25519";
4632
+ if (!is25519 && type !== "x448")
4633
+ throw new Error("invalid type");
4634
+ const randomBytes_ = rand || randomBytes;
4635
+ const montgomeryBits = is25519 ? 255 : 448;
4636
+ const fieldLen = is25519 ? 32 : 56;
4637
+ const Gu = is25519 ? BigInt(9) : BigInt(5);
4638
+ const a24 = is25519 ? BigInt(121665) : BigInt(39081);
4639
+ const minScalar = is25519 ? _2n3 ** BigInt(254) : _2n3 ** BigInt(447);
4640
+ const maxAdded = is25519 ? BigInt(8) * _2n3 ** BigInt(251) - _1n5 : BigInt(4) * _2n3 ** BigInt(445) - _1n5;
4641
+ const maxScalar = minScalar + maxAdded + _1n5;
4642
+ const modP = (n) => mod(n, P);
4643
+ const GuBytes = encodeU(Gu);
4644
+ function encodeU(u) {
4645
+ return numberToBytesLE(modP(u), fieldLen);
4646
+ }
4647
+ function decodeU(u) {
4648
+ const _u = ensureBytes("u coordinate", u, fieldLen);
4649
+ if (is25519)
4650
+ _u[31] &= 127;
4651
+ return modP(bytesToNumberLE(_u));
4652
+ }
4653
+ function decodeScalar(scalar) {
4654
+ return bytesToNumberLE(adjustScalarBytes2(ensureBytes("scalar", scalar, fieldLen)));
4655
+ }
4656
+ function scalarMult(scalar, u) {
4657
+ const pu = montgomeryLadder(decodeU(u), decodeScalar(scalar));
4658
+ if (pu === _0n5)
4659
+ throw new Error("invalid private or public key received");
4660
+ return encodeU(pu);
4661
+ }
4662
+ function scalarMultBase(scalar) {
4663
+ return scalarMult(scalar, GuBytes);
4664
+ }
4665
+ function cswap(swap, x_2, x_3) {
4666
+ const dummy = modP(swap * (x_2 - x_3));
4667
+ x_2 = modP(x_2 - dummy);
4668
+ x_3 = modP(x_3 + dummy);
4669
+ return { x_2, x_3 };
4670
+ }
4671
+ function montgomeryLadder(u, scalar) {
4672
+ aInRange("u", u, _0n5, P);
4673
+ aInRange("scalar", scalar, minScalar, maxScalar);
4674
+ const k = scalar;
4675
+ const x_1 = u;
4676
+ let x_2 = _1n5;
4677
+ let z_2 = _0n5;
4678
+ let x_3 = u;
4679
+ let z_3 = _1n5;
4680
+ let swap = _0n5;
4681
+ for (let t = BigInt(montgomeryBits - 1); t >= _0n5; t--) {
4682
+ const k_t = k >> t & _1n5;
4683
+ swap ^= k_t;
4684
+ ({ x_2, x_3 } = cswap(swap, x_2, x_3));
4685
+ ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
4686
+ swap = k_t;
4687
+ const A = x_2 + z_2;
4688
+ const AA = modP(A * A);
4689
+ const B = x_2 - z_2;
4690
+ const BB = modP(B * B);
4691
+ const E = AA - BB;
4692
+ const C = x_3 + z_3;
4693
+ const D = x_3 - z_3;
4694
+ const DA = modP(D * A);
4695
+ const CB = modP(C * B);
4696
+ const dacb = DA + CB;
4697
+ const da_cb = DA - CB;
4698
+ x_3 = modP(dacb * dacb);
4699
+ z_3 = modP(x_1 * modP(da_cb * da_cb));
4700
+ x_2 = modP(AA * BB);
4701
+ z_2 = modP(E * (AA + modP(a24 * E)));
4702
+ }
4703
+ ({ x_2, x_3 } = cswap(swap, x_2, x_3));
4704
+ ({ x_2: z_2, x_3: z_3 } = cswap(swap, z_2, z_3));
4705
+ const z2 = powPminus2(z_2);
4706
+ return modP(x_2 * z2);
4707
+ }
4708
+ const lengths = {
4709
+ secretKey: fieldLen,
4710
+ publicKey: fieldLen,
4711
+ seed: fieldLen
4712
+ };
4713
+ const randomSecretKey = (seed = randomBytes_(fieldLen)) => {
4714
+ abytes(seed, lengths.seed);
4715
+ return seed;
4716
+ };
4717
+ function keygen(seed) {
4718
+ const secretKey = randomSecretKey(seed);
4719
+ return { secretKey, publicKey: scalarMultBase(secretKey) };
4720
+ }
4721
+ const utils = {
4722
+ randomSecretKey,
4723
+ randomPrivateKey: randomSecretKey
4724
+ };
4725
+ return {
4726
+ keygen,
4727
+ getSharedSecret: (secretKey, publicKey) => scalarMult(secretKey, publicKey),
4728
+ getPublicKey: (secretKey) => scalarMultBase(secretKey),
4729
+ scalarMult,
4730
+ scalarMultBase,
4731
+ utils,
4732
+ GuBytes: GuBytes.slice(),
4733
+ lengths
4734
+ };
4735
+ }
4736
+ var _0n5, _1n5, _2n3;
4737
+ var init_montgomery = __esm({
4738
+ "../../node_modules/@noble/curves/esm/abstract/montgomery.js"() {
4739
+ "use strict";
4740
+ init_utils2();
4741
+ init_modular();
4742
+ _0n5 = BigInt(0);
4743
+ _1n5 = BigInt(1);
4744
+ _2n3 = BigInt(2);
4745
+ }
4746
+ });
4747
+
4748
+ // ../../node_modules/@noble/curves/esm/ed25519.js
4749
+ function ed25519_pow_2_252_3(x) {
4750
+ const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
4751
+ const P = ed25519_CURVE_p;
4752
+ const x2 = x * x % P;
4753
+ const b2 = x2 * x % P;
4754
+ const b4 = pow2(b2, _2n4, P) * b2 % P;
4755
+ const b5 = pow2(b4, _1n6, P) * x % P;
4756
+ const b10 = pow2(b5, _5n2, P) * b5 % P;
4757
+ const b20 = pow2(b10, _10n, P) * b10 % P;
4758
+ const b40 = pow2(b20, _20n, P) * b20 % P;
4759
+ const b80 = pow2(b40, _40n, P) * b40 % P;
4760
+ const b160 = pow2(b80, _80n, P) * b80 % P;
4761
+ const b240 = pow2(b160, _80n, P) * b80 % P;
4762
+ const b250 = pow2(b240, _10n, P) * b10 % P;
4763
+ const pow_p_5_8 = pow2(b250, _2n4, P) * x % P;
4764
+ return { pow_p_5_8, b2 };
4765
+ }
4766
+ function adjustScalarBytes(bytes) {
4767
+ bytes[0] &= 248;
4768
+ bytes[31] &= 127;
4769
+ bytes[31] |= 64;
4770
+ return bytes;
4771
+ }
4772
+ function uvRatio(u, v) {
4773
+ const P = ed25519_CURVE_p;
4774
+ const v3 = mod(v * v * v, P);
4775
+ const v7 = mod(v3 * v3 * v, P);
4776
+ const pow = ed25519_pow_2_252_3(u * v7).pow_p_5_8;
4777
+ let x = mod(u * v3 * pow, P);
4778
+ const vx2 = mod(v * x * x, P);
4779
+ const root1 = x;
4780
+ const root2 = mod(x * ED25519_SQRT_M1, P);
4781
+ const useRoot1 = vx2 === u;
4782
+ const useRoot2 = vx2 === mod(-u, P);
4783
+ const noRoot = vx2 === mod(-u * ED25519_SQRT_M1, P);
4784
+ if (useRoot1)
4785
+ x = root1;
4786
+ if (useRoot2 || noRoot)
4787
+ x = root2;
4788
+ if (isNegativeLE(x, P))
4789
+ x = mod(-x, P);
4790
+ return { isValid: useRoot1 || useRoot2, value: x };
4791
+ }
4792
+ function calcElligatorRistrettoMap(r0) {
4793
+ const { d } = ed25519_CURVE;
4794
+ const P = ed25519_CURVE_p;
4795
+ const mod2 = (n) => Fp.create(n);
4796
+ const r = mod2(SQRT_M1 * r0 * r0);
4797
+ const Ns = mod2((r + _1n6) * ONE_MINUS_D_SQ);
4798
+ let c = BigInt(-1);
4799
+ const D = mod2((c - d * r) * mod2(r + d));
4800
+ let { isValid: Ns_D_is_sq, value: s } = uvRatio(Ns, D);
4801
+ let s_ = mod2(s * r0);
4802
+ if (!isNegativeLE(s_, P))
4803
+ s_ = mod2(-s_);
4804
+ if (!Ns_D_is_sq)
4805
+ s = s_;
4806
+ if (!Ns_D_is_sq)
4807
+ c = r;
4808
+ const Nt = mod2(c * (r - _1n6) * D_MINUS_ONE_SQ - D);
4809
+ const s2 = s * s;
4810
+ const W0 = mod2((s + s) * D);
4811
+ const W1 = mod2(Nt * SQRT_AD_MINUS_ONE);
4812
+ const W2 = mod2(_1n6 - s2);
4813
+ const W3 = mod2(_1n6 + s2);
4814
+ return new ed25519.Point(mod2(W0 * W3), mod2(W2 * W1), mod2(W1 * W3), mod2(W0 * W2));
4815
+ }
4816
+ function ristretto255_map(bytes) {
4817
+ abytes(bytes, 64);
4818
+ const r1 = bytes255ToNumberLE(bytes.subarray(0, 32));
4819
+ const R1 = calcElligatorRistrettoMap(r1);
4820
+ const r2 = bytes255ToNumberLE(bytes.subarray(32, 64));
4821
+ const R2 = calcElligatorRistrettoMap(r2);
4822
+ return new _RistrettoPoint(R1.add(R2));
4823
+ }
4824
+ var _0n6, _1n6, _2n4, _3n2, _5n2, _8n3, ed25519_CURVE_p, ed25519_CURVE, ED25519_SQRT_M1, Fp, Fn, ed25519Defaults, ed25519, x25519, SQRT_M1, SQRT_AD_MINUS_ONE, INVSQRT_A_MINUS_D, ONE_MINUS_D_SQ, D_MINUS_ONE_SQ, invertSqrt, MAX_255B, bytes255ToNumberLE, _RistrettoPoint;
4825
+ var init_ed25519 = __esm({
4826
+ "../../node_modules/@noble/curves/esm/ed25519.js"() {
4827
+ "use strict";
4828
+ init_sha2();
4829
+ init_utils();
4830
+ init_curve();
4831
+ init_edwards();
4832
+ init_modular();
4833
+ init_montgomery();
4834
+ init_utils2();
4835
+ _0n6 = /* @__PURE__ */ BigInt(0);
4836
+ _1n6 = BigInt(1);
4837
+ _2n4 = BigInt(2);
4838
+ _3n2 = BigInt(3);
4839
+ _5n2 = BigInt(5);
4840
+ _8n3 = BigInt(8);
4841
+ ed25519_CURVE_p = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
4842
+ ed25519_CURVE = /* @__PURE__ */ (() => ({
4843
+ p: ed25519_CURVE_p,
4844
+ n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
4845
+ h: _8n3,
4846
+ a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
4847
+ d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
4848
+ Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
4849
+ Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
4850
+ }))();
4851
+ ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
4852
+ Fp = /* @__PURE__ */ (() => Field(ed25519_CURVE.p, { isLE: true }))();
4853
+ Fn = /* @__PURE__ */ (() => Field(ed25519_CURVE.n, { isLE: true }))();
4854
+ ed25519Defaults = /* @__PURE__ */ (() => ({
4855
+ ...ed25519_CURVE,
4856
+ Fp,
4857
+ hash: sha512,
4858
+ adjustScalarBytes,
4859
+ // dom2
4860
+ // Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
4861
+ // Constant-time, u/√v
4862
+ uvRatio
4863
+ }))();
4864
+ ed25519 = /* @__PURE__ */ (() => twistedEdwards(ed25519Defaults))();
4865
+ x25519 = /* @__PURE__ */ (() => {
4866
+ const P = Fp.ORDER;
4867
+ return montgomery({
4868
+ P,
4869
+ type: "x25519",
4870
+ powPminus2: (x) => {
4871
+ const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x);
4872
+ return mod(pow2(pow_p_5_8, _3n2, P) * b2, P);
4873
+ },
4874
+ adjustScalarBytes
4875
+ });
4876
+ })();
4877
+ SQRT_M1 = ED25519_SQRT_M1;
4878
+ SQRT_AD_MINUS_ONE = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");
4879
+ INVSQRT_A_MINUS_D = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");
4880
+ ONE_MINUS_D_SQ = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");
4881
+ D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");
4882
+ invertSqrt = (number) => uvRatio(_1n6, number);
4883
+ MAX_255B = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
4884
+ bytes255ToNumberLE = (bytes) => ed25519.Point.Fp.create(bytesToNumberLE(bytes) & MAX_255B);
4885
+ _RistrettoPoint = class __RistrettoPoint extends PrimeEdwardsPoint {
4886
+ constructor(ep) {
4887
+ super(ep);
4888
+ }
4889
+ static fromAffine(ap) {
4890
+ return new __RistrettoPoint(ed25519.Point.fromAffine(ap));
4891
+ }
4892
+ assertSame(other) {
4893
+ if (!(other instanceof __RistrettoPoint))
4894
+ throw new Error("RistrettoPoint expected");
4895
+ }
4896
+ init(ep) {
4897
+ return new __RistrettoPoint(ep);
4898
+ }
4899
+ /** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
4900
+ static hashToCurve(hex) {
4901
+ return ristretto255_map(ensureBytes("ristrettoHash", hex, 64));
4902
+ }
4903
+ static fromBytes(bytes) {
4904
+ abytes(bytes, 32);
4905
+ const { a, d } = ed25519_CURVE;
4906
+ const P = ed25519_CURVE_p;
4907
+ const mod2 = (n) => Fp.create(n);
4908
+ const s = bytes255ToNumberLE(bytes);
4909
+ if (!equalBytes(Fp.toBytes(s), bytes) || isNegativeLE(s, P))
4910
+ throw new Error("invalid ristretto255 encoding 1");
4911
+ const s2 = mod2(s * s);
4912
+ const u1 = mod2(_1n6 + a * s2);
4913
+ const u2 = mod2(_1n6 - a * s2);
4914
+ const u1_2 = mod2(u1 * u1);
4915
+ const u2_2 = mod2(u2 * u2);
4916
+ const v = mod2(a * d * u1_2 - u2_2);
4917
+ const { isValid, value: I } = invertSqrt(mod2(v * u2_2));
4918
+ const Dx = mod2(I * u2);
4919
+ const Dy = mod2(I * Dx * v);
4920
+ let x = mod2((s + s) * Dx);
4921
+ if (isNegativeLE(x, P))
4922
+ x = mod2(-x);
4923
+ const y = mod2(u1 * Dy);
4924
+ const t = mod2(x * y);
4925
+ if (!isValid || isNegativeLE(t, P) || y === _0n6)
4926
+ throw new Error("invalid ristretto255 encoding 2");
4927
+ return new __RistrettoPoint(new ed25519.Point(x, y, _1n6, t));
4928
+ }
4929
+ /**
4930
+ * Converts ristretto-encoded string to ristretto point.
4931
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
4932
+ * @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
4933
+ */
4934
+ static fromHex(hex) {
4935
+ return __RistrettoPoint.fromBytes(ensureBytes("ristrettoHex", hex, 32));
4936
+ }
4937
+ static msm(points, scalars) {
4938
+ return pippenger(__RistrettoPoint, ed25519.Point.Fn, points, scalars);
4939
+ }
4940
+ /**
4941
+ * Encodes ristretto point to Uint8Array.
4942
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
4943
+ */
4944
+ toBytes() {
4945
+ let { X, Y, Z, T } = this.ep;
4946
+ const P = ed25519_CURVE_p;
4947
+ const mod2 = (n) => Fp.create(n);
4948
+ const u1 = mod2(mod2(Z + Y) * mod2(Z - Y));
4949
+ const u2 = mod2(X * Y);
4950
+ const u2sq = mod2(u2 * u2);
4951
+ const { value: invsqrt } = invertSqrt(mod2(u1 * u2sq));
4952
+ const D1 = mod2(invsqrt * u1);
4953
+ const D2 = mod2(invsqrt * u2);
4954
+ const zInv = mod2(D1 * D2 * T);
4955
+ let D;
4956
+ if (isNegativeLE(T * zInv, P)) {
4957
+ let _x = mod2(Y * SQRT_M1);
4958
+ let _y = mod2(X * SQRT_M1);
4959
+ X = _x;
4960
+ Y = _y;
4961
+ D = mod2(D1 * INVSQRT_A_MINUS_D);
4962
+ } else {
4963
+ D = D2;
4964
+ }
4965
+ if (isNegativeLE(X * zInv, P))
4966
+ Y = mod2(-Y);
4967
+ let s = mod2((Z - Y) * D);
4968
+ if (isNegativeLE(s, P))
4969
+ s = mod2(-s);
4970
+ return Fp.toBytes(s);
4971
+ }
4972
+ /**
4973
+ * Compares two Ristretto points.
4974
+ * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
4975
+ */
4976
+ equals(other) {
4977
+ this.assertSame(other);
4978
+ const { X: X1, Y: Y1 } = this.ep;
4979
+ const { X: X2, Y: Y2 } = other.ep;
4980
+ const mod2 = (n) => Fp.create(n);
4981
+ const one = mod2(X1 * Y2) === mod2(Y1 * X2);
4982
+ const two = mod2(Y1 * Y2) === mod2(X1 * X2);
4983
+ return one || two;
4984
+ }
4985
+ is0() {
4986
+ return this.equals(__RistrettoPoint.ZERO);
4987
+ }
4988
+ };
4989
+ _RistrettoPoint.BASE = /* @__PURE__ */ (() => new _RistrettoPoint(ed25519.Point.BASE))();
4990
+ _RistrettoPoint.ZERO = /* @__PURE__ */ (() => new _RistrettoPoint(ed25519.Point.ZERO))();
4991
+ _RistrettoPoint.Fp = /* @__PURE__ */ (() => Fp)();
4992
+ _RistrettoPoint.Fn = /* @__PURE__ */ (() => Fn)();
4993
+ }
4994
+ });
4995
+
4996
+ // ../../node_modules/@noble/ciphers/esm/utils.js
4997
+ function isBytes2(a) {
4998
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
4999
+ }
5000
+ function abool(b) {
5001
+ if (typeof b !== "boolean")
5002
+ throw new Error(`boolean expected, not ${b}`);
5003
+ }
5004
+ function anumber2(n) {
5005
+ if (!Number.isSafeInteger(n) || n < 0)
5006
+ throw new Error("positive integer expected, got " + n);
5007
+ }
5008
+ function abytes2(b, ...lengths) {
5009
+ if (!isBytes2(b))
5010
+ throw new Error("Uint8Array expected");
5011
+ if (lengths.length > 0 && !lengths.includes(b.length))
5012
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
5013
+ }
5014
+ function aexists2(instance, checkFinished = true) {
5015
+ if (instance.destroyed)
5016
+ throw new Error("Hash instance has been destroyed");
5017
+ if (checkFinished && instance.finished)
5018
+ throw new Error("Hash#digest() has already been called");
5019
+ }
5020
+ function aoutput2(out, instance) {
5021
+ abytes2(out);
5022
+ const min = instance.outputLen;
5023
+ if (out.length < min) {
5024
+ throw new Error("digestInto() expects output buffer of length at least " + min);
5025
+ }
5026
+ }
5027
+ function u32(arr) {
5028
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
5029
+ }
5030
+ function clean2(...arrays) {
5031
+ for (let i = 0; i < arrays.length; i++) {
5032
+ arrays[i].fill(0);
5033
+ }
5034
+ }
5035
+ function createView2(arr) {
5036
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
5037
+ }
5038
+ function utf8ToBytes2(str) {
5039
+ if (typeof str !== "string")
5040
+ throw new Error("string expected");
5041
+ return new Uint8Array(new TextEncoder().encode(str));
5042
+ }
5043
+ function toBytes2(data) {
5044
+ if (typeof data === "string")
5045
+ data = utf8ToBytes2(data);
5046
+ else if (isBytes2(data))
5047
+ data = copyBytes2(data);
5048
+ else
5049
+ throw new Error("Uint8Array expected, got " + typeof data);
5050
+ return data;
5051
+ }
5052
+ function checkOpts(defaults, opts) {
5053
+ if (opts == null || typeof opts !== "object")
5054
+ throw new Error("options must be defined");
5055
+ const merged = Object.assign(defaults, opts);
5056
+ return merged;
5057
+ }
5058
+ function equalBytes2(a, b) {
5059
+ if (a.length !== b.length)
5060
+ return false;
5061
+ let diff = 0;
5062
+ for (let i = 0; i < a.length; i++)
5063
+ diff |= a[i] ^ b[i];
5064
+ return diff === 0;
5065
+ }
5066
+ function getOutput(expectedLength, out, onlyAligned = true) {
5067
+ if (out === void 0)
5068
+ return new Uint8Array(expectedLength);
5069
+ if (out.length !== expectedLength)
5070
+ throw new Error("invalid output length, expected " + expectedLength + ", got: " + out.length);
5071
+ if (onlyAligned && !isAligned32(out))
5072
+ throw new Error("invalid output, must be aligned");
5073
+ return out;
5074
+ }
5075
+ function setBigUint642(view, byteOffset, value, isLE2) {
5076
+ if (typeof view.setBigUint64 === "function")
5077
+ return view.setBigUint64(byteOffset, value, isLE2);
5078
+ const _32n2 = BigInt(32);
5079
+ const _u32_max = BigInt(4294967295);
5080
+ const wh = Number(value >> _32n2 & _u32_max);
5081
+ const wl = Number(value & _u32_max);
5082
+ const h = isLE2 ? 4 : 0;
5083
+ const l = isLE2 ? 0 : 4;
5084
+ view.setUint32(byteOffset + h, wh, isLE2);
5085
+ view.setUint32(byteOffset + l, wl, isLE2);
5086
+ }
5087
+ function u64Lengths(dataLength, aadLength, isLE2) {
5088
+ abool(isLE2);
5089
+ const num = new Uint8Array(16);
5090
+ const view = createView2(num);
5091
+ setBigUint642(view, 0, BigInt(aadLength), isLE2);
5092
+ setBigUint642(view, 8, BigInt(dataLength), isLE2);
5093
+ return num;
5094
+ }
5095
+ function isAligned32(bytes) {
5096
+ return bytes.byteOffset % 4 === 0;
5097
+ }
5098
+ function copyBytes2(bytes) {
5099
+ return Uint8Array.from(bytes);
5100
+ }
5101
+ var isLE, wrapCipher;
5102
+ var init_utils3 = __esm({
5103
+ "../../node_modules/@noble/ciphers/esm/utils.js"() {
5104
+ "use strict";
5105
+ isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
5106
+ wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
5107
+ function wrappedCipher(key, ...args2) {
5108
+ abytes2(key);
5109
+ if (!isLE)
5110
+ throw new Error("Non little-endian hardware is not yet supported");
5111
+ if (params.nonceLength !== void 0) {
5112
+ const nonce = args2[0];
5113
+ if (!nonce)
5114
+ throw new Error("nonce / iv required");
5115
+ if (params.varSizeNonce)
5116
+ abytes2(nonce);
5117
+ else
5118
+ abytes2(nonce, params.nonceLength);
5119
+ }
5120
+ const tagl = params.tagLength;
5121
+ if (tagl && args2[1] !== void 0) {
5122
+ abytes2(args2[1]);
5123
+ }
5124
+ const cipher = constructor(key, ...args2);
5125
+ const checkOutput = (fnLength, output) => {
5126
+ if (output !== void 0) {
5127
+ if (fnLength !== 2)
5128
+ throw new Error("cipher output not supported");
5129
+ abytes2(output);
5130
+ }
5131
+ };
5132
+ let called = false;
5133
+ const wrCipher = {
5134
+ encrypt(data, output) {
5135
+ if (called)
5136
+ throw new Error("cannot encrypt() twice with same key + nonce");
5137
+ called = true;
5138
+ abytes2(data);
5139
+ checkOutput(cipher.encrypt.length, output);
5140
+ return cipher.encrypt(data, output);
5141
+ },
5142
+ decrypt(data, output) {
5143
+ abytes2(data);
5144
+ if (tagl && data.length < tagl)
5145
+ throw new Error("invalid ciphertext length: smaller than tagLength=" + tagl);
5146
+ checkOutput(cipher.decrypt.length, output);
5147
+ return cipher.decrypt(data, output);
5148
+ }
5149
+ };
5150
+ return wrCipher;
5151
+ }
5152
+ Object.assign(wrappedCipher, params);
5153
+ return wrappedCipher;
5154
+ };
5155
+ }
5156
+ });
5157
+
5158
+ // ../../node_modules/@noble/ciphers/esm/_arx.js
5159
+ function rotl(a, b) {
5160
+ return a << b | a >>> 32 - b;
5161
+ }
5162
+ function isAligned322(b) {
5163
+ return b.byteOffset % 4 === 0;
5164
+ }
5165
+ function runCipher(core, sigma, key, nonce, data, output, counter, rounds) {
5166
+ const len = data.length;
5167
+ const block = new Uint8Array(BLOCK_LEN);
5168
+ const b32 = u32(block);
5169
+ const isAligned = isAligned322(data) && isAligned322(output);
5170
+ const d32 = isAligned ? u32(data) : U32_EMPTY;
5171
+ const o32 = isAligned ? u32(output) : U32_EMPTY;
5172
+ for (let pos = 0; pos < len; counter++) {
5173
+ core(sigma, key, nonce, b32, counter, rounds);
5174
+ if (counter >= MAX_COUNTER)
5175
+ throw new Error("arx: counter overflow");
5176
+ const take = Math.min(BLOCK_LEN, len - pos);
5177
+ if (isAligned && take === BLOCK_LEN) {
5178
+ const pos32 = pos / 4;
5179
+ if (pos % 4 !== 0)
5180
+ throw new Error("arx: invalid block position");
5181
+ for (let j = 0, posj; j < BLOCK_LEN32; j++) {
5182
+ posj = pos32 + j;
5183
+ o32[posj] = d32[posj] ^ b32[j];
5184
+ }
5185
+ pos += BLOCK_LEN;
5186
+ continue;
5187
+ }
5188
+ for (let j = 0, posj; j < take; j++) {
5189
+ posj = pos + j;
5190
+ output[posj] = data[posj] ^ block[j];
5191
+ }
5192
+ pos += take;
5193
+ }
5194
+ }
5195
+ function createCipher(core, opts) {
5196
+ const { allowShortKeys, extendNonceFn, counterLength, counterRight, rounds } = checkOpts({ allowShortKeys: false, counterLength: 8, counterRight: false, rounds: 20 }, opts);
5197
+ if (typeof core !== "function")
5198
+ throw new Error("core must be a function");
5199
+ anumber2(counterLength);
5200
+ anumber2(rounds);
5201
+ abool(counterRight);
5202
+ abool(allowShortKeys);
5203
+ return (key, nonce, data, output, counter = 0) => {
5204
+ abytes2(key);
5205
+ abytes2(nonce);
5206
+ abytes2(data);
5207
+ const len = data.length;
5208
+ if (output === void 0)
5209
+ output = new Uint8Array(len);
5210
+ abytes2(output);
5211
+ anumber2(counter);
5212
+ if (counter < 0 || counter >= MAX_COUNTER)
5213
+ throw new Error("arx: counter overflow");
5214
+ if (output.length < len)
5215
+ throw new Error(`arx: output (${output.length}) is shorter than data (${len})`);
5216
+ const toClean = [];
5217
+ let l = key.length;
5218
+ let k;
5219
+ let sigma;
5220
+ if (l === 32) {
5221
+ toClean.push(k = copyBytes2(key));
5222
+ sigma = sigma32_32;
5223
+ } else if (l === 16 && allowShortKeys) {
5224
+ k = new Uint8Array(32);
5225
+ k.set(key);
5226
+ k.set(key, 16);
5227
+ sigma = sigma16_32;
5228
+ toClean.push(k);
5229
+ } else {
5230
+ throw new Error(`arx: invalid 32-byte key, got length=${l}`);
5231
+ }
5232
+ if (!isAligned322(nonce))
5233
+ toClean.push(nonce = copyBytes2(nonce));
5234
+ const k32 = u32(k);
5235
+ if (extendNonceFn) {
5236
+ if (nonce.length !== 24)
5237
+ throw new Error(`arx: extended nonce must be 24 bytes`);
5238
+ extendNonceFn(sigma, k32, u32(nonce.subarray(0, 16)), k32);
5239
+ nonce = nonce.subarray(16);
5240
+ }
5241
+ const nonceNcLen = 16 - counterLength;
5242
+ if (nonceNcLen !== nonce.length)
5243
+ throw new Error(`arx: nonce must be ${nonceNcLen} or 16 bytes`);
5244
+ if (nonceNcLen !== 12) {
5245
+ const nc2 = new Uint8Array(12);
5246
+ nc2.set(nonce, counterRight ? 0 : 12 - nonce.length);
5247
+ nonce = nc2;
5248
+ toClean.push(nonce);
5249
+ }
5250
+ const n32 = u32(nonce);
5251
+ runCipher(core, sigma, k32, n32, data, output, counter, rounds);
5252
+ clean2(...toClean);
5253
+ return output;
5254
+ };
5255
+ }
5256
+ var _utf8ToBytes, sigma16, sigma32, sigma16_32, sigma32_32, BLOCK_LEN, BLOCK_LEN32, MAX_COUNTER, U32_EMPTY;
5257
+ var init_arx = __esm({
5258
+ "../../node_modules/@noble/ciphers/esm/_arx.js"() {
5259
+ "use strict";
5260
+ init_utils3();
5261
+ _utf8ToBytes = (str) => Uint8Array.from(str.split("").map((c) => c.charCodeAt(0)));
5262
+ sigma16 = _utf8ToBytes("expand 16-byte k");
5263
+ sigma32 = _utf8ToBytes("expand 32-byte k");
5264
+ sigma16_32 = u32(sigma16);
5265
+ sigma32_32 = u32(sigma32);
5266
+ BLOCK_LEN = 64;
5267
+ BLOCK_LEN32 = 16;
5268
+ MAX_COUNTER = 2 ** 32 - 1;
5269
+ U32_EMPTY = new Uint32Array();
5270
+ }
5271
+ });
5272
+
5273
+ // ../../node_modules/@noble/ciphers/esm/_poly1305.js
5274
+ function wrapConstructorWithKey(hashCons) {
5275
+ const hashC = (msg, key) => hashCons(key).update(toBytes2(msg)).digest();
5276
+ const tmp = hashCons(new Uint8Array(32));
5277
+ hashC.outputLen = tmp.outputLen;
5278
+ hashC.blockLen = tmp.blockLen;
5279
+ hashC.create = (key) => hashCons(key);
5280
+ return hashC;
5281
+ }
5282
+ var u8to16, Poly1305, poly1305;
5283
+ var init_poly1305 = __esm({
5284
+ "../../node_modules/@noble/ciphers/esm/_poly1305.js"() {
5285
+ "use strict";
5286
+ init_utils3();
5287
+ u8to16 = (a, i) => a[i++] & 255 | (a[i++] & 255) << 8;
5288
+ Poly1305 = class {
5289
+ constructor(key) {
5290
+ this.blockLen = 16;
5291
+ this.outputLen = 16;
5292
+ this.buffer = new Uint8Array(16);
5293
+ this.r = new Uint16Array(10);
5294
+ this.h = new Uint16Array(10);
5295
+ this.pad = new Uint16Array(8);
5296
+ this.pos = 0;
5297
+ this.finished = false;
5298
+ key = toBytes2(key);
5299
+ abytes2(key, 32);
5300
+ const t0 = u8to16(key, 0);
5301
+ const t1 = u8to16(key, 2);
5302
+ const t2 = u8to16(key, 4);
5303
+ const t3 = u8to16(key, 6);
5304
+ const t4 = u8to16(key, 8);
5305
+ const t5 = u8to16(key, 10);
5306
+ const t6 = u8to16(key, 12);
5307
+ const t7 = u8to16(key, 14);
5308
+ this.r[0] = t0 & 8191;
5309
+ this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
5310
+ this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
5311
+ this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
5312
+ this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
5313
+ this.r[5] = t4 >>> 1 & 8190;
5314
+ this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
5315
+ this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
5316
+ this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
5317
+ this.r[9] = t7 >>> 5 & 127;
5318
+ for (let i = 0; i < 8; i++)
5319
+ this.pad[i] = u8to16(key, 16 + 2 * i);
5320
+ }
5321
+ process(data, offset, isLast = false) {
5322
+ const hibit = isLast ? 0 : 1 << 11;
5323
+ const { h, r } = this;
5324
+ const r0 = r[0];
5325
+ const r1 = r[1];
5326
+ const r2 = r[2];
5327
+ const r3 = r[3];
5328
+ const r4 = r[4];
5329
+ const r5 = r[5];
5330
+ const r6 = r[6];
5331
+ const r7 = r[7];
5332
+ const r8 = r[8];
5333
+ const r9 = r[9];
5334
+ const t0 = u8to16(data, offset + 0);
5335
+ const t1 = u8to16(data, offset + 2);
5336
+ const t2 = u8to16(data, offset + 4);
5337
+ const t3 = u8to16(data, offset + 6);
5338
+ const t4 = u8to16(data, offset + 8);
5339
+ const t5 = u8to16(data, offset + 10);
5340
+ const t6 = u8to16(data, offset + 12);
5341
+ const t7 = u8to16(data, offset + 14);
5342
+ let h0 = h[0] + (t0 & 8191);
5343
+ let h1 = h[1] + ((t0 >>> 13 | t1 << 3) & 8191);
5344
+ let h2 = h[2] + ((t1 >>> 10 | t2 << 6) & 8191);
5345
+ let h3 = h[3] + ((t2 >>> 7 | t3 << 9) & 8191);
5346
+ let h4 = h[4] + ((t3 >>> 4 | t4 << 12) & 8191);
5347
+ let h5 = h[5] + (t4 >>> 1 & 8191);
5348
+ let h6 = h[6] + ((t4 >>> 14 | t5 << 2) & 8191);
5349
+ let h7 = h[7] + ((t5 >>> 11 | t6 << 5) & 8191);
5350
+ let h8 = h[8] + ((t6 >>> 8 | t7 << 8) & 8191);
5351
+ let h9 = h[9] + (t7 >>> 5 | hibit);
5352
+ let c = 0;
5353
+ let d0 = c + h0 * r0 + h1 * (5 * r9) + h2 * (5 * r8) + h3 * (5 * r7) + h4 * (5 * r6);
5354
+ c = d0 >>> 13;
5355
+ d0 &= 8191;
5356
+ d0 += h5 * (5 * r5) + h6 * (5 * r4) + h7 * (5 * r3) + h8 * (5 * r2) + h9 * (5 * r1);
5357
+ c += d0 >>> 13;
5358
+ d0 &= 8191;
5359
+ let d1 = c + h0 * r1 + h1 * r0 + h2 * (5 * r9) + h3 * (5 * r8) + h4 * (5 * r7);
5360
+ c = d1 >>> 13;
5361
+ d1 &= 8191;
5362
+ d1 += h5 * (5 * r6) + h6 * (5 * r5) + h7 * (5 * r4) + h8 * (5 * r3) + h9 * (5 * r2);
5363
+ c += d1 >>> 13;
5364
+ d1 &= 8191;
5365
+ let d2 = c + h0 * r2 + h1 * r1 + h2 * r0 + h3 * (5 * r9) + h4 * (5 * r8);
5366
+ c = d2 >>> 13;
5367
+ d2 &= 8191;
5368
+ d2 += h5 * (5 * r7) + h6 * (5 * r6) + h7 * (5 * r5) + h8 * (5 * r4) + h9 * (5 * r3);
5369
+ c += d2 >>> 13;
5370
+ d2 &= 8191;
5371
+ let d3 = c + h0 * r3 + h1 * r2 + h2 * r1 + h3 * r0 + h4 * (5 * r9);
5372
+ c = d3 >>> 13;
5373
+ d3 &= 8191;
5374
+ d3 += h5 * (5 * r8) + h6 * (5 * r7) + h7 * (5 * r6) + h8 * (5 * r5) + h9 * (5 * r4);
5375
+ c += d3 >>> 13;
5376
+ d3 &= 8191;
5377
+ let d4 = c + h0 * r4 + h1 * r3 + h2 * r2 + h3 * r1 + h4 * r0;
5378
+ c = d4 >>> 13;
5379
+ d4 &= 8191;
5380
+ d4 += h5 * (5 * r9) + h6 * (5 * r8) + h7 * (5 * r7) + h8 * (5 * r6) + h9 * (5 * r5);
5381
+ c += d4 >>> 13;
5382
+ d4 &= 8191;
5383
+ let d5 = c + h0 * r5 + h1 * r4 + h2 * r3 + h3 * r2 + h4 * r1;
5384
+ c = d5 >>> 13;
5385
+ d5 &= 8191;
5386
+ d5 += h5 * r0 + h6 * (5 * r9) + h7 * (5 * r8) + h8 * (5 * r7) + h9 * (5 * r6);
5387
+ c += d5 >>> 13;
5388
+ d5 &= 8191;
5389
+ let d6 = c + h0 * r6 + h1 * r5 + h2 * r4 + h3 * r3 + h4 * r2;
5390
+ c = d6 >>> 13;
5391
+ d6 &= 8191;
5392
+ d6 += h5 * r1 + h6 * r0 + h7 * (5 * r9) + h8 * (5 * r8) + h9 * (5 * r7);
5393
+ c += d6 >>> 13;
5394
+ d6 &= 8191;
5395
+ let d7 = c + h0 * r7 + h1 * r6 + h2 * r5 + h3 * r4 + h4 * r3;
5396
+ c = d7 >>> 13;
5397
+ d7 &= 8191;
5398
+ d7 += h5 * r2 + h6 * r1 + h7 * r0 + h8 * (5 * r9) + h9 * (5 * r8);
5399
+ c += d7 >>> 13;
5400
+ d7 &= 8191;
5401
+ let d8 = c + h0 * r8 + h1 * r7 + h2 * r6 + h3 * r5 + h4 * r4;
5402
+ c = d8 >>> 13;
5403
+ d8 &= 8191;
5404
+ d8 += h5 * r3 + h6 * r2 + h7 * r1 + h8 * r0 + h9 * (5 * r9);
5405
+ c += d8 >>> 13;
5406
+ d8 &= 8191;
5407
+ let d9 = c + h0 * r9 + h1 * r8 + h2 * r7 + h3 * r6 + h4 * r5;
5408
+ c = d9 >>> 13;
5409
+ d9 &= 8191;
5410
+ d9 += h5 * r4 + h6 * r3 + h7 * r2 + h8 * r1 + h9 * r0;
5411
+ c += d9 >>> 13;
5412
+ d9 &= 8191;
5413
+ c = (c << 2) + c | 0;
5414
+ c = c + d0 | 0;
5415
+ d0 = c & 8191;
5416
+ c = c >>> 13;
5417
+ d1 += c;
5418
+ h[0] = d0;
5419
+ h[1] = d1;
5420
+ h[2] = d2;
5421
+ h[3] = d3;
5422
+ h[4] = d4;
5423
+ h[5] = d5;
5424
+ h[6] = d6;
5425
+ h[7] = d7;
5426
+ h[8] = d8;
5427
+ h[9] = d9;
5428
+ }
5429
+ finalize() {
5430
+ const { h, pad } = this;
5431
+ const g = new Uint16Array(10);
5432
+ let c = h[1] >>> 13;
5433
+ h[1] &= 8191;
5434
+ for (let i = 2; i < 10; i++) {
5435
+ h[i] += c;
5436
+ c = h[i] >>> 13;
5437
+ h[i] &= 8191;
5438
+ }
5439
+ h[0] += c * 5;
5440
+ c = h[0] >>> 13;
5441
+ h[0] &= 8191;
5442
+ h[1] += c;
5443
+ c = h[1] >>> 13;
5444
+ h[1] &= 8191;
5445
+ h[2] += c;
5446
+ g[0] = h[0] + 5;
5447
+ c = g[0] >>> 13;
5448
+ g[0] &= 8191;
5449
+ for (let i = 1; i < 10; i++) {
5450
+ g[i] = h[i] + c;
5451
+ c = g[i] >>> 13;
5452
+ g[i] &= 8191;
5453
+ }
5454
+ g[9] -= 1 << 13;
5455
+ let mask = (c ^ 1) - 1;
5456
+ for (let i = 0; i < 10; i++)
5457
+ g[i] &= mask;
5458
+ mask = ~mask;
5459
+ for (let i = 0; i < 10; i++)
5460
+ h[i] = h[i] & mask | g[i];
5461
+ h[0] = (h[0] | h[1] << 13) & 65535;
5462
+ h[1] = (h[1] >>> 3 | h[2] << 10) & 65535;
5463
+ h[2] = (h[2] >>> 6 | h[3] << 7) & 65535;
5464
+ h[3] = (h[3] >>> 9 | h[4] << 4) & 65535;
5465
+ h[4] = (h[4] >>> 12 | h[5] << 1 | h[6] << 14) & 65535;
5466
+ h[5] = (h[6] >>> 2 | h[7] << 11) & 65535;
5467
+ h[6] = (h[7] >>> 5 | h[8] << 8) & 65535;
5468
+ h[7] = (h[8] >>> 8 | h[9] << 5) & 65535;
5469
+ let f = h[0] + pad[0];
5470
+ h[0] = f & 65535;
5471
+ for (let i = 1; i < 8; i++) {
5472
+ f = (h[i] + pad[i] | 0) + (f >>> 16) | 0;
5473
+ h[i] = f & 65535;
5474
+ }
5475
+ clean2(g);
5476
+ }
5477
+ update(data) {
5478
+ aexists2(this);
5479
+ data = toBytes2(data);
5480
+ abytes2(data);
5481
+ const { buffer, blockLen } = this;
5482
+ const len = data.length;
5483
+ for (let pos = 0; pos < len; ) {
5484
+ const take = Math.min(blockLen - this.pos, len - pos);
5485
+ if (take === blockLen) {
5486
+ for (; blockLen <= len - pos; pos += blockLen)
5487
+ this.process(data, pos);
5488
+ continue;
5489
+ }
5490
+ buffer.set(data.subarray(pos, pos + take), this.pos);
5491
+ this.pos += take;
5492
+ pos += take;
5493
+ if (this.pos === blockLen) {
5494
+ this.process(buffer, 0, false);
5495
+ this.pos = 0;
5496
+ }
5497
+ }
5498
+ return this;
5499
+ }
5500
+ destroy() {
5501
+ clean2(this.h, this.r, this.buffer, this.pad);
5502
+ }
5503
+ digestInto(out) {
5504
+ aexists2(this);
5505
+ aoutput2(out, this);
5506
+ this.finished = true;
5507
+ const { buffer, h } = this;
5508
+ let { pos } = this;
5509
+ if (pos) {
5510
+ buffer[pos++] = 1;
5511
+ for (; pos < 16; pos++)
5512
+ buffer[pos] = 0;
5513
+ this.process(buffer, 0, true);
5514
+ }
5515
+ this.finalize();
5516
+ let opos = 0;
5517
+ for (let i = 0; i < 8; i++) {
5518
+ out[opos++] = h[i] >>> 0;
5519
+ out[opos++] = h[i] >>> 8;
5520
+ }
5521
+ return out;
5522
+ }
5523
+ digest() {
5524
+ const { buffer, outputLen } = this;
5525
+ this.digestInto(buffer);
5526
+ const res = buffer.slice(0, outputLen);
5527
+ this.destroy();
5528
+ return res;
5529
+ }
5530
+ };
5531
+ poly1305 = wrapConstructorWithKey((key) => new Poly1305(key));
5532
+ }
5533
+ });
5534
+
5535
+ // ../../node_modules/@noble/ciphers/esm/chacha.js
5536
+ function chachaCore(s, k, n, out, cnt, rounds = 20) {
5537
+ let y00 = s[0], y01 = s[1], y02 = s[2], y03 = s[3], y04 = k[0], y05 = k[1], y06 = k[2], y07 = k[3], y08 = k[4], y09 = k[5], y10 = k[6], y11 = k[7], y12 = cnt, y13 = n[0], y14 = n[1], y15 = n[2];
5538
+ let x00 = y00, x01 = y01, x02 = y02, x03 = y03, x04 = y04, x05 = y05, x06 = y06, x07 = y07, x08 = y08, x09 = y09, x10 = y10, x11 = y11, x12 = y12, x13 = y13, x14 = y14, x15 = y15;
5539
+ for (let r = 0; r < rounds; r += 2) {
5540
+ x00 = x00 + x04 | 0;
5541
+ x12 = rotl(x12 ^ x00, 16);
5542
+ x08 = x08 + x12 | 0;
5543
+ x04 = rotl(x04 ^ x08, 12);
5544
+ x00 = x00 + x04 | 0;
5545
+ x12 = rotl(x12 ^ x00, 8);
5546
+ x08 = x08 + x12 | 0;
5547
+ x04 = rotl(x04 ^ x08, 7);
5548
+ x01 = x01 + x05 | 0;
5549
+ x13 = rotl(x13 ^ x01, 16);
5550
+ x09 = x09 + x13 | 0;
5551
+ x05 = rotl(x05 ^ x09, 12);
5552
+ x01 = x01 + x05 | 0;
5553
+ x13 = rotl(x13 ^ x01, 8);
5554
+ x09 = x09 + x13 | 0;
5555
+ x05 = rotl(x05 ^ x09, 7);
5556
+ x02 = x02 + x06 | 0;
5557
+ x14 = rotl(x14 ^ x02, 16);
5558
+ x10 = x10 + x14 | 0;
5559
+ x06 = rotl(x06 ^ x10, 12);
5560
+ x02 = x02 + x06 | 0;
5561
+ x14 = rotl(x14 ^ x02, 8);
5562
+ x10 = x10 + x14 | 0;
5563
+ x06 = rotl(x06 ^ x10, 7);
5564
+ x03 = x03 + x07 | 0;
5565
+ x15 = rotl(x15 ^ x03, 16);
5566
+ x11 = x11 + x15 | 0;
5567
+ x07 = rotl(x07 ^ x11, 12);
5568
+ x03 = x03 + x07 | 0;
5569
+ x15 = rotl(x15 ^ x03, 8);
5570
+ x11 = x11 + x15 | 0;
5571
+ x07 = rotl(x07 ^ x11, 7);
5572
+ x00 = x00 + x05 | 0;
5573
+ x15 = rotl(x15 ^ x00, 16);
5574
+ x10 = x10 + x15 | 0;
5575
+ x05 = rotl(x05 ^ x10, 12);
5576
+ x00 = x00 + x05 | 0;
5577
+ x15 = rotl(x15 ^ x00, 8);
5578
+ x10 = x10 + x15 | 0;
5579
+ x05 = rotl(x05 ^ x10, 7);
5580
+ x01 = x01 + x06 | 0;
5581
+ x12 = rotl(x12 ^ x01, 16);
5582
+ x11 = x11 + x12 | 0;
5583
+ x06 = rotl(x06 ^ x11, 12);
5584
+ x01 = x01 + x06 | 0;
5585
+ x12 = rotl(x12 ^ x01, 8);
5586
+ x11 = x11 + x12 | 0;
5587
+ x06 = rotl(x06 ^ x11, 7);
5588
+ x02 = x02 + x07 | 0;
5589
+ x13 = rotl(x13 ^ x02, 16);
5590
+ x08 = x08 + x13 | 0;
5591
+ x07 = rotl(x07 ^ x08, 12);
5592
+ x02 = x02 + x07 | 0;
5593
+ x13 = rotl(x13 ^ x02, 8);
5594
+ x08 = x08 + x13 | 0;
5595
+ x07 = rotl(x07 ^ x08, 7);
5596
+ x03 = x03 + x04 | 0;
5597
+ x14 = rotl(x14 ^ x03, 16);
5598
+ x09 = x09 + x14 | 0;
5599
+ x04 = rotl(x04 ^ x09, 12);
5600
+ x03 = x03 + x04 | 0;
5601
+ x14 = rotl(x14 ^ x03, 8);
5602
+ x09 = x09 + x14 | 0;
5603
+ x04 = rotl(x04 ^ x09, 7);
5604
+ }
5605
+ let oi = 0;
5606
+ out[oi++] = y00 + x00 | 0;
5607
+ out[oi++] = y01 + x01 | 0;
5608
+ out[oi++] = y02 + x02 | 0;
5609
+ out[oi++] = y03 + x03 | 0;
5610
+ out[oi++] = y04 + x04 | 0;
5611
+ out[oi++] = y05 + x05 | 0;
5612
+ out[oi++] = y06 + x06 | 0;
5613
+ out[oi++] = y07 + x07 | 0;
5614
+ out[oi++] = y08 + x08 | 0;
5615
+ out[oi++] = y09 + x09 | 0;
5616
+ out[oi++] = y10 + x10 | 0;
5617
+ out[oi++] = y11 + x11 | 0;
5618
+ out[oi++] = y12 + x12 | 0;
5619
+ out[oi++] = y13 + x13 | 0;
5620
+ out[oi++] = y14 + x14 | 0;
5621
+ out[oi++] = y15 + x15 | 0;
5622
+ }
5623
+ function hchacha(s, k, i, o32) {
5624
+ let x00 = s[0], x01 = s[1], x02 = s[2], x03 = s[3], x04 = k[0], x05 = k[1], x06 = k[2], x07 = k[3], x08 = k[4], x09 = k[5], x10 = k[6], x11 = k[7], x12 = i[0], x13 = i[1], x14 = i[2], x15 = i[3];
5625
+ for (let r = 0; r < 20; r += 2) {
5626
+ x00 = x00 + x04 | 0;
5627
+ x12 = rotl(x12 ^ x00, 16);
5628
+ x08 = x08 + x12 | 0;
5629
+ x04 = rotl(x04 ^ x08, 12);
5630
+ x00 = x00 + x04 | 0;
5631
+ x12 = rotl(x12 ^ x00, 8);
5632
+ x08 = x08 + x12 | 0;
5633
+ x04 = rotl(x04 ^ x08, 7);
5634
+ x01 = x01 + x05 | 0;
5635
+ x13 = rotl(x13 ^ x01, 16);
5636
+ x09 = x09 + x13 | 0;
5637
+ x05 = rotl(x05 ^ x09, 12);
5638
+ x01 = x01 + x05 | 0;
5639
+ x13 = rotl(x13 ^ x01, 8);
5640
+ x09 = x09 + x13 | 0;
5641
+ x05 = rotl(x05 ^ x09, 7);
5642
+ x02 = x02 + x06 | 0;
5643
+ x14 = rotl(x14 ^ x02, 16);
5644
+ x10 = x10 + x14 | 0;
5645
+ x06 = rotl(x06 ^ x10, 12);
5646
+ x02 = x02 + x06 | 0;
5647
+ x14 = rotl(x14 ^ x02, 8);
5648
+ x10 = x10 + x14 | 0;
5649
+ x06 = rotl(x06 ^ x10, 7);
5650
+ x03 = x03 + x07 | 0;
5651
+ x15 = rotl(x15 ^ x03, 16);
5652
+ x11 = x11 + x15 | 0;
5653
+ x07 = rotl(x07 ^ x11, 12);
5654
+ x03 = x03 + x07 | 0;
5655
+ x15 = rotl(x15 ^ x03, 8);
5656
+ x11 = x11 + x15 | 0;
5657
+ x07 = rotl(x07 ^ x11, 7);
5658
+ x00 = x00 + x05 | 0;
5659
+ x15 = rotl(x15 ^ x00, 16);
5660
+ x10 = x10 + x15 | 0;
5661
+ x05 = rotl(x05 ^ x10, 12);
5662
+ x00 = x00 + x05 | 0;
5663
+ x15 = rotl(x15 ^ x00, 8);
5664
+ x10 = x10 + x15 | 0;
5665
+ x05 = rotl(x05 ^ x10, 7);
5666
+ x01 = x01 + x06 | 0;
5667
+ x12 = rotl(x12 ^ x01, 16);
5668
+ x11 = x11 + x12 | 0;
5669
+ x06 = rotl(x06 ^ x11, 12);
5670
+ x01 = x01 + x06 | 0;
5671
+ x12 = rotl(x12 ^ x01, 8);
5672
+ x11 = x11 + x12 | 0;
5673
+ x06 = rotl(x06 ^ x11, 7);
5674
+ x02 = x02 + x07 | 0;
5675
+ x13 = rotl(x13 ^ x02, 16);
5676
+ x08 = x08 + x13 | 0;
5677
+ x07 = rotl(x07 ^ x08, 12);
5678
+ x02 = x02 + x07 | 0;
5679
+ x13 = rotl(x13 ^ x02, 8);
5680
+ x08 = x08 + x13 | 0;
5681
+ x07 = rotl(x07 ^ x08, 7);
5682
+ x03 = x03 + x04 | 0;
5683
+ x14 = rotl(x14 ^ x03, 16);
5684
+ x09 = x09 + x14 | 0;
5685
+ x04 = rotl(x04 ^ x09, 12);
5686
+ x03 = x03 + x04 | 0;
5687
+ x14 = rotl(x14 ^ x03, 8);
5688
+ x09 = x09 + x14 | 0;
5689
+ x04 = rotl(x04 ^ x09, 7);
5690
+ }
5691
+ let oi = 0;
5692
+ o32[oi++] = x00;
5693
+ o32[oi++] = x01;
5694
+ o32[oi++] = x02;
5695
+ o32[oi++] = x03;
5696
+ o32[oi++] = x12;
5697
+ o32[oi++] = x13;
5698
+ o32[oi++] = x14;
5699
+ o32[oi++] = x15;
5700
+ }
5701
+ function computeTag(fn, key, nonce, data, AAD) {
5702
+ const authKey = fn(key, nonce, ZEROS32);
5703
+ const h = poly1305.create(authKey);
5704
+ if (AAD)
5705
+ updatePadded(h, AAD);
5706
+ updatePadded(h, data);
5707
+ const num = u64Lengths(data.length, AAD ? AAD.length : 0, true);
5708
+ h.update(num);
5709
+ const res = h.digest();
5710
+ clean2(authKey, num);
5711
+ return res;
5712
+ }
5713
+ var chacha20, xchacha20, ZEROS16, updatePadded, ZEROS32, _poly1305_aead, chacha20poly1305, xchacha20poly1305;
5714
+ var init_chacha = __esm({
5715
+ "../../node_modules/@noble/ciphers/esm/chacha.js"() {
5716
+ "use strict";
5717
+ init_arx();
5718
+ init_poly1305();
5719
+ init_utils3();
5720
+ chacha20 = /* @__PURE__ */ createCipher(chachaCore, {
5721
+ counterRight: false,
5722
+ counterLength: 4,
5723
+ allowShortKeys: false
5724
+ });
5725
+ xchacha20 = /* @__PURE__ */ createCipher(chachaCore, {
5726
+ counterRight: false,
5727
+ counterLength: 8,
5728
+ extendNonceFn: hchacha,
5729
+ allowShortKeys: false
5730
+ });
5731
+ ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
5732
+ updatePadded = (h, msg) => {
5733
+ h.update(msg);
5734
+ const left = msg.length % 16;
5735
+ if (left)
5736
+ h.update(ZEROS16.subarray(left));
5737
+ };
5738
+ ZEROS32 = /* @__PURE__ */ new Uint8Array(32);
5739
+ _poly1305_aead = (xorStream) => (key, nonce, AAD) => {
5740
+ const tagLength = 16;
5741
+ return {
5742
+ encrypt(plaintext, output) {
5743
+ const plength = plaintext.length;
5744
+ output = getOutput(plength + tagLength, output, false);
5745
+ output.set(plaintext);
5746
+ const oPlain = output.subarray(0, -tagLength);
5747
+ xorStream(key, nonce, oPlain, oPlain, 1);
5748
+ const tag = computeTag(xorStream, key, nonce, oPlain, AAD);
5749
+ output.set(tag, plength);
5750
+ clean2(tag);
5751
+ return output;
5752
+ },
5753
+ decrypt(ciphertext, output) {
5754
+ output = getOutput(ciphertext.length - tagLength, output, false);
5755
+ const data = ciphertext.subarray(0, -tagLength);
5756
+ const passedTag = ciphertext.subarray(-tagLength);
5757
+ const tag = computeTag(xorStream, key, nonce, data, AAD);
5758
+ if (!equalBytes2(passedTag, tag))
5759
+ throw new Error("invalid tag");
5760
+ output.set(ciphertext.subarray(0, -tagLength));
5761
+ xorStream(key, nonce, output, output, 1);
5762
+ clean2(tag);
5763
+ return output;
5764
+ }
5765
+ };
5766
+ };
5767
+ chacha20poly1305 = /* @__PURE__ */ wrapCipher({ blockSize: 64, nonceLength: 12, tagLength: 16 }, _poly1305_aead(chacha20));
5768
+ xchacha20poly1305 = /* @__PURE__ */ wrapCipher({ blockSize: 64, nonceLength: 24, tagLength: 16 }, _poly1305_aead(xchacha20));
5769
+ }
5770
+ });
5771
+
5772
+ // ../../packages/core/src/chatCrypto.ts
5773
+ import { hkdfSync, createHash, randomBytes as randomBytes2 } from "crypto";
5774
+ function bytesToHex2(bytes) {
5775
+ return Buffer.from(bytes).toString("hex");
5776
+ }
5777
+ function hexToBytes2(hex) {
5778
+ const buf = Buffer.from(hex, "hex");
5779
+ if (buf.length === 0 || buf.toString("hex") !== hex.toLowerCase()) {
5780
+ throw new Error("chatCrypto: invalid hex-encoded key");
5781
+ }
5782
+ return new Uint8Array(buf);
5783
+ }
5784
+ function bytesToB64(bytes) {
5785
+ return Buffer.from(bytes).toString("base64");
5786
+ }
5787
+ function b64ToBytes(b64) {
5788
+ return new Uint8Array(Buffer.from(b64, "base64"));
5789
+ }
5790
+ function generateIdentityKeypair() {
5791
+ const privateKey = x25519.utils.randomPrivateKey();
5792
+ const publicKey = x25519.getPublicKey(privateKey);
5793
+ return { publicKey: bytesToHex2(publicKey), privateKey: bytesToHex2(privateKey) };
5794
+ }
5795
+ function deriveSharedKey(myPrivateKey, peerPublicKey) {
5796
+ const shared = x25519.getSharedSecret(hexToBytes2(myPrivateKey), hexToBytes2(peerPublicKey));
5797
+ const derived = hkdfSync("sha256", shared, new Uint8Array(0), KDF_INFO, SHARED_KEY_BYTES);
5798
+ return new Uint8Array(derived);
5799
+ }
5800
+ function encryptMessage(plaintext, myPrivateKey, peerPublicKey) {
5801
+ const key = deriveSharedKey(myPrivateKey, peerPublicKey);
5802
+ const nonce = new Uint8Array(randomBytes2(NONCE_BYTES));
5803
+ const cipher = xchacha20poly1305(key, nonce);
5804
+ const ct = cipher.encrypt(new Uint8Array(Buffer.from(plaintext, "utf8")));
5805
+ return { ciphertext: bytesToB64(ct), nonce: bytesToB64(nonce) };
5806
+ }
5807
+ function decryptMessage(message, myPrivateKey, peerPublicKey) {
5808
+ const key = deriveSharedKey(myPrivateKey, peerPublicKey);
5809
+ const nonce = b64ToBytes(message.nonce);
5810
+ if (nonce.length !== NONCE_BYTES) {
5811
+ throw new Error(`chatCrypto: bad nonce length (expected ${NONCE_BYTES}, got ${nonce.length})`);
5812
+ }
5813
+ const ciphertext = b64ToBytes(message.ciphertext);
5814
+ if (ciphertext.length === 0) {
5815
+ throw new Error("chatCrypto: empty ciphertext");
5816
+ }
5817
+ const cipher = xchacha20poly1305(key, nonce);
5818
+ const pt = cipher.decrypt(ciphertext);
5819
+ return Buffer.from(pt).toString("utf8");
5820
+ }
5821
+ function safetyNumber(pubA, pubB) {
5822
+ const [first, second] = [pubA.toLowerCase(), pubB.toLowerCase()].sort();
5823
+ const digest = createHash("sha256").update(first).update("\n").update(second).digest();
5824
+ const groups = [];
5825
+ for (let i = 0; i < 12; i++) {
5826
+ const chunk = digest.readUInt16BE(i * 2 % 30);
5827
+ groups.push(String(chunk % 1e5).padStart(5, "0"));
5828
+ }
5829
+ return groups.join(" ");
5830
+ }
5831
+ var KDF_INFO, SHARED_KEY_BYTES, NONCE_BYTES;
5832
+ var init_chatCrypto = __esm({
5833
+ "../../packages/core/src/chatCrypto.ts"() {
5834
+ "use strict";
5835
+ init_ed25519();
5836
+ init_chacha();
5837
+ KDF_INFO = Buffer.from("terminalhire-chat-v1");
5838
+ SHARED_KEY_BYTES = 32;
5839
+ NONCE_BYTES = 24;
5840
+ }
5841
+ });
5842
+
2812
5843
  // ../../packages/core/src/index.ts
2813
5844
  var src_exports = {};
2814
5845
  __export(src_exports, {
@@ -2850,13 +5881,17 @@ __export(src_exports, {
2850
5881
  computeAcceptanceCredential: () => computeAcceptanceCredential,
2851
5882
  computeAcceptanceCredentialPublic: () => computeAcceptanceCredentialPublic,
2852
5883
  coreTagsFromTitle: () => coreTagsFromTitle,
5884
+ decryptMessage: () => decryptMessage,
2853
5885
  deriveResumeTrend: () => deriveResumeTrend,
5886
+ deriveSharedKey: () => deriveSharedKey,
5887
+ encryptMessage: () => encryptMessage,
2854
5888
  expandWeighted: () => expandWeighted,
2855
5889
  extractSkillTags: () => extractSkillTags,
2856
5890
  fetchGitHubProfile: () => fetchGitHubProfile,
2857
5891
  fetchOwnedRepoTraction: () => fetchOwnedRepoTraction,
2858
5892
  fetchRepoRecency: () => fetchRepoRecency,
2859
5893
  flattenTiers: () => flattenTiers,
5894
+ generateIdentityKeypair: () => generateIdentityKeypair,
2860
5895
  getBuyer: () => getBuyer,
2861
5896
  githubBounties: () => githubBounties,
2862
5897
  githubToFingerprint: () => githubToFingerprint,
@@ -2879,6 +5914,7 @@ __export(src_exports, {
2879
5914
  projectCardToJob: () => projectCardToJob,
2880
5915
  rejectExtraIntroFields: () => rejectExtraIntroFields,
2881
5916
  revealIntroContacts: () => revealIntroContacts,
5917
+ safetyNumber: () => safetyNumber,
2882
5918
  tokenize: () => tokenize,
2883
5919
  validateGraph: () => validateGraph,
2884
5920
  validateIntroPayload: () => validateIntroPayload,
@@ -2898,6 +5934,7 @@ var init_src = __esm({
2898
5934
  init_github();
2899
5935
  init_intro();
2900
5936
  init_directoryThreshold();
5937
+ init_chatCrypto();
2901
5938
  }
2902
5939
  });
2903
5940
 
@@ -2918,7 +5955,7 @@ __export(profile_exports, {
2918
5955
  import {
2919
5956
  createCipheriv,
2920
5957
  createDecipheriv,
2921
- randomBytes
5958
+ randomBytes as randomBytes3
2922
5959
  } from "crypto";
2923
5960
  import {
2924
5961
  readFileSync as readFileSync2,
@@ -2935,7 +5972,7 @@ async function loadKey() {
2935
5972
  if (stored) {
2936
5973
  return Buffer.from(stored, "hex");
2937
5974
  }
2938
- const key2 = randomBytes(KEY_BYTES);
5975
+ const key2 = randomBytes3(KEY_BYTES);
2939
5976
  await kt.setPassword("terminalhire", "profile-key", key2.toString("hex"));
2940
5977
  return key2;
2941
5978
  } catch {
@@ -2944,12 +5981,12 @@ async function loadKey() {
2944
5981
  if (existsSync(KEY_FILE)) {
2945
5982
  return Buffer.from(readFileSync2(KEY_FILE, "utf8").trim(), "hex");
2946
5983
  }
2947
- const key = randomBytes(KEY_BYTES);
5984
+ const key = randomBytes3(KEY_BYTES);
2948
5985
  writeFileSync(KEY_FILE, key.toString("hex"), { mode: 384, encoding: "utf8" });
2949
5986
  return key;
2950
5987
  }
2951
5988
  function encrypt(plaintext, key) {
2952
- const iv = randomBytes(IV_BYTES);
5989
+ const iv = randomBytes3(IV_BYTES);
2953
5990
  const cipher = createCipheriv(ALGO, key, iv);
2954
5991
  const ct = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
2955
5992
  const tag = cipher.getAuthTag();
@@ -3276,3 +6313,19 @@ Open this to claim/work the bounty (you go straight to the source \u2014 we neve
3276
6313
  export {
3277
6314
  run
3278
6315
  };
6316
+ /*! Bundled license information:
6317
+
6318
+ @noble/hashes/esm/utils.js:
6319
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
6320
+
6321
+ @noble/curves/esm/utils.js:
6322
+ @noble/curves/esm/abstract/modular.js:
6323
+ @noble/curves/esm/abstract/curve.js:
6324
+ @noble/curves/esm/abstract/edwards.js:
6325
+ @noble/curves/esm/abstract/montgomery.js:
6326
+ @noble/curves/esm/ed25519.js:
6327
+ (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
6328
+
6329
+ @noble/ciphers/esm/utils.js:
6330
+ (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
6331
+ */