@keetanetwork/anchor 0.0.103 → 0.0.105

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.
Files changed (38) hide show
  1. package/lib/resolver.d.ts +5 -0
  2. package/lib/resolver.d.ts.map +1 -1
  3. package/lib/resolver.generated.js +19 -4
  4. package/lib/resolver.generated.js.map +1 -1
  5. package/lib/resolver.js.map +1 -1
  6. package/npm-shrinkwrap.json +2 -2
  7. package/package.json +1 -1
  8. package/services/asset-movement/client.d.ts +37 -4
  9. package/services/asset-movement/client.d.ts.map +1 -1
  10. package/services/asset-movement/client.js +65 -17
  11. package/services/asset-movement/client.js.map +1 -1
  12. package/services/asset-movement/common.d.ts +25 -3
  13. package/services/asset-movement/common.d.ts.map +1 -1
  14. package/services/asset-movement/common.generated.d.ts +1 -0
  15. package/services/asset-movement/common.generated.d.ts.map +1 -1
  16. package/services/asset-movement/common.generated.js +79 -115
  17. package/services/asset-movement/common.generated.js.map +1 -1
  18. package/services/asset-movement/common.js +60 -15
  19. package/services/asset-movement/common.js.map +1 -1
  20. package/services/kyc/client.d.ts +8 -0
  21. package/services/kyc/client.d.ts.map +1 -1
  22. package/services/kyc/client.js +55 -0
  23. package/services/kyc/client.js.map +1 -1
  24. package/services/kyc/common.d.ts +10 -0
  25. package/services/kyc/common.d.ts.map +1 -1
  26. package/services/kyc/common.js.map +1 -1
  27. package/services/kyc/iso20022.generated.d.ts +8 -3
  28. package/services/kyc/iso20022.generated.d.ts.map +1 -1
  29. package/services/kyc/iso20022.generated.js +4 -0
  30. package/services/kyc/iso20022.generated.js.map +1 -1
  31. package/services/kyc/oids.generated.d.ts +3 -0
  32. package/services/kyc/oids.generated.d.ts.map +1 -1
  33. package/services/kyc/oids.generated.js +5 -0
  34. package/services/kyc/oids.generated.js.map +1 -1
  35. package/services/kyc/server.d.ts +13 -1
  36. package/services/kyc/server.d.ts.map +1 -1
  37. package/services/kyc/server.js +47 -19
  38. package/services/kyc/server.js.map +1 -1
@@ -7,6 +7,28 @@ import { kycEntityTypes } from '../../lib/resolver.js';
7
7
  import { parseSignatureFromURL } from '../../lib/http-server/common.js';
8
8
  import { KeetaAnchorMetadataServer } from '../../lib/anchor-metadata-server.js';
9
9
  const kycProviderURLUndefined = 'NO_KYC_PROVIDER_URL:87f0175c-4d0a-4029-a4f3-ba93ef725654';
10
+ async function assertSignedRequester(requestUrl) {
11
+ const parsed = parseSignatureFromURL(requestUrl);
12
+ const signedField = parsed.signedField;
13
+ const account = parsed.account;
14
+ if (!signedField || !account) {
15
+ throw (new KeetaAnchorUserError('Missing signature'));
16
+ }
17
+ let valid;
18
+ try {
19
+ valid = await verifySignedData({
20
+ account: account.publicKeyString.get(),
21
+ signed: signedField
22
+ });
23
+ }
24
+ catch {
25
+ valid = false;
26
+ }
27
+ if (!valid) {
28
+ throw (new KeetaAnchorUserError('Invalid signature'));
29
+ }
30
+ return (account);
31
+ }
10
32
  ;
