@reclaimprotocol/js-sdk 5.1.0-dev.0 → 5.1.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 +45 -9
- package/dist/index.js +73 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ interface Proof {
|
|
|
12
12
|
signatures: string[];
|
|
13
13
|
witnesses: WitnessData[];
|
|
14
14
|
extractedParameterValues: any;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/**
|
|
16
|
+
* A JSON serializable object that is returned by the provider as additional data attached to proof.
|
|
17
|
+
* This data is not verified or validated.
|
|
18
|
+
*/
|
|
19
|
+
publicData?: any;
|
|
18
20
|
taskId?: number;
|
|
19
21
|
teeAttestation?: TeeAttestation;
|
|
20
22
|
}
|
|
@@ -388,11 +390,34 @@ type CreateVerificationRequest = {
|
|
|
388
390
|
applicationSecret?: string;
|
|
389
391
|
};
|
|
390
392
|
type StartSessionParams = {
|
|
393
|
+
/**
|
|
394
|
+
* Callback function that is invoked when the session is successfully created.
|
|
395
|
+
*
|
|
396
|
+
* @param proofOrProofs - A single proof object or an array of proof objects. This can be empty when proofs are sent to callback.
|
|
397
|
+
*/
|
|
391
398
|
onSuccess: OnSuccess;
|
|
399
|
+
/**
|
|
400
|
+
* Callback function that is invoked when the session fails to be created.
|
|
401
|
+
*
|
|
402
|
+
* @param error - The error that caused the session to fail.
|
|
403
|
+
*/
|
|
392
404
|
onError: OnError;
|
|
405
|
+
/**
|
|
406
|
+
* Configuration for proof validation. Defaults to the provider id and version used in this session.
|
|
407
|
+
*/
|
|
393
408
|
verificationConfig?: VerificationConfig;
|
|
394
409
|
};
|
|
395
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Callback function that is invoked when the session is successfully created.
|
|
412
|
+
*
|
|
413
|
+
* @param proofOrProofs - A single proof object or an array of proof objects. This can be empty when proofs are sent to callback.
|
|
414
|
+
*/
|
|
415
|
+
type OnSuccess = (proofOrProofs: Proof | Proof[]) => void;
|
|
416
|
+
/**
|
|
417
|
+
* Callback function that is invoked when the session fails to be created.
|
|
418
|
+
*
|
|
419
|
+
* @param error - The error that caused the session to fail.
|
|
420
|
+
*/
|
|
396
421
|
type OnError = (error: Error) => void;
|
|
397
422
|
type ProofRequestOptions = {
|
|
398
423
|
/**
|
|
@@ -645,12 +670,21 @@ type TrustedData = {
|
|
|
645
670
|
context: Record<string, unknown>;
|
|
646
671
|
extractedParameters: Record<string, string>;
|
|
647
672
|
};
|
|
648
|
-
type
|
|
649
|
-
isVerified:
|
|
673
|
+
type VerifyProofResultSuccess = {
|
|
674
|
+
isVerified: true;
|
|
650
675
|
isTeeVerified?: boolean;
|
|
676
|
+
error: undefined;
|
|
651
677
|
data: TrustedData[];
|
|
652
|
-
|
|
678
|
+
publicData: any[];
|
|
679
|
+
};
|
|
680
|
+
type VerifyProofResultFailure = {
|
|
681
|
+
isVerified: false;
|
|
682
|
+
isTeeVerified?: boolean;
|
|
683
|
+
error: Error;
|
|
684
|
+
data: [];
|
|
685
|
+
publicData: [];
|
|
653
686
|
};
|
|
687
|
+
type VerifyProofResult = VerifyProofResultSuccess | VerifyProofResultFailure;
|
|
654
688
|
type ProviderVersionConfig = {
|
|
655
689
|
major?: number;
|
|
656
690
|
minor?: number;
|
|
@@ -757,6 +791,8 @@ type ProviderHashRequirementsResponse = {
|
|
|
757
791
|
* ```
|
|
758
792
|
*/
|
|
759
793
|
declare function verifyProof(proofOrProofs: Proof | Proof[], config: VerificationConfig): Promise<VerifyProofResult>;
|
|
794
|
+
declare function createTrustedDataFromProofData(proof: Proof): TrustedData;
|
|
795
|
+
declare function getPublicDataFromProofs(proofs: Proof[]): any[];
|
|
760
796
|
/**
|
|
761
797
|
* Transforms a Reclaim proof into a format suitable for on-chain verification
|
|
762
798
|
*
|
|
@@ -1282,7 +1318,7 @@ declare class ReclaimProofRequest {
|
|
|
1282
1318
|
* and the startSession function source for more details.
|
|
1283
1319
|
*
|
|
1284
1320
|
* > [!TIP]
|
|
1285
|
-
* > **Best Practice:** When using `setAppCallbackUrl` and/or `setCancelCallbackUrl`, your backend receives the proof or cancellation details directly. We recommend your backend notifies the frontend (e.g. via WebSockets, SSE, or polling) to stop the verification process and handle the appropriate success/failure action.
|
|
1321
|
+
* > **Best Practice:** When using `setAppCallbackUrl` and/or `setCancelCallbackUrl`, your backend receives the proof or cancellation details directly. We recommend your backend notifies the frontend (e.g. via WebSockets, SSE, or polling) to stop the verification process and handle the appropriate success/failure action. When a callback is set, `onSuccess` callback provided to `startSession` will have an empty array as its argument.
|
|
1286
1322
|
*
|
|
1287
1323
|
* @param onSuccess - Callback function invoked when proof is successfully submitted
|
|
1288
1324
|
* @param onError - Callback function invoked when an error occurs during the session
|
|
@@ -1482,4 +1518,4 @@ declare function isDesktopDevice(): boolean;
|
|
|
1482
1518
|
*/
|
|
1483
1519
|
declare function clearDeviceCache(): void;
|
|
1484
1520
|
|
|
1485
|
-
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 };
|
|
1521
|
+
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 VerifyProofResultFailure, type VerifyProofResultSuccess, type WitnessData, assertValidProofsByHash, assertValidateProof, assertVerifiedProof, clearDeviceCache, createLinkWithTemplateData, createSignDataForClaim, createTrustedDataFromProofData, fetchProviderConfigs, fetchProviderHashRequirementsBy, fetchStatusUrl, generateSpecsFromRequestSpecTemplate, getAttestors, getDeviceType, getHttpProviderClaimParamsFromProof, getIdentifierFromClaimInfo, getMobileDeviceType, getProviderHashRequirementSpecFromProviderConfig, getProviderHashRequirementsFromSpec, getProviderParamsAsCanonicalizedString, getPublicDataFromProofs, 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.1.0-dev.
|
|
87
|
+
version: "5.1.0-dev.1",
|
|
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",
|
|
@@ -200,6 +200,7 @@ __export(index_exports, {
|
|
|
200
200
|
clearDeviceCache: () => clearDeviceCache,
|
|
201
201
|
createLinkWithTemplateData: () => createLinkWithTemplateData,
|
|
202
202
|
createSignDataForClaim: () => createSignDataForClaim,
|
|
203
|
+
createTrustedDataFromProofData: () => createTrustedDataFromProofData,
|
|
203
204
|
fetchProviderConfigs: () => fetchProviderConfigs,
|
|
204
205
|
fetchProviderHashRequirementsBy: () => fetchProviderHashRequirementsBy,
|
|
205
206
|
fetchStatusUrl: () => fetchStatusUrl,
|
|
@@ -212,6 +213,7 @@ __export(index_exports, {
|
|
|
212
213
|
getProviderHashRequirementSpecFromProviderConfig: () => getProviderHashRequirementSpecFromProviderConfig,
|
|
213
214
|
getProviderHashRequirementsFromSpec: () => getProviderHashRequirementsFromSpec,
|
|
214
215
|
getProviderParamsAsCanonicalizedString: () => getProviderParamsAsCanonicalizedString,
|
|
216
|
+
getPublicDataFromProofs: () => getPublicDataFromProofs,
|
|
215
217
|
getShortenedUrl: () => getShortenedUrl,
|
|
216
218
|
hashProofClaimParams: () => hashProofClaimParams,
|
|
217
219
|
hashRequestSpec: () => hashRequestSpec,
|
|
@@ -585,6 +587,16 @@ function validateModalOptions(modalOptions, functionName, paramPrefix = "") {
|
|
|
585
587
|
], functionName);
|
|
586
588
|
}
|
|
587
589
|
}
|
|
590
|
+
function hashObject(o) {
|
|
591
|
+
try {
|
|
592
|
+
const canonicalData = canonicalStringify(o);
|
|
593
|
+
const messageHash = import_ethers.ethers.keccak256(new TextEncoder().encode(canonicalData));
|
|
594
|
+
return messageHash;
|
|
595
|
+
} catch (e) {
|
|
596
|
+
logger3.info(`Failed to hash object: ${e.message}`);
|
|
597
|
+
throw new Error(`Failed to hash object: ${e.message}`);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
588
600
|
|
|
589
601
|
// src/utils/fetch.ts
|
|
590
602
|
var import_fetch_retry = __toESM(require("fetch-retry"));
|
|
@@ -2350,49 +2362,69 @@ function verifyProof(proofOrProofs, config) {
|
|
|
2350
2362
|
yield assertVerifiedProof(proof, attestors);
|
|
2351
2363
|
}
|
|
2352
2364
|
yield assertValidateProof(proofs, config);
|
|
2353
|
-
|
|
2354
|
-
isVerified: true,
|
|
2355
|
-
data: proofs.map(extractProofData)
|
|
2356
|
-
};
|
|
2365
|
+
let isTeeVerified = void 0;
|
|
2357
2366
|
if (config.verifyTEE) {
|
|
2358
2367
|
const hasTeeData = proofs.every((proof) => proof.teeAttestation || JSON.parse(proof.claimData.context).attestationNonce);
|
|
2359
2368
|
if (!hasTeeData) {
|
|
2360
2369
|
const teeError = new TeeVerificationError("TEE verification requested but one or more proofs are missing TEE attestation data");
|
|
2361
2370
|
logger10.error(teeError.message);
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2371
|
+
const errorResult = {
|
|
2372
|
+
isVerified: false,
|
|
2373
|
+
isTeeVerified: false,
|
|
2374
|
+
error: teeError,
|
|
2375
|
+
data: [],
|
|
2376
|
+
publicData: []
|
|
2377
|
+
};
|
|
2378
|
+
return errorResult;
|
|
2366
2379
|
}
|
|
2367
2380
|
try {
|
|
2368
2381
|
const teeResults = yield Promise.all(proofs.map((proof) => verifyTeeAttestation(proof)));
|
|
2369
|
-
|
|
2370
|
-
if (!
|
|
2382
|
+
isTeeVerified = teeResults.every((r) => r === true);
|
|
2383
|
+
if (!isTeeVerified) {
|
|
2371
2384
|
const teeError = new TeeVerificationError("TEE attestation verification failed for one or more proofs");
|
|
2372
2385
|
logger10.error(teeError.message);
|
|
2373
|
-
|
|
2374
|
-
|
|
2386
|
+
const errorResult = {
|
|
2387
|
+
isVerified: false,
|
|
2388
|
+
isTeeVerified: false,
|
|
2389
|
+
error: teeError,
|
|
2390
|
+
data: [],
|
|
2391
|
+
publicData: []
|
|
2392
|
+
};
|
|
2393
|
+
return errorResult;
|
|
2375
2394
|
}
|
|
2376
2395
|
} catch (error) {
|
|
2377
2396
|
const teeError = new TeeVerificationError("Error verifying TEE attestation", error);
|
|
2378
2397
|
logger10.error(teeError.message);
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2398
|
+
const errorResult = {
|
|
2399
|
+
isVerified: false,
|
|
2400
|
+
isTeeVerified: false,
|
|
2401
|
+
error: teeError,
|
|
2402
|
+
data: [],
|
|
2403
|
+
publicData: []
|
|
2404
|
+
};
|
|
2405
|
+
return errorResult;
|
|
2382
2406
|
}
|
|
2383
2407
|
}
|
|
2408
|
+
const result = {
|
|
2409
|
+
isVerified: true,
|
|
2410
|
+
isTeeVerified,
|
|
2411
|
+
data: proofs.map(createTrustedDataFromProofData),
|
|
2412
|
+
publicData: getPublicDataFromProofs(proofs),
|
|
2413
|
+
error: void 0
|
|
2414
|
+
};
|
|
2384
2415
|
return result;
|
|
2385
2416
|
} catch (error) {
|
|
2386
2417
|
logger10.error("Error in validating proof:", error);
|
|
2387
2418
|
return {
|
|
2388
2419
|
isVerified: false,
|
|
2420
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
2389
2421
|
data: [],
|
|
2390
|
-
|
|
2422
|
+
publicData: []
|
|
2391
2423
|
};
|
|
2392
2424
|
}
|
|
2393
2425
|
});
|
|
2394
2426
|
}
|
|
2395
|
-
function
|
|
2427
|
+
function createTrustedDataFromProofData(proof) {
|
|
2396
2428
|
try {
|
|
2397
2429
|
const context = JSON.parse(proof.claimData.context);
|
|
2398
2430
|
const _a = context, { extractedParameters } = _a, rest = __objRest(_a, ["extractedParameters"]);
|
|
@@ -2407,6 +2439,26 @@ function extractProofData(proof) {
|
|
|
2407
2439
|
};
|
|
2408
2440
|
}
|
|
2409
2441
|
}
|
|
2442
|
+
function getPublicDataFromProofs(proofs) {
|
|
2443
|
+
const data = [];
|
|
2444
|
+
const seenData = /* @__PURE__ */ new Set();
|
|
2445
|
+
for (const proof of proofs) {
|
|
2446
|
+
const publicData = proof.publicData;
|
|
2447
|
+
if (publicData === null || publicData === void 0) {
|
|
2448
|
+
continue;
|
|
2449
|
+
}
|
|
2450
|
+
try {
|
|
2451
|
+
const hash = hashObject(publicData);
|
|
2452
|
+
if (seenData.has(hash)) {
|
|
2453
|
+
continue;
|
|
2454
|
+
}
|
|
2455
|
+
seenData.add(hash);
|
|
2456
|
+
} catch (_) {
|
|
2457
|
+
}
|
|
2458
|
+
data.push(publicData);
|
|
2459
|
+
}
|
|
2460
|
+
return data;
|
|
2461
|
+
}
|
|
2410
2462
|
function transformForOnchain(proof) {
|
|
2411
2463
|
const claimInfoBuilder = /* @__PURE__ */ new Map([
|
|
2412
2464
|
["context", proof.claimData.context],
|
|
@@ -3715,7 +3767,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3715
3767
|
* and the startSession function source for more details.
|
|
3716
3768
|
*
|
|
3717
3769
|
* > [!TIP]
|
|
3718
|
-
* > **Best Practice:** When using `setAppCallbackUrl` and/or `setCancelCallbackUrl`, your backend receives the proof or cancellation details directly. We recommend your backend notifies the frontend (e.g. via WebSockets, SSE, or polling) to stop the verification process and handle the appropriate success/failure action.
|
|
3770
|
+
* > **Best Practice:** When using `setAppCallbackUrl` and/or `setCancelCallbackUrl`, your backend receives the proof or cancellation details directly. We recommend your backend notifies the frontend (e.g. via WebSockets, SSE, or polling) to stop the verification process and handle the appropriate success/failure action. When a callback is set, `onSuccess` callback provided to `startSession` will have an empty array as its argument.
|
|
3719
3771
|
*
|
|
3720
3772
|
* @param onSuccess - Callback function invoked when proof is successfully submitted
|
|
3721
3773
|
* @param onError - Callback function invoked when an error occurs during the session
|
|
@@ -3861,6 +3913,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3861
3913
|
clearDeviceCache,
|
|
3862
3914
|
createLinkWithTemplateData,
|
|
3863
3915
|
createSignDataForClaim,
|
|
3916
|
+
createTrustedDataFromProofData,
|
|
3864
3917
|
fetchProviderConfigs,
|
|
3865
3918
|
fetchProviderHashRequirementsBy,
|
|
3866
3919
|
fetchStatusUrl,
|
|
@@ -3873,6 +3926,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3873
3926
|
getProviderHashRequirementSpecFromProviderConfig,
|
|
3874
3927
|
getProviderHashRequirementsFromSpec,
|
|
3875
3928
|
getProviderParamsAsCanonicalizedString,
|
|
3929
|
+
getPublicDataFromProofs,
|
|
3876
3930
|
getShortenedUrl,
|
|
3877
3931
|
hashProofClaimParams,
|
|
3878
3932
|
hashRequestSpec,
|