@openeudi/openid4vp 0.5.0 → 0.6.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.js CHANGED
@@ -610,6 +610,9 @@ __export(index_es_exports, {
610
610
  Choice: () => Choice,
611
611
  Constructed: () => Constructed,
612
612
  DATE: () => DATE,
613
+ DEFAULT_MAX_CONTENT_LENGTH: () => DEFAULT_MAX_CONTENT_LENGTH,
614
+ DEFAULT_MAX_DEPTH: () => DEFAULT_MAX_DEPTH,
615
+ DEFAULT_MAX_NODES: () => DEFAULT_MAX_NODES,
613
616
  DateTime: () => DateTime,
614
617
  Duration: () => Duration,
615
618
  EndOfContent: () => EndOfContent,
@@ -704,7 +707,7 @@ function HexBlock(BaseClass) {
704
707
  this.isHexOnly = (_b = params.isHexOnly) !== null && _b !== void 0 ? _b : false;
705
708
  this.valueHexView = params.valueHex ? BufferSourceConverter.toUint8Array(params.valueHex) : EMPTY_VIEW;
706
709
  }
707
- fromBER(inputBuffer, inputOffset, inputLength) {
710
+ fromBER(inputBuffer, inputOffset, inputLength, _context) {
708
711
  const view = inputBuffer instanceof ArrayBuffer ? new Uint8Array(inputBuffer) : inputBuffer;
709
712
  if (!checkBufferParams(this, view, inputOffset, inputLength)) {
710
713
  return -1;
@@ -748,6 +751,49 @@ function prepareIndefiniteForm(baseBlock) {
748
751
  }
749
752
  return !!((_a2 = baseBlock.lenBlock) === null || _a2 === void 0 ? void 0 : _a2.isIndefiniteForm);
750
753
  }
754
+ function createFromBerContext(options = {}) {
755
+ var _a2, _b, _c;
756
+ return {
757
+ depth: 0,
758
+ maxDepth: (_a2 = options.maxDepth) !== null && _a2 !== void 0 ? _a2 : DEFAULT_MAX_DEPTH,
759
+ nodesCount: 0,
760
+ maxNodes: (_b = options.maxNodes) !== null && _b !== void 0 ? _b : DEFAULT_MAX_NODES,
761
+ maxContentLength: (_c = options.maxContentLength) !== null && _c !== void 0 ? _c : DEFAULT_MAX_CONTENT_LENGTH
762
+ };
763
+ }
764
+ function createErrorResult(error) {
765
+ const result = new BaseBlock({}, ValueBlock);
766
+ result.error = error;
767
+ return {
768
+ offset: -1,
769
+ result
770
+ };
771
+ }
772
+ function checkNodesLimit(context) {
773
+ context.nodesCount += 1;
774
+ if (context.nodesCount > context.maxNodes) {
775
+ return MAX_NODES_EXCEEDED_ERROR;
776
+ }
777
+ return void 0;
778
+ }
779
+ function checkContentLengthLimit(inputLength, context) {
780
+ if (inputLength > context.maxContentLength) {
781
+ return MAX_CONTENT_LENGTH_EXCEEDED_ERROR;
782
+ }
783
+ return void 0;
784
+ }
785
+ function localFromBERWithChildContext(inputBuffer, inputOffset, inputLength, context) {
786
+ const childDepth = context.depth + 1;
787
+ if (childDepth > context.maxDepth) {
788
+ return createErrorResult(MAX_DEPTH_EXCEEDED_ERROR);
789
+ }
790
+ context.depth = childDepth;
791
+ try {
792
+ return localFromBER(inputBuffer, inputOffset, inputLength, context);
793
+ } finally {
794
+ context.depth -= 1;
795
+ }
796
+ }
751
797
  function localChangeType(inputObject, newType) {
752
798
  if (inputObject instanceof newType) {
753
799
  return inputObject;
@@ -759,7 +805,7 @@ function localChangeType(inputObject, newType) {
759
805
  newObject.valueBeforeDecodeView = inputObject.valueBeforeDecodeView;
760
806
  return newObject;
761
807
  }
762
- function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length) {
808
+ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.length, context = createFromBerContext()) {
763
809
  const incomingOffset = inputOffset;
764
810
  let returnObject = new BaseBlock({}, ValueBlock);
765
811
  const baseBlock = new LocalBaseBlock();
@@ -778,6 +824,14 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
778
824
  result: returnObject
779
825
  };
780
826
  }
827
+ const nodesLimitError = checkNodesLimit(context);
828
+ if (nodesLimitError) {
829
+ returnObject.error = nodesLimitError;
830
+ return {
831
+ offset: -1,
832
+ result: returnObject
833
+ };
834
+ }
781
835
  let resultOffset = returnObject.idBlock.fromBER(inputBuffer, inputOffset, inputLength);
782
836
  if (returnObject.idBlock.warnings.length) {
783
837
  returnObject.warnings.concat(returnObject.idBlock.warnings);
@@ -804,6 +858,15 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
804
858
  }
805
859
  inputOffset = resultOffset;
806
860
  inputLength -= returnObject.lenBlock.blockLength;
861
+ const valueLength = returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length;
862
+ const contentLengthError = checkContentLengthLimit(valueLength, context);
863
+ if (contentLengthError) {
864
+ returnObject.error = contentLengthError;
865
+ return {
866
+ offset: -1,
867
+ result: returnObject
868
+ };
869
+ }
807
870
  if (!returnObject.idBlock.isConstructed && returnObject.lenBlock.isIndefiniteForm) {
808
871
  returnObject.error = "Indefinite length form used for primitive encoding form";
809
872
  return {
@@ -942,14 +1005,14 @@ function localFromBER(inputBuffer, inputOffset = 0, inputLength = inputBuffer.le
942
1005
  }
943
1006
  }
944
1007
  returnObject = localChangeType(returnObject, newASN1Type);
945
- resultOffset = returnObject.fromBER(inputBuffer, inputOffset, returnObject.lenBlock.isIndefiniteForm ? inputLength : returnObject.lenBlock.length);
1008
+ resultOffset = returnObject.fromBER(inputBuffer, inputOffset, valueLength, context);
946
1009
  returnObject.valueBeforeDecodeView = inputBuffer.subarray(incomingOffset, incomingOffset + returnObject.blockLength);
947
1010
  return {
948
1011
  offset: resultOffset,
949
1012
  result: returnObject
950
1013
  };
951
1014
  }
952
- function fromBER(inputBuffer) {
1015
+ function fromBER(inputBuffer, options = {}) {
953
1016
  if (!inputBuffer.byteLength) {
954
1017
  const result = new BaseBlock({}, ValueBlock);
955
1018
  result.error = "Input buffer has zero length";
@@ -958,7 +1021,7 @@ function fromBER(inputBuffer) {
958
1021
  result
959
1022
  };
960
1023
  }
961
- return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength);
1024
+ return localFromBER(BufferSourceConverter.toUint8Array(inputBuffer).slice(), 0, inputBuffer.byteLength, createFromBerContext(options));
962
1025
  }
963
1026
  function checkLen(indefiniteLength, length) {
964
1027
  if (indefiniteLength) {
@@ -1364,7 +1427,7 @@ function verifySchema(inputBuffer, inputSchema) {
1364
1427
  }
1365
1428
  return compareSchema(asn1.result, asn1.result, inputSchema);
1366
1429
  }
1367
- var ViewWriter, powers2, digitsString, NAME, VALUE_HEX_VIEW, IS_HEX_ONLY, ID_BLOCK, TAG_CLASS, TAG_NUMBER, IS_CONSTRUCTED, FROM_BER, TO_BER, LOCAL, EMPTY_STRING, EMPTY_BUFFER, EMPTY_VIEW, END_OF_CONTENT_NAME, OCTET_STRING_NAME, BIT_STRING_NAME, LocalBaseBlock, ValueBlock, LocalIdentificationBlock, LocalLengthBlock, typeStore, BaseBlock, BaseStringBlock, LocalPrimitiveValueBlock, _a$w, Primitive, LocalConstructedValueBlock, _a$v, Constructed, LocalEndOfContentValueBlock, _a$u, EndOfContent, _a$t, Null, LocalBooleanValueBlock, _a$s, Boolean2, LocalOctetStringValueBlock, _a$r, OctetString, LocalBitStringValueBlock, _a$q, BitString, _a$p, LocalIntegerValueBlock, _a$o, Integer, _a$n, Enumerated, LocalSidValueBlock, LocalObjectIdentifierValueBlock, _a$m, ObjectIdentifier, LocalRelativeSidValueBlock, LocalRelativeObjectIdentifierValueBlock, _a$l, RelativeObjectIdentifier, _a$k, Sequence, _a$j, Set2, LocalStringValueBlock, LocalSimpleStringValueBlock, LocalSimpleStringBlock, LocalUtf8StringValueBlock, _a$i, Utf8String, LocalBmpStringValueBlock, _a$h, BmpString, LocalUniversalStringValueBlock, _a$g, UniversalString, _a$f, NumericString, _a$e, PrintableString, _a$d, TeletexString, _a$c, VideotexString, _a$b, IA5String, _a$a, GraphicString, _a$9, VisibleString, _a$8, GeneralString, _a$7, CharacterString, _a$6, UTCTime, _a$5, GeneralizedTime, _a$4, DATE, _a$3, TimeOfDay, _a$2, DateTime, _a$1, Duration, _a, TIME, Any, Choice, Repeated, RawData;
1430
+ var ViewWriter, powers2, digitsString, NAME, VALUE_HEX_VIEW, IS_HEX_ONLY, ID_BLOCK, TAG_CLASS, TAG_NUMBER, IS_CONSTRUCTED, FROM_BER, TO_BER, LOCAL, EMPTY_STRING, EMPTY_BUFFER, EMPTY_VIEW, END_OF_CONTENT_NAME, OCTET_STRING_NAME, BIT_STRING_NAME, LocalBaseBlock, ValueBlock, LocalIdentificationBlock, LocalLengthBlock, typeStore, BaseBlock, BaseStringBlock, LocalPrimitiveValueBlock, _a$w, Primitive, DEFAULT_MAX_DEPTH, DEFAULT_MAX_NODES, DEFAULT_MAX_CONTENT_LENGTH, MAX_DEPTH_EXCEEDED_ERROR, MAX_NODES_EXCEEDED_ERROR, MAX_CONTENT_LENGTH_EXCEEDED_ERROR, LocalConstructedValueBlock, _a$v, Constructed, LocalEndOfContentValueBlock, _a$u, EndOfContent, _a$t, Null, LocalBooleanValueBlock, _a$s, Boolean2, LocalOctetStringValueBlock, _a$r, OctetString, LocalBitStringValueBlock, _a$q, BitString, _a$p, LocalIntegerValueBlock, _a$o, Integer, _a$n, Enumerated, LocalSidValueBlock, LocalObjectIdentifierValueBlock, _a$m, ObjectIdentifier, LocalRelativeSidValueBlock, LocalRelativeObjectIdentifierValueBlock, _a$l, RelativeObjectIdentifier, _a$k, Sequence, _a$j, Set2, LocalStringValueBlock, LocalSimpleStringValueBlock, LocalSimpleStringBlock, LocalUtf8StringValueBlock, _a$i, Utf8String, LocalBmpStringValueBlock, _a$h, BmpString, LocalUniversalStringValueBlock, _a$g, UniversalString, _a$f, NumericString, _a$e, PrintableString, _a$d, TeletexString, _a$c, VideotexString, _a$b, IA5String, _a$a, GraphicString, _a$9, VisibleString, _a$8, GeneralString, _a$7, CharacterString, _a$6, UTCTime, _a$5, GeneralizedTime, _a$4, DATE, _a$3, TimeOfDay, _a$2, DateTime, _a$1, Duration, _a, TIME, Any, Choice, Repeated, RawData;
1368
1431
  var init_index_es2 = __esm({
1369
1432
  "node_modules/asn1js/build/index.es.js"() {
1370
1433
  init_index_es();
@@ -1426,7 +1489,7 @@ var init_index_es2 = __esm({
1426
1489
  };
1427
1490
  LocalBaseBlock.NAME = "baseBlock";
1428
1491
  ValueBlock = class extends LocalBaseBlock {
1429
- fromBER(_inputBuffer, _inputOffset, _inputLength) {
1492
+ fromBER(_inputBuffer, _inputOffset, _inputLength, _context) {
1430
1493
  throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
1431
1494
  }
1432
1495
  toBER(_sizeOnly, _writer) {
@@ -1539,31 +1602,21 @@ var init_index_es2 = __esm({
1539
1602
  this.tagNumber = tagNumberMask;
1540
1603
  this.blockLength = 1;
1541
1604
  } else {
1542
- let count = 1;
1543
- let intTagNumberBuffer = this.valueHexView = new Uint8Array(255);
1544
- let tagNumberBufferMaxLength = 255;
1545
- while (intBuffer[count] & 128) {
1546
- intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
1547
- count++;
1548
- if (count >= intBuffer.length) {
1605
+ let count = 0;
1606
+ while (true) {
1607
+ const tagByteIndex = count + 1;
1608
+ if (tagByteIndex >= intBuffer.length) {
1549
1609
  this.error = "End of input reached before message was fully decoded";
1550
1610
  return -1;
1551
1611
  }
1552
- if (count === tagNumberBufferMaxLength) {
1553
- tagNumberBufferMaxLength += 255;
1554
- const tempBufferView2 = new Uint8Array(tagNumberBufferMaxLength);
1555
- for (let i = 0; i < intTagNumberBuffer.length; i++)
1556
- tempBufferView2[i] = intTagNumberBuffer[i];
1557
- intTagNumberBuffer = this.valueHexView = new Uint8Array(tagNumberBufferMaxLength);
1558
- }
1612
+ count++;
1613
+ if ((intBuffer[tagByteIndex] & 128) === 0)
1614
+ break;
1559
1615
  }
1560
1616
  this.blockLength = count + 1;
1561
- intTagNumberBuffer[count - 1] = intBuffer[count] & 127;
1562
- const tempBufferView = new Uint8Array(count);
1617
+ const intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
1563
1618
  for (let i = 0; i < count; i++)
1564
- tempBufferView[i] = intTagNumberBuffer[i];
1565
- intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
1566
- intTagNumberBuffer.set(tempBufferView);
1619
+ intTagNumberBuffer[i] = intBuffer[i + 1] & 127;
1567
1620
  if (this.blockLength <= 9)
1568
1621
  this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
1569
1622
  else {
@@ -1713,8 +1766,8 @@ var init_index_es2 = __esm({
1713
1766
  this.lenBlock = new LocalLengthBlock(parameters);
1714
1767
  this.valueBlock = valueBlockType ? new valueBlockType(parameters) : new ValueBlock(parameters);
1715
1768
  }
1716
- fromBER(inputBuffer, inputOffset, inputLength) {
1717
- const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
1769
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
1770
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length, context);
1718
1771
  if (resultOffset === -1) {
1719
1772
  this.error = this.valueBlock.error;
1720
1773
  return resultOffset;
@@ -1838,14 +1891,21 @@ var init_index_es2 = __esm({
1838
1891
  typeStore.Primitive = _a$w;
1839
1892
  })();
1840
1893
  Primitive.NAME = "PRIMITIVE";
1894
+ DEFAULT_MAX_DEPTH = 100;
1895
+ DEFAULT_MAX_NODES = 1e4;
1896
+ DEFAULT_MAX_CONTENT_LENGTH = 16 * 1024 * 1024;
1897
+ MAX_DEPTH_EXCEEDED_ERROR = "Maximum ASN.1 nesting depth exceeded";
1898
+ MAX_NODES_EXCEEDED_ERROR = "Maximum ASN.1 node count exceeded";
1899
+ MAX_CONTENT_LENGTH_EXCEEDED_ERROR = "Maximum ASN.1 content length exceeded";
1841
1900
  LocalConstructedValueBlock = class extends ValueBlock {
1842
1901
  constructor({ value = [], isIndefiniteForm = false, ...parameters } = {}) {
1843
1902
  super(parameters);
1844
1903
  this.value = value;
1845
1904
  this.isIndefiniteForm = isIndefiniteForm;
1846
1905
  }
1847
- fromBER(inputBuffer, inputOffset, inputLength) {
1906
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
1848
1907
  const view = BufferSourceConverter.toUint8Array(inputBuffer);
1908
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
1849
1909
  if (!checkBufferParams(this, view, inputOffset, inputLength)) {
1850
1910
  return -1;
1851
1911
  }
@@ -1856,7 +1916,7 @@ var init_index_es2 = __esm({
1856
1916
  }
1857
1917
  let currentOffset = inputOffset;
1858
1918
  while (checkLen(this.isIndefiniteForm, inputLength) > 0) {
1859
- const returnObject = localFromBER(view, currentOffset, inputLength);
1919
+ const returnObject = localFromBERWithChildContext(view, currentOffset, inputLength, parseContext);
1860
1920
  if (returnObject.offset === -1) {
1861
1921
  this.error = returnObject.result.error;
1862
1922
  this.warnings.concat(returnObject.result.warnings);
@@ -1907,9 +1967,9 @@ var init_index_es2 = __esm({
1907
1967
  super(parameters, LocalConstructedValueBlock);
1908
1968
  this.idBlock.isConstructed = true;
1909
1969
  }
1910
- fromBER(inputBuffer, inputOffset, inputLength) {
1970
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
1911
1971
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
1912
- const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length);
1972
+ const resultOffset = this.valueBlock.fromBER(inputBuffer, inputOffset, this.lenBlock.isIndefiniteForm ? inputLength : this.lenBlock.length, context);
1913
1973
  if (resultOffset === -1) {
1914
1974
  this.error = this.valueBlock.error;
1915
1975
  return resultOffset;
@@ -2072,11 +2132,11 @@ ${values.join("\n")}` : `${blockName} :`;
2072
2132
  super(parameters);
2073
2133
  this.isConstructed = isConstructed;
2074
2134
  }
2075
- fromBER(inputBuffer, inputOffset, inputLength) {
2135
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2076
2136
  let resultOffset = 0;
2077
2137
  if (this.isConstructed) {
2078
2138
  this.isHexOnly = false;
2079
- resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
2139
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
2080
2140
  if (resultOffset === -1)
2081
2141
  return resultOffset;
2082
2142
  for (let i = 0; i < this.value.length; i++) {
@@ -2132,7 +2192,7 @@ ${values.join("\n")}` : `${blockName} :`;
2132
2192
  this.idBlock.tagClass = 1;
2133
2193
  this.idBlock.tagNumber = 4;
2134
2194
  }
2135
- fromBER(inputBuffer, inputOffset, inputLength) {
2195
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2136
2196
  this.valueBlock.isConstructed = this.idBlock.isConstructed;
2137
2197
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
2138
2198
  if (inputLength === 0) {
@@ -2147,7 +2207,8 @@ ${values.join("\n")}` : `${blockName} :`;
2147
2207
  const buf = view.subarray(inputOffset, inputOffset + inputLength);
2148
2208
  try {
2149
2209
  if (buf.byteLength) {
2150
- const asn = localFromBER(buf, 0, buf.byteLength);
2210
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
2211
+ const asn = localFromBERWithChildContext(buf, 0, buf.byteLength, parseContext);
2151
2212
  if (asn.offset !== -1 && asn.offset === inputLength) {
2152
2213
  this.valueBlock.value = [asn.result];
2153
2214
  }
@@ -2155,7 +2216,7 @@ ${values.join("\n")}` : `${blockName} :`;
2155
2216
  } catch {
2156
2217
  }
2157
2218
  }
2158
- return super.fromBER(inputBuffer, inputOffset, inputLength);
2219
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
2159
2220
  }
2160
2221
  onAsciiEncoding() {
2161
2222
  if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
@@ -2190,13 +2251,13 @@ ${values.join("\n")}` : `${blockName} :`;
2190
2251
  this.isConstructed = isConstructed;
2191
2252
  this.blockLength = this.valueHexView.byteLength;
2192
2253
  }
2193
- fromBER(inputBuffer, inputOffset, inputLength) {
2254
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2194
2255
  if (!inputLength) {
2195
2256
  return inputOffset;
2196
2257
  }
2197
2258
  let resultOffset = -1;
2198
2259
  if (this.isConstructed) {
2199
- resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength);
2260
+ resultOffset = LocalConstructedValueBlock.prototype.fromBER.call(this, inputBuffer, inputOffset, inputLength, context);
2200
2261
  if (resultOffset === -1)
2201
2262
  return resultOffset;
2202
2263
  for (const value of this.value) {
@@ -2236,7 +2297,8 @@ ${values.join("\n")}` : `${blockName} :`;
2236
2297
  const buf = intBuffer.subarray(1);
2237
2298
  try {
2238
2299
  if (buf.byteLength) {
2239
- const asn = localFromBER(buf, 0, buf.byteLength);
2300
+ const parseContext = context !== null && context !== void 0 ? context : createFromBerContext();
2301
+ const asn = localFromBERWithChildContext(buf, 0, buf.byteLength, parseContext);
2240
2302
  if (asn.offset !== -1 && asn.offset === inputLength - 1) {
2241
2303
  this.value = [asn.result];
2242
2304
  }
@@ -2292,10 +2354,10 @@ ${values.join("\n")}` : `${blockName} :`;
2292
2354
  this.idBlock.tagClass = 1;
2293
2355
  this.idBlock.tagNumber = 3;
2294
2356
  }
2295
- fromBER(inputBuffer, inputOffset, inputLength) {
2357
+ fromBER(inputBuffer, inputOffset, inputLength, context) {
2296
2358
  this.valueBlock.isConstructed = this.idBlock.isConstructed;
2297
2359
  this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
2298
- return super.fromBER(inputBuffer, inputOffset, inputLength);
2360
+ return super.fromBER(inputBuffer, inputOffset, inputLength, context);
2299
2361
  }
2300
2362
  onAsciiEncoding() {
2301
2363
  if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length) {
@@ -8850,38 +8912,6 @@ var INTERNAL_TO_DCQL_FORMAT = {
8850
8912
  "sd-jwt-vc": "dc+sd-jwt",
8851
8913
  mdoc: "mso_mdoc"
8852
8914
  };
8853
- function classifyMismatch(query, decoded, hasDetail) {
8854
- if (decoded.format !== query.format) return "format_mismatch";
8855
- if (query.format === "dc+sd-jwt") {
8856
- const allowed = query.meta?.vct_values;
8857
- if (allowed && allowed.length > 0 && !allowed.includes(decoded.vct ?? "")) {
8858
- return "vct_mismatch";
8859
- }
8860
- }
8861
- if (query.format === "mso_mdoc") {
8862
- const expected = query.meta?.doctype_value;
8863
- if (expected && expected !== decoded.doctype) return "doctype_mismatch";
8864
- }
8865
- if (query.trusted_authorities && query.trusted_authorities.length > 0) {
8866
- const decodedAuthIds = decoded.trusted_authority_ids ?? [];
8867
- const anyMatch = query.trusted_authorities.some(
8868
- (ta) => ta.values.some((v) => decodedAuthIds.includes(v))
8869
- );
8870
- if (!anyMatch) return "trusted_authority_mismatch";
8871
- }
8872
- if (hasDetail) return "missing_claims";
8873
- return "no_credential_found";
8874
- }
8875
- function refineUnmatched(query, decoded, match) {
8876
- if (match.unmatched.length === 0) return match;
8877
- const refined = match.unmatched.map((entry) => {
8878
- const credentialQuery = query.credentials.find((c) => c.id === entry.queryId);
8879
- if (!credentialQuery) return entry;
8880
- const specific = classifyMismatch(credentialQuery, decoded, entry.detail !== void 0);
8881
- return { ...entry, reason: specific };
8882
- });
8883
- return { ...match, unmatched: refined };
8884
- }
8885
8915
  async function verifyPresentation(vpToken, query, options) {
8886
8916
  const parsed = await parsePresentation(vpToken, options);
8887
8917
  const dcqlFormat = INTERNAL_TO_DCQL_FORMAT[parsed.format] ?? parsed.format;
@@ -8900,8 +8930,7 @@ async function verifyPresentation(vpToken, query, options) {
8900
8930
  if (parsed.trust?.trustedAuthorityIds && parsed.trust.trustedAuthorityIds.length > 0) {
8901
8931
  decoded.trusted_authority_ids = [...parsed.trust.trustedAuthorityIds];
8902
8932
  }
8903
- const rawMatch = matchQuery(query, [decoded]);
8904
- const match = refineUnmatched(query, decoded, rawMatch);
8933
+ const match = matchQuery(query, [decoded]);
8905
8934
  const submission = match.satisfied ? buildSubmission(query, match) : null;
8906
8935
  return {
8907
8936
  parsed,