@reclaimprotocol/js-sdk 5.1.0-dev.0 → 5.1.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 +43 -9
- package/dist/index.js +149 -113
- 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;
|
|
@@ -1282,7 +1316,7 @@ declare class ReclaimProofRequest {
|
|
|
1282
1316
|
* and the startSession function source for more details.
|
|
1283
1317
|
*
|
|
1284
1318
|
* > [!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.
|
|
1319
|
+
* > **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
1320
|
*
|
|
1287
1321
|
* @param onSuccess - Callback function invoked when proof is successfully submitted
|
|
1288
1322
|
* @param onError - Callback function invoked when an error occurs during the session
|
|
@@ -1482,4 +1516,4 @@ declare function isDesktopDevice(): boolean;
|
|
|
1482
1516
|
*/
|
|
1483
1517
|
declare function clearDeviceCache(): void;
|
|
1484
1518
|
|
|
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 };
|
|
1519
|
+
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, 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.1.0
|
|
87
|
+
version: "5.1.0",
|
|
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",
|
|
@@ -338,62 +338,6 @@ var logger_default = {
|
|
|
338
338
|
setLogLevel
|
|
339
339
|
};
|
|
340
340
|
|
|
341
|
-
// src/utils/helper.ts
|
|
342
|
-
var logger2 = logger_default.logger;
|
|
343
|
-
function escapeRegExp(string) {
|
|
344
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
345
|
-
}
|
|
346
|
-
function replaceAll(str, find, replace) {
|
|
347
|
-
if (find === "") return str;
|
|
348
|
-
return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
|
|
349
|
-
}
|
|
350
|
-
function scheduleIntervalEndingTask(sessionId, intervals, onFailureCallback, timeout = 1e3 * 60 * 10) {
|
|
351
|
-
setTimeout(() => {
|
|
352
|
-
if (intervals.has(sessionId)) {
|
|
353
|
-
const message = "Interval ended without receiving proofs";
|
|
354
|
-
onFailureCallback(new TimeoutError(message));
|
|
355
|
-
logger2.info(message);
|
|
356
|
-
clearInterval(intervals.get(sessionId));
|
|
357
|
-
intervals.delete(sessionId);
|
|
358
|
-
}
|
|
359
|
-
}, timeout);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// src/utils/constants.ts
|
|
363
|
-
var BACKEND_BASE_URL = "https://api.reclaimprotocol.org";
|
|
364
|
-
function setBackendBaseUrl(url) {
|
|
365
|
-
BACKEND_BASE_URL = url;
|
|
366
|
-
}
|
|
367
|
-
var constants = {
|
|
368
|
-
// Default callback URL for Reclaim protocol
|
|
369
|
-
get DEFAULT_RECLAIM_CALLBACK_URL() {
|
|
370
|
-
return `${BACKEND_BASE_URL}/api/sdk/callback?callbackId=`;
|
|
371
|
-
},
|
|
372
|
-
// Default error callback URL for Reclaim protocol
|
|
373
|
-
get DEFAULT_RECLAIM_CANCEL_CALLBACK_URL() {
|
|
374
|
-
return `${BACKEND_BASE_URL}/api/sdk/error-callback?callbackId=`;
|
|
375
|
-
},
|
|
376
|
-
// Default status URL for Reclaim sessions
|
|
377
|
-
get DEFAULT_RECLAIM_STATUS_URL() {
|
|
378
|
-
return `${BACKEND_BASE_URL}/api/sdk/session/`;
|
|
379
|
-
},
|
|
380
|
-
// Default attestors URL for Reclaim sessions
|
|
381
|
-
get DEFAULT_ATTESTORS_URL() {
|
|
382
|
-
return `${BACKEND_BASE_URL}/api/attestors`;
|
|
383
|
-
},
|
|
384
|
-
DEFAULT_PROVIDER_CONFIGS_URL(providerId, exactProviderVersionString, allowedTags) {
|
|
385
|
-
return `${BACKEND_BASE_URL}/api/providers/${providerId}/configs?versionNumber=${exactProviderVersionString || ""}&allowedTags=${(allowedTags == null ? void 0 : allowedTags.join(",")) || ""}`;
|
|
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",
|
|
391
|
-
// URL for sharing Reclaim templates
|
|
392
|
-
RECLAIM_SHARE_URL: "https://share.reclaimprotocol.org/verifier/?template=",
|
|
393
|
-
// Chrome extension URL for Reclaim Protocol
|
|
394
|
-
CHROME_EXTENSION_URL: "https://chromewebstore.google.com/detail/reclaim-extension/oafieibbbcepkmenknelhmgaoahamdeh"
|
|
395
|
-
};
|
|
396
|
-
|
|
397
341
|
// src/utils/validationUtils.ts
|
|
398
342
|
var import_ethers = require("ethers");
|
|
399
343
|
var import_canonicalize2 = __toESM(require("canonicalize"));
|
|
@@ -408,43 +352,43 @@ function canonicalStringify(params) {
|
|
|
408
352
|
}
|
|
409
353
|
|
|
410
354
|
// src/utils/validationUtils.ts
|
|
411
|
-
var
|
|
355
|
+
var logger2 = logger_default.logger;
|
|
412
356
|
function validateFunctionParams(params, functionName) {
|
|
413
357
|
params.forEach(({ input, paramName, isString }) => {
|
|
414
358
|
if (input == null) {
|
|
415
|
-
|
|
359
|
+
logger2.info(`Validation failed: ${paramName} in ${functionName} is null or undefined`);
|
|
416
360
|
throw new InvalidParamError(`${paramName} passed to ${functionName} must not be null or undefined.`);
|
|
417
361
|
}
|
|
418
362
|
if (isString && typeof input !== "string") {
|
|
419
|
-
|
|
363
|
+
logger2.info(`Validation failed: ${paramName} in ${functionName} is not a string`);
|
|
420
364
|
throw new InvalidParamError(`${paramName} passed to ${functionName} must be a string.`);
|
|
421
365
|
}
|
|
422
366
|
if (isString && input.trim() === "") {
|
|
423
|
-
|
|
367
|
+
logger2.info(`Validation failed: ${paramName} in ${functionName} is an empty string`);
|
|
424
368
|
throw new InvalidParamError(`${paramName} passed to ${functionName} must not be an empty string.`);
|
|
425
369
|
}
|
|
426
370
|
});
|
|
427
371
|
}
|
|
428
372
|
function validateFunctionParamsWithFn(param, functionName) {
|
|
429
373
|
if (!param.isValid()) {
|
|
430
|
-
|
|
374
|
+
logger2.info(`Validation failed: ${param.paramName} in ${functionName} is not valid`);
|
|
431
375
|
throw new InvalidParamError(`${param.paramName} passed to ${functionName} must be valid.`);
|
|
432
376
|
}
|
|
433
377
|
}
|
|
434
378
|
function validateParameters(parameters) {
|
|
435
379
|
try {
|
|
436
380
|
if (typeof parameters !== "object" || parameters === null) {
|
|
437
|
-
|
|
381
|
+
logger2.info(`Parameters validation failed: Provided parameters is not an object`);
|
|
438
382
|
throw new InavlidParametersError(`The provided parameters is not an object`);
|
|
439
383
|
}
|
|
440
384
|
for (const [key, value] of Object.entries(parameters)) {
|
|
441
385
|
if (typeof key !== "string" || typeof value !== "string") {
|
|
442
|
-
|
|
386
|
+
logger2.info(`Parameters validation failed: Provided parameters is not an object of key value pairs of string and string`);
|
|
443
387
|
throw new InavlidParametersError(`The provided parameters is not an object of key value pairs of string and string`);
|
|
444
388
|
}
|
|
445
389
|
}
|
|
446
390
|
} catch (e) {
|
|
447
|
-
|
|
391
|
+
logger2.info(`Parameters validation failed: ${e.message}`);
|
|
448
392
|
throw new InavlidParametersError(`Invalid parameters passed to validateParameters.`, e);
|
|
449
393
|
}
|
|
450
394
|
}
|
|
@@ -452,7 +396,7 @@ function validateURL(url, functionName) {
|
|
|
452
396
|
try {
|
|
453
397
|
new URL(url);
|
|
454
398
|
} catch (e) {
|
|
455
|
-
|
|
399
|
+
logger2.info(`URL validation failed for ${url} in ${functionName}: ${e.message}`);
|
|
456
400
|
throw new InvalidParamError(`Invalid URL format ${url} passed to ${functionName}.`, e);
|
|
457
401
|
}
|
|
458
402
|
}
|
|
@@ -465,7 +409,7 @@ function validateRedirectionMethod(method, functionName) {
|
|
|
465
409
|
throw new Error(`Invalid redirection method ${method} passed to ${functionName}.`);
|
|
466
410
|
}
|
|
467
411
|
} catch (e) {
|
|
468
|
-
|
|
412
|
+
logger2.info(`Redirection method validation failed for ${method} in ${functionName}: ${e.message}`);
|
|
469
413
|
throw new InvalidParamError(`Invalid redirection method ${method} passed to ${functionName}.`, e);
|
|
470
414
|
}
|
|
471
415
|
}
|
|
@@ -487,16 +431,16 @@ function validateRedirectionBody(records, functionName) {
|
|
|
487
431
|
throw new Error("Redirection body must be an array of objects with name, and value");
|
|
488
432
|
}
|
|
489
433
|
} catch (e) {
|
|
490
|
-
|
|
434
|
+
logger2.info(`Redirection body validation failed for ${records} in ${functionName}: ${e.message}`);
|
|
491
435
|
throw new InvalidParamError(`Invalid redirection body ${records} passed to ${functionName}.`, e);
|
|
492
436
|
}
|
|
493
437
|
}
|
|
494
438
|
function validateSignature(providerId, signature, applicationId, timestamp) {
|
|
495
439
|
try {
|
|
496
|
-
|
|
440
|
+
logger2.info(`Starting signature validation for providerId: ${providerId}, applicationId: ${applicationId}, timestamp: ${timestamp}`);
|
|
497
441
|
const message = (0, import_canonicalize2.default)({ providerId, timestamp });
|
|
498
442
|
if (!message) {
|
|
499
|
-
|
|
443
|
+
logger2.info("Failed to canonicalize message for signature validation");
|
|
500
444
|
throw new Error("Failed to canonicalize message");
|
|
501
445
|
}
|
|
502
446
|
const messageHash = import_ethers.ethers.keccak256(new TextEncoder().encode(message));
|
|
@@ -505,12 +449,12 @@ function validateSignature(providerId, signature, applicationId, timestamp) {
|
|
|
505
449
|
import_ethers.ethers.hexlify(signature)
|
|
506
450
|
).toLowerCase();
|
|
507
451
|
if (import_ethers.ethers.getAddress(appId) !== import_ethers.ethers.getAddress(applicationId)) {
|
|
508
|
-
|
|
452
|
+
logger2.info(`Signature validation failed: Mismatch between derived appId (${appId}) and provided applicationId (${applicationId})`);
|
|
509
453
|
throw new InvalidSignatureError(`Signature does not match the application id: ${appId}`);
|
|
510
454
|
}
|
|
511
|
-
|
|
455
|
+
logger2.info(`Signature validated successfully for applicationId: ${applicationId}`);
|
|
512
456
|
} catch (err) {
|
|
513
|
-
|
|
457
|
+
logger2.info(`Signature validation failed: ${err.message}`);
|
|
514
458
|
if (err instanceof InvalidSignatureError) {
|
|
515
459
|
throw err;
|
|
516
460
|
}
|
|
@@ -526,16 +470,16 @@ function validateContext(context) {
|
|
|
526
470
|
JSON.parse(canonicalStringify(context));
|
|
527
471
|
return;
|
|
528
472
|
} catch (e) {
|
|
529
|
-
|
|
473
|
+
logger2.info(`Context validation failed: Provided JSON serializable context is not valid`);
|
|
530
474
|
throw new InvalidParamError(`The provided context is not valid`);
|
|
531
475
|
}
|
|
532
476
|
}
|
|
533
477
|
if (!context.contextAddress) {
|
|
534
|
-
|
|
478
|
+
logger2.info(`Context validation failed: Provided context address in context is not valid`);
|
|
535
479
|
throw new InvalidParamError(`The provided context address in context is not valid`);
|
|
536
480
|
}
|
|
537
481
|
if (!context.contextMessage) {
|
|
538
|
-
|
|
482
|
+
logger2.info(`Context validation failed: Provided context message in context is not valid`);
|
|
539
483
|
throw new InvalidParamError(`The provided context message in context is not valid`);
|
|
540
484
|
}
|
|
541
485
|
validateFunctionParams([
|
|
@@ -585,6 +529,125 @@ function validateModalOptions(modalOptions, functionName, paramPrefix = "") {
|
|
|
585
529
|
], functionName);
|
|
586
530
|
}
|
|
587
531
|
}
|
|
532
|
+
function hashObject(o) {
|
|
533
|
+
try {
|
|
534
|
+
const canonicalData = canonicalStringify(o);
|
|
535
|
+
const messageHash = import_ethers.ethers.keccak256(new TextEncoder().encode(canonicalData));
|
|
536
|
+
return messageHash;
|
|
537
|
+
} catch (e) {
|
|
538
|
+
logger2.info(`Failed to hash object: ${e.message}`);
|
|
539
|
+
throw new Error(`Failed to hash object: ${e.message}`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/utils/helper.ts
|
|
544
|
+
var logger3 = logger_default.logger;
|
|
545
|
+
function escapeRegExp(string) {
|
|
546
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
547
|
+
}
|
|
548
|
+
function replaceAll(str, find, replace) {
|
|
549
|
+
if (find === "") return str;
|
|
550
|
+
return str.replace(new RegExp(escapeRegExp(find), "g"), replace);
|
|
551
|
+
}
|
|
552
|
+
function scheduleIntervalEndingTask(sessionId, intervals, onFailureCallback, timeout = 1e3 * 60 * 10) {
|
|
553
|
+
setTimeout(() => {
|
|
554
|
+
if (intervals.has(sessionId)) {
|
|
555
|
+
const message = "Interval ended without receiving proofs";
|
|
556
|
+
onFailureCallback(new TimeoutError(message));
|
|
557
|
+
logger3.info(message);
|
|
558
|
+
clearInterval(intervals.get(sessionId));
|
|
559
|
+
intervals.delete(sessionId);
|
|
560
|
+
}
|
|
561
|
+
}, timeout);
|
|
562
|
+
}
|
|
563
|
+
var createVerifyProofResultSuccess = (proofs, isTeeVerified) => {
|
|
564
|
+
return {
|
|
565
|
+
isVerified: true,
|
|
566
|
+
isTeeVerified,
|
|
567
|
+
error: void 0,
|
|
568
|
+
data: proofs.map(createTrustedDataFromProofData),
|
|
569
|
+
publicData: getPublicDataFromProofs(proofs)
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
var createVerifyProofResultFailure = (error, isTeeVerified) => {
|
|
573
|
+
return {
|
|
574
|
+
isVerified: false,
|
|
575
|
+
isTeeVerified,
|
|
576
|
+
error,
|
|
577
|
+
data: [],
|
|
578
|
+
publicData: []
|
|
579
|
+
};
|
|
580
|
+
};
|
|
581
|
+
function createTrustedDataFromProofData(proof) {
|
|
582
|
+
try {
|
|
583
|
+
const context = JSON.parse(proof.claimData.context);
|
|
584
|
+
const _a = context, { extractedParameters } = _a, rest = __objRest(_a, ["extractedParameters"]);
|
|
585
|
+
return {
|
|
586
|
+
context: rest,
|
|
587
|
+
extractedParameters: extractedParameters != null ? extractedParameters : {}
|
|
588
|
+
};
|
|
589
|
+
} catch (e) {
|
|
590
|
+
return {
|
|
591
|
+
context: {},
|
|
592
|
+
extractedParameters: {}
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function getPublicDataFromProofs(proofs) {
|
|
597
|
+
const data = [];
|
|
598
|
+
const seenData = /* @__PURE__ */ new Set();
|
|
599
|
+
for (const proof of proofs) {
|
|
600
|
+
const publicData = proof.publicData;
|
|
601
|
+
if (publicData === null || publicData === void 0) {
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
try {
|
|
605
|
+
const hash = hashObject(publicData);
|
|
606
|
+
if (seenData.has(hash)) {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
seenData.add(hash);
|
|
610
|
+
} catch (_) {
|
|
611
|
+
}
|
|
612
|
+
data.push(publicData);
|
|
613
|
+
}
|
|
614
|
+
return data;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/utils/constants.ts
|
|
618
|
+
var BACKEND_BASE_URL = "https://api.reclaimprotocol.org";
|
|
619
|
+
function setBackendBaseUrl(url) {
|
|
620
|
+
BACKEND_BASE_URL = url;
|
|
621
|
+
}
|
|
622
|
+
var constants = {
|
|
623
|
+
// Default callback URL for Reclaim protocol
|
|
624
|
+
get DEFAULT_RECLAIM_CALLBACK_URL() {
|
|
625
|
+
return `${BACKEND_BASE_URL}/api/sdk/callback?callbackId=`;
|
|
626
|
+
},
|
|
627
|
+
// Default error callback URL for Reclaim protocol
|
|
628
|
+
get DEFAULT_RECLAIM_CANCEL_CALLBACK_URL() {
|
|
629
|
+
return `${BACKEND_BASE_URL}/api/sdk/error-callback?callbackId=`;
|
|
630
|
+
},
|
|
631
|
+
// Default status URL for Reclaim sessions
|
|
632
|
+
get DEFAULT_RECLAIM_STATUS_URL() {
|
|
633
|
+
return `${BACKEND_BASE_URL}/api/sdk/session/`;
|
|
634
|
+
},
|
|
635
|
+
// Default attestors URL for Reclaim sessions
|
|
636
|
+
get DEFAULT_ATTESTORS_URL() {
|
|
637
|
+
return `${BACKEND_BASE_URL}/api/attestors`;
|
|
638
|
+
},
|
|
639
|
+
DEFAULT_PROVIDER_CONFIGS_URL(providerId, exactProviderVersionString, allowedTags) {
|
|
640
|
+
return `${BACKEND_BASE_URL}/api/providers/${providerId}/configs?versionNumber=${exactProviderVersionString || ""}&allowedTags=${(allowedTags == null ? void 0 : allowedTags.join(",")) || ""}`;
|
|
641
|
+
},
|
|
642
|
+
// Default portal URL
|
|
643
|
+
DEFAULT_PORTAL_URL: "https://portal.reclaimprotocol.org",
|
|
644
|
+
// Default sharepage URL
|
|
645
|
+
DEFAULT_APP_SHARE_PAGE_URL: "https://share.reclaimprotocol.org/verifier",
|
|
646
|
+
// URL for sharing Reclaim templates
|
|
647
|
+
RECLAIM_SHARE_URL: "https://share.reclaimprotocol.org/verifier/?template=",
|
|
648
|
+
// Chrome extension URL for Reclaim Protocol
|
|
649
|
+
CHROME_EXTENSION_URL: "https://chromewebstore.google.com/detail/reclaim-extension/oafieibbbcepkmenknelhmgaoahamdeh"
|
|
650
|
+
};
|
|
588
651
|
|
|
589
652
|
// src/utils/fetch.ts
|
|
590
653
|
var import_fetch_retry = __toESM(require("fetch-retry"));
|
|
@@ -2350,63 +2413,36 @@ function verifyProof(proofOrProofs, config) {
|
|
|
2350
2413
|
yield assertVerifiedProof(proof, attestors);
|
|
2351
2414
|
}
|
|
2352
2415
|
yield assertValidateProof(proofs, config);
|
|
2353
|
-
|
|
2354
|
-
isVerified: true,
|
|
2355
|
-
data: proofs.map(extractProofData)
|
|
2356
|
-
};
|
|
2416
|
+
let isTeeVerified = void 0;
|
|
2357
2417
|
if (config.verifyTEE) {
|
|
2358
2418
|
const hasTeeData = proofs.every((proof) => proof.teeAttestation || JSON.parse(proof.claimData.context).attestationNonce);
|
|
2359
2419
|
if (!hasTeeData) {
|
|
2360
2420
|
const teeError = new TeeVerificationError("TEE verification requested but one or more proofs are missing TEE attestation data");
|
|
2361
2421
|
logger10.error(teeError.message);
|
|
2362
|
-
|
|
2363
|
-
result.isVerified = false;
|
|
2364
|
-
result.error = teeError;
|
|
2365
|
-
return result;
|
|
2422
|
+
return createVerifyProofResultFailure(teeError, false);
|
|
2366
2423
|
}
|
|
2367
2424
|
try {
|
|
2368
2425
|
const teeResults = yield Promise.all(proofs.map((proof) => verifyTeeAttestation(proof)));
|
|
2369
|
-
|
|
2370
|
-
if (!
|
|
2426
|
+
isTeeVerified = teeResults.every((r) => r === true);
|
|
2427
|
+
if (!isTeeVerified) {
|
|
2371
2428
|
const teeError = new TeeVerificationError("TEE attestation verification failed for one or more proofs");
|
|
2372
2429
|
logger10.error(teeError.message);
|
|
2373
|
-
|
|
2374
|
-
result.error = teeError;
|
|
2430
|
+
return createVerifyProofResultFailure(teeError, false);
|
|
2375
2431
|
}
|
|
2376
2432
|
} catch (error) {
|
|
2377
2433
|
const teeError = new TeeVerificationError("Error verifying TEE attestation", error);
|
|
2378
2434
|
logger10.error(teeError.message);
|
|
2379
|
-
|
|
2380
|
-
result.isVerified = false;
|
|
2381
|
-
result.error = teeError;
|
|
2435
|
+
return createVerifyProofResultFailure(teeError, false);
|
|
2382
2436
|
}
|
|
2383
2437
|
}
|
|
2384
|
-
return
|
|
2438
|
+
return createVerifyProofResultSuccess(proofs, isTeeVerified);
|
|
2385
2439
|
} catch (error) {
|
|
2386
2440
|
logger10.error("Error in validating proof:", error);
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
data: [],
|
|
2390
|
-
error: error instanceof Error ? error : new Error(String(error))
|
|
2391
|
-
};
|
|
2441
|
+
const _error = error instanceof Error ? error : new Error(String(error));
|
|
2442
|
+
return createVerifyProofResultFailure(_error);
|
|
2392
2443
|
}
|
|
2393
2444
|
});
|
|
2394
2445
|
}
|
|
2395
|
-
function extractProofData(proof) {
|
|
2396
|
-
try {
|
|
2397
|
-
const context = JSON.parse(proof.claimData.context);
|
|
2398
|
-
const _a = context, { extractedParameters } = _a, rest = __objRest(_a, ["extractedParameters"]);
|
|
2399
|
-
return {
|
|
2400
|
-
context: rest,
|
|
2401
|
-
extractedParameters: extractedParameters != null ? extractedParameters : {}
|
|
2402
|
-
};
|
|
2403
|
-
} catch (e) {
|
|
2404
|
-
return {
|
|
2405
|
-
context: {},
|
|
2406
|
-
extractedParameters: {}
|
|
2407
|
-
};
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
2446
|
function transformForOnchain(proof) {
|
|
2411
2447
|
const claimInfoBuilder = /* @__PURE__ */ new Map([
|
|
2412
2448
|
["context", proof.claimData.context],
|
|
@@ -3715,7 +3751,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3715
3751
|
* and the startSession function source for more details.
|
|
3716
3752
|
*
|
|
3717
3753
|
* > [!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.
|
|
3754
|
+
* > **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
3755
|
*
|
|
3720
3756
|
* @param onSuccess - Callback function invoked when proof is successfully submitted
|
|
3721
3757
|
* @param onError - Callback function invoked when an error occurs during the session
|