@0xpolygonid/js-sdk 1.5.1 → 1.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.
Files changed (83) hide show
  1. package/dist/browser/esm/index.js +1685 -468
  2. package/dist/browser/esm/index.js.map +1 -1
  3. package/dist/browser/umd/index.js +1703 -470
  4. package/dist/browser/umd/index.js.map +1 -1
  5. package/dist/node/cjs/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
  6. package/dist/node/cjs/circuits/atomic-query-mtp-v2.js +1 -1
  7. package/dist/node/cjs/circuits/atomic-query-sig-v2-on-chain.js +2 -2
  8. package/dist/node/cjs/circuits/atomic-query-sig-v2.js +11 -14
  9. package/dist/node/cjs/circuits/atomic-query-v3-on-chain.js +320 -0
  10. package/dist/node/cjs/circuits/atomic-query-v3.js +275 -0
  11. package/dist/node/cjs/circuits/common.js +5 -7
  12. package/dist/node/cjs/circuits/comparer.js +57 -2
  13. package/dist/node/cjs/circuits/index.js +4 -0
  14. package/dist/node/cjs/circuits/linked-multi-query.js +128 -0
  15. package/dist/node/cjs/circuits/linked-nullifier.js +57 -0
  16. package/dist/node/cjs/circuits/models.js +25 -1
  17. package/dist/node/cjs/credentials/credential-wallet.js +2 -10
  18. package/dist/node/cjs/credentials/index.js +1 -0
  19. package/dist/node/cjs/credentials/utils.js +23 -0
  20. package/dist/node/cjs/iden3comm/handlers/auth.js +49 -8
  21. package/dist/node/cjs/iden3comm/handlers/contract-request.js +20 -8
  22. package/dist/node/cjs/proof/common.js +104 -1
  23. package/dist/node/cjs/proof/inputs-generator.js +393 -0
  24. package/dist/node/cjs/proof/proof-service.js +105 -372
  25. package/dist/node/cjs/schema-processor/json/parser.js +7 -0
  26. package/dist/node/cjs/schema-processor/json/validator.js +1 -0
  27. package/dist/node/cjs/storage/filters/jsonQuery.js +73 -8
  28. package/dist/node/cjs/utils/did-helper.js +14 -0
  29. package/dist/node/cjs/utils/index.js +2 -0
  30. package/dist/node/cjs/utils/object.js +42 -0
  31. package/dist/node/cjs/verifiable/presentation.js +34 -33
  32. package/dist/node/cjs/verifiable/proof.js +2 -0
  33. package/dist/node/esm/circuits/atomic-query-mtp-v2-on-chain.js +1 -1
  34. package/dist/node/esm/circuits/atomic-query-mtp-v2.js +1 -1
  35. package/dist/node/esm/circuits/atomic-query-sig-v2-on-chain.js +2 -2
  36. package/dist/node/esm/circuits/atomic-query-sig-v2.js +11 -14
  37. package/dist/node/esm/circuits/atomic-query-v3-on-chain.js +315 -0
  38. package/dist/node/esm/circuits/atomic-query-v3.js +270 -0
  39. package/dist/node/esm/circuits/common.js +4 -6
  40. package/dist/node/esm/circuits/comparer.js +55 -1
  41. package/dist/node/esm/circuits/index.js +4 -0
  42. package/dist/node/esm/circuits/linked-multi-query.js +123 -0
  43. package/dist/node/esm/circuits/linked-nullifier.js +52 -0
  44. package/dist/node/esm/circuits/models.js +25 -1
  45. package/dist/node/esm/credentials/credential-wallet.js +2 -10
  46. package/dist/node/esm/credentials/index.js +1 -0
  47. package/dist/node/esm/credentials/utils.js +19 -0
  48. package/dist/node/esm/iden3comm/handlers/auth.js +50 -9
  49. package/dist/node/esm/iden3comm/handlers/contract-request.js +20 -8
  50. package/dist/node/esm/proof/common.js +101 -2
  51. package/dist/node/esm/proof/inputs-generator.js +389 -0
  52. package/dist/node/esm/proof/proof-service.js +111 -377
  53. package/dist/node/esm/schema-processor/json/parser.js +7 -0
  54. package/dist/node/esm/schema-processor/json/validator.js +1 -0
  55. package/dist/node/esm/storage/filters/jsonQuery.js +74 -9
  56. package/dist/node/esm/utils/did-helper.js +10 -0
  57. package/dist/node/esm/utils/index.js +2 -0
  58. package/dist/node/esm/utils/object.js +38 -0
  59. package/dist/node/esm/verifiable/presentation.js +30 -29
  60. package/dist/node/esm/verifiable/proof.js +2 -0
  61. package/dist/types/circuits/atomic-query-mtp-v2.d.ts +13 -13
  62. package/dist/types/circuits/atomic-query-v3-on-chain.d.ts +142 -0
  63. package/dist/types/circuits/atomic-query-v3.d.ts +120 -0
  64. package/dist/types/circuits/common.d.ts +4 -4
  65. package/dist/types/circuits/comparer.d.ts +33 -1
  66. package/dist/types/circuits/index.d.ts +4 -0
  67. package/dist/types/circuits/linked-multi-query.d.ts +38 -0
  68. package/dist/types/circuits/linked-nullifier.d.ts +37 -0
  69. package/dist/types/circuits/models.d.ts +20 -2
  70. package/dist/types/credentials/index.d.ts +1 -0
  71. package/dist/types/credentials/utils.d.ts +12 -0
  72. package/dist/types/iden3comm/types/packer.d.ts +1 -2
  73. package/dist/types/iden3comm/types/protocol/auth.d.ts +1 -0
  74. package/dist/types/proof/common.d.ts +34 -3
  75. package/dist/types/proof/inputs-generator.d.ts +46 -0
  76. package/dist/types/proof/proof-service.d.ts +14 -25
  77. package/dist/types/schema-processor/json/parser.d.ts +1 -0
  78. package/dist/types/storage/filters/jsonQuery.d.ts +1 -1
  79. package/dist/types/utils/did-helper.d.ts +6 -0
  80. package/dist/types/utils/index.d.ts +2 -0
  81. package/dist/types/utils/object.d.ts +12 -0
  82. package/dist/types/verifiable/presentation.d.ts +6 -10
  83. package/package.json +1 -1
