@ac-kit/format-tsp 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.
Files changed (64) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/LICENSE +28 -0
  3. package/README.md +202 -2
  4. package/dist/_decode.d.ts +17 -0
  5. package/dist/_decode.d.ts.map +1 -0
  6. package/dist/_decode.js +41 -0
  7. package/dist/_decode.js.map +1 -0
  8. package/dist/_generalized-time.d.ts +12 -0
  9. package/dist/_generalized-time.d.ts.map +1 -0
  10. package/dist/_generalized-time.js +40 -0
  11. package/dist/_generalized-time.js.map +1 -0
  12. package/dist/_hash-algorithms.d.ts +41 -0
  13. package/dist/_hash-algorithms.d.ts.map +1 -0
  14. package/dist/_hash-algorithms.js +66 -0
  15. package/dist/_hash-algorithms.js.map +1 -0
  16. package/dist/_pkix.d.ts +37 -0
  17. package/dist/_pkix.d.ts.map +1 -0
  18. package/dist/_pkix.js +48 -0
  19. package/dist/_pkix.js.map +1 -0
  20. package/dist/consistency.d.ts +101 -0
  21. package/dist/consistency.d.ts.map +1 -0
  22. package/dist/consistency.js +61 -0
  23. package/dist/consistency.js.map +1 -0
  24. package/dist/constants.d.ts +32 -0
  25. package/dist/constants.d.ts.map +1 -0
  26. package/dist/constants.js +39 -0
  27. package/dist/constants.js.map +1 -0
  28. package/dist/errors.d.ts +17 -0
  29. package/dist/errors.d.ts.map +1 -0
  30. package/dist/errors.js +21 -0
  31. package/dist/errors.js.map +1 -0
  32. package/dist/index.d.ts +10 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +10 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/message-imprint.d.ts +72 -0
  37. package/dist/message-imprint.d.ts.map +1 -0
  38. package/dist/message-imprint.js +97 -0
  39. package/dist/message-imprint.js.map +1 -0
  40. package/dist/request.d.ts +94 -0
  41. package/dist/request.d.ts.map +1 -0
  42. package/dist/request.js +123 -0
  43. package/dist/request.js.map +1 -0
  44. package/dist/response.d.ts +56 -0
  45. package/dist/response.d.ts.map +1 -0
  46. package/dist/response.js +92 -0
  47. package/dist/response.js.map +1 -0
  48. package/dist/schema.d.ts +39 -0
  49. package/dist/schema.d.ts.map +1 -0
  50. package/dist/schema.js +107 -0
  51. package/dist/schema.js.map +1 -0
  52. package/dist/token.d.ts +51 -0
  53. package/dist/token.d.ts.map +1 -0
  54. package/dist/token.js +137 -0
  55. package/dist/token.js.map +1 -0
  56. package/dist/tst-info.d.ts +94 -0
  57. package/dist/tst-info.d.ts.map +1 -0
  58. package/dist/tst-info.js +140 -0
  59. package/dist/tst-info.js.map +1 -0
  60. package/dist/verify.d.ts +110 -0
  61. package/dist/verify.d.ts.map +1 -0
  62. package/dist/verify.js +160 -0
  63. package/dist/verify.js.map +1 -0
  64. package/package.json +78 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,59 @@
