@reclaimprotocol/js-sdk 5.0.0-dev.3 → 5.0.0-dev.5

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.d.ts CHANGED
@@ -133,6 +133,16 @@ declare function fetchProviderHashRequirementsBy(providerId: string, exactProvid
133
133
  declare function generateSpecsFromRequestSpecTemplate(requestSpecTemplates: RequestSpec[], templateParameters: Record<string, string[]>): RequestSpec[];
134
134
  declare function takeTemplateParametersFromProofs(proofs?: Proof[]): Record<string, string[]>;
135
135
  declare function takePairsWhereValueIsArray(o: Record<string, string> | undefined): Record<string, string[]>;
136
+ /**
137
+ * Builds and returns raw hash requirement spec that can be used with `getProviderHashRequirementsFromSpec` to computes the expected proof hashes for a provider configuration
138
+ * by combining its explicitly required requests and allowed injected requests.
139
+ * It resolves template parameters from provided proofs to generate the final request specifications.
140
+ *
141
+ * @param providerConfig - The provider configuration containing request data and allowed injected requests.
142
+ * @param proofs - Optional array of proofs used to extract template parameters for resolving placeholders in injected requests.
143
+ * @returns A structured configuration containing that can be used with `getProviderHashRequirementsFromSpec` to compute the hashes.
144
+ */
145
+ declare function getProviderHashRequirementSpecFromProviderConfig(providerConfig: ReclaimProviderConfigWithRequestSpec, proofs?: Proof[]): ProviderHashRequirementSpec;
136
146
  /**
137
147
  * Transforms a raw provider hash requirement specification into a structured configuration for proof validation.
138
148
  * It computes the proof hashes for both required and allowed extra requests to correctly match uploaded proofs.
@@ -188,6 +198,10 @@ type HashRequirement = {
188
198
  */
189
199
  multiple?: boolean;
190
200
  };
201
+ interface ReclaimProviderConfigWithRequestSpec {
202
+ requestData: InterceptorRequestSpec[];
203
+ allowedInjectedRequestData: InjectedRequestSpec[];
204
+ }
191
205
  /**
192
206
  * Specific marker interface for intercepted request specifications.
193
207
  */
