@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.d.ts CHANGED
@@ -37,6 +37,7 @@ interface ProviderClaimData {
37
37
  interface Context {
38
38
  contextAddress: string;
39
39
  contextMessage: string;
40
+ reclaimSessionId: string;
40
41
  }
41
42
  interface Beacon {
42
43
  getState(epoch?: number): Promise<BeaconState>;
@@ -49,9 +50,144 @@ type BeaconState = {
49
50
  nextEpochTimestampS: number;
50
51
  };
51
52
 
53
+ /**
54
+ * Transforms a raw provider hash requirement specification into a structured configuration for proof validation.
55
+ * It computes the proof hashes for both required and allowed extra requests to correctly match uploaded proofs.
56
+ *
57
+ * See also:
58
+ *
59
+ * * `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.
60
+ * * `ReclaimProofRequest.getProviderHashRequirements()` - An alternative of this function to get the expected hashes for a proof request. The result can be provided in verifyProof function's `config` parameter for proof validation.
61
+ *
62
+ * @param spec - The raw provider specifications including required and allowed requests.
63
+ * @returns A structured configuration containing computed required and allowed hashes for validation.
64
+ */
65
+ declare function getProviderHashRequirementsFromSpec(spec: ProviderHashRequirementSpec): ProviderHashRequirementsConfig;
66
+ /**
67
+ * Computes the claim hash for a specific request specification based on its properties.
68
+ *
69
+ * @param request - The HTTP request specification (e.g., URL, method, sniffs).
70
+ * @returns A string representing the hashed proof claim parameters.
71
+ */
72
+ declare function hashRequestSpec(request: RequestSpec): HashRequirement;
73
+ /**
74
+ * Represents the raw specification of hash requirements provided by a provider's configuration.
75
+ */
76
+ interface ProviderHashRequirementSpec {
77
+ /** List of request specs that can match with HTTP requests to create a proof using Reclaim Protocol */
78
+ requests: RequestSpec[] | undefined;
79
+ }
80
+ /**
81
+ * The structured hash requirements configuration used during proof verification and content validation.
82
+ */
83
+ type ProviderHashRequirementsConfig = {
84
+ /**
85
+ * Array of computed hash requirements that must be satisfied by the proofs.
86
+ */
87
+ hashes: HashRequirement[];
88
+ };
89
+ /**
90
+ * Describes a hash requirement for a proof.
91
+ */
92
+ type HashRequirement = {
93
+ /**
94
+ * The hash value to match
95
+ */
96
+ value: string;
97
+ /**
98
+ * Whether the hash is required to be present in the proof.
99
+ * Defaults to true
100
+ */
101
+ required?: boolean;
102
+ /**
103
+ * Whether the hash can appear multiple times in the proof.
104
+ * Defaults to false
105
+ */
106
+ multiple?: boolean;
107
+ };
108
+ /**
109
+ * Specific marker interface for intercepted request specifications.
110
+ */
111
+ interface InterceptorRequestSpec extends RequestSpec {
112
+ }
113
+ /**
114
+ * Specific marker interface for injected request specifications.
115
+ */
116
+ interface InjectedRequestSpec extends RequestSpec {
117
+ }
118
+ /**
119
+ * Represents the properties and validation steps for an HTTP request involved in a Reclaim proof.
120
+ */
121
+ interface RequestSpec {
122
+ /** The URL or generic path of the HTTP request */
123
+ url: string;
124
+ /** Type or representation of the URL */
125
+ urlType: string;
126
+ /** The HTTP method used for the request */
127
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
128
+ /** Identifies and captures the request body if enabled */
129
+ bodySniff: BodySniff;
130
+ /** Required matching configurations for the HTTP response */
131
+ responseMatches: ResponseMatchSpec[];
132
+ /** Redaction rules applied to the HTTP response before passing to attestors */
133
+ responseRedactions: ResponseRedactionSpec[];
134
+ /**
135
+ * Whether request matching this spec is required and always expected in list of proofs
136
+ * Defaults to true.
137
+ */
138
+ required?: boolean;
139
+ /**
140
+ * Whether request matching this spec is allowed to appear multiple times in list of proofs.
141
+ * Defaults to false.
142
+ */
143
+ multiple?: boolean;
144
+ }
145
+ /**
146
+ * Defines the configuration for identifying/sniffing the request body.
147
+ */
148
+ interface BodySniff {
149
+ /** Indicates whether body sniffing is enabled */
150
+ enabled: boolean;
151
+ /** The template string used to match or capture the body */
152
+ template: string;
153
+ }
154
+ /**
155
+ * Specifies a rule to match against a string in response to validate proof content.
156
+ */
157
+ interface ResponseMatchSpec {
158
+ /** If true, the match condition is reversed */
159
+ invert: boolean | undefined;
160
+ /** If true, the match condition is optional and won't fail if absent */
161
+ isOptional: boolean | undefined;
162
+ /** The matching mechanism, typically regex or simple string containment */
163
+ type: "regex" | "contains";
164
+ /** The pattern or value to look for in the response */
165
+ value: string;
166
+ }
167
+ /**
168
+ * Specifies redaction rules for obscuring sensitive parts of the response.
169
+ */
170
+ interface ResponseRedactionSpec {
171
+ /** Optional hashing method applied to the redacted content (e.g., 'oprf') */
172
+ hash?: "oprf" | undefined;
173
+ /** JSON path for locating the value to redact */
174
+ jsonPath: string;
175
+ /** RegEx applied to correctly parse and extract/redact value */
176
+ regex: string;
177
+ /** XPath for XML/HTML matching configuration */
178
+ xPath: string;
179
+ }
180
+
52
181
  type ClaimID = ProviderClaimData['identifier'];
53
182
  type ClaimInfo = Pick<ProviderClaimData, 'context' | 'provider' | 'parameters'>;
54
183
  type CompleteClaimData = Pick<ProviderClaimData, 'owner' | 'timestampS' | 'epoch'> & ClaimInfo;
184
+ interface HttpProviderClaimParams {
185
+ body: string;
186
+ method: RequestSpec['method'];
187
+ responseMatches: ResponseMatchSpec[];
188
+ responseRedactions: ResponseRedactionSpec[];
189
+ url: string;
190
+ }
55
191
  type SignedClaim = {
56
192
  claim: CompleteClaimData;
57
193
  signatures: Uint8Array[];
@@ -264,37 +400,119 @@ type TemplateData = {
264
400
  metadata?: Record<string, string>;
265
401
  preferredLocale?: ProofRequestOptions['preferredLocale'];
266
402
  };
403
+ type ProviderVersionConfig = {
404
+ major?: number;
405
+ minor?: number;
406
+ patch?: number;
407
+ prereleaseTag?: string;
408
+ prereleaseNumber?: number;
409
+ };
267
410
  type StatusUrlResponse = {
268
411
  message: string;
269
412
  session?: {
270
413
  id: string;
271
414
  appId: string;
272
415
  httpProviderId: string[];
416
+ providerId: string;
417
+ providerVersionString: string;
273
418
  sessionId: string;
274
419
  proofs?: Proof[];
275
420
  statusV2: string;
276
421
  };
277
422
  providerId?: string;
278
423
  };
424
+ type ProviderConfigResponse = {
425
+ message: string;
426
+ providers?: ReclaimProviderConfig;
427
+ providerId?: string;
428
+ providerVersionString?: string;
429
+ };
430
+ interface ReclaimProviderConfig {
431
+ loginUrl: string;
432
+ customInjection: string;
433
+ geoLocation: string;
434
+ injectionType: string;
435
+ disableRequestReplay: boolean;
436
+ verificationType: string;
437
+ requestData: InterceptorRequestSpec[];
438
+ allowedInjectedRequestData: InjectedRequestSpec[];
439
+ }
440
+
441
+ /**
442
+ * Content validation configuration specifying essential required hashes and optional extra proofs.
443
+ * Used to explicitly validate that a generated proof matches the exact request structure expected.
444
+ */
445
+ type ValidationConfigWithHash = {
446
+ /**
447
+ * Array of computed hashes that must be satisfied by the proofs.
448
+ *
449
+ * An element can be a `HashRequirement` object or a string that is equivalent to
450
+ * a `{ value: '<hash>', required: true, multiple: false }` as `HashRequirement`.
451
+ */
452
+ hashes: (string | HashRequirement)[];
453
+ };
454
+ /**
455
+ * Legacy configuration to completely bypass content validation during verification.
456
+ * Warning: Using this poses a risk as it avoids strictly matching proof parameters to expected hashes.
457
+ */
458
+ interface ValidationConfigWithDisabledValidation {
459
+ dangerouslyDisableContentValidation: true;
460
+ }
461
+ /**
462
+ * Represents the configuration options applied when validating proof contents, allowing
463
+ * strict hash checking or intentionally skipping validation if flagged.
464
+ */
465
+ type ValidationConfig = ValidationConfigWithHash | ValidationConfigWithDisabledValidation;
466
+ /**
467
+ * Describes the comprehensive configuration required to initialize the proof verification process.
468
+ * Aligns with `ValidationConfig` options for verifying signatures alongside proof contents.
469
+ */
470
+ type VerificationConfig = ValidationConfig;
471
+ declare function assertValidProofsByHash(proofs: Proof[], config: ProviderHashRequirementsConfig): void;
472
+ declare function isHttpProviderClaimParams(claimParams: unknown): claimParams is HttpProviderClaimParams;
473
+ declare function getHttpProviderClaimParamsFromProof(proof: Proof): HttpProviderClaimParams;
474
+ /**
475
+ * Asserts that the proof is validated by checking the content of proof with with expectations from provider config or hash based on [options]
476
+ * @param proofs - The proofs to validate
477
+ * @param config - The validation config
478
+ * @throws {ProofNotValidatedError} When the proof is not validated
479
+ */
480
+ declare function assertValidateProof(proofs: Proof[], config: VerificationConfig): void;
279
481
 
280
482
  /**
281
- * Verifies one or more Reclaim proofs by validating signatures and witness information
483
+ * Verifies one or more Reclaim proofs by validating signatures, verifying witness information,
484
+ * and performing content validation against the expected configuration.
485
+ *
486
+ * See also:
487
+ *
488
+ * * `ReclaimProofRequest.getProviderHashRequirements()` - To get the expected proof hash requirements for a proof request.
489
+ * * `fetchProviderHashRequirementsBy()` - To get the expected proof hash requirements for a provider version by providing providerId and exactProviderVersionString.
490
+ * * `getProviderHashRequirementsFromSpec()` - To get the expected proof hash requirements from a provider spec.
491
+ * * All 3 functions above are alternatives of each other and result from these functions can be directly used as `config` parameter in this function for proof validation.
282
492
  *
283
- * @param proofOrProofs - A single proof object or an array of proof objects to verify
284
- * @param allowAiWitness - Optional flag to allow AI witness verification. Defaults to false
285
- * @returns Promise<boolean> - Returns true if all proofs are valid, false otherwise
286
- * @throws {SignatureNotFoundError} When proof has no signatures
287
- * @throws {ProofNotVerifiedError} When identifier mismatch occurs
493
+ * @param proofOrProofs - A single proof object or an array of proof objects to be verified.
494
+ * @param config - Verification configuration that specifies required hashes, allowed extra hashes, or disables content validation.
495
+ * @returns Promise<boolean> - Returns `true` if all proofs are successfully verified and validated, `false` otherwise.
496
+ * @throws {ProofNotVerifiedError} When signature validation or identifier mismatch occurs.
497
+ * @throws {ProofNotValidatedError} When no proofs are provided, when the configuration is missing, or when proof content does not match the expectations set in the config.
288
498
  *
289
499
  * @example
290
500
  * ```typescript
291
- * const isValid = await verifyProof(proof);
292
- * const areAllValid = await verifyProof([proof1, proof2, proof3]);
293
- * const isValidWithAI = await verifyProof(proof, true);
501
+ * // Validate a single proof against expected hash
502
+ * const isValid = await verifyProof(proof, { hashes: ['0xAbC...'] });
503
+ *
504
+ * // Validate multiple proofs
505
+ * const areAllValid = await verifyProof([proof1, proof2], {
506
+ * hashes: ['0xAbC...', '0xF22..'],
507
+ * });
508
+ *
509
+ * // Validate 1 required proofs, any number of multiple with same hash, and one optional
510
+ * const areAllValid = await verifyProof([proof1, proof2, sameAsProof2], {
511
+ * hashes: ['0xAbC...', { value: '0xF22..', multiple: true }, { value: '0xE33..', required: false }],
512
+ * });
294
513
  * ```
295
514
  */
296
- declare function verifyProof(proofOrProofs: Proof | Proof[], allowAiWitness?: boolean): Promise<boolean>;
297
- declare function assertValidProof(proofOrProofs: Proof | Proof[], allowAiWitness?: boolean): Promise<void>;
515
+ declare function verifyProof(proofOrProofs: Proof | Proof[], config: VerificationConfig): Promise<boolean>;
298
516
  /**
299
517
  * Transforms a Reclaim proof into a format suitable for on-chain verification
300
518
  *
@@ -728,6 +946,16 @@ declare class ReclaimProofRequest {
728
946
  private showQRCodeModal;
729
947
  private redirectToInstantApp;
730
948
  private redirectToAppClip;
949
+ /**
950
+ * Fetches the provider config that was used for this session and returns the hash requirements
951
+ *
952
+ * See also:
953
+ * * `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.
954
+ * * `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.
955
+ *
956
+ * @returns A promise that resolves to a ProviderHashRequirementsConfig
957
+ */
958
+ getProviderHashRequirements(): Promise<ProviderHashRequirementsConfig>;
731
959
  /**
732
960
  * Starts the proof request session and monitors for proof submission
733
961
  *
@@ -795,6 +1023,79 @@ declare class ReclaimProofRequest {
795
1023
  getJsonProofResponse(): boolean;
796
1024
  }
797
1025
 
1026
+ /**
1027
+ * Retrieves a shortened URL for the given URL
1028
+ * @param url - The URL to be shortened
1029
+ * @returns A promise that resolves to the shortened URL, or the original URL if shortening fails
1030
+ */
1031
+ declare function getShortenedUrl(url: string): Promise<string>;
1032
+ /**
1033
+ * Creates a link with embedded template data
1034
+ * @param templateData - The data to be embedded in the link
1035
+ * @param sharePagePath - The path to the share page (optional)
1036
+ * @returns A promise that resolves to the created link (shortened if possible)
1037
+ */
1038
+ declare function createLinkWithTemplateData(templateData: TemplateData, sharePagePath?: string): Promise<string>;
1039
+ /**
1040
+ * Retrieves the list of witnesses for a given claim
1041
+ */
1042
+ declare function getAttestors(): Promise<WitnessData[]>;
1043
+ /**
1044
+ * Recovers the signers' addresses from a signed claim
1045
+ * @param claim - The signed claim object
1046
+ * @param signatures - The signatures associated with the claim
1047
+ * @returns An array of recovered signer addresses
1048
+ */
1049
+ declare function recoverSignersOfSignedClaim({ claim, signatures }: SignedClaim): string[];
1050
+ /**
1051
+ * Asserts that the proof is verified by checking the signatures and witness information
1052
+ * @param proof - The proof to verify
1053
+ * @param attestors - The attestors to check against
1054
+ * @throws {ProofNotVerifiedError} When the proof is not verified
1055
+ */
1056
+ declare function assertVerifiedProof(proof: Proof, attestors: WitnessData[]): Promise<void>;
1057
+
1058
+ /**
1059
+ * Initializes a session with the provided parameters
1060
+ * @param providerId - The ID of the provider
1061
+ * @param appId - The ID of the application
1062
+ * @param timestamp - The timestamp of the request
1063
+ * @param signature - The signature for authentication
1064
+ * @returns A promise that resolves to an InitSessionResponse
1065
+ * @throws InitSessionError if the session initialization fails
1066
+ */
1067
+ declare function initSession(providerId: string, appId: string, timestamp: string, signature: string, versionNumber?: string): Promise<InitSessionResponse>;
1068
+ /**
1069
+ * Updates the status of an existing session
1070
+ * @param sessionId - The ID of the session to update
1071
+ * @param status - The new status of the session
1072
+ * @returns A promise that resolves to the update response
1073
+ * @throws UpdateSessionError if the session update fails
1074
+ */
1075
+ declare function updateSession(sessionId: string, status: SessionStatus): Promise<any>;
1076
+ /**
1077
+ * Fetches the status URL for a given session ID
1078
+ * @param sessionId - The ID of the session to fetch the status URL for
1079
+ * @returns A promise that resolves to a StatusUrlResponse
1080
+ * @throws StatusUrlError if the status URL fetch fails
1081
+ */
1082
+ declare function fetchStatusUrl(sessionId: string): Promise<StatusUrlResponse>;
1083
+ declare function fetchProviderConfig(providerId: string, exactProviderVersionString: string): Promise<ProviderConfigResponse>;
1084
+ /**
1085
+ * Fetches the provider configuration by the providerId and its version; and constructs the robust hash requirements needed for proof validation.
1086
+ * It resolves both explicitly required HTTP requests and allowed injected requests based on the provider version.
1087
+ *
1088
+ * See also:
1089
+ *
1090
+ * * `ReclaimProofRequest.getProviderHashRequirements()` - An alternative of this function to get the expected hashes for a proof request. The result can be provided in verifyProof function's `config` parameter for proof validation.
1091
+ * * `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.
1092
+ *
1093
+ * @param providerId - The unique identifier of the selected provider.
1094
+ * @param exactProviderVersion - The specific version string of the provider configuration to ensure deterministic validation.
1095
+ * @returns A promise that resolves to `ProviderHashRequirementsConfig` representing the expected hashes for proof validation.
1096
+ */
1097
+ declare function fetchProviderHashRequirementsBy(providerId: string, exactProviderVersion: string): Promise<ProviderHashRequirementsConfig>;
1098
+
798
1099
  /**
799
1100
  * Highly accurate device type detection - returns only 'desktop' or 'mobile'
800
1101
  * Uses multiple detection methods and scoring system for maximum accuracy
@@ -822,4 +1123,4 @@ declare function isDesktopDevice(): boolean;
822
1123
  */
823
1124
  declare function clearDeviceCache(): void;
824
1125
 
825
- export { type Beacon, type BeaconState, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type ExtensionMessage, type HttpFormEntry, type HttpRedirectionMethod, type HttpRedirectionOptions, type InitSessionResponse, type ModalOptions, type OnError, type OnSuccess, type Proof, type ProofPropertiesJSON, type ProofRequestOptions, type ProviderClaimData, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TemplateData, type UpdateSessionResponse, type WitnessData, assertValidProof, clearDeviceCache, getDeviceType, getMobileDeviceType, isDesktopDevice, isMobileDevice, transformForOnchain, verifyProof };
1126
+ export { type Beacon, type BeaconState, type BodySniff, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type ExtensionMessage, type HashRequirement, 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 ProviderVersionConfig, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type ReclaimProviderConfig, type RequestSpec, type ResponseMatchSpec, type ResponseRedactionSpec, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TemplateData, type UpdateSessionResponse, type ValidationConfig, type ValidationConfigWithDisabledValidation, type ValidationConfigWithHash, type VerificationConfig, type WitnessData, assertValidProofsByHash, assertValidateProof, assertVerifiedProof, clearDeviceCache, createLinkWithTemplateData, fetchProviderConfig, fetchProviderHashRequirementsBy, fetchStatusUrl, getAttestors, getDeviceType, getHttpProviderClaimParamsFromProof, getMobileDeviceType, getProviderHashRequirementsFromSpec, getShortenedUrl, hashRequestSpec, initSession, isDesktopDevice, isHttpProviderClaimParams, isMobileDevice, recoverSignersOfSignedClaim, transformForOnchain, updateSession, verifyProof };