micro509 0.13.0 → 0.15.0

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 (165) hide show
  1. package/CHANGELOG.md +2064 -0
  2. package/README.md +111 -183
  3. package/dist/crypto/crypto.d.ts +104 -0
  4. package/dist/crypto/crypto.js +105 -0
  5. package/dist/crypto/crypto.js.map +1 -0
  6. package/dist/crypto.d.ts +4 -0
  7. package/dist/crypto.js +1 -0
  8. package/dist/der/der.d.ts +41 -33
  9. package/dist/der/der.js +26 -24
  10. package/dist/der/der.js.map +1 -1
  11. package/dist/index.d.ts +18 -14
  12. package/dist/index.js +19 -17
  13. package/dist/internal/asn1/asn1.d.ts +3 -6
  14. package/dist/internal/asn1/asn1.js +355 -44
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js +146 -0
  17. package/dist/internal/asn1/ber.js.map +1 -0
  18. package/dist/internal/asn1/decode-refusal.js +29 -0
  19. package/dist/internal/asn1/decode-refusal.js.map +1 -0
  20. package/dist/internal/asn1/der.d.ts +42 -43
  21. package/dist/internal/asn1/der.js +148 -56
  22. package/dist/internal/asn1/der.js.map +1 -1
  23. package/dist/internal/asn1/oids.js +90 -54
  24. package/dist/internal/asn1/oids.js.map +1 -1
  25. package/dist/internal/asn1/oids2.js +1 -2
  26. package/dist/internal/asn1/oids2.js.map +1 -1
  27. package/dist/internal/crypto/algorithm-names.js +5 -2
  28. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  29. package/dist/internal/crypto/ecdsa.js +13 -8
  30. package/dist/internal/crypto/ecdsa.js.map +1 -1
  31. package/dist/internal/crypto/hash.js +1 -2
  32. package/dist/internal/crypto/hash.js.map +1 -1
  33. package/dist/internal/crypto/pbes2.d.ts +51 -0
  34. package/dist/internal/crypto/pbes2.js +86 -34
  35. package/dist/internal/crypto/pbes2.js.map +1 -1
  36. package/dist/internal/crypto/rsa-pss.js +48 -44
  37. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  38. package/dist/internal/crypto/sig-verify.d.ts +28 -0
  39. package/dist/internal/crypto/sig-verify.js +111 -62
  40. package/dist/internal/crypto/sig-verify.js.map +1 -1
  41. package/dist/internal/crypto/signing.d.ts +1 -4
  42. package/dist/internal/crypto/signing.js +28 -29
  43. package/dist/internal/crypto/signing.js.map +1 -1
  44. package/dist/internal/crypto/webcrypto.js +1 -2
  45. package/dist/internal/crypto/webcrypto.js.map +1 -1
  46. package/dist/internal/shared/base64.js +8 -3
  47. package/dist/internal/shared/base64.js.map +1 -1
  48. package/dist/internal/shared/dn.d.ts +13 -0
  49. package/dist/internal/shared/dn.js +101 -48
  50. package/dist/internal/shared/dn.js.map +1 -1
  51. package/dist/internal/shared/idna-tables.js +7217 -0
  52. package/dist/internal/shared/idna-tables.js.map +1 -0
  53. package/dist/internal/shared/idna.js +296 -0
  54. package/dist/internal/shared/idna.js.map +1 -0
  55. package/dist/internal/shared/ip.d.ts +66 -0
  56. package/dist/internal/shared/ip.js +19 -3
  57. package/dist/internal/shared/ip.js.map +1 -1
  58. package/dist/internal/shared/mailbox.js +26 -0
  59. package/dist/internal/shared/mailbox.js.map +1 -0
  60. package/dist/internal/shared/punycode.js +101 -0
  61. package/dist/internal/shared/punycode.js.map +1 -0
  62. package/dist/internal/shared/rfc3454-tables.js +1 -2
  63. package/dist/internal/shared/rfc3454-tables.js.map +1 -1
  64. package/dist/internal/shared/rfc4518-tables.js +119 -0
  65. package/dist/internal/shared/rfc4518-tables.js.map +1 -0
  66. package/dist/internal/shared/uri-host.js +102 -0
  67. package/dist/internal/shared/uri-host.js.map +1 -0
  68. package/dist/internal/verify/name-constraints-engine.js +246 -131
  69. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  70. package/dist/internal/verify/policy-engine.js +6 -21
  71. package/dist/internal/verify/policy-engine.js.map +1 -1
  72. package/dist/internal/verify/verify-path.d.ts +4 -0
  73. package/dist/internal/verify/verify-path.js +264 -128
  74. package/dist/internal/verify/verify-path.js.map +1 -1
  75. package/dist/internal/x509/directory-name.js +23 -0
  76. package/dist/internal/x509/directory-name.js.map +1 -0
  77. package/dist/internal/x509/extension-bits.js +15 -13
  78. package/dist/internal/x509/extension-bits.js.map +1 -1
  79. package/dist/internal/x509/extension-errors.d.ts +3 -0
  80. package/dist/internal/x509/extension-errors.js +19 -0
  81. package/dist/internal/x509/extension-errors.js.map +1 -0
  82. package/dist/internal/x509/extension-registry.js +157 -81
  83. package/dist/internal/x509/extension-registry.js.map +1 -1
  84. package/dist/internal/x509/general-name-profile.js +129 -0
  85. package/dist/internal/x509/general-name-profile.js.map +1 -0
  86. package/dist/internal/x509/general-name-tags.js +27 -0
  87. package/dist/internal/x509/general-name-tags.js.map +1 -0
  88. package/dist/internal/x509/general-name.js +183 -0
  89. package/dist/internal/x509/general-name.js.map +1 -0
  90. package/dist/internal/x509/name-fields.js +21 -12
  91. package/dist/internal/x509/name-fields.js.map +1 -1
  92. package/dist/internal/x509/or-address.js +217 -0
  93. package/dist/internal/x509/or-address.js.map +1 -0
  94. package/dist/keys/keys.d.ts +124 -95
  95. package/dist/keys/keys.js +362 -214
  96. package/dist/keys/keys.js.map +1 -1
  97. package/dist/keys.d.ts +3 -2
  98. package/dist/keys.js +3 -2
  99. package/dist/pem/pem.d.ts +17 -19
  100. package/dist/pem/pem.js +122 -41
  101. package/dist/pem/pem.js.map +1 -1
  102. package/dist/pem.js +1 -2
  103. package/dist/pkcs/pfx.d.ts +57 -32
  104. package/dist/pkcs/pfx.js +209 -173
  105. package/dist/pkcs/pfx.js.map +1 -1
  106. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  107. package/dist/pkcs/pkcs12-mac.js +266 -79
  108. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  109. package/dist/pkcs/pkcs7.d.ts +123 -53
  110. package/dist/pkcs/pkcs7.js +314 -238
  111. package/dist/pkcs/pkcs7.js.map +1 -1
  112. package/dist/pkcs.d.ts +5 -4
  113. package/dist/result/result.d.ts +43 -28
  114. package/dist/result/result.js +27 -14
  115. package/dist/result/result.js.map +1 -1
  116. package/dist/result.d.ts +2 -2
  117. package/dist/result.js +1 -2
  118. package/dist/revocation/chain.d.ts +101 -23
  119. package/dist/revocation/chain.js +456 -206
  120. package/dist/revocation/chain.js.map +1 -1
  121. package/dist/revocation/crl.d.ts +140 -65
  122. package/dist/revocation/crl.js +691 -391
  123. package/dist/revocation/crl.js.map +1 -1
  124. package/dist/revocation/ocsp.d.ts +145 -69
  125. package/dist/revocation/ocsp.js +347 -297
  126. package/dist/revocation/ocsp.js.map +1 -1
  127. package/dist/revocation/revocation.d.ts +48 -36
  128. package/dist/revocation/revocation.js +112 -63
  129. package/dist/revocation/revocation.js.map +1 -1
  130. package/dist/revocation.d.ts +5 -5
  131. package/dist/revocation.js +5 -5
  132. package/dist/verify/identity.d.ts +18 -20
  133. package/dist/verify/identity.js +120 -90
  134. package/dist/verify/identity.js.map +1 -1
  135. package/dist/verify/name-constraints.d.ts +1 -4
  136. package/dist/verify/policy.d.ts +15 -8
  137. package/dist/verify/verify.d.ts +86 -46
  138. package/dist/verify/verify.js +309 -143
  139. package/dist/verify/verify.js.map +1 -1
  140. package/dist/verify.d.ts +3 -2
  141. package/dist/verify.js +4 -3
  142. package/dist/x509/certificate.d.ts +50 -28
  143. package/dist/x509/certificate.js +69 -36
  144. package/dist/x509/certificate.js.map +1 -1
  145. package/dist/x509/csr.d.ts +9 -8
  146. package/dist/x509/csr.js +10 -11
  147. package/dist/x509/csr.js.map +1 -1
  148. package/dist/x509/extensions.d.ts +207 -82
  149. package/dist/x509/extensions.js +561 -128
  150. package/dist/x509/extensions.js.map +1 -1
  151. package/dist/x509/fingerprint.d.ts +4 -7
  152. package/dist/x509/fingerprint.js +1 -2
  153. package/dist/x509/fingerprint.js.map +1 -1
  154. package/dist/x509/name-text.d.ts +7 -9
  155. package/dist/x509/name-text.js +20 -4
  156. package/dist/x509/name-text.js.map +1 -1
  157. package/dist/x509/name.d.ts +15 -14
  158. package/dist/x509/name.js +23 -19
  159. package/dist/x509/name.js.map +1 -1
  160. package/dist/x509/parse.d.ts +165 -64
  161. package/dist/x509/parse.js +444 -459
  162. package/dist/x509/parse.js.map +1 -1
  163. package/dist/x509.d.ts +8 -5
  164. package/dist/x509.js +10 -8
  165. package/package.json +90 -65