11
33
  export class KeetaNetKYCAnchorHTTPServer extends KeetaAnchorMetadataServer {
12
34
  homepage;
@@ -152,25 +174,7 @@ export class KeetaNetKYCAnchorHTTPServer extends KeetaAnchorMetadataServer {
152
174
  if (verificationID === undefined) {
153
175
  throw (new KeetaAnchorUserError('No verification ID provided'));
154
176
  }
155
- const parsed = parseSignatureFromURL(requestUrl);
156
- const signedField = parsed.signedField;
157
- const account = parsed.account;
158
- if (!signedField || !account) {
159
- throw (new KeetaAnchorUserError('Missing signature'));
160
- }
161
- let valid;
162
- try {
163
- valid = await verifySignedData({
164
- account: account.publicKeyString.get(),
165
- signed: signedField
166
- });
167
- }
168
- catch {
169
- valid = false;
170
- }
171
- if (!valid) {
172
- throw (new KeetaAnchorUserError('Invalid signature'));
173
- }
177
+ const account = await assertSignedRequester(requestUrl);
174
178
  const result = await config.kyc.getVerificationStatus(verificationID, { account });
175
179
  const response = {
176
180
  ok: true,
@@ -183,6 +187,27 @@ export class KeetaNetKYCAnchorHTTPServer extends KeetaAnchorMetadataServer {
183
187
  output: JSON.stringify(response)
184
188
  });
185
189
  };
190
+ /**
191
+ * Get a new link to continue an existing verification (optional)
192
+ */
193
+ const getVerificationURL = config.kyc.getVerificationURL;
194
+ if (getVerificationURL !== undefined) {
195
+ routes['GET /api/getVerificationURL/:verificationID'] = async function (params, _ignore_body, _ignore_headers, requestUrl) {
196
+ const verificationID = params.get('verificationID');
197
+ if (verificationID === undefined) {
198
+ throw (new KeetaAnchorUserError('No verification ID provided'));
199
+ }
200
+ const account = await assertSignedRequester(requestUrl);
201
+ const result = await getVerificationURL(verificationID, { account });
202
+ const response = {
203
+ ok: true,
204
+ webURL: result.webURL
205
+ };
206
+ return ({
207
+ output: JSON.stringify(response)
208
+ });
209
+ };
210
+ }
186
211
  /**
187
212
  * Check if the KYC provider can
188
213
  * service a more specific locality
@@ -219,6 +244,9 @@ export class KeetaNetKYCAnchorHTTPServer extends KeetaAnchorMetadataServer {
219
244
  getCertificates: (new URL('/api/getCertificates', this.url)).toString() + '/{id}',
220
245
  getVerificationStatus: (new URL('/api/getVerificationStatus', this.url)).toString() + '/{id}'
221
246
  };
247
+ if (this.kyc.getVerificationURL !== undefined) {
248
+ operations.getVerificationURL = (new URL('/api/getVerificationURL', this.url)).toString() + '/{id}';
249
+ }
222
250
  return ({
223
251
  ca: this.ca.toPEM(),
224
252
  countryCodes: this.#countryCodes?.map(function (country) {
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/kyc/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAI5D,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EACN,+BAA+B,EAC/B,gCAAgC,EAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,gBAAgB,EAChB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,cAAc,EAAE,MAAM,uB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,CAAC,IAAI,EAAE;YACR,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;gBACjE,OAAM,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;YACH,UAAU;SACV,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import * as KeetaNet from '@keetanetwork/keetanet-client';\nimport * as CurrencyInfo from '@keetanetwork/currency-info';\n\nimport type * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';\nimport type { KeetaAnchorMetadataServerConfig } from '../../lib/anchor-metadata-server.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type {\n\tKeetaKYCAnchorCreateVerificationRequest,\n\tKeetaKYCAnchorCreateVerificationResponse,\n\tKeetaKYCAnchorGetCertificateResponse,\n\tKeetaKYCAnchorGetVerificationStatusResponse\n} from './common.ts';\nimport {\n\tassertCreateVerificationRequest,\n\tassertCreateVerificationResponse\n} from './common.server.generated.js';\nimport {\n\tverifySignedData\n} from './common.js';\nimport type { Account } from '@keetanetwork/keetanet-client/lib/account.js';\nimport type * as Signing from '../../lib/utils/signing.js';\nimport type { KYCEntityType, ServiceMetadata } from '../../lib/resolver.ts';\nimport { kycEntityTypes } from '../../lib/resolver.js';\nimport { parseSignatureFromURL } from '../../lib/http-server/common.js';\nimport { KeetaAnchorMetadataServer } from '../../lib/anchor-metadata-server.js';\n\nconst kycProviderURLUndefined = 'NO_KYC_PROVIDER_URL:87f0175c-4d0a-4029-a4f3-ba93ef725654';\n\n/**\n * The Base certificate type, from the KeetaNet Client\n *\n * The KYC Certificate type is a subclass of this, so it will also work\n */\ntype BaseCertificate = InstanceType<typeof KeetaNet.lib.Utils.Certificate.Certificate>;\n\nexport interface KeetaAnchorKYCServerConfig extends KeetaAnchorMetadataServerConfig {\n\t/**\n\t * The data to use for the index page (optional)\n\t */\n\thomepage?: string | (() => Promise<string> | string);\n\n\t/**\n\t * The network client to use for submitting blocks\n\t */\n\tclient: { client: KeetaNet.Client; network: bigint; networkAlias: typeof KeetaNet.Client.Config.networksArray[number] } | KeetaNet.UserClient;\n\n\t/**\n\t * Configuration for the KYC Anchor\n\t *\n\t * The flow for a KYC Anchor is as follows:\n\t * 1. Client requests a new verification with a country code and\n\t * account from the KYC Anchor Server\n\t * 2. KYC Anchor Server responds with a verification ID and a URL\n\t * to the KYC provider's web URL, including the verification ID\n\t * 3. Client visits the KYC provider's web URL to complete the\n\t * verification\n\t * 4. KYC provider notifies the Anchor server that the\n\t * verification is complete\n\t * 5. Client requests the certificate for the verification ID\n\t * (polling) from the KYC Anchor Server\n\t * 6. KYC Anchor Server responds with the certificate(s) for the\n\t * verification ID (if complete, pending if still in progress,\n\t * an error if failed)\n\t * 7. Client installs the certificate(s) in their wallet using\n\t * the KeetaNet Client library\n\t *\n\t *\n\t * +-------------------+ +---------------------+ +------------------+\n\t * | Client | | KYC Anchor Server | | KYC Provider |\n\t * +-------------------+ +---------------------+ +------------------+\n\t * | | |\n\t * (1) Create Verification | |\n\t * countryCode, account ---------------------->| |\n\t * | | |\n\t * | (2) Create verification |\n\t * |----------------------------------- verificationID, providerURL |\n\t * | | |\n\t * (3) Open providerURL (with verificationID)------------------------------------>|\n\t * | | |\n\t * | | (4) Notify\n\t * | |<-------- verificationID, verificationStatus, certificates?\n\t * | |\n\t * (5) Poll certificate for verificationID --->|\n\t * | |\n\t * |<-------------------------- (6) Pending / Certificate(s) / Error\n\t * | (repeat #5 until complete)\n\t * |\n\t * (7) Install certificate(s) in wallet using KeetaNet Client library\n\t */\n\tkyc: {\n\t\t/**\n\t\t * Notification that a verification has been started (optional)\n\t\t *\n\t\t * This method can be used to notify the KYC provider that\n\t\t * a verification has been started. It can return additional\n\t\t * information about the verification, such as the web URL\n\t\t * where the user can complete the verification.\n\t\t *\n\t\t * If this method is not provided, the server will generate\n\t\t * a random verification ID and use the `kycProviderURL` from\n\t\t * the server configuration, replacing `{id}` with the\n\t\t * verification ID.\n\t\t */\n\t\tverificationStarted?: (request: KeetaKYCAnchorCreateVerificationRequest) => Promise<Partial<KeetaKYCAnchorCreateVerificationResponse> | undefined>;\n\n\t\t/**\n\t\t * Retrieve the certificate for a verification\n\t\t *\n\t\t * This should return the certificate(s) for the\n\t\t * verification ID. If the verification is still\n\t\t * in progress, it should throw an `CertificateNotFound`\n\t\t * error.\n\t\t * If the verification has failed permanently, it should\n\t\t * throw a `KeetaAnchorUserError` with an appropriate\n\t\t * error message or `VerificationNotFound` if the\n\t\t * verification ID is not found.\n\t\t */\n\t\tgetCertificates: (verificationID: string) => Promise<Extract<KeetaKYCAnchorGetCertificateResponse, { ok: true; }>['results']>;\n\n\t\t/**\n\t\t * Retrieve the verification status for a verification.\n\t\t *\n\t\t * If the verification ID is unknown, the implementation should\n\t\t * throw a `VerificationNotFound` error.\n\t\t */\n\t\tgetVerificationStatus: (verificationID: string, requester: { account: Account }) => Promise<Pick<Extract<KeetaKYCAnchorGetVerificationStatusResponse, { ok: true; }>, 'status' | 'requiresManualVerification'>>;\n\n\t\t/**\n\t\t * Country codes that this KYC provider can service (default is all country codes)\n\t\t */\n\t\tcountryCodes?: (CurrencyInfo.Country | CurrencyInfo.ISOCountryCode)[];\n\n\t\t/**\n\t\t * Entity types that this KYC provider can verify.\n\t\t *\n\t\t * Defaults to `['individual']` (the classic KYC flow).\n\t\t * Add `'business'` to advertise Know Your Business (KYB)\n\t\t * support. Both are hosted redirect flows: the provider\n\t\t * returns a `webURL` to the hosted collection experience it\n\t\t * owns (individual KYC or KYB), and the client polls for the\n\t\t * certificate. A provider that does both lists both:\n\t\t * `['individual', 'business']`.\n\t\t */\n\t\tentityTypes?: KYCEntityType[];\n\t}\n\n\t/**\n\t * The certificate to use for signing certificates\n\t */\n\tca: BaseCertificate;\n\n\t/**\n\t * The account to use for signing certificates\n\t */\n\tsigner: Signing.SignableAccount;\n\n\t/**\n\t * URL for the KYC Provider (optional)\n\t *\n\t * This is the URL that clients will be directed to in order to\n\t * complete the KYC verification process. It is optional because\n\t * the `kyc.verificationStarted` method can also return a `webURL`.\n\t * If both are provided, the URL from `kyc.verificationStarted` takes\n\t * precedence.\n\t */\n\tkycProviderURL?: string | ((verificationID: string) => string);\n\n\t/**\n\t * Additional routes to add to the server (optional)\n\t */\n\troutes?: KeetaAnchorHTTPServer.Routes;\n};\n\nexport class KeetaNetKYCAnchorHTTPServer extends KeetaAnchorMetadataServer<NonNullable<ServiceMetadata['services']['kyc']>[string], KeetaAnchorKYCServerConfig> implements Omit<Required<KeetaAnchorKYCServerConfig>, 'serviceMetadataEndpoint'> {\n\treadonly homepage: NonNullable<KeetaAnchorKYCServerConfig['homepage']>;\n\treadonly client: KeetaAnchorKYCServerConfig['client'];\n\treadonly signer: NonNullable<KeetaAnchorKYCServerConfig['signer']>;\n\treadonly ca: KeetaAnchorKYCServerConfig['ca'];\n\treadonly kyc: KeetaAnchorKYCServerConfig['kyc'];\n\treadonly kycProviderURL: NonNullable<KeetaAnchorKYCServerConfig['kycProviderURL']>;\n\treadonly routes: NonNullable<KeetaAnchorKYCServerConfig['routes']>;\n\treadonly #countryCodes?: CurrencyInfo.Country[] | undefined;\n\treadonly #entityTypes: KYCEntityType[];\n\n\tconstructor(config: KeetaAnchorKYCServerConfig) {\n\t\tsuper(config);\n\n\t\tthis.homepage = config.homepage ?? '';\n\t\tthis.client = config.client;\n\t\tthis.signer = config.signer;\n\t\tthis.ca = config.ca;\n\t\tthis.kyc = config.kyc;\n\t\tthis.routes = config.routes ?? {};\n\t\tthis.kycProviderURL = config.kycProviderURL ?? kycProviderURLUndefined;\n\t\tif (config.kyc.entityTypes !== undefined && config.kyc.entityTypes.length === 0) {\n\t\t\tthrow(new Error('Expected \"kyc.entityTypes\" to declare at least one entity type'));\n\t\t}\n\n\t\tthis.#entityTypes = [...config.kyc.entityTypes ?? ['individual']];\n\n\t\tif (config.kyc.countryCodes) {\n\t\t\tthis.#countryCodes = config.kyc.countryCodes.map(function(inputCode) {\n\t\t\t\tif (CurrencyInfo.Country.isCountryCode(inputCode)) {\n\t\t\t\t\treturn(new CurrencyInfo.Country(inputCode));\n\t\t\t\t}\n\n\t\t\t\treturn(inputCode);\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected async initRoutes(config: KeetaAnchorKYCServerConfig): Promise<KeetaAnchorHTTPServer.Routes> {\n\t\tconst routes: KeetaAnchorHTTPServer.Routes = await super.initRoutes(config);\n\n\t\t/**\n\t\t * If a homepage is provided, setup the route for it\n\t\t */\n\t\tif ('homepage' in config) {\n\t\t\troutes['GET /'] = async function() {\n\t\t\t\tlet homepageData: string;\n\t\t\t\tif (typeof config.homepage === 'string') {\n\t\t\t\t\thomepageData = config.homepage;\n\t\t\t\t} else {\n\t\t\t\t\tif (!config.homepage) {\n\t\t\t\t\t\tthrow(new Error('internal error: No homepage function provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\thomepageData = await config.homepage();\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: homepageData,\n\t\t\t\t\tcontentType: 'text/html'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\t/**\n\t\t * Begin the KYC verification process\n\t\t * with this KYC provider\n\t\t */\n\t\troutes['POST /api/createVerification'] = async function(_ignore_params, bodyInput) {\n\t\t\tif (bodyInput === null || typeof bodyInput !== 'object' || !('request' in bodyInput)) {\n\t\t\t\tthrow(new KeetaAnchorUserError('Invalid request'));\n\t\t\t}\n\n\t\t\tconst body = assertCreateVerificationRequest(bodyInput.request);\n\t\t\tconst valid = await verifySignedData(body);\n\t\t\tif (!valid) {\n\t\t\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t\t\t}\n\n\t\t\t/* XXX:TODO: Validate that the nonce is unique (within a reasonable time frame) */\n\n\t\t\tlet response: Partial<KeetaKYCAnchorCreateVerificationResponse> | undefined = {};\n\t\t\tif (config.kyc.verificationStarted) {\n\t\t\t\tresponse = await config.kyc.verificationStarted(body);\n\t\t\t}\n\n\t\t\tresponse ??= {};\n\n\t\t\tif (response?.ok === false) {\n\t\t\t\tthrow(new KeetaAnchorUserError(response.error ?? 'Unknown error'));\n\t\t\t}\n\n\t\t\tresponse.ok = true;\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow(new Error('internal error: invalid response'));\n\t\t\t}\n\t\t\tresponse.id ??= crypto.randomUUID();\n\n\t\t\tlet defaultWebURL: string;\n\t\t\tif (typeof config.kycProviderURL === 'string') {\n\t\t\t\tdefaultWebURL = config.kycProviderURL.replace('{id}', encodeURIComponent(response.id));\n\t\t\t} else if (config.kycProviderURL !== undefined) {\n\t\t\t\tdefaultWebURL = config.kycProviderURL(response.id);\n\t\t\t} else {\n\t\t\t\tdefaultWebURL = kycProviderURLUndefined;\n\t\t\t}\n\t\t\tresponse.webURL ??= defaultWebURL;\n\n\t\t\tif (!response.webURL || response.webURL === kycProviderURLUndefined) {\n\t\t\t\tthrow(new KeetaAnchorUserError('No webURL provided -- cannot proceed with verification'));\n\t\t\t}\n\n\t\t\tresponse.expectedCost = {\n\t\t\t\tmin: '0',\n\t\t\t\tmax: '0',\n\t\t\t\ttoken: KeetaNet.lib.Account.generateBaseAddresses(config.client.network).baseToken.publicKeyString.get(),\n\t\t\t\t...response.expectedCost\n\t\t\t};\n\n\t\t\tconst responseValidated = assertCreateVerificationResponse(response);\n\n\t\t\treturn({\n\t\t\t\toutput: JSON.stringify(responseValidated)\n\t\t\t});\n\t\t};\n\n\t\t/**\n\t\t * Request an estimate for a KYC\n\t\t * verification (optional)\n\t\t *\n\t\t * XXX:TODO\n\t\t */\n\t\t// if (false) {\n\t\t// \troutes['POST /api/createEstimate'] = async function(_ignore_params, _ignore_body) {\n\t\t// \t\tthrow(new Error('not implemented'));\n\t\t// \t};\n\t\t// }\n\n\t\t/**\n\t\t * Get the certificate for the\n\t\t * KYC verification\n\t\t */\n\t\troutes['GET /api/getCertificates/:verificationID'] = async function(params) {\n\t\t\tconst verificationID = params.get('verificationID');\n\t\t\tif (verificationID === undefined) {\n\t\t\t\tthrow(new KeetaAnchorUserError('No verification ID provided'));\n\t\t\t}\n\n\t\t\tconst certificates = await config.kyc.getCertificates(verificationID);\n\n\t\t\tconst response: KeetaKYCAnchorGetCertificateResponse = {\n\t\t\t\tok: true,\n\t\t\t\tresults: certificates\n\t\t\t};\n\n\t\t\treturn({\n\t\t\t\toutput: JSON.stringify(response)\n\t\t\t});\n\t\t};\n\n\t\t/**\n\t\t * Get the verification status.\n\t\t */\n\t\troutes['GET /api/getVerificationStatus/:verificationID'] = async function(params, _ignore_body, _ignore_headers, requestUrl) {\n\t\t\tconst verificationID = params.get('verificationID');\n\t\t\tif (verificationID === undefined) {\n\t\t\t\tthrow(new KeetaAnchorUserError('No verification ID provided'));\n\t\t\t}\n\n\t\t\tconst parsed = parseSignatureFromURL(requestUrl);\n\t\t\tconst signedField = parsed.signedField;\n\t\t\tconst account = parsed.account;\n\t\t\tif (!signedField || !account) {\n\t\t\t\tthrow(new KeetaAnchorUserError('Missing signature'));\n\t\t\t}\n\n\t\t\tlet valid: boolean;\n\t\t\ttry {\n\t\t\t\tvalid = await verifySignedData({\n\t\t\t\t\taccount: account.publicKeyString.get(),\n\t\t\t\t\tsigned: signedField\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\tvalid = false;\n\t\t\t}\n\n\t\t\tif (!valid) {\n\t\t\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t\t\t}\n\n\t\t\tconst result = await config.kyc.getVerificationStatus(verificationID, { account });\n\t\t\tconst response: KeetaKYCAnchorGetVerificationStatusResponse = {\n\t\t\t\tok: true,\n\t\t\t\tstatus: result.status\n\t\t\t};\n\t\t\tif (result.requiresManualVerification !== undefined) {\n\t\t\t\tresponse.requiresManualVerification = result.requiresManualVerification;\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\toutput: JSON.stringify(response)\n\t\t\t});\n\t\t};\n\n\t\t/**\n\t\t * Check if the KYC provider can\n\t\t * service a more specific locality\n\t\t * (optional)\n\t\t *\n\t\t * XXX:TODO\n\t\t */\n\t\t// if (false) {\n\t\t// \troutes['GET /api/checkLocality'] = async function(_ignore_params, _ignore_body) {\n\t\t// \t\tthrow(new Error('not implemented'));\n\t\t// \t};\n\t\t// }\n\n\t\t/**\n\t\t * Notification that payment has been received for the KYC verification\n\t\t *\n\t\t * XXX:TODO\n\t\t */\n\t\t// if (false) {\n\t\t// \troutes['POST /api/notifyPayment/:verificationID'] = async function(_ignore_params, _ignore_body) {\n\t\t// \t\tthrow(new Error('not implemented'));\n\t\t// \t};\n\t\t// }\n\n\t\treturn({\n\t\t\t...config.routes,\n\t\t\t...routes\n\t\t});\n\t}\n\n\tprotected async buildServiceMetadata(): Promise<NonNullable<ServiceMetadata['services']['kyc']>[string]> {\n\t\tconst operations: NonNullable<ServiceMetadata['services']['kyc']>[string]['operations'] = {\n\t\t\t// checkLocality: (new URL('/api/checkLocality', this.url)).toString(),\n\t\t\t// getEstimate: (new URL('/api/createEstimate', this.url)).toString(),\n\t\t\t// notifyPayment: (new URL('/api/notifyPayment/{id}', this.url)).toString(),\n\t\t\tcreateVerification: (new URL('/api/createVerification', this.url)).toString(),\n\t\t\tgetCertificates: (new URL('/api/getCertificates', this.url)).toString() + '/{id}',\n\t\t\tgetVerificationStatus: (new URL('/api/getVerificationStatus', this.url)).toString() + '/{id}'\n\t\t};\n\n\t\treturn({\n\t\t\tca: this.ca.toPEM(),\n\t\t\tcountryCodes: this.#countryCodes?.map(function(country) {\n\t\t\t\treturn(country.code);\n\t\t\t}) ?? [],\n\t\t\tentityTypes: Object.fromEntries(kycEntityTypes.map((entityType) => {\n\t\t\t\treturn([entityType, this.#entityTypes.includes(entityType)]);\n\t\t\t})),\n\t\t\toperations\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/kyc/server.ts"],"names":[],"mappings":"AAAA,OAAO,KA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QAED,OAAM,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;YACnB,YAAY,EAAE,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,UAAS,OAAO;gBACrD,OAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC,CAAC,IAAI,EAAE;YACR,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;gBACjE,OAAM,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;YACH,UAAU;SACV,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import * as KeetaNet from '@keetanetwork/keetanet-client';\nimport * as CurrencyInfo from '@keetanetwork/currency-info';\n\nimport type * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';\nimport type { KeetaAnchorMetadataServerConfig } from '../../lib/anchor-metadata-server.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type {\n\tKeetaKYCAnchorCreateVerificationRequest,\n\tKeetaKYCAnchorCreateVerificationResponse,\n\tKeetaKYCAnchorGetCertificateResponse,\n\tKeetaKYCAnchorGetVerificationStatusResponse,\n\tKeetaKYCAnchorGetVerificationURLResponse\n} from './common.ts';\nimport {\n\tassertCreateVerificationRequest,\n\tassertCreateVerificationResponse\n} from './common.server.generated.js';\nimport {\n\tverifySignedData\n} from './common.js';\nimport type { Account } from '@keetanetwork/keetanet-client/lib/account.js';\nimport type * as Signing from '../../lib/utils/signing.js';\nimport type { KYCEntityType, ServiceMetadata } from '../../lib/resolver.ts';\nimport { kycEntityTypes } from '../../lib/resolver.js';\nimport { parseSignatureFromURL } from '../../lib/http-server/common.js';\nimport { KeetaAnchorMetadataServer } from '../../lib/anchor-metadata-server.js';\n\nconst kycProviderURLUndefined = 'NO_KYC_PROVIDER_URL:87f0175c-4d0a-4029-a4f3-ba93ef725654';\n\nasync function assertSignedRequester(requestUrl: URL): Promise<Account> {\n\tconst parsed = parseSignatureFromURL(requestUrl);\n\tconst signedField = parsed.signedField;\n\tconst account = parsed.account;\n\tif (!signedField || !account) {\n\t\tthrow(new KeetaAnchorUserError('Missing signature'));\n\t}\n\n\tlet valid: boolean;\n\ttry {\n\t\tvalid = await verifySignedData({\n\t\t\taccount: account.publicKeyString.get(),\n\t\t\tsigned: signedField\n\t\t});\n\t} catch {\n\t\tvalid = false;\n\t}\n\n\tif (!valid) {\n\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t}\n\n\treturn(account);\n}\n\n/**\n * The Base certificate type, from the KeetaNet Client\n *\n * The KYC Certificate type is a subclass of this, so it will also work\n */\ntype BaseCertificate = InstanceType<typeof KeetaNet.lib.Utils.Certificate.Certificate>;\n\nexport interface KeetaAnchorKYCServerConfig extends KeetaAnchorMetadataServerConfig {\n\t/**\n\t * The data to use for the index page (optional)\n\t */\n\thomepage?: string | (() => Promise<string> | string);\n\n\t/**\n\t * The network client to use for submitting blocks\n\t */\n\tclient: { client: KeetaNet.Client; network: bigint; networkAlias: typeof KeetaNet.Client.Config.networksArray[number] } | KeetaNet.UserClient;\n\n\t/**\n\t * Configuration for the KYC Anchor\n\t *\n\t * The flow for a KYC Anchor is as follows:\n\t * 1. Client requests a new verification with a country code and\n\t * account from the KYC Anchor Server\n\t * 2. KYC Anchor Server responds with a verification ID and a URL\n\t * to the KYC provider's web URL, including the verification ID\n\t * 3. Client visits the KYC provider's web URL to complete the\n\t * verification\n\t * 4. KYC provider notifies the Anchor server that the\n\t * verification is complete\n\t * 5. Client requests the certificate for the verification ID\n\t * (polling) from the KYC Anchor Server\n\t * 6. KYC Anchor Server responds with the certificate(s) for the\n\t * verification ID (if complete, pending if still in progress,\n\t * an error if failed)\n\t * 7. Client installs the certificate(s) in their wallet using\n\t * the KeetaNet Client library\n\t *\n\t *\n\t * +-------------------+ +---------------------+ +------------------+\n\t * | Client | | KYC Anchor Server | | KYC Provider |\n\t * +-------------------+ +---------------------+ +------------------+\n\t * | | |\n\t * (1) Create Verification | |\n\t * countryCode, account ---------------------->| |\n\t * | | |\n\t * | (2) Create verification |\n\t * |----------------------------------- verificationID, providerURL |\n\t * | | |\n\t * (3) Open providerURL (with verificationID)------------------------------------>|\n\t * | | |\n\t * | | (4) Notify\n\t * | |<-------- verificationID, verificationStatus, certificates?\n\t * | |\n\t * (5) Poll certificate for verificationID --->|\n\t * | |\n\t * |<-------------------------- (6) Pending / Certificate(s) / Error\n\t * | (repeat #5 until complete)\n\t * |\n\t * (7) Install certificate(s) in wallet using KeetaNet Client library\n\t */\n\tkyc: {\n\t\t/**\n\t\t * Notification that a verification has been started (optional)\n\t\t *\n\t\t * This method can be used to notify the KYC provider that\n\t\t * a verification has been started. It can return additional\n\t\t * information about the verification, such as the web URL\n\t\t * where the user can complete the verification.\n\t\t *\n\t\t * If this method is not provided, the server will generate\n\t\t * a random verification ID and use the `kycProviderURL` from\n\t\t * the server configuration, replacing `{id}` with the\n\t\t * verification ID.\n\t\t */\n\t\tverificationStarted?: (request: KeetaKYCAnchorCreateVerificationRequest) => Promise<Partial<KeetaKYCAnchorCreateVerificationResponse> | undefined>;\n\n\t\t/**\n\t\t * Retrieve the certificate for a verification\n\t\t *\n\t\t * This should return the certificate(s) for the\n\t\t * verification ID. If the verification is still\n\t\t * in progress, it should throw an `CertificateNotFound`\n\t\t * error.\n\t\t * If the verification has failed permanently, it should\n\t\t * throw a `KeetaAnchorUserError` with an appropriate\n\t\t * error message or `VerificationNotFound` if the\n\t\t * verification ID is not found.\n\t\t */\n\t\tgetCertificates: (verificationID: string) => Promise<Extract<KeetaKYCAnchorGetCertificateResponse, { ok: true; }>['results']>;\n\n\t\t/**\n\t\t * Retrieve the verification status for a verification.\n\t\t *\n\t\t * If the verification ID is unknown, the implementation should\n\t\t * throw a `VerificationNotFound` error.\n\t\t */\n\t\tgetVerificationStatus: (verificationID: string, requester: { account: Account }) => Promise<Pick<Extract<KeetaKYCAnchorGetVerificationStatusResponse, { ok: true; }>, 'status' | 'requiresManualVerification'>>;\n\n\t\t/**\n\t\t * Issue a new link to continue an existing verification (optional)\n\t\t *\n\t\t * Links handed out earlier should keep working. If the\n\t\t * verification ID is unknown or belongs to another account,\n\t\t * the implementation should throw a `VerificationNotFound` error.\n\t\t */\n\t\tgetVerificationURL?: (verificationID: string, requester: { account: Account }) => Promise<Pick<Extract<KeetaKYCAnchorGetVerificationURLResponse, { ok: true; }>, 'webURL'>>;\n\n\t\t/**\n\t\t * Country codes that this KYC provider can service (default is all country codes)\n\t\t */\n\t\tcountryCodes?: (CurrencyInfo.Country | CurrencyInfo.ISOCountryCode)[];\n\n\t\t/**\n\t\t * Entity types that this KYC provider can verify.\n\t\t *\n\t\t * Defaults to `['individual']` (the classic KYC flow).\n\t\t * Add `'business'` to advertise Know Your Business (KYB)\n\t\t * support. Both are hosted redirect flows: the provider\n\t\t * returns a `webURL` to the hosted collection experience it\n\t\t * owns (individual KYC or KYB), and the client polls for the\n\t\t * certificate. A provider that does both lists both:\n\t\t * `['individual', 'business']`.\n\t\t */\n\t\tentityTypes?: KYCEntityType[];\n\t}\n\n\t/**\n\t * The certificate to use for signing certificates\n\t */\n\tca: BaseCertificate;\n\n\t/**\n\t * The account to use for signing certificates\n\t */\n\tsigner: Signing.SignableAccount;\n\n\t/**\n\t * URL for the KYC Provider (optional)\n\t *\n\t * This is the URL that clients will be directed to in order to\n\t * complete the KYC verification process. It is optional because\n\t * the `kyc.verificationStarted` method can also return a `webURL`.\n\t * If both are provided, the URL from `kyc.verificationStarted` takes\n\t * precedence.\n\t */\n\tkycProviderURL?: string | ((verificationID: string) => string);\n\n\t/**\n\t * Additional routes to add to the server (optional)\n\t */\n\troutes?: KeetaAnchorHTTPServer.Routes;\n};\n\nexport class KeetaNetKYCAnchorHTTPServer extends KeetaAnchorMetadataServer<NonNullable<ServiceMetadata['services']['kyc']>[string], KeetaAnchorKYCServerConfig> implements Omit<Required<KeetaAnchorKYCServerConfig>, 'serviceMetadataEndpoint'> {\n\treadonly homepage: NonNullable<KeetaAnchorKYCServerConfig['homepage']>;\n\treadonly client: KeetaAnchorKYCServerConfig['client'];\n\treadonly signer: NonNullable<KeetaAnchorKYCServerConfig['signer']>;\n\treadonly ca: KeetaAnchorKYCServerConfig['ca'];\n\treadonly kyc: KeetaAnchorKYCServerConfig['kyc'];\n\treadonly kycProviderURL: NonNullable<KeetaAnchorKYCServerConfig['kycProviderURL']>;\n\treadonly routes: NonNullable<KeetaAnchorKYCServerConfig['routes']>;\n\treadonly #countryCodes?: CurrencyInfo.Country[] | undefined;\n\treadonly #entityTypes: KYCEntityType[];\n\n\tconstructor(config: KeetaAnchorKYCServerConfig) {\n\t\tsuper(config);\n\n\t\tthis.homepage = config.homepage ?? '';\n\t\tthis.client = config.client;\n\t\tthis.signer = config.signer;\n\t\tthis.ca = config.ca;\n\t\tthis.kyc = config.kyc;\n\t\tthis.routes = config.routes ?? {};\n\t\tthis.kycProviderURL = config.kycProviderURL ?? kycProviderURLUndefined;\n\t\tif (config.kyc.entityTypes !== undefined && config.kyc.entityTypes.length === 0) {\n\t\t\tthrow(new Error('Expected \"kyc.entityTypes\" to declare at least one entity type'));\n\t\t}\n\n\t\tthis.#entityTypes = [...config.kyc.entityTypes ?? ['individual']];\n\n\t\tif (config.kyc.countryCodes) {\n\t\t\tthis.#countryCodes = config.kyc.countryCodes.map(function(inputCode) {\n\t\t\t\tif (CurrencyInfo.Country.isCountryCode(inputCode)) {\n\t\t\t\t\treturn(new CurrencyInfo.Country(inputCode));\n\t\t\t\t}\n\n\t\t\t\treturn(inputCode);\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected async initRoutes(config: KeetaAnchorKYCServerConfig): Promise<KeetaAnchorHTTPServer.Routes> {\n\t\tconst routes: KeetaAnchorHTTPServer.Routes = await super.initRoutes(config);\n\n\t\t/**\n\t\t * If a homepage is provided, setup the route for it\n\t\t */\n\t\tif ('homepage' in config) {\n\t\t\troutes['GET /'] = async function() {\n\t\t\t\tlet homepageData: string;\n\t\t\t\tif (typeof config.homepage === 'string') {\n\t\t\t\t\thomepageData = config.homepage;\n\t\t\t\t} else {\n\t\t\t\t\tif (!config.homepage) {\n\t\t\t\t\t\tthrow(new Error('internal error: No homepage function provided'));\n\t\t\t\t\t}\n\n\t\t\t\t\thomepageData = await config.homepage();\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: homepageData,\n\t\t\t\t\tcontentType: 'text/html'\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\t/**\n\t\t * Begin the KYC verification process\n\t\t * with this KYC provider\n\t\t */\n\t\troutes['POST /api/createVerification'] = async function(_ignore_params, bodyInput) {\n\t\t\tif (bodyInput === null || typeof bodyInput !== 'object' || !('request' in bodyInput)) {\n\t\t\t\tthrow(new KeetaAnchorUserError('Invalid request'));\n\t\t\t}\n\n\t\t\tconst body = assertCreateVerificationRequest(bodyInput.request);\n\t\t\tconst valid = await verifySignedData(body);\n\t\t\tif (!valid) {\n\t\t\t\tthrow(new KeetaAnchorUserError('Invalid signature'));\n\t\t\t}\n\n\t\t\t/* XXX:TODO: Validate that the nonce is unique (within a reasonable time frame) */\n\n\t\t\tlet response: Partial<KeetaKYCAnchorCreateVerificationResponse> | undefined = {};\n\t\t\tif (config.kyc.verificationStarted) {\n\t\t\t\tresponse = await config.kyc.verificationStarted(body);\n\t\t\t}\n\n\t\t\tresponse ??= {};\n\n\t\t\tif (response?.ok === false) {\n\t\t\t\tthrow(new KeetaAnchorUserError(response.error ?? 'Unknown error'));\n\t\t\t}\n\n\t\t\tresponse.ok = true;\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow(new Error('internal error: invalid response'));\n\t\t\t}\n\t\t\tresponse.id ??= crypto.randomUUID();\n\n\t\t\tlet defaultWebURL: string;\n\t\t\tif (typeof config.kycProviderURL === 'string') {\n\t\t\t\tdefaultWebURL = config.kycProviderURL.replace('{id}', encodeURIComponent(response.id));\n\t\t\t} else if (config.kycProviderURL !== undefined) {\n\t\t\t\tdefaultWebURL = config.kycProviderURL(response.id);\n\t\t\t} else {\n\t\t\t\tdefaultWebURL = kycProviderURLUndefined;\n\t\t\t}\n\t\t\tresponse.webURL ??= defaultWebURL;\n\n\t\t\tif (!response.webURL || response.webURL === kycProviderURLUndefined) {\n\t\t\t\tthrow(new KeetaAnchorUserError('No webURL provided -- cannot proceed with verification'));\n\t\t\t}\n\n\t\t\tresponse.expectedCost = {\n\t\t\t\tmin: '0',\n\t\t\t\tmax: '0',\n\t\t\t\ttoken: KeetaNet.lib.Account.generateBaseAddresses(config.client.network).baseToken.publicKeyString.get(),\n\t\t\t\t...response.expectedCost\n\t\t\t};\n\n\t\t\tconst responseValidated = assertCreateVerificationResponse(response);\n\n\t\t\treturn({\n\t\t\t\toutput: JSON.stringify(responseValidated)\n\t\t\t});\n\t\t};\n\n\t\t/**\n\t\t * Request an estimate for a KYC\n\t\t * verification (optional)\n\t\t *\n\t\t * XXX:TODO\n\t\t */\n\t\t// if (false) {\n\t\t// \troutes['POST /api/createEstimate'] = async function(_ignore_params, _ignore_body) {\n\t\t// \t\tthrow(new Error('not implemented'));\n\t\t// \t};\n\t\t// }\n\n\t\t/**\n\t\t * Get the certificate for the\n\t\t * KYC verification\n\t\t */\n\t\troutes['GET /api/getCertificates/:verificationID'] = async function(params) {\n\t\t\tconst verificationID = params.get('verificationID');\n\t\t\tif (verificationID === undefined) {\n\t\t\t\tthrow(new KeetaAnchorUserError('No verification ID provided'));\n\t\t\t}\n\n\t\t\tconst certificates = await config.kyc.getCertificates(verificationID);\n\n\t\t\tconst response: KeetaKYCAnchorGetCertificateResponse = {\n\t\t\t\tok: true,\n\t\t\t\tresults: certificates\n\t\t\t};\n\n\t\t\treturn({\n\t\t\t\toutput: JSON.stringify(response)\n\t\t\t});\n\t\t};\n\n\t\t/**\n\t\t * Get the verification status.\n\t\t */\n\t\troutes['GET /api/getVerificationStatus/:verificationID'] = async function(params, _ignore_body, _ignore_headers, requestUrl) {\n\t\t\tconst verificationID = params.get('verificationID');\n\t\t\tif (verificationID === undefined) {\n\t\t\t\tthrow(new KeetaAnchorUserError('No verification ID provided'));\n\t\t\t}\n\n\t\t\tconst account = await assertSignedRequester(requestUrl);\n\n\t\t\tconst result = await config.kyc.getVerificationStatus(verificationID, { account });\n\t\t\tconst response: KeetaKYCAnchorGetVerificationStatusResponse = {\n\t\t\t\tok: true,\n\t\t\t\tstatus: result.status\n\t\t\t};\n\t\t\tif (result.requiresManualVerification !== undefined) {\n\t\t\t\tresponse.requiresManualVerification = result.requiresManualVerification;\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\toutput: JSON.stringify(response)\n\t\t\t});\n\t\t};\n\n\t\t/**\n\t\t * Get a new link to continue an existing verification (optional)\n\t\t */\n\t\tconst getVerificationURL = config.kyc.getVerificationURL;\n\t\tif (getVerificationURL !== undefined) {\n\t\t\troutes['GET /api/getVerificationURL/:verificationID'] = async function(params, _ignore_body, _ignore_headers, requestUrl) {\n\t\t\t\tconst verificationID = params.get('verificationID');\n\t\t\t\tif (verificationID === undefined) {\n\t\t\t\t\tthrow(new KeetaAnchorUserError('No verification ID provided'));\n\t\t\t\t}\n\n\t\t\t\tconst account = await assertSignedRequester(requestUrl);\n\n\t\t\t\tconst result = await getVerificationURL(verificationID, { account });\n\t\t\t\tconst response: KeetaKYCAnchorGetVerificationURLResponse = {\n\t\t\t\t\tok: true,\n\t\t\t\t\twebURL: result.webURL\n\t\t\t\t};\n\n\t\t\t\treturn({\n\t\t\t\t\toutput: JSON.stringify(response)\n\t\t\t\t});\n\t\t\t};\n\t\t}\n\n\t\t/**\n\t\t * Check if the KYC provider can\n\t\t * service a more specific locality\n\t\t * (optional)\n\t\t *\n\t\t * XXX:TODO\n\t\t */\n\t\t// if (false) {\n\t\t// \troutes['GET /api/checkLocality'] = async function(_ignore_params, _ignore_body) {\n\t\t// \t\tthrow(new Error('not implemented'));\n\t\t// \t};\n\t\t// }\n\n\t\t/**\n\t\t * Notification that payment has been received for the KYC verification\n\t\t *\n\t\t * XXX:TODO\n\t\t */\n\t\t// if (false) {\n\t\t// \troutes['POST /api/notifyPayment/:verificationID'] = async function(_ignore_params, _ignore_body) {\n\t\t// \t\tthrow(new Error('not implemented'));\n\t\t// \t};\n\t\t// }\n\n\t\treturn({\n\t\t\t...config.routes,\n\t\t\t...routes\n\t\t});\n\t}\n\n\tprotected async buildServiceMetadata(): Promise<NonNullable<ServiceMetadata['services']['kyc']>[string]> {\n\t\tconst operations: NonNullable<ServiceMetadata['services']['kyc']>[string]['operations'] = {\n\t\t\t// checkLocality: (new URL('/api/checkLocality', this.url)).toString(),\n\t\t\t// getEstimate: (new URL('/api/createEstimate', this.url)).toString(),\n\t\t\t// notifyPayment: (new URL('/api/notifyPayment/{id}', this.url)).toString(),\n\t\t\tcreateVerification: (new URL('/api/createVerification', this.url)).toString(),\n\t\t\tgetCertificates: (new URL('/api/getCertificates', this.url)).toString() + '/{id}',\n\t\t\tgetVerificationStatus: (new URL('/api/getVerificationStatus', this.url)).toString() + '/{id}'\n\t\t};\n\t\tif (this.kyc.getVerificationURL !== undefined) {\n\t\t\toperations.getVerificationURL = (new URL('/api/getVerificationURL', this.url)).toString() + '/{id}';\n\t\t}\n\n\t\treturn({\n\t\t\tca: this.ca.toPEM(),\n\t\t\tcountryCodes: this.#countryCodes?.map(function(country) {\n\t\t\t\treturn(country.code);\n\t\t\t}) ?? [],\n\t\t\tentityTypes: Object.fromEntries(kycEntityTypes.map((entityType) => {\n\t\t\t\treturn([entityType, this.#entityTypes.includes(entityType)]);\n\t\t\t})),\n\t\t\toperations\n\t\t});\n\t}\n}\n"]}