@openeudi/openid4vp 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6382,6 +6382,33 @@ var init_es20152 = __esm({
6382
6382
  init_validity();
6383
6383
  }
6384
6384
  });
6385
+ function getSkiHex(cert) {
6386
+ const ext = cert.getExtension(x509.SubjectKeyIdentifierExtension);
6387
+ return ext ? ext.keyId.toLowerCase() : null;
6388
+ }
6389
+ function certificatesEqual(a, b) {
6390
+ const ab = new Uint8Array(a.rawData);
6391
+ const bb = new Uint8Array(b.rawData);
6392
+ if (ab.length !== bb.length) return false;
6393
+ for (let i = 0; i < ab.length; i++) {
6394
+ if (ab[i] !== bb[i]) return false;
6395
+ }
6396
+ return true;
6397
+ }
6398
+ function getSkiBytes(cert) {
6399
+ const ext = cert.getExtension(x509.SubjectKeyIdentifierExtension);
6400
+ if (!ext) return null;
6401
+ const hex = ext.keyId;
6402
+ const out = new Uint8Array(hex.length / 2);
6403
+ for (let i = 0; i < out.length; i++) {
6404
+ out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
6405
+ }
6406
+ return out;
6407
+ }
6408
+ var init_x509_utils = __esm({
6409
+ "src/trust/x509-utils.ts"() {
6410
+ }
6411
+ });
6385
6412
  function mapX509AlgoToJwaName(cert) {
6386
6413
  const alg = cert.signatureAlgorithm;
6387
6414
  const name = alg?.name ?? "";
@@ -6391,8 +6418,11 @@ function mapX509AlgoToJwaName(cert) {
6391
6418
  if (name === "ECDSA" && hash === "SHA-512") return "ES512";
6392
6419
  if (name === "Ed25519" || name === "EdDSA") return "EdDSA";
6393
6420
  if (name === "RSASSA-PKCS1-v1_5" && hash === "SHA-256") return "RS256";
6421
+ if (name === "RSASSA-PKCS1-v1_5" && hash === "SHA-384") return "RS384";
6422
+ if (name === "RSASSA-PKCS1-v1_5" && hash === "SHA-512") return "RS512";
6394
6423
  if (name === "RSA-PSS" && hash === "SHA-256") return "PS256";
6395
6424
  if (name === "RSA-PSS" && hash === "SHA-384") return "PS384";
6425
+ if (name === "RSA-PSS" && hash === "SHA-512") return "PS512";
6396
6426
  return `${name}-${hash}`;
6397
6427
  }
6398
6428
  function collectLeafNames(leaf) {
@@ -6485,8 +6515,20 @@ var init_ChainBuilder = __esm({
6485
6515
  init_es2015();
6486
6516
  init_es20152();
6487
6517
  init_errors();
6518
+ init_x509_utils();
6488
6519
  NAME_CONSTRAINTS_OID = "2.5.29.30";
6489
- DEFAULT_ALGORITHMS = ["ES256", "ES384", "EdDSA", "RS256", "PS256"];
6520
+ DEFAULT_ALGORITHMS = [
6521
+ "ES256",
6522
+ "ES384",
6523
+ "ES512",
6524
+ "EdDSA",
6525
+ "RS256",
6526
+ "RS384",
6527
+ "RS512",
6528
+ "PS256",
6529
+ "PS384",
6530
+ "PS512"
6531
+ ];
6490
6532
  ChainBuilder = class {
6491
6533
  constructor(opts = {}) {
6492
6534
  this.opts = opts;
@@ -6545,6 +6587,12 @@ var init_ChainBuilder = __esm({
6545
6587
  current = issuer;
6546
6588
  nonLeafDepth += 1;
6547
6589
  }
6590
+ if (!certificatesEqual(current, anchor)) {
6591
+ throw new exports.CertificateChainError(
6592
+ `certificate ${current.subject} shares the trust anchor's Subject DN but is not the anchor (no signature closure)`,
6593
+ { reason: "signature" }
6594
+ );
6595
+ }
6548
6596
  this.checkNameConstraints(leaf, chain.slice(1));
6549
6597
  return chain;
6550
6598
  }
@@ -7785,7 +7833,10 @@ var init_RevocationChecker = __esm({
7785
7833
  if (hints.ocspUrl) {
7786
7834
  try {
7787
7835
  return await this.ocsp.checkCached(subjectCert, issuerCert, hints.ocspUrl, now);
7788
- } catch {
7836
+ } catch (err) {
7837
+ console.warn(
7838
+ `[openid4vp] OCSP check failed for ${subjectCert.subject} via ${hints.ocspUrl}, falling back to CRL: ${err.message}`
7839
+ );
7789
7840
  }
7790
7841
  }
7791
7842
  for (const url of hints.crlUrls) {
@@ -7813,6 +7864,9 @@ var init_RevocationChecker = __esm({
7813
7864
  return { status: "good", source: "crl", checkedAt: now };
7814
7865
  } catch (err) {
7815
7866
  if (err instanceof exports.RevocationCheckFailedError) throw err;
7867
+ console.warn(
7868
+ `[openid4vp] CRL check failed for ${subjectCert.subject} via ${url}: ${err.message}`
7869
+ );
7816
7870
  continue;
7817
7871
  }
7818
7872
  }
@@ -7831,24 +7885,6 @@ var init_RevocationChecker = __esm({
7831
7885
  };
7832
7886
  }
7833
7887
  });
7834
- function getSkiHex(cert) {
7835
- const ext = cert.getExtension(x509.SubjectKeyIdentifierExtension);
7836
- return ext ? ext.keyId.toLowerCase() : null;
7837
- }
7838
- function getSkiBytes(cert) {
7839
- const ext = cert.getExtension(x509.SubjectKeyIdentifierExtension);
7840
- if (!ext) return null;
7841
- const hex = ext.keyId;
7842
- const out = new Uint8Array(hex.length / 2);
7843
- for (let i = 0; i < out.length; i++) {
7844
- out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
7845
- }
7846
- return out;
7847
- }
7848
- var init_x509_utils = __esm({
7849
- "src/trust/x509-utils.ts"() {
7850
- }
7851
- });
7852
7888
 
7853
7889
  // src/trust/lotl-loa-mapping.ts
7854
7890
  function mapLoA(uris) {
@@ -8030,8 +8066,13 @@ var init_TrustEvaluator = __esm({
8030
8066
  );
8031
8067
  const terminusCert = chain[chain.length - 1];
8032
8068
  const anchor = anchors.find(
8033
- (a) => a.certificate.serialNumber === terminusCert.serialNumber
8034
- ) ?? anchors[0];
8069
+ (a) => certificatesEqual(a.certificate, terminusCert)
8070
+ );
8071
+ if (!anchor) {
8072
+ throw new exports.TrustAnchorNotFoundError(
8073
+ `chain terminus ${terminusCert.subject} does not match any trust anchor certificate`
8074
+ );
8075
+ }
8035
8076
  const issuerForRevocation = chain.length > 1 ? chain[1] : terminusCert;
8036
8077
  const revocation = await this.revocationChecker.check(
8037
8078
  leaf,
@@ -8335,7 +8376,7 @@ function isHaipQuery(query) {
8335
8376
 
8336
8377
  // src/crypto/cose-sign1.ts
8337
8378
  init_errors();
8338
- var decoder = new cborX.Encoder({ mapsAsObjects: false, useRecords: false });
8379
+ var decoder = new cborX.Encoder({ mapsAsObjects: false, useRecords: false, tagUint8Array: false });
8339
8380
  var HEADER_ALG = 1;
8340
8381
  var HEADER_X5CHAIN = 33;
8341
8382
  var COSE_ALG_TO_NAME = {