@reclaimprotocol/js-sdk 4.14.0 → 5.0.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
9
  var __getProtoOf = Object.getPrototypeOf;
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
19
21
  }
20
22
  return a;
21
23
  };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
25
  var __commonJS = (cb, mod) => function __require() {
23
26
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
24
27
  };
@@ -69,7 +72,7 @@ var require_package = __commonJS({
69
72
  "package.json"(exports2, module2) {
70
73
  module2.exports = {
71
74
  name: "@reclaimprotocol/js-sdk",
72
- version: "4.14.0",
75
+ version: "5.0.0-dev.0",
73
76
  description: "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
74
77
  main: "dist/index.js",
75
78
  types: "dist/index.d.ts",
@@ -143,7 +146,7 @@ var require_package = __commonJS({
143
146
  devDependencies: {
144
147
  "@commitlint/cli": "^17.7.1",
145
148
  "@commitlint/config-conventional": "^17.7.0",
146
- "@release-it/conventional-changelog": "^10.0.1",
149
+ "@release-it/conventional-changelog": "10.0.6",
147
150
  "@types/jest": "^30.0.0",
148
151
  "@types/qs": "^6.9.11",
149
152
  "@types/url-parse": "^1.4.11",
@@ -151,7 +154,7 @@ var require_package = __commonJS({
151
154
  jest: "^30.1.3",
152
155
  "jest-environment-jsdom": "^30.1.2",
153
156
  qs: "^6.11.2",
154
- "release-it": "^19.0.4",
157
+ "release-it": "^19.2.4",
155
158
  "ts-jest": "^29.4.1",
156
159
  tsup: "^8.0.1",
157
160
  typescript: "^5.3.3"
@@ -174,7 +177,6 @@ var require_package = __commonJS({
174
177
  var index_exports = {};
175
178
  __export(index_exports, {
176
179
  ReclaimProofRequest: () => ReclaimProofRequest,
177
- assertValidProof: () => assertValidProof,
178
180
  clearDeviceCache: () => clearDeviceCache,
179
181
  getDeviceType: () => getDeviceType,
180
182
  getMobileDeviceType: () => getMobileDeviceType,
@@ -214,6 +216,8 @@ Caused by: ${innerError.stack}`;
214
216
  }
215
217
  var TimeoutError = createErrorClass("TimeoutError");
216
218
  var ProofNotVerifiedError = createErrorClass("ProofNotVerifiedError");
219
+ var ProofNotValidatedError = createErrorClass("ProofNotValidatedError");
220
+ var UnknownProofsNotValidatedError = createErrorClass("UnknownProofsNotValidatedError");
217
221
  var SessionNotStartedError = createErrorClass("SessionNotStartedError");
218
222
  var ProviderNotFoundError = createErrorClass("ProviderNotFoundError");
219
223
  var SignatureGeneratingError = createErrorClass("SignatureGeneratingError");
@@ -233,6 +237,7 @@ var SetContextError = createErrorClass("SetContextError");
233
237
  var SetSignatureError = createErrorClass("SetSignatureError");
234
238
  var GetAppCallbackUrlError = createErrorClass("GetAppCallbackUrlError");
235
239
  var StatusUrlError = createErrorClass("StatusUrlError");
240
+ var ProviderConfigFetchError = createErrorClass("ProviderConfigFetchError");
236
241
  var InavlidParametersError = createErrorClass("InavlidParametersError");
237
242
  var ProofSubmissionFailedError = createErrorClass("ProofSubmissionFailedError");
238
243
  var ErrorDuringVerificationError = createErrorClass("ErrorDuringVerificationError");
@@ -328,9 +333,13 @@ var constants = {
328
333
  get DEFAULT_RECLAIM_STATUS_URL() {
329
334
  return `${BACKEND_BASE_URL}/api/sdk/session/`;
330
335
  },
336
+ // Default attestors URL for Reclaim sessions
331
337
  get DEFAULT_ATTESTORS_URL() {
332
338
  return `${BACKEND_BASE_URL}/api/attestors`;
333
339
  },
340
+ DEFAULT_PROVIDER_URL(providerId, exactProviderVersionString) {
341
+ return `${BACKEND_BASE_URL}/api/providers/${providerId}?versionNumber=${exactProviderVersionString}`;
342
+ },
334
343
  // URL for sharing Reclaim templates
335
344
  RECLAIM_SHARE_URL: "https://share.reclaimprotocol.org/verifier/?template=",
336
345
  // Chrome extension URL for Reclaim Protocol
@@ -577,6 +586,92 @@ var http = {
577
586
  }
578
587
  };
579
588
 
589
+ // src/witness.ts
590
+ var import_ethers2 = require("ethers");
591
+ function createSignDataForClaim(data) {
592
+ const identifier = getIdentifierFromClaimInfo(data);
593
+ const lines = [
594
+ identifier,
595
+ data.owner.toLowerCase(),
596
+ data.timestampS.toString(),
597
+ data.epoch.toString()
598
+ ];
599
+ return lines.join("\n");
600
+ }
601
+ function getIdentifierFromClaimInfo(info) {
602
+ let canonicalContext = info.context || "";
603
+ if (canonicalContext.length > 0) {
604
+ try {
605
+ const ctx = JSON.parse(canonicalContext);
606
+ canonicalContext = canonicalStringify(ctx);
607
+ } catch (e) {
608
+ throw new Error("unable to parse non-empty context. Must be JSON");
609
+ }
610
+ }
611
+ const str = `${info.provider}
612
+ ${info.parameters}
613
+ ${canonicalContext}`;
614
+ return import_ethers2.ethers.keccak256(strToUint8Array(str)).toLowerCase();
615
+ }
616
+ function hashProofClaimParams(params) {
617
+ const serializedParams = getProviderParamsAsCanonicalizedString(params);
618
+ return import_ethers2.ethers.keccak256(
619
+ strToUint8Array(serializedParams)
620
+ ).toLowerCase();
621
+ }
622
+ function strToUint8Array(str) {
623
+ return new TextEncoder().encode(str);
624
+ }
625
+ function getProviderParamsAsCanonicalizedString(params) {
626
+ var _a, _b, _c, _d, _e, _f, _g;
627
+ const filteredParams = {
628
+ url: (_a = params == null ? void 0 : params.url) != null ? _a : "",
629
+ // METHOD needs to be explicitly specified and absence or unknown method should cause error, but we're choosing to ignore it in this case
630
+ method: (_b = params == null ? void 0 : params.method) != null ? _b : "GET",
631
+ body: (_c = params == null ? void 0 : params.body) != null ? _c : "",
632
+ responseMatches: (_e = (_d = params == null ? void 0 : params.responseMatches) == null ? void 0 : _d.map((it) => {
633
+ var _a2, _b2;
634
+ return {
635
+ value: (_a2 = it.value) != null ? _a2 : "",
636
+ // This needs to be explicitly specified and absence should cause error, but we're choosing to ignore it in this case
637
+ type: (_b2 = it.type) != null ? _b2 : "contains",
638
+ invert: it.invert || void 0,
639
+ isOptional: it.isOptional || void 0
640
+ };
641
+ })) != null ? _e : [],
642
+ responseRedactions: (_g = (_f = params == null ? void 0 : params.responseRedactions) == null ? void 0 : _f.map((it) => {
643
+ var _a2, _b2, _c2;
644
+ return {
645
+ xPath: (_a2 = it.xPath) != null ? _a2 : "",
646
+ jsonPath: (_b2 = it.jsonPath) != null ? _b2 : "",
647
+ regex: (_c2 = it.regex) != null ? _c2 : "",
648
+ hash: it.hash || void 0
649
+ };
650
+ })) != null ? _g : []
651
+ };
652
+ const serializedParams = canonicalStringify(filteredParams);
653
+ return serializedParams;
654
+ }
655
+
656
+ // src/utils/providerUtils.ts
657
+ function getProviderHashRequirementsFromSpec(spec) {
658
+ var _a;
659
+ return {
660
+ hashes: ((_a = spec == null ? void 0 : spec.requests) == null ? void 0 : _a.map(hashRequestSpec)) || []
661
+ };
662
+ }
663
+ function hashRequestSpec(request) {
664
+ const hash = hashProofClaimParams(__spreadProps(__spreadValues({}, request), {
665
+ // Body is strictly empty unless body sniff is explicitly enabled
666
+ body: request.bodySniff.enabled ? request.bodySniff.template : ""
667
+ }));
668
+ return {
669
+ value: hash,
670
+ required: request.required,
671
+ multiple: request.multiple
672
+ };
673
+ }
674
+
580
675
  // src/utils/sessionUtils.ts
581
676
  var logger4 = logger_default.logger;
582
677
  function initSession(providerId, appId, timestamp, signature, versionNumber) {
@@ -653,42 +748,47 @@ function fetchStatusUrl(sessionId) {
653
748
  }
654
749
  });
655
750
  }
656
-
657
- // src/utils/proofUtils.ts
658
- var import_ethers3 = require("ethers");
659
-
660
- // src/witness.ts
661
- var import_ethers2 = require("ethers");
662
- function createSignDataForClaim(data) {
663
- const identifier = "identifier" in data ? data.identifier : getIdentifierFromClaimInfo(data);
664
- const lines = [
665
- identifier,
666
- data.owner.toLowerCase(),
667
- data.timestampS.toString(),
668
- data.epoch.toString()
669
- ];
670
- return lines.join("\n");
671
- }
672
- function getIdentifierFromClaimInfo(info) {
673
- let canonicalContext = info.context || "";
674
- if (canonicalContext.length > 0) {
751
+ function fetchProviderConfig(providerId, exactProviderVersionString) {
752
+ return __async(this, null, function* () {
753
+ validateFunctionParams(
754
+ [
755
+ { input: providerId, paramName: "providerId", isString: true },
756
+ { input: exactProviderVersionString, paramName: "exactProviderVersionString", isString: true }
757
+ ],
758
+ "fetchProviderConfig"
759
+ );
675
760
  try {
676
- const ctx = JSON.parse(canonicalContext);
677
- canonicalContext = canonicalStringify(ctx);
678
- } catch (e) {
679
- throw new Error("unable to parse non-empty context. Must be JSON");
761
+ const response = yield http.client(constants.DEFAULT_PROVIDER_URL(providerId, exactProviderVersionString), {
762
+ method: "GET",
763
+ headers: { "Content-Type": "application/json" }
764
+ });
765
+ const res = yield response.json();
766
+ if (!response.ok) {
767
+ const errorMessage = `Error fetching provider config for providerId: ${providerId}, exactProviderVersionString: ${exactProviderVersionString}. Status Code: ${response.status}`;
768
+ logger4.info(errorMessage, res);
769
+ throw new ProviderConfigFetchError(errorMessage);
770
+ }
771
+ return res;
772
+ } catch (err) {
773
+ const errorMessage = `Failed to fetch provider config for providerId: ${providerId}, exactProviderVersionString: ${exactProviderVersionString}`;
774
+ logger4.info(errorMessage, err);
775
+ throw new ProviderConfigFetchError(`Error fetching provider config for providerId: ${providerId}, exactProviderVersionString: ${exactProviderVersionString}`);
680
776
  }
681
- }
682
- const str = `${info.provider}
683
- ${info.parameters}
684
- ${canonicalContext}`;
685
- return import_ethers2.ethers.keccak256(strToUint8Array(str)).toLowerCase();
777
+ });
686
778
  }
687
- function strToUint8Array(str) {
688
- return new TextEncoder().encode(str);
779
+ function fetchProviderHashRequirementsBy(providerId, exactProviderVersion) {
780
+ return __async(this, null, function* () {
781
+ var _a, _b;
782
+ const providerResponse = yield fetchProviderConfig(providerId, exactProviderVersion);
783
+ const providerConfig = providerResponse.providers;
784
+ return getProviderHashRequirementsFromSpec({
785
+ requests: [...(_a = providerConfig == null ? void 0 : providerConfig.requestData) != null ? _a : [], ...(_b = providerConfig == null ? void 0 : providerConfig.allowedInjectedRequestData) != null ? _b : []]
786
+ });
787
+ });
689
788
  }
690
789
 
691
790
  // src/utils/proofUtils.ts
791
+ var import_ethers3 = require("ethers");
692
792
  var logger5 = logger_default.logger;
693
793
  function getShortenedUrl(url) {
694
794
  return __async(this, null, function* () {
@@ -752,6 +852,17 @@ function recoverSignersOfSignedClaim({
752
852
  );
753
853
  return signers;
754
854
  }
855
+ function assertVerifiedProof(proof, attestors) {
856
+ return __async(this, null, function* () {
857
+ const signers = recoverSignersOfSignedClaim({
858
+ claim: proof.claimData,
859
+ signatures: proof.signatures.map((signature) => import_ethers3.ethers.getBytes(signature))
860
+ });
861
+ if (!attestors.some((attestor) => signers.includes(attestor.id.toLowerCase()))) {
862
+ throw new ProofNotVerifiedError("Identifier mismatch");
863
+ }
864
+ });
865
+ }
755
866
 
756
867
  // src/utils/modalUtils.ts
757
868
  var logger6 = logger_default.logger;
@@ -1202,35 +1313,108 @@ function clearDeviceCache() {
1202
1313
  cachedMobileType = null;
1203
1314
  }
1204
1315
 
1205
- // src/Reclaim.ts
1316
+ // src/utils/proofValidationUtils.ts
1206
1317
  var logger7 = logger_default.logger;
1318
+ var HASH_REQUIRED_DEFAULT = true;
1319
+ var HASH_MATCH_MULTIPLE_DEFAULT = false;
1320
+ function assertValidProofsByHash(proofs, config) {
1321
+ var _a, _b;
1322
+ if (!config.hashes) {
1323
+ throw new ProofNotValidatedError("No proof hash was provided for validation");
1324
+ }
1325
+ const unvalidatedProofHashByIndex = /* @__PURE__ */ new Map();
1326
+ for (let i = 0; i < proofs.length; i++) {
1327
+ const proof = proofs[i];
1328
+ const claimParams = getHttpProviderClaimParamsFromProof(proof);
1329
+ const computedHashOfProof = hashProofClaimParams(claimParams).toLowerCase().trim();
1330
+ unvalidatedProofHashByIndex.set(i, computedHashOfProof);
1331
+ }
1332
+ for (const hashRequirement of config.hashes) {
1333
+ let found = false;
1334
+ const expectedHash = hashRequirement.value.toLowerCase().trim();
1335
+ const isRequired = (_a = hashRequirement.required) != null ? _a : HASH_REQUIRED_DEFAULT;
1336
+ const canMatchMultiple = (_b = hashRequirement.multiple) != null ? _b : HASH_MATCH_MULTIPLE_DEFAULT;
1337
+ for (const [i, proofHash] of unvalidatedProofHashByIndex.entries()) {
1338
+ if (proofHash === expectedHash) {
1339
+ unvalidatedProofHashByIndex.delete(i);
1340
+ if (!found) {
1341
+ found = true;
1342
+ } else if (!canMatchMultiple) {
1343
+ throw new ProofNotValidatedError(`Proof by hash '${expectedHash}' is not allowed to appear more than once`);
1344
+ }
1345
+ }
1346
+ }
1347
+ if (!found && isRequired) {
1348
+ throw new ProofNotValidatedError(`Proof by required hash '${expectedHash}' was not found`);
1349
+ }
1350
+ }
1351
+ if (unvalidatedProofHashByIndex.size > 0) {
1352
+ const contactSupport = "Please contact Reclaim Protocol Support team or mail us at support@reclaimprotocol.org.";
1353
+ throw new UnknownProofsNotValidatedError(`Extra ${unvalidatedProofHashByIndex.size} proof(s) by hashes ${[...unvalidatedProofHashByIndex.values()].join(", ")} was found but could not be validated and indicates a security risk. ${contactSupport}`);
1354
+ }
1355
+ }
1356
+ var allowedHttpMethods = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
1357
+ function isHttpProviderClaimParams(claimParams) {
1358
+ if (!claimParams || typeof claimParams !== "object" || Array.isArray(claimParams)) {
1359
+ return false;
1360
+ }
1361
+ const params = claimParams;
1362
+ return typeof params.url === "string" && typeof params.method === "string" && allowedHttpMethods.has(params.method) && typeof params.body === "string" && Array.isArray(params.responseMatches) && params.responseMatches.length > 0 && Array.isArray(params.responseRedactions);
1363
+ }
1364
+ function getHttpProviderClaimParamsFromProof(proof) {
1365
+ try {
1366
+ const claimParams = JSON.parse(proof.claimData.parameters);
1367
+ if (isHttpProviderClaimParams(claimParams)) {
1368
+ return claimParams;
1369
+ }
1370
+ } catch (_) {
1371
+ }
1372
+ throw new ProofNotValidatedError("Proof has no HTTP provider params to hash");
1373
+ }
1374
+ function assertValidateProof(proofs, config) {
1375
+ if ("dangerouslyDisableContentValidation" in config && config.dangerouslyDisableContentValidation) {
1376
+ logger7.warn("Validation skipped because it was disabled during proof verification");
1377
+ return;
1378
+ }
1379
+ const effectiveHashRequirement = ("hashes" in config && Array.isArray(config == null ? void 0 : config.hashes) ? config.hashes : []).map((it) => {
1380
+ if (typeof it == "string") {
1381
+ return {
1382
+ value: it
1383
+ };
1384
+ } else {
1385
+ return it;
1386
+ }
1387
+ });
1388
+ return assertValidProofsByHash(proofs, {
1389
+ hashes: effectiveHashRequirement
1390
+ });
1391
+ }
1392
+
1393
+ // src/Reclaim.ts
1394
+ var logger8 = logger_default.logger;
1207
1395
  var sdkVersion = require_package().version;
1208
- function verifyProof(proofOrProofs, allowAiWitness = false) {
1396
+ function verifyProof(proofOrProofs, config) {
1209
1397
  return __async(this, null, function* () {
1210
1398
  try {
1211
- yield assertValidProof(proofOrProofs, allowAiWitness);
1399
+ const proofs = Array.isArray(proofOrProofs) ? proofOrProofs : [proofOrProofs];
1400
+ if (proofs.length === 0) {
1401
+ throw new ProofNotValidatedError("No proofs provided");
1402
+ }
1403
+ if (!config) {
1404
+ throw new ProofNotValidatedError("Verification configuration is required for `verifyProof(proof, config)`");
1405
+ }
1406
+ const attestors = yield getAttestors();
1407
+ for (const proof of proofs) {
1408
+ yield assertVerifiedProof(proof, attestors);
1409
+ }
1410
+ assertValidateProof(proofs, config);
1212
1411
  return true;
1213
1412
  } catch (error) {
1214
- logger7.error("error in validating proof", error);
1413
+ logger8.error("Error in validating proof:", error);
1215
1414
  return false;
1216
1415
  }
1217
1416
  });
1218
1417
  }
1219
- function assertValidProof(proofOrProofs, allowAiWitness = false) {
1220
- return __async(this, null, function* () {
1221
- const attestors = yield getAttestors();
1222
- proofOrProofs = Array.isArray(proofOrProofs) ? proofOrProofs : [proofOrProofs];
1223
- for (const proof of proofOrProofs) {
1224
- const signers = recoverSignersOfSignedClaim({
1225
- claim: proof.claimData,
1226
- signatures: proof.signatures.map((signature) => import_ethers4.ethers.getBytes(signature))
1227
- });
1228
- if (!attestors.some((attestor) => signers.includes(attestor.id.toLowerCase()))) {
1229
- throw new ProofNotVerifiedError("Identifier mismatch");
1230
- }
1231
- }
1232
- });
1233
- }
1234
1418
  function transformForOnchain(proof) {
1235
1419
  const claimInfoBuilder = /* @__PURE__ */ new Map([
1236
1420
  ["context", proof.claimData.context],
@@ -1274,7 +1458,7 @@ var emptyTemplateData = {
1274
1458
  var ReclaimProofRequest = class _ReclaimProofRequest {
1275
1459
  // 30 seconds timeout, can be adjusted
1276
1460
  constructor(applicationId, providerId, options) {
1277
- this.context = { contextAddress: "0x0", contextMessage: "sample context" };
1461
+ this.context = { contextAddress: "0x0", contextMessage: "sample context", reclaimSessionId: "" };
1278
1462
  this.claimCreationType = "createClaim" /* STANDALONE */;
1279
1463
  this.intervals = /* @__PURE__ */ new Map();
1280
1464
  this.jsonProofResponse = false;
@@ -1364,7 +1548,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1364
1548
  }
1365
1549
  this.options = options;
1366
1550
  this.sdkVersion = "js-" + sdkVersion;
1367
- logger7.info(`Initializing client with applicationId: ${this.applicationId}`);
1551
+ logger8.info(`Initializing client with applicationId: ${this.applicationId}`);
1368
1552
  }
1369
1553
  /**
1370
1554
  * Initializes a new Reclaim proof request instance with automatic signature generation and session creation
@@ -1457,7 +1641,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1457
1641
  Intl.getCanonicalLocales(options.preferredLocale);
1458
1642
  return true;
1459
1643
  } catch (error) {
1460
- logger7.info("Failed to canonicalize locale", error);
1644
+ logger8.info("Failed to canonicalize locale", error);
1461
1645
  return false;
1462
1646
  }
1463
1647
  }
@@ -1470,10 +1654,11 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1470
1654
  const data = yield initSession(providerId, applicationId, proofRequestInstance.timeStamp, signature, options == null ? void 0 : options.providerVersion);
1471
1655
  proofRequestInstance.sessionId = data.sessionId;
1472
1656
  proofRequestInstance.resolvedProviderVersion = data.resolvedProviderVersion;
1657
+ proofRequestInstance.context.reclaimSessionId = data.sessionId;
1473
1658
  return proofRequestInstance;
1474
1659
  } catch (error) {
1475
1660
  console.error(error);
1476
- logger7.info("Failed to initialize ReclaimProofRequest", error);
1661
+ logger8.info("Failed to initialize ReclaimProofRequest", error);
1477
1662
  throw new InitError("Failed to initialize ReclaimProofRequest", error);
1478
1663
  }
1479
1664
  });
@@ -1590,7 +1775,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1590
1775
  Intl.getCanonicalLocales(options.preferredLocale);
1591
1776
  return true;
1592
1777
  } catch (error) {
1593
- logger7.info("Failed to canonicalize locale", error);
1778
+ logger8.info("Failed to canonicalize locale", error);
1594
1779
  return false;
1595
1780
  }
1596
1781
  }
@@ -1614,7 +1799,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1614
1799
  proofRequestInstance.cancelRedirectUrlOptions = cancelRedirectUrlOptions;
1615
1800
  return proofRequestInstance;
1616
1801
  } catch (error) {
1617
- logger7.info("Failed to parse JSON string in fromJsonString:", error);
1802
+ logger8.info("Failed to parse JSON string in fromJsonString:", error);
1618
1803
  throw new InvalidParamError("Invalid JSON string provided to fromJsonString");
1619
1804
  }
1620
1805
  });
@@ -1775,9 +1960,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1775
1960
  try {
1776
1961
  validateModalOptions(options, "setModalOptions");
1777
1962
  this.modalOptions = __spreadValues(__spreadValues({}, this.modalOptions), options);
1778
- logger7.info("Modal options set successfully");
1963
+ logger8.info("Modal options set successfully");
1779
1964
  } catch (error) {
1780
- logger7.info("Error setting modal options:", error);
1965
+ logger8.info("Error setting modal options:", error);
1781
1966
  throw new SetParamsError("Error setting modal options", error);
1782
1967
  }
1783
1968
  }
@@ -1804,9 +1989,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1804
1989
  validateFunctionParams([
1805
1990
  { input: context, paramName: "context", isString: false }
1806
1991
  ], "setJsonContext");
1807
- this.context = JSON.parse(canonicalStringify(context));
1992
+ this.context = JSON.parse(canonicalStringify(__spreadProps(__spreadValues({}, context), { reclaimSessionId: this.sessionId })));
1808
1993
  } catch (error) {
1809
- logger7.info("Error setting context", error);
1994
+ logger8.info("Error setting context", error);
1810
1995
  throw new SetContextError("Error setting context", error);
1811
1996
  }
1812
1997
  }
@@ -1835,9 +2020,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1835
2020
  { input: address, paramName: "address", isString: true },
1836
2021
  { input: message, paramName: "message", isString: true }
1837
2022
  ], "setContext");
1838
- this.context = { contextAddress: address, contextMessage: message };
2023
+ this.context = { contextAddress: address, contextMessage: message, reclaimSessionId: this.sessionId };
1839
2024
  } catch (error) {
1840
- logger7.info("Error setting context", error);
2025
+ logger8.info("Error setting context", error);
1841
2026
  throw new SetContextError("Error setting context", error);
1842
2027
  }
1843
2028
  }
@@ -1872,7 +2057,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1872
2057
  validateParameters(params);
1873
2058
  this.parameters = __spreadValues(__spreadValues({}, this.parameters), params);
1874
2059
  } catch (error) {
1875
- logger7.info("Error Setting Params:", error);
2060
+ logger8.info("Error Setting Params:", error);
1876
2061
  throw new SetParamsError("Error setting params", error);
1877
2062
  }
1878
2063
  }
@@ -1896,7 +2081,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1896
2081
  validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getAppCallbackUrl");
1897
2082
  return this.appCallbackUrl || `${constants.DEFAULT_RECLAIM_CALLBACK_URL}${this.sessionId}`;
1898
2083
  } catch (error) {
1899
- logger7.info("Error getting app callback url", error);
2084
+ logger8.info("Error getting app callback url", error);
1900
2085
  throw new GetAppCallbackUrlError("Error getting app callback url", error);
1901
2086
  }
1902
2087
  }
@@ -1920,7 +2105,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1920
2105
  validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getCancelCallbackUrl");
1921
2106
  return this.cancelCallbackUrl || `${constants.DEFAULT_RECLAIM_CANCEL_CALLBACK_URL}${this.sessionId}`;
1922
2107
  } catch (error) {
1923
- logger7.info("Error getting cancel callback url", error);
2108
+ logger8.info("Error getting cancel callback url", error);
1924
2109
  throw new GetAppCallbackUrlError("Error getting cancel callback url", error);
1925
2110
  }
1926
2111
  }
@@ -1943,7 +2128,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1943
2128
  validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getStatusUrl");
1944
2129
  return `${constants.DEFAULT_RECLAIM_STATUS_URL}${this.sessionId}`;
1945
2130
  } catch (error) {
1946
- logger7.info("Error fetching Status Url", error);
2131
+ logger8.info("Error fetching Status Url", error);
1947
2132
  throw new GetStatusUrlError("Error fetching status url", error);
1948
2133
  }
1949
2134
  }
@@ -1973,9 +2158,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1973
2158
  try {
1974
2159
  validateFunctionParams([{ input: signature, paramName: "signature", isString: true }], "setSignature");
1975
2160
  this.signature = signature;
1976
- logger7.info(`Signature set successfully for applicationId: ${this.applicationId}`);
2161
+ logger8.info(`Signature set successfully for applicationId: ${this.applicationId}`);
1977
2162
  } catch (error) {
1978
- logger7.info("Error setting signature", error);
2163
+ logger8.info("Error setting signature", error);
1979
2164
  throw new SetSignatureError("Error setting signature", error);
1980
2165
  }
1981
2166
  }
@@ -1990,7 +2175,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1990
2175
  const messageHash = import_ethers4.ethers.keccak256(new TextEncoder().encode(canonicalData));
1991
2176
  return yield wallet.signMessage(import_ethers4.ethers.getBytes(messageHash));
1992
2177
  } catch (err) {
1993
- logger7.info(`Error generating proof request for applicationId: ${this.applicationId}, providerId: ${this.providerId}, signature: ${this.signature}, timeStamp: ${this.timeStamp}`, err);
2178
+ logger8.info(`Error generating proof request for applicationId: ${this.applicationId}, providerId: ${this.providerId}, signature: ${this.signature}, timeStamp: ${this.timeStamp}`, err);
1994
2179
  throw new SignatureGeneratingError(`Error generating signature for applicationSecret: ${applicationSecret}`);
1995
2180
  }
1996
2181
  });
@@ -2082,7 +2267,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2082
2267
  return __async(this, null, function* () {
2083
2268
  var _a, _b, _c;
2084
2269
  const options = launchOptions || ((_a = this.options) == null ? void 0 : _a.launchOptions) || {};
2085
- logger7.info("Creating Request Url");
2270
+ logger8.info("Creating Request Url");
2086
2271
  if (!this.signature) {
2087
2272
  throw new SignatureNotFoundError("Signature is not set.");
2088
2273
  }
@@ -2101,20 +2286,20 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2101
2286
  if (isDeferredDeeplinksFlowEnabled) {
2102
2287
  instantAppUrl = instantAppUrl.replace("/verifier", "/link");
2103
2288
  }
2104
- logger7.info("Instant App Url created successfully: " + instantAppUrl);
2289
+ logger8.info("Instant App Url created successfully: " + instantAppUrl);
2105
2290
  return instantAppUrl;
2106
2291
  } else {
2107
2292
  const appClipUrl = this.customAppClipUrl ? `${this.customAppClipUrl}&template=${template}` : `https://appclip.apple.com/id?p=org.reclaimprotocol.app.clip&template=${template}`;
2108
- logger7.info("App Clip Url created successfully: " + appClipUrl);
2293
+ logger8.info("App Clip Url created successfully: " + appClipUrl);
2109
2294
  return appClipUrl;
2110
2295
  }
2111
2296
  } else {
2112
2297
  const link = yield createLinkWithTemplateData(templateData, this.customSharePageUrl);
2113
- logger7.info("Request Url created successfully: " + link);
2298
+ logger8.info("Request Url created successfully: " + link);
2114
2299
  return link;
2115
2300
  }
2116
2301
  } catch (error) {
2117
- logger7.info("Error creating Request Url:", error);
2302
+ logger8.info("Error creating Request Url:", error);
2118
2303
  throw error;
2119
2304
  }
2120
2305
  });
@@ -2148,31 +2333,31 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2148
2333
  try {
2149
2334
  const templateData = this.getTemplateData();
2150
2335
  this.templateData = templateData;
2151
- logger7.info("Triggering Reclaim flow");
2336
+ logger8.info("Triggering Reclaim flow");
2152
2337
  const deviceType = getDeviceType();
2153
2338
  updateSession(this.sessionId, "SESSION_STARTED" /* SESSION_STARTED */);
2154
2339
  if (deviceType === "desktop" /* DESKTOP */) {
2155
2340
  const extensionAvailable = yield this.isBrowserExtensionAvailable();
2156
2341
  if (((_b = this.options) == null ? void 0 : _b.useBrowserExtension) && extensionAvailable) {
2157
- logger7.info("Triggering browser extension flow");
2342
+ logger8.info("Triggering browser extension flow");
2158
2343
  this.triggerBrowserExtensionFlow();
2159
2344
  return;
2160
2345
  } else {
2161
- logger7.info("Browser extension not available, showing QR code modal");
2346
+ logger8.info("Browser extension not available, showing QR code modal");
2162
2347
  yield this.showQRCodeModal();
2163
2348
  }
2164
2349
  } else if (deviceType === "mobile" /* MOBILE */) {
2165
2350
  const mobileDeviceType = getMobileDeviceType();
2166
2351
  if (mobileDeviceType === "android" /* ANDROID */) {
2167
- logger7.info("Redirecting to Android instant app");
2352
+ logger8.info("Redirecting to Android instant app");
2168
2353
  yield this.redirectToInstantApp(options);
2169
2354
  } else if (mobileDeviceType === "ios" /* IOS */) {
2170
- logger7.info("Redirecting to iOS app clip");
2355
+ logger8.info("Redirecting to iOS app clip");
2171
2356
  this.redirectToAppClip();
2172
2357
  }
2173
2358
  }
2174
2359
  } catch (error) {
2175
- logger7.info("Error triggering Reclaim flow:", error);
2360
+ logger8.info("Error triggering Reclaim flow:", error);
2176
2361
  throw error;
2177
2362
  }
2178
2363
  });
@@ -2220,7 +2405,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2220
2405
  window.postMessage(message, "*");
2221
2406
  });
2222
2407
  } catch (error) {
2223
- logger7.info("Error checking Reclaim extension installed:", error);
2408
+ logger8.info("Error checking Reclaim extension installed:", error);
2224
2409
  return false;
2225
2410
  }
2226
2411
  });
@@ -2233,7 +2418,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2233
2418
  extensionID: this.extensionID
2234
2419
  };