package/README.md CHANGED
@@ -1,7 +1,19 @@
1
1
  <picture>
2
- <source media="(prefers-color-scheme: dark)" srcset="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon-light.svg">
3
- <source media="(prefers-color-scheme: light)" srcset="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon.svg">
4
- <img alt="" src="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon.svg" width="64" height="64" align="left">
2
+ <source
3
+ media="(prefers-color-scheme: dark)"
4
+ srcset="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon-light.svg"
5
+ >
6
+ <source
7
+ media="(prefers-color-scheme: light)"
8
+ srcset="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon.svg"
9
+ >
10
+ <img
11
+ alt=""
12
+ src="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon.svg"
13
+ width="64"
14
+ height="64"
15
+ align="left"
16
+ >
5
17
  </picture>
6
18
 
7
19
  # micro509
@@ -10,13 +22,12 @@
10
22
  [![JSR](https://img.shields.io/jsr/v/@kjanat/micro509?logoColor=083344&logo=jsr&logoSize=auto&label=&labelColor=f7df1e&color=black)][jsr]
11
23
  [![Socket](https://badge.socket.dev/npm/package/micro509)][socket]
12
24
 
13
- [npm]: https://npm.im/micro509
14
- [jsr]: https://jsr.io/@kjanat/micro509
15
- [socket]: https://socket.dev/npm/package/micro509
16
-
17
- A zero-dependency TypeScript PKI toolkit for certificates, verification, revocation, and PKCS workflows.
25
+ A zero-dependency TypeScript X.509 and PKI toolkit. Create certificates and
26
+ CSRs, verify certificate chains and identities, manage revocation, and work
27
+ with keys and PKCS containers using WebCrypto.
18
28
 
19
- Zero dependencies. Tree-shakeable subpath entrypoints. Pure WebCrypto. Runs everywhere: Node, Bun, Deno, browsers, Cloudflare Workers.
29
+ Zero dependencies. Tree-shakeable subpath entrypoints. Pure WebCrypto. Runs in
30
+ Node, Bun, Deno, browsers, and Cloudflare Workers.
20
31
 
21
32
  > **Prerelease** — API may change before 1.0.
22
33
 
@@ -26,214 +37,131 @@ Zero dependencies. Tree-shakeable subpath entrypoints. Pure WebCrypto. Runs ever
26
37
  npm install micro509
27
38
  ```
28
39
 
29
- In a browser, no build step — it is WebCrypto and nothing else:
30
-
31
- ```html
32
- <script type="module">
33
- import { createSelfSignedCertificate } from 'https://esm.run/micro509';
34
- </script>
35
- ```
36
-
37
- Two runnable examples: [`examples/browser`] is one HTML file you can open, and
38
- [`examples/vite`] is the same demo with types and a dev server. Both open in StackBlitz.
39
-
40
- [`examples/browser`]: ./examples/browser/README.md
41
- [`examples/vite`]: ./examples/vite/README.md
42
-
43
- ## Why micro509
44
-
45
- JavaScript PKI libraries usually force a bad tradeoff:
46
- heavyweight standards toolkits, legacy crypto kitchen sinks,
47
- or narrow parsing utilities.
48
-
49
- micro509 is the practical middle: a modern, WebCrypto-native
50
- PKI toolkit with zero runtime dependencies and typed APIs for
51
- the workflows most applications actually need.
52
-
53
- It gives you one library for certificate and CSR creation,
54
- chain verification, service-identity matching, CRLs, OCSP,
55
- PKCS#7 SignedData, PFX/PKCS#12, PEM handling, and key
56
- import/export.
57
-
58
- And when verification fails, you get typed results your code
59
- can act on: [a typed error code for every failure mode], the failing
60
- certificate index, and structured failure details instead of `false`.
40
+ ## Quick start
61
41
 
62
- [a typed error code for every failure mode]: https://micro509.kjanat.dev/guide/verification#error-codes
42
+ Create a self-signed certificate, verify its chain and service identity, then
43
+ see a typed failure when the requested identity does not match:
63
44
 
64
45
  ```ts
65
- if (!result.ok) {
66
- // result.error.code: 'signature_invalid' | 'certificate_expired' | 'name_constraints_violated' | ...
67
- // result.error.index: which certificate in the chain failed
68
- // result.error.details: { expected, actual } for identity mismatches
69
- }
70
- ```
71
-
72
- Beyond verification, micro509 covers PKI surface that's hard to find
73
- in a single zero-dependency JS package:
74
-
75
- - **OCSP** — build requests, parse and validate responses, verify responder authorization
76
- - **PFX / PKCS#12** — create and parse password-protected key+cert bundles
77
- - **PKCS#7 / CMS** — sign content, parse and verify SignedData, extract cert bags
78
- - **CRLs** — create, parse, verify, and check revocation status
79
- - **Encrypted keys** — PBES2 PKCS#8, legacy OpenSSL encrypted PEM, PKCS#1, SEC1
80
- - **Key import/export** — PKCS#8, SPKI, JWK, PKCS#1, SEC1 with generation for RSA, ECDSA, Ed25519
81
- - **Service identity** — wildcard DNS, IPv6 normalization, URI-ID, SRV-ID, explicit CN opt-in
46
+ import { createSelfSignedCertificate, verifyCertificateChain } from 'micro509';
82
47
 
83
- Narrow defaults, explicit escape hatches — dangerous operations like CN
84
- fallback or self-signed leaf acceptance require opt-in. All with no `any`,
85
- no type assertions, no non-null assertions, and no runtime DI frameworks
86
- that break edge runtimes.
87
-
88
- ## Quick start
48
+ const { certificate } = await createSelfSignedCertificate({
49
+ subject: { commonName: 'app.example.com' },
50
+ extensions: {
51
+ subjectAltNames: [{ type: 'dns', value: 'app.example.com' }],
52
+ },
53
+ });
89
54
 
90
- Create a self-signed certificate:
55
+ const options = {
56
+ leaf: certificate.pem,
57
+ roots: [certificate.pem],
58
+ allowSelfSignedLeaf: true,
59
+ } as const;
91
60
 
92
- ```ts
93
- import { createSelfSignedCertificate } from 'micro509';
94
-
95
- const { certificate, keyPair } = await createSelfSignedCertificate({
96
- subject: {
97
- commonName: 'example.com',
98
- organization: 'Acme',
99
- country: 'US',
100
- },
101
- validity: { days: 30 },
102
- extensions: {
103
- keyUsage: ['digitalSignature', 'keyEncipherment'],
104
- subjectAltNames: [
105
- { type: 'dns', value: 'example.com' },
106
- { type: 'dns', value: 'www.example.com' },
107
- ],
108
- },
61
+ const valid = await verifyCertificateChain({
62
+ ...options,
63
+ serviceIdentity: { type: 'dns', value: 'app.example.com' },
109
64
  });
65
+ console.log(valid.ok ? 'verified app.example.com' : valid.error.code);
110
66
 
111
- console.log(certificate.pem);
112
- console.log(await keyPair.exportPkcs8Pem());
67
+ const mismatch = await verifyCertificateChain({
68
+ ...options,
69
+ serviceIdentity: { type: 'dns', value: 'admin.example.com' },
70
+ });
71
+ console.log(mismatch.ok ? 'verified' : mismatch.error.code);
113
72
  ```
114
73
 
115
- Create a CSR:
116
-
117
- ```ts
118
- import { createCertificateSigningRequest, generateKeyPair } from 'micro509';
119
-
120
- const keyPair = await generateKeyPair({ kind: 'ed25519' });
121
- const csr = await createCertificateSigningRequest({
122
- subject: { commonName: 'csr.example' },
123
- publicKey: keyPair.publicKey,
124
- signerPrivateKey: keyPair.privateKey,
125
- extensions: {
126
- subjectAltNames: [{ type: 'dns', value: 'csr.example' }],
127
- },
128
- });
74
+ Output:
129
75
 
130
- console.log(csr.pem);
76
+ ```text
77
+ verified app.example.com
78
+ subject_alt_name_mismatch
131
79
  ```
132
80
 
133
- Parse a certificate:
81
+ A verification failure is a typed result with an error code, failing
82
+ certificate index when relevant, and structured details. Callers can handle a
83
+ specific case without parsing messages or collapsing every failure into
84
+ `false`.
134
85
 
135
- ```ts
136
- import { parseCertificatePem, unwrap } from 'micro509';
86
+ The self-signed leaf option above is useful for a compact local demo. In
87
+ production, supply the appropriate trust anchors and intermediates for your
88
+ PKI.
137
89
 
138
- // Using certificate from previous example
139
- const parsed = unwrap(parseCertificatePem(certificate.pem));
140
- console.log(parsed.subject.values.commonName);
141
- console.log(parsed.extendedKeyUsage);
142
- console.log(parsed.authorityInfoAccess);
143
- ```
90
+ ## What it covers
144
91
 
145
- `parseCertificatePem` returns a typed `Result` — check `result.ok`, or
146
- `unwrap()` to throw on malformed input.
92
+ - **Certificates and CSRs:** create, parse, and encode common X.509 extensions
93
+ - **Verification:** build and validate chains, enforce policy, and match DNS,
94
+ IP, URI, and SRV service identities
95
+ - **Revocation:** create and process CRLs and OCSP requests and responses
96
+ - **Keys and signatures:** import, export, and generate RSA, ECDSA, and
97
+ Ed25519 keys, plus signing and verification of detached data
98
+ - **PKCS workflows:** PKCS#7 SignedData and password-protected PFX/PKCS#12
99
+ - **PEM and DER:** encode, decode, and parse common formats
147
100
 
148
- Verify a chain:
101
+ The root package exports the usual workflows:
149
102
 
150
103
  ```ts
151
- import { verifyCertificateChain } from 'micro509';
152
-
153
- // Assuming you have a self-signed certificate used as both leaf and root; no intermediates
154
- const result = await verifyCertificateChain({
155
- leaf: certificate.pem,
156
- intermediates: [],
157
- roots: [certificate.pem], // Using self-signed cert as root for demo
158
- purpose: 'serverAuth',
159
- serviceIdentity: { type: 'dns', value: 'example.com' },
160
- });
161
-
162
- if (result.ok) {
163
- console.log(result.value.chain.length);
164
- } else {
165
- console.log(result.error.code);
166
- }
104
+ import { createCertificate, parseCertificatePem, verifyCertificateChain } from 'micro509';
167
105
  ```
168
106
 
169
- ## Runtime support
107
+ For smaller imports or more specialized types, use domain entrypoints:
170
108
 
171
- | Runtime | Status | Notes |
172
- | ------- | --------- | -------------------------------------------------- |
173
- | Node | supported | modern Node with WebCrypto globals (tested on 24+) |
174
- | Bun | supported | Bun 1.3+ |
175
- | Deno | supported | requires WebCrypto and web text/base64 globals |
176
- | Browser | supported | modern browsers only |
177
- | Worker | supported | same WebCrypto and text/base64 globals required |
109
+ ```ts
110
+ import { parseCertificatePem } from 'micro509/x509';
111
+ import { verifyCertificateChain } from 'micro509/verify';
112
+ import { checkCertificateRevocation } from 'micro509/revocation';
113
+ import { createPfx } from 'micro509/pkcs';
114
+ import { generateKeyPair } from 'micro509/keys';
115
+ ```
178
116
 
179
- The core stays ESM-only and side-effect-free.
117
+ See the [API reference](https://micro509.kjanat.dev/api/) for the full entrypoint list.
180
118
 
181
- ## Algorithm support
119
+ ## Standards and algorithms
182
120
 
183
- | Area | Shipped support |
184
- | ------------------------------ | -------------------------------------------------------------------- |
185
- | Certificate and CSR signatures | RSA PKCS#1 v1.5, RSA-PSS, ECDSA `P-256` / `P-384` / `P-521`, Ed25519 |
186
- | RSA key APIs | `scheme: 'pkcs1-v1_5'` |
187
- | ECDSA key APIs | `P-256`, `P-384`, `P-521` |
188
- | Encrypted PKCS#8 and PFX | PBES2 with AES-CBC plus PBKDF2 HMAC-SHA1/HMAC-SHA256 |
189
- | Encrypted traditional PEM | AES-128-CBC, AES-192-CBC, AES-256-CBC for RSA and EC private keys |
121
+ micro509 implements core certificate path validation, service identity,
122
+ policy, PEM, safe-curve, OCSP, and PKCS container workflows. The exact claim
123
+ boundary and partial areas are documented in the [PKIX scope](./docs/PKIX-SCOPE.md).
124
+ See [algorithms](https://micro509.kjanat.dev/reference/algorithms) for supported
125
+ curves and signature schemes, [runtimes](https://micro509.kjanat.dev/reference/runtimes)
126
+ for environment support, and [standards](https://micro509.kjanat.dev/reference/standards)
127
+ for implementation coverage.
190
128
 
191
- `micro509` focuses on algorithms that are broadly interoperable in modern X.509 and WebCrypto-backed runtimes.\
192
- It intentionally excludes niche, blockchain-specific, or key-agreement-only primitives from the core API unless they are needed for a PKI workflow the library explicitly supports.
129
+ ## Try it in a browser
193
130
 
194
- ## Standards status
131
+ The browser example is a single HTML file that issues a certificate and parses
132
+ it back with no build step. The Vite example adds TypeScript and a dev server.
195
133
 
196
- | Area | Status |
197
- | -------------------------- | -------- |
198
- | RFC 5280 path validation | complete |
199
- | RFC 6960 OCSP | complete |
200
- | RFC 6125 service identity | complete |
201
- | RFC 9618 policy validation | complete |
134
+ - [Browser example][browser-example], [open in StackBlitz][browser-example:stackblitz]
135
+ - [Vite example][vite-example], [open in StackBlitz][vite-example:stackblitz]
202
136
 
203
- See [`docs/PKIX-SCOPE.md`](./docs/PKIX-SCOPE.md) for the detailed scope boundary
204
- and the [API reference](https://micro509.kjanat.dev/api/) for the public module surface.
137
+ ## Documentation
205
138
 
206
- ## Imports
139
+ - [Recipes: server verification, CSR issuance, PFX import](https://micro509.kjanat.dev/guide/recipes)
140
+ - [Migration from 0.14.0](https://micro509.kjanat.dev/guide/migration)
207
141
 
208
- Use the root package for most applications:
142
+ - [Getting started](https://micro509.kjanat.dev/guide/getting-started)
143
+ - [Certificates and extensions](https://micro509.kjanat.dev/guide/certificates)
144
+ - [Verification and trust inputs](https://micro509.kjanat.dev/guide/verification)
145
+ - [CRL and OCSP revocation](https://micro509.kjanat.dev/guide/revocation)
146
+ - [Keys and encrypted formats](https://micro509.kjanat.dev/guide/keys)
147
+ - [PKCS#7 and PKCS#12](https://micro509.kjanat.dev/guide/pkcs)
148
+ - [Error reference](https://micro509.kjanat.dev/reference/errors)
149
+ - [API reference](https://micro509.kjanat.dev/api/)
150
+ - [Contributing](./CONTRIBUTING.md)
209
151
 
210
- ```ts
211
- import { createCertificate, parseCertificatePem, verifyCertificateChain } from 'micro509';
212
- ```
152
+ ## OpenSSL builds
213
153
 
214
- Use domain entrypoints when you want exhaustive advanced types or a narrower
215
- workflow surface:
216
-
217
- ```ts
218
- import { parseCertificatePem } from 'micro509/x509';
219
- import { verifyCertificateChain, matchServiceIdentity } from 'micro509/verify';
220
- import { createOcspRequest, checkCertificateRevocation } from 'micro509/revocation';
221
- import { createPfx } from 'micro509/pkcs';
222
- import { generateKeyPair } from 'micro509/keys';
223
- import { pemDecode, pemEncode } from 'micro509/pem';
224
- import type { Micro509Error } from 'micro509/result';
225
- ```
226
-
227
- The full stable subpath list lives in the [API reference](https://micro509.kjanat.dev/api/).
228
-
229
- ## More docs
230
-
231
- - API reference: [micro509.kjanat.dev/api](https://micro509.kjanat.dev/api/)
232
- - Standards scope: [`docs/PKIX-SCOPE.md`](./docs/PKIX-SCOPE.md)
233
- - PKITS harness: [`test/pkits.test.ts`](./test/pkits.test.ts)
234
- - Differential harness: [`test/differential.test.ts`](./test/differential.test.ts)
235
- - Contributing: [`CONTRIBUTING.md`](./CONTRIBUTING.md)
154
+ This repository also publishes statically linked OpenSSL builds to GHCR for
155
+ micro509 CI and general use. See [build details](./.github/openssl/README.md).
236
156
 
237
157
  ## License
238
158
 
239
159
  [MIT](./LICENSE)
160
+
161
+ [npm]: https://npm.im/micro509
162
+ [jsr]: https://jsr.io/@kjanat/micro509
163
+ [socket]: https://socket.dev/npm/package/micro509
164
+ [browser-example]: ./examples/browser/README.md "GitHub"
165
+ [browser-example:stackblitz]: https://stackblitz.com/github/kjanat/micro509/tree/master/examples/browser?title=micro509%20in%20the%20browser "StackBlitz"
166
+ [vite-example]: ./examples/vite/README.md "GitHub"
167
+ [vite-example:stackblitz]: https://stackblitz.com/github/kjanat/micro509/tree/master/examples/vite?title=micro509%20with%20Vite "StackBlitz"
@@ -0,0 +1,104 @@
1
+ import { EcNamedCurve } from "../keys/keys.js";
2
+ import { VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess } from "../internal/crypto/sig-verify.js";
3
+ import { SignatureProfileInput } from "../internal/crypto/signing.js";
4
+ /** Failure: the signature algorithm parameters exceed a micro509 decoding limit. */
5
+ export interface VerifySignatureLimitFailure {
6
+ /** Discriminant for the failure branch. */
7
+ readonly ok: false;
8
+ /** Machine-readable failure code. */
9
+ readonly code: "limit_exceeded";
10
+ /** Human-readable description of the limit. */
11
+ readonly reason: string;
12
+ }
13
+ /** Result of {@linkcode verifySignature} and {@linkcode verifySignatureWithKey}. */
14
+ export type VerifySignatureResult = VerifySignedDataResult | VerifySignatureLimitFailure;
15
+ /** Input for {@linkcode verifySignature}. */
16
+ export interface VerifySignatureInput {
17
+ /** DER `SubjectPublicKeyInfo` of the signer (`subjectPublicKeyInfoDer` on a parsed certificate). */
18
+ readonly signerSpkiDer: Uint8Array;
19
+ /** The signature algorithm as carried beside the signature. */
20
+ readonly signatureAlgorithm: {
21
+ /** Dotted-decimal signature algorithm OID. */
22
+ readonly oid: string;
23
+ /** DER algorithm parameters when the algorithm carries them (RSA-PSS). */
24
+ readonly parametersDer?: Uint8Array;
25
+ };
26
+ /** The signer's public key algorithm as carried in its SPKI. */
27
+ readonly publicKeyAlgorithm: {
28
+ /** Dotted-decimal public key algorithm OID. */
29
+ readonly oid: string;
30
+ /** Named-curve or scheme parameters OID, when present. */
31
+ readonly parametersOid?: string;
32
+ };
33
+ /** The signature bytes. ECDSA accepts DER or raw encoding. */
34
+ readonly signature: Uint8Array;
35
+ /** The exact bytes the signature covers. */
36
+ readonly data: Uint8Array;
37
+ }
38
+ /** Input for {@linkcode verifySignatureWithKey}. */
39
+ export interface VerifySignatureWithKeyInput {
40
+ /** An existing public key with verify usage; extractability is not required. */
41
+ readonly publicKey: CryptoKey;
42
+ /** Explicit signature OID and parameters, including RSA-PSS salt length. */
43
+ readonly signatureAlgorithm: VerifySignatureInput["signatureAlgorithm"];
44
+ /** ECDSA accepts raw r || s or DER; RSA and Ed25519 require raw. No encoding retry occurs. */
45
+ readonly signatureEncoding: "raw" | "der";
46
+ /** The signature bytes in the declared encoding. */
47
+ readonly signature: Uint8Array;
48
+ /** The exact bytes the signature covers. */
49
+ readonly data: Uint8Array;
50
+ }
51
+ /**
52
+ * Verifies a detached signature using an existing WebCrypto public key without
53
+ * exporting or importing it. Repeated calls may reuse non-extractable keys.
54
+ * Signature algorithms and parameters follow {@linkcode verifySignature}; RSA
55
+ * scheme and hash must match the key. ECDSA encoding is explicit and never retried.
56
+ * Returns the same validity, unsupported-parameter, operational-error and decoding-limit
57
+ * branches as {@linkcode verifySignature}.
58
+ */
59
+ export declare function verifySignatureWithKey(input: VerifySignatureWithKeyInput): Promise<VerifySignatureResult>;
60
+ /** Result of {@linkcode signData}: the signature plus its on-wire algorithm identity. */
61
+ export interface SignDataResult {
62
+ /** The signature bytes. ECDSA is DER `ECDSA-Sig-Value`, everything else raw. */
63
+ readonly signature: Uint8Array;
64
+ /** Dotted-decimal signature algorithm OID. */
65
+ readonly algorithmOid: string;
66
+ /** DER algorithm parameters when the algorithm carries them (NULL for PKCS#1 v1.5, RSA-PSS params). */
67
+ readonly parametersDer?: Uint8Array;
68
+ }
69
+ /**
70
+ * Verifies a detached signature against the signer's DER `SubjectPublicKeyInfo`.
71
+ *
72
+ * Supports RSA PKCS#1 v1.5 (SHA-256/384/512), RSA-PSS with parsed parameters,
73
+ * ECDSA P-256/P-384/P-521, and Ed25519. When an ECDSA signature fails to
74
+ * verify under one encoding, the alternate DER/raw encoding is retried.
75
+ *
76
+ * Returns a typed union: `{ ok: true, valid }` when verification ran,
77
+ * `unsupported_signature_algorithm_parameters`, `verification_error` or
78
+ * `limit_exceeded` failures otherwise.
79
+ */
80
+ export declare function verifySignature(input: VerifySignatureInput): Promise<VerifySignatureResult>;
81
+ /**
82
+ * Signs `data` with a WebCrypto private key and returns the signature beside
83
+ * the resolved `AlgorithmIdentifier` material for embedding in a signed
84
+ * structure.
85
+ *
86
+ * The algorithm is inferred from the key (RSASSA-PKCS1-v1_5, ECDSA, Ed25519);
87
+ * RSA-PSS keys require an explicit `{ kind: 'rsa-pss' }` profile. ECDSA
88
+ * signatures are returned DER-encoded. Throws on unsupported key algorithms.
89
+ */
90
+ export declare function signData(privateKey: CryptoKey, data: Uint8Array, profile?: SignatureProfileInput): Promise<SignDataResult>;
91
+ /**
92
+ * Converts a DER `ECDSA-Sig-Value` (RFC 5480: SEQUENCE of INTEGERs r and s)
93
+ * to the fixed-width raw `r || s` encoding WebCrypto and JOSE use.
94
+ * Throws on malformed DER or integers too large for the curve.
95
+ */
96
+ export declare function ecdsaSignatureDerToRaw(signature: Uint8Array, curve: EcNamedCurve): Uint8Array;
97
+ /**
98
+ * Converts a fixed-width raw `r || s` ECDSA signature to the DER
99
+ * `ECDSA-Sig-Value` encoding X.509 and CMS structures embed.
100
+ * Throws when the input length does not match the curve.
101
+ */
102
+ export declare function ecdsaSignatureRawToDer(signature: Uint8Array, curve: EcNamedCurve): Uint8Array;
103
+ export type { SignatureProfileInput, VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess };
104
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1,105 @@
1
+ import { DECODE_LIMIT_CODES as e, decodeRefusalOf as t } from "../internal/asn1/decode-refusal.js";
2
+ import { derEcdsaSignatureToRaw as n, rawEcdsaSignatureToDer as r } from "../internal/crypto/ecdsa.js";
3
+ import { verifySignedDataDetailed as i, verifySignedDataWithKeyDetailed as a } from "../internal/crypto/sig-verify.js";
4
+ import { getSignatureAlgorithm as o, signBytes as s } from "../internal/crypto/signing.js";
5
+ // src/crypto/crypto.ts
6
+ /**
7
+ * Detached-signature primitives: verify a signature against a signer's SPKI or CryptoKey,
8
+ * sign arbitrary bytes with a WebCrypto private key, and convert ECDSA
9
+ * signatures between DER `ECDSA-Sig-Value` and fixed-width raw encodings.
10
+ *
11
+ * @module
12
+ */
13
+ /**
14
+ * Verifies a detached signature using an existing WebCrypto public key without
15
+ * exporting or importing it. Repeated calls may reuse non-extractable keys.
16
+ * Signature algorithms and parameters follow {@linkcode verifySignature}; RSA
17
+ * scheme and hash must match the key. ECDSA encoding is explicit and never retried.
18
+ * Returns the same validity, unsupported-parameter, operational-error and decoding-limit
19
+ * branches as {@linkcode verifySignature}.
20
+ */
21
+ async function verifySignatureWithKey(n) {
22
+ try {
23
+ return await a(n.publicKey, n.signatureAlgorithm.oid, n.signatureAlgorithm.parametersDer, n.signature, n.data, n.signatureEncoding);
24
+ } catch (n) {
25
+ let r = t(n, e);
26
+ if (r === void 0) throw n;
27
+ return {
28
+ ok: !1,
29
+ code: r.code,
30
+ reason: r.message
31
+ };
32
+ }
33
+ }
34
+ /**
35
+ * Verifies a detached signature against the signer's DER `SubjectPublicKeyInfo`.
36
+ *
37
+ * Supports RSA PKCS#1 v1.5 (SHA-256/384/512), RSA-PSS with parsed parameters,
38
+ * ECDSA P-256/P-384/P-521, and Ed25519. When an ECDSA signature fails to
39
+ * verify under one encoding, the alternate DER/raw encoding is retried.
40
+ *
41
+ * Returns a typed union: `{ ok: true, valid }` when verification ran,
42
+ * `unsupported_signature_algorithm_parameters`, `verification_error` or
43
+ * `limit_exceeded` failures otherwise.
44
+ */
45
+ async function verifySignature(n) {
46
+ try {
47
+ return await i(n.signatureAlgorithm.oid, n.signatureAlgorithm.parametersDer, n.publicKeyAlgorithm.oid, n.publicKeyAlgorithm.parametersOid, n.signerSpkiDer, n.signature, n.data);
48
+ } catch (n) {
49
+ let r = t(n, e);
50
+ if (r === void 0) throw n;
51
+ return {
52
+ ok: !1,
53
+ code: r.code,
54
+ reason: r.message
55
+ };
56
+ }
57
+ }
58
+ /**
59
+ * Signs `data` with a WebCrypto private key and returns the signature beside
60
+ * the resolved `AlgorithmIdentifier` material for embedding in a signed
61
+ * structure.
62
+ *
63
+ * The algorithm is inferred from the key (RSASSA-PKCS1-v1_5, ECDSA, Ed25519);
64
+ * RSA-PSS keys require an explicit `{ kind: 'rsa-pss' }` profile. ECDSA
65
+ * signatures are returned DER-encoded. Throws on unsupported key algorithms.
66
+ */
67
+ async function signData(e, t, n) {
68
+ let r = o(e, n), i = await s(e, r, t);
69
+ return r.parameters === void 0 ? {
70
+ signature: i,
71
+ algorithmOid: r.algorithmOid
72
+ } : {
73
+ signature: i,
74
+ algorithmOid: r.algorithmOid,
75
+ parametersDer: r.parameters
76
+ };
77
+ }
78
+ /**
79
+ * Converts a DER `ECDSA-Sig-Value` (RFC 5480: SEQUENCE of INTEGERs r and s)
80
+ * to the fixed-width raw `r || s` encoding WebCrypto and JOSE use.
81
+ * Throws on malformed DER or integers too large for the curve.
82
+ */
83
+ function ecdsaSignatureDerToRaw(e, t) {
84
+ return n(e, ecdsaPartLength(t));
85
+ }
86
+ /**
87
+ * Converts a fixed-width raw `r || s` ECDSA signature to the DER
88
+ * `ECDSA-Sig-Value` encoding X.509 and CMS structures embed.
89
+ * Throws when the input length does not match the curve.
90
+ */
91
+ function ecdsaSignatureRawToDer(e, t) {
92
+ return r(e, ecdsaPartLength(t));
93
+ }
94
+ /** Byte width of one ECDSA signature integer for the given curve. */
95
+ function ecdsaPartLength(e) {
96
+ switch (e) {
97
+ case "P-256": return 32;
98
+ case "P-384": return 48;
99
+ case "P-521": return 66;
100
+ default: throw Error(`Unhandled EcNamedCurve: ${String(e)}`);
101
+ }
102
+ }
103
+ export { ecdsaSignatureDerToRaw, ecdsaSignatureRawToDer, signData, verifySignature, verifySignatureWithKey };
104
+
105
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","names":["_exhaustive","verifySignedDataWithKeyDetailed","input","error","refusal","decodeRefusalOf","DECODE_LIMIT_CODES","verifySignedDataDetailed","algorithm","getSignatureAlgorithm","privateKey","profile","signature","signBytes","data","derEcdsaSignatureToRaw","curve","rawEcdsaSignatureToDer"],"sources":["../../src/crypto/crypto.ts"],"sourcesContent":["/**\n * Detached-signature primitives: verify a signature against a signer's SPKI or CryptoKey,\n * sign arbitrary bytes with a WebCrypto private key, and convert ECDSA\n * signatures between DER `ECDSA-Sig-Value` and fixed-width raw encodings.\n *\n * @module\n */\n\nimport { DECODE_LIMIT_CODES, decodeRefusalOf } from '#micro509/internal/asn1/decode-refusal';\nimport { derEcdsaSignatureToRaw, rawEcdsaSignatureToDer } from '#micro509/internal/crypto/ecdsa';\nimport type { VerifySignedDataResult } from '#micro509/internal/crypto/sig-verify';\nimport {\n\tverifySignedDataDetailed,\n\tverifySignedDataWithKeyDetailed,\n} from '#micro509/internal/crypto/sig-verify';\nimport type { SignatureProfileInput } from '#micro509/internal/crypto/signing';\nimport { getSignatureAlgorithm, signBytes } from '#micro509/internal/crypto/signing';\nimport type { EcNamedCurve } from '#micro509/keys/keys';\n\nexport type {\n\tVerifySignatureConfigFailure,\n\tVerifySignedDataFailure,\n\tVerifySignedDataResult,\n\tVerifySignedDataSuccess,\n} from '#micro509/internal/crypto/sig-verify';\nexport type { SignatureProfileInput } from '#micro509/internal/crypto/signing';\n\n/** Failure: the signature algorithm parameters exceed a micro509 decoding limit. */\nexport interface VerifySignatureLimitFailure {\n\t/** Discriminant for the failure branch. */\n\treadonly ok: false;\n\t/** Machine-readable failure code. */\n\treadonly code: 'limit_exceeded';\n\t/** Human-readable description of the limit. */\n\treadonly reason: string;\n}\n\n/** Result of {@linkcode verifySignature} and {@linkcode verifySignatureWithKey}. */\nexport type VerifySignatureResult = VerifySignedDataResult | VerifySignatureLimitFailure;\n\n/** Input for {@linkcode verifySignature}. */\nexport interface VerifySignatureInput {\n\t/** DER `SubjectPublicKeyInfo` of the signer (`subjectPublicKeyInfoDer` on a parsed certificate). */\n\treadonly signerSpkiDer: Uint8Array;\n\t/** The signature algorithm as carried beside the signature. */\n\treadonly signatureAlgorithm: {\n\t\t/** Dotted-decimal signature algorithm OID. */\n\t\treadonly oid: string;\n\t\t/** DER algorithm parameters when the algorithm carries them (RSA-PSS). */\n\t\treadonly parametersDer?: Uint8Array;\n\t};\n\t/** The signer's public key algorithm as carried in its SPKI. */\n\treadonly publicKeyAlgorithm: {\n\t\t/** Dotted-decimal public key algorithm OID. */\n\t\treadonly oid: string;\n\t\t/** Named-curve or scheme parameters OID, when present. */\n\t\treadonly parametersOid?: string;\n\t};\n\t/** The signature bytes. ECDSA accepts DER or raw encoding. */\n\treadonly signature: Uint8Array;\n\t/** The exact bytes the signature covers. */\n\treadonly data: Uint8Array;\n}\n\n/** Input for {@linkcode verifySignatureWithKey}. */\nexport interface VerifySignatureWithKeyInput {\n\t/** An existing public key with verify usage; extractability is not required. */\n\treadonly publicKey: CryptoKey;\n\t/** Explicit signature OID and parameters, including RSA-PSS salt length. */\n\treadonly signatureAlgorithm: VerifySignatureInput['signatureAlgorithm'];\n\t/** ECDSA accepts raw r || s or DER; RSA and Ed25519 require raw. No encoding retry occurs. */\n\treadonly signatureEncoding: 'raw' | 'der';\n\t/** The signature bytes in the declared encoding. */\n\treadonly signature: Uint8Array;\n\t/** The exact bytes the signature covers. */\n\treadonly data: Uint8Array;\n}\n\n/**\n * Verifies a detached signature using an existing WebCrypto public key without\n * exporting or importing it. Repeated calls may reuse non-extractable keys.\n * Signature algorithms and parameters follow {@linkcode verifySignature}; RSA\n * scheme and hash must match the key. ECDSA encoding is explicit and never retried.\n * Returns the same validity, unsupported-parameter, operational-error and decoding-limit\n * branches as {@linkcode verifySignature}.\n */\nexport async function verifySignatureWithKey(\n\tinput: VerifySignatureWithKeyInput,\n): Promise<VerifySignatureResult> {\n\ttry {\n\t\treturn await verifySignedDataWithKeyDetailed(\n\t\t\tinput.publicKey,\n\t\t\tinput.signatureAlgorithm.oid,\n\t\t\tinput.signatureAlgorithm.parametersDer,\n\t\t\tinput.signature,\n\t\t\tinput.data,\n\t\t\tinput.signatureEncoding,\n\t\t);\n\t} catch (error) {\n\t\tconst refusal = decodeRefusalOf(error, DECODE_LIMIT_CODES);\n\t\tif (refusal === undefined) throw error;\n\t\treturn { ok: false, code: refusal.code, reason: refusal.message };\n\t}\n}\n\n/** Result of {@linkcode signData}: the signature plus its on-wire algorithm identity. */\nexport interface SignDataResult {\n\t/** The signature bytes. ECDSA is DER `ECDSA-Sig-Value`, everything else raw. */\n\treadonly signature: Uint8Array;\n\t/** Dotted-decimal signature algorithm OID. */\n\treadonly algorithmOid: string;\n\t/** DER algorithm parameters when the algorithm carries them (NULL for PKCS#1 v1.5, RSA-PSS params). */\n\treadonly parametersDer?: Uint8Array;\n}\n\n/**\n * Verifies a detached signature against the signer's DER `SubjectPublicKeyInfo`.\n *\n * Supports RSA PKCS#1 v1.5 (SHA-256/384/512), RSA-PSS with parsed parameters,\n * ECDSA P-256/P-384/P-521, and Ed25519. When an ECDSA signature fails to\n * verify under one encoding, the alternate DER/raw encoding is retried.\n *\n * Returns a typed union: `{ ok: true, valid }` when verification ran,\n * `unsupported_signature_algorithm_parameters`, `verification_error` or\n * `limit_exceeded` failures otherwise.\n */\nexport async function verifySignature(input: VerifySignatureInput): Promise<VerifySignatureResult> {\n\ttry {\n\t\treturn await verifySignedDataDetailed(\n\t\t\tinput.signatureAlgorithm.oid,\n\t\t\tinput.signatureAlgorithm.parametersDer,\n\t\t\tinput.publicKeyAlgorithm.oid,\n\t\t\tinput.publicKeyAlgorithm.parametersOid,\n\t\t\tinput.signerSpkiDer,\n\t\t\tinput.signature,\n\t\t\tinput.data,\n\t\t);\n\t} catch (error) {\n\t\tconst refusal = decodeRefusalOf(error, DECODE_LIMIT_CODES);\n\t\tif (refusal === undefined) {\n\t\t\tthrow error;\n\t\t}\n\t\treturn { ok: false, code: refusal.code, reason: refusal.message };\n\t}\n}\n\n/**\n * Signs `data` with a WebCrypto private key and returns the signature beside\n * the resolved `AlgorithmIdentifier` material for embedding in a signed\n * structure.\n *\n * The algorithm is inferred from the key (RSASSA-PKCS1-v1_5, ECDSA, Ed25519);\n * RSA-PSS keys require an explicit `{ kind: 'rsa-pss' }` profile. ECDSA\n * signatures are returned DER-encoded. Throws on unsupported key algorithms.\n */\nexport async function signData(\n\tprivateKey: CryptoKey,\n\tdata: Uint8Array,\n\tprofile?: SignatureProfileInput,\n): Promise<SignDataResult> {\n\tconst algorithm = getSignatureAlgorithm(privateKey, profile);\n\tconst signature = await signBytes(privateKey, algorithm, data);\n\treturn algorithm.parameters === undefined\n\t\t? { signature, algorithmOid: algorithm.algorithmOid }\n\t\t: { signature, algorithmOid: algorithm.algorithmOid, parametersDer: algorithm.parameters };\n}\n\n/**\n * Converts a DER `ECDSA-Sig-Value` (RFC 5480: SEQUENCE of INTEGERs r and s)\n * to the fixed-width raw `r || s` encoding WebCrypto and JOSE use.\n * Throws on malformed DER or integers too large for the curve.\n */\nexport function ecdsaSignatureDerToRaw(signature: Uint8Array, curve: EcNamedCurve): Uint8Array {\n\treturn derEcdsaSignatureToRaw(signature, ecdsaPartLength(curve));\n}\n\n/**\n * Converts a fixed-width raw `r || s` ECDSA signature to the DER\n * `ECDSA-Sig-Value` encoding X.509 and CMS structures embed.\n * Throws when the input length does not match the curve.\n */\nexport function ecdsaSignatureRawToDer(signature: Uint8Array, curve: EcNamedCurve): Uint8Array {\n\treturn rawEcdsaSignatureToDer(signature, ecdsaPartLength(curve));\n}\n\n/** Byte width of one ECDSA signature integer for the given curve. */\nfunction ecdsaPartLength(curve: EcNamedCurve): number {\n\tswitch (curve) {\n\t\tcase 'P-256':\n\t\t\treturn 32;\n\t\tcase 'P-384':\n\t\t\treturn 48;\n\t\tcase 'P-521':\n\t\t\treturn 66;\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = curve;\n\t\t\tthrow new Error(`Unhandled EcNamedCurve: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsFA,eAAsB,uBACrB,GACiC;CACjC,IAAI;EACH,OAAO,MAAMC,EACZC,EAAM,WACNA,EAAM,mBAAmB,KACzBA,EAAM,mBAAmB,eACzBA,EAAM,WACNA,EAAM,MACNA,EAAM,iBACP;CACD,SAASC,GAAO;EACf,IAAMC,IAAUC,EAAgBF,GAAOG,CAAkB;EACzD,IAAIF,MAAY,KAAA,GAAW,MAAMD;EACjC,OAAO;GAAE,IAAI;GAAO,MAAMC,EAAQ;GAAM,QAAQA,EAAQ;EAAQ;CACjE;AACD;;;;;;;;;;;;AAuBA,eAAsB,gBAAgB,GAA6D;CAClG,IAAI;EACH,OAAO,MAAMG,EACZL,EAAM,mBAAmB,KACzBA,EAAM,mBAAmB,eACzBA,EAAM,mBAAmB,KACzBA,EAAM,mBAAmB,eACzBA,EAAM,eACNA,EAAM,WACNA,EAAM,IACP;CACD,SAASC,GAAO;EACf,IAAMC,IAAUC,EAAgBF,GAAOG,CAAkB;EACzD,IAAIF,MAAY,KAAA,GACf,MAAMD;EAEP,OAAO;GAAE,IAAI;GAAO,MAAMC,EAAQ;GAAM,QAAQA,EAAQ;EAAQ;CACjE;AACD;;;;;;;;;;AAWA,eAAsB,SACrB,GACA,GACA,GAC0B;CAC1B,IAAMI,IAAYC,EAAsBC,GAAYC,CAAO,GACrDC,IAAY,MAAMC,EAAUH,GAAYF,GAAWM,CAAI;CAC7D,OAAON,EAAU,eAAe,KAAA,IAC7B;EAAE;EAAW,cAAcA,EAAU;CAAa,IAClD;EAAE;EAAW,cAAcA,EAAU;EAAc,eAAeA,EAAU;CAAW;AAC3F;;;;;;AAOA,SAAgB,uBAAuB,GAAuB,GAAiC;CAC9F,OAAOO,EAAuBH,GAAW,gBAAgBI,CAAK,CAAC;AAChE;;;;;;AAOA,SAAgB,uBAAuB,GAAuB,GAAiC;CAC9F,OAAOC,EAAuBL,GAAW,gBAAgBI,CAAK,CAAC;AAChE;;AAGA,SAAS,gBAAgB,GAA6B;CACrD,QAAQA,GAAR;EACC,KAAK,SACJ,OAAO;EACR,KAAK,SACJ,OAAO;EACR,KAAK,SACJ,OAAO;EACR,SAEC,MAAU,MAAM,2BAA2B,OAAOhB,CAAW,GAAG;CAElE;AACD"}
@@ -0,0 +1,4 @@
1
+ import { VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess } from "./internal/crypto/sig-verify.js";
2
+ import { SignatureProfileInput } from "./internal/crypto/signing.js";
3
+ import { SignDataResult, VerifySignatureInput, VerifySignatureLimitFailure, VerifySignatureResult, VerifySignatureWithKeyInput, ecdsaSignatureDerToRaw, ecdsaSignatureRawToDer, signData, verifySignature, verifySignatureWithKey } from "./crypto/crypto.js";
4
+ export { type SignDataResult, type SignatureProfileInput, type VerifySignatureConfigFailure, type VerifySignatureInput, type VerifySignatureLimitFailure, type VerifySignatureResult, type VerifySignatureWithKeyInput, type VerifySignedDataFailure, type VerifySignedDataResult, type VerifySignedDataSuccess, ecdsaSignatureDerToRaw, ecdsaSignatureRawToDer, signData, verifySignature, verifySignatureWithKey };
package/dist/crypto.js ADDED
@@ -0,0 +1 @@
1
+ export { ecdsaSignatureDerToRaw, ecdsaSignatureRawToDer, signData, verifySignature, verifySignatureWithKey } from "./crypto/crypto.js";