@reclaimprotocol/js-sdk 4.15.0 → 5.0.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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.15.0",
75
+ version: "5.0.0-dev.1",
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,13 +177,28 @@ var require_package = __commonJS({
174
177
  var index_exports = {};
175
178
  __export(index_exports, {
176
179
  ReclaimProofRequest: () => ReclaimProofRequest,
177
- assertValidProof: () => assertValidProof,
180
+ assertValidProofsByHash: () => assertValidProofsByHash,
181
+ assertValidateProof: () => assertValidateProof,
182
+ assertVerifiedProof: () => assertVerifiedProof,
178
183
  clearDeviceCache: () => clearDeviceCache,
184
+ createLinkWithTemplateData: () => createLinkWithTemplateData,
185
+ fetchProviderConfig: () => fetchProviderConfig,
186
+ fetchProviderHashRequirementsBy: () => fetchProviderHashRequirementsBy,
187
+ fetchStatusUrl: () => fetchStatusUrl,
188
+ getAttestors: () => getAttestors,
179
189
  getDeviceType: () => getDeviceType,
190
+ getHttpProviderClaimParamsFromProof: () => getHttpProviderClaimParamsFromProof,
180
191
  getMobileDeviceType: () => getMobileDeviceType,
192
+ getProviderHashRequirementsFromSpec: () => getProviderHashRequirementsFromSpec,
193
+ getShortenedUrl: () => getShortenedUrl,
194
+ hashRequestSpec: () => hashRequestSpec,
195
+ initSession: () => initSession,
181
196
  isDesktopDevice: () => isDesktopDevice,
197
+ isHttpProviderClaimParams: () => isHttpProviderClaimParams,
182
198
  isMobileDevice: () => isMobileDevice,
199
+ recoverSignersOfSignedClaim: () => recoverSignersOfSignedClaim,
183
200
  transformForOnchain: () => transformForOnchain,
201
+ updateSession: () => updateSession,
184
202
  verifyProof: () => verifyProof
185
203
  });
186
204
  module.exports = __toCommonJS(index_exports);
@@ -214,6 +232,8 @@ Caused by: ${innerError.stack}`;
214
232
  }
215
233
  var TimeoutError = createErrorClass("TimeoutError");
216
234
  var ProofNotVerifiedError = createErrorClass("ProofNotVerifiedError");
235
+ var ProofNotValidatedError = createErrorClass("ProofNotValidatedError");
236
+ var UnknownProofsNotValidatedError = createErrorClass("UnknownProofsNotValidatedError");
217
237
  var SessionNotStartedError = createErrorClass("SessionNotStartedError");
218
238
  var ProviderNotFoundError = createErrorClass("ProviderNotFoundError");
219
239
  var SignatureGeneratingError = createErrorClass("SignatureGeneratingError");
@@ -233,6 +253,7 @@ var SetContextError = createErrorClass("SetContextError");
233
253
  var SetSignatureError = createErrorClass("SetSignatureError");
234
254
  var GetAppCallbackUrlError = createErrorClass("GetAppCallbackUrlError");
235
255
  var StatusUrlError = createErrorClass("StatusUrlError");
256
+ var ProviderConfigFetchError = createErrorClass("ProviderConfigFetchError");
236
257
  var InavlidParametersError = createErrorClass("InavlidParametersError");
237
258
  var ProofSubmissionFailedError = createErrorClass("ProofSubmissionFailedError");
238
259
  var ErrorDuringVerificationError = createErrorClass("ErrorDuringVerificationError");
@@ -328,9 +349,13 @@ var constants = {
328
349
  get DEFAULT_RECLAIM_STATUS_URL() {
329
350
  return `${BACKEND_BASE_URL}/api/sdk/session/`;
330
351
  },
352
+ // Default attestors URL for Reclaim sessions
331
353
  get DEFAULT_ATTESTORS_URL() {
332
354
  return `${BACKEND_BASE_URL}/api/attestors`;
333
355
  },
356
+ DEFAULT_PROVIDER_URL(providerId, exactProviderVersionString) {
357
+ return `${BACKEND_BASE_URL}/api/providers/${providerId}?versionNumber=${exactProviderVersionString}`;
358
+ },
334
359
  // URL for sharing Reclaim templates
335
360
  RECLAIM_SHARE_URL: "https://share.reclaimprotocol.org/verifier/?template=",
336
361
  // Chrome extension URL for Reclaim Protocol
@@ -577,6 +602,92 @@ var http = {
577
602
  }
578
603
  };
579
604
 
605
+ // src/witness.ts
606
+ var import_ethers2 = require("ethers");
607
+ function createSignDataForClaim(data) {
608
+ const identifier = getIdentifierFromClaimInfo(data);
609
+ const lines = [
610
+ identifier,
611
+ data.owner.toLowerCase(),
612
+ data.timestampS.toString(),
613
+ data.epoch.toString()
614
+ ];
615
+ return lines.join("\n");
616
+ }
617
+ function getIdentifierFromClaimInfo(info) {
618
+ let canonicalContext = info.context || "";
619
+ if (canonicalContext.length > 0) {
620
+ try {
621
+ const ctx = JSON.parse(canonicalContext);
622
+ canonicalContext = canonicalStringify(ctx);
623
+ } catch (e) {
624
+ throw new Error("unable to parse non-empty context. Must be JSON");
625
+ }
626
+ }
627
+ const str = `${info.provider}
628
+ ${info.parameters}
629
+ ${canonicalContext}`;
630
+ return import_ethers2.ethers.keccak256(strToUint8Array(str)).toLowerCase();
631
+ }
632
+ function hashProofClaimParams(params) {
633
+ const serializedParams = getProviderParamsAsCanonicalizedString(params);
634
+ return import_ethers2.ethers.keccak256(
635
+ strToUint8Array(serializedParams)
636
+ ).toLowerCase();
637
+ }
638
+ function strToUint8Array(str) {
639
+ return new TextEncoder().encode(str);
640
+ }
641
+ function getProviderParamsAsCanonicalizedString(params) {
642
+ var _a, _b, _c, _d, _e, _f, _g;
643
+ const filteredParams = {
644
+ url: (_a = params == null ? void 0 : params.url) != null ? _a : "",
645
+ // METHOD needs to be explicitly specified and absence or unknown method should cause error, but we're choosing to ignore it in this case
646
+ method: (_b = params == null ? void 0 : params.method) != null ? _b : "GET",
647
+ body: (_c = params == null ? void 0 : params.body) != null ? _c : "",
648
+ responseMatches: (_e = (_d = params == null ? void 0 : params.responseMatches) == null ? void 0 : _d.map((it) => {
649
+ var _a2, _b2;
650
+ return {
651
+ value: (_a2 = it.value) != null ? _a2 : "",
652
+ // This needs to be explicitly specified and absence should cause error, but we're choosing to ignore it in this case
653
+ type: (_b2 = it.type) != null ? _b2 : "contains",
654
+ invert: it.invert || void 0,
655
+ isOptional: it.isOptional || void 0
656
+ };
657
+ })) != null ? _e : [],
658
+ responseRedactions: (_g = (_f = params == null ? void 0 : params.responseRedactions) == null ? void 0 : _f.map((it) => {
659
+ var _a2, _b2, _c2;
660
+ return {
661
+ xPath: (_a2 = it.xPath) != null ? _a2 : "",
662
+ jsonPath: (_b2 = it.jsonPath) != null ? _b2 : "",
663
+ regex: (_c2 = it.regex) != null ? _c2 : "",
664
+ hash: it.hash || void 0
665
+ };
666
+ })) != null ? _g : []
667
+ };
668
+ const serializedParams = canonicalStringify(filteredParams);
669
+ return serializedParams;
670
+ }
671
+
672
+ // src/utils/providerUtils.ts
673
+ function getProviderHashRequirementsFromSpec(spec) {
674
+ var _a;
675
+ return {
676
+ hashes: ((_a = spec == null ? void 0 : spec.requests) == null ? void 0 : _a.map(hashRequestSpec)) || []
677
+ };
678
+ }
679
+ function hashRequestSpec(request) {
680
+ const hash = hashProofClaimParams(__spreadProps(__spreadValues({}, request), {
681
+ // Body is strictly empty unless body sniff is explicitly enabled
682
+ body: request.bodySniff.enabled ? request.bodySniff.template : ""
683
+ }));
684
+ return {
685
+ value: hash,
686
+ required: request.required,
687
+ multiple: request.multiple
688
+ };
689
+ }
690
+
580
691
  // src/utils/sessionUtils.ts
581
692
  var logger4 = logger_default.logger;
582
693
  function initSession(providerId, appId, timestamp, signature, versionNumber) {
@@ -653,42 +764,47 @@ function fetchStatusUrl(sessionId) {
653
764
  }
654
765
  });
655
766
  }
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 = 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) {
767
+ function fetchProviderConfig(providerId, exactProviderVersionString) {
768
+ return __async(this, null, function* () {
769
+ validateFunctionParams(
770
+ [
771
+ { input: providerId, paramName: "providerId", isString: true },
772
+ { input: exactProviderVersionString, paramName: "exactProviderVersionString", isString: true }
773
+ ],
774
+ "fetchProviderConfig"
775
+ );
675
776
  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");
777
+ const response = yield http.client(constants.DEFAULT_PROVIDER_URL(providerId, exactProviderVersionString), {
778
+ method: "GET",
779
+ headers: { "Content-Type": "application/json" }
780
+ });
781
+ const res = yield response.json();
782
+ if (!response.ok) {
783
+ const errorMessage = `Error fetching provider config for providerId: ${providerId}, exactProviderVersionString: ${exactProviderVersionString}. Status Code: ${response.status}`;
784
+ logger4.info(errorMessage, res);
785
+ throw new ProviderConfigFetchError(errorMessage);
786
+ }
787
+ return res;
788
+ } catch (err) {
789
+ const errorMessage = `Failed to fetch provider config for providerId: ${providerId}, exactProviderVersionString: ${exactProviderVersionString}`;
790
+ logger4.info(errorMessage, err);
791
+ throw new ProviderConfigFetchError(`Error fetching provider config for providerId: ${providerId}, exactProviderVersionString: ${exactProviderVersionString}`);
680
792
  }
681
- }
682
- const str = `${info.provider}
683
- ${info.parameters}
684
- ${canonicalContext}`;
685
- return import_ethers2.ethers.keccak256(strToUint8Array(str)).toLowerCase();
793
+ });
686
794
  }
687
- function strToUint8Array(str) {
688
- return new TextEncoder().encode(str);
795
+ function fetchProviderHashRequirementsBy(providerId, exactProviderVersion) {
796
+ return __async(this, null, function* () {
797
+ var _a, _b;
798
+ const providerResponse = yield fetchProviderConfig(providerId, exactProviderVersion);
799
+ const providerConfig = providerResponse.providers;
800
+ return getProviderHashRequirementsFromSpec({
801
+ requests: [...(_a = providerConfig == null ? void 0 : providerConfig.requestData) != null ? _a : [], ...(_b = providerConfig == null ? void 0 : providerConfig.allowedInjectedRequestData) != null ? _b : []]
802
+ });
803
+ });
689
804
  }
690
805
 
691
806
  // src/utils/proofUtils.ts
807
+ var import_ethers3 = require("ethers");
692
808
  var logger5 = logger_default.logger;
693
809
  function getShortenedUrl(url) {
694
810
  return __async(this, null, function* () {
@@ -752,6 +868,17 @@ function recoverSignersOfSignedClaim({
752
868
  );
753
869
  return signers;
754
870
  }
871
+ function assertVerifiedProof(proof, attestors) {
872
+ return __async(this, null, function* () {
873
+ const signers = recoverSignersOfSignedClaim({
874
+ claim: proof.claimData,
875
+ signatures: proof.signatures.map((signature) => import_ethers3.ethers.getBytes(signature))
876
+ });
877
+ if (!attestors.some((attestor) => signers.includes(attestor.id.toLowerCase()))) {
878
+ throw new ProofNotVerifiedError("Identifier mismatch");
879
+ }
880
+ });
881
+ }
755
882
 
756
883
  // src/utils/modalUtils.ts
757
884
  var logger6 = logger_default.logger;
@@ -1202,35 +1329,108 @@ function clearDeviceCache() {
1202
1329
  cachedMobileType = null;
1203
1330
  }
1204
1331
 
1205
- // src/Reclaim.ts
1332
+ // src/utils/proofValidationUtils.ts
1206
1333
  var logger7 = logger_default.logger;
1334
+ var HASH_REQUIRED_DEFAULT = true;
1335
+ var HASH_MATCH_MULTIPLE_DEFAULT = false;
1336
+ function assertValidProofsByHash(proofs, config) {
1337
+ var _a, _b;
1338
+ if (!config.hashes) {
1339
+ throw new ProofNotValidatedError("No proof hash was provided for validation");
1340
+ }
1341
+ const unvalidatedProofHashByIndex = /* @__PURE__ */ new Map();
1342
+ for (let i = 0; i < proofs.length; i++) {
1343
+ const proof = proofs[i];
1344
+ const claimParams = getHttpProviderClaimParamsFromProof(proof);
1345
+ const computedHashOfProof = hashProofClaimParams(claimParams).toLowerCase().trim();
1346
+ unvalidatedProofHashByIndex.set(i, computedHashOfProof);
1347
+ }
1348
+ for (const hashRequirement of config.hashes) {
1349
+ let found = false;
1350
+ const expectedHash = hashRequirement.value.toLowerCase().trim();
1351
+ const isRequired = (_a = hashRequirement.required) != null ? _a : HASH_REQUIRED_DEFAULT;
1352
+ const canMatchMultiple = (_b = hashRequirement.multiple) != null ? _b : HASH_MATCH_MULTIPLE_DEFAULT;
1353
+ for (const [i, proofHash] of unvalidatedProofHashByIndex.entries()) {
1354
+ if (proofHash === expectedHash) {
1355
+ unvalidatedProofHashByIndex.delete(i);
1356
+ if (!found) {
1357
+ found = true;
1358
+ } else if (!canMatchMultiple) {
1359
+ throw new ProofNotValidatedError(`Proof by hash '${expectedHash}' is not allowed to appear more than once`);
1360
+ }
1361
+ }
1362
+ }
1363
+ if (!found && isRequired) {
1364
+ throw new ProofNotValidatedError(`Proof by required hash '${expectedHash}' was not found`);
1365
+ }
1366
+ }
1367
+ if (unvalidatedProofHashByIndex.size > 0) {
1368
+ const contactSupport = "Please contact Reclaim Protocol Support team or mail us at support@reclaimprotocol.org.";
1369
+ 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}`);
1370
+ }
1371
+ }
1372
+ var allowedHttpMethods = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
1373
+ function isHttpProviderClaimParams(claimParams) {
1374
+ if (!claimParams || typeof claimParams !== "object" || Array.isArray(claimParams)) {
1375
+ return false;
1376
+ }
1377
+ const params = claimParams;
1378
+ 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);
1379
+ }
1380
+ function getHttpProviderClaimParamsFromProof(proof) {
1381
+ try {
1382
+ const claimParams = JSON.parse(proof.claimData.parameters);
1383
+ if (isHttpProviderClaimParams(claimParams)) {
1384
+ return claimParams;
1385
+ }
1386
+ } catch (_) {
1387
+ }
1388
+ throw new ProofNotValidatedError("Proof has no HTTP provider params to hash");
1389
+ }
1390
+ function assertValidateProof(proofs, config) {
1391
+ if ("dangerouslyDisableContentValidation" in config && config.dangerouslyDisableContentValidation) {
1392
+ logger7.warn("Validation skipped because it was disabled during proof verification");
1393
+ return;
1394
+ }
1395
+ const effectiveHashRequirement = ("hashes" in config && Array.isArray(config == null ? void 0 : config.hashes) ? config.hashes : []).map((it) => {
1396
+ if (typeof it == "string") {
1397
+ return {
1398
+ value: it
1399
+ };
1400
+ } else {
1401
+ return it;
1402
+ }
1403
+ });
1404
+ return assertValidProofsByHash(proofs, {
1405
+ hashes: effectiveHashRequirement
1406
+ });
1407
+ }
1408
+
1409
+ // src/Reclaim.ts
1410
+ var logger8 = logger_default.logger;
1207
1411
  var sdkVersion = require_package().version;
