@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/LICENSE +21 -0
- package/README.md +98 -2
- package/THIRD-PARTY-NOTICES.txt +16006 -0
- package/addon-sha256.json +10 -0
- package/backend.d.ts +86 -0
- package/backend.js +253 -0
- package/facade/api.d.ts +123 -0
- package/facade/api.js +567 -0
- package/facade/backend.d.ts +159 -0
- package/facade/backend.js +19 -0
- package/facade/error-codes.d.ts +4 -0
- package/facade/error-codes.js +22 -0
- package/facade/normalize.d.ts +134 -0
- package/facade/normalize.js +380 -0
- package/facade/types.d.ts +206 -0
- package/facade/types.js +14 -0
- package/index.d.ts +11 -0
- package/index.js +12 -0
- package/package.json +60 -4
- package/polyjose.darwin-arm64.node +0 -0
- package/polyjose.darwin-x64.node +0 -0
- package/polyjose.linux-arm64-gnu.node +0 -0
- package/polyjose.linux-arm64-musl.node +0 -0
- package/polyjose.linux-x64-gnu.node +0 -0
- package/polyjose.linux-x64-musl.node +0 -0
- package/polyjose.win32-arm64-msvc.node +0 -0
- package/polyjose.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The backend contract: what each native layer (`@polyjose/node`'s napi-rs loader,
|
|
3
|
+
* `@polyjose/wasm`'s wasm-bindgen glue) exports for the facade (ADR 0031 §1). Documented in
|
|
4
|
+
* `bindings/js/BACKEND.md`.
|
|
5
|
+
*
|
|
6
|
+
* - Every ADR 0030 §4 operation, camelCase, with the ADR's argument order.
|
|
7
|
+
* - JSON-valued arguments and result fields are JSON **text**; the facade does the
|
|
8
|
+
* object↔JSON idiom (ADR 0030 §2). Rust parses with the core's strict I-JSON parser.
|
|
9
|
+
* - Records are plain objects with camelCase fields. The facade only ever passes fields it has
|
|
10
|
+
* validated; an absent optional field is **left out** (never `undefined` or `null`: napi
|
|
11
|
+
* throws on `null`, research §3).
|
|
12
|
+
* - Integers are already range-checked (u32 sizes and counts, safe-integer `now`), because
|
|
13
|
+
* wasm-bindgen coerces `-1` to `4294967295` (research §3).
|
|
14
|
+
* - Results may be returned directly or as a Promise (napi `AsyncTask`). Errors are thrown or
|
|
15
|
+
* rejected with an object whose `code` is one of `errorCodes()` (ADR 0030 §5).
|
|
16
|
+
* - `version()` and `errorCodes()` are synchronous; `ready()` is optional and awaited once,
|
|
17
|
+
* lazily, before the first call (WASM initialisation without top-level await).
|
|
18
|
+
*/
|
|
19
|
+
/** A value or a Promise of it. */
|
|
20
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
21
|
+
export interface BackendJwkSelector {
|
|
22
|
+
kid?: string;
|
|
23
|
+
alg?: string;
|
|
24
|
+
keyUse?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface BackendJwsSignOptions {
|
|
27
|
+
protectedHeader?: string;
|
|
28
|
+
protectedB64u?: string;
|
|
29
|
+
detached?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface BackendJwsSigner {
|
|
32
|
+
key: string;
|
|
33
|
+
protectedHeader?: string;
|
|
34
|
+
protectedB64u?: string;
|
|
35
|
+
unprotectedHeader?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface BackendJwsVerifyOptions {
|
|
38
|
+
allowedAlgs: string[];
|
|
39
|
+
detachedPayload?: Uint8Array;
|
|
40
|
+
maxInputLen?: number;
|
|
41
|
+
maxSignatures?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface BackendJwsVerified {
|
|
44
|
+
alg: string;
|
|
45
|
+
payload: Uint8Array;
|
|
46
|
+
protectedHeader?: string | null | undefined;
|
|
47
|
+
unprotectedHeader?: string | null | undefined;
|
|
48
|
+
signatureIndex: number;
|
|
49
|
+
}
|
|
50
|
+
export interface BackendJweRecipient {
|
|
51
|
+
alg: string;
|
|
52
|
+
key: string;
|
|
53
|
+
header?: string;
|
|
54
|
+
apu?: Uint8Array;
|
|
55
|
+
apv?: Uint8Array;
|
|
56
|
+
p2c?: number;
|
|
57
|
+
p2sLen?: number;
|
|
58
|
+
}
|
|
59
|
+
export interface BackendJweEncryptOptions {
|
|
60
|
+
enc: string;
|
|
61
|
+
recipients: BackendJweRecipient[];
|
|
62
|
+
protectedHeader?: string;
|
|
63
|
+
sharedUnprotectedHeader?: string;
|
|
64
|
+
aad?: Uint8Array;
|
|
65
|
+
compress?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface BackendJweDecryptOptions {
|
|
68
|
+
allowedAlgs: string[];
|
|
69
|
+
allowedEnc: string[];
|
|
70
|
+
maxPbes2Count?: number;
|
|
71
|
+
maxDecompressedLen?: number;
|
|
72
|
+
maxInputLen?: number;
|
|
73
|
+
maxRecipients?: number;
|
|
74
|
+
understoodCrit?: string[];
|
|
75
|
+
}
|
|
76
|
+
export interface BackendJweDecrypted {
|
|
77
|
+
plaintext: Uint8Array;
|
|
78
|
+
header: string;
|
|
79
|
+
protectedHeader?: string | null | undefined;
|
|
80
|
+
sharedUnprotectedHeader?: string | null | undefined;
|
|
81
|
+
recipientHeader?: string | null | undefined;
|
|
82
|
+
aad?: Uint8Array | null | undefined;
|
|
83
|
+
recipientIndex: number;
|
|
84
|
+
}
|
|
85
|
+
export interface BackendJwtSignOptions {
|
|
86
|
+
alg: string;
|
|
87
|
+
typ?: string;
|
|
88
|
+
omitTyp?: boolean;
|
|
89
|
+
accessToken?: boolean;
|
|
90
|
+
header?: string;
|
|
91
|
+
}
|
|
92
|
+
/** `now` is always present: the facade reads the JS clock when the caller gives none (ADR 0030 §4). */
|
|
93
|
+
export interface BackendJwtVerifyOptions {
|
|
94
|
+
allowedAlgs: string[];
|
|
95
|
+
now: number;
|
|
96
|
+
issuers?: string[];
|
|
97
|
+
audiences?: string[];
|
|
98
|
+
subject?: string;
|
|
99
|
+
leeway?: number;
|
|
100
|
+
maxAge?: number;
|
|
101
|
+
requiredClaims?: string[];
|
|
102
|
+
allowMissingExp?: boolean;
|
|
103
|
+
ignoreAudience?: boolean;
|
|
104
|
+
typ?: string;
|
|
105
|
+
anyTyp?: boolean;
|
|
106
|
+
profile?: string;
|
|
107
|
+
maxKeyCandidates?: number;
|
|
108
|
+
maxInputLen?: number;
|
|
109
|
+
}
|
|
110
|
+
export interface BackendJwtVerified {
|
|
111
|
+
claims: string;
|
|
112
|
+
header: string;
|
|
113
|
+
alg: string;
|
|
114
|
+
keyIndex?: number | null | undefined;
|
|
115
|
+
kid?: string | null | undefined;
|
|
116
|
+
}
|
|
117
|
+
export interface BackendJwtNestedVerified {
|
|
118
|
+
inner: BackendJwtVerified;
|
|
119
|
+
outerHeader: string;
|
|
120
|
+
recipientIndex: number;
|
|
121
|
+
}
|
|
122
|
+
/** The functions a native layer provides (BACKEND.md). */
|
|
123
|
+
export interface Backend {
|
|
124
|
+
/** Optional one-time initialisation, awaited lazily before the first call. */
|
|
125
|
+
ready?(): Promise<void>;
|
|
126
|
+
version(): string;
|
|
127
|
+
errorCodes(): readonly string[];
|
|
128
|
+
base64urlEncode(bytes: Uint8Array): MaybePromise<string>;
|
|
129
|
+
base64urlDecode(text: string): MaybePromise<Uint8Array>;
|
|
130
|
+
jwkParse(jwk: string): MaybePromise<string>;
|
|
131
|
+
jwkToPublic(jwk: string): MaybePromise<string>;
|
|
132
|
+
/** `hash` is `undefined` when the caller gave none: the core default, SHA-256 (ADR 0054 §9). */
|
|
133
|
+
jwkThumbprint(jwk: string, hash: string | undefined): MaybePromise<string>;
|
|
134
|
+
jwkThumbprintUri(jwk: string, hash: string | undefined): MaybePromise<string>;
|
|
135
|
+
jwksSelect(jwks: string, selector: BackendJwkSelector): MaybePromise<string>;
|
|
136
|
+
jwkGenerateOct(lenBytes: number): MaybePromise<string>;
|
|
137
|
+
jwkGenerateEc(crv: string): MaybePromise<string>;
|
|
138
|
+
jwkGenerateOkp(crv: string): MaybePromise<string>;
|
|
139
|
+
jwkGenerateForAlg(alg: string): MaybePromise<string>;
|
|
140
|
+
jwkFromPem(pem: string): MaybePromise<string>;
|
|
141
|
+
jwkFromDer(der: Uint8Array, format: string): MaybePromise<string>;
|
|
142
|
+
jwkToPem(jwk: string, format: string): MaybePromise<string>;
|
|
143
|
+
jwkToDer(jwk: string, format: string): MaybePromise<Uint8Array>;
|
|
144
|
+
jwsSignCompact(payload: Uint8Array, key: string, options: BackendJwsSignOptions): MaybePromise<string>;
|
|
145
|
+
jwsSignFlattened(payload: Uint8Array, signer: BackendJwsSigner, detached: boolean): MaybePromise<string>;
|
|
146
|
+
jwsSignGeneral(payload: Uint8Array, signers: BackendJwsSigner[], detached: boolean): MaybePromise<string>;
|
|
147
|
+
jwsVerifyCompact(token: string, key: string, options: BackendJwsVerifyOptions): MaybePromise<BackendJwsVerified>;
|
|
148
|
+
jwsVerifyJson(jws: string, key: string, options: BackendJwsVerifyOptions): MaybePromise<BackendJwsVerified>;
|
|
149
|
+
jweEncryptCompact(plaintext: Uint8Array, options: BackendJweEncryptOptions): MaybePromise<string>;
|
|
150
|
+
jweEncryptJson(plaintext: Uint8Array, options: BackendJweEncryptOptions, form: string): MaybePromise<string>;
|
|
151
|
+
jweDecryptCompact(token: string, key: string, options: BackendJweDecryptOptions): MaybePromise<BackendJweDecrypted>;
|
|
152
|
+
jweDecryptJson(jwe: string, key: string, options: BackendJweDecryptOptions): MaybePromise<BackendJweDecrypted>;
|
|
153
|
+
jwtSign(claims: string, key: string, options: BackendJwtSignOptions): MaybePromise<string>;
|
|
154
|
+
jwtVerify(token: string, key: string, options: BackendJwtVerifyOptions): MaybePromise<BackendJwtVerified>;
|
|
155
|
+
jwtVerifyWithJwks(token: string, jwks: string, options: BackendJwtVerifyOptions): MaybePromise<BackendJwtVerified>;
|
|
156
|
+
jwtEncryptNested(signedJwt: string, options: BackendJweEncryptOptions): MaybePromise<string>;
|
|
157
|
+
jwtDecryptNested(token: string, decryptKey: string, decryptOptions: BackendJweDecryptOptions, key: string, verifyOptions: BackendJwtVerifyOptions): MaybePromise<BackendJwtNestedVerified>;
|
|
158
|
+
jwtDecryptNestedWithJwks(token: string, decryptKey: string, decryptOptions: BackendJweDecryptOptions, jwks: string, verifyOptions: BackendJwtVerifyOptions): MaybePromise<BackendJwtNestedVerified>;
|
|
159
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The backend contract: what each native layer (`@polyjose/node`'s napi-rs loader,
|
|
3
|
+
* `@polyjose/wasm`'s wasm-bindgen glue) exports for the facade (ADR 0031 §1). Documented in
|
|
4
|
+
* `bindings/js/BACKEND.md`.
|
|
5
|
+
*
|
|
6
|
+
* - Every ADR 0030 §4 operation, camelCase, with the ADR's argument order.
|
|
7
|
+
* - JSON-valued arguments and result fields are JSON **text**; the facade does the
|
|
8
|
+
* object↔JSON idiom (ADR 0030 §2). Rust parses with the core's strict I-JSON parser.
|
|
9
|
+
* - Records are plain objects with camelCase fields. The facade only ever passes fields it has
|
|
10
|
+
* validated; an absent optional field is **left out** (never `undefined` or `null`: napi
|
|
11
|
+
* throws on `null`, research §3).
|
|
12
|
+
* - Integers are already range-checked (u32 sizes and counts, safe-integer `now`), because
|
|
13
|
+
* wasm-bindgen coerces `-1` to `4294967295` (research §3).
|
|
14
|
+
* - Results may be returned directly or as a Promise (napi `AsyncTask`). Errors are thrown or
|
|
15
|
+
* rejected with an object whose `code` is one of `errorCodes()` (ADR 0030 §5).
|
|
16
|
+
* - `version()` and `errorCodes()` are synchronous; `ready()` is optional and awaited once,
|
|
17
|
+
* lazily, before the first call (WASM initialisation without top-level await).
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The stable error codes of every polyjose binding, in the core's order (ADR 0030 §5). */
|
|
2
|
+
export declare const ERROR_CODES: readonly ["InvalidBase64", "InvalidJson", "InvalidHeader", "UnsupportedAlgorithm", "AlgorithmNotAllowed", "InvalidKey", "KeyAlgorithmMismatch", "InvalidSignature", "DecryptionFailed", "UnknownCritical", "TokenExpired", "TokenNotYetValid", "InvalidClaim", "RandomnessUnavailable", "InvalidFormat", "NoMatchingKey", "MultipleMatchingKeys"];
|
|
3
|
+
/** One stable error code: `PolyjoseError.code` is always one of these (ADR 0030 §5). */
|
|
4
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// GENERATED by tools/gen-error-codes.ts from crates/polyjose/src/error.rs (Error::CODES).
|
|
2
|
+
// Do not edit: `npm run build` (or bindings/js/test.sh) regenerates it (ADR 0047).
|
|
3
|
+
/** The stable error codes of every polyjose binding, in the core's order (ADR 0030 §5). */
|
|
4
|
+
export const ERROR_CODES = [
|
|
5
|
+
"InvalidBase64",
|
|
6
|
+
"InvalidJson",
|
|
7
|
+
"InvalidHeader",
|
|
8
|
+
"UnsupportedAlgorithm",
|
|
9
|
+
"AlgorithmNotAllowed",
|
|
10
|
+
"InvalidKey",
|
|
11
|
+
"KeyAlgorithmMismatch",
|
|
12
|
+
"InvalidSignature",
|
|
13
|
+
"DecryptionFailed",
|
|
14
|
+
"UnknownCritical",
|
|
15
|
+
"TokenExpired",
|
|
16
|
+
"TokenNotYetValid",
|
|
17
|
+
"InvalidClaim",
|
|
18
|
+
"RandomnessUnavailable",
|
|
19
|
+
"InvalidFormat",
|
|
20
|
+
"NoMatchingKey",
|
|
21
|
+
"MultipleMatchingKeys",
|
|
22
|
+
];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input and output normalisation of the facade: idiom only (ADR 0030 §1 host facade row, §2;
|
|
3
|
+
* ADR 0031 §1). No policy, no defaults, no JOSE validation: the core decides all of that.
|
|
4
|
+
*
|
|
5
|
+
* Every failure here is a host `TypeError`, never a `PolyjoseError` (ADR 0030 E2: host type
|
|
6
|
+
* errors stay outside the code contract). A message names the argument and the expected type,
|
|
7
|
+
* never the value, which may be key material (ADR 0030 §5, "no input in errors").
|
|
8
|
+
*/
|
|
9
|
+
import type { JsonObject } from "./types.js";
|
|
10
|
+
/** `null` and `undefined` both mean "absent" (napi throws on `null`, research §3). */
|
|
11
|
+
export declare function isAbsent(v: unknown): v is null | undefined;
|
|
12
|
+
/** A `Uint8Array`, including a Node `Buffer` (a subclass). */
|
|
13
|
+
export declare function isUint8Array(v: unknown): v is Uint8Array;
|
|
14
|
+
/** An object literal (or `Object.create(null)`), not an array or class instance. */
|
|
15
|
+
export declare function isPlainObject(v: unknown): v is Record<string, unknown>;
|
|
16
|
+
export declare function str(v: unknown, at: string): string;
|
|
17
|
+
export declare function optStr(v: unknown, at: string): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* A byte input, as a fresh copy (ADR 0030 §7; 0013 B06). The facade calls this synchronously,
|
|
20
|
+
* when the operation is called and before it awaits the backend's lazy `ready()` (ADR 0031 §3),
|
|
21
|
+
* so a caller that reuses its array after starting a call can't change what is signed or
|
|
22
|
+
* encrypted. The copy is a plain `Uint8Array` holding exactly the view's bytes (a `Buffer` or a
|
|
23
|
+
* subarray shares no memory with it) and is pushed onto `copies`, which the facade wipes once the
|
|
24
|
+
* backend call settles; the caller's own array is never wiped. A view over a detached buffer
|
|
25
|
+
* can't be copied and is a TypeError.
|
|
26
|
+
*/
|
|
27
|
+
export declare function bytes(v: unknown, at: string, copies: Uint8Array[]): Uint8Array;
|
|
28
|
+
export declare function optBytes(v: unknown, at: string, copies: Uint8Array[]): Uint8Array | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Wipes the copies {@link bytes} made with `fill(0)` (ADR 0030 §7). JS gives no guarantee that
|
|
31
|
+
* the engine kept no other copy (ADR 0030 §7 rule 4); this removes the facade's own.
|
|
32
|
+
*/
|
|
33
|
+
export declare function wipe(copies: readonly Uint8Array[]): void;
|
|
34
|
+
export declare function bool(v: unknown, at: string): boolean;
|
|
35
|
+
export declare function optBool(v: unknown, at: string): boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* A size or count: an integer in 0..=2^32−1. Checked here because wasm-bindgen would coerce
|
|
38
|
+
* `-1` to `4294967295` (research §3).
|
|
39
|
+
*/
|
|
40
|
+
export declare function u32(v: unknown, at: string): number;
|
|
41
|
+
export declare function optU32(v: unknown, at: string): number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Whole seconds since the epoch (RFC 7519 §2), a safe integer: the NumericDate and clock range
|
|
44
|
+
* ±(2^53 − 1) of ADR 0027 §2 and ADR 0028 §1, which a JS number holds exactly.
|
|
45
|
+
*/
|
|
46
|
+
export declare function optSeconds(v: unknown, at: string): number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* JSON text (ADR 0030 §2): a string is passed through unchanged (so member order and number
|
|
49
|
+
* spelling reach the core's strict parser as written); a plain object is serialised by
|
|
50
|
+
* {@link jsonText}, the `JSON.stringify` text of its own plain data, with no `toJSON` consulted
|
|
51
|
+
* and nothing read through a prototype (0013 F09).
|
|
52
|
+
*/
|
|
53
|
+
export declare function json(v: unknown, at: string): string;
|
|
54
|
+
export declare function optJson(v: unknown, at: string): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* A list, item by item, copied. Only the array's own elements below its `length` are read: a
|
|
57
|
+
* hole is a TypeError naming its index, never read through `Array.prototype`, where a pollution
|
|
58
|
+
* bug elsewhere in the host app could have put a value (0013 F04, security audit M1).
|
|
59
|
+
*/
|
|
60
|
+
export declare function list<T>(v: unknown, at: string, item: (x: unknown, at: string) => T): T[];
|
|
61
|
+
export declare function strList(v: unknown, at: string): string[];
|
|
62
|
+
export declare function optStrList(v: unknown, at: string): string[] | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* An allow-list (`allowedAlgs`, `allowedEnc`). Absent is passed as `[]`, which the core refuses
|
|
65
|
+
* with `AlgorithmNotAllowed`, the code an empty or `none`-only list gets on every platform
|
|
66
|
+
* (ADR 0030 §3). This is not a default list: it can never accept anything.
|
|
67
|
+
*/
|
|
68
|
+
export declare function allowList(v: unknown, at: string): string[];
|
|
69
|
+
/**
|
|
70
|
+
* A record with no prototype, holding only `init`'s own members. Every record the facade hands
|
|
71
|
+
* the backend is one, so a backend that reads a member by name or tests it with `in` sees only
|
|
72
|
+
* what the facade put there, never an inherited member of a polluted `Object.prototype`
|
|
73
|
+
* (0013 F04, security audit M1; ADR 0030 §3: an absent member is the core default).
|
|
74
|
+
*/
|
|
75
|
+
export declare function bare<T extends object>(init: T): T;
|
|
76
|
+
/**
|
|
77
|
+
* A record argument: a plain object whose own enumerable members are all among `members`.
|
|
78
|
+
* Absent means no members. An unknown member is a TypeError, so a misspelling (`issuer` for
|
|
79
|
+
* `issuers`) can never silently drop a check. The message lists the accepted members, not the
|
|
80
|
+
* unknown one.
|
|
81
|
+
*
|
|
82
|
+
* Returns a {@link bare} copy of the caller's own enumerable members, each read exactly once, and
|
|
83
|
+
* the facade reads options only from that copy (0013 F04, review S2, security audit M1). An
|
|
84
|
+
* inherited member, such as `Object.prototype.ignoreAudience = true` set by a pollution bug
|
|
85
|
+
* elsewhere in the host app, is never read, so it can't loosen policy, lift a limit, stand in
|
|
86
|
+
* for a missing required member or inject a header: ADR 0030 §3 makes an absent option the core
|
|
87
|
+
* default, and the host's global state must not write one either. A non-enumerable own member is
|
|
88
|
+
* not read either, and reading once means a getter can't pass the type check with one value and
|
|
89
|
+
* reach the backend with another.
|
|
90
|
+
*/
|
|
91
|
+
export declare function record(v: unknown, at: string, members: readonly string[]): Record<string, unknown>;
|
|
92
|
+
/**
|
|
93
|
+
* Creates `out[key]` as an own, enumerable, writable, configurable data property holding `value`
|
|
94
|
+
* (ECMA-262 ValidateAndApplyPropertyDescriptor), the descriptor an object literal's member gets
|
|
95
|
+
* (CreateDataProperty). Never an assignment (0013 F13, security audit M1 follow-up): an assignment
|
|
96
|
+
* to a member `out` doesn't own consults `out`'s prototype (OrdinarySet), so on a result, which
|
|
97
|
+
* keeps `Object.prototype`, an accessor a pollution bug put on `Object.prototype.aad` would run
|
|
98
|
+
* its setter with the secret `aad` (ADR 0030 §7) and leave the result without it, and a
|
|
99
|
+
* non-writable inherited member would make the write a TypeError.
|
|
100
|
+
*
|
|
101
|
+
* The descriptor itself has no prototype: `Object.defineProperty` reads `value`, `get`, `set`,
|
|
102
|
+
* `writable`, ... through the descriptor's prototype chain (ToPropertyDescriptor), so with an
|
|
103
|
+
* ordinary descriptor object a polluted `Object.prototype.get` would make every write a TypeError.
|
|
104
|
+
*/
|
|
105
|
+
export declare function define<T extends object, K extends keyof T>(out: T, key: K, value: T[K]): void;
|
|
106
|
+
/** {@link define}s `out[key]` only when `value` is present, so absent optional fields are left out. */
|
|
107
|
+
export declare function put<T extends object, K extends keyof T>(out: T, key: K, value: T[K] | undefined): void;
|
|
108
|
+
/**
|
|
109
|
+
* Adds `value` at the end of `out` as an own data element ({@link define} at index `length`,
|
|
110
|
+
* which also grows `length`, ECMA-262 ArrayDefineOwnProperty). Never `push`: `push` assigns the
|
|
111
|
+
* next index (Array.prototype.push, Set(O, len, E, true)), so an accessor a pollution bug put on
|
|
112
|
+
* `Array.prototype[0]` or `Object.prototype[0]` would receive the element (a byte copy of a
|
|
113
|
+
* secret, a `JweRecipient` with its key) and leave a hole, and a non-writable one would make the
|
|
114
|
+
* call a TypeError (0013 F13).
|
|
115
|
+
*/
|
|
116
|
+
export declare function append<T>(out: T[], value: T): void;
|
|
117
|
+
export declare function outStr(v: unknown, at: string): string;
|
|
118
|
+
export declare function outBytes(v: unknown, at: string): Uint8Array;
|
|
119
|
+
export declare function outIndex(v: unknown, at: string): number;
|
|
120
|
+
/**
|
|
121
|
+
* A list result (`errorCodes()`), item by item, copied: only the array's own elements below its
|
|
122
|
+
* `length` are read, so a hole reaches `item` as `undefined` (a TypeError naming its index) and is
|
|
123
|
+
* never read through a polluted `Array.prototype` (0013 F09).
|
|
124
|
+
*/
|
|
125
|
+
export declare function outList<T>(v: unknown, at: string, item: (x: unknown, at: string) => T): T[];
|
|
126
|
+
/** JSON text the core serialized, parsed to an object (ADR 0030 §2: JWKs, headers, claims). */
|
|
127
|
+
export declare function outObject(v: unknown, at: string): JsonObject;
|
|
128
|
+
/**
|
|
129
|
+
* One member of a backend result (a plain object, BACKEND.md), read only if the result owns it
|
|
130
|
+
* (0013 F09, security audit M1 follow-up). A member the backend left out is `undefined`, never
|
|
131
|
+
* a value a pollution bug put on `Object.prototype`: an absent optional field (`kid`,
|
|
132
|
+
* `keyIndex`, a header, `aad`) stays absent, and a missing required one is a TypeError.
|
|
133
|
+
*/
|
|
134
|
+
export declare function member(v: unknown, name: string, at: string): unknown;
|