@owf/x509 0.0.0-stage → 0.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["X509Name","X509Certificate","X509Certificate","AsnRevokedCertificate"],"sources":["../src/constants.ts","../src/x509-exception.ts","../src/encoding.ts","../src/der.ts","../src/name.ts","../src/extensions.ts","../src/qc-statements.ts","../src/certificate.ts","../src/signature.ts","../src/create.ts","../src/crl.ts"],"sourcesContent":["import { id_pe_qcStatements } from '@peculiar/asn1-x509-qualified'\nimport {\n id_etsi_qcs_qcCClegislation,\n id_etsi_qcs_qcCompliance,\n id_etsi_qcs_qcPDS,\n id_etsi_qcs_qcSSCD,\n id_etsi_qcs_qcType,\n id_etsi_qct_eseal,\n id_etsi_qct_esign,\n id_etsi_qct_web,\n} from '@peculiar/asn1-x509-qualified-etsi'\n\n/** X.520 attribute types and PKCS#9 emailAddress, as used in distinguished names */\nexport const ATTRIBUTE_TYPES = {\n commonName: '2.5.4.3',\n surname: '2.5.4.4',\n serialNumber: '2.5.4.5',\n countryName: '2.5.4.6',\n localityName: '2.5.4.7',\n stateOrProvinceName: '2.5.4.8',\n streetAddress: '2.5.4.9',\n organizationName: '2.5.4.10',\n organizationalUnitName: '2.5.4.11',\n title: '2.5.4.12',\n postalCode: '2.5.4.17',\n telephoneNumber: '2.5.4.20',\n givenName: '2.5.4.42',\n initials: '2.5.4.43',\n generationQualifier: '2.5.4.44',\n pseudonym: '2.5.4.65',\n organizationIdentifier: '2.5.4.97',\n emailAddress: '1.2.840.113549.1.9.1',\n} as const\n\nexport type AttributeName = keyof typeof ATTRIBUTE_TYPES\n\n/** Policy qualifier identifiers (RFC 5280 clause 4.2.1.4) */\nexport const POLICY_QUALIFIERS = {\n cps: '1.3.6.1.5.5.7.2.1',\n unotice: '1.3.6.1.5.5.7.2.2',\n} as const\n\n/** Access methods for the Authority Information Access extension (RFC 5280 clause 4.2.2.1) */\nexport const ACCESS_METHODS = {\n ocsp: '1.3.6.1.5.5.7.48.1',\n caIssuers: '1.3.6.1.5.5.7.48.2',\n} as const\n\n/** QCStatements extension (RFC 3739) and statements from ETSI EN 319 412-5 */\nexport const QC_STATEMENTS = {\n extension: id_pe_qcStatements,\n qcCompliance: id_etsi_qcs_qcCompliance,\n qcSSCD: id_etsi_qcs_qcSSCD,\n qcPDS: id_etsi_qcs_qcPDS,\n qcType: id_etsi_qcs_qcType,\n qcCClegislation: id_etsi_qcs_qcCClegislation,\n} as const\n\n/** QcType values (ETSI EN 319 412-5 clause 4.2.3) */\nexport const QC_TYPES = {\n esign: id_etsi_qct_esign,\n eseal: id_etsi_qct_eseal,\n web: id_etsi_qct_web,\n} as const\n\nexport type QcType = keyof typeof QC_TYPES\n\n/** Signature algorithms supported for creating and describing certificates and CRLs */\nexport const SIGNATURE_ALGORITHMS = {\n ES256: { oid: '1.2.840.10045.4.3.2', hash: 'SHA-256', family: 'ecdsa' },\n ES384: { oid: '1.2.840.10045.4.3.3', hash: 'SHA-384', family: 'ecdsa' },\n ES512: { oid: '1.2.840.10045.4.3.4', hash: 'SHA-512', family: 'ecdsa' },\n RS256: { oid: '1.2.840.113549.1.1.11', hash: 'SHA-256', family: 'rsa' },\n RS384: { oid: '1.2.840.113549.1.1.12', hash: 'SHA-384', family: 'rsa' },\n RS512: { oid: '1.2.840.113549.1.1.13', hash: 'SHA-512', family: 'rsa' },\n} as const\n\nexport type SignatureAlgorithm = keyof typeof SIGNATURE_ALGORITHMS\n\n/** Public key algorithm and curve identifiers */\nexport const KEY_ALGORITHMS = {\n ecPublicKey: '1.2.840.10045.2.1',\n rsaEncryption: '1.2.840.113549.1.1.1',\n 'P-256': '1.2.840.10045.3.1.7',\n 'P-384': '1.3.132.0.34',\n 'P-521': '1.3.132.0.35',\n} as const\n\n/** CRL entry revocation reasons (RFC 5280 clause 5.3.1) */\nexport const CRL_REASONS = {\n unspecified: 0,\n keyCompromise: 1,\n cACompromise: 2,\n affiliationChanged: 3,\n superseded: 4,\n cessationOfOperation: 5,\n certificateHold: 6,\n removeFromCRL: 8,\n privilegeWithdrawn: 9,\n aACompromise: 10,\n} as const\n\nexport type CrlReason = keyof typeof CRL_REASONS\n","import { IdentityException } from '@owf/identity-common'\n\n/**\n * X509Exception is thrown when a certificate or CRL cannot be parsed or created.\n */\nexport class X509Exception extends IdentityException {\n constructor(message: string, details?: unknown) {\n super(message, details)\n Object.setPrototypeOf(this, X509Exception.prototype)\n this.name = 'X509Exception'\n }\n}\n","import { base64 } from '@owf/identity-common'\nimport { X509Exception } from './x509-exception'\n\n/** DER bytes, a base64 encoded DER string, or a PEM string */\nexport type DerInput = Uint8Array | ArrayBuffer | string\n\n/** A DER encoded certificate as bytes, a base64 DER string, or a PEM string */\nexport type CertificateInput = DerInput\n\n/** A DER encoded CRL as bytes, a base64 DER string, or a PEM string (`X509 CRL`) */\nexport type CrlInput = DerInput\n\nexport const PEM_LABELS = {\n certificate: 'CERTIFICATE',\n crl: 'X509 CRL',\n} as const\n\n/**\n * Normalize a {@link DerInput} to DER bytes. PEM strings must use the given label; the\n * first matching block is used.\n */\nexport function toDer(input: DerInput, label: string = PEM_LABELS.certificate): Uint8Array {\n if (input instanceof Uint8Array) return input\n if (input instanceof ArrayBuffer) return new Uint8Array(input)\n if (typeof input !== 'string') {\n throw new X509Exception('Input must be DER bytes, a base64 DER string, or PEM')\n }\n let body = input\n if (input.includes('-----BEGIN')) {\n const pem = input.match(new RegExp(`-----BEGIN ${label}-----([\\\\s\\\\S]*?)-----END ${label}-----`))\n if (!pem) throw new X509Exception(`No PEM block with label \"${label}\" found`)\n body = pem[1]\n }\n body = body.replace(/\\s/g, '')\n if (!/^[A-Za-z0-9+/]+={0,2}$/.test(body)) {\n throw new X509Exception('Input is neither PEM nor base64 encoded DER')\n }\n return base64.decode(body)\n}\n\n/** Encode DER bytes as PEM. */\nexport function toPem(der: Uint8Array, label: string = PEM_LABELS.certificate): string {\n const lines = base64.encode(der).match(/.{1,64}/g) ?? []\n return `-----BEGIN ${label}-----\\n${lines.join('\\n')}\\n-----END ${label}-----\\n`\n}\n\n/** Copy bytes into a standalone ArrayBuffer (asn1-schema works on ArrayBuffers). */\nexport function toArrayBuffer(bytes: Uint8Array): ArrayBuffer {\n return bytes.slice().buffer as ArrayBuffer\n}\n","import { base64url, concatBytes, hexEncode, type JsonWebKey } from '@owf/identity-common'\nimport { AsnConvert } from '@peculiar/asn1-schema'\nimport { AlgorithmIdentifier, SubjectPublicKeyInfo } from '@peculiar/asn1-x509'\nimport * as asn1js from 'asn1js'\nimport { KEY_ALGORITHMS } from './constants'\nimport { toArrayBuffer } from './encoding'\nimport type { ParsedPublicKey } from './types'\nimport { X509Exception } from './x509-exception'\n\nconst CURVES = {\n 'P-256': { oid: KEY_ALGORITHMS['P-256'], size: 32 },\n 'P-384': { oid: KEY_ALGORITHMS['P-384'], size: 48 },\n 'P-521': { oid: KEY_ALGORITHMS['P-521'], size: 66 },\n} as const\n\ntype CurveName = keyof typeof CURVES\n\n/** Byte length of a coordinate (and of r and s in an ECDSA signature) for a named curve OID */\nexport function curveCoordinateLength(namedCurve: string | undefined): number | undefined {\n return Object.values(CURVES).find((c) => c.oid === namedCurve)?.size\n}\n\n/** Parse a single DER value, rejecting trailing or malformed data. */\nexport function parseDer(bytes: Uint8Array | ArrayBuffer): asn1js.AsnType {\n const buffer = bytes instanceof Uint8Array ? toArrayBuffer(bytes) : bytes\n const result = asn1js.fromBER(buffer)\n if (result.offset === -1 || result.offset !== buffer.byteLength) {\n throw new X509Exception('Invalid DER encoding')\n }\n return result.result\n}\n\n/** Decode an ASN.1 string type (or unwrap an explicit tag around one) to a JS string. */\nexport function asn1ToString(node: asn1js.AsnType): string | undefined {\n if (node instanceof asn1js.BaseStringBlock) return node.getValue()\n if (node instanceof asn1js.Constructed && node.valueBlock.value.length === 1) {\n return asn1ToString(node.valueBlock.value[0])\n }\n return undefined\n}\n\n/** Strip leading zeros from an unsigned big endian integer. */\nfunction stripLeadingZeros(bytes: Uint8Array): Uint8Array {\n let i = 0\n while (i < bytes.length - 1 && bytes[i] === 0) i++\n return bytes.subarray(i)\n}\n\n/**\n * Encode unsigned big endian bytes as the content of a DER INTEGER, adding a leading\n * zero when the high bit is set so the value stays positive.\n */\nexport function toPositiveIntegerBytes(bytes: Uint8Array): Uint8Array {\n const stripped = stripLeadingZeros(bytes)\n return stripped[0] & 0x80 ? concatBytes(new Uint8Array([0]), stripped) : stripped\n}\n\nfunction integer(bytes: Uint8Array): asn1js.Integer {\n return new asn1js.Integer({ valueHex: toArrayBuffer(toPositiveIntegerBytes(bytes)) })\n}\n\nfunction leftPad(bytes: Uint8Array, length: number): Uint8Array {\n const stripped = stripLeadingZeros(bytes)\n if (stripped.length > length) {\n throw new X509Exception('Integer does not fit the expected length')\n }\n const out = new Uint8Array(length)\n out.set(stripped, length - stripped.length)\n return out\n}\n\n/** Convert an IEEE P1363 (r || s) ECDSA signature to DER. */\nexport function ecdsaP1363ToDer(signature: Uint8Array, coordinateLength: number): Uint8Array {\n if (signature.length !== coordinateLength * 2) {\n throw new X509Exception(\n `Expected a ${coordinateLength * 2} byte IEEE P1363 ECDSA signature, got ${signature.length} bytes`\n )\n }\n const seq = new asn1js.Sequence({\n value: [integer(signature.subarray(0, coordinateLength)), integer(signature.subarray(coordinateLength))],\n })\n return new Uint8Array(seq.toBER())\n}\n\n/** Convert a DER ECDSA signature to IEEE P1363 (r || s). */\nexport function ecdsaDerToP1363(signature: Uint8Array, coordinateLength: number): Uint8Array {\n const seq = parseDer(signature)\n if (!(seq instanceof asn1js.Sequence) || seq.valueBlock.value.length !== 2) {\n throw new X509Exception('Invalid DER ECDSA signature')\n }\n const [r, s] = seq.valueBlock.value\n if (!(r instanceof asn1js.Integer) || !(s instanceof asn1js.Integer)) {\n throw new X509Exception('Invalid DER ECDSA signature')\n }\n return concatBytes(\n leftPad(new Uint8Array(r.valueBlock.valueHexView), coordinateLength),\n leftPad(new Uint8Array(s.valueBlock.valueHexView), coordinateLength)\n )\n}\n\n/**\n * Convert a public JWK to a DER SubjectPublicKeyInfo. Refuses private keys: only the\n * public part of the wallet-relying party key is needed to issue its certificate.\n */\nexport function publicJwkToSpki(jwk: JsonWebKey): Uint8Array {\n if (jwk.d !== undefined || jwk.p !== undefined || jwk.q !== undefined) {\n throw new X509Exception('The subject public key must not contain private key material')\n }\n if (jwk.kty === 'EC') {\n const curve = CURVES[jwk.crv as CurveName]\n if (!curve || !jwk.x || !jwk.y) {\n throw new X509Exception(`Unsupported EC public key (crv: ${jwk.crv})`)\n }\n const point = concatBytes(\n new Uint8Array([4]),\n leftPad(base64url.decode(jwk.x), curve.size),\n leftPad(base64url.decode(jwk.y), curve.size)\n )\n const spki = new SubjectPublicKeyInfo({\n algorithm: new AlgorithmIdentifier({\n algorithm: KEY_ALGORITHMS.ecPublicKey,\n parameters: new asn1js.ObjectIdentifier({ value: curve.oid }).toBER(),\n }),\n subjectPublicKey: toArrayBuffer(point),\n })\n return new Uint8Array(AsnConvert.serialize(spki))\n }\n if (jwk.kty === 'RSA') {\n if (!jwk.n || !jwk.e) throw new X509Exception('RSA public key requires n and e')\n const rsaPublicKey = new asn1js.Sequence({\n value: [integer(base64url.decode(jwk.n)), integer(base64url.decode(jwk.e))],\n })\n const spki = new SubjectPublicKeyInfo({\n algorithm: new AlgorithmIdentifier({ algorithm: KEY_ALGORITHMS.rsaEncryption, parameters: null }),\n subjectPublicKey: rsaPublicKey.toBER(),\n })\n return new Uint8Array(AsnConvert.serialize(spki))\n }\n throw new X509Exception(`Unsupported key type: ${jwk.kty}`)\n}\n\n/** Describe a SubjectPublicKeyInfo, including a JWK for EC and RSA keys. */\nexport function describePublicKey(spki: SubjectPublicKeyInfo): ParsedPublicKey {\n const der = new Uint8Array(AsnConvert.serialize(spki))\n const algorithm = spki.algorithm.algorithm\n const key = new Uint8Array(spki.subjectPublicKey)\n\n if (algorithm === KEY_ALGORITHMS.ecPublicKey && spki.algorithm.parameters) {\n const namedCurveNode = parseDer(spki.algorithm.parameters)\n const namedCurve =\n namedCurveNode instanceof asn1js.ObjectIdentifier ? namedCurveNode.valueBlock.toString() : undefined\n const entry = Object.entries(CURVES).find(([, c]) => c.oid === namedCurve)\n let jwk: JsonWebKey | undefined\n if (entry && key[0] === 4 && key.length === 1 + entry[1].size * 2) {\n const size = entry[1].size\n jwk = {\n kty: 'EC',\n crv: entry[0],\n x: base64url.encode(key.subarray(1, 1 + size)),\n y: base64url.encode(key.subarray(1 + size)),\n }\n }\n return { algorithm, namedCurve, spki: der, jwk }\n }\n\n if (algorithm === KEY_ALGORITHMS.rsaEncryption) {\n let jwk: JsonWebKey | undefined\n try {\n const seq = parseDer(key)\n if (seq instanceof asn1js.Sequence) {\n const [n, e] = seq.valueBlock.value\n if (n instanceof asn1js.Integer && e instanceof asn1js.Integer) {\n jwk = {\n kty: 'RSA',\n n: base64url.encode(stripLeadingZeros(new Uint8Array(n.valueBlock.valueHexView))),\n e: base64url.encode(stripLeadingZeros(new Uint8Array(e.valueBlock.valueHexView))),\n }\n }\n }\n } catch {\n // Leave jwk undefined for malformed RSA keys\n }\n return { algorithm, spki: der, jwk }\n }\n\n return { algorithm, spki: der }\n}\n\nexport function toHex(bytes: ArrayBuffer | Uint8Array): string {\n return hexEncode(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes))\n}\n\nfunction derLength(length: number): Uint8Array {\n if (length < 0x80) return new Uint8Array([length])\n const bytes: number[] = []\n for (let l = length; l > 0; l >>= 8) bytes.unshift(l & 0xff)\n return new Uint8Array([0x80 | bytes.length, ...bytes])\n}\n\n/** Encode a single DER TLV. */\nexport function derTlv(tag: number, content: Uint8Array): Uint8Array {\n return concatBytes(new Uint8Array([tag]), derLength(content.length), content)\n}\n\n/** Interpret big endian two's complement INTEGER content as a bigint (non-negative values only). */\nexport function integerBytesToBigInt(bytes: Uint8Array): bigint {\n return bytes.length === 0 ? BigInt(0) : BigInt(`0x${hexEncode(bytes)}`)\n}\n","import {\n AttributeTypeAndValue,\n AttributeValue,\n type Name,\n RelativeDistinguishedName,\n Name as X509Name,\n} from '@peculiar/asn1-x509'\nimport { ATTRIBUTE_TYPES, type AttributeName } from './constants'\nimport { toHex } from './der'\nimport type { DistinguishedName, DistinguishedNameAttribute } from './types'\nimport { X509Exception } from './x509-exception'\n\nconst NAME_BY_OID = new Map<string, AttributeName>(\n Object.entries(ATTRIBUTE_TYPES).map(([name, oid]) => [oid, name as AttributeName])\n)\n\n/** Short names for the RFC 4514 representation (RFC 4514 clause 3 plus common extensions) */\nconst RFC4514_SHORT_NAMES: Partial<Record<AttributeName, string>> = {\n commonName: 'CN',\n surname: 'SN',\n serialNumber: 'SERIALNUMBER',\n countryName: 'C',\n localityName: 'L',\n stateOrProvinceName: 'ST',\n streetAddress: 'STREET',\n organizationName: 'O',\n organizationalUnitName: 'OU',\n title: 'T',\n givenName: 'GN',\n organizationIdentifier: 'organizationIdentifier',\n emailAddress: 'E',\n}\n\nfunction attributeValueToString(value: AttributeValue): string {\n if (value.anyValue) return `#${toHex(value.anyValue)}`\n return value.toString()\n}\n\nfunction escapeRfc4514(value: string): string {\n return value\n .replace(/[\\\\\"+,;<>=]/g, (c) => `\\\\${c}`)\n .replace(/^[ #]/, (c) => `\\\\${c}`)\n .replace(/ $/, '\\\\ ')\n}\n\n/** Convert an ASN.1 Name into a {@link DistinguishedName}. */\nexport function parseName(name: Name): DistinguishedName {\n const attributes: DistinguishedNameAttribute[] = []\n const rdnStrings: string[] = []\n for (const rdn of name) {\n const parts: string[] = []\n for (const atv of rdn) {\n const attrName = NAME_BY_OID.get(atv.type)\n const value = attributeValueToString(atv.value)\n attributes.push({ type: atv.type, name: attrName, value })\n const key = (attrName && RFC4514_SHORT_NAMES[attrName]) ?? atv.type\n parts.push(`${key}=${atv.value.anyValue ? value : escapeRfc4514(value)}`)\n }\n rdnStrings.push(parts.join('+'))\n }\n\n const first = (n: AttributeName) => attributes.find((a) => a.name === n)?.value\n return {\n attributes,\n rfc4514: rdnStrings.reverse().join(','),\n commonName: first('commonName'),\n organizationName: first('organizationName'),\n organizationIdentifier: first('organizationIdentifier'),\n organizationalUnitNames: attributes.filter((a) => a.name === 'organizationalUnitName').map((a) => a.value),\n countryName: first('countryName'),\n localityName: first('localityName'),\n stateOrProvinceName: first('stateOrProvinceName'),\n serialNumber: first('serialNumber'),\n givenName: first('givenName'),\n surname: first('surname'),\n pseudonym: first('pseudonym'),\n }\n}\n\n/** Attributes that X.520 restricts to PrintableString */\nconst PRINTABLE_ATTRIBUTES = new Set<AttributeName>(['countryName', 'serialNumber'])\n\n/** One name attribute: a well-known attribute name or an attribute type OID, and its value */\nexport type NameAttributeInput = readonly [AttributeName | string, string | undefined]\n\n/**\n * Build an ASN.1 Name from attributes in encoding order (most general first), one attribute\n * per RDN. Empty values are skipped. `countryName` and `serialNumber` are encoded as\n * PrintableString, `emailAddress` as IA5String and everything else as UTF8String.\n */\nexport function buildName(attributes: readonly NameAttributeInput[]): Name {\n const rdns: RelativeDistinguishedName[] = []\n for (const [nameOrOid, value] of attributes) {\n if (value === undefined || value === '') continue\n const name = nameOrOid in ATTRIBUTE_TYPES ? (nameOrOid as AttributeName) : NAME_BY_OID.get(nameOrOid)\n if (!name && !/^\\d+(\\.\\d+)+$/.test(nameOrOid)) {\n throw new X509Exception(`Unknown name attribute: ${nameOrOid}`)\n }\n const type = name ? ATTRIBUTE_TYPES[name] : nameOrOid\n const attributeValue =\n name && PRINTABLE_ATTRIBUTES.has(name)\n ? new AttributeValue({ printableString: value })\n : name === 'emailAddress'\n ? new AttributeValue({ ia5String: value })\n : new AttributeValue({ utf8String: value })\n rdns.push(new RelativeDistinguishedName([new AttributeTypeAndValue({ type, value: attributeValue })]))\n }\n return new X509Name(rdns)\n}\n\nfunction normalize(value: string): string {\n return value.trim().replace(/\\s+/g, ' ').toLowerCase()\n}\n\n/**\n * Compare two distinguished names attribute by attribute, ignoring case and insignificant\n * whitespace in the values (a simplification of the RFC 5280 clause 7.1 matching rules).\n */\nexport function namesEqual(a: DistinguishedName, b: DistinguishedName): boolean {\n return (\n a.attributes.length === b.attributes.length &&\n a.attributes.every(\n (attr, i) => attr.type === b.attributes[i].type && normalize(attr.value) === normalize(b.attributes[i].value)\n )\n )\n}\n","import { AsnConvert } from '@peculiar/asn1-schema'\nimport type { Extension, GeneralName } from '@peculiar/asn1-x509'\nimport { ATTRIBUTE_TYPES } from './constants'\nimport { asn1ToString, parseDer } from './der'\nimport { toArrayBuffer } from './encoding'\nimport { parseName } from './name'\nimport type { SubjectAlternativeNames, X509Extension } from './types'\nimport { X509Exception } from './x509-exception'\n\n/** Convert ASN.1 extensions, rejecting duplicates (RFC 5280 clause 4.2). */\nexport function toExtensions(extensions: Extension[] | undefined): X509Extension[] {\n const result = (extensions ?? []).map((e) => ({\n oid: e.extnID,\n critical: e.critical,\n value: new Uint8Array(e.extnValue.buffer),\n }))\n const seen = new Set<string>()\n for (const { oid } of result) {\n if (seen.has(oid)) throw new X509Exception(`Duplicate extension ${oid}`)\n seen.add(oid)\n }\n return result\n}\n\n/** Decode an extension value with an asn1-schema type, if the extension is present. */\nexport function decodeExtension<T>(\n extensions: X509Extension[],\n oid: string,\n type: new () => T,\n name: string\n): T | undefined {\n const extension = extensions.find((e) => e.oid === oid)\n if (!extension) return undefined\n try {\n return AsnConvert.parse(toArrayBuffer(extension.value), type)\n } catch (error) {\n throw new X509Exception(`Invalid ${name} extension`, error)\n }\n}\n\nexport function uriOf(name: GeneralName | undefined): string | undefined {\n return name?.uniformResourceIdentifier\n}\n\nexport function urisOf(names: GeneralName[] | undefined): string[] {\n return (names ?? []).map(uriOf).filter((u): u is string => u !== undefined)\n}\n\nexport function emptySubjectAlternativeNames(): SubjectAlternativeNames {\n return { dnsNames: [], uris: [], emails: [], ipAddresses: [], directoryNames: [], otherNames: [] }\n}\n\nexport function toSubjectAlternativeNames(names: GeneralName[]): SubjectAlternativeNames {\n const result = emptySubjectAlternativeNames()\n for (const name of names) {\n if (name.uniformResourceIdentifier !== undefined) result.uris.push(name.uniformResourceIdentifier)\n else if (name.rfc822Name !== undefined) result.emails.push(name.rfc822Name)\n else if (name.dNSName !== undefined) result.dnsNames.push(name.dNSName)\n else if (name.iPAddress !== undefined) result.ipAddresses.push(name.iPAddress)\n else if (name.directoryName) result.directoryNames.push(parseName(name.directoryName))\n else if (name.otherName) {\n const value = new Uint8Array(name.otherName.value)\n let text: string | undefined\n try {\n text = asn1ToString(parseDer(value))\n } catch {\n // Not a string value\n }\n result.otherNames.push({ typeId: name.otherName.typeId, value, text })\n }\n }\n return result\n}\n\n/** Telephone numbers from otherName entries with type-id id-at-telephoneNumber */\nexport function telephoneNumbers(names: SubjectAlternativeNames): string[] {\n return names.otherNames\n .filter((o) => o.typeId === ATTRIBUTE_TYPES.telephoneNumber && o.text !== undefined)\n .map((o) => o.text as string)\n}\n","import { AsnConvert } from '@peculiar/asn1-schema'\nimport { QCStatement, QCStatements } from '@peculiar/asn1-x509-qualified'\nimport { PdsLocation, QcCClegislation, QcEuPDS, QcType } from '@peculiar/asn1-x509-qualified-etsi'\nimport { QC_STATEMENTS, QC_TYPES, type QcType as QcTypeName } from './constants'\nimport type { QcStatements } from './types'\nimport { X509Exception } from './x509-exception'\n\nconst QC_TYPE_BY_OID = new Map<string, QcTypeName>(\n Object.entries(QC_TYPES).map(([name, oid]) => [oid, name as QcTypeName])\n)\n\n/** Decode the statementInfo of a statement with its ETSI EN 319 412-5 schema. */\nfunction statementInfo<T>(statement: QCStatement, type: new () => T): T {\n if (!statement.statementInfo) {\n throw new X509Exception(`QCStatement ${statement.statementId} is missing its statementInfo`)\n }\n try {\n return AsnConvert.parse(statement.statementInfo, type)\n } catch (error) {\n throw new X509Exception(`Invalid statementInfo for QCStatement ${statement.statementId}`, error)\n }\n}\n\n/** Convert a decoded QCStatements extension (RFC 3739, ETSI EN 319 412-5). */\nexport function parseQcStatements(statements: QCStatements): QcStatements {\n const result: QcStatements = {\n statementIds: [],\n qcCompliance: false,\n qcSSCD: false,\n qcTypes: [],\n pds: [],\n legislationCountries: [],\n }\n\n for (const statement of statements) {\n result.statementIds.push(statement.statementId)\n\n switch (statement.statementId) {\n case QC_STATEMENTS.qcCompliance:\n result.qcCompliance = true\n break\n case QC_STATEMENTS.qcSSCD:\n result.qcSSCD = true\n break\n case QC_STATEMENTS.qcType:\n for (const oid of statementInfo(statement, QcType)) {\n result.qcTypes.push(QC_TYPE_BY_OID.get(oid) ?? oid)\n }\n break\n case QC_STATEMENTS.qcPDS:\n for (const { url, language } of statementInfo(statement, QcEuPDS)) {\n result.pds.push({ url, language })\n }\n break\n case QC_STATEMENTS.qcCClegislation:\n result.legislationCountries.push(...statementInfo(statement, QcCClegislation))\n break\n }\n }\n return result\n}\n\nexport interface QcStatementsInput {\n qcTypes: QcTypeName[]\n qcSSCD?: boolean\n pds?: { url: string; language: string }[]\n legislationCountries?: string[]\n}\n\nfunction statement(statementId: string, info?: unknown): QCStatement {\n return Object.assign(new QCStatement(), {\n statementId,\n statementInfo: info === undefined ? undefined : AsnConvert.serialize(info),\n })\n}\n\n/** Build a QCStatements extension value with QcCompliance and the given statements. */\nexport function toQcStatements(input: QcStatementsInput): QCStatements {\n const statements = new QCStatements([statement(QC_STATEMENTS.qcCompliance)])\n\n if (input.qcSSCD) {\n statements.push(statement(QC_STATEMENTS.qcSSCD))\n }\n if (input.qcTypes.length > 0) {\n statements.push(statement(QC_STATEMENTS.qcType, new QcType(input.qcTypes.map((t) => QC_TYPES[t]))))\n }\n if (input.pds?.length) {\n statements.push(statement(QC_STATEMENTS.qcPDS, new QcEuPDS(input.pds.map((p) => new PdsLocation(p)))))\n }\n if (input.legislationCountries?.length) {\n statements.push(statement(QC_STATEMENTS.qcCClegislation, new QcCClegislation(input.legislationCountries)))\n }\n return statements\n}\n","import { AsnConvert, type IAsnParseOptions } from '@peculiar/asn1-schema'\nimport {\n AuthorityInfoAccessSyntax,\n AuthorityKeyIdentifier,\n BasicConstraints,\n CertificatePolicies,\n CRLDistributionPoints,\n ExtendedKeyUsage,\n id_ce_authorityKeyIdentifier,\n id_ce_basicConstraints,\n id_ce_certificatePolicies,\n id_ce_cRLDistributionPoints,\n id_ce_extKeyUsage,\n id_ce_keyUsage,\n id_ce_subjectAltName,\n id_ce_subjectKeyIdentifier,\n id_pe_authorityInfoAccess,\n KeyUsage,\n SubjectAlternativeName,\n SubjectKeyIdentifier,\n UserNotice,\n Certificate as X509Certificate,\n} from '@peculiar/asn1-x509'\nimport { QCStatements } from '@peculiar/asn1-x509-qualified'\nimport {\n ACCESS_METHODS,\n POLICY_QUALIFIERS,\n QC_STATEMENTS,\n SIGNATURE_ALGORITHMS,\n type SignatureAlgorithm,\n} from './constants'\nimport { asn1ToString, describePublicKey, parseDer, toHex } from './der'\nimport { type CertificateInput, PEM_LABELS, toArrayBuffer, toDer, toPem } from './encoding'\nimport {\n decodeExtension,\n emptySubjectAlternativeNames,\n toExtensions,\n toSubjectAlternativeNames,\n uriOf,\n urisOf,\n} from './extensions'\nimport { parseName } from './name'\nimport { parseQcStatements } from './qc-statements'\nimport type { Certificate, CertificatePolicyInformation } from './types'\nimport { X509Exception } from './x509-exception'\n\nconst SIGNATURE_ALGORITHM_BY_OID = new Map<string, SignatureAlgorithm>(\n Object.entries(SIGNATURE_ALGORITHMS).map(([name, { oid }]) => [oid, name as SignatureAlgorithm])\n)\n\nexport function signatureAlgorithmName(oid: string): SignatureAlgorithm | undefined {\n return SIGNATURE_ALGORITHM_BY_OID.get(oid)\n}\n\nfunction toPolicies(policies: CertificatePolicies | undefined): CertificatePolicyInformation[] {\n return (policies ?? []).map((policy) => {\n const cpsUris: string[] = []\n const userNotices: string[] = []\n for (const qualifier of policy.policyQualifiers ?? []) {\n if (qualifier.policyQualifierId === POLICY_QUALIFIERS.cps) {\n const uri = asn1ToString(parseDer(qualifier.qualifier))\n if (uri) cpsUris.push(uri)\n } else if (qualifier.policyQualifierId === POLICY_QUALIFIERS.unotice) {\n const notice = AsnConvert.parse(qualifier.qualifier, UserNotice)\n if (notice.explicitText) userNotices.push(notice.explicitText.toString())\n }\n }\n return { oid: policy.policyIdentifier, cpsUris, userNotices }\n })\n}\n\n/**\n * Parse an X.509 certificate.\n *\n * Decodes the standard extensions of RFC 5280 plus QCStatements. Parsing does not verify the\n * signature; use {@link verifyCertificateSignature} for that.\n *\n * @param input DER bytes, base64 encoded DER, or PEM\n * @param options Resource limits forwarded to asn1js (`berOptions`)\n * @throws X509Exception when the input is not a well-formed X.509 certificate\n */\nexport function parseCertificate(input: CertificateInput, options?: IAsnParseOptions): Certificate {\n const der = toDer(input, PEM_LABELS.certificate)\n\n let certificate: X509Certificate\n try {\n certificate = AsnConvert.parse(toArrayBuffer(der), X509Certificate, options)\n } catch (error) {\n throw new X509Exception('Invalid X.509 certificate', error)\n }\n if (!certificate.tbsCertificateRaw) {\n throw new X509Exception('Unable to extract the TBSCertificate')\n }\n\n const tbs = certificate.tbsCertificate\n const extensions = toExtensions(tbs.extensions)\n const decode = <T>(oid: string, type: new () => T, name: string) => decodeExtension(extensions, oid, type, name)\n\n const san = decode(id_ce_subjectAltName, SubjectAlternativeName, 'subjectAltName')\n const keyUsage = decode(id_ce_keyUsage, KeyUsage, 'keyUsage')\n const eku = decode(id_ce_extKeyUsage, ExtendedKeyUsage, 'extKeyUsage')\n const basicConstraints = decode(id_ce_basicConstraints, BasicConstraints, 'basicConstraints')\n const ski = decode(id_ce_subjectKeyIdentifier, SubjectKeyIdentifier, 'subjectKeyIdentifier')\n const aki = decode(id_ce_authorityKeyIdentifier, AuthorityKeyIdentifier, 'authorityKeyIdentifier')\n const crlDps = decode(id_ce_cRLDistributionPoints, CRLDistributionPoints, 'cRLDistributionPoints')\n const aia = decode(id_pe_authorityInfoAccess, AuthorityInfoAccessSyntax, 'authorityInfoAccess') ?? []\n const qcStatements = decode(QC_STATEMENTS.extension, QCStatements, 'qcStatements')\n const accessUrls = (method: string) =>\n aia\n .filter((a) => a.accessMethod === method)\n .map((a) => uriOf(a.accessLocation))\n .filter((u): u is string => u !== undefined)\n\n return {\n der,\n pem: toPem(der, PEM_LABELS.certificate),\n version: tbs.version + 1,\n serialNumber: toHex(tbs.serialNumber),\n issuer: parseName(tbs.issuer),\n subject: parseName(tbs.subject),\n notBefore: tbs.validity.notBefore.getTime(),\n notAfter: tbs.validity.notAfter.getTime(),\n publicKey: describePublicKey(tbs.subjectPublicKeyInfo),\n signatureAlgorithm: certificate.signatureAlgorithm.algorithm,\n signatureAlgorithmName: signatureAlgorithmName(certificate.signatureAlgorithm.algorithm),\n tbsCertificate: new Uint8Array(certificate.tbsCertificateRaw),\n signature: new Uint8Array(certificate.signatureValue),\n\n policies: toPolicies(decode(id_ce_certificatePolicies, CertificatePolicies, 'certificatePolicies')),\n subjectAlternativeNames: san ? toSubjectAlternativeNames(san) : emptySubjectAlternativeNames(),\n keyUsage: keyUsage?.toJSON(),\n extendedKeyUsage: eku ? [...eku] : undefined,\n basicConstraints: basicConstraints\n ? { cA: basicConstraints.cA, pathLenConstraint: basicConstraints.pathLenConstraint }\n : undefined,\n subjectKeyIdentifier: ski ? toHex(ski.buffer) : undefined,\n authorityKeyIdentifier: aki?.keyIdentifier ? toHex(aki.keyIdentifier.buffer) : undefined,\n crlDistributionPoints: (crlDps ?? []).flatMap((dp) => urisOf(dp.distributionPoint?.fullName)),\n ocspUrls: accessUrls(ACCESS_METHODS.ocsp),\n caIssuersUrls: accessUrls(ACCESS_METHODS.caIssuers),\n qcStatements: qcStatements ? parseQcStatements(qcStatements) : undefined,\n\n extensions,\n }\n}\n","import { concatBytes, hexDecode } from '@owf/identity-common'\nimport { AsnConvert } from '@peculiar/asn1-schema'\nimport { AlgorithmIdentifier } from '@peculiar/asn1-x509'\nimport * as asn1js from 'asn1js'\nimport { parseCertificate } from './certificate'\nimport { SIGNATURE_ALGORITHMS, type SignatureAlgorithm } from './constants'\nimport { curveCoordinateLength, derTlv, ecdsaDerToP1363, ecdsaP1363ToDer, toPositiveIntegerBytes } from './der'\nimport { type CertificateInput, toArrayBuffer } from './encoding'\nimport { namesEqual } from './name'\nimport type {\n Certificate,\n Crl,\n ParsedPublicKey,\n PreparedSignedStructure,\n SignatureEncoding,\n SignatureVerifier,\n} from './types'\nimport { X509Exception } from './x509-exception'\n\n/** AlgorithmIdentifier for a supported signature algorithm (RFC 3279, RFC 5758). */\nexport function signatureAlgorithmIdentifier(name: SignatureAlgorithm): AlgorithmIdentifier {\n const algorithm = SIGNATURE_ALGORITHMS[name]\n if (!algorithm) throw new X509Exception(`Unsupported signature algorithm: ${name}`)\n return new AlgorithmIdentifier({\n algorithm: algorithm.oid,\n // RSA PKCS#1 v1.5 algorithms carry NULL parameters, ECDSA ones none\n parameters: algorithm.family === 'rsa' ? new asn1js.Null().toBER() : undefined,\n })\n}\n\n/** Normalize a serial number to positive DER INTEGER content (RFC 5280 clause 4.1.2.2). */\nexport function toSerialNumber(serialNumber: Uint8Array | string): ArrayBuffer {\n const bytes = typeof serialNumber === 'string' ? hexDecode(serialNumber.replace(/^0x/i, '')) : serialNumber\n const positive = toPositiveIntegerBytes(bytes)\n if (positive.length === 0 || positive.every((b) => b === 0)) {\n throw new X509Exception('Serial number must be a positive integer')\n }\n if (positive.length > 20) {\n throw new X509Exception('Serial number must not be longer than 20 octets (RFC 5280 clause 4.1.2.2)')\n }\n return toArrayBuffer(positive)\n}\n\n/**\n * Combine prepared to-be-signed bytes with their signature into the DER encoding of the\n * signed structure: `SEQUENCE { tbs, signatureAlgorithm, BIT STRING signature }`.\n */\nexport function assembleSignedStructure(\n prepared: PreparedSignedStructure,\n signature: Uint8Array,\n signatureEncoding: SignatureEncoding = 'ieee-p1363'\n): Uint8Array {\n const algorithm = SIGNATURE_ALGORITHMS[prepared.signatureAlgorithm]\n let signatureDer = signature\n if (algorithm.family === 'ecdsa' && signatureEncoding === 'ieee-p1363') {\n const coordinateLength = curveCoordinateLength(prepared.signerPublicKey.namedCurve)\n if (!coordinateLength) {\n throw new X509Exception('Unable to determine the curve of the signer key for ECDSA encoding')\n }\n signatureDer = ecdsaP1363ToDer(signature, coordinateLength)\n }\n const algorithmIdentifier = new Uint8Array(\n AsnConvert.serialize(signatureAlgorithmIdentifier(prepared.signatureAlgorithm))\n )\n return derTlv(\n 0x30,\n concatBytes(prepared.tbs, algorithmIdentifier, derTlv(0x03, concatBytes(new Uint8Array([0]), signatureDer)))\n )\n}\n\nasync function verifySignature(\n signed: { signature: Uint8Array; signatureAlgorithm: string; signatureAlgorithmName?: SignatureAlgorithm },\n data: Uint8Array,\n publicKey: ParsedPublicKey,\n verifier: SignatureVerifier\n): Promise<boolean> {\n let signatureP1363 = signed.signature\n if (signed.signatureAlgorithmName && SIGNATURE_ALGORITHMS[signed.signatureAlgorithmName].family === 'ecdsa') {\n const coordinateLength = curveCoordinateLength(publicKey.namedCurve)\n if (!coordinateLength) return false\n try {\n signatureP1363 = ecdsaDerToP1363(signed.signature, coordinateLength)\n } catch {\n return false\n }\n }\n return verifier({\n data,\n signature: signed.signature,\n signatureP1363,\n signatureAlgorithm: signed.signatureAlgorithm,\n signatureAlgorithmName: signed.signatureAlgorithmName,\n publicKey,\n })\n}\n\nfunction toCertificate(input: Certificate | CertificateInput): Certificate {\n return typeof input === 'object' && 'tbsCertificate' in input ? input : parseCertificate(input)\n}\n\n/**\n * Verify that `certificate` was signed by the key of `issuerCertificate`.\n *\n * The issuer name and, when both are present, the authority / subject key identifiers must\n * match. The cryptographic check is delegated to `verifier`, so no global crypto is needed:\n * with WebCrypto, import `publicKey.jwk` and verify `signatureP1363` over `data`.\n *\n * This checks a single link, not a path to a trust anchor.\n */\nexport async function verifyCertificateSignature(\n certificate: Certificate | CertificateInput,\n issuerCertificate: Certificate | CertificateInput,\n verifier: SignatureVerifier\n): Promise<boolean> {\n const cert = toCertificate(certificate)\n const issuer = toCertificate(issuerCertificate)\n if (!namesEqual(cert.issuer, issuer.subject)) return false\n if (\n cert.authorityKeyIdentifier &&\n issuer.subjectKeyIdentifier &&\n cert.authorityKeyIdentifier !== issuer.subjectKeyIdentifier\n ) {\n return false\n }\n return verifySignature(cert, cert.tbsCertificate, issuer.publicKey, verifier)\n}\n\n/**\n * Verify that `crl` was signed by `issuerCertificate`.\n *\n * The CRL issuer name and, when both are present, the key identifiers must match, and the\n * issuer key usage (if present) must allow cRLSign (RFC 5280 clause 6.3.3).\n */\nexport async function verifyCrlSignature(\n crl: Crl,\n issuerCertificate: Certificate | CertificateInput,\n verifier: SignatureVerifier\n): Promise<boolean> {\n const issuer = toCertificate(issuerCertificate)\n if (!namesEqual(crl.issuer, issuer.subject)) return false\n if (\n crl.authorityKeyIdentifier &&\n issuer.subjectKeyIdentifier &&\n crl.authorityKeyIdentifier !== issuer.subjectKeyIdentifier\n ) {\n return false\n }\n if (issuer.keyUsage && !issuer.keyUsage.includes('crlSign')) return false\n return verifySignature(crl, crl.tbsCertList, issuer.publicKey, verifier)\n}\n","import { AsnConvert, OctetString } from '@peculiar/asn1-schema'\nimport {\n AccessDescription,\n AuthorityInfoAccessSyntax,\n AuthorityKeyIdentifier,\n BasicConstraints,\n CertificatePolicies,\n CRLDistributionPoints,\n DistributionPoint,\n DistributionPointName,\n ExtendedKeyUsage,\n Extension,\n Extensions,\n GeneralName,\n id_ce_authorityKeyIdentifier,\n id_ce_basicConstraints,\n id_ce_certificatePolicies,\n id_ce_cRLDistributionPoints,\n id_ce_extKeyUsage,\n id_ce_keyUsage,\n id_ce_subjectAltName,\n id_ce_subjectKeyIdentifier,\n id_pe_authorityInfoAccess,\n KeyIdentifier,\n KeyUsage,\n KeyUsageFlags,\n type KeyUsageType,\n OtherName,\n PolicyInformation,\n PolicyQualifierInfo,\n SubjectAlternativeName,\n SubjectKeyIdentifier,\n SubjectPublicKeyInfo,\n TBSCertificate,\n Validity,\n Version,\n Certificate as X509Certificate,\n} from '@peculiar/asn1-x509'\nimport * as asn1js from 'asn1js'\nimport { parseCertificate } from './certificate'\nimport { ACCESS_METHODS, POLICY_QUALIFIERS, QC_STATEMENTS } from './constants'\nimport { describePublicKey, publicJwkToSpki } from './der'\nimport { type CertificateInput, PEM_LABELS, toArrayBuffer, toDer } from './encoding'\nimport { buildName } from './name'\nimport { toQcStatements } from './qc-statements'\nimport { assembleSignedStructure, signatureAlgorithmIdentifier, toSerialNumber } from './signature'\nimport type {\n Certificate,\n CertificateTemplate,\n PreparedSignedStructure,\n SignatureEncoding,\n SignOptions,\n X509Extension,\n} from './types'\nimport { X509Exception } from './x509-exception'\n\nfunction extension(extnID: string, value: unknown, critical = false): Extension {\n return new Extension({ extnID, critical, extnValue: new OctetString(AsnConvert.serialize(value)) })\n}\n\nexport function keyUsageFlags(usages: KeyUsageType[]): number {\n return usages.reduce((flags, usage) => flags | KeyUsageFlags[usage === 'crlSign' ? 'cRLSign' : usage], 0)\n}\n\n/** Parse an issuer certificate into its ASN.1 form. */\nexport function parseIssuerCertificate(input: CertificateInput): X509Certificate {\n try {\n return AsnConvert.parse(toArrayBuffer(toDer(input, PEM_LABELS.certificate)), X509Certificate)\n } catch (error) {\n throw new X509Exception('Invalid issuer certificate', error)\n }\n}\n\n/** The subject key identifier of an ASN.1 certificate, if present. */\nexport function subjectKeyIdentifierOf(certificate: X509Certificate): ArrayBuffer | undefined {\n const ski = certificate.tbsCertificate.extensions?.find((e) => e.extnID === id_ce_subjectKeyIdentifier)\n return ski ? AsnConvert.parse(ski.extnValue.buffer, SubjectKeyIdentifier).buffer : undefined\n}\n\n/**\n * Encode an otherName whose value is a PrintableString (or UTF8String for non-printable\n * values), e.g. an `id-at-telephoneNumber` subject alternative name.\n */\nexport function stringOtherName(typeId: string, value: string): { typeId: string; value: Uint8Array } {\n const printable = /^[A-Za-z0-9 '()+,\\-./:=?]*$/.test(value)\n const encoded = printable ? new asn1js.PrintableString({ value }) : new asn1js.Utf8String({ value })\n return { typeId, value: new Uint8Array(encoded.toBER()) }\n}\n\n/**\n * Build the TBSCertificate for a certificate template.\n *\n * Sign the returned `tbs` bytes with the issuer key wherever that key lives and pass the\n * signature to {@link assembleCertificate}. {@link createCertificate} wraps both steps\n * around a signer callback.\n */\nexport async function prepareCertificate(template: CertificateTemplate): Promise<PreparedSignedStructure> {\n if (!(template.notAfter > template.notBefore)) {\n throw new X509Exception('notAfter must be later than notBefore')\n }\n\n const spkiDer =\n template.subjectPublicKey instanceof Uint8Array\n ? template.subjectPublicKey\n : publicJwkToSpki(template.subjectPublicKey)\n let subjectPublicKeyInfo: SubjectPublicKeyInfo\n try {\n subjectPublicKeyInfo = AsnConvert.parse(toArrayBuffer(spkiDer), SubjectPublicKeyInfo)\n } catch (error) {\n throw new X509Exception('Invalid subject public key', error)\n }\n\n const issuer = template.issuerCertificate ? parseIssuerCertificate(template.issuerCertificate) : undefined\n const subject = buildName(template.subject)\n if (subject.length === 0) throw new X509Exception('The subject must not be empty')\n\n const extensions: Extension[] = []\n const basicConstraints = template.basicConstraints ?? { cA: false }\n extensions.push(extension(id_ce_basicConstraints, new BasicConstraints(basicConstraints), true))\n\n const keyUsage = template.keyUsage ?? (basicConstraints.cA ? ['keyCertSign', 'crlSign'] : ['digitalSignature'])\n if (keyUsage.length > 0) {\n extensions.push(extension(id_ce_keyUsage, new KeyUsage(keyUsageFlags(keyUsage)), true))\n }\n\n if (template.extendedKeyUsage?.length) {\n extensions.push(extension(id_ce_extKeyUsage, new ExtendedKeyUsage(template.extendedKeyUsage)))\n }\n\n if (template.certificatePolicies?.length) {\n extensions.push(\n extension(\n id_ce_certificatePolicies,\n new CertificatePolicies(\n template.certificatePolicies.map(\n (policy) =>\n new PolicyInformation({\n policyIdentifier: policy.oid,\n policyQualifiers: policy.cpsUris?.length\n ? policy.cpsUris.map(\n (uri) =>\n new PolicyQualifierInfo({\n policyQualifierId: POLICY_QUALIFIERS.cps,\n qualifier: new asn1js.IA5String({ value: uri }).toBER(),\n })\n )\n : undefined,\n })\n )\n )\n )\n )\n }\n\n const san = template.subjectAlternativeNames\n const generalNames = [\n ...(san?.dnsNames ?? []).map((dNSName) => new GeneralName({ dNSName })),\n ...(san?.uris ?? []).map((uniformResourceIdentifier) => new GeneralName({ uniformResourceIdentifier })),\n ...(san?.emails ?? []).map((rfc822Name) => new GeneralName({ rfc822Name })),\n ...(san?.otherNames ?? []).map(\n (o) => new GeneralName({ otherName: new OtherName({ typeId: o.typeId, value: toArrayBuffer(o.value) }) })\n ),\n ]\n if (generalNames.length > 0) {\n extensions.push(extension(id_ce_subjectAltName, new SubjectAlternativeName(generalNames)))\n }\n\n let subjectKeyIdentifier: ArrayBuffer | undefined\n if (template.hasher) {\n // RFC 7093 method 1: leftmost 160 bits of the SHA-256 hash of the subjectPublicKey\n const hash = await template.hasher(subjectPublicKeyInfo.subjectPublicKey, 'sha-256')\n subjectKeyIdentifier = toArrayBuffer(hash.slice(0, 20))\n extensions.push(extension(id_ce_subjectKeyIdentifier, new SubjectKeyIdentifier(subjectKeyIdentifier)))\n }\n\n const authorityKeyIdentifier = issuer ? subjectKeyIdentifierOf(issuer) : subjectKeyIdentifier\n if (authorityKeyIdentifier) {\n extensions.push(\n extension(\n id_ce_authorityKeyIdentifier,\n new AuthorityKeyIdentifier({ keyIdentifier: new KeyIdentifier(authorityKeyIdentifier) })\n )\n )\n }\n\n if (template.crlDistributionPoints?.length) {\n extensions.push(\n extension(\n id_ce_cRLDistributionPoints,\n new CRLDistributionPoints(\n template.crlDistributionPoints.map(\n (uri) =>\n new DistributionPoint({\n distributionPoint: new DistributionPointName({\n fullName: [new GeneralName({ uniformResourceIdentifier: uri })],\n }),\n })\n )\n )\n )\n )\n }\n\n const accessDescriptions = [\n ...(template.ocspUrls ?? []).map((uri) => [ACCESS_METHODS.ocsp, uri] as const),\n ...(template.caIssuersUrls ?? []).map((uri) => [ACCESS_METHODS.caIssuers, uri] as const),\n ].map(\n ([accessMethod, uri]) =>\n new AccessDescription({ accessMethod, accessLocation: new GeneralName({ uniformResourceIdentifier: uri }) })\n )\n if (accessDescriptions.length > 0) {\n extensions.push(extension(id_pe_authorityInfoAccess, new AuthorityInfoAccessSyntax(accessDescriptions)))\n }\n\n if (template.qcStatements) {\n const qcStatements = toQcStatements({ ...template.qcStatements, qcTypes: template.qcStatements.qcTypes ?? [] })\n extensions.push(extension(QC_STATEMENTS.extension, qcStatements))\n }\n\n for (const custom of template.extensions ?? []) {\n extensions.push(toAsnExtension(custom))\n }\n const seen = new Set<string>()\n for (const { extnID } of extensions) {\n if (seen.has(extnID)) throw new X509Exception(`Duplicate extension ${extnID}`)\n seen.add(extnID)\n }\n\n const tbs = new TBSCertificate({\n version: Version.v3,\n serialNumber: toSerialNumber(template.serialNumber),\n signature: signatureAlgorithmIdentifier(template.signatureAlgorithm),\n issuer: issuer ? issuer.tbsCertificate.subject : subject,\n validity: new Validity({ notBefore: template.notBefore, notAfter: template.notAfter }),\n subject,\n subjectPublicKeyInfo,\n extensions: new Extensions(extensions),\n })\n\n return {\n tbs: new Uint8Array(AsnConvert.serialize(tbs)),\n signatureAlgorithm: template.signatureAlgorithm,\n signerPublicKey: describePublicKey(issuer ? issuer.tbsCertificate.subjectPublicKeyInfo : subjectPublicKeyInfo),\n }\n}\n\nexport function toAsnExtension(extension: X509Extension): Extension {\n return new Extension({\n extnID: extension.oid,\n critical: extension.critical,\n extnValue: new OctetString(toArrayBuffer(extension.value)),\n })\n}\n\n/**\n * Combine a prepared TBSCertificate with the issuer signature.\n *\n * @param signatureEncoding Encoding of ECDSA signatures; WebCrypto produces `ieee-p1363` (default)\n */\nexport function assembleCertificate(\n prepared: PreparedSignedStructure,\n signature: Uint8Array,\n signatureEncoding?: SignatureEncoding\n): Certificate {\n return parseCertificate(assembleSignedStructure(prepared, signature, signatureEncoding))\n}\n\n/**\n * Create an X.509 v3 certificate.\n *\n * The issuer key is never passed in: the `signer` callback receives the DER encoded\n * TBSCertificate and returns the signature, so the key can stay in WebCrypto, a KMS or an\n * HSM. Only the public key of the subject is needed; a JWK with private key material is\n * rejected.\n */\nexport async function createCertificate(template: CertificateTemplate & SignOptions): Promise<Certificate> {\n const prepared = await prepareCertificate(template)\n const signature = await template.signer(prepared.tbs)\n return assembleCertificate(prepared, signature, template.signatureEncoding)\n}\n","import { hexDecode } from '@owf/identity-common'\nimport { AsnConvert, type IAsnParseOptions, OctetString } from '@peculiar/asn1-schema'\nimport {\n RevokedCertificate as AsnRevokedCertificate,\n AuthorityKeyIdentifier,\n CertificateIssuer,\n CertificateList,\n CRLReason,\n DistributionPointName,\n Extension,\n FreshestCRL,\n GeneralName,\n InvalidityDate,\n IssuingDistributionPoint,\n id_ce_authorityKeyIdentifier,\n id_ce_certificateIssuer,\n id_ce_cRLNumber,\n id_ce_cRLReasons,\n id_ce_deltaCRLIndicator,\n id_ce_freshestCRL,\n id_ce_invalidityDate,\n id_ce_issuerAltName,\n id_ce_issuingDistributionPoint,\n id_pe_authorityInfoAccess,\n KeyIdentifier,\n TBSCertList,\n Time,\n Version,\n} from '@peculiar/asn1-x509'\nimport * as asn1js from 'asn1js'\nimport { signatureAlgorithmName } from './certificate'\nimport { CRL_REASONS, type CrlReason } from './constants'\nimport { parseIssuerCertificate, subjectKeyIdentifierOf, toAsnExtension } from './create'\nimport { describePublicKey, integerBytesToBigInt, parseDer, toHex, toPositiveIntegerBytes } from './der'\nimport { type CertificateInput, type CrlInput, PEM_LABELS, toArrayBuffer, toDer, toPem } from './encoding'\nimport { decodeExtension, toExtensions, urisOf } from './extensions'\nimport { namesEqual, parseName } from './name'\nimport { assembleSignedStructure, signatureAlgorithmIdentifier, toSerialNumber, verifyCrlSignature } from './signature'\nimport type {\n Certificate,\n Crl,\n CrlTemplate,\n DistinguishedName,\n PreparedSignedStructure,\n RevocationCheckOptions,\n RevocationStatus,\n RevokedCertificate,\n SignatureEncoding,\n SignatureVerifier,\n SignOptions,\n X509Extension,\n} from './types'\nimport { X509Exception } from './x509-exception'\n\nconst REASON_BY_CODE = new Map<number, CrlReason>(\n Object.entries(CRL_REASONS).map(([name, code]) => [code, name as CrlReason])\n)\n\n/** CRL extensions understood by {@link getRevocationStatus} */\nconst KNOWN_CRL_EXTENSIONS = new Set([\n id_ce_authorityKeyIdentifier,\n id_ce_issuerAltName,\n id_ce_cRLNumber,\n id_ce_deltaCRLIndicator,\n id_ce_issuingDistributionPoint,\n id_ce_freshestCRL,\n id_pe_authorityInfoAccess,\n])\n\n/** CRL entry extensions understood by {@link getRevocationStatus} */\nconst KNOWN_ENTRY_EXTENSIONS = new Set([\n id_ce_cRLReasons,\n id_ce_invalidityDate,\n id_ce_certificateIssuer,\n '2.5.29.23', // holdInstructionCode\n])\n\nfunction decodeInteger(extensions: X509Extension[], oid: string, name: string): bigint | undefined {\n const extension = extensions.find((e) => e.oid === oid)\n if (!extension) return undefined\n const node = parseDer(extension.value)\n const bytes = node instanceof asn1js.Integer ? new Uint8Array(node.valueBlock.valueHexView) : undefined\n if (!bytes || bytes.length === 0 || bytes[0] & 0x80) {\n throw new X509Exception(`Invalid ${name} extension`)\n }\n return integerBytesToBigInt(bytes)\n}\n\nfunction directoryNameOf(names: GeneralName[]): DistinguishedName | undefined {\n const name = names.find((n) => n.directoryName)?.directoryName\n return name ? parseName(name) : undefined\n}\n\nfunction toRevokedCertificates(entries: AsnRevokedCertificate[] | undefined): RevokedCertificate[] {\n let certificateIssuer: DistinguishedName | undefined\n return (entries ?? []).map((entry) => {\n const extensions = toExtensions(entry.crlEntryExtensions)\n const decode = <T>(oid: string, type: new () => T, name: string) => decodeExtension(extensions, oid, type, name)\n const reason = decode(id_ce_cRLReasons, CRLReason, 'reasonCode')\n const invalidity = decode(id_ce_invalidityDate, InvalidityDate, 'invalidityDate')\n const issuer = decode(id_ce_certificateIssuer, CertificateIssuer, 'certificateIssuer')\n // RFC 5280 clause 5.3.3: the certificate issuer applies to this and all following entries\n if (issuer) certificateIssuer = directoryNameOf(issuer)\n return {\n serialNumber: toHex(entry.userCertificate),\n revocationDate: entry.revocationDate.getTime(),\n reason: reason ? REASON_BY_CODE.get(reason.reason) : undefined,\n invalidityDate: invalidity?.value,\n certificateIssuer,\n extensions,\n }\n })\n}\n\nexport interface ParseCrlOptions extends IAsnParseOptions {\n /**\n * Upper bound for the number of revoked certificate entries, protecting against resource\n * exhaustion by untrusted input. Defaults to 100 000. Ignored when `berOptions.maxNodes`\n * is set explicitly.\n */\n maxEntries?: number\n}\n\n/** ASN.1 nodes per CRL entry: SEQUENCE, INTEGER, Time and up to three extensions of four nodes */\nconst NODES_PER_ENTRY = 16\n\n/**\n * Parse an X.509 certificate revocation list (RFC 5280 clause 5).\n *\n * Parsing does not verify the signature; use {@link verifyCrlSignature} or {@link checkRevocation}.\n *\n * @param input DER bytes, base64 encoded DER, or PEM (`X509 CRL`)\n * @throws X509Exception when the input is not a well-formed CRL or exceeds the size limits\n */\nexport function parseCrl(input: CrlInput, options: ParseCrlOptions = {}): Crl {\n const der = toDer(input, PEM_LABELS.crl)\n const { maxEntries = 100_000, berOptions } = options\n let crl: CertificateList\n try {\n crl = AsnConvert.parse(toArrayBuffer(der), CertificateList, {\n berOptions: { maxNodes: 1_000 + maxEntries * NODES_PER_ENTRY, ...berOptions },\n })\n } catch (error) {\n throw new X509Exception('Invalid CRL', error)\n }\n if (!crl.tbsCertListRaw) throw new X509Exception('Unable to extract the TBSCertList')\n\n const tbs = crl.tbsCertList\n const extensions = toExtensions(tbs.crlExtensions)\n const decode = <T>(oid: string, type: new () => T, name: string) => decodeExtension(extensions, oid, type, name)\n const aki = decode(id_ce_authorityKeyIdentifier, AuthorityKeyIdentifier, 'authorityKeyIdentifier')\n const idp = decode(id_ce_issuingDistributionPoint, IssuingDistributionPoint, 'issuingDistributionPoint')\n const freshest = decode(id_ce_freshestCRL, FreshestCRL, 'freshestCRL')\n\n return {\n der,\n pem: toPem(der, PEM_LABELS.crl),\n version: tbs.version === undefined ? 1 : tbs.version + 1,\n issuer: parseName(tbs.issuer),\n thisUpdate: tbs.thisUpdate.getTime(),\n nextUpdate: tbs.nextUpdate?.getTime(),\n signatureAlgorithm: crl.signatureAlgorithm.algorithm,\n signatureAlgorithmName: signatureAlgorithmName(crl.signatureAlgorithm.algorithm),\n signature: new Uint8Array(crl.signature),\n tbsCertList: new Uint8Array(crl.tbsCertListRaw),\n crlNumber: decodeInteger(extensions, id_ce_cRLNumber, 'cRLNumber'),\n deltaCrlIndicator: decodeInteger(extensions, id_ce_deltaCRLIndicator, 'deltaCRLIndicator'),\n authorityKeyIdentifier: aki?.keyIdentifier ? toHex(aki.keyIdentifier.buffer) : undefined,\n issuingDistributionPoint: idp\n ? {\n distributionPointUris: urisOf(idp.distributionPoint?.fullName),\n onlyContainsUserCerts: idp.onlyContainsUserCerts,\n onlyContainsCACerts: idp.onlyContainsCACerts,\n onlyContainsAttributeCerts: idp.onlyContainsAttributeCerts,\n indirectCRL: idp.indirectCRL,\n onlySomeReasons: idp.onlySomeReasons?.toJSON(),\n }\n : undefined,\n freshestCrl: (freshest ?? []).flatMap((dp) => urisOf(dp.distributionPoint?.fullName)),\n revokedCertificates: toRevokedCertificates(tbs.revokedCertificates),\n extensions,\n }\n}\n\n// ============================================================================\n// Revocation checking\n// ============================================================================\n\nfunction normalizeSerial(hex: string): string {\n return hex.toLowerCase().replace(/^(00)+(?=..)/, '')\n}\n\nfunction unknown(\n reason: Extract<RevocationStatus, { status: 'unknown' }>['reason'],\n message: string\n): RevocationStatus {\n return { status: 'unknown', reason, message }\n}\n\n/**\n * Look up the revocation status of `certificate` in `crl`.\n *\n * This does **not** verify the CRL signature; use {@link checkRevocation} unless the CRL\n * has already been verified. The CRL must be issued by the certificate issuer (or be an\n * indirect CRL naming it), must be current, and must cover the certificate. Otherwise the\n * status is `unknown` with the reason, and the caller should find a suitable CRL or fall\n * back to OCSP.\n */\nexport function getRevocationStatus(\n certificate: Certificate,\n crl: Crl,\n options: RevocationCheckOptions = {}\n): RevocationStatus {\n if (crl.deltaCrlIndicator !== undefined) {\n return unknown('delta_crl', 'Delta CRLs can only be used together with their base CRL')\n }\n const unsupported = crl.extensions.find((e) => e.critical && !KNOWN_CRL_EXTENSIONS.has(e.oid))\n if (unsupported) {\n return unknown('unsupported_critical_extension', `Unsupported critical CRL extension ${unsupported.oid}`)\n }\n\n const idp = crl.issuingDistributionPoint\n const indirect = idp?.indirectCRL ?? false\n if (!indirect) {\n if (!namesEqual(crl.issuer, certificate.issuer)) {\n return unknown('issuer_mismatch', 'The CRL is not issued by the certificate issuer')\n }\n if (\n crl.authorityKeyIdentifier &&\n certificate.authorityKeyIdentifier &&\n crl.authorityKeyIdentifier !== certificate.authorityKeyIdentifier\n ) {\n return unknown('issuer_mismatch', 'The CRL is signed with a different key than the certificate')\n }\n }\n\n if (options.now !== false) {\n const now = options.now ?? new Date()\n if (now < crl.thisUpdate) {\n return unknown('crl_not_yet_valid', `The CRL is not valid before ${crl.thisUpdate.toISOString()}`)\n }\n if (crl.nextUpdate && now > crl.nextUpdate) {\n return unknown('crl_expired', `The CRL expired at ${crl.nextUpdate.toISOString()}`)\n }\n }\n\n if (idp) {\n const isCA = certificate.basicConstraints?.cA === true\n if (idp.onlyContainsAttributeCerts) return unknown('out_of_scope', 'The CRL only covers attribute certificates')\n if (idp.onlyContainsCACerts && !isCA) return unknown('out_of_scope', 'The CRL only covers CA certificates')\n if (idp.onlyContainsUserCerts && isCA) return unknown('out_of_scope', 'The CRL only covers end-entity certificates')\n if (\n idp.distributionPointUris.length > 0 &&\n !idp.distributionPointUris.some((uri) => certificate.crlDistributionPoints.includes(uri))\n ) {\n return unknown('out_of_scope', 'The CRL distribution point does not match the certificate')\n }\n }\n\n const serial = normalizeSerial(certificate.serialNumber)\n const entry = crl.revokedCertificates.find(\n (e) =>\n normalizeSerial(e.serialNumber) === serial &&\n (!indirect || namesEqual(e.certificateIssuer ?? crl.issuer, certificate.issuer))\n )\n\n if (entry) {\n const unsupportedEntry = entry.extensions.find((e) => e.critical && !KNOWN_ENTRY_EXTENSIONS.has(e.oid))\n if (unsupportedEntry) {\n return unknown(\n 'unsupported_critical_extension',\n `Unsupported critical CRL entry extension ${unsupportedEntry.oid}`\n )\n }\n if (entry.reason === 'removeFromCRL') return { status: 'good' }\n return {\n status: 'revoked',\n revocationDate: entry.revocationDate,\n reason: entry.reason,\n invalidityDate: entry.invalidityDate,\n }\n }\n\n if (idp?.onlySomeReasons) {\n return unknown('out_of_scope', `The CRL only covers the reasons ${idp.onlySomeReasons.join(', ')}`)\n }\n return { status: 'good' }\n}\n\n/**\n * Verify the CRL signature against `crlIssuerCertificate`, then look up the revocation\n * status of `certificate` (see {@link getRevocationStatus}).\n *\n * The signature check is delegated to `verifier`; an invalid signature yields `unknown`\n * with reason `invalid_signature`. Fetching the CRL (see `crlDistributionPoints` on the\n * certificate) is up to the caller.\n */\nexport async function checkRevocation(options: {\n certificate: Certificate\n crl: Crl\n crlIssuerCertificate: Certificate | CertificateInput\n verifier: SignatureVerifier\n now?: Date | false\n}): Promise<RevocationStatus> {\n if (!(await verifyCrlSignature(options.crl, options.crlIssuerCertificate, options.verifier))) {\n return unknown('invalid_signature', 'The CRL signature is invalid or not issued by the given certificate')\n }\n return getRevocationStatus(options.certificate, options.crl, { now: options.now })\n}\n\n// ============================================================================\n// CRL creation\n// ============================================================================\n\nfunction bigintToIntegerBytes(value: bigint | number): Uint8Array {\n const n = BigInt(value)\n if (n < BigInt(0)) throw new X509Exception('CRL numbers must not be negative')\n const hex = n.toString(16)\n const bytes = toPositiveIntegerBytes(hexDecode(hex.length % 2 ? `0${hex}` : hex))\n if (bytes.length > 20) throw new X509Exception('CRL numbers must not be longer than 20 octets')\n return bytes\n}\n\nfunction derExtension(oid: string, value: Uint8Array | ArrayBuffer, critical = false): Extension {\n return new Extension({\n extnID: oid,\n critical,\n extnValue: new OctetString(value instanceof Uint8Array ? toArrayBuffer(value) : value),\n })\n}\n\n/**\n * Build the TBSCertList of a v2 CRL. Sign the returned `tbs` bytes with the CRL issuer key\n * and pass the signature to {@link assembleCrl}, or use {@link createCrl} with a signer.\n */\nexport function prepareCrl(template: CrlTemplate): PreparedSignedStructure {\n if (!(template.nextUpdate > template.thisUpdate)) {\n throw new X509Exception('nextUpdate must be later than thisUpdate')\n }\n const issuer = parseIssuerCertificate(template.issuerCertificate)\n\n const extensions: Extension[] = []\n const ski = subjectKeyIdentifierOf(issuer)\n if (ski) {\n extensions.push(\n derExtension(\n id_ce_authorityKeyIdentifier,\n AsnConvert.serialize(new AuthorityKeyIdentifier({ keyIdentifier: new KeyIdentifier(ski) }))\n )\n )\n }\n extensions.push(\n derExtension(\n id_ce_cRLNumber,\n new asn1js.Integer({ valueHex: toArrayBuffer(bigintToIntegerBytes(template.crlNumber)) }).toBER()\n )\n )\n const idp = template.issuingDistributionPoint\n if (idp) {\n extensions.push(\n derExtension(\n id_ce_issuingDistributionPoint,\n AsnConvert.serialize(\n new IssuingDistributionPoint({\n distributionPoint: idp.distributionPointUris?.length\n ? new DistributionPointName({\n fullName: idp.distributionPointUris.map((uri) => new GeneralName({ uniformResourceIdentifier: uri })),\n })\n : undefined,\n onlyContainsUserCerts: idp.onlyContainsUserCerts ?? false,\n onlyContainsCACerts: idp.onlyContainsCACerts ?? false,\n })\n ),\n true\n )\n )\n }\n for (const custom of template.extensions ?? []) extensions.push(toAsnExtension(custom))\n\n const revoked = (template.revokedCertificates ?? []).map((entry) => {\n const entryExtensions: Extension[] = []\n if (entry.reason && entry.reason !== 'unspecified') {\n entryExtensions.push(\n derExtension(id_ce_cRLReasons, new asn1js.Enumerated({ value: CRL_REASONS[entry.reason] }).toBER())\n )\n }\n if (entry.invalidityDate) {\n entryExtensions.push(\n derExtension(id_ce_invalidityDate, AsnConvert.serialize(new InvalidityDate(entry.invalidityDate)))\n )\n }\n return new AsnRevokedCertificate({\n userCertificate: toSerialNumber(entry.serialNumber),\n revocationDate: new Time(entry.revocationDate),\n crlEntryExtensions: entryExtensions.length > 0 ? entryExtensions : undefined,\n })\n })\n\n const tbs = new TBSCertList({\n version: Version.v2,\n signature: signatureAlgorithmIdentifier(template.signatureAlgorithm),\n issuer: issuer.tbsCertificate.subject,\n thisUpdate: new Time(template.thisUpdate),\n nextUpdate: new Time(template.nextUpdate),\n revokedCertificates: revoked.length > 0 ? revoked : undefined,\n crlExtensions: extensions,\n })\n\n return {\n tbs: new Uint8Array(AsnConvert.serialize(tbs)),\n signatureAlgorithm: template.signatureAlgorithm,\n signerPublicKey: describePublicKey(issuer.tbsCertificate.subjectPublicKeyInfo),\n }\n}\n\n/** Combine a prepared TBSCertList with the issuer signature. */\nexport function assembleCrl(\n prepared: PreparedSignedStructure,\n signature: Uint8Array,\n signatureEncoding?: SignatureEncoding\n): Crl {\n return parseCrl(assembleSignedStructure(prepared, signature, signatureEncoding))\n}\n\n/**\n * Create a v2 CRL. The CRL issuer key is never passed in: the `signer` callback receives the\n * DER encoded TBSCertList and returns the signature.\n */\nexport async function createCrl(template: CrlTemplate & SignOptions): Promise<Crl> {\n const prepared = prepareCrl(template)\n return assembleCrl(prepared, await template.signer(prepared.tbs), template.signatureEncoding)\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,kBAAkB;CAC7B,YAAY;CACZ,SAAS;CACT,cAAc;CACd,aAAa;CACb,cAAc;CACd,qBAAqB;CACrB,eAAe;CACf,kBAAkB;CAClB,wBAAwB;CACxB,OAAO;CACP,YAAY;CACZ,iBAAiB;CACjB,WAAW;CACX,UAAU;CACV,qBAAqB;CACrB,WAAW;CACX,wBAAwB;CACxB,cAAc;AAChB;;AAKA,MAAa,oBAAoB;CAC/B,KAAK;CACL,SAAS;AACX;;AAGA,MAAa,iBAAiB;CAC5B,MAAM;CACN,WAAW;AACb;;AAGA,MAAa,gBAAgB;CAC3B,WAAW;CACX,cAAc;CACd,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,iBAAiB;AACnB;;AAGA,MAAa,WAAW;CACtB,OAAO;CACP,OAAO;CACP,KAAK;AACP;;AAKA,MAAa,uBAAuB;CAClC,OAAO;EAAE,KAAK;EAAuB,MAAM;EAAW,QAAQ;CAAQ;CACtE,OAAO;EAAE,KAAK;EAAuB,MAAM;EAAW,QAAQ;CAAQ;CACtE,OAAO;EAAE,KAAK;EAAuB,MAAM;EAAW,QAAQ;CAAQ;CACtE,OAAO;EAAE,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C,CAAC,CAAC,MAAM,CAAC,CACpG;EAEF,IAAI,MAAM,gBACR,gBAAgB,KACd,aAAa,sBAAsB,WAAW,UAAU,IAAI,eAAe,MAAM,cAAc,CAAC,CAAC,CACnG;EAEF,OAAO,IAAIC,mBAAsB;GAC/B,iBAAiB,eAAe,MAAM,YAAY;GAClD,gBAAgB,IAAI,KAAK,MAAM,cAAc;GAC7C,oBAAoB,gBAAgB,SAAS,IAAI,kBAAkB,KAAA;EACrE,CAAC;CACH,CAAC;CAED,MAAM,MAAM,IAAI,YAAY;EAC1B,SAAS,QAAQ;EACjB,WAAW,6BAA6B,SAAS,kBAAkB;EACnE,QAAQ,OAAO,eAAe;EAC9B,YAAY,IAAI,KAAK,SAAS,UAAU;EACxC,YAAY,IAAI,KAAK,SAAS,UAAU;EACxC,qBAAqB,QAAQ,SAAS,IAAI,UAAU,KAAA;EACpD,eAAe;CACjB,CAAC;CAED,OAAO;EACL,KAAK,IAAI,WAAW,WAAW,UAAU,GAAG,CAAC;EAC7C,oBAAoB,SAAS;EAC7B,iBAAiB,kBAAkB,OAAO,eAAe,oBAAoB;CAC/E;AACF;;AAGA,SAAgB,YACd,UACA,WACA,mBACK;CACL,OAAO,SAAS,wBAAwB,UAAU,WAAW,iBAAiB,CAAC;AACjF;;;;;AAMA,eAAsB,UAAU,UAAmD;CACjF,MAAM,WAAW,WAAW,QAAQ;CACpC,OAAO,YAAY,UAAU,MAAM,SAAS,OAAO,SAAS,GAAG,GAAG,SAAS,iBAAiB;AAC9F"}
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@owf/x509",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.0",
4
+ "description": "Environment agnostic X.509 certificate and CRL parsing, creation and verification with pluggable crypto",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "license": "Apache-2.0",
9
+ "exports": "./src/index.ts",
10
+ "homepage": "https://github.com/openwallet-foundation-labs/identity-common-ts/tree/main/packages/x509",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/openwallet-foundation-labs/identity-common-ts",
14
+ "directory": "packages/x509"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.mjs",
20
+ "types": "./dist/index.d.mts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.mts",
24
+ "import": "./dist/index.mjs",
25
+ "require": "./dist/index.cjs",
26
+ "default": "./dist/index.mjs"
27
+ },
28
+ "./package.json": "./package.json"
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "tsdown src/index.ts --format esm,cjs --dts --sourcemap"
33
+ },
34
+ "dependencies": {
35
+ "@owf/identity-common": "workspace:*",
36
+ "@peculiar/asn1-schema": "catalog:",
37
+ "@peculiar/asn1-x509": "catalog:",
38
+ "@peculiar/asn1-x509-qualified": "catalog:",
39
+ "@peculiar/asn1-x509-qualified-etsi": "catalog:",
40
+ "asn1js": "^3.0.10"
41
+ },
42
+ "keywords": [
43
+ "x509",
44
+ "certificate",
45
+ "crl",
46
+ "pkix",
47
+ "rfc5280",
48
+ "asn1",
49
+ "react-native"
50
+ ]
51
+ }