1208
- function verifyProof(proofOrProofs, allowAiWitness = false) {
1412
+ function verifyProof(proofOrProofs, config) {
1209
1413
  return __async(this, null, function* () {
1210
1414
  try {
1211
- yield assertValidProof(proofOrProofs, allowAiWitness);
1415
+ const proofs = Array.isArray(proofOrProofs) ? proofOrProofs : [proofOrProofs];
1416
+ if (proofs.length === 0) {
1417
+ throw new ProofNotValidatedError("No proofs provided");
1418
+ }
1419
+ if (!config) {
1420
+ throw new ProofNotValidatedError("Verification configuration is required for `verifyProof(proof, config)`");
1421
+ }
1422
+ const attestors = yield getAttestors();
1423
+ for (const proof of proofs) {
1424
+ yield assertVerifiedProof(proof, attestors);
1425
+ }
1426
+ assertValidateProof(proofs, config);
1212
1427
  return true;
1213
1428
  } catch (error) {
1214
- logger7.error("error in validating proof", error);
1429
+ logger8.error("Error in validating proof:", error);
1215
1430
  return false;
1216
1431
  }
1217
1432
  });
1218
1433
  }
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
1434
  function transformForOnchain(proof) {
1235
1435
  const claimInfoBuilder = /* @__PURE__ */ new Map([
1236
1436
  ["context", proof.claimData.context],
@@ -1274,7 +1474,7 @@ var emptyTemplateData = {
1274
1474
  var ReclaimProofRequest = class _ReclaimProofRequest {
1275
1475
  // 30 seconds timeout, can be adjusted
1276
1476
  constructor(applicationId, providerId, options) {
1277
- this.context = { contextAddress: "0x0", contextMessage: "sample context" };
1477
+ this.context = { contextAddress: "0x0", contextMessage: "sample context", reclaimSessionId: "" };
1278
1478
  this.claimCreationType = "createClaim" /* STANDALONE */;
1279
1479
  this.intervals = /* @__PURE__ */ new Map();
1280
1480
  this.jsonProofResponse = false;
@@ -1364,7 +1564,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1364
1564
  }
1365
1565
  this.options = options;
1366
1566
  this.sdkVersion = "js-" + sdkVersion;
1367
- logger7.info(`Initializing client with applicationId: ${this.applicationId}`);
1567
+ logger8.info(`Initializing client with applicationId: ${this.applicationId}`);
1368
1568
  }
1369
1569
  /**
1370
1570
  * Initializes a new Reclaim proof request instance with automatic signature generation and session creation
@@ -1457,7 +1657,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1457
1657
  Intl.getCanonicalLocales(options.preferredLocale);
1458
1658
  return true;
1459
1659
  } catch (error) {
1460
- logger7.info("Failed to canonicalize locale", error);
1660
+ logger8.info("Failed to canonicalize locale", error);
1461
1661
  return false;
1462
1662
  }
1463
1663
  }
@@ -1470,10 +1670,11 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1470
1670
  const data = yield initSession(providerId, applicationId, proofRequestInstance.timeStamp, signature, options == null ? void 0 : options.providerVersion);
1471
1671
  proofRequestInstance.sessionId = data.sessionId;
1472
1672
  proofRequestInstance.resolvedProviderVersion = data.resolvedProviderVersion;
1673
+ proofRequestInstance.context.reclaimSessionId = data.sessionId;
1473
1674
  return proofRequestInstance;
1474
1675
  } catch (error) {
1475
1676
  console.error(error);
1476
- logger7.info("Failed to initialize ReclaimProofRequest", error);
1677
+ logger8.info("Failed to initialize ReclaimProofRequest", error);
1477
1678
  throw new InitError("Failed to initialize ReclaimProofRequest", error);
1478
1679
  }
1479
1680
  });
@@ -1590,7 +1791,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1590
1791
  Intl.getCanonicalLocales(options.preferredLocale);
1591
1792
  return true;
1592
1793
  } catch (error) {
1593
- logger7.info("Failed to canonicalize locale", error);
1794
+ logger8.info("Failed to canonicalize locale", error);
1594
1795
  return false;
1595
1796
  }
1596
1797
  }
@@ -1614,7 +1815,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1614
1815
  proofRequestInstance.cancelRedirectUrlOptions = cancelRedirectUrlOptions;
1615
1816
  return proofRequestInstance;
1616
1817
  } catch (error) {
1617
- logger7.info("Failed to parse JSON string in fromJsonString:", error);
1818
+ logger8.info("Failed to parse JSON string in fromJsonString:", error);
1618
1819
  throw new InvalidParamError("Invalid JSON string provided to fromJsonString");
1619
1820
  }
1620
1821
  });
@@ -1775,9 +1976,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1775
1976
  try {
1776
1977
  validateModalOptions(options, "setModalOptions");
1777
1978
  this.modalOptions = __spreadValues(__spreadValues({}, this.modalOptions), options);
1778
- logger7.info("Modal options set successfully");
1979
+ logger8.info("Modal options set successfully");
1779
1980
  } catch (error) {
1780
- logger7.info("Error setting modal options:", error);
1981
+ logger8.info("Error setting modal options:", error);
1781
1982
  throw new SetParamsError("Error setting modal options", error);
1782
1983
  }
1783
1984
  }
@@ -1804,9 +2005,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1804
2005
  validateFunctionParams([
1805
2006
  { input: context, paramName: "context", isString: false }
1806
2007
  ], "setJsonContext");
1807
- this.context = JSON.parse(canonicalStringify(context));
2008
+ this.context = JSON.parse(canonicalStringify(__spreadProps(__spreadValues({}, context), { reclaimSessionId: this.sessionId })));
1808
2009
  } catch (error) {
1809
- logger7.info("Error setting context", error);
2010
+ logger8.info("Error setting context", error);
1810
2011
  throw new SetContextError("Error setting context", error);
1811
2012
  }
1812
2013
  }
@@ -1835,9 +2036,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1835
2036
  { input: address, paramName: "address", isString: true },
1836
2037
  { input: message, paramName: "message", isString: true }
1837
2038
  ], "setContext");
1838
- this.context = { contextAddress: address, contextMessage: message };
2039
+ this.context = { contextAddress: address, contextMessage: message, reclaimSessionId: this.sessionId };
1839
2040
  } catch (error) {
1840
- logger7.info("Error setting context", error);
2041
+ logger8.info("Error setting context", error);
1841
2042
  throw new SetContextError("Error setting context", error);
1842
2043
  }
1843
2044
  }
@@ -1872,7 +2073,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1872
2073
  validateParameters(params);
1873
2074
  this.parameters = __spreadValues(__spreadValues({}, this.parameters), params);
1874
2075
  } catch (error) {
1875
- logger7.info("Error Setting Params:", error);
2076
+ logger8.info("Error Setting Params:", error);
1876
2077
  throw new SetParamsError("Error setting params", error);
1877
2078
  }
1878
2079
  }
@@ -1896,7 +2097,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1896
2097
  validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getAppCallbackUrl");
1897
2098
  return this.appCallbackUrl || `${constants.DEFAULT_RECLAIM_CALLBACK_URL}${this.sessionId}`;
1898
2099
  } catch (error) {
1899
- logger7.info("Error getting app callback url", error);
2100
+ logger8.info("Error getting app callback url", error);
1900
2101
  throw new GetAppCallbackUrlError("Error getting app callback url", error);
1901
2102
  }
1902
2103
  }
@@ -1920,7 +2121,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1920
2121
  validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getCancelCallbackUrl");
1921
2122
  return this.cancelCallbackUrl || `${constants.DEFAULT_RECLAIM_CANCEL_CALLBACK_URL}${this.sessionId}`;
1922
2123
  } catch (error) {
1923
- logger7.info("Error getting cancel callback url", error);
2124
+ logger8.info("Error getting cancel callback url", error);
1924
2125
  throw new GetAppCallbackUrlError("Error getting cancel callback url", error);
1925
2126
  }
1926
2127
  }
@@ -1943,7 +2144,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1943
2144
  validateFunctionParams([{ input: this.sessionId, paramName: "sessionId", isString: true }], "getStatusUrl");
1944
2145
  return `${constants.DEFAULT_RECLAIM_STATUS_URL}${this.sessionId}`;
1945
2146
  } catch (error) {
1946
- logger7.info("Error fetching Status Url", error);
2147
+ logger8.info("Error fetching Status Url", error);
1947
2148
  throw new GetStatusUrlError("Error fetching status url", error);
1948
2149
  }
1949
2150
  }
@@ -1973,9 +2174,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1973
2174
  try {
1974
2175
  validateFunctionParams([{ input: signature, paramName: "signature", isString: true }], "setSignature");
1975
2176
  this.signature = signature;
1976
- logger7.info(`Signature set successfully for applicationId: ${this.applicationId}`);
2177
+ logger8.info(`Signature set successfully for applicationId: ${this.applicationId}`);
1977
2178
  } catch (error) {
1978
- logger7.info("Error setting signature", error);
2179
+ logger8.info("Error setting signature", error);
1979
2180
  throw new SetSignatureError("Error setting signature", error);
1980
2181
  }
1981
2182
  }
@@ -1990,7 +2191,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
1990
2191
  const messageHash = import_ethers4.ethers.keccak256(new TextEncoder().encode(canonicalData));
1991
2192
  return yield wallet.signMessage(import_ethers4.ethers.getBytes(messageHash));
1992
2193
  } catch (err) {
1993
- logger7.info(`Error generating proof request for applicationId: ${this.applicationId}, providerId: ${this.providerId}, signature: ${this.signature}, timeStamp: ${this.timeStamp}`, err);
2194
+ logger8.info(`Error generating proof request for applicationId: ${this.applicationId}, providerId: ${this.providerId}, signature: ${this.signature}, timeStamp: ${this.timeStamp}`, err);
1994
2195
  throw new SignatureGeneratingError(`Error generating signature for applicationSecret: ${applicationSecret}`);
1995
2196
  }
1996
2197
  });
@@ -2082,7 +2283,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2082
2283
  return __async(this, null, function* () {
2083
2284
  var _a, _b, _c;
2084
2285
  const options = launchOptions || ((_a = this.options) == null ? void 0 : _a.launchOptions) || {};
2085
- logger7.info("Creating Request Url");
2286
+ logger8.info("Creating Request Url");
2086
2287
  if (!this.signature) {
2087
2288
  throw new SignatureNotFoundError("Signature is not set.");
2088
2289
  }
@@ -2101,20 +2302,20 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2101
2302
  if (isDeferredDeeplinksFlowEnabled) {
2102
2303
  instantAppUrl = instantAppUrl.replace("/verifier", "/link");
2103
2304
  }
2104
- logger7.info("Instant App Url created successfully: " + instantAppUrl);
2305
+ logger8.info("Instant App Url created successfully: " + instantAppUrl);
2105
2306
  return instantAppUrl;
2106
2307
  } else {
2107
2308
  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);
2309
+ logger8.info("App Clip Url created successfully: " + appClipUrl);
2109
2310
  return appClipUrl;
2110
2311
  }
2111
2312
  } else {
2112
2313
  const link = yield createLinkWithTemplateData(templateData, this.customSharePageUrl);
2113
- logger7.info("Request Url created successfully: " + link);
2314
+ logger8.info("Request Url created successfully: " + link);
2114
2315
  return link;
2115
2316
  }
2116
2317
  } catch (error) {
2117
- logger7.info("Error creating Request Url:", error);
2318
+ logger8.info("Error creating Request Url:", error);
2118
2319
  throw error;
2119
2320
  }
2120
2321
  });
@@ -2148,31 +2349,31 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2148
2349
  try {
2149
2350
  const templateData = this.getTemplateData();
2150
2351
  this.templateData = templateData;
2151
- logger7.info("Triggering Reclaim flow");
2352
+ logger8.info("Triggering Reclaim flow");
2152
2353
  const deviceType = getDeviceType();
2153
2354
  updateSession(this.sessionId, "SESSION_STARTED" /* SESSION_STARTED */);
2154
2355
  if (deviceType === "desktop" /* DESKTOP */) {
2155
2356
  const extensionAvailable = yield this.isBrowserExtensionAvailable();
2156
2357
  if (((_b = this.options) == null ? void 0 : _b.useBrowserExtension) && extensionAvailable) {
2157
- logger7.info("Triggering browser extension flow");
2358
+ logger8.info("Triggering browser extension flow");
2158
2359
  this.triggerBrowserExtensionFlow();
2159
2360
  return;
2160
2361
  } else {
2161
- logger7.info("Browser extension not available, showing QR code modal");
2362
+ logger8.info("Browser extension not available, showing QR code modal");
2162
2363
  yield this.showQRCodeModal();
2163
2364
  }
2164
2365
  } else if (deviceType === "mobile" /* MOBILE */) {
2165
2366
  const mobileDeviceType = getMobileDeviceType();
2166
2367
  if (mobileDeviceType === "android" /* ANDROID */) {
2167
- logger7.info("Redirecting to Android instant app");
2368
+ logger8.info("Redirecting to Android instant app");
2168
2369
  yield this.redirectToInstantApp(options);
2169
2370
  } else if (mobileDeviceType === "ios" /* IOS */) {
2170
- logger7.info("Redirecting to iOS app clip");
2371
+ logger8.info("Redirecting to iOS app clip");
2171
2372
  this.redirectToAppClip();
2172
2373
  }
2173
2374
  }
2174
2375
  } catch (error) {
2175
- logger7.info("Error triggering Reclaim flow:", error);
2376
+ logger8.info("Error triggering Reclaim flow:", error);
2176
2377
  throw error;
2177
2378
  }
2178
2379
  });
@@ -2220,7 +2421,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2220
2421
  window.postMessage(message, "*");
2221
2422
  });
