@metamask-previews/kyc-controller 0.0.0-preview-11d78534e
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 +21 -0
- package/LICENSE +6 -0
- package/LICENSE.APACHE2 +201 -0
- package/LICENSE.MIT +21 -0
- package/README.md +648 -0
- package/dist/KycController-method-action-types.cjs +7 -0
- package/dist/KycController-method-action-types.cjs.map +1 -0
- package/dist/KycController-method-action-types.d.cts +143 -0
- package/dist/KycController-method-action-types.d.cts.map +1 -0
- package/dist/KycController-method-action-types.d.mts +143 -0
- package/dist/KycController-method-action-types.d.mts.map +1 -0
- package/dist/KycController-method-action-types.mjs +6 -0
- package/dist/KycController-method-action-types.mjs.map +1 -0
- package/dist/KycController.cjs +800 -0
- package/dist/KycController.cjs.map +1 -0
- package/dist/KycController.d.cts +219 -0
- package/dist/KycController.d.cts.map +1 -0
- package/dist/KycController.d.mts +219 -0
- package/dist/KycController.d.mts.map +1 -0
- package/dist/KycController.mjs +795 -0
- package/dist/KycController.mjs.map +1 -0
- package/dist/KycService-method-action-types.cjs +7 -0
- package/dist/KycService-method-action-types.cjs.map +1 -0
- package/dist/KycService-method-action-types.d.cts +74 -0
- package/dist/KycService-method-action-types.d.cts.map +1 -0
- package/dist/KycService-method-action-types.d.mts +74 -0
- package/dist/KycService-method-action-types.d.mts.map +1 -0
- package/dist/KycService-method-action-types.mjs +6 -0
- package/dist/KycService-method-action-types.mjs.map +1 -0
- package/dist/KycService.cjs +238 -0
- package/dist/KycService.cjs.map +1 -0
- package/dist/KycService.d.cts +169 -0
- package/dist/KycService.d.cts.map +1 -0
- package/dist/KycService.d.mts +169 -0
- package/dist/KycService.d.mts.map +1 -0
- package/dist/KycService.mjs +234 -0
- package/dist/KycService.mjs.map +1 -0
- package/dist/countryCodes.cjs +274 -0
- package/dist/countryCodes.cjs.map +1 -0
- package/dist/countryCodes.d.cts +18 -0
- package/dist/countryCodes.d.cts.map +1 -0
- package/dist/countryCodes.d.mts +18 -0
- package/dist/countryCodes.d.mts.map +1 -0
- package/dist/countryCodes.mjs +270 -0
- package/dist/countryCodes.mjs.map +1 -0
- package/dist/crypto.cjs +165 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.d.cts +83 -0
- package/dist/crypto.d.cts.map +1 -0
- package/dist/crypto.d.mts +83 -0
- package/dist/crypto.d.mts.map +1 -0
- package/dist/crypto.mjs +160 -0
- package/dist/crypto.mjs.map +1 -0
- package/dist/index.cjs +21 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/selectors.cjs +30 -0
- package/dist/selectors.cjs.map +1 -0
- package/dist/selectors.d.cts +24 -0
- package/dist/selectors.d.cts.map +1 -0
- package/dist/selectors.d.mts +24 -0
- package/dist/selectors.d.mts.map +1 -0
- package/dist/selectors.mjs +24 -0
- package/dist/selectors.mjs.map +1 -0
- package/dist/types.cjs +10 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +93 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +93 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +9 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,800 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _KycController_instances, _KycController_sumsubLauncher, _KycController_keypair, _KycController_authClientToken, _KycController_generation, _KycController_continuationInFlight, _KycController_createSession, _KycController_clearAcceptedTerms, _KycController_handleCheckOutcome, _KycController_handleAuthOutcome, _KycController_continueAfterAuthentication, _KycController_requireTermsReacceptance, _KycController_updateIfCurrent, _KycController_applyUpdate, _KycController_fail;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KycController = exports.getDefaultKycControllerState = exports.controllerName = void 0;
|
|
16
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
+
const crypto_1 = require("./crypto.cjs");
|
|
18
|
+
// === GENERAL ===
|
|
19
|
+
exports.controllerName = 'KycController';
|
|
20
|
+
const FRAMES_BASE_URL = 'https://blocks.moonpay.com/platform/v1';
|
|
21
|
+
const CHANNEL_CHECK = 'ch_1';
|
|
22
|
+
const CHANNEL_AUTH = 'ch_2';
|
|
23
|
+
const CHANNEL_RESET = 'ch_reset';
|
|
24
|
+
// Placeholder credentials for the SumSub sub-flow. These are demo values that
|
|
25
|
+
// must be replaced with real UKYC-issued material before production use.
|
|
26
|
+
const MOCK_JWT_TOKEN = 'mock-jwt-token';
|
|
27
|
+
// The SumSub SDK status that signals the applicant finished the flow
|
|
28
|
+
// successfully. Any other resolution (abandonment, failure, or a non-success
|
|
29
|
+
// outcome) must not be recorded as `complete`.
|
|
30
|
+
const SUMSUB_COMPLETED_STATUS = 'Completed';
|
|
31
|
+
const kycControllerMetadata = {
|
|
32
|
+
phase: {
|
|
33
|
+
includeInDebugSnapshot: true,
|
|
34
|
+
includeInStateLogs: true,
|
|
35
|
+
persist: false,
|
|
36
|
+
usedInUi: true,
|
|
37
|
+
},
|
|
38
|
+
statusMessage: {
|
|
39
|
+
includeInDebugSnapshot: true,
|
|
40
|
+
includeInStateLogs: true,
|
|
41
|
+
persist: false,
|
|
42
|
+
usedInUi: true,
|
|
43
|
+
},
|
|
44
|
+
error: {
|
|
45
|
+
includeInDebugSnapshot: true,
|
|
46
|
+
includeInStateLogs: true,
|
|
47
|
+
persist: false,
|
|
48
|
+
usedInUi: true,
|
|
49
|
+
},
|
|
50
|
+
email: {
|
|
51
|
+
includeInDebugSnapshot: false,
|
|
52
|
+
includeInStateLogs: false,
|
|
53
|
+
persist: false,
|
|
54
|
+
usedInUi: false,
|
|
55
|
+
},
|
|
56
|
+
termsAcceptedAt: {
|
|
57
|
+
includeInDebugSnapshot: true,
|
|
58
|
+
includeInStateLogs: true,
|
|
59
|
+
persist: true,
|
|
60
|
+
usedInUi: false,
|
|
61
|
+
},
|
|
62
|
+
acceptedDisclaimerIds: {
|
|
63
|
+
includeInDebugSnapshot: true,
|
|
64
|
+
includeInStateLogs: true,
|
|
65
|
+
persist: true,
|
|
66
|
+
usedInUi: false,
|
|
67
|
+
},
|
|
68
|
+
disclaimers: {
|
|
69
|
+
includeInDebugSnapshot: false,
|
|
70
|
+
includeInStateLogs: false,
|
|
71
|
+
persist: false,
|
|
72
|
+
usedInUi: true,
|
|
73
|
+
},
|
|
74
|
+
disclaimersError: {
|
|
75
|
+
includeInDebugSnapshot: true,
|
|
76
|
+
includeInStateLogs: true,
|
|
77
|
+
persist: false,
|
|
78
|
+
usedInUi: true,
|
|
79
|
+
},
|
|
80
|
+
geoCountry: {
|
|
81
|
+
includeInDebugSnapshot: true,
|
|
82
|
+
includeInStateLogs: true,
|
|
83
|
+
persist: false,
|
|
84
|
+
usedInUi: true,
|
|
85
|
+
},
|
|
86
|
+
sessionToken: {
|
|
87
|
+
includeInDebugSnapshot: false,
|
|
88
|
+
includeInStateLogs: false,
|
|
89
|
+
persist: false,
|
|
90
|
+
usedInUi: false,
|
|
91
|
+
},
|
|
92
|
+
accessToken: {
|
|
93
|
+
includeInDebugSnapshot: false,
|
|
94
|
+
includeInStateLogs: false,
|
|
95
|
+
persist: false,
|
|
96
|
+
usedInUi: false,
|
|
97
|
+
},
|
|
98
|
+
moonpayCustomerId: {
|
|
99
|
+
includeInDebugSnapshot: false,
|
|
100
|
+
includeInStateLogs: false,
|
|
101
|
+
persist: false,
|
|
102
|
+
usedInUi: false,
|
|
103
|
+
},
|
|
104
|
+
activeProduct: {
|
|
105
|
+
includeInDebugSnapshot: true,
|
|
106
|
+
includeInStateLogs: true,
|
|
107
|
+
persist: false,
|
|
108
|
+
usedInUi: true,
|
|
109
|
+
},
|
|
110
|
+
kycRequiredByProduct: {
|
|
111
|
+
includeInDebugSnapshot: true,
|
|
112
|
+
includeInStateLogs: true,
|
|
113
|
+
persist: true,
|
|
114
|
+
usedInUi: true,
|
|
115
|
+
},
|
|
116
|
+
lastCheckedAt: {
|
|
117
|
+
includeInDebugSnapshot: true,
|
|
118
|
+
includeInStateLogs: true,
|
|
119
|
+
persist: true,
|
|
120
|
+
usedInUi: false,
|
|
121
|
+
},
|
|
122
|
+
sumsub: {
|
|
123
|
+
includeInDebugSnapshot: false,
|
|
124
|
+
includeInStateLogs: false,
|
|
125
|
+
persist: false,
|
|
126
|
+
usedInUi: true,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Constructs the default {@link KycController} state.
|
|
131
|
+
*
|
|
132
|
+
* @returns The default state.
|
|
133
|
+
*/
|
|
134
|
+
function getDefaultKycControllerState() {
|
|
135
|
+
return {
|
|
136
|
+
phase: 'idle',
|
|
137
|
+
statusMessage: '',
|
|
138
|
+
error: null,
|
|
139
|
+
email: null,
|
|
140
|
+
termsAcceptedAt: null,
|
|
141
|
+
acceptedDisclaimerIds: [],
|
|
142
|
+
disclaimers: [],
|
|
143
|
+
disclaimersError: null,
|
|
144
|
+
geoCountry: null,
|
|
145
|
+
sessionToken: null,
|
|
146
|
+
accessToken: null,
|
|
147
|
+
moonpayCustomerId: null,
|
|
148
|
+
activeProduct: null,
|
|
149
|
+
kycRequiredByProduct: {},
|
|
150
|
+
lastCheckedAt: null,
|
|
151
|
+
sumsub: {
|
|
152
|
+
status: 'idle',
|
|
153
|
+
result: null,
|
|
154
|
+
sessionId: null,
|
|
155
|
+
applicantAccessToken: null,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
exports.getDefaultKycControllerState = getDefaultKycControllerState;
|
|
160
|
+
// === MESSENGER ===
|
|
161
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
162
|
+
'initialize',
|
|
163
|
+
'loadDisclaimers',
|
|
164
|
+
'acceptTermsAndStartSession',
|
|
165
|
+
'clearSavedTerms',
|
|
166
|
+
'handleFrameMessage',
|
|
167
|
+
'buildCheckFrameUrl',
|
|
168
|
+
'buildAuthFrameUrl',
|
|
169
|
+
'buildResetFrameUrl',
|
|
170
|
+
'checkKycRequired',
|
|
171
|
+
'getKycStatus',
|
|
172
|
+
'startSumSub',
|
|
173
|
+
'reset',
|
|
174
|
+
];
|
|
175
|
+
// === CONTROLLER DEFINITION ===
|
|
176
|
+
/**
|
|
177
|
+
* `KycController` orchestrates the vendor-backed KYC / identity-verification
|
|
178
|
+
* flow (MoonPay identity + SumSub documents) behind a vendor-neutral, per
|
|
179
|
+
* product surface used by ramps and card. It owns all state, HTTP
|
|
180
|
+
* orchestration (via `KycService`), crypto, and the frame message protocol;
|
|
181
|
+
* platform-specific presentation (WebView/iframe, SumSub SDK) is injected.
|
|
182
|
+
*/
|
|
183
|
+
class KycController extends base_controller_1.BaseController {
|
|
184
|
+
/**
|
|
185
|
+
* Constructs a new {@link KycController}.
|
|
186
|
+
*
|
|
187
|
+
* @param options - The constructor options.
|
|
188
|
+
* @param options.messenger - The messenger suited for this controller.
|
|
189
|
+
* @param options.state - Partial initial state; merged over defaults.
|
|
190
|
+
* @param options.sumsubLauncher - The platform SumSub launcher adapter.
|
|
191
|
+
*/
|
|
192
|
+
constructor({ messenger, state, sumsubLauncher }) {
|
|
193
|
+
super({
|
|
194
|
+
messenger,
|
|
195
|
+
metadata: kycControllerMetadata,
|
|
196
|
+
name: exports.controllerName,
|
|
197
|
+
state: { ...getDefaultKycControllerState(), ...state },
|
|
198
|
+
});
|
|
199
|
+
_KycController_instances.add(this);
|
|
200
|
+
_KycController_sumsubLauncher.set(this, void 0);
|
|
201
|
+
/** Ephemeral X25519 keypair for the frame key exchange (never persisted). */
|
|
202
|
+
_KycController_keypair.set(this, void 0);
|
|
203
|
+
/** Auth-frame client token, kept out of state. */
|
|
204
|
+
_KycController_authClientToken.set(this, null);
|
|
205
|
+
/**
|
|
206
|
+
* Monotonic flow generation. Incremented by {@link reset} so in-flight async
|
|
207
|
+
* work (e.g. the KYC-required check) can detect that it was superseded and
|
|
208
|
+
* avoid writing stale results onto a reset controller.
|
|
209
|
+
*/
|
|
210
|
+
_KycController_generation.set(this, 0);
|
|
211
|
+
/**
|
|
212
|
+
* Guards the automatic post-authentication continuation. The Check/Auth
|
|
213
|
+
* frames can post more than one `complete` message (duplicate or late), each
|
|
214
|
+
* of which resolves to an `active` outcome with an access token. Without this
|
|
215
|
+
* flag, every such message would re-enter {@link #continueAfterAuthentication}
|
|
216
|
+
* and run the KYC-required check / SumSub sub-flow again while a prior run is
|
|
217
|
+
* still in flight. Set for the duration of a continuation and cleared by
|
|
218
|
+
* {@link reset} so a fresh flow can continue again.
|
|
219
|
+
*/
|
|
220
|
+
_KycController_continuationInFlight.set(this, false);
|
|
221
|
+
__classPrivateFieldSet(this, _KycController_sumsubLauncher, sumsubLauncher, "f");
|
|
222
|
+
__classPrivateFieldSet(this, _KycController_keypair, (0, crypto_1.generateKeyPair)(), "f");
|
|
223
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Resolves persisted terms + geolocation, and auto-creates a session when
|
|
227
|
+
* terms are already accepted and an email is available.
|
|
228
|
+
*
|
|
229
|
+
* @param params - Optional parameters.
|
|
230
|
+
* @param params.email - The account email to associate with the session.
|
|
231
|
+
* @param params.product - The consuming feature the flow runs for. When
|
|
232
|
+
* provided, the controller automatically runs the KYC-required check once
|
|
233
|
+
* authentication completes (and chains into document verification when KYC
|
|
234
|
+
* is required). When omitted, the flow stops at `form` and the consumer must
|
|
235
|
+
* call `checkKycRequired` manually.
|
|
236
|
+
*/
|
|
237
|
+
async initialize(params) {
|
|
238
|
+
// `initialize` starts a fresh flow, so `activeProduct` is always reset to
|
|
239
|
+
// this call's product (or `null`). Otherwise a prior run's product could
|
|
240
|
+
// linger and cause `#continueAfterAuthentication` to auto-run the check /
|
|
241
|
+
// sub-flow when the caller intended the manual (product-less) flow.
|
|
242
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
243
|
+
if (params?.email) {
|
|
244
|
+
state.email = params.email;
|
|
245
|
+
}
|
|
246
|
+
state.activeProduct = params?.product ?? null;
|
|
247
|
+
});
|
|
248
|
+
// Resolve country for display; non-blocking.
|
|
249
|
+
try {
|
|
250
|
+
const country = await this.messenger.call('KycService:getGeoCountry');
|
|
251
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
252
|
+
state.geoCountry = country;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// Ignore; disclaimers loading will surface a country error if needed.
|
|
257
|
+
}
|
|
258
|
+
const hasTerms = Boolean(this.state.termsAcceptedAt) &&
|
|
259
|
+
this.state.acceptedDisclaimerIds.length > 0;
|
|
260
|
+
if (hasTerms && this.state.email) {
|
|
261
|
+
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_createSession).call(this);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
265
|
+
state.phase = 'terms';
|
|
266
|
+
});
|
|
267
|
+
await this.loadDisclaimers();
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Loads the disclaimers for the resolved (or provided) country.
|
|
271
|
+
*
|
|
272
|
+
* @param params - Optional parameters.
|
|
273
|
+
* @param params.country - ISO 3166-1 alpha-3 country code override.
|
|
274
|
+
*/
|
|
275
|
+
async loadDisclaimers(params) {
|
|
276
|
+
try {
|
|
277
|
+
const country = params?.country ??
|
|
278
|
+
this.state.geoCountry ??
|
|
279
|
+
(await this.messenger.call('KycService:getGeoCountry'));
|
|
280
|
+
if (country !== this.state.geoCountry) {
|
|
281
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
282
|
+
state.geoCountry = country;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
const disclaimers = await this.messenger.call('KycService:fetchDisclaimers', { country });
|
|
286
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
287
|
+
state.disclaimers = disclaimers;
|
|
288
|
+
state.disclaimersError = null;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
293
|
+
state.disclaimersError = `Failed to load disclaimers: ${String(error)}`;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Captures terms acceptance for the currently loaded disclaimers and creates
|
|
299
|
+
* a session.
|
|
300
|
+
*
|
|
301
|
+
* @param params - Optional parameters.
|
|
302
|
+
* @param params.email - The account email to associate with the session.
|
|
303
|
+
* @param params.product - The consuming feature the flow runs for. See
|
|
304
|
+
* {@link initialize} for how the product drives the automatic post
|
|
305
|
+
* authentication continuation.
|
|
306
|
+
*/
|
|
307
|
+
async acceptTermsAndStartSession(params) {
|
|
308
|
+
const termsAcceptedAt = new Date().toISOString();
|
|
309
|
+
const disclaimerIds = this.state.disclaimers.map((disclaimer) => disclaimer.id);
|
|
310
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
311
|
+
if (params?.email) {
|
|
312
|
+
state.email = params.email;
|
|
313
|
+
}
|
|
314
|
+
if (params?.product) {
|
|
315
|
+
state.activeProduct = params.product;
|
|
316
|
+
}
|
|
317
|
+
state.termsAcceptedAt = termsAcceptedAt;
|
|
318
|
+
state.acceptedDisclaimerIds = disclaimerIds;
|
|
319
|
+
});
|
|
320
|
+
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_createSession).call(this);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Clears the persisted terms acceptance.
|
|
324
|
+
*/
|
|
325
|
+
clearSavedTerms() {
|
|
326
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
327
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Handles a message posted by a Check/Auth frame and advances the flow.
|
|
332
|
+
*
|
|
333
|
+
* The transport-agnostic caller (WebView on mobile, iframe on web) forwards
|
|
334
|
+
* the raw message and injects the returned `reply` back into the frame.
|
|
335
|
+
*
|
|
336
|
+
* @param params - The parameters.
|
|
337
|
+
* @param params.message - The raw message posted by the frame.
|
|
338
|
+
* @returns An object whose optional `reply` should be posted back.
|
|
339
|
+
*/
|
|
340
|
+
async handleFrameMessage(params) {
|
|
341
|
+
const payload = params.message;
|
|
342
|
+
if (!payload) {
|
|
343
|
+
return {};
|
|
344
|
+
}
|
|
345
|
+
if (payload.kind === 'handshake') {
|
|
346
|
+
const channelId = payload.meta?.channelId;
|
|
347
|
+
return { reply: { version: 2, meta: { channelId }, kind: 'ack' } };
|
|
348
|
+
}
|
|
349
|
+
if (payload.kind !== 'complete') {
|
|
350
|
+
return {};
|
|
351
|
+
}
|
|
352
|
+
const channelId = payload.meta?.channelId;
|
|
353
|
+
const status = payload.payload?.status;
|
|
354
|
+
const credsEnvelope = payload.payload?.credentials;
|
|
355
|
+
const customerId = payload.payload?.customer?.id ?? null;
|
|
356
|
+
if (customerId) {
|
|
357
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
358
|
+
state.moonpayCustomerId = customerId;
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
if (!status) {
|
|
362
|
+
return {};
|
|
363
|
+
}
|
|
364
|
+
let accessToken;
|
|
365
|
+
let clientToken;
|
|
366
|
+
if (credsEnvelope) {
|
|
367
|
+
try {
|
|
368
|
+
const { credentials } = (0, crypto_1.decryptCredentials)(credsEnvelope, __classPrivateFieldGet(this, _KycController_keypair, "f").privateKey);
|
|
369
|
+
accessToken = credentials.accessToken;
|
|
370
|
+
clientToken = credentials.clientToken;
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, `Failed to decrypt frame credentials: ${String(error)}`);
|
|
374
|
+
return {};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (channelId === CHANNEL_CHECK) {
|
|
378
|
+
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_handleCheckOutcome).call(this, status, accessToken, clientToken);
|
|
379
|
+
return {};
|
|
380
|
+
}
|
|
381
|
+
if (channelId === CHANNEL_AUTH) {
|
|
382
|
+
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_handleAuthOutcome).call(this, status, accessToken);
|
|
383
|
+
return {};
|
|
384
|
+
}
|
|
385
|
+
return {};
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Builds the Check-frame URL, or `null` when no session exists yet.
|
|
389
|
+
*
|
|
390
|
+
* @returns The Check-frame URL or `null`.
|
|
391
|
+
*/
|
|
392
|
+
buildCheckFrameUrl() {
|
|
393
|
+
if (!this.state.sessionToken) {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
const url = new URL(`${FRAMES_BASE_URL}/check-connection`);
|
|
397
|
+
url.searchParams.set('sessionToken', this.state.sessionToken);
|
|
398
|
+
url.searchParams.set('publicKey', __classPrivateFieldGet(this, _KycController_keypair, "f").publicKeyHex);
|
|
399
|
+
url.searchParams.set('channelId', CHANNEL_CHECK);
|
|
400
|
+
url.searchParams.set('skipKyc', 'true');
|
|
401
|
+
return url.toString();
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Builds the Auth-frame URL, or `null` when no client token is available.
|
|
405
|
+
*
|
|
406
|
+
* @returns The Auth-frame URL or `null`.
|
|
407
|
+
*/
|
|
408
|
+
buildAuthFrameUrl() {
|
|
409
|
+
if (!__classPrivateFieldGet(this, _KycController_authClientToken, "f")) {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
const url = new URL(`${FRAMES_BASE_URL}/auth`);
|
|
413
|
+
url.searchParams.set('clientToken', __classPrivateFieldGet(this, _KycController_authClientToken, "f"));
|
|
414
|
+
url.searchParams.set('publicKey', __classPrivateFieldGet(this, _KycController_keypair, "f").publicKeyHex);
|
|
415
|
+
url.searchParams.set('channelId', CHANNEL_AUTH);
|
|
416
|
+
return url.toString();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Builds the Reset-frame URL.
|
|
420
|
+
*
|
|
421
|
+
* @returns The Reset-frame URL.
|
|
422
|
+
*/
|
|
423
|
+
buildResetFrameUrl() {
|
|
424
|
+
const url = new URL(`${FRAMES_BASE_URL}/reset`);
|
|
425
|
+
url.searchParams.set('channelId', CHANNEL_RESET);
|
|
426
|
+
return url.toString();
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Checks whether KYC is required for a product and caches the result.
|
|
430
|
+
*
|
|
431
|
+
* @param params - The parameters.
|
|
432
|
+
* @param params.product - The consuming feature.
|
|
433
|
+
* @param params.country - Optional alpha-3 country override.
|
|
434
|
+
* @returns Whether KYC is required.
|
|
435
|
+
*/
|
|
436
|
+
async checkKycRequired(params) {
|
|
437
|
+
const { accessToken } = this.state;
|
|
438
|
+
if (!accessToken) {
|
|
439
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing accessToken — repeat the authentication step.');
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
const country = params.country ?? this.state.geoCountry;
|
|
443
|
+
if (!country) {
|
|
444
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing country for KYC-required check.');
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
// Capture the flow generation so we can detect a `reset()` that happens
|
|
448
|
+
// while the HTTP call is in flight and avoid writing stale results.
|
|
449
|
+
const generation = __classPrivateFieldGet(this, _KycController_generation, "f");
|
|
450
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
451
|
+
state.phase = 'submit';
|
|
452
|
+
state.statusMessage = 'Checking KYC status...';
|
|
453
|
+
});
|
|
454
|
+
try {
|
|
455
|
+
const { kycRequired } = await this.messenger.call('KycService:checkKycRequired', { accessToken, country, capabilities: [{ product: params.product }] });
|
|
456
|
+
// The flow was reset while the check was in flight; discard the result
|
|
457
|
+
// rather than resurrecting a done/cached state on an idle controller.
|
|
458
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
462
|
+
state.kycRequiredByProduct[params.product] = kycRequired;
|
|
463
|
+
state.lastCheckedAt = new Date().toISOString();
|
|
464
|
+
state.phase = 'done';
|
|
465
|
+
state.statusMessage = 'KYC check complete.';
|
|
466
|
+
});
|
|
467
|
+
return kycRequired;
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, `KYC check failed: ${String(error)}`);
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Reads the cached "is KYC required" result for a product.
|
|
479
|
+
*
|
|
480
|
+
* @param params - The parameters.
|
|
481
|
+
* @param params.product - The consuming feature.
|
|
482
|
+
* @returns The cached value, or `undefined` if not yet checked.
|
|
483
|
+
*/
|
|
484
|
+
getKycStatus(params) {
|
|
485
|
+
return this.state.kycRequiredByProduct[params.product];
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Runs the SumSub document-verification sub-flow: creates a UKYC session,
|
|
489
|
+
* exchanges the wrapped key for an applicant access token, and presents the
|
|
490
|
+
* SDK via the injected launcher.
|
|
491
|
+
*
|
|
492
|
+
* @param params - Optional parameters.
|
|
493
|
+
* @param params.locale - BCP-47 locale for the SDK UI.
|
|
494
|
+
* @param params.debug - Enables SDK debug logging.
|
|
495
|
+
* @returns The SDK result.
|
|
496
|
+
*/
|
|
497
|
+
async startSumSub(params) {
|
|
498
|
+
if (!__classPrivateFieldGet(this, _KycController_sumsubLauncher, "f").isAvailable()) {
|
|
499
|
+
const error = 'SumSub SDK is not available in this runtime.';
|
|
500
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
501
|
+
state.sumsub.status = 'failed';
|
|
502
|
+
state.sumsub.result = { error };
|
|
503
|
+
});
|
|
504
|
+
throw new Error(error);
|
|
505
|
+
}
|
|
506
|
+
// Capture the flow generation so each async step can detect a `reset()`
|
|
507
|
+
// that lands mid-flight and avoid writing stale sub-flow state (or, worse,
|
|
508
|
+
// presenting the SDK) on a controller that is now idle.
|
|
509
|
+
const generation = __classPrivateFieldGet(this, _KycController_generation, "f");
|
|
510
|
+
try {
|
|
511
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
512
|
+
state.sumsub.status = 'creatingSession';
|
|
513
|
+
state.sumsub.result = null;
|
|
514
|
+
});
|
|
515
|
+
const jwtToken = MOCK_JWT_TOKEN;
|
|
516
|
+
const { sessionId, wrappingPublicKey, idosSessionId } = await this.messenger.call('KycService:createUkycSession', {
|
|
517
|
+
jwtToken,
|
|
518
|
+
vendorMetadata: {
|
|
519
|
+
moonPayAccessToken: this.state.accessToken,
|
|
520
|
+
moonPayUserId: this.state.moonpayCustomerId,
|
|
521
|
+
},
|
|
522
|
+
});
|
|
523
|
+
// Retain the exchange material so the SDK can refresh its token. The
|
|
524
|
+
// session's `wrappingPublicKey` is forwarded opaquely as the request's
|
|
525
|
+
// `wrappedUserKey` field (the /wrapped-key endpoint's body is unchanged).
|
|
526
|
+
const exchange = {
|
|
527
|
+
sessionId,
|
|
528
|
+
wrappedUserKey: wrappingPublicKey,
|
|
529
|
+
idosSessionId,
|
|
530
|
+
jwtToken,
|
|
531
|
+
};
|
|
532
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
533
|
+
state.sumsub.status = 'fetchingToken';
|
|
534
|
+
state.sumsub.sessionId = sessionId;
|
|
535
|
+
});
|
|
536
|
+
const { applicantAccessToken } = await this.messenger.call('KycService:submitWrappedKey', exchange);
|
|
537
|
+
// A reset() landed while the session/token was being prepared; abort
|
|
538
|
+
// before presenting the SDK rather than launching on an idle controller.
|
|
539
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
540
|
+
return {};
|
|
541
|
+
}
|
|
542
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
543
|
+
state.sumsub.status = 'launching';
|
|
544
|
+
state.sumsub.applicantAccessToken = applicantAccessToken;
|
|
545
|
+
});
|
|
546
|
+
// Track whether the SDK ever reported a successful completion. A resolved
|
|
547
|
+
// `launch` alone does not imply success — the applicant may have
|
|
548
|
+
// abandoned the flow or the SDK may have reported a non-success outcome.
|
|
549
|
+
let reachedCompletion = false;
|
|
550
|
+
const result = await __classPrivateFieldGet(this, _KycController_sumsubLauncher, "f").launch({
|
|
551
|
+
applicantAccessToken,
|
|
552
|
+
onTokenExpiration: async () => {
|
|
553
|
+
// A reset() may have superseded this flow while the SDK stayed open.
|
|
554
|
+
// Refuse to refresh against the now-stale UKYC session rather than
|
|
555
|
+
// silently keeping an orphaned SDK alive.
|
|
556
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
557
|
+
throw new Error('KYC flow was reset; SumSub session is no longer active.');
|
|
558
|
+
}
|
|
559
|
+
const refreshed = await this.messenger.call('KycService:submitWrappedKey', exchange);
|
|
560
|
+
return refreshed.applicantAccessToken;
|
|
561
|
+
},
|
|
562
|
+
onStatusChange: (_prev, next) => {
|
|
563
|
+
if (next === SUMSUB_COMPLETED_STATUS) {
|
|
564
|
+
reachedCompletion = true;
|
|
565
|
+
}
|
|
566
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
567
|
+
state.sumsub.status =
|
|
568
|
+
next === SUMSUB_COMPLETED_STATUS ? 'complete' : 'inProgress';
|
|
569
|
+
});
|
|
570
|
+
},
|
|
571
|
+
locale: params?.locale ?? 'en',
|
|
572
|
+
debug: params?.debug ?? false,
|
|
573
|
+
});
|
|
574
|
+
// Only record `complete` when the SDK actually reported completion;
|
|
575
|
+
// otherwise treat the resolved-but-unfinished flow as `failed` so
|
|
576
|
+
// consumers and UI do not mistake it for a finished verification.
|
|
577
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
578
|
+
state.sumsub.status = reachedCompletion ? 'complete' : 'failed';
|
|
579
|
+
state.sumsub.result = result;
|
|
580
|
+
});
|
|
581
|
+
return result;
|
|
582
|
+
}
|
|
583
|
+
catch (error) {
|
|
584
|
+
const result = { error: String(error) };
|
|
585
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_updateIfCurrent).call(this, generation, (state) => {
|
|
586
|
+
state.sumsub.status = 'failed';
|
|
587
|
+
state.sumsub.result = result;
|
|
588
|
+
});
|
|
589
|
+
return result;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Resets the flow to idle, clearing session tokens and sub-flow state while
|
|
594
|
+
* preserving persisted terms acceptance and the per-product cache.
|
|
595
|
+
*/
|
|
596
|
+
reset() {
|
|
597
|
+
__classPrivateFieldSet(this, _KycController_authClientToken, null, "f");
|
|
598
|
+
// Invalidate any in-flight async work started before this reset.
|
|
599
|
+
__classPrivateFieldSet(this, _KycController_generation, __classPrivateFieldGet(this, _KycController_generation, "f") + 1, "f");
|
|
600
|
+
// Allow the next authenticated flow to auto-continue; any continuation from
|
|
601
|
+
// the superseded generation will no longer clear this flag (see the
|
|
602
|
+
// generation guard in `#continueAfterAuthentication`).
|
|
603
|
+
__classPrivateFieldSet(this, _KycController_continuationInFlight, false, "f");
|
|
604
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
605
|
+
state.phase = 'idle';
|
|
606
|
+
state.statusMessage = '';
|
|
607
|
+
state.error = null;
|
|
608
|
+
state.disclaimers = [];
|
|
609
|
+
state.disclaimersError = null;
|
|
610
|
+
state.sessionToken = null;
|
|
611
|
+
state.accessToken = null;
|
|
612
|
+
state.moonpayCustomerId = null;
|
|
613
|
+
state.activeProduct = null;
|
|
614
|
+
state.sumsub = {
|
|
615
|
+
status: 'idle',
|
|
616
|
+
result: null,
|
|
617
|
+
sessionId: null,
|
|
618
|
+
applicantAccessToken: null,
|
|
619
|
+
};
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
exports.KycController = KycController;
|
|
624
|
+
_KycController_sumsubLauncher = new WeakMap(), _KycController_keypair = new WeakMap(), _KycController_authClientToken = new WeakMap(), _KycController_generation = new WeakMap(), _KycController_continuationInFlight = new WeakMap(), _KycController_instances = new WeakSet(), _KycController_createSession =
|
|
625
|
+
/**
|
|
626
|
+
* Creates a vendor session from the currently stored terms + email.
|
|
627
|
+
*/
|
|
628
|
+
async function _KycController_createSession() {
|
|
629
|
+
const { email, termsAcceptedAt, acceptedDisclaimerIds } = this.state;
|
|
630
|
+
if (!email) {
|
|
631
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing email for session creation.');
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (!termsAcceptedAt || acceptedDisclaimerIds.length === 0) {
|
|
635
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, 'Missing terms acceptance for session creation.');
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
// A new session invalidates any authentication carried over from a prior
|
|
639
|
+
// session. Clear the stale access token and auth-frame client token so
|
|
640
|
+
// `buildAuthFrameUrl` cannot return a URL tied to an old client token and
|
|
641
|
+
// `checkKycRequired` cannot run with an access token from an earlier
|
|
642
|
+
// authentication. The Check/Auth frames re-populate these for the new
|
|
643
|
+
// session.
|
|
644
|
+
__classPrivateFieldSet(this, _KycController_authClientToken, null, "f");
|
|
645
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
646
|
+
state.error = null;
|
|
647
|
+
state.phase = 'session';
|
|
648
|
+
state.statusMessage = 'Creating session...';
|
|
649
|
+
state.accessToken = null;
|
|
650
|
+
});
|
|
651
|
+
try {
|
|
652
|
+
const { sessionToken } = await this.messenger.call('KycService:createSession', { email, termsAcceptedAt, disclaimerIds: acceptedDisclaimerIds });
|
|
653
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
654
|
+
state.sessionToken = sessionToken;
|
|
655
|
+
state.phase = 'check';
|
|
656
|
+
state.statusMessage = 'Authenticating via Check frame...';
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
// Invalidate the stored acceptance so the customer can retry. Also clear
|
|
661
|
+
// `activeProduct` so a later `acceptTermsAndStartSession` that omits a
|
|
662
|
+
// product cannot auto-run the KYC check / SumSub chain for this failed
|
|
663
|
+
// flow's product — matching how `initialize` starts from a clean product.
|
|
664
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
665
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
666
|
+
state.activeProduct = null;
|
|
667
|
+
state.error = `Session creation failed: ${String(error)}`;
|
|
668
|
+
state.statusMessage =
|
|
669
|
+
'Session creation failed — accept the terms to try again.';
|
|
670
|
+
state.phase = 'terms';
|
|
671
|
+
});
|
|
672
|
+
await this.loadDisclaimers();
|
|
673
|
+
}
|
|
674
|
+
}, _KycController_clearAcceptedTerms = function _KycController_clearAcceptedTerms(state) {
|
|
675
|
+
state.termsAcceptedAt = null;
|
|
676
|
+
state.acceptedDisclaimerIds = [];
|
|
677
|
+
}, _KycController_handleCheckOutcome =
|
|
678
|
+
/**
|
|
679
|
+
* Applies a Check-frame outcome.
|
|
680
|
+
*
|
|
681
|
+
* @param status - The frame status.
|
|
682
|
+
* @param accessToken - The decrypted access token, if any.
|
|
683
|
+
* @param clientToken - The decrypted client token, if any.
|
|
684
|
+
*/
|
|
685
|
+
async function _KycController_handleCheckOutcome(status, accessToken, clientToken) {
|
|
686
|
+
if (status === 'active' && accessToken) {
|
|
687
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
688
|
+
state.accessToken = accessToken;
|
|
689
|
+
state.phase = 'form';
|
|
690
|
+
state.statusMessage = 'Already authenticated. Review to submit.';
|
|
691
|
+
});
|
|
692
|
+
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_continueAfterAuthentication).call(this);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (status === 'connectionRequired' && clientToken) {
|
|
696
|
+
__classPrivateFieldSet(this, _KycController_authClientToken, clientToken, "f");
|
|
697
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
698
|
+
state.phase = 'auth';
|
|
699
|
+
state.statusMessage = 'Verify your email via OTP in the Auth frame.';
|
|
700
|
+
});
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
if (status === 'termsAcceptanceRequired') {
|
|
704
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_requireTermsReacceptance).call(this);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, `Check frame returned status: ${status}`);
|
|
708
|
+
}, _KycController_handleAuthOutcome =
|
|
709
|
+
/**
|
|
710
|
+
* Applies an Auth-frame outcome.
|
|
711
|
+
*
|
|
712
|
+
* @param status - The frame status.
|
|
713
|
+
* @param accessToken - The decrypted access token, if any.
|
|
714
|
+
*/
|
|
715
|
+
async function _KycController_handleAuthOutcome(status, accessToken) {
|
|
716
|
+
if (status === 'active' && accessToken) {
|
|
717
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
718
|
+
state.accessToken = accessToken;
|
|
719
|
+
state.phase = 'form';
|
|
720
|
+
state.statusMessage = 'Authenticated. Review to submit.';
|
|
721
|
+
});
|
|
722
|
+
await __classPrivateFieldGet(this, _KycController_instances, "m", _KycController_continueAfterAuthentication).call(this);
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (status === 'termsAcceptanceRequired') {
|
|
726
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_requireTermsReacceptance).call(this);
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_fail).call(this, `Auth frame returned status: ${status}`);
|
|
730
|
+
}, _KycController_continueAfterAuthentication =
|
|
731
|
+
/**
|
|
732
|
+
* Continues the flow once authentication has completed (phase `form`).
|
|
733
|
+
*
|
|
734
|
+
* When the flow is scoped to a product (see {@link initialize}), the
|
|
735
|
+
* KYC-required check runs automatically, and — when KYC is required — the
|
|
736
|
+
* document-verification sub-flow is launched. When no product is set, this is
|
|
737
|
+
* a no-op and the flow stays at `form` for the consumer to drive manually.
|
|
738
|
+
*
|
|
739
|
+
* Errors are already recorded on state by `checkKycRequired` (`error`
|
|
740
|
+
* phase) and `startSumSub` (`sumsub.status = 'failed'`); this method swallows
|
|
741
|
+
* them so it can be awaited safely from the frame-message handler.
|
|
742
|
+
*/
|
|
743
|
+
async function _KycController_continueAfterAuthentication() {
|
|
744
|
+
const product = this.state.activeProduct;
|
|
745
|
+
if (!product) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
// A duplicate or late `complete` message can re-enter here while a prior
|
|
749
|
+
// continuation is still running; ignore it so the check / sub-flow does not
|
|
750
|
+
// run twice concurrently.
|
|
751
|
+
if (__classPrivateFieldGet(this, _KycController_continuationInFlight, "f")) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
__classPrivateFieldSet(this, _KycController_continuationInFlight, true, "f");
|
|
755
|
+
// Capture the generation so a `reset()` landing mid-continuation does not
|
|
756
|
+
// let the `finally` clear a flag that belongs to a newer flow.
|
|
757
|
+
const generation = __classPrivateFieldGet(this, _KycController_generation, "f");
|
|
758
|
+
try {
|
|
759
|
+
const kycRequired = await this.checkKycRequired({ product });
|
|
760
|
+
if (!kycRequired) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
try {
|
|
764
|
+
await this.startSumSub();
|
|
765
|
+
}
|
|
766
|
+
catch {
|
|
767
|
+
// `startSumSub` already records `sumsub.status = 'failed'`; swallow the
|
|
768
|
+
// rethrown error (e.g. SDK unavailable) so the awaited continuation
|
|
769
|
+
// resolves cleanly rather than surfacing as an unhandled rejection.
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
finally {
|
|
773
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") === generation) {
|
|
774
|
+
__classPrivateFieldSet(this, _KycController_continuationInFlight, false, "f");
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}, _KycController_requireTermsReacceptance = function _KycController_requireTermsReacceptance() {
|
|
778
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
779
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_clearAcceptedTerms).call(this, state);
|
|
780
|
+
state.phase = 'terms';
|
|
781
|
+
state.statusMessage =
|
|
782
|
+
'The vendor updated its Terms of Use — please re-accept.';
|
|
783
|
+
});
|
|
784
|
+
}, _KycController_updateIfCurrent = function _KycController_updateIfCurrent(generation, updater) {
|
|
785
|
+
if (__classPrivateFieldGet(this, _KycController_generation, "f") !== generation) {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, updater);
|
|
789
|
+
return true;
|
|
790
|
+
}, _KycController_applyUpdate = function _KycController_applyUpdate(updater) {
|
|
791
|
+
this.update((state) => {
|
|
792
|
+
updater(state);
|
|
793
|
+
});
|
|
794
|
+
}, _KycController_fail = function _KycController_fail(message) {
|
|
795
|
+
__classPrivateFieldGet(this, _KycController_instances, "m", _KycController_applyUpdate).call(this, (state) => {
|
|
796
|
+
state.error = message;
|
|
797
|
+
state.phase = 'error';
|
|
798
|
+
});
|
|
799
|
+
};
|
|
800
|
+
//# sourceMappingURL=KycController.cjs.map
|