@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.d.ts +204 -16
- package/dist/index.js +297 -100
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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,12 +50,117 @@ type BeaconState = {
|
|
|
49
50
|
nextEpochTimestampS: number;
|
|
50
51
|
};
|
|
51
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The structured hash requirements configuration used during proof verification and content validation.
|
|
55
|
+
*/
|
|
56
|
+
type ProviderHashRequirementsConfig = {
|
|
57
|
+
/**
|
|
58
|
+
* Array of computed hash requirements that must be satisfied by the proofs.
|
|
59
|
+
*/
|
|
60
|
+
hashes: HashRequirement[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Describes a hash requirement for a proof.
|
|
64
|
+
*/
|
|
65
|
+
type HashRequirement = {
|
|
66
|
+
/**
|
|
67
|
+
* The hash value to match
|
|
68
|
+
*/
|
|
69
|
+
value: string;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the hash is required to be present in the proof.
|
|
72
|
+
* Defaults to true
|
|
73
|
+
*/
|
|
74
|
+
required?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the hash can appear multiple times in the proof.
|
|
77
|
+
* Defaults to false
|
|
78
|
+
*/
|
|
79
|
+
multiple?: boolean;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Specific marker interface for intercepted request specifications.
|
|
83
|
+
*/
|
|
84
|
+
interface InterceptorRequestSpec extends RequestSpec {
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Specific marker interface for injected request specifications.
|
|
88
|
+
*/
|
|
89
|
+
interface InjectedRequestSpec extends RequestSpec {
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Represents the properties and validation steps for an HTTP request involved in a Reclaim proof.
|
|
93
|
+
*/
|
|
94
|
+
interface RequestSpec {
|
|
95
|
+
/** The URL or generic path of the HTTP request */
|
|
96
|
+
url: string;
|
|
97
|
+
/** Type or representation of the URL */
|
|
98
|
+
urlType: string;
|
|
99
|
+
/** The HTTP method used for the request */
|
|
100
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
101
|
+
/** Identifies and captures the request body if enabled */
|
|
102
|
+
bodySniff: BodySniff;
|
|
103
|
+
/** Required matching configurations for the HTTP response */
|
|
104
|
+
responseMatches: ResponseMatchSpec[];
|
|
105
|
+
/** Redaction rules applied to the HTTP response before passing to attestors */
|
|
106
|
+
responseRedactions: ResponseRedactionSpec[];
|
|
107
|
+
/**
|
|
108
|
+
* Whether request matching this spec is required and always expected in list of proofs
|
|
109
|
+
* Defaults to true.
|
|
110
|
+
*/
|
|
111
|
+
required?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Whether request matching this spec is allowed to appear multiple times in list of proofs.
|
|
114
|
+
* Defaults to false.
|
|
115
|
+
*/
|
|
116
|
+
multiple?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Defines the configuration for identifying/sniffing the request body.
|
|
120
|
+
*/
|
|
121
|
+
interface BodySniff {
|
|
122
|
+
/** Indicates whether body sniffing is enabled */
|
|
123
|
+
enabled: boolean;
|
|
124
|
+
/** The template string used to match or capture the body */
|
|
125
|
+
template: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Specifies a rule to match against a string in response to validate proof content.
|
|
129
|
+
*/
|
|
130
|
+
interface ResponseMatchSpec {
|
|
131
|
+
/** If true, the match condition is reversed */
|
|
132
|
+
invert: boolean | undefined;
|
|
133
|
+
/** If true, the match condition is optional and won't fail if absent */
|
|
134
|
+
isOptional: boolean | undefined;
|
|
135
|
+
/** The matching mechanism, typically regex or simple string containment */
|
|
136
|
+
type: "regex" | "contains";
|
|
137
|
+
/** The pattern or value to look for in the response */
|
|
138
|
+
value: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Specifies redaction rules for obscuring sensitive parts of the response.
|
|
142
|
+
*/
|
|
143
|
+
interface ResponseRedactionSpec {
|
|
144
|
+
/** Optional hashing method applied to the redacted content (e.g., 'oprf') */
|
|
145
|
+
hash?: "oprf" | undefined;
|
|
146
|
+
/** JSON path for locating the value to redact */
|
|
147
|
+
jsonPath: string;
|
|
148
|
+
/** RegEx applied to correctly parse and extract/redact value */
|
|
149
|
+
regex: string;
|
|
150
|
+
/** XPath for XML/HTML matching configuration */
|
|
151
|
+
xPath: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
52
154
|
type ClaimID = ProviderClaimData['identifier'];
|
|
53
155
|
type ClaimInfo = Pick<ProviderClaimData, 'context' | 'provider' | 'parameters'>;
|
|
54
|
-
type
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
156
|
+
type CompleteClaimData = Pick<ProviderClaimData, 'owner' | 'timestampS' | 'epoch'> & ClaimInfo;
|
|
157
|
+
interface HttpProviderClaimParams {
|
|
158
|
+
body: string;
|
|
159
|
+
method: RequestSpec['method'];
|
|
160
|
+
responseMatches: ResponseMatchSpec[];
|
|
161
|
+
responseRedactions: ResponseRedactionSpec[];
|
|
162
|
+
url: string;
|
|
163
|
+
}
|
|
58
164
|
type SignedClaim = {
|
|
59
165
|
claim: CompleteClaimData;
|
|
60
166
|
signatures: Uint8Array[];
|
|
@@ -267,37 +373,109 @@ type TemplateData = {
|
|
|
267
373
|
metadata?: Record<string, string>;
|
|
268
374
|
preferredLocale?: ProofRequestOptions['preferredLocale'];
|
|
269
375
|
};
|
|
376
|
+
type ProviderVersionConfig = {
|
|
377
|
+
major?: number;
|
|
378
|
+
minor?: number;
|
|
379
|
+
patch?: number;
|
|
380
|
+
prereleaseTag?: string;
|
|
381
|
+
prereleaseNumber?: number;
|
|
382
|
+
};
|
|
270
383
|
type StatusUrlResponse = {
|
|
271
384
|
message: string;
|
|
272
385
|
session?: {
|
|
273
386
|
id: string;
|
|
274
387
|
appId: string;
|
|
275
388
|
httpProviderId: string[];
|
|
389
|
+
providerId: string;
|
|
390
|
+
providerVersionString: string;
|
|
276
391
|
sessionId: string;
|
|
277
392
|
proofs?: Proof[];
|
|
278
393
|
statusV2: string;
|
|
279
394
|
};
|
|
280
395
|
providerId?: string;
|
|
281
396
|
};
|
|
397
|
+
type ProviderConfigResponse = {
|
|
398
|
+
message: string;
|
|
399
|
+
providers?: ReclaimProviderConfig;
|
|
400
|
+
providerId?: string;
|
|
401
|
+
providerVersionString?: string;
|
|
402
|
+
};
|
|
403
|
+
interface ReclaimProviderConfig {
|
|
404
|
+
loginUrl: string;
|
|
405
|
+
customInjection: string;
|
|
406
|
+
geoLocation: string;
|
|
407
|
+
injectionType: string;
|
|
408
|
+
disableRequestReplay: boolean;
|
|
409
|
+
verificationType: string;
|
|
410
|
+
requestData: InterceptorRequestSpec[];
|
|
411
|
+
allowedInjectedRequestData: InjectedRequestSpec[];
|
|
412
|
+
}
|
|
282
413
|
|
|
283
414
|
/**
|
|
284
|
-
*
|
|
415
|
+
* Content validation configuration specifying essential required hashes and optional extra proofs.
|
|
416
|
+
* Used to explicitly validate that a generated proof matches the exact request structure expected.
|
|
417
|
+
*/
|
|
418
|
+
type ValidationConfigWithHash = {
|
|
419
|
+
/**
|
|
420
|
+
* Array of computed hashes that must be satisfied by the proofs.
|
|
421
|
+
*
|
|
422
|
+
* An element can be a `HashRequirement` object or a string that is equivalent to
|
|
423
|
+
* a `{ value: '<hash>', required: true, multiple: false }` as `HashRequirement`.
|
|
424
|
+
*/
|
|
425
|
+
hashes: (string | HashRequirement)[];
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* Legacy configuration to completely bypass content validation during verification.
|
|
429
|
+
* Warning: Using this poses a risk as it avoids strictly matching proof parameters to expected hashes.
|
|
430
|
+
*/
|
|
431
|
+
interface ValidationConfigWithDisabledValidation {
|
|
432
|
+
dangerouslyDisableContentValidation: true;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Represents the configuration options applied when validating proof contents, allowing
|
|
436
|
+
* strict hash checking or intentionally skipping validation if flagged.
|
|
437
|
+
*/
|
|
438
|
+
type ValidationConfig = ValidationConfigWithHash | ValidationConfigWithDisabledValidation;
|
|
439
|
+
/**
|
|
440
|
+
* Describes the comprehensive configuration required to initialize the proof verification process.
|
|
441
|
+
* Aligns with `ValidationConfig` options for verifying signatures alongside proof contents.
|
|
442
|
+
*/
|
|
443
|
+
type VerificationConfig = ValidationConfig;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Verifies one or more Reclaim proofs by validating signatures, verifying witness information,
|
|
447
|
+
* and performing content validation against the expected configuration.
|
|
285
448
|
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
449
|
+
* See also:
|
|
450
|
+
*
|
|
451
|
+
* * `ReclaimProofRequest.getProviderHashRequirements()` - To get the expected proof hash requirements for a proof request.
|
|
452
|
+
* * `fetchProviderHashRequirementsBy()` - To get the expected proof hash requirements for a provider version by providing providerId and exactProviderVersionString.
|
|
453
|
+
* * `getProviderHashRequirementsFromSpec()` - To get the expected proof hash requirements from a provider spec.
|
|
454
|
+
* * 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.
|
|
455
|
+
*
|
|
456
|
+
* @param proofOrProofs - A single proof object or an array of proof objects to be verified.
|
|
457
|
+
* @param config - Verification configuration that specifies required hashes, allowed extra hashes, or disables content validation.
|
|
458
|
+
* @returns Promise<boolean> - Returns `true` if all proofs are successfully verified and validated, `false` otherwise.
|
|
459
|
+
* @throws {ProofNotVerifiedError} When signature validation or identifier mismatch occurs.
|
|
460
|
+
* @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.
|
|
291
461
|
*
|
|
292
462
|
* @example
|
|
293
463
|
* ```typescript
|
|
294
|
-
*
|
|
295
|
-
* const
|
|
296
|
-
*
|
|
464
|
+
* // Validate a single proof against expected hash
|
|
465
|
+
* const isValid = await verifyProof(proof, { hashes: ['0xAbC...'] });
|
|
466
|
+
*
|
|
467
|
+
* // Validate multiple proofs
|
|
468
|
+
* const areAllValid = await verifyProof([proof1, proof2], {
|
|
469
|
+
* hashes: ['0xAbC...', '0xF22..'],
|
|
470
|
+
* });
|
|
471
|
+
*
|
|
472
|
+
* // Validate 1 required proofs, any number of multiple with same hash, and one optional
|
|
473
|
+
* const areAllValid = await verifyProof([proof1, proof2, sameAsProof2], {
|
|
474
|
+
* hashes: ['0xAbC...', { value: '0xF22..', multiple: true }, { value: '0xE33..', required: false }],
|
|
475
|
+
* });
|
|
297
476
|
* ```
|
|
298
477
|
*/
|
|
299
|
-
declare function verifyProof(proofOrProofs: Proof | Proof[],
|
|
300
|
-
declare function assertValidProof(proofOrProofs: Proof | Proof[], allowAiWitness?: boolean): Promise<void>;
|
|
478
|
+
declare function verifyProof(proofOrProofs: Proof | Proof[], config: VerificationConfig): Promise<boolean>;
|
|
301
479
|
/**
|
|
302
480
|
* Transforms a Reclaim proof into a format suitable for on-chain verification
|
|
303
481
|
*
|
|
@@ -731,6 +909,16 @@ declare class ReclaimProofRequest {
|
|
|
731
909
|
private showQRCodeModal;
|
|
732
910
|
private redirectToInstantApp;
|
|
733
911
|
private redirectToAppClip;
|
|
912
|
+
/**
|
|
913
|
+
* Fetches the provider config that was used for this session and returns the hash requirements
|
|
914
|
+
*
|
|
915
|
+
* See also:
|
|
916
|
+
* * `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.
|
|
917
|
+
* * `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.
|
|
918
|
+
*
|
|
919
|
+
* @returns A promise that resolves to a ProviderHashRequirementsConfig
|
|
920
|
+
*/
|
|
921
|
+
getProviderHashRequirements(): Promise<ProviderHashRequirementsConfig>;
|
|
734
922
|
/**
|
|
735
923
|
* Starts the proof request session and monitors for proof submission
|
|
736
924
|
*
|
|
@@ -825,4 +1013,4 @@ declare function isDesktopDevice(): boolean;
|
|
|
825
1013
|
*/
|
|
826
1014
|
declare function clearDeviceCache(): void;
|
|
827
1015
|
|
|
828
|
-
export { type
|
|
1016
|
+
export { type Beacon, type BeaconState, ClaimCreationType, type ClaimID, type ClaimInfo, type CompleteClaimData, type Context, type CreateVerificationRequest, DeviceType, type ExtensionMessage, type HttpFormEntry, type HttpProviderClaimParams, type HttpRedirectionMethod, type HttpRedirectionOptions, type InitSessionResponse, type ModalOptions, type OnError, type OnSuccess, type Proof, type ProofPropertiesJSON, type ProofRequestOptions, type ProviderClaimData, type ProviderConfigResponse, type ProviderVersionConfig, RECLAIM_EXTENSION_ACTIONS, type ReclaimFlowLaunchOptions, ReclaimProofRequest, type ReclaimProviderConfig, type SerializableModalOptions, SessionStatus, type SignedClaim, type StartSessionParams, type StatusUrlResponse, type TemplateData, type UpdateSessionResponse, type WitnessData, clearDeviceCache, getDeviceType, getMobileDeviceType, isDesktopDevice, isMobileDevice, transformForOnchain, verifyProof };
|