@metamask-previews/kyc-controller 0.0.0-preview-e12b5ece6 → 0.0.0-preview-fe4b3be11
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/CHANGELOG.md +0 -7
- package/dist/KycController-method-action-types.cjs.map +1 -1
- package/dist/KycController-method-action-types.d.cts +4 -6
- package/dist/KycController-method-action-types.d.cts.map +1 -1
- package/dist/KycController-method-action-types.d.mts +4 -6
- package/dist/KycController-method-action-types.d.mts.map +1 -1
- package/dist/KycController-method-action-types.mjs.map +1 -1
- package/dist/KycController.cjs +135 -157
- package/dist/KycController.cjs.map +1 -1
- package/dist/KycController.d.cts +34 -40
- package/dist/KycController.d.cts.map +1 -1
- package/dist/KycController.d.mts +34 -40
- package/dist/KycController.d.mts.map +1 -1
- package/dist/KycController.mjs +134 -154
- package/dist/KycController.mjs.map +1 -1
- package/dist/KycService-method-action-types.cjs.map +1 -1
- package/dist/KycService-method-action-types.d.cts +4 -4
- package/dist/KycService-method-action-types.d.mts +4 -4
- package/dist/KycService-method-action-types.mjs.map +1 -1
- package/dist/KycService.cjs +13 -21
- package/dist/KycService.cjs.map +1 -1
- package/dist/KycService.d.cts +4 -4
- package/dist/KycService.d.cts.map +1 -1
- package/dist/KycService.d.mts +4 -4
- package/dist/KycService.d.mts.map +1 -1
- package/dist/KycService.mjs +13 -21
- package/dist/KycService.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +11 -50
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +11 -50
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/vendorDisclaimerAcceptance.cjs +0 -74
- package/dist/vendorDisclaimerAcceptance.cjs.map +0 -1
- package/dist/vendorDisclaimerAcceptance.d.cts +0 -39
- package/dist/vendorDisclaimerAcceptance.d.cts.map +0 -1
- package/dist/vendorDisclaimerAcceptance.d.mts +0 -39
- package/dist/vendorDisclaimerAcceptance.d.mts.map +0 -1
- package/dist/vendorDisclaimerAcceptance.mjs +0 -67
- package/dist/vendorDisclaimerAcceptance.mjs.map +0 -1
package/dist/KycController.cjs
CHANGED
|
@@ -10,9 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _KycController_instances, _KycController_sumsubLauncher, _KycController_moonpayFrameKeypair, _KycController_authClientToken, _KycController_generation, _KycController_sessionStatusPollIntervalMs, _KycController_pollTimer, _KycController_pollToken, _KycController_userStatusPollIntervalMs, _KycController_userStatusPollTimer, _KycController_userStatusPolling, _KycController_userStatusPollToken, _KycController_localUserSecretStore, _KycController_startConsentsSession, _KycController_recordSessionDisclaimers, _KycController_createSession, _KycController_clearAcceptedTerms, _KycController_clearMoonPaySession, _KycController_handleCheckOutcome, _KycController_handleAuthOutcome, _KycController_continueAfterAuthentication, _KycController_requireTermsReacceptance, _KycController_buildUkycSessionVendorFields, _KycController_createUkycSession, _KycController_fetchAndApplyUserStatus, _KycController_applyUserStatus, _KycController_ensureUserStatusPolling, _KycController_stopUserStatusPolling, _KycController_startSessionStatusPolling, _KycController_pollSessionStatusOnce, _KycController_stopPolling, _KycController_cancelPendingSession, _KycController_updateIfCurrent, _KycController_applyUpdate, _KycController_assertAttestedServerPublicKey, _KycController_fail;
|
|
13
|
+
var _KycController_instances, _KycController_sumsubLauncher, _KycController_moonpayFrameKeypair, _KycController_authClientToken, _KycController_generation, _KycController_sessionStatusPollIntervalMs, _KycController_pollTimer, _KycController_pollToken, _KycController_userStatusPollIntervalMs, _KycController_userStatusPollTimer, _KycController_userStatusPolling, _KycController_userStatusPollToken, _KycController_localUserSecretStore, _KycController_startConsentsSession, _KycController_recordSessionDisclaimers, _KycController_createSession, _KycController_clearAcceptedTerms, _KycController_clearMoonPaySession, _KycController_dropTermsUnlessForVendor, _KycController_hasTermsForVendor, _KycController_handleCheckOutcome, _KycController_handleAuthOutcome, _KycController_continueAfterAuthentication, _KycController_requireTermsReacceptance, _KycController_buildUkycSessionVendorFields, _KycController_createUkycSession, _KycController_fetchAndApplyUserStatus, _KycController_applyUserStatus, _KycController_ensureUserStatusPolling, _KycController_stopUserStatusPolling, _KycController_startSessionStatusPolling, _KycController_pollSessionStatusOnce, _KycController_stopPolling, _KycController_cancelPendingSession, _KycController_updateIfCurrent, _KycController_applyUpdate, _KycController_assertAttestedServerPublicKey, _KycController_fail;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.KycController = exports.getDefaultKycControllerState = exports.
|
|
15
|
+
exports.KycController = exports.getDefaultKycControllerState = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
17
17
|
const utils_1 = require("@metamask/utils");
|
|
18
18
|
const ed25519_1 = require("@noble/curves/ed25519");
|
|
@@ -24,7 +24,6 @@ const jwtChain_js_1 = require("./ukyc/jwtChain.cjs");
|
|
|
24
24
|
const localUserSecret_js_1 = require("./ukyc/localUserSecret.cjs");
|
|
25
25
|
const storageAccessToken_js_1 = require("./ukyc/storageAccessToken.cjs");
|
|
26
26
|
const wrapEncryptionKey_js_1 = require("./ukyc/wrapEncryptionKey.cjs");
|
|
27
|
-
const vendorDisclaimerAcceptance_js_1 = require("./vendorDisclaimerAcceptance.cjs");
|
|
28
27
|
// === GENERAL ===
|
|
29
28
|
exports.controllerName = 'KycController';
|
|
30
29
|
const FRAMES_BASE_URL = 'https://blocks.moonpay.com/platform/v1';
|
|
@@ -121,19 +120,31 @@ const kycControllerMetadata = {
|
|
|
121
120
|
persist: false,
|
|
122
121
|
usedInUi: false,
|
|
123
122
|
},
|
|
124
|
-
|
|
123
|
+
termsAcceptedAt: {
|
|
125
124
|
includeInDebugSnapshot: true,
|
|
126
125
|
includeInStateLogs: true,
|
|
127
126
|
persist: true,
|
|
128
127
|
usedInUi: false,
|
|
129
128
|
},
|
|
130
|
-
|
|
129
|
+
acceptedDisclaimerIds: {
|
|
131
130
|
includeInDebugSnapshot: true,
|
|
132
131
|
includeInStateLogs: true,
|
|
133
132
|
persist: true,
|
|
134
133
|
usedInUi: false,
|
|
135
134
|
},
|
|
136
|
-
|
|
135
|
+
termsAcceptedVendor: {
|
|
136
|
+
includeInDebugSnapshot: true,
|
|
137
|
+
includeInStateLogs: true,
|
|
138
|
+
persist: true,
|
|
139
|
+
usedInUi: false,
|
|
140
|
+
},
|
|
141
|
+
sumsubTncAccepted: {
|
|
142
|
+
includeInDebugSnapshot: true,
|
|
143
|
+
includeInStateLogs: true,
|
|
144
|
+
persist: true,
|
|
145
|
+
usedInUi: false,
|
|
146
|
+
},
|
|
147
|
+
idosTncAccepted: {
|
|
137
148
|
includeInDebugSnapshot: true,
|
|
138
149
|
includeInStateLogs: true,
|
|
139
150
|
persist: true,
|
|
@@ -145,13 +156,13 @@ const kycControllerMetadata = {
|
|
|
145
156
|
persist: false,
|
|
146
157
|
usedInUi: false,
|
|
147
158
|
},
|
|
148
|
-
|
|
159
|
+
disclaimers: {
|
|
149
160
|
includeInDebugSnapshot: false,
|
|
150
161
|
includeInStateLogs: false,
|
|
151
162
|
persist: false,
|
|
152
163
|
usedInUi: true,
|
|
153
164
|
},
|
|
154
|
-
|
|
165
|
+
disclaimersError: {
|
|
155
166
|
includeInDebugSnapshot: true,
|
|
156
167
|
includeInStateLogs: true,
|
|
157
168
|
persist: false,
|
|
@@ -169,13 +180,13 @@ const kycControllerMetadata = {
|
|
|
169
180
|
persist: false,
|
|
170
181
|
usedInUi: true,
|
|
171
182
|
},
|
|
172
|
-
|
|
183
|
+
sessionToken: {
|
|
173
184
|
includeInDebugSnapshot: false,
|
|
174
185
|
includeInStateLogs: false,
|
|
175
186
|
persist: false,
|
|
176
187
|
usedInUi: false,
|
|
177
188
|
},
|
|
178
|
-
|
|
189
|
+
accessToken: {
|
|
179
190
|
includeInDebugSnapshot: false,
|
|
180
191
|
includeInStateLogs: false,
|
|
181
192
|
persist: false,
|
|
@@ -236,19 +247,6 @@ const kycControllerMetadata = {
|
|
|
236
247
|
usedInUi: true,
|
|
237
248
|
},
|
|
238
249
|
};
|
|
239
|
-
/**
|
|
240
|
-
* Constructs the default {@link KycVendorDisclaimersAccepted} value.
|
|
241
|
-
*
|
|
242
|
-
* @returns The default vendor-disclaimer acceptance map.
|
|
243
|
-
*/
|
|
244
|
-
function getDefaultKycVendorDisclaimersAccepted() {
|
|
245
|
-
return { moonpay: null, iron: null };
|
|
246
|
-
}
|
|
247
|
-
exports.getDefaultKycVendorDisclaimersAccepted = getDefaultKycVendorDisclaimersAccepted;
|
|
248
|
-
function getDefaultKycProviderDisclaimersAccepted() {
|
|
249
|
-
return { sumsub: null };
|
|
250
|
-
}
|
|
251
|
-
exports.getDefaultKycProviderDisclaimersAccepted = getDefaultKycProviderDisclaimersAccepted;
|
|
252
250
|
/**
|
|
253
251
|
* Constructs the default {@link KycController} state.
|
|
254
252
|
*
|
|
@@ -260,16 +258,18 @@ function getDefaultKycControllerState() {
|
|
|
260
258
|
statusMessage: '',
|
|
261
259
|
error: null,
|
|
262
260
|
email: null,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
261
|
+
termsAcceptedAt: null,
|
|
262
|
+
acceptedDisclaimerIds: [],
|
|
263
|
+
termsAcceptedVendor: null,
|
|
264
|
+
sumsubTncAccepted: null,
|
|
265
|
+
idosTncAccepted: null,
|
|
266
266
|
credentialReusabilityConsentGiven: null,
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
disclaimers: [],
|
|
268
|
+
disclaimersError: null,
|
|
269
269
|
sessionDisclaimers: null,
|
|
270
270
|
geoCountry: null,
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
sessionToken: null,
|
|
272
|
+
accessToken: null,
|
|
273
273
|
moonpayCustomerId: null,
|
|
274
274
|
activeVendor: 'moonpay',
|
|
275
275
|
activeProduct: null,
|
|
@@ -314,62 +314,45 @@ function isConsentConflictError(error) {
|
|
|
314
314
|
error.httpStatus === 409);
|
|
315
315
|
}
|
|
316
316
|
/**
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*/
|
|
321
|
-
function isValidConsentRecordList(value) {
|
|
322
|
-
return (Array.isArray(value) &&
|
|
323
|
-
value.every((item) => typeof item === 'object' &&
|
|
324
|
-
item !== null &&
|
|
325
|
-
typeof item.key === 'string' &&
|
|
326
|
-
typeof item.version === 'string'));
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Maps accepted disclaimer records onto unconsented catalog documents.
|
|
317
|
+
* Maps a session-disclaimer catalog into the `{ key, version }` records the
|
|
318
|
+
* record-consents API expects, or an empty list when the user declined that
|
|
319
|
+
* category.
|
|
330
320
|
*
|
|
331
321
|
* @param documents - Catalog documents for one consent category.
|
|
332
|
-
* @param accepted -
|
|
333
|
-
* @returns Consent records
|
|
322
|
+
* @param accepted - Whether the user accepted that category.
|
|
323
|
+
* @returns Consent records, or `[]` when not accepted.
|
|
334
324
|
*/
|
|
335
|
-
function
|
|
336
|
-
if (accepted
|
|
325
|
+
function consentRecordsFromCatalog(documents, accepted) {
|
|
326
|
+
if (!accepted) {
|
|
337
327
|
return [];
|
|
338
328
|
}
|
|
339
|
-
const acceptedKeys = new Set(accepted.map((record) => `${record.key}:${record.version}`));
|
|
340
329
|
return documents
|
|
341
|
-
.filter((document) => !document.consented
|
|
342
|
-
acceptedKeys.has(`${document.key}:${document.version}`))
|
|
330
|
+
.filter((document) => !document.consented)
|
|
343
331
|
.map(({ key, version }) => ({ key, version }));
|
|
344
332
|
}
|
|
345
333
|
/**
|
|
346
|
-
* Whether accepted
|
|
334
|
+
* Whether an accepted T&C2 category has no catalog documents. An empty list
|
|
335
|
+
* would otherwise skip the POST and count as success.
|
|
347
336
|
*
|
|
348
337
|
* @param documents - Catalog documents for one consent category.
|
|
349
|
-
* @param accepted -
|
|
350
|
-
* @returns `true` when the
|
|
338
|
+
* @param accepted - Whether the user accepted that category.
|
|
339
|
+
* @returns `true` when the user accepted and the catalog is empty.
|
|
351
340
|
*/
|
|
352
341
|
function isAcceptedCategoryEmpty(documents, accepted) {
|
|
353
|
-
return accepted
|
|
342
|
+
return accepted && documents.length === 0;
|
|
354
343
|
}
|
|
355
344
|
/**
|
|
356
|
-
* Whether accepted
|
|
357
|
-
* empty catalog or any
|
|
345
|
+
* Whether an accepted category is still missing consent after a 409 re-GET:
|
|
346
|
+
* empty catalog or any document still unconsented.
|
|
358
347
|
*
|
|
359
348
|
* @param documents - Latest catalog documents for one consent category.
|
|
360
|
-
* @param accepted -
|
|
349
|
+
* @param accepted - Whether the user accepted that category.
|
|
361
350
|
* @returns `true` when accepted documents are not fully consented.
|
|
362
351
|
*/
|
|
363
352
|
function acceptedCategoryStillMissing(documents, accepted) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (documents.length === 0) {
|
|
368
|
-
return true;
|
|
369
|
-
}
|
|
370
|
-
const acceptedKeys = new Set(accepted.map((record) => `${record.key}:${record.version}`));
|
|
371
|
-
const relevant = documents.filter((document) => acceptedKeys.has(`${document.key}:${document.version}`));
|
|
372
|
-
return (relevant.length === 0 || relevant.some((document) => !document.consented));
|
|
353
|
+
return (accepted &&
|
|
354
|
+
(documents.length === 0 ||
|
|
355
|
+
documents.some((document) => !document.consented)));
|
|
373
356
|
}
|
|
374
357
|
/**
|
|
375
358
|
* Vendors other than MoonPay skip Check/Auth frames and use the empty-shell
|
|
@@ -516,8 +499,8 @@ class KycController extends base_controller_1.BaseController {
|
|
|
516
499
|
}
|
|
517
500
|
state.activeVendor = vendor;
|
|
518
501
|
// MoonPay Check/Auth artifacts must not survive a switch to another
|
|
519
|
-
// vendor: leftover `
|
|
520
|
-
// leftover `
|
|
502
|
+
// vendor: leftover `sessionToken` would keep `buildCheckFrameUrl` alive,
|
|
503
|
+
// leftover `accessToken` / `#authClientToken` would keep Auth / KYC
|
|
521
504
|
// calls bound to MoonPay, and leftover `moonpayCustomerId` would make
|
|
522
505
|
// `getCustomerIdentity` report a MoonPay id under the wrong vendor.
|
|
523
506
|
if (vendor !== 'moonpay') {
|
|
@@ -570,14 +553,16 @@ class KycController extends base_controller_1.BaseController {
|
|
|
570
553
|
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
571
554
|
return;
|
|
572
555
|
}
|
|
573
|
-
|
|
556
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_dropTermsUnlessForVendor).call(this, vendor);
|
|
557
|
+
const hasTerms = Boolean(this.state.termsAcceptedAt) &&
|
|
558
|
+
this.state.acceptedDisclaimerIds.length > 0;
|
|
574
559
|
if (hasTerms && this.state.email) {
|
|
575
560
|
if (usesConsentsFlow(vendor)) {
|
|
576
561
|
// Consents-path vendors require T&C2 flags; if they weren't persisted
|
|
577
562
|
// (i.e. null from pre-migration state), require reacceptance.
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
563
|
+
const sumsubTncSigned = this.state.sumsubTncAccepted;
|
|
564
|
+
const idosTncSigned = this.state.idosTncAccepted;
|
|
565
|
+
if (sumsubTncSigned === null || idosTncSigned === null) {
|
|
581
566
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
582
567
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
583
568
|
state.phase = 'terms';
|
|
@@ -586,19 +571,12 @@ class KycController extends base_controller_1.BaseController {
|
|
|
586
571
|
return;
|
|
587
572
|
}
|
|
588
573
|
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_startConsentsSession).call(this, {
|
|
589
|
-
|
|
590
|
-
|
|
574
|
+
sumsubTncSigned,
|
|
575
|
+
idosTncSigned,
|
|
591
576
|
credentialReusabilityConsentGiven: this.state.credentialReusabilityConsentGiven ?? false,
|
|
592
577
|
});
|
|
593
578
|
}
|
|
594
579
|
else {
|
|
595
|
-
// TODO: should this be here? or should it exist at all?
|
|
596
|
-
if (vendor === 'moonpay' && this.state.vendorDisclaimers.length === 0) {
|
|
597
|
-
await this.loadDisclaimers();
|
|
598
|
-
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
580
|
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_createSession).call(this);
|
|
603
581
|
}
|
|
604
582
|
return;
|
|
@@ -643,6 +621,10 @@ class KycController extends base_controller_1.BaseController {
|
|
|
643
621
|
vendor: params.vendor,
|
|
644
622
|
email: params.email,
|
|
645
623
|
});
|
|
624
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_dropTermsUnlessForVendor).call(this, params.vendor);
|
|
646
628
|
}
|
|
647
629
|
catch (error) {
|
|
648
630
|
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
@@ -676,13 +658,13 @@ class KycController extends base_controller_1.BaseController {
|
|
|
676
658
|
country,
|
|
677
659
|
});
|
|
678
660
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
679
|
-
state.
|
|
680
|
-
state.
|
|
661
|
+
state.disclaimers = disclaimers;
|
|
662
|
+
state.disclaimersError = null;
|
|
681
663
|
});
|
|
682
664
|
}
|
|
683
665
|
catch (error) {
|
|
684
666
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
685
|
-
state.
|
|
667
|
+
state.disclaimersError = `Failed to load disclaimers: ${String(error)}`;
|
|
686
668
|
});
|
|
687
669
|
}
|
|
688
670
|
}
|
|
@@ -695,47 +677,44 @@ class KycController extends base_controller_1.BaseController {
|
|
|
695
677
|
* @param params.product - The consuming feature the flow runs for. See
|
|
696
678
|
* {@link initialize} for how the product drives the automatic post
|
|
697
679
|
* authentication continuation.
|
|
698
|
-
* @param params.
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
* customer accepted (`{ key, version }` records). Required for every vendor
|
|
703
|
-
* so callers explicitly declare acceptance.
|
|
680
|
+
* @param params.sumsubTncSigned - Whether Sumsub T&C were accepted (T&C2).
|
|
681
|
+
* Required for every vendor so callers explicitly declare acceptance.
|
|
682
|
+
* @param params.idosTncSigned - Whether idOS T&C were accepted (T&C2).
|
|
683
|
+
* Required for every vendor so callers explicitly declare acceptance.
|
|
704
684
|
* @param params.credentialReusabilityConsentGiven - Whether the customer
|
|
705
685
|
* consented to reuse existing idOS credentials. Used when recording
|
|
706
686
|
* session-scoped disclaimers on the consents path. Defaults to `false`.
|
|
707
687
|
*/
|
|
708
688
|
async acceptTermsAndStartSession(params) {
|
|
709
|
-
const
|
|
710
|
-
const
|
|
711
|
-
if (
|
|
712
|
-
|
|
689
|
+
const sumsubTncSigned = params?.sumsubTncSigned;
|
|
690
|
+
const idosTncSigned = params?.idosTncSigned;
|
|
691
|
+
if (typeof sumsubTncSigned !== 'boolean' ||
|
|
692
|
+
typeof idosTncSigned !== 'boolean') {
|
|
713
693
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing T&C2 acceptance flags.');
|
|
714
694
|
return;
|
|
715
695
|
}
|
|
716
|
-
const credentialReusabilityConsentGiven = params
|
|
696
|
+
const credentialReusabilityConsentGiven = params.credentialReusabilityConsentGiven ?? false;
|
|
717
697
|
const termsAcceptedAt = new Date().toISOString();
|
|
718
|
-
const disclaimerIds = this.state.
|
|
698
|
+
const disclaimerIds = this.state.disclaimers.map((disclaimer) => disclaimer.id);
|
|
719
699
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
720
|
-
if (params
|
|
700
|
+
if (params.email) {
|
|
721
701
|
state.email = params.email;
|
|
722
702
|
}
|
|
723
|
-
if (params
|
|
703
|
+
if (params.product) {
|
|
724
704
|
state.activeProduct = params.product;
|
|
725
705
|
}
|
|
726
|
-
state.
|
|
727
|
-
state.
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
state.idosDisclaimersAccepted = idosDisclaimersAccepted;
|
|
706
|
+
state.termsAcceptedAt = termsAcceptedAt;
|
|
707
|
+
state.acceptedDisclaimerIds = disclaimerIds;
|
|
708
|
+
state.termsAcceptedVendor = state.activeVendor;
|
|
709
|
+
state.sumsubTncAccepted = sumsubTncSigned;
|
|
710
|
+
state.idosTncAccepted = idosTncSigned;
|
|
732
711
|
state.credentialReusabilityConsentGiven =
|
|
733
712
|
credentialReusabilityConsentGiven;
|
|
734
713
|
});
|
|
735
714
|
if (usesConsentsFlow(this.state.activeVendor)) {
|
|
736
715
|
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_startConsentsSession).call(this, {
|
|
737
|
-
|
|
738
|
-
|
|
716
|
+
sumsubTncSigned,
|
|
717
|
+
idosTncSigned,
|
|
739
718
|
credentialReusabilityConsentGiven,
|
|
740
719
|
});
|
|
741
720
|
return;
|
|
@@ -747,12 +726,7 @@ class KycController extends base_controller_1.BaseController {
|
|
|
747
726
|
*/
|
|
748
727
|
clearSavedTerms() {
|
|
749
728
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
750
|
-
|
|
751
|
-
getDefaultKycVendorDisclaimersAccepted();
|
|
752
|
-
state.providerDisclaimersAccepted =
|
|
753
|
-
getDefaultKycProviderDisclaimersAccepted();
|
|
754
|
-
state.idosDisclaimersAccepted = null;
|
|
755
|
-
state.credentialReusabilityConsentGiven = null;
|
|
729
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
756
730
|
});
|
|
757
731
|
}
|
|
758
732
|
/**
|
|
@@ -836,12 +810,12 @@ class KycController extends base_controller_1.BaseController {
|
|
|
836
810
|
*/
|
|
837
811
|
buildCheckFrameUrl() {
|
|
838
812
|
if (this.state.activeVendor !== 'moonpay' ||
|
|
839
|
-
!this.state.
|
|
813
|
+
!this.state.sessionToken ||
|
|
840
814
|
!__classPrivateFieldGet(this, _KycController_moonpayFrameKeypair, "f")) {
|
|
841
815
|
return null;
|
|
842
816
|
}
|
|
843
817
|
const url = new URL(`${FRAMES_BASE_URL}/check-connection`);
|
|
844
|
-
url.searchParams.set('sessionToken', this.state.
|
|
818
|
+
url.searchParams.set('sessionToken', this.state.sessionToken);
|
|
845
819
|
url.searchParams.set('publicKey', __classPrivateFieldGet(this, _KycController_moonpayFrameKeypair, "f").publicKeyHex);
|
|
846
820
|
url.searchParams.set('channelId', CHANNEL_CHECK);
|
|
847
821
|
url.searchParams.set('skipKyc', 'true');
|
|
@@ -883,9 +857,9 @@ class KycController extends base_controller_1.BaseController {
|
|
|
883
857
|
* @returns Whether KYC is required.
|
|
884
858
|
*/
|
|
885
859
|
async checkKycRequired(params) {
|
|
886
|
-
const {
|
|
887
|
-
if (!
|
|
888
|
-
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing
|
|
860
|
+
const { accessToken } = this.state;
|
|
861
|
+
if (!accessToken) {
|
|
862
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing accessToken — repeat the authentication step.');
|
|
889
863
|
return false;
|
|
890
864
|
}
|
|
891
865
|
const country = params.country ?? this.state.geoCountry;
|
|
@@ -901,11 +875,7 @@ class KycController extends base_controller_1.BaseController {
|
|
|
901
875
|
state.statusMessage = 'Checking KYC status...';
|
|
902
876
|
});
|
|
903
877
|
try {
|
|
904
|
-
const { kycRequired } = await this.messenger.call('KycService:checkKycRequired', {
|
|
905
|
-
accessToken: moonpayAccessToken,
|
|
906
|
-
country,
|
|
907
|
-
capabilities: [{ product: params.product }],
|
|
908
|
-
});
|
|
878
|
+
const { kycRequired } = await this.messenger.call('KycService:checkKycRequired', { accessToken, country, capabilities: [{ product: params.product }] });
|
|
909
879
|
// The flow was reset while the check was in flight; discard the result
|
|
910
880
|
// rather than resurrecting a done/cached state on an idle controller.
|
|
911
881
|
const applied = __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
@@ -1190,12 +1160,12 @@ class KycController extends base_controller_1.BaseController {
|
|
|
1190
1160
|
state.phase = 'idle';
|
|
1191
1161
|
state.statusMessage = '';
|
|
1192
1162
|
state.error = null;
|
|
1193
|
-
state.
|
|
1194
|
-
state.
|
|
1163
|
+
state.disclaimers = [];
|
|
1164
|
+
state.disclaimersError = null;
|
|
1195
1165
|
state.sessionDisclaimers = null;
|
|
1196
1166
|
state.credentialReusabilityConsentGiven = null;
|
|
1197
|
-
state.
|
|
1198
|
-
state.
|
|
1167
|
+
state.sessionToken = null;
|
|
1168
|
+
state.accessToken = null;
|
|
1199
1169
|
state.moonpayCustomerId = null;
|
|
1200
1170
|
state.activeVendor = 'moonpay';
|
|
1201
1171
|
state.activeProduct = null;
|
|
@@ -1236,14 +1206,13 @@ _KycController_sumsubLauncher = new WeakMap(), _KycController_moonpayFrameKeypai
|
|
|
1236
1206
|
* SumSub — skipping MoonPay Check/Auth frames.
|
|
1237
1207
|
*
|
|
1238
1208
|
* @param consents - T&C2 flags mapped onto the session disclaimer catalog.
|
|
1239
|
-
* @param consents.
|
|
1240
|
-
* @param consents.
|
|
1209
|
+
* @param consents.sumsubTncSigned - Whether Sumsub T&C were accepted.
|
|
1210
|
+
* @param consents.idosTncSigned - Whether idOS T&C were accepted.
|
|
1241
1211
|
* @param consents.credentialReusabilityConsentGiven - Whether credential
|
|
1242
1212
|
* reuse was accepted.
|
|
1243
1213
|
*/
|
|
1244
1214
|
async function _KycController_startConsentsSession(consents) {
|
|
1245
|
-
const { email } = this.state;
|
|
1246
|
-
const acceptedDisclaimerIds = (0, vendorDisclaimerAcceptance_js_1.ironDisclaimerIds)(this.state.vendorDisclaimersAccepted);
|
|
1215
|
+
const { email, acceptedDisclaimerIds } = this.state;
|
|
1247
1216
|
if (!email) {
|
|
1248
1217
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing email for consents session.');
|
|
1249
1218
|
return;
|
|
@@ -1378,8 +1347,8 @@ async function _KycController_startConsentsSession(consents) {
|
|
|
1378
1347
|
*
|
|
1379
1348
|
* @param sessionId - The UKYC session id.
|
|
1380
1349
|
* @param consents - T&C2 flags mapped onto catalog documents.
|
|
1381
|
-
* @param consents.
|
|
1382
|
-
* @param consents.
|
|
1350
|
+
* @param consents.sumsubTncSigned - Whether Sumsub T&C were accepted.
|
|
1351
|
+
* @param consents.idosTncSigned - Whether idOS T&C were accepted.
|
|
1383
1352
|
* @param consents.credentialReusabilityConsentGiven - Whether credential
|
|
1384
1353
|
* reuse was accepted.
|
|
1385
1354
|
* @param generation - Flow generation captured by the caller.
|
|
@@ -1393,12 +1362,12 @@ async function _KycController_recordSessionDisclaimers(sessionId, consents, gene
|
|
|
1393
1362
|
state.sessionDisclaimers = catalog;
|
|
1394
1363
|
state.statusMessage = 'Submitting consents...';
|
|
1395
1364
|
});
|
|
1396
|
-
if (isAcceptedCategoryEmpty(catalog.idOS, consents.
|
|
1397
|
-
isAcceptedCategoryEmpty(catalog.kycProvider, consents.
|
|
1365
|
+
if (isAcceptedCategoryEmpty(catalog.idOS, consents.idosTncSigned) ||
|
|
1366
|
+
isAcceptedCategoryEmpty(catalog.kycProvider, consents.sumsubTncSigned)) {
|
|
1398
1367
|
throw new Error('Session disclaimer catalog is missing documents for an accepted category.');
|
|
1399
1368
|
}
|
|
1400
|
-
const idOS =
|
|
1401
|
-
const kycProvider =
|
|
1369
|
+
const idOS = consentRecordsFromCatalog(catalog.idOS, consents.idosTncSigned);
|
|
1370
|
+
const kycProvider = consentRecordsFromCatalog(catalog.kycProvider, consents.sumsubTncSigned);
|
|
1402
1371
|
const reuseUnchanged = catalog.credentialReusabilityConsentGiven ===
|
|
1403
1372
|
consents.credentialReusabilityConsentGiven;
|
|
1404
1373
|
if (idOS.length === 0 && kycProvider.length === 0 && reuseUnchanged) {
|
|
@@ -1429,9 +1398,8 @@ async function _KycController_recordSessionDisclaimers(sessionId, consents, gene
|
|
|
1429
1398
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1430
1399
|
state.sessionDisclaimers = latest;
|
|
1431
1400
|
});
|
|
1432
|
-
|
|
1433
|
-
const
|
|
1434
|
-
const stillMissingProvider = acceptedCategoryStillMissing(latest.kycProvider, consents.providerDisclaimersAccepted);
|
|
1401
|
+
const stillMissingIdos = acceptedCategoryStillMissing(latest.idOS, consents.idosTncSigned);
|
|
1402
|
+
const stillMissingProvider = acceptedCategoryStillMissing(latest.kycProvider, consents.sumsubTncSigned);
|
|
1435
1403
|
const stillMissingReuse = consents.credentialReusabilityConsentGiven &&
|
|
1436
1404
|
!latest.credentialReusabilityConsentGiven;
|
|
1437
1405
|
if (stillMissingIdos || stillMissingProvider || stillMissingReuse) {
|
|
@@ -1443,9 +1411,7 @@ async function _KycController_recordSessionDisclaimers(sessionId, consents, gene
|
|
|
1443
1411
|
* Creates a vendor session from the currently stored terms + email.
|
|
1444
1412
|
*/
|
|
1445
1413
|
async function _KycController_createSession() {
|
|
1446
|
-
const { email } = this.state;
|
|
1447
|
-
const termsAcceptedAt = this.state.vendorDisclaimersAccepted.moonpay?.termsAcceptedAt;
|
|
1448
|
-
const acceptedDisclaimerIds = this.state.vendorDisclaimers.map((disclaimer) => disclaimer.id);
|
|
1414
|
+
const { email, termsAcceptedAt, acceptedDisclaimerIds } = this.state;
|
|
1449
1415
|
if (!email) {
|
|
1450
1416
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing email for session creation.');
|
|
1451
1417
|
return;
|
|
@@ -1460,7 +1426,7 @@ async function _KycController_createSession() {
|
|
|
1460
1426
|
// (or, on failure, invalid) session token, `buildAuthFrameUrl` cannot
|
|
1461
1427
|
// return a URL tied to an old client token, and `checkKycRequired` cannot
|
|
1462
1428
|
// run with an access token from an earlier authentication. The Check/Auth
|
|
1463
|
-
// frames re-populate these for the new session. Because `
|
|
1429
|
+
// frames re-populate these for the new session. Because `sessionToken` is
|
|
1464
1430
|
// cleared here and only re-set on success, a failed creation leaves it
|
|
1465
1431
|
// `null` rather than resurrecting the previous session.
|
|
1466
1432
|
// Capture the flow generation so a `reset()` landing while the create
|
|
@@ -1473,13 +1439,13 @@ async function _KycController_createSession() {
|
|
|
1473
1439
|
state.error = null;
|
|
1474
1440
|
state.phase = 'session';
|
|
1475
1441
|
state.statusMessage = 'Creating session...';
|
|
1476
|
-
state.
|
|
1477
|
-
state.
|
|
1442
|
+
state.sessionToken = null;
|
|
1443
|
+
state.accessToken = null;
|
|
1478
1444
|
});
|
|
1479
1445
|
try {
|
|
1480
1446
|
const { sessionToken } = await this.messenger.call('KycService:createSession', { email, termsAcceptedAt, disclaimerIds: acceptedDisclaimerIds });
|
|
1481
1447
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
1482
|
-
state.
|
|
1448
|
+
state.sessionToken = sessionToken;
|
|
1483
1449
|
state.phase = 'check';
|
|
1484
1450
|
state.statusMessage = 'Authenticating via Check frame...';
|
|
1485
1451
|
});
|
|
@@ -1505,17 +1471,29 @@ async function _KycController_createSession() {
|
|
|
1505
1471
|
});
|
|
1506
1472
|
await this.loadDisclaimers();
|
|
1507
1473
|
}
|
|
1508
|
-
}, _KycController_clearAcceptedTerms = function _KycController_clearAcceptedTerms(state
|
|
1509
|
-
|
|
1510
|
-
state.
|
|
1511
|
-
state.
|
|
1512
|
-
|
|
1513
|
-
state.
|
|
1474
|
+
}, _KycController_clearAcceptedTerms = function _KycController_clearAcceptedTerms(state) {
|
|
1475
|
+
state.termsAcceptedAt = null;
|
|
1476
|
+
state.acceptedDisclaimerIds = [];
|
|
1477
|
+
state.termsAcceptedVendor = null;
|
|
1478
|
+
state.sumsubTncAccepted = null;
|
|
1479
|
+
state.idosTncAccepted = null;
|
|
1514
1480
|
state.credentialReusabilityConsentGiven = null;
|
|
1515
1481
|
}, _KycController_clearMoonPaySession = function _KycController_clearMoonPaySession(state) {
|
|
1516
1482
|
state.moonpayCustomerId = null;
|
|
1517
|
-
state.
|
|
1518
|
-
state.
|
|
1483
|
+
state.sessionToken = null;
|
|
1484
|
+
state.accessToken = null;
|
|
1485
|
+
}, _KycController_dropTermsUnlessForVendor = function _KycController_dropTermsUnlessForVendor(vendor) {
|
|
1486
|
+
if (__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_hasTermsForVendor).call(this, vendor)) {
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1490
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
1491
|
+
});
|
|
1492
|
+
}, _KycController_hasTermsForVendor = function _KycController_hasTermsForVendor(vendor) {
|
|
1493
|
+
if (this.state.termsAcceptedVendor === null) {
|
|
1494
|
+
return false;
|
|
1495
|
+
}
|
|
1496
|
+
return this.state.termsAcceptedVendor === vendor;
|
|
1519
1497
|
}, _KycController_handleCheckOutcome =
|
|
1520
1498
|
/**
|
|
1521
1499
|
* Applies a Check-frame outcome.
|
|
@@ -1527,7 +1505,7 @@ async function _KycController_createSession() {
|
|
|
1527
1505
|
async function _KycController_handleCheckOutcome(status, accessToken, clientToken) {
|
|
1528
1506
|
if (status === 'active' && accessToken) {
|
|
1529
1507
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1530
|
-
state.
|
|
1508
|
+
state.accessToken = accessToken;
|
|
1531
1509
|
state.phase = 'form';
|
|
1532
1510
|
state.statusMessage = 'Already authenticated. Review to submit.';
|
|
1533
1511
|
});
|
|
@@ -1557,7 +1535,7 @@ async function _KycController_handleCheckOutcome(status, accessToken, clientToke
|
|
|
1557
1535
|
async function _KycController_handleAuthOutcome(status, accessToken) {
|
|
1558
1536
|
if (status === 'active' && accessToken) {
|
|
1559
1537
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1560
|
-
state.
|
|
1538
|
+
state.accessToken = accessToken;
|
|
1561
1539
|
state.phase = 'form';
|
|
1562
1540
|
state.statusMessage = 'Authenticated. Review to submit.';
|
|
1563
1541
|
});
|
|
@@ -1620,7 +1598,7 @@ async function _KycController_continueAfterAuthentication() {
|
|
|
1620
1598
|
return {
|
|
1621
1599
|
vendor: 'moonpay',
|
|
1622
1600
|
vendorMetadata: {
|
|
1623
|
-
moonPayAccessToken: this.state.
|
|
1601
|
+
moonPayAccessToken: this.state.accessToken,
|
|
1624
1602
|
moonPayUserId: this.state.moonpayCustomerId,
|
|
1625
1603
|
},
|
|
1626
1604
|
};
|