@@ -13760,6 +13760,54 @@ var PolygonIdSdk = (function (exports) {
13760
13760
  return b$5.encodeString(b);
13761
13761
  }
13762
13762
 
13763
+ function mergeObjects(credSubject, otherCredSubject) {
13764
+ let result = {};
13765
+ const credSubjectKeys = Object.keys(credSubject);
13766
+ for (const key of credSubjectKeys) {
13767
+ if (typeof otherCredSubject[key] !== 'undefined') {
13768
+ if (typeof credSubject[key] !== 'object' && typeof otherCredSubject[key] !== 'object') {
13769
+ throw new Error('Invalid query');
13770
+ }
13771
+ const subjectProperty = credSubject[key];
13772
+ const otherSubjectProperty = otherCredSubject[key];
13773
+ const propertyOperators = Object.keys(subjectProperty);
13774
+ const subjectPropertyResult = {};
13775
+ for (const operatorKey of propertyOperators) {
13776
+ if (typeof otherSubjectProperty[operatorKey] !== 'undefined') {
13777
+ const operatorValue1 = subjectProperty[operatorKey];
13778
+ const operatorValue2 = otherSubjectProperty[operatorKey];
13779
+ subjectPropertyResult[operatorKey] = [
13780
+ ...new Set([
13781
+ ...(subjectPropertyResult[operatorKey] ?? []),
13782
+ operatorValue1,
13783
+ ...(Array.isArray(operatorValue2) ? operatorValue2 : [operatorValue2])
13784
+ ])
13785
+ ];
13786
+ }
13787
+ else {
13788
+ subjectPropertyResult[operatorKey] = subjectProperty[operatorKey];
13789
+ }
13790
+ }
13791
+ result[key] = {
13792
+ ...otherCredSubject[key],
13793
+ ...subjectPropertyResult
13794
+ };
13795
+ }
13796
+ }
13797
+ // Add remaining keys from obj2
13798
+ result = { ...credSubject, ...otherCredSubject, ...result };
13799
+ return result;
13800
+ }
13801
+
13802
+ const buildVerifierId = (address, info) => {
13803
+ address = address.replace('0x', '');
13804
+ const ethAddrBytes = b$5.decodeString(address);
13805
+ const ethAddr = ethAddrBytes.slice(0, 20);
13806
+ const genesis = O$2(ethAddr);
13807
+ const tp = P$2(info.method, info.blockchain, info.networkId);
13808
+ return new k$2(tp, genesis);
13809
+ };
13810
+
13763
13811
  /**
13764
13812
  * Provider for Sec256p1 keys256p1
13765
13813
  * @public
@@ -14182,6 +14230,7 @@ var PolygonIdSdk = (function (exports) {
14182
14230
  mtp: this.mtp.toJSON()
14183
14231
  };
14184
14232
  }
14233
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14185
14234
  static fromJSON(obj) {
14186
14235
  let mtp;
14187
14236
  if (obj?.mtp?.notEmpties && obj?.mtp?.depth && obj?.mtp?.siblings) {
@@ -14260,6 +14309,7 @@ var PolygonIdSdk = (function (exports) {
14260
14309
  * fromJSON is a method to deserialize BJJSignatureProof2021 from json
14261
14310
  * @param obj
14262
14311
  */
14312
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14263
14313
  static fromJSON(obj) {
14264
14314
  return new BJJSignatureProof2021({
14265
14315
  issuerData: {
@@ -14547,19 +14597,23 @@ var PolygonIdSdk = (function (exports) {
14547
14597
  }
14548
14598
  return value.toString();
14549
14599
  };
14550
- const buildQueryPath = async (contextURL, contextType, field, opts) => {
14551
- let resp;
14552
- try {
14553
- resp = await (await fetch(contextURL)).json();
14600
+ const buildFieldPath = async (ldSchema, contextType, field, opts) => {
14601
+ let path = new lf();
14602
+ if (field) {
14603
+ path = await lf.getContextPathKey(ldSchema, contextType, field, opts);
14554
14604
  }
14555
- catch (error) {
14556
- throw new Error(`context not found: ${error.message}`);
14557
- }
14558
- const path = await lf.getContextPathKey(JSON.stringify(resp), contextType, field, opts);
14559
14605
  path.prepend([VerifiableConstants.CREDENTIAL_SUBJECT_PATH]);
14560
14606
  return path;
14561
14607
  };
14562
- const createVerifiablePresentation = (context, tp, path, value) => {
14608
+ const findValue = (fieldName, credential) => {
14609
+ const [first, ...rest] = fieldName.split('.');
14610
+ let v = credential.credentialSubject[first];
14611
+ for (const part of rest) {
14612
+ v = v[part];
14613
+ }
14614
+ return v;
14615
+ };
14616
+ const createVerifiablePresentation = (context, tp, credential, queries) => {
14563
14617
  const baseContext = [VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018];
14564
14618
  const ldContext = baseContext[0] === context ? baseContext : [...baseContext, context];
14565
14619
  const vc = VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_CREDENTIAL;
@@ -14567,36 +14621,33 @@ var PolygonIdSdk = (function (exports) {
14567
14621
  if (tp !== vc) {
14568
14622
  vcTypes.push(tp);
14569
14623
  }
14570
- const [first, ...rest] = path.split('.');
14571
- const obj = rest.reduceRight((acc, key) => ({ [key]: acc }), value);
14572
- return {
14624
+ const skeleton = {
14573
14625
  '@context': baseContext,
14574
14626
  '@type': VerifiableConstants.CREDENTIAL_TYPE.W3C_VERIFIABLE_PRESENTATION,
14575
14627
  verifiableCredential: {
14576
14628
  '@context': ldContext,
14577
14629
  '@type': vcTypes,
14578
14630
  credentialSubject: {
14579
- '@type': tp,
14580
- [first]: obj
14631
+ '@type': tp
14581
14632
  }
14582
14633
  }
14583
14634
  };
14584
- };
14585
- const verifiablePresentationFromCred = async (w3cCred, requestObj, field, opts) => {
14586
- const mz = await w3cCred.merklize(opts);
14587
- const request = requestObj;
14588
- const contextType = stringByPath(request, 'type');
14589
- const hasher = mz.hasher;
14590
- const contextURL = stringByPath(request, 'context');
14591
- const path = await buildQueryPath(contextURL, contextType, field, opts);
14592
- const dataType = await mz.jsonLDType(path);
14593
- const rawValue = mz.rawValue(path);
14594
- const { value } = await mz.proof(path);
14595
- const vp = createVerifiablePresentation(contextURL, contextType, field, rawValue);
14596
- if (!value) {
14597
- throw new Error(`can't merklize verifiable presentation`);
14598
- }
14599
- return { vp, mzValue: value, dataType, hasher };
14635
+ let result = {};
14636
+ for (const query of queries) {
14637
+ const parts = query.fieldName.split('.');
14638
+ const current = parts.reduceRight((acc, part) => {
14639
+ if (result[part]) {
14640
+ return { [part]: { ...result[part], ...acc } };
14641
+ }
14642
+ return { [part]: acc };
14643
+ }, findValue(query.fieldName, credential));
14644
+ result = { ...result, ...current };
14645
+ }
14646
+ skeleton.verifiableCredential.credentialSubject = {
14647
+ ...skeleton.verifiableCredential.credentialSubject,
14648
+ ...result
14649
+ };
14650
+ return skeleton;
14600
14651
  };
14601
14652
 
14602
14653
  /** DIDDocumentJSONSchema is a basic schema of did document */
@@ -27671,6 +27722,13 @@ var PolygonIdSdk = (function (exports) {
27671
27722
  const ldCtx = await jsonld.processContext(context.getInitialContext({}), credential['@context'], opts);
27672
27723
  return Parser.getSerializationAttrFromParsedContext(ldCtx, tp);
27673
27724
  }
27725
+ // Get `iden3_serialization` attr definition from context document either using
27726
+ // type name like DeliverAddressMultiTestForked or by type id like
27727
+ // urn:uuid:ac2ede19-b3b9-454d-b1a9-a7b3d5763100.
27728
+ static async getSerializationAttrFromContext(context$1, opts, tp) {
27729
+ const ldCtx = await jsonld.processContext(context.getInitialContext({}), context$1, opts);
27730
+ return Parser.getSerializationAttrFromParsedContext(ldCtx, tp);
27731
+ }
27674
27732
  static async getSerializationAttrFromParsedContext(ldCtx, tp) {
27675
27733
  const termDef = ldCtx.mappings;
27676
27734
  if (!termDef) {
@@ -36939,6 +36997,7 @@ var PolygonIdSdk = (function (exports) {
36939
36997
  const validate = (schema.$id ? validator.getSchema(schema.$id) : undefined) || validator.compile(schema);
36940
36998
  const valid = validate(data);
36941
36999
  if (!valid) {
37000
+ // TODO: extract correct error messages
36942
37001
  throw new Error(validate.errors?.map((e) => e.message).join(', '));
36943
37002
  }
36944
37003
  return true;
@@ -55288,7 +55347,7 @@ var PolygonIdSdk = (function (exports) {
55288
55347
  const defaultMTLevels = 40; // max MT levels, default value for identity circuits
55289
55348
  const defaultValueArraySize = 64; // max value array size, default value for identity circuits
55290
55349
  const defaultMTLevelsOnChain = 64; // max MT levels on chain, default value for identity circuits
55291
- const defaultMTLevelsClaimsMerklization = 32; // max MT levels of JSON-LD merklization on claim
55350
+ const defaultMTLevelsClaim = 32; // max MT levels of JSON-LD merklization on claim
55292
55351
  const ErrorEmptyAuthClaimProof = 'empty auth claim mtp proof';
55293
55352
  const ErrorEmptyAuthClaimNonRevProof = 'empty auth claim non-revocation mtp proof';
55294
55353
  const ErrorEmptyChallengeSignature = 'empty challenge signature';
@@ -55314,14 +55373,12 @@ var PolygonIdSdk = (function (exports) {
55314
55373
  return this.mtLevel ? this.mtLevel : defaultMTLevels;
55315
55374
  }
55316
55375
  /**
55317
- * getMTLevel max circuit MT levels
55376
+ * GetMTLevelsClaim max jsonld Claim levels
55318
55377
  *
55319
55378
  * @returns number
55320
55379
  */
55321
- getMTLevelsClaimMerklization() {
55322
- return this.mtLevelClaimsMerklization
55323
- ? this.mtLevelClaimsMerklization
55324
- : defaultMTLevelsClaimsMerklization;
55380
+ getMTLevelsClaim() {
55381
+ return this.mtLevelClaim ? this.mtLevelClaim : defaultMTLevelsClaim;
55325
55382
  }
55326
55383
  /**
55327
55384
  * GetValueArrSize return size of circuits value array size
@@ -55465,6 +55522,21 @@ var PolygonIdSdk = (function (exports) {
55465
55522
  return result;
55466
55523
  }
55467
55524
 
55525
+ /**
55526
+ * Represents the XSD namespace and its corresponding data types.
55527
+ */
55528
+ exports.XSDNS = void 0;
55529
+ (function (XSDNS) {
55530
+ XSDNS["Boolean"] = "http://www.w3.org/2001/XMLSchema#boolean";
55531
+ XSDNS["Integer"] = "http://www.w3.org/2001/XMLSchema#integer";
55532
+ XSDNS["NonNegativeInteger"] = "http://www.w3.org/2001/XMLSchema#nonNegativeInteger";
55533
+ XSDNS["NonPositiveInteger"] = "http://www.w3.org/2001/XMLSchema#nonPositiveInteger";
55534
+ XSDNS["NegativeInteger"] = "http://www.w3.org/2001/XMLSchema#negativeInteger";
55535
+ XSDNS["PositiveInteger"] = "http://www.w3.org/2001/XMLSchema#positiveInteger";
55536
+ XSDNS["DateTime"] = "http://www.w3.org/2001/XMLSchema#dateTime";
55537
+ XSDNS["Double"] = "http://www.w3.org/2001/XMLSchema#double";
55538
+ XSDNS["String"] = "http://www.w3.org/2001/XMLSchema#string";
55539
+ })(exports.XSDNS || (exports.XSDNS = {}));
55468
55540
  /**
55469
55541
  * List of available operators.
55470
55542
  *
@@ -55479,6 +55551,11 @@ var PolygonIdSdk = (function (exports) {
55479
55551
  Operators[Operators["IN"] = 4] = "IN";
55480
55552
  Operators[Operators["NIN"] = 5] = "NIN";
55481
55553
  Operators[Operators["NE"] = 6] = "NE";
55554
+ Operators[Operators["LTE"] = 7] = "LTE";
55555
+ Operators[Operators["GTE"] = 8] = "GTE";
55556
+ Operators[Operators["BETWEEN"] = 9] = "BETWEEN";
55557
+ Operators[Operators["SD"] = 16] = "SD";
55558
+ Operators[Operators["NULLIFY"] = 17] = "NULLIFY";
55482
55559
  })(exports.Operators || (exports.Operators = {}));
55483
55560
  /** QueryOperators represents operators for atomic circuits */
55484
55561
  const QueryOperators = {
@@ -55488,7 +55565,41 @@ var PolygonIdSdk = (function (exports) {
55488
55565
  $gt: exports.Operators.GT,
55489
55566
  $in: exports.Operators.IN,
55490
55567
  $nin: exports.Operators.NIN,
55491
- $ne: exports.Operators.NE
55568
+ $ne: exports.Operators.NE,
55569
+ $lte: exports.Operators.LTE,
55570
+ $gte: exports.Operators.GTE,
55571
+ $between: exports.Operators.BETWEEN,
55572
+ $sd: exports.Operators.SD,
55573
+ $nullify: exports.Operators.NULLIFY
55574
+ };
55575
+ const allOperations = Object.values(QueryOperators);
55576
+ const availableTypesOperators = new Map([
55577
+ [exports.XSDNS.Boolean, [QueryOperators.$eq, QueryOperators.$ne]],
55578
+ [exports.XSDNS.Integer, allOperations],
55579
+ [exports.XSDNS.NonNegativeInteger, allOperations],
55580
+ [exports.XSDNS.PositiveInteger, allOperations],
55581
+ [exports.XSDNS.Double, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$in, QueryOperators.$nin]],
55582
+ [exports.XSDNS.String, [QueryOperators.$eq, QueryOperators.$ne, QueryOperators.$in, QueryOperators.$nin]],
55583
+ [exports.XSDNS.DateTime, allOperations]
55584
+ ]);
55585
+ /**
55586
+ * Checks if the given operation is valid for the specified datatype.
55587
+ * @param datatype - The datatype to check the operation for.
55588
+ * @param op - The operation to check.
55589
+ * @returns True if the operation is valid, false otherwise.
55590
+ */
55591
+ const isValidOperation = (datatype, op) => {
55592
+ if (op === exports.Operators.NOOP) {
55593
+ return true;
55594
+ }
55595
+ if (!availableTypesOperators.has(datatype)) {
55596
+ return false;
55597
+ }
55598
+ const ops = availableTypesOperators.get(datatype);
55599
+ if (!ops) {
55600
+ return false;
55601
+ }
55602
+ return ops.includes(op);
55492
55603
  };
55493
55604
  /**
55494
55605
  * Scalar is used to compare two scalar value.
@@ -55600,7 +55711,9 @@ var PolygonIdSdk = (function (exports) {
55600
55711
  *
55601
55712
  */
55602
55713
  validate() {
55603
- if (this.operator !== QueryOperators.$noop && this.values?.some((v) => typeof v !== 'bigint'))
55714
+ if (this.operator !== QueryOperators.$noop &&
55715
+ this.operator !== QueryOperators.$sd &&
55716
+ this.values?.some((v) => typeof v !== 'bigint'))
55604
55717
  throw new Error(exports.CircuitError.EmptyQueryValue);
55605
55718
  }
55606
55719
  }
@@ -55623,6 +55736,26 @@ var PolygonIdSdk = (function (exports) {
55623
55736
  CircuitId["AtomicQuerySigV2"] = "credentialAtomicQuerySigV2";
55624
55737
  // AtomicQuerySigOnChain is a type for credentialAtomicQuerySigOnChain.circom
55625
55738
  CircuitId["AtomicQuerySigV2OnChain"] = "credentialAtomicQuerySigV2OnChain";
55739
+ /**
55740
+ * @beta
55741
+ */
55742
+ // AtomicQueryV3CircuitID is a type for credentialAtomicQueryV3.circom
55743
+ CircuitId["AtomicQueryV3"] = "credentialAtomicQueryV3-beta.0";
55744
+ /**
55745
+ * @beta
55746
+ */
55747
+ // AtomicQueryV3OnChainCircuitID is a type for credentialAtomicQueryV3OnChain.circom
55748
+ CircuitId["AtomicQueryV3OnChain"] = "credentialAtomicQueryV3OnChain-beta.0";
55749
+ /**
55750
+ * @beta
55751
+ */
55752
+ // LinkedNullifier is a type for linkedNullifier.circom
55753
+ CircuitId["LinkedNullifier"] = "linkedNullifier-beta.0";
55754
+ /**
55755
+ * @beta
55756
+ */
55757
+ // LinkedMultiQuery is a type for linkedMultiQuery.circom
55758
+ CircuitId["LinkedMultiQuery10"] = "linkedMultiQuery10-beta.0";
55626
55759
  })(exports.CircuitId || (exports.CircuitId = {}));
55627
55760
  /**
55628
55761
  * Claim structure for circuit inputs
@@ -55656,7 +55789,9 @@ var PolygonIdSdk = (function (exports) {
55656
55789
  CircuitError["EmptyId"] = "empty Id";
55657
55790
  CircuitError["EmptyChallenge"] = "empty challenge";
55658
55791
  CircuitError["EmptyGISTProof"] = "empty GIST merkle tree proof";
55792
+ CircuitError["EmptyTreeState"] = "empty tree state";
55659
55793
  CircuitError["EmptyRequestID"] = "empty request ID";
55794
+ CircuitError["InvalidProofType"] = "invalid proof type";
55660
55795
  })(exports.CircuitError || (exports.CircuitError = {}));
55661
55796
  /**
55662
55797
  * ValueProof represents a Merkle Proof for a value stored as MT
@@ -55745,7 +55880,7 @@ var PolygonIdSdk = (function (exports) {
55745
55880
  .toString(),
55746
55881
  issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(),
55747
55882
  claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
55748
- claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()),
55883
+ claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
55749
55884
  claimPathValue: valueProof.value.toString(),
55750
55885
  operator: this.query.operator,
55751
55886
  slotIndex: this.query.slotIndex,
@@ -55926,7 +56061,7 @@ var PolygonIdSdk = (function (exports) {
55926
56061
  issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots?.string(),
55927
56062
  issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.string(),
55928
56063
  claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
55929
- claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()),
56064
+ claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
55930
56065
  claimPathValue: valueProof.value.toString(),
55931
56066
  operator: this.query.operator,
55932
56067
  slotIndex: this.query.slotIndex,
@@ -56083,6 +56218,9 @@ var PolygonIdSdk = (function (exports) {
56083
56218
  this.query.valueProof.validate();
56084
56219
  }
56085
56220
  const valueProof = this.query.valueProof ?? new ValueProof();
56221
+ const treeState = this.skipClaimRevocationCheck
56222
+ ? this.claim.signatureProof?.issuerAuthNonRevProof.treeState
56223
+ : this.claim.nonRevProof?.treeState;
56086
56224
  const s = {
56087
56225
  requestID: this.requestID.toString(),
56088
56226
  userGenesisID: this.id.bigInt().toString(),
@@ -56090,16 +56228,10 @@ var PolygonIdSdk = (function (exports) {
56090
56228
  claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(),
56091
56229
  issuerID: this.claim.issuerID?.bigInt().toString(),
56092
56230
  issuerClaim: this.claim.claim?.marshalJson(),
56093
- issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot
56094
- ?.bigInt()
56095
- .toString(),
56096
- issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot
56097
- ?.bigInt()
56098
- .toString(),
56099
- issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots
56100
- ?.bigInt()
56101
- .toString(),
56102
- issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(),
56231
+ issuerClaimNonRevClaimsTreeRoot: treeState?.claimsRoot.bigInt().toString(),
56232
+ issuerClaimNonRevRevTreeRoot: treeState?.revocationRoot.bigInt().toString(),
56233
+ issuerClaimNonRevRootsTreeRoot: treeState?.rootOfRoots.bigInt().toString(),
56234
+ issuerClaimNonRevState: treeState?.state.bigInt().toString(),
56103
56235
  issuerClaimNonRevMtp: this.claim.nonRevProof?.proof &&
56104
56236
  prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
56105
56237
  issuerClaimSignatureR8x: this.claim.signatureProof?.signature.R8[0].toString(),
@@ -56109,18 +56241,18 @@ var PolygonIdSdk = (function (exports) {
56109
56241
  issuerAuthClaimMtp: this.claim.signatureProof?.issuerAuthIncProof?.proof &&
56110
56242
  prepareSiblingsStr(this.claim.signatureProof.issuerAuthIncProof.proof, this.getMTLevel()),
56111
56243
  issuerAuthClaimsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof.treeState?.claimsRoot
56112
- ?.bigInt()
56244
+ .bigInt()
56113
56245
  .toString(),
56114
56246
  issuerAuthRevTreeRoot: this.claim.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot
56115
- ?.bigInt()
56247
+ .bigInt()
56116
56248
  .toString(),
56117
56249
  issuerAuthRootsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots
56118
- ?.bigInt()
56250
+ .bigInt()
56119
56251
  .toString(),
56120
56252
  issuerAuthClaimNonRevMtp: this.claim.signatureProof?.issuerAuthNonRevProof?.proof &&
56121
56253
  prepareSiblingsStr(this.claim.signatureProof.issuerAuthNonRevProof.proof, this.getMTLevel()),
56122
56254
  claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
56123
- claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()),
56255
+ claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
56124
56256
  claimPathValue: valueProof.value.toString(),
56125
56257
  operator: this.query.operator,
56126
56258
  timestamp: this.currentTimeStamp,
@@ -56250,6 +56382,581 @@ var PolygonIdSdk = (function (exports) {
56250
56382
  }
56251
56383
  }
56252
56384
 
56385
+ const zero$2 = '0';
56386
+ /**
56387
+ * AtomicQueryV3Inputs ZK private inputs for credentialAtomicQueryV3.circom
56388
+ *
56389
+ * @beta
56390
+ * @class AtomicQueryV3Inputs
56391
+ * @extends {BaseConfig}
56392
+ */
56393
+ class AtomicQueryV3Inputs extends BaseConfig {
56394
+ validate() {
56395
+ if (!this.requestID) {
56396
+ throw new Error(exports.CircuitError.EmptyRequestID);
56397
+ }
56398
+ if (!this.claim.nonRevProof.proof) {
56399
+ throw new Error(exports.CircuitError.EmptyClaimNonRevProof);
56400
+ }
56401
+ if (!this.query.values) {
56402
+ throw new Error(exports.CircuitError.EmptyQueryValue);
56403
+ }
56404
+ if (!this.proofType) {
56405
+ throw new Error(exports.CircuitError.InvalidProofType);
56406
+ }
56407
+ if (this.proofType === exports.ProofType.BJJSignature) {
56408
+ if (!this.claim.signatureProof?.issuerAuthIncProof.proof) {
56409
+ throw new Error(exports.CircuitError.EmptyIssuerAuthClaimProof);
56410
+ }
56411
+ if (!this.claim.signatureProof.issuerAuthNonRevProof.proof) {
56412
+ throw new Error(exports.CircuitError.EmptyIssuerAuthClaimNonRevProof);
56413
+ }
56414
+ if (!this.claim.signatureProof.signature) {
56415
+ throw new Error(exports.CircuitError.EmptyClaimSignature);
56416
+ }
56417
+ }
56418
+ if (this.proofType === exports.ProofType.Iden3SparseMerkleTreeProof) {
56419
+ if (!this.claim?.incProof?.proof) {
56420
+ throw new Error(exports.CircuitError.EmptyClaimProof);
56421
+ }
56422
+ }
56423
+ }
56424
+ fillMTPProofsWithZero(s) {
56425
+ s.issuerClaimMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56426
+ s.issuerClaimClaimsTreeRoot = M$2.bigInt().toString();
56427
+ s.issuerClaimRevTreeRoot = M$2.bigInt().toString();
56428
+ s.issuerClaimRootsTreeRoot = M$2.bigInt().toString();
56429
+ s.issuerClaimIdenState = M$2.bigInt().toString();
56430
+ }
56431
+ fillSigProofWithZero(s) {
56432
+ s.issuerClaimSignatureR8x = zero$2;
56433
+ s.issuerClaimSignatureR8y = zero$2;
56434
+ s.issuerClaimSignatureS = zero$2;
56435
+ s.issuerAuthClaim = new v$3().marshalJson();
56436
+ s.issuerAuthClaimMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56437
+ s.issuerAuthClaimsTreeRoot = zero$2;
56438
+ s.issuerAuthRevTreeRoot = zero$2;
56439
+ s.issuerAuthRootsTreeRoot = zero$2;
56440
+ s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56441
+ s.issuerAuthClaimNonRevMtpAuxHi = M$2.bigInt().toString();
56442
+ s.issuerAuthClaimNonRevMtpAuxHv = M$2.bigInt().toString();
56443
+ s.issuerAuthClaimNonRevMtpNoAux = zero$2;
56444
+ s.issuerAuthState = zero$2;
56445
+ }
56446
+ // InputsMarshal returns Circom private inputs for credentialAtomicQueryV3.circom
56447
+ inputsMarshal() {
56448
+ this.validate();
56449
+ if (this.query.valueProof) {
56450
+ this.query.validate();
56451
+ this.query.valueProof.validate();
56452
+ }
56453
+ let valueProof = this.query.valueProof;
56454
+ if (!valueProof) {
56455
+ valueProof = new ValueProof();
56456
+ valueProof.path = 0n;
56457
+ valueProof.value = 0n;
56458
+ valueProof.mtp = new Kt$1();
56459
+ }
56460
+ let treeState = this.claim.nonRevProof.treeState;
56461
+ if (this.proofType === exports.ProofType.BJJSignature && this.skipClaimRevocationCheck) {
56462
+ treeState = this.claim.signatureProof?.issuerAuthNonRevProof.treeState;
56463
+ }
56464
+ if (!treeState) {
56465
+ throw new Error(exports.CircuitError.EmptyTreeState);
56466
+ }
56467
+ const s = {
56468
+ requestID: this.requestID.toString(),
56469
+ userGenesisID: this.id.bigInt().toString(),
56470
+ profileNonce: this.profileNonce.toString(),
56471
+ claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
56472
+ issuerID: this.claim.issuerID.bigInt().toString(),
56473
+ issuerClaim: this.claim.claim.marshalJson(),
56474
+ issuerClaimNonRevClaimsTreeRoot: treeState.claimsRoot.bigInt().toString(),
56475
+ issuerClaimNonRevRevTreeRoot: treeState.revocationRoot.bigInt().toString(),
56476
+ issuerClaimNonRevRootsTreeRoot: treeState.rootOfRoots.bigInt().toString(),
56477
+ issuerClaimNonRevState: treeState.state.bigInt().toString(),
56478
+ issuerClaimNonRevMtp: prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
56479
+ claimSchema: this.claim.claim.getSchemaHash().bigInt().toString(),
56480
+ claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
56481
+ claimPathValue: valueProof.value.toString(),
56482
+ operator: this.query.operator,
56483
+ timestamp: this.currentTimeStamp,
56484
+ // value in this path in merklized json-ld document
56485
+ slotIndex: this.query.slotIndex,
56486
+ isRevocationChecked: 1
56487
+ };
56488
+ if (this.skipClaimRevocationCheck) {
56489
+ s.isRevocationChecked = 0;
56490
+ }
56491
+ if (this.proofType === exports.ProofType.BJJSignature) {
56492
+ s.proofType = '1';
56493
+ s.issuerClaimSignatureR8x = this.claim.signatureProof?.signature.R8[0].toString();
56494
+ s.issuerClaimSignatureR8y = this.claim.signatureProof?.signature.R8[1].toString();
56495
+ s.issuerClaimSignatureS = this.claim.signatureProof?.signature.S.toString();
56496
+ s.issuerAuthClaim = this.claim.signatureProof?.issuerAuthClaim?.marshalJson();
56497
+ s.issuerAuthClaimMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthIncProof.proof, this.getMTLevel());
56498
+ s.issuerAuthClaimsTreeRoot = treeState.claimsRoot.bigInt().toString();
56499
+ s.issuerAuthRevTreeRoot = treeState.revocationRoot.bigInt().toString();
56500
+ s.issuerAuthRootsTreeRoot = treeState.rootOfRoots.bigInt().toString();
56501
+ s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthNonRevProof.proof, this.getMTLevel());
56502
+ const nodeAuxIssuerAuthNonRev = getNodeAuxValue(this.claim.signatureProof?.issuerAuthNonRevProof.proof);
56503
+ s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key.bigInt().toString();
56504
+ s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value.bigInt().toString();
56505
+ s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux;
56506
+ s.issuerAuthState = this.claim.signatureProof?.issuerAuthIncProof.treeState?.state
56507
+ .bigInt()
56508
+ .toString();
56509
+ this.fillMTPProofsWithZero(s);
56510
+ }
56511
+ else if (this.proofType === exports.ProofType.Iden3SparseMerkleTreeProof) {
56512
+ s.proofType = '2';
56513
+ const incProofTreeState = this.claim.incProof?.treeState;
56514
+ if (!incProofTreeState) {
56515
+ throw new Error(exports.CircuitError.EmptyTreeState);
56516
+ }
56517
+ s.issuerClaimMtp = prepareSiblingsStr(this.claim.incProof?.proof, this.getMTLevel());
56518
+ s.issuerClaimClaimsTreeRoot = incProofTreeState.claimsRoot.bigInt().toString();
56519
+ s.issuerClaimRevTreeRoot = incProofTreeState.revocationRoot.bigInt().toString();
56520
+ s.issuerClaimRootsTreeRoot = incProofTreeState.rootOfRoots.bigInt().toString();
56521
+ s.issuerClaimIdenState = incProofTreeState.state.bigInt().toString();
56522
+ this.fillSigProofWithZero(s);
56523
+ }
56524
+ const nodeAuxNonRev = getNodeAuxValue(this.claim.nonRevProof.proof);
56525
+ s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
56526
+ s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
56527
+ s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
56528
+ s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
56529
+ const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
56530
+ s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
56531
+ s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
56532
+ s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
56533
+ s.claimPathKey = valueProof.path.toString();
56534
+ const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
56535
+ s.value = bigIntArrayToStringArray(values);
56536
+ s.linkNonce = this.linkNonce.toString();
56537
+ s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
56538
+ s.nullifierSessionID = this.nullifierSessionID.toString();
56539
+ return byteEncoder.encode(JSON.stringify(s));
56540
+ }
56541
+ }
56542
+ /**
56543
+ * @beta
56544
+ * AtomicQueryV3PubSignals public inputs
56545
+ */
56546
+ class AtomicQueryV3PubSignals extends BaseConfig {
56547
+ constructor() {
56548
+ super(...arguments);
56549
+ this.value = [];
56550
+ }
56551
+ // PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
56552
+ pubSignalsUnmarshal(data) {
56553
+ // expected order:
56554
+ // merklized
56555
+ // userID
56556
+ // issuerState
56557
+ // linkID
56558
+ // nullifier
56559
+ // operatorOutput
56560
+ // proofType
56561
+ // requestID
56562
+ // issuerID
56563
+ // isRevocationChecked
56564
+ // issuerClaimNonRevState
56565
+ // timestamp
56566
+ // claimSchema
56567
+ // claimPathNotExists
56568
+ // claimPathKey
56569
+ // slotIndex
56570
+ // operator
56571
+ // value
56572
+ // verifierID
56573
+ // nullifierSessionID
56574
+ // 19 is a number of fields in AtomicQueryV3PubSignals before values, values is last element in the proof and
56575
+ // it is length could be different base on the circuit configuration. The length could be modified by set value
56576
+ // in ValueArraySize
56577
+ const fieldLength = 19;
56578
+ const sVals = JSON.parse(byteDecoder.decode(data));
56579
+ if (sVals.length !== fieldLength + this.getValueArrSize()) {
56580
+ throw new Error(`invalid number of Output values expected ${fieldLength + this.getValueArrSize()} got ${sVals.length}`);
56581
+ }
56582
+ let fieldIdx = 0;
56583
+ // -- merklized
56584
+ this.merklized = parseInt(sVals[fieldIdx]);
56585
+ fieldIdx++;
56586
+ // - userID
56587
+ this.userID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
56588
+ fieldIdx++;
56589
+ // - issuerState
56590
+ this.issuerState = V$1.fromString(sVals[fieldIdx]);
56591
+ fieldIdx++;
56592
+ // - linkID
56593
+ this.linkID = BigInt(sVals[fieldIdx]);
56594
+ fieldIdx++;
56595
+ // - nullifier
56596
+ this.nullifier = BigInt(sVals[fieldIdx]);
56597
+ fieldIdx++;
56598
+ // - operatorOutput
56599
+ this.operatorOutput = BigInt(sVals[fieldIdx]);
56600
+ fieldIdx++;
56601
+ // - proofType
56602
+ this.proofType = parseInt(sVals[fieldIdx]);
56603
+ fieldIdx++;
56604
+ // - requestID
56605
+ this.requestID = BigInt(sVals[fieldIdx]);
56606
+ fieldIdx++;
56607
+ // - issuerID
56608
+ this.issuerID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
56609
+ fieldIdx++;
56610
+ // - isRevocationChecked
56611
+ this.isRevocationChecked = parseInt(sVals[fieldIdx]);
56612
+ fieldIdx++;
56613
+ // - issuerClaimNonRevState
56614
+ this.issuerClaimNonRevState = V$1.fromString(sVals[fieldIdx]);
56615
+ fieldIdx++;
56616
+ // - timestamp
56617
+ this.timestamp = parseInt(sVals[fieldIdx]);
56618
+ fieldIdx++;
56619
+ // - claimSchema
56620
+ this.claimSchema = B$3.newSchemaHashFromInt(BigInt(sVals[fieldIdx]));
56621
+ fieldIdx++;
56622
+ // - ClaimPathNotExists
56623
+ this.claimPathNotExists = parseInt(sVals[fieldIdx]);
56624
+ fieldIdx++;
56625
+ // - ClaimPathKey
56626
+ this.claimPathKey = BigInt(sVals[fieldIdx]);
56627
+ fieldIdx++;
56628
+ // - slotIndex
56629
+ this.slotIndex = parseInt(sVals[fieldIdx]);
56630
+ fieldIdx++;
56631
+ // - operator
56632
+ this.operator = parseInt(sVals[fieldIdx]);
56633
+ fieldIdx++;
56634
+ // - values
56635
+ for (let index = 0; index < this.getValueArrSize(); index++) {
56636
+ this.value.push(BigInt(sVals[fieldIdx]));
56637
+ fieldIdx++;
56638
+ }
56639
+ // - verifierID
56640
+ if (sVals[fieldIdx] !== '0') {
56641
+ this.verifierID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
56642
+ }
56643
+ fieldIdx++;
56644
+ // - nullifierSessionID
56645
+ this.nullifierSessionID = BigInt(sVals[fieldIdx]);
56646
+ return this;
56647
+ }
56648
+ }
56649
+
56650
+ const zero$1 = '0';
56651
+ /**
56652
+ * AtomicQueryV3OnChainInputs ZK private inputs for credentialAtomicQueryV3OnChain.circom
56653
+ *
56654
+ * @beta
56655
+ * @class AtomicQueryV3OnChainInputs
56656
+ * @extends {BaseConfig}
56657
+ */
56658
+ class AtomicQueryV3OnChainInputs extends BaseConfig {
56659
+ validate() {
56660
+ if (!this.requestID) {
56661
+ throw new Error(exports.CircuitError.EmptyRequestID);
56662
+ }
56663
+ if (!this.claim.nonRevProof.proof) {
56664
+ throw new Error(exports.CircuitError.EmptyClaimNonRevProof);
56665
+ }
56666
+ if (!this.query.values) {
56667
+ throw new Error(exports.CircuitError.EmptyQueryValue);
56668
+ }
56669
+ if (!this.proofType) {
56670
+ throw new Error(exports.CircuitError.InvalidProofType);
56671
+ }
56672
+ if (!this.challenge) {
56673
+ throw new Error(exports.CircuitError.EmptyChallenge);
56674
+ }
56675
+ if (this.authEnabled === 1) {
56676
+ if (!this.authClaimIncMtp) {
56677
+ throw new Error(exports.CircuitError.EmptyAuthClaimProof);
56678
+ }
56679
+ if (!this.authClaimNonRevMtp) {
56680
+ throw new Error(exports.CircuitError.EmptyAuthClaimNonRevProof);
56681
+ }
56682
+ if (!this.signature) {
56683
+ throw new Error(exports.CircuitError.EmptyChallengeSignature);
56684
+ }
56685
+ if (!this.gistProof.proof) {
56686
+ throw new Error(exports.CircuitError.EmptyGISTProof);
56687
+ }
56688
+ }
56689
+ if (this.proofType === exports.ProofType.BJJSignature) {
56690
+ if (!this.claim.signatureProof?.issuerAuthIncProof.proof) {
56691
+ throw new Error(exports.CircuitError.EmptyIssuerAuthClaimProof);
56692
+ }
56693
+ if (!this.claim.signatureProof.issuerAuthNonRevProof.proof) {
56694
+ throw new Error(exports.CircuitError.EmptyIssuerAuthClaimNonRevProof);
56695
+ }
56696
+ if (!this.claim.signatureProof.signature) {
56697
+ throw new Error(exports.CircuitError.EmptyClaimSignature);
56698
+ }
56699
+ }
56700
+ if (this.proofType === exports.ProofType.Iden3SparseMerkleTreeProof) {
56701
+ if (!this.claim?.incProof?.proof) {
56702
+ throw new Error(exports.CircuitError.EmptyClaimProof);
56703
+ }
56704
+ }
56705
+ }
56706
+ fillMTPProofsWithZero(s) {
56707
+ s.issuerClaimMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56708
+ s.issuerClaimClaimsTreeRoot = M$2.bigInt().toString();
56709
+ s.issuerClaimRevTreeRoot = M$2.bigInt().toString();
56710
+ s.issuerClaimRootsTreeRoot = M$2.bigInt().toString();
56711
+ s.issuerClaimIdenState = M$2.bigInt().toString();
56712
+ }
56713
+ fillSigProofWithZero(s) {
56714
+ s.issuerClaimSignatureR8x = zero$1;
56715
+ s.issuerClaimSignatureR8y = zero$1;
56716
+ s.issuerClaimSignatureS = zero$1;
56717
+ s.issuerAuthClaim = new v$3().marshalJson();
56718
+ s.issuerAuthClaimMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56719
+ s.issuerAuthClaimsTreeRoot = zero$1;
56720
+ s.issuerAuthRevTreeRoot = zero$1;
56721
+ s.issuerAuthRootsTreeRoot = zero$1;
56722
+ s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56723
+ s.issuerAuthClaimNonRevMtpAuxHi = M$2.bigInt().toString();
56724
+ s.issuerAuthClaimNonRevMtpAuxHv = M$2.bigInt().toString();
56725
+ s.issuerAuthClaimNonRevMtpNoAux = zero$1;
56726
+ s.issuerAuthState = zero$1;
56727
+ }
56728
+ fillAuthWithZero(s) {
56729
+ s.authClaim = new v$3().marshalJson();
56730
+ s.userClaimsTreeRoot = M$2.bigInt().toString();
56731
+ s.userRevTreeRoot = M$2.bigInt().toString();
56732
+ s.userRootsTreeRoot = M$2.bigInt().toString();
56733
+ s.userState = M$2.bigInt().toString();
56734
+ s.authClaimIncMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56735
+ s.authClaimNonRevMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevel());
56736
+ s.challengeSignatureR8x = zero$1;
56737
+ s.challengeSignatureR8y = zero$1;
56738
+ s.challengeSignatureS = zero$1;
56739
+ s.gistRoot = M$2.bigInt().toString();
56740
+ s.gistMtp = prepareSiblingsStr(new Kt$1(), this.getMTLevelOnChain());
56741
+ s.authClaimNonRevMtpAuxHi = M$2.bigInt().toString();
56742
+ s.authClaimNonRevMtpAuxHv = M$2.bigInt().toString();
56743
+ s.authClaimNonRevMtpNoAux = zero$1;
56744
+ s.gistMtpAuxHi = M$2.bigInt().toString();
56745
+ s.gistMtpAuxHv = M$2.bigInt().toString();
56746
+ s.gistMtpNoAux = zero$1;
56747
+ }
56748
+ // InputsMarshal returns Circom private inputs for credentialAtomicQueryV3OnChain.circom
56749
+ inputsMarshal() {
56750
+ this.validate();
56751
+ if (this.query.valueProof) {
56752
+ this.query.validate();
56753
+ this.query.valueProof.validate();
56754
+ }
56755
+ let valueProof = this.query.valueProof;
56756
+ if (!valueProof) {
56757
+ valueProof = new ValueProof();
56758
+ valueProof.path = 0n;
56759
+ valueProof.value = 0n;
56760
+ valueProof.mtp = new Kt$1();
56761
+ }
56762
+ const treeState = this.claim.nonRevProof.treeState;
56763
+ if (!treeState) {
56764
+ throw new Error(exports.CircuitError.EmptyTreeState);
56765
+ }
56766
+ const s = {
56767
+ requestID: this.requestID.toString(),
56768
+ userGenesisID: this.id.bigInt().toString(),
56769
+ profileNonce: this.profileNonce.toString(),
56770
+ claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
56771
+ issuerID: this.claim.issuerID.bigInt().toString(),
56772
+ issuerClaim: this.claim.claim.marshalJson(),
56773
+ issuerClaimNonRevClaimsTreeRoot: treeState.claimsRoot.bigInt().toString(),
56774
+ issuerClaimNonRevRevTreeRoot: treeState.revocationRoot.bigInt().toString(),
56775
+ issuerClaimNonRevRootsTreeRoot: treeState.rootOfRoots.bigInt().toString(),
56776
+ issuerClaimNonRevState: treeState.state.bigInt().toString(),
56777
+ issuerClaimNonRevMtp: prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()),
56778
+ claimSchema: this.claim.claim.getSchemaHash().bigInt().toString(),
56779
+ claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
56780
+ claimPathValue: valueProof.value.toString(),
56781
+ operator: this.query.operator,
56782
+ timestamp: this.currentTimeStamp,
56783
+ // value in this path in merklized json-ld document
56784
+ slotIndex: this.query.slotIndex,
56785
+ isRevocationChecked: 1
56786
+ };
56787
+ s.challenge = this.challenge?.toString();
56788
+ if (this.authEnabled === 1) {
56789
+ s.authClaim = this.authClaim?.marshalJson();
56790
+ s.userClaimsTreeRoot = this.treeState.claimsRoot?.bigInt().toString();
56791
+ s.userRevTreeRoot = this.treeState.revocationRoot?.bigInt().toString();
56792
+ s.userRootsTreeRoot = this.treeState.rootOfRoots?.bigInt().toString();
56793
+ s.userState = this.treeState.state?.bigInt().toString();
56794
+ s.authClaimIncMtp = prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel());
56795
+ s.authClaimNonRevMtp = prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel());
56796
+ s.challengeSignatureR8x = this.signature.R8[0].toString();
56797
+ s.challengeSignatureR8y = this.signature.R8[1].toString();
56798
+ s.challengeSignatureS = this.signature.S.toString();
56799
+ s.gistMtp =
56800
+ this.gistProof && prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain());
56801
+ const nodeAuxAuth = getNodeAuxValue(this.authClaimNonRevMtp);
56802
+ s.authClaimNonRevMtpAuxHi = nodeAuxAuth.key.bigInt().toString();
56803
+ s.authClaimNonRevMtpAuxHv = nodeAuxAuth.value.bigInt().toString();
56804
+ s.authClaimNonRevMtpNoAux = nodeAuxAuth.noAux;
56805
+ const globalNodeAux = getNodeAuxValue(this.gistProof.proof);
56806
+ s.gistMtpAuxHi = globalNodeAux.key.bigInt().toString();
56807
+ s.gistMtpAuxHv = globalNodeAux.value.bigInt().toString();
56808
+ s.gistMtpNoAux = globalNodeAux.noAux;
56809
+ s.gistRoot = this.gistProof.root.bigInt().toString();
56810
+ }
56811
+ else {
56812
+ this.fillAuthWithZero(s);
56813
+ }
56814
+ if (this.skipClaimRevocationCheck) {
56815
+ s.isRevocationChecked = 0;
56816
+ }
56817
+ if (this.proofType === exports.ProofType.BJJSignature) {
56818
+ s.proofType = '1';
56819
+ s.issuerClaimSignatureR8x = this.claim.signatureProof?.signature.R8[0].toString();
56820
+ s.issuerClaimSignatureR8y = this.claim.signatureProof?.signature.R8[1].toString();
56821
+ s.issuerClaimSignatureS = this.claim.signatureProof?.signature.S.toString();
56822
+ s.issuerAuthClaim = this.claim.signatureProof?.issuerAuthClaim?.marshalJson();
56823
+ s.issuerAuthClaimMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthIncProof.proof, this.getMTLevel());
56824
+ const issuerAuthTreeState = this.claim.nonRevProof.treeState;
56825
+ if (!issuerAuthTreeState) {
56826
+ throw new Error(exports.CircuitError.EmptyTreeState);
56827
+ }
56828
+ s.issuerAuthClaimsTreeRoot = issuerAuthTreeState.claimsRoot.bigInt().toString();
56829
+ s.issuerAuthRevTreeRoot = issuerAuthTreeState.revocationRoot.bigInt().toString();
56830
+ s.issuerAuthRootsTreeRoot = issuerAuthTreeState.rootOfRoots.bigInt().toString();
56831
+ s.issuerAuthClaimNonRevMtp = prepareSiblingsStr(this.claim.signatureProof?.issuerAuthNonRevProof.proof, this.getMTLevel());
56832
+ const nodeAuxIssuerAuthNonRev = getNodeAuxValue(this.claim.signatureProof?.issuerAuthNonRevProof.proof);
56833
+ s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev.key.bigInt().toString();
56834
+ s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev.value.bigInt().toString();
56835
+ s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev.noAux;
56836
+ s.issuerAuthState = this.claim.signatureProof?.issuerAuthIncProof.treeState?.state
56837
+ .bigInt()
56838
+ .toString();
56839
+ this.fillMTPProofsWithZero(s);
56840
+ }
56841
+ else if (this.proofType === exports.ProofType.Iden3SparseMerkleTreeProof) {
56842
+ s.proofType = '2';
56843
+ const incProofTreeState = this.claim.incProof?.treeState;
56844
+ if (!incProofTreeState) {
56845
+ throw new Error(exports.CircuitError.EmptyTreeState);
56846
+ }
56847
+ s.issuerClaimMtp = prepareSiblingsStr(this.claim.incProof?.proof, this.getMTLevel());
56848
+ s.issuerClaimClaimsTreeRoot = incProofTreeState.claimsRoot.bigInt().toString();
56849
+ s.issuerClaimRevTreeRoot = incProofTreeState.revocationRoot.bigInt().toString();
56850
+ s.issuerClaimRootsTreeRoot = incProofTreeState.rootOfRoots.bigInt().toString();
56851
+ s.issuerClaimIdenState = incProofTreeState.state.bigInt().toString();
56852
+ this.fillSigProofWithZero(s);
56853
+ }
56854
+ const nodeAuxNonRev = getNodeAuxValue(this.claim.nonRevProof.proof);
56855
+ s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev.key.bigInt().toString();
56856
+ s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev.value.bigInt().toString();
56857
+ s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev.noAux;
56858
+ s.claimPathNotExists = existenceToInt(valueProof.mtp.existence);
56859
+ const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
56860
+ s.claimPathMtpNoAux = nodAuxJSONLD.noAux;
56861
+ s.claimPathMtpAuxHi = nodAuxJSONLD.key.bigInt().toString();
56862
+ s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString();
56863
+ s.claimPathKey = valueProof.path.toString();
56864
+ const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize());
56865
+ s.value = bigIntArrayToStringArray(values);
56866
+ s.linkNonce = this.linkNonce.toString();
56867
+ s.verifierID = this.verifierID?.bigInt().toString() ?? '0';
56868
+ s.nullifierSessionID = this.nullifierSessionID.toString();
56869
+ s.authEnabled = this.authEnabled.toString();
56870
+ return byteEncoder.encode(JSON.stringify(s));
56871
+ }
56872
+ }
56873
+ /**
56874
+ * @beta
56875
+ * AtomicQueryV3OnChainPubSignals public inputs
56876
+ */
56877
+ class AtomicQueryV3OnChainPubSignals extends BaseConfig {
56878
+ // PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals
56879
+ pubSignalsUnmarshal(data) {
56880
+ // expected order:
56881
+ // merklized
56882
+ // userID
56883
+ // circuitQueryHash
56884
+ // issuerState
56885
+ // linkID
56886
+ // nullifier
56887
+ // operatorOutput
56888
+ // proofType
56889
+ // requestID
56890
+ // challenge
56891
+ // gistRoot
56892
+ // issuerID
56893
+ // isRevocationChecked
56894
+ // issuerClaimNonRevState
56895
+ // timestamp
56896
+ // verifierID
56897
+ // nullifierSessionID
56898
+ // authEnabled
56899
+ const sVals = JSON.parse(byteDecoder.decode(data));
56900
+ let fieldIdx = 0;
56901
+ // -- merklized
56902
+ this.merklized = parseInt(sVals[fieldIdx]);
56903
+ fieldIdx++;
56904
+ // - userID
56905
+ this.userID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
56906
+ fieldIdx++;
56907
+ // - circuitQueryHash
56908
+ this.circuitQueryHash = BigInt(sVals[fieldIdx]);
56909
+ fieldIdx++;
56910
+ // - issuerState
56911
+ this.issuerState = V$1.fromString(sVals[fieldIdx]);
56912
+ fieldIdx++;
56913
+ // - linkID
56914
+ this.linkID = BigInt(sVals[fieldIdx]);
56915
+ fieldIdx++;
56916
+ // - nullifier
56917
+ this.nullifier = BigInt(sVals[fieldIdx]);
56918
+ fieldIdx++;
56919
+ // - operatorOutput
56920
+ this.operatorOutput = BigInt(sVals[fieldIdx]);
56921
+ fieldIdx++;
56922
+ // - proofType
56923
+ this.proofType = parseInt(sVals[fieldIdx]);
56924
+ fieldIdx++;
56925
+ // - requestID
56926
+ this.requestID = BigInt(sVals[fieldIdx]);
56927
+ fieldIdx++;
56928
+ // - challenge
56929
+ this.challenge = BigInt(sVals[fieldIdx]);
56930
+ fieldIdx++;
56931
+ // - gistRoot
56932
+ this.gistRoot = V$1.fromString(sVals[fieldIdx]);
56933
+ fieldIdx++;
56934
+ // - issuerID
56935
+ this.issuerID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
56936
+ fieldIdx++;
56937
+ // - isRevocationChecked
56938
+ this.isRevocationChecked = parseInt(sVals[fieldIdx]);
56939
+ fieldIdx++;
56940
+ // - issuerClaimNonRevState
56941
+ this.issuerClaimNonRevState = V$1.fromString(sVals[fieldIdx]);
56942
+ fieldIdx++;
56943
+ // - timestamp
56944
+ this.timestamp = parseInt(sVals[fieldIdx]);
56945
+ fieldIdx++;
56946
+ // - verifierID
56947
+ if (sVals[fieldIdx] !== '0') {
56948
+ this.verifierID = k$2.fromBigInt(BigInt(sVals[fieldIdx]));
56949
+ }
56950
+ fieldIdx++;
56951
+ // - nullifierSessionID
56952
+ this.nullifierSessionID = BigInt(sVals[fieldIdx]);
56953
+ fieldIdx++;
56954
+ // - authEnabled
56955
+ this.authEnabled = parseInt(sVals[fieldIdx]);
56956
+ return this;
56957
+ }
56958
+ }
56959
+
56253
56960
  /**
56254
56961
  * AtomicQuerySigV2OnChainInputs ZK private inputs for credentialAtomicQuerySig.circom
56255
56962
  *
@@ -56347,9 +57054,9 @@ var PolygonIdSdk = (function (exports) {
56347
57054
  issuerAuthClaimNonRevMtp: this.claim.signatureProof?.issuerAuthNonRevProof?.proof &&
56348
57055
  prepareSiblingsStr(this.claim.signatureProof.issuerAuthNonRevProof.proof, this.getMTLevel()),
56349
57056
  claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(),
56350
- claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()),
57057
+ claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()),
56351
57058
  claimPathValue: valueProof.value.toString(),
56352
- operator: this.query?.operator,
57059
+ operator: this.query.operator,
56353
57060
  timestamp: this.currentTimeStamp,
56354
57061
  // value in this path in merklized json-ld document
56355
57062
  slotIndex: this.query?.slotIndex,
@@ -56645,6 +57352,179 @@ var PolygonIdSdk = (function (exports) {
56645
57352
  }
56646
57353
  }
56647
57354
 
57355
+ /**
57356
+ * LinkedNullifier circuit representation
57357
+ * Inputs and public signals declaration, marshalling and parsing
57358
+ *
57359
+ * @beta
57360
+ * @class LinkedNullifierInputs
57361
+ */
57362
+ class LinkedNullifierInputs {
57363
+ // InputsMarshal returns Circom private inputs for nullifier.circom
57364
+ inputsMarshal() {
57365
+ const s = {
57366
+ linkNonce: this.linkNonce.toString(),
57367
+ issuerClaim: this.issuerClaim.marshalJson(),
57368
+ userGenesisID: this.id.bigInt().toString(),
57369
+ claimSubjectProfileNonce: this.claimSubjectProfileNonce.toString(),
57370
+ claimSchema: this.issuerClaim.getSchemaHash().bigInt().toString(),
57371
+ verifierID: this.verifierID?.bigInt().toString() ?? '0',
57372
+ nullifierSessionID: this.nullifierSessionID.toString()
57373
+ };
57374
+ return byteEncoder.encode(JSON.stringify(s));
57375
+ }
57376
+ }
57377
+ // LinkedNullifierPubSignals nullifier.circom public signals
57378
+ /**
57379
+ * public signals
57380
+ *
57381
+ * @beta
57382
+ * @class LinkedNullifierPubSignals
57383
+ */
57384
+ class LinkedNullifierPubSignals {
57385
+ /**
57386
+ * PubSignalsUnmarshal unmarshal nullifier.circom public inputs to LinkedNullifierPubSignals
57387
+ *
57388
+ * @beta
57389
+ * @param {Uint8Array} data
57390
+ * @returns LinkedNullifierPubSignals
57391
+ */
57392
+ pubSignalsUnmarshal(data) {
57393
+ const len = 4;
57394
+ const sVals = JSON.parse(byteDecoder.decode(data));
57395
+ if (sVals.length !== len) {
57396
+ throw new Error(`invalid number of Output values expected ${len} got ${sVals.length}`);
57397
+ }
57398
+ this.nullifier = BigInt(sVals[0]);
57399
+ this.linkID = BigInt(sVals[1]);
57400
+ this.verifierID = k$2.fromBigInt(BigInt(sVals[2]));
57401
+ this.nullifierSessionID = BigInt(sVals[3]);
57402
+ return this;
57403
+ }
57404
+ }
57405
+
57406
+ /**
57407
+ * LinkedMultiQuery circuit representation
57408
+ * Inputs and public signals declaration, marshalling and parsing
57409
+ *
57410
+ * @beta
57411
+ * @class LinkedMultiQueryInputs
57412
+ */
57413
+ class LinkedMultiQueryInputs extends BaseConfig {
57414
+ // InputsMarshal returns Circom private inputs for linkedMultiQueryInputs.circom
57415
+ inputsMarshal() {
57416
+ const enabled = [];
57417
+ const claimPathNotExists = [];
57418
+ const claimPathMtp = [];
57419
+ const claimPathMtpNoAux = [];
57420
+ const claimPathMtpAuxHi = [];
57421
+ const claimPathMtpAuxHv = [];
57422
+ const claimPathKey = [];
57423
+ const claimPathValue = [];
57424
+ const slotIndex = [];
57425
+ const operator = [];
57426
+ const value = [];
57427
+ for (let i = 0; i < this.queryLength; i++) {
57428
+ if (!this.query) {
57429
+ enabled.push(0);
57430
+ claimPathNotExists.push(0);
57431
+ claimPathMtp.push([]);
57432
+ claimPathMtpNoAux.push('0');
57433
+ claimPathMtpAuxHi.push('0');
57434
+ claimPathMtpAuxHv.push('0');
57435
+ claimPathKey.push('0');
57436
+ claimPathValue.push('0');
57437
+ slotIndex.push(0);
57438
+ operator.push(0);
57439
+ const valuesArr = prepareCircuitArrayValues([], this.getValueArrSize());
57440
+ value.push(bigIntArrayToStringArray(valuesArr));
57441
+ continue;
57442
+ }
57443
+ enabled.push(1);
57444
+ const valueProof = this.query[i].valueProof;
57445
+ claimPathNotExists.push(existenceToInt(valueProof.mtp.existence));
57446
+ claimPathMtp.push(prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaim()));
57447
+ const nodAuxJSONLD = getNodeAuxValue(valueProof.mtp);
57448
+ claimPathMtpNoAux.push(nodAuxJSONLD.noAux);
57449
+ claimPathMtpAuxHi.push(nodAuxJSONLD.key.bigInt().toString());
57450
+ claimPathMtpAuxHv.push(nodAuxJSONLD.value.bigInt().toString());
57451
+ claimPathKey.push(valueProof.path.toString());
57452
+ claimPathValue.push(valueProof.value.toString());
57453
+ slotIndex.push(this.query[i].slotIndex);
57454
+ operator.push(this.query[i].operator);
57455
+ const valuesArr = prepareCircuitArrayValues(this.query[i].values, this.getValueArrSize());
57456
+ value.push(bigIntArrayToStringArray(valuesArr));
57457
+ }
57458
+ const s = {
57459
+ linkNonce: this.linkNonce.toString(),
57460
+ issuerClaim: this.claim.marshalJson(),
57461
+ enabled,
57462
+ claimSchema: this.claim.getSchemaHash().bigInt().toString(),
57463
+ claimPathNotExists,
57464
+ claimPathMtp,
57465
+ claimPathMtpNoAux,
57466
+ claimPathMtpAuxHi,
57467
+ claimPathMtpAuxHv,
57468
+ claimPathKey,
57469
+ claimPathValue,
57470
+ slotIndex,
57471
+ operator,
57472
+ value
57473
+ };
57474
+ return byteEncoder.encode(JSON.stringify(s));
57475
+ }
57476
+ }
57477
+ // LinkedMultiQueryPubSignals linkedMultiQuery.circom public signals
57478
+ /**
57479
+ * public signals
57480
+ *
57481
+ * @beta
57482
+ * @class LinkedMultiQueryPubSignals
57483
+ */
57484
+ class LinkedMultiQueryPubSignals {
57485
+ /**
57486
+ * PubSignalsUnmarshal unmarshal linkedMultiQuery.circom public inputs to LinkedMultiQueryPubSignals
57487
+ *
57488
+ * @beta
57489
+ * @param {Uint8Array} data
57490
+ * @returns LinkedMultiQueryPubSignals
57491
+ */
57492
+ pubSignalsUnmarshal(data, queryLength) {
57493
+ const len = queryLength * 3 + 2;
57494
+ const sVals = JSON.parse(byteDecoder.decode(data));
57495
+ if (sVals.length !== len) {
57496
+ throw new Error(`invalid number of Output values expected ${len} got ${sVals.length}`);
57497
+ }
57498
+ let fieldIdx = 0;
57499
+ // -- linkID
57500
+ this.linkID = BigInt(sVals[fieldIdx]);
57501
+ fieldIdx++;
57502
+ // -- merklized
57503
+ this.merklized = parseInt(sVals[fieldIdx]);
57504
+ fieldIdx++;
57505
+ // - operatorOutput
57506
+ this.operatorOutput = [];
57507
+ for (let i = 0; i < queryLength; i++) {
57508
+ this.operatorOutput.push(BigInt(sVals[fieldIdx]));
57509
+ fieldIdx++;
57510
+ }
57511
+ // - circuitQueryHash
57512
+ this.circuitQueryHash = [];
57513
+ for (let i = 0; i < queryLength; i++) {
57514
+ this.circuitQueryHash.push(BigInt(sVals[fieldIdx]));
57515
+ fieldIdx++;
57516
+ }
57517
+ // - enabled
57518
+ this.enabled = [];
57519
+ for (let i = 0; i < queryLength; i++) {
57520
+ const enabledNum = parseInt(sVals[fieldIdx]);
57521
+ this.enabled.push(enabledNum === 1);
57522
+ fieldIdx++;
57523
+ }
57524
+ return this;
57525
+ }
57526
+ }
57527
+
56648
57528
  var abi$1 = [
56649
57529
  {
56650
57530
  inputs: [
@@ -58399,6 +59279,25 @@ var PolygonIdSdk = (function (exports) {
58399
59279
  };
58400
59280
  }
58401
59281
 
59282
+ /**
59283
+ * Retrieves the user DID from a given credential.
59284
+ * If the credential does not have a credentialSubject.id property, the issuer DID is returned.
59285
+ * If the credentialSubject.id is not a string, an error is thrown.
59286
+ * @param issuerDID The DID of the issuer.
59287
+ * @param credential The credential object.
59288
+ * @returns The user DID parsed from the credential.
59289
+ * @throws Error if the credentialSubject.id is not a string.
59290
+ */
59291
+ const getUserDIDFromCredential = (issuerDID, credential) => {
59292
+ if (!credential.credentialSubject.id) {
59293
+ return issuerDID;
59294
+ }
59295
+ if (typeof credential.credentialSubject.id !== 'string') {
59296
+ throw new Error('credential subject `id` is not a string');
59297
+ }
59298
+ return W$3.parse(credential.credentialSubject.id);
59299
+ };
59300
+
58402
59301
  // ErrAllClaimsRevoked all claims are revoked.
58403
59302
  const ErrAllClaimsRevoked = 'all claims are revoked';
58404
59303
  /**
@@ -58494,16 +59393,7 @@ var PolygonIdSdk = (function (exports) {
58494
59393
  ? mtpProof.issuerData.state
58495
59394
  : sigProof?.issuerData.state;
58496
59395
  const issuerDID = W$3.parse(cred.issuer);
58497
- let userDID;
58498
- if (!cred.credentialSubject.id) {
58499
- userDID = issuerDID;
58500
- }
58501
- else {
58502
- if (typeof cred.credentialSubject.id !== 'string') {
58503
- throw new Error('credential status `id` is not a string');
58504
- }
58505
- userDID = W$3.parse(cred.credentialSubject.id);
58506
- }
59396
+ const userDID = getUserDIDFromCredential(issuerDID, cred);
58507
59397
  const opts = {
58508
59398
  issuerGenesisState: stateInfo,
58509
59399
  issuerDID,
@@ -59546,6 +60436,17 @@ var PolygonIdSdk = (function (exports) {
59546
60436
  const truthyValues = [true, 1, 'true'];
59547
60437
  const falsyValues = [false, 0, 'false'];
59548
60438
  const equalsComparator = (a, b) => {
60439
+ if (Array.isArray(a) && Array.isArray(b)) {
60440
+ return (a.length === b.length && a.every((val, index) => val === b[index]));
60441
+ }
60442
+ if (!Array.isArray(a) && Array.isArray(b)) {
60443
+ return b.includes(a);
60444
+ }
60445
+ if (Array.isArray(a) && !Array.isArray(b)) {
60446
+ return a.includes(b);
60447
+ }
60448
+ a = a;
60449
+ b = b;
59549
60450
  if (truthyValues.includes(a) && truthyValues.includes(b)) {
59550
60451
  return true;
59551
60452
  }
@@ -59554,14 +60455,65 @@ var PolygonIdSdk = (function (exports) {
59554
60455
  }
59555
60456
  return a === b;
59556
60457
  };
60458
+ const greaterThan = (a, b) => {
60459
+ if (Array.isArray(a) && Array.isArray(b)) {
60460
+ return a.every((val, index) => val > b[index]);
60461
+ }
60462
+ if (!Array.isArray(a) && Array.isArray(b)) {
60463
+ return b.every((val) => a > val);
60464
+ }
60465
+ if (Array.isArray(a) && !Array.isArray(b)) {
60466
+ return a.every((val) => val > b);
60467
+ }
60468
+ return a > b;
60469
+ };
60470
+ const greaterThanOrEqual = (a, b) => {
60471
+ if (Array.isArray(a) && Array.isArray(b)) {
60472
+ return a.every((val, index) => val >= b[index]);
60473
+ }
60474
+ if (!Array.isArray(a) && Array.isArray(b)) {
60475
+ return b.every((val) => a >= val);
60476
+ }
60477
+ if (Array.isArray(a) && !Array.isArray(b)) {
60478
+ return a.every((val) => val >= b);
60479
+ }
60480
+ return a >= b;
60481
+ };
60482
+ const lessThanOrEqual = (a, b) => {
60483
+ if (Array.isArray(a) && Array.isArray(b)) {
60484
+ return a.every((val, index) => val <= b[index]);
60485
+ }
60486
+ if (!Array.isArray(a) && Array.isArray(b)) {
60487
+ return b.every((val) => a <= val);
60488
+ }
60489
+ if (Array.isArray(a) && !Array.isArray(b)) {
60490
+ return a.every((val) => val <= b);
60491
+ }
60492
+ return a <= b;
60493
+ };
60494
+ const inOperator = (a, b) => {
60495
+ if (Array.isArray(a) && Array.isArray(b)) {
60496
+ return a.every((val) => b.includes(val));
60497
+ }
60498
+ if (!Array.isArray(a) && Array.isArray(b)) {
60499
+ return b.includes(a);
60500
+ }
60501
+ if (Array.isArray(a) && !Array.isArray(b)) {
60502
+ return a.includes(b);
60503
+ }
60504
+ return false;
60505
+ };
59557
60506
  const comparatorOptions = {
59558
60507
  $noop: () => true,
60508
+ $sd: () => true,
59559
60509
  $eq: (a, b) => equalsComparator(a, b),
59560
- $in: (a, b) => b.includes(a),
59561
- $nin: (a, b) => !b.includes(a),
59562
- $gt: (a, b) => a > b,
59563
- $lt: (a, b) => a < b,
59564
- $ne: (a, b) => !equalsComparator(a, b)
60510
+ $in: (a, b) => inOperator(a, b),
60511
+ $nin: (a, b) => !inOperator(a, b),
60512
+ $gt: (a, b) => greaterThan(a, b),
60513
+ $lt: (a, b) => !greaterThan(a, b),
60514
+ $ne: (a, b) => !equalsComparator(a, b),
60515
+ $gte: (a, b) => greaterThanOrEqual(a, b),
60516
+ $lte: (a, b) => lessThanOrEqual(a, b)
59565
60517
  };
59566
60518
  /**
59567
60519
  * credential search path resolver
@@ -59645,8 +60597,6 @@ var PolygonIdSdk = (function (exports) {
59645
60597
  return acc.concat(new FilterQuery('credentialSubject.id', comparatorOptions.$eq, queryValue));
59646
60598
  case 'schema':
59647
60599
  return acc.concat(new FilterQuery('credentialSchema.id', comparatorOptions.$eq, queryValue));
59648
- case 'skipClaimRevocationCheck':
59649
- return acc;
59650
60600
  case 'credentialSubject': {
59651
60601
  const reqFilters = Object.keys(queryValue).reduce((acc, fieldKey) => {
59652
60602
  const fieldParams = queryValue[fieldKey];
@@ -59664,8 +60614,13 @@ var PolygonIdSdk = (function (exports) {
59664
60614
  }, []);
59665
60615
  return acc.concat(reqFilters);
59666
60616
  }
60617
+ case 'proofType':
60618
+ case 'groupId':
60619
+ case 'skipClaimRevocationCheck': {
60620
+ return acc;
60621
+ }
59667
60622
  default:
59668
- throw new Error(exports.SearchError.NotDefinedQueryKey);
60623
+ throw new Error(`${queryKey} : ${exports.SearchError.NotDefinedQueryKey}`);
59669
60624
  }
59670
60625
  }, []);
59671
60626
  };
@@ -60364,6 +61319,18 @@ var PolygonIdSdk = (function (exports) {
60364
61319
  * @returns {ClaimNonRevStatus}
60365
61320
  */
60366
61321
  const toClaimNonRevStatus = (s) => {
61322
+ if (!s) {
61323
+ const hash = $$2.hash(new Array(3).fill(0n));
61324
+ return {
61325
+ proof: new Kt$1(),
61326
+ treeState: {
61327
+ state: V$1.fromBigInt(hash),
61328
+ claimsRoot: M$2,
61329
+ revocationRoot: M$2,
61330
+ rootOfRoots: M$2
61331
+ }
61332
+ };
61333
+ }
60367
61334
  return {
60368
61335
  proof: s.mtp,
60369
61336
  treeState: buildTreeState(s.issuer.state, s.issuer.claimsTreeRoot, s.issuer.revocationTreeRoot, s.issuer.rootOfRoots)
@@ -60397,6 +61364,88 @@ var PolygonIdSdk = (function (exports) {
60397
61364
  proof
60398
61365
  };
60399
61366
  };
61367
+ const parseCredentialSubject = (credentialSubject) => {
61368
+ // credentialSubject is empty
61369
+ if (!credentialSubject) {
61370
+ return [{ operator: QueryOperators.$eq, fieldName: '' }];
61371
+ }
61372
+ const queries = [];
61373
+ const entries = Object.entries(credentialSubject);
61374
+ if (!entries.length) {
61375
+ throw new Error(`query must have at least 1 predicate`);
61376
+ }
61377
+ for (const [fieldName, fieldReq] of entries) {
61378
+ const fieldReqEntries = Object.entries(fieldReq);
61379
+ const isSelectiveDisclosure = fieldReqEntries.length === 0;
61380
+ if (isSelectiveDisclosure) {
61381
+ queries.push({ operator: QueryOperators.$sd, fieldName: fieldName });
61382
+ continue;
61383
+ }
61384
+ for (const [operatorName, operatorValue] of fieldReqEntries) {
61385
+ if (!QueryOperators[operatorName]) {
61386
+ throw new Error(`operator is not supported by lib`);
61387
+ }
61388
+ const operator = QueryOperators[operatorName];
61389
+ queries.push({ operator, fieldName, operatorValue });
61390
+ }
61391
+ }
61392
+ return queries;
61393
+ };
61394
+ const parseQueryMetadata = async (propertyQuery, ldContextJSON, credentialType, options) => {
61395
+ const datatype = await lf.newTypeFromContext(ldContextJSON, `${credentialType}.${propertyQuery.fieldName}`, options);
61396
+ const query = {
61397
+ ...propertyQuery,
61398
+ slotIndex: 0,
61399
+ merklizedSchema: false,
61400
+ datatype: datatype,
61401
+ claimPathKey: BigInt(0),
61402
+ values: [],
61403
+ path: new lf()
61404
+ };
61405
+ const serAttr = await Parser.getSerializationAttrFromContext(JSON.parse(ldContextJSON), options, credentialType);
61406
+ if (!serAttr) {
61407
+ query.merklizedSchema = true;
61408
+ }
61409
+ // for merklized credentials slotIndex in query must be equal to zero
61410
+ // and not a position of merklization root.
61411
+ // it has no influence on check in the off-chain circuits, but it aligns with onchain verification standard
61412
+ if (!query.merklizedSchema) {
61413
+ query.slotIndex = await Parser.getFieldSlotIndex(propertyQuery.fieldName, credentialType, byteEncoder.encode(ldContextJSON));
61414
+ }
61415
+ else {
61416
+ try {
61417
+ const path = await buildFieldPath(ldContextJSON, credentialType, propertyQuery.fieldName, options);
61418
+ query.claimPathKey = await path.mtEntry();
61419
+ query.path = path;
61420
+ }
61421
+ catch (e) {
61422
+ throw new Error(`field does not exist in the schema ${e.message}`);
61423
+ }
61424
+ }
61425
+ if (propertyQuery.operatorValue) {
61426
+ if (!isValidOperation(datatype, propertyQuery.operator)) {
61427
+ throw new Error(`operator ${propertyQuery.operator} is not supported for datatype ${datatype}`);
61428
+ }
61429
+ query.values = await transformQueryValueToBigInts(propertyQuery.operatorValue, datatype);
61430
+ }
61431
+ return query;
61432
+ };
61433
+ const parseQueriesMetadata = async (credentialType, ldContextJSON, credentialSubject, options) => {
61434
+ const queriesMetadata = parseCredentialSubject(credentialSubject);
61435
+ return Promise.all(queriesMetadata.map((m) => parseQueryMetadata(m, ldContextJSON, credentialType, options)));
61436
+ };
61437
+ const transformQueryValueToBigInts = async (value, ldType) => {
61438
+ const values = new Array(64).fill(BigInt(0));
61439
+ if (Array.isArray(value)) {
61440
+ for (let index = 0; index < value.length; index++) {
61441
+ values[index] = await ff.hashValue(ldType, value[index]);
61442
+ }
61443
+ }
61444
+ else {
61445
+ values[0] = await ff.hashValue(ldType, value);
61446
+ }
61447
+ return values;
61448
+ };
60400
61449
 
60401
61450
  /* eslint-disable require-await */
60402
61451
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -81503,6 +82552,391 @@ var PolygonIdSdk = (function (exports) {
81503
82552
  }
81504
82553
  NativeProver.curveName = 'bn128';
81505
82554
 
82555
+ const circuitValidator = {
82556
+ [exports.CircuitId.AtomicQueryMTPV2]: { maxQueriesCount: 1 },
82557
+ [exports.CircuitId.AtomicQueryMTPV2OnChain]: { maxQueriesCount: 1 },
82558
+ [exports.CircuitId.AtomicQuerySigV2]: { maxQueriesCount: 1 },
82559
+ [exports.CircuitId.AtomicQuerySigV2OnChain]: { maxQueriesCount: 1 },
82560
+ [exports.CircuitId.AtomicQueryV3]: { maxQueriesCount: 1 },
82561
+ [exports.CircuitId.AtomicQueryV3OnChain]: { maxQueriesCount: 1 },
82562
+ [exports.CircuitId.AuthV2]: { maxQueriesCount: 0 },
82563
+ [exports.CircuitId.StateTransition]: { maxQueriesCount: 0 },
82564
+ [exports.CircuitId.LinkedNullifier]: { maxQueriesCount: 1 },
82565
+ [exports.CircuitId.LinkedMultiQuery10]: { maxQueriesCount: 10 }
82566
+ };
82567
+ class InputGenerator {
82568
+ constructor(_identityWallet, _credentialWallet, _stateStorage) {
82569
+ this._identityWallet = _identityWallet;
82570
+ this._credentialWallet = _credentialWallet;
82571
+ this._stateStorage = _stateStorage;
82572
+ this.credentialAtomicQueryMTPV2PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
82573
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82574
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82575
+ const circuitInputs = new AtomicQueryMTPV2Inputs();
82576
+ circuitInputs.id = W$3.idFromDID(identifier);
82577
+ circuitInputs.requestID = BigInt(proofReq.id);
82578
+ const query = circuitQueries[0];
82579
+ query.operator = query.operator === exports.Operators.SD ? exports.Operators.EQ : query.operator;
82580
+ circuitInputs.query = query;
82581
+ circuitInputs.claim = {
82582
+ issuerID: circuitClaimData.issuerId,
82583
+ claim: circuitClaimData.claim,
82584
+ incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
82585
+ nonRevProof: circuitClaimData.nonRevProof
82586
+ };
82587
+ circuitInputs.currentTimeStamp = S$3(new Date());
82588
+ circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
82589
+ circuitInputs.profileNonce = BigInt(params.authProfileNonce);
82590
+ circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
82591
+ return circuitInputs.inputsMarshal();
82592
+ };
82593
+ this.credentialAtomicQueryMTPV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
82594
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82595
+ const authInfo = await this.prepareAuthBJJCredential(identifier);
82596
+ const authClaimData = await this.newCircuitClaimData({
82597
+ credential: authInfo.credential,
82598
+ credentialCoreClaim: authInfo.coreClaim
82599
+ });
82600
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82601
+ const circuitInputs = new AtomicQueryMTPV2OnChainInputs();
82602
+ const id = W$3.idFromDID(identifier);
82603
+ circuitInputs.id = W$3.idFromDID(identifier);
82604
+ circuitInputs.requestID = BigInt(proofReq.id);
82605
+ const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
82606
+ const gistProof = toGISTProof(stateProof);
82607
+ circuitInputs.gistProof = gistProof;
82608
+ if (authClaimData?.treeState) {
82609
+ circuitInputs.treeState = {
82610
+ state: authClaimData?.treeState?.state,
82611
+ claimsRoot: authClaimData?.treeState?.claimsRoot,
82612
+ revocationRoot: authClaimData?.treeState?.revocationRoot,
82613
+ rootOfRoots: authClaimData?.treeState?.rootOfRoots
82614
+ };
82615
+ }
82616
+ circuitInputs.authClaim = authClaimData.claim;
82617
+ circuitInputs.authClaimIncMtp = authClaimData.proof;
82618
+ circuitInputs.authClaimNonRevMtp = authInfo.nonRevProof.proof;
82619
+ if (!params.challenge) {
82620
+ throw new Error('challenge must be provided for onchain circuits');
82621
+ }
82622
+ const signature = await this._identityWallet.signChallenge(params.challenge, authInfo.credential);
82623
+ circuitInputs.signature = signature;
82624
+ circuitInputs.challenge = params.challenge;
82625
+ const query = circuitQueries[0];
82626
+ query.operator = query.operator === exports.Operators.SD ? exports.Operators.EQ : query.operator;
82627
+ circuitInputs.query = query;
82628
+ circuitInputs.claim = {
82629
+ issuerID: circuitClaimData.issuerId,
82630
+ claim: circuitClaimData.claim,
82631
+ incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
82632
+ nonRevProof: circuitClaimData.nonRevProof
82633
+ };
82634
+ circuitInputs.currentTimeStamp = S$3(new Date());
82635
+ circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
82636
+ circuitInputs.profileNonce = BigInt(params.authProfileNonce);
82637
+ circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
82638
+ return circuitInputs.inputsMarshal();
82639
+ };
82640
+ this.credentialAtomicQuerySigV2PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
82641
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82642
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82643
+ const circuitInputs = new AtomicQuerySigV2Inputs();
82644
+ circuitInputs.id = W$3.idFromDID(identifier);
82645
+ circuitInputs.claim = {
82646
+ issuerID: circuitClaimData?.issuerId,
82647
+ signatureProof: circuitClaimData.signatureProof,
82648
+ claim: circuitClaimData.claim,
82649
+ nonRevProof: circuitClaimData.nonRevProof
82650
+ };
82651
+ circuitInputs.requestID = BigInt(proofReq.id);
82652
+ circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
82653
+ circuitInputs.profileNonce = BigInt(params.authProfileNonce);
82654
+ circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
82655
+ const query = circuitQueries[0];
82656
+ query.operator = query.operator === exports.Operators.SD ? exports.Operators.EQ : query.operator;
82657
+ circuitInputs.query = query;
82658
+ circuitInputs.currentTimeStamp = S$3(new Date());
82659
+ return circuitInputs.inputsMarshal();
82660
+ };
82661
+ this.credentialAtomicQuerySigV2OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
82662
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82663
+ const authInfo = await this.prepareAuthBJJCredential(identifier);
82664
+ const authClaimData = await this.newCircuitClaimData({
82665
+ credential: authInfo.credential,
82666
+ credentialCoreClaim: authInfo.coreClaim
82667
+ });
82668
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82669
+ const circuitInputs = new AtomicQuerySigV2OnChainInputs();
82670
+ const id = W$3.idFromDID(identifier);
82671
+ circuitInputs.id = id;
82672
+ circuitInputs.claim = {
82673
+ issuerID: circuitClaimData.issuerId,
82674
+ signatureProof: circuitClaimData.signatureProof,
82675
+ claim: circuitClaimData.claim,
82676
+ nonRevProof: circuitClaimData.nonRevProof
82677
+ };
82678
+ circuitInputs.requestID = BigInt(proofReq.id);
82679
+ circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
82680
+ circuitInputs.profileNonce = BigInt(params.authProfileNonce);
82681
+ circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
82682
+ const query = circuitQueries[0];
82683
+ query.operator = query.operator === exports.Operators.SD ? exports.Operators.EQ : query.operator;
82684
+ circuitInputs.query = query;
82685
+ circuitInputs.currentTimeStamp = S$3(new Date());
82686
+ if (authClaimData.treeState) {
82687
+ circuitInputs.treeState = {
82688
+ state: authClaimData.treeState?.state,
82689
+ claimsRoot: authClaimData.treeState?.claimsRoot,
82690
+ revocationRoot: authClaimData.treeState?.revocationRoot,
82691
+ rootOfRoots: authClaimData.treeState?.rootOfRoots
82692
+ };
82693
+ }
82694
+ const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
82695
+ const gistProof = toGISTProof(stateProof);
82696
+ circuitInputs.gistProof = gistProof;
82697
+ circuitInputs.authClaim = authClaimData.claim;
82698
+ circuitInputs.authClaimIncMtp = authClaimData.proof;
82699
+ circuitInputs.authClaimNonRevMtp = authInfo.nonRevProof.proof;
82700
+ if (!params.challenge) {
82701
+ throw new Error('challenge must be provided for onchain circuits');
82702
+ }
82703
+ const signature = await this._identityWallet.signChallenge(params.challenge, authInfo.credential);
82704
+ circuitInputs.signature = signature;
82705
+ circuitInputs.challenge = params.challenge;
82706
+ return circuitInputs.inputsMarshal();
82707
+ };
82708
+ this.credentialAtomicQueryV3PrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
82709
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82710
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82711
+ let proofType;
82712
+ switch (proofReq.query.proofType) {
82713
+ case exports.ProofType.BJJSignature:
82714
+ proofType = exports.ProofType.BJJSignature;
82715
+ break;
82716
+ case exports.ProofType.Iden3SparseMerkleTreeProof:
82717
+ proofType = exports.ProofType.Iden3SparseMerkleTreeProof;
82718
+ break;
82719
+ default:
82720
+ if (circuitClaimData.proof) {
82721
+ proofType = exports.ProofType.Iden3SparseMerkleTreeProof;
82722
+ }
82723
+ else if (circuitClaimData.signatureProof) {
82724
+ proofType = exports.ProofType.BJJSignature;
82725
+ }
82726
+ else {
82727
+ throw Error('claim has no MTP or signature proof');
82728
+ }
82729
+ break;
82730
+ }
82731
+ const circuitInputs = new AtomicQueryV3Inputs();
82732
+ circuitInputs.id = W$3.idFromDID(identifier);
82733
+ circuitInputs.claim = {
82734
+ issuerID: circuitClaimData?.issuerId,
82735
+ signatureProof: circuitClaimData.signatureProof,
82736
+ claim: circuitClaimData.claim,
82737
+ nonRevProof: circuitClaimData.nonRevProof,
82738
+ incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState }
82739
+ };
82740
+ circuitInputs.requestID = BigInt(proofReq.id);
82741
+ circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
82742
+ circuitInputs.profileNonce = BigInt(params.authProfileNonce);
82743
+ circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
82744
+ const query = circuitQueries[0];
82745
+ query.values = query.operator === exports.Operators.SD ? new Array(64).fill(0) : query.values;
82746
+ circuitInputs.query = query;
82747
+ circuitInputs.currentTimeStamp = S$3(new Date());
82748
+ circuitInputs.proofType = proofType;
82749
+ circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
82750
+ circuitInputs.verifierID = params.verifierDid ? W$3.idFromDID(params.verifierDid) : undefined;
82751
+ circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
82752
+ ? BigInt(proofReq.params?.nullifierSessionId?.toString())
82753
+ : BigInt(0);
82754
+ return circuitInputs.inputsMarshal();
82755
+ };
82756
+ this.credentialAtomicQueryV3OnChainPrepareInputs = async ({ preparedCredential, identifier, proofReq, params, circuitQueries }) => {
82757
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82758
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82759
+ let proofType;
82760
+ switch (proofReq.query.proofType) {
82761
+ case exports.ProofType.BJJSignature:
82762
+ proofType = exports.ProofType.BJJSignature;
82763
+ break;
82764
+ case exports.ProofType.Iden3SparseMerkleTreeProof:
82765
+ proofType = exports.ProofType.Iden3SparseMerkleTreeProof;
82766
+ break;
82767
+ default:
82768
+ if (circuitClaimData.proof) {
82769
+ proofType = exports.ProofType.Iden3SparseMerkleTreeProof;
82770
+ }
82771
+ else if (circuitClaimData.signatureProof) {
82772
+ proofType = exports.ProofType.BJJSignature;
82773
+ }
82774
+ else {
82775
+ throw Error('claim has no MTP or signature proof');
82776
+ }
82777
+ break;
82778
+ }
82779
+ const circuitInputs = new AtomicQueryV3OnChainInputs();
82780
+ circuitInputs.id = W$3.idFromDID(identifier);
82781
+ circuitInputs.claim = {
82782
+ issuerID: circuitClaimData?.issuerId,
82783
+ signatureProof: circuitClaimData.signatureProof,
82784
+ claim: circuitClaimData.claim,
82785
+ nonRevProof: circuitClaimData.nonRevProof,
82786
+ incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState }
82787
+ };
82788
+ circuitInputs.requestID = BigInt(proofReq.id);
82789
+ circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
82790
+ circuitInputs.profileNonce = BigInt(params.authProfileNonce);
82791
+ circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
82792
+ const query = circuitQueries[0];
82793
+ query.values = query.operator === exports.Operators.SD ? new Array(64).fill(0) : query.values;
82794
+ circuitInputs.query = query;
82795
+ circuitInputs.currentTimeStamp = S$3(new Date());
82796
+ circuitInputs.proofType = proofType;
82797
+ circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
82798
+ circuitInputs.verifierID = params.verifierDid ? W$3.idFromDID(params.verifierDid) : undefined;
82799
+ circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
82800
+ ? BigInt(proofReq.params?.nullifierSessionID?.toString())
82801
+ : BigInt(0);
82802
+ let isEthIdentity = true;
82803
+ try {
82804
+ k$2.ethAddressFromId(circuitInputs.id);
82805
+ }
82806
+ catch {
82807
+ isEthIdentity = false;
82808
+ }
82809
+ circuitInputs.authEnabled = isEthIdentity ? 0 : 1;
82810
+ circuitInputs.challenge = BigInt(params.challenge ?? 0);
82811
+ const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
82812
+ const id = W$3.idFromDID(genesisDID);
82813
+ const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
82814
+ const gistProof = toGISTProof(stateProof);
82815
+ circuitInputs.gistProof = gistProof;
82816
+ // auth inputs
82817
+ if (circuitInputs.authEnabled === 1) {
82818
+ const authPrepared = await this.prepareAuthBJJCredential(genesisDID);
82819
+ const authClaimData = await this.newCircuitClaimData({
82820
+ credential: authPrepared.credential,
82821
+ credentialCoreClaim: authPrepared.coreClaim
82822
+ });
82823
+ const signature = await this._identityWallet.signChallenge(circuitInputs.challenge, authPrepared.credential);
82824
+ circuitInputs.profileNonce = BigInt(authProfileNonce);
82825
+ circuitInputs.authClaim = authClaimData.claim;
82826
+ circuitInputs.authClaimIncMtp = authClaimData.proof;
82827
+ circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof;
82828
+ circuitInputs.treeState = authClaimData.treeState;
82829
+ circuitInputs.signature = signature;
82830
+ }
82831
+ return circuitInputs.inputsMarshal();
82832
+ };
82833
+ this.linkedNullifierPrepareInputs = async ({ preparedCredential, identifier, proofReq, params }) => {
82834
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82835
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82836
+ const circuitInputs = new LinkedNullifierInputs();
82837
+ circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
82838
+ circuitInputs.issuerClaim = circuitClaimData.claim;
82839
+ circuitInputs.id = W$3.idFromDID(identifier);
82840
+ circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
82841
+ circuitInputs.verifierID = params.verifierDid ? W$3.idFromDID(params.verifierDid) : undefined;
82842
+ circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
82843
+ ? BigInt(proofReq.params?.nullifierSessionID?.toString())
82844
+ : BigInt(0);
82845
+ return circuitInputs.inputsMarshal();
82846
+ };
82847
+ this.linkedMultiQuery10PrepareInputs = async ({ preparedCredential, proofReq, params, circuitQueries }) => {
82848
+ const circuitClaimData = await this.newCircuitClaimData(preparedCredential);
82849
+ circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
82850
+ const circuitInputs = new LinkedMultiQueryInputs();
82851
+ circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
82852
+ circuitInputs.claim = circuitClaimData.claim;
82853
+ circuitInputs.query = circuitQueries;
82854
+ circuitInputs.queryLength = circuitValidator[proofReq.circuitId].maxQueriesCount;
82855
+ return circuitInputs.inputsMarshal();
82856
+ };
82857
+ }
82858
+ async generateInputs(ctx) {
82859
+ const { circuitId } = ctx.proofReq;
82860
+ const fnName = `${circuitId.split('-')[0]}PrepareInputs`;
82861
+ const queriesLength = ctx.circuitQueries.length;
82862
+ if (queriesLength > circuitValidator[circuitId].maxQueriesCount) {
82863
+ throw new Error(`circuit ${circuitId} supports only ${circuitValidator[circuitId].maxQueriesCount} queries`);
82864
+ }
82865
+ const fn = this[fnName];
82866
+ if (!fn) {
82867
+ throw new Error(`inputs generator for ${circuitId} not found`);
82868
+ }
82869
+ return fn(ctx);
82870
+ }
82871
+ async newCircuitClaimData(preparedCredential) {
82872
+ const smtProof = preparedCredential.credential.getIden3SparseMerkleTreeProof();
82873
+ const circuitClaim = new CircuitClaim();
82874
+ circuitClaim.claim = preparedCredential.credentialCoreClaim;
82875
+ circuitClaim.issuerId = W$3.idFromDID(W$3.parse(preparedCredential.credential.issuer));
82876
+ if (smtProof) {
82877
+ circuitClaim.proof = smtProof.mtp;
82878
+ circuitClaim.treeState = {
82879
+ state: smtProof.issuerData.state.value,
82880
+ claimsRoot: smtProof.issuerData.state.claimsTreeRoot,
82881
+ revocationRoot: smtProof.issuerData.state.revocationTreeRoot,
82882
+ rootOfRoots: smtProof.issuerData.state.rootOfRoots
82883
+ };
82884
+ }
82885
+ const sigProof = preparedCredential.credential.getBJJSignature2021Proof();
82886
+ if (sigProof) {
82887
+ const issuerDID = sigProof.issuerData.id;
82888
+ const userDID = getUserDIDFromCredential(issuerDID, preparedCredential.credential);
82889
+ const { credentialStatus, mtp, authCoreClaim } = sigProof.issuerData;
82890
+ if (!credentialStatus) {
82891
+ throw new Error("can't check the validity of issuer auth claim: no credential status in proof");
82892
+ }
82893
+ if (!mtp) {
82894
+ throw new Error('issuer auth credential must have a mtp proof');
82895
+ }
82896
+ if (!authCoreClaim) {
82897
+ throw new Error('issuer auth credential must have a core claim proof');
82898
+ }
82899
+ const opts = {
82900
+ issuerGenesisState: sigProof.issuerData.state,
82901
+ issuerDID,
82902
+ userDID
82903
+ };
82904
+ const rs = await this._credentialWallet.getRevocationStatus(credentialStatus, opts);
82905
+ const issuerAuthNonRevProof = toClaimNonRevStatus(rs);
82906
+ circuitClaim.signatureProof = {
82907
+ signature: sigProof.signature,
82908
+ issuerAuthIncProof: {
82909
+ proof: sigProof.issuerData.mtp,
82910
+ treeState: {
82911
+ state: sigProof.issuerData.state.value,
82912
+ claimsRoot: sigProof.issuerData.state.claimsTreeRoot,
82913
+ revocationRoot: sigProof.issuerData.state.revocationTreeRoot,
82914
+ rootOfRoots: sigProof.issuerData.state.rootOfRoots
82915
+ }
82916
+ },
82917
+ issuerAuthClaim: sigProof.issuerData.authCoreClaim,
82918
+ issuerAuthNonRevProof
82919
+ };
82920
+ }
82921
+ return circuitClaim;
82922
+ }
82923
+ async prepareAuthBJJCredential(did, treeStateInfo) {
82924
+ const authCredential = await this._credentialWallet.getAuthBJJCredential(did);
82925
+ const incProof = await this._identityWallet.generateCredentialMtp(did, authCredential, treeStateInfo);
82926
+ const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
82927
+ const authCoreClaim = authCredential.getCoreClaimFromProof(exports.ProofType.Iden3SparseMerkleTreeProof);
82928
+ if (!authCoreClaim) {
82929
+ throw new Error('auth core claim is not defined for auth bjj credential');
82930
+ }
82931
+ return {
82932
+ credential: authCredential,
82933
+ incProof,
82934
+ nonRevProof,
82935
+ coreClaim: authCoreClaim
82936
+ };
82937
+ }
82938
+ }
82939
+
81506
82940
  /**
81507
82941
  * Proof service is an implementation of IProofService
81508
82942
  * that works with a native groth16 prover
@@ -81525,6 +82959,7 @@ var PolygonIdSdk = (function (exports) {
81525
82959
  this._stateStorage = _stateStorage;
81526
82960
  this._prover = opts?.prover ?? new NativeProver(_circuitStorage);
81527
82961
  this._ldOptions = { ...opts, documentLoader: opts?.documentLoader ?? cacheLoader(opts) };
82962
+ this._inputsGenerator = new InputGenerator(_identityWallet, _credentialWallet, _stateStorage);
81528
82963
  }
81529
82964
  /** {@inheritdoc IProofService.verifyProof} */
81530
82965
  async verifyProof(zkp, circuitId) {
@@ -81538,20 +82973,61 @@ var PolygonIdSdk = (function (exports) {
81538
82973
  challenge: 0n
81539
82974
  };
81540
82975
  }
81541
- // find credential
81542
- const credential = opts.credential ?? (await this.findCredential(identifier, proofReq.query));
82976
+ let credentialWithRevStatus = { cred: opts.credential, revStatus: opts.credentialRevocationStatus };
82977
+ if (!opts.credential) {
82978
+ credentialWithRevStatus = await this.findCredentialByProofQuery(identifier, proofReq.query);
82979
+ }
82980
+ if (opts.credential && !opts.credentialRevocationStatus && !opts.skipRevocation) {
82981
+ const revStatus = await this._credentialWallet.getRevocationStatusFromCredential(opts.credential);
82982
+ credentialWithRevStatus = { cred: opts.credential, revStatus };
82983
+ }
82984
+ if (!credentialWithRevStatus.cred) {
82985
+ throw new Error(`credential not found for query ${JSON.stringify(proofReq.query)}`);
82986
+ }
82987
+ const credentialCoreClaim = await this._identityWallet.getCoreClaimFromCredential(credentialWithRevStatus.cred);
81543
82988
  const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(identifier);
81544
- const preparedCredential = await this.getPreparedCredential(credential);
82989
+ const preparedCredential = {
82990
+ credential: credentialWithRevStatus.cred,
82991
+ credentialCoreClaim,
82992
+ revStatus: credentialWithRevStatus.revStatus
82993
+ };
81545
82994
  const subjectDID = W$3.parse(preparedCredential.credential.credentialSubject['id']);
81546
82995
  const { nonce: credentialSubjectProfileNonce, genesisDID: subjectGenesisDID } = await this._identityWallet.getGenesisDIDMetadata(subjectDID);
81547
82996
  if (subjectGenesisDID.string() !== genesisDID.string()) {
81548
82997
  throw new Error('subject and auth profiles are not derived from the same did');
81549
82998
  }
81550
- const { inputs, vp } = await this.generateInputs(preparedCredential, genesisDID, proofReq, {
82999
+ const propertiesMetadata = parseCredentialSubject(proofReq.query.credentialSubject);
83000
+ if (!propertiesMetadata.length) {
83001
+ throw new Error('no queries in zkp request');
83002
+ }
83003
+ const mtPosition = preparedCredential.credentialCoreClaim.getMerklizedPosition();
83004
+ let mk;
83005
+ if (mtPosition !== U$2.None) {
83006
+ mk = await preparedCredential.credential.merklize(this._ldOptions);
83007
+ }
83008
+ const context = proofReq.query['context'];
83009
+ const groupId = proofReq.query['groupId'];
83010
+ const ldContext = await this.loadLdContext(context);
83011
+ const credentialType = proofReq.query['type'];
83012
+ const queriesMetadata = [];
83013
+ const circuitQueries = [];
83014
+ for (const propertyMetadata of propertiesMetadata) {
83015
+ const queryMetadata = await parseQueryMetadata(propertyMetadata, byteDecoder.decode(ldContext), credentialType, this._ldOptions);
83016
+ queriesMetadata.push(queryMetadata);
83017
+ const circuitQuery = await this.toCircuitsQuery(preparedCredential.credential, queryMetadata, mk);
83018
+ circuitQueries.push(circuitQuery);
83019
+ }
83020
+ const inputs = await this.generateInputs(preparedCredential, genesisDID, proofReq, {
81551
83021
  ...opts,
81552
83022
  authProfileNonce,
81553
- credentialSubjectProfileNonce
81554
- });
83023
+ credentialSubjectProfileNonce,
83024
+ linkNonce: groupId ? opts.linkNonce : 0n
83025
+ }, circuitQueries);
83026
+ const sdQueries = queriesMetadata.filter((q) => q.operator === exports.Operators.SD);
83027
+ let vp;
83028
+ if (sdQueries.length) {
83029
+ vp = createVerifiablePresentation(context, credentialType, preparedCredential.credential, sdQueries);
83030
+ }
81555
83031
  const { proof, pub_signals } = await this._prover.generate(inputs, proofReq.circuitId);
81556
83032
  return {
81557
83033
  id: proofReq.id,
@@ -81563,7 +83039,7 @@ var PolygonIdSdk = (function (exports) {
81563
83039
  }
81564
83040
  /** {@inheritdoc IProofService.transitState} */
81565
83041
  async transitState(did, oldTreeState, isOldStateGenesis, stateStorage, ethSigner) {
81566
- const authInfo = await this.prepareAuthBJJCredential(did, oldTreeState);
83042
+ const authInfo = await this._inputsGenerator.prepareAuthBJJCredential(did, oldTreeState);
81567
83043
  const newTreeModel = await this._identityWallet.getDIDTreeModel(did);
81568
83044
  const claimsRoot = await newTreeModel.claimsTree.root();
81569
83045
  const rootOfRoots = await newTreeModel.rootsTree.root();
@@ -81575,17 +83051,17 @@ var PolygonIdSdk = (function (exports) {
81575
83051
  rootOfRoots
81576
83052
  };
81577
83053
  const challenge = _$3.hash([oldTreeState.state.bigInt(), newTreeState.state.bigInt()]);
81578
- const signature = await this._identityWallet.signChallenge(challenge, authInfo.authCredential);
83054
+ const signature = await this._identityWallet.signChallenge(challenge, authInfo.credential);
81579
83055
  const circuitInputs = new StateTransitionInputs();
81580
83056
  circuitInputs.id = W$3.idFromDID(did);
81581
83057
  circuitInputs.signature = signature;
81582
83058
  circuitInputs.isOldStateGenesis = isOldStateGenesis;
81583
- const authClaimIncProofNewState = await this._identityWallet.generateCredentialMtp(did, authInfo.authCredential, newTreeState);
83059
+ const authClaimIncProofNewState = await this._identityWallet.generateCredentialMtp(did, authInfo.credential, newTreeState);
81584
83060
  circuitInputs.newTreeState = authClaimIncProofNewState.treeState;
81585
83061
  circuitInputs.authClaimNewStateIncProof = authClaimIncProofNewState.proof;
81586
83062
  circuitInputs.oldTreeState = oldTreeState;
81587
83063
  circuitInputs.authClaim = {
81588
- claim: authInfo.authCoreClaim,
83064
+ claim: authInfo.coreClaim,
81589
83065
  incProof: authInfo.incProof,
81590
83066
  nonRevProof: authInfo.nonRevProof
81591
83067
  };
@@ -81595,370 +83071,65 @@ var PolygonIdSdk = (function (exports) {
81595
83071
  await this._identityWallet.updateIdentityState(did, true, newTreeState);
81596
83072
  return txId;
81597
83073
  }
81598
- async getPreparedCredential(credential) {
81599
- const revStatus = await this._credentialWallet.getRevocationStatusFromCredential(credential);
81600
- const credCoreClaim = await this._identityWallet.getCoreClaimFromCredential(credential);
81601
- return { credential, revStatus, credentialCoreClaim: credCoreClaim };
81602
- }
81603
- async prepareAuthBJJCredential(did, treeStateInfo) {
81604
- const authCredential = await this._credentialWallet.getAuthBJJCredential(did);
81605
- const incProof = await this._identityWallet.generateCredentialMtp(did, authCredential, treeStateInfo);
81606
- const nonRevProof = await this._identityWallet.generateNonRevocationMtp(did, authCredential, treeStateInfo);
81607
- const authCoreClaim = authCredential.getCoreClaimFromProof(exports.ProofType.Iden3SparseMerkleTreeProof);
81608
- if (!authCoreClaim) {
81609
- throw new Error('auth core claim is not defined for auth bjj credential');
81610
- }
81611
- return { authCredential, incProof, nonRevProof, authCoreClaim };
81612
- }
81613
- async generateInputs(preparedCredential, identifier, proofReq, params) {
81614
- let generateInputFn;
81615
- switch (proofReq.circuitId) {
81616
- case exports.CircuitId.AtomicQueryMTPV2:
81617
- generateInputFn = this.generateMTPV2Inputs.bind(this);
81618
- break;
81619
- case exports.CircuitId.AtomicQueryMTPV2OnChain:
81620
- generateInputFn = this.generateMTPV2OnChainInputs.bind(this);
81621
- break;
81622
- case exports.CircuitId.AtomicQuerySigV2:
81623
- generateInputFn = this.generateQuerySigV2Inputs.bind(this);
81624
- break;
81625
- case exports.CircuitId.AtomicQuerySigV2OnChain:
81626
- generateInputFn = this.generateQuerySigV2OnChainInputs.bind(this);
81627
- break;
81628
- default:
81629
- throw new Error(`circuit with id ${proofReq.circuitId} is not supported by issuer`);
81630
- }
81631
- return generateInputFn(preparedCredential, identifier, proofReq, params);
81632
- }
81633
- async generateMTPV2Inputs(preparedCredential, identifier, proofReq, params) {
81634
- const circuitClaimData = await this.newCircuitClaimData(preparedCredential.credential, preparedCredential.credentialCoreClaim);
81635
- circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
81636
- const circuitInputs = new AtomicQueryMTPV2Inputs();
81637
- circuitInputs.id = W$3.idFromDID(identifier);
81638
- circuitInputs.requestID = BigInt(proofReq.id);
81639
- const { query, vp } = await this.toCircuitsQuery(proofReq.query, preparedCredential.credential, preparedCredential.credentialCoreClaim);
81640
- circuitInputs.query = query;
81641
- circuitInputs.claim = {
81642
- issuerID: circuitClaimData.issuerId,
81643
- claim: circuitClaimData.claim,
81644
- incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
81645
- nonRevProof: circuitClaimData.nonRevProof
81646
- };
81647
- circuitInputs.currentTimeStamp = S$3(new Date());
81648
- circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
81649
- circuitInputs.profileNonce = BigInt(params.authProfileNonce);
81650
- circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
81651
- return { inputs: circuitInputs.inputsMarshal(), vp };
81652
- }
81653
- async generateMTPV2OnChainInputs(preparedCredential, identifier, proofReq, params) {
81654
- const circuitClaimData = await this.newCircuitClaimData(preparedCredential.credential, preparedCredential.credentialCoreClaim);
81655
- const authPrepared = await this.prepareAuthBJJCredential(identifier);
81656
- const authClaimData = await this.newCircuitClaimData(authPrepared.authCredential, authPrepared.authCoreClaim);
81657
- circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
81658
- const circuitInputs = new AtomicQueryMTPV2OnChainInputs();
81659
- const id = W$3.idFromDID(identifier);
81660
- circuitInputs.id = W$3.idFromDID(identifier);
81661
- circuitInputs.requestID = BigInt(proofReq.id);
81662
- const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
81663
- const gistProof = toGISTProof(stateProof);
81664
- circuitInputs.gistProof = gistProof;
81665
- if (authClaimData?.treeState) {
81666
- circuitInputs.treeState = {
81667
- state: authClaimData?.treeState?.state,
81668
- claimsRoot: authClaimData?.treeState?.claimsRoot,
81669
- revocationRoot: authClaimData?.treeState?.revocationRoot,
81670
- rootOfRoots: authClaimData?.treeState?.rootOfRoots
81671
- };
81672
- }
81673
- circuitInputs.authClaim = authClaimData.claim;
81674
- circuitInputs.authClaimIncMtp = authClaimData.proof;
81675
- circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof;
81676
- if (!params.challenge) {
81677
- throw new Error('challenge must be provided for onchain circuits');
81678
- }
81679
- const signature = await this._identityWallet.signChallenge(params.challenge, authPrepared.authCredential);
81680
- circuitInputs.signature = signature;
81681
- circuitInputs.challenge = params.challenge;
81682
- const { query, vp } = await this.toCircuitsQuery(proofReq.query, preparedCredential.credential, preparedCredential.credentialCoreClaim);
81683
- circuitInputs.query = query;
81684
- circuitInputs.claim = {
81685
- issuerID: circuitClaimData.issuerId,
81686
- claim: circuitClaimData.claim,
81687
- incProof: { proof: circuitClaimData.proof, treeState: circuitClaimData.treeState },
81688
- nonRevProof: circuitClaimData.nonRevProof
81689
- };
81690
- circuitInputs.currentTimeStamp = S$3(new Date());
81691
- circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
81692
- circuitInputs.profileNonce = BigInt(params.authProfileNonce);
81693
- circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
81694
- return { inputs: circuitInputs.inputsMarshal(), vp };
81695
- }
81696
- async generateQuerySigV2Inputs(preparedCredential, identifier, proofReq, params) {
81697
- const circuitClaimData = await this.newCircuitClaimData(preparedCredential.credential, preparedCredential.credentialCoreClaim);
81698
- circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
81699
- const circuitInputs = new AtomicQuerySigV2Inputs();
81700
- circuitInputs.id = W$3.idFromDID(identifier);
81701
- circuitInputs.claim = {
81702
- issuerID: circuitClaimData?.issuerId,
81703
- signatureProof: circuitClaimData.signatureProof,
81704
- claim: circuitClaimData.claim,
81705
- nonRevProof: circuitClaimData.nonRevProof
81706
- };
81707
- circuitInputs.requestID = BigInt(proofReq.id);
81708
- circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
81709
- circuitInputs.profileNonce = BigInt(params.authProfileNonce);
81710
- circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
81711
- const { query, vp } = await this.toCircuitsQuery(proofReq.query, preparedCredential.credential, preparedCredential.credentialCoreClaim);
81712
- circuitInputs.query = query;
81713
- circuitInputs.currentTimeStamp = S$3(new Date());
81714
- return { inputs: circuitInputs.inputsMarshal(), vp };
81715
- }
81716
- async generateQuerySigV2OnChainInputs(preparedCredential, identifier, proofReq, params) {
81717
- const circuitClaimData = await this.newCircuitClaimData(preparedCredential.credential, preparedCredential.credentialCoreClaim);
81718
- const authPrepared = await this.prepareAuthBJJCredential(identifier);
81719
- const authClaimData = await this.newCircuitClaimData(authPrepared.authCredential, authPrepared.authCoreClaim);
81720
- circuitClaimData.nonRevProof = toClaimNonRevStatus(preparedCredential.revStatus);
81721
- const circuitInputs = new AtomicQuerySigV2OnChainInputs();
81722
- const id = W$3.idFromDID(identifier);
81723
- circuitInputs.id = id;
81724
- circuitInputs.claim = {
81725
- issuerID: circuitClaimData.issuerId,
81726
- signatureProof: circuitClaimData.signatureProof,
81727
- claim: circuitClaimData.claim,
81728
- nonRevProof: circuitClaimData.nonRevProof
81729
- };
81730
- circuitInputs.requestID = BigInt(proofReq.id);
81731
- circuitInputs.claimSubjectProfileNonce = BigInt(params.credentialSubjectProfileNonce);
81732
- circuitInputs.profileNonce = BigInt(params.authProfileNonce);
81733
- circuitInputs.skipClaimRevocationCheck = params.skipRevocation;
81734
- const { query, vp } = await this.toCircuitsQuery(proofReq.query, preparedCredential.credential, preparedCredential.credentialCoreClaim);
81735
- circuitInputs.query = query;
81736
- circuitInputs.currentTimeStamp = S$3(new Date());
81737
- if (authClaimData.treeState) {
81738
- circuitInputs.treeState = {
81739
- state: authClaimData.treeState?.state,
81740
- claimsRoot: authClaimData.treeState?.claimsRoot,
81741
- revocationRoot: authClaimData.treeState?.revocationRoot,
81742
- rootOfRoots: authClaimData.treeState?.rootOfRoots
81743
- };
81744
- }
81745
- const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
81746
- const gistProof = toGISTProof(stateProof);
81747
- circuitInputs.gistProof = gistProof;
81748
- circuitInputs.authClaim = authClaimData.claim;
81749
- circuitInputs.authClaimIncMtp = authClaimData.proof;
81750
- circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof;
81751
- if (!params.challenge) {
81752
- throw new Error('challenge must be provided for onchain circuits');
81753
- }
81754
- const signature = await this._identityWallet.signChallenge(params.challenge, authPrepared.authCredential);
81755
- circuitInputs.signature = signature;
81756
- circuitInputs.challenge = params.challenge;
81757
- return { inputs: circuitInputs.inputsMarshal(), vp };
83074
+ async generateInputs(preparedCredential, identifier, proofReq, params, circuitQueries) {
83075
+ return this._inputsGenerator.generateInputs({
83076
+ preparedCredential,
83077
+ identifier,
83078
+ proofReq,
83079
+ params,
83080
+ circuitQueries
83081
+ });
81758
83082
  }
81759
- // NewCircuitClaimData generates circuits claim structure
81760
- async newCircuitClaimData(credential, coreClaim) {
81761
- const smtProof = credential.getIden3SparseMerkleTreeProof();
81762
- const circuitClaim = new CircuitClaim();
81763
- circuitClaim.claim = coreClaim;
81764
- circuitClaim.issuerId = W$3.idFromDID(W$3.parse(credential.issuer));
81765
- if (smtProof) {
81766
- circuitClaim.proof = smtProof.mtp;
81767
- circuitClaim.treeState = {
81768
- state: smtProof.issuerData.state.value,
81769
- claimsRoot: smtProof.issuerData.state.claimsTreeRoot,
81770
- revocationRoot: smtProof.issuerData.state.revocationTreeRoot,
81771
- rootOfRoots: smtProof.issuerData.state.rootOfRoots
81772
- };
83083
+ async toCircuitsQuery(credential, queryMetadata, merklizedCredential) {
83084
+ if (queryMetadata.merklizedSchema && !merklizedCredential) {
83085
+ throw new Error('merklized root position is set to None for merklized schema');
81773
83086
  }
81774
- const sigProof = credential.getBJJSignature2021Proof();
81775
- if (sigProof) {
81776
- const issuerDID = sigProof.issuerData.id;
81777
- let userDID;
81778
- if (!credential.credentialSubject.id) {
81779
- userDID = issuerDID;
81780
- }
81781
- else {
81782
- if (typeof credential.credentialSubject.id !== 'string') {
81783
- throw new Error('credential status `id` is not a string');
81784
- }
81785
- userDID = W$3.parse(credential.credentialSubject.id);
81786
- }
81787
- if (!sigProof.issuerData.credentialStatus) {
81788
- throw new Error("can't check the validity of issuer auth claim: no credential status in proof");
81789
- }
81790
- const opts = {
81791
- issuerGenesisState: sigProof.issuerData.state,
81792
- issuerDID,
81793
- userDID
81794
- };
81795
- const rs = await this._credentialWallet.getRevocationStatus(sigProof.issuerData.credentialStatus, opts);
81796
- if (!rs) {
81797
- throw new Error("can't fetch the credential status of issuer auth claim");
81798
- }
81799
- const issuerAuthNonRevProof = toClaimNonRevStatus(rs);
81800
- if (!sigProof.issuerData.mtp) {
81801
- throw new Error('issuer auth credential must have a mtp proof');
81802
- }
81803
- if (!sigProof.issuerData.authCoreClaim) {
81804
- throw new Error('issuer auth credential must have a core claim proof');
81805
- }
81806
- circuitClaim.signatureProof = {
81807
- signature: sigProof.signature,
81808
- issuerAuthIncProof: {
81809
- proof: sigProof.issuerData.mtp,
81810
- treeState: {
81811
- state: sigProof.issuerData.state.value,
81812
- claimsRoot: sigProof.issuerData.state.claimsTreeRoot,
81813
- revocationRoot: sigProof.issuerData.state.revocationTreeRoot,
81814
- rootOfRoots: sigProof.issuerData.state.rootOfRoots
81815
- }
81816
- },
81817
- issuerAuthClaim: sigProof.issuerData.authCoreClaim,
81818
- issuerAuthNonRevProof
81819
- };
83087
+ if (!queryMetadata.merklizedSchema && merklizedCredential) {
83088
+ throw new Error('merklized root position is not set to None for non-merklized schema');
81820
83089
  }
81821
- return circuitClaim;
81822
- }
81823
- async toCircuitsQuery(query, credential, coreClaim) {
81824
- const mtPosition = coreClaim.getMerklizedPosition();
81825
- return mtPosition === U$2.None
81826
- ? this.prepareNonMerklizedQuery(query, credential)
81827
- : this.prepareMerklizedQuery(query, credential);
81828
- }
81829
- async prepareMerklizedQuery(query, credential) {
81830
- const parsedQuery = await this.parseRequest(query.credentialSubject);
81831
- const ldContext = await this.loadLdContextFromJSONSchema(credential.credentialSchema.id);
81832
- let path = new lf();
81833
- if (parsedQuery.fieldName) {
81834
- path = await lf.getContextPathKey(byteDecoder.decode(ldContext), credential.type[1], parsedQuery.fieldName, this._ldOptions);
81835
- }
81836
- path.prepend(['https://www.w3.org/2018/credentials#credentialSubject']);
81837
- const mk = await credential.merklize(this._ldOptions);
81838
- const { proof, value: mtValue } = await mk.proof(path);
81839
- const pathKey = await path.mtEntry();
81840
- parsedQuery.query.valueProof = new ValueProof();
81841
- parsedQuery.query.valueProof.mtp = proof;
81842
- parsedQuery.query.valueProof.path = pathKey;
81843
- parsedQuery.query.valueProof.mtp = proof;
81844
- const mtEntry = await mtValue?.mtEntry();
81845
- if (!mtEntry) {
81846
- throw new Error(`can't merklize credential: no merkle tree entry found`);
81847
- }
81848
- parsedQuery.query.valueProof.value = mtEntry;
81849
- // for merklized credentials slotIndex in query must be equal to zero
81850
- // and not a position of merklization root.
81851
- // it has no influence on check in the off-chain circuits, but it aligns with onchain verification standard
81852
- parsedQuery.query.slotIndex = 0;
81853
- if (!parsedQuery.fieldName) {
81854
- const resultQuery = parsedQuery.query;
81855
- resultQuery.operator = QueryOperators.$eq;
81856
- resultQuery.values = [mtEntry];
81857
- return { query: resultQuery };
81858
- }
81859
- if (parsedQuery.isSelectiveDisclosure) {
81860
- const rawValue = mk.rawValue(path);
81861
- const vp = createVerifiablePresentation(query.context ?? '', query.type ?? '', parsedQuery.fieldName, rawValue);
81862
- const resultQuery = parsedQuery.query;
81863
- resultQuery.operator = QueryOperators.$eq;
81864
- resultQuery.values = [mtEntry];
81865
- return { query: resultQuery, vp };
81866
- }
81867
- if (parsedQuery.rawValue === null || parsedQuery.rawValue === undefined) {
81868
- throw new Error('value is not presented in the query');
81869
- }
81870
- const ldType = await mk.jsonLDType(path);
81871
- parsedQuery.query.values = await this.transformQueryValueToBigInts(parsedQuery.rawValue, ldType);
81872
- return { query: parsedQuery.query };
81873
- }
81874
- async prepareNonMerklizedQuery(query, credential) {
81875
- const ldContext = await this.loadLdContextFromJSONSchema(credential.credentialSchema.id);
81876
- if (query.credentialSubject && Object.keys(query.credentialSubject).length > 1) {
81877
- throw new Error('multiple requests are not supported');
81878
- }
81879
- const parsedQuery = await this.parseRequest(query.credentialSubject);
81880
- if (!query.type) {
81881
- throw new Error('query type is not defined');
81882
- }
81883
- parsedQuery.query.slotIndex = await Parser.getFieldSlotIndex(parsedQuery.fieldName, query.type, ldContext);
81884
- const { vp, mzValue, dataType } = await verifiablePresentationFromCred(credential, query, parsedQuery.fieldName, this._ldOptions);
81885
- if (parsedQuery.isSelectiveDisclosure) {
81886
- const resultQuery = parsedQuery.query;
81887
- resultQuery.operator = QueryOperators.$eq;
81888
- resultQuery.values = [await mzValue.mtEntry()];
81889
- return { query: resultQuery, vp };
81890
- }
81891
- if (parsedQuery.rawValue === null || parsedQuery.rawValue === undefined) {
81892
- throw new Error('value is not presented in the query');
81893
- }
81894
- parsedQuery.query.values = await this.transformQueryValueToBigInts(parsedQuery.rawValue, dataType);
81895
- return { query: parsedQuery.query };
81896
- }
81897
- async loadLdContextFromJSONSchema(jsonSchemaURL) {
83090
+ const query = new Query();
83091
+ query.slotIndex = queryMetadata.slotIndex;
83092
+ query.operator = queryMetadata.operator;
83093
+ query.values = queryMetadata.values;
83094
+ if (queryMetadata.merklizedSchema && merklizedCredential) {
83095
+ const { proof, value: mtValue } = await merklizedCredential.proof(queryMetadata.path);
83096
+ query.valueProof = new ValueProof();
83097
+ query.valueProof.mtp = proof;
83098
+ query.valueProof.path = queryMetadata.claimPathKey;
83099
+ const mtEntry = await mtValue?.mtEntry();
83100
+ if (!mtEntry) {
83101
+ throw new Error(`can't merklize credential: no merkle tree entry found`);
83102
+ }
83103
+ query.valueProof.value = mtEntry;
83104
+ if (!queryMetadata.fieldName) {
83105
+ query.values = [mtEntry];
83106
+ return query;
83107
+ }
83108
+ }
83109
+ if (queryMetadata.operator === exports.Operators.SD) {
83110
+ const [first, ...rest] = queryMetadata.fieldName.split('.');
83111
+ let v = credential.credentialSubject[first];
83112
+ for (const part of rest) {
83113
+ v = v[part];
83114
+ }
83115
+ if (typeof v === 'undefined') {
83116
+ throw new Error(`credential doesn't contain value for field ${queryMetadata.fieldName}`);
83117
+ }
83118
+ query.values = await transformQueryValueToBigInts(v, queryMetadata.datatype);
83119
+ }
83120
+ return query;
83121
+ }
83122
+ async loadLdContext(context) {
81898
83123
  const loader = af(this._ldOptions);
81899
- let schema;
81900
- try {
81901
- schema = (await loader(jsonSchemaURL)).document;
81902
- }
81903
- catch (e) {
81904
- throw new Error(`can't load credential schema ${jsonSchemaURL}`);
81905
- }
81906
- const jsonSchema = schema;
81907
83124
  let ldSchema;
81908
- let ldContextUrl = '';
81909
83125
  try {
81910
- ldContextUrl = jsonSchema.$metadata.uris['jsonLdContext'];
81911
- if (!ldContextUrl) {
81912
- throw new Error('ldContext is not defined in json schema metadata');
81913
- }
81914
- ldSchema = (await loader(ldContextUrl)).document;
83126
+ ldSchema = (await loader(context)).document;
81915
83127
  }
81916
83128
  catch (e) {
81917
- throw new Error(`can't load ld context from url ${ldContextUrl}`);
83129
+ throw new Error(`can't load ld context from url ${context}`);
81918
83130
  }
81919
83131
  return byteEncoder.encode(JSON.stringify(ldSchema));
81920
83132
  }
81921
- async parseRequest(req) {
81922
- if (!req) {
81923
- const query = new Query();
81924
- query.operator = QueryOperators.$eq;
81925
- return { query, fieldName: '' };
81926
- }
81927
- const entries = Object.entries(req);
81928
- if (entries.length > 1) {
81929
- throw new Error(`multiple requests not supported`);
81930
- }
81931
- const [fieldName, fieldReq] = entries[0];
81932
- const fieldReqEntries = Object.entries(fieldReq);
81933
- if (fieldReqEntries.length > 1) {
81934
- throw new Error(`multiple predicates for one field not supported`);
81935
- }
81936
- const isSelectiveDisclosure = fieldReqEntries.length === 0;
81937
- const query = new Query();
81938
- if (isSelectiveDisclosure) {
81939
- return { query, fieldName, isSelectiveDisclosure };
81940
- }
81941
- let operator = 0;
81942
- const [key, value] = fieldReqEntries[0];
81943
- if (!QueryOperators[key]) {
81944
- throw new Error(`operator is not supported by lib`);
81945
- }
81946
- operator = QueryOperators[key];
81947
- query.operator = operator;
81948
- return { query, fieldName, rawValue: value };
81949
- }
81950
- async transformQueryValueToBigInts(value, ldType) {
81951
- const values = new Array(64).fill(BigInt(0));
81952
- if (Array.isArray(value)) {
81953
- for (let index = 0; index < value.length; index++) {
81954
- values[index] = await ff.hashValue(ldType, value[index]);
81955
- }
81956
- }
81957
- else {
81958
- values[0] = await ff.hashValue(ldType, value);
81959
- }
81960
- return values;
81961
- }
81962
83133
  /** {@inheritdoc IProofService.generateAuthV2Inputs} */
81963
83134
  async generateAuthV2Inputs(hash, did, circuitId) {
81964
83135
  if (circuitId !== exports.CircuitId.AuthV2) {
@@ -81966,9 +83137,12 @@ var PolygonIdSdk = (function (exports) {
81966
83137
  }
81967
83138
  const { nonce: authProfileNonce, genesisDID } = await this._identityWallet.getGenesisDIDMetadata(did);
81968
83139
  const challenge = T$3.bytesToInt(hash.reverse());
81969
- const authPrepared = await this.prepareAuthBJJCredential(genesisDID);
81970
- const authClaimData = await this.newCircuitClaimData(authPrepared.authCredential, authPrepared.authCoreClaim);
81971
- const signature = await this._identityWallet.signChallenge(challenge, authPrepared.authCredential);
83140
+ const authPrepared = await this._inputsGenerator.prepareAuthBJJCredential(genesisDID);
83141
+ const authClaimData = await this._inputsGenerator.newCircuitClaimData({
83142
+ credential: authPrepared.credential,
83143
+ credentialCoreClaim: authPrepared.coreClaim
83144
+ });
83145
+ const signature = await this._identityWallet.signChallenge(challenge, authPrepared.credential);
81972
83146
  const id = W$3.idFromDID(genesisDID);
81973
83147
  const stateProof = await this._stateStorage.getGISTProof(id.bigInt());
81974
83148
  const gistProof = toGISTProof(stateProof);
@@ -82004,7 +83178,7 @@ var PolygonIdSdk = (function (exports) {
82004
83178
  }
82005
83179
  return true;
82006
83180
  }
82007
- async findCredential(did, query) {
83181
+ async findCredentialByProofQuery(did, query) {
82008
83182
  const credentials = await this._identityWallet.findOwnedCredentialsByDID(did, query);
82009
83183
  if (!credentials.length) {
82010
83184
  throw new Error(`no credentials belong to did or its profiles`);
@@ -82012,18 +83186,11 @@ var PolygonIdSdk = (function (exports) {
82012
83186
  // For EQ / IN / NIN / LT / GT operations selective if credential satisfies query - we can get any.
82013
83187
  // TODO: choose credential for selective credentials
82014
83188
  const credential = query.skipClaimRevocationCheck
82015
- ? credentials[0]
82016
- : (await this._credentialWallet.findNonRevokedCredential(credentials)).cred;
83189
+ ? { cred: credentials[0], revStatus: undefined }
83190
+ : await this._credentialWallet.findNonRevokedCredential(credentials);
82017
83191
  return credential;
82018
83192
  }
82019
83193
  }
82020
- // BJJSignatureFromHexString converts hex to babyjub.Signature
82021
- const bJJSignatureFromHexString = async (sigHex) => {
82022
- const signatureBytes = b$5.decodeString(sigHex);
82023
- const compressedSig = Uint8Array.from(signatureBytes).slice(0, 64);
82024
- const bjjSig = EI.newFromCompressed(compressedSig);
82025
- return bjjSig;
82026
- };
82027
83194
 
82028
83195
  /**
82029
83196
  * creates empty basic message
@@ -82677,15 +83844,55 @@ var PolygonIdSdk = (function (exports) {
82677
83844
  from: did.string(),
82678
83845
  to: authRequest.from
82679
83846
  };
82680
- for (const proofReq of authRequest.body.scope) {
82681
- const zkpReq = {
82682
- id: proofReq.id,
82683
- circuitId: proofReq.circuitId,
82684
- query: proofReq.query
82685
- };
83847
+ const requestScope = authRequest.body.scope;
83848
+ const combinedQueries = requestScope.reduce((acc, proofReq) => {
83849
+ const groupId = proofReq.query.groupId;
83850
+ if (!groupId) {
83851
+ return acc;
83852
+ }
83853
+ const existedData = acc.get(groupId);
83854
+ if (!existedData) {
83855
+ const seed = V$3(12);
83856
+ const dataView = new DataView(seed.buffer);
83857
+ const linkNonce = dataView.getUint32(0);
83858
+ acc.set(groupId, { query: proofReq.query, linkNonce });
83859
+ return acc;
83860
+ }
83861
+ const credentialSubject = mergeObjects(existedData.query.credentialSubject, proofReq.query.credentialSubject);
83862
+ acc.set(groupId, {
83863
+ ...existedData,
83864
+ query: {
83865
+ skipClaimRevocationCheck: existedData.query.skipClaimRevocationCheck || proofReq.query.skipClaimRevocationCheck,
83866
+ ...existedData.query,
83867
+ credentialSubject
83868
+ }
83869
+ });
83870
+ return acc;
83871
+ }, new Map());
83872
+ const groupedCredentialsCache = new Map();
83873
+ for (const proofReq of requestScope) {
82686
83874
  const query = proofReq.query;
82687
- const zkpRes = await this._proofService.generateProof(zkpReq, did, {
82688
- skipRevocation: query.skipClaimRevocationCheck ?? false
83875
+ const groupId = query.groupId;
83876
+ const combinedQueryData = combinedQueries.get(groupId);
83877
+ if (groupId) {
83878
+ if (!combinedQueryData) {
83879
+ throw new Error(`Invalid group id ${query.groupId}`);
83880
+ }
83881
+ const combinedQuery = combinedQueryData.query;
83882
+ if (!groupedCredentialsCache.has(groupId)) {
83883
+ const credWithRevStatus = await this._proofService.findCredentialByProofQuery(did, combinedQueryData.query);
83884
+ if (!credWithRevStatus.cred) {
83885
+ throw new Error(`Credential not found for query ${JSON.stringify(combinedQuery)}`);
83886
+ }
83887
+ groupedCredentialsCache.set(groupId, credWithRevStatus);
83888
+ }
83889
+ }
83890
+ const credWithRevStatus = groupedCredentialsCache.get(groupId);
83891
+ const zkpRes = await this._proofService.generateProof(proofReq, did, {
83892
+ skipRevocation: Boolean(query.skipClaimRevocationCheck),
83893
+ credential: credWithRevStatus?.cred,
83894
+ credentialRevocationStatus: credWithRevStatus?.revStatus,
83895
+ linkNonce: combinedQueryData?.linkNonce ? BigInt(combinedQueryData.linkNonce) : undefined
82689
83896
  });
82690
83897
  authResponse.body.scope.push(zkpRes);
82691
83898
  }
@@ -82819,7 +84026,8 @@ var PolygonIdSdk = (function (exports) {
82819
84026
  this._zkpVerifier = _zkpVerifier;
82820
84027
  this._allowedCircuits = [
82821
84028
  exports.CircuitId.AtomicQueryMTPV2OnChain,
82822
- exports.CircuitId.AtomicQuerySigV2OnChain
84029
+ exports.CircuitId.AtomicQuerySigV2OnChain,
84030
+ exports.CircuitId.AtomicQueryV3OnChain
82823
84031
  ];
82824
84032
  }
82825
84033
  /**
@@ -82853,19 +84061,28 @@ var PolygonIdSdk = (function (exports) {
82853
84061
  throw new Error("Can't sign transaction. Provide Signer in options.");
82854
84062
  }
82855
84063
  const zkRequests = [];
84064
+ const { contract_address, chain_id } = ciRequest.body.transaction_data;
84065
+ const networkFlag = Object.keys(u$2).find((key) => u$2[key] === chain_id);
84066
+ if (!networkFlag) {
84067
+ throw new Error(`Invalid chain id ${chain_id}`);
84068
+ }
84069
+ const [blockchain, networkId] = networkFlag.split(':');
84070
+ const verifierId = buildVerifierId(contract_address, {
84071
+ blockchain,
84072
+ networkId,
84073
+ // DidMethod.Iden3 is used based on discussions: all onchain issuers have iden3 did method by default. This can be changed in the release of v3 circuit.
84074
+ method: h$3.Iden3
84075
+ });
84076
+ const verifierDid = W$3.parseFromId(verifierId);
82856
84077
  for (const proofReq of ciRequest.body.scope) {
82857
84078
  if (!this._allowedCircuits.includes(proofReq.circuitId)) {
82858
84079
  throw new Error(`Can't handle circuit ${proofReq.circuitId}. Only onchain circuits are allowed.`);
82859
84080
  }
82860
- const zkpReq = {
82861
- id: proofReq.id,
82862
- circuitId: proofReq.circuitId,
82863
- query: proofReq.query
82864
- };
82865
84081
  const query = proofReq.query;
82866
- const zkpRes = await this._proofService.generateProof(zkpReq, did, {
84082
+ const zkpRes = await this._proofService.generateProof(proofReq, did, {
82867
84083
  skipRevocation: query.skipClaimRevocationCheck ?? false,
82868
- challenge: opts.challenge
84084
+ challenge: opts.challenge,
84085
+ verifierDid
82869
84086
  });
82870
84087
  zkRequests.push(zkpRes);
82871
84088
  }
@@ -82884,6 +84101,10 @@ var PolygonIdSdk = (function (exports) {
82884
84101
  exports.AtomicQuerySigV2OnChainInputs = AtomicQuerySigV2OnChainInputs;
82885
84102
  exports.AtomicQuerySigV2OnChainPubSignals = AtomicQuerySigV2OnChainPubSignals;
82886
84103
  exports.AtomicQuerySigV2PubSignals = AtomicQuerySigV2PubSignals;
84104
+ exports.AtomicQueryV3Inputs = AtomicQueryV3Inputs;
84105
+ exports.AtomicQueryV3OnChainInputs = AtomicQueryV3OnChainInputs;
84106
+ exports.AtomicQueryV3OnChainPubSignals = AtomicQueryV3OnChainPubSignals;
84107
+ exports.AtomicQueryV3PubSignals = AtomicQueryV3PubSignals;
82887
84108
  exports.AuthHandler = AuthHandler;
82888
84109
  exports.AuthV2Inputs = AuthV2Inputs;
82889
84110
  exports.AuthV2PubSignals = AuthV2PubSignals;
@@ -82926,6 +84147,10 @@ var PolygonIdSdk = (function (exports) {
82926
84147
  exports.JsonSchemaValidator = JsonSchemaValidator;
82927
84148
  exports.KMS = KMS;
82928
84149
  exports.LDParser = LDParser;
84150
+ exports.LinkedMultiQueryInputs = LinkedMultiQueryInputs;
84151
+ exports.LinkedMultiQueryPubSignals = LinkedMultiQueryPubSignals;
84152
+ exports.LinkedNullifierInputs = LinkedNullifierInputs;
84153
+ exports.LinkedNullifierPubSignals = LinkedNullifierPubSignals;
82929
84154
  exports.LocalStoragePrivateKeyStore = LocalStoragePrivateKeyStore;
82930
84155
  exports.MerkleTreeIndexedDBStorage = MerkleTreeIndexedDBStorage;
82931
84156
  exports.MerkleTreeLocalStorage = MerkleTreeLocalStorage;
@@ -82952,13 +84177,14 @@ var PolygonIdSdk = (function (exports) {
82952
84177
  exports.VerificationHandlerFunc = VerificationHandlerFunc;
82953
84178
  exports.W3CCredential = W3CCredential;
82954
84179
  exports.ZKPPacker = ZKPPacker;
82955
- exports.bJJSignatureFromHexString = bJJSignatureFromHexString;
84180
+ exports.availableTypesOperators = availableTypesOperators;
82956
84181
  exports.base58ToBytes = base58ToBytes;
82957
84182
  exports.base64ToBytes = base64ToBytes;
82958
84183
  exports.base64UrlToBytes = base64UrlToBytes;
82959
84184
  exports.bigIntArrayToStringArray = bigIntArrayToStringArray;
82960
- exports.buildQueryPath = buildQueryPath;
84185
+ exports.buildFieldPath = buildFieldPath;
82961
84186
  exports.buildTreeState = buildTreeState;
84187
+ exports.buildVerifierId = buildVerifierId;
82962
84188
  exports.byteDecoder = byteDecoder;
82963
84189
  exports.byteEncoder = byteEncoder;
82964
84190
  exports.bytesToBase58 = bytesToBase58;
@@ -82976,7 +84202,7 @@ var PolygonIdSdk = (function (exports) {
82976
84202
  exports.decodeBase64url = decodeBase64url;
82977
84203
  exports.defaultEthConnectionConfig = defaultEthConnectionConfig;
82978
84204
  exports.defaultMTLevels = defaultMTLevels;
82979
- exports.defaultMTLevelsClaimsMerklization = defaultMTLevelsClaimsMerklization;
84205
+ exports.defaultMTLevelsClaim = defaultMTLevelsClaim;
82980
84206
  exports.defaultMTLevelsOnChain = defaultMTLevelsOnChain;
82981
84207
  exports.defaultValueArraySize = defaultValueArraySize;
82982
84208
  exports.defineMerklizedRootPosition = defineMerklizedRootPosition;
@@ -82987,15 +84213,22 @@ var PolygonIdSdk = (function (exports) {
82987
84213
  exports.factoryComparer = factoryComparer;
82988
84214
  exports.fieldToByteArray = fieldToByteArray;
82989
84215
  exports.fillSlot = fillSlot;
84216
+ exports.findValue = findValue;
82990
84217
  exports.generateProfileDID = generateProfileDID;
82991
84218
  exports.getNodeAuxValue = getNodeAuxValue;
82992
84219
  exports.getProperties = getProperties;
84220
+ exports.getUserDIDFromCredential = getUserDIDFromCredential;
82993
84221
  exports.hexToBytes = hexToBytes$1;
82994
84222
  exports.isGenesisState = isGenesisState;
82995
84223
  exports.isGenesisStateId = isGenesisStateId;
82996
84224
  exports.isIssuerGenesis = isIssuerGenesis;
84225
+ exports.isValidOperation = isValidOperation;
82997
84226
  exports.jsonLDMerklizer = index;
82998
84227
  exports.keyPath = keyPath;
84228
+ exports.mergeObjects = mergeObjects;
84229
+ exports.parseCredentialSubject = parseCredentialSubject;
84230
+ exports.parseQueriesMetadata = parseQueriesMetadata;
84231
+ exports.parseQueryMetadata = parseQueryMetadata;
82999
84232
  exports.prepareCircuitArrayValues = prepareCircuitArrayValues;
83000
84233
  exports.prepareSiblingsStr = prepareSiblingsStr;
83001
84234
  exports.pushHashesToRHS = pushHashesToRHS;
@@ -83008,7 +84241,7 @@ var PolygonIdSdk = (function (exports) {
83008
84241
  exports.toClaimNonRevStatus = toClaimNonRevStatus;
83009
84242
  exports.toGISTProof = toGISTProof;
83010
84243
  exports.toRevocationStatus = toRevocationStatus;
83011
- exports.verifiablePresentationFromCred = verifiablePresentationFromCred;
84244
+ exports.transformQueryValueToBigInts = transformQueryValueToBigInts;
83012
84245
 
83013
84246
  return exports;
83014
84247