2222
2423
  } catch (error) {
2223
- logger7.info("Error checking Reclaim extension installed:", error);
2424
+ logger8.info("Error checking Reclaim extension installed:", error);
2224
2425
  return false;
2225
2426
  }
2226
2427
  });
@@ -2233,7 +2434,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2233
2434
  extensionID: this.extensionID
2234
2435
  };
2235
2436
  window.postMessage(message, "*");
2236
- logger7.info("Browser extension flow triggered");
2437
+ logger8.info("Browser extension flow triggered");
2237
2438
  }
2238
2439
  showQRCodeModal() {
2239
2440
  return __async(this, null, function* () {
@@ -2242,7 +2443,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2242
2443
  this.modal = new QRCodeModal(this.modalOptions);
2243
2444
  yield this.modal.show(requestUrl);
2244
2445
  } catch (error) {
2245
- logger7.info("Error showing QR code modal:", error);
2446
+ logger8.info("Error showing QR code modal:", error);
2246
2447
  throw error;
2247
2448
  }
2248
2449
  });
@@ -2255,7 +2456,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2255
2456
  template = replaceAll(template, "(", "%28");
2256
2457
  template = replaceAll(template, ")", "%29");
2257
2458
  let instantAppUrl = this.buildSharePageUrl(template);
2258
- logger7.info("Redirecting to Android instant app: " + instantAppUrl);
2459
+ logger8.info("Redirecting to Android instant app: " + instantAppUrl);
2259
2460
  const isDeferredDeeplinksFlowEnabled = (_a = options.canUseDeferredDeepLinksFlow) != null ? _a : false;
