@naylence/agent-sdk 0.3.6 → 0.3.9
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/browser/index.js +302 -218
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/naylence/agent/base-agent.d.ts +3 -1
- package/dist/cjs/naylence/agent/base-agent.js +13 -3
- package/dist/cjs/naylence/agent/base-agent.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/naylence/agent/base-agent.d.ts +8 -1
- package/dist/esm/naylence/agent/base-agent.js +20 -4
- package/dist/esm/naylence/agent/base-agent.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +2 -2
- package/dist/types/naylence/agent/base-agent.d.ts +8 -1
- package/dist/types/naylence/agent/base-agent.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
package/dist/browser/index.js
CHANGED
|
@@ -11,21 +11,30 @@
|
|
|
11
11
|
});
|
|
12
12
|
function $constructor(name, initializer, params) {
|
|
13
13
|
function init(inst, def) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (!inst._zod) {
|
|
15
|
+
Object.defineProperty(inst, "_zod", {
|
|
16
|
+
value: {
|
|
17
|
+
def,
|
|
18
|
+
constr: _,
|
|
19
|
+
traits: new Set(),
|
|
20
|
+
},
|
|
21
|
+
enumerable: false,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (inst._zod.traits.has(name)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
20
27
|
inst._zod.traits.add(name);
|
|
21
28
|
initializer(inst, def);
|
|
22
29
|
// support prototype modifications
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
const proto = _.prototype;
|
|
31
|
+
const keys = Object.keys(proto);
|
|
32
|
+
for (let i = 0; i < keys.length; i++) {
|
|
33
|
+
const k = keys[i];
|
|
34
|
+
if (!(k in inst)) {
|
|
35
|
+
inst[k] = proto[k].bind(inst);
|
|
36
|
+
}
|
|
26
37
|
}
|
|
27
|
-
inst._zod.constr = _;
|
|
28
|
-
inst._zod.def = def;
|
|
29
38
|
}
|
|
30
39
|
// doesn't work if Parent has a constructor with arguments
|
|
31
40
|
const Parent = params?.Parent ?? Object;
|
|
@@ -160,6 +169,14 @@
|
|
|
160
169
|
function esc(str) {
|
|
161
170
|
return JSON.stringify(str);
|
|
162
171
|
}
|
|
172
|
+
function slugify(input) {
|
|
173
|
+
return input
|
|
174
|
+
.toLowerCase()
|
|
175
|
+
.trim()
|
|
176
|
+
.replace(/[^\w\s-]/g, "")
|
|
177
|
+
.replace(/[\s_-]+/g, "-")
|
|
178
|
+
.replace(/^-+|-+$/g, "");
|
|
179
|
+
}
|
|
163
180
|
const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
|
164
181
|
function isObject$2(data) {
|
|
165
182
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
@@ -185,6 +202,8 @@
|
|
|
185
202
|
const ctor = o.constructor;
|
|
186
203
|
if (ctor === undefined)
|
|
187
204
|
return true;
|
|
205
|
+
if (typeof ctor !== "function")
|
|
206
|
+
return true;
|
|
188
207
|
// modified prototype
|
|
189
208
|
const prot = ctor.prototype;
|
|
190
209
|
if (isObject$2(prot) === false)
|
|
@@ -648,9 +667,6 @@
|
|
|
648
667
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
649
668
|
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
650
669
|
const base64url$1 = /^[A-Za-z0-9_-]*$/;
|
|
651
|
-
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
652
|
-
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
653
|
-
const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
654
670
|
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
|
655
671
|
const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
|
656
672
|
// const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
@@ -1142,7 +1158,7 @@
|
|
|
1142
1158
|
const version = {
|
|
1143
1159
|
major: 4,
|
|
1144
1160
|
minor: 1,
|
|
1145
|
-
patch:
|
|
1161
|
+
patch: 13,
|
|
1146
1162
|
};
|
|
1147
1163
|
|
|
1148
1164
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
@@ -1345,7 +1361,7 @@
|
|
|
1345
1361
|
code: "invalid_format",
|
|
1346
1362
|
format: "url",
|
|
1347
1363
|
note: "Invalid hostname",
|
|
1348
|
-
pattern: hostname.source,
|
|
1364
|
+
pattern: def.hostname.source,
|
|
1349
1365
|
input: payload.value,
|
|
1350
1366
|
inst,
|
|
1351
1367
|
continue: !def.abort,
|
|
@@ -1435,18 +1451,12 @@
|
|
|
1435
1451
|
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
|
|
1436
1452
|
def.pattern ?? (def.pattern = ipv4);
|
|
1437
1453
|
$ZodStringFormat.init(inst, def);
|
|
1438
|
-
inst._zod.
|
|
1439
|
-
const bag = inst._zod.bag;
|
|
1440
|
-
bag.format = `ipv4`;
|
|
1441
|
-
});
|
|
1454
|
+
inst._zod.bag.format = `ipv4`;
|
|
1442
1455
|
});
|
|
1443
1456
|
const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
|
|
1444
1457
|
def.pattern ?? (def.pattern = ipv6);
|
|
1445
1458
|
$ZodStringFormat.init(inst, def);
|
|
1446
|
-
inst._zod.
|
|
1447
|
-
const bag = inst._zod.bag;
|
|
1448
|
-
bag.format = `ipv6`;
|
|
1449
|
-
});
|
|
1459
|
+
inst._zod.bag.format = `ipv6`;
|
|
1450
1460
|
inst._zod.check = (payload) => {
|
|
1451
1461
|
try {
|
|
1452
1462
|
// @ts-ignore
|
|
@@ -1516,9 +1526,7 @@
|
|
|
1516
1526
|
const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
|
|
1517
1527
|
def.pattern ?? (def.pattern = base64);
|
|
1518
1528
|
$ZodStringFormat.init(inst, def);
|
|
1519
|
-
inst._zod.
|
|
1520
|
-
inst._zod.bag.contentEncoding = "base64";
|
|
1521
|
-
});
|
|
1529
|
+
inst._zod.bag.contentEncoding = "base64";
|
|
1522
1530
|
inst._zod.check = (payload) => {
|
|
1523
1531
|
if (isValidBase64(payload.value))
|
|
1524
1532
|
return;
|
|
@@ -1542,9 +1550,7 @@
|
|
|
1542
1550
|
const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
|
|
1543
1551
|
def.pattern ?? (def.pattern = base64url$1);
|
|
1544
1552
|
$ZodStringFormat.init(inst, def);
|
|
1545
|
-
inst._zod.
|
|
1546
|
-
inst._zod.bag.contentEncoding = "base64url";
|
|
1547
|
-
});
|
|
1553
|
+
inst._zod.bag.contentEncoding = "base64url";
|
|
1548
1554
|
inst._zod.check = (payload) => {
|
|
1549
1555
|
if (isValidBase64URL(payload.value))
|
|
1550
1556
|
return;
|
|
@@ -1628,9 +1634,9 @@
|
|
|
1628
1634
|
return payload;
|
|
1629
1635
|
};
|
|
1630
1636
|
});
|
|
1631
|
-
const $ZodNumberFormat = /*@__PURE__*/ $constructor("$
|
|
1637
|
+
const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
|
|
1632
1638
|
$ZodCheckNumberFormat.init(inst, def);
|
|
1633
|
-
$ZodNumber.init(inst, def); // no format
|
|
1639
|
+
$ZodNumber.init(inst, def); // no format checks
|
|
1634
1640
|
});
|
|
1635
1641
|
const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
|
|
1636
1642
|
$ZodType.init(inst, def);
|
|
@@ -1789,7 +1795,7 @@
|
|
|
1789
1795
|
const keySet = def.keySet;
|
|
1790
1796
|
const _catchall = def.catchall._zod;
|
|
1791
1797
|
const t = _catchall.def.type;
|
|
1792
|
-
for (const key
|
|
1798
|
+
for (const key in input) {
|
|
1793
1799
|
if (keySet.has(key))
|
|
1794
1800
|
continue;
|
|
1795
1801
|
if (t === "never") {
|
|
@@ -2188,11 +2194,13 @@
|
|
|
2188
2194
|
return payload;
|
|
2189
2195
|
}
|
|
2190
2196
|
const proms = [];
|
|
2191
|
-
|
|
2192
|
-
|
|
2197
|
+
const values = def.keyType._zod.values;
|
|
2198
|
+
if (values) {
|
|
2193
2199
|
payload.value = {};
|
|
2200
|
+
const recordKeys = new Set();
|
|
2194
2201
|
for (const key of values) {
|
|
2195
2202
|
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
2203
|
+
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
|
2196
2204
|
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2197
2205
|
if (result instanceof Promise) {
|
|
2198
2206
|
proms.push(result.then((result) => {
|
|
@@ -2212,7 +2220,7 @@
|
|
|
2212
2220
|
}
|
|
2213
2221
|
let unrecognized;
|
|
2214
2222
|
for (const key in input) {
|
|
2215
|
-
if (!
|
|
2223
|
+
if (!recordKeys.has(key)) {
|
|
2216
2224
|
unrecognized = unrecognized ?? [];
|
|
2217
2225
|
unrecognized.push(key);
|
|
2218
2226
|
}
|
|
@@ -2298,13 +2306,14 @@
|
|
|
2298
2306
|
if (def.values.length === 0) {
|
|
2299
2307
|
throw new Error("Cannot create literal schema with no valid values");
|
|
2300
2308
|
}
|
|
2301
|
-
|
|
2309
|
+
const values = new Set(def.values);
|
|
2310
|
+
inst._zod.values = values;
|
|
2302
2311
|
inst._zod.pattern = new RegExp(`^(${def.values
|
|
2303
2312
|
.map((o) => (typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)))
|
|
2304
2313
|
.join("|")})$`);
|
|
2305
2314
|
inst._zod.parse = (payload, _ctx) => {
|
|
2306
2315
|
const input = payload.value;
|
|
2307
|
-
if (
|
|
2316
|
+
if (values.has(input)) {
|
|
2308
2317
|
return payload;
|
|
2309
2318
|
}
|
|
2310
2319
|
payload.issues.push({
|
|
@@ -2530,8 +2539,8 @@
|
|
|
2530
2539
|
$ZodType.init(inst, def);
|
|
2531
2540
|
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
2532
2541
|
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2533
|
-
defineLazy(inst._zod, "optin", () => def.innerType
|
|
2534
|
-
defineLazy(inst._zod, "optout", () => def.innerType
|
|
2542
|
+
defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
|
2543
|
+
defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
|
2535
2544
|
inst._zod.parse = (payload, ctx) => {
|
|
2536
2545
|
if (ctx.direction === "backward") {
|
|
2537
2546
|
return def.innerType._zod.run(payload, ctx);
|
|
@@ -2579,6 +2588,7 @@
|
|
|
2579
2588
|
}
|
|
2580
2589
|
}
|
|
2581
2590
|
|
|
2591
|
+
var _a$1;
|
|
2582
2592
|
class $ZodRegistry {
|
|
2583
2593
|
constructor() {
|
|
2584
2594
|
this._map = new WeakMap();
|
|
@@ -2628,7 +2638,8 @@
|
|
|
2628
2638
|
function registry() {
|
|
2629
2639
|
return new $ZodRegistry();
|
|
2630
2640
|
}
|
|
2631
|
-
|
|
2641
|
+
(_a$1 = globalThis).__zod_globalRegistry ?? (_a$1.__zod_globalRegistry = registry());
|
|
2642
|
+
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2632
2643
|
|
|
2633
2644
|
function _string(Class, params) {
|
|
2634
2645
|
return new Class({
|
|
@@ -3059,6 +3070,10 @@
|
|
|
3059
3070
|
function _toUpperCase() {
|
|
3060
3071
|
return _overwrite((input) => input.toUpperCase());
|
|
3061
3072
|
}
|
|
3073
|
+
// slugify
|
|
3074
|
+
function _slugify() {
|
|
3075
|
+
return _overwrite((input) => slugify(input));
|
|
3076
|
+
}
|
|
3062
3077
|
function _array(Class, element, params) {
|
|
3063
3078
|
return new Class({
|
|
3064
3079
|
type: "array",
|
|
@@ -3190,7 +3205,7 @@
|
|
|
3190
3205
|
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
3191
3206
|
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
3192
3207
|
// Codec functions
|
|
3193
|
-
const encode$
|
|
3208
|
+
const encode$2 = /* @__PURE__ */ _encode(ZodRealError);
|
|
3194
3209
|
const decode$1 = /* @__PURE__ */ _decode(ZodRealError);
|
|
3195
3210
|
const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
3196
3211
|
const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
@@ -3226,7 +3241,7 @@
|
|
|
3226
3241
|
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
3227
3242
|
inst.spa = inst.safeParseAsync;
|
|
3228
3243
|
// encoding/decoding
|
|
3229
|
-
inst.encode = (data, params) => encode$
|
|
3244
|
+
inst.encode = (data, params) => encode$2(inst, data, params);
|
|
3230
3245
|
inst.decode = (data, params) => decode$1(inst, data, params);
|
|
3231
3246
|
inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
|
|
3232
3247
|
inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
|
|
@@ -3302,6 +3317,7 @@
|
|
|
3302
3317
|
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
3303
3318
|
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
3304
3319
|
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
3320
|
+
inst.slugify = () => inst.check(_slugify());
|
|
3305
3321
|
});
|
|
3306
3322
|
const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
|
|
3307
3323
|
$ZodString.init(inst, def);
|
|
@@ -9312,7 +9328,7 @@
|
|
|
9312
9328
|
data = anchors.get(source);
|
|
9313
9329
|
}
|
|
9314
9330
|
/* istanbul ignore if */
|
|
9315
|
-
if (
|
|
9331
|
+
if (data?.res === undefined) {
|
|
9316
9332
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
9317
9333
|
throw new ReferenceError(msg);
|
|
9318
9334
|
}
|
|
@@ -10324,7 +10340,7 @@
|
|
|
10324
10340
|
ws += `\n${indentComment(cs, ctx.indent)}`;
|
|
10325
10341
|
}
|
|
10326
10342
|
if (valueStr === '' && !ctx.inFlow) {
|
|
10327
|
-
if (ws === '\n')
|
|
10343
|
+
if (ws === '\n' && valueComment)
|
|
10328
10344
|
ws = '\n\n';
|
|
10329
10345
|
}
|
|
10330
10346
|
else {
|
|
@@ -10972,7 +10988,7 @@
|
|
|
10972
10988
|
const num = typeof value === 'number' ? value : Number(value);
|
|
10973
10989
|
if (!isFinite(num))
|
|
10974
10990
|
return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';
|
|
10975
|
-
let n = JSON.stringify(value);
|
|
10991
|
+
let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);
|
|
10976
10992
|
if (!format &&
|
|
10977
10993
|
minFractionDigits &&
|
|
10978
10994
|
(!tag || tag === 'tag:yaml.org,2002:float') &&
|
|
@@ -12228,7 +12244,7 @@
|
|
|
12228
12244
|
if (/[^ ]/.test(lineStr)) {
|
|
12229
12245
|
let count = 1;
|
|
12230
12246
|
const end = error.linePos[1];
|
|
12231
|
-
if (end
|
|
12247
|
+
if (end?.line === line && end.col > col) {
|
|
12232
12248
|
count = Math.max(1, Math.min(end.col - col, 80 - ci));
|
|
12233
12249
|
}
|
|
12234
12250
|
const pointer = ' '.repeat(ci) + '^'.repeat(count);
|
|
@@ -12563,7 +12579,7 @@
|
|
|
12563
12579
|
});
|
|
12564
12580
|
if (!props.found) {
|
|
12565
12581
|
if (props.anchor || props.tag || value) {
|
|
12566
|
-
if (value
|
|
12582
|
+
if (value?.type === 'block-seq')
|
|
12567
12583
|
onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
|
|
12568
12584
|
else
|
|
12569
12585
|
onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
|
|
@@ -12749,7 +12765,7 @@
|
|
|
12749
12765
|
}
|
|
12750
12766
|
}
|
|
12751
12767
|
else if (value) {
|
|
12752
|
-
if ('source' in value && value.source
|
|
12768
|
+
if ('source' in value && value.source?.[0] === ':')
|
|
12753
12769
|
onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
|
|
12754
12770
|
else
|
|
12755
12771
|
onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
|
|
@@ -12793,7 +12809,7 @@
|
|
|
12793
12809
|
const expectedEnd = isMap ? '}' : ']';
|
|
12794
12810
|
const [ce, ...ee] = fc.end;
|
|
12795
12811
|
let cePos = offset;
|
|
12796
|
-
if (ce
|
|
12812
|
+
if (ce?.source === expectedEnd)
|
|
12797
12813
|
cePos = ce.offset + ce.source.length;
|
|
12798
12814
|
else {
|
|
12799
12815
|
const name = fcName[0].toUpperCase() + fcName.substring(1);
|
|
@@ -12873,7 +12889,7 @@
|
|
|
12873
12889
|
let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
|
|
12874
12890
|
if (!tag) {
|
|
12875
12891
|
const kt = ctx.schema.knownTags[tagName];
|
|
12876
|
-
if (kt
|
|
12892
|
+
if (kt?.collection === expType) {
|
|
12877
12893
|
ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
|
|
12878
12894
|
tag = kt;
|
|
12879
12895
|
}
|
|
@@ -14804,7 +14820,7 @@
|
|
|
14804
14820
|
}
|
|
14805
14821
|
*step() {
|
|
14806
14822
|
const top = this.peek(1);
|
|
14807
|
-
if (this.type === 'doc-end' &&
|
|
14823
|
+
if (this.type === 'doc-end' && top?.type !== 'doc-end') {
|
|
14808
14824
|
while (this.stack.length > 0)
|
|
14809
14825
|
yield* this.pop();
|
|
14810
14826
|
this.stack.push({
|
|
@@ -15336,7 +15352,7 @@
|
|
|
15336
15352
|
do {
|
|
15337
15353
|
yield* this.pop();
|
|
15338
15354
|
top = this.peek(1);
|
|
15339
|
-
} while (top
|
|
15355
|
+
} while (top?.type === 'flow-collection');
|
|
15340
15356
|
}
|
|
15341
15357
|
else if (fc.end.length === 0) {
|
|
15342
15358
|
switch (this.type) {
|
|
@@ -15607,6 +15623,7 @@
|
|
|
15607
15623
|
Object.assign(out, g.__ENV__);
|
|
15608
15624
|
try {
|
|
15609
15625
|
// import.meta is only available in ESM builds
|
|
15626
|
+
// prettier-ignore
|
|
15610
15627
|
// @ts-ignore
|
|
15611
15628
|
const ie = (typeof ({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) }) !== 'undefined' && undefined) || undefined;
|
|
15612
15629
|
if (ie && typeof ie === 'object')
|
|
@@ -15675,12 +15692,12 @@
|
|
|
15675
15692
|
// --- END ENV SHIM ---
|
|
15676
15693
|
|
|
15677
15694
|
// This file is auto-generated during build - do not edit manually
|
|
15678
|
-
// Generated from package.json version: 0.3.
|
|
15695
|
+
// Generated from package.json version: 0.3.10
|
|
15679
15696
|
/**
|
|
15680
15697
|
* The package version, injected at build time.
|
|
15681
15698
|
* @internal
|
|
15682
15699
|
*/
|
|
15683
|
-
const VERSION$1 = '0.3.
|
|
15700
|
+
const VERSION$1 = '0.3.10';
|
|
15684
15701
|
|
|
15685
15702
|
/**
|
|
15686
15703
|
* Fame protocol specific error classes with WebSocket close codes and proper inheritance.
|
|
@@ -19193,13 +19210,18 @@
|
|
|
19193
19210
|
this.sidFn = sidFn;
|
|
19194
19211
|
}
|
|
19195
19212
|
createEnvelope(options) {
|
|
19196
|
-
const { frame, id, traceId, to, capabilities, replyTo, flowId, windowId, flags, timestamp, corrId, responseType, } = options;
|
|
19213
|
+
const { frame, id, sid, traceId, to, capabilities, replyTo, flowId, windowId, flags, timestamp, corrId, responseType, } = options;
|
|
19197
19214
|
const optionsRecord = isPlainRecord$8(options)
|
|
19198
19215
|
? options
|
|
19199
19216
|
: {};
|
|
19200
19217
|
validateFrame(frame);
|
|
19201
19218
|
const sidValue = this.sidFn();
|
|
19202
|
-
|
|
19219
|
+
let sanitizedSid = typeof sidValue === 'string' ? sidValue.trim() : sidValue;
|
|
19220
|
+
const sidInput = pickAlias(sid ?? null, optionsRecord, 'sid', 'source_id');
|
|
19221
|
+
if ((!sanitizedSid || sanitizedSid.length === 0) &&
|
|
19222
|
+
typeof sidInput === 'string') {
|
|
19223
|
+
sanitizedSid = sidInput.trim();
|
|
19224
|
+
}
|
|
19203
19225
|
const idInput = pickAlias(id ?? null, optionsRecord, 'envelope_id');
|
|
19204
19226
|
const traceIdInput = pickAlias(traceId ?? null, optionsRecord, 'trace_id');
|
|
19205
19227
|
const toInput = pickAlias(to ?? null, optionsRecord, 'to', 'recipient', 'target', 'address');
|
|
@@ -42811,6 +42833,44 @@
|
|
|
42811
42833
|
|
|
42812
42834
|
getLogger('naylence.fame.welcome.node_welcome_router');
|
|
42813
42835
|
|
|
42836
|
+
/**
|
|
42837
|
+
* Fabric Registry
|
|
42838
|
+
*
|
|
42839
|
+
* Provides a mapping from nodes to their associated fabrics.
|
|
42840
|
+
* This allows agents to retrieve the fabric they were registered on
|
|
42841
|
+
* without relying on the global fabric stack.
|
|
42842
|
+
*/
|
|
42843
|
+
/**
|
|
42844
|
+
* WeakMap to store the node-to-fabric mapping.
|
|
42845
|
+
* Using WeakMap ensures that nodes can be garbage collected
|
|
42846
|
+
* when no longer referenced elsewhere.
|
|
42847
|
+
*/
|
|
42848
|
+
const nodeToFabric = new WeakMap();
|
|
42849
|
+
/**
|
|
42850
|
+
* @internal
|
|
42851
|
+
* Associates a node with its fabric. This should only be called
|
|
42852
|
+
* by fabric implementations when they create or adopt a node.
|
|
42853
|
+
*
|
|
42854
|
+
* @param node - The node to associate
|
|
42855
|
+
* @param fabric - The fabric that owns the node
|
|
42856
|
+
*/
|
|
42857
|
+
function _setFabricForNode(node, fabric) {
|
|
42858
|
+
nodeToFabric.set(node, fabric);
|
|
42859
|
+
}
|
|
42860
|
+
/**
|
|
42861
|
+
* Retrieves the fabric associated with a node.
|
|
42862
|
+
*
|
|
42863
|
+
* This is useful for agents that need to access the fabric they
|
|
42864
|
+
* were registered on, particularly in environments where multiple
|
|
42865
|
+
* fabrics exist (e.g., React with multiple FabricProviders).
|
|
42866
|
+
*
|
|
42867
|
+
* @param node - The node to look up
|
|
42868
|
+
* @returns The fabric associated with the node, or undefined if not found
|
|
42869
|
+
*/
|
|
42870
|
+
function getFabricForNode(node) {
|
|
42871
|
+
return nodeToFabric.get(node);
|
|
42872
|
+
}
|
|
42873
|
+
|
|
42814
42874
|
/**
|
|
42815
42875
|
* Browser-friendly entry point for Naylence Runtime.
|
|
42816
42876
|
*
|
|
@@ -46018,6 +46078,8 @@
|
|
|
46018
46078
|
this._currentNode = await NodeLikeFactory.createNode(nodeConfig);
|
|
46019
46079
|
this._ownsNode = true;
|
|
46020
46080
|
}
|
|
46081
|
+
// Register this fabric in the registry so agents can look it up
|
|
46082
|
+
_setFabricForNode(this._currentNode, this);
|
|
46021
46083
|
if (this._ownsNode && !this._nodeStarted) {
|
|
46022
46084
|
await this.getRequiredNode().start();
|
|
46023
46085
|
this._nodeStarted = true;
|
|
@@ -55814,6 +55876,7 @@
|
|
|
55814
55876
|
this._subscriptions = new Map();
|
|
55815
55877
|
this._stateLock = new AsyncLock();
|
|
55816
55878
|
this._node = null;
|
|
55879
|
+
this._fabric = null;
|
|
55817
55880
|
this._stateStore = null;
|
|
55818
55881
|
this._stateCache = null;
|
|
55819
55882
|
this._name = name ?? camelToSnakeCase(this.constructor.name);
|
|
@@ -55853,8 +55916,18 @@
|
|
|
55853
55916
|
}
|
|
55854
55917
|
return this._storageProvider;
|
|
55855
55918
|
}
|
|
55919
|
+
/**
|
|
55920
|
+
* Returns the fabric this agent is registered with.
|
|
55921
|
+
* This is set during onRegister() and should be used instead of FameFabric.current()
|
|
55922
|
+
* when the agent needs to make calls to other agents.
|
|
55923
|
+
*/
|
|
55924
|
+
get fabric() {
|
|
55925
|
+
return this._fabric;
|
|
55926
|
+
}
|
|
55856
55927
|
async onRegister(node) {
|
|
55857
55928
|
this._node = node;
|
|
55929
|
+
// Look up the fabric from the registry (set by InProcessFameFabric.start())
|
|
55930
|
+
this._fabric = getFabricForNode(node) ?? null;
|
|
55858
55931
|
}
|
|
55859
55932
|
async acquireStateLock() {
|
|
55860
55933
|
let acquiredResolve;
|
|
@@ -56044,7 +56117,9 @@
|
|
|
56044
56117
|
if (rpcRequest.id != null) {
|
|
56045
56118
|
envelopeOptions.corrId = String(rpcRequest.id);
|
|
56046
56119
|
}
|
|
56047
|
-
const envelopeResponse =
|
|
56120
|
+
const envelopeResponse = this._node
|
|
56121
|
+
? this._node.envelopeFactory.createEnvelope(envelopeOptions)
|
|
56122
|
+
: createFameEnvelope(envelopeOptions);
|
|
56048
56123
|
yield createMessageResponse(envelopeResponse);
|
|
56049
56124
|
}
|
|
56050
56125
|
}.bind(this);
|
|
@@ -56100,8 +56175,11 @@
|
|
|
56100
56175
|
if (rpcRequest.id != null) {
|
|
56101
56176
|
envelopeOptions.corrId = String(rpcRequest.id);
|
|
56102
56177
|
}
|
|
56103
|
-
const envelope =
|
|
56104
|
-
|
|
56178
|
+
const envelope = this._node
|
|
56179
|
+
? this._node.envelopeFactory.createEnvelope(envelopeOptions)
|
|
56180
|
+
: createFameEnvelope(envelopeOptions);
|
|
56181
|
+
const fabricToUse = this._fabric ?? FameFabric.current();
|
|
56182
|
+
await fabricToUse.send(envelope);
|
|
56105
56183
|
}
|
|
56106
56184
|
}
|
|
56107
56185
|
catch (error) {
|
|
@@ -56996,6 +57074,17 @@
|
|
|
56996
57074
|
writeUInt32BE(buf, value);
|
|
56997
57075
|
return buf;
|
|
56998
57076
|
}
|
|
57077
|
+
function encode$1(string) {
|
|
57078
|
+
const bytes = new Uint8Array(string.length);
|
|
57079
|
+
for (let i = 0; i < string.length; i++) {
|
|
57080
|
+
const code = string.charCodeAt(i);
|
|
57081
|
+
if (code > 127) {
|
|
57082
|
+
throw new TypeError('non-ASCII string encountered in encode()');
|
|
57083
|
+
}
|
|
57084
|
+
bytes[i] = code;
|
|
57085
|
+
}
|
|
57086
|
+
return bytes;
|
|
57087
|
+
}
|
|
56999
57088
|
|
|
57000
57089
|
function encodeBase64(input) {
|
|
57001
57090
|
if (Uint8Array.prototype.toBase64) {
|
|
@@ -57030,7 +57119,7 @@
|
|
|
57030
57119
|
if (encoded instanceof Uint8Array) {
|
|
57031
57120
|
encoded = decoder.decode(encoded);
|
|
57032
57121
|
}
|
|
57033
|
-
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/')
|
|
57122
|
+
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
|
|
57034
57123
|
try {
|
|
57035
57124
|
return decodeBase64(encoded);
|
|
57036
57125
|
}
|
|
@@ -57174,7 +57263,7 @@
|
|
|
57174
57263
|
JWTInvalid: JWTInvalid
|
|
57175
57264
|
});
|
|
57176
57265
|
|
|
57177
|
-
function bitLength
|
|
57266
|
+
function bitLength(alg) {
|
|
57178
57267
|
switch (alg) {
|
|
57179
57268
|
case 'A128GCM':
|
|
57180
57269
|
case 'A128GCMKW':
|
|
@@ -57191,27 +57280,23 @@
|
|
|
57191
57280
|
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
57192
57281
|
}
|
|
57193
57282
|
}
|
|
57194
|
-
|
|
57283
|
+
const generateIv = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
|
|
57195
57284
|
|
|
57196
|
-
|
|
57197
|
-
if (iv.length << 3 !== bitLength
|
|
57285
|
+
function checkIvLength(enc, iv) {
|
|
57286
|
+
if (iv.length << 3 !== bitLength(enc)) {
|
|
57198
57287
|
throw new JWEInvalid('Invalid Initialization Vector length');
|
|
57199
57288
|
}
|
|
57200
|
-
}
|
|
57289
|
+
}
|
|
57201
57290
|
|
|
57202
|
-
|
|
57291
|
+
function checkCekLength(cek, expected) {
|
|
57203
57292
|
const actual = cek.byteLength << 3;
|
|
57204
57293
|
if (actual !== expected) {
|
|
57205
57294
|
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
57206
57295
|
}
|
|
57207
|
-
};
|
|
57208
|
-
|
|
57209
|
-
function unusable(name, prop = 'algorithm.name') {
|
|
57210
|
-
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
57211
|
-
}
|
|
57212
|
-
function isAlgorithm(algorithm, name) {
|
|
57213
|
-
return algorithm.name === name;
|
|
57214
57296
|
}
|
|
57297
|
+
|
|
57298
|
+
const unusable = (name, prop = 'algorithm.name') => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
57299
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
57215
57300
|
function getHashLength(hash) {
|
|
57216
57301
|
return parseInt(hash.name.slice(4), 10);
|
|
57217
57302
|
}
|
|
@@ -57379,27 +57464,26 @@
|
|
|
57379
57464
|
}
|
|
57380
57465
|
return msg;
|
|
57381
57466
|
}
|
|
57382
|
-
|
|
57383
|
-
|
|
57384
|
-
};
|
|
57385
|
-
function withAlg(alg, actual, ...types) {
|
|
57386
|
-
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
57387
|
-
}
|
|
57467
|
+
const invalidKeyInput = (actual, ...types) => message('Key must be ', actual, ...types);
|
|
57468
|
+
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
57388
57469
|
|
|
57389
57470
|
function assertCryptoKey(key) {
|
|
57390
57471
|
if (!isCryptoKey(key)) {
|
|
57391
57472
|
throw new Error('CryptoKey instance expected');
|
|
57392
57473
|
}
|
|
57393
57474
|
}
|
|
57394
|
-
|
|
57395
|
-
|
|
57396
|
-
|
|
57397
|
-
|
|
57398
|
-
|
|
57399
|
-
|
|
57400
|
-
|
|
57401
|
-
|
|
57475
|
+
const isCryptoKey = (key) => {
|
|
57476
|
+
if (key?.[Symbol.toStringTag] === 'CryptoKey')
|
|
57477
|
+
return true;
|
|
57478
|
+
try {
|
|
57479
|
+
return key instanceof CryptoKey;
|
|
57480
|
+
}
|
|
57481
|
+
catch {
|
|
57482
|
+
return false;
|
|
57483
|
+
}
|
|
57402
57484
|
};
|
|
57485
|
+
const isKeyObject = (key) => key?.[Symbol.toStringTag] === 'KeyObject';
|
|
57486
|
+
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
57403
57487
|
|
|
57404
57488
|
async function timingSafeEqual(a, b) {
|
|
57405
57489
|
if (!(a instanceof Uint8Array)) {
|
|
@@ -57442,7 +57526,7 @@
|
|
|
57442
57526
|
}
|
|
57443
57527
|
let plaintext;
|
|
57444
57528
|
try {
|
|
57445
|
-
plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv, name: 'AES-CBC' }, encKey, ciphertext));
|
|
57529
|
+
plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv: iv, name: 'AES-CBC' }, encKey, ciphertext));
|
|
57446
57530
|
}
|
|
57447
57531
|
catch {
|
|
57448
57532
|
}
|
|
@@ -57463,7 +57547,7 @@
|
|
|
57463
57547
|
try {
|
|
57464
57548
|
return new Uint8Array(await crypto.subtle.decrypt({
|
|
57465
57549
|
additionalData: aad,
|
|
57466
|
-
iv,
|
|
57550
|
+
iv: iv,
|
|
57467
57551
|
name: 'AES-GCM',
|
|
57468
57552
|
tagLength: 128,
|
|
57469
57553
|
}, encKey, concat(ciphertext, tag)));
|
|
@@ -57472,7 +57556,7 @@
|
|
|
57472
57556
|
throw new JWEDecryptionFailed();
|
|
57473
57557
|
}
|
|
57474
57558
|
}
|
|
57475
|
-
|
|
57559
|
+
async function decrypt$1(enc, cek, ciphertext, iv, tag, aad) {
|
|
57476
57560
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
57477
57561
|
throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'KeyObject', 'Uint8Array', 'JSON Web Key'));
|
|
57478
57562
|
}
|
|
@@ -57499,9 +57583,9 @@
|
|
|
57499
57583
|
default:
|
|
57500
57584
|
throw new JOSENotSupported('Unsupported JWE Content Encryption Algorithm');
|
|
57501
57585
|
}
|
|
57502
|
-
}
|
|
57586
|
+
}
|
|
57503
57587
|
|
|
57504
|
-
|
|
57588
|
+
function isDisjoint(...headers) {
|
|
57505
57589
|
const sources = headers.filter(Boolean);
|
|
57506
57590
|
if (sources.length === 0 || sources.length === 1) {
|
|
57507
57591
|
return true;
|
|
@@ -57521,12 +57605,10 @@
|
|
|
57521
57605
|
}
|
|
57522
57606
|
}
|
|
57523
57607
|
return true;
|
|
57524
|
-
};
|
|
57525
|
-
|
|
57526
|
-
function isObjectLike(value) {
|
|
57527
|
-
return typeof value === 'object' && value !== null;
|
|
57528
57608
|
}
|
|
57529
|
-
|
|
57609
|
+
|
|
57610
|
+
const isObjectLike = (value) => typeof value === 'object' && value !== null;
|
|
57611
|
+
function isObject(input) {
|
|
57530
57612
|
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== '[object Object]') {
|
|
57531
57613
|
return false;
|
|
57532
57614
|
}
|
|
@@ -57538,7 +57620,7 @@
|
|
|
57538
57620
|
proto = Object.getPrototypeOf(proto);
|
|
57539
57621
|
}
|
|
57540
57622
|
return Object.getPrototypeOf(input) === proto;
|
|
57541
|
-
}
|
|
57623
|
+
}
|
|
57542
57624
|
|
|
57543
57625
|
function checkKeySize(key, alg) {
|
|
57544
57626
|
if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
|
|
@@ -57565,10 +57647,10 @@
|
|
|
57565
57647
|
return new Uint8Array(await crypto.subtle.exportKey('raw', cryptoKeyCek));
|
|
57566
57648
|
}
|
|
57567
57649
|
|
|
57568
|
-
|
|
57650
|
+
async function digest(algorithm, data) {
|
|
57569
57651
|
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
57570
57652
|
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
57571
|
-
}
|
|
57653
|
+
}
|
|
57572
57654
|
|
|
57573
57655
|
function lengthAndInput(input) {
|
|
57574
57656
|
return concat(uint32be(input.length), input);
|
|
@@ -57588,14 +57670,14 @@
|
|
|
57588
57670
|
}
|
|
57589
57671
|
return dk.slice(0, dkLen);
|
|
57590
57672
|
}
|
|
57591
|
-
async function deriveKey$1(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(
|
|
57673
|
+
async function deriveKey$1(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
|
|
57592
57674
|
checkEncCryptoKey(publicKey, 'ECDH');
|
|
57593
57675
|
checkEncCryptoKey(privateKey, 'ECDH', 'deriveBits');
|
|
57594
|
-
const algorithmID = lengthAndInput(
|
|
57676
|
+
const algorithmID = lengthAndInput(encode$1(algorithm));
|
|
57595
57677
|
const partyUInfo = lengthAndInput(apu);
|
|
57596
57678
|
const partyVInfo = lengthAndInput(apv);
|
|
57597
57679
|
const suppPubInfo = uint32be(keyLength);
|
|
57598
|
-
const suppPrivInfo = new Uint8Array(
|
|
57680
|
+
const suppPrivInfo = new Uint8Array();
|
|
57599
57681
|
const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
|
|
57600
57682
|
const Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
57601
57683
|
name: publicKey.algorithm.name,
|
|
@@ -57622,12 +57704,14 @@
|
|
|
57622
57704
|
|
|
57623
57705
|
function getCryptoKey(key, alg) {
|
|
57624
57706
|
if (key instanceof Uint8Array) {
|
|
57625
|
-
return crypto.subtle.importKey('raw', key, 'PBKDF2', false, [
|
|
57707
|
+
return crypto.subtle.importKey('raw', key, 'PBKDF2', false, [
|
|
57708
|
+
'deriveBits',
|
|
57709
|
+
]);
|
|
57626
57710
|
}
|
|
57627
57711
|
checkEncCryptoKey(key, alg, 'deriveBits');
|
|
57628
57712
|
return key;
|
|
57629
57713
|
}
|
|
57630
|
-
const concatSalt = (alg, p2sInput) => concat(
|
|
57714
|
+
const concatSalt = (alg, p2sInput) => concat(encode$1(alg), Uint8Array.of(0x00), p2sInput);
|
|
57631
57715
|
async function deriveKey(p2s, alg, p2c, key) {
|
|
57632
57716
|
if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
|
|
57633
57717
|
throw new JWEInvalid('PBES2 Salt Input must be 8 or more octets');
|
|
@@ -57653,14 +57737,14 @@
|
|
|
57653
57737
|
return unwrap$2(alg.slice(-6), derived, encryptedKey);
|
|
57654
57738
|
}
|
|
57655
57739
|
|
|
57656
|
-
|
|
57740
|
+
function checkKeyLength(alg, key) {
|
|
57657
57741
|
if (alg.startsWith('RS') || alg.startsWith('PS')) {
|
|
57658
57742
|
const { modulusLength } = key.algorithm;
|
|
57659
57743
|
if (typeof modulusLength !== 'number' || modulusLength < 2048) {
|
|
57660
57744
|
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
57661
57745
|
}
|
|
57662
57746
|
}
|
|
57663
|
-
}
|
|
57747
|
+
}
|
|
57664
57748
|
|
|
57665
57749
|
const subtleAlgorithm$1 = (alg) => {
|
|
57666
57750
|
switch (alg) {
|
|
@@ -57684,7 +57768,7 @@
|
|
|
57684
57768
|
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm$1(alg), key, encryptedKey));
|
|
57685
57769
|
}
|
|
57686
57770
|
|
|
57687
|
-
function
|
|
57771
|
+
function cekLength(alg) {
|
|
57688
57772
|
switch (alg) {
|
|
57689
57773
|
case 'A128GCM':
|
|
57690
57774
|
return 128;
|
|
@@ -57701,7 +57785,7 @@
|
|
|
57701
57785
|
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
57702
57786
|
}
|
|
57703
57787
|
}
|
|
57704
|
-
|
|
57788
|
+
const generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
57705
57789
|
|
|
57706
57790
|
const formatPEM = (b64, descriptor) => {
|
|
57707
57791
|
const newlined = (b64.match(/.{1,64}/g) || []).join('\n');
|
|
@@ -57725,12 +57809,8 @@
|
|
|
57725
57809
|
}
|
|
57726
57810
|
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
57727
57811
|
};
|
|
57728
|
-
const toSPKI = (key) =>
|
|
57729
|
-
|
|
57730
|
-
};
|
|
57731
|
-
const toPKCS8 = (key) => {
|
|
57732
|
-
return genericExport('private', 'pkcs8', key);
|
|
57733
|
-
};
|
|
57812
|
+
const toSPKI = (key) => genericExport('public', 'spki', key);
|
|
57813
|
+
const toPKCS8 = (key) => genericExport('private', 'pkcs8', key);
|
|
57734
57814
|
const bytesEqual = (a, b) => {
|
|
57735
57815
|
if (a.byteLength !== b.length)
|
|
57736
57816
|
return false;
|
|
@@ -58043,7 +58123,7 @@
|
|
|
58043
58123
|
}
|
|
58044
58124
|
return { algorithm, keyUsages };
|
|
58045
58125
|
}
|
|
58046
|
-
|
|
58126
|
+
async function jwkToKey(jwk) {
|
|
58047
58127
|
if (!jwk.alg) {
|
|
58048
58128
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
58049
58129
|
}
|
|
@@ -58054,7 +58134,7 @@
|
|
|
58054
58134
|
}
|
|
58055
58135
|
delete keyData.use;
|
|
58056
58136
|
return crypto.subtle.importKey('jwk', keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
58057
|
-
}
|
|
58137
|
+
}
|
|
58058
58138
|
|
|
58059
58139
|
async function importSPKI(spki, alg, options) {
|
|
58060
58140
|
if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {
|
|
@@ -58091,7 +58171,7 @@
|
|
|
58091
58171
|
if ('oth' in jwk && jwk.oth !== undefined) {
|
|
58092
58172
|
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
58093
58173
|
}
|
|
58094
|
-
return
|
|
58174
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
58095
58175
|
case 'AKP': {
|
|
58096
58176
|
if (typeof jwk.alg !== 'string' || !jwk.alg) {
|
|
58097
58177
|
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
@@ -58099,11 +58179,11 @@
|
|
|
58099
58179
|
if (alg !== undefined && alg !== jwk.alg) {
|
|
58100
58180
|
throw new TypeError('JWK alg and alg option value mismatch');
|
|
58101
58181
|
}
|
|
58102
|
-
return
|
|
58182
|
+
return jwkToKey({ ...jwk, ext });
|
|
58103
58183
|
}
|
|
58104
58184
|
case 'EC':
|
|
58105
58185
|
case 'OKP':
|
|
58106
|
-
return
|
|
58186
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
58107
58187
|
default:
|
|
58108
58188
|
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
58109
58189
|
}
|
|
@@ -58120,7 +58200,7 @@
|
|
|
58120
58200
|
name: 'HMAC',
|
|
58121
58201
|
}, false, ['sign']);
|
|
58122
58202
|
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
58123
|
-
iv,
|
|
58203
|
+
iv: iv,
|
|
58124
58204
|
name: 'AES-CBC',
|
|
58125
58205
|
}, encKey, plaintext));
|
|
58126
58206
|
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
@@ -58138,7 +58218,7 @@
|
|
|
58138
58218
|
}
|
|
58139
58219
|
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
58140
58220
|
additionalData: aad,
|
|
58141
|
-
iv,
|
|
58221
|
+
iv: iv,
|
|
58142
58222
|
name: 'AES-GCM',
|
|
58143
58223
|
tagLength: 128,
|
|
58144
58224
|
}, encKey, plaintext));
|
|
@@ -58146,7 +58226,7 @@
|
|
|
58146
58226
|
const ciphertext = encrypted.slice(0, -16);
|
|
58147
58227
|
return { ciphertext, tag, iv };
|
|
58148
58228
|
}
|
|
58149
|
-
|
|
58229
|
+
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
58150
58230
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
58151
58231
|
throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'KeyObject', 'Uint8Array', 'JSON Web Key'));
|
|
58152
58232
|
}
|
|
@@ -58174,11 +58254,11 @@
|
|
|
58174
58254
|
default:
|
|
58175
58255
|
throw new JOSENotSupported('Unsupported JWE Content Encryption Algorithm');
|
|
58176
58256
|
}
|
|
58177
|
-
}
|
|
58257
|
+
}
|
|
58178
58258
|
|
|
58179
58259
|
async function wrap(alg, key, cek, iv) {
|
|
58180
58260
|
const jweAlgorithm = alg.slice(0, 7);
|
|
58181
|
-
const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array(
|
|
58261
|
+
const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array());
|
|
58182
58262
|
return {
|
|
58183
58263
|
encryptedKey: wrapped.ciphertext,
|
|
58184
58264
|
iv: encode(wrapped.iv),
|
|
@@ -58187,10 +58267,10 @@
|
|
|
58187
58267
|
}
|
|
58188
58268
|
async function unwrap(alg, key, encryptedKey, iv, tag) {
|
|
58189
58269
|
const jweAlgorithm = alg.slice(0, 7);
|
|
58190
|
-
return decrypt$1(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(
|
|
58270
|
+
return decrypt$1(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array());
|
|
58191
58271
|
}
|
|
58192
58272
|
|
|
58193
|
-
|
|
58273
|
+
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
58194
58274
|
switch (alg) {
|
|
58195
58275
|
case 'dir': {
|
|
58196
58276
|
if (encryptedKey !== undefined)
|
|
@@ -58232,7 +58312,7 @@
|
|
|
58232
58312
|
throw new JWEInvalid('Failed to base64url decode the apv');
|
|
58233
58313
|
}
|
|
58234
58314
|
}
|
|
58235
|
-
const sharedSecret = await deriveKey$1(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, alg === 'ECDH-ES' ?
|
|
58315
|
+
const sharedSecret = await deriveKey$1(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, alg === 'ECDH-ES' ? cekLength(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
58236
58316
|
if (alg === 'ECDH-ES')
|
|
58237
58317
|
return sharedSecret;
|
|
58238
58318
|
if (encryptedKey === undefined)
|
|
@@ -58305,9 +58385,9 @@
|
|
|
58305
58385
|
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
58306
58386
|
}
|
|
58307
58387
|
}
|
|
58308
|
-
}
|
|
58388
|
+
}
|
|
58309
58389
|
|
|
58310
|
-
|
|
58390
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
58311
58391
|
if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
|
|
58312
58392
|
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
58313
58393
|
}
|
|
@@ -58338,9 +58418,9 @@
|
|
|
58338
58418
|
}
|
|
58339
58419
|
}
|
|
58340
58420
|
return new Set(protectedHeader.crit);
|
|
58341
|
-
}
|
|
58421
|
+
}
|
|
58342
58422
|
|
|
58343
|
-
|
|
58423
|
+
function validateAlgorithms(option, algorithms) {
|
|
58344
58424
|
if (algorithms !== undefined &&
|
|
58345
58425
|
(!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== 'string'))) {
|
|
58346
58426
|
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
@@ -58349,22 +58429,14 @@
|
|
|
58349
58429
|
return undefined;
|
|
58350
58430
|
}
|
|
58351
58431
|
return new Set(algorithms);
|
|
58352
|
-
};
|
|
58353
|
-
|
|
58354
|
-
function isJWK(key) {
|
|
58355
|
-
return isObject(key) && typeof key.kty === 'string';
|
|
58356
|
-
}
|
|
58357
|
-
function isPrivateJWK(key) {
|
|
58358
|
-
return (key.kty !== 'oct' &&
|
|
58359
|
-
((key.kty === 'AKP' && typeof key.priv === 'string') || typeof key.d === 'string'));
|
|
58360
|
-
}
|
|
58361
|
-
function isPublicJWK(key) {
|
|
58362
|
-
return key.kty !== 'oct' && typeof key.d === 'undefined' && typeof key.priv === 'undefined';
|
|
58363
|
-
}
|
|
58364
|
-
function isSecretJWK(key) {
|
|
58365
|
-
return key.kty === 'oct' && typeof key.k === 'string';
|
|
58366
58432
|
}
|
|
58367
58433
|
|
|
58434
|
+
const isJWK = (key) => isObject(key) && typeof key.kty === 'string';
|
|
58435
|
+
const isPrivateJWK = (key) => key.kty !== 'oct' &&
|
|
58436
|
+
((key.kty === 'AKP' && typeof key.priv === 'string') || typeof key.d === 'string');
|
|
58437
|
+
const isPublicJWK = (key) => key.kty !== 'oct' && key.d === undefined && key.priv === undefined;
|
|
58438
|
+
const isSecretJWK = (key) => key.kty === 'oct' && typeof key.k === 'string';
|
|
58439
|
+
|
|
58368
58440
|
let cache;
|
|
58369
58441
|
const handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
58370
58442
|
cache ||= new WeakMap();
|
|
@@ -58372,7 +58444,7 @@
|
|
|
58372
58444
|
if (cached?.[alg]) {
|
|
58373
58445
|
return cached[alg];
|
|
58374
58446
|
}
|
|
58375
|
-
const cryptoKey = await
|
|
58447
|
+
const cryptoKey = await jwkToKey({ ...jwk, alg });
|
|
58376
58448
|
if (freeze)
|
|
58377
58449
|
Object.freeze(key);
|
|
58378
58450
|
if (!cached) {
|
|
@@ -58505,7 +58577,7 @@
|
|
|
58505
58577
|
}
|
|
58506
58578
|
return cryptoKey;
|
|
58507
58579
|
};
|
|
58508
|
-
|
|
58580
|
+
async function normalizeKey(key, alg) {
|
|
58509
58581
|
if (key instanceof Uint8Array) {
|
|
58510
58582
|
return key;
|
|
58511
58583
|
}
|
|
@@ -58536,7 +58608,7 @@
|
|
|
58536
58608
|
return handleJWK(key, key, alg, true);
|
|
58537
58609
|
}
|
|
58538
58610
|
throw new Error('unreachable');
|
|
58539
|
-
}
|
|
58611
|
+
}
|
|
58540
58612
|
|
|
58541
58613
|
const tag = (key) => key?.[Symbol.toStringTag];
|
|
58542
58614
|
const jwkMatchesOp = (alg, key, usage) => {
|
|
@@ -58613,12 +58685,12 @@
|
|
|
58613
58685
|
case 'sign':
|
|
58614
58686
|
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
58615
58687
|
return;
|
|
58616
|
-
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
58688
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
58617
58689
|
case 'encrypt':
|
|
58618
58690
|
case 'verify':
|
|
58619
58691
|
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
58620
58692
|
return;
|
|
58621
|
-
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
58693
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
58622
58694
|
}
|
|
58623
58695
|
}
|
|
58624
58696
|
if (!isKeyLike(key)) {
|
|
@@ -58644,19 +58716,19 @@
|
|
|
58644
58716
|
}
|
|
58645
58717
|
}
|
|
58646
58718
|
};
|
|
58647
|
-
|
|
58648
|
-
|
|
58649
|
-
|
|
58650
|
-
|
|
58651
|
-
|
|
58652
|
-
|
|
58653
|
-
|
|
58654
|
-
|
|
58655
|
-
|
|
58656
|
-
|
|
58657
|
-
|
|
58719
|
+
function checkKeyType(alg, key, usage) {
|
|
58720
|
+
switch (alg.substring(0, 2)) {
|
|
58721
|
+
case 'A1':
|
|
58722
|
+
case 'A2':
|
|
58723
|
+
case 'di':
|
|
58724
|
+
case 'HS':
|
|
58725
|
+
case 'PB':
|
|
58726
|
+
symmetricTypeCheck(alg, key, usage);
|
|
58727
|
+
break;
|
|
58728
|
+
default:
|
|
58729
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
58658
58730
|
}
|
|
58659
|
-
}
|
|
58731
|
+
}
|
|
58660
58732
|
|
|
58661
58733
|
async function flattenedDecrypt(jwe, key, options) {
|
|
58662
58734
|
if (!isObject(jwe)) {
|
|
@@ -58772,10 +58844,10 @@
|
|
|
58772
58844
|
throw new JWEInvalid('Failed to base64url decode the tag');
|
|
58773
58845
|
}
|
|
58774
58846
|
}
|
|
58775
|
-
const protectedHeader =
|
|
58847
|
+
const protectedHeader = jwe.protected !== undefined ? encode$1(jwe.protected) : new Uint8Array();
|
|
58776
58848
|
let additionalData;
|
|
58777
58849
|
if (jwe.aad !== undefined) {
|
|
58778
|
-
additionalData = concat(protectedHeader,
|
|
58850
|
+
additionalData = concat(protectedHeader, encode$1('.'), encode$1(jwe.aad));
|
|
58779
58851
|
}
|
|
58780
58852
|
else {
|
|
58781
58853
|
additionalData = protectedHeader;
|
|
@@ -58906,7 +58978,7 @@
|
|
|
58906
58978
|
return keyToJWK(key);
|
|
58907
58979
|
}
|
|
58908
58980
|
|
|
58909
|
-
|
|
58981
|
+
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
58910
58982
|
let encryptedKey;
|
|
58911
58983
|
let parameters;
|
|
58912
58984
|
let cek;
|
|
@@ -58932,7 +59004,7 @@
|
|
|
58932
59004
|
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ['deriveBits'])).privateKey;
|
|
58933
59005
|
}
|
|
58934
59006
|
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
58935
|
-
const sharedSecret = await deriveKey$1(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ?
|
|
59007
|
+
const sharedSecret = await deriveKey$1(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
58936
59008
|
parameters = { epk: { x, crv, kty } };
|
|
58937
59009
|
if (kty === 'EC')
|
|
58938
59010
|
parameters.epk.y = y;
|
|
@@ -58986,7 +59058,7 @@
|
|
|
58986
59058
|
}
|
|
58987
59059
|
}
|
|
58988
59060
|
return { cek, encryptedKey, parameters };
|
|
58989
|
-
}
|
|
59061
|
+
}
|
|
58990
59062
|
|
|
58991
59063
|
class FlattenedEncrypt {
|
|
58992
59064
|
#plaintext;
|
|
@@ -59100,20 +59172,24 @@
|
|
|
59100
59172
|
}
|
|
59101
59173
|
}
|
|
59102
59174
|
let additionalData;
|
|
59103
|
-
let
|
|
59175
|
+
let protectedHeaderS;
|
|
59176
|
+
let protectedHeaderB;
|
|
59104
59177
|
let aadMember;
|
|
59105
59178
|
if (this.#protectedHeader) {
|
|
59106
|
-
|
|
59179
|
+
protectedHeaderS = encode(JSON.stringify(this.#protectedHeader));
|
|
59180
|
+
protectedHeaderB = encode$1(protectedHeaderS);
|
|
59107
59181
|
}
|
|
59108
59182
|
else {
|
|
59109
|
-
|
|
59183
|
+
protectedHeaderS = '';
|
|
59184
|
+
protectedHeaderB = new Uint8Array();
|
|
59110
59185
|
}
|
|
59111
59186
|
if (this.#aad) {
|
|
59112
59187
|
aadMember = encode(this.#aad);
|
|
59113
|
-
|
|
59188
|
+
const aadMemberBytes = encode$1(aadMember);
|
|
59189
|
+
additionalData = concat(protectedHeaderB, encode$1('.'), aadMemberBytes);
|
|
59114
59190
|
}
|
|
59115
59191
|
else {
|
|
59116
|
-
additionalData =
|
|
59192
|
+
additionalData = protectedHeaderB;
|
|
59117
59193
|
}
|
|
59118
59194
|
const { ciphertext, tag, iv } = await encrypt(enc, this.#plaintext, cek, this.#iv, additionalData);
|
|
59119
59195
|
const jwe = {
|
|
@@ -59132,7 +59208,7 @@
|
|
|
59132
59208
|
jwe.aad = aadMember;
|
|
59133
59209
|
}
|
|
59134
59210
|
if (this.#protectedHeader) {
|
|
59135
|
-
jwe.protected =
|
|
59211
|
+
jwe.protected = protectedHeaderS;
|
|
59136
59212
|
}
|
|
59137
59213
|
if (this.#sharedUnprotectedHeader) {
|
|
59138
59214
|
jwe.unprotected = this.#sharedUnprotectedHeader;
|
|
@@ -59147,6 +59223,7 @@
|
|
|
59147
59223
|
class IndividualRecipient {
|
|
59148
59224
|
#parent;
|
|
59149
59225
|
unprotectedHeader;
|
|
59226
|
+
keyManagementParameters;
|
|
59150
59227
|
key;
|
|
59151
59228
|
options;
|
|
59152
59229
|
constructor(enc, key, options) {
|
|
@@ -59161,6 +59238,13 @@
|
|
|
59161
59238
|
this.unprotectedHeader = unprotectedHeader;
|
|
59162
59239
|
return this;
|
|
59163
59240
|
}
|
|
59241
|
+
setKeyManagementParameters(parameters) {
|
|
59242
|
+
if (this.keyManagementParameters) {
|
|
59243
|
+
throw new TypeError('setKeyManagementParameters can only be called once');
|
|
59244
|
+
}
|
|
59245
|
+
this.keyManagementParameters = parameters;
|
|
59246
|
+
return this;
|
|
59247
|
+
}
|
|
59164
59248
|
addRecipient(...args) {
|
|
59165
59249
|
return this.#parent.addRecipient(...args);
|
|
59166
59250
|
}
|
|
@@ -59268,20 +59352,12 @@
|
|
|
59268
59352
|
const cek = generateCek(enc);
|
|
59269
59353
|
const jwe = {
|
|
59270
59354
|
ciphertext: '',
|
|
59271
|
-
iv: '',
|
|
59272
59355
|
recipients: [],
|
|
59273
|
-
tag: '',
|
|
59274
59356
|
};
|
|
59275
59357
|
for (let i = 0; i < this.#recipients.length; i++) {
|
|
59276
59358
|
const recipient = this.#recipients[i];
|
|
59277
59359
|
const target = {};
|
|
59278
59360
|
jwe.recipients.push(target);
|
|
59279
|
-
const joseHeader = {
|
|
59280
|
-
...this.#protectedHeader,
|
|
59281
|
-
...this.#unprotectedHeader,
|
|
59282
|
-
...recipient.unprotectedHeader,
|
|
59283
|
-
};
|
|
59284
|
-
const p2c = joseHeader.alg.startsWith('PBES2') ? 2048 + i : undefined;
|
|
59285
59361
|
if (i === 0) {
|
|
59286
59362
|
const flattened = await new FlattenedEncrypt(this.#plaintext)
|
|
59287
59363
|
.setAdditionalAuthenticatedData(this.#aad)
|
|
@@ -59289,7 +59365,7 @@
|
|
|
59289
59365
|
.setProtectedHeader(this.#protectedHeader)
|
|
59290
59366
|
.setSharedUnprotectedHeader(this.#unprotectedHeader)
|
|
59291
59367
|
.setUnprotectedHeader(recipient.unprotectedHeader)
|
|
59292
|
-
.setKeyManagementParameters(
|
|
59368
|
+
.setKeyManagementParameters(recipient.keyManagementParameters)
|
|
59293
59369
|
.encrypt(recipient.key, {
|
|
59294
59370
|
...recipient.options,
|
|
59295
59371
|
[unprotected]: true,
|
|
@@ -59313,7 +59389,7 @@
|
|
|
59313
59389
|
this.#unprotectedHeader?.alg;
|
|
59314
59390
|
checkKeyType(alg === 'dir' ? enc : alg, recipient.key, 'encrypt');
|
|
59315
59391
|
const k = await normalizeKey(recipient.key, alg);
|
|
59316
|
-
const { encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, cek,
|
|
59392
|
+
const { encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, cek, recipient.keyManagementParameters);
|
|
59317
59393
|
target.encrypted_key = encode(encryptedKey);
|
|
59318
59394
|
if (recipient.unprotectedHeader || parameters)
|
|
59319
59395
|
target.header = { ...recipient.unprotectedHeader, ...parameters };
|
|
@@ -59322,7 +59398,7 @@
|
|
|
59322
59398
|
}
|
|
59323
59399
|
}
|
|
59324
59400
|
|
|
59325
|
-
|
|
59401
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
59326
59402
|
const hash = `SHA-${alg.slice(-3)}`;
|
|
59327
59403
|
switch (alg) {
|
|
59328
59404
|
case 'HS256':
|
|
@@ -59351,9 +59427,9 @@
|
|
|
59351
59427
|
default:
|
|
59352
59428
|
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
59353
59429
|
}
|
|
59354
|
-
}
|
|
59430
|
+
}
|
|
59355
59431
|
|
|
59356
|
-
|
|
59432
|
+
async function getSigKey(alg, key, usage) {
|
|
59357
59433
|
if (key instanceof Uint8Array) {
|
|
59358
59434
|
if (!alg.startsWith('HS')) {
|
|
59359
59435
|
throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'KeyObject', 'JSON Web Key'));
|
|
@@ -59362,10 +59438,10 @@
|
|
|
59362
59438
|
}
|
|
59363
59439
|
checkSigCryptoKey(key, alg, usage);
|
|
59364
59440
|
return key;
|
|
59365
|
-
}
|
|
59441
|
+
}
|
|
59366
59442
|
|
|
59367
|
-
|
|
59368
|
-
const cryptoKey = await
|
|
59443
|
+
async function verify(alg, key, signature, data) {
|
|
59444
|
+
const cryptoKey = await getSigKey(alg, key, 'verify');
|
|
59369
59445
|
checkKeyLength(alg, cryptoKey);
|
|
59370
59446
|
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
59371
59447
|
try {
|
|
@@ -59374,7 +59450,7 @@
|
|
|
59374
59450
|
catch {
|
|
59375
59451
|
return false;
|
|
59376
59452
|
}
|
|
59377
|
-
}
|
|
59453
|
+
}
|
|
59378
59454
|
|
|
59379
59455
|
async function flattenedVerify(jws, key, options) {
|
|
59380
59456
|
if (!isObject(jws)) {
|
|
@@ -59442,7 +59518,11 @@
|
|
|
59442
59518
|
resolvedKey = true;
|
|
59443
59519
|
}
|
|
59444
59520
|
checkKeyType(alg, key, 'verify');
|
|
59445
|
-
const data = concat(
|
|
59521
|
+
const data = concat(jws.protected !== undefined ? encode$1(jws.protected) : new Uint8Array(), encode$1('.'), typeof jws.payload === 'string'
|
|
59522
|
+
? b64
|
|
59523
|
+
? encode$1(jws.payload)
|
|
59524
|
+
: encoder.encode(jws.payload)
|
|
59525
|
+
: jws.payload);
|
|
59446
59526
|
let signature;
|
|
59447
59527
|
try {
|
|
59448
59528
|
signature = decode(jws.signature);
|
|
@@ -59524,15 +59604,14 @@
|
|
|
59524
59604
|
throw new JWSSignatureVerificationFailed();
|
|
59525
59605
|
}
|
|
59526
59606
|
|
|
59527
|
-
|
|
59528
|
-
|
|
59607
|
+
const epoch = (date) => Math.floor(date.getTime() / 1000);
|
|
59529
59608
|
const minute = 60;
|
|
59530
59609
|
const hour = minute * 60;
|
|
59531
59610
|
const day = hour * 24;
|
|
59532
59611
|
const week = day * 7;
|
|
59533
59612
|
const year = day * 365.25;
|
|
59534
59613
|
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
59535
|
-
|
|
59614
|
+
function secs(str) {
|
|
59536
59615
|
const matched = REGEX.exec(str);
|
|
59537
59616
|
if (!matched || (matched[4] && matched[1])) {
|
|
59538
59617
|
throw new TypeError('Invalid time period format');
|
|
@@ -59580,8 +59659,7 @@
|
|
|
59580
59659
|
return -numericDate;
|
|
59581
59660
|
}
|
|
59582
59661
|
return numericDate;
|
|
59583
|
-
}
|
|
59584
|
-
|
|
59662
|
+
}
|
|
59585
59663
|
function validateInput(label, input) {
|
|
59586
59664
|
if (!Number.isFinite(input)) {
|
|
59587
59665
|
throw new TypeError(`Invalid ${label} input`);
|
|
@@ -59747,7 +59825,7 @@
|
|
|
59747
59825
|
}
|
|
59748
59826
|
}
|
|
59749
59827
|
set iat(value) {
|
|
59750
|
-
if (
|
|
59828
|
+
if (value === undefined) {
|
|
59751
59829
|
this.#payload.iat = epoch(new Date());
|
|
59752
59830
|
}
|
|
59753
59831
|
else if (value instanceof Date) {
|
|
@@ -59823,12 +59901,12 @@
|
|
|
59823
59901
|
}
|
|
59824
59902
|
}
|
|
59825
59903
|
|
|
59826
|
-
|
|
59827
|
-
const cryptoKey = await
|
|
59904
|
+
async function sign(alg, key, data) {
|
|
59905
|
+
const cryptoKey = await getSigKey(alg, key, 'sign');
|
|
59828
59906
|
checkKeyLength(alg, cryptoKey);
|
|
59829
59907
|
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
59830
59908
|
return new Uint8Array(signature);
|
|
59831
|
-
}
|
|
59909
|
+
}
|
|
59832
59910
|
|
|
59833
59911
|
class FlattenedSign {
|
|
59834
59912
|
#payload;
|
|
@@ -59878,32 +59956,38 @@
|
|
|
59878
59956
|
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
59879
59957
|
}
|
|
59880
59958
|
checkKeyType(alg, key, 'sign');
|
|
59881
|
-
let
|
|
59959
|
+
let payloadS;
|
|
59960
|
+
let payloadB;
|
|
59882
59961
|
if (b64) {
|
|
59883
|
-
|
|
59962
|
+
payloadS = encode(this.#payload);
|
|
59963
|
+
payloadB = encode$1(payloadS);
|
|
59964
|
+
}
|
|
59965
|
+
else {
|
|
59966
|
+
payloadB = this.#payload;
|
|
59967
|
+
payloadS = '';
|
|
59884
59968
|
}
|
|
59885
|
-
let
|
|
59969
|
+
let protectedHeaderString;
|
|
59970
|
+
let protectedHeaderBytes;
|
|
59886
59971
|
if (this.#protectedHeader) {
|
|
59887
|
-
|
|
59972
|
+
protectedHeaderString = encode(JSON.stringify(this.#protectedHeader));
|
|
59973
|
+
protectedHeaderBytes = encode$1(protectedHeaderString);
|
|
59888
59974
|
}
|
|
59889
59975
|
else {
|
|
59890
|
-
|
|
59976
|
+
protectedHeaderString = '';
|
|
59977
|
+
protectedHeaderBytes = new Uint8Array();
|
|
59891
59978
|
}
|
|
59892
|
-
const data = concat(
|
|
59979
|
+
const data = concat(protectedHeaderBytes, encode$1('.'), payloadB);
|
|
59893
59980
|
const k = await normalizeKey(key, alg);
|
|
59894
59981
|
const signature = await sign(alg, k, data);
|
|
59895
59982
|
const jws = {
|
|
59896
59983
|
signature: encode(signature),
|
|
59897
|
-
payload:
|
|
59984
|
+
payload: payloadS,
|
|
59898
59985
|
};
|
|
59899
|
-
if (b64) {
|
|
59900
|
-
jws.payload = decoder.decode(payload);
|
|
59901
|
-
}
|
|
59902
59986
|
if (this.#unprotectedHeader) {
|
|
59903
59987
|
jws.header = this.#unprotectedHeader;
|
|
59904
59988
|
}
|
|
59905
59989
|
if (this.#protectedHeader) {
|
|
59906
|
-
jws.protected =
|
|
59990
|
+
jws.protected = protectedHeaderString;
|
|
59907
59991
|
}
|
|
59908
59992
|
return jws;
|
|
59909
59993
|
}
|
|
@@ -60208,7 +60292,7 @@
|
|
|
60208
60292
|
default:
|
|
60209
60293
|
throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
|
|
60210
60294
|
}
|
|
60211
|
-
const data =
|
|
60295
|
+
const data = encode$1(JSON.stringify(components));
|
|
60212
60296
|
return encode(await digest(digestAlgorithm, data));
|
|
60213
60297
|
}
|
|
60214
60298
|
async function calculateJwkThumbprintUri(key, digestAlgorithm) {
|
|
@@ -60357,7 +60441,7 @@
|
|
|
60357
60441
|
let USER_AGENT;
|
|
60358
60442
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
60359
60443
|
const NAME = 'jose';
|
|
60360
|
-
const VERSION = 'v6.1.
|
|
60444
|
+
const VERSION = 'v6.1.3';
|
|
60361
60445
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
60362
60446
|
}
|
|
60363
60447
|
const customFetch = Symbol();
|
|
@@ -60663,7 +60747,7 @@
|
|
|
60663
60747
|
algorithm = {
|
|
60664
60748
|
name: 'RSA-PSS',
|
|
60665
60749
|
hash: `SHA-${alg.slice(-3)}`,
|
|
60666
|
-
publicExponent:
|
|
60750
|
+
publicExponent: Uint8Array.of(0x01, 0x00, 0x01),
|
|
60667
60751
|
modulusLength: getModulusLengthOption(options),
|
|
60668
60752
|
};
|
|
60669
60753
|
keyUsages = ['sign', 'verify'];
|
|
@@ -60674,7 +60758,7 @@
|
|
|
60674
60758
|
algorithm = {
|
|
60675
60759
|
name: 'RSASSA-PKCS1-v1_5',
|
|
60676
60760
|
hash: `SHA-${alg.slice(-3)}`,
|
|
60677
|
-
publicExponent:
|
|
60761
|
+
publicExponent: Uint8Array.of(0x01, 0x00, 0x01),
|
|
60678
60762
|
modulusLength: getModulusLengthOption(options),
|
|
60679
60763
|
};
|
|
60680
60764
|
keyUsages = ['sign', 'verify'];
|
|
@@ -60686,7 +60770,7 @@
|
|
|
60686
60770
|
algorithm = {
|
|
60687
60771
|
name: 'RSA-OAEP',
|
|
60688
60772
|
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
|
|
60689
|
-
publicExponent:
|
|
60773
|
+
publicExponent: Uint8Array.of(0x01, 0x00, 0x01),
|
|
60690
60774
|
modulusLength: getModulusLengthOption(options),
|
|
60691
60775
|
};
|
|
60692
60776
|
keyUsages = ['decrypt', 'unwrapKey', 'encrypt', 'wrapKey'];
|