@palbase/backend 33.0.0 → 33.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/palbase-backend.cjs.map +1 -1
- package/dist/bin/palbase-backend.js +5 -5
- package/dist/{chunk-BRLJOXWS.js → chunk-AAT5G7KY.js} +2 -2
- package/dist/{chunk-BRLJOXWS.js.map → chunk-AAT5G7KY.js.map} +1 -1
- package/dist/{chunk-DCDHAKF3.js → chunk-C6COAB3E.js} +5 -5
- package/dist/{chunk-C4ZA5AT2.js → chunk-SI4KGEM3.js} +1 -1
- package/dist/{chunk-C4ZA5AT2.js.map → chunk-SI4KGEM3.js.map} +1 -1
- package/dist/{chunk-QMFOL2K6.js → chunk-TVCCR6SO.js} +2 -2
- package/dist/{chunk-N54QZER3.js → chunk-WWUG2QXF.js} +2 -2
- package/dist/{chunk-GOPZPM2A.js → chunk-YIQ4RS4F.js} +2 -2
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +2 -2
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.d.cts +3 -3
- package/dist/engine/index.d.ts +3 -3
- package/dist/engine/index.js +5 -5
- package/dist/{index-Bi74dcOu.d.ts → index-D-3duy8Y.d.ts} +2 -2
- package/dist/{index-BWgnGj68.d.cts → index-DB_nW-AV.d.cts} +19 -10
- package/dist/{index-g6iQyYci.d.cts → index-DLveQoOf.d.cts} +2 -2
- package/dist/{index-Dg10RnZO.d.ts → index-DMZG3kpo.d.ts} +19 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/openapi/index.cjs +1 -1
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +2 -2
- package/dist/openapi/index.d.ts +2 -2
- package/dist/openapi/index.js +1 -1
- package/dist/{registry-6VT5RPeO.d.cts → registry-DSTThhKf.d.cts} +1 -1
- package/dist/{registry-B-sxJJN0.d.ts → registry-JjF5lcj4.d.ts} +1 -1
- package/dist/test/index.cjs +1120 -4
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +1121 -5
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +123 -79
- package/docs/auth.md +11 -7
- package/docs/background.md +16 -7
- package/docs/database.md +22 -18
- package/docs/endpoints.md +26 -20
- package/docs/errors.md +2 -3
- package/docs/events.md +63 -29
- package/docs/getting-started.md +8 -7
- package/docs/llms-full.txt +399 -232
- package/docs/migrations.md +6 -5
- package/docs/routing.md +34 -11
- package/docs/schema.md +61 -36
- package/docs/services.md +30 -13
- package/package.json +2 -1
- package/stack-images.json +24 -0
- package/template/AGENTS.md +7 -7
- package/template/modules/health/health.controller.ts +7 -4
- package/template/modules/notes/dto/create.ts +4 -3
- package/template/modules/notes/notes.controller.ts +8 -6
- /package/dist/{chunk-DCDHAKF3.js.map → chunk-C6COAB3E.js.map} +0 -0
- /package/dist/{chunk-QMFOL2K6.js.map → chunk-TVCCR6SO.js.map} +0 -0
- /package/dist/{chunk-N54QZER3.js.map → chunk-WWUG2QXF.js.map} +0 -0
- /package/dist/{chunk-GOPZPM2A.js.map → chunk-YIQ4RS4F.js.map} +0 -0
package/dist/test/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__requestALS,
|
|
3
3
|
makeTypedSurface
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-TVCCR6SO.js";
|
|
5
5
|
import {
|
|
6
6
|
assertNoExpressionHandles,
|
|
7
7
|
assertUsableFilter,
|
|
@@ -11,11 +11,1114 @@ import {
|
|
|
11
11
|
isColumnExpr,
|
|
12
12
|
isNowExpr,
|
|
13
13
|
isSqlFragment
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-SI4KGEM3.js";
|
|
15
15
|
import {
|
|
16
16
|
__name
|
|
17
17
|
} from "../chunk-KATPXCJ5.js";
|
|
18
18
|
|
|
19
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/_dnt.shims.js
|
|
20
|
+
var dntGlobals = {};
|
|
21
|
+
var dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
22
|
+
function createMergeProxy(baseObj, extObj) {
|
|
23
|
+
return new Proxy(baseObj, {
|
|
24
|
+
get(_target, prop, _receiver) {
|
|
25
|
+
if (prop in extObj) {
|
|
26
|
+
return extObj[prop];
|
|
27
|
+
} else {
|
|
28
|
+
return baseObj[prop];
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
set(_target, prop, value) {
|
|
32
|
+
if (prop in extObj) {
|
|
33
|
+
delete extObj[prop];
|
|
34
|
+
}
|
|
35
|
+
baseObj[prop] = value;
|
|
36
|
+
return true;
|
|
37
|
+
},
|
|
38
|
+
deleteProperty(_target, prop) {
|
|
39
|
+
let success = false;
|
|
40
|
+
if (prop in extObj) {
|
|
41
|
+
delete extObj[prop];
|
|
42
|
+
success = true;
|
|
43
|
+
}
|
|
44
|
+
if (prop in baseObj) {
|
|
45
|
+
delete baseObj[prop];
|
|
46
|
+
success = true;
|
|
47
|
+
}
|
|
48
|
+
return success;
|
|
49
|
+
},
|
|
50
|
+
ownKeys(_target) {
|
|
51
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
52
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
53
|
+
const extKeysSet = new Set(extKeys);
|
|
54
|
+
return [
|
|
55
|
+
...baseKeys.filter((k) => !extKeysSet.has(k)),
|
|
56
|
+
...extKeys
|
|
57
|
+
];
|
|
58
|
+
},
|
|
59
|
+
defineProperty(_target, prop, desc) {
|
|
60
|
+
if (prop in extObj) {
|
|
61
|
+
delete extObj[prop];
|
|
62
|
+
}
|
|
63
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
64
|
+
return true;
|
|
65
|
+
},
|
|
66
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
67
|
+
if (prop in extObj) {
|
|
68
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
69
|
+
} else {
|
|
70
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
has(_target, prop) {
|
|
74
|
+
return prop in extObj || prop in baseObj;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
__name(createMergeProxy, "createMergeProxy");
|
|
79
|
+
|
|
80
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/src/consts.js
|
|
81
|
+
var N_0 = 0n;
|
|
82
|
+
|
|
83
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/src/kems/dhkemPrimitives/ec.js
|
|
84
|
+
var EC_P_521_PARAMS = {
|
|
85
|
+
p: (1n << 521n) - 1n,
|
|
86
|
+
b: 0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00n,
|
|
87
|
+
gx: 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66n,
|
|
88
|
+
gy: 0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650n,
|
|
89
|
+
coordinateSize: 66
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/src/utils/noble.js
|
|
93
|
+
function isBytes(a) {
|
|
94
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
95
|
+
}
|
|
96
|
+
__name(isBytes, "isBytes");
|
|
97
|
+
function anumber(n, title = "") {
|
|
98
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
99
|
+
const prefix = title && `"${title}" `;
|
|
100
|
+
throw new Error(`${prefix}expected integer >0, got ${n}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
__name(anumber, "anumber");
|
|
104
|
+
function abytes(value, length, title = "") {
|
|
105
|
+
const bytes = isBytes(value);
|
|
106
|
+
const len = value?.length;
|
|
107
|
+
const needsLen = length !== void 0;
|
|
108
|
+
if (!bytes || needsLen && len !== length) {
|
|
109
|
+
const prefix = title && `"${title}" `;
|
|
110
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
111
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
112
|
+
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
__name(abytes, "abytes");
|
|
117
|
+
function aexists(instance, checkFinished = true) {
|
|
118
|
+
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
119
|
+
if (checkFinished && instance.finished) {
|
|
120
|
+
throw new Error("Hash#digest() has already been called");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
__name(aexists, "aexists");
|
|
124
|
+
function aoutput(out, instance) {
|
|
125
|
+
abytes(out, void 0, "digestInto() output");
|
|
126
|
+
const min = instance.outputLen;
|
|
127
|
+
if (out.length < min) {
|
|
128
|
+
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
__name(aoutput, "aoutput");
|
|
132
|
+
function u32(arr) {
|
|
133
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
134
|
+
}
|
|
135
|
+
__name(u32, "u32");
|
|
136
|
+
function clean(...arrays) {
|
|
137
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
138
|
+
arrays[i].fill(0);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
__name(clean, "clean");
|
|
142
|
+
var _endianTestBuffer = /* @__PURE__ */ new Uint32Array([
|
|
143
|
+
287454020
|
|
144
|
+
]);
|
|
145
|
+
var _endianTestBytes = /* @__PURE__ */ new Uint8Array(_endianTestBuffer.buffer);
|
|
146
|
+
var isLE = _endianTestBytes[0] === 68;
|
|
147
|
+
function createView(arr) {
|
|
148
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
149
|
+
}
|
|
150
|
+
__name(createView, "createView");
|
|
151
|
+
function numberToBigint(num) {
|
|
152
|
+
anumber(num, "numberToBigint");
|
|
153
|
+
let n = num;
|
|
154
|
+
let out = N_0;
|
|
155
|
+
let bit = 1n;
|
|
156
|
+
while (n > 0) {
|
|
157
|
+
if (n % 2 === 1) out += bit;
|
|
158
|
+
n = Math.floor(n / 2);
|
|
159
|
+
bit <<= 1n;
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
__name(numberToBigint, "numberToBigint");
|
|
164
|
+
function copyBytes(bytes) {
|
|
165
|
+
return Uint8Array.from(bytes);
|
|
166
|
+
}
|
|
167
|
+
__name(copyBytes, "copyBytes");
|
|
168
|
+
|
|
169
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/src/hash/hash.js
|
|
170
|
+
function ahash(h) {
|
|
171
|
+
if (typeof h !== "function" || typeof h.create !== "function") {
|
|
172
|
+
throw new Error("Hash must wrapped by utils.createHasher");
|
|
173
|
+
}
|
|
174
|
+
anumber(h.outputLen);
|
|
175
|
+
anumber(h.blockLen);
|
|
176
|
+
}
|
|
177
|
+
__name(ahash, "ahash");
|
|
178
|
+
|
|
179
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/src/hash/hmac.js
|
|
180
|
+
var _HMAC = class {
|
|
181
|
+
static {
|
|
182
|
+
__name(this, "_HMAC");
|
|
183
|
+
}
|
|
184
|
+
constructor(hash, key) {
|
|
185
|
+
Object.defineProperty(this, "oHash", {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
configurable: true,
|
|
188
|
+
writable: true,
|
|
189
|
+
value: void 0
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(this, "iHash", {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
configurable: true,
|
|
194
|
+
writable: true,
|
|
195
|
+
value: void 0
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(this, "blockLen", {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
configurable: true,
|
|
200
|
+
writable: true,
|
|
201
|
+
value: void 0
|
|
202
|
+
});
|
|
203
|
+
Object.defineProperty(this, "outputLen", {
|
|
204
|
+
enumerable: true,
|
|
205
|
+
configurable: true,
|
|
206
|
+
writable: true,
|
|
207
|
+
value: void 0
|
|
208
|
+
});
|
|
209
|
+
Object.defineProperty(this, "finished", {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
configurable: true,
|
|
212
|
+
writable: true,
|
|
213
|
+
value: false
|
|
214
|
+
});
|
|
215
|
+
Object.defineProperty(this, "destroyed", {
|
|
216
|
+
enumerable: true,
|
|
217
|
+
configurable: true,
|
|
218
|
+
writable: true,
|
|
219
|
+
value: false
|
|
220
|
+
});
|
|
221
|
+
ahash(hash);
|
|
222
|
+
abytes(key, void 0, "key");
|
|
223
|
+
this.iHash = hash.create();
|
|
224
|
+
if (typeof this.iHash.update !== "function") {
|
|
225
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
226
|
+
}
|
|
227
|
+
this.blockLen = this.iHash.blockLen;
|
|
228
|
+
this.outputLen = this.iHash.outputLen;
|
|
229
|
+
const blockLen = this.blockLen;
|
|
230
|
+
const pad = new Uint8Array(blockLen);
|
|
231
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
232
|
+
for (let i = 0; i < pad.length; i++) pad[i] ^= 54;
|
|
233
|
+
this.iHash.update(pad);
|
|
234
|
+
this.oHash = hash.create();
|
|
235
|
+
for (let i = 0; i < pad.length; i++) pad[i] ^= 54 ^ 92;
|
|
236
|
+
this.oHash.update(pad);
|
|
237
|
+
clean(pad);
|
|
238
|
+
}
|
|
239
|
+
update(buf) {
|
|
240
|
+
aexists(this);
|
|
241
|
+
this.iHash.update(buf);
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
digestInto(out) {
|
|
245
|
+
aexists(this);
|
|
246
|
+
abytes(out, this.outputLen, "output");
|
|
247
|
+
this.finished = true;
|
|
248
|
+
this.iHash.digestInto(out);
|
|
249
|
+
this.oHash.update(out);
|
|
250
|
+
this.oHash.digestInto(out);
|
|
251
|
+
this.destroy();
|
|
252
|
+
}
|
|
253
|
+
digest() {
|
|
254
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
255
|
+
this.digestInto(out);
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
_cloneInto(to) {
|
|
259
|
+
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
260
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
261
|
+
to = to;
|
|
262
|
+
to.finished = finished;
|
|
263
|
+
to.destroyed = destroyed;
|
|
264
|
+
to.blockLen = blockLen;
|
|
265
|
+
to.outputLen = outputLen;
|
|
266
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
267
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
268
|
+
return to;
|
|
269
|
+
}
|
|
270
|
+
clone() {
|
|
271
|
+
return this._cloneInto();
|
|
272
|
+
}
|
|
273
|
+
destroy() {
|
|
274
|
+
this.destroyed = true;
|
|
275
|
+
this.oHash.destroy();
|
|
276
|
+
this.iHash.destroy();
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
var hmac = /* @__PURE__ */ __name((hash, key, message) => new _HMAC(hash, key).update(message).digest(), "hmac");
|
|
280
|
+
hmac.create = (hash, key) => new _HMAC(hash, key);
|
|
281
|
+
|
|
282
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/src/hash/u64.js
|
|
283
|
+
var U32_MASK64 = 0xffffffffn;
|
|
284
|
+
var _32n = 32n;
|
|
285
|
+
function fromBig(n, le = false) {
|
|
286
|
+
if (le) {
|
|
287
|
+
return {
|
|
288
|
+
h: Number(n & U32_MASK64),
|
|
289
|
+
l: Number(n >> _32n & U32_MASK64)
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
294
|
+
l: Number(n & U32_MASK64) | 0
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
__name(fromBig, "fromBig");
|
|
298
|
+
function split(lst, le = false) {
|
|
299
|
+
const len = lst.length;
|
|
300
|
+
const Ah = new Uint32Array(len);
|
|
301
|
+
const Al = new Uint32Array(len);
|
|
302
|
+
for (let i = 0; i < len; i++) {
|
|
303
|
+
const { h, l } = fromBig(lst[i], le);
|
|
304
|
+
[Ah[i], Al[i]] = [
|
|
305
|
+
h,
|
|
306
|
+
l
|
|
307
|
+
];
|
|
308
|
+
}
|
|
309
|
+
return [
|
|
310
|
+
Ah,
|
|
311
|
+
Al
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
__name(split, "split");
|
|
315
|
+
|
|
316
|
+
// ../node_modules/.pnpm/@hpke+common@1.10.1/node_modules/@hpke/common/esm/src/hash/sha3.js
|
|
317
|
+
var _0n = 0n;
|
|
318
|
+
var _1n = 1n;
|
|
319
|
+
var _2n = 2n;
|
|
320
|
+
var _7n = 7n;
|
|
321
|
+
var _256n = 256n;
|
|
322
|
+
var _0x71n = 0x71n;
|
|
323
|
+
var SHA3_PI = [];
|
|
324
|
+
var SHA3_ROTL = [];
|
|
325
|
+
var _SHA3_IOTA = [];
|
|
326
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
327
|
+
[x, y] = [
|
|
328
|
+
y,
|
|
329
|
+
(2 * x + 3 * y) % 5
|
|
330
|
+
];
|
|
331
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
332
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
333
|
+
let t = _0n;
|
|
334
|
+
for (let j = 0; j < 7; j++) {
|
|
335
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
336
|
+
if (R & _2n) t ^= _1n << (_1n << BigInt(j)) - _1n;
|
|
337
|
+
}
|
|
338
|
+
_SHA3_IOTA.push(t);
|
|
339
|
+
}
|
|
340
|
+
var IOTAS = split(_SHA3_IOTA, true);
|
|
341
|
+
var SHA3_IOTA_H = IOTAS[0];
|
|
342
|
+
var SHA3_IOTA_L = IOTAS[1];
|
|
343
|
+
|
|
344
|
+
// ../node_modules/.pnpm/@hpke+chacha20poly1305@1.8.0/node_modules/@hpke/chacha20poly1305/esm/src/chacha/utils.js
|
|
345
|
+
function abool(b) {
|
|
346
|
+
if (typeof b !== "boolean") throw new Error(`boolean expected, not ${b}`);
|
|
347
|
+
}
|
|
348
|
+
__name(abool, "abool");
|
|
349
|
+
var wrapCipher = /* @__PURE__ */ __name(/* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
350
|
+
function wrappedCipher(key, ...args) {
|
|
351
|
+
abytes(key, void 0, "key");
|
|
352
|
+
if (!isLE) {
|
|
353
|
+
throw new Error("Non little-endian hardware is not yet supported");
|
|
354
|
+
}
|
|
355
|
+
if (params.nonceLength !== void 0) {
|
|
356
|
+
const nonce = args[0];
|
|
357
|
+
abytes(nonce, params.varSizeNonce ? void 0 : params.nonceLength, "nonce");
|
|
358
|
+
}
|
|
359
|
+
const tagl = params.tagLength;
|
|
360
|
+
if (tagl && args[1] !== void 0) abytes(args[1], void 0, "AAD");
|
|
361
|
+
const cipher = constructor(key, ...args);
|
|
362
|
+
const checkOutput = /* @__PURE__ */ __name((fnLength, output) => {
|
|
363
|
+
if (output !== void 0) {
|
|
364
|
+
if (fnLength !== 2) throw new Error("cipher output not supported");
|
|
365
|
+
abytes(output, void 0, "output");
|
|
366
|
+
}
|
|
367
|
+
}, "checkOutput");
|
|
368
|
+
let called = false;
|
|
369
|
+
const wrCipher = {
|
|
370
|
+
encrypt(data, output) {
|
|
371
|
+
if (called) {
|
|
372
|
+
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
373
|
+
}
|
|
374
|
+
called = true;
|
|
375
|
+
abytes(data);
|
|
376
|
+
checkOutput(cipher.encrypt.length, output);
|
|
377
|
+
return cipher.encrypt(data, output);
|
|
378
|
+
},
|
|
379
|
+
decrypt(data, output) {
|
|
380
|
+
abytes(data);
|
|
381
|
+
if (tagl && data.length < tagl) {
|
|
382
|
+
throw new Error('"ciphertext" expected length bigger than tagLength=' + tagl);
|
|
383
|
+
}
|
|
384
|
+
checkOutput(cipher.decrypt.length, output);
|
|
385
|
+
return cipher.decrypt(data, output);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
return wrCipher;
|
|
389
|
+
}
|
|
390
|
+
__name(wrappedCipher, "wrappedCipher");
|
|
391
|
+
Object.assign(wrappedCipher, params);
|
|
392
|
+
return wrappedCipher;
|
|
393
|
+
}, "wrapCipher");
|
|
394
|
+
function checkOpts(defaults, opts) {
|
|
395
|
+
if (opts == null || typeof opts !== "object") {
|
|
396
|
+
throw new Error("options must be defined");
|
|
397
|
+
}
|
|
398
|
+
const merged = Object.assign(defaults, opts);
|
|
399
|
+
return merged;
|
|
400
|
+
}
|
|
401
|
+
__name(checkOpts, "checkOpts");
|
|
402
|
+
function equalBytes(a, b) {
|
|
403
|
+
if (a.length !== b.length) return false;
|
|
404
|
+
let diff = 0;
|
|
405
|
+
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
406
|
+
return diff === 0;
|
|
407
|
+
}
|
|
408
|
+
__name(equalBytes, "equalBytes");
|
|
409
|
+
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
410
|
+
if (out === void 0) return new Uint8Array(expectedLength);
|
|
411
|
+
if (out.length !== expectedLength) {
|
|
412
|
+
throw new Error('"output" expected Uint8Array of length ' + expectedLength + ", got: " + out.length);
|
|
413
|
+
}
|
|
414
|
+
if (onlyAligned && !isAligned32(out)) {
|
|
415
|
+
throw new Error("invalid output, must be aligned");
|
|
416
|
+
}
|
|
417
|
+
return out;
|
|
418
|
+
}
|
|
419
|
+
__name(getOutput, "getOutput");
|
|
420
|
+
function u64Lengths(dataLength, aadLength, isLE2) {
|
|
421
|
+
abool(isLE2);
|
|
422
|
+
const num = new Uint8Array(16);
|
|
423
|
+
const view = createView(num);
|
|
424
|
+
view.setBigUint64(0, numberToBigint(aadLength), isLE2);
|
|
425
|
+
view.setBigUint64(8, numberToBigint(dataLength), isLE2);
|
|
426
|
+
return num;
|
|
427
|
+
}
|
|
428
|
+
__name(u64Lengths, "u64Lengths");
|
|
429
|
+
function isAligned32(bytes) {
|
|
430
|
+
return bytes.byteOffset % 4 === 0;
|
|
431
|
+
}
|
|
432
|
+
__name(isAligned32, "isAligned32");
|
|
433
|
+
|
|
434
|
+
// ../node_modules/.pnpm/@hpke+chacha20poly1305@1.8.0/node_modules/@hpke/chacha20poly1305/esm/src/chacha/_arx.js
|
|
435
|
+
var _utf8ToBytes = /* @__PURE__ */ __name((str) => Uint8Array.from(str.split("").map((c) => c.charCodeAt(0))), "_utf8ToBytes");
|
|
436
|
+
var sigma16 = _utf8ToBytes("expand 16-byte k");
|
|
437
|
+
var sigma32 = _utf8ToBytes("expand 32-byte k");
|
|
438
|
+
var sigma16_32 = u32(sigma16);
|
|
439
|
+
var sigma32_32 = u32(sigma32);
|
|
440
|
+
function rotl(a, b) {
|
|
441
|
+
return a << b | a >>> 32 - b;
|
|
442
|
+
}
|
|
443
|
+
__name(rotl, "rotl");
|
|
444
|
+
function isAligned322(b) {
|
|
445
|
+
return b.byteOffset % 4 === 0;
|
|
446
|
+
}
|
|
447
|
+
__name(isAligned322, "isAligned32");
|
|
448
|
+
var BLOCK_LEN = 64;
|
|
449
|
+
var BLOCK_LEN32 = 16;
|
|
450
|
+
var MAX_COUNTER = 2 ** 32 - 1;
|
|
451
|
+
var U32_EMPTY = Uint32Array.of();
|
|
452
|
+
function runCipher(core, sigma, key, nonce, data, output, counter, rounds) {
|
|
453
|
+
const len = data.length;
|
|
454
|
+
const block = new Uint8Array(BLOCK_LEN);
|
|
455
|
+
const b32 = u32(block);
|
|
456
|
+
const isAligned = isAligned322(data) && isAligned322(output);
|
|
457
|
+
const d32 = isAligned ? u32(data) : U32_EMPTY;
|
|
458
|
+
const o32 = isAligned ? u32(output) : U32_EMPTY;
|
|
459
|
+
for (let pos = 0; pos < len; counter++) {
|
|
460
|
+
core(sigma, key, nonce, b32, counter, rounds);
|
|
461
|
+
if (counter >= MAX_COUNTER) throw new Error("arx: counter overflow");
|
|
462
|
+
const take = Math.min(BLOCK_LEN, len - pos);
|
|
463
|
+
if (isAligned && take === BLOCK_LEN) {
|
|
464
|
+
const pos32 = pos / 4;
|
|
465
|
+
if (pos % 4 !== 0) throw new Error("arx: invalid block position");
|
|
466
|
+
for (let j = 0, posj; j < BLOCK_LEN32; j++) {
|
|
467
|
+
posj = pos32 + j;
|
|
468
|
+
o32[posj] = d32[posj] ^ b32[j];
|
|
469
|
+
}
|
|
470
|
+
pos += BLOCK_LEN;
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
for (let j = 0, posj; j < take; j++) {
|
|
474
|
+
posj = pos + j;
|
|
475
|
+
output[posj] = data[posj] ^ block[j];
|
|
476
|
+
}
|
|
477
|
+
pos += take;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
__name(runCipher, "runCipher");
|
|
481
|
+
function createCipher(core, opts) {
|
|
482
|
+
const { allowShortKeys, extendNonceFn, counterLength, counterRight, rounds } = checkOpts({
|
|
483
|
+
allowShortKeys: false,
|
|
484
|
+
counterLength: 8,
|
|
485
|
+
counterRight: false,
|
|
486
|
+
rounds: 20
|
|
487
|
+
}, opts);
|
|
488
|
+
if (typeof core !== "function") throw new Error("core must be a function");
|
|
489
|
+
anumber(counterLength);
|
|
490
|
+
anumber(rounds);
|
|
491
|
+
abool(counterRight);
|
|
492
|
+
abool(allowShortKeys);
|
|
493
|
+
return (key, nonce, data, output, counter = 0) => {
|
|
494
|
+
abytes(key, void 0, "key");
|
|
495
|
+
abytes(nonce, void 0, "nonce");
|
|
496
|
+
abytes(data, void 0, "data");
|
|
497
|
+
const len = data.length;
|
|
498
|
+
if (output === void 0) output = new Uint8Array(len);
|
|
499
|
+
abytes(output, void 0, "output");
|
|
500
|
+
anumber(counter);
|
|
501
|
+
if (counter < 0 || counter >= MAX_COUNTER) {
|
|
502
|
+
throw new Error("arx: counter overflow");
|
|
503
|
+
}
|
|
504
|
+
if (output.length < len) {
|
|
505
|
+
throw new Error(`arx: output (${output.length}) is shorter than data (${len})`);
|
|
506
|
+
}
|
|
507
|
+
const toClean = [];
|
|
508
|
+
const l = key.length;
|
|
509
|
+
let k;
|
|
510
|
+
let sigma;
|
|
511
|
+
if (l === 32) {
|
|
512
|
+
toClean.push(k = copyBytes(key));
|
|
513
|
+
sigma = sigma32_32;
|
|
514
|
+
} else if (l === 16 && allowShortKeys) {
|
|
515
|
+
k = new Uint8Array(32);
|
|
516
|
+
k.set(key);
|
|
517
|
+
k.set(key, 16);
|
|
518
|
+
sigma = sigma16_32;
|
|
519
|
+
toClean.push(k);
|
|
520
|
+
} else {
|
|
521
|
+
abytes(key, 32, "arx key");
|
|
522
|
+
throw new Error("invalid key size");
|
|
523
|
+
}
|
|
524
|
+
if (!isAligned322(nonce)) toClean.push(nonce = copyBytes(nonce));
|
|
525
|
+
const k32 = u32(k);
|
|
526
|
+
if (extendNonceFn) {
|
|
527
|
+
if (nonce.length !== 24) {
|
|
528
|
+
throw new Error(`arx: extended nonce must be 24 bytes`);
|
|
529
|
+
}
|
|
530
|
+
extendNonceFn(sigma, k32, u32(nonce.subarray(0, 16)), k32);
|
|
531
|
+
nonce = nonce.subarray(16);
|
|
532
|
+
}
|
|
533
|
+
const nonceNcLen = 16 - counterLength;
|
|
534
|
+
if (nonceNcLen !== nonce.length) {
|
|
535
|
+
throw new Error(`arx: nonce must be ${nonceNcLen} or 16 bytes`);
|
|
536
|
+
}
|
|
537
|
+
if (nonceNcLen !== 12) {
|
|
538
|
+
const nc = new Uint8Array(12);
|
|
539
|
+
nc.set(nonce, counterRight ? 0 : 12 - nonce.length);
|
|
540
|
+
nonce = nc;
|
|
541
|
+
toClean.push(nonce);
|
|
542
|
+
}
|
|
543
|
+
const n32 = u32(nonce);
|
|
544
|
+
runCipher(core, sigma, k32, n32, data, output, counter, rounds);
|
|
545
|
+
clean(...toClean);
|
|
546
|
+
return output;
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
__name(createCipher, "createCipher");
|
|
550
|
+
|
|
551
|
+
// ../node_modules/.pnpm/@hpke+chacha20poly1305@1.8.0/node_modules/@hpke/chacha20poly1305/esm/src/chacha/_poly1305.js
|
|
552
|
+
function u8to16(a, i) {
|
|
553
|
+
return a[i++] & 255 | (a[i++] & 255) << 8;
|
|
554
|
+
}
|
|
555
|
+
__name(u8to16, "u8to16");
|
|
556
|
+
var Poly1305 = class {
|
|
557
|
+
static {
|
|
558
|
+
__name(this, "Poly1305");
|
|
559
|
+
}
|
|
560
|
+
// Can be speed-up using BigUint64Array, at the cost of complexity
|
|
561
|
+
constructor(key) {
|
|
562
|
+
Object.defineProperty(this, "blockLen", {
|
|
563
|
+
enumerable: true,
|
|
564
|
+
configurable: true,
|
|
565
|
+
writable: true,
|
|
566
|
+
value: 16
|
|
567
|
+
});
|
|
568
|
+
Object.defineProperty(this, "outputLen", {
|
|
569
|
+
enumerable: true,
|
|
570
|
+
configurable: true,
|
|
571
|
+
writable: true,
|
|
572
|
+
value: 16
|
|
573
|
+
});
|
|
574
|
+
Object.defineProperty(this, "buffer", {
|
|
575
|
+
enumerable: true,
|
|
576
|
+
configurable: true,
|
|
577
|
+
writable: true,
|
|
578
|
+
value: new Uint8Array(16)
|
|
579
|
+
});
|
|
580
|
+
Object.defineProperty(this, "r", {
|
|
581
|
+
enumerable: true,
|
|
582
|
+
configurable: true,
|
|
583
|
+
writable: true,
|
|
584
|
+
value: new Uint16Array(10)
|
|
585
|
+
});
|
|
586
|
+
Object.defineProperty(this, "h", {
|
|
587
|
+
enumerable: true,
|
|
588
|
+
configurable: true,
|
|
589
|
+
writable: true,
|
|
590
|
+
value: new Uint16Array(10)
|
|
591
|
+
});
|
|
592
|
+
Object.defineProperty(this, "pad", {
|
|
593
|
+
enumerable: true,
|
|
594
|
+
configurable: true,
|
|
595
|
+
writable: true,
|
|
596
|
+
value: new Uint16Array(8)
|
|
597
|
+
});
|
|
598
|
+
Object.defineProperty(this, "pos", {
|
|
599
|
+
enumerable: true,
|
|
600
|
+
configurable: true,
|
|
601
|
+
writable: true,
|
|
602
|
+
value: 0
|
|
603
|
+
});
|
|
604
|
+
Object.defineProperty(this, "finished", {
|
|
605
|
+
enumerable: true,
|
|
606
|
+
configurable: true,
|
|
607
|
+
writable: true,
|
|
608
|
+
value: false
|
|
609
|
+
});
|
|
610
|
+
key = copyBytes(abytes(key, 32, "key"));
|
|
611
|
+
const t0 = u8to16(key, 0);
|
|
612
|
+
const t1 = u8to16(key, 2);
|
|
613
|
+
const t2 = u8to16(key, 4);
|
|
614
|
+
const t3 = u8to16(key, 6);
|
|
615
|
+
const t4 = u8to16(key, 8);
|
|
616
|
+
const t5 = u8to16(key, 10);
|
|
617
|
+
const t6 = u8to16(key, 12);
|
|
618
|
+
const t7 = u8to16(key, 14);
|
|
619
|
+
this.r[0] = t0 & 8191;
|
|
620
|
+
this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
|
|
621
|
+
this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
|
|
622
|
+
this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
|
|
623
|
+
this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
|
|
624
|
+
this.r[5] = t4 >>> 1 & 8190;
|
|
625
|
+
this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
|
|
626
|
+
this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
|
|
627
|
+
this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
|
|
628
|
+
this.r[9] = t7 >>> 5 & 127;
|
|
629
|
+
for (let i = 0; i < 8; i++) this.pad[i] = u8to16(key, 16 + 2 * i);
|
|
630
|
+
}
|
|
631
|
+
process(data, offset, isLast = false) {
|
|
632
|
+
const hibit = isLast ? 0 : 1 << 11;
|
|
633
|
+
const { h, r } = this;
|
|
634
|
+
const r0 = r[0];
|
|
635
|
+
const r1 = r[1];
|
|
636
|
+
const r2 = r[2];
|
|
637
|
+
const r3 = r[3];
|
|
638
|
+
const r4 = r[4];
|
|
639
|
+
const r5 = r[5];
|
|
640
|
+
const r6 = r[6];
|
|
641
|
+
const r7 = r[7];
|
|
642
|
+
const r8 = r[8];
|
|
643
|
+
const r9 = r[9];
|
|
644
|
+
const t0 = u8to16(data, offset + 0);
|
|
645
|
+
const t1 = u8to16(data, offset + 2);
|
|
646
|
+
const t2 = u8to16(data, offset + 4);
|
|
647
|
+
const t3 = u8to16(data, offset + 6);
|
|
648
|
+
const t4 = u8to16(data, offset + 8);
|
|
649
|
+
const t5 = u8to16(data, offset + 10);
|
|
650
|
+
const t6 = u8to16(data, offset + 12);
|
|
651
|
+
const t7 = u8to16(data, offset + 14);
|
|
652
|
+
const h0 = h[0] + (t0 & 8191);
|
|
653
|
+
const h1 = h[1] + ((t0 >>> 13 | t1 << 3) & 8191);
|
|
654
|
+
const h2 = h[2] + ((t1 >>> 10 | t2 << 6) & 8191);
|
|
655
|
+
const h3 = h[3] + ((t2 >>> 7 | t3 << 9) & 8191);
|
|
656
|
+
const h4 = h[4] + ((t3 >>> 4 | t4 << 12) & 8191);
|
|
657
|
+
const h5 = h[5] + (t4 >>> 1 & 8191);
|
|
658
|
+
const h6 = h[6] + ((t4 >>> 14 | t5 << 2) & 8191);
|
|
659
|
+
const h7 = h[7] + ((t5 >>> 11 | t6 << 5) & 8191);
|
|
660
|
+
const h8 = h[8] + ((t6 >>> 8 | t7 << 8) & 8191);
|
|
661
|
+
const h9 = h[9] + (t7 >>> 5 | hibit);
|
|
662
|
+
let c = 0;
|
|
663
|
+
let d0 = c + h0 * r0 + h1 * (5 * r9) + h2 * (5 * r8) + h3 * (5 * r7) + h4 * (5 * r6);
|
|
664
|
+
c = d0 >>> 13;
|
|
665
|
+
d0 &= 8191;
|
|
666
|
+
d0 += h5 * (5 * r5) + h6 * (5 * r4) + h7 * (5 * r3) + h8 * (5 * r2) + h9 * (5 * r1);
|
|
667
|
+
c += d0 >>> 13;
|
|
668
|
+
d0 &= 8191;
|
|
669
|
+
let d1 = c + h0 * r1 + h1 * r0 + h2 * (5 * r9) + h3 * (5 * r8) + h4 * (5 * r7);
|
|
670
|
+
c = d1 >>> 13;
|
|
671
|
+
d1 &= 8191;
|
|
672
|
+
d1 += h5 * (5 * r6) + h6 * (5 * r5) + h7 * (5 * r4) + h8 * (5 * r3) + h9 * (5 * r2);
|
|
673
|
+
c += d1 >>> 13;
|
|
674
|
+
d1 &= 8191;
|
|
675
|
+
let d2 = c + h0 * r2 + h1 * r1 + h2 * r0 + h3 * (5 * r9) + h4 * (5 * r8);
|
|
676
|
+
c = d2 >>> 13;
|
|
677
|
+
d2 &= 8191;
|
|
678
|
+
d2 += h5 * (5 * r7) + h6 * (5 * r6) + h7 * (5 * r5) + h8 * (5 * r4) + h9 * (5 * r3);
|
|
679
|
+
c += d2 >>> 13;
|
|
680
|
+
d2 &= 8191;
|
|
681
|
+
let d3 = c + h0 * r3 + h1 * r2 + h2 * r1 + h3 * r0 + h4 * (5 * r9);
|
|
682
|
+
c = d3 >>> 13;
|
|
683
|
+
d3 &= 8191;
|
|
684
|
+
d3 += h5 * (5 * r8) + h6 * (5 * r7) + h7 * (5 * r6) + h8 * (5 * r5) + h9 * (5 * r4);
|
|
685
|
+
c += d3 >>> 13;
|
|
686
|
+
d3 &= 8191;
|
|
687
|
+
let d4 = c + h0 * r4 + h1 * r3 + h2 * r2 + h3 * r1 + h4 * r0;
|
|
688
|
+
c = d4 >>> 13;
|
|
689
|
+
d4 &= 8191;
|
|
690
|
+
d4 += h5 * (5 * r9) + h6 * (5 * r8) + h7 * (5 * r7) + h8 * (5 * r6) + h9 * (5 * r5);
|
|
691
|
+
c += d4 >>> 13;
|
|
692
|
+
d4 &= 8191;
|
|
693
|
+
let d5 = c + h0 * r5 + h1 * r4 + h2 * r3 + h3 * r2 + h4 * r1;
|
|
694
|
+
c = d5 >>> 13;
|
|
695
|
+
d5 &= 8191;
|
|
696
|
+
d5 += h5 * r0 + h6 * (5 * r9) + h7 * (5 * r8) + h8 * (5 * r7) + h9 * (5 * r6);
|
|
697
|
+
c += d5 >>> 13;
|
|
698
|
+
d5 &= 8191;
|
|
699
|
+
let d6 = c + h0 * r6 + h1 * r5 + h2 * r4 + h3 * r3 + h4 * r2;
|
|
700
|
+
c = d6 >>> 13;
|
|
701
|
+
d6 &= 8191;
|
|
702
|
+
d6 += h5 * r1 + h6 * r0 + h7 * (5 * r9) + h8 * (5 * r8) + h9 * (5 * r7);
|
|
703
|
+
c += d6 >>> 13;
|
|
704
|
+
d6 &= 8191;
|
|
705
|
+
let d7 = c + h0 * r7 + h1 * r6 + h2 * r5 + h3 * r4 + h4 * r3;
|
|
706
|
+
c = d7 >>> 13;
|
|
707
|
+
d7 &= 8191;
|
|
708
|
+
d7 += h5 * r2 + h6 * r1 + h7 * r0 + h8 * (5 * r9) + h9 * (5 * r8);
|
|
709
|
+
c += d7 >>> 13;
|
|
710
|
+
d7 &= 8191;
|
|
711
|
+
let d8 = c + h0 * r8 + h1 * r7 + h2 * r6 + h3 * r5 + h4 * r4;
|
|
712
|
+
c = d8 >>> 13;
|
|
713
|
+
d8 &= 8191;
|
|
714
|
+
d8 += h5 * r3 + h6 * r2 + h7 * r1 + h8 * r0 + h9 * (5 * r9);
|
|
715
|
+
c += d8 >>> 13;
|
|
716
|
+
d8 &= 8191;
|
|
717
|
+
let d9 = c + h0 * r9 + h1 * r8 + h2 * r7 + h3 * r6 + h4 * r5;
|
|
718
|
+
c = d9 >>> 13;
|
|
719
|
+
d9 &= 8191;
|
|
720
|
+
d9 += h5 * r4 + h6 * r3 + h7 * r2 + h8 * r1 + h9 * r0;
|
|
721
|
+
c += d9 >>> 13;
|
|
722
|
+
d9 &= 8191;
|
|
723
|
+
c = (c << 2) + c | 0;
|
|
724
|
+
c = c + d0 | 0;
|
|
725
|
+
d0 = c & 8191;
|
|
726
|
+
c = c >>> 13;
|
|
727
|
+
d1 += c;
|
|
728
|
+
h[0] = d0;
|
|
729
|
+
h[1] = d1;
|
|
730
|
+
h[2] = d2;
|
|
731
|
+
h[3] = d3;
|
|
732
|
+
h[4] = d4;
|
|
733
|
+
h[5] = d5;
|
|
734
|
+
h[6] = d6;
|
|
735
|
+
h[7] = d7;
|
|
736
|
+
h[8] = d8;
|
|
737
|
+
h[9] = d9;
|
|
738
|
+
}
|
|
739
|
+
finalize() {
|
|
740
|
+
const { h, pad } = this;
|
|
741
|
+
const g = new Uint16Array(10);
|
|
742
|
+
let c = h[1] >>> 13;
|
|
743
|
+
h[1] &= 8191;
|
|
744
|
+
for (let i = 2; i < 10; i++) {
|
|
745
|
+
h[i] += c;
|
|
746
|
+
c = h[i] >>> 13;
|
|
747
|
+
h[i] &= 8191;
|
|
748
|
+
}
|
|
749
|
+
h[0] += c * 5;
|
|
750
|
+
c = h[0] >>> 13;
|
|
751
|
+
h[0] &= 8191;
|
|
752
|
+
h[1] += c;
|
|
753
|
+
c = h[1] >>> 13;
|
|
754
|
+
h[1] &= 8191;
|
|
755
|
+
h[2] += c;
|
|
756
|
+
g[0] = h[0] + 5;
|
|
757
|
+
c = g[0] >>> 13;
|
|
758
|
+
g[0] &= 8191;
|
|
759
|
+
for (let i = 1; i < 10; i++) {
|
|
760
|
+
g[i] = h[i] + c;
|
|
761
|
+
c = g[i] >>> 13;
|
|
762
|
+
g[i] &= 8191;
|
|
763
|
+
}
|
|
764
|
+
g[9] -= 1 << 13;
|
|
765
|
+
let mask = (c ^ 1) - 1;
|
|
766
|
+
for (let i = 0; i < 10; i++) g[i] &= mask;
|
|
767
|
+
mask = ~mask;
|
|
768
|
+
for (let i = 0; i < 10; i++) h[i] = h[i] & mask | g[i];
|
|
769
|
+
h[0] = (h[0] | h[1] << 13) & 65535;
|
|
770
|
+
h[1] = (h[1] >>> 3 | h[2] << 10) & 65535;
|
|
771
|
+
h[2] = (h[2] >>> 6 | h[3] << 7) & 65535;
|
|
772
|
+
h[3] = (h[3] >>> 9 | h[4] << 4) & 65535;
|
|
773
|
+
h[4] = (h[4] >>> 12 | h[5] << 1 | h[6] << 14) & 65535;
|
|
774
|
+
h[5] = (h[6] >>> 2 | h[7] << 11) & 65535;
|
|
775
|
+
h[6] = (h[7] >>> 5 | h[8] << 8) & 65535;
|
|
776
|
+
h[7] = (h[8] >>> 8 | h[9] << 5) & 65535;
|
|
777
|
+
let f = h[0] + pad[0];
|
|
778
|
+
h[0] = f & 65535;
|
|
779
|
+
for (let i = 1; i < 8; i++) {
|
|
780
|
+
f = (h[i] + pad[i] | 0) + (f >>> 16) | 0;
|
|
781
|
+
h[i] = f & 65535;
|
|
782
|
+
}
|
|
783
|
+
clean(g);
|
|
784
|
+
}
|
|
785
|
+
update(data) {
|
|
786
|
+
aexists(this);
|
|
787
|
+
abytes(data);
|
|
788
|
+
data = copyBytes(data);
|
|
789
|
+
const { buffer, blockLen } = this;
|
|
790
|
+
const len = data.length;
|
|
791
|
+
for (let pos = 0; pos < len; ) {
|
|
792
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
793
|
+
if (take === blockLen) {
|
|
794
|
+
for (; blockLen <= len - pos; pos += blockLen) this.process(data, pos);
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
798
|
+
this.pos += take;
|
|
799
|
+
pos += take;
|
|
800
|
+
if (this.pos === blockLen) {
|
|
801
|
+
this.process(buffer, 0, false);
|
|
802
|
+
this.pos = 0;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
destroy() {
|
|
808
|
+
clean(this.h, this.r, this.buffer, this.pad);
|
|
809
|
+
}
|
|
810
|
+
digestInto(out) {
|
|
811
|
+
aexists(this);
|
|
812
|
+
aoutput(out, this);
|
|
813
|
+
this.finished = true;
|
|
814
|
+
const { buffer, h } = this;
|
|
815
|
+
let { pos } = this;
|
|
816
|
+
if (pos) {
|
|
817
|
+
buffer[pos++] = 1;
|
|
818
|
+
for (; pos < 16; pos++) buffer[pos] = 0;
|
|
819
|
+
this.process(buffer, 0, true);
|
|
820
|
+
}
|
|
821
|
+
this.finalize();
|
|
822
|
+
let opos = 0;
|
|
823
|
+
for (let i = 0; i < 8; i++) {
|
|
824
|
+
out[opos++] = h[i] >>> 0;
|
|
825
|
+
out[opos++] = h[i] >>> 8;
|
|
826
|
+
}
|
|
827
|
+
return out;
|
|
828
|
+
}
|
|
829
|
+
digest() {
|
|
830
|
+
const { buffer, outputLen } = this;
|
|
831
|
+
this.digestInto(buffer);
|
|
832
|
+
const res = buffer.slice(0, outputLen);
|
|
833
|
+
this.destroy();
|
|
834
|
+
return res;
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
function wrapConstructorWithKey(hashCons) {
|
|
838
|
+
const hashC = /* @__PURE__ */ __name((msg, key) => hashCons(key).update(msg).digest(), "hashC");
|
|
839
|
+
const tmp = hashCons(new Uint8Array(32));
|
|
840
|
+
hashC.outputLen = tmp.outputLen;
|
|
841
|
+
hashC.blockLen = tmp.blockLen;
|
|
842
|
+
hashC.create = (key) => hashCons(key);
|
|
843
|
+
return hashC;
|
|
844
|
+
}
|
|
845
|
+
__name(wrapConstructorWithKey, "wrapConstructorWithKey");
|
|
846
|
+
var poly1305 = /* @__PURE__ */ (() => wrapConstructorWithKey((key) => new Poly1305(key)))();
|
|
847
|
+
|
|
848
|
+
// ../node_modules/.pnpm/@hpke+chacha20poly1305@1.8.0/node_modules/@hpke/chacha20poly1305/esm/src/chacha/chacha.js
|
|
849
|
+
function chachaCore(s, k, n, out, cnt, rounds = 20) {
|
|
850
|
+
const 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];
|
|
851
|
+
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;
|
|
852
|
+
for (let r = 0; r < rounds; r += 2) {
|
|
853
|
+
x00 = x00 + x04 | 0;
|
|
854
|
+
x12 = rotl(x12 ^ x00, 16);
|
|
855
|
+
x08 = x08 + x12 | 0;
|
|
856
|
+
x04 = rotl(x04 ^ x08, 12);
|
|
857
|
+
x00 = x00 + x04 | 0;
|
|
858
|
+
x12 = rotl(x12 ^ x00, 8);
|
|
859
|
+
x08 = x08 + x12 | 0;
|
|
860
|
+
x04 = rotl(x04 ^ x08, 7);
|
|
861
|
+
x01 = x01 + x05 | 0;
|
|
862
|
+
x13 = rotl(x13 ^ x01, 16);
|
|
863
|
+
x09 = x09 + x13 | 0;
|
|
864
|
+
x05 = rotl(x05 ^ x09, 12);
|
|
865
|
+
x01 = x01 + x05 | 0;
|
|
866
|
+
x13 = rotl(x13 ^ x01, 8);
|
|
867
|
+
x09 = x09 + x13 | 0;
|
|
868
|
+
x05 = rotl(x05 ^ x09, 7);
|
|
869
|
+
x02 = x02 + x06 | 0;
|
|
870
|
+
x14 = rotl(x14 ^ x02, 16);
|
|
871
|
+
x10 = x10 + x14 | 0;
|
|
872
|
+
x06 = rotl(x06 ^ x10, 12);
|
|
873
|
+
x02 = x02 + x06 | 0;
|
|
874
|
+
x14 = rotl(x14 ^ x02, 8);
|
|
875
|
+
x10 = x10 + x14 | 0;
|
|
876
|
+
x06 = rotl(x06 ^ x10, 7);
|
|
877
|
+
x03 = x03 + x07 | 0;
|
|
878
|
+
x15 = rotl(x15 ^ x03, 16);
|
|
879
|
+
x11 = x11 + x15 | 0;
|
|
880
|
+
x07 = rotl(x07 ^ x11, 12);
|
|
881
|
+
x03 = x03 + x07 | 0;
|
|
882
|
+
x15 = rotl(x15 ^ x03, 8);
|
|
883
|
+
x11 = x11 + x15 | 0;
|
|
884
|
+
x07 = rotl(x07 ^ x11, 7);
|
|
885
|
+
x00 = x00 + x05 | 0;
|
|
886
|
+
x15 = rotl(x15 ^ x00, 16);
|
|
887
|
+
x10 = x10 + x15 | 0;
|
|
888
|
+
x05 = rotl(x05 ^ x10, 12);
|
|
889
|
+
x00 = x00 + x05 | 0;
|
|
890
|
+
x15 = rotl(x15 ^ x00, 8);
|
|
891
|
+
x10 = x10 + x15 | 0;
|
|
892
|
+
x05 = rotl(x05 ^ x10, 7);
|
|
893
|
+
x01 = x01 + x06 | 0;
|
|
894
|
+
x12 = rotl(x12 ^ x01, 16);
|
|
895
|
+
x11 = x11 + x12 | 0;
|
|
896
|
+
x06 = rotl(x06 ^ x11, 12);
|
|
897
|
+
x01 = x01 + x06 | 0;
|
|
898
|
+
x12 = rotl(x12 ^ x01, 8);
|
|
899
|
+
x11 = x11 + x12 | 0;
|
|
900
|
+
x06 = rotl(x06 ^ x11, 7);
|
|
901
|
+
x02 = x02 + x07 | 0;
|
|
902
|
+
x13 = rotl(x13 ^ x02, 16);
|
|
903
|
+
x08 = x08 + x13 | 0;
|
|
904
|
+
x07 = rotl(x07 ^ x08, 12);
|
|
905
|
+
x02 = x02 + x07 | 0;
|
|
906
|
+
x13 = rotl(x13 ^ x02, 8);
|
|
907
|
+
x08 = x08 + x13 | 0;
|
|
908
|
+
x07 = rotl(x07 ^ x08, 7);
|
|
909
|
+
x03 = x03 + x04 | 0;
|
|
910
|
+
x14 = rotl(x14 ^ x03, 16);
|
|
911
|
+
x09 = x09 + x14 | 0;
|
|
912
|
+
x04 = rotl(x04 ^ x09, 12);
|
|
913
|
+
x03 = x03 + x04 | 0;
|
|
914
|
+
x14 = rotl(x14 ^ x03, 8);
|
|
915
|
+
x09 = x09 + x14 | 0;
|
|
916
|
+
x04 = rotl(x04 ^ x09, 7);
|
|
917
|
+
}
|
|
918
|
+
let oi = 0;
|
|
919
|
+
out[oi++] = y00 + x00 | 0;
|
|
920
|
+
out[oi++] = y01 + x01 | 0;
|
|
921
|
+
out[oi++] = y02 + x02 | 0;
|
|
922
|
+
out[oi++] = y03 + x03 | 0;
|
|
923
|
+
out[oi++] = y04 + x04 | 0;
|
|
924
|
+
out[oi++] = y05 + x05 | 0;
|
|
925
|
+
out[oi++] = y06 + x06 | 0;
|
|
926
|
+
out[oi++] = y07 + x07 | 0;
|
|
927
|
+
out[oi++] = y08 + x08 | 0;
|
|
928
|
+
out[oi++] = y09 + x09 | 0;
|
|
929
|
+
out[oi++] = y10 + x10 | 0;
|
|
930
|
+
out[oi++] = y11 + x11 | 0;
|
|
931
|
+
out[oi++] = y12 + x12 | 0;
|
|
932
|
+
out[oi++] = y13 + x13 | 0;
|
|
933
|
+
out[oi++] = y14 + x14 | 0;
|
|
934
|
+
out[oi++] = y15 + x15 | 0;
|
|
935
|
+
}
|
|
936
|
+
__name(chachaCore, "chachaCore");
|
|
937
|
+
var chacha20 = /* @__PURE__ */ createCipher(chachaCore, {
|
|
938
|
+
counterRight: false,
|
|
939
|
+
counterLength: 4,
|
|
940
|
+
allowShortKeys: false
|
|
941
|
+
});
|
|
942
|
+
var ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
|
|
943
|
+
var updatePadded = /* @__PURE__ */ __name((h, msg) => {
|
|
944
|
+
h.update(msg);
|
|
945
|
+
const leftover = msg.length % 16;
|
|
946
|
+
if (leftover) h.update(ZEROS16.subarray(leftover));
|
|
947
|
+
}, "updatePadded");
|
|
948
|
+
var ZEROS32 = /* @__PURE__ */ new Uint8Array(32);
|
|
949
|
+
function computeTag(fn, key, nonce, ciphertext, AAD) {
|
|
950
|
+
if (AAD !== void 0) abytes(AAD, void 0, "AAD");
|
|
951
|
+
const authKey = fn(key, nonce, ZEROS32);
|
|
952
|
+
const lengths = u64Lengths(ciphertext.length, AAD ? AAD.length : 0, true);
|
|
953
|
+
const h = poly1305.create(authKey);
|
|
954
|
+
if (AAD) updatePadded(h, AAD);
|
|
955
|
+
updatePadded(h, ciphertext);
|
|
956
|
+
h.update(lengths);
|
|
957
|
+
const res = h.digest();
|
|
958
|
+
clean(authKey, lengths);
|
|
959
|
+
return res;
|
|
960
|
+
}
|
|
961
|
+
__name(computeTag, "computeTag");
|
|
962
|
+
var _poly1305_aead = /* @__PURE__ */ __name((xorStream) => (key, nonce, AAD) => {
|
|
963
|
+
const tagLength = 16;
|
|
964
|
+
return {
|
|
965
|
+
encrypt(plaintext, output) {
|
|
966
|
+
const plength = plaintext.length;
|
|
967
|
+
output = getOutput(plength + tagLength, output, false);
|
|
968
|
+
output.set(plaintext);
|
|
969
|
+
const oPlain = output.subarray(0, -tagLength);
|
|
970
|
+
xorStream(key, nonce, oPlain, oPlain, 1);
|
|
971
|
+
const tag = computeTag(xorStream, key, nonce, oPlain, AAD);
|
|
972
|
+
output.set(tag, plength);
|
|
973
|
+
clean(tag);
|
|
974
|
+
return output;
|
|
975
|
+
},
|
|
976
|
+
decrypt(ciphertext, output) {
|
|
977
|
+
output = getOutput(ciphertext.length - tagLength, output, false);
|
|
978
|
+
const data = ciphertext.subarray(0, -tagLength);
|
|
979
|
+
const passedTag = ciphertext.subarray(-tagLength);
|
|
980
|
+
const tag = computeTag(xorStream, key, nonce, data, AAD);
|
|
981
|
+
if (!equalBytes(passedTag, tag)) throw new Error("invalid tag");
|
|
982
|
+
output.set(ciphertext.subarray(0, -tagLength));
|
|
983
|
+
xorStream(key, nonce, output, output, 1);
|
|
984
|
+
clean(tag);
|
|
985
|
+
return output;
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
}, "_poly1305_aead");
|
|
989
|
+
var chacha20poly1305 = /* @__PURE__ */ wrapCipher({
|
|
990
|
+
blockSize: 64,
|
|
991
|
+
nonceLength: 12,
|
|
992
|
+
tagLength: 16
|
|
993
|
+
}, _poly1305_aead(chacha20));
|
|
994
|
+
|
|
995
|
+
// ../node_modules/.pnpm/@hpke+core@1.9.0/node_modules/@hpke/core/esm/src/exporterContext.js
|
|
996
|
+
var LABEL_SEC = new Uint8Array([
|
|
997
|
+
115,
|
|
998
|
+
101,
|
|
999
|
+
99
|
|
1000
|
+
]);
|
|
1001
|
+
|
|
1002
|
+
// ../node_modules/.pnpm/@hpke+core@1.9.0/node_modules/@hpke/core/esm/src/mutex.js
|
|
1003
|
+
var _Mutex_locked;
|
|
1004
|
+
_Mutex_locked = /* @__PURE__ */ new WeakMap();
|
|
1005
|
+
|
|
1006
|
+
// ../node_modules/.pnpm/@hpke+core@1.9.0/node_modules/@hpke/core/esm/src/recipientContext.js
|
|
1007
|
+
var _RecipientContextImpl_mutex;
|
|
1008
|
+
_RecipientContextImpl_mutex = /* @__PURE__ */ new WeakMap();
|
|
1009
|
+
|
|
1010
|
+
// ../node_modules/.pnpm/@hpke+core@1.9.0/node_modules/@hpke/core/esm/src/senderContext.js
|
|
1011
|
+
var _SenderContextImpl_mutex;
|
|
1012
|
+
_SenderContextImpl_mutex = /* @__PURE__ */ new WeakMap();
|
|
1013
|
+
|
|
1014
|
+
// ../node_modules/.pnpm/@hpke+core@1.9.0/node_modules/@hpke/core/esm/src/cipherSuiteNative.js
|
|
1015
|
+
var LABEL_BASE_NONCE = new Uint8Array([
|
|
1016
|
+
98,
|
|
1017
|
+
97,
|
|
1018
|
+
115,
|
|
1019
|
+
101,
|
|
1020
|
+
95,
|
|
1021
|
+
110,
|
|
1022
|
+
111,
|
|
1023
|
+
110,
|
|
1024
|
+
99,
|
|
1025
|
+
101
|
|
1026
|
+
]);
|
|
1027
|
+
var LABEL_EXP = new Uint8Array([
|
|
1028
|
+
101,
|
|
1029
|
+
120,
|
|
1030
|
+
112
|
|
1031
|
+
]);
|
|
1032
|
+
var LABEL_INFO_HASH = new Uint8Array([
|
|
1033
|
+
105,
|
|
1034
|
+
110,
|
|
1035
|
+
102,
|
|
1036
|
+
111,
|
|
1037
|
+
95,
|
|
1038
|
+
104,
|
|
1039
|
+
97,
|
|
1040
|
+
115,
|
|
1041
|
+
104
|
|
1042
|
+
]);
|
|
1043
|
+
var LABEL_KEY = new Uint8Array([
|
|
1044
|
+
107,
|
|
1045
|
+
101,
|
|
1046
|
+
121
|
|
1047
|
+
]);
|
|
1048
|
+
var LABEL_PSK_ID_HASH = new Uint8Array([
|
|
1049
|
+
112,
|
|
1050
|
+
115,
|
|
1051
|
+
107,
|
|
1052
|
+
95,
|
|
1053
|
+
105,
|
|
1054
|
+
100,
|
|
1055
|
+
95,
|
|
1056
|
+
104,
|
|
1057
|
+
97,
|
|
1058
|
+
115,
|
|
1059
|
+
104
|
|
1060
|
+
]);
|
|
1061
|
+
var LABEL_SECRET = new Uint8Array([
|
|
1062
|
+
115,
|
|
1063
|
+
101,
|
|
1064
|
+
99,
|
|
1065
|
+
114,
|
|
1066
|
+
101,
|
|
1067
|
+
116
|
|
1068
|
+
]);
|
|
1069
|
+
var SUITE_ID_HEADER_HPKE = new Uint8Array([
|
|
1070
|
+
72,
|
|
1071
|
+
80,
|
|
1072
|
+
75,
|
|
1073
|
+
69,
|
|
1074
|
+
0,
|
|
1075
|
+
0,
|
|
1076
|
+
0,
|
|
1077
|
+
0,
|
|
1078
|
+
0,
|
|
1079
|
+
0
|
|
1080
|
+
]);
|
|
1081
|
+
|
|
1082
|
+
// ../node_modules/.pnpm/@hpke+core@1.9.0/node_modules/@hpke/core/esm/src/kems/dhkemPrimitives/x25519.js
|
|
1083
|
+
var PKCS8_ALG_ID_X25519 = new Uint8Array([
|
|
1084
|
+
48,
|
|
1085
|
+
46,
|
|
1086
|
+
2,
|
|
1087
|
+
1,
|
|
1088
|
+
0,
|
|
1089
|
+
48,
|
|
1090
|
+
5,
|
|
1091
|
+
6,
|
|
1092
|
+
3,
|
|
1093
|
+
43,
|
|
1094
|
+
101,
|
|
1095
|
+
110,
|
|
1096
|
+
4,
|
|
1097
|
+
34,
|
|
1098
|
+
4,
|
|
1099
|
+
32
|
|
1100
|
+
]);
|
|
1101
|
+
|
|
1102
|
+
// ../node_modules/.pnpm/@hpke+core@1.9.0/node_modules/@hpke/core/esm/src/kems/dhkemPrimitives/x448.js
|
|
1103
|
+
var PKCS8_ALG_ID_X448 = new Uint8Array([
|
|
1104
|
+
48,
|
|
1105
|
+
70,
|
|
1106
|
+
2,
|
|
1107
|
+
1,
|
|
1108
|
+
0,
|
|
1109
|
+
48,
|
|
1110
|
+
5,
|
|
1111
|
+
6,
|
|
1112
|
+
3,
|
|
1113
|
+
43,
|
|
1114
|
+
101,
|
|
1115
|
+
111,
|
|
1116
|
+
4,
|
|
1117
|
+
58,
|
|
1118
|
+
4,
|
|
1119
|
+
56
|
|
1120
|
+
]);
|
|
1121
|
+
|
|
19
1122
|
// ../core/dist/index.js
|
|
20
1123
|
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
21
1124
|
var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
|
|
@@ -44,12 +1147,12 @@ async function digester() {
|
|
|
44
1147
|
const nodeish = runtime.process?.versions?.node !== void 0 || runtime.process?.versions?.bun !== void 0;
|
|
45
1148
|
if (nodeish) {
|
|
46
1149
|
try {
|
|
47
|
-
const
|
|
1150
|
+
const mod2 = await import(
|
|
48
1151
|
/* @vite-ignore */
|
|
49
1152
|
`${"node:"}crypto`
|
|
50
1153
|
);
|
|
51
|
-
if (typeof
|
|
52
|
-
const createHash =
|
|
1154
|
+
if (typeof mod2.createHash === "function") {
|
|
1155
|
+
const createHash = mod2.createHash;
|
|
53
1156
|
hasher = /* @__PURE__ */ __name((input) => new Uint8Array(createHash("sha256").update(input).digest()), "hasher");
|
|
54
1157
|
return hasher;
|
|
55
1158
|
}
|
|
@@ -122,6 +1225,12 @@ async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.
|
|
|
122
1225
|
throw new Error(`proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`);
|
|
123
1226
|
}
|
|
124
1227
|
__name(solvePowChallenge, "solvePowChallenge");
|
|
1228
|
+
var encoder2 = new TextEncoder();
|
|
1229
|
+
var decoder = new TextDecoder("utf-8", {
|
|
1230
|
+
fatal: true
|
|
1231
|
+
});
|
|
1232
|
+
var REFRESH_MS = 5 * 6e4;
|
|
1233
|
+
var encoder3 = new TextEncoder();
|
|
125
1234
|
|
|
126
1235
|
// src/test/api.ts
|
|
127
1236
|
var TestApiError = class extends Error {
|
|
@@ -1170,4 +2279,11 @@ export {
|
|
|
1170
2279
|
isolated,
|
|
1171
2280
|
withServices
|
|
1172
2281
|
};
|
|
2282
|
+
/*! Bundled license information:
|
|
2283
|
+
|
|
2284
|
+
@hpke/common/esm/src/curve/modular.js:
|
|
2285
|
+
@hpke/common/esm/src/curve/montgomery.js:
|
|
2286
|
+
@hpke/dhkem-x25519/esm/src/primitives/x25519.js:
|
|
2287
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2288
|
+
*/
|
|
1173
2289
|
//# sourceMappingURL=index.js.map
|