1
+ # @ac-kit/format-tsp
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [66187b7]
8
+ - @ac-kit/core@0.15.0
9
+ - @ac-kit/format-asn1@0.5.1
10
+ - @ac-kit/cred-cms@0.1.1
11
+ - @ac-kit/cred-x509@0.1.1
12
+ - @ac-kit/crypto-hash@0.2.1
13
+ - @ac-kit/crypto-random@0.3.1
14
+
15
+ ## 0.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 5c203e7: New package: RFC 3161 time-stamp protocol. Build a `TimeStampReq`
20
+ (`createTimeStampRequest`, `createMessageImprint`), read a `TimeStampResp`
21
+ and a token (`decodeTimeStampResponse`, `decodeTimeStampToken`) and the
22
+ `TSTInfo` inside it, and compare it with the request it answers
23
+ (`checkTstInfoConsistency`). `verifyTimeStampToken` authenticates a token
24
+ through `@ac-kit/cred-cms` and `@ac-kit/cred-x509`: one signer, `id-ct-TSTInfo`
25
+ content, the CMS signature, the ESS signing-certificate attribute, the critical
26
+ sole `id-kp-timeStamping` usage, the TSA certificate path at `genTime` against
27
+ caller-supplied trust anchors and optional CRLs, and the `tsa` name; every
28
+ refusal is a result with a `reason`. Functions that read a token without
29
+ verifying say so in their name. Nothing is fetched. `./schema` exports the
30
+ RFC 3161 ASN.1 definitions.
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [5c203e7]
35
+ - Updated dependencies [5c203e7]
36
+ - Updated dependencies [5c203e7]
37
+ - Updated dependencies [5c203e7]
38
+ - Updated dependencies [5c203e7]
39
+ - Updated dependencies [5c203e7]
40
+ - Updated dependencies [5c203e7]
41
+ - Updated dependencies [5c203e7]
42
+ - Updated dependencies [5c203e7]
43
+ - Updated dependencies [5c203e7]
44
+ - Updated dependencies [5c203e7]
45
+ - Updated dependencies [5c203e7]
46
+ - Updated dependencies [5c203e7]
47
+ - Updated dependencies [5c203e7]
48
+ - Updated dependencies [5c203e7]
49
+ - Updated dependencies [5c203e7]
50
+ - Updated dependencies [5c203e7]
51
+ - Updated dependencies [5c203e7]
52
+ - Updated dependencies [5c203e7]
53
+ - @ac-kit/crypto-hash@0.2.0
54
+ - @ac-kit/format-asn1@0.5.0
55
+ - @ac-kit/core@0.14.0
56
+ - @ac-kit/cred-cms@0.1.0
57
+ - @ac-kit/cred-x509@0.1.0
58
+ - @ac-kit/crypto-random@0.3.0
59
+ - @ac-kit/format-oid@0.3.0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,203 @@
1
- # Temporary Holding Version
1
+ # @ac-kit/format-tsp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The RFC 3161 Time-Stamp Protocol as a format: build a `TimeStampReq`, read a `TimeStampResp`, keep the token as the
4
+ bytes the TSA sent, and read the `TSTInfo` inside it — what was stamped
5
+ (the message imprint), when (`genTime` and its accuracy), under which policy,
6
+ with which nonce. Consistency checks compare a `TSTInfo` with the request it
7
+ answers, and `verifyTimeStampToken` authenticates the token.
8
+
9
+ Only `verifyTimeStampToken` checks a signature, a signer or a certificate:
10
+ the CMS `SignedData` signature, the ESS signing-certificate attribute
11
+ (`ESSCertID` or `ESSCertIDv2`, RFC 5816), the TSA certificate's critical
12
+ `id-kp-timeStamping` usage and its path at `genTime`, through
13
+ `@ac-kit/cred-cms` and `@ac-kit/cred-x509`. Every other function that reads a
14
+ token says so in its name (`readTstInfoUnverified`), and the consistency
15
+ check's success is typed `"consistentUnauthenticated"`.
16
+
17
+ Portable: no Node.js built-ins. Times use the `Temporal` global (Node.js 26
18
+ has it; elsewhere load a polyfill such as `temporal-polyfill`). Hashing goes
19
+ through `@ac-kit/crypto-hash` (Web Crypto when present) and nonces through
20
+ `@ac-kit/crypto-random` (`crypto.getRandomValues`). Transport is yours: over
21
+ HTTP a request is a `POST` of the DER bytes with
22
+ `timeStampQueryMediaType`, and the reply body is the DER response.
23
+
24
+ ## Requesting a time stamp
25
+
26
+ ```ts
27
+ import {
28
+ checkTstInfoConsistency,
29
+ createMessageImprint,
30
+ createTimeStampRequest,
31
+ decodeTimeStampResponse,
32
+ encodeTimeStampRequest,
33
+ timeStampQueryMediaType,
34
+ verifyTimeStampToken,
35
+ } from "@ac-kit/format-tsp";
36
+
37
+ declare const freeTsaRoot: Uint8Array; // https://freetsa.org/files/cacert.pem, as DER
38
+
39
+ const archive = new TextEncoder().encode("the bytes to stamp");
40
+ const request = createTimeStampRequest(
41
+ await createMessageImprint("sha256", archive),
42
+ { certReq: true },
43
+ );
44
+
45
+ const sentAt = Temporal.Now.instant();
46
+ const reply = await fetch("https://freetsa.org/tsr", {
47
+ method: "POST",
48
+ headers: { "content-type": timeStampQueryMediaType },
49
+ body: encodeTimeStampRequest(request),
50
+ });
51
+ const response = decodeTimeStampResponse(
52
+ new Uint8Array(await reply.arrayBuffer()),
53
+ );
54
+ if (response.timeStampToken === undefined) {
55
+ throw new Error(`TSA refused: ${response.status}`, { cause: response });
56
+ }
57
+
58
+ // Who issued it: the signature, the TSA certificate and its path at genTime.
59
+ const verified = await verifyTimeStampToken(response.timeStampToken, {
60
+ trustAnchors: [freeTsaRoot],
61
+ requireCertificate: request.certReq,
62
+ });
63
+ if (!verified.valid) {
64
+ throw new Error(`bad token: ${verified.reason}`, { cause: verified });
65
+ }
66
+
67
+ // What it answers: this request, at a time inside the window.
68
+ const consistency = checkTstInfoConsistency(verified.tstInfo, request, {
69
+ acceptedPolicies: "any", // the request named no policy
70
+ window: {
71
+ earliest: sentAt.subtract({ seconds: 2 }),
72
+ latest: Temporal.Now.instant().add({ seconds: 2 }),
73
+ },
74
+ });
75
+ if (consistency.consistency === "inconsistent") {
76
+ throw new Error("the token does not answer this request", {
77
+ cause: consistency.mismatches,
78
+ });
79
+ }
80
+ ```
81
+
82
+ `verifyTimeStampToken` authenticates the token: one signer, `id-ct-TSTInfo`
83
+ content, the CMS signature (ECDSA, as FreeTSA signs since March 2026, or
84
+ RSA), the ESS signing-certificate attribute naming the TSA certificate, that
85
+ certificate's path to one of `trustAnchors` valid at the token's own
86
+ `genTime`, with a critical `id-kp-timeStamping` as its only extended key
87
+ usage, and the `tsa` name, when present, one of the certificate's names. Its
88
+ `tstInfo` is decoded from the very bytes the signature covers. Trust anchors
89
+ are yours: no root store ships, and nothing is fetched — pass the TSA
90
+ certificate in `certificates` when the request had no `certReq`. Every
91
+ refusal is a result with a `reason`.
92
+
93
+ `consistentUnauthenticated` means the token answers this request — same
94
+ imprint, nonce echoed, acceptable policy, a time inside the window, no
95
+ critical extension nobody understands. On its own it does not mean the TSA
96
+ issued it: **do not store a token as evidence, or act on its time, before
97
+ `verifyTimeStampToken` accepted it**. The two run together, since a valid
98
+ signature on a token for some other request is still the wrong token.
99
+
100
+ - `createMessageImprint` hashes in memory; for a file or a stream, hash it
101
+ through a `@ac-kit/crypto-hash` `*Sink` and pass the digest to
102
+ `messageImprintFromDigest`. Requests use SHA-256, SHA-384 or SHA-512; SHA-1
103
+ and MD5 are refused.
104
+ - The nonce is random by default, 8 bytes (64 bits, as RFC 3161 suggests and
105
+ `openssl ts` sends); `nonceByteLength` takes 8 to 32. `nonce: null` sends
106
+ none, a `bigint` sends that value.
107
+ - `certReq: true` asks the TSA to include its certificate, so the token can be
108
+ verified offline later. The RFC's default, kept here, is `false`.
109
+ - `acceptedPolicies` is required when the request named no `reqPolicy`: list
110
+ the TSA policies you accept, or write `"any"`. With a `reqPolicy`, the token
111
+ must carry exactly it.
112
+ - An imprint of a known hash with the wrong digest length, or parameters
113
+ other than absent or `NULL`, never matches anything, so it can never be
114
+ consistent; an imprint of a hash this package does not know is compared
115
+ byte for byte.
116
+ - `window.earliest` after `window.latest` throws `RangeError` (equal ends are
117
+ allowed). The window is your own clock, so widen it by its tolerance — and by the
118
+ TSA's precision: FreeTSA states no `accuracy` and truncates `genTime` to the
119
+ second, so its `genTime` can fall up to a second before the request was
120
+ sent. Without `accuracy`, `tstInfoTimeInterval` is `genTime` alone.
121
+
122
+ ## Reading a stored token
123
+
124
+ `decodeTimeStampToken(bytes)` takes a token kept on its own (the `encoded`
125
+ bytes of a granted response) and checks it is a CMS `SignedData`. To check
126
+ an old token against data hashed with a known algorithm — SHA-1 included, for
127
+ tokens issued long ago — compare digests, naming the algorithm you hashed
128
+ with so a token cannot choose a weaker one:
129
+
130
+ ```ts
131
+ import { sha1 } from "@ac-kit/crypto-hash";
132
+ import {
133
+ decodeTimeStampToken,
134
+ isMessageImprintOfDigest,
135
+ readTstInfoUnverified,
136
+ } from "@ac-kit/format-tsp";
137
+
138
+ declare const storedToken: Uint8Array;
139
+ declare const document: Uint8Array<ArrayBuffer>;
140
+
141
+ const tstInfo = readTstInfoUnverified(decodeTimeStampToken(storedToken));
142
+ isMessageImprintOfDigest(tstInfo.messageImprint, "sha1", await sha1(document));
143
+ ```
144
+
145
+ ## How strict the decoders are
146
+
147
+ - **`TimeStampResp` is read leniently**: it is not signed, and TSAs differ. A
148
+ status code RFC 3161 does not name is kept (`status: "unknown"`, with
149
+ `statusCode`), `failInfo` may carry trailing zero bits or the bits only CMP
150
+ names (`otherBits`), and BER canonical-form slips are accepted. Malformed
151
+ framing, trailing bytes, and a granted status without a token (or a token
152
+ with any other status) are refused with `TspFormatError`.
153
+ - **`TSTInfo` is strict DER by default**, as RFC 3161 requires. Every token
154
+ this package was checked against complies — OpenSSL 3.5 under four TSA
155
+ configurations and live FreeTSA replies — so strictness costs nothing
156
+ observed; `{ strict: false }` exists for an encoder that slips, and never
157
+ changes which bytes a signature covers.
158
+ - **The CMS envelope around the `TSTInfo` is read non-strict**: OpenSSL writes
159
+ the certificate set out of DER order when the request asked for
160
+ certificates. `decodeTimeStampToken` and `readTstInfoUnverified` check it
161
+ for framing only, and refuse a BER token with indefinite lengths, with a
162
+ message saying so; `verifyTimeStampToken` reads it with
163
+ `@ac-kit/cred-cms`, as the BER RFC 5652 allows, the signed attributes
164
+ in DER.
165
+
166
+ Every decoder runs in time linear in its input, with nesting depth-limited:
167
+ no input, however nested, overflows the stack, and every decoding error is a
168
+ `TspFormatError` (a `SyntaxError` with the byte `position`).
169
+
170
+ ## Contract, errors and limits
171
+
172
+ - **Errors**: a decoder throws `TspFormatError` (a `SyntaxError` with the byte
173
+ `position`) for anything malformed; a request option out of range
174
+ (`nonceByteLength`, a reversed `window`, an unsupported hash) throws
175
+ `RangeError`. `verifyTimeStampToken` never throws for a bad token: it
176
+ returns `{ valid: false, reason, message }`, where `reason` is one of the
177
+ `@ac-kit/cred-cms` reasons or `malformed`, `signerCount`,
178
+ `tsaNameMismatch`, `certificateNotIncluded`. It throws `RangeError` only
179
+ when a trust anchor is not a DER certificate.
180
+ - **Limits**: decoding is linear in the input with depth-limited nesting, so
181
+ no input overflows the stack. `verifyTimeStampToken` reads the token under
182
+ `@ac-kit/cred-cms`'s default `CmsLimits` (message size, certificates, CRLs,
183
+ signers), enforced while the input is walked; the package sets no limit of
184
+ its own and does not cap the size of a `TimeStampResp` you hand it, so
185
+ bound the bytes you read from the network.
186
+ - **Verification**: `verifyTimeStampToken` is the only function that
187
+ authenticates; its result is the only `VerifiedTimeStampToken`. It sets
188
+ `genTime` as the time of the path validation, never your clock, and fetches
189
+ nothing (no root store, no CRL, no OCSP): revocation uses the `revocation.crls`
190
+ you pass.
191
+ - **Not covered**: transport, and long-term preservation (re-stamping,
192
+ archive time stamps).
193
+
194
+ ## Schemas
195
+
196
+ `@ac-kit/format-tsp/schema` exports the RFC 3161 Appendix C types as
197
+ `@ac-kit/format-asn1` definitions (`timeStampReqSchema`,
198
+ `timeStampRespSchema`, `tstInfoSchema`, …) for composing into larger
199
+ schemas. Both entry points compile under TypeScript 6 and 7.
200
+
201
+ See the
202
+ [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/format-tsp/)
203
+ for the full reference.
@@ -0,0 +1,17 @@
1
+ import { type DefValueOf } from "@ac-kit/format-asn1";
2
+ import { derDecode } from "@ac-kit/format-asn1/der";
3
+ /**
4
+ * `derDecode`, with a `DecodingError` turned into a {@link TspFormatError}
5
+ * naming `part` and keeping the original as `cause`. Trailing bytes after the
6
+ * value are refused in both modes, since `derDecode` ignores them when not
7
+ * strict.
8
+ *
9
+ * Complexity: O(n) in `bytes`.
10
+ */
11
+ export declare function decodeDer_<D extends Parameters<typeof derDecode>[0]>(def: D, bytes: Uint8Array, strict: boolean, part: string): DefValueOf<D>;
12
+ /**
13
+ * A `DecodingError` as a {@link TspFormatError}; anything else is returned
14
+ * unchanged, to be rethrown.
15
+ */
16
+ export declare function toTspFormatError_(error: unknown, part: string): unknown;
17
+ //# sourceMappingURL=_decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_decode.d.ts","sourceRoot":"","sources":["../src/_decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAMpD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,EACnE,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,GACV,UAAU,CAAC,CAAC,CAAC,CAgBf;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAYvE"}
@@ -0,0 +1,41 @@
1
+ import { any, DecodingError, ref } from "@ac-kit/format-asn1";
2
+ import { derDecode } from "@ac-kit/format-asn1/der";
3
+ import { TspFormatError } from "./errors.js";
4
+ const anyElementDef_ = ref(any());
5
+ /**
6
+ * `derDecode`, with a `DecodingError` turned into a {@link TspFormatError}
7
+ * naming `part` and keeping the original as `cause`. Trailing bytes after the
8
+ * value are refused in both modes, since `derDecode` ignores them when not
9
+ * strict.
10
+ *
11
+ * Complexity: O(n) in `bytes`.
12
+ */
13
+ export function decodeDer_(def, bytes, strict, part) {
14
+ try {
15
+ const value = derDecode(def, bytes, strict);
16
+ if (!strict) {
17
+ const length = derDecode(anyElementDef_, bytes, false).encoded.length;
18
+ if (length !== bytes.length) {
19
+ throw new TspFormatError(`${part}: ${bytes.length - length} byte(s) after the value`, length);
20
+ }
21
+ }
22
+ return value;
23
+ }
24
+ catch (error) {
25
+ throw toTspFormatError_(error, part);
26
+ }
27
+ }
28
+ /**
29
+ * A `DecodingError` as a {@link TspFormatError}; anything else is returned
30
+ * unchanged, to be rethrown.
31
+ */
32
+ export function toTspFormatError_(error, part) {
33
+ if (error instanceof DecodingError) {
34
+ const hint = error.message.includes("indefinite length")
35
+ ? " (BER indefinite lengths are not supported yet)"
36
+ : "";
37
+ return new TspFormatError(`${part}: ${error.message}${hint}`, error.offset, { cause: error });
38
+ }
39
+ return error;
40
+ }
41
+ //# sourceMappingURL=_decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_decode.js","sourceRoot":"","sources":["../src/_decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,EAAmB,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,cAAc,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CACzB,GAAM,EACN,KAAiB,EACjB,MAAe,EACf,IAAY;IAEZ,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,MAAM,GAAG,SAAS,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,OAAQ,CAAC,MAAM,CAAC;YACvE,IAAI,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC7B,MAAM,IAAI,cAAc,CACvB,GAAG,IAAI,KAAK,KAAK,CAAC,MAAM,GAAG,MAAM,0BAA0B,EAC3D,MAAM,CACN,CAAC;YACH,CAAC;QACF,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc,EAAE,IAAY;IAC7D,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC;YACvD,CAAC,CAAC,iDAAiD;YACnD,CAAC,CAAC,EAAE,CAAC;QACN,OAAO,IAAI,cAAc,CACxB,GAAG,IAAI,KAAK,KAAK,CAAC,OAAO,GAAG,IAAI,EAAE,EAClC,KAAK,CAAC,MAAM,EACZ,EAAE,KAAK,EAAE,KAAK,EAAE,CAChB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { UtcGeneralizedTime } from "./tst-info.js";
2
+ /**
3
+ * Nanoseconds since the epoch of a UTC GeneralizedTime. A fraction finer than a
4
+ * nanosecond is rounded down, or up when `roundUp`, so the result bounds the
5
+ * exact time on the side asked for.
6
+ *
7
+ * Complexity: O(fraction digits).
8
+ */
9
+ export declare function generalizedTimeEpochNanoseconds_(value: UtcGeneralizedTime, roundUp: boolean): bigint;
10
+ /** `epochNanoseconds` clamped to `Temporal.Instant`'s range. */
11
+ export declare function clampedInstant_(epochNanoseconds: bigint): Temporal.Instant;
12
+ //# sourceMappingURL=_generalized-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_generalized-time.d.ts","sourceRoot":"","sources":["../src/_generalized-time.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAMxD;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC/C,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE,OAAO,GACd,MAAM,CAaR;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAQ1E"}
@@ -0,0 +1,40 @@
1
+ /** `Temporal.Instant`'s range: ±10⁸ days from the epoch, in nanoseconds. */
2
+ const MAX_EPOCH_NANOSECONDS = 8640000000000000000000n;
3
+ const NANOSECOND_DIGITS = 9;
4
+ /**
5
+ * Nanoseconds since the epoch of a UTC GeneralizedTime. A fraction finer than a
6
+ * nanosecond is rounded down, or up when `roundUp`, so the result bounds the
7
+ * exact time on the side asked for.
8
+ *
9
+ * Complexity: O(fraction digits).
10
+ */
11
+ export function generalizedTimeEpochNanoseconds_(value, roundUp) {
12
+ const whole = Temporal.PlainDateTime.from({
13
+ year: value.year,
14
+ month: value.month,
15
+ day: value.day,
16
+ hour: value.hour,
17
+ minute: value.minute,
18
+ second: value.second,
19
+ }, { overflow: "reject" }).toZonedDateTime("UTC").epochNanoseconds;
20
+ return whole + fractionNanoseconds_(value, roundUp);
21
+ }
22
+ /** `epochNanoseconds` clamped to `Temporal.Instant`'s range. */
23
+ export function clampedInstant_(epochNanoseconds) {
24
+ const clamped = epochNanoseconds > MAX_EPOCH_NANOSECONDS
25
+ ? MAX_EPOCH_NANOSECONDS
26
+ : epochNanoseconds < -MAX_EPOCH_NANOSECONDS
27
+ ? -MAX_EPOCH_NANOSECONDS
28
+ : epochNanoseconds;
29
+ return Temporal.Instant.fromEpochNanoseconds(clamped);
30
+ }
31
+ function fractionNanoseconds_(value, roundUp) {
32
+ const digits = value.fractionDigits ?? "";
33
+ const kept = digits
34
+ .slice(0, NANOSECOND_DIGITS)
35
+ .padEnd(NANOSECOND_DIGITS, "0");
36
+ const nanoseconds = BigInt(kept);
37
+ const dropped = digits.slice(NANOSECOND_DIGITS);
38
+ return roundUp && /[1-9]/u.test(dropped) ? nanoseconds + 1n : nanoseconds;
39
+ }
40
+ //# sourceMappingURL=_generalized-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_generalized-time.js","sourceRoot":"","sources":["../src/_generalized-time.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,MAAM,qBAAqB,GAAG,uBAA8B,CAAC;AAC7D,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAC/C,KAAyB,EACzB,OAAgB;IAEhB,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CACxC;QACC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;KACpB,EACD,EAAE,QAAQ,EAAE,QAAQ,EAAE,CACtB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC;IAC1C,OAAO,KAAK,GAAG,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,eAAe,CAAC,gBAAwB;IACvD,MAAM,OAAO,GACZ,gBAAgB,GAAG,qBAAqB;QACvC,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,gBAAgB,GAAG,CAAC,qBAAqB;YAC1C,CAAC,CAAC,CAAC,qBAAqB;YACxB,CAAC,CAAC,gBAAgB,CAAC;IACtB,OAAO,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,oBAAoB,CAC5B,KAAyB,EACzB,OAAgB;IAEhB,MAAM,MAAM,GAAG,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC;IAC1C,MAAM,IAAI,GAAG,MAAM;SACjB,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC;SAC3B,MAAM,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACjC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChD,OAAO,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { MaybePromiseLike } from "@ac-kit/core";
2
+ import { type ObjectIdentifier } from "@ac-kit/format-oid";
3
+ import type { TspHashAlgorithm } from "./message-imprint.js";
4
+ /** What this package knows of a hash it can read in a `MessageImprint`. */
5
+ export interface HashAlgorithmEntry_ {
6
+ readonly name: TspHashAlgorithm;
7
+ readonly oid: ObjectIdentifier;
8
+ readonly digestLength: number;
9
+ readonly hash: (data: Uint8Array<ArrayBuffer>) => MaybePromiseLike<Uint8Array<ArrayBuffer>>;
10
+ }
11
+ export declare const hashAlgorithms_: Readonly<Record<TspHashAlgorithm, HashAlgorithmEntry_>>;
12
+ /** MD5 (RFC 1321): recognised only to be refused in a new request. */
13
+ export declare const md5Oid_: ObjectIdentifier;
14
+ /** How a `MessageImprint`'s algorithm and digest read against the table. */
15
+ export type ImprintClass_ = {
16
+ readonly kind: "known";
17
+ readonly entry: HashAlgorithmEntry_;
18
+ } | {
19
+ readonly kind: "unknown";
20
+ } | {
21
+ readonly kind: "malformed";
22
+ readonly reason: string;
23
+ };
24
+ /**
25
+ * The one check every consumer of an imprint shares. A known OID must carry
26
+ * absent or DER `NULL` parameters (RFC 5754 §2 for SHA-2, RFC 8017 Appendix B.1
27
+ * for SHA-1) and a digest of its algorithm's length, or it is malformed; an
28
+ * unknown OID is opaque and compared byte for byte.
29
+ *
30
+ * Complexity: O(1).
31
+ */
32
+ export declare function classifyImprint_(imprint: {
33
+ readonly hashAlgorithm: {
34
+ readonly algorithm: ObjectIdentifier;
35
+ readonly parameters?: Uint8Array;
36
+ };
37
+ readonly hashedMessage: Uint8Array;
38
+ }): ImprintClass_;
39
+ /** Absent, or the DER `NULL` `05 00`. */
40
+ export declare function isAbsentOrNull_(parameters: Uint8Array | undefined): boolean;
41
+ //# sourceMappingURL=_hash-algorithms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_hash-algorithms.d.ts","sourceRoot":"","sources":["../src/_hash-algorithms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,2EAA2E;AAC3E,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,CACd,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KACzB,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;CAC/C;AAED,eAAO,MAAM,eAAe,EAAE,QAAQ,CACrC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CA0B7C,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,OAAO,EAAE,gBAA4C,CAAC;AAEnE,4EAA4E;AAC5E,MAAM,MAAM,aAAa,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,GAC/D;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACzC,QAAQ,CAAC,aAAa,EAAE;QACvB,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;QACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;KACjC,CAAC;IACF,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;CACnC,GAAG,aAAa,CAqBhB;AAED,yCAAyC;AACzC,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAO3E"}
@@ -0,0 +1,66 @@
1
+ import { sha1, sha256, sha384, sha512 } from "@ac-kit/crypto-hash";
2
+ import { oidEqual } from "@ac-kit/format-oid";
3
+ export const hashAlgorithms_ = {
4
+ sha1: {
5
+ name: "sha1",
6
+ oid: [1, 3, 14, 3, 2, 26],
7
+ digestLength: 20,
8
+ hash: sha1,
9
+ },
10
+ sha256: {
11
+ name: "sha256",
12
+ oid: [2, 16, 840, 1, 101, 3, 4, 2, 1],
13
+ digestLength: 32,
14
+ hash: sha256,
15
+ },
16
+ sha384: {
17
+ name: "sha384",
18
+ oid: [2, 16, 840, 1, 101, 3, 4, 2, 2],
19
+ digestLength: 48,
20
+ hash: sha384,
21
+ },
22
+ sha512: {
23
+ name: "sha512",
24
+ oid: [2, 16, 840, 1, 101, 3, 4, 2, 3],
25
+ digestLength: 64,
26
+ hash: sha512,
27
+ },
28
+ };
29
+ /** MD5 (RFC 1321): recognised only to be refused in a new request. */
30
+ export const md5Oid_ = [1, 2, 840, 113549, 2, 5];
31
+ /**
32
+ * The one check every consumer of an imprint shares. A known OID must carry
33
+ * absent or DER `NULL` parameters (RFC 5754 §2 for SHA-2, RFC 8017 Appendix B.1
34
+ * for SHA-1) and a digest of its algorithm's length, or it is malformed; an
35
+ * unknown OID is opaque and compared byte for byte.
36
+ *
37
+ * Complexity: O(1).
38
+ */
39
+ export function classifyImprint_(imprint) {
40
+ const { algorithm, parameters } = imprint.hashAlgorithm;
41
+ const entry = Object.values(hashAlgorithms_).find((candidate) => oidEqual(candidate.oid, algorithm));
42
+ if (entry === undefined) {
43
+ return { kind: "unknown" };
44
+ }
45
+ if (!isAbsentOrNull_(parameters)) {
46
+ return {
47
+ kind: "malformed",
48
+ reason: `${entry.name} parameters must be absent or NULL`,
49
+ };
50
+ }
51
+ if (imprint.hashedMessage.length !== entry.digestLength) {
52
+ return {
53
+ kind: "malformed",
54
+ reason: `a ${entry.name} digest is ${entry.digestLength} bytes, got ${imprint.hashedMessage.length}`,
55
+ };
56
+ }
57
+ return { kind: "known", entry };
58
+ }
59
+ /** Absent, or the DER `NULL` `05 00`. */
60
+ export function isAbsentOrNull_(parameters) {
61
+ return (parameters === undefined ||
62
+ (parameters.length === 2 &&
63
+ parameters[0] === 0x05 &&
64
+ parameters[1] === 0x00));
65
+ }
66
+ //# sourceMappingURL=_hash-algorithms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_hash-algorithms.js","sourceRoot":"","sources":["../src/_hash-algorithms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAyB,MAAM,oBAAoB,CAAC;AAcrE,MAAM,CAAC,MAAM,eAAe,GAExB;IACH,IAAI,EAAE;QACL,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzB,YAAY,EAAE,EAAE;QAChB,IAAI,EAAE,IAAI;KACV;IACD,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACrC,YAAY,EAAE,EAAE;QAChB,IAAI,EAAE,MAAM;KACZ;IACD,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACrC,YAAY,EAAE,EAAE;QAChB,IAAI,EAAE,MAAM;KACZ;IACD,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACrC,YAAY,EAAE,EAAE;QAChB,IAAI,EAAE,MAAM;KACZ;CACD,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAQnE;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAMhC;IACA,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IACxD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAC/D,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,CAClC,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAC5B,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,OAAO;YACN,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,oCAAoC;SACzD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,KAAK,KAAK,CAAC,YAAY,EAAE,CAAC;QACzD,OAAO;YACN,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,KAAK,KAAK,CAAC,IAAI,cAAc,KAAK,CAAC,YAAY,eAAe,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE;SACpG,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,eAAe,CAAC,UAAkC;IACjE,OAAO,CACN,UAAU,KAAK,SAAS;QACxB,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YACvB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;YACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CACxB,CAAC;AACH,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { ObjectIdentifier } from "@ac-kit/format-oid";
2
+ import type { AlgorithmIdentifierValue } from "./message-imprint.js";
3
+ import type { TspExtension } from "./request.js";
4
+ /** `AlgorithmIdentifier`, parameters kept as received (RFC 5280 §4.1.1.2). */
5
+ export declare const algorithmIdentifier_: import("@ac-kit/format-asn1").Asn1SequenceType<readonly [import("@ac-kit/format-asn1").Asn1ComponentDef<"algorithm", import("@ac-kit/format-asn1").Asn1ObjectIdentifierTypeDef, false>, import("@ac-kit/format-asn1").Asn1ComponentDef<"parameters", import("@ac-kit/format-asn1").Asn1AnyTypeDef, true>]>;
6
+ /** `Extension` with `critical BOOLEAN DEFAULT FALSE` (RFC 5280 §4.1). */
7
+ export declare const extension_: import("@ac-kit/format-asn1").Asn1SequenceType<readonly [import("@ac-kit/format-asn1").Asn1ComponentDef<"extnID", import("@ac-kit/format-asn1").Asn1ObjectIdentifierTypeDef, false>, import("@ac-kit/format-asn1").Asn1ComponentDef<"critical", import("@ac-kit/format-asn1").Asn1BooleanTypeDef, true>, import("@ac-kit/format-asn1").Asn1ComponentDef<"extnValue", import("@ac-kit/format-asn1").Asn1OctetStringTypeDef, false>]>;
8
+ /**
9
+ * `Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension`; the size is checked by
10
+ * the callers, the DER decoder not enforcing constraints.
11
+ */
12
+ export declare const extensions_: import("@ac-kit/format-asn1").Asn1SequenceOfType<import("@ac-kit/format-asn1").Asn1SequenceTypeDef<readonly [import("@ac-kit/format-asn1").Asn1ComponentDef<"extnID", import("@ac-kit/format-asn1").Asn1ObjectIdentifierTypeDef, false>, import("@ac-kit/format-asn1").Asn1ComponentDef<"critical", import("@ac-kit/format-asn1").Asn1BooleanTypeDef, true>, import("@ac-kit/format-asn1").Asn1ComponentDef<"extnValue", import("@ac-kit/format-asn1").Asn1OctetStringTypeDef, false>]>>;
13
+ /** The decoded shape of {@link algorithmIdentifier_}. */
14
+ interface AlgorithmIdentifierDer_ {
15
+ readonly algorithm: ObjectIdentifier;
16
+ readonly parameters?: {
17
+ readonly encoded?: Uint8Array;
18
+ } | undefined;
19
+ }
20
+ /** The decoded shape of {@link extension_}. */
21
+ interface ExtensionDer_ {
22
+ readonly extnID: ObjectIdentifier;
23
+ readonly critical?: boolean | undefined;
24
+ readonly extnValue: Uint8Array;
25
+ }
26
+ /** A decoded `AlgorithmIdentifier` as the public value, bytes copied. */
27
+ export declare function algorithmIdentifierFromDer_(value: AlgorithmIdentifierDer_): AlgorithmIdentifierValue;
28
+ /** The public value as `algorithmIdentifier_` input. */
29
+ export declare function algorithmIdentifierToDer_(value: AlgorithmIdentifierValue): AlgorithmIdentifierDer_;
30
+ /**
31
+ * Decoded `Extensions` as public values, bytes copied.
32
+ *
33
+ * @throws {TspFormatError} When the list is empty (`SIZE (1..MAX)`).
34
+ */
35
+ export declare function extensionsFromDer_(values: readonly ExtensionDer_[], part: string): readonly TspExtension[];
36
+ export {};
37
+ //# sourceMappingURL=_pkix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_pkix.d.ts","sourceRoot":"","sources":["../src/_pkix.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,4SAGtB,CAAC;AAEZ,yEAAyE;AACzE,eAAO,MAAM,UAAU,qaAIZ,CAAC;AAEZ;;;GAGG;AACH,eAAO,MAAM,WAAW,0dAAwC,CAAC;AAEjE,yDAAyD;AACzD,UAAU,uBAAuB;IAChC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAA;KAAE,GAAG,SAAS,CAAC;CACpE;AAED,+CAA+C;AAC/C,UAAU,aAAa;IACtB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAC/B;AAED,yEAAyE;AACzE,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,uBAAuB,GAC5B,wBAAwB,CAK1B;AAED,wDAAwD;AACxD,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,wBAAwB,GAC7B,uBAAuB,CAIzB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,IAAI,EAAE,MAAM,GACV,SAAS,YAAY,EAAE,CAYzB"}
package/dist/_pkix.js ADDED
@@ -0,0 +1,48 @@
1
+ import { any, boolean, component, objectIdentifier, octetString, sequence, sequenceOf, } from "@ac-kit/format-asn1";
2
+ import { TspFormatError } from "./errors.js";
3
+ // RFC 5280's types as RFC 3161 uses them; cred-x509 will own the public ones.
4
+ /** `AlgorithmIdentifier`, parameters kept as received (RFC 5280 §4.1.1.2). */
5
+ export const algorithmIdentifier_ = sequence([
6
+ component("algorithm", objectIdentifier()),
7
+ component("parameters", any()).optional(),
8
+ ]);
9
+ /** `Extension` with `critical BOOLEAN DEFAULT FALSE` (RFC 5280 §4.1). */
10
+ export const extension_ = sequence([
11
+ component("extnID", objectIdentifier()),
12
+ component("critical", boolean()).default(false),
13
+ component("extnValue", octetString()),
14
+ ]);
15
+ /**
16
+ * `Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension`; the size is checked by
17
+ * the callers, the DER decoder not enforcing constraints.
18
+ */
19
+ export const extensions_ = sequenceOf(extension_).size(1, "MAX");
20
+ /** A decoded `AlgorithmIdentifier` as the public value, bytes copied. */
21
+ export function algorithmIdentifierFromDer_(value) {
22
+ const parameters = value.parameters?.encoded;
23
+ return parameters === undefined
24
+ ? { algorithm: value.algorithm }
25
+ : { algorithm: value.algorithm, parameters: new Uint8Array(parameters) };
26
+ }
27
+ /** The public value as `algorithmIdentifier_` input. */
28
+ export function algorithmIdentifierToDer_(value) {
29
+ return value.parameters === undefined
30
+ ? { algorithm: value.algorithm }
31
+ : { algorithm: value.algorithm, parameters: { encoded: value.parameters } };
32
+ }
33
+ /**
34
+ * Decoded `Extensions` as public values, bytes copied.
35
+ *
36
+ * @throws {TspFormatError} When the list is empty (`SIZE (1..MAX)`).
37
+ */
38
+ export function extensionsFromDer_(values, part) {
39
+ if (values.length === 0) {
40
+ throw new TspFormatError(`${part}: empty extensions (SIZE (1..MAX))`, undefined);
41
+ }
42
+ return values.map((value) => ({
43
+ extnID: value.extnID,
44
+ critical: value.critical ?? false,
45
+ extnValue: new Uint8Array(value.extnValue),
46
+ }));
47
+ }
48
+ //# sourceMappingURL=_pkix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_pkix.js","sourceRoot":"","sources":["../src/_pkix.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,EACH,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,UAAU,GACV,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C,8EAA8E;AAE9E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC5C,SAAS,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAC1C,SAAS,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAEZ,yEAAyE;AACzE,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC;IAClC,SAAS,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IACvC,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAC/C,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,CAAC;CAC5B,CAAC,CAAC;AAEZ;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAejE,yEAAyE;AACzE,MAAM,UAAU,2BAA2B,CAC1C,KAA8B;IAE9B,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7C,OAAO,UAAU,KAAK,SAAS;QAC9B,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE;QAChC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;AAC3E,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,yBAAyB,CACxC,KAA+B;IAE/B,OAAO,KAAK,CAAC,UAAU,KAAK,SAAS;QACpC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE;QAChC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CACjC,MAAgC,EAChC,IAAY;IAEZ,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,cAAc,CACvB,GAAG,IAAI,oCAAoC,EAC3C,SAAS,CACT,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK;QACjC,SAAS,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC;KAC1C,CAAC,CAAC,CAAC;AACL,CAAC"}