micro509 0.8.0 → 0.10.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.
- package/dist/index.d.ts +4 -4
- package/dist/index.js +15 -15
- package/dist/internal/asn1/asn1.js +145 -186
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +210 -227
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +297 -101
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/asn1/oids2.js +69 -0
- package/dist/internal/asn1/oids2.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +37 -35
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +25 -28
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +56 -117
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.js +122 -133
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +118 -124
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +87 -99
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +12 -8
- package/dist/internal/crypto/signing.js +53 -55
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +5 -3
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +10 -9
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +50 -57
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +43 -53
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +211 -239
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +228 -247
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +213 -228
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +62 -59
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +133 -164
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +35 -41
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +626 -447
- package/dist/keys/keys.js +652 -404
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.d.ts +2 -2
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +46 -46
- package/dist/pem/pem.js +62 -81
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.js +2 -2
- package/dist/pkcs/pfx.d.ts +96 -80
- package/dist/pkcs/pfx.js +191 -231
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +20 -18
- package/dist/pkcs/pkcs12-mac.js +90 -111
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +118 -69
- package/dist/pkcs/pkcs7.js +401 -443
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +37 -32
- package/dist/result/result.js +46 -44
- package/dist/result/result.js.map +1 -0
- package/dist/result.js +2 -2
- package/dist/revocation/chain.d.ts +138 -119
- package/dist/revocation/chain.js +248 -281
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +125 -123
- package/dist/revocation/crl.js +653 -745
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +183 -177
- package/dist/revocation/ocsp.js +581 -638
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +26 -26
- package/dist/revocation/revocation.js +104 -125
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +42 -42
- package/dist/verify/identity.js +158 -167
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +7 -7
- package/dist/verify/policy.d.ts +10 -10
- package/dist/verify/verify.d.ts +163 -163
- package/dist/verify/verify.js +396 -392
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.js +3 -3
- package/dist/x509/certificate.d.ts +117 -117
- package/dist/x509/certificate.js +51 -60
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +25 -25
- package/dist/x509/csr.js +26 -30
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +228 -184
- package/dist/x509/extensions.js +175 -200
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/name.d.ts +94 -93
- package/dist/x509/name.js +30 -29
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +185 -185
- package/dist/x509/parse.js +638 -676
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.js +6 -6
- package/package.json +79 -41
package/dist/x509/certificate.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { bitString, explicitContext, integer, integerFromNumber, sequence, time } from "../internal/asn1/der.js";
|
|
2
|
-
import { getCrypto } from "../internal/crypto/webcrypto.js";
|
|
3
|
-
import { base64Encode } from "../internal/shared/base64.js";
|
|
4
|
-
import { pemEncode } from "../pem/pem.js";
|
|
5
|
-
import { exportSpkiDer, generateKeyPair } from "../keys/keys.js";
|
|
6
|
-
import { encodeName, isNameInputEmpty } from "./name.js";
|
|
7
|
-
import { buildCertificateExtensions } from "./extensions.js";
|
|
8
|
-
import { encodeAlgorithmIdentifier, getSignatureAlgorithm, signBytes } from "../internal/crypto/signing.js";
|
|
1
|
+
import { bitString as e, explicitContext as t, integer as n, integerFromNumber as r, sequence as i, time as a } from "../internal/asn1/der.js";
|
|
2
|
+
import { getCrypto as o } from "../internal/crypto/webcrypto.js";
|
|
3
|
+
import { base64Encode as s } from "../internal/shared/base64.js";
|
|
4
|
+
import { pemEncode as c } from "../pem/pem.js";
|
|
5
|
+
import { exportSpkiDer as l, generateKeyPair as u } from "../keys/keys.js";
|
|
6
|
+
import { encodeName as d, isNameInputEmpty as f } from "./name.js";
|
|
7
|
+
import { buildCertificateExtensions as p } from "./extensions.js";
|
|
8
|
+
import { encodeAlgorithmIdentifier as m, getSignatureAlgorithm as h, signBytes as g } from "../internal/crypto/signing.js";
|
|
9
9
|
//#region src/x509/certificate.ts
|
|
10
10
|
/**
|
|
11
11
|
* Create X.509 certificates from typed names, extensions, and WebCrypto keys.
|
|
@@ -33,21 +33,21 @@ import { encodeAlgorithmIdentifier, getSignatureAlgorithm, signBytes } from "../
|
|
|
33
33
|
* @param input Certificate subject, key, validity, and extension settings.
|
|
34
34
|
* @returns The certificate plus the key pair used to sign it.
|
|
35
35
|
*/
|
|
36
|
-
async function createSelfSignedCertificate(
|
|
37
|
-
|
|
36
|
+
async function createSelfSignedCertificate(e) {
|
|
37
|
+
let t = e.keyPair ?? await u(e.algorithm);
|
|
38
38
|
return {
|
|
39
39
|
certificate: await createCertificate({
|
|
40
|
-
issuer:
|
|
41
|
-
subject:
|
|
42
|
-
publicKey:
|
|
43
|
-
signerPrivateKey:
|
|
44
|
-
issuerPublicKey:
|
|
45
|
-
...
|
|
46
|
-
...
|
|
47
|
-
...
|
|
48
|
-
...
|
|
40
|
+
issuer: e.subject,
|
|
41
|
+
subject: e.subject,
|
|
42
|
+
publicKey: t.publicKey,
|
|
43
|
+
signerPrivateKey: t.privateKey,
|
|
44
|
+
issuerPublicKey: t.publicKey,
|
|
45
|
+
...e.validity === void 0 ? {} : { validity: e.validity },
|
|
46
|
+
...e.serialNumber === void 0 ? {} : { serialNumber: e.serialNumber },
|
|
47
|
+
...e.extensions === void 0 ? {} : { extensions: e.extensions },
|
|
48
|
+
...e.signature === void 0 ? {} : { signature: e.signature }
|
|
49
49
|
}),
|
|
50
|
-
keyPair
|
|
50
|
+
keyPair: t
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -72,28 +72,21 @@ async function createSelfSignedCertificate(input) {
|
|
|
72
72
|
* @param input Issuer, subject, key, validity, and extension settings.
|
|
73
73
|
* @returns The encoded certificate material.
|
|
74
74
|
*/
|
|
75
|
-
async function createCertificate(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
explicitContext(3, sequence(extensions))
|
|
91
|
-
]);
|
|
92
|
-
const signatureValue = await signBytes(input.signerPrivateKey, signatureAlgorithm, tbsCertificate);
|
|
93
|
-
return materializeCertificate(sequence([
|
|
94
|
-
tbsCertificate,
|
|
95
|
-
encodeAlgorithmIdentifier(signatureAlgorithm),
|
|
96
|
-
bitString(signatureValue)
|
|
75
|
+
async function createCertificate(o) {
|
|
76
|
+
let s = await l(o.publicKey), c = o.issuerPublicKey ? await l(o.issuerPublicKey) : void 0, u = h(o.signerPrivateKey, o.signature), _ = resolveValidity(o.validity), v = f(o.subject), y = p(s, c, o.extensions, v), b = i([
|
|
77
|
+
t(0, r(2)),
|
|
78
|
+
n(o.serialNumber ?? randomSerialNumber()),
|
|
79
|
+
m(u),
|
|
80
|
+
d(o.issuer),
|
|
81
|
+
i([a(_.notBefore), a(_.notAfter)]),
|
|
82
|
+
d(o.subject),
|
|
83
|
+
s,
|
|
84
|
+
t(3, i(y))
|
|
85
|
+
]), x = await g(o.signerPrivateKey, u, b);
|
|
86
|
+
return materializeCertificate(i([
|
|
87
|
+
b,
|
|
88
|
+
m(u),
|
|
89
|
+
e(x)
|
|
97
90
|
]));
|
|
98
91
|
}
|
|
99
92
|
/**
|
|
@@ -102,11 +95,11 @@ async function createCertificate(input) {
|
|
|
102
95
|
* @param der DER-encoded certificate bytes.
|
|
103
96
|
* @returns DER, PEM, and base64 views of the same certificate.
|
|
104
97
|
*/
|
|
105
|
-
function materializeCertificate(
|
|
98
|
+
function materializeCertificate(e) {
|
|
106
99
|
return {
|
|
107
|
-
der,
|
|
108
|
-
pem:
|
|
109
|
-
base64:
|
|
100
|
+
der: e,
|
|
101
|
+
pem: c("CERTIFICATE", e),
|
|
102
|
+
base64: s(e)
|
|
110
103
|
};
|
|
111
104
|
}
|
|
112
105
|
/**
|
|
@@ -115,13 +108,12 @@ function materializeCertificate(der) {
|
|
|
115
108
|
* @param input Optional validity settings.
|
|
116
109
|
* @returns A concrete `notBefore` and `notAfter` pair.
|
|
117
110
|
*/
|
|
118
|
-
function resolveValidity(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (notAfter.getTime() <= notBefore.getTime()) throw new Error("notAfter must be after notBefore");
|
|
111
|
+
function resolveValidity(e) {
|
|
112
|
+
let t = e?.notBefore ?? /* @__PURE__ */ new Date(), n = e?.notAfter ?? addDays(t, e?.days ?? 30);
|
|
113
|
+
if (n.getTime() <= t.getTime()) throw Error("notAfter must be after notBefore");
|
|
122
114
|
return {
|
|
123
|
-
notBefore,
|
|
124
|
-
notAfter
|
|
115
|
+
notBefore: t,
|
|
116
|
+
notAfter: n
|
|
125
117
|
};
|
|
126
118
|
}
|
|
127
119
|
/**
|
|
@@ -131,10 +123,9 @@ function resolveValidity(input) {
|
|
|
131
123
|
* @param days Number of days to add.
|
|
132
124
|
* @returns The shifted date.
|
|
133
125
|
*/
|
|
134
|
-
function addDays(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return out;
|
|
126
|
+
function addDays(e, t) {
|
|
127
|
+
let n = new Date(e.getTime());
|
|
128
|
+
return n.setUTCDate(n.getUTCDate() + t), n;
|
|
138
129
|
}
|
|
139
130
|
/**
|
|
140
131
|
* Generate a random positive serial number suitable for certificate issuance.
|
|
@@ -142,10 +133,10 @@ function addDays(date, days) {
|
|
|
142
133
|
* @returns A 16-byte positive serial number.
|
|
143
134
|
*/
|
|
144
135
|
function randomSerialNumber() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if ((serial[0] ?? 0) === 0) serial[0] = 1;
|
|
148
|
-
return serial;
|
|
136
|
+
let e = o().getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
137
|
+
return e[0] = (e[0] ?? 0) & 127, (e[0] ?? 0) === 0 && (e[0] = 1), e;
|
|
149
138
|
}
|
|
150
139
|
//#endregion
|
|
151
140
|
export { createCertificate, createSelfSignedCertificate };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=certificate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"certificate.js","names":[],"sources":["../../src/x509/certificate.ts"],"sourcesContent":["/**\n * Create X.509 certificates from typed names, extensions, and WebCrypto keys.\n *\n * Use this module to issue a certificate from an existing issuer key pair or to\n * generate a self-signed certificate in one step.\n *\n * @module\n */\n\nimport {\n\tbitString,\n\texplicitContext,\n\tinteger,\n\tintegerFromNumber,\n\tsequence,\n\ttime,\n} from '#micro509/internal/asn1/der';\nimport type { SignatureProfileInput } from '#micro509/internal/crypto/signing';\n\nexport type { SignatureProfileInput };\n\nimport {\n\tencodeAlgorithmIdentifier,\n\tgetSignatureAlgorithm,\n\tsignBytes,\n} from '#micro509/internal/crypto/signing';\nimport { getCrypto } from '#micro509/internal/crypto/webcrypto';\nimport { base64Encode } from '#micro509/internal/shared/base64';\nimport type { KeyAlgorithmInput, KeyPairMaterial } from '#micro509/keys/keys';\nimport { exportSpkiDer, generateKeyPair } from '#micro509/keys/keys';\nimport { pemEncode } from '#micro509/pem/pem';\nimport type { CertificateExtensionsInput } from '#micro509/x509/extensions';\nimport { buildCertificateExtensions } from '#micro509/x509/extensions';\nimport type { NameInput } from '#micro509/x509/name';\nimport { encodeName, isNameInputEmpty } from '#micro509/x509/name';\n\nexport type * from '#micro509/x509/extensions';\nexport type * from '#micro509/x509/name';\n\n/**\n * Configures the certificate validity window.\n *\n * If `notAfter` is omitted, it is derived from `notBefore` plus `days`. If both\n * `notAfter` and `days` are omitted, the certificate is valid for 30 days.\n */\nexport interface ValidityInput {\n\t/**\n\t * Start of the validity window.\n\t *\n\t * Defaults to the current time.\n\t */\n\treadonly notBefore?: Date;\n\t/**\n\t * End of the validity window.\n\t *\n\t * Must be later than `notBefore`.\n\t */\n\treadonly notAfter?: Date;\n\t/**\n\t * Number of days to add to `notBefore` when `notAfter` is omitted.\n\t */\n\treadonly days?: number;\n}\n\n/**\n * Input for {@linkcode createCertificate}.\n */\nexport interface CreateCertificateInput {\n\t/**\n\t * Issuer distinguished name.\n\t */\n\treadonly issuer: NameInput;\n\t/**\n\t * Subject distinguished name.\n\t */\n\treadonly subject: NameInput;\n\t/**\n\t * Subject public key to encode into the certificate.\n\t */\n\treadonly publicKey: CryptoKey;\n\t/**\n\t * Private key used to sign the certificate.\n\t */\n\treadonly signerPrivateKey: CryptoKey;\n\t/**\n\t * Issuer public key.\n\t *\n\t * Provide this when extension builders need issuer key material, such as\n\t * authority key identifier derivation.\n\t */\n\treadonly issuerPublicKey?: CryptoKey;\n\t/**\n\t * Validity window configuration.\n\t */\n\treadonly validity?: ValidityInput;\n\t/**\n\t * DER integer bytes for the certificate serial number.\n\t *\n\t * When omitted, a random positive 16-byte serial number is generated.\n\t */\n\treadonly serialNumber?: Uint8Array;\n\t/**\n\t * X.509 extensions to encode into the certificate.\n\t */\n\treadonly extensions?: CertificateExtensionsInput;\n\t/**\n\t * Signature algorithm override.\n\t *\n\t * When omitted, the library selects a compatible profile from the signing\n\t * key.\n\t */\n\treadonly signature?: SignatureProfileInput;\n}\n\n/**\n * Input for {@linkcode createSelfSignedCertificate}.\n */\nexport interface CreateSelfSignedCertificateInput {\n\t/**\n\t * Subject distinguished name used as both subject and issuer.\n\t */\n\treadonly subject: NameInput;\n\t/**\n\t * Key generation parameters.\n\t *\n\t * Ignored when `keyPair` is provided.\n\t */\n\treadonly algorithm?: KeyAlgorithmInput;\n\t/**\n\t * Existing key pair to reuse for both subject and issuer.\n\t *\n\t * When omitted, a new key pair is generated.\n\t */\n\treadonly keyPair?: KeyPairMaterial;\n\t/**\n\t * Validity window configuration.\n\t */\n\treadonly validity?: ValidityInput;\n\t/**\n\t * DER integer bytes for the certificate serial number.\n\t */\n\treadonly serialNumber?: Uint8Array;\n\t/**\n\t * X.509 extensions to encode into the certificate.\n\t */\n\treadonly extensions?: CertificateExtensionsInput;\n\t/**\n\t * Signature algorithm override.\n\t */\n\treadonly signature?: SignatureProfileInput;\n}\n\n/**\n * Encoded certificate material in common interchange formats.\n */\nexport interface CertificateMaterial {\n\t/**\n\t * DER-encoded certificate bytes.\n\t */\n\treadonly der: Uint8Array;\n\t/**\n\t * PEM-encoded certificate.\n\t */\n\treadonly pem: string;\n\t/**\n\t * Base64 encoding of {@linkcode der} without PEM armor.\n\t */\n\treadonly base64: string;\n}\n\n/**\n * Result returned by {@linkcode createSelfSignedCertificate}.\n */\nexport interface SelfSignedCertificateResult {\n\t/**\n\t * Encoded certificate outputs.\n\t */\n\treadonly certificate: CertificateMaterial;\n\t/**\n\t * Key pair used to issue the certificate.\n\t */\n\treadonly keyPair: KeyPairMaterial;\n}\n\n/**\n * Create a self-signed certificate.\n *\n * Reuses `input.keyPair` when provided; otherwise generates a new key pair from\n * `input.algorithm`. The returned certificate uses `input.subject` as both\n * issuer and subject.\n *\n * @example\n * ```ts\n * const { certificate, keyPair } = await createSelfSignedCertificate({\n * \tsubject: { commonName: 'example.com' },\n * \talgorithm: { kind: 'ecdsa', curve: 'P-256' },\n * });\n * ```\n *\n * @param input Certificate subject, key, validity, and extension settings.\n * @returns The certificate plus the key pair used to sign it.\n */\nexport async function createSelfSignedCertificate(\n\tinput: CreateSelfSignedCertificateInput,\n): Promise<SelfSignedCertificateResult> {\n\tconst keyPair = input.keyPair ?? (await generateKeyPair(input.algorithm));\n\tconst certificateInput = {\n\t\tissuer: input.subject,\n\t\tsubject: input.subject,\n\t\tpublicKey: keyPair.publicKey,\n\t\tsignerPrivateKey: keyPair.privateKey,\n\t\tissuerPublicKey: keyPair.publicKey,\n\t\t...(input.validity !== undefined ? { validity: input.validity } : {}),\n\t\t...(input.serialNumber !== undefined ? { serialNumber: input.serialNumber } : {}),\n\t\t...(input.extensions !== undefined ? { extensions: input.extensions } : {}),\n\t\t...(input.signature !== undefined ? { signature: input.signature } : {}),\n\t} satisfies CreateCertificateInput;\n\tconst certificate = await createCertificate(certificateInput);\n\n\treturn { certificate, keyPair };\n}\n\n/**\n * Create an X.509 certificate signed by `input.signerPrivateKey`.\n *\n * The certificate encodes `input.subject`, `input.publicKey`, and any supplied\n * extensions. When `serialNumber` is omitted, a random positive serial number is\n * generated. When `validity` is omitted, the certificate is valid from now for\n * 30 days.\n *\n * @example\n * ```ts\n * const certificate = await createCertificate({\n * \tissuer: { commonName: 'Example Root CA' },\n * \tsubject: { commonName: 'example.com' },\n * \tpublicKey: leafKeys.publicKey,\n * \tsignerPrivateKey: issuerKeys.privateKey,\n * \tissuerPublicKey: issuerKeys.publicKey,\n * });\n * ```\n *\n * @param input Issuer, subject, key, validity, and extension settings.\n * @returns The encoded certificate material.\n */\nexport async function createCertificate(\n\tinput: CreateCertificateInput,\n): Promise<CertificateMaterial> {\n\tconst subjectPublicKeyInfo = await exportSpkiDer(input.publicKey);\n\tconst issuerPublicKeyInfo = input.issuerPublicKey\n\t\t? await exportSpkiDer(input.issuerPublicKey)\n\t\t: undefined;\n\tconst signatureAlgorithm = getSignatureAlgorithm(input.signerPrivateKey, input.signature);\n\tconst validity = resolveValidity(input.validity);\n\tconst subjectIsEmpty = isNameInputEmpty(input.subject);\n\tconst extensions = buildCertificateExtensions(\n\t\tsubjectPublicKeyInfo,\n\t\tissuerPublicKeyInfo,\n\t\tinput.extensions,\n\t\tsubjectIsEmpty,\n\t);\n\tconst tbsCertificate = sequence([\n\t\texplicitContext(0, integerFromNumber(2)),\n\t\tinteger(input.serialNumber ?? randomSerialNumber()),\n\t\tencodeAlgorithmIdentifier(signatureAlgorithm),\n\t\tencodeName(input.issuer),\n\t\tsequence([time(validity.notBefore), time(validity.notAfter)]),\n\t\tencodeName(input.subject),\n\t\tsubjectPublicKeyInfo,\n\t\texplicitContext(3, sequence(extensions)),\n\t]);\n\n\tconst signatureValue = await signBytes(\n\t\tinput.signerPrivateKey,\n\t\tsignatureAlgorithm,\n\t\ttbsCertificate,\n\t);\n\tconst certificateDer = sequence([\n\t\ttbsCertificate,\n\t\tencodeAlgorithmIdentifier(signatureAlgorithm),\n\t\tbitString(signatureValue),\n\t]);\n\n\treturn materializeCertificate(certificateDer);\n}\n\n/**\n * Convert DER bytes into all exported certificate encodings.\n *\n * @param der DER-encoded certificate bytes.\n * @returns DER, PEM, and base64 views of the same certificate.\n */\nfunction materializeCertificate(der: Uint8Array): CertificateMaterial {\n\treturn {\n\t\tder,\n\t\tpem: pemEncode('CERTIFICATE', der),\n\t\tbase64: base64Encode(der),\n\t};\n}\n\n/**\n * Normalized validity window used during certificate creation.\n */\ninterface ResolvedValidity {\n\t/**\n\t * Start of the validity window.\n\t */\n\treadonly notBefore: Date;\n\t/**\n\t * End of the validity window.\n\t */\n\treadonly notAfter: Date;\n}\n\n/**\n * Resolve defaults for a certificate validity window.\n *\n * @param input Optional validity settings.\n * @returns A concrete `notBefore` and `notAfter` pair.\n */\nfunction resolveValidity(input: ValidityInput | undefined): ResolvedValidity {\n\tconst notBefore = input?.notBefore ?? new Date();\n\tconst notAfter = input?.notAfter ?? addDays(notBefore, input?.days ?? 30);\n\tif (notAfter.getTime() <= notBefore.getTime()) {\n\t\tthrow new Error('notAfter must be after notBefore');\n\t}\n\treturn { notBefore, notAfter };\n}\n\n/**\n * Return a new date offset by a whole number of UTC days.\n *\n * @param date Base date.\n * @param days Number of days to add.\n * @returns The shifted date.\n */\nfunction addDays(date: Date, days: number): Date {\n\tconst out = new Date(date.getTime());\n\tout.setUTCDate(out.getUTCDate() + days);\n\treturn out;\n}\n\n/**\n * Generate a random positive serial number suitable for certificate issuance.\n *\n * @returns A 16-byte positive serial number.\n */\nfunction randomSerialNumber(): Uint8Array {\n\tconst serial = getCrypto().getRandomValues(new Uint8Array(16));\n\tconst first = serial[0] ?? 0;\n\tserial[0] = first & 0x7f;\n\tif ((serial[0] ?? 0) === 0) {\n\t\tserial[0] = 1;\n\t}\n\treturn serial;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0MA,eAAsB,4BACrB,GACuC;CACvC,IAAM,IAAU,EAAM,WAAY,MAAM,EAAgB,EAAM,SAAS;CAcvE,OAAO;EAAE,aAAA,MAFiB,kBAAkB;GAV3C,QAAQ,EAAM;GACd,SAAS,EAAM;GACf,WAAW,EAAQ;GACnB,kBAAkB,EAAQ;GAC1B,iBAAiB,EAAQ;GACzB,GAAI,EAAM,aAAa,KAAA,IAA2C,CAAC,IAAhC,EAAE,UAAU,EAAM,SAAS;GAC9D,GAAI,EAAM,iBAAiB,KAAA,IAAmD,CAAC,IAAxC,EAAE,cAAc,EAAM,aAAa;GAC1E,GAAI,EAAM,eAAe,KAAA,IAA+C,CAAC,IAApC,EAAE,YAAY,EAAM,WAAW;GACpE,GAAI,EAAM,cAAc,KAAA,IAA6C,CAAC,IAAlC,EAAE,WAAW,EAAM,UAAU;EAEP,CAAC;EAEtC;CAAQ;AAC/B;;;;;;;;;;;;;;;;;;;;;;;AAwBA,eAAsB,kBACrB,GAC+B;CAC/B,IAAM,IAAuB,MAAM,EAAc,EAAM,SAAS,GAC1D,IAAsB,EAAM,kBAC/B,MAAM,EAAc,EAAM,eAAe,IACzC,KAAA,GACG,IAAqB,EAAsB,EAAM,kBAAkB,EAAM,SAAS,GAClF,IAAW,gBAAgB,EAAM,QAAQ,GACzC,IAAiB,EAAiB,EAAM,OAAO,GAC/C,IAAa,EAClB,GACA,GACA,EAAM,YACN,CACD,GACM,IAAiB,EAAS;EAC/B,EAAgB,GAAG,EAAkB,CAAC,CAAC;EACvC,EAAQ,EAAM,gBAAgB,mBAAmB,CAAC;EAClD,EAA0B,CAAkB;EAC5C,EAAW,EAAM,MAAM;EACvB,EAAS,CAAC,EAAK,EAAS,SAAS,GAAG,EAAK,EAAS,QAAQ,CAAC,CAAC;EAC5D,EAAW,EAAM,OAAO;EACxB;EACA,EAAgB,GAAG,EAAS,CAAU,CAAC;CACxC,CAAC,GAEK,IAAiB,MAAM,EAC5B,EAAM,kBACN,GACA,CACD;CAOA,OAAO,uBANgB,EAAS;EAC/B;EACA,EAA0B,CAAkB;EAC5C,EAAU,CAAc;CACzB,CAE2C,CAAC;AAC7C;;;;;;;AAQA,SAAS,uBAAuB,GAAsC;CACrE,OAAO;EACN;EACA,KAAK,EAAU,eAAe,CAAG;EACjC,QAAQ,EAAa,CAAG;CACzB;AACD;;;;;;;AAsBA,SAAS,gBAAgB,GAAoD;CAC5E,IAAM,IAAY,GAAO,6BAAa,IAAI,KAAK,GACzC,IAAW,GAAO,YAAY,QAAQ,GAAW,GAAO,QAAQ,EAAE;CACxE,IAAI,EAAS,QAAQ,KAAK,EAAU,QAAQ,GAC3C,MAAU,MAAM,kCAAkC;CAEnD,OAAO;EAAE;EAAW;CAAS;AAC9B;;;;;;;;AASA,SAAS,QAAQ,GAAY,GAAoB;CAChD,IAAM,IAAM,IAAI,KAAK,EAAK,QAAQ,CAAC;CAEnC,OADA,EAAI,WAAW,EAAI,WAAW,IAAI,CAAI,GAC/B;AACR;;;;;;AAOA,SAAS,qBAAiC;CACzC,IAAM,IAAS,EAAU,CAAC,CAAC,gCAAgB,IAAI,WAAW,EAAE,CAAC;CAM7D,OAJA,EAAO,MADO,EAAO,MAAM,KACP,MACf,EAAO,MAAM,OAAO,MACxB,EAAO,KAAK,IAEN;AACR"}
|
package/dist/x509/csr.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { NameAttribute, NameFieldKey, NameInput, NameObject, RelativeDistinguishedNameInput, encodeName, encodeRelativeDistinguishedName } from "./name.js";
|
|
2
2
|
import { AuthorityInfoAccessMethod, AuthorityInformationAccess, BasicConstraints, CertificateExtensionsInput, CertificatePolicies, CpsPolicyQualifierInfo, CustomAuthorityInfoAccessMethod, CustomExtendedKeyUsage, CustomExtension, CustomPolicyQualifierInfo, DistributionPoint, DistributionPointName, DistributionPointReason, ExtendedKeyUsage, GeneralName, GeneralSubtree, InhibitAnyPolicy, IssuingDistributionPoint, IssuingDistributionPointBase, IssuingDistributionPointForAttributeCerts, IssuingDistributionPointForCaCerts, IssuingDistributionPointForUserCerts, KeyUsage, KnownAuthorityInfoAccessMethod, KnownExtendedKeyUsage, NameConstraintForm, NameConstraints, ParsedBitFlags, ParsedNameConstraintForm, PolicyConstraints, PolicyInformation, PolicyMapping, PolicyMappings, PolicyNoticeReference, PolicyQualifierInfo, SubjectAltName, UnsupportedNameConstraintForm, UserNoticePolicyQualifierInfo, buildCertificateExtensions, buildRequestedExtensions, encodeAuthorityInfoAccess, encodeBasicConstraints, encodeCertificatePolicies, encodeCrlDistributionPoints, encodeExtendedKeyUsage, encodeExtension, encodeInhibitAnyPolicy, encodeKeyUsage, encodeNameConstraints, encodePolicyConstraints, encodePolicyMappings, encodeSubjectAltName, getAuthorityInfoAccessMethodOid, getExtendedKeyUsageOid, parseAuthorityInfoAccessMethodOid, parseExtendedKeyUsageOid } from "./extensions.js";
|
|
3
3
|
import { SignatureProfileInput } from "../internal/crypto/signing.js";
|
|
4
|
-
|
|
5
4
|
//#region src/x509/csr.d.ts
|
|
6
5
|
/** Input for {@linkcode createCertificateSigningRequest}. */
|
|
7
6
|
interface CreateCsrInput {
|
|
@@ -26,29 +25,30 @@ interface CsrMaterial {
|
|
|
26
25
|
readonly base64: string;
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
29
|
-
* Creates a PKCS#10 Certificate Signing Request signed with the given private key.
|
|
30
|
-
*
|
|
31
|
-
* The CSR embeds the public key's SPKI, the subject name, and any requested extensions
|
|
32
|
-
* as attributes. The signature proves possession of the private key.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* import { createCertificateSigningRequest } from 'micro509';
|
|
37
|
-
*
|
|
38
|
-
* const keyPair = await crypto.subtle.generateKey(
|
|
39
|
-
* { name: 'ECDSA', namedCurve: 'P-256' },
|
|
40
|
-
* true,
|
|
41
|
-
* ['sign', 'verify'],
|
|
42
|
-
* );
|
|
43
|
-
* const csr = await createCertificateSigningRequest({
|
|
44
|
-
* subject: { commonName: 'example.com' },
|
|
45
|
-
* publicKey: keyPair.publicKey,
|
|
46
|
-
* signerPrivateKey: keyPair.privateKey,
|
|
47
|
-
* extensions: { subjectAltNames: [{ type: 'dns', value: 'example.com' }] },
|
|
48
|
-
* });
|
|
49
|
-
* console.log(csr.pem);
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
28
|
+
* Creates a PKCS#10 Certificate Signing Request signed with the given private key.
|
|
29
|
+
*
|
|
30
|
+
* The CSR embeds the public key's SPKI, the subject name, and any requested extensions
|
|
31
|
+
* as attributes. The signature proves possession of the private key.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createCertificateSigningRequest } from 'micro509';
|
|
36
|
+
*
|
|
37
|
+
* const keyPair = await crypto.subtle.generateKey(
|
|
38
|
+
* { name: 'ECDSA', namedCurve: 'P-256' },
|
|
39
|
+
* true,
|
|
40
|
+
* ['sign', 'verify'],
|
|
41
|
+
* );
|
|
42
|
+
* const csr = await createCertificateSigningRequest({
|
|
43
|
+
* subject: { commonName: 'example.com' },
|
|
44
|
+
* publicKey: keyPair.publicKey,
|
|
45
|
+
* signerPrivateKey: keyPair.privateKey,
|
|
46
|
+
* extensions: { subjectAltNames: [{ type: 'dns', value: 'example.com' }] },
|
|
47
|
+
* });
|
|
48
|
+
* console.log(csr.pem);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
52
51
|
declare function createCertificateSigningRequest(input: CreateCsrInput): Promise<CsrMaterial>;
|
|
53
52
|
//#endregion
|
|
54
|
-
export { type AuthorityInfoAccessMethod, type AuthorityInformationAccess, type BasicConstraints, type CertificateExtensionsInput, type CertificatePolicies, type CpsPolicyQualifierInfo, CreateCsrInput, CsrMaterial, type CustomAuthorityInfoAccessMethod, type CustomExtendedKeyUsage, type CustomExtension, type CustomPolicyQualifierInfo, type DistributionPoint, type DistributionPointName, type DistributionPointReason, type ExtendedKeyUsage, type GeneralName, type GeneralSubtree, type InhibitAnyPolicy, type IssuingDistributionPoint, type IssuingDistributionPointBase, type IssuingDistributionPointForAttributeCerts, type IssuingDistributionPointForCaCerts, type IssuingDistributionPointForUserCerts, type KeyUsage, type KnownAuthorityInfoAccessMethod, type KnownExtendedKeyUsage, type NameConstraintForm, type NameConstraints, type NameInput, type NameObject, type ParsedBitFlags, type ParsedNameConstraintForm, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyNoticeReference, type PolicyQualifierInfo, type SubjectAltName, type UnsupportedNameConstraintForm, type UserNoticePolicyQualifierInfo, type buildCertificateExtensions, type buildRequestedExtensions, createCertificateSigningRequest, type encodeAuthorityInfoAccess, type encodeBasicConstraints, type encodeCertificatePolicies, type encodeCrlDistributionPoints, type encodeExtendedKeyUsage, type encodeExtension, type encodeInhibitAnyPolicy, type encodeKeyUsage, type encodeName, type encodeNameConstraints, type encodePolicyConstraints, type encodePolicyMappings, type encodeRelativeDistinguishedName, type encodeSubjectAltName, type getAuthorityInfoAccessMethodOid, type getExtendedKeyUsageOid, type parseAuthorityInfoAccessMethodOid, type parseExtendedKeyUsageOid };
|
|
53
|
+
export { type AuthorityInfoAccessMethod, type AuthorityInformationAccess, type BasicConstraints, type CertificateExtensionsInput, type CertificatePolicies, type CpsPolicyQualifierInfo, CreateCsrInput, CsrMaterial, type CustomAuthorityInfoAccessMethod, type CustomExtendedKeyUsage, type CustomExtension, type CustomPolicyQualifierInfo, type DistributionPoint, type DistributionPointName, type DistributionPointReason, type ExtendedKeyUsage, type GeneralName, type GeneralSubtree, type InhibitAnyPolicy, type IssuingDistributionPoint, type IssuingDistributionPointBase, type IssuingDistributionPointForAttributeCerts, type IssuingDistributionPointForCaCerts, type IssuingDistributionPointForUserCerts, type KeyUsage, type KnownAuthorityInfoAccessMethod, type KnownExtendedKeyUsage, type NameConstraintForm, type NameConstraints, type NameInput, type NameObject, type ParsedBitFlags, type ParsedNameConstraintForm, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyNoticeReference, type PolicyQualifierInfo, type SubjectAltName, type UnsupportedNameConstraintForm, type UserNoticePolicyQualifierInfo, type buildCertificateExtensions, type buildRequestedExtensions, createCertificateSigningRequest, type encodeAuthorityInfoAccess, type encodeBasicConstraints, type encodeCertificatePolicies, type encodeCrlDistributionPoints, type encodeExtendedKeyUsage, type encodeExtension, type encodeInhibitAnyPolicy, type encodeKeyUsage, type encodeName, type encodeNameConstraints, type encodePolicyConstraints, type encodePolicyMappings, type encodeRelativeDistinguishedName, type encodeSubjectAltName, type getAuthorityInfoAccessMethodOid, type getExtendedKeyUsageOid, type parseAuthorityInfoAccessMethodOid, type parseExtendedKeyUsageOid };
|
|
54
|
+
//# sourceMappingURL=csr.d.ts.map
|
package/dist/x509/csr.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { bitString, concatBytes, implicitConstructedContext, integerFromNumber, objectIdentifier, sequence, setOf } from "../internal/asn1/der.js";
|
|
2
|
-
import { OIDS } from "../internal/asn1/
|
|
3
|
-
import { base64Encode } from "../internal/shared/base64.js";
|
|
4
|
-
import { pemEncode } from "../pem/pem.js";
|
|
5
|
-
import { exportSpkiDer } from "../keys/keys.js";
|
|
6
|
-
import { encodeName } from "./name.js";
|
|
7
|
-
import { buildRequestedExtensions } from "./extensions.js";
|
|
8
|
-
import { encodeAlgorithmIdentifier, getSignatureAlgorithm, signBytes } from "../internal/crypto/signing.js";
|
|
1
|
+
import { bitString as e, concatBytes as t, implicitConstructedContext as n, integerFromNumber as r, objectIdentifier as i, sequence as a, setOf as o } from "../internal/asn1/der.js";
|
|
2
|
+
import { OIDS as s } from "../internal/asn1/oids2.js";
|
|
3
|
+
import { base64Encode as c } from "../internal/shared/base64.js";
|
|
4
|
+
import { pemEncode as l } from "../pem/pem.js";
|
|
5
|
+
import { exportSpkiDer as u } from "../keys/keys.js";
|
|
6
|
+
import { encodeName as d } from "./name.js";
|
|
7
|
+
import { buildRequestedExtensions as f } from "./extensions.js";
|
|
8
|
+
import { encodeAlgorithmIdentifier as p, getSignatureAlgorithm as m, signBytes as h } from "../internal/crypto/signing.js";
|
|
9
9
|
//#region src/x509/csr.ts
|
|
10
10
|
/**
|
|
11
11
|
* PKCS#10 Certificate Signing Request (CSR) creation.
|
|
@@ -39,33 +39,29 @@ import { encodeAlgorithmIdentifier, getSignatureAlgorithm, signBytes } from "../
|
|
|
39
39
|
* console.log(csr.pem);
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
async function createCertificateSigningRequest(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const normalizedSignature = await signBytes(input.signerPrivateKey, signatureAlgorithm, certificationRequestInfo);
|
|
53
|
-
const der = sequence([
|
|
54
|
-
certificationRequestInfo,
|
|
55
|
-
encodeAlgorithmIdentifier(signatureAlgorithm),
|
|
56
|
-
bitString(normalizedSignature)
|
|
42
|
+
async function createCertificateSigningRequest(i) {
|
|
43
|
+
let o = m(i.signerPrivateKey, i.signature), s = await u(i.publicKey), f = buildAttributes(i.extensions), g = a([
|
|
44
|
+
r(0),
|
|
45
|
+
d(i.subject),
|
|
46
|
+
s,
|
|
47
|
+
n(0, t(f))
|
|
48
|
+
]), _ = await h(i.signerPrivateKey, o, g), v = a([
|
|
49
|
+
g,
|
|
50
|
+
p(o),
|
|
51
|
+
e(_)
|
|
57
52
|
]);
|
|
58
53
|
return {
|
|
59
|
-
der,
|
|
60
|
-
pem:
|
|
61
|
-
base64:
|
|
54
|
+
der: v,
|
|
55
|
+
pem: l("CERTIFICATE REQUEST", v),
|
|
56
|
+
base64: c(v)
|
|
62
57
|
};
|
|
63
58
|
}
|
|
64
59
|
/** Encodes extensions into a CSR extensionRequest attribute, or returns empty. */
|
|
65
|
-
function buildAttributes(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return [sequence([objectIdentifier(OIDS.extensionRequest), setOf([sequence(builtExtensions)])])];
|
|
60
|
+
function buildAttributes(e) {
|
|
61
|
+
let t = f(e);
|
|
62
|
+
return t.length === 0 ? [] : [a([i(s.extensionRequest), o([a(t)])])];
|
|
69
63
|
}
|
|
70
64
|
//#endregion
|
|
71
65
|
export { createCertificateSigningRequest };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=csr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csr.js","names":[],"sources":["../../src/x509/csr.ts"],"sourcesContent":["/**\n * PKCS#10 Certificate Signing Request (CSR) creation.\n *\n * Builds a CSR from a subject name, WebCrypto key pair, and optional extensions,\n * producing DER, PEM, and base64 outputs.\n *\n * @module\n */\n\nimport {\n\tbitString,\n\tconcatBytes,\n\timplicitConstructedContext,\n\tintegerFromNumber,\n\tobjectIdentifier,\n\tsequence,\n\tsetOf,\n} from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport {\n\tencodeAlgorithmIdentifier,\n\tgetSignatureAlgorithm,\n\tsignBytes,\n} from '#micro509/internal/crypto/signing';\nimport { base64Encode } from '#micro509/internal/shared/base64';\nimport { exportSpkiDer } from '#micro509/keys/keys';\nimport { pemEncode } from '#micro509/pem/pem';\nimport type { SignatureProfileInput } from '#micro509/x509/certificate';\nimport type { CertificateExtensionsInput } from '#micro509/x509/extensions';\nimport { buildRequestedExtensions } from '#micro509/x509/extensions';\nimport type { NameInput } from '#micro509/x509/name';\nimport { encodeName } from '#micro509/x509/name';\n\nexport type * from '#micro509/x509/extensions';\nexport type * from '#micro509/x509/name';\n\n/** Input for {@linkcode createCertificateSigningRequest}. */\nexport interface CreateCsrInput {\n\t/** Distinguished name for the CSR subject (e.g. `{ commonName: 'example.com' }`). */\n\treadonly subject: NameInput;\n\t/** WebCrypto public key to embed in the CSR's SubjectPublicKeyInfo. */\n\treadonly publicKey: CryptoKey;\n\t/** WebCrypto private key used to self-sign the CSR (proves key possession). */\n\treadonly signerPrivateKey: CryptoKey;\n\t/** Requested X.509v3 extensions to include in the CSR attributes. */\n\treadonly extensions?: CertificateExtensionsInput;\n\t/** Override the signature algorithm profile (hash, salt length, etc.). */\n\treadonly signature?: SignatureProfileInput;\n}\n\n/** DER, PEM, and base64 encodings of a CSR produced by {@linkcode createCertificateSigningRequest}. */\nexport interface CsrMaterial {\n\t/** Raw DER-encoded PKCS#10 CertificationRequest. */\n\treadonly der: Uint8Array;\n\t/** PEM-armored CSR (`-----BEGIN CERTIFICATE REQUEST-----`). */\n\treadonly pem: string;\n\t/** Base64-encoded DER (no PEM armor). */\n\treadonly base64: string;\n}\n\n/**\n * Creates a PKCS#10 Certificate Signing Request signed with the given private key.\n *\n * The CSR embeds the public key's SPKI, the subject name, and any requested extensions\n * as attributes. The signature proves possession of the private key.\n *\n * @example\n * ```ts\n * import { createCertificateSigningRequest } from 'micro509';\n *\n * const keyPair = await crypto.subtle.generateKey(\n * { name: 'ECDSA', namedCurve: 'P-256' },\n * true,\n * ['sign', 'verify'],\n * );\n * const csr = await createCertificateSigningRequest({\n * subject: { commonName: 'example.com' },\n * publicKey: keyPair.publicKey,\n * signerPrivateKey: keyPair.privateKey,\n * extensions: { subjectAltNames: [{ type: 'dns', value: 'example.com' }] },\n * });\n * console.log(csr.pem);\n * ```\n */\nexport async function createCertificateSigningRequest(input: CreateCsrInput): Promise<CsrMaterial> {\n\tconst signatureAlgorithm = getSignatureAlgorithm(input.signerPrivateKey, input.signature);\n\tconst spki = await exportSpkiDer(input.publicKey);\n\tconst attributes = buildAttributes(input.extensions);\n\tconst certificationRequestInfo = sequence([\n\t\tintegerFromNumber(0),\n\t\tencodeName(input.subject),\n\t\tspki,\n\t\timplicitConstructedContext(0, concatBytes(attributes)),\n\t]);\n\tconst normalizedSignature = await signBytes(\n\t\tinput.signerPrivateKey,\n\t\tsignatureAlgorithm,\n\t\tcertificationRequestInfo,\n\t);\n\n\tconst der = sequence([\n\t\tcertificationRequestInfo,\n\t\tencodeAlgorithmIdentifier(signatureAlgorithm),\n\t\tbitString(normalizedSignature),\n\t]);\n\treturn {\n\t\tder,\n\t\tpem: pemEncode('CERTIFICATE REQUEST', der),\n\t\tbase64: base64Encode(der),\n\t};\n}\n\n/** Encodes extensions into a CSR extensionRequest attribute, or returns empty. */\nfunction buildAttributes(extensions: CertificateExtensionsInput | undefined): Uint8Array[] {\n\tconst builtExtensions = buildRequestedExtensions(extensions);\n\tif (builtExtensions.length === 0) {\n\t\treturn [];\n\t}\n\treturn [sequence([objectIdentifier(OIDS.extensionRequest), setOf([sequence(builtExtensions)])])];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,eAAsB,gCAAgC,GAA6C;CAClG,IAAM,IAAqB,EAAsB,EAAM,kBAAkB,EAAM,SAAS,GAClF,IAAO,MAAM,EAAc,EAAM,SAAS,GAC1C,IAAa,gBAAgB,EAAM,UAAU,GAC7C,IAA2B,EAAS;EACzC,EAAkB,CAAC;EACnB,EAAW,EAAM,OAAO;EACxB;EACA,EAA2B,GAAG,EAAY,CAAU,CAAC;CACtD,CAAC,GACK,IAAsB,MAAM,EACjC,EAAM,kBACN,GACA,CACD,GAEM,IAAM,EAAS;EACpB;EACA,EAA0B,CAAkB;EAC5C,EAAU,CAAmB;CAC9B,CAAC;CACD,OAAO;EACN;EACA,KAAK,EAAU,uBAAuB,CAAG;EACzC,QAAQ,EAAa,CAAG;CACzB;AACD;;AAGA,SAAS,gBAAgB,GAAkE;CAC1F,IAAM,IAAkB,EAAyB,CAAU;CAI3D,OAHI,EAAgB,WAAW,IACvB,CAAC,IAEF,CAAC,EAAS,CAAC,EAAiB,EAAK,gBAAgB,GAAG,EAAM,CAAC,EAAS,CAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AAChG"}
|