@polyjose/node 0.0.0-stage → 0.1.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/facade/api.js ADDED
@@ -0,0 +1,567 @@
1
+ /**
2
+ * The polyjose JS facade (ADR 0030, ADR 0031 §1, ADR 0047), shared unchanged by
3
+ * `@polyjose/node` and `@polyjose/wasm`. Each package's entry binds it to its native layer:
4
+ *
5
+ * ```ts
6
+ * export const { version, errorCodes, jwsVerifyCompact, ... } = createApi(backend);
7
+ * export { PolyjoseError, ERROR_CODES } from "./api.js";
8
+ * ```
9
+ *
10
+ * The facade adds idiom only (ADR 0030 §1): Promises, object↔JSON, JS type checks
11
+ * (`TypeError`), `null` → `undefined`, the JS clock for JWT `now`, and `PolyjoseError`.
12
+ * Policy, defaults and every JOSE check stay in the core.
13
+ */
14
+ import { ERROR_CODES } from "./error-codes.js";
15
+ import { allowList, bare, bool, bytes, isAbsent, json, list, member, optBool, optBytes, optJson, optSeconds, optStr, optStrList, optU32, outBytes, outIndex, outList, outObject, outStr, put, record, str, u32, wipe, } from "./normalize.js";
16
+ export { ERROR_CODES } from "./error-codes.js";
17
+ /**
18
+ * A polyjose failure (ADR 0030 §5). `code` is one of {@link ERROR_CODES}, the core's stable
19
+ * `Error::code()` (ADR 0007): match on it, never on `message`, which may be reworded. Neither
20
+ * ever contains key material or input bytes.
21
+ */
22
+ export class PolyjoseError extends Error {
23
+ name = "PolyjoseError";
24
+ /** The stable error code. */
25
+ code;
26
+ constructor(code, message) {
27
+ super(message);
28
+ this.code = code;
29
+ }
30
+ }
31
+ // --- records: validated, rebuilt with only known, present members -------------------------
32
+ // Each reads the caller's members only from `record`'s own-member copy and returns a `bare`
33
+ // (prototype-less) record, so a polluted `Object.prototype` reaches neither (0013 F04).
34
+ // A record with byte members takes the call's `copies` list: see `bytes` and `run`.
35
+ function signOptions(v, at) {
36
+ const o = record(v, at, ["protectedHeader", "protectedB64u", "detached"]);
37
+ const out = bare({});
38
+ put(out, "protectedHeader", optJson(o["protectedHeader"], `${at}.protectedHeader`));
39
+ put(out, "protectedB64u", optStr(o["protectedB64u"], `${at}.protectedB64u`));
40
+ put(out, "detached", optBool(o["detached"], `${at}.detached`));
41
+ return out;
42
+ }
43
+ function signer(v, at) {
44
+ const o = record(v, at, ["key", "protectedHeader", "protectedB64u", "unprotectedHeader"]);
45
+ const out = bare({ key: json(o["key"], `${at}.key`) });
46
+ put(out, "protectedHeader", optJson(o["protectedHeader"], `${at}.protectedHeader`));
47
+ put(out, "protectedB64u", optStr(o["protectedB64u"], `${at}.protectedB64u`));
48
+ put(out, "unprotectedHeader", optJson(o["unprotectedHeader"], `${at}.unprotectedHeader`));
49
+ return out;
50
+ }
51
+ function jwsVerifyOptions(v, at, copies) {
52
+ const o = record(v, at, ["allowedAlgs", "detachedPayload", "maxInputLen", "maxSignatures"]);
53
+ const out = bare({ allowedAlgs: allowList(o["allowedAlgs"], `${at}.allowedAlgs`) });
54
+ put(out, "detachedPayload", optBytes(o["detachedPayload"], `${at}.detachedPayload`, copies));
55
+ put(out, "maxInputLen", optU32(o["maxInputLen"], `${at}.maxInputLen`));
56
+ put(out, "maxSignatures", optU32(o["maxSignatures"], `${at}.maxSignatures`));
57
+ return out;
58
+ }
59
+ function recipient(v, at, copies) {
60
+ const o = record(v, at, ["alg", "key", "header", "apu", "apv", "p2c", "p2sLen"]);
61
+ const out = bare({ alg: str(o["alg"], `${at}.alg`), key: json(o["key"], `${at}.key`) });
62
+ put(out, "header", optJson(o["header"], `${at}.header`));
63
+ put(out, "apu", optBytes(o["apu"], `${at}.apu`, copies));
64
+ put(out, "apv", optBytes(o["apv"], `${at}.apv`, copies));
65
+ put(out, "p2c", optU32(o["p2c"], `${at}.p2c`));
66
+ put(out, "p2sLen", optU32(o["p2sLen"], `${at}.p2sLen`));
67
+ return out;
68
+ }
69
+ function encryptOptions(v, at, copies) {
70
+ const o = record(v, at, ["enc", "recipients", "protectedHeader", "sharedUnprotectedHeader", "aad", "compress"]);
71
+ const out = bare({
72
+ enc: str(o["enc"], `${at}.enc`),
73
+ recipients: list(o["recipients"], `${at}.recipients`, (r, rat) => recipient(r, rat, copies)),
74
+ });
75
+ put(out, "protectedHeader", optJson(o["protectedHeader"], `${at}.protectedHeader`));
76
+ put(out, "sharedUnprotectedHeader", optJson(o["sharedUnprotectedHeader"], `${at}.sharedUnprotectedHeader`));
77
+ put(out, "aad", optBytes(o["aad"], `${at}.aad`, copies));
78
+ put(out, "compress", optBool(o["compress"], `${at}.compress`));
79
+ return out;
80
+ }
81
+ function decryptOptions(v, at) {
82
+ const o = record(v, at, [
83
+ "allowedAlgs",
84
+ "allowedEnc",
85
+ "maxPbes2Count",
86
+ "maxDecompressedLen",
87
+ "maxInputLen",
88
+ "maxRecipients",
89
+ "understoodCrit",
90
+ ]);
91
+ const out = bare({
92
+ allowedAlgs: allowList(o["allowedAlgs"], `${at}.allowedAlgs`),
93
+ allowedEnc: allowList(o["allowedEnc"], `${at}.allowedEnc`),
94
+ });
95
+ put(out, "maxPbes2Count", optU32(o["maxPbes2Count"], `${at}.maxPbes2Count`));
96
+ put(out, "maxDecompressedLen", optU32(o["maxDecompressedLen"], `${at}.maxDecompressedLen`));
97
+ put(out, "maxInputLen", optU32(o["maxInputLen"], `${at}.maxInputLen`));
98
+ put(out, "maxRecipients", optU32(o["maxRecipients"], `${at}.maxRecipients`));
99
+ put(out, "understoodCrit", optStrList(o["understoodCrit"], `${at}.understoodCrit`));
100
+ return out;
101
+ }
102
+ function jwtSignOptions(v, at) {
103
+ const o = record(v, at, ["alg", "typ", "omitTyp", "accessToken", "header"]);
104
+ const out = bare({ alg: str(o["alg"], `${at}.alg`) });
105
+ put(out, "typ", optStr(o["typ"], `${at}.typ`));
106
+ put(out, "omitTyp", optBool(o["omitTyp"], `${at}.omitTyp`));
107
+ put(out, "accessToken", optBool(o["accessToken"], `${at}.accessToken`));
108
+ put(out, "header", optJson(o["header"], `${at}.header`));
109
+ return out;
110
+ }
111
+ function jwtVerifyOptions(v, at) {
112
+ const o = record(v, at, [
113
+ "allowedAlgs",
114
+ "now",
115
+ "issuers",
116
+ "audiences",
117
+ "subject",
118
+ "leeway",
119
+ "maxAge",
120
+ "requiredClaims",
121
+ "allowMissingExp",
122
+ "ignoreAudience",
123
+ "typ",
124
+ "anyTyp",
125
+ "profile",
126
+ "maxKeyCandidates",
127
+ "maxInputLen",
128
+ ]);
129
+ const options = bare({ allowedAlgs: allowList(o["allowedAlgs"], `${at}.allowedAlgs`) });
130
+ put(options, "issuers", optStrList(o["issuers"], `${at}.issuers`));
131
+ put(options, "audiences", optStrList(o["audiences"], `${at}.audiences`));
132
+ put(options, "subject", optStr(o["subject"], `${at}.subject`));
133
+ put(options, "leeway", optU32(o["leeway"], `${at}.leeway`));
134
+ put(options, "maxAge", optU32(o["maxAge"], `${at}.maxAge`));
135
+ put(options, "requiredClaims", optStrList(o["requiredClaims"], `${at}.requiredClaims`));
136
+ put(options, "allowMissingExp", optBool(o["allowMissingExp"], `${at}.allowMissingExp`));
137
+ put(options, "ignoreAudience", optBool(o["ignoreAudience"], `${at}.ignoreAudience`));
138
+ put(options, "typ", optStr(o["typ"], `${at}.typ`));
139
+ put(options, "anyTyp", optBool(o["anyTyp"], `${at}.anyTyp`));
140
+ put(options, "profile", optStr(o["profile"], `${at}.profile`));
141
+ put(options, "maxKeyCandidates", optU32(o["maxKeyCandidates"], `${at}.maxKeyCandidates`));
142
+ put(options, "maxInputLen", optU32(o["maxInputLen"], `${at}.maxInputLen`));
143
+ return { options, now: optSeconds(o["now"], `${at}.now`) };
144
+ }
145
+ /**
146
+ * The JWT clock (ADR 0028 §4, ADR 0030 §4): the caller's `now` wins; otherwise the JS wall
147
+ * clock, floored to whole seconds, read at the call (in `run`'s synchronous preparation, so a
148
+ * pending `ready()` can't delay the reading). A clock reading, not a policy default:
149
+ * `@polyjose/node` and `@polyjose/wasm` behave identically and no Rust code reads time.
150
+ */
151
+ function withNow(prepared) {
152
+ return bare({ ...prepared.options, now: prepared.now ?? Math.floor(Date.now() / 1000) });
153
+ }
154
+ function selector(v, at) {
155
+ const o = record(v, at, ["kid", "alg", "keyUse"]);
156
+ const out = bare({});
157
+ put(out, "kid", optStr(o["kid"], `${at}.kid`));
158
+ put(out, "alg", optStr(o["alg"], `${at}.alg`));
159
+ put(out, "keyUse", optStr(o["keyUse"], `${at}.keyUse`));
160
+ return out;
161
+ }
162
+ /** A positional `detached` flag: absent is `false`, the ADR 0030 `detached: bool = false`. */
163
+ function detachedFlag(v, at) {
164
+ return isAbsent(v) ? false : bool(v, at);
165
+ }
166
+ // --- results ------------------------------------------------------------------------------
167
+ /** An optional JSON-object member of a backend result; absent (`null`/`undefined`) is left out. */
168
+ function optObject(v, name, at) {
169
+ const raw = member(v, name, at);
170
+ return isAbsent(raw) ? undefined : outObject(raw, `${at}.${name}`);
171
+ }
172
+ function jwsVerified(v, at) {
173
+ const out = {
174
+ alg: outStr(member(v, "alg", at), `${at}.alg`),
175
+ payload: outBytes(member(v, "payload", at), `${at}.payload`),
176
+ signatureIndex: outIndex(member(v, "signatureIndex", at), `${at}.signatureIndex`),
177
+ };
178
+ put(out, "protectedHeader", optObject(v, "protectedHeader", at));
179
+ put(out, "unprotectedHeader", optObject(v, "unprotectedHeader", at));
180
+ return out;
181
+ }
182
+ function jweDecrypted(v, at) {
183
+ const out = {
184
+ plaintext: outBytes(member(v, "plaintext", at), `${at}.plaintext`),
185
+ header: outObject(member(v, "header", at), `${at}.header`),
186
+ recipientIndex: outIndex(member(v, "recipientIndex", at), `${at}.recipientIndex`),
187
+ };
188
+ put(out, "protectedHeader", optObject(v, "protectedHeader", at));
189
+ put(out, "sharedUnprotectedHeader", optObject(v, "sharedUnprotectedHeader", at));
190
+ put(out, "recipientHeader", optObject(v, "recipientHeader", at));
191
+ const aad = member(v, "aad", at);
192
+ put(out, "aad", isAbsent(aad) ? undefined : outBytes(aad, `${at}.aad`));
193
+ return out;
194
+ }
195
+ function jwtVerified(v, at) {
196
+ const out = {
197
+ claims: outObject(member(v, "claims", at), `${at}.claims`),
198
+ header: outObject(member(v, "header", at), `${at}.header`),
199
+ alg: outStr(member(v, "alg", at), `${at}.alg`),
200
+ };
201
+ // `keyIndex` 0 is a real index (ADR 0029 §4): only null/undefined mean absent.
202
+ const keyIndex = member(v, "keyIndex", at);
203
+ put(out, "keyIndex", isAbsent(keyIndex) ? undefined : outIndex(keyIndex, `${at}.keyIndex`));
204
+ const kid = member(v, "kid", at);
205
+ put(out, "kid", isAbsent(kid) ? undefined : outStr(kid, `${at}.kid`));
206
+ return out;
207
+ }
208
+ function jwtNestedVerified(v, at) {
209
+ return {
210
+ inner: jwtVerified(member(v, "inner", at), `${at}.inner`),
211
+ outerHeader: outObject(member(v, "outerHeader", at), `${at}.outerHeader`),
212
+ recipientIndex: outIndex(member(v, "recipientIndex", at), `${at}.recipientIndex`),
213
+ };
214
+ }
215
+ const jwk = (v, at) => outObject(v, at);
216
+ // --- errors -------------------------------------------------------------------------------
217
+ /**
218
+ * `e`'s own data member `name`, or `undefined` (0013 F09, F12): never read through a prototype,
219
+ * so a polluted `Object.prototype.code` or `Error.prototype.message` can't stand in for one the
220
+ * backend didn't set, and never through a getter, so reading runs no backend or caller code.
221
+ * napi-rs (`napi_create_error`) and wasm-bindgen (`Reflect::set`) set `code` and `message` as
222
+ * own data properties.
223
+ */
224
+ function ownData(e, name) {
225
+ if ((typeof e !== "object" || e === null) && typeof e !== "function")
226
+ return undefined;
227
+ try {
228
+ const d = Object.getOwnPropertyDescriptor(e, name);
229
+ return d !== undefined && "value" in d ? d.value : undefined;
230
+ }
231
+ catch {
232
+ return undefined; // a Proxy whose trap throws has no readable member
233
+ }
234
+ }
235
+ /** `e instanceof C`, false if a hostile `Proxy` or `Symbol.hasInstance` throws. */
236
+ function isInstance(e, C) {
237
+ try {
238
+ return e instanceof C;
239
+ }
240
+ catch {
241
+ return false;
242
+ }
243
+ }
244
+ /** One of the generated {@link ERROR_CODES}, the core's `Error::CODES` this facade was built from. */
245
+ function isErrorCode(code) {
246
+ return ERROR_CODES.includes(code);
247
+ }
248
+ /**
249
+ * napi-rs's argument-conversion `Status` names: the `code` napi-rs puts on the JS error when a
250
+ * caller's value can't be converted to the Rust parameter type (napi 3.16, `Status` and its
251
+ * `AsRef<str>`; Node-API `napi_status`). Other statuses (`GenericFailure`, `PendingException`,
252
+ * `Cancelled`, ...) don't say the caller misused the API, so they pass through unchanged.
253
+ */
254
+ const NAPI_ARGUMENT_STATUSES = new Set([
255
+ "InvalidArg",
256
+ "ObjectExpected",
257
+ "StringExpected",
258
+ "NameExpected",
259
+ "FunctionExpected",
260
+ "NumberExpected",
261
+ "BooleanExpected",
262
+ "ArrayExpected",
263
+ "BigintExpected",
264
+ "DateExpected",
265
+ "ArrayBufferExpected",
266
+ "DetachableArraybufferExpected",
267
+ ]);
268
+ /** `e`'s own string `message`, or `fallback`: never a prototype's (0013 F12). */
269
+ function ownMessage(e, fallback) {
270
+ const m = ownData(e, "message");
271
+ return typeof m === "string" ? m : fallback;
272
+ }
273
+ /**
274
+ * A backend failure as the facade reports it (ADR 0030 §5, ADR 0031 §1, BACKEND.md "Errors";
275
+ * 0013 F04, F12). `code` and `message` are read as own data members only.
276
+ *
277
+ * 1. An own `code` that is in the generated {@link ERROR_CODES} and in the backend's
278
+ * `errorCodes()` gives a `PolyjoseError` with the backend's own message, so
279
+ * `PolyjoseError.code` is always an {@link ErrorCode} even if the backend and the facade
280
+ * versions drift (F04, review N2). `codes` throws if the backend can't list its codes; that
281
+ * error is reported instead. It is asked only for a code in `ERROR_CODES`, the only codes
282
+ * that could become a `PolyjoseError`.
283
+ * 2. A host argument error is a `TypeError` with the original message: a `TypeError` (a wasm
284
+ * reader's), returned as is, or an `Error` whose own `code` is one of
285
+ * {@link NAPI_ARGUMENT_STATUSES}, re-made as a `TypeError`.
286
+ * 3. Anything else is returned unchanged, the same value: a `WebAssembly.RuntimeError` trap, a
287
+ * backend's own "unusable, reload it" refusal, another napi status, a code only one side
288
+ * knows. It isn't the caller's misuse, so it isn't reported as a `TypeError` (F12).
289
+ */
290
+ function mapError(e, codes) {
291
+ const code = ownData(e, "code");
292
+ if (typeof code === "string" && isErrorCode(code) && codes().has(code))
293
+ return new PolyjoseError(code, ownMessage(e, code));
294
+ if (isInstance(e, TypeError))
295
+ return e;
296
+ if (typeof code === "string" && NAPI_ARGUMENT_STATUSES.has(code) && isInstance(e, Error)) {
297
+ return new TypeError(ownMessage(e, `polyjose: the backend could not convert an argument (${code})`));
298
+ }
299
+ return e;
300
+ }
301
+ function describe(e) {
302
+ if ((typeof e === "object" && e !== null) || typeof e === "function")
303
+ return "the backend threw a value with no message";
304
+ try {
305
+ return String(e);
306
+ }
307
+ catch {
308
+ return "polyjose: the backend failed";
309
+ }
310
+ }
311
+ /** Binds the facade to one native layer (BACKEND.md). */
312
+ export function createApi(backend) {
313
+ let initialised = backend.ready === undefined;
314
+ let pending;
315
+ let codeSet;
316
+ /**
317
+ * Awaits `backend.ready()` once, lazily, on first use (ADR 0031 §3: WASM initialises without
318
+ * top-level await). A failure is reported unchanged and the next call tries again.
319
+ */
320
+ function ready() {
321
+ if (initialised)
322
+ return undefined;
323
+ const init = backend.ready;
324
+ if (init === undefined)
325
+ return undefined;
326
+ pending ??= Promise.resolve()
327
+ .then(() => init.call(backend))
328
+ .then(() => {
329
+ initialised = true;
330
+ }, (e) => {
331
+ pending = undefined;
332
+ throw e;
333
+ });
334
+ return pending;
335
+ }
336
+ /**
337
+ * The backend's `errorCodes()`, read once, on the first failure to map (0013 F04, review N2).
338
+ * If the backend can't list them (it throws, or returns no array), the facade can't tell a core
339
+ * failure from a host one, so it throws an `Error` naming the cause rather than reporting every
340
+ * core failure as a `TypeError`; nothing is cached, and the next failure asks again.
341
+ */
342
+ const codes = () => {
343
+ if (codeSet !== undefined)
344
+ return codeSet;
345
+ let listed;
346
+ try {
347
+ listed = backend.errorCodes();
348
+ }
349
+ catch (e) {
350
+ throw new Error(`polyjose: the backend's errorCodes() failed (${ownMessage(e, describe(e))}), so a backend error can't be mapped`, {
351
+ cause: e,
352
+ });
353
+ }
354
+ if (!Array.isArray(listed))
355
+ throw new Error("polyjose: the backend's errorCodes() did not return an array, so a backend error can't be mapped");
356
+ // Own elements only: `filter` would read a hole through a polluted `Array.prototype` and map
357
+ // a code the backend never listed (0013 F09).
358
+ const own = new Set();
359
+ for (let i = 0; i < listed.length; i++) {
360
+ const c = Object.hasOwn(listed, i) ? listed[i] : undefined;
361
+ if (typeof c === "string")
362
+ own.add(c);
363
+ }
364
+ codeSet = own;
365
+ return codeSet;
366
+ };
367
+ /** Initialises, calls the backend, and maps its sync throws and rejections. */
368
+ async function invoke(call) {
369
+ const waiting = ready();
370
+ if (waiting !== undefined)
371
+ await waiting;
372
+ try {
373
+ return await call();
374
+ }
375
+ catch (e) {
376
+ throw mapError(e, codes);
377
+ }
378
+ }
379
+ /**
380
+ * One operation with arguments (ADR 0030 §2, §7; ADR 0031 §1, §3; 0013 B06).
381
+ *
382
+ * `prepare` runs synchronously, when the operation is called and before anything is awaited:
383
+ * it validates and normalises every argument (a `TypeError` rejects the call before
384
+ * `ready()` or the backend is reached), copies each byte input into a fresh `Uint8Array`
385
+ * recorded in `copies`, serialises JSON objects, reads the JWT clock, and returns the backend
386
+ * call. Only that call waits for `ready()`, so nothing the caller does to its arrays or objects
387
+ * after starting the call changes what is processed. Once the backend call settles, success or
388
+ * failure, the copies are wiped with `fill(0)`; they are never handed back to the caller.
389
+ */
390
+ async function run(prepare, output) {
391
+ const copies = [];
392
+ try {
393
+ const call = prepare(copies);
394
+ return output(await invoke(call));
395
+ }
396
+ finally {
397
+ wipe(copies);
398
+ }
399
+ }
400
+ const b = backend;
401
+ return {
402
+ version: async () => outStr(await invoke(() => b.version()), "version"),
403
+ // Own elements only (0013 F09): a hole is reported, never read through `Array.prototype`.
404
+ errorCodes: async () => outList(await invoke(() => b.errorCodes()), "errorCodes", outStr),
405
+ base64urlEncode: (input) => run((copies) => {
406
+ const data = bytes(input, "base64urlEncode: bytes", copies);
407
+ return () => b.base64urlEncode(data);
408
+ }, (r) => outStr(r, "base64urlEncode")),
409
+ base64urlDecode: (input) => run(() => {
410
+ const text = str(input, "base64urlDecode: text");
411
+ return () => b.base64urlDecode(text);
412
+ }, (r) => outBytes(r, "base64urlDecode")),
413
+ jwkParse: (key) => run(() => {
414
+ const k = json(key, "jwkParse: jwk");
415
+ return () => b.jwkParse(k);
416
+ }, (r) => jwk(r, "jwkParse")),
417
+ jwkToPublic: (key) => run(() => {
418
+ const k = json(key, "jwkToPublic: jwk");
419
+ return () => b.jwkToPublic(k);
420
+ }, (r) => jwk(r, "jwkToPublic")),
421
+ // `hash` is optional (ADR 0054 §9): null and undefined reach the backend as undefined, so
422
+ // the core's default applies; a name is passed as given, for the core to parse (§8.2).
423
+ jwkThumbprint: (key, hash) => run(() => {
424
+ const k = json(key, "jwkThumbprint: jwk");
425
+ const h = optStr(hash, "jwkThumbprint: hash");
426
+ return () => b.jwkThumbprint(k, h);
427
+ }, (r) => outStr(r, "jwkThumbprint")),
428
+ jwkThumbprintUri: (key, hash) => run(() => {
429
+ const k = json(key, "jwkThumbprintUri: jwk");
430
+ const h = optStr(hash, "jwkThumbprintUri: hash");
431
+ return () => b.jwkThumbprintUri(k, h);
432
+ }, (r) => outStr(r, "jwkThumbprintUri")),
433
+ jwksSelect: (jwks, criteria) => run(() => {
434
+ const set = json(jwks, "jwksSelect: jwks");
435
+ const sel = selector(criteria, "jwksSelect: selector");
436
+ return () => b.jwksSelect(set, sel);
437
+ }, (r) => jwk(r, "jwksSelect")),
438
+ jwkGenerateOct: (lenBytes) => run(() => {
439
+ const n = u32(lenBytes, "jwkGenerateOct: lenBytes");
440
+ return () => b.jwkGenerateOct(n);
441
+ }, (r) => jwk(r, "jwkGenerateOct")),
442
+ jwkGenerateEc: (crv) => run(() => {
443
+ const c = str(crv, "jwkGenerateEc: crv");
444
+ return () => b.jwkGenerateEc(c);
445
+ }, (r) => jwk(r, "jwkGenerateEc")),
446
+ jwkGenerateOkp: (crv) => run(() => {
447
+ const c = str(crv, "jwkGenerateOkp: crv");
448
+ return () => b.jwkGenerateOkp(c);
449
+ }, (r) => jwk(r, "jwkGenerateOkp")),
450
+ jwkGenerateForAlg: (alg) => run(() => {
451
+ const a = str(alg, "jwkGenerateForAlg: alg");
452
+ return () => b.jwkGenerateForAlg(a);
453
+ }, (r) => jwk(r, "jwkGenerateForAlg")),
454
+ jwkFromPem: (pem) => run(() => {
455
+ const p = str(pem, "jwkFromPem: pem");
456
+ return () => b.jwkFromPem(p);
457
+ }, (r) => jwk(r, "jwkFromPem")),
458
+ jwkFromDer: (der, format) => run((copies) => {
459
+ const d = bytes(der, "jwkFromDer: der", copies);
460
+ const f = str(format, "jwkFromDer: format");
461
+ return () => b.jwkFromDer(d, f);
462
+ }, (r) => jwk(r, "jwkFromDer")),
463
+ jwkToPem: (key, format) => run(() => {
464
+ const k = json(key, "jwkToPem: jwk");
465
+ const f = str(format, "jwkToPem: format");
466
+ return () => b.jwkToPem(k, f);
467
+ }, (r) => outStr(r, "jwkToPem")),
468
+ jwkToDer: (key, format) => run(() => {
469
+ const k = json(key, "jwkToDer: jwk");
470
+ const f = str(format, "jwkToDer: format");
471
+ return () => b.jwkToDer(k, f);
472
+ }, (r) => outBytes(r, "jwkToDer")),
473
+ jwsSignCompact: (payload, key, options) => run((copies) => {
474
+ const p = bytes(payload, "jwsSignCompact: payload", copies);
475
+ const k = json(key, "jwsSignCompact: key");
476
+ const o = signOptions(options, "jwsSignCompact: options");
477
+ return () => b.jwsSignCompact(p, k, o);
478
+ }, (r) => outStr(r, "jwsSignCompact")),
479
+ jwsSignFlattened: (payload, one, detached) => run((copies) => {
480
+ const p = bytes(payload, "jwsSignFlattened: payload", copies);
481
+ const s = signer(one, "jwsSignFlattened: signer");
482
+ const d = detachedFlag(detached, "jwsSignFlattened: detached");
483
+ return () => b.jwsSignFlattened(p, s, d);
484
+ }, (r) => outStr(r, "jwsSignFlattened")),
485
+ jwsSignGeneral: (payload, signers, detached) => run((copies) => {
486
+ const p = bytes(payload, "jwsSignGeneral: payload", copies);
487
+ const s = list(signers, "jwsSignGeneral: signers", signer);
488
+ const d = detachedFlag(detached, "jwsSignGeneral: detached");
489
+ return () => b.jwsSignGeneral(p, s, d);
490
+ }, (r) => outStr(r, "jwsSignGeneral")),
491
+ jwsVerifyCompact: (token, key, options) => run((copies) => {
492
+ const t = str(token, "jwsVerifyCompact: token");
493
+ const k = json(key, "jwsVerifyCompact: key");
494
+ const o = jwsVerifyOptions(options, "jwsVerifyCompact: options", copies);
495
+ return () => b.jwsVerifyCompact(t, k, o);
496
+ }, (r) => jwsVerified(r, "jwsVerifyCompact")),
497
+ jwsVerifyJson: (jws, key, options) => run((copies) => {
498
+ const t = json(jws, "jwsVerifyJson: jws");
499
+ const k = json(key, "jwsVerifyJson: key");
500
+ const o = jwsVerifyOptions(options, "jwsVerifyJson: options", copies);
501
+ return () => b.jwsVerifyJson(t, k, o);
502
+ }, (r) => jwsVerified(r, "jwsVerifyJson")),
503
+ jweEncryptCompact: (plaintext, options) => run((copies) => {
504
+ const p = bytes(plaintext, "jweEncryptCompact: plaintext", copies);
505
+ const o = encryptOptions(options, "jweEncryptCompact: options", copies);
506
+ return () => b.jweEncryptCompact(p, o);
507
+ }, (r) => outStr(r, "jweEncryptCompact")),
508
+ jweEncryptJson: (plaintext, options, form) => run((copies) => {
509
+ const p = bytes(plaintext, "jweEncryptJson: plaintext", copies);
510
+ const o = encryptOptions(options, "jweEncryptJson: options", copies);
511
+ const f = str(form, "jweEncryptJson: form");
512
+ return () => b.jweEncryptJson(p, o, f);
513
+ }, (r) => outStr(r, "jweEncryptJson")),
514
+ jweDecryptCompact: (token, key, options) => run(() => {
515
+ const t = str(token, "jweDecryptCompact: token");
516
+ const k = json(key, "jweDecryptCompact: key");
517
+ const o = decryptOptions(options, "jweDecryptCompact: options");
518
+ return () => b.jweDecryptCompact(t, k, o);
519
+ }, (r) => jweDecrypted(r, "jweDecryptCompact")),
520
+ jweDecryptJson: (jwe, key, options) => run(() => {
521
+ const t = json(jwe, "jweDecryptJson: jwe");
522
+ const k = json(key, "jweDecryptJson: key");
523
+ const o = decryptOptions(options, "jweDecryptJson: options");
524
+ return () => b.jweDecryptJson(t, k, o);
525
+ }, (r) => jweDecrypted(r, "jweDecryptJson")),
526
+ jwtSign: (claims, key, options) => run(() => {
527
+ const c = json(claims, "jwtSign: claims");
528
+ const k = json(key, "jwtSign: key");
529
+ const o = jwtSignOptions(options, "jwtSign: options");
530
+ return () => b.jwtSign(c, k, o);
531
+ }, (r) => outStr(r, "jwtSign")),
532
+ jwtVerify: (token, key, options) => run(() => {
533
+ const t = str(token, "jwtVerify: token");
534
+ const k = json(key, "jwtVerify: key");
535
+ const o = withNow(jwtVerifyOptions(options, "jwtVerify: options"));
536
+ return () => b.jwtVerify(t, k, o);
537
+ }, (r) => jwtVerified(r, "jwtVerify")),
538
+ jwtVerifyWithJwks: (token, jwks, options) => run(() => {
539
+ const t = str(token, "jwtVerifyWithJwks: token");
540
+ const s = json(jwks, "jwtVerifyWithJwks: jwks");
541
+ const o = withNow(jwtVerifyOptions(options, "jwtVerifyWithJwks: options"));
542
+ return () => b.jwtVerifyWithJwks(t, s, o);
543
+ }, (r) => jwtVerified(r, "jwtVerifyWithJwks")),
544
+ jwtEncryptNested: (signedJwt, options) => run((copies) => {
545
+ const t = str(signedJwt, "jwtEncryptNested: signedJwt");
546
+ const o = encryptOptions(options, "jwtEncryptNested: options", copies);
547
+ return () => b.jwtEncryptNested(t, o);
548
+ }, (r) => outStr(r, "jwtEncryptNested")),
549
+ jwtDecryptNested: (token, decryptKey, decrypt, key, verify) => run(() => {
550
+ const t = str(token, "jwtDecryptNested: token");
551
+ const dk = json(decryptKey, "jwtDecryptNested: decryptKey");
552
+ const d = decryptOptions(decrypt, "jwtDecryptNested: decryptOptions");
553
+ const k = json(key, "jwtDecryptNested: key");
554
+ const v = withNow(jwtVerifyOptions(verify, "jwtDecryptNested: verifyOptions"));
555
+ return () => b.jwtDecryptNested(t, dk, d, k, v);
556
+ }, (r) => jwtNestedVerified(r, "jwtDecryptNested")),
557
+ jwtDecryptNestedWithJwks: (token, decryptKey, decrypt, jwks, verify) => run(() => {
558
+ const t = str(token, "jwtDecryptNestedWithJwks: token");
559
+ const dk = json(decryptKey, "jwtDecryptNestedWithJwks: decryptKey");
560
+ const d = decryptOptions(decrypt, "jwtDecryptNestedWithJwks: decryptOptions");
561
+ const s = json(jwks, "jwtDecryptNestedWithJwks: jwks");
562
+ const v = withNow(jwtVerifyOptions(verify, "jwtDecryptNestedWithJwks: verifyOptions"));
563
+ return () => b.jwtDecryptNestedWithJwks(t, dk, d, s, v);
564
+ }, (r) => jwtNestedVerified(r, "jwtDecryptNestedWithJwks")),
565
+ PolyjoseError,
566
+ };
567
+ }