@polyjose/node 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.d.ts ADDED
@@ -0,0 +1,469 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
+
12
+ /**
13
+ * Decodes strict unpadded base64url (RFC 4648 §5, RFC 7515 §2): padding, characters outside the
14
+ * URL-safe alphabet, whitespace and non-canonical trailing bits reject with `InvalidBase64`.
15
+ * Resolves to a `Uint8Array`.
16
+ */
17
+ export declare function base64urlDecode(text: string): Promise<unknown>
18
+
19
+ /** Encodes `data` as unpadded base64url (RFC 4648 §5, RFC 7515 §2). Resolves to a string. */
20
+ export declare function base64urlEncode(data: Uint8Array): Promise<unknown>
21
+
22
+ /**
23
+ * Every stable error code, in the core's order: equal to `polyjose::Error::CODES` (ADR 0030 §5).
24
+ * Synchronous.
25
+ */
26
+ export declare function errorCodes(): Array<string>
27
+
28
+ /**
29
+ * Decrypts the compact JWE `token` with the JWK `key` under `options.allowedAlgs` and
30
+ * `options.allowedEnc` (RFC 7516 §5.2, RFC 8725 §3.1). Resolves to `{ plaintext, header,
31
+ * protectedHeader?, sharedUnprotectedHeader?, recipientHeader?, aad?, recipientIndex }`.
32
+ */
33
+ export declare function jweDecryptCompact(token: string, key: string, options: JweDecryptOptions): Promise<unknown>
34
+
35
+ /** A decrypted JWE (RFC 7516 §5.2): the result of `jweDecryptCompact`/`jweDecryptJson`. */
36
+ export interface JweDecrypted {
37
+ /** The plaintext, copied from the surface's zeroizing buffer (ADR 0030 §7). */
38
+ plaintext: Uint8Array
39
+ /**
40
+ * The JOSE Header used (the union of the header members, RFC 7516 §5.2 step 4), as JSON
41
+ * text. Only its protected members are integrity-protected (ADR 0050 §3).
42
+ */
43
+ header: string
44
+ /** The JWE Protected Header as JSON text, when present (RFC 7516 §7.2.1). */
45
+ protectedHeader?: string
46
+ /** The JWE Shared Unprotected Header as JSON text, when present (RFC 7516 §7.2.1). */
47
+ sharedUnprotectedHeader?: string
48
+ /**
49
+ * The recipient's JWE Per-Recipient Unprotected Header as JSON text, when present
50
+ * (RFC 7516 §7.2.1).
51
+ */
52
+ recipientHeader?: string
53
+ /** The JWE AAD, when present, copied from the surface's zeroizing buffer (ADR 0050 §4). */
54
+ aad?: Uint8Array
55
+ /** The index of the recipient that decrypted (RFC 7516 §7.2.1). */
56
+ recipientIndex: number
57
+ }
58
+
59
+ /**
60
+ * Decrypts the JWE JSON Serialization `jwe` with the JWK `key` (RFC 7516 §5.2, §7.2,
61
+ * RFC 8725 §3.1). Resolves like [`jwe_decrypt_compact`].
62
+ */
63
+ export declare function jweDecryptJson(jwe: string, key: string, options: JweDecryptOptions): Promise<unknown>
64
+
65
+ /**
66
+ * Options of `jweDecryptCompact`/`jweDecryptJson` and the outer layer of nested JWT decryption
67
+ * (RFC 7516 §5.2, RFC 8725 §3.1). `allowedAlgs` and `allowedEnc` are required (ADR 0007); the
68
+ * limits default in the core (ADR 0023, ADR 0050 §2).
69
+ */
70
+ export interface JweDecryptOptions {
71
+ /** The key management algorithms the caller accepts (RFC 8725 §3.1). */
72
+ allowedAlgs: Array<string>
73
+ /** The content encryption algorithms the caller accepts (RFC 8725 §3.1). */
74
+ allowedEnc: Array<string>
75
+ /** The PBES2 iteration budget per token (ADR 0050 §2). */
76
+ maxPbes2Count?: number
77
+ /** The largest decompressed plaintext, in octets (ADR 0017). */
78
+ maxDecompressedLen?: number
79
+ /** The longest input accepted, in octets. */
80
+ maxInputLen?: number
81
+ /** The most recipients a JSON Serialization may carry. */
82
+ maxRecipients?: number
83
+ /** Extra `crit` names the caller understands (RFC 7516 §4.1.13, RFC 7515 §4.1.11). */
84
+ understoodCrit?: Array<string>
85
+ }
86
+
87
+ /**
88
+ * Encrypts `plaintext` for the single recipient of `options` into a JWE Compact Serialization
89
+ * (RFC 7516 §5.1, §7.1). Resolves to the token.
90
+ */
91
+ export declare function jweEncryptCompact(plaintext: Uint8Array, options: JweEncryptOptions): Promise<unknown>
92
+
93
+ /**
94
+ * Encrypts `plaintext` for the recipients of `options` into a JWE JSON Serialization of `form`
95
+ * (`general`, RFC 7516 §7.2.1, or `flattened`, §7.2.2). Resolves to JSON text.
96
+ */
97
+ export declare function jweEncryptJson(plaintext: Uint8Array, options: JweEncryptOptions, form: string): Promise<unknown>
98
+
99
+ /** Options of `jweEncryptCompact`/`jweEncryptJson`/`jwtEncryptNested` (RFC 7516 §5.1). */
100
+ export interface JweEncryptOptions {
101
+ /** The content encryption algorithm, as registered (RFC 7518 §5.1). */
102
+ enc: string
103
+ /** The JWE Protected Header as JSON text (RFC 7516 §7.2.1). */
104
+ protectedHeader?: string
105
+ /** The JWE Shared Unprotected Header as JSON text (RFC 7516 §7.2.1). */
106
+ sharedUnprotectedHeader?: string
107
+ /** The JWE AAD (RFC 7516 §5.1 step 14). Secret (ADR 0050 §4). */
108
+ aad?: Uint8Array
109
+ /** Compress with DEFLATE before encryption (RFC 7516 §4.1.3). Absent: no compression. */
110
+ compress?: boolean
111
+ /**
112
+ * The recipients (exactly one for the compact form, RFC 7516 §7.1). They hold the secret
113
+ * keys, so they are declared last: see the module docs.
114
+ */
115
+ recipients: Array<JweRecipient>
116
+ }
117
+
118
+ /** One recipient of a JWE (RFC 7516 §7.2.1, RFC 7518 §4). The key is secret (ADR 0030 §7). */
119
+ export interface JweRecipient {
120
+ /** The key management algorithm, as registered (RFC 7518 §4.1). */
121
+ alg: string
122
+ /** The per-recipient JWE Unprotected Header as JSON text (RFC 7516 §7.2.1). */
123
+ header?: string
124
+ /** The ECDH-ES `apu` (RFC 7518 §4.6.1.2). */
125
+ apu?: Uint8Array
126
+ /** The ECDH-ES `apv` (RFC 7518 §4.6.1.3). */
127
+ apv?: Uint8Array
128
+ /** The PBES2 iteration count (RFC 7518 §4.8.1.2). */
129
+ p2c?: number
130
+ /** The PBES2 salt input length, in octets (RFC 7518 §4.8.1.1). */
131
+ p2sLen?: number
132
+ /** The recipient JWK as JSON text (RFC 7517 §4). Declared last: see the module docs. */
133
+ key: string
134
+ }
135
+
136
+ /**
137
+ * Imports a DER key in `format` (`pkcs8` RFC 5958, `sec1` RFC 5915, `spki` RFC 5280 §4.1,
138
+ * `pkcs1` RFC 8017 Appendix A.1.1) as a JWK; another format rejects with
139
+ * `UnsupportedAlgorithm`. The borrowed bytes are copied on the JS thread. Resolves to JWK JSON
140
+ * text.
141
+ */
142
+ export declare function jwkFromDer(der: Uint8Array, format: string): Promise<unknown>
143
+
144
+ /**
145
+ * Imports a PEM key (`PRIVATE KEY`, `EC PRIVATE KEY`, `PUBLIC KEY`, `RSA PUBLIC KEY`;
146
+ * RFC 7468 §10, §11, §13) as a JWK. RSA private keys reject with `UnsupportedAlgorithm`
147
+ * (ADR 0021). Resolves to JWK JSON text.
148
+ */
149
+ export declare function jwkFromPem(pem: string): Promise<unknown>
150
+
151
+ /**
152
+ * Generates an EC private JWK on `crv` (`P-256`, `P-384`, `P-521`, `secp256k1`) (RFC 7518
153
+ * §6.2, RFC 8812 §3.1); another name rejects with `UnsupportedAlgorithm`. Resolves to JWK JSON
154
+ * text.
155
+ */
156
+ export declare function jwkGenerateEc(crv: string): Promise<unknown>
157
+
158
+ /**
159
+ * Generates a JWK for the JWS `alg`, JWE `alg` or `enc` name, with `alg` set (RFC 7517 §4.4,
160
+ * RFC 7518 §3.1, §4.1, §5.1). RSA rejects with `UnsupportedAlgorithm` (ADR 0021). Resolves to
161
+ * JWK JSON text.
162
+ */
163
+ export declare function jwkGenerateForAlg(alg: string): Promise<unknown>
164
+
165
+ /**
166
+ * Generates an `oct` JWK of `lenBytes` octets (16..=512) from the OS CSPRNG (RFC 7518 §6.4,
167
+ * ADR 0005); out of range rejects with `InvalidKey`. Resolves to JWK JSON text.
168
+ */
169
+ export declare function jwkGenerateOct(lenBytes: number): Promise<unknown>
170
+
171
+ /**
172
+ * Generates an OKP private JWK on `crv` (`Ed25519`, `X25519`) (RFC 8037 §2); another name
173
+ * rejects with `UnsupportedAlgorithm`. Resolves to JWK JSON text.
174
+ */
175
+ export declare function jwkGenerateOkp(crv: string): Promise<unknown>
176
+
177
+ /**
178
+ * Validates `jwk` and returns it re-serialized by the core, members in core order (RFC 7517 §4,
179
+ * RFC 7518 §6, RFC 8037 §2). Resolves to JWK JSON text.
180
+ */
181
+ export declare function jwkParse(jwk: string): Promise<unknown>
182
+
183
+ /**
184
+ * Which member of a JWK Set `jwksSelect` picks; an absent member places no constraint
185
+ * (RFC 7517 §4.2, §4.4, §4.5, §5).
186
+ */
187
+ export interface JwkSelector {
188
+ /** The JWK `kid` to match exactly (RFC 7517 §4.5). */
189
+ kid?: string
190
+ /** The algorithm the key must serve, as registered (RFC 7517 §4.4). */
191
+ alg?: string
192
+ /** The JWK `use` to match, `sig` or `enc` (RFC 7517 §4.2). JS: `keyUse`. */
193
+ keyUse?: string
194
+ }
195
+
196
+ /**
197
+ * The one member of the JWK Set `jwks` that `selector` picks (RFC 7517 §5, §4.2, §4.4, §4.5),
198
+ * by the core's `JwkSet::select` rule (ADR 0054 §2, ADR 0057 §1). Each selector member is passed
199
+ * on unchanged; an absent one places no constraint.
200
+ *
201
+ * Rejects, the first error being the outcome (ADR 0054 §4): the set's import errors, then
202
+ * `UnsupportedAlgorithm` for an `alg` or `keyUse` the core refuses, then `NoMatchingKey` when no
203
+ * member matches or `MultipleMatchingKeys` when more than one does (ADR 0054 §5). Resolves to
204
+ * the member's JWK JSON text, which may be private, so it is built from the surface's
205
+ * `SecretString` (ADR 0030 §7.2).
206
+ */
207
+ export declare function jwksSelect(jwks: string, selector: JwkSelector): Promise<unknown>
208
+
209
+ /**
210
+ * The JWK Thumbprint of `jwk` under `hash`, base64url-encoded (RFC 7638 §3, RFC 9278 §5).
211
+ *
212
+ * `hash` is optional and passed on unchanged (ADR 0054 §9; ADR 0030 §1, §3: the adapter has no
213
+ * default). Absent, `undefined` or `null` is `None`, the core default SHA-256 (RFC 9278 §5). A
214
+ * name is parsed by the core: `sha-256`, `SHA-256`, `sha256` and the same forms for 384 and 512,
215
+ * exactly (ADR 0054 §8.2); any other, SHA-1 among them, rejects with `UnsupportedAlgorithm`
216
+ * (ADR 0022). The JWK is imported first, so an invalid key is reported before an invalid name
217
+ * (ADR 0057 §2). Resolves to a string of 43, 64 or 86 characters.
218
+ */
219
+ export declare function jwkThumbprint(jwk: string, hash?: string | undefined | null): Promise<unknown>
220
+
221
+ /**
222
+ * The JWK Thumbprint URI of `jwk` under `hash`,
223
+ * `urn:ietf:params:oauth:jwk-thumbprint:<hash>:<thumbprint>` (RFC 9278 §3), `<hash>` being the
224
+ * IANA name (`sha-256`, `sha-384`, `sha-512`, RFC 9278 §4) whichever spelling was passed.
225
+ * `hash` is as for `jwkThumbprint` (ADR 0054 §9, ADR 0057 §2). Resolves to a string.
226
+ */
227
+ export declare function jwkThumbprintUri(jwk: string, hash?: string | undefined | null): Promise<unknown>
228
+
229
+ /**
230
+ * Exports `jwk` as DER in `format` (`pkcs8`, `sec1`, `spki`, `pkcs1`). A private key exports
231
+ * secret octets (ADR 0030 §7). Resolves to a `Uint8Array`.
232
+ */
233
+ export declare function jwkToDer(jwk: string, format: string): Promise<unknown>
234
+
235
+ /**
236
+ * Exports `jwk` as PEM in `format` (`pkcs8`, `sec1`, `spki`, `pkcs1`; RFC 7468). A private key
237
+ * exports secret text (ADR 0030 §7). Resolves to a string.
238
+ */
239
+ export declare function jwkToPem(jwk: string, format: string): Promise<unknown>
240
+
241
+ /**
242
+ * The public form of `jwk` (RFC 7517 §4, RFC 7518 §6.2.2, §6.3.2, RFC 8037 §2); an `oct` key
243
+ * has none and rejects with `UnsupportedAlgorithm`. Resolves to JWK JSON text.
244
+ */
245
+ export declare function jwkToPublic(jwk: string): Promise<unknown>
246
+
247
+ /**
248
+ * Signs `payload` with the JWK `key` into a JWS Compact Serialization (RFC 7515 §5.1, §7.1),
249
+ * detached on request (RFC 7515 Appendix F). Resolves to the token.
250
+ */
251
+ export declare function jwsSignCompact(payload: Uint8Array, key: string, options: JwsSignOptions): Promise<unknown>
252
+
253
+ /**
254
+ * One signature of a JWS JSON Serialization (RFC 7515 §7.2.1): the key and its headers, with
255
+ * the `JwsSignOptions` header rule (ADR 0030 §4). The key is secret (ADR 0030 §7).
256
+ */
257
+ export interface JwsSigner {
258
+ /** The JWS Protected Header as JSON text (RFC 7515 §7.2.1). */
259
+ protectedHeader?: string
260
+ /** The JWS Protected Header already base64url-encoded (RFC 7515 §7.2.1). */
261
+ protectedB64u?: string
262
+ /** The JWS Unprotected Header as JSON text (RFC 7515 §7.2.1). */
263
+ unprotectedHeader?: string
264
+ /** The signing JWK as JSON text (RFC 7517 §4). Declared last: see the module docs. */
265
+ key: string
266
+ }
267
+
268
+ /**
269
+ * Signs `payload` for one signer into a flattened JWS JSON Serialization (RFC 7515 §7.2.2).
270
+ * Resolves to JSON text.
271
+ */
272
+ export declare function jwsSignFlattened(payload: Uint8Array, signer: JwsSigner, detached: boolean): Promise<unknown>
273
+
274
+ /**
275
+ * Signs `payload` for every signer into a general JWS JSON Serialization (RFC 7515 §7.2.1).
276
+ * Resolves to JSON text.
277
+ */
278
+ export declare function jwsSignGeneral(payload: Uint8Array, signers: Array<JwsSigner>, detached: boolean): Promise<unknown>
279
+
280
+ /**
281
+ * Options of `jwsSignCompact` (RFC 7515 §5.1, §7.1). Exactly one of `protectedHeader` and
282
+ * `protectedB64u`; both or neither reject with `InvalidHeader` (ADR 0030 §4).
283
+ */
284
+ export interface JwsSignOptions {
285
+ /** The JWS Protected Header as JSON text (RFC 7515 §5.1 step 3). */
286
+ protectedHeader?: string
287
+ /**
288
+ * The JWS Protected Header already base64url-encoded, signed over as given (RFC 7515 §5.1
289
+ * step 3, Appendix A.1).
290
+ */
291
+ protectedB64u?: string
292
+ /** Leave the payload out of the output (RFC 7515 Appendix F). Absent: not detached. */
293
+ detached?: boolean
294
+ }
295
+
296
+ /** A verified JWS (RFC 7515 §5.2): the result of `jwsVerifyCompact`/`jwsVerifyJson`. */
297
+ export interface JwsVerified {
298
+ /** The algorithm that verified (RFC 7515 §4.1.1). */
299
+ alg: string
300
+ /** The payload octets, copied from the surface's zeroizing buffer (ADR 0049 §4). */
301
+ payload: Uint8Array
302
+ /** The JWS Protected Header as JSON text, when present (RFC 7515 §4). */
303
+ protectedHeader?: string
304
+ /**
305
+ * The JWS Unprotected Header as JSON text, when present; not integrity-protected
306
+ * (RFC 7515 §7.2.1, ADR 0049 §2).
307
+ */
308
+ unprotectedHeader?: string
309
+ /** The index of the signature that verified (RFC 7515 §7.2.1). */
310
+ signatureIndex: number
311
+ }
312
+
313
+ /**
314
+ * Verifies the compact JWS `token` with the JWK `key` under `options.allowedAlgs` (RFC 7515
315
+ * §5.2, RFC 8725 §3.1). Resolves to `{ alg, payload, protectedHeader?, unprotectedHeader?,
316
+ * signatureIndex }`.
317
+ */
318
+ export declare function jwsVerifyCompact(token: string, key: string, options: JwsVerifyOptions): Promise<unknown>
319
+
320
+ /**
321
+ * Verifies the JWS JSON Serialization `jws` (flattened or general) with the JWK `key` under
322
+ * `options.allowedAlgs` (RFC 7515 §5.2, §7.2, RFC 8725 §3.1). Resolves like
323
+ * [`jws_verify_compact`].
324
+ */
325
+ export declare function jwsVerifyJson(jws: string, key: string, options: JwsVerifyOptions): Promise<unknown>
326
+
327
+ /**
328
+ * Options of `jwsVerifyCompact`/`jwsVerifyJson` (RFC 7515 §5.2, RFC 8725 §3.1). `allowedAlgs`
329
+ * is required (ADR 0007); the limits default in the core (ADR 0026 §7).
330
+ */
331
+ export interface JwsVerifyOptions {
332
+ /**
333
+ * The algorithms the caller accepts (RFC 8725 §3.1). Empty rejects with
334
+ * `AlgorithmNotAllowed`.
335
+ */
336
+ allowedAlgs: Array<string>
337
+ /** The payload of a detached JWS (RFC 7515 Appendix F). Secret (ADR 0030 §7). */
338
+ detachedPayload?: Uint8Array
339
+ /** The longest input accepted, in octets (ADR 0026 §7). */
340
+ maxInputLen?: number
341
+ /** The most signatures a JSON Serialization may carry (ADR 0026 §7). */
342
+ maxSignatures?: number
343
+ }
344
+
345
+ /**
346
+ * Decrypts the nested JWT `token` with `decryptKey` under `decryptOptions`, then verifies the
347
+ * inner JWT with `key` under `verifyOptions` (RFC 7519 §7.2 step 8, RFC 8725 §3). Resolves to
348
+ * `{ inner, outerHeader, recipientIndex }`.
349
+ */
350
+ export declare function jwtDecryptNested(token: string, decryptKey: string, decryptOptions: JweDecryptOptions, key: string, verifyOptions: JwtVerifyOptions): Promise<unknown>
351
+
352
+ /**
353
+ * Like [`jwt_decrypt_nested`], verifying the inner JWT with a member of the JWK Set `jwks`
354
+ * (ADR 0029).
355
+ */
356
+ export declare function jwtDecryptNestedWithJwks(token: string, decryptKey: string, decryptOptions: JweDecryptOptions, jwks: string, verifyOptions: JwtVerifyOptions): Promise<unknown>
357
+
358
+ /**
359
+ * Encrypts the signed JWT `signedJwt` into a compact JWE for the single recipient of `options`,
360
+ * `cty: "JWT"` set by the core (RFC 7519 §5.2, §7.1 step 5). Resolves to the token.
361
+ */
362
+ export declare function jwtEncryptNested(signedJwt: string, options: JweEncryptOptions): Promise<unknown>
363
+
364
+ /**
365
+ * A verified nested JWT (RFC 7519 §5.2, §7.2 step 8): the result of `jwtDecryptNested` and
366
+ * `jwtDecryptNestedWithJwks`.
367
+ */
368
+ export interface JwtNestedVerified {
369
+ /** The inner, signed JWT. */
370
+ inner: JwtVerified
371
+ /** The outer JWE's JOSE Header as JSON text (RFC 7516 §5.2). */
372
+ outerHeader: string
373
+ /** The index of the JWE recipient that decrypted (RFC 7516 §7.2.1). */
374
+ recipientIndex: number
375
+ }
376
+
377
+ /**
378
+ * Signs the JWT Claims Set `claims` (JSON text) with the JWK `key` (RFC 7519 §7.1). RS*\/PS*
379
+ * signing rejects with `UnsupportedAlgorithm` (ADR 0021). Resolves to the token.
380
+ */
381
+ export declare function jwtSign(claims: string, key: string, options: JwtSignOptions): Promise<unknown>
382
+
383
+ /**
384
+ * Options of `jwtSign` (RFC 7519 §7.1, RFC 9068 §2.1). `typ` together with `omitTyp` or
385
+ * `accessToken` rejects with `InvalidHeader` (ADR 0030 §4).
386
+ */
387
+ export interface JwtSignOptions {
388
+ /** The signing algorithm, as registered (RFC 7518 §3.1). */
389
+ alg: string
390
+ /** The `typ` header; absent: the core default `JWT` (RFC 7519 §5.1). */
391
+ typ?: string
392
+ /** Write no `typ` header. Absent: not set. */
393
+ omitTyp?: boolean
394
+ /** Issue an RFC 9068 access token (`typ: at+jwt`, RFC 9068 §2.1). Absent: not set. */
395
+ accessToken?: boolean
396
+ /** Extra JWS Protected Header members as a JSON object text (RFC 7515 §4). */
397
+ header?: string
398
+ }
399
+
400
+ /** A verified JWT (RFC 7519 §7.2): the result of `jwtVerify`/`jwtVerifyWithJwks`. */
401
+ export interface JwtVerified {
402
+ /**
403
+ * The claims as the core's JSON serialization (ADR 0027 §1). Plain in the API (ADR 0058,
404
+ * owner decision 2); the adapter's copy is wiped all the same (see the module docs).
405
+ */
406
+ claims: string
407
+ /** The JOSE Header as JSON text (RFC 7519 §5). */
408
+ header: string
409
+ /** The algorithm that verified (RFC 7515 §4.1.1). */
410
+ alg: string
411
+ /** The index of the JWK Set member that verified, for a set (ADR 0029). */
412
+ keyIndex?: number
413
+ /** The `kid` of the key that verified, when it has one (RFC 7517 §4.5). */
414
+ kid?: string
415
+ }
416
+
417
+ /**
418
+ * Verifies the signed JWT `token` with the JWK `key` and validates its claims under `options`
419
+ * (RFC 7519 §7.2, RFC 8725 §3; ADR 0027 §9 fixes the error order). Resolves to `{ claims,
420
+ * header, alg, keyIndex?, kid? }`.
421
+ */
422
+ export declare function jwtVerify(token: string, key: string, options: JwtVerifyOptions): Promise<unknown>
423
+
424
+ /**
425
+ * Options of the JWT verify operations (RFC 7519 §7.2, RFC 8725 §3, RFC 9068 §4). Each field
426
+ * maps to one core `Policy` method, and an absent one calls nothing (ADR 0030 §4, ADR 0027).
427
+ * The facade always passes `now` (ADR 0028 §4); an absent one reaches the surface as `None`.
428
+ */
429
+ export interface JwtVerifyOptions {
430
+ /** The algorithms the caller accepts (RFC 8725 §3.1). */
431
+ allowedAlgs: Array<string>
432
+ /** The verification time, whole seconds since the epoch (RFC 7519 §2, ADR 0028). */
433
+ now?: number
434
+ /** The accepted `iss` values (RFC 7519 §4.1.1). */
435
+ issuers?: Array<string>
436
+ /** The accepted `aud` values (RFC 7519 §4.1.3). */
437
+ audiences?: Array<string>
438
+ /** The required `sub` (RFC 7519 §4.1.2). */
439
+ subject?: string
440
+ /** Clock skew allowance in seconds (RFC 7519 §4.1.4, §4.1.5). */
441
+ leeway?: number
442
+ /** The oldest `iat` accepted, in seconds (RFC 7519 §4.1.6). */
443
+ maxAge?: number
444
+ /** Claims that must be present (RFC 7519 §4). */
445
+ requiredClaims?: Array<string>
446
+ /** Accept a token without `exp` (RFC 7519 §4.1.4). Absent: not set. */
447
+ allowMissingExp?: boolean
448
+ /** Do not check `aud` (RFC 7519 §4.1.3). Absent: not set. */
449
+ ignoreAudience?: boolean
450
+ /** The expected `typ` header (RFC 8725 §3.11). */
451
+ typ?: string
452
+ /** Accept any `typ` (RFC 8725 §3.11). Absent: not set. */
453
+ anyTyp?: boolean
454
+ /** A validation profile, `access_token` (RFC 9068 §4). */
455
+ profile?: string
456
+ /** The most JWK Set members tried (ADR 0029). */
457
+ maxKeyCandidates?: number
458
+ /** The longest token accepted, in octets. */
459
+ maxInputLen?: number
460
+ }
461
+
462
+ /**
463
+ * Verifies the signed JWT `token` with a member of the JWK Set `jwks` (RFC 7517 §5, ADR 0029;
464
+ * no member verifying rejects with `NoMatchingKey`). Resolves like [`jwt_verify`].
465
+ */
466
+ export declare function jwtVerifyWithJwks(token: string, jwks: string, options: JwtVerifyOptions): Promise<unknown>
467
+
468
+ /** The polyjose crate version, e.g. `0.1.0` (ADR 0030 §4). Synchronous. */
469
+ export declare function version(): string
@@ -0,0 +1,123 @@
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 type { Backend } from "./backend.js";
15
+ import { type ErrorCode } from "./error-codes.js";
16
+ import type { EcCurve, JsonInput, JweDecrypted, JweDecryptOptions, JweEncryptOptions, JweJsonForm, Jwk, JwkObject, JwkSelector, JwkSet, JwsSigner, JwsSignOptions, JwsVerified, JwsVerifyOptions, JwtNestedVerified, JwtSignOptions, JwtVerified, JwtVerifyOptions, KeyFormat, OkpCurve, ThumbprintHash } from "./types.js";
17
+ export type * from "./types.js";
18
+ export type { Backend } from "./backend.js";
19
+ export { ERROR_CODES, type ErrorCode } from "./error-codes.js";
20
+ /**
21
+ * A polyjose failure (ADR 0030 §5). `code` is one of {@link ERROR_CODES}, the core's stable
22
+ * `Error::code()` (ADR 0007): match on it, never on `message`, which may be reworded. Neither
23
+ * ever contains key material or input bytes.
24
+ */
25
+ export declare class PolyjoseError extends Error {
26
+ readonly name = "PolyjoseError";
27
+ /** The stable error code. */
28
+ readonly code: ErrorCode;
29
+ constructor(code: ErrorCode, message: string);
30
+ }
31
+ /** Every operation of ADR 0030 §4, camelCase (§2), each returning a Promise (ADR 0031 §1). */
32
+ export interface PolyjoseApi {
33
+ /** The polyjose crate version. */
34
+ version(): Promise<string>;
35
+ /** The stable error codes, equal to the core's `Error::CODES` (ADR 0030 §5). */
36
+ errorCodes(): Promise<string[]>;
37
+ /** base64url without padding (RFC 4648 §5, RFC 7515 §2). */
38
+ base64urlEncode(bytes: Uint8Array): Promise<string>;
39
+ /** Strict, canonical base64url decoding (RFC 4648 §5, §3.5). */
40
+ base64urlDecode(text: string): Promise<Uint8Array>;
41
+ /** Validates a JWK (RFC 7517 §4, RFC 7518 §6, RFC 8037 §2) and returns the core's serialization. */
42
+ jwkParse(jwk: Jwk): Promise<JwkObject>;
43
+ /** The public half of a JWK (RFC 7517 §4, RFC 7518 §6.2.1, §6.3.1). */
44
+ jwkToPublic(jwk: Jwk): Promise<JwkObject>;
45
+ /**
46
+ * The JWK Thumbprint (RFC 7638 §3, §3.4), base64url: 43, 64 or 86 characters for SHA-256,
47
+ * SHA-384 or SHA-512. An absent `hash` (or `null`) is the core default, SHA-256 (ADR 0054 §9,
48
+ * RFC 9278 §5). Any other name fails with `UnsupportedAlgorithm` from the core, after the key's
49
+ * own import errors (ADR 0057 §2). Never publish the thumbprint of a password or other
50
+ * low-entropy `oct` key, or use it as a `kid`: it is an unsalted fast hash of the secret
51
+ * (ADR 0057 §4, RFC 7638 §7).
52
+ */
53
+ jwkThumbprint(jwk: Jwk, hash?: ThumbprintHash): Promise<string>;
54
+ /**
55
+ * The JWK Thumbprint URI (RFC 9278 §3), `urn:ietf:params:oauth:jwk-thumbprint:<name>:<thumbprint>`,
56
+ * always with the IANA hash name (`sha-256`, `sha-384`, `sha-512`; RFC 9278 §4). `hash` is as
57
+ * for `jwkThumbprint`.
58
+ */
59
+ jwkThumbprintUri(jwk: Jwk, hash?: ThumbprintHash): Promise<string>;
60
+ /**
61
+ * The one key of a JWK Set (RFC 7517 §5) that `selector` picks by `kid`, `alg` and `keyUse`,
62
+ * under the core rule (`JwkSet::select`, ADR 0054 §2). An absent selector (or `{}`) matches
63
+ * every member. No match rejects with `NoMatchingKey`, two or more with `MultipleMatchingKeys`
64
+ * (RFC 7517 §5.1 gives a set's order no meaning); an `alg` or `keyUse` the core refuses with
65
+ * `UnsupportedAlgorithm`, after the set's own import errors (ADR 0054 §4).
66
+ *
67
+ * The key may be private (`d`, `k`): call `jwkToPublic` before publishing it. Selection never
68
+ * authorizes an algorithm, so pass the key only to an operation with an allow-list, and pair a
69
+ * `kid` from an untrusted header with `alg` (ADR 0054 §7). A server maps `NoMatchingKey` and
70
+ * `MultipleMatchingKeys` to one opaque client error, such as `invalid_token` (RFC 6750 §3.1).
71
+ */
72
+ jwksSelect(jwks: JwkSet, selector?: JwkSelector): Promise<JwkObject>;
73
+ /** A random `oct` key of `lenBytes` octets (RFC 7518 §6.4), from the OS CSPRNG (ADR 0005). */
74
+ jwkGenerateOct(lenBytes: number): Promise<JwkObject>;
75
+ /** A random EC private key (RFC 7518 §6.2). */
76
+ jwkGenerateEc(crv: EcCurve): Promise<JwkObject>;
77
+ /** A random OKP private key (RFC 8037 §2). */
78
+ jwkGenerateOkp(crv: OkpCurve): Promise<JwkObject>;
79
+ /** A random key for a JWS `alg`, JWE `alg` or `enc` (RFC 7518 §7.1 registry), with `alg` set. */
80
+ jwkGenerateForAlg(alg: string): Promise<JwkObject>;
81
+ /** Imports one RFC 7468 PEM block (ADR 0018 §3). */
82
+ jwkFromPem(pem: string): Promise<JwkObject>;
83
+ /** Imports DER in the structure `format` names; no sniffing (ADR 0018 §3, ADR 0007). */
84
+ jwkFromDer(der: Uint8Array, format: KeyFormat): Promise<JwkObject>;
85
+ /** Exports a JWK as PEM (RFC 7468, ADR 0018 §3). */
86
+ jwkToPem(jwk: Jwk, format: KeyFormat): Promise<string>;
87
+ /** Exports a JWK as DER (ADR 0018 §3). */
88
+ jwkToDer(jwk: Jwk, format: KeyFormat): Promise<Uint8Array>;
89
+ /** Signs in the JWS Compact Serialization (RFC 7515 §5.1, §7.1). */
90
+ jwsSignCompact(payload: Uint8Array, key: Jwk, options: JwsSignOptions): Promise<string>;
91
+ /** Signs in the flattened JWS JSON Serialization (RFC 7515 §7.2.2); returns JSON text. */
92
+ jwsSignFlattened(payload: Uint8Array, signer: JwsSigner, detached?: boolean): Promise<string>;
93
+ /** Signs in the general JWS JSON Serialization (RFC 7515 §7.2.1); returns JSON text. */
94
+ jwsSignGeneral(payload: Uint8Array, signers: readonly JwsSigner[], detached?: boolean): Promise<string>;
95
+ /** Verifies a compact JWS against an explicit allow-list (RFC 7515 §5.2, RFC 8725 §3.1). */
96
+ jwsVerifyCompact(token: string, key: Jwk, options: JwsVerifyOptions): Promise<JwsVerified>;
97
+ /** Verifies a flattened or general JWS JSON Serialization (RFC 7515 §7.2, §5.2). */
98
+ jwsVerifyJson(jws: JsonInput, key: Jwk, options: JwsVerifyOptions): Promise<JwsVerified>;
99
+ /** Encrypts to one recipient in the JWE Compact Serialization (RFC 7516 §5.1, §7.1). */
100
+ jweEncryptCompact(plaintext: Uint8Array, options: JweEncryptOptions): Promise<string>;
101
+ /** Encrypts in a JWE JSON Serialization (RFC 7516 §7.2); returns JSON text. */
102
+ jweEncryptJson(plaintext: Uint8Array, options: JweEncryptOptions, form: JweJsonForm): Promise<string>;
103
+ /** Decrypts a compact JWE against explicit allow-lists (RFC 7516 §5.2, RFC 8725 §3.1). */
104
+ jweDecryptCompact(token: string, key: Jwk, options: JweDecryptOptions): Promise<JweDecrypted>;
105
+ /** Decrypts a flattened or general JWE JSON Serialization (RFC 7516 §7.2, §5.2). */
106
+ jweDecryptJson(jwe: JsonInput, key: Jwk, options: JweDecryptOptions): Promise<JweDecrypted>;
107
+ /** Issues a signed JWT (RFC 7519 §7.1; ADR 0027 §8). */
108
+ jwtSign(claims: JsonInput, key: Jwk, options: JwtSignOptions): Promise<string>;
109
+ /** Validates a signed JWT with one key (RFC 7519 §7.2; ADR 0027 policy and error order). */
110
+ jwtVerify(token: string, key: Jwk, options: JwtVerifyOptions): Promise<JwtVerified>;
111
+ /** Validates a signed JWT with a JWK Set (RFC 7517 §5; ADR 0029 selection). */
112
+ jwtVerifyWithJwks(token: string, jwks: JwkSet, options: JwtVerifyOptions): Promise<JwtVerified>;
113
+ /** Encrypts a signed JWT as a nested JWT, `cty: "JWT"` (RFC 7519 §5.2, §11.2; ADR 0027 §7). */
114
+ jwtEncryptNested(signedJwt: string, options: JweEncryptOptions): Promise<string>;
115
+ /** Decrypts and validates a nested JWT with one verification key (RFC 7519 §7.2 step 8). */
116
+ jwtDecryptNested(token: string, decryptKey: Jwk, decryptOptions: JweDecryptOptions, key: Jwk, verifyOptions: JwtVerifyOptions): Promise<JwtNestedVerified>;
117
+ /** Decrypts and validates a nested JWT with a JWK Set for the inner signature. */
118
+ jwtDecryptNestedWithJwks(token: string, decryptKey: Jwk, decryptOptions: JweDecryptOptions, jwks: JwkSet, verifyOptions: JwtVerifyOptions): Promise<JwtNestedVerified>;
119
+ /** The error class every operation rejects with for a core failure. */
120
+ readonly PolyjoseError: typeof PolyjoseError;
121
+ }
122
+ /** Binds the facade to one native layer (BACKEND.md). */
123
+ export declare function createApi(backend: Backend): PolyjoseApi;