@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.mjs
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
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;
|
|
12
|
+
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;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
import { stringToBytes } from "@metamask/utils";
|
|
15
15
|
import { x25519 } from "@noble/curves/ed25519";
|
|
@@ -21,7 +21,6 @@ import { verifyJwtChain } from "./ukyc/jwtChain.mjs";
|
|
|
21
21
|
import { getOrCreateLocalUserSecret } from "./ukyc/localUserSecret.mjs";
|
|
22
22
|
import { encodeStorageAccessTokenForHeader, signStorageAccessToken } from "./ukyc/storageAccessToken.mjs";
|
|
23
23
|
import { wrapEncryptionKey } from "./ukyc/wrapEncryptionKey.mjs";
|
|
24
|
-
import { clearVendorDisclaimerAcceptance, hasVendorDisclaimerAcceptance, ironDisclaimerIds, recordVendorDisclaimerAcceptance } from "./vendorDisclaimerAcceptance.mjs";
|
|
25
24
|
// === GENERAL ===
|
|
26
25
|
export const controllerName = 'KycController';
|
|
27
26
|
const FRAMES_BASE_URL = 'https://blocks.moonpay.com/platform/v1';
|
|
@@ -118,19 +117,31 @@ const kycControllerMetadata = {
|
|
|
118
117
|
persist: false,
|
|
119
118
|
usedInUi: false,
|
|
120
119
|
},
|
|
121
|
-
|
|
120
|
+
termsAcceptedAt: {
|
|
122
121
|
includeInDebugSnapshot: true,
|
|
123
122
|
includeInStateLogs: true,
|
|
124
123
|
persist: true,
|
|
125
124
|
usedInUi: false,
|
|
126
125
|
},
|
|
127
|
-
|
|
126
|
+
acceptedDisclaimerIds: {
|
|
128
127
|
includeInDebugSnapshot: true,
|
|
129
128
|
includeInStateLogs: true,
|
|
130
129
|
persist: true,
|
|
131
130
|
usedInUi: false,
|
|
132
131
|
},
|
|
133
|
-
|
|
132
|
+
termsAcceptedVendor: {
|
|
133
|
+
includeInDebugSnapshot: true,
|
|
134
|
+
includeInStateLogs: true,
|
|
135
|
+
persist: true,
|
|
136
|
+
usedInUi: false,
|
|
137
|
+
},
|
|
138
|
+
sumsubTncAccepted: {
|
|
139
|
+
includeInDebugSnapshot: true,
|
|
140
|
+
includeInStateLogs: true,
|
|
141
|
+
persist: true,
|
|
142
|
+
usedInUi: false,
|
|
143
|
+
},
|
|
144
|
+
idosTncAccepted: {
|
|
134
145
|
includeInDebugSnapshot: true,
|
|
135
146
|
includeInStateLogs: true,
|
|
136
147
|
persist: true,
|
|
@@ -142,13 +153,13 @@ const kycControllerMetadata = {
|
|
|
142
153
|
persist: false,
|
|
143
154
|
usedInUi: false,
|
|
144
155
|
},
|
|
145
|
-
|
|
156
|
+
disclaimers: {
|
|
146
157
|
includeInDebugSnapshot: false,
|
|
147
158
|
includeInStateLogs: false,
|
|
148
159
|
persist: false,
|
|
149
160
|
usedInUi: true,
|
|
150
161
|
},
|
|
151
|
-
|
|
162
|
+
disclaimersError: {
|
|
152
163
|
includeInDebugSnapshot: true,
|
|
153
164
|
includeInStateLogs: true,
|
|
154
165
|
persist: false,
|
|
@@ -166,13 +177,13 @@ const kycControllerMetadata = {
|
|
|
166
177
|
persist: false,
|
|
167
178
|
usedInUi: true,
|
|
168
179
|
},
|
|
169
|
-
|
|
180
|
+
sessionToken: {
|
|
170
181
|
includeInDebugSnapshot: false,
|
|
171
182
|
includeInStateLogs: false,
|
|
172
183
|
persist: false,
|
|
173
184
|
usedInUi: false,
|
|
174
185
|
},
|
|
175
|
-
|
|
186
|
+
accessToken: {
|
|
176
187
|
includeInDebugSnapshot: false,
|
|
177
188
|
includeInStateLogs: false,
|
|
178
189
|
persist: false,
|
|
@@ -233,17 +244,6 @@ const kycControllerMetadata = {
|
|
|
233
244
|
usedInUi: true,
|
|
234
245
|
},
|
|
235
246
|
};
|
|
236
|
-
/**
|
|
237
|
-
* Constructs the default {@link KycVendorDisclaimersAccepted} value.
|
|
238
|
-
*
|
|
239
|
-
* @returns The default vendor-disclaimer acceptance map.
|
|
240
|
-
*/
|
|
241
|
-
export function getDefaultKycVendorDisclaimersAccepted() {
|
|
242
|
-
return { moonpay: null, iron: null };
|
|
243
|
-
}
|
|
244
|
-
export function getDefaultKycProviderDisclaimersAccepted() {
|
|
245
|
-
return { sumsub: null };
|
|
246
|
-
}
|
|
247
247
|
/**
|
|
248
248
|
* Constructs the default {@link KycController} state.
|
|
249
249
|
*
|
|
@@ -255,16 +255,18 @@ export function getDefaultKycControllerState() {
|
|
|
255
255
|
statusMessage: '',
|
|
256
256
|
error: null,
|
|
257
257
|
email: null,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
termsAcceptedAt: null,
|
|
259
|
+
acceptedDisclaimerIds: [],
|
|
260
|
+
termsAcceptedVendor: null,
|
|
261
|
+
sumsubTncAccepted: null,
|
|
262
|
+
idosTncAccepted: null,
|
|
261
263
|
credentialReusabilityConsentGiven: null,
|
|
262
|
-
|
|
263
|
-
|
|
264
|
+
disclaimers: [],
|
|
265
|
+
disclaimersError: null,
|
|
264
266
|
sessionDisclaimers: null,
|
|
265
267
|
geoCountry: null,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
+
sessionToken: null,
|
|
269
|
+
accessToken: null,
|
|
268
270
|
moonpayCustomerId: null,
|
|
269
271
|
activeVendor: 'moonpay',
|
|
270
272
|
activeProduct: null,
|
|
@@ -308,62 +310,45 @@ function isConsentConflictError(error) {
|
|
|
308
310
|
error.httpStatus === 409);
|
|
309
311
|
}
|
|
310
312
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*/
|
|
315
|
-
function isValidConsentRecordList(value) {
|
|
316
|
-
return (Array.isArray(value) &&
|
|
317
|
-
value.every((item) => typeof item === 'object' &&
|
|
318
|
-
item !== null &&
|
|
319
|
-
typeof item.key === 'string' &&
|
|
320
|
-
typeof item.version === 'string'));
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Maps accepted disclaimer records onto unconsented catalog documents.
|
|
313
|
+
* Maps a session-disclaimer catalog into the `{ key, version }` records the
|
|
314
|
+
* record-consents API expects, or an empty list when the user declined that
|
|
315
|
+
* category.
|
|
324
316
|
*
|
|
325
317
|
* @param documents - Catalog documents for one consent category.
|
|
326
|
-
* @param accepted -
|
|
327
|
-
* @returns Consent records
|
|
318
|
+
* @param accepted - Whether the user accepted that category.
|
|
319
|
+
* @returns Consent records, or `[]` when not accepted.
|
|
328
320
|
*/
|
|
329
|
-
function
|
|
330
|
-
if (accepted
|
|
321
|
+
function consentRecordsFromCatalog(documents, accepted) {
|
|
322
|
+
if (!accepted) {
|
|
331
323
|
return [];
|
|
332
324
|
}
|
|
333
|
-
const acceptedKeys = new Set(accepted.map((record) => `${record.key}:${record.version}`));
|
|
334
325
|
return documents
|
|
335
|
-
.filter((document) => !document.consented
|
|
336
|
-
acceptedKeys.has(`${document.key}:${document.version}`))
|
|
326
|
+
.filter((document) => !document.consented)
|
|
337
327
|
.map(({ key, version }) => ({ key, version }));
|
|
338
328
|
}
|
|
339
329
|
/**
|
|
340
|
-
* Whether accepted
|
|
330
|
+
* Whether an accepted T&C2 category has no catalog documents. An empty list
|
|
331
|
+
* would otherwise skip the POST and count as success.
|
|
341
332
|
*
|
|
342
333
|
* @param documents - Catalog documents for one consent category.
|
|
343
|
-
* @param accepted -
|
|
344
|
-
* @returns `true` when the
|
|
334
|
+
* @param accepted - Whether the user accepted that category.
|
|
335
|
+
* @returns `true` when the user accepted and the catalog is empty.
|
|
345
336
|
*/
|
|
346
337
|
function isAcceptedCategoryEmpty(documents, accepted) {
|
|
347
|
-
return accepted
|
|
338
|
+
return accepted && documents.length === 0;
|
|
348
339
|
}
|
|
349
340
|
/**
|
|
350
|
-
* Whether accepted
|
|
351
|
-
* empty catalog or any
|
|
341
|
+
* Whether an accepted category is still missing consent after a 409 re-GET:
|
|
342
|
+
* empty catalog or any document still unconsented.
|
|
352
343
|
*
|
|
353
344
|
* @param documents - Latest catalog documents for one consent category.
|
|
354
|
-
* @param accepted -
|
|
345
|
+
* @param accepted - Whether the user accepted that category.
|
|
355
346
|
* @returns `true` when accepted documents are not fully consented.
|
|
356
347
|
*/
|
|
357
348
|
function acceptedCategoryStillMissing(documents, accepted) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (documents.length === 0) {
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
364
|
-
const acceptedKeys = new Set(accepted.map((record) => `${record.key}:${record.version}`));
|
|
365
|
-
const relevant = documents.filter((document) => acceptedKeys.has(`${document.key}:${document.version}`));
|
|
366
|
-
return (relevant.length === 0 || relevant.some((document) => !document.consented));
|
|
349
|
+
return (accepted &&
|
|
350
|
+
(documents.length === 0 ||
|
|
351
|
+
documents.some((document) => !document.consented)));
|
|
367
352
|
}
|
|
368
353
|
/**
|
|
369
354
|
* Vendors other than MoonPay skip Check/Auth frames and use the empty-shell
|
|
@@ -510,8 +495,8 @@ export class KycController extends BaseController {
|
|
|
510
495
|
}
|
|
511
496
|
state.activeVendor = vendor;
|
|
512
497
|
// MoonPay Check/Auth artifacts must not survive a switch to another
|
|
513
|
-
// vendor: leftover `
|
|
514
|
-
// leftover `
|
|
498
|
+
// vendor: leftover `sessionToken` would keep `buildCheckFrameUrl` alive,
|
|
499
|
+
// leftover `accessToken` / `#authClientToken` would keep Auth / KYC
|
|
515
500
|
// calls bound to MoonPay, and leftover `moonpayCustomerId` would make
|
|
516
501
|
// `getCustomerIdentity` report a MoonPay id under the wrong vendor.
|
|
517
502
|
if (vendor !== 'moonpay') {
|
|
@@ -564,14 +549,16 @@ export class KycController extends BaseController {
|
|
|
564
549
|
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
565
550
|
return;
|
|
566
551
|
}
|
|
567
|
-
|
|
552
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_dropTermsUnlessForVendor).call(this, vendor);
|
|
553
|
+
const hasTerms = Boolean(this.state.termsAcceptedAt) &&
|
|
554
|
+
this.state.acceptedDisclaimerIds.length > 0;
|
|
568
555
|
if (hasTerms && this.state.email) {
|
|
569
556
|
if (usesConsentsFlow(vendor)) {
|
|
570
557
|
// Consents-path vendors require T&C2 flags; if they weren't persisted
|
|
571
558
|
// (i.e. null from pre-migration state), require reacceptance.
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
559
|
+
const sumsubTncSigned = this.state.sumsubTncAccepted;
|
|
560
|
+
const idosTncSigned = this.state.idosTncAccepted;
|
|
561
|
+
if (sumsubTncSigned === null || idosTncSigned === null) {
|
|
575
562
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
576
563
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
577
564
|
state.phase = 'terms';
|
|
@@ -580,19 +567,12 @@ export class KycController extends BaseController {
|
|
|
580
567
|
return;
|
|
581
568
|
}
|
|
582
569
|
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_startConsentsSession).call(this, {
|
|
583
|
-
|
|
584
|
-
|
|
570
|
+
sumsubTncSigned,
|
|
571
|
+
idosTncSigned,
|
|
585
572
|
credentialReusabilityConsentGiven: this.state.credentialReusabilityConsentGiven ?? false,
|
|
586
573
|
});
|
|
587
574
|
}
|
|
588
575
|
else {
|
|
589
|
-
// TODO: should this be here? or should it exist at all?
|
|
590
|
-
if (vendor === 'moonpay' && this.state.vendorDisclaimers.length === 0) {
|
|
591
|
-
await this.loadDisclaimers();
|
|
592
|
-
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
576
|
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_createSession).call(this);
|
|
597
577
|
}
|
|
598
578
|
return;
|
|
@@ -637,6 +617,10 @@ export class KycController extends BaseController {
|
|
|
637
617
|
vendor: params.vendor,
|
|
638
618
|
email: params.email,
|
|
639
619
|
});
|
|
620
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_dropTermsUnlessForVendor).call(this, params.vendor);
|
|
640
624
|
}
|
|
641
625
|
catch (error) {
|
|
642
626
|
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
@@ -670,13 +654,13 @@ export class KycController extends BaseController {
|
|
|
670
654
|
country,
|
|
671
655
|
});
|
|
672
656
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
673
|
-
state.
|
|
674
|
-
state.
|
|
657
|
+
state.disclaimers = disclaimers;
|
|
658
|
+
state.disclaimersError = null;
|
|
675
659
|
});
|
|
676
660
|
}
|
|
677
661
|
catch (error) {
|
|
678
662
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
679
|
-
state.
|
|
663
|
+
state.disclaimersError = `Failed to load disclaimers: ${String(error)}`;
|
|
680
664
|
});
|
|
681
665
|
}
|
|
682
666
|
}
|
|
@@ -689,47 +673,44 @@ export class KycController extends BaseController {
|
|
|
689
673
|
* @param params.product - The consuming feature the flow runs for. See
|
|
690
674
|
* {@link initialize} for how the product drives the automatic post
|
|
691
675
|
* authentication continuation.
|
|
692
|
-
* @param params.
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
* customer accepted (`{ key, version }` records). Required for every vendor
|
|
697
|
-
* so callers explicitly declare acceptance.
|
|
676
|
+
* @param params.sumsubTncSigned - Whether Sumsub T&C were accepted (T&C2).
|
|
677
|
+
* Required for every vendor so callers explicitly declare acceptance.
|
|
678
|
+
* @param params.idosTncSigned - Whether idOS T&C were accepted (T&C2).
|
|
679
|
+
* Required for every vendor so callers explicitly declare acceptance.
|
|
698
680
|
* @param params.credentialReusabilityConsentGiven - Whether the customer
|
|
699
681
|
* consented to reuse existing idOS credentials. Used when recording
|
|
700
682
|
* session-scoped disclaimers on the consents path. Defaults to `false`.
|
|
701
683
|
*/
|
|
702
684
|
async acceptTermsAndStartSession(params) {
|
|
703
|
-
const
|
|
704
|
-
const
|
|
705
|
-
if (
|
|
706
|
-
|
|
685
|
+
const sumsubTncSigned = params?.sumsubTncSigned;
|
|
686
|
+
const idosTncSigned = params?.idosTncSigned;
|
|
687
|
+
if (typeof sumsubTncSigned !== 'boolean' ||
|
|
688
|
+
typeof idosTncSigned !== 'boolean') {
|
|
707
689
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing T&C2 acceptance flags.');
|
|
708
690
|
return;
|
|
709
691
|
}
|
|
710
|
-
const credentialReusabilityConsentGiven = params
|
|
692
|
+
const credentialReusabilityConsentGiven = params.credentialReusabilityConsentGiven ?? false;
|
|
711
693
|
const termsAcceptedAt = new Date().toISOString();
|
|
712
|
-
const disclaimerIds = this.state.
|
|
694
|
+
const disclaimerIds = this.state.disclaimers.map((disclaimer) => disclaimer.id);
|
|
713
695
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
714
|
-
if (params
|
|
696
|
+
if (params.email) {
|
|
715
697
|
state.email = params.email;
|
|
716
698
|
}
|
|
717
|
-
if (params
|
|
699
|
+
if (params.product) {
|
|
718
700
|
state.activeProduct = params.product;
|
|
719
701
|
}
|
|
720
|
-
state.
|
|
721
|
-
state.
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
state.idosDisclaimersAccepted = idosDisclaimersAccepted;
|
|
702
|
+
state.termsAcceptedAt = termsAcceptedAt;
|
|
703
|
+
state.acceptedDisclaimerIds = disclaimerIds;
|
|
704
|
+
state.termsAcceptedVendor = state.activeVendor;
|
|
705
|
+
state.sumsubTncAccepted = sumsubTncSigned;
|
|
706
|
+
state.idosTncAccepted = idosTncSigned;
|
|
726
707
|
state.credentialReusabilityConsentGiven =
|
|
727
708
|
credentialReusabilityConsentGiven;
|
|
728
709
|
});
|
|
729
710
|
if (usesConsentsFlow(this.state.activeVendor)) {
|
|
730
711
|
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_startConsentsSession).call(this, {
|
|
731
|
-
|
|
732
|
-
|
|
712
|
+
sumsubTncSigned,
|
|
713
|
+
idosTncSigned,
|
|
733
714
|
credentialReusabilityConsentGiven,
|
|
734
715
|
});
|
|
735
716
|
return;
|
|
@@ -741,12 +722,7 @@ export class KycController extends BaseController {
|
|
|
741
722
|
*/
|
|
742
723
|
clearSavedTerms() {
|
|
743
724
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
744
|
-
|
|
745
|
-
getDefaultKycVendorDisclaimersAccepted();
|
|
746
|
-
state.providerDisclaimersAccepted =
|
|
747
|
-
getDefaultKycProviderDisclaimersAccepted();
|
|
748
|
-
state.idosDisclaimersAccepted = null;
|
|
749
|
-
state.credentialReusabilityConsentGiven = null;
|
|
725
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
750
726
|
});
|
|
751
727
|
}
|
|
752
728
|
/**
|
|
@@ -830,12 +806,12 @@ export class KycController extends BaseController {
|
|
|
830
806
|
*/
|
|
831
807
|
buildCheckFrameUrl() {
|
|
832
808
|
if (this.state.activeVendor !== 'moonpay' ||
|
|
833
|
-
!this.state.
|
|
809
|
+
!this.state.sessionToken ||
|
|
834
810
|
!__classPrivateFieldGet(this, _KycController_moonpayFrameKeypair, "f")) {
|
|
835
811
|
return null;
|
|
836
812
|
}
|
|
837
813
|
const url = new URL(`${FRAMES_BASE_URL}/check-connection`);
|
|
838
|
-
url.searchParams.set('sessionToken', this.state.
|
|
814
|
+
url.searchParams.set('sessionToken', this.state.sessionToken);
|
|
839
815
|
url.searchParams.set('publicKey', __classPrivateFieldGet(this, _KycController_moonpayFrameKeypair, "f").publicKeyHex);
|
|
840
816
|
url.searchParams.set('channelId', CHANNEL_CHECK);
|
|
841
817
|
url.searchParams.set('skipKyc', 'true');
|
|
@@ -877,9 +853,9 @@ export class KycController extends BaseController {
|
|
|
877
853
|
* @returns Whether KYC is required.
|
|
878
854
|
*/
|
|
879
855
|
async checkKycRequired(params) {
|
|
880
|
-
const {
|
|
881
|
-
if (!
|
|
882
|
-
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing
|
|
856
|
+
const { accessToken } = this.state;
|
|
857
|
+
if (!accessToken) {
|
|
858
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing accessToken — repeat the authentication step.');
|
|
883
859
|
return false;
|
|
884
860
|
}
|
|
885
861
|
const country = params.country ?? this.state.geoCountry;
|
|
@@ -895,11 +871,7 @@ export class KycController extends BaseController {
|
|
|
895
871
|
state.statusMessage = 'Checking KYC status...';
|
|
896
872
|
});
|
|
897
873
|
try {
|
|
898
|
-
const { kycRequired } = await this.messenger.call('KycService:checkKycRequired', {
|
|
899
|
-
accessToken: moonpayAccessToken,
|
|
900
|
-
country,
|
|
901
|
-
capabilities: [{ product: params.product }],
|
|
902
|
-
});
|
|
874
|
+
const { kycRequired } = await this.messenger.call('KycService:checkKycRequired', { accessToken, country, capabilities: [{ product: params.product }] });
|
|
903
875
|
// The flow was reset while the check was in flight; discard the result
|
|
904
876
|
// rather than resurrecting a done/cached state on an idle controller.
|
|
905
877
|
const applied = __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
@@ -1184,12 +1156,12 @@ export class KycController extends BaseController {
|
|
|
1184
1156
|
state.phase = 'idle';
|
|
1185
1157
|
state.statusMessage = '';
|
|
1186
1158
|
state.error = null;
|
|
1187
|
-
state.
|
|
1188
|
-
state.
|
|
1159
|
+
state.disclaimers = [];
|
|
1160
|
+
state.disclaimersError = null;
|
|
1189
1161
|
state.sessionDisclaimers = null;
|
|
1190
1162
|
state.credentialReusabilityConsentGiven = null;
|
|
1191
|
-
state.
|
|
1192
|
-
state.
|
|
1163
|
+
state.sessionToken = null;
|
|
1164
|
+
state.accessToken = null;
|
|
1193
1165
|
state.moonpayCustomerId = null;
|
|
1194
1166
|
state.activeVendor = 'moonpay';
|
|
1195
1167
|
state.activeProduct = null;
|
|
@@ -1229,14 +1201,13 @@ _KycController_sumsubLauncher = new WeakMap(), _KycController_moonpayFrameKeypai
|
|
|
1229
1201
|
* SumSub — skipping MoonPay Check/Auth frames.
|
|
1230
1202
|
*
|
|
1231
1203
|
* @param consents - T&C2 flags mapped onto the session disclaimer catalog.
|
|
1232
|
-
* @param consents.
|
|
1233
|
-
* @param consents.
|
|
1204
|
+
* @param consents.sumsubTncSigned - Whether Sumsub T&C were accepted.
|
|
1205
|
+
* @param consents.idosTncSigned - Whether idOS T&C were accepted.
|
|
1234
1206
|
* @param consents.credentialReusabilityConsentGiven - Whether credential
|
|
1235
1207
|
* reuse was accepted.
|
|
1236
1208
|
*/
|
|
1237
1209
|
async function _KycController_startConsentsSession(consents) {
|
|
1238
|
-
const { email } = this.state;
|
|
1239
|
-
const acceptedDisclaimerIds = ironDisclaimerIds(this.state.vendorDisclaimersAccepted);
|
|
1210
|
+
const { email, acceptedDisclaimerIds } = this.state;
|
|
1240
1211
|
if (!email) {
|
|
1241
1212
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing email for consents session.');
|
|
1242
1213
|
return;
|
|
@@ -1371,8 +1342,8 @@ async function _KycController_startConsentsSession(consents) {
|
|
|
1371
1342
|
*
|
|
1372
1343
|
* @param sessionId - The UKYC session id.
|
|
1373
1344
|
* @param consents - T&C2 flags mapped onto catalog documents.
|
|
1374
|
-
* @param consents.
|
|
1375
|
-
* @param consents.
|
|
1345
|
+
* @param consents.sumsubTncSigned - Whether Sumsub T&C were accepted.
|
|
1346
|
+
* @param consents.idosTncSigned - Whether idOS T&C were accepted.
|
|
1376
1347
|
* @param consents.credentialReusabilityConsentGiven - Whether credential
|
|
1377
1348
|
* reuse was accepted.
|
|
1378
1349
|
* @param generation - Flow generation captured by the caller.
|
|
@@ -1386,12 +1357,12 @@ async function _KycController_recordSessionDisclaimers(sessionId, consents, gene
|
|
|
1386
1357
|
state.sessionDisclaimers = catalog;
|
|
1387
1358
|
state.statusMessage = 'Submitting consents...';
|
|
1388
1359
|
});
|
|
1389
|
-
if (isAcceptedCategoryEmpty(catalog.idOS, consents.
|
|
1390
|
-
isAcceptedCategoryEmpty(catalog.kycProvider, consents.
|
|
1360
|
+
if (isAcceptedCategoryEmpty(catalog.idOS, consents.idosTncSigned) ||
|
|
1361
|
+
isAcceptedCategoryEmpty(catalog.kycProvider, consents.sumsubTncSigned)) {
|
|
1391
1362
|
throw new Error('Session disclaimer catalog is missing documents for an accepted category.');
|
|
1392
1363
|
}
|
|
1393
|
-
const idOS =
|
|
1394
|
-
const kycProvider =
|
|
1364
|
+
const idOS = consentRecordsFromCatalog(catalog.idOS, consents.idosTncSigned);
|
|
1365
|
+
const kycProvider = consentRecordsFromCatalog(catalog.kycProvider, consents.sumsubTncSigned);
|
|
1395
1366
|
const reuseUnchanged = catalog.credentialReusabilityConsentGiven ===
|
|
1396
1367
|
consents.credentialReusabilityConsentGiven;
|
|
1397
1368
|
if (idOS.length === 0 && kycProvider.length === 0 && reuseUnchanged) {
|
|
@@ -1422,9 +1393,8 @@ async function _KycController_recordSessionDisclaimers(sessionId, consents, gene
|
|
|
1422
1393
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1423
1394
|
state.sessionDisclaimers = latest;
|
|
1424
1395
|
});
|
|
1425
|
-
|
|
1426
|
-
const
|
|
1427
|
-
const stillMissingProvider = acceptedCategoryStillMissing(latest.kycProvider, consents.providerDisclaimersAccepted);
|
|
1396
|
+
const stillMissingIdos = acceptedCategoryStillMissing(latest.idOS, consents.idosTncSigned);
|
|
1397
|
+
const stillMissingProvider = acceptedCategoryStillMissing(latest.kycProvider, consents.sumsubTncSigned);
|
|
1428
1398
|
const stillMissingReuse = consents.credentialReusabilityConsentGiven &&
|
|
1429
1399
|
!latest.credentialReusabilityConsentGiven;
|
|
1430
1400
|
if (stillMissingIdos || stillMissingProvider || stillMissingReuse) {
|
|
@@ -1436,9 +1406,7 @@ async function _KycController_recordSessionDisclaimers(sessionId, consents, gene
|
|
|
1436
1406
|
* Creates a vendor session from the currently stored terms + email.
|
|
1437
1407
|
*/
|
|
1438
1408
|
async function _KycController_createSession() {
|
|
1439
|
-
const { email } = this.state;
|
|
1440
|
-
const termsAcceptedAt = this.state.vendorDisclaimersAccepted.moonpay?.termsAcceptedAt;
|
|
1441
|
-
const acceptedDisclaimerIds = this.state.vendorDisclaimers.map((disclaimer) => disclaimer.id);
|
|
1409
|
+
const { email, termsAcceptedAt, acceptedDisclaimerIds } = this.state;
|
|
1442
1410
|
if (!email) {
|
|
1443
1411
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing email for session creation.');
|
|
1444
1412
|
return;
|
|
@@ -1453,7 +1421,7 @@ async function _KycController_createSession() {
|
|
|
1453
1421
|
// (or, on failure, invalid) session token, `buildAuthFrameUrl` cannot
|
|
1454
1422
|
// return a URL tied to an old client token, and `checkKycRequired` cannot
|
|
1455
1423
|
// run with an access token from an earlier authentication. The Check/Auth
|
|
1456
|
-
// frames re-populate these for the new session. Because `
|
|
1424
|
+
// frames re-populate these for the new session. Because `sessionToken` is
|
|
1457
1425
|
// cleared here and only re-set on success, a failed creation leaves it
|
|
1458
1426
|
// `null` rather than resurrecting the previous session.
|
|
1459
1427
|
// Capture the flow generation so a `reset()` landing while the create
|
|
@@ -1466,13 +1434,13 @@ async function _KycController_createSession() {
|
|
|
1466
1434
|
state.error = null;
|
|
1467
1435
|
state.phase = 'session';
|
|
1468
1436
|
state.statusMessage = 'Creating session...';
|
|
1469
|
-
state.
|
|
1470
|
-
state.
|
|
1437
|
+
state.sessionToken = null;
|
|
1438
|
+
state.accessToken = null;
|
|
1471
1439
|
});
|
|
1472
1440
|
try {
|
|
1473
1441
|
const { sessionToken } = await this.messenger.call('KycService:createSession', { email, termsAcceptedAt, disclaimerIds: acceptedDisclaimerIds });
|
|
1474
1442
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
1475
|
-
state.
|
|
1443
|
+
state.sessionToken = sessionToken;
|
|
1476
1444
|
state.phase = 'check';
|
|
1477
1445
|
state.statusMessage = 'Authenticating via Check frame...';
|
|
1478
1446
|
});
|
|
@@ -1498,17 +1466,29 @@ async function _KycController_createSession() {
|
|
|
1498
1466
|
});
|
|
1499
1467
|
await this.loadDisclaimers();
|
|
1500
1468
|
}
|
|
1501
|
-
}, _KycController_clearAcceptedTerms = function _KycController_clearAcceptedTerms(state
|
|
1502
|
-
|
|
1503
|
-
state.
|
|
1504
|
-
state.
|
|
1505
|
-
|
|
1506
|
-
state.
|
|
1469
|
+
}, _KycController_clearAcceptedTerms = function _KycController_clearAcceptedTerms(state) {
|
|
1470
|
+
state.termsAcceptedAt = null;
|
|
1471
|
+
state.acceptedDisclaimerIds = [];
|
|
1472
|
+
state.termsAcceptedVendor = null;
|
|
1473
|
+
state.sumsubTncAccepted = null;
|
|
1474
|
+
state.idosTncAccepted = null;
|
|
1507
1475
|
state.credentialReusabilityConsentGiven = null;
|
|
1508
1476
|
}, _KycController_clearMoonPaySession = function _KycController_clearMoonPaySession(state) {
|
|
1509
1477
|
state.moonpayCustomerId = null;
|
|
1510
|
-
state.
|
|
1511
|
-
state.
|
|
1478
|
+
state.sessionToken = null;
|
|
1479
|
+
state.accessToken = null;
|
|
1480
|
+
}, _KycController_dropTermsUnlessForVendor = function _KycController_dropTermsUnlessForVendor(vendor) {
|
|
1481
|
+
if (__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_hasTermsForVendor).call(this, vendor)) {
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1485
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
1486
|
+
});
|
|
1487
|
+
}, _KycController_hasTermsForVendor = function _KycController_hasTermsForVendor(vendor) {
|
|
1488
|
+
if (this.state.termsAcceptedVendor === null) {
|
|
1489
|
+
return false;
|
|
1490
|
+
}
|
|
1491
|
+
return this.state.termsAcceptedVendor === vendor;
|
|
1512
1492
|
}, _KycController_handleCheckOutcome =
|
|
1513
1493
|
/**
|
|
1514
1494
|
* Applies a Check-frame outcome.
|
|
@@ -1520,7 +1500,7 @@ async function _KycController_createSession() {
|
|
|
1520
1500
|
async function _KycController_handleCheckOutcome(status, accessToken, clientToken) {
|
|
1521
1501
|
if (status === 'active' && accessToken) {
|
|
1522
1502
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1523
|
-
state.
|
|
1503
|
+
state.accessToken = accessToken;
|
|
1524
1504
|
state.phase = 'form';
|
|
1525
1505
|
state.statusMessage = 'Already authenticated. Review to submit.';
|
|
1526
1506
|
});
|
|
@@ -1550,7 +1530,7 @@ async function _KycController_handleCheckOutcome(status, accessToken, clientToke
|
|
|
1550
1530
|
async function _KycController_handleAuthOutcome(status, accessToken) {
|
|
1551
1531
|
if (status === 'active' && accessToken) {
|
|
1552
1532
|
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
1553
|
-
state.
|
|
1533
|
+
state.accessToken = accessToken;
|
|
1554
1534
|
state.phase = 'form';
|
|
1555
1535
|
state.statusMessage = 'Authenticated. Review to submit.';
|
|
1556
1536
|
});
|
|
@@ -1613,7 +1593,7 @@ async function _KycController_continueAfterAuthentication() {
|
|
|
1613
1593
|
return {
|
|
1614
1594
|
vendor: 'moonpay',
|
|
1615
1595
|
vendorMetadata: {
|
|
1616
|
-
moonPayAccessToken: this.state.
|
|
1596
|
+
moonPayAccessToken: this.state.accessToken,
|
|
1617
1597
|
moonPayUserId: this.state.moonpayCustomerId,
|
|
1618
1598
|
},
|
|
1619
1599
|
};
|