@@ -257,7 +271,7 @@ interface ResponseMatchSpec {
257
271
  */
258
272
  interface ResponseRedactionSpec {
259
273
  /** Optional hashing method applied to the redacted content (e.g., 'oprf') */
260
- hash?: "oprf" | undefined;
274
+ hash?: "oprf" | "oprf-mpc" | undefined;
261
275
  /** JSON path for locating the value to redact */
262
276
  jsonPath: string;
263
277
  /** RegEx applied to correctly parse and extract/redact value */
@@ -323,7 +337,7 @@ type ProofRequestOptions = {
323
337
  */
324
338
  portalUrl?: string;
325
339
  customAppClipUrl?: string;
326
- launchOptions?: ReclaimFlowLaunchOptions;
340
+ launchOptions?: ReclaimFlowInitOptions;
327
341
  /**
328
342
  * Whether the verification client should automatically submit necessary proofs once they are generated.
329
343
  * If set to false, the user must manually click a button to submit.
@@ -362,7 +376,7 @@ type ProofRequestOptions = {
362
376
  */
363
377
  acceptTeeAttestation?: boolean;
364
378
  };
365
- type ReclaimFlowLaunchOptions = {
379
+ type ReclaimFlowInitOptions = {
366
380
  /**
367
381
  * Enables deferred deep links for the Reclaim verification flow.
368
382
  *
@@ -388,6 +402,8 @@ type ReclaimFlowLaunchOptions = {
388
402
  * @default 'portal'
389
403
  */
390
404
  verificationMode?: 'app' | 'portal';
405
+ };
406
+ type ReclaimFlowLaunchOptions = ReclaimFlowInitOptions & {
391
407
  /**
392
408
  * Target DOM element to embed the verification flow in an iframe.
393
409
  * When provided, the portal opens inside the element instead of a new tab.
@@ -583,15 +599,13 @@ type ProviderConfigResponse = {
583
599
  providerId?: string;
584
600
  providerVersionString?: string;
585
601
  };
586
- interface ReclaimProviderConfig {
602
+ interface ReclaimProviderConfig extends ReclaimProviderConfigWithRequestSpec {
587
603
  loginUrl: string;
588
604
  customInjection: string;
589
605
  geoLocation: string;
590
606
  injectionType: string;
591
607
  disableRequestReplay: boolean;
592
608
  verificationType: string;
593
- requestData: InterceptorRequestSpec[];
594
- allowedInjectedRequestData: InjectedRequestSpec[];
595
609
  }
596
610
  type ProviderHashRequirementsResponse = {
597
611
  message?: string;
@@ -1376,6 +1390,49 @@ declare function updateSession(sessionId: string, status: SessionStatus): Promis
1376
1390
  declare function fetchStatusUrl(sessionId: string): Promise<StatusUrlResponse>;
1377
1391
  declare function fetchProviderConfigs(providerId: string, exactProviderVersionString: string | null | undefined, allowedTags: string[] | null | undefined): Promise<ProviderConfigResponse>;
1378
1392
 
1393
+ declare function createSignDataForClaim(data: CompleteClaimData): string;
1394
+ declare function getIdentifierFromClaimInfo(info: ClaimInfo): ClaimID;
1395
+ /**
1396
+ * Computes the cryptographic claim hash(es) for the HTTP provider payload parameters.
1397
+ *
1398
+ * If the parameters comprise solely of rigid/required rules (or represents an extracted
1399
+ * attested payload that enforces all its defined elements), this computes and returns a single deterministic string.
1400
+ *
1401
+ * **Combinatorial Hashes Intention:**
1402
+ * If the payload configuration defines optional elements (`isOptional: true` on ResponseMatchSpec),
1403
+ * a single rule configuration inherently encompasses multiple logical subset definitions.
1404
+ * Since cryptographic hashes strictly enforce exact data byte-by-byte,
1405
+ * this function recursively computes a hash for every mathematically valid permutation of the optional subsets
1406
+ * (inclusive and exclusive) so the validator can verify the proof against any of the legitimate subset match signatures.
1407
+ *
1408
+ * @param params - The HTTP provider claim configuration or extracted attested parameters.
1409
+ * @returns A single keccak256 hash string, or an array of hex-string hashes if parameter optionality generates combinations.
1410
+ */
1411
+ declare function hashProofClaimParams(params: HttpProviderClaimParams): string | string[];
1412
+ /**
1413
+ * Computes canonicalized string(s) for the provided HTTP parameter payload.
1414
+ *
1415
+ * **Architectural Concept**:
1416
+ * In Reclaim, proof security revolves around generating a deterministic Hash based on the JSON stringified keys
1417
+ * of matched specifications (e.g. `responseMatches` and `responseRedactions`).
1418
+ * When processing a Provider Configuration containing `isOptional` rules, the protocol doesn't require users to generate a
1419
+ * proof that matched *all* of the rules. A client could inherently omit any optional rules from claim before
1420
+ * starting claim creation to make a valid proof if the server payload may not contain them.
1421
+ *
1422
+ * To ensure the eventual Proof's Hash safely validates against the parent template's Requirement Hash, logic here
1423
+ * loops $2^N$ times using bitmask computation (where N = number of rule pairs) and yields canonically sorted
1424
+ * permutations for every sub-set of optional combinations.
1425
+ * Any combination forcefully omitting a mathematically required (`isOptional: false`) rule is stripped out.
1426
+ *
1427
+ * Note: When a user successfully generates a proof, their attested parameter payload does not contain `isOptional` tags
1428
+ * because the client sending request to attestor omits rules where data may not be present in response,
1429
+ * producing exactly 1 deterministic configuration subset (what the user actually proved!).
1430
+ *
1431
+ * @param params - The structured parameters.
1432
+ * @returns Serialized string or array of strings.
1433
+ */
1434
+ declare function getProviderParamsAsCanonicalizedString(params: HttpProviderClaimParams): string[];
1435
+
1379
1436
  /**
1380
1437
  * Validates the hardware TEE attestation included in the proof.
1381
1438
  * Throws an error if the attestation is invalid or compromised.
@@ -1423,4 +1480,4 @@ declare function isDesktopDevice(): boolean;
1423
1480
  */
1424
1481
  declare function clearDeviceCache(): void;
1425
1482
 
1426
- export { type Beacon, type BeaconState, type BodySniff, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type EmbeddedFlowHandle, type ExtensionMessage, type FlowHandle, type HashRequirement, type HashableHttpProviderClaimParams, type HttpFormEntry, type HttpProviderClaimParams, type HttpRedirectionMethod, type HttpRedirectionOptions, type InitSessionResponse, type InjectedRequestSpec, type InterceptorRequestSpec, type ModalOptions, type OnError, type OnSuccess, type Proof, type ProofPropertiesJSON, type ProofRequestOptions, type ProviderClaimData, type ProviderConfigResponse, type ProviderHashRequirementSpec, type ProviderHashRequirementsConfig, type ProviderHashRequirementsResponse, type ProviderVersionConfig, type ProviderVersionInfo, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type ReclaimProviderConfig, type RequestSpec, type ResponseMatchSpec, type ResponseRedactionSpec, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TeeAttestation, TeeVerificationError, type TemplateData, type TrustedData, type UpdateSessionResponse, type ValidationConfig, type ValidationConfigWithDisabledValidation, type ValidationConfigWithHash, type ValidationConfigWithProviderInformation, type VerificationConfig, type VerifyProofResult, type WitnessData, assertValidProofsByHash, assertValidateProof, assertVerifiedProof, clearDeviceCache, createLinkWithTemplateData, fetchProviderConfigs, fetchProviderHashRequirementsBy, fetchStatusUrl, generateSpecsFromRequestSpecTemplate, getAttestors, getDeviceType, getHttpProviderClaimParamsFromProof, getMobileDeviceType, getProviderHashRequirementsFromSpec, getShortenedUrl, hashRequestSpec, initSession, isDesktopDevice, isHttpProviderClaimParams, isMobileDevice, recoverSignersOfSignedClaim, takePairsWhereValueIsArray, takeTemplateParametersFromProofs, transformForOnchain, updateSession, verifyProof, verifyTeeAttestation };
1483
+ export { type Beacon, type BeaconState, type BodySniff, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type EmbeddedFlowHandle, type ExtensionMessage, type FlowHandle, type HashRequirement, type HashableHttpProviderClaimParams, type HttpFormEntry, type HttpProviderClaimParams, type HttpRedirectionMethod, type HttpRedirectionOptions, type InitSessionResponse, type InjectedRequestSpec, type InterceptorRequestSpec, type ModalOptions, type OnError, type OnSuccess, type Proof, type ProofPropertiesJSON, type ProofRequestOptions, type ProviderClaimData, type ProviderConfigResponse, type ProviderHashRequirementSpec, type ProviderHashRequirementsConfig, type ProviderHashRequirementsResponse, type ProviderVersionConfig, type ProviderVersionInfo, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowInitOptions, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type ReclaimProviderConfig, type ReclaimProviderConfigWithRequestSpec, type RequestSpec, type ResponseMatchSpec, type ResponseRedactionSpec, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TeeAttestation, TeeVerificationError, type TemplateData, type TrustedData, type UpdateSessionResponse, type ValidationConfig, type ValidationConfigWithDisabledValidation, type ValidationConfigWithHash, type ValidationConfigWithProviderInformation, type VerificationConfig, type VerifyProofResult, type WitnessData, assertValidProofsByHash, assertValidateProof, assertVerifiedProof, clearDeviceCache, createLinkWithTemplateData, createSignDataForClaim, fetchProviderConfigs, fetchProviderHashRequirementsBy, fetchStatusUrl, generateSpecsFromRequestSpecTemplate, getAttestors, getDeviceType, getHttpProviderClaimParamsFromProof, getIdentifierFromClaimInfo, getMobileDeviceType, getProviderHashRequirementSpecFromProviderConfig, getProviderHashRequirementsFromSpec, getProviderParamsAsCanonicalizedString, getShortenedUrl, hashProofClaimParams, hashRequestSpec, initSession, isDesktopDevice, isHttpProviderClaimParams, isMobileDevice, recoverSignersOfSignedClaim, takePairsWhereValueIsArray, takeTemplateParametersFromProofs, transformForOnchain, updateSession, verifyProof, verifyTeeAttestation };
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ var require_package = __commonJS({
84
84
  "package.json"(exports2, module2) {
85
85
  module2.exports = {
86
86
  name: "@reclaimprotocol/js-sdk",
87
- version: "5.0.0-dev.3",
87
+ version: "5.0.0-dev.5",
88
88
  description: "Designed to request proofs from the Reclaim protocol and manage the flow of claims and witness interactions.",
89
89
  main: "dist/index.js",
90
90
  types: "dist/index.d.ts",
@@ -199,6 +199,7 @@ __export(index_exports, {
199
199
  assertVerifiedProof: () => assertVerifiedProof,
200
200
  clearDeviceCache: () => clearDeviceCache,
201
201
  createLinkWithTemplateData: () => createLinkWithTemplateData,
202
+ createSignDataForClaim: () => createSignDataForClaim,
202
203
  fetchProviderConfigs: () => fetchProviderConfigs,
203
204
  fetchProviderHashRequirementsBy: () => fetchProviderHashRequirementsBy,
204
205
  fetchStatusUrl: () => fetchStatusUrl,
@@ -206,9 +207,13 @@ __export(index_exports, {
206
207
  getAttestors: () => getAttestors,
207
208
  getDeviceType: () => getDeviceType,
208
209
  getHttpProviderClaimParamsFromProof: () => getHttpProviderClaimParamsFromProof,
210
+ getIdentifierFromClaimInfo: () => getIdentifierFromClaimInfo,
209
211
  getMobileDeviceType: () => getMobileDeviceType,
212
+ getProviderHashRequirementSpecFromProviderConfig: () => getProviderHashRequirementSpecFromProviderConfig,
210
213
  getProviderHashRequirementsFromSpec: () => getProviderHashRequirementsFromSpec,
214
+ getProviderParamsAsCanonicalizedString: () => getProviderParamsAsCanonicalizedString,
211
215
  getShortenedUrl: () => getShortenedUrl,
216
+ hashProofClaimParams: () => hashProofClaimParams,
212
217
  hashRequestSpec: () => hashRequestSpec,
213
218
  initSession: () => initSession,
214
219
  isDesktopDevice: () => isDesktopDevice,
@@ -379,6 +384,10 @@ var constants = {
379
384
  DEFAULT_PROVIDER_CONFIGS_URL(providerId, exactProviderVersionString, allowedTags) {
380
385
  return `${BACKEND_BASE_URL}/api/providers/${providerId}/configs?versionNumber=${exactProviderVersionString || ""}&allowedTags=${(allowedTags == null ? void 0 : allowedTags.join(",")) || ""}`;
381
386
  },
387
+ // Default portal URL
388
+ DEFAULT_PORTAL_URL: "https://portal.reclaimprotocol.org",
389
+ // Default sharepage URL
390
+ DEFAULT_APP_SHARE_PAGE_URL: "https://share.reclaimprotocol.org/verifier",
382
391
  // URL for sharing Reclaim templates
383
392
  RECLAIM_SHARE_URL: "https://share.reclaimprotocol.org/verifier/?template=",
384
393
  // Chrome extension URL for Reclaim Protocol
@@ -838,9 +847,9 @@ function getProviderParamsAsCanonicalizedString(params) {
838
847
  responseMatches: [],
839
848
  responseRedactions: []
840
849
  };
841
- return canonicalStringify(filteredParams);
850
+ return [canonicalStringify(filteredParams)];
842
851
  }
843
- return validCanonicalizedStrings.length === 1 ? validCanonicalizedStrings[0] : validCanonicalizedStrings;
852
+ return validCanonicalizedStrings;
844
853
  }
845
854
 
846
855
  // src/utils/proofUtils.ts
@@ -1378,7 +1387,6 @@ function clearDeviceCache() {
1378
1387
  var logger7 = logger_default.logger;
1379
1388
  function fetchProviderHashRequirementsBy(providerId, exactProviderVersionString, allowedTags, proofs) {
1380
1389
  return __async(this, null, function* () {
1381
- var _a, _b;
1382
1390
  const providerResponse = yield fetchProviderConfigs(providerId, exactProviderVersionString, allowedTags);
1383
1391
  try {
1384
1392
  const providerConfigs = providerResponse.providers;
@@ -1387,9 +1395,8 @@ function fetchProviderHashRequirementsBy(providerId, exactProviderVersionString,
1387
1395
  }
1388
1396
  const hashRequirements = [];
1389
1397
  for (const providerConfig of providerConfigs) {
1390
- hashRequirements.push(getProviderHashRequirementsFromSpec({
1391
- requests: [...(_a = providerConfig == null ? void 0 : providerConfig.requestData) != null ? _a : [], ...generateSpecsFromRequestSpecTemplate((_b = providerConfig == null ? void 0 : providerConfig.allowedInjectedRequestData) != null ? _b : [], takeTemplateParametersFromProofs(proofs))]
1392
- }));
1398
+ const requestSpec = getProviderHashRequirementSpecFromProviderConfig(providerConfig, proofs);
1399
+ hashRequirements.push(getProviderHashRequirementsFromSpec(requestSpec));
1393
1400
  }
1394
1401
  return hashRequirements;
1395
1402
  } catch (e) {
@@ -1469,6 +1476,12 @@ function takePairsWhereValueIsArray(o) {
1469
1476
  }
1470
1477
  return pairs;
1471
1478
  }
1479
+ function getProviderHashRequirementSpecFromProviderConfig(providerConfig, proofs) {
1480
+ var _a, _b;
1481
+ return {
1482
+ requests: [...(_a = providerConfig == null ? void 0 : providerConfig.requestData) != null ? _a : [], ...generateSpecsFromRequestSpecTemplate((_b = providerConfig == null ? void 0 : providerConfig.allowedInjectedRequestData) != null ? _b : [], takeTemplateParametersFromProofs(proofs))]
1483
+ };
1484
+ }
1472
1485
  function getProviderHashRequirementsFromSpec(spec) {
1473
1486
  var _a;
1474
1487
  return {
@@ -2442,7 +2455,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2442
2455
  this.intervals = /* @__PURE__ */ new Map();
2443
2456
  this.jsonProofResponse = false;
2444
2457
  this.extensionID = "reclaim-extension";
2445
- this.appSharePageUrl = "https://share.reclaimprotocol.org/verify";
2458
+ this.appSharePageUrl = constants.DEFAULT_APP_SHARE_PAGE_URL;
2446
2459
  this.FAILURE_TIMEOUT = 30 * 1e3;
2447
2460
  /**
2448
2461
  * Validates signature and returns template data
@@ -2493,7 +2506,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2493
2506
  };
2494
2507
  return templateData;
2495
2508
  };
2496
- var _a, _b;
2509
+ var _a;
2497
2510
  this.providerId = providerId;
2498
2511
  this.timeStamp = Date.now().toString();
2499
2512
  this.applicationId = applicationId;
@@ -2512,9 +2525,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
2512
2525
  if (options.useAppClip === void 0) {
2513
2526
  options.useAppClip = false;
2514
2527
  }
2515
- const customUrl = (_b = options.portalUrl) != null ? _b : options.customSharePageUrl;
2516
- this.customSharePageUrl = customUrl != null ? customUrl : "https://portal.reclaimprotocol.org";
2517
- if (customUrl) {
2528
+ const customUrl = options.portalUrl || options.customSharePageUrl;
2529
+ this.customSharePageUrl = customUrl || constants.DEFAULT_PORTAL_URL;
2530
+ if (customUrl && customUrl !== constants.DEFAULT_PORTAL_URL) {
2518
2531
  this.appSharePageUrl = customUrl;
2519
2532
  }
2520
2533
  options.customSharePageUrl = this.customSharePageUrl;
@@ -3363,7 +3376,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
3363
3376
  getRequestUrl(launchOptions) {
3364
3377
  return __async(this, null, function* () {
3365
3378
  var _a, _b, _c;
3366
- const options = launchOptions || ((_a = this.options) == null ? void 0 : _a.launchOptions) || {};
3379
+ const options = __spreadValues(__spreadValues({}, (_a = this.options) == null ? void 0 : _a.launchOptions), launchOptions);
3367
3380
  const mode = (_b = options.verificationMode) != null ? _b : "portal";
3368
3381
  logger10.info("Creating Request Url");
3369
3382
  if (!this.signature) {
@@ -3438,7 +3451,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
3438
3451
  triggerReclaimFlow(launchOptions) {
3439
3452
  return __async(this, null, function* () {
3440
3453
  var _a, _b, _c, _d, _e;
3441
- const options = launchOptions || ((_a = this.options) == null ? void 0 : _a.launchOptions) || {};
3454
+ const options = __spreadValues(__spreadValues({}, (_a = this.options) == null ? void 0 : _a.launchOptions), launchOptions);
3442
3455
  const mode = (_b = options.verificationMode) != null ? _b : "portal";
3443
3456
  if (!this.signature) {
3444
3457
  throw new SignatureNotFoundError("Signature is not set.");
@@ -3449,11 +3462,11 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
3449
3462
  logger10.info(`Triggering Reclaim flow (mode: ${mode})`);
3450
3463
  const deviceType = getDeviceType();
3451
3464
  updateSession(this.sessionId, "SESSION_STARTED" /* SESSION_STARTED */);
3452
- if ("target" in options && !options.target) {
3465
+ if (launchOptions && "target" in launchOptions && !launchOptions.target) {
3453
3466
  logger10.warn("triggerReclaimFlow: target was provided but is null/undefined \u2014 falling back to default flow. Ensure the element exists in the DOM.");
3454
3467
  }
3455
- if (options.target && mode === "portal") {
3456
- yield this.embedPortalIframe(templateData, options.target);
3468
+ if ((launchOptions == null ? void 0 : launchOptions.target) && mode === "portal") {
3469
+ yield this.embedPortalIframe(templateData, launchOptions.target);
3457
3470
  return {
3458
3471
  close: () => this.closeEmbeddedFlow(),
3459
3472
  iframe: this.portalIframe
@@ -3846,6 +3859,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
3846
3859
  assertVerifiedProof,
3847
3860
  clearDeviceCache,
3848
3861
  createLinkWithTemplateData,
3862
+ createSignDataForClaim,
3849
3863
  fetchProviderConfigs,
3850
3864
  fetchProviderHashRequirementsBy,
3851
3865
  fetchStatusUrl,
@@ -3853,9 +3867,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
3853
3867
  getAttestors,
3854
3868
  getDeviceType,
3855
3869
  getHttpProviderClaimParamsFromProof,
3870
+ getIdentifierFromClaimInfo,
3856
3871
  getMobileDeviceType,
3872
+ getProviderHashRequirementSpecFromProviderConfig,
3857
3873
  getProviderHashRequirementsFromSpec,
3874
+ getProviderParamsAsCanonicalizedString,
3858
3875
  getShortenedUrl,
3876
+ hashProofClaimParams,
3859
3877
  hashRequestSpec,
3860
3878
  initSession,
3861
3879
  isDesktopDevice,