2235
2420
  window.postMessage(message, "*");
2236
- logger7.info("Browser extension flow triggered");
2421
+ logger8.info("Browser extension flow triggered");
2237
2422
  }
2238
2423
  showQRCodeModal() {
2239
2424
  return __async(this, null, function* () {
@@ -2242,7 +2427,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2242
2427
  this.modal = new QRCodeModal(this.modalOptions);
2243
2428
  yield this.modal.show(requestUrl);
2244
2429
  } catch (error) {
2245
- logger7.info("Error showing QR code modal:", error);
2430
+ logger8.info("Error showing QR code modal:", error);
2246
2431
  throw error;
2247
2432
  }
2248
2433
  });
@@ -2255,7 +2440,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2255
2440
  template = replaceAll(template, "(", "%28");
2256
2441
  template = replaceAll(template, ")", "%29");
2257
2442
  let instantAppUrl = this.buildSharePageUrl(template);
2258
- logger7.info("Redirecting to Android instant app: " + instantAppUrl);
2443
+ logger8.info("Redirecting to Android instant app: " + instantAppUrl);
2259
2444
  const isDeferredDeeplinksFlowEnabled = (_a = options.canUseDeferredDeepLinksFlow) != null ? _a : false;
2260
2445
  if (isDeferredDeeplinksFlowEnabled) {
2261
2446
  instantAppUrl = instantAppUrl.replace("/verifier", "/link");
@@ -2305,7 +2490,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2305
2490
  }
