@keetanetwork/anchor 0.0.71 → 0.0.73
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/lib/resolver.d.ts +4 -0
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +23 -8
- package/lib/resolver.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/services/asset-movement/common.generated.js +10866 -10866
- package/services/asset-movement/common.generated.js.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/ae.d.ts +4 -0
- package/services/asset-movement/lib/data/addresses/bank-account/ae.d.ts.map +1 -0
- package/services/asset-movement/lib/data/addresses/bank-account/{uae.js → ae.js} +3 -3
- package/services/asset-movement/lib/data/addresses/bank-account/ae.js.map +1 -0
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.d.ts +2 -2
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.d.ts.map +1 -1
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.js +2 -2
- package/services/asset-movement/lib/data/addresses/bank-account/index.generated.js.map +1 -1
- package/services/asset-movement/lib/data/addresses/types.generated.d.ts +126 -126
- package/services/asset-movement/lib/data/addresses/types.generated.d.ts.map +1 -1
- package/services/asset-movement/lib/data/addresses/types.generated.js +122 -122
- package/services/asset-movement/lib/data/addresses/types.generated.js.map +1 -1
- package/services/asset-movement/lib/location.generated.js +3 -3
- package/services/kyc/client.d.ts +18 -1
- package/services/kyc/client.d.ts.map +1 -1
- package/services/kyc/client.js +71 -3
- package/services/kyc/client.js.map +1 -1
- package/services/kyc/common.d.ts +28 -0
- package/services/kyc/common.d.ts.map +1 -1
- package/services/kyc/common.js +14 -0
- package/services/kyc/common.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 +49 -7
- package/services/kyc/server.js.map +1 -1
- package/services/storage/clients/contacts.generated.js +746 -746
- package/services/asset-movement/lib/data/addresses/bank-account/uae.d.ts +0 -4
- package/services/asset-movement/lib/data/addresses/bank-account/uae.d.ts.map +0 -1
- package/services/asset-movement/lib/data/addresses/bank-account/uae.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
|
|
2
2
|
import { createAssert, createIs } from "typia";
|
|
3
3
|
export const isTronNetworkAlias = (() => { return input => null !== input && undefined !== input && ("mainnet" === input || "shasta" === input || "nile" === input || "string" === typeof input && RegExp(/^custom:(.*)/).test(input)); })();
|
|
4
|
-
export const assertBankAccountType = (() => { const _iv1 = new Set(["ar", "au", "bcr-pay", "bd", "bf", "bj", "ca", "card", "ci", "ck", "cl", "clabe", "cn", "co", "cr", "cz", "dk", "duit-now", "eg", "fo", "fps", "gg", "gh", "gi", "gl", "gm", "gn", "gt", "hk-fps", "iban-swift", "id", "il", "im", "interac", "je", "jm", "jo", "jp", "ke", "ki", "kr", "lk", "ma", "ng", "np", "nz", "pay-now", "pe", "ph", "pix", "pk", "sn", "sv", "tg", "th", "tn", "tr", "tv", "tz", "
|
|
4
|
+
export const assertBankAccountType = (() => { const _iv1 = new Set(["ae", "ar", "au", "bcr-pay", "bd", "bf", "bj", "ca", "card", "ci", "ck", "cl", "clabe", "cn", "co", "cr", "cz", "dk", "duit-now", "eg", "fo", "fps", "gg", "gh", "gi", "gl", "gm", "gn", "gt", "hk-fps", "iban-swift", "id", "il", "im", "interac", "je", "jm", "jo", "jp", "ke", "ki", "kr", "lk", "ma", "ng", "np", "nz", "pay-now", "pe", "ph", "pix", "pk", "sn", "sv", "tg", "th", "tn", "tr", "tv", "tz", "ug", "upi", "us", "vn", "za", "zm"]); const _av2 = new Set(["ae", "ar", "au", "bcr-pay", "bd", "bf", "bj", "ca", "card", "ci", "ck", "cl", "clabe", "cn", "co", "cr", "cz", "dk", "duit-now", "eg", "fo", "fps", "gg", "gh", "gi", "gl", "gm", "gn", "gt", "hk-fps", "iban-swift", "id", "il", "im", "interac", "je", "jm", "jo", "jp", "ke", "ki", "kr", "lk", "ma", "ng", "np", "nz", "pay-now", "pe", "ph", "pix", "pk", "sn", "sv", "tg", "th", "tn", "tr", "tv", "tz", "ug", "upi", "us", "vn", "za", "zm"]); const __is = input => true === _iv1.has(input); let _errorFactory; return (input, errorFactory) => {
|
|
5
5
|
if (false === __is(input)) {
|
|
6
6
|
_errorFactory = errorFactory;
|
|
7
7
|
((input, _path, _exceptionable = true) => true === _av2.has(input) || __typia_transform__assertGuard._assertGuard(true, {
|
|
8
8
|
method: "createAssert",
|
|
9
9
|
path: _path + "",
|
|
10
|
-
expected: "(\"ar\" | \"au\" | \"bcr-pay\" | \"bd\" | \"bf\" | \"bj\" | \"ca\" | \"card\" | \"ci\" | \"ck\" | \"cl\" | \"clabe\" | \"cn\" | \"co\" | \"cr\" | \"cz\" | \"dk\" | \"duit-now\" | \"eg\" | \"fo\" | \"fps\" | \"gg\" | \"gh\" | \"gi\" | \"gl\" | \"gm\" | \"gn\" | \"gt\" | \"hk-fps\" | \"iban-swift\" | \"id\" | \"il\" | \"im\" | \"interac\" | \"je\" | \"jm\" | \"jo\" | \"jp\" | \"ke\" | \"ki\" | \"kr\" | \"lk\" | \"ma\" | \"ng\" | \"np\" | \"nz\" | \"pay-now\" | \"pe\" | \"ph\" | \"pix\" | \"pk\" | \"sn\" | \"sv\" | \"tg\" | \"th\" | \"tn\" | \"tr\" | \"tv\" | \"tz\" | \"
|
|
10
|
+
expected: "(\"ae\" | \"ar\" | \"au\" | \"bcr-pay\" | \"bd\" | \"bf\" | \"bj\" | \"ca\" | \"card\" | \"ci\" | \"ck\" | \"cl\" | \"clabe\" | \"cn\" | \"co\" | \"cr\" | \"cz\" | \"dk\" | \"duit-now\" | \"eg\" | \"fo\" | \"fps\" | \"gg\" | \"gh\" | \"gi\" | \"gl\" | \"gm\" | \"gn\" | \"gt\" | \"hk-fps\" | \"iban-swift\" | \"id\" | \"il\" | \"im\" | \"interac\" | \"je\" | \"jm\" | \"jo\" | \"jp\" | \"ke\" | \"ki\" | \"kr\" | \"lk\" | \"ma\" | \"ng\" | \"np\" | \"nz\" | \"pay-now\" | \"pe\" | \"ph\" | \"pix\" | \"pk\" | \"sn\" | \"sv\" | \"tg\" | \"th\" | \"tn\" | \"tr\" | \"tv\" | \"tz\" | \"ug\" | \"upi\" | \"us\" | \"vn\" | \"za\" | \"zm\")",
|
|
11
11
|
value: input
|
|
12
12
|
}, _errorFactory))(input, "$input", true);
|
|
13
13
|
}
|
|
@@ -25,7 +25,7 @@ export const assertMobileWalletAccountType = (() => { const _iv1 = new Set(["air
|
|
|
25
25
|
}
|
|
26
26
|
return input;
|
|
27
27
|
}; })();
|
|
28
|
-
export const isAssetLocationLike = (() => { const _iv1 = new Set(["bank-account:ar", "bank-account:au", "bank-account:bcr-pay", "bank-account:bd", "bank-account:bf", "bank-account:bj", "bank-account:ca", "bank-account:card", "bank-account:ci", "bank-account:ck", "bank-account:cl", "bank-account:clabe", "bank-account:cn", "bank-account:co", "bank-account:cr", "bank-account:cz", "bank-account:dk", "bank-account:duit-now", "bank-account:eg", "bank-account:fo", "bank-account:fps", "bank-account:gg", "bank-account:gh", "bank-account:gi", "bank-account:gl", "bank-account:gm", "bank-account:gn", "bank-account:gt", "bank-account:hk-fps", "bank-account:iban-swift", "bank-account:id", "bank-account:il", "bank-account:im", "bank-account:interac", "bank-account:je", "bank-account:jm", "bank-account:jo", "bank-account:jp", "bank-account:ke", "bank-account:ki", "bank-account:kr", "bank-account:lk", "bank-account:ma", "bank-account:ng", "bank-account:np", "bank-account:nz", "bank-account:pay-now", "bank-account:pe", "bank-account:ph", "bank-account:pix", "bank-account:pk", "bank-account:sn", "bank-account:sv", "bank-account:tg", "bank-account:th", "bank-account:tn", "bank-account:tr", "bank-account:tv", "bank-account:tz", "bank-account:
|
|
28
|
+
export const isAssetLocationLike = (() => { const _iv1 = new Set(["bank-account:ae", "bank-account:ar", "bank-account:au", "bank-account:bcr-pay", "bank-account:bd", "bank-account:bf", "bank-account:bj", "bank-account:ca", "bank-account:card", "bank-account:ci", "bank-account:ck", "bank-account:cl", "bank-account:clabe", "bank-account:cn", "bank-account:co", "bank-account:cr", "bank-account:cz", "bank-account:dk", "bank-account:duit-now", "bank-account:eg", "bank-account:fo", "bank-account:fps", "bank-account:gg", "bank-account:gh", "bank-account:gi", "bank-account:gl", "bank-account:gm", "bank-account:gn", "bank-account:gt", "bank-account:hk-fps", "bank-account:iban-swift", "bank-account:id", "bank-account:il", "bank-account:im", "bank-account:interac", "bank-account:je", "bank-account:jm", "bank-account:jo", "bank-account:jp", "bank-account:ke", "bank-account:ki", "bank-account:kr", "bank-account:lk", "bank-account:ma", "bank-account:ng", "bank-account:np", "bank-account:nz", "bank-account:pay-now", "bank-account:pe", "bank-account:ph", "bank-account:pix", "bank-account:pk", "bank-account:sn", "bank-account:sv", "bank-account:tg", "bank-account:th", "bank-account:tn", "bank-account:tr", "bank-account:tv", "bank-account:tz", "bank-account:ug", "bank-account:upi", "bank-account:us", "bank-account:vn", "bank-account:za", "bank-account:zm", "mobile-wallet:airtel-money", "mobile-wallet:bkash", "mobile-wallet:easy-paisa", "mobile-wallet:finja-wallet", "mobile-wallet:jazz-cash", "mobile-wallet:mtn-mobile-money", "mobile-wallet:nagad", "mobile-wallet:naya-pay", "mobile-wallet:paypal", "mobile-wallet:rocket", "mobile-wallet:sada-pay", "mobile-wallet:venmo"]); const _iv2 = new Set(["ae", "ar", "au", "bcr-pay", "bd", "bf", "bj", "ca", "card", "ci", "ck", "cl", "clabe", "cn", "co", "cr", "cz", "dk", "duit-now", "eg", "fo", "fps", "gg", "gh", "gi", "gl", "gm", "gn", "gt", "hk-fps", "iban-swift", "id", "il", "im", "interac", "je", "jm", "jo", "jp", "ke", "ki", "kr", "lk", "ma", "ng", "np", "nz", "pay-now", "pe", "ph", "pix", "pk", "sn", "sv", "tg", "th", "tn", "tr", "tv", "tz", "ug", "upi", "us", "vn", "za", "zm"]); const _iv3 = new Set(["airtel-money", "bkash", "easy-paisa", "finja-wallet", "jazz-cash", "mtn-mobile-money", "nagad", "naya-pay", "paypal", "rocket", "sada-pay", "venmo"]); const _io0 = input => "chain" === input.type && ("object" === typeof input.chain && null !== input.chain && _iu0(input.chain)); const _io1 = input => "keeta" === input.type && "bigint" === typeof input.networkId; const _io2 = input => "evm" === input.type && "bigint" === typeof input.chainId; const _io3 = input => "solana" === input.type && "string" === typeof input.genesisHash; const _io4 = input => "bitcoin" === input.type && "string" === typeof input.magicBytes; const _io5 = input => "tron" === input.type && (null !== input.networkAlias && undefined !== input.networkAlias && ("mainnet" === input.networkAlias || "shasta" === input.networkAlias || "nile" === input.networkAlias || "string" === typeof input.networkAlias && RegExp(/^custom:(.*)/).test(input.networkAlias))); const _io6 = input => "object" === typeof input.account && null !== input.account && _io7(input.account) && "bank-account" === input.type; const _io7 = input => true === _iv2.has(input.type); const _io8 = input => "object" === typeof input.account && null !== input.account && _io9(input.account) && "mobile-wallet" === input.type; const _io9 = input => true === _iv3.has(input.type); const _iu0 = input => (() => {
|
|
29
29
|
if ("keeta" === input.type)
|
|
30
30
|
return _io1(input);
|
|
31
31
|
else if ("evm" === input.type)
|
package/services/kyc/client.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { getDefaultResolver } from '../../config.js';
|
|
|
4
4
|
import { Certificate as KYCCertificate } from '../../lib/certificates.js';
|
|
5
5
|
import type { Client as KeetaNetClient, UserClient as KeetaNetUserClient } from '@keetanetwork/keetanet-client';
|
|
6
6
|
import type { KeetaKYCAnchorCreateVerificationRequest } from './common.ts';
|
|
7
|
+
import type { KYCVerificationStatus } from './common.js';
|
|
8
|
+
import { type SignableAccount } from '../../lib/utils/signing.js';
|
|
7
9
|
import type { Logger } from '../../lib/log/index.ts';
|
|
8
10
|
import type Resolver from '../../lib/resolver.ts';
|
|
9
11
|
import type { ServiceMetadata } from '../../lib/resolver.ts';
|
|
@@ -48,6 +50,13 @@ type KeetaKYCAnchorClientGetCertificateResponse = ({
|
|
|
48
50
|
retryAfter: number;
|
|
49
51
|
reason: string;
|
|
50
52
|
});
|
|
53
|
+
/**
|
|
54
|
+
* The response type for {@link KeetaKYCAnchorClient['getVerificationStatus']()}.
|
|
55
|
+
*/
|
|
56
|
+
type KeetaKYCAnchorClientGetVerificationStatusResponse = {
|
|
57
|
+
status: KYCVerificationStatus;
|
|
58
|
+
requiresManualVerification?: boolean;
|
|
59
|
+
};
|
|
51
60
|
type KeetaKYCAnchorClientCreateVerificationRequest = Omit<KeetaKYCAnchorCreateVerificationRequest, 'signed' | 'account'> & {
|
|
52
61
|
account: InstanceType<typeof KeetaNetLib.Account>;
|
|
53
62
|
};
|
|
@@ -85,8 +94,9 @@ type KeetaKYCAnchorCommonConfig = {
|
|
|
85
94
|
id: ProviderID;
|
|
86
95
|
serviceInfo: KeetaKYCVerificationServiceInfo;
|
|
87
96
|
request: KeetaKYCAnchorCreateVerificationRequest;
|
|
97
|
+
account: SignableAccount;
|
|
88
98
|
client: KeetaKYCAnchorClient;
|
|
89
|
-
operations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates'>>;
|
|
99
|
+
operations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates' | 'getVerificationStatus'>>;
|
|
90
100
|
logger?: Logger | undefined;
|
|
91
101
|
};
|
|
92
102
|
/**
|
|
@@ -97,6 +107,7 @@ declare class KeetaKYCVerification {
|
|
|
97
107
|
readonly id: RequestID;
|
|
98
108
|
private readonly serviceInfo;
|
|
99
109
|
private readonly request;
|
|
110
|
+
private readonly account;
|
|
100
111
|
private readonly logger?;
|
|
101
112
|
private readonly client;
|
|
102
113
|
private readonly response;
|
|
@@ -106,6 +117,7 @@ declare class KeetaKYCVerification {
|
|
|
106
117
|
get webURL(): URL;
|
|
107
118
|
getProviderIssuerCertificate(): Promise<KYCCertificate>;
|
|
108
119
|
getCertificates(): Promise<KeetaKYCAnchorClientGetCertificateResponse>;
|
|
120
|
+
getVerificationStatus(): Promise<KeetaKYCAnchorClientGetVerificationStatusResponse>;
|
|
109
121
|
}
|
|
110
122
|
/**
|
|
111
123
|
* Represents the KYC operations for a specific provider
|
|
@@ -114,6 +126,7 @@ declare class KeetaKYCProvider {
|
|
|
114
126
|
readonly id: ProviderID;
|
|
115
127
|
private readonly serviceInfo;
|
|
116
128
|
private readonly request;
|
|
129
|
+
private readonly account;
|
|
117
130
|
private readonly logger?;
|
|
118
131
|
private readonly client;
|
|
119
132
|
private readonly operations;
|
|
@@ -133,6 +146,10 @@ declare class KeetaKYCAnchorClient {
|
|
|
133
146
|
id: RequestID;
|
|
134
147
|
}): Promise<KeetaKYCAnchorClientGetCertificateResponse>;
|
|
135
148
|
getSupportedCountries(): Promise<CurrencyInfo.Country[]>;
|
|
149
|
+
getVerificationStatus(providerID: ProviderID, request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'countryCodes'> & {
|
|
150
|
+
id: RequestID;
|
|
151
|
+
account: SignableAccount;
|
|
152
|
+
}): Promise<KeetaKYCAnchorClientGetVerificationStatusResponse>;
|
|
136
153
|
getEstimate(..._ignore_args: unknown[]): Promise<never>;
|
|
137
154
|
checkLocality(..._ignore_args: unknown[]): Promise<never>;
|
|
138
155
|
}
|
|
@@ -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,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACX,uCAAuC,
|
|
1
|
+
{"version":3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AAO,CAAC,iDAAiD,CAAC;IAmDhO,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
|
@@ -4,6 +4,8 @@ import { createIs } from 'typia';
|
|
|
4
4
|
import { getDefaultResolver } from '../../config.js';
|
|
5
5
|
import { Certificate as KYCCertificate } from '../../lib/certificates.js';
|
|
6
6
|
import { verifySignedData, generateSignedData } from './common.js';
|
|
7
|
+
import { addSignatureToURL } from '../../lib/http-server/common.js';
|
|
8
|
+
import { SignData } from '../../lib/utils/signing.js';
|
|
7
9
|
import crypto from '../../lib/utils/crypto.js';
|
|
8
10
|
import { validateURL } from '../../lib/utils/url.js';
|
|
9
11
|
const PARANOID = true;
|
|
@@ -23,6 +25,14 @@ const isKeetaKYCAnchorGetCertificateResponse = (() => { const _io0 = input => tr
|
|
|
23
25
|
else
|
|
24
26
|
return false;
|
|
25
27
|
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
28
|
+
const isKeetaKYCAnchorGetVerificationStatusResponse = (() => { const _io0 = input => true === input.ok && ("pass" === input.status || "fail" === input.status || "incomplete" === input.status || "pending" === input.status || "error" === input.status) && (undefined === input.requiresManualVerification || "boolean" === typeof input.requiresManualVerification); const _io1 = input => false === input.ok && "string" === typeof input.error; const _iu0 = input => (() => {
|
|
29
|
+
if (true === input.ok)
|
|
30
|
+
return _io0(input);
|
|
31
|
+
else if (false === input.ok)
|
|
32
|
+
return _io1(input);
|
|
33
|
+
else
|
|
34
|
+
return false;
|
|
35
|
+
})(); return input => "object" === typeof input && null !== input && _iu0(input); })();
|
|
26
36
|
async function getEndpoints(resolver, request) {
|
|
27
37
|
const response = await resolver.lookup('kyc', {
|
|
28
38
|
countryCodes: request.countryCodes
|
|
@@ -90,6 +100,7 @@ class KeetaKYCVerification {
|
|
|
90
100
|
id;
|
|
91
101
|
serviceInfo;
|
|
92
102
|
request;
|
|
103
|
+
account;
|
|
93
104
|
logger;
|
|
94
105
|
client;
|
|
95
106
|
response;
|
|
@@ -99,6 +110,7 @@ class KeetaKYCVerification {
|
|
|
99
110
|
this.id = response.id;
|
|
100
111
|
this.serviceInfo = args.serviceInfo;
|
|
101
112
|
this.request = args.request;
|
|
113
|
+
this.account = args.account;
|
|
102
114
|
this.client = args.client;
|
|
103
115
|
this.logger = args.logger;
|
|
104
116
|
this.response = response;
|
|
@@ -146,6 +158,13 @@ class KeetaKYCVerification {
|
|
|
146
158
|
...this.request
|
|
147
159
|
}));
|
|
148
160
|
}
|
|
161
|
+
getVerificationStatus() {
|
|
162
|
+
return (this.client.getVerificationStatus(this.providerID, {
|
|
163
|
+
id: this.id,
|
|
164
|
+
account: this.account,
|
|
165
|
+
countryCodes: this.request.countryCodes
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
149
168
|
}
|
|
150
169
|
/**
|
|
151
170
|
* Represents the KYC operations for a specific provider
|
|
@@ -154,6 +173,7 @@ class KeetaKYCProvider {
|
|
|
154
173
|
id;
|
|
155
174
|
serviceInfo;
|
|
156
175
|
request;
|
|
176
|
+
account;
|
|
157
177
|
logger;
|
|
158
178
|
client;
|
|
159
179
|
operations;
|
|
@@ -162,6 +182,7 @@ class KeetaKYCProvider {
|
|
|
162
182
|
this.id = args.id;
|
|
163
183
|
this.serviceInfo = args.serviceInfo;
|
|
164
184
|
this.request = args.request;
|
|
185
|
+
this.account = args.account;
|
|
165
186
|
this.client = args.client;
|
|
166
187
|
this.operations = args.operations;
|
|
167
188
|
this.logger = args.logger;
|
|
@@ -182,6 +203,7 @@ class KeetaKYCProvider {
|
|
|
182
203
|
id: this.id,
|
|
183
204
|
serviceInfo: this.serviceInfo,
|
|
184
205
|
request: this.request,
|
|
206
|
+
account: this.account,
|
|
185
207
|
client: this.client,
|
|
186
208
|
operations: this.operations,
|
|
187
209
|
logger: this.logger
|
|
@@ -222,8 +244,9 @@ class KeetaKYCAnchorClient {
|
|
|
222
244
|
*/
|
|
223
245
|
const createVerification = await endpoints.createVerification;
|
|
224
246
|
const getCertificates = await endpoints.getCertificates;
|
|
225
|
-
|
|
226
|
-
|
|
247
|
+
const getVerificationStatus = await endpoints.getVerificationStatus;
|
|
248
|
+
if (createVerification === undefined || getCertificates === undefined || getVerificationStatus === undefined) {
|
|
249
|
+
this.logger?.warn(`KYC verification provider ${id} does not support required operations (createVerification, getCertificates, getVerificationStatus)`);
|
|
227
250
|
return (null);
|
|
228
251
|
}
|
|
229
252
|
/*
|
|
@@ -236,11 +259,13 @@ class KeetaKYCAnchorClient {
|
|
|
236
259
|
id: providerID,
|
|
237
260
|
serviceInfo: serviceInfo,
|
|
238
261
|
request: signedRequest,
|
|
262
|
+
account: request.account.assertAccount(),
|
|
239
263
|
client: this,
|
|
240
264
|
logger: this.logger,
|
|
241
265
|
operations: {
|
|
242
266
|
createVerification,
|
|
243
|
-
getCertificates
|
|
267
|
+
getCertificates,
|
|
268
|
+
getVerificationStatus
|
|
244
269
|
}
|
|
245
270
|
}));
|
|
246
271
|
}));
|
|
@@ -329,6 +354,49 @@ class KeetaKYCAnchorClient {
|
|
|
329
354
|
async getSupportedCountries() {
|
|
330
355
|
return (await this.resolver.listSupportedKYCCountries());
|
|
331
356
|
}
|
|
357
|
+
async getVerificationStatus(providerID, request) {
|
|
358
|
+
const endpoints = await getEndpoints(this.resolver, { countryCodes: request.countryCodes });
|
|
359
|
+
if (endpoints === null) {
|
|
360
|
+
throw (new Error('No KYC endpoints found for the given criteria'));
|
|
361
|
+
}
|
|
362
|
+
const providerEndpoints = endpoints[providerID];
|
|
363
|
+
if (providerEndpoints === undefined) {
|
|
364
|
+
throw (new Error(`No KYC endpoints found for provider ID: ${providerID}`));
|
|
365
|
+
}
|
|
366
|
+
const operations = providerEndpoints.operations;
|
|
367
|
+
const getVerificationStatus = (await operations.getVerificationStatus)?.({ id: request.id });
|
|
368
|
+
if (getVerificationStatus === undefined) {
|
|
369
|
+
throw (new Error('internal error: KYC verification service does not support getVerificationStatus operation'));
|
|
370
|
+
}
|
|
371
|
+
const signed = await SignData(request.account, []);
|
|
372
|
+
const signedURL = addSignatureToURL(getVerificationStatus, {
|
|
373
|
+
signedField: signed,
|
|
374
|
+
account: request.account
|
|
375
|
+
});
|
|
376
|
+
const response = await fetch(signedURL, {
|
|
377
|
+
method: 'GET',
|
|
378
|
+
headers: {
|
|
379
|
+
'Accept': 'application/json'
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
if (!response.ok) {
|
|
383
|
+
throw (new Error(`Failed to get verification status: ${response.statusText}`));
|
|
384
|
+
}
|
|
385
|
+
const responseJSON = await response.json();
|
|
386
|
+
if (!isKeetaKYCAnchorGetVerificationStatusResponse(responseJSON)) {
|
|
387
|
+
throw (new Error(`Invalid response from KYC status service: ${JSON.stringify(responseJSON)}`));
|
|
388
|
+
}
|
|
389
|
+
if (!responseJSON.ok) {
|
|
390
|
+
throw (new Error(`KYC status request failed: ${responseJSON.error}`));
|
|
391
|
+
}
|
|
392
|
+
const result = {
|
|
393
|
+
status: responseJSON.status
|
|
394
|
+
};
|
|
395
|
+
if (responseJSON.requiresManualVerification !== undefined) {
|
|
396
|
+
result.requiresManualVerification = responseJSON.requiresManualVerification;
|
|
397
|
+
}
|
|
398
|
+
return (result);
|
|
399
|
+
}
|
|
332
400
|
async getEstimate(..._ignore_args) {
|
|
333
401
|
throw (new Error('not implemented'));
|
|
334
402
|
}
|
|
@@ -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;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I,KAAK,CAAC,mCAAmC,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;QAED,OAAM,CAAC;YACN,EAAE,EAAE,IAAI;YACR,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,UAAS,MAAM;gBAChD,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,UAAS,YAAY;oBACpE,OAAM,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;gBACrE,CAAC,CAAC,CAAC;gBAEH,IAAI,gBAAgB,CAAC;gBACrB,IAAI,aAAa,KAAK,SAAS,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC7D,gBAAgB,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC;gBAC3C,CAAC;gBAED,OAAM,CAAC;oBACN,WAAW,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC;oBACnD,aAAa,EAAE,gBAAgB;iBAC/B,CAAC,CAAC;YACJ,CAAC,CAAC;SACF,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,qBAAqB;QAC1B,OAAM,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,yBAAyB,EAAE,CAAC,CAAC;IACzD,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} from './common.ts';\nimport {\n\tverifySignedData,\n\tgenerateSignedData\n} from './common.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\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>();\n\nasync function getEndpoints(resolver: Resolver, request: KeetaKYCAnchorCreateVerificationRequest): 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\tclient: KeetaKYCAnchorClient;\n\toperations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates'>>;\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 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.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\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 logger?: Logger | undefined;\n\tprivate readonly client: KeetaKYCAnchorClient;\n\tprivate readonly operations: NonNullable<Pick<KeetaKYCAnchorOperations, 'createVerification' | 'getCertificates'>>;\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.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\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\tif (createVerification === undefined || getCertificates === undefined) {\n\t\t\t\tthis.logger?.warn(`KYC verification provider ${id} does not support required operations (createVerification, getCertificates)`);\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\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}\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 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;;;;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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 './common.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"]}
|
package/services/kyc/common.d.ts
CHANGED
|
@@ -8,6 +8,19 @@ export type CountryCodesSearchCriteria = ServiceSearchCriteria<'kyc'>['countryCo
|
|
|
8
8
|
export type Operations = NonNullable<ServiceMetadata['services']['kyc']>[string]['operations'];
|
|
9
9
|
export type OperationNames = keyof Operations;
|
|
10
10
|
export type KYCRedirectStatus = 'completed' | 'cancelled' | 'failed';
|
|
11
|
+
/**
|
|
12
|
+
* Standard set of KYC verification statuses reported by a KYC Anchor.
|
|
13
|
+
*
|
|
14
|
+
* Providers report one of these values via the `getVerificationStatus` operation
|
|
15
|
+
* and (where applicable) on certificate issuance flows.
|
|
16
|
+
*/
|
|
17
|
+
export declare enum KYCVerificationStatus {
|
|
18
|
+
PASSED = "pass",
|
|
19
|
+
FAILED = "fail",
|
|
20
|
+
INCOMPLETE = "incomplete",
|
|
21
|
+
PENDING = "pending",
|
|
22
|
+
ERROR = "error"
|
|
23
|
+
}
|
|
11
24
|
export interface KeetaKYCAnchorCreateVerificationRequest {
|
|
12
25
|
countryCodes: CountryCodesSearchCriteria;
|
|
13
26
|
account: ReturnType<InstanceType<typeof KeetaNet.lib.Account>['publicKeyString']['get']>;
|
|
@@ -68,6 +81,21 @@ export type KeetaKYCAnchorGetCertificateResponse = ({
|
|
|
68
81
|
ok: false;
|
|
69
82
|
error: string;
|
|
70
83
|
});
|
|
84
|
+
export type KeetaKYCAnchorGetVerificationStatusResponse = ({
|
|
85
|
+
ok: true;
|
|
86
|
+
/**
|
|
87
|
+
* The verification status reported by the KYC provider.
|
|
88
|
+
*/
|
|
89
|
+
status: KYCVerificationStatus;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the verification requires manual review by the
|
|
92
|
+
* KYC provider before a final determination can be made.
|
|
93
|
+
*/
|
|
94
|
+
requiresManualVerification?: boolean;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
error: string;
|
|
98
|
+
});
|
|
71
99
|
declare class KeetaKYCAnchorVerificationNotFoundError extends KeetaAnchorUserError {
|
|
72
100
|
static readonly name: string;
|
|
73
101
|
private readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/services/kyc/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,qBAAqB,EACrB,MAAM,uBAAuB,CAAC;AAC/B,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AAO,GAAG,KAAK,IAAI,wCAAwC;IAIpF,eAAe,CAAC,WAAW,EAAE,YAAY,GAAG,kBAAkB,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAuB3H,MAAM,IAAI;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;WAY9G,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,wCAAwC,CAAC;CAuBxF;AAED,eAAO,MAAM,MAAM,EAAE;IACpB,oBAAoB,EAAE,OAAO,uCAAuC,CAAC;IACrE,mBAAmB,EAAE,OAAO,sCAAsC,CAAC;IACnE,eAAe,EAAE,OAAO,wCAAwC,CAAC;CAiBjE,CAAA;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;CAAE,CAAC,CAE5I;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,uCAAuC,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAGrI"}
|
package/services/kyc/common.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import * as KeetaNet from '@keetanetwork/keetanet-client';
|
|
2
2
|
import * as Signing from '../../lib/utils/signing.js';
|
|
3
3
|
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
4
|
+
/**
|
|
5
|
+
* Standard set of KYC verification statuses reported by a KYC Anchor.
|
|
6
|
+
*
|
|
7
|
+
* Providers report one of these values via the `getVerificationStatus` operation
|
|
8
|
+
* and (where applicable) on certificate issuance flows.
|
|
9
|
+
*/
|
|
10
|
+
export var KYCVerificationStatus;
|
|
11
|
+
(function (KYCVerificationStatus) {
|
|
12
|
+
KYCVerificationStatus["PASSED"] = "pass";
|
|
13
|
+
KYCVerificationStatus["FAILED"] = "fail";
|
|
14
|
+
KYCVerificationStatus["INCOMPLETE"] = "incomplete";
|
|
15
|
+
KYCVerificationStatus["PENDING"] = "pending";
|
|
16
|
+
KYCVerificationStatus["ERROR"] = "error";
|
|
17
|
+
})(KYCVerificationStatus || (KYCVerificationStatus = {}));
|
|
4
18
|
class KeetaKYCAnchorVerificationNotFoundError extends KeetaAnchorUserError {
|
|
5
19
|
static name = 'KeetaKYCAnchorVerificationNotFoundError';
|
|
6
20
|
KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/services/kyc/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AA4E5B,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,CA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AAO,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';\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\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":"AAIA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAY5B;;;;;GAKG;AACH,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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\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';\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\n/**\n * Standard set of KYC verification statuses reported by a KYC Anchor.\n *\n * Providers report one of these values via the `getVerificationStatus` operation\n * and (where applicable) on certificate issuance flows.\n */\nexport enum KYCVerificationStatus {\n\tPASSED = 'pass',\n\tFAILED = 'fail',\n\tINCOMPLETE = 'incomplete',\n\tPENDING = 'pending',\n\tERROR = 'error'\n}\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"]}
|