@metamask-previews/kyc-controller 0.0.0-preview-6b4bcdab3 → 0.0.0-preview-0b5bfc2
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 +3 -42
- package/dist/KycController-method-action-types.cjs.map +1 -1
- package/dist/KycController-method-action-types.d.cts +2 -48
- package/dist/KycController-method-action-types.d.cts.map +1 -1
- package/dist/KycController-method-action-types.d.mts +2 -48
- 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 +13 -472
- package/dist/KycController.cjs.map +1 -1
- package/dist/KycController.d.cts +5 -109
- package/dist/KycController.d.cts.map +1 -1
- package/dist/KycController.d.mts +5 -109
- package/dist/KycController.d.mts.map +1 -1
- package/dist/KycController.mjs +13 -472
- 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 +2 -38
- package/dist/KycService-method-action-types.d.cts.map +1 -1
- package/dist/KycService-method-action-types.d.mts +2 -38
- package/dist/KycService-method-action-types.d.mts.map +1 -1
- package/dist/KycService-method-action-types.mjs.map +1 -1
- package/dist/KycService.cjs +29 -184
- package/dist/KycService.cjs.map +1 -1
- package/dist/KycService.d.cts +14 -99
- package/dist/KycService.d.cts.map +1 -1
- package/dist/KycService.d.mts +14 -99
- package/dist/KycService.d.mts.map +1 -1
- package/dist/KycService.mjs +30 -185
- package/dist/KycService.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +10 -49
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +10 -49
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -19,7 +19,6 @@ export type KycServiceGetGeoCountryAction = {
|
|
|
19
19
|
* created.
|
|
20
20
|
*
|
|
21
21
|
* @param params - The parameters.
|
|
22
|
-
* @param params.vendor - Identity vendor. Defaults to `moonpay`.
|
|
23
22
|
* @param params.country - ISO 3166-1 alpha-3 country code.
|
|
24
23
|
* @returns The disclaimers.
|
|
25
24
|
*/
|
|
@@ -38,7 +37,7 @@ export type KycServiceCreateSessionAction = {
|
|
|
38
37
|
handler: KycService['createSession'];
|
|
39
38
|
};
|
|
40
39
|
/**
|
|
41
|
-
* Checks whether KYC is required for the given
|
|
40
|
+
* Checks whether KYC is required for the given access token, country, and
|
|
42
41
|
* capabilities.
|
|
43
42
|
*
|
|
44
43
|
* @param params - The check parameters.
|
|
@@ -48,41 +47,6 @@ export type KycServiceCheckKycRequiredAction = {
|
|
|
48
47
|
type: `KycService:checkKycRequired`;
|
|
49
48
|
handler: KycService['checkKycRequired'];
|
|
50
49
|
};
|
|
51
|
-
/**
|
|
52
|
-
* Creates (or resumes) an empty-shell customer for the authenticated
|
|
53
|
-
* canonical user on the given identity vendor. Must run before showing
|
|
54
|
-
* vendor T&C so the customer exists and resume logic can key off vendor
|
|
55
|
-
* status.
|
|
56
|
-
*
|
|
57
|
-
* @param params - The parameters.
|
|
58
|
-
* @param params.vendor - Identity vendor (e.g. `iron` for Money/VBA).
|
|
59
|
-
* @param params.email - Email associated with the customer.
|
|
60
|
-
* @returns The vendor customer record (subset validated for controller use).
|
|
61
|
-
*/
|
|
62
|
-
export type KycServiceCreateVendorCustomerAction = {
|
|
63
|
-
type: `KycService:createVendorCustomer`;
|
|
64
|
-
handler: KycService['createVendorCustomer'];
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Posts T&C1 (vendor signings) and T&C2 (Sumsub + idOS) consents for the
|
|
68
|
-
* authenticated user. The API responds with 204 No Content on success.
|
|
69
|
-
*
|
|
70
|
-
* @param params - The consent parameters.
|
|
71
|
-
*/
|
|
72
|
-
export type KycServiceSubmitConsentsAction = {
|
|
73
|
-
type: `KycService:submitConsents`;
|
|
74
|
-
handler: KycService['submitConsents'];
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Fetches the user-keyed simplified KYC status used by Money toast / banner
|
|
78
|
-
* surfaces (`GET /kyc/status`).
|
|
79
|
-
*
|
|
80
|
-
* @returns The simplified status payload.
|
|
81
|
-
*/
|
|
82
|
-
export type KycServiceFetchKycStatusAction = {
|
|
83
|
-
type: `KycService:fetchKycStatus`;
|
|
84
|
-
handler: KycService['fetchKycStatus'];
|
|
85
|
-
};
|
|
86
50
|
/**
|
|
87
51
|
* Requests a per-session wrapping key from the UKYC backend.
|
|
88
52
|
*
|
|
@@ -153,5 +117,5 @@ export type KycServiceGetSessionStatusAction = {
|
|
|
153
117
|
/**
|
|
154
118
|
* Union of all KycService action types.
|
|
155
119
|
*/
|
|
156
|
-
export type KycServiceMethodActions = KycServiceGetGeoCountryAction | KycServiceFetchDisclaimersAction | KycServiceCreateSessionAction | KycServiceCheckKycRequiredAction |
|
|
120
|
+
export type KycServiceMethodActions = KycServiceGetGeoCountryAction | KycServiceFetchDisclaimersAction | KycServiceCreateSessionAction | KycServiceCheckKycRequiredAction | KycServiceGetWrappingKeyAction | KycServiceFetchJwksAction | KycServiceCreateUkycSessionAction | KycServiceCreateJourneyAction | KycServiceGetSessionStatusAction;
|
|
157
121
|
//# sourceMappingURL=KycService-method-action-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KycService-method-action-types.d.mts","sourceRoot":"","sources":["../src/KycService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAwB;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;CACtC,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"KycService-method-action-types.d.mts","sourceRoot":"","sources":["../src/KycService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAwB;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAC/B,6BAA6B,GAC7B,gCAAgC,GAChC,6BAA6B,GAC7B,gCAAgC,GAChC,8BAA8B,GAC9B,yBAAyB,GACzB,iCAAiC,GACjC,6BAA6B,GAC7B,gCAAgC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KycService-method-action-types.mjs","sourceRoot":"","sources":["../src/KycService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { KycService } from './KycService.js';\n\n/**\n * Resolves the customer's country from the geolocation source and converts it\n * to an ISO 3166-1 alpha-3 code.\n *\n * @returns The alpha-3 country code.\n * @throws If the country cannot be determined or mapped.\n */\nexport type KycServiceGetGeoCountryAction = {\n type: `KycService:getGeoCountry`;\n handler: KycService['getGeoCountry'];\n};\n\n/**\n * Fetches the disclaimers the customer must accept before a session is\n * created.\n *\n * @param params - The parameters.\n * @param params.
|
|
1
|
+
{"version":3,"file":"KycService-method-action-types.mjs","sourceRoot":"","sources":["../src/KycService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { KycService } from './KycService.js';\n\n/**\n * Resolves the customer's country from the geolocation source and converts it\n * to an ISO 3166-1 alpha-3 code.\n *\n * @returns The alpha-3 country code.\n * @throws If the country cannot be determined or mapped.\n */\nexport type KycServiceGetGeoCountryAction = {\n type: `KycService:getGeoCountry`;\n handler: KycService['getGeoCountry'];\n};\n\n/**\n * Fetches the disclaimers the customer must accept before a session is\n * created.\n *\n * @param params - The parameters.\n * @param params.country - ISO 3166-1 alpha-3 country code.\n * @returns The disclaimers.\n */\nexport type KycServiceFetchDisclaimersAction = {\n type: `KycService:fetchDisclaimers`;\n handler: KycService['fetchDisclaimers'];\n};\n\n/**\n * Creates a vendor session via the UKYC backend.\n *\n * @param params - The session parameters.\n * @returns The created session token.\n */\nexport type KycServiceCreateSessionAction = {\n type: `KycService:createSession`;\n handler: KycService['createSession'];\n};\n\n/**\n * Checks whether KYC is required for the given access token, country, and\n * capabilities.\n *\n * @param params - The check parameters.\n * @returns Whether KYC is required.\n */\nexport type KycServiceCheckKycRequiredAction = {\n type: `KycService:checkKycRequired`;\n handler: KycService['checkKycRequired'];\n};\n\n/**\n * Requests a per-session wrapping key from the UKYC backend.\n *\n * The client sends its ephemeral X25519 public key; the backend responds with\n * its session public key (`sessionServerPublicKey`) and a `jwtChain` that\n * attests it. The caller must verify `jwtChain` against the Fractal JWKS\n * (see {@link KycService.fetchJwks}) before trusting the key to wrap the\n * `data_encryption_key`.\n *\n * @param params - The parameters.\n * @param params.sessionClientPublicKey - Our ephemeral X25519 public key\n * (base64url).\n * @returns The wrapping key id, `jwtChain`, and session server public key.\n */\nexport type KycServiceGetWrappingKeyAction = {\n type: `KycService:getWrappingKey`;\n handler: KycService['getWrappingKey'];\n};\n\n/**\n * Fetches the Fractal encryption service JWKS used to verify the `jwtChain`\n * returned by {@link KycService.getWrappingKey}.\n *\n * This is an unauthenticated request to a well-known path on the Fractal\n * host, distinct from the UKYC base URL.\n *\n * @returns The JWKS keys.\n */\nexport type KycServiceFetchJwksAction = {\n type: `KycService:fetchJwks`;\n handler: KycService['fetchJwks'];\n};\n\n/**\n * Creates a UKYC session for the SumSub document-verification sub-flow,\n * handing over the wrapped `data_encryption_key` and the client-signed,\n * read-only `ukyc_capability_token` that authorizes later storage access for\n * the session.\n *\n * @param params - The session parameters.\n * @returns The UKYC session identifiers.\n */\nexport type KycServiceCreateUkycSessionAction = {\n type: `KycService:createUkycSession`;\n handler: KycService['createUkycSession'];\n};\n\n/**\n * Creates (or refreshes) the SumSub verification journey for a UKYC session,\n * returning the applicant access token used to launch the SDK.\n *\n * @param sessionId - The UKYC session id from `createUkycSession`.\n * @returns The applicant access token and status.\n */\nexport type KycServiceCreateJourneyAction = {\n type: `KycService:createJourney`;\n handler: KycService['createJourney'];\n};\n\n/**\n * Fetches the current status of a UKYC session. Polled after the SumSub SDK\n * completes to determine the final verification decision.\n *\n * @param params - The parameters.\n * @param params.sessionId - The UKYC session id.\n * @returns The session status.\n */\nexport type KycServiceGetSessionStatusAction = {\n type: `KycService:getSessionStatus`;\n handler: KycService['getSessionStatus'];\n};\n\n/**\n * Union of all KycService action types.\n */\nexport type KycServiceMethodActions =\n | KycServiceGetGeoCountryAction\n | KycServiceFetchDisclaimersAction\n | KycServiceCreateSessionAction\n | KycServiceCheckKycRequiredAction\n | KycServiceGetWrappingKeyAction\n | KycServiceFetchJwksAction\n | KycServiceCreateUkycSessionAction\n | KycServiceCreateJourneyAction\n | KycServiceGetSessionStatusAction;\n"]}
|
package/dist/KycService.cjs
CHANGED
|
@@ -10,7 +10,7 @@ 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 _KycService_instances,
|
|
13
|
+
var _KycService_instances, _KycService_baseUrl, _KycService_fractalEncryptionBaseUrl, _KycService_validateResponse, _KycService_requestJson;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.KycService = exports.serviceName = void 0;
|
|
16
16
|
const base_data_service_1 = require("@metamask/base-data-service");
|
|
@@ -31,9 +31,6 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
31
31
|
'fetchDisclaimers',
|
|
32
32
|
'createSession',
|
|
33
33
|
'checkKycRequired',
|
|
34
|
-
'createVendorCustomer',
|
|
35
|
-
'submitConsents',
|
|
36
|
-
'fetchKycStatus',
|
|
37
34
|
'getWrappingKey',
|
|
38
35
|
'fetchJwks',
|
|
39
36
|
'createUkycSession',
|
|
@@ -92,39 +89,19 @@ const SessionStatusResponseStruct = (0, superstruct_1.type)({
|
|
|
92
89
|
vendor: (0, superstruct_1.string)(),
|
|
93
90
|
vendorStatus: (0, superstruct_1.string)(),
|
|
94
91
|
});
|
|
95
|
-
// Vendor customer subset — `type` (not `object`) keeps extra vendor fields from
|
|
96
|
-
// failing validation while still requiring the fields the controller needs.
|
|
97
|
-
const VendorCustomerResponseStruct = (0, superstruct_1.type)({
|
|
98
|
-
id: (0, superstruct_1.string)(),
|
|
99
|
-
email: (0, superstruct_1.string)(),
|
|
100
|
-
status: (0, superstruct_1.string)(),
|
|
101
|
-
});
|
|
102
|
-
const KYC_USER_STATUSES = [
|
|
103
|
-
'not-started',
|
|
104
|
-
'pending',
|
|
105
|
-
'need-more-information',
|
|
106
|
-
'terminal-failure',
|
|
107
|
-
'completed',
|
|
108
|
-
];
|
|
109
|
-
const KycUserStatusResponseStruct = (0, superstruct_1.type)({
|
|
110
|
-
status: (0, superstruct_1.enums)([...KYC_USER_STATUSES]),
|
|
111
|
-
sumsubSessionId: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
112
|
-
errorCode: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
113
|
-
});
|
|
114
92
|
// === SERVICE DEFINITION ===
|
|
115
93
|
/**
|
|
116
94
|
* `KycService` communicates with the Universal KYC (UKYC) backend to drive the
|
|
117
95
|
* identity + document-verification flow. It is stateless and platform-agnostic:
|
|
118
|
-
* HTTP is performed through the
|
|
119
|
-
*
|
|
120
|
-
* other controllers via the messenger.
|
|
96
|
+
* HTTP is performed through the global `fetch`, and the auth bearer token and
|
|
97
|
+
* geolocation come from other controllers via the messenger.
|
|
121
98
|
*
|
|
122
99
|
* It extends {@link BaseDataService}, so every request is routed through
|
|
123
100
|
* `fetchQuery`: it is wrapped in the shared service policy (retries, circuit
|
|
124
101
|
* breaker) and its result is exposed via the service's `QueryClient`. Read-only
|
|
125
102
|
* endpoints (`fetchDisclaimers`, `fetchJwks`) are cached with a `staleTime`;
|
|
126
103
|
* the session-creating and status-polling endpoints opt out of caching
|
|
127
|
-
* (`staleTime`/`
|
|
104
|
+
* (`staleTime`/`gcTime` of `0`) so they never serve a stale result.
|
|
128
105
|
*/
|
|
129
106
|
class KycService extends base_data_service_1.BaseDataService {
|
|
130
107
|
/**
|
|
@@ -132,8 +109,6 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
132
109
|
*
|
|
133
110
|
* @param options - The constructor options.
|
|
134
111
|
* @param options.messenger - The messenger suited for this service.
|
|
135
|
-
* @param options.fetch - A function used to make HTTP requests. Defaults to
|
|
136
|
-
* the runtime's native `fetch`.
|
|
137
112
|
* @param options.baseUrl - Base URL of the KYC API
|
|
138
113
|
* @param options.fractalEncryptionBaseUrl - Base URL of the Fractal
|
|
139
114
|
* encryption service, from which the JWKS used to verify the wrapping-key
|
|
@@ -142,7 +117,7 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
142
117
|
* exposed by the service.
|
|
143
118
|
* @param options.policyOptions - Options for the request service policy.
|
|
144
119
|
*/
|
|
145
|
-
constructor({ messenger,
|
|
120
|
+
constructor({ messenger, baseUrl, fractalEncryptionBaseUrl, queryClientConfig = {}, policyOptions = {}, }) {
|
|
146
121
|
super({
|
|
147
122
|
name: exports.serviceName,
|
|
148
123
|
messenger,
|
|
@@ -150,26 +125,10 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
150
125
|
policyOptions,
|
|
151
126
|
});
|
|
152
127
|
_KycService_instances.add(this);
|
|
153
|
-
_KycService_fetch.set(this, void 0);
|
|
154
128
|
_KycService_baseUrl.set(this, void 0);
|
|
155
129
|
_KycService_fractalEncryptionBaseUrl.set(this, void 0);
|
|
156
|
-
// Fall back to the runtime's native `fetch`, bound to `globalThis` so it
|
|
157
|
-
// can be invoked as a method of this instance without an illegal-invocation
|
|
158
|
-
// error on platforms that check the receiver.
|
|
159
|
-
if (fetchFunction) {
|
|
160
|
-
__classPrivateFieldSet(this, _KycService_fetch, fetchFunction, "f");
|
|
161
|
-
}
|
|
162
|
-
else if (typeof globalThis.fetch === 'function') {
|
|
163
|
-
__classPrivateFieldSet(this, _KycService_fetch, globalThis.fetch.bind(globalThis), "f");
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
throw new Error('KycService: fetch is not available globally and was not provided in options. Please inject a fetch implementation.');
|
|
167
|
-
}
|
|
168
|
-
if (!baseUrl) {
|
|
169
|
-
throw new Error('KycService: baseUrl is required');
|
|
170
|
-
}
|
|
171
130
|
__classPrivateFieldSet(this, _KycService_baseUrl, baseUrl, "f");
|
|
172
|
-
__classPrivateFieldSet(this, _KycService_fractalEncryptionBaseUrl, fractalEncryptionBaseUrl
|
|
131
|
+
__classPrivateFieldSet(this, _KycService_fractalEncryptionBaseUrl, fractalEncryptionBaseUrl, "f");
|
|
173
132
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
174
133
|
}
|
|
175
134
|
/**
|
|
@@ -200,15 +159,14 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
200
159
|
* created.
|
|
201
160
|
*
|
|
202
161
|
* @param params - The parameters.
|
|
203
|
-
* @param params.vendor - Identity vendor. Defaults to `moonpay`.
|
|
204
162
|
* @param params.country - ISO 3166-1 alpha-3 country code.
|
|
205
163
|
* @returns The disclaimers.
|
|
206
164
|
*/
|
|
207
|
-
async fetchDisclaimers({
|
|
208
|
-
const url = new URL(
|
|
165
|
+
async fetchDisclaimers({ country, }) {
|
|
166
|
+
const url = new URL('/vendors/moonpay/disclaimers', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
209
167
|
url.searchParams.set('country', country);
|
|
210
168
|
const data = await this.fetchQuery({
|
|
211
|
-
queryKey: [`${this.name}:fetchDisclaimers`,
|
|
169
|
+
queryKey: [`${this.name}:fetchDisclaimers`, country],
|
|
212
170
|
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
|
|
213
171
|
staleTime: (0, utils_1.inMilliseconds)(5, utils_1.Duration.Minute),
|
|
214
172
|
});
|
|
@@ -235,132 +193,42 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
235
193
|
}),
|
|
236
194
|
// A session-creating mutation must never serve a stale/cached result.
|
|
237
195
|
staleTime: 0,
|
|
238
|
-
|
|
196
|
+
gcTime: 0,
|
|
239
197
|
});
|
|
240
198
|
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, CreateSessionResponseStruct, 'sessions');
|
|
241
199
|
}
|
|
242
200
|
/**
|
|
243
|
-
* Checks whether KYC is required for the given
|
|
201
|
+
* Checks whether KYC is required for the given access token, country, and
|
|
244
202
|
* capabilities.
|
|
245
203
|
*
|
|
246
204
|
* @param params - The check parameters.
|
|
247
205
|
* @returns Whether KYC is required.
|
|
248
206
|
*/
|
|
249
207
|
async checkKycRequired(params) {
|
|
250
|
-
const
|
|
251
|
-
const url = new URL(`/vendors/${vendor}/kyc-required`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
208
|
+
const url = new URL('/vendors/moonpay/kyc-required', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
252
209
|
const capabilities = params.capabilities ?? [{ product: 'ramps' }];
|
|
253
|
-
const body = vendor === 'moonpay'
|
|
254
|
-
? {
|
|
255
|
-
accessToken: params.accessToken,
|
|
256
|
-
country: params.country,
|
|
257
|
-
capabilities,
|
|
258
|
-
}
|
|
259
|
-
: {};
|
|
260
|
-
// MoonPay requires accessToken and country; validate before making the request.
|
|
261
|
-
if (vendor === 'moonpay') {
|
|
262
|
-
if (!params.accessToken) {
|
|
263
|
-
throw new Error('checkKycRequired: accessToken is required for vendor "moonpay".');
|
|
264
|
-
}
|
|
265
|
-
if (!params.country) {
|
|
266
|
-
throw new Error('checkKycRequired: country is required for vendor "moonpay".');
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
210
|
const data = await this.fetchQuery({
|
|
270
211
|
queryKey: [
|
|
271
212
|
`${this.name}:checkKycRequired`,
|
|
272
|
-
|
|
273
|
-
params.
|
|
274
|
-
params.country ?? null,
|
|
213
|
+
params.accessToken,
|
|
214
|
+
params.country,
|
|
275
215
|
capabilities,
|
|
276
216
|
],
|
|
277
217
|
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
278
218
|
method: 'POST',
|
|
279
|
-
body: JSON.stringify(
|
|
219
|
+
body: JSON.stringify({
|
|
220
|
+
accessToken: params.accessToken,
|
|
221
|
+
country: params.country,
|
|
222
|
+
capabilities,
|
|
223
|
+
}),
|
|
280
224
|
}),
|
|
281
225
|
// The requirement can change server-side, so always re-check.
|
|
282
226
|
staleTime: 0,
|
|
283
|
-
|
|
227
|
+
gcTime: 0,
|
|
284
228
|
});
|
|
285
229
|
const { required } = __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, KycRequiredResponseStruct, 'kyc-required');
|
|
286
230
|
return { kycRequired: required };
|
|
287
231
|
}
|
|
288
|
-
/**
|
|
289
|
-
* Creates (or resumes) an empty-shell customer for the authenticated
|
|
290
|
-
* canonical user on the given identity vendor. Must run before showing
|
|
291
|
-
* vendor T&C so the customer exists and resume logic can key off vendor
|
|
292
|
-
* status.
|
|
293
|
-
*
|
|
294
|
-
* @param params - The parameters.
|
|
295
|
-
* @param params.vendor - Identity vendor (e.g. `iron` for Money/VBA).
|
|
296
|
-
* @param params.email - Email associated with the customer.
|
|
297
|
-
* @returns The vendor customer record (subset validated for controller use).
|
|
298
|
-
*/
|
|
299
|
-
async createVendorCustomer(params) {
|
|
300
|
-
const url = new URL(`/vendors/${params.vendor}/customers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
301
|
-
const data = await this.fetchQuery({
|
|
302
|
-
queryKey: [
|
|
303
|
-
`${this.name}:createVendorCustomer`,
|
|
304
|
-
params.vendor,
|
|
305
|
-
params.email,
|
|
306
|
-
],
|
|
307
|
-
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
308
|
-
method: 'POST',
|
|
309
|
-
body: JSON.stringify({ email: params.email }),
|
|
310
|
-
}),
|
|
311
|
-
// Customer creation/resume must never serve a stale/cached result.
|
|
312
|
-
staleTime: 0,
|
|
313
|
-
cacheTime: 0,
|
|
314
|
-
});
|
|
315
|
-
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, VendorCustomerResponseStruct, 'vendor customers');
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Posts T&C1 (vendor signings) and T&C2 (Sumsub + idOS) consents for the
|
|
319
|
-
* authenticated user. The API responds with 204 No Content on success.
|
|
320
|
-
*
|
|
321
|
-
* @param params - The consent parameters.
|
|
322
|
-
*/
|
|
323
|
-
async submitConsents(params) {
|
|
324
|
-
const url = new URL('/consents', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
325
|
-
await this.fetchQuery({
|
|
326
|
-
queryKey: [
|
|
327
|
-
`${this.name}:submitConsents`,
|
|
328
|
-
params.disclaimerIds,
|
|
329
|
-
params.sumsubTncSigned,
|
|
330
|
-
params.idosTncSigned,
|
|
331
|
-
params.kycLevel ?? 'standard',
|
|
332
|
-
],
|
|
333
|
-
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
334
|
-
method: 'POST',
|
|
335
|
-
// UKYC Money/VBA consents contract still uses `ironDisclaimerIds`.
|
|
336
|
-
body: JSON.stringify({
|
|
337
|
-
ironDisclaimerIds: params.disclaimerIds,
|
|
338
|
-
sumsubTncSigned: params.sumsubTncSigned,
|
|
339
|
-
idosTncSigned: params.idosTncSigned,
|
|
340
|
-
kycLevel: params.kycLevel ?? 'standard',
|
|
341
|
-
}),
|
|
342
|
-
}),
|
|
343
|
-
staleTime: 0,
|
|
344
|
-
cacheTime: 0,
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Fetches the user-keyed simplified KYC status used by Money toast / banner
|
|
349
|
-
* surfaces (`GET /kyc/status`).
|
|
350
|
-
*
|
|
351
|
-
* @returns The simplified status payload.
|
|
352
|
-
*/
|
|
353
|
-
async fetchKycStatus() {
|
|
354
|
-
const url = new URL('/kyc/status', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
355
|
-
const data = await this.fetchQuery({
|
|
356
|
-
queryKey: [`${this.name}:fetchKycStatus`],
|
|
357
|
-
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
|
|
358
|
-
// Status is polled for toast flips, so it must always be fresh.
|
|
359
|
-
staleTime: 0,
|
|
360
|
-
cacheTime: 0,
|
|
361
|
-
});
|
|
362
|
-
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, KycUserStatusResponseStruct, 'kyc status');
|
|
363
|
-
}
|
|
364
232
|
/**
|
|
365
233
|
* Requests a per-session wrapping key from the UKYC backend.
|
|
366
234
|
*
|
|
@@ -387,7 +255,7 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
387
255
|
}),
|
|
388
256
|
// A per-session key exchange must always run fresh.
|
|
389
257
|
staleTime: 0,
|
|
390
|
-
|
|
258
|
+
gcTime: 0,
|
|
391
259
|
});
|
|
392
260
|
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, WrappingKeyResponseStruct, 'wrapping-key');
|
|
393
261
|
}
|
|
@@ -431,17 +299,17 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
431
299
|
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
432
300
|
method: 'POST',
|
|
433
301
|
body: JSON.stringify({
|
|
434
|
-
vendorId:
|
|
302
|
+
vendorId: 'moonpay',
|
|
435
303
|
vendorUserId: 'mockedId',
|
|
436
304
|
jwtToken: params.jwtToken,
|
|
437
|
-
vendorMetadata: params.vendorMetadata
|
|
305
|
+
vendorMetadata: params.vendorMetadata,
|
|
438
306
|
wrappedEncryptionKey: params.wrappedEncryptionKey,
|
|
439
307
|
ukycCapabilityToken: (0, storageAccessToken_js_1.encodeStorageAccessTokenForHeader)(params.ukycCapabilityToken),
|
|
440
308
|
}),
|
|
441
309
|
}),
|
|
442
310
|
// A session-creating mutation must never serve a stale/cached result.
|
|
443
311
|
staleTime: 0,
|
|
444
|
-
|
|
312
|
+
gcTime: 0,
|
|
445
313
|
});
|
|
446
314
|
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, UkycSessionResponseStruct, 'UKYC sessions');
|
|
447
315
|
}
|
|
@@ -459,7 +327,7 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
459
327
|
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'POST' }),
|
|
460
328
|
// Journeys are (re)created on demand; do not reuse a cached token.
|
|
461
329
|
staleTime: 0,
|
|
462
|
-
|
|
330
|
+
gcTime: 0,
|
|
463
331
|
});
|
|
464
332
|
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, ApplicantAccessTokenResponseStruct, 'journey');
|
|
465
333
|
}
|
|
@@ -478,13 +346,13 @@ class KycService extends base_data_service_1.BaseDataService {
|
|
|
478
346
|
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
|
|
479
347
|
// Status is polled for a terminal decision, so it must always be fresh.
|
|
480
348
|
staleTime: 0,
|
|
481
|
-
|
|
349
|
+
gcTime: 0,
|
|
482
350
|
});
|
|
483
351
|
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionStatusResponseStruct, 'session status');
|
|
484
352
|
}
|
|
485
353
|
}
|
|
486
354
|
exports.KycService = KycService;
|
|
487
|
-
|
|
355
|
+
_KycService_baseUrl = new WeakMap(), _KycService_fractalEncryptionBaseUrl = new WeakMap(), _KycService_instances = new WeakSet(), _KycService_validateResponse = function _KycService_validateResponse(data, struct, apiName) {
|
|
488
356
|
try {
|
|
489
357
|
(0, superstruct_1.assert)(data, struct);
|
|
490
358
|
return data;
|
|
@@ -525,38 +393,15 @@ async function _KycService_requestJson(url, init, options = {}) {
|
|
|
525
393
|
}
|
|
526
394
|
if (authenticated) {
|
|
527
395
|
const bearerToken = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
528
|
-
if (!bearerToken) {
|
|
529
|
-
throw new Error('Unable to obtain an authentication bearer token — is the wallet signed in?');
|
|
530
|
-
}
|
|
531
396
|
(0, superstruct_1.assert)(bearerToken, (0, superstruct_1.string)());
|
|
532
397
|
headers.Authorization = `Bearer ${bearerToken}`;
|
|
533
398
|
}
|
|
534
|
-
const response = await
|
|
399
|
+
const response = await fetch(url.toString(), {
|
|
535
400
|
...init,
|
|
536
401
|
headers,
|
|
537
402
|
});
|
|
538
403
|
if (!response.ok) {
|
|
539
|
-
|
|
540
|
-
try {
|
|
541
|
-
const errorBody = await response.json();
|
|
542
|
-
if (errorBody && typeof errorBody === 'object') {
|
|
543
|
-
const record = errorBody;
|
|
544
|
-
if (typeof record.message === 'string') {
|
|
545
|
-
detail = record.message;
|
|
546
|
-
}
|
|
547
|
-
else if (typeof record.error === 'string') {
|
|
548
|
-
detail = record.error;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
catch {
|
|
553
|
-
// Ignore body parse failures; status alone is still useful.
|
|
554
|
-
}
|
|
555
|
-
throw new controller_utils_1.HttpError(response.status, `Fetching '${url.toString()}' failed with status '${response.status}'${detail ? `: ${detail}` : ''}`);
|
|
556
|
-
}
|
|
557
|
-
// Consent (and similar) endpoints return 204 No Content.
|
|
558
|
-
if (response.status === 204) {
|
|
559
|
-
return null;
|
|
404
|
+
throw new controller_utils_1.HttpError(response.status, `Fetching '${url.toString()}' failed with status '${response.status}'`);
|
|
560
405
|
}
|
|
561
406
|
return (await response.json());
|
|
562
407
|
};
|