2306
2491
  window.location.href = instantAppUrl;
2307
2492
  } catch (error) {
2308
- logger7.info("Error redirecting to instant app:", error);
2493
+ logger8.info("Error redirecting to instant app:", error);
2309
2494
  throw error;
2310
2495
  }
2311
2496
  });
@@ -2316,17 +2501,30 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2316
2501
  template = replaceAll(template, "(", "%28");
2317
2502
  template = replaceAll(template, ")", "%29");
2318
2503
  const appClipUrl = this.customAppClipUrl ? `${this.customAppClipUrl}&template=${template}` : `https://appclip.apple.com/id?p=org.reclaimprotocol.app.clip&template=${template}`;
2319
- logger7.info("Redirecting to iOS app clip: " + appClipUrl);
2504
+ logger8.info("Redirecting to iOS app clip: " + appClipUrl);
2320
2505
  const verifierUrl = `https://share.reclaimprotocol.org/verifier/?template=${template}`;
2321
2506
  window.location.href = appClipUrl;
2322
2507
  setTimeout(() => {
2323
2508
  window.location.href = verifierUrl;
2324
2509
  }, 5 * 1e3);
2325
2510
  } catch (error) {
2326
- logger7.info("Error redirecting to app clip:", error);
2511
+ logger8.info("Error redirecting to app clip:", error);
2327
2512
  throw error;
2328
2513
  }
