@keetanetwork/anchor 0.0.97 → 0.0.99
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/client/index.d.ts +2 -0
- package/client/index.d.ts.map +1 -1
- package/client/index.js.map +1 -1
- package/lib/queue/index.d.ts +39 -16
- package/lib/queue/index.d.ts.map +1 -1
- package/lib/queue/index.js +72 -0
- package/lib/queue/index.js.map +1 -1
- package/lib/resolver.d.ts +44 -2
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.generated.js +391 -341
- package/lib/resolver.generated.js.map +1 -1
- package/lib/resolver.js +45 -1
- package/lib/resolver.js.map +1 -1
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
- package/services/kyc/client.d.ts +3 -3
- package/services/kyc/client.d.ts.map +1 -1
- package/services/kyc/client.js +12 -6
- package/services/kyc/client.js.map +1 -1
- package/services/kyc/common.d.ts +9 -2
- package/services/kyc/common.d.ts.map +1 -1
- package/services/kyc/common.js.map +1 -1
- package/services/kyc/common.server.generated.js +6 -1
- package/services/kyc/common.server.generated.js.map +1 -1
- package/services/kyc/server.d.ts +13 -1
- package/services/kyc/server.d.ts.map +1 -1
- package/services/kyc/server.js +9 -0
- package/services/kyc/server.js.map +1 -1
- package/services/storage/clients/profile.d.ts +4 -4
- package/services/storage/clients/profile.d.ts.map +1 -1
- package/services/storage/clients/profile.generated.js +13 -13
- package/services/storage/clients/profile.js +1 -1
- package/services/storage/clients/profile.js.map +1 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.99",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@keetanetwork/anchor",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.99",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@keetanetwork/currency-info": "1.2.5",
|
|
13
|
-
"@keetanetwork/keetanet-client": "0.18.
|
|
13
|
+
"@keetanetwork/keetanet-client": "0.18.7",
|
|
14
14
|
"@noble/hashes": "1.5.0",
|
|
15
15
|
"typia": "9.5.0"
|
|
16
16
|
},
|
|
@@ -186,8 +186,8 @@
|
|
|
186
186
|
"license": "ISC"
|
|
187
187
|
},
|
|
188
188
|
"node_modules/@keetanetwork/keetanet-client": {
|
|
189
|
-
"version": "0.18.
|
|
190
|
-
"integrity": "sha512-
|
|
189
|
+
"version": "0.18.7",
|
|
190
|
+
"integrity": "sha512-JXiFaI8l/J2iYXyfWw0RoJXrvA2iVoKz7y+OO9IVH7FmqssL5u3oPZm2jGUDZ2Z5hYl4qIqiSb1XwU89si6H9w==",
|
|
191
191
|
"license": "see LICENSE",
|
|
192
192
|
"dependencies": {
|
|
193
193
|
"secp256k1": "5.0.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.99",
|
|
4
4
|
"description": "KeetaNetwork Network Anchor",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@keetanetwork/currency-info": "1.2.5",
|
|
27
|
-
"@keetanetwork/keetanet-client": "0.18.
|
|
27
|
+
"@keetanetwork/keetanet-client": "0.18.7",
|
|
28
28
|
"@noble/hashes": "1.5.0",
|
|
29
29
|
"typia": "9.5.0"
|
|
30
30
|
},
|
package/services/kyc/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { KYCVerificationStatus } from './status.js';
|
|
|
8
8
|
import { type SignableAccount } from '../../lib/utils/signing.js';
|
|
9
9
|
import type { Logger } from '../../lib/log/index.ts';
|
|
10
10
|
import type Resolver from '../../lib/resolver.ts';
|
|
11
|
-
import type { ServiceMetadata } from '../../lib/resolver.ts';
|
|
11
|
+
import type { KYCEntityType, ServiceMetadata } from '../../lib/resolver.ts';
|
|
12
12
|
/**
|
|
13
13
|
* The configuration options for the KYC Anchor client.
|
|
14
14
|
*/
|
|
@@ -145,8 +145,8 @@ declare class KeetaKYCAnchorClient {
|
|
|
145
145
|
getCertificates(providerID: ProviderID, request: KeetaKYCAnchorCreateVerificationRequest & {
|
|
146
146
|
id: RequestID;
|
|
147
147
|
}): Promise<KeetaKYCAnchorClientGetCertificateResponse>;
|
|
148
|
-
getSupportedCountries(): Promise<CurrencyInfo.Country[]>;
|
|
149
|
-
getVerificationStatus(providerID: ProviderID, request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'countryCodes'> & {
|
|
148
|
+
getSupportedCountries(entityType?: KYCEntityType): Promise<CurrencyInfo.Country[]>;
|
|
149
|
+
getVerificationStatus(providerID: ProviderID, request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'countryCodes' | 'entityType'> & {
|
|
150
150
|
id: RequestID;
|
|
151
151
|
account: SignableAccount;
|
|
152
152
|
}): Promise<KeetaKYCAnchorClientGetVerificationStatusResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/services/kyc/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,KAAK,EACX,MAAM,IAAI,cAAc,EACxB,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BA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eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,uCAAuC,GAAG;QAAE,EAAE,EAAE,SAAS,CAAC;KAAE,GAAG,OAAO,CAAC,0CAA0C,CAAC;IAwEnK,qBAAqB,CAAC,UAAU,GAAE,aAA4B,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;IAIhG,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,uCAAuC,EAAE,cAAc,GAAG,YAAY,CAAC,GAAG;QAAE,EAAE,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,eAAe,CAAC;KAAE,GAAG,OAAO,CAAC,iDAAiD,CAAC;IAmD/O,WAAW,CAAC,GAAG,YAAY,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IAIvD,aAAa,CAAC,GAAG,YAAY,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;CAG/D;AAED,eAAe,oBAAoB,CAAC"}
|
package/services/kyc/client.js
CHANGED
|
@@ -35,7 +35,8 @@ const isKeetaKYCAnchorGetVerificationStatusResponse = (() => { const _io0 = inpu
|
|
|
35
35
|
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
36
36
|
async function getEndpoints(resolver, request) {
|
|
37
37
|
const response = await resolver.lookup('kyc', {
|
|
38
|
-
countryCodes: request.countryCodes
|
|
38
|
+
countryCodes: request.countryCodes,
|
|
39
|
+
...(request.entityType !== undefined ? { entityType: request.entityType } : {})
|
|
39
40
|
});
|
|
40
41
|
if (response === undefined) {
|
|
41
42
|
return (null);
|
|
@@ -162,7 +163,8 @@ class KeetaKYCVerification {
|
|
|
162
163
|
return (this.client.getVerificationStatus(this.providerID, {
|
|
163
164
|
id: this.id,
|
|
164
165
|
account: this.account,
|
|
165
|
-
countryCodes: this.request.countryCodes
|
|
166
|
+
countryCodes: this.request.countryCodes,
|
|
167
|
+
...(this.request.entityType !== undefined ? { entityType: this.request.entityType } : {})
|
|
166
168
|
}));
|
|
167
169
|
}
|
|
168
170
|
}
|
|
@@ -232,7 +234,11 @@ class KeetaKYCAnchorClient {
|
|
|
232
234
|
account: request.account.publicKeyString.get(),
|
|
233
235
|
signed: signedData
|
|
234
236
|
};
|
|
235
|
-
|
|
237
|
+
/* Only provider selection defaults to individual; the by-ID lookups below must not filter. */
|
|
238
|
+
const endpoints = await getEndpoints(this.resolver, {
|
|
239
|
+
countryCodes: signedRequest.countryCodes,
|
|
240
|
+
entityType: signedRequest.entityType ?? 'individual'
|
|
241
|
+
});
|
|
236
242
|
if (endpoints === null) {
|
|
237
243
|
throw (new Error('No KYC endpoints found for the given criteria'));
|
|
238
244
|
}
|
|
@@ -351,11 +357,11 @@ class KeetaKYCAnchorClient {
|
|
|
351
357
|
})
|
|
352
358
|
});
|
|
353
359
|
}
|
|
354
|
-
async getSupportedCountries() {
|
|
355
|
-
return (await this.resolver.listSupportedKYCCountries());
|
|
360
|
+
async getSupportedCountries(entityType = 'individual') {
|
|
361
|
+
return (await this.resolver.listSupportedKYCCountries(entityType));
|
|
356
362
|
}
|
|
357
363
|
async getVerificationStatus(providerID, request) {
|
|
358
|
-
const endpoints = await getEndpoints(this.resolver,
|
|
364
|
+
const endpoints = await getEndpoints(this.resolver, request);
|
|
359
365
|
if (endpoints === null) {
|
|
360
366
|
throw (new Error('No KYC endpoints found for the given criteria'));
|
|
361
367
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/services/kyc/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,M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etaNetLib } from '@keetanetwork/keetanet-client';\nimport * as CurrencyInfo from '@keetanetwork/currency-info';\nimport { createIs } from 'typia';\n\nimport { getDefaultResolver } from '../../config.js';\nimport { Certificate as KYCCertificate } from '../../lib/certificates.js';\n\nimport type {\n\tClient as KeetaNetClient,\n\tUserClient as KeetaNetUserClient\n} from '@keetanetwork/keetanet-client';\nimport type {\n\tKeetaKYCAnchorCreateVerificationRequest,\n\tKeetaKYCAnchorCreateVerificationResponse,\n\tKeetaKYCAnchorGetCertificateResponse,\n\tKeetaKYCAnchorGetVerificationStatusResponse\n} from './common.ts';\nimport type {\n\tKYCVerificationStatus\n} from './status.js';\nimport {\n\tverifySignedData,\n\tgenerateSignedData\n} from './common.js';\nimport { addSignatureToURL } from '../../lib/http-server/common.js';\nimport { SignData, type SignableAccount } from '../../lib/utils/signing.js';\nimport type { Logger } from '../../lib/log/index.ts';\nimport type Resolver from '../../lib/resolver.ts';\nimport type { ServiceMetadata } from '../../lib/resolver.ts';\nimport crypto from '../../lib/utils/crypto.js';\nimport { validateURL } from '../../lib/utils/url.js';\n\nconst PARANOID = true;\n\n/**\n * The configuration options for the KYC Anchor client.\n */\nexport type KeetaKYCAnchorClientConfig = {\n\t/**\n\t * The ID of the client. This is used to identify the client in logs.\n\t * If not provided, a random ID will be generated.\n\t */\n\tid?: string;\n\t/**\n\t * The logger to use for logging messages. If not provided, no logging\n\t * will be done.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The resolver to use for resolving KYC Anchor services. If not\n\t * provided, a default resolver will be created using the provided\n\t * client and network (if the network is also not provided and the\n\t * client is not a UserClient, an error occurs).\n\t */\n\tresolver?: Resolver;\n} & Omit<NonNullable<Parameters<typeof getDefaultResolver>[1]>, 'client'>;\n\n/**\n * Any kind of X.509v3 Certificate. This may or may not be a KYC certificate.\n */\ntype BaseCertificate = InstanceType<typeof KeetaNetLib.Utils.Certificate.Certificate>;\n\n/**\n * The response type for the {@link KeetaKYCAnchorClient['getCertificates']()} method of the KYC Anchor client.\n * It contains the certificate and optionally a set of intermediate certificates.\n */\ntype KeetaKYCAnchorClientGetCertificateResponse = ({\n\tok: true;\n\tresults: {\n\t\tcertificate: KYCCertificate;\n\t\tintermediates?: Set<BaseCertificate> | undefined;\n\t}[]\n} | {\n\tok: false;\n\tretryAfter: number;\n\treason: string;\n});\n\n/**\n * The response type for {@link KeetaKYCAnchorClient['getVerificationStatus']()}.\n */\ntype KeetaKYCAnchorClientGetVerificationStatusResponse = {\n\tstatus: KYCVerificationStatus;\n\trequiresManualVerification?: boolean;\n};\n\ntype KeetaKYCAnchorClientCreateVerificationRequest = Omit<KeetaKYCAnchorCreateVerificationRequest, 'signed' | 'account'> & {\n\taccount: InstanceType<typeof KeetaNetLib.Account>;\n};\n\n/**\n * An opaque type that represents a provider ID.\n */\ntype ProviderID = string & {\n\treadonly __providerID: unique symbol;\n};\n\n/**\n * An opaque type that represents a KYC Anchor request ID\n */\ntype RequestID = string & {\n\treadonly __requestID: unique symbol;\n};\n\n/**\n * A list of operations that can be performed by the KYC Anchor service.\n */\ntype KeetaKYCAnchorOperations = {\n\t[operation in keyof NonNullable<ServiceMetadata['services']['kyc']>[string]['operations']]?: (params?: { [key: string]: string; }) => URL;\n};\n\n/**\n * The service information for a KYC Anchor service.\n */\ntype KeetaKYCVerificationServiceInfo = {\n\toperations: {\n\t\t[operation in keyof KeetaKYCAnchorOperations]: Promise<KeetaKYCAnchorOperations[operation]>;\n\t};\n\tcountryCodes?: CurrencyInfo.Country[] | undefined;\n\tca: () => Promise<KYCCertificate>;\n};\n\n/**\n * For each matching KYC Anchor service, this type describes the\n * operations available and the country codes that the service supports.\n */\ntype GetEndpointsResult = {\n\t[id: ProviderID]: KeetaKYCVerificationServiceInfo;\n};\n\nconst isKeetaKYCAnchorCreateVerificationResponse = createIs<KeetaKYCAnchorCreateVerificationResponse>();\nconst isKeetaKYCAnchorGetCertificateResponse = createIs<KeetaKYCAnchorGetCertificateResponse>();\nconst isKeetaKYCAnchorGetVerificationStatusResponse = createIs<KeetaKYCAnchorGetVerificationStatusResponse>();\n\nasync function getEndpoints(resolver: Resolver, request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'countryCodes'>): Promise<GetEndpointsResult | null> {\n\tconst response = await resolver.lookup('kyc', {\n\t\tcountryCodes: request.countryCodes\n\t});\n\n\tif (response === undefined) {\n\t\treturn(null);\n\t}\n\n\tconst serviceInfoPromises = Object.entries(response).map(async function([id, serviceInfo]): Promise<[ProviderID, KeetaKYCVerificationServiceInfo]> {\n\t\tconst countryCodesPromises = (await serviceInfo.countryCodes?.('array'))?.map(async function(countryCode) {\n\t\t\treturn(new CurrencyInfo.Country(CurrencyInfo.Country.assertCountryCode(await countryCode('string'))));\n\t\t});\n\n\t\tlet countryCodes: CurrencyInfo.Country[] | undefined;\n\t\tif (countryCodesPromises !== undefined) {\n\t\t\tconst countryCodesResults = await Promise.allSettled(countryCodesPromises);\n\t\t\tcountryCodes = countryCodesResults.map(function(result) {\n\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\treturn(result.value);\n\t\t\t\t}\n\t\t\t\tthrow(result.reason);\n\t\t\t});\n\t\t}\n\n\t\tconst operations = await serviceInfo.operations('object');\n\t\tconst operationsFunctions: KeetaKYCVerificationServiceInfo['operations'] = {};\n\t\tfor (const [key, operation] of Object.entries(operations)) {\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tObject.defineProperty(operationsFunctions, key, {\n\t\t\t\tget: async function() {\n\t\t\t\t\tconst url = await operation('string');\n\t\t\t\t\treturn(function(params?: { [key: string]: string; }): URL {\n\t\t\t\t\t\tlet substitutedURL = url;\n\t\t\t\t\t\tfor (const [paramKey, paramValue] of Object.entries(params ?? {})) {\n\t\t\t\t\t\t\tsubstitutedURL = substitutedURL.replace(`{${paramKey}}`, encodeURIComponent(paramValue));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(validateURL(substitutedURL));\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true\n\t\t\t});\n\t\t}\n\t\treturn([\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tid as ProviderID,\n\t\t\t{\n\t\t\t\tcountryCodes: countryCodes,\n\t\t\t\toperations: operationsFunctions,\n\t\t\t\tca: async function() {\n\t\t\t\t\tconst certificatePEM = await serviceInfo.ca?.('string');\n\t\t\t\t\tconst certificate = new KYCCertificate(certificatePEM);\n\n\t\t\t\t\treturn(certificate);\n\t\t\t\t}\n\t\t\t}\n\t\t]);\n\t});\n\n\tconst retval = Object.fromEntries(await Promise.all(serviceInfoPromises));\n\n\treturn(retval);\n}\n\ntype KeetaKYCAnchorCommonConfig = {\n\tid: ProviderID;\n\tserviceInfo: KeetaKYCVerificationServiceInfo;\n\trequest: KeetaKYCAnchorCreateVerificationRequest;\n\taccount: SignableAccount;\n\tclient: KeetaKYCAnchorClient;\n\toperations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates' | 'getVerificationStatus'>>;\n\tlogger?: Logger | undefined;\n};\n\n/**\n * Represents an in-progress KYC verification request.\n */\nclass KeetaKYCVerification {\n\treadonly providerID: KeetaKYCAnchorCommonConfig['id'];\n\treadonly id: RequestID;\n\tprivate readonly serviceInfo: KeetaKYCAnchorCommonConfig['serviceInfo'];\n\tprivate readonly request: KeetaKYCAnchorCommonConfig['request'];\n\tprivate readonly account: KeetaKYCAnchorCommonConfig['account'];\n\tprivate readonly logger?: KeetaKYCAnchorCommonConfig['logger'] | undefined;\n\tprivate readonly client: KeetaKYCAnchorCommonConfig['client'];\n\tprivate readonly response: Extract<KeetaKYCAnchorCreateVerificationResponse, { ok: true }>;\n\n\tprivate constructor(args: KeetaKYCAnchorCommonConfig, response: Extract<KeetaKYCAnchorCreateVerificationResponse, { ok: true }>) {\n\t\tthis.providerID = args.id;\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.id = response.id as RequestID;\n\t\tthis.serviceInfo = args.serviceInfo;\n\t\tthis.request = args.request;\n\t\tthis.account = args.account;\n\t\tthis.client = args.client;\n\t\tthis.logger = args.logger;\n\t\tthis.response = response;\n\n\t\tthis.logger?.debug(`Created KYC verification for provider ID: ${this.providerID}, request: ${JSON.stringify(args.request)}, response: ${JSON.stringify(response)}`);\n\t}\n\n\tstatic async start(args: KeetaKYCAnchorCommonConfig): Promise<KeetaKYCVerification> {\n\t\targs.logger?.debug(`Starting KYC verification for provider ID: ${args.id}, request: ${JSON.stringify(args.request)}`);\n\n\t\tconst endpoints = args.operations;\n\t\tconst createVerification = endpoints.createVerification?.();\n\t\tif (createVerification === undefined) {\n\t\t\tthrow(new Error('KYC verification service does not support createVerification operation'));\n\t\t}\n\n\t\tconst requestInformation = await fetch(createVerification, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: args.request\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaKYCAnchorCreateVerificationResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from KYC verification service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(new Error(`KYC verification request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\targs.logger?.debug(`KYC verification request successful, request ID ${requestInformationJSON.id}`);\n\n\t\treturn(new KeetaKYCVerification(args, requestInformationJSON));\n\n\t}\n\n\tget expectedCost(): typeof this.response.expectedCost {\n\t\treturn(this.response.expectedCost);\n\t}\n\n\tget webURL(): URL {\n\t\treturn(validateURL(this.response.webURL));\n\t}\n\n\tasync getProviderIssuerCertificate(): Promise<KYCCertificate> {\n\t\treturn(await this.serviceInfo.ca());\n\t}\n\n\tgetCertificates(): Promise<KeetaKYCAnchorClientGetCertificateResponse> {\n\t\treturn(this.client.getCertificates(this.providerID, {\n\t\t\tid: this.id,\n\t\t\t...this.request\n\t\t}));\n\t}\n\n\tgetVerificationStatus(): Promise<KeetaKYCAnchorClientGetVerificationStatusResponse> {\n\t\treturn(this.client.getVerificationStatus(this.providerID, {\n\t\t\tid: this.id,\n\t\t\taccount: this.account,\n\t\t\tcountryCodes: this.request.countryCodes\n\t\t}));\n\t}\n}\n\n/**\n * Represents the KYC operations for a specific provider\n */\nclass KeetaKYCProvider {\n\treadonly id: ProviderID;\n\tprivate readonly serviceInfo: KeetaKYCVerificationServiceInfo;\n\tprivate readonly request: KeetaKYCAnchorCreateVerificationRequest;\n\tprivate readonly account: SignableAccount;\n\tprivate readonly logger?: Logger | undefined;\n\tprivate readonly client: KeetaKYCAnchorClient;\n\tprivate readonly operations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates' | 'getVerificationStatus'>>;\n\n\tprivate cachedCA?: KYCCertificate;\n\n\tconstructor(args: KeetaKYCAnchorCommonConfig) {\n\t\tthis.id = args.id;\n\t\tthis.serviceInfo = args.serviceInfo;\n\t\tthis.request = args.request;\n\t\tthis.account = args.account;\n\t\tthis.client = args.client;\n\t\tthis.operations = args.operations;\n\t\tthis.logger = args.logger;\n\n\t\tthis.logger?.debug(`Created KYC verification for provider ID: ${args.id}, request: ${JSON.stringify(args.request)}`);\n\t}\n\n\tasync countryCodes(): Promise<CurrencyInfo.Country[] | undefined> {\n\t\treturn(this.serviceInfo.countryCodes);\n\t}\n\n\tasync ca(): Promise<KYCCertificate> {\n\t\tif (this.cachedCA !== undefined) {\n\t\t\treturn(this.cachedCA);\n\t\t}\n\n\t\tthis.cachedCA = await this.serviceInfo.ca();\n\n\t\treturn(this.cachedCA);\n\t}\n\n\tasync startVerification(): Promise<KeetaKYCVerification> {\n\t\treturn(await KeetaKYCVerification.start({\n\t\t\tid: this.id,\n\t\t\tserviceInfo: this.serviceInfo,\n\t\t\trequest: this.request,\n\t\t\taccount: this.account,\n\t\t\tclient: this.client,\n\t\t\toperations: this.operations,\n\t\t\tlogger: this.logger\n\t\t}));\n\t}\n}\n\n\nclass KeetaKYCAnchorClient {\n\treadonly resolver: Resolver;\n\treadonly id: string;\n\tprivate readonly logger?: Logger | undefined;\n\n\tconstructor(client: KeetaNetClient | KeetaNetUserClient, config: KeetaKYCAnchorClientConfig = {}) {\n\t\tthis.resolver = config.resolver ?? getDefaultResolver(client, config);\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\t\tthis.logger = config.logger;\n\t}\n\n\tasync createVerification(request: KeetaKYCAnchorClientCreateVerificationRequest): Promise<KeetaKYCProvider[]> {\n\t\tconst signedData = await generateSignedData(request.account.assertAccount());\n\n\t\tif (PARANOID) {\n\t\t\tconst check = await verifySignedData({ account: request.account.publicKeyString.get(), signed: signedData });\n\t\t\tif (!check) {\n\t\t\t\tthrow(new Error('Failed to verify signed data'));\n\t\t\t}\n\t\t}\n\n\t\tconst signedRequest: KeetaKYCAnchorCreateVerificationRequest = {\n\t\t\t...request,\n\t\t\taccount: request.account.publicKeyString.get(),\n\t\t\tsigned: signedData\n\t\t};\n\n\t\tconst endpoints = await getEndpoints(this.resolver, signedRequest);\n\t\tif (endpoints === null) {\n\t\t\tthrow(new Error('No KYC endpoints found for the given criteria'));\n\t\t}\n\n\t\tconst validEndpoints = await Promise.allSettled(Object.entries(endpoints).map(async ([id, serviceInfo]) => {\n\t\t\tconst endpoints = serviceInfo.operations;\n\t\t\t/*\n\t\t\t * Verify that we have the required operations\n\t\t\t * available to perform a KYC verification.\n\t\t\t */\n\t\t\tconst createVerification = await endpoints.createVerification;\n\t\t\tconst getCertificates = await endpoints.getCertificates;\n\t\t\tconst getVerificationStatus = await endpoints.getVerificationStatus;\n\t\t\tif (createVerification === undefined || getCertificates === undefined || getVerificationStatus === undefined) {\n\t\t\t\tthis.logger?.warn(`KYC verification provider ${id} does not support required operations (createVerification, getCertificates, getVerificationStatus)`);\n\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * We can safely cast the ID to a ProviderID because it's a branded type\n\t\t\t * for this specific type\n\t\t\t */\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tconst providerID = id as ProviderID;\n\t\t\treturn(new KeetaKYCProvider({\n\t\t\t\tid: providerID,\n\t\t\t\tserviceInfo: serviceInfo,\n\t\t\t\trequest: signedRequest,\n\t\t\t\taccount: request.account.assertAccount(),\n\t\t\t\tclient: this,\n\t\t\t\tlogger: this.logger,\n\t\t\t\toperations: {\n\t\t\t\t\tcreateVerification,\n\t\t\t\t\tgetCertificates,\n\t\t\t\t\tgetVerificationStatus\n\t\t\t\t}\n\t\t\t}));\n\t\t}));\n\n\t\t/*\n\t\t * Filter out any endpoints that were not able to be resolved\n\t\t * or that did not have the required operations.\n\t\t */\n\t\tconst retval = validEndpoints.map(function(result) {\n\t\t\tif (result.status !== 'fulfilled') {\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t\tif (result.value === null) {\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t\treturn(result.value);\n\t\t}).filter(function(result) {\n\t\t\treturn(result !== null);\n\t\t});\n\n\t\tif (retval.length === 0) {\n\t\t\tthrow(new Error('No valid KYC verification endpoints found'));\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync getCertificates(providerID: ProviderID, request: KeetaKYCAnchorCreateVerificationRequest & { id: RequestID; }): Promise<KeetaKYCAnchorClientGetCertificateResponse> {\n\t\tconst endpoints = await getEndpoints(this.resolver, request);\n\t\tif (endpoints === null) {\n\t\t\tthrow(new Error('No KYC endpoints found for the given criteria'));\n\t\t}\n\t\tconst providerEndpoints = endpoints[providerID];\n\t\tif (providerEndpoints === undefined) {\n\t\t\tthrow(new Error(`No KYC endpoints found for provider ID: ${providerID}`));\n\t\t}\n\n\t\tconst requestID = request.id;\n\t\tconst operations = providerEndpoints.operations;\n\t\tconst getCertificate = (await operations.getCertificates)?.({ id: requestID });\n\t\tif (getCertificate === undefined) {\n\t\t\tthrow(new Error('internal error: KYC verification service does not support getCertificate operation'));\n\t\t}\n\n\t\tconst response = await fetch(getCertificate, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\t/*\n\t\t * Handle retryable errors by passing them up to the caller to\n\t\t * retry.\n\t\t */\n\t\tif (response.status === 404) {\n\t\t\treturn({\n\t\t\t\tok: false,\n\t\t\t\tretryAfter: 500,\n\t\t\t\treason: 'Certificate not found'\n\t\t\t});\n\t\t}\n\n\t\t/*\n\t\t * Handle other errors as fatal errors that should not be retried.\n\t\t */\n\t\tif (!response.ok) {\n\t\t\tthrow(new Error(`Failed to get certificate: ${response.statusText}`));\n\t\t}\n\n\t\tconst responseJSON: unknown = await response.json();\n\t\tif (!isKeetaKYCAnchorGetCertificateResponse(responseJSON)) {\n\t\t\tthrow(new Error(`Invalid response from KYC certificate service: ${JSON.stringify(responseJSON)}`));\n\t\t}\n\n\t\tif (!responseJSON.ok) {\n\t\t\tthrow(new Error(`KYC certificate request failed: ${responseJSON.error}`));\n\t\t}\n\n\t\treturn({\n\t\t\tok: true,\n\t\t\tresults: responseJSON.results.map(function(result) {\n\t\t\t\tconst intermediates = result.intermediates?.map(function(intermediate) {\n\t\t\t\t\treturn(new KeetaNetLib.Utils.Certificate.Certificate(intermediate));\n\t\t\t\t});\n\n\t\t\t\tlet intermediatesSet;\n\t\t\t\tif (intermediates !== undefined && intermediates.length > 0) {\n\t\t\t\t\tintermediatesSet = new Set(intermediates);\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\tcertificate: new KYCCertificate(result.certificate),\n\t\t\t\t\tintermediates: intermediatesSet\n\t\t\t\t});\n\t\t\t})\n\t\t});\n\t}\n\n\tasync getSupportedCountries(): Promise<CurrencyInfo.Country[]> {\n\t\treturn(await this.resolver.listSupportedKYCCountries());\n\t}\n\n\tasync getVerificationStatus(providerID: ProviderID, request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'countryCodes'> & { id: RequestID; account: SignableAccount; }): Promise<KeetaKYCAnchorClientGetVerificationStatusResponse> {\n\t\tconst endpoints = await getEndpoints(this.resolver, { countryCodes: request.countryCodes });\n\t\tif (endpoints === null) {\n\t\t\tthrow(new Error('No KYC endpoints found for the given criteria'));\n\t\t}\n\n\t\tconst providerEndpoints = endpoints[providerID];\n\t\tif (providerEndpoints === undefined) {\n\t\t\tthrow(new Error(`No KYC endpoints found for provider ID: ${providerID}`));\n\t\t}\n\n\t\tconst operations = providerEndpoints.operations;\n\t\tconst getVerificationStatus = (await operations.getVerificationStatus)?.({ id: request.id });\n\t\tif (getVerificationStatus === undefined) {\n\t\t\tthrow(new Error('internal error: KYC verification service does not support getVerificationStatus operation'));\n\t\t}\n\n\t\tconst signed = await SignData(request.account, []);\n\t\tconst signedURL = addSignatureToURL(getVerificationStatus, {\n\t\t\tsignedField: signed,\n\t\t\taccount: request.account\n\t\t});\n\n\t\tconst response = await fetch(signedURL, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow(new Error(`Failed to get verification status: ${response.statusText}`));\n\t\t}\n\n\t\tconst responseJSON: unknown = await response.json();\n\t\tif (!isKeetaKYCAnchorGetVerificationStatusResponse(responseJSON)) {\n\t\t\tthrow(new Error(`Invalid response from KYC status service: ${JSON.stringify(responseJSON)}`));\n\t\t}\n\t\tif (!responseJSON.ok) {\n\t\t\tthrow(new Error(`KYC status request failed: ${responseJSON.error}`));\n\t\t}\n\n\t\tconst result: KeetaKYCAnchorClientGetVerificationStatusResponse = {\n\t\t\tstatus: responseJSON.status\n\t\t};\n\t\tif (responseJSON.requiresManualVerification !== undefined) {\n\t\t\tresult.requiresManualVerification = responseJSON.requiresManualVerification;\n\t\t}\n\n\t\treturn(result);\n\t}\n\n\tasync getEstimate(..._ignore_args: unknown[]): Promise<never> {\n\t\tthrow(new Error('not implemented'));\n\t}\n\n\tasync checkLocality(..._ignore_args: unknown[]): Promise<never> {\n\t\tthrow(new Error('not implemented'));\n\t}\n}\n\nexport default KeetaKYCAnchorClient;\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/services/kyc/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAe1E,OAAO,EACN,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAwB,MAAM,4BAA4B,CAAC;AAI5E,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,QAAQ,GAAG,IAAI,CAAC;AAkGtB,MAAM,0CAA0C;;;;;;;sFAAuD,CAAC;AACxG,MAAM,sCAAsC;;;;;;;sFAAmD,CAAC;AAChG,MAAM,6CAA6C;;;;;;;sFAA0D,CAAC;AAE9G,KAAK,UAAU,YAAY,CAAC,QAAkB,EAAE,OAAqF;IACpI,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE;QAC7C,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,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AAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACpD,IAAI,CAAC,6CAA6C,CAAC,YAAY,CAAC,EAAE,CAAC;YAClE,MAAK,CAAC,IAAI,KAAK,CAAC,6CAA6C,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/F,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC;YACtB,MAAK,CAAC,IAAI,KAAK,CAAC,8BAA8B,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACtE,CAAC;QAED,MAAM,MAAM,GAAsD;YACjE,MAAM,EAAE,YAAY,CAAC,MAAM;SAC3B,CAAC;QACF,IAAI,YAAY,CAAC,0BAA0B,KAAK,SAAS,EAAE,CAAC;YAC3D,MAAM,CAAC,0BAA0B,GAAG,YAAY,CAAC,0BAA0B,CAAC;QAC7E,CAAC;QAED,OAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,GAAG,YAAuB;QAC3C,MAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,GAAG,YAAuB;QAC7C,MAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrC,CAAC;CACD;AAED,eAAe,oBAAoB,CAAC","sourcesContent":["import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\nimport * as CurrencyInfo from '@keetanetwork/currency-info';\nimport { createIs } from 'typia';\n\nimport { getDefaultResolver } from '../../config.js';\nimport { Certificate as KYCCertificate } from '../../lib/certificates.js';\n\nimport type {\n\tClient as KeetaNetClient,\n\tUserClient as KeetaNetUserClient\n} from '@keetanetwork/keetanet-client';\nimport type {\n\tKeetaKYCAnchorCreateVerificationRequest,\n\tKeetaKYCAnchorCreateVerificationResponse,\n\tKeetaKYCAnchorGetCertificateResponse,\n\tKeetaKYCAnchorGetVerificationStatusResponse\n} from './common.ts';\nimport type {\n\tKYCVerificationStatus\n} from './status.js';\nimport {\n\tverifySignedData,\n\tgenerateSignedData\n} from './common.js';\nimport { addSignatureToURL } from '../../lib/http-server/common.js';\nimport { SignData, type SignableAccount } from '../../lib/utils/signing.js';\nimport type { Logger } from '../../lib/log/index.ts';\nimport type Resolver from '../../lib/resolver.ts';\nimport type { KYCEntityType, ServiceMetadata } from '../../lib/resolver.ts';\nimport crypto from '../../lib/utils/crypto.js';\nimport { validateURL } from '../../lib/utils/url.js';\n\nconst PARANOID = true;\n\n/**\n * The configuration options for the KYC Anchor client.\n */\nexport type KeetaKYCAnchorClientConfig = {\n\t/**\n\t * The ID of the client. This is used to identify the client in logs.\n\t * If not provided, a random ID will be generated.\n\t */\n\tid?: string;\n\t/**\n\t * The logger to use for logging messages. If not provided, no logging\n\t * will be done.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The resolver to use for resolving KYC Anchor services. If not\n\t * provided, a default resolver will be created using the provided\n\t * client and network (if the network is also not provided and the\n\t * client is not a UserClient, an error occurs).\n\t */\n\tresolver?: Resolver;\n} & Omit<NonNullable<Parameters<typeof getDefaultResolver>[1]>, 'client'>;\n\n/**\n * Any kind of X.509v3 Certificate. This may or may not be a KYC certificate.\n */\ntype BaseCertificate = InstanceType<typeof KeetaNetLib.Utils.Certificate.Certificate>;\n\n/**\n * The response type for the {@link KeetaKYCAnchorClient['getCertificates']()} method of the KYC Anchor client.\n * It contains the certificate and optionally a set of intermediate certificates.\n */\ntype KeetaKYCAnchorClientGetCertificateResponse = ({\n\tok: true;\n\tresults: {\n\t\tcertificate: KYCCertificate;\n\t\tintermediates?: Set<BaseCertificate> | undefined;\n\t}[]\n} | {\n\tok: false;\n\tretryAfter: number;\n\treason: string;\n});\n\n/**\n * The response type for {@link KeetaKYCAnchorClient['getVerificationStatus']()}.\n */\ntype KeetaKYCAnchorClientGetVerificationStatusResponse = {\n\tstatus: KYCVerificationStatus;\n\trequiresManualVerification?: boolean;\n};\n\ntype KeetaKYCAnchorClientCreateVerificationRequest = Omit<KeetaKYCAnchorCreateVerificationRequest, 'signed' | 'account'> & {\n\taccount: InstanceType<typeof KeetaNetLib.Account>;\n};\n\n/**\n * An opaque type that represents a provider ID.\n */\ntype ProviderID = string & {\n\treadonly __providerID: unique symbol;\n};\n\n/**\n * An opaque type that represents a KYC Anchor request ID\n */\ntype RequestID = string & {\n\treadonly __requestID: unique symbol;\n};\n\n/**\n * A list of operations that can be performed by the KYC Anchor service.\n */\ntype KeetaKYCAnchorOperations = {\n\t[operation in keyof NonNullable<ServiceMetadata['services']['kyc']>[string]['operations']]?: (params?: { [key: string]: string; }) => URL;\n};\n\n/**\n * The service information for a KYC Anchor service.\n */\ntype KeetaKYCVerificationServiceInfo = {\n\toperations: {\n\t\t[operation in keyof KeetaKYCAnchorOperations]: Promise<KeetaKYCAnchorOperations[operation]>;\n\t};\n\tcountryCodes?: CurrencyInfo.Country[] | undefined;\n\tca: () => Promise<KYCCertificate>;\n};\n\n/**\n * For each matching KYC Anchor service, this type describes the\n * operations available and the country codes that the service supports.\n */\ntype GetEndpointsResult = {\n\t[id: ProviderID]: KeetaKYCVerificationServiceInfo;\n};\n\nconst isKeetaKYCAnchorCreateVerificationResponse = createIs<KeetaKYCAnchorCreateVerificationResponse>();\nconst isKeetaKYCAnchorGetCertificateResponse = createIs<KeetaKYCAnchorGetCertificateResponse>();\nconst isKeetaKYCAnchorGetVerificationStatusResponse = createIs<KeetaKYCAnchorGetVerificationStatusResponse>();\n\nasync function getEndpoints(resolver: Resolver, request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'countryCodes' | 'entityType'>): Promise<GetEndpointsResult | null> {\n\tconst response = await resolver.lookup('kyc', {\n\t\tcountryCodes: request.countryCodes,\n\t\t...(request.entityType !== undefined ? { entityType: request.entityType } : {})\n\t});\n\n\tif (response === undefined) {\n\t\treturn(null);\n\t}\n\n\tconst serviceInfoPromises = Object.entries(response).map(async function([id, serviceInfo]): Promise<[ProviderID, KeetaKYCVerificationServiceInfo]> {\n\t\tconst countryCodesPromises = (await serviceInfo.countryCodes?.('array'))?.map(async function(countryCode) {\n\t\t\treturn(new CurrencyInfo.Country(CurrencyInfo.Country.assertCountryCode(await countryCode('string'))));\n\t\t});\n\n\t\tlet countryCodes: CurrencyInfo.Country[] | undefined;\n\t\tif (countryCodesPromises !== undefined) {\n\t\t\tconst countryCodesResults = await Promise.allSettled(countryCodesPromises);\n\t\t\tcountryCodes = countryCodesResults.map(function(result) {\n\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\treturn(result.value);\n\t\t\t\t}\n\t\t\t\tthrow(result.reason);\n\t\t\t});\n\t\t}\n\n\t\tconst operations = await serviceInfo.operations('object');\n\t\tconst operationsFunctions: KeetaKYCVerificationServiceInfo['operations'] = {};\n\t\tfor (const [key, operation] of Object.entries(operations)) {\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tObject.defineProperty(operationsFunctions, key, {\n\t\t\t\tget: async function() {\n\t\t\t\t\tconst url = await operation('string');\n\t\t\t\t\treturn(function(params?: { [key: string]: string; }): URL {\n\t\t\t\t\t\tlet substitutedURL = url;\n\t\t\t\t\t\tfor (const [paramKey, paramValue] of Object.entries(params ?? {})) {\n\t\t\t\t\t\t\tsubstitutedURL = substitutedURL.replace(`{${paramKey}}`, encodeURIComponent(paramValue));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(validateURL(substitutedURL));\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true\n\t\t\t});\n\t\t}\n\t\treturn([\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tid as ProviderID,\n\t\t\t{\n\t\t\t\tcountryCodes: countryCodes,\n\t\t\t\toperations: operationsFunctions,\n\t\t\t\tca: async function() {\n\t\t\t\t\tconst certificatePEM = await serviceInfo.ca?.('string');\n\t\t\t\t\tconst certificate = new KYCCertificate(certificatePEM);\n\n\t\t\t\t\treturn(certificate);\n\t\t\t\t}\n\t\t\t}\n\t\t]);\n\t});\n\n\tconst retval = Object.fromEntries(await Promise.all(serviceInfoPromises));\n\n\treturn(retval);\n}\n\ntype KeetaKYCAnchorCommonConfig = {\n\tid: ProviderID;\n\tserviceInfo: KeetaKYCVerificationServiceInfo;\n\trequest: KeetaKYCAnchorCreateVerificationRequest;\n\taccount: SignableAccount;\n\tclient: KeetaKYCAnchorClient;\n\toperations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates' | 'getVerificationStatus'>>;\n\tlogger?: Logger | undefined;\n};\n\n/**\n * Represents an in-progress KYC verification request.\n */\nclass KeetaKYCVerification {\n\treadonly providerID: KeetaKYCAnchorCommonConfig['id'];\n\treadonly id: RequestID;\n\tprivate readonly serviceInfo: KeetaKYCAnchorCommonConfig['serviceInfo'];\n\tprivate readonly request: KeetaKYCAnchorCommonConfig['request'];\n\tprivate readonly account: KeetaKYCAnchorCommonConfig['account'];\n\tprivate readonly logger?: KeetaKYCAnchorCommonConfig['logger'] | undefined;\n\tprivate readonly client: KeetaKYCAnchorCommonConfig['client'];\n\tprivate readonly response: Extract<KeetaKYCAnchorCreateVerificationResponse, { ok: true }>;\n\n\tprivate constructor(args: KeetaKYCAnchorCommonConfig, response: Extract<KeetaKYCAnchorCreateVerificationResponse, { ok: true }>) {\n\t\tthis.providerID = args.id;\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.id = response.id as RequestID;\n\t\tthis.serviceInfo = args.serviceInfo;\n\t\tthis.request = args.request;\n\t\tthis.account = args.account;\n\t\tthis.client = args.client;\n\t\tthis.logger = args.logger;\n\t\tthis.response = response;\n\n\t\tthis.logger?.debug(`Created KYC verification for provider ID: ${this.providerID}, request: ${JSON.stringify(args.request)}, response: ${JSON.stringify(response)}`);\n\t}\n\n\tstatic async start(args: KeetaKYCAnchorCommonConfig): Promise<KeetaKYCVerification> {\n\t\targs.logger?.debug(`Starting KYC verification for provider ID: ${args.id}, request: ${JSON.stringify(args.request)}`);\n\n\t\tconst endpoints = args.operations;\n\t\tconst createVerification = endpoints.createVerification?.();\n\t\tif (createVerification === undefined) {\n\t\t\tthrow(new Error('KYC verification service does not support createVerification operation'));\n\t\t}\n\n\t\tconst requestInformation = await fetch(createVerification, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: args.request\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaKYCAnchorCreateVerificationResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from KYC verification service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(new Error(`KYC verification request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\targs.logger?.debug(`KYC verification request successful, request ID ${requestInformationJSON.id}`);\n\n\t\treturn(new KeetaKYCVerification(args, requestInformationJSON));\n\n\t}\n\n\tget expectedCost(): typeof this.response.expectedCost {\n\t\treturn(this.response.expectedCost);\n\t}\n\n\tget webURL(): URL {\n\t\treturn(validateURL(this.response.webURL));\n\t}\n\n\tasync getProviderIssuerCertificate(): Promise<KYCCertificate> {\n\t\treturn(await this.serviceInfo.ca());\n\t}\n\n\tgetCertificates(): Promise<KeetaKYCAnchorClientGetCertificateResponse> {\n\t\treturn(this.client.getCertificates(this.providerID, {\n\t\t\tid: this.id,\n\t\t\t...this.request\n\t\t}));\n\t}\n\n\tgetVerificationStatus(): Promise<KeetaKYCAnchorClientGetVerificationStatusResponse> {\n\t\treturn(this.client.getVerificationStatus(this.providerID, {\n\t\t\tid: this.id,\n\t\t\taccount: this.account,\n\t\t\tcountryCodes: this.request.countryCodes,\n\t\t\t...(this.request.entityType !== undefined ? { entityType: this.request.entityType } : {})\n\t\t}));\n\t}\n}\n\n/**\n * Represents the KYC operations for a specific provider\n */\nclass KeetaKYCProvider {\n\treadonly id: ProviderID;\n\tprivate readonly serviceInfo: KeetaKYCVerificationServiceInfo;\n\tprivate readonly request: KeetaKYCAnchorCreateVerificationRequest;\n\tprivate readonly account: SignableAccount;\n\tprivate readonly logger?: Logger | undefined;\n\tprivate readonly client: KeetaKYCAnchorClient;\n\tprivate readonly operations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates' | 'getVerificationStatus'>>;\n\n\tprivate cachedCA?: KYCCertificate;\n\n\tconstructor(args: KeetaKYCAnchorCommonConfig) {\n\t\tthis.id = args.id;\n\t\tthis.serviceInfo = args.serviceInfo;\n\t\tthis.request = args.request;\n\t\tthis.account = args.account;\n\t\tthis.client = args.client;\n\t\tthis.operations = args.operations;\n\t\tthis.logger = args.logger;\n\n\t\tthis.logger?.debug(`Created KYC verification for provider ID: ${args.id}, request: ${JSON.stringify(args.request)}`);\n\t}\n\n\tasync countryCodes(): Promise<CurrencyInfo.Country[] | undefined> {\n\t\treturn(this.serviceInfo.countryCodes);\n\t}\n\n\tasync ca(): Promise<KYCCertificate> {\n\t\tif (this.cachedCA !== undefined) {\n\t\t\treturn(this.cachedCA);\n\t\t}\n\n\t\tthis.cachedCA = await this.serviceInfo.ca();\n\n\t\treturn(this.cachedCA);\n\t}\n\n\tasync startVerification(): Promise<KeetaKYCVerification> {\n\t\treturn(await KeetaKYCVerification.start({\n\t\t\tid: this.id,\n\t\t\tserviceInfo: this.serviceInfo,\n\t\t\trequest: this.request,\n\t\t\taccount: this.account,\n\t\t\tclient: this.client,\n\t\t\toperations: this.operations,\n\t\t\tlogger: this.logger\n\t\t}));\n\t}\n}\n\n\nclass KeetaKYCAnchorClient {\n\treadonly resolver: Resolver;\n\treadonly id: string;\n\tprivate readonly logger?: Logger | undefined;\n\n\tconstructor(client: KeetaNetClient | KeetaNetUserClient, config: KeetaKYCAnchorClientConfig = {}) {\n\t\tthis.resolver = config.resolver ?? getDefaultResolver(client, config);\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\t\tthis.logger = config.logger;\n\t}\n\n\tasync createVerification(request: KeetaKYCAnchorClientCreateVerificationRequest): Promise<KeetaKYCProvider[]> {\n\t\tconst signedData = await generateSignedData(request.account.assertAccount());\n\n\t\tif (PARANOID) {\n\t\t\tconst check = await verifySignedData({ account: request.account.publicKeyString.get(), signed: signedData });\n\t\t\tif (!check) {\n\t\t\t\tthrow(new Error('Failed to verify signed data'));\n\t\t\t}\n\t\t}\n\n\t\tconst signedRequest: KeetaKYCAnchorCreateVerificationRequest = {\n\t\t\t...request,\n\t\t\taccount: request.account.publicKeyString.get(),\n\t\t\tsigned: signedData\n\t\t};\n\n\t\t/* Only provider selection defaults to individual; the by-ID lookups below must not filter. */\n\t\tconst endpoints = await getEndpoints(this.resolver, {\n\t\t\tcountryCodes: signedRequest.countryCodes,\n\t\t\tentityType: signedRequest.entityType ?? 'individual'\n\t\t});\n\t\tif (endpoints === null) {\n\t\t\tthrow(new Error('No KYC endpoints found for the given criteria'));\n\t\t}\n\n\t\tconst validEndpoints = await Promise.allSettled(Object.entries(endpoints).map(async ([id, serviceInfo]) => {\n\t\t\tconst endpoints = serviceInfo.operations;\n\t\t\t/*\n\t\t\t * Verify that we have the required operations\n\t\t\t * available to perform a KYC verification.\n\t\t\t */\n\t\t\tconst createVerification = await endpoints.createVerification;\n\t\t\tconst getCertificates = await endpoints.getCertificates;\n\t\t\tconst getVerificationStatus = await endpoints.getVerificationStatus;\n\t\t\tif (createVerification === undefined || getCertificates === undefined || getVerificationStatus === undefined) {\n\t\t\t\tthis.logger?.warn(`KYC verification provider ${id} does not support required operations (createVerification, getCertificates, getVerificationStatus)`);\n\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * We can safely cast the ID to a ProviderID because it's a branded type\n\t\t\t * for this specific type\n\t\t\t */\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tconst providerID = id as ProviderID;\n\t\t\treturn(new KeetaKYCProvider({\n\t\t\t\tid: providerID,\n\t\t\t\tserviceInfo: serviceInfo,\n\t\t\t\trequest: signedRequest,\n\t\t\t\taccount: request.account.assertAccount(),\n\t\t\t\tclient: this,\n\t\t\t\tlogger: this.logger,\n\t\t\t\toperations: {\n\t\t\t\t\tcreateVerification,\n\t\t\t\t\tgetCertificates,\n\t\t\t\t\tgetVerificationStatus\n\t\t\t\t}\n\t\t\t}));\n\t\t}));\n\n\t\t/*\n\t\t * Filter out any endpoints that were not able to be resolved\n\t\t * or that did not have the required operations.\n\t\t */\n\t\tconst retval = validEndpoints.map(function(result) {\n\t\t\tif (result.status !== 'fulfilled') {\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t\tif (result.value === null) {\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t\treturn(result.value);\n\t\t}).filter(function(result) {\n\t\t\treturn(result !== null);\n\t\t});\n\n\t\tif (retval.length === 0) {\n\t\t\tthrow(new Error('No valid KYC verification endpoints found'));\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync getCertificates(providerID: ProviderID, request: KeetaKYCAnchorCreateVerificationRequest & { id: RequestID; }): Promise<KeetaKYCAnchorClientGetCertificateResponse> {\n\t\tconst endpoints = await getEndpoints(this.resolver, request);\n\t\tif (endpoints === null) {\n\t\t\tthrow(new Error('No KYC endpoints found for the given criteria'));\n\t\t}\n\t\tconst providerEndpoints = endpoints[providerID];\n\t\tif (providerEndpoints === undefined) {\n\t\t\tthrow(new Error(`No KYC endpoints found for provider ID: ${providerID}`));\n\t\t}\n\n\t\tconst requestID = request.id;\n\t\tconst operations = providerEndpoints.operations;\n\t\tconst getCertificate = (await operations.getCertificates)?.({ id: requestID });\n\t\tif (getCertificate === undefined) {\n\t\t\tthrow(new Error('internal error: KYC verification service does not support getCertificate operation'));\n\t\t}\n\n\t\tconst response = await fetch(getCertificate, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\t/*\n\t\t * Handle retryable errors by passing them up to the caller to\n\t\t * retry.\n\t\t */\n\t\tif (response.status === 404) {\n\t\t\treturn({\n\t\t\t\tok: false,\n\t\t\t\tretryAfter: 500,\n\t\t\t\treason: 'Certificate not found'\n\t\t\t});\n\t\t}\n\n\t\t/*\n\t\t * Handle other errors as fatal errors that should not be retried.\n\t\t */\n\t\tif (!response.ok) {\n\t\t\tthrow(new Error(`Failed to get certificate: ${response.statusText}`));\n\t\t}\n\n\t\tconst responseJSON: unknown = await response.json();\n\t\tif (!isKeetaKYCAnchorGetCertificateResponse(responseJSON)) {\n\t\t\tthrow(new Error(`Invalid response from KYC certificate service: ${JSON.stringify(responseJSON)}`));\n\t\t}\n\n\t\tif (!responseJSON.ok) {\n\t\t\tthrow(new Error(`KYC certificate request failed: ${responseJSON.error}`));\n\t\t}\n\n\t\treturn({\n\t\t\tok: true,\n\t\t\tresults: responseJSON.results.map(function(result) {\n\t\t\t\tconst intermediates = result.intermediates?.map(function(intermediate) {\n\t\t\t\t\treturn(new KeetaNetLib.Utils.Certificate.Certificate(intermediate));\n\t\t\t\t});\n\n\t\t\t\tlet intermediatesSet;\n\t\t\t\tif (intermediates !== undefined && intermediates.length > 0) {\n\t\t\t\t\tintermediatesSet = new Set(intermediates);\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\tcertificate: new KYCCertificate(result.certificate),\n\t\t\t\t\tintermediates: intermediatesSet\n\t\t\t\t});\n\t\t\t})\n\t\t});\n\t}\n\n\tasync getSupportedCountries(entityType: KYCEntityType = 'individual'): Promise<CurrencyInfo.Country[]> {\n\t\treturn(await this.resolver.listSupportedKYCCountries(entityType));\n\t}\n\n\tasync getVerificationStatus(providerID: ProviderID, request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'countryCodes' | 'entityType'> & { id: RequestID; account: SignableAccount; }): Promise<KeetaKYCAnchorClientGetVerificationStatusResponse> {\n\t\tconst endpoints = await getEndpoints(this.resolver, request);\n\t\tif (endpoints === null) {\n\t\t\tthrow(new Error('No KYC endpoints found for the given criteria'));\n\t\t}\n\n\t\tconst providerEndpoints = endpoints[providerID];\n\t\tif (providerEndpoints === undefined) {\n\t\t\tthrow(new Error(`No KYC endpoints found for provider ID: ${providerID}`));\n\t\t}\n\n\t\tconst operations = providerEndpoints.operations;\n\t\tconst getVerificationStatus = (await operations.getVerificationStatus)?.({ id: request.id });\n\t\tif (getVerificationStatus === undefined) {\n\t\t\tthrow(new Error('internal error: KYC verification service does not support getVerificationStatus operation'));\n\t\t}\n\n\t\tconst signed = await SignData(request.account, []);\n\t\tconst signedURL = addSignatureToURL(getVerificationStatus, {\n\t\t\tsignedField: signed,\n\t\t\taccount: request.account\n\t\t});\n\n\t\tconst response = await fetch(signedURL, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tthrow(new Error(`Failed to get verification status: ${response.statusText}`));\n\t\t}\n\n\t\tconst responseJSON: unknown = await response.json();\n\t\tif (!isKeetaKYCAnchorGetVerificationStatusResponse(responseJSON)) {\n\t\t\tthrow(new Error(`Invalid response from KYC status service: ${JSON.stringify(responseJSON)}`));\n\t\t}\n\t\tif (!responseJSON.ok) {\n\t\t\tthrow(new Error(`KYC status request failed: ${responseJSON.error}`));\n\t\t}\n\n\t\tconst result: KeetaKYCAnchorClientGetVerificationStatusResponse = {\n\t\t\tstatus: responseJSON.status\n\t\t};\n\t\tif (responseJSON.requiresManualVerification !== undefined) {\n\t\t\tresult.requiresManualVerification = responseJSON.requiresManualVerification;\n\t\t}\n\n\t\treturn(result);\n\t}\n\n\tasync getEstimate(..._ignore_args: unknown[]): Promise<never> {\n\t\tthrow(new Error('not implemented'));\n\t}\n\n\tasync checkLocality(..._ignore_args: unknown[]): Promise<never> {\n\t\tthrow(new Error('not implemented'));\n\t}\n}\n\nexport default KeetaKYCAnchorClient;\n"]}
|
package/services/kyc/common.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ServiceMetadata, ServiceSearchCriteria } from '../../lib/resolver.ts';
|
|
1
|
+
import type { KYCEntityType, ServiceMetadata, ServiceSearchCriteria } from '../../lib/resolver.ts';
|
|
2
2
|
import * as KeetaNet from '@keetanetwork/keetanet-client';
|
|
3
3
|
import * as Signing from '../../lib/utils/signing.js';
|
|
4
4
|
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
@@ -19,6 +19,12 @@ export interface KeetaKYCAnchorCreateVerificationRequest {
|
|
|
19
19
|
* {@link KYCRedirectStatus} query parameter indicating the outcome.
|
|
20
20
|
*/
|
|
21
21
|
redirectURL?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The type of entity being verified. Defaults to `individual` when
|
|
24
|
+
* omitted, preserving the classic KYC behavior. The provider uses
|
|
25
|
+
* this to choose which hosted collection experience to present.
|
|
26
|
+
*/
|
|
27
|
+
entityType?: KYCEntityType;
|
|
22
28
|
}
|
|
23
29
|
type KeetaNetTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;
|
|
24
30
|
export type KeetaKYCAnchorCreateVerificationResponse = ({
|
|
@@ -41,7 +47,8 @@ export type KeetaKYCAnchorCreateVerificationResponse = ({
|
|
|
41
47
|
/**
|
|
42
48
|
* The URL to the verification service where the user can complete the
|
|
43
49
|
* verification process. This URL is expected to be a web URL that the
|
|
44
|
-
* user can visit to complete the verification.
|
|
50
|
+
* user can visit to complete the verification. The provider hosts the
|
|
51
|
+
* collection experience for both individual and business entity types.
|
|
45
52
|
*/
|
|
46
53
|
webURL: string;
|
|
47
54
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/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E,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA4E;IAClH,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1E,OAAM,CAAC,MAAM,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type {\n\tServiceMetadata,\n\tServiceSearchCriteria\n} from '../../lib/resolver.ts';\nimport * as KeetaNet from '@keetanetwork/keetanet-client';\nimport * as Signing from '../../lib/utils/signing.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type { HTTPSignedField } from '../../lib/http-server/common.js';\nimport type { KYCVerificationStatus } from './status.js';\n\ntype KeetaNetToken = InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>;\n\nexport type CountryCodesSearchCriteria = ServiceSearchCriteria<'kyc'>['countryCodes'];\n\nexport type Operations = NonNullable<ServiceMetadata['services']['kyc']>[string]['operations'];\nexport type OperationNames = keyof Operations;\n\nexport type KYCRedirectStatus = 'completed' | 'cancelled' | 'failed';\n\nexport interface KeetaKYCAnchorCreateVerificationRequest {\n\tcountryCodes: CountryCodesSearchCriteria;\n\taccount: ReturnType<InstanceType<typeof KeetaNet.lib.Account>['publicKeyString']['get']>;\n\tsigned: HTTPSignedField;\n\t/**\n\t * An optional URL that the KYC provider will redirect the user to\n\t * after the verification flow ends. The provider appends a\n\t * {@link KYCRedirectStatus} query parameter indicating the outcome.\n\t */\n\tredirectURL?: string;\n}\n\ntype KeetaNetTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;\nexport type KeetaKYCAnchorCreateVerificationResponse = ({\n\tok: true;\n\n\t/**\n\t * The ID of the verification request -- this is a unique identifier\n\t * for the verification request that can be used to fetch the\n\t * certificate later\n\t */\n\tid: string;\n\t/**\n\t * The expected cost of the verification request, in the form of a\n\t * token and a range of minimum and maximum expected costs\n\t */\n\texpectedCost: {\n\t\tmin: string;\n\t\tmax: string;\n\t\ttoken: KeetaNetTokenPublicKeyString;\n\t};\n\t/**\n\t * The URL to the verification service where the user can complete the\n\t * verification process. This URL is expected to be a web URL that the\n\t * user can visit to complete the verification.\n\t */\n\twebURL: string;\n} | {\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaKYCAnchorGetCertificateResponse = ({\n\tok: true;\n\t/**\n\t * The certificates that were issued by the KYC Anchor service.\n\t * Typically this will just be a single certificate, but\n\t * it could also be multiple certificates if the service\n\t * issues multiple certificates for a single verification.\n\t *\n\t * Each certificate is represented as a PEM-encoded string.\n\t * The `intermediates` field is optional and may contain\n\t * additional intermediate certificates that are required to\n\t * validate the certificate chain.\n\t */\n\tresults: ({\n\t\tcertificate: string;\n\t\tintermediates?: string[];\n\t})[];\n} | {\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaKYCAnchorGetVerificationStatusResponse = ({\n\tok: true;\n\t/**\n\t * The verification status reported by the KYC provider.\n\t */\n\tstatus: KYCVerificationStatus;\n\t/**\n\t * Whether the verification requires manual review by the\n\t * KYC provider before a final determination can be made.\n\t */\n\trequiresManualVerification?: boolean;\n} | {\n\tok: false;\n\terror: string;\n});\n\nclass KeetaKYCAnchorVerificationNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorVerificationNotFoundError';\n\tprivate readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID = '79d7036f-58ad-4eec-b64c-26bdf98cd3c1';\n\toverride readonly logLevel = 'DEBUG';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Verification ID not found');\n\t\tthis.statusCode = 400;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorVerificationNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificateNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificateNotFoundError';\n\tprivate readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID = '6f4d9620-df33-468e-ae03-898d4fa67aeb';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Certificate not found (pending)');\n\t\tthis.statusCode = 404;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificateNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificatePaymentRequired extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificatePaymentRequired';\n\tprivate readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID = '92b2481d-b29b-4fa2-a295-3a47d99c0869';\n\treadonly amount: bigint;\n\treadonly token: KeetaNetToken;\n\n\tconstructor(cost: { amount: bigint | string; token: KeetaNetToken | string; }, message?: string) {\n\t\tsuper(message ?? 'Payment required for certificate');\n\t\tthis.statusCode = 402;\n\n\t\tthis.amount = BigInt(cost.amount);\n\t\tthis.token = KeetaNet.lib.Account.toAccount<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>(cost.token);\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificatePaymentRequired {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tcode: 'KEETA_ANCHOR_KYC_PAYMENT_REQUIRED',\n\t\t\t\tdata: {\n\t\t\t\t\tcost: {\n\t\t\t\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\t\t\t\ttoken: this.token.publicKeyString.get()\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number; amount: string; token: string } {\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: this.message,\n\t\t\tname: this.name,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\ttoken: this.token.publicKeyString.get()\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaKYCAnchorCertificatePaymentRequired> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\t// Extract required properties specific to PaymentRequired\n\t\tif (!('amount' in other) || typeof other.amount !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid amount'));\n\t\t}\n\n\t\tif (!('token' in other) || typeof other.token !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid token'));\n\t\t}\n\n\t\tconst error = new this(\n\t\t\t{\n\t\t\t\tamount: other.amount,\n\t\t\t\ttoken: other.token\n\t\t\t},\n\t\t\tmessage\n\t\t);\n\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\nexport const Errors: {\n\tVerificationNotFound: typeof KeetaKYCAnchorVerificationNotFoundError;\n\tCertificateNotFound: typeof KeetaKYCAnchorCertificateNotFoundError;\n\tPaymentRequired: typeof KeetaKYCAnchorCertificatePaymentRequired;\n} = {\n\t/**\n\t * The verification ID was not found\n\t */\n\tVerificationNotFound: KeetaKYCAnchorVerificationNotFoundError,\n\n\t/**\n\t * The certificate for the verification ID was not found\n\t * (typically this means the verification is still pending)\n\t */\n\tCertificateNotFound: KeetaKYCAnchorCertificateNotFoundError,\n\n\t/**\n\t * Payment is required for the certificate\n\t */\n\tPaymentRequired: KeetaKYCAnchorCertificatePaymentRequired\n}\n\nexport async function generateSignedData(account: Signing.SignableAccount): Promise<{ nonce: string; timestamp: string; signature: string; }> {\n\treturn(await Signing.SignData(account, []));\n}\n\nexport async function verifySignedData(request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'account' | 'signed'>): Promise<boolean> {\n\tconst account = KeetaNet.lib.Account.fromPublicKeyString(request.account);\n\treturn(await Signing.VerifySignedData(account, [], request.signed));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/services/kyc/common.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAoG5B,MAAM,uCAAwC,SAAQ,oBAAoB;IACzE,MAAM,CAAmB,IAAI,GAAW,yCAAyC,CAAC;IACjE,mDAAmD,CAAU;IACtE,MAAM,CAAU,mDAAmD,GAAG,sCAAsC,CAAC;IACnG,QAAQ,GAAG,OAAO,CAAC;IAErC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QAEtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qDAAqD,EAAE;YAClF,KAAK,EAAE,uCAAuC,CAAC,mDAAmD;YAClG,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAc;QAC/B,OAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,qDAAqD,EAAE,uCAAuC,CAAC,mDAAmD,CAAC,CAAC,CAAC;IAC1L,CAAC;;AAGF,MAAM,sCAAuC,SAAQ,oBAAoB;IACxE,MAAM,CAAmB,IAAI,GAAW,wCAAwC,CAAC;IAChE,kDAAkD,CAAU;IACrE,MAAM,CAAU,kDAAkD,GAAG,sCAAsC,CAAC;IAEpH,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,iCAAiC,CAAC,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QAEtB,MAAM,CAAC,cAAc,CAAC,IAAI,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IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5D,MAAK,CAAC,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAC,CAAC;QAC5G,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,IAAI,CACrB;YACC,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;SAClB,EACD,OAAO,CACP,CAAC;QAEF,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;;AAGF,MAAM,CAAC,MAAM,MAAM,GAIf;IACH;;OAEG;IACH,oBAAoB,EAAE,uCAAuC;IAE7D;;;OAGG;IACH,mBAAmB,EAAE,sCAAsC;IAE3D;;OAEG;IACH,eAAe,EAAE,wCAAwC;CACzD,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAgC;IACxE,OAAM,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA4E;IAClH,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1E,OAAM,CAAC,MAAM,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type {\n\tKYCEntityType,\n\tServiceMetadata,\n\tServiceSearchCriteria\n} from '../../lib/resolver.ts';\nimport * as KeetaNet from '@keetanetwork/keetanet-client';\nimport * as Signing from '../../lib/utils/signing.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type { HTTPSignedField } from '../../lib/http-server/common.js';\nimport type { KYCVerificationStatus } from './status.js';\n\ntype KeetaNetToken = InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>;\n\nexport type CountryCodesSearchCriteria = ServiceSearchCriteria<'kyc'>['countryCodes'];\n\nexport type Operations = NonNullable<ServiceMetadata['services']['kyc']>[string]['operations'];\nexport type OperationNames = keyof Operations;\n\nexport type KYCRedirectStatus = 'completed' | 'cancelled' | 'failed';\n\nexport interface KeetaKYCAnchorCreateVerificationRequest {\n\tcountryCodes: CountryCodesSearchCriteria;\n\taccount: ReturnType<InstanceType<typeof KeetaNet.lib.Account>['publicKeyString']['get']>;\n\tsigned: HTTPSignedField;\n\t/**\n\t * An optional URL that the KYC provider will redirect the user to\n\t * after the verification flow ends. The provider appends a\n\t * {@link KYCRedirectStatus} query parameter indicating the outcome.\n\t */\n\tredirectURL?: string;\n\t/**\n\t * The type of entity being verified. Defaults to `individual` when\n\t * omitted, preserving the classic KYC behavior. The provider uses\n\t * this to choose which hosted collection experience to present.\n\t */\n\tentityType?: KYCEntityType;\n}\n\ntype KeetaNetTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;\nexport type KeetaKYCAnchorCreateVerificationResponse = ({\n\tok: true;\n\n\t/**\n\t * The ID of the verification request -- this is a unique identifier\n\t * for the verification request that can be used to fetch the\n\t * certificate later\n\t */\n\tid: string;\n\t/**\n\t * The expected cost of the verification request, in the form of a\n\t * token and a range of minimum and maximum expected costs\n\t */\n\texpectedCost: {\n\t\tmin: string;\n\t\tmax: string;\n\t\ttoken: KeetaNetTokenPublicKeyString;\n\t};\n\t/**\n\t * The URL to the verification service where the user can complete the\n\t * verification process. This URL is expected to be a web URL that the\n\t * user can visit to complete the verification. The provider hosts the\n\t * collection experience for both individual and business entity types.\n\t */\n\twebURL: string;\n} | {\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaKYCAnchorGetCertificateResponse = ({\n\tok: true;\n\t/**\n\t * The certificates that were issued by the KYC Anchor service.\n\t * Typically this will just be a single certificate, but\n\t * it could also be multiple certificates if the service\n\t * issues multiple certificates for a single verification.\n\t *\n\t * Each certificate is represented as a PEM-encoded string.\n\t * The `intermediates` field is optional and may contain\n\t * additional intermediate certificates that are required to\n\t * validate the certificate chain.\n\t */\n\tresults: ({\n\t\tcertificate: string;\n\t\tintermediates?: string[];\n\t})[];\n} | {\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaKYCAnchorGetVerificationStatusResponse = ({\n\tok: true;\n\t/**\n\t * The verification status reported by the KYC provider.\n\t */\n\tstatus: KYCVerificationStatus;\n\t/**\n\t * Whether the verification requires manual review by the\n\t * KYC provider before a final determination can be made.\n\t */\n\trequiresManualVerification?: boolean;\n} | {\n\tok: false;\n\terror: string;\n});\n\nclass KeetaKYCAnchorVerificationNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorVerificationNotFoundError';\n\tprivate readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID = '79d7036f-58ad-4eec-b64c-26bdf98cd3c1';\n\toverride readonly logLevel = 'DEBUG';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Verification ID not found');\n\t\tthis.statusCode = 400;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorVerificationNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificateNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificateNotFoundError';\n\tprivate readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID = '6f4d9620-df33-468e-ae03-898d4fa67aeb';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Certificate not found (pending)');\n\t\tthis.statusCode = 404;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificateNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificatePaymentRequired extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificatePaymentRequired';\n\tprivate readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID = '92b2481d-b29b-4fa2-a295-3a47d99c0869';\n\treadonly amount: bigint;\n\treadonly token: KeetaNetToken;\n\n\tconstructor(cost: { amount: bigint | string; token: KeetaNetToken | string; }, message?: string) {\n\t\tsuper(message ?? 'Payment required for certificate');\n\t\tthis.statusCode = 402;\n\n\t\tthis.amount = BigInt(cost.amount);\n\t\tthis.token = KeetaNet.lib.Account.toAccount<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>(cost.token);\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificatePaymentRequired {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tcode: 'KEETA_ANCHOR_KYC_PAYMENT_REQUIRED',\n\t\t\t\tdata: {\n\t\t\t\t\tcost: {\n\t\t\t\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\t\t\t\ttoken: this.token.publicKeyString.get()\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number; amount: string; token: string } {\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: this.message,\n\t\t\tname: this.name,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\ttoken: this.token.publicKeyString.get()\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaKYCAnchorCertificatePaymentRequired> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\t// Extract required properties specific to PaymentRequired\n\t\tif (!('amount' in other) || typeof other.amount !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid amount'));\n\t\t}\n\n\t\tif (!('token' in other) || typeof other.token !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid token'));\n\t\t}\n\n\t\tconst error = new this(\n\t\t\t{\n\t\t\t\tamount: other.amount,\n\t\t\t\ttoken: other.token\n\t\t\t},\n\t\t\tmessage\n\t\t);\n\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\nexport const Errors: {\n\tVerificationNotFound: typeof KeetaKYCAnchorVerificationNotFoundError;\n\tCertificateNotFound: typeof KeetaKYCAnchorCertificateNotFoundError;\n\tPaymentRequired: typeof KeetaKYCAnchorCertificatePaymentRequired;\n} = {\n\t/**\n\t * The verification ID was not found\n\t */\n\tVerificationNotFound: KeetaKYCAnchorVerificationNotFoundError,\n\n\t/**\n\t * The certificate for the verification ID was not found\n\t * (typically this means the verification is still pending)\n\t */\n\tCertificateNotFound: KeetaKYCAnchorCertificateNotFoundError,\n\n\t/**\n\t * Payment is required for the certificate\n\t */\n\tPaymentRequired: KeetaKYCAnchorCertificatePaymentRequired\n}\n\nexport async function generateSignedData(account: Signing.SignableAccount): Promise<{ nonce: string; timestamp: string; signature: string; }> {\n\treturn(await Signing.SignData(account, []));\n}\n\nexport async function verifySignedData(request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'account' | 'signed'>): Promise<boolean> {\n\tconst account = KeetaNet.lib.Account.fromPublicKeyString(request.account);\n\treturn(await Signing.VerifySignedData(account, [], request.signed));\n}\n"]}
|