@reclaimprotocol/js-sdk 5.0.0-dev.2 → 5.0.0-dev.4
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/README.md +82 -41
- package/dist/index.d.ts +229 -104
- package/dist/index.js +186 -83
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.
|
|
87
|
+
version: "5.0.0-dev.4",
|
|
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",
|
|
@@ -193,11 +193,13 @@ var require_package = __commonJS({
|
|
|
193
193
|
var index_exports = {};
|
|
194
194
|
__export(index_exports, {
|
|
195
195
|
ReclaimProofRequest: () => ReclaimProofRequest,
|
|
196
|
+
TeeVerificationError: () => TeeVerificationError,
|
|
196
197
|
assertValidProofsByHash: () => assertValidProofsByHash,
|
|
197
198
|
assertValidateProof: () => assertValidateProof,
|
|
198
199
|
assertVerifiedProof: () => assertVerifiedProof,
|
|
199
200
|
clearDeviceCache: () => clearDeviceCache,
|
|
200
201
|
createLinkWithTemplateData: () => createLinkWithTemplateData,
|
|
202
|
+
createSignDataForClaim: () => createSignDataForClaim,
|
|
201
203
|
fetchProviderConfigs: () => fetchProviderConfigs,
|
|
202
204
|
fetchProviderHashRequirementsBy: () => fetchProviderHashRequirementsBy,
|
|
203
205
|
fetchStatusUrl: () => fetchStatusUrl,
|
|
@@ -205,9 +207,13 @@ __export(index_exports, {
|
|
|
205
207
|
getAttestors: () => getAttestors,
|
|
206
208
|
getDeviceType: () => getDeviceType,
|
|
207
209
|
getHttpProviderClaimParamsFromProof: () => getHttpProviderClaimParamsFromProof,
|
|
210
|
+
getIdentifierFromClaimInfo: () => getIdentifierFromClaimInfo,
|
|
208
211
|
getMobileDeviceType: () => getMobileDeviceType,
|
|
212
|
+
getProviderHashRequirementSpecFromProviderConfig: () => getProviderHashRequirementSpecFromProviderConfig,
|
|
209
213
|
getProviderHashRequirementsFromSpec: () => getProviderHashRequirementsFromSpec,
|
|
214
|
+
getProviderParamsAsCanonicalizedString: () => getProviderParamsAsCanonicalizedString,
|
|
210
215
|
getShortenedUrl: () => getShortenedUrl,
|
|
216
|
+
hashProofClaimParams: () => hashProofClaimParams,
|
|
211
217
|
hashRequestSpec: () => hashRequestSpec,
|
|
212
218
|
initSession: () => initSession,
|
|
213
219
|
isDesktopDevice: () => isDesktopDevice,
|
|
@@ -279,6 +285,7 @@ var InavlidParametersError = createErrorClass("InavlidParametersError");
|
|
|
279
285
|
var ProofSubmissionFailedError = createErrorClass("ProofSubmissionFailedError");
|
|
280
286
|
var ErrorDuringVerificationError = createErrorClass("ErrorDuringVerificationError");
|
|
281
287
|
var CallbackUrlRequiredError = createErrorClass("CallbackUrlRequiredError");
|
|
288
|
+
var TeeVerificationError = createErrorClass("TeeVerificationError");
|
|
282
289
|
|
|
283
290
|
// src/utils/logger.ts
|
|
284
291
|
var SimpleLogger = class {
|
|
@@ -836,9 +843,9 @@ function getProviderParamsAsCanonicalizedString(params) {
|
|
|
836
843
|
responseMatches: [],
|
|
837
844
|
responseRedactions: []
|
|
838
845
|
};
|
|
839
|
-
return canonicalStringify(filteredParams);
|
|
846
|
+
return [canonicalStringify(filteredParams)];
|
|
840
847
|
}
|
|
841
|
-
return validCanonicalizedStrings
|
|
848
|
+
return validCanonicalizedStrings;
|
|
842
849
|
}
|
|
843
850
|
|
|
844
851
|
// src/utils/proofUtils.ts
|
|
@@ -855,7 +862,7 @@ function getShortenedUrl(url) {
|
|
|
855
862
|
});
|
|
856
863
|
const res = yield response.json();
|
|
857
864
|
if (!response.ok) {
|
|
858
|
-
logger5.info(`Failed to shorten URL:
|
|
865
|
+
logger5.info(`Failed to shorten URL: status=${response.status}`);
|
|
859
866
|
return url;
|
|
860
867
|
}
|
|
861
868
|
const shortenedVerificationUrl = res.result.shortUrl;
|
|
@@ -1376,7 +1383,6 @@ function clearDeviceCache() {
|
|
|
1376
1383
|
var logger7 = logger_default.logger;
|
|
1377
1384
|
function fetchProviderHashRequirementsBy(providerId, exactProviderVersionString, allowedTags, proofs) {
|
|
1378
1385
|
return __async(this, null, function* () {
|
|
1379
|
-
var _a, _b;
|
|
1380
1386
|
const providerResponse = yield fetchProviderConfigs(providerId, exactProviderVersionString, allowedTags);
|
|
1381
1387
|
try {
|
|
1382
1388
|
const providerConfigs = providerResponse.providers;
|
|
@@ -1385,9 +1391,8 @@ function fetchProviderHashRequirementsBy(providerId, exactProviderVersionString,
|
|
|
1385
1391
|
}
|
|
1386
1392
|
const hashRequirements = [];
|
|
1387
1393
|
for (const providerConfig of providerConfigs) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
}));
|
|
1394
|
+
const requestSpec = getProviderHashRequirementSpecFromProviderConfig(providerConfig, proofs);
|
|
1395
|
+
hashRequirements.push(getProviderHashRequirementsFromSpec(requestSpec));
|
|
1391
1396
|
}
|
|
1392
1397
|
return hashRequirements;
|
|
1393
1398
|
} catch (e) {
|
|
@@ -1467,6 +1472,12 @@ function takePairsWhereValueIsArray(o) {
|
|
|
1467
1472
|
}
|
|
1468
1473
|
return pairs;
|
|
1469
1474
|
}
|
|
1475
|
+
function getProviderHashRequirementSpecFromProviderConfig(providerConfig, proofs) {
|
|
1476
|
+
var _a, _b;
|
|
1477
|
+
return {
|
|
1478
|
+
requests: [...(_a = providerConfig == null ? void 0 : providerConfig.requestData) != null ? _a : [], ...generateSpecsFromRequestSpecTemplate((_b = providerConfig == null ? void 0 : providerConfig.allowedInjectedRequestData) != null ? _b : [], takeTemplateParametersFromProofs(proofs))]
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1470
1481
|
function getProviderHashRequirementsFromSpec(spec) {
|
|
1471
1482
|
var _a;
|
|
1472
1483
|
return {
|
|
@@ -2320,7 +2331,7 @@ Got: ${report.reportData}`);
|
|
|
2320
2331
|
// src/Reclaim.ts
|
|
2321
2332
|
var logger10 = logger_default.logger;
|
|
2322
2333
|
var sdkVersion = require_package().version;
|
|
2323
|
-
function verifyProof(proofOrProofs, config
|
|
2334
|
+
function verifyProof(proofOrProofs, config) {
|
|
2324
2335
|
return __async(this, null, function* () {
|
|
2325
2336
|
const proofs = Array.isArray(proofOrProofs) ? proofOrProofs : [proofOrProofs];
|
|
2326
2337
|
try {
|
|
@@ -2339,25 +2350,31 @@ function verifyProof(proofOrProofs, config, verifyTEE) {
|
|
|
2339
2350
|
isVerified: true,
|
|
2340
2351
|
data: proofs.map(extractProofData)
|
|
2341
2352
|
};
|
|
2342
|
-
if (verifyTEE) {
|
|
2353
|
+
if (config.verifyTEE) {
|
|
2343
2354
|
const hasTeeData = proofs.every((proof) => proof.teeAttestation || JSON.parse(proof.claimData.context).attestationNonce);
|
|
2344
2355
|
if (!hasTeeData) {
|
|
2345
|
-
|
|
2356
|
+
const teeError = new TeeVerificationError("TEE verification requested but one or more proofs are missing TEE attestation data");
|
|
2357
|
+
logger10.error(teeError.message);
|
|
2346
2358
|
result.isTeeVerified = false;
|
|
2347
2359
|
result.isVerified = false;
|
|
2360
|
+
result.error = teeError;
|
|
2348
2361
|
return result;
|
|
2349
2362
|
}
|
|
2350
2363
|
try {
|
|
2351
2364
|
const teeResults = yield Promise.all(proofs.map((proof) => verifyTeeAttestation(proof)));
|
|
2352
2365
|
result.isTeeVerified = teeResults.every((r) => r === true);
|
|
2353
2366
|
if (!result.isTeeVerified) {
|
|
2354
|
-
|
|
2367
|
+
const teeError = new TeeVerificationError("TEE attestation verification failed for one or more proofs");
|
|
2368
|
+
logger10.error(teeError.message);
|
|
2369
|
+
result.isVerified = false;
|
|
2370
|
+
result.error = teeError;
|
|
2355
2371
|
}
|
|
2356
|
-
result.isVerified = result.isVerified && result.isTeeVerified;
|
|
2357
2372
|
} catch (error) {
|
|
2358
|
-
|
|
2373
|
+
const teeError = new TeeVerificationError("Error verifying TEE attestation", error);
|
|
2374
|
+
logger10.error(teeError.message);
|
|
2359
2375
|
result.isTeeVerified = false;
|
|
2360
2376
|
result.isVerified = false;
|
|
2377
|
+
result.error = teeError;
|
|
2361
2378
|
}
|
|
2362
2379
|
}
|
|
2363
2380
|
return result;
|
|
@@ -2365,7 +2382,8 @@ function verifyProof(proofOrProofs, config, verifyTEE) {
|
|
|
2365
2382
|
logger10.error("Error in validating proof:", error);
|
|
2366
2383
|
return {
|
|
2367
2384
|
isVerified: false,
|
|
2368
|
-
data: []
|
|
2385
|
+
data: [],
|
|
2386
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
2369
2387
|
};
|
|
2370
2388
|
}
|
|
2371
2389
|
});
|
|
@@ -2433,6 +2451,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2433
2451
|
this.intervals = /* @__PURE__ */ new Map();
|
|
2434
2452
|
this.jsonProofResponse = false;
|
|
2435
2453
|
this.extensionID = "reclaim-extension";
|
|
2454
|
+
this.appSharePageUrl = "https://share.reclaimprotocol.org/verify";
|
|
2436
2455
|
this.FAILURE_TIMEOUT = 30 * 1e3;
|
|
2437
2456
|
/**
|
|
2438
2457
|
* Validates signature and returns template data
|
|
@@ -2483,7 +2502,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2483
2502
|
};
|
|
2484
2503
|
return templateData;
|
|
2485
2504
|
};
|
|
2486
|
-
var _a, _b
|
|
2505
|
+
var _a, _b;
|
|
2487
2506
|
this.providerId = providerId;
|
|
2488
2507
|
this.timeStamp = Date.now().toString();
|
|
2489
2508
|
this.applicationId = applicationId;
|
|
@@ -2502,7 +2521,11 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2502
2521
|
if (options.useAppClip === void 0) {
|
|
2503
2522
|
options.useAppClip = false;
|
|
2504
2523
|
}
|
|
2505
|
-
|
|
2524
|
+
const customUrl = (_b = options.portalUrl) != null ? _b : options.customSharePageUrl;
|
|
2525
|
+
this.customSharePageUrl = customUrl != null ? customUrl : "https://portal.reclaimprotocol.org";
|
|
2526
|
+
if (customUrl) {
|
|
2527
|
+
this.appSharePageUrl = customUrl;
|
|
2528
|
+
}
|
|
2506
2529
|
options.customSharePageUrl = this.customSharePageUrl;
|
|
2507
2530
|
if (options == null ? void 0 : options.envUrl) {
|
|
2508
2531
|
setBackendBaseUrl(options.envUrl);
|
|
@@ -2831,11 +2854,11 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2831
2854
|
*
|
|
2832
2855
|
* @param url - The URL where users should be redirected after successful proof generation
|
|
2833
2856
|
* @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
|
|
2834
|
-
* `POST` form redirection is only supported in
|
|
2857
|
+
* `POST` form redirection is only supported in Portal flow.
|
|
2835
2858
|
* @param body - List of name-value pairs to be sent as the body of the form request.
|
|
2836
2859
|
* `When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
|
|
2837
2860
|
* When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
|
|
2838
|
-
* Sending `body` on redirection is only supported in
|
|
2861
|
+
* Sending `body` on redirection is only supported in Portal flow.
|
|
2839
2862
|
*
|
|
2840
2863
|
* @throws {InvalidParamError} When URL is invalid
|
|
2841
2864
|
*
|
|
@@ -2897,11 +2920,11 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
2897
2920
|
*
|
|
2898
2921
|
* @param url - The URL where users should be redirected after an error which aborts the verification process
|
|
2899
2922
|
* @param method - The redirection method that should be used for redirection. Allowed options: `GET`, and `POST`.
|
|
2900
|
-
* `POST` form redirection is only supported in
|
|
2923
|
+
* `POST` form redirection is only supported in Portal flow.
|
|
2901
2924
|
* @param body - List of name-value pairs to be sent as the body of the form request.
|
|
2902
2925
|
* When `method` is set to `POST`, `body` will be sent with 'application/x-www-form-urlencoded' content type.
|
|
2903
2926
|
* When `method` is set to `GET`, if `body` is set then `body` will be sent as query parameters.
|
|
2904
|
-
* Sending `body` on redirection is only supported in
|
|
2927
|
+
* Sending `body` on redirection is only supported in Portal flow.
|
|
2905
2928
|
* @throws {InvalidParamError} When URL is invalid
|
|
2906
2929
|
*
|
|
2907
2930
|
* @example
|
|
@@ -3196,8 +3219,80 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3196
3219
|
attestationNonceData: this.attestationNonceData
|
|
3197
3220
|
});
|
|
3198
3221
|
}
|
|
3222
|
+
encodeTemplateData(templateData) {
|
|
3223
|
+
let template = encodeURIComponent(JSON.stringify(templateData));
|
|
3224
|
+
template = replaceAll(template, "(", "%28");
|
|
3225
|
+
template = replaceAll(template, ")", "%29");
|
|
3226
|
+
return template;
|
|
3227
|
+
}
|
|
3199
3228
|
buildSharePageUrl(template) {
|
|
3200
|
-
return
|
|
3229
|
+
return `${this.appSharePageUrl}/?template=${template}`;
|
|
3230
|
+
}
|
|
3231
|
+
openPortalTab(templateData, preOpenedTab) {
|
|
3232
|
+
return __async(this, null, function* () {
|
|
3233
|
+
const newTab = preOpenedTab != null ? preOpenedTab : window.open("about:blank", "_blank");
|
|
3234
|
+
const link = yield createLinkWithTemplateData(templateData, this.customSharePageUrl);
|
|
3235
|
+
logger10.info("Opening portal in new tab: " + link);
|
|
3236
|
+
if (newTab) {
|
|
3237
|
+
this.portalTab = newTab;
|
|
3238
|
+
newTab.location = link;
|
|
3239
|
+
setTimeout(() => {
|
|
3240
|
+
try {
|
|
3241
|
+
if (newTab.location.href === "about:blank") {
|
|
3242
|
+
newTab.close();
|
|
3243
|
+
this.portalTab = void 0;
|
|
3244
|
+
window.open(link, "_blank");
|
|
3245
|
+
}
|
|
3246
|
+
} catch (_) {
|
|
3247
|
+
}
|
|
3248
|
+
}, 500);
|
|
3249
|
+
}
|
|
3250
|
+
});
|
|
3251
|
+
}
|
|
3252
|
+
closePortalTab() {
|
|
3253
|
+
var _a;
|
|
3254
|
+
try {
|
|
3255
|
+
(_a = this.portalTab) == null ? void 0 : _a.close();
|
|
3256
|
+
} catch (_) {
|
|
3257
|
+
}
|
|
3258
|
+
this.portalTab = void 0;
|
|
3259
|
+
}
|
|
3260
|
+
embedPortalIframe(templateData, target) {
|
|
3261
|
+
return __async(this, null, function* () {
|
|
3262
|
+
let link = yield createLinkWithTemplateData(templateData, this.customSharePageUrl);
|
|
3263
|
+
const separator = link.includes("?") ? "&" : "?";
|
|
3264
|
+
link = `${link}${separator}embedded=true`;
|
|
3265
|
+
logger10.info("Embedding portal in iframe: " + link);
|
|
3266
|
+
this.closeEmbeddedFlow();
|
|
3267
|
+
const iframe = document.createElement("iframe");
|
|
3268
|
+
iframe.src = link;
|
|
3269
|
+
iframe.style.width = "100%";
|
|
3270
|
+
iframe.style.height = "100%";
|
|
3271
|
+
iframe.style.border = "none";
|
|
3272
|
+
iframe.setAttribute("allow", "clipboard-write");
|
|
3273
|
+
iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
|
|
3274
|
+
target.appendChild(iframe);
|
|
3275
|
+
this.portalIframe = iframe;
|
|
3276
|
+
});
|
|
3277
|
+
}
|
|
3278
|
+
/**
|
|
3279
|
+
* Closes the embedded portal iframe and stops the session polling.
|
|
3280
|
+
*
|
|
3281
|
+
* Call this to programmatically cancel the embedded verification flow
|
|
3282
|
+
* that was started with `triggerReclaimFlow({ target: element })`.
|
|
3283
|
+
* Also called automatically when verification succeeds or fails.
|
|
3284
|
+
*
|
|
3285
|
+
* @example
|
|
3286
|
+
* ```typescript
|
|
3287
|
+
* proofRequest.closeEmbeddedFlow();
|
|
3288
|
+
* ```
|
|
3289
|
+
*/
|
|
3290
|
+
closeEmbeddedFlow() {
|
|
3291
|
+
if (this.portalIframe) {
|
|
3292
|
+
this.portalIframe.remove();
|
|
3293
|
+
this.portalIframe = void 0;
|
|
3294
|
+
}
|
|
3295
|
+
this.clearInterval();
|
|
3201
3296
|
}
|
|
3202
3297
|
/**
|
|
3203
3298
|
* Exports the Reclaim proof verification request as a JSON string
|
|
@@ -3270,7 +3365,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3270
3365
|
* // Portal URL (default)
|
|
3271
3366
|
* const url = await proofRequest.getRequestUrl();
|
|
3272
3367
|
*
|
|
3273
|
-
* //
|
|
3368
|
+
* // Verifier app flow URL
|
|
3274
3369
|
* const url = await proofRequest.getRequestUrl({ verificationMode: 'app' });
|
|
3275
3370
|
* ```
|
|
3276
3371
|
*/
|
|
@@ -3287,15 +3382,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3287
3382
|
const templateData = this.getTemplateData();
|
|
3288
3383
|
yield updateSession(this.sessionId, "SESSION_STARTED" /* SESSION_STARTED */);
|
|
3289
3384
|
if (mode === "app") {
|
|
3290
|
-
|
|
3291
|
-
template = replaceAll(template, "(", "%28");
|
|
3292
|
-
template = replaceAll(template, ")", "%29");
|
|
3385
|
+
const template = this.encodeTemplateData(templateData);
|
|
3293
3386
|
if (((_c = this.options) == null ? void 0 : _c.useAppClip) && getDeviceType() === "mobile" /* MOBILE */ && getMobileDeviceType() === "ios" /* IOS */) {
|
|
3294
3387
|
const appClipUrl = this.customAppClipUrl ? `${this.customAppClipUrl}&template=${template}` : `https://appclip.apple.com/id?p=org.reclaimprotocol.app.clip&template=${template}`;
|
|
3295
3388
|
logger10.info("App Clip Url created successfully: " + appClipUrl);
|
|
3296
3389
|
return appClipUrl;
|
|
3297
3390
|
}
|
|
3298
|
-
const sharePageUrl = yield createLinkWithTemplateData(templateData,
|
|
3391
|
+
const sharePageUrl = yield createLinkWithTemplateData(templateData, this.appSharePageUrl);
|
|
3299
3392
|
logger10.info("Share page Url created successfully: " + sharePageUrl);
|
|
3300
3393
|
return sharePageUrl;
|
|
3301
3394
|
}
|
|
@@ -3312,8 +3405,9 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3312
3405
|
* Triggers the appropriate Reclaim verification flow based on device type and configuration.
|
|
3313
3406
|
*
|
|
3314
3407
|
* Defaults to portal mode (remote browser verification). Pass `{ verificationMode: 'app' }`
|
|
3315
|
-
* for
|
|
3408
|
+
* for verifier app flow via the share page.
|
|
3316
3409
|
*
|
|
3410
|
+
* - **Embedded iframe**: Pass `{ target: element }` to embed the portal inside a DOM element instead of a new tab
|
|
3317
3411
|
* - Desktop: browser extension takes priority in both modes
|
|
3318
3412
|
* - Desktop portal mode (no extension): opens portal in new tab
|
|
3319
3413
|
* - Desktop app mode (no extension): shows QR code modal with share page URL
|
|
@@ -3321,15 +3415,22 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3321
3415
|
* - Mobile app mode: opens share page (or App Clip on iOS if `useAppClip` is `true`)
|
|
3322
3416
|
*
|
|
3323
3417
|
* @param launchOptions - Optional launch configuration to override default behavior
|
|
3324
|
-
* @returns Promise<
|
|
3418
|
+
* @returns Promise<FlowHandle> - Handle to control the flow (close, access iframe)
|
|
3325
3419
|
* @throws {SignatureNotFoundError} When signature is not set
|
|
3326
3420
|
*
|
|
3327
3421
|
* @example
|
|
3328
3422
|
* ```typescript
|
|
3329
|
-
* // Portal flow (default)
|
|
3330
|
-
* await proofRequest.triggerReclaimFlow();
|
|
3423
|
+
* // Portal flow (default) — opens in new tab
|
|
3424
|
+
* const handle = await proofRequest.triggerReclaimFlow();
|
|
3425
|
+
* handle.tab; // Window reference to the opened tab
|
|
3426
|
+
* handle.close(); // close tab and stop polling
|
|
3331
3427
|
*
|
|
3332
|
-
* //
|
|
3428
|
+
* // Embed portal in an iframe inside a DOM element
|
|
3429
|
+
* const handle = await proofRequest.triggerReclaimFlow({ target: document.getElementById('reclaim-container') });
|
|
3430
|
+
* handle.iframe; // HTMLIFrameElement reference
|
|
3431
|
+
* handle.close(); // remove iframe and stop polling
|
|
3432
|
+
*
|
|
3433
|
+
* // Verifier app flow
|
|
3333
3434
|
* await proofRequest.triggerReclaimFlow({ verificationMode: 'app' });
|
|
3334
3435
|
*
|
|
3335
3436
|
* // App Clip on iOS (requires useAppClip: true at init)
|
|
@@ -3345,7 +3446,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3345
3446
|
*/
|
|
3346
3447
|
triggerReclaimFlow(launchOptions) {
|
|
3347
3448
|
return __async(this, null, function* () {
|
|
3348
|
-
var _a, _b, _c, _d, _e
|
|
3449
|
+
var _a, _b, _c, _d, _e;
|
|
3349
3450
|
const options = launchOptions || ((_a = this.options) == null ? void 0 : _a.launchOptions) || {};
|
|
3350
3451
|
const mode = (_b = options.verificationMode) != null ? _b : "portal";
|
|
3351
3452
|
if (!this.signature) {
|
|
@@ -3357,37 +3458,38 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3357
3458
|
logger10.info(`Triggering Reclaim flow (mode: ${mode})`);
|
|
3358
3459
|
const deviceType = getDeviceType();
|
|
3359
3460
|
updateSession(this.sessionId, "SESSION_STARTED" /* SESSION_STARTED */);
|
|
3461
|
+
if ("target" in options && !options.target) {
|
|
3462
|
+
logger10.warn("triggerReclaimFlow: target was provided but is null/undefined \u2014 falling back to default flow. Ensure the element exists in the DOM.");
|
|
3463
|
+
}
|
|
3464
|
+
if (options.target && mode === "portal") {
|
|
3465
|
+
yield this.embedPortalIframe(templateData, options.target);
|
|
3466
|
+
return {
|
|
3467
|
+
close: () => this.closeEmbeddedFlow(),
|
|
3468
|
+
iframe: this.portalIframe
|
|
3469
|
+
};
|
|
3470
|
+
}
|
|
3360
3471
|
if (deviceType === "desktop" /* DESKTOP */) {
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
const newTab = window.open("about:blank", "_blank");
|
|
3370
|
-
const link = yield createLinkWithTemplateData(templateData, portalUrl);
|
|
3371
|
-
logger10.info("Opening portal in new tab: " + link);
|
|
3372
|
-
if (newTab) {
|
|
3373
|
-
newTab.location = link;
|
|
3374
|
-
setTimeout(() => {
|
|
3375
|
-
try {
|
|
3376
|
-
if (newTab.location.href === "about:blank") {
|
|
3377
|
-
newTab.close();
|
|
3378
|
-
window.open(link, "_blank");
|
|
3379
|
-
}
|
|
3380
|
-
} catch (_) {
|
|
3472
|
+
if ((_c = this.options) == null ? void 0 : _c.useBrowserExtension) {
|
|
3473
|
+
const extensionAvailable = yield this.isBrowserExtensionAvailable();
|
|
3474
|
+
if (extensionAvailable) {
|
|
3475
|
+
logger10.info("Triggering browser extension flow");
|
|
3476
|
+
this.triggerBrowserExtensionFlow();
|
|
3477
|
+
return {
|
|
3478
|
+
close: () => {
|
|
3479
|
+
this.clearInterval();
|
|
3381
3480
|
}
|
|
3382
|
-
}
|
|
3481
|
+
};
|
|
3383
3482
|
}
|
|
3483
|
+
}
|
|
3484
|
+
if (mode === "portal") {
|
|
3485
|
+
yield this.openPortalTab(templateData);
|
|
3384
3486
|
} else {
|
|
3385
3487
|
logger10.info("Showing QR code modal with share page URL");
|
|
3386
|
-
yield this.showQRCodeModal(
|
|
3488
|
+
yield this.showQRCodeModal();
|
|
3387
3489
|
}
|
|
3388
3490
|
} else if (deviceType === "mobile" /* MOBILE */) {
|
|
3389
3491
|
if (mode === "app") {
|
|
3390
|
-
if (((
|
|
3492
|
+
if (((_d = this.options) == null ? void 0 : _d.useAppClip) && getMobileDeviceType() === "ios" /* IOS */) {
|
|
3391
3493
|
logger10.info("Redirecting to iOS app clip");
|
|
3392
3494
|
this.redirectToAppClip();
|
|
3393
3495
|
} else {
|
|
@@ -3395,24 +3497,18 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3395
3497
|
yield this.redirectToInstantApp(options);
|
|
3396
3498
|
}
|
|
3397
3499
|
} else {
|
|
3398
|
-
|
|
3399
|
-
const newTab = window.open("about:blank", "_blank");
|
|
3400
|
-
const link = yield createLinkWithTemplateData(templateData, portalUrl);
|
|
3401
|
-
logger10.info("Opening portal on mobile: " + link);
|
|
3402
|
-
if (newTab) {
|
|
3403
|
-
newTab.location = link;
|
|
3404
|
-
setTimeout(() => {
|
|
3405
|
-
try {
|
|
3406
|
-
if (newTab.location.href === "about:blank") {
|
|
3407
|
-
newTab.close();
|
|
3408
|
-
window.open(link, "_blank");
|
|
3409
|
-
}
|
|
3410
|
-
} catch (_) {
|
|
3411
|
-
}
|
|
3412
|
-
}, 500);
|
|
3413
|
-
}
|
|
3500
|
+
yield this.openPortalTab(templateData);
|
|
3414
3501
|
}
|
|
3415
3502
|
}
|
|
3503
|
+
return {
|
|
3504
|
+
close: () => {
|
|
3505
|
+
var _a2;
|
|
3506
|
+
this.closePortalTab();
|
|
3507
|
+
this.closeEmbeddedFlow();
|
|
3508
|
+
(_a2 = this.modal) == null ? void 0 : _a2.close();
|
|
3509
|
+
},
|
|
3510
|
+
tab: (_e = this.portalTab) != null ? _e : void 0
|
|
3511
|
+
};
|
|
3416
3512
|
} catch (error) {
|
|
3417
3513
|
logger10.info("Error triggering Reclaim flow:", error);
|
|
3418
3514
|
throw error;
|
|
@@ -3477,11 +3573,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3477
3573
|
window.postMessage(message, "*");
|
|
3478
3574
|
logger10.info("Browser extension flow triggered");
|
|
3479
3575
|
}
|
|
3480
|
-
showQRCodeModal(
|
|
3576
|
+
showQRCodeModal() {
|
|
3481
3577
|
return __async(this, null, function* () {
|
|
3482
3578
|
try {
|
|
3483
|
-
const
|
|
3484
|
-
const requestUrl = yield createLinkWithTemplateData(this.templateData, url);
|
|
3579
|
+
const requestUrl = yield createLinkWithTemplateData(this.templateData, this.appSharePageUrl);
|
|
3485
3580
|
this.modal = new QRCodeModal(this.modalOptions);
|
|
3486
3581
|
yield this.modal.show(requestUrl);
|
|
3487
3582
|
} catch (error) {
|
|
@@ -3494,9 +3589,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3494
3589
|
return __async(this, null, function* () {
|
|
3495
3590
|
var _a;
|
|
3496
3591
|
try {
|
|
3497
|
-
|
|
3498
|
-
template = replaceAll(template, "(", "%28");
|
|
3499
|
-
template = replaceAll(template, ")", "%29");
|
|
3592
|
+
const template = this.encodeTemplateData(this.templateData);
|
|
3500
3593
|
let instantAppUrl = this.buildSharePageUrl(template);
|
|
3501
3594
|
logger10.info("Redirecting to Android instant app: " + instantAppUrl);
|
|
3502
3595
|
const isDeferredDeeplinksFlowEnabled = (_a = options.canUseDeferredDeepLinksFlow) != null ? _a : false;
|
|
@@ -3555,12 +3648,10 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3555
3648
|
}
|
|
3556
3649
|
redirectToAppClip() {
|
|
3557
3650
|
try {
|
|
3558
|
-
|
|
3559
|
-
template = replaceAll(template, "(", "%28");
|
|
3560
|
-
template = replaceAll(template, ")", "%29");
|
|
3651
|
+
const template = this.encodeTemplateData(this.templateData);
|
|
3561
3652
|
const appClipUrl = this.customAppClipUrl ? `${this.customAppClipUrl}&template=${template}` : `https://appclip.apple.com/id?p=org.reclaimprotocol.app.clip&template=${template}`;
|
|
3562
3653
|
logger10.info("Redirecting to iOS app clip: " + appClipUrl);
|
|
3563
|
-
const verifierUrl =
|
|
3654
|
+
const verifierUrl = `${this.appSharePageUrl}/?template=${template}`;
|
|
3564
3655
|
window.location.href = appClipUrl;
|
|
3565
3656
|
setTimeout(() => {
|
|
3566
3657
|
window.location.href = verifierUrl;
|
|
@@ -3643,7 +3734,7 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3643
3734
|
* ```
|
|
3644
3735
|
*/
|
|
3645
3736
|
startSession(_0) {
|
|
3646
|
-
return __async(this, arguments, function* ({ onSuccess, onError
|
|
3737
|
+
return __async(this, arguments, function* ({ onSuccess, onError }) {
|
|
3647
3738
|
if (!this.sessionId) {
|
|
3648
3739
|
const message = "Session can't be started due to undefined value of sessionId";
|
|
3649
3740
|
logger10.info(message);
|
|
@@ -3690,6 +3781,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3690
3781
|
}
|
|
3691
3782
|
this.clearInterval();
|
|
3692
3783
|
(_b = this.modal) == null ? void 0 : _b.close();
|
|
3784
|
+
this.closePortalTab();
|
|
3785
|
+
this.closeEmbeddedFlow();
|
|
3693
3786
|
}
|
|
3694
3787
|
} else {
|
|
3695
3788
|
if (statusUrlResponse.session.statusV2 === "PROOF_SUBMISSION_FAILED" /* PROOF_SUBMISSION_FAILED */) {
|
|
@@ -3702,6 +3795,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3702
3795
|
}
|
|
3703
3796
|
this.clearInterval();
|
|
3704
3797
|
(_d = this.modal) == null ? void 0 : _d.close();
|
|
3798
|
+
this.closePortalTab();
|
|
3799
|
+
this.closeEmbeddedFlow();
|
|
3705
3800
|
}
|
|
3706
3801
|
}
|
|
3707
3802
|
} catch (e) {
|
|
@@ -3710,6 +3805,8 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3710
3805
|
}
|
|
3711
3806
|
this.clearInterval();
|
|
3712
3807
|
(_e = this.modal) == null ? void 0 : _e.close();
|
|
3808
|
+
this.closePortalTab();
|
|
3809
|
+
this.closeEmbeddedFlow();
|
|
3713
3810
|
}
|
|
3714
3811
|
}), sessionUpdatePollingInterval);
|
|
3715
3812
|
this.intervals.set(this.sessionId, interval);
|
|
@@ -3752,11 +3849,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3752
3849
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3753
3850
|
0 && (module.exports = {
|
|
3754
3851
|
ReclaimProofRequest,
|
|
3852
|
+
TeeVerificationError,
|
|
3755
3853
|
assertValidProofsByHash,
|
|
3756
3854
|
assertValidateProof,
|
|
3757
3855
|
assertVerifiedProof,
|
|
3758
3856
|
clearDeviceCache,
|
|
3759
3857
|
createLinkWithTemplateData,
|
|
3858
|
+
createSignDataForClaim,
|
|
3760
3859
|
fetchProviderConfigs,
|
|
3761
3860
|
fetchProviderHashRequirementsBy,
|
|
3762
3861
|
fetchStatusUrl,
|
|
@@ -3764,9 +3863,13 @@ var ReclaimProofRequest = class _ReclaimProofRequest {
|
|
|
3764
3863
|
getAttestors,
|
|
3765
3864
|
getDeviceType,
|
|
3766
3865
|
getHttpProviderClaimParamsFromProof,
|
|
3866
|
+
getIdentifierFromClaimInfo,
|
|
3767
3867
|
getMobileDeviceType,
|
|
3868
|
+
getProviderHashRequirementSpecFromProviderConfig,
|
|
3768
3869
|
getProviderHashRequirementsFromSpec,
|
|
3870
|
+
getProviderParamsAsCanonicalizedString,
|
|
3769
3871
|
getShortenedUrl,
|
|
3872
|
+
hashProofClaimParams,
|
|
3770
3873
|
hashRequestSpec,
|
|
3771
3874
|
initSession,
|
|
3772
3875
|
isDesktopDevice,
|