2329
2514
  }
2515
+ /**
2516
+ * Fetches the provider config that was used for this session and returns the hash requirements
2517
+ *
2518
+ * See also:
2519
+ * * `fetchProviderHashRequirementsBy()` - An alternative of this function to get the expected hashes for a provider version by providing providerId and exactProviderVersionString. The result can be provided in verifyProof function's `config` parameter for proof validation.
2520
+ * * `getProviderHashRequirementsFromSpec()` - An alternative of this function to get the expected hashes from a provider spec. The result can be provided in verifyProof function's `config` parameter for proof validation.
2521
+ *
2522
+ * @returns A promise that resolves to a ProviderHashRequirementsConfig
2523
+ */
2524
+ getProviderHashRequirements() {
2525
+ var _a;
2526
+ return fetchProviderHashRequirementsBy(this.providerId, (_a = this.resolvedProviderVersion) != null ? _a : "");
2527
+ }
2330
2528
  /**
2331
2529
  * Starts the proof request session and monitors for proof submission
2332
2530
  *
@@ -2370,13 +2568,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2370
2568
  return __async(this, arguments, function* ({ onSuccess, onError }) {
2371
2569
  if (!this.sessionId) {
2372
2570
  const message = "Session can't be started due to undefined value of sessionId";
2373
- logger7.info(message);
2571
+ logger8.info(message);
2374
2572
  throw new SessionNotStartedError(message);
2375
2573
  }
2376
- logger7.info("Starting session");
2574
+ logger8.info("Starting session");
2377
2575
  const sessionUpdatePollingInterval = 3 * 1e3;
2378
2576
  const interval = setInterval(() => __async(this, null, function* () {
2379
- var _a, _b, _c, _d;
2577
+ var _a, _b, _c;
2380
2578
  try {
2381
2579
  const statusUrlResponse = yield fetchStatusUrl(this.sessionId);
2382
2580
  if (!statusUrlResponse.session) return;
@@ -2400,9 +2598,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2400
2598
  if (statusUrlResponse.session.proofs && statusUrlResponse.session.proofs.length > 0) {
2401
2599
  const proofs = statusUrlResponse.session.proofs;
2402
2600
  if (this.claimCreationType === "createClaim" /* STANDALONE */) {
2403
- const verified = yield verifyProof(proofs, (_a = this.options) == null ? void 0 : _a.acceptAiProviders);
2601
+ const verified = yield verifyProof(proofs, yield this.getProviderHashRequirements());
2404
2602
  if (!verified) {
2405
- logger7.info(`Proofs not verified: ${JSON.stringify(proofs)}`);
2603
+ logger8.info(`Proofs not verified: ${JSON.stringify(proofs)}`);
2406
2604
  throw new ProofNotVerifiedError();
2407
2605
  }
2408
2606
  }
