@metamask-previews/kyc-controller 0.0.0-preview-4f4c98e → 0.0.0-preview-eb263b0ee
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/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.ts → KycController-method-action-types.d.cts} +2 -2
- package/dist/KycController-method-action-types.d.cts.map +1 -0
- package/dist/KycController-method-action-types.d.mts +237 -0
- package/dist/KycController-method-action-types.d.mts.map +1 -0
- package/dist/{KycController-method-action-types.js → KycController-method-action-types.mjs} +1 -1
- package/dist/KycController-method-action-types.mjs.map +1 -0
- package/dist/KycController.cjs +1843 -0
- package/dist/KycController.cjs.map +1 -0
- package/dist/{KycController.d.ts → KycController.d.cts} +9 -9
- package/dist/KycController.d.cts.map +1 -0
- package/dist/KycController.d.mts +393 -0
- package/dist/KycController.d.mts.map +1 -0
- package/dist/{KycController.js → KycController.mjs} +10 -10
- 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.ts → KycService-method-action-types.d.cts} +2 -2
- package/dist/KycService-method-action-types.d.cts.map +1 -0
- package/dist/KycService-method-action-types.d.mts +186 -0
- package/dist/KycService-method-action-types.d.mts.map +1 -0
- package/dist/{KycService-method-action-types.js → KycService-method-action-types.mjs} +1 -1
- package/dist/KycService-method-action-types.mjs.map +1 -0
- package/dist/KycService.cjs +628 -0
- package/dist/KycService.cjs.map +1 -0
- package/dist/{KycService.d.ts → KycService.d.cts} +12 -12
- package/dist/KycService.d.cts.map +1 -0
- package/dist/KycService.d.mts +494 -0
- package/dist/KycService.d.mts.map +1 -0
- package/dist/{KycService.js → KycService.mjs} +7 -7
- package/dist/{KycService.js.map → KycService.mjs.map} +1 -1
- package/dist/countryCodes.cjs +274 -0
- package/dist/countryCodes.cjs.map +1 -0
- package/dist/{countryCodes.d.ts → countryCodes.d.cts} +1 -1
- 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.js → countryCodes.mjs} +1 -1
- package/dist/countryCodes.mjs.map +1 -0
- package/dist/crypto.cjs +154 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/{crypto.d.ts → crypto.d.cts} +1 -1
- package/dist/crypto.d.cts.map +1 -0
- package/dist/crypto.d.mts +84 -0
- package/dist/crypto.d.mts.map +1 -0
- package/dist/{crypto.js → crypto.mjs} +7 -7
- package/dist/crypto.mjs.map +1 -0
- package/dist/encoding.cjs +40 -0
- package/dist/encoding.cjs.map +1 -0
- package/dist/{encoding.d.ts → encoding.d.cts} +1 -1
- package/dist/encoding.d.cts.map +1 -0
- package/dist/encoding.d.mts +24 -0
- package/dist/encoding.d.mts.map +1 -0
- package/dist/{encoding.js → encoding.mjs} +2 -2
- package/dist/encoding.mjs.map +1 -0
- package/dist/index.cjs +37 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +19 -19
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +12 -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.ts → selectors.d.cts} +4 -4
- 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.js → selectors.mjs} +2 -2
- package/dist/selectors.mjs.map +1 -0
- package/dist/types.cjs +10 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +1 -1
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +208 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/ukyc/constants.cjs +75 -0
- package/dist/ukyc/constants.cjs.map +1 -0
- package/dist/ukyc/{constants.d.ts → constants.d.cts} +9 -9
- package/dist/ukyc/constants.d.cts.map +1 -0
- package/dist/ukyc/constants.d.mts +69 -0
- package/dist/ukyc/constants.d.mts.map +1 -0
- package/dist/ukyc/{constants.js → constants.mjs} +1 -1
- package/dist/ukyc/constants.mjs.map +1 -0
- package/dist/ukyc/deriveClientMaterial.cjs +65 -0
- package/dist/ukyc/deriveClientMaterial.cjs.map +1 -0
- package/dist/ukyc/{deriveClientMaterial.d.ts → deriveClientMaterial.d.cts} +1 -1
- package/dist/ukyc/deriveClientMaterial.d.cts.map +1 -0
- package/dist/ukyc/deriveClientMaterial.d.mts +54 -0
- package/dist/ukyc/deriveClientMaterial.d.mts.map +1 -0
- package/dist/ukyc/{deriveClientMaterial.js → deriveClientMaterial.mjs} +7 -7
- package/dist/ukyc/deriveClientMaterial.mjs.map +1 -0
- package/dist/ukyc/jwtChain.cjs +54 -0
- package/dist/ukyc/jwtChain.cjs.map +1 -0
- package/dist/ukyc/{jwtChain.d.ts → jwtChain.d.cts} +1 -1
- package/dist/ukyc/jwtChain.d.cts.map +1 -0
- package/dist/ukyc/jwtChain.d.mts +40 -0
- package/dist/ukyc/jwtChain.d.mts.map +1 -0
- package/dist/ukyc/{jwtChain.js → jwtChain.mjs} +4 -4
- package/dist/ukyc/jwtChain.mjs.map +1 -0
- package/dist/ukyc/localUserSecret.cjs +98 -0
- package/dist/ukyc/localUserSecret.cjs.map +1 -0
- package/dist/ukyc/{localUserSecret.d.ts → localUserSecret.d.cts} +1 -1
- package/dist/ukyc/localUserSecret.d.cts.map +1 -0
- package/dist/ukyc/localUserSecret.d.mts +65 -0
- package/dist/ukyc/localUserSecret.d.mts.map +1 -0
- package/dist/ukyc/{localUserSecret.js → localUserSecret.mjs} +4 -4
- package/dist/ukyc/localUserSecret.mjs.map +1 -0
- package/dist/ukyc/storageAccessToken.cjs +139 -0
- package/dist/ukyc/storageAccessToken.cjs.map +1 -0
- package/dist/ukyc/{storageAccessToken.d.ts → storageAccessToken.d.cts} +2 -2
- package/dist/ukyc/storageAccessToken.d.cts.map +1 -0
- package/dist/ukyc/storageAccessToken.d.mts +99 -0
- package/dist/ukyc/storageAccessToken.d.mts.map +1 -0
- package/dist/ukyc/{storageAccessToken.js → storageAccessToken.mjs} +5 -5
- package/dist/ukyc/storageAccessToken.mjs.map +1 -0
- package/dist/ukyc/testToken.cjs +61 -0
- package/dist/ukyc/testToken.cjs.map +1 -0
- package/dist/ukyc/{testToken.d.ts → testToken.d.cts} +2 -2
- package/dist/ukyc/testToken.d.cts.map +1 -0
- package/dist/ukyc/testToken.d.mts +50 -0
- package/dist/ukyc/testToken.d.mts.map +1 -0
- package/dist/ukyc/{testToken.js → testToken.mjs} +5 -5
- package/dist/ukyc/testToken.mjs.map +1 -0
- package/dist/ukyc/wrapEncryptionKey.cjs +37 -0
- package/dist/ukyc/wrapEncryptionKey.cjs.map +1 -0
- package/dist/ukyc/{wrapEncryptionKey.d.ts → wrapEncryptionKey.d.cts} +1 -1
- package/dist/ukyc/wrapEncryptionKey.d.cts.map +1 -0
- package/dist/ukyc/wrapEncryptionKey.d.mts +41 -0
- package/dist/ukyc/wrapEncryptionKey.d.mts.map +1 -0
- package/dist/ukyc/{wrapEncryptionKey.js → wrapEncryptionKey.mjs} +4 -3
- package/dist/ukyc/wrapEncryptionKey.mjs.map +1 -0
- package/dist/ukyc/wrapUserKey.cjs +80 -0
- package/dist/ukyc/wrapUserKey.cjs.map +1 -0
- package/dist/ukyc/{wrapUserKey.d.ts → wrapUserKey.d.cts} +1 -1
- package/dist/ukyc/wrapUserKey.d.cts.map +1 -0
- package/dist/ukyc/wrapUserKey.d.mts +26 -0
- package/dist/ukyc/wrapUserKey.d.mts.map +1 -0
- package/dist/ukyc/{wrapUserKey.js → wrapUserKey.mjs} +8 -8
- package/dist/ukyc/wrapUserKey.mjs.map +1 -0
- package/dist/ukyc/wrappedRelayPayload.cjs +32 -0
- package/dist/ukyc/wrappedRelayPayload.cjs.map +1 -0
- package/dist/ukyc/{wrappedRelayPayload.d.ts → wrappedRelayPayload.d.cts} +3 -3
- package/dist/ukyc/wrappedRelayPayload.d.cts.map +1 -0
- package/dist/ukyc/wrappedRelayPayload.d.mts +35 -0
- package/dist/ukyc/wrappedRelayPayload.d.mts.map +1 -0
- package/dist/ukyc/{wrappedRelayPayload.js → wrappedRelayPayload.mjs} +2 -2
- package/dist/ukyc/wrappedRelayPayload.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/KycController-method-action-types.d.ts.map +0 -1
- package/dist/KycController-method-action-types.js.map +0 -1
- package/dist/KycController.d.ts.map +0 -1
- package/dist/KycController.js.map +0 -1
- package/dist/KycService-method-action-types.d.ts.map +0 -1
- package/dist/KycService-method-action-types.js.map +0 -1
- package/dist/KycService.d.ts.map +0 -1
- package/dist/countryCodes.d.ts.map +0 -1
- package/dist/countryCodes.js.map +0 -1
- package/dist/crypto.d.ts.map +0 -1
- package/dist/crypto.js.map +0 -1
- package/dist/encoding.d.ts.map +0 -1
- package/dist/encoding.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -12
- package/dist/index.js.map +0 -1
- package/dist/selectors.d.ts.map +0 -1
- package/dist/selectors.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/ukyc/constants.d.ts.map +0 -1
- package/dist/ukyc/constants.js.map +0 -1
- package/dist/ukyc/deriveClientMaterial.d.ts.map +0 -1
- package/dist/ukyc/deriveClientMaterial.js.map +0 -1
- package/dist/ukyc/jwtChain.d.ts.map +0 -1
- package/dist/ukyc/jwtChain.js.map +0 -1
- package/dist/ukyc/localUserSecret.d.ts.map +0 -1
- package/dist/ukyc/localUserSecret.js.map +0 -1
- package/dist/ukyc/storageAccessToken.d.ts.map +0 -1
- package/dist/ukyc/storageAccessToken.js.map +0 -1
- package/dist/ukyc/testToken.d.ts.map +0 -1
- package/dist/ukyc/testToken.js.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.d.ts.map +0 -1
- package/dist/ukyc/wrapEncryptionKey.js.map +0 -1
- package/dist/ukyc/wrapUserKey.d.ts.map +0 -1
- package/dist/ukyc/wrapUserKey.js.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.d.ts.map +0 -1
- package/dist/ukyc/wrappedRelayPayload.js.map +0 -1
|
@@ -0,0 +1,628 @@
|
|
|
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 _KycService_instances, _KycService_fetch, _KycService_baseUrl, _KycService_fractalEncryptionBaseUrl, _KycService_validateResponse, _KycService_requestJson;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KycService = exports.serviceName = void 0;
|
|
16
|
+
const base_data_service_1 = require("@metamask/base-data-service");
|
|
17
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
19
|
+
const utils_1 = require("@metamask/utils");
|
|
20
|
+
const countryCodes_js_1 = require("./countryCodes.cjs");
|
|
21
|
+
const constants_js_1 = require("./ukyc/constants.cjs");
|
|
22
|
+
// === GENERAL ===
|
|
23
|
+
/**
|
|
24
|
+
* The name of the {@link KycService}, used to namespace the service's actions.
|
|
25
|
+
*/
|
|
26
|
+
exports.serviceName = 'KycService';
|
|
27
|
+
// === MESSENGER ===
|
|
28
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
29
|
+
'getGeoCountry',
|
|
30
|
+
'fetchDisclaimers',
|
|
31
|
+
'createSession',
|
|
32
|
+
'checkKycRequired',
|
|
33
|
+
'createVendorCustomer',
|
|
34
|
+
'submitVendorDisclaimers',
|
|
35
|
+
'fetchSessionDisclaimers',
|
|
36
|
+
'submitSessionDisclaimers',
|
|
37
|
+
'fetchKycStatus',
|
|
38
|
+
'fetchJwks',
|
|
39
|
+
'createUkycSession',
|
|
40
|
+
'setAuthorizations',
|
|
41
|
+
'createJourney',
|
|
42
|
+
'getSessionStatus',
|
|
43
|
+
];
|
|
44
|
+
// === API RESPONSE SCHEMAS ===
|
|
45
|
+
const DisclaimerStruct = (0, superstruct_1.type)({
|
|
46
|
+
id: (0, superstruct_1.string)(),
|
|
47
|
+
display_name: (0, superstruct_1.string)(),
|
|
48
|
+
url: (0, superstruct_1.string)(),
|
|
49
|
+
});
|
|
50
|
+
const DisclaimersResponseStruct = (0, superstruct_1.array)(DisclaimerStruct);
|
|
51
|
+
const VendorSigningStruct = (0, superstruct_1.type)({
|
|
52
|
+
id: (0, superstruct_1.string)(),
|
|
53
|
+
customer_id: (0, superstruct_1.string)(),
|
|
54
|
+
content_id: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
55
|
+
});
|
|
56
|
+
const VendorSigningsResponseStruct = (0, superstruct_1.array)(VendorSigningStruct);
|
|
57
|
+
const CreateSessionResponseStruct = (0, superstruct_1.type)({ sessionToken: (0, superstruct_1.string)() });
|
|
58
|
+
// The live KYC API returns the flag under `required`; the service normalizes
|
|
59
|
+
// this to `kycRequired` for consumers (see `checkKycRequired`).
|
|
60
|
+
const KycRequiredResponseStruct = (0, superstruct_1.type)({ required: (0, superstruct_1.boolean)() });
|
|
61
|
+
// The session server's public key, in JWK-like form, returned inside an
|
|
62
|
+
// encryption schema from `POST /sessions`. `x` is the base64url public key
|
|
63
|
+
// used to wrap a secret for that schema.
|
|
64
|
+
const ServerPublicKeyStruct = (0, superstruct_1.type)({
|
|
65
|
+
kty: (0, superstruct_1.string)(),
|
|
66
|
+
crv: (0, superstruct_1.string)(),
|
|
67
|
+
x: (0, superstruct_1.string)(),
|
|
68
|
+
kid: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
69
|
+
alg: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
70
|
+
use: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
71
|
+
});
|
|
72
|
+
const EncryptionSchemaStruct = (0, superstruct_1.type)({
|
|
73
|
+
serverPublicKey: ServerPublicKeyStruct,
|
|
74
|
+
jwtChain: (0, superstruct_1.string)(),
|
|
75
|
+
});
|
|
76
|
+
// A single Ed25519 (OKP) JWK. `type` (not `object`) keeps optional/extra JWK
|
|
77
|
+
// fields (`use`, `alg`) from failing validation.
|
|
78
|
+
const JwkStruct = (0, superstruct_1.type)({
|
|
79
|
+
kty: (0, superstruct_1.string)(),
|
|
80
|
+
crv: (0, superstruct_1.string)(),
|
|
81
|
+
x: (0, superstruct_1.string)(),
|
|
82
|
+
kid: (0, superstruct_1.string)(),
|
|
83
|
+
});
|
|
84
|
+
const JwksResponseStruct = (0, superstruct_1.type)({ keys: (0, superstruct_1.array)(JwkStruct) });
|
|
85
|
+
const UkycSessionResponseStruct = (0, superstruct_1.type)({
|
|
86
|
+
sessionId: (0, superstruct_1.string)(),
|
|
87
|
+
// Per-secret wrapping material so the client can seal the
|
|
88
|
+
// `data_encryption_key` and the `ukyc_capability_token` independently.
|
|
89
|
+
encryptionDataKey: EncryptionSchemaStruct,
|
|
90
|
+
ukycCapabilityToken: EncryptionSchemaStruct,
|
|
91
|
+
});
|
|
92
|
+
const ApplicantAccessTokenResponseStruct = (0, superstruct_1.type)({
|
|
93
|
+
status: (0, superstruct_1.string)(),
|
|
94
|
+
applicantAccessToken: (0, superstruct_1.string)(),
|
|
95
|
+
});
|
|
96
|
+
const SessionStatusResponseStruct = (0, superstruct_1.type)({
|
|
97
|
+
finalStatus: (0, superstruct_1.string)(),
|
|
98
|
+
statusMessage: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
99
|
+
externalUserId: (0, superstruct_1.string)(),
|
|
100
|
+
kycStatus: (0, superstruct_1.string)(),
|
|
101
|
+
vendor: (0, superstruct_1.string)(),
|
|
102
|
+
vendorStatus: (0, superstruct_1.string)(),
|
|
103
|
+
});
|
|
104
|
+
// Vendor customer subset — `type` (not `object`) keeps extra vendor fields from
|
|
105
|
+
// failing validation while still requiring the fields the controller needs.
|
|
106
|
+
const VendorCustomerResponseStruct = (0, superstruct_1.type)({
|
|
107
|
+
id: (0, superstruct_1.string)(),
|
|
108
|
+
email: (0, superstruct_1.string)(),
|
|
109
|
+
status: (0, superstruct_1.string)(),
|
|
110
|
+
});
|
|
111
|
+
const KYC_USER_STATUSES = [
|
|
112
|
+
'not-started',
|
|
113
|
+
'pending',
|
|
114
|
+
'need-more-information',
|
|
115
|
+
'terminal-failure',
|
|
116
|
+
'completed',
|
|
117
|
+
];
|
|
118
|
+
const KycUserStatusResponseStruct = (0, superstruct_1.type)({
|
|
119
|
+
status: (0, superstruct_1.enums)([...KYC_USER_STATUSES]),
|
|
120
|
+
sumsubSessionId: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
121
|
+
errorCode: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
122
|
+
});
|
|
123
|
+
const ConsentDocumentStruct = (0, superstruct_1.type)({
|
|
124
|
+
key: (0, superstruct_1.string)(),
|
|
125
|
+
version: (0, superstruct_1.string)(),
|
|
126
|
+
title: (0, superstruct_1.string)(),
|
|
127
|
+
url: (0, superstruct_1.string)(),
|
|
128
|
+
consented: (0, superstruct_1.boolean)(),
|
|
129
|
+
});
|
|
130
|
+
const SessionDisclaimersResponseStruct = (0, superstruct_1.type)({
|
|
131
|
+
idOS: (0, superstruct_1.array)(ConsentDocumentStruct),
|
|
132
|
+
kycProvider: (0, superstruct_1.array)(ConsentDocumentStruct),
|
|
133
|
+
credentialReusabilityConsentGiven: (0, superstruct_1.boolean)(),
|
|
134
|
+
});
|
|
135
|
+
// === SERVICE DEFINITION ===
|
|
136
|
+
/**
|
|
137
|
+
* `KycService` communicates with the Universal KYC (UKYC) backend to drive the
|
|
138
|
+
* identity + document-verification flow. It is stateless and platform-agnostic:
|
|
139
|
+
* HTTP is performed through the runtime's native `fetch` (or an injected
|
|
140
|
+
* `fetch` when provided), and the auth bearer token and geolocation come from
|
|
141
|
+
* other controllers via the messenger.
|
|
142
|
+
*
|
|
143
|
+
* It extends {@link BaseDataService}, so every request is routed through
|
|
144
|
+
* `fetchQuery`: it is wrapped in the shared service policy (retries, circuit
|
|
145
|
+
* breaker) and its result is exposed via the service's `QueryClient`. Read-only
|
|
146
|
+
* endpoints (`fetchDisclaimers`, `fetchJwks`) are cached with a `staleTime`;
|
|
147
|
+
* vendor-disclaimer, session-scoped disclaimer, session-creating, and
|
|
148
|
+
* status-polling endpoints opt out of caching (`staleTime`/`gcTime` of `0`)
|
|
149
|
+
* so they never serve a stale result.
|
|
150
|
+
*/
|
|
151
|
+
class KycService extends base_data_service_1.BaseDataService {
|
|
152
|
+
/**
|
|
153
|
+
* Constructs a new KycService.
|
|
154
|
+
*
|
|
155
|
+
* @param options - The constructor options.
|
|
156
|
+
* @param options.messenger - The messenger suited for this service.
|
|
157
|
+
* @param options.fetch - A function used to make HTTP requests. Defaults to
|
|
158
|
+
* the runtime's native `fetch`.
|
|
159
|
+
* @param options.baseUrl - Base URL of the KYC API
|
|
160
|
+
* @param options.fractalEncryptionBaseUrl - Base URL of the Fractal
|
|
161
|
+
* encryption service, from which the JWKS used to verify encryption-schema
|
|
162
|
+
* `jwtChain`s is fetched.
|
|
163
|
+
* @param options.queryClientConfig - Shared configuration for all queries
|
|
164
|
+
* exposed by the service.
|
|
165
|
+
* @param options.policyOptions - Options for the request service policy.
|
|
166
|
+
*/
|
|
167
|
+
constructor({ messenger, fetch: fetchFunction, baseUrl, fractalEncryptionBaseUrl, queryClientConfig = {}, policyOptions = {}, }) {
|
|
168
|
+
super({
|
|
169
|
+
name: exports.serviceName,
|
|
170
|
+
messenger,
|
|
171
|
+
queryClientConfig,
|
|
172
|
+
policyOptions,
|
|
173
|
+
});
|
|
174
|
+
_KycService_instances.add(this);
|
|
175
|
+
_KycService_fetch.set(this, void 0);
|
|
176
|
+
_KycService_baseUrl.set(this, void 0);
|
|
177
|
+
_KycService_fractalEncryptionBaseUrl.set(this, void 0);
|
|
178
|
+
// Fall back to the runtime's native `fetch`, bound to `globalThis` so it
|
|
179
|
+
// can be invoked as a method of this instance without an illegal-invocation
|
|
180
|
+
// error on platforms that check the receiver.
|
|
181
|
+
if (fetchFunction) {
|
|
182
|
+
__classPrivateFieldSet(this, _KycService_fetch, fetchFunction, "f");
|
|
183
|
+
}
|
|
184
|
+
else if (typeof globalThis.fetch === 'function') {
|
|
185
|
+
__classPrivateFieldSet(this, _KycService_fetch, globalThis.fetch.bind(globalThis), "f");
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new Error('KycService: fetch is not available globally and was not provided in options. Please inject a fetch implementation.');
|
|
189
|
+
}
|
|
190
|
+
if (!baseUrl) {
|
|
191
|
+
throw new Error('KycService: baseUrl is required');
|
|
192
|
+
}
|
|
193
|
+
__classPrivateFieldSet(this, _KycService_baseUrl, baseUrl, "f");
|
|
194
|
+
__classPrivateFieldSet(this, _KycService_fractalEncryptionBaseUrl, fractalEncryptionBaseUrl ?? '', "f");
|
|
195
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Resolves the customer's country from the geolocation source and converts it
|
|
199
|
+
* to an ISO 3166-1 alpha-3 code.
|
|
200
|
+
*
|
|
201
|
+
* @returns The alpha-3 country code.
|
|
202
|
+
* @throws If the country cannot be determined or mapped.
|
|
203
|
+
*/
|
|
204
|
+
async getGeoCountry() {
|
|
205
|
+
const location = await this.messenger.call('GeolocationController:getGeolocation');
|
|
206
|
+
// Guard nullish/empty geolocation with the documented domain error rather
|
|
207
|
+
// than letting `assert(location, string())` surface a superstruct
|
|
208
|
+
// assertion error (which would change how the failure reads in
|
|
209
|
+
// `disclaimersError`).
|
|
210
|
+
const alpha2 = typeof location === 'string' ? location.split('-')[0].toUpperCase() : '';
|
|
211
|
+
if (!alpha2 || alpha2 === 'UNKNOWN') {
|
|
212
|
+
throw new Error(`Unable to determine country from geolocation (got "${String(location)}").`);
|
|
213
|
+
}
|
|
214
|
+
const alpha3 = (0, countryCodes_js_1.alpha2ToAlpha3)(alpha2);
|
|
215
|
+
if (!alpha3) {
|
|
216
|
+
throw new Error(`Unable to map country code "${alpha2}" to an ISO 3166-1 alpha-3 code.`);
|
|
217
|
+
}
|
|
218
|
+
return alpha3;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Fetches the disclaimers the customer must accept before a session is
|
|
222
|
+
* created.
|
|
223
|
+
*
|
|
224
|
+
* @param params - The parameters.
|
|
225
|
+
* @param params.vendor - Identity vendor. Defaults to `moonpay`.
|
|
226
|
+
* @param params.country - ISO 3166-1 alpha-3 country code.
|
|
227
|
+
* @returns The disclaimers.
|
|
228
|
+
*/
|
|
229
|
+
async fetchDisclaimers({ vendor = 'moonpay', country, }) {
|
|
230
|
+
const url = new URL(`/vendors/${vendor}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
231
|
+
url.searchParams.set('country', country);
|
|
232
|
+
const data = await this.fetchQuery({
|
|
233
|
+
queryKey: [`${this.name}:fetchDisclaimers`, vendor, country],
|
|
234
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
|
|
235
|
+
staleTime: (0, utils_1.inMilliseconds)(5, utils_1.Duration.Minute),
|
|
236
|
+
});
|
|
237
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, DisclaimersResponseStruct, 'disclaimers');
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Creates a vendor session via the UKYC backend.
|
|
241
|
+
*
|
|
242
|
+
* @param params - The session parameters.
|
|
243
|
+
* @returns The created session token.
|
|
244
|
+
*/
|
|
245
|
+
async createSession(params) {
|
|
246
|
+
const url = new URL('/vendors/moonpay/sessions', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
247
|
+
const data = await this.fetchQuery({
|
|
248
|
+
queryKey: [
|
|
249
|
+
`${this.name}:createSession`,
|
|
250
|
+
params.email,
|
|
251
|
+
params.termsAcceptedAt,
|
|
252
|
+
params.disclaimerIds,
|
|
253
|
+
],
|
|
254
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
255
|
+
method: 'POST',
|
|
256
|
+
body: JSON.stringify(params),
|
|
257
|
+
}),
|
|
258
|
+
// A session-creating mutation must never serve a stale/cached result.
|
|
259
|
+
staleTime: 0,
|
|
260
|
+
gcTime: 0,
|
|
261
|
+
});
|
|
262
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, CreateSessionResponseStruct, 'sessions');
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Checks whether KYC is required for the given vendor, country, and
|
|
266
|
+
* capabilities.
|
|
267
|
+
*
|
|
268
|
+
* @param params - The check parameters.
|
|
269
|
+
* @returns Whether KYC is required.
|
|
270
|
+
*/
|
|
271
|
+
async checkKycRequired(params) {
|
|
272
|
+
const vendor = params.vendor ?? 'moonpay';
|
|
273
|
+
const url = new URL(`/vendors/${vendor}/kyc-required`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
274
|
+
const capabilities = params.capabilities ?? [{ product: 'ramps' }];
|
|
275
|
+
const body = vendor === 'moonpay'
|
|
276
|
+
? {
|
|
277
|
+
accessToken: params.accessToken,
|
|
278
|
+
country: params.country,
|
|
279
|
+
capabilities,
|
|
280
|
+
}
|
|
281
|
+
: {};
|
|
282
|
+
// MoonPay requires accessToken and country; validate before making the request.
|
|
283
|
+
if (vendor === 'moonpay') {
|
|
284
|
+
if (!params.accessToken) {
|
|
285
|
+
throw new Error('checkKycRequired: accessToken is required for vendor "moonpay".');
|
|
286
|
+
}
|
|
287
|
+
if (!params.country) {
|
|
288
|
+
throw new Error('checkKycRequired: country is required for vendor "moonpay".');
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const data = await this.fetchQuery({
|
|
292
|
+
queryKey: [
|
|
293
|
+
`${this.name}:checkKycRequired`,
|
|
294
|
+
vendor,
|
|
295
|
+
params.accessToken ?? null,
|
|
296
|
+
params.country ?? null,
|
|
297
|
+
capabilities,
|
|
298
|
+
],
|
|
299
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
300
|
+
method: 'POST',
|
|
301
|
+
body: JSON.stringify(body),
|
|
302
|
+
}),
|
|
303
|
+
// The requirement can change server-side, so always re-check.
|
|
304
|
+
staleTime: 0,
|
|
305
|
+
gcTime: 0,
|
|
306
|
+
});
|
|
307
|
+
const { required } = __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, KycRequiredResponseStruct, 'kyc-required');
|
|
308
|
+
return { kycRequired: required };
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Creates (or resumes) an empty-shell customer for the authenticated
|
|
312
|
+
* canonical user on the given identity vendor. Must run before showing
|
|
313
|
+
* vendor T&C so the customer exists and resume logic can key off vendor
|
|
314
|
+
* status.
|
|
315
|
+
*
|
|
316
|
+
* @param params - The parameters.
|
|
317
|
+
* @param params.vendor - Identity vendor (e.g. `iron` for Money/VBA).
|
|
318
|
+
* @param params.email - Email associated with the customer.
|
|
319
|
+
* @returns The vendor customer record (subset validated for controller use).
|
|
320
|
+
*/
|
|
321
|
+
async createVendorCustomer(params) {
|
|
322
|
+
const url = new URL(`/vendors/${params.vendor}/customers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
323
|
+
const data = await this.fetchQuery({
|
|
324
|
+
queryKey: [
|
|
325
|
+
`${this.name}:createVendorCustomer`,
|
|
326
|
+
params.vendor,
|
|
327
|
+
params.email,
|
|
328
|
+
],
|
|
329
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
330
|
+
method: 'POST',
|
|
331
|
+
body: JSON.stringify({ email: params.email }),
|
|
332
|
+
}),
|
|
333
|
+
// Customer creation/resume must never serve a stale/cached result.
|
|
334
|
+
staleTime: 0,
|
|
335
|
+
gcTime: 0,
|
|
336
|
+
});
|
|
337
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, VendorCustomerResponseStruct, 'vendor customers');
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Records vendor T&C acceptance (`POST /vendors/{vendor}/disclaimers`).
|
|
341
|
+
* For Iron this creates content signings from the disclaimer ids the
|
|
342
|
+
* customer accepted. Session-scoped idOS / KYC-provider consents are
|
|
343
|
+
* recorded separately via {@link submitSessionDisclaimers}. Retries re-POST
|
|
344
|
+
* the same ids, matching the legacy `POST /consents` signing step.
|
|
345
|
+
*
|
|
346
|
+
* @param params - The parameters.
|
|
347
|
+
* @param params.vendor - Identity vendor (e.g. `iron`).
|
|
348
|
+
* @param params.disclaimerIds - Accepted vendor T&C ids.
|
|
349
|
+
* @returns The vendor signing records.
|
|
350
|
+
*/
|
|
351
|
+
async submitVendorDisclaimers(params) {
|
|
352
|
+
const url = new URL(`/vendors/${encodeURIComponent(params.vendor)}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
353
|
+
const data = await this.fetchQuery({
|
|
354
|
+
queryKey: [
|
|
355
|
+
`${this.name}:submitVendorDisclaimers`,
|
|
356
|
+
params.vendor,
|
|
357
|
+
params.disclaimerIds,
|
|
358
|
+
],
|
|
359
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
360
|
+
method: 'POST',
|
|
361
|
+
body: JSON.stringify({ disclaimerIds: params.disclaimerIds }),
|
|
362
|
+
}),
|
|
363
|
+
staleTime: 0,
|
|
364
|
+
gcTime: 0,
|
|
365
|
+
});
|
|
366
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, VendorSigningsResponseStruct, 'vendor disclaimers');
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Fetches the session-scoped idOS + KYC-provider disclaimer catalog
|
|
370
|
+
* (`GET /sessions/{sessionId}/disclaimers`). Requires an existing UKYC
|
|
371
|
+
* session; vendor T&Cs continue to come from {@link fetchDisclaimers}.
|
|
372
|
+
*
|
|
373
|
+
* @param params - The parameters.
|
|
374
|
+
* @param params.sessionId - The UKYC session id.
|
|
375
|
+
* @returns The catalog, including which documents are already consented.
|
|
376
|
+
*/
|
|
377
|
+
async fetchSessionDisclaimers(params) {
|
|
378
|
+
const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
379
|
+
const data = await this.fetchQuery({
|
|
380
|
+
queryKey: [`${this.name}:fetchSessionDisclaimers`, params.sessionId],
|
|
381
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
|
|
382
|
+
// Consent state can change after a POST, so always re-fetch.
|
|
383
|
+
staleTime: 0,
|
|
384
|
+
gcTime: 0,
|
|
385
|
+
});
|
|
386
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionDisclaimersResponseStruct, 'session disclaimers');
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Records idOS + KYC-provider consents for a UKYC session
|
|
390
|
+
* (`POST /sessions/{sessionId}/disclaimers`). `key`/`version` pairs must
|
|
391
|
+
* match the current catalog from {@link fetchSessionDisclaimers}. A 409
|
|
392
|
+
* means those document versions were already recorded for the session.
|
|
393
|
+
*
|
|
394
|
+
* @param params - The consent parameters.
|
|
395
|
+
* @returns The updated catalog after recording.
|
|
396
|
+
*/
|
|
397
|
+
async submitSessionDisclaimers(params) {
|
|
398
|
+
const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/disclaimers`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
399
|
+
const data = await this.fetchQuery({
|
|
400
|
+
queryKey: [
|
|
401
|
+
`${this.name}:submitSessionDisclaimers`,
|
|
402
|
+
params.sessionId,
|
|
403
|
+
params.idOS,
|
|
404
|
+
params.kycProvider,
|
|
405
|
+
params.credentialReusabilityConsentGiven,
|
|
406
|
+
],
|
|
407
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
408
|
+
method: 'POST',
|
|
409
|
+
body: JSON.stringify({
|
|
410
|
+
idOS: params.idOS,
|
|
411
|
+
kycProvider: params.kycProvider,
|
|
412
|
+
credentialReusabilityConsentGiven: params.credentialReusabilityConsentGiven,
|
|
413
|
+
}),
|
|
414
|
+
}),
|
|
415
|
+
staleTime: 0,
|
|
416
|
+
gcTime: 0,
|
|
417
|
+
});
|
|
418
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionDisclaimersResponseStruct, 'session disclaimers');
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Fetches the user-keyed simplified KYC status used by Money toast / banner
|
|
422
|
+
* surfaces (`GET /kyc/status`).
|
|
423
|
+
*
|
|
424
|
+
* @returns The simplified status payload.
|
|
425
|
+
*/
|
|
426
|
+
async fetchKycStatus() {
|
|
427
|
+
const url = new URL('/kyc/status', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
428
|
+
const data = await this.fetchQuery({
|
|
429
|
+
queryKey: [`${this.name}:fetchKycStatus`],
|
|
430
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
|
|
431
|
+
// Status is polled for toast flips, so it must always be fresh.
|
|
432
|
+
staleTime: 0,
|
|
433
|
+
gcTime: 0,
|
|
434
|
+
});
|
|
435
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, KycUserStatusResponseStruct, 'kyc status');
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Fetches the Fractal encryption service JWKS used to verify the `jwtChain`s
|
|
439
|
+
* returned inside encryption schemas from {@link KycService.createUkycSession}.
|
|
440
|
+
*
|
|
441
|
+
* This is an unauthenticated request to a well-known path on the Fractal
|
|
442
|
+
* host, distinct from the UKYC base URL.
|
|
443
|
+
*
|
|
444
|
+
* @returns The JWKS keys.
|
|
445
|
+
*/
|
|
446
|
+
async fetchJwks() {
|
|
447
|
+
if (!__classPrivateFieldGet(this, _KycService_fractalEncryptionBaseUrl, "f")) {
|
|
448
|
+
throw new Error('KycService: fractalEncryptionBaseUrl is not configured; cannot fetch JWKS to verify encryption schemas.');
|
|
449
|
+
}
|
|
450
|
+
const url = new URL(constants_js_1.UKYC_JWKS_PATH, __classPrivateFieldGet(this, _KycService_fractalEncryptionBaseUrl, "f"));
|
|
451
|
+
const data = await this.fetchQuery({
|
|
452
|
+
queryKey: [`${this.name}:fetchJwks`, __classPrivateFieldGet(this, _KycService_fractalEncryptionBaseUrl, "f")],
|
|
453
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }, { authenticated: false }),
|
|
454
|
+
staleTime: (0, utils_1.inMilliseconds)(1, utils_1.Duration.Hour),
|
|
455
|
+
});
|
|
456
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, JwksResponseStruct, 'JWKS');
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Creates a UKYC session for the SumSub document-verification sub-flow.
|
|
460
|
+
*
|
|
461
|
+
* The response carries per-secret encryption schemas (`encryptionDataKey` and
|
|
462
|
+
* `ukycCapabilityToken`) so the client can wrap the `data_encryption_key` and
|
|
463
|
+
* the read-only `ukyc_capability_token` and submit them via
|
|
464
|
+
* {@link KycService.setAuthorizations}.
|
|
465
|
+
*
|
|
466
|
+
* @param params - The session parameters.
|
|
467
|
+
* @returns The UKYC session id and encryption schemas.
|
|
468
|
+
*/
|
|
469
|
+
async createUkycSession(params) {
|
|
470
|
+
const url = new URL('/sessions', __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
471
|
+
const data = await this.fetchQuery({
|
|
472
|
+
queryKey: [`${this.name}:createUkycSession`, params.jwtToken],
|
|
473
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
474
|
+
method: 'POST',
|
|
475
|
+
body: JSON.stringify({
|
|
476
|
+
vendorId: params.vendor ?? 'moonpay',
|
|
477
|
+
vendorUserId: 'mockedId',
|
|
478
|
+
jwtToken: params.jwtToken,
|
|
479
|
+
vendorMetadata: params.vendorMetadata ?? {},
|
|
480
|
+
}),
|
|
481
|
+
}),
|
|
482
|
+
// A session-creating mutation must never serve a stale/cached result.
|
|
483
|
+
staleTime: 0,
|
|
484
|
+
gcTime: 0,
|
|
485
|
+
});
|
|
486
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, UkycSessionResponseStruct, 'UKYC sessions');
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Submits the wrapped `data_encryption_key` and wrapped
|
|
490
|
+
* `ukyc_capability_token` for a UKYC session. Both secrets are sealed with
|
|
491
|
+
* `wrapEncryptionKey` against the encryption schemas returned by
|
|
492
|
+
* {@link KycService.createUkycSession}.
|
|
493
|
+
*
|
|
494
|
+
* @param params - The wrapped authorizations.
|
|
495
|
+
* @returns The session status after the authorizations are applied.
|
|
496
|
+
*/
|
|
497
|
+
async setAuthorizations(params) {
|
|
498
|
+
const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/authorizations`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
499
|
+
const data = await this.fetchQuery({
|
|
500
|
+
queryKey: [`${this.name}:setAuthorizations`, params.sessionId],
|
|
501
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, {
|
|
502
|
+
method: 'POST',
|
|
503
|
+
body: JSON.stringify({
|
|
504
|
+
wrappedEncryptionDataKey: params.wrappedEncryptionDataKey,
|
|
505
|
+
wrappedUkycCapabilityToken: params.wrappedUkycCapabilityToken,
|
|
506
|
+
}),
|
|
507
|
+
}),
|
|
508
|
+
staleTime: 0,
|
|
509
|
+
gcTime: 0,
|
|
510
|
+
});
|
|
511
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionStatusResponseStruct, 'authorizations');
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Creates (or refreshes) the SumSub verification journey for a UKYC session,
|
|
515
|
+
* returning the applicant access token used to launch the SDK.
|
|
516
|
+
*
|
|
517
|
+
* @param sessionId - The UKYC session id from `createUkycSession`.
|
|
518
|
+
* @returns The applicant access token and status.
|
|
519
|
+
*/
|
|
520
|
+
async createJourney(sessionId) {
|
|
521
|
+
const url = new URL(`/sessions/${encodeURIComponent(sessionId)}/journey`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
522
|
+
const data = await this.fetchQuery({
|
|
523
|
+
queryKey: [`${this.name}:createJourney`, sessionId],
|
|
524
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'POST' }),
|
|
525
|
+
// Journeys are (re)created on demand; do not reuse a cached token.
|
|
526
|
+
staleTime: 0,
|
|
527
|
+
gcTime: 0,
|
|
528
|
+
});
|
|
529
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, ApplicantAccessTokenResponseStruct, 'journey');
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Fetches the current status of a UKYC session. Polled after the SumSub SDK
|
|
533
|
+
* completes to determine the final verification decision.
|
|
534
|
+
*
|
|
535
|
+
* @param params - The parameters.
|
|
536
|
+
* @param params.sessionId - The UKYC session id.
|
|
537
|
+
* @returns The session status.
|
|
538
|
+
*/
|
|
539
|
+
async getSessionStatus(params) {
|
|
540
|
+
const url = new URL(`/sessions/${encodeURIComponent(params.sessionId)}/status`, __classPrivateFieldGet(this, _KycService_baseUrl, "f"));
|
|
541
|
+
const data = await this.fetchQuery({
|
|
542
|
+
queryKey: [`${this.name}:getSessionStatus`, params.sessionId],
|
|
543
|
+
queryFn: async () => __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_requestJson).call(this, url, { method: 'GET' }),
|
|
544
|
+
// Status is polled for a terminal decision, so it must always be fresh.
|
|
545
|
+
staleTime: 0,
|
|
546
|
+
gcTime: 0,
|
|
547
|
+
});
|
|
548
|
+
return __classPrivateFieldGet(this, _KycService_instances, "m", _KycService_validateResponse).call(this, data, SessionStatusResponseStruct, 'session status');
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
exports.KycService = KycService;
|
|
552
|
+
_KycService_fetch = new WeakMap(), _KycService_baseUrl = new WeakMap(), _KycService_fractalEncryptionBaseUrl = new WeakMap(), _KycService_instances = new WeakSet(), _KycService_validateResponse = function _KycService_validateResponse(data, struct, apiName) {
|
|
553
|
+
try {
|
|
554
|
+
(0, superstruct_1.assert)(data, struct);
|
|
555
|
+
return data;
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
const detail = error instanceof superstruct_1.StructError
|
|
559
|
+
? `${error.message} (received: ${JSON.stringify(data)})`
|
|
560
|
+
: // `assert` only ever throws `StructError` for the plain structs used
|
|
561
|
+
// here, so this is a defensive fallback that is not exercised.
|
|
562
|
+
/* istanbul ignore next */
|
|
563
|
+
String(error);
|
|
564
|
+
throw new Error(`Malformed response received from ${apiName} API: ${detail}`);
|
|
565
|
+
}
|
|
566
|
+
}, _KycService_requestJson =
|
|
567
|
+
/**
|
|
568
|
+
* Performs a single JSON request.
|
|
569
|
+
*
|
|
570
|
+
* This is meant to be used as the `queryFn` for {@link fetchQuery}, which
|
|
571
|
+
* wraps it in the shared service policy (retries, circuit breaker). Requests
|
|
572
|
+
* are authenticated with the wallet bearer token by default; pass
|
|
573
|
+
* `{ authenticated: false }` for calls to services that do not expect it
|
|
574
|
+
* (e.g. the Fractal JWKS endpoint).
|
|
575
|
+
*
|
|
576
|
+
* @param url - The request URL.
|
|
577
|
+
* @param init - The request init (method, body).
|
|
578
|
+
* @param options - Request options.
|
|
579
|
+
* @param options.authenticated - Whether to attach the bearer token. Defaults
|
|
580
|
+
* to `true`.
|
|
581
|
+
* @returns The parsed JSON response.
|
|
582
|
+
*/
|
|
583
|
+
async function _KycService_requestJson(url, init, options = {}) {
|
|
584
|
+
const { authenticated = true } = options;
|
|
585
|
+
const headers = {};
|
|
586
|
+
// Only advertise a JSON body when one is actually sent; bodyless requests
|
|
587
|
+
// (e.g. `createJourney`) must not carry a `Content-Type`.
|
|
588
|
+
if (init.body !== undefined && init.body !== null) {
|
|
589
|
+
headers['Content-Type'] = 'application/json';
|
|
590
|
+
}
|
|
591
|
+
if (authenticated) {
|
|
592
|
+
const bearerToken = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
593
|
+
if (!bearerToken) {
|
|
594
|
+
throw new Error('Unable to obtain an authentication bearer token — is the wallet signed in?');
|
|
595
|
+
}
|
|
596
|
+
(0, superstruct_1.assert)(bearerToken, (0, superstruct_1.string)());
|
|
597
|
+
headers.Authorization = `Bearer ${bearerToken}`;
|
|
598
|
+
}
|
|
599
|
+
const response = await __classPrivateFieldGet(this, _KycService_fetch, "f").call(this, url.toString(), {
|
|
600
|
+
...init,
|
|
601
|
+
headers,
|
|
602
|
+
});
|
|
603
|
+
if (!response.ok) {
|
|
604
|
+
let detail = '';
|
|
605
|
+
try {
|
|
606
|
+
const errorBody = await response.json();
|
|
607
|
+
if (errorBody && typeof errorBody === 'object') {
|
|
608
|
+
const record = errorBody;
|
|
609
|
+
if (typeof record.message === 'string') {
|
|
610
|
+
detail = record.message;
|
|
611
|
+
}
|
|
612
|
+
else if (typeof record.error === 'string') {
|
|
613
|
+
detail = record.error;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
catch {
|
|
618
|
+
// Ignore body parse failures; status alone is still useful.
|
|
619
|
+
}
|
|
620
|
+
throw new controller_utils_1.HttpError(response.status, `Fetching '${url.toString()}' failed with status '${response.status}'${detail ? `: ${detail}` : ''}`);
|
|
621
|
+
}
|
|
622
|
+
// DELETE (and similar) endpoints return 204 No Content.
|
|
623
|
+
if (response.status === 204) {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
return (await response.json());
|
|
627
|
+
};
|
|
628
|
+
//# sourceMappingURL=KycService.cjs.map
|