2260
2461
  if (isDeferredDeeplinksFlowEnabled) {
2261
2462
  instantAppUrl = instantAppUrl.replace("/verifier", "/link");
@@ -2305,7 +2506,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2305
2506
  }
2306
2507
  window.location.href = instantAppUrl;
2307
2508
  } catch (error) {
2308
- logger7.info("Error redirecting to instant app:", error);
2509
+ logger8.info("Error redirecting to instant app:", error);
2309
2510
  throw error;
2310
2511
  }
2311
2512
  });
@@ -2316,17 +2517,30 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2316
2517
  template = replaceAll(template, "(", "%28");
2317
2518
  template = replaceAll(template, ")", "%29");
2318
2519
  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);
2520
+ logger8.info("Redirecting to iOS app clip: " + appClipUrl);
2320
2521
  const verifierUrl = `https://share.reclaimprotocol.org/verifier/?template=${template}`;
2321
2522
  window.location.href = appClipUrl;
2322
2523
  setTimeout(() => {
2323
2524
  window.location.href = verifierUrl;
2324
2525
  }, 5 * 1e3);
2325
2526
  } catch (error) {
2326
- logger7.info("Error redirecting to app clip:", error);
2527
+ logger8.info("Error redirecting to app clip:", error);
2327
2528
  throw error;
2328
2529
  }
2329
2530
  }
2531
+ /**
2532
+ * Fetches the provider config that was used for this session and returns the hash requirements
2533
+ *
2534
+ * See also:
2535
+ * * `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.
2536
+ * * `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.
2537
+ *
2538
+ * @returns A promise that resolves to a ProviderHashRequirementsConfig
2539
+ */
2540
+ getProviderHashRequirements() {
2541
+ var _a;
2542
+ return fetchProviderHashRequirementsBy(this.providerId, (_a = this.resolvedProviderVersion) != null ? _a : "");
2543
+ }
2330
2544
  /**
2331
2545
  * Starts the proof request session and monitors for proof submission
2332
2546
  *
@@ -2370,13 +2584,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2370
2584
  return __async(this, arguments, function* ({ onSuccess, onError }) {
2371
2585
  if (!this.sessionId) {
2372
2586
  const message = "Session can't be started due to undefined value of sessionId";
2373
- logger7.info(message);
2587
+ logger8.info(message);
2374
2588
  throw new SessionNotStartedError(message);
2375
2589
  }
2376
- logger7.info("Starting session");
2590
+ logger8.info("Starting session");
2377
2591
  const sessionUpdatePollingInterval = 3 * 1e3;
2378
2592
  const interval = setInterval(() => __async(this, null, function* () {
2379
- var _a, _b, _c, _d;
2593
+ var _a, _b, _c;
2380
2594
  try {
2381
2595
  const statusUrlResponse = yield fetchStatusUrl(this.sessionId);
2382
2596
  if (!statusUrlResponse.session) return;
@@ -2400,9 +2614,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2400
2614
  if (statusUrlResponse.session.proofs && statusUrlResponse.session.proofs.length > 0) {
2401
2615
  const proofs = statusUrlResponse.session.proofs;
2402
2616
  if (this.claimCreationType === "createClaim" /* STANDALONE */) {
2403
- const verified = yield verifyProof(proofs, (_a = this.options) == null ? void 0 : _a.acceptAiProviders);
2617
+ const verified = yield verifyProof(proofs, yield this.getProviderHashRequirements());
2404
2618
  if (!verified) {
2405
- logger7.info(`Proofs not verified: ${JSON.stringify(proofs)}`);
2619
+ logger8.info(`Proofs not verified: ${JSON.stringify(proofs)}`);
2406
2620
  throw new ProofNotVerifiedError();
2407
2621
  }
2408
2622
  }
@@ -2412,7 +2626,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2412
2626
  onSuccess(proofs);
2413
2627
  }
2414
2628
  this.clearInterval();
2415
- (_b = this.modal) == null ? void 0 : _b.close();
2629
+ (_a = this.modal) == null ? void 0 : _a.close();
2416
2630
  }
2417
2631
  } else {
2418
2632
  if (statusUrlResponse.session.statusV2 === "PROOF_SUBMISSION_FAILED" /* PROOF_SUBMISSION_FAILED */) {
@@ -2423,7 +2637,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2423
2637
  onSuccess([]);
2424
2638
  }
2425
2639
  this.clearInterval();
2426
- (_c = this.modal) == null ? void 0 : _c.close();
2640
+ (_b = this.modal) == null ? void 0 : _b.close();
2427
2641
  }
2428
2642
  }
2429
2643
  } catch (e) {
@@ -2431,7 +2645,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2431
2645
  onError(e);
2432
2646
  }
2433
2647
  this.clearInterval();
2434
- (_d = this.modal) == null ? void 0 : _d.close();
2648
+ (_c = this.modal) == null ? void 0 : _c.close();
2435
2649
  }
2436
2650
  }), sessionUpdatePollingInterval);
2437
2651
  this.intervals.set(this.sessionId, interval);