@@ -2412,7 +2610,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2412
2610
  onSuccess(proofs);
2413
2611
  }
2414
2612
  this.clearInterval();
2415
- (_b = this.modal) == null ? void 0 : _b.close();
2613
+ (_a = this.modal) == null ? void 0 : _a.close();
2416
2614
  }
2417
2615
  } else {
2418
2616
  if (statusUrlResponse.session.statusV2 === "PROOF_SUBMISSION_FAILED" /* PROOF_SUBMISSION_FAILED */) {
@@ -2423,7 +2621,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2423
2621
  onSuccess([]);
2424
2622
  }
2425
2623
  this.clearInterval();
2426
- (_c = this.modal) == null ? void 0 : _c.close();
2624
+ (_b = this.modal) == null ? void 0 : _b.close();
2427
2625
  }
2428
2626
  }
2429
2627
  } catch (e) {
@@ -2431,7 +2629,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2431
2629
  onError(e);
2432
2630
  }
2433
2631
  this.clearInterval();
2434
- (_d = this.modal) == null ? void 0 : _d.close();
2632
+ (_c = this.modal) == null ? void 0 : _c.close();
2435
2633
  }
2436
2634
  }), sessionUpdatePollingInterval);
2437
2635
  this.intervals.set(this.sessionId, interval);
@@ -2453,7 +2651,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2453
2651
  closeModal() {
2454
2652
  if (this.modal) {
2455
2653
  this.modal.close();
2456
- logger7.info("Modal closed by user");
2654
+ logger8.info("Modal closed by user");
2457
2655
  }
2458
2656
  }
2459
2657
  /**
@@ -2474,7 +2672,6 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2474
2672
  // Annotate the CommonJS export names for ESM import in node:
2475
2673
  0 && (module.exports = {
2476
2674
  ReclaimProofRequest,
2477
- assertValidProof,
2478
2675
  clearDeviceCache,
2479
2676
  getDeviceType,
2480
2677
  getMobileDeviceType,