@@ -2453,7 +2667,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2453
2667
  closeModal() {
2454
2668
  if (this.modal) {
2455
2669
  this.modal.close();
2456
- logger7.info("Modal closed by user");
2670
+ logger8.info("Modal closed by user");
2457
2671
  }
2458
2672
  }
2459
2673
  /**
@@ -2474,13 +2688,28 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2474
2688
  // Annotate the CommonJS export names for ESM import in node:
2475
2689
  0 && (module.exports = {
2476
2690
  ReclaimProofRequest,
2477
- assertValidProof,
2691
+ assertValidProofsByHash,
2692
+ assertValidateProof,
2693
+ assertVerifiedProof,
2478
2694
  clearDeviceCache,
2695
+ createLinkWithTemplateData,
2696
+ fetchProviderConfig,
2697
+ fetchProviderHashRequirementsBy,
2698
+ fetchStatusUrl,
2699
+ getAttestors,
2479
2700
  getDeviceType,
2701
+ getHttpProviderClaimParamsFromProof,
2480
2702
  getMobileDeviceType,
2703
+ getProviderHashRequirementsFromSpec,
2704
+ getShortenedUrl,
2705
+ hashRequestSpec,
2706
+ initSession,
2481
2707
  isDesktopDevice,
2708
+ isHttpProviderClaimParams,
2482
2709
  isMobileDevice,
2710
+ recoverSignersOfSignedClaim,
2483
2711
  transformForOnchain,
2712
+ updateSession,
2484
2713
  verifyProof
2485
2714
  });
2486
2715
  //# sourceMappingURL=index.js.map