@keetanetwork/anchor 0.0.62 → 0.0.63
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/anchor-metadata-server.d.ts +54 -0
- package/lib/anchor-metadata-server.d.ts.map +1 -0
- package/lib/anchor-metadata-server.js +62 -0
- package/lib/anchor-metadata-server.js.map +1 -0
- package/lib/error.d.ts +35 -0
- package/lib/error.d.ts.map +1 -1
- package/lib/error.generated.d.ts +3 -0
- package/lib/error.generated.d.ts.map +1 -0
- package/lib/error.generated.js +104 -0
- package/lib/error.generated.js.map +1 -0
- package/lib/error.js +66 -1
- package/lib/error.js.map +1 -1
- package/lib/http-server/common.d.ts +20 -2
- package/lib/http-server/common.d.ts.map +1 -1
- package/lib/http-server/common.js +47 -0
- package/lib/http-server/common.js.map +1 -1
- package/lib/http-server/index.d.ts +22 -0
- package/lib/http-server/index.d.ts.map +1 -1
- package/lib/http-server/index.js +23 -0
- package/lib/http-server/index.js.map +1 -1
- package/lib/metadata.types.d.ts +40 -0
- package/lib/metadata.types.d.ts.map +1 -1
- package/lib/metadata.types.js.map +1 -1
- package/lib/resolver.d.ts +19 -20
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.js +1420 -681
- package/lib/resolver.js.map +1 -1
- package/lib/utils/certificate-network.d.ts +84 -0
- package/lib/utils/certificate-network.d.ts.map +1 -0
- package/lib/utils/certificate-network.js +104 -0
- package/lib/utils/certificate-network.js.map +1 -0
- package/lib/utils/signing.d.ts +12 -0
- package/lib/utils/signing.d.ts.map +1 -1
- package/lib/utils/signing.js +145 -2
- package/lib/utils/signing.js.map +1 -1
- package/npm-shrinkwrap.json +4 -4
- package/package.json +1 -1
- package/services/asset-movement/common.d.ts.map +1 -1
- package/services/asset-movement/common.js +7 -53
- package/services/asset-movement/common.js.map +1 -1
- package/services/asset-movement/server.d.ts +6 -4
- package/services/asset-movement/server.d.ts.map +1 -1
- package/services/asset-movement/server.js +3 -3
- package/services/asset-movement/server.js.map +1 -1
- package/services/fx/common.js +7 -7
- package/services/fx/server.d.ts +9 -7
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +5 -5
- package/services/fx/server.js.map +1 -1
- package/services/kyc/server.d.ts +6 -4
- package/services/kyc/server.d.ts.map +1 -1
- package/services/kyc/server.js +3 -3
- package/services/kyc/server.js.map +1 -1
- package/services/notification/common.d.ts +2 -1
- package/services/notification/common.d.ts.map +1 -1
- package/services/notification/common.generated.js +20 -20
- package/services/notification/common.js +3 -2
- package/services/notification/common.js.map +1 -1
- package/services/notification/server.d.ts +7 -6
- package/services/notification/server.d.ts.map +1 -1
- package/services/notification/server.js +25 -62
- package/services/notification/server.js.map +1 -1
- package/services/storage/common.d.ts +2 -1
- package/services/storage/common.d.ts.map +1 -1
- package/services/storage/common.js +7 -2
- package/services/storage/common.js.map +1 -1
- package/services/storage/server.d.ts +7 -5
- package/services/storage/server.d.ts.map +1 -1
- package/services/storage/server.js +29 -99
- package/services/storage/server.js.map +1 -1
- package/services/username/common.d.ts +2 -1
- package/services/username/common.d.ts.map +1 -1
- package/services/username/common.generated.js +14 -48
- package/services/username/common.generated.js.map +1 -1
- package/services/username/common.js +3 -2
- package/services/username/common.js.map +1 -1
- package/services/username/server.d.ts +7 -6
- package/services/username/server.d.ts.map +1 -1
- package/services/username/server.js +38 -46
- package/services/username/server.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/kyc/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAE5D,OAAO,KAAK,qBAAqB,MAAM,gCAAgC,CAAC;AACxE,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EACN,+BAA+B,EAC/B,gCAAgC,EAChC,MAAM,uBAAuB,CAAC;AAC/B,OAA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AAC,eAAe;QACpB,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,UAAU,EAAE;gBACX,uEAAuE;gBACvE,sEAAsE;gBACtE,4EAA4E;gBAC5E,kBAAkB,EAAE,CAAC,IAAI,GAAG,CAAC,yBAAyB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;gBAC7E,eAAe,EAAE,CAAC,IAAI,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,OAAO;aACjF;SACD,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { KeetaNet } from '../../client/index.js';\nimport * as CurrencyInfo from '@keetanetwork/currency-info';\n\nimport * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\nimport type {\n\tKeetaKYCAnchorCreateVerificationRequest,\n\tKeetaKYCAnchorCreateVerificationResponse,\n\tKeetaKYCAnchorGetCertificateResponse\n} from './common.ts';\nimport {\n\tassertCreateVerificationRequest,\n\tassertCreateVerificationResponse\n} from './common.generated.js';\nimport {\n\tverifySignedData\n} from './common.js';\nimport type * as Signing from '../../lib/utils/signing.js';\nimport type { ServiceMetadata } from '../../lib/resolver.ts';\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 KeetaAnchorHTTPServer.KeetaAnchorHTTPServerConfig {\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 * Country codes that this KYC provider can service (default is all country codes)\n\t\t */\n\t\tcountryCodes?: (CurrencyInfo.Country | CurrencyInfo.ISOCountryCode)[];\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 KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer<KeetaAnchorKYCServerConfig> implements Required<KeetaAnchorKYCServerConfig> {\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\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\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 = {};\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 * 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\tasync serviceMetadata(): Promise<NonNullable<ServiceMetadata['services']['kyc']>[string]> {\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\toperations: {\n\t\t\t\t// checkLocality: (new URL('/api/checkLocality', this.url)).toString(),\n\t\t\t\t// getEstimate: (new URL('/api/createEstimate', this.url)).toString(),\n\t\t\t\t// notifyPayment: (new URL('/api/notifyPayment/{id}', this.url)).toString(),\n\t\t\t\tcreateVerification: (new URL('/api/createVerification', this.url)).toString(),\n\t\t\t\tgetCertificates: (new URL('/api/getCertificates', this.url)).toString() + '/{id}'\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/services/kyc/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAI5D,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EACN,+BAA+B,EAC/B,gCAAgC,EAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,gBAAgB,EAChB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAEhF,MAAM,uBAAuB,GAAG,0DAA0D,CAAC;AA4H1F,CAAC;AAEF,MAAM,OAAO,2BAA4B,SAAQ,yBAA8G;IACrJ,QAAQ,CAAsD;IAC9D,MAAM,CAAuC;IAC7C,MAAM,CAAoD;IAC1D,EAAE,CAAmC;IACrC,GAAG,CAAoC;IACvC,cAAc,CAA4D;IAC1E,MAAM,CAAoD;IAC1D,aAAa,CAAsC;IAE5D,YAAY,MAAkC;QAC7C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BAAyB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;gBAC7E,eAAe,EAAE,CAAC,IAAI,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,OAAO;aACjF;SACD,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { KeetaNet } from '../../client/index.js';\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} from './common.ts';\nimport {\n\tassertCreateVerificationRequest,\n\tassertCreateVerificationResponse\n} from './common.generated.js';\nimport {\n\tverifySignedData\n} from './common.js';\nimport type * as Signing from '../../lib/utils/signing.js';\nimport type { ServiceMetadata } from '../../lib/resolver.ts';\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 * Country codes that this KYC provider can service (default is all country codes)\n\t\t */\n\t\tcountryCodes?: (CurrencyInfo.Country | CurrencyInfo.ISOCountryCode)[];\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 Required<KeetaAnchorKYCServerConfig> {\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\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\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 = {};\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 * 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\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\toperations: {\n\t\t\t\t// checkLocality: (new URL('/api/checkLocality', this.url)).toString(),\n\t\t\t\t// getEstimate: (new URL('/api/createEstimate', this.url)).toString(),\n\t\t\t\t// notifyPayment: (new URL('/api/notifyPayment/{id}', this.url)).toString(),\n\t\t\t\tcreateVerification: (new URL('/api/createVerification', this.url)).toString(),\n\t\t\t\tgetCertificates: (new URL('/api/getCertificates', this.url)).toString() + '/{id}'\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { ToJSONSerializable } from '../../lib/utils/json.js';
|
|
|
2
2
|
import type { HTTPSignedField } from '../../lib/http-server/common.js';
|
|
3
3
|
import type { Signable } from '../../lib/utils/signing.js';
|
|
4
4
|
import type { Account, GenericAccount } from '@keetanetwork/keetanet-client/lib/account.js';
|
|
5
|
-
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
5
|
+
import { KeetaAnchorCertificateRequiredError, KeetaAnchorUserError } from '../../lib/error.js';
|
|
6
6
|
export * from './common.generated.js';
|
|
7
7
|
interface BaseNotificationChannelArguments<T extends string> {
|
|
8
8
|
type: T;
|
|
@@ -176,5 +176,6 @@ declare class KeetaNotificationAnchorMethodNotSupportedError extends KeetaAnchor
|
|
|
176
176
|
}
|
|
177
177
|
export declare const Errors: {
|
|
178
178
|
MethodNotSupported: typeof KeetaNotificationAnchorMethodNotSupportedError;
|
|
179
|
+
CertificateRequired: typeof KeetaAnchorCertificateRequiredError;
|
|
179
180
|
};
|
|
180
181
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/services/notification/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,C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rF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0DAA0D,CAA0C;IAC5H,SAAkB,QAAQ,UAAU;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,uBAAuB,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,4BAA4B,GAAG,SAAS,CAAC;gBAEzD,UAAU,EAAE,wDAAwD,EAAE,OAAO,CAAC,EAAE,MAAM;IAalG,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,8CAA8C;IAI1F,MAAM,IAAI,kDAAkD;WAQ/C,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,8CAA8C,CAAC;CAiB9F;AAED,eAAO,MAAM,MAAM,EAAE;IACpB,kBAAkB,EAAE,OAAO,8CAA8C,CAAC;IAC1E,mBAAmB,EAAE,OAAO,mCAAmC,CAAC;CAIhE,CAAC"}
|
|
@@ -23,12 +23,12 @@ export const assertKeetaNotificationAnchorListTargetsRequestJSON = (() => { cons
|
|
|
23
23
|
}, _errorFactory)) && (("object" === typeof input.signed && null !== input.signed || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
24
24
|
method: "createAssertEquals",
|
|
25
25
|
path: _path + ".signed",
|
|
26
|
-
expected: "
|
|
26
|
+
expected: "HTTPSignedField",
|
|
27
27
|
value: input.signed
|
|
28
28
|
}, _errorFactory)) && _ao1(input.signed, _path + ".signed", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
29
29
|
method: "createAssertEquals",
|
|
30
30
|
path: _path + ".signed",
|
|
31
|
-
expected: "
|
|
31
|
+
expected: "HTTPSignedField",
|
|
32
32
|
value: input.signed
|
|
33
33
|
}, _errorFactory)) && (2 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).every(key => {
|
|
34
34
|
if (["account", "signed"].some(prop => key === prop))
|
|
@@ -75,12 +75,12 @@ export const assertKeetaNotificationAnchorListTargetsRequestJSON = (() => { cons
|
|
|
75
75
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
76
76
|
method: "createAssertEquals",
|
|
77
77
|
path: _path + "",
|
|
78
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
78
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; } & {}",
|
|
79
79
|
value: input
|
|
80
80
|
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
81
81
|
method: "createAssertEquals",
|
|
82
82
|
path: _path + "",
|
|
83
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
83
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; } & {}",
|
|
84
84
|
value: input
|
|
85
85
|
}, _errorFactory))(input, "$input", true);
|
|
86
86
|
}
|
|
@@ -115,12 +115,12 @@ export const assertKeetaNotificationAnchorRegisterTargetRequestJSON = (() => { c
|
|
|
115
115
|
}, _errorFactory)) && (("object" === typeof input.signed && null !== input.signed || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
116
116
|
method: "createAssertEquals",
|
|
117
117
|
path: _path + ".signed",
|
|
118
|
-
expected: "
|
|
118
|
+
expected: "HTTPSignedField",
|
|
119
119
|
value: input.signed
|
|
120
120
|
}, _errorFactory)) && _ao1(input.signed, _path + ".signed", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
121
121
|
method: "createAssertEquals",
|
|
122
122
|
path: _path + ".signed",
|
|
123
|
-
expected: "
|
|
123
|
+
expected: "HTTPSignedField",
|
|
124
124
|
value: input.signed
|
|
125
125
|
}, _errorFactory)) && (("object" === typeof input.channel && null !== input.channel || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
126
126
|
method: "createAssertEquals",
|
|
@@ -204,12 +204,12 @@ export const assertKeetaNotificationAnchorRegisterTargetRequestJSON = (() => { c
|
|
|
204
204
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
205
205
|
method: "createAssertEquals",
|
|
206
206
|
path: _path + "",
|
|
207
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
207
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; channel: { ...; } & {}; } & {}",
|
|
208
208
|
value: input
|
|
209
209
|
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
210
210
|
method: "createAssertEquals",
|
|
211
211
|
path: _path + "",
|
|
212
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
212
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; channel: { ...; } & {}; } & {}",
|
|
213
213
|
value: input
|
|
214
214
|
}, _errorFactory))(input, "$input", true);
|
|
215
215
|
}
|
|
@@ -237,12 +237,12 @@ export const assertKeetaNotificationAnchorDeleteTargetRequestJSON = (() => { con
|
|
|
237
237
|
}, _errorFactory)) && (("object" === typeof input.signed && null !== input.signed || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
238
238
|
method: "createAssertEquals",
|
|
239
239
|
path: _path + ".signed",
|
|
240
|
-
expected: "
|
|
240
|
+
expected: "HTTPSignedField",
|
|
241
241
|
value: input.signed
|
|
242
242
|
}, _errorFactory)) && _ao1(input.signed, _path + ".signed", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
243
243
|
method: "createAssertEquals",
|
|
244
244
|
path: _path + ".signed",
|
|
245
|
-
expected: "
|
|
245
|
+
expected: "HTTPSignedField",
|
|
246
246
|
value: input.signed
|
|
247
247
|
}, _errorFactory)) && ("string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
248
248
|
method: "createAssertEquals",
|
|
@@ -294,12 +294,12 @@ export const assertKeetaNotificationAnchorDeleteTargetRequestJSON = (() => { con
|
|
|
294
294
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
295
295
|
method: "createAssertEquals",
|
|
296
296
|
path: _path + "",
|
|
297
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
297
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; id: string; } & {}",
|
|
298
298
|
value: input
|
|
299
299
|
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
300
300
|
method: "createAssertEquals",
|
|
301
301
|
path: _path + "",
|
|
302
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
302
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; id: string; } & {}",
|
|
303
303
|
value: input
|
|
304
304
|
}, _errorFactory))(input, "$input", true);
|
|
305
305
|
}
|
|
@@ -529,12 +529,12 @@ export const assertKeetaNotificationAnchorDeleteSubscriptionRequestJSON = (() =>
|
|
|
529
529
|
}, _errorFactory)) && (("object" === typeof input.signed && null !== input.signed || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
530
530
|
method: "createAssertEquals",
|
|
531
531
|
path: _path + ".signed",
|
|
532
|
-
expected: "
|
|
532
|
+
expected: "HTTPSignedField",
|
|
533
533
|
value: input.signed
|
|
534
534
|
}, _errorFactory)) && _ao1(input.signed, _path + ".signed", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
535
535
|
method: "createAssertEquals",
|
|
536
536
|
path: _path + ".signed",
|
|
537
|
-
expected: "
|
|
537
|
+
expected: "HTTPSignedField",
|
|
538
538
|
value: input.signed
|
|
539
539
|
}, _errorFactory)) && ("string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
540
540
|
method: "createAssertEquals",
|
|
@@ -586,12 +586,12 @@ export const assertKeetaNotificationAnchorDeleteSubscriptionRequestJSON = (() =>
|
|
|
586
586
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
587
587
|
method: "createAssertEquals",
|
|
588
588
|
path: _path + "",
|
|
589
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
589
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; id: string; } & {}",
|
|
590
590
|
value: input
|
|
591
591
|
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
592
592
|
method: "createAssertEquals",
|
|
593
593
|
path: _path + "",
|
|
594
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
594
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; id: string; } & {}",
|
|
595
595
|
value: input
|
|
596
596
|
}, _errorFactory))(input, "$input", true);
|
|
597
597
|
}
|
|
@@ -619,12 +619,12 @@ export const assertKeetaNotificationAnchorListSubscriptionsRequestJSON = (() =>
|
|
|
619
619
|
}, _errorFactory)) && (("object" === typeof input.signed && null !== input.signed || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
620
620
|
method: "createAssertEquals",
|
|
621
621
|
path: _path + ".signed",
|
|
622
|
-
expected: "
|
|
622
|
+
expected: "HTTPSignedField",
|
|
623
623
|
value: input.signed
|
|
624
624
|
}, _errorFactory)) && _ao1(input.signed, _path + ".signed", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
|
|
625
625
|
method: "createAssertEquals",
|
|
626
626
|
path: _path + ".signed",
|
|
627
|
-
expected: "
|
|
627
|
+
expected: "HTTPSignedField",
|
|
628
628
|
value: input.signed
|
|
629
629
|
}, _errorFactory)) && (2 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).every(key => {
|
|
630
630
|
if (["account", "signed"].some(prop => key === prop))
|
|
@@ -671,12 +671,12 @@ export const assertKeetaNotificationAnchorListSubscriptionsRequestJSON = (() =>
|
|
|
671
671
|
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
|
|
672
672
|
method: "createAssertEquals",
|
|
673
673
|
path: _path + "",
|
|
674
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
674
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; } & {}",
|
|
675
675
|
value: input
|
|
676
676
|
}, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
|
|
677
677
|
method: "createAssertEquals",
|
|
678
678
|
path: _path + "",
|
|
679
|
-
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed:
|
|
679
|
+
expected: "{ account: Secp256K1PublicKeyString | ED25519PublicKeyString | Secp256R1PublicKeyString; signed: HTTPSignedField; } & {}",
|
|
680
680
|
value: input
|
|
681
681
|
}, _errorFactory))(input, "$input", true);
|
|
682
682
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertNever } from '../../lib/utils/never.js';
|
|
2
|
-
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
2
|
+
import { KeetaAnchorCertificateRequiredError, KeetaAnchorUserError } from '../../lib/error.js';
|
|
3
3
|
import { assertNotificationChannelType, assertNotificationSubscriptionType } from './common.generated.js';
|
|
4
4
|
import { KeetaNet } from '../../client/index.js';
|
|
5
5
|
export * from './common.generated.js';
|
|
@@ -134,6 +134,7 @@ class KeetaNotificationAnchorMethodNotSupportedError extends KeetaAnchorUserErro
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
export const Errors = {
|
|
137
|
-
MethodNotSupported: KeetaNotificationAnchorMethodNotSupportedError
|
|
137
|
+
MethodNotSupported: KeetaNotificationAnchorMethodNotSupportedError,
|
|
138
|
+
CertificateRequired: KeetaAnchorCertificateRequiredError
|
|
138
139
|
};
|
|
139
140
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/services/notification/common.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,kCAAkC,EAAE,MAAM,uBAAuB,CAAC;AAC1G,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,cAAc,uBAAuB,CAAC;AA6DtC,MAAM,qBAAqB,GAAG,sCAAsC,CAAC;AAoBrE,MAAM,UAAU,4CAA4C,CAAC,OAA4E;IACxI,MAAM,KAAK,GAAa;QACvB,qBAAqB;QACrB,iBAAiB;QACjB,OAAO,CAAC,OAAO,CAAC,IAAI;KACpB,CAAC;IAEF,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACpC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;SAAM,CAAC;QACP,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,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AG,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEpE,IAAI,gBAA0D,CAAC;QAC/D,IAAI,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACrD,gBAAgB,GAAG,kCAAkC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC/E,CAAC;QAED,IAAI,WAAgD,CAAC;QACrD,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC/D,WAAW,GAAG,6BAA6B,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,EAAE,gBAAgB,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;QACnE,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;;AAGF,MAAM,CAAC,MAAM,MAAM,GAEf;IACH,kBAAkB,EAAE,8CAA8C;CAClE,CAAC","sourcesContent":["import type { ToJSONSerializable } from '../../lib/utils/json.js';\nimport type { HTTPSignedField } from '../../lib/http-server/common.js';\nimport type { Signable } from '../../lib/utils/signing.js';\nimport type { Account, GenericAccount } from '@keetanetwork/keetanet-client/lib/account.js';\nimport { assertNever } from '../../lib/utils/never.js';\nimport { KeetaAnchorUserError } from '../../lib/error.js';\nimport { assertNotificationChannelType, assertNotificationSubscriptionType } from './common.generated.js';\nimport { KeetaNet } from '../../client/index.js';\nexport * from './common.generated.js';\n\ninterface BaseNotificationChannelArguments<T extends string> {\n\ttype: T;\n}\n\ninterface FCMNotificationChannelArguments extends BaseNotificationChannelArguments<'FCM'> {\n\tappId: string;\n\tfcmToken: string;\n}\n\nexport type NotificationChannelArguments = FCMNotificationChannelArguments;\n\nexport type NotificationChannelType = NotificationChannelArguments['type'];\n\ninterface NotificationChannelServiceMetadata {\n\tFCM: {\n\t\tprojectId: string;\n\t\tmessagingSenderId: string;\n\t\tappId: string;\n\t\tapiKey: string;\n\t\tvapidKey?: string;\n\t\tbundleId?: string;\n\t}\n}\n\ninterface BaseNotificationSubscriptionArguments<T extends string> {\n\ttype: T;\n\n\t// The preferred locale to receive notifications in, if supported by the channel and provider\n\tlocale?: Intl.Locale;\n\n\ttarget: {\n\t\tprovider?: string | undefined;\n\n\t\tids: string[];\n\t}\n}\n\ninterface ReceiveFundsNotificationSubscriptionArguments extends BaseNotificationSubscriptionArguments<'RECEIVE_FUNDS'> {\n\t// Address to listen to incoming transactions for, if omitted will use the requestors address\n\ttoAddress?: GenericAccount;\n}\n\nexport type NotificationSubscriptionArguments = ReceiveFundsNotificationSubscriptionArguments;\nexport type NotificationSubscriptionArgumentsJSON = ToJSONSerializable<Omit<NotificationSubscriptionArguments, 'locale'>> & {\n\tlocale?: string | undefined;\n};\nexport type NotificationSubscriptionType = NotificationSubscriptionArguments['type'];\n\nexport type SupportedChannelConfigurationMetadata = {\n\tFCM: NotificationChannelServiceMetadata['FCM'][];\n}\n\n// API types\n\nexport interface NotificationTargetWithIDResponse {\n\tid: string;\n\tchannel: NotificationChannelArguments;\n}\n\nconst notificationNamespace = '75ed4792-333f-4a50-832f-b9fcc5663d1f';\n\nexport interface KeetaNotificationAnchorRegisterTargetClientRequest {\n\taccount?: Account;\n\tchannel: NotificationChannelArguments;\n}\nexport interface KeetaNotificationAnchorRegisterTargetRequest extends KeetaNotificationAnchorRegisterTargetClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorRegisterTargetRequestJSON = ToJSONSerializable<KeetaNotificationAnchorRegisterTargetRequest>;\n\nexport type KeetaNotificationAnchorRegisterTargetResponseJSON = ({\n\tok: true;\n\tid: string;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport function getNotificationRegisterTargetRequestSignable(request: Pick<KeetaNotificationAnchorRegisterTargetClientRequest, 'channel'>): Signable {\n\tconst parts: Signable = [\n\t\tnotificationNamespace,\n\t\t'REGISTER_TARGET',\n\t\trequest.channel.type\n\t];\n\n\tif (request.channel.type === 'FCM') {\n\t\tparts.push(request.channel.fcmToken, request.channel.appId);\n\t} else {\n\t\tassertNever(request.channel.type);\n\t}\n\n\treturn(parts);\n}\n\nexport interface KeetaNotificationAnchorListTargetsClientRequest { account?: Account; }\ninterface KeetaNotificationAnchorListTargetsRequest extends KeetaNotificationAnchorListTargetsClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorListTargetsRequestJSON = ToJSONSerializable<KeetaNotificationAnchorListTargetsRequest>;\n\nexport type KeetaNotificationAnchorListTargetsResponse = ({\n\tok: true;\n\ttargets: NotificationTargetWithIDResponse[];\n}) | ({\n\tok: false;\n\terror: string;\n});\nexport type KeetaNotificationAnchorListTargetsResponseJSON = ToJSONSerializable<KeetaNotificationAnchorListTargetsResponse>;\n\nexport function getNotificationListTargetsRequestSignable(_ignore_request?: KeetaNotificationAnchorListTargetsClientRequest): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'LIST_TARGETS'\n\t]);\n}\n\n\nexport interface KeetaNotificationAnchorDeleteTargetClientRequest {\n\taccount?: Account;\n\tid: string;\n}\nexport interface KeetaNotificationAnchorDeleteTargetRequest extends KeetaNotificationAnchorDeleteTargetClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorDeleteTargetRequestJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteTargetRequest>;\n\nexport type KeetaNotificationAnchorDeleteTargetResponse = ({\n\tok: true;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorDeleteTargetResponseJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteTargetResponse>;\n\nexport function getNotificationDeleteTargetRequestSignable(request: Pick<KeetaNotificationAnchorDeleteTargetClientRequest, 'id'>): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'DELETE_TARGET',\n\t\trequest.id\n\t]);\n}\n\nexport interface KeetaNotificationAnchorCreateSubscriptionClientRequest {\n\taccount?: Account;\n\tsubscription: NotificationSubscriptionArguments;\n}\n\nexport type KeetaNotificationAnchorCreateSubscriptionRequestJSON = {\n\tsubscription: NotificationSubscriptionArgumentsJSON;\n\taccount: string;\n\tsigned: HTTPSignedField;\n}\n\nexport type KeetaNotificationAnchorCreateSubscriptionResponse = ({\n\tok: true;\n\tid: string;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorCreateSubscriptionResponseJSON = ToJSONSerializable<KeetaNotificationAnchorCreateSubscriptionResponse>;\n\nexport function getNotificationCreateSubscriptionRequestSignable(request: Pick<KeetaNotificationAnchorCreateSubscriptionClientRequest, 'subscription'>): Signable {\n\tconst parts: Signable = [\n\t\tnotificationNamespace,\n\t\t'CREATE_SUBSCRIPTION',\n\t\trequest.subscription.type\n\t];\n\n\tparts.push(request.subscription.locale?.toString() ?? 'NO_LOCALE');\n\n\tif (request.subscription.type === 'RECEIVE_FUNDS') {\n\t\tparts.push(request.subscription.toAddress ?? 'NO_ADDRESS');\n\t} else {\n\t\tassertNever(request.subscription.type);\n\t}\n\n\tparts.push(request.subscription.target.provider ?? 'NO_PROVIDER');\n\n\tparts.push('BEGIN_TARGETS');\n\tfor (const target of request.subscription.target.ids) {\n\t\tparts.push(target);\n\t}\n\tparts.push('END_TARGETS');\n\n\treturn(parts);\n}\n\nexport interface KeetaNotificationAnchorDeleteSubscriptionClientRequest {\n\taccount?: Account;\n\tid: string;\n}\nexport interface KeetaNotificationAnchorDeleteSubscriptionRequest extends KeetaNotificationAnchorDeleteSubscriptionClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorDeleteSubscriptionRequestJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteSubscriptionRequest>;\n\nexport type KeetaNotificationAnchorDeleteSubscriptionResponse = ({\n\tok: true;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorDeleteSubscriptionResponseJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteSubscriptionResponse>;\n\nexport function getNotificationDeleteSubscriptionRequestSignable(request: Pick<KeetaNotificationAnchorDeleteSubscriptionClientRequest, 'id'>): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'DELETE_SUBSCRIPTION',\n\t\trequest.id\n\t]);\n}\n\nexport interface SubscriptionDetails {\n\tid: string;\n\tsubscription: NotificationSubscriptionArguments;\n}\n\nexport type SubscriptionDetailsJSON = ToJSONSerializable<Omit<SubscriptionDetails, 'subscription'>> & {\n\tsubscription: NotificationSubscriptionArgumentsJSON;\n}\n\nexport function parseSubscriptionDetailsWithID(input: SubscriptionDetailsJSON | SubscriptionDetails): SubscriptionDetails {\n\tlet subscription: NotificationSubscriptionArguments;\n\tif (input.subscription.type === 'RECEIVE_FUNDS') {\n\t\tlet locale;\n\t\tif (input.subscription.locale) {\n\t\t\tif (typeof input.subscription.locale === 'string') {\n\t\t\t\tlocale = new Intl.Locale(input.subscription.locale);\n\t\t\t} else {\n\t\t\t\tlocale = input.subscription.locale;\n\t\t\t}\n\t\t}\n\n\t\tsubscription = {\n\t\t\ttype: 'RECEIVE_FUNDS',\n\t\t\ttarget: input.subscription.target,\n\t\t\t...(locale ? { locale } : {}),\n\t\t\t...(input.subscription.toAddress\n\t\t\t\t? { toAddress: KeetaNet.lib.Account.toAccount(input.subscription.toAddress) }\n\t\t\t\t: {})\n\t\t};\n\t} else {\n\t\tassertNever(input.subscription.type);\n\t}\n\n\treturn({ id: input.id, subscription });\n}\n\nexport interface KeetaNotificationAnchorListSubscriptionsClientRequest { account?: Account; }\ninterface KeetaNotificationAnchorListSubscriptionsRequest extends KeetaNotificationAnchorListSubscriptionsClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorListSubscriptionsRequestJSON = ToJSONSerializable<KeetaNotificationAnchorListSubscriptionsRequest>;\n\nexport type KeetaNotificationAnchorListSubscriptionsResponse = ({\n\tok: true;\n\tsubscriptions: SubscriptionDetailsJSON[];\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorListSubscriptionsResponseJSON = ToJSONSerializable<KeetaNotificationAnchorListSubscriptionsResponse>;\n\nexport function getNotificationListSubscriptionsRequestSignable(_ignore_request?: KeetaNotificationAnchorListSubscriptionsClientRequest): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'LIST_SUBSCRIPTIONS'\n\t]);\n}\n\ninterface KeetaNotificationAnchorMethodNotSupportedErrorProperties {\n\tchannelType?: NotificationChannelType | undefined;\n\tsubscriptionType?: NotificationSubscriptionType | undefined;\n}\n\ntype KeetaNotificationAnchorMethodNotSupportedErrorJSON = ReturnType<KeetaAnchorUserError['toJSON']> & KeetaNotificationAnchorMethodNotSupportedErrorProperties;\n\nclass KeetaNotificationAnchorMethodNotSupportedError extends KeetaAnchorUserError implements KeetaNotificationAnchorMethodNotSupportedErrorProperties {\n\tstatic override readonly name: string = 'KeetaNotificationAnchorMethodNotSupportedError';\n\tprivate readonly KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID!: string;\n\tprivate static readonly KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID = '95268e45-2305-4a75-92af-417feb57fdd6';\n\toverride readonly logLevel = 'INFO';\n\treadonly channelType?: NotificationChannelType | undefined;\n\treadonly subscriptionType?: NotificationSubscriptionType | undefined;\n\n\tconstructor(properties: KeetaNotificationAnchorMethodNotSupportedErrorProperties, message?: string) {\n\t\tsuper(message ?? `Request failed: ${properties.channelType ? `channel type ${properties.channelType}` : `subscription type ${properties.subscriptionType}`} not supported`);\n\t\tthis.statusCode = 400;\n\n\t\tObject.defineProperty(this, 'KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID', {\n\t\t\tvalue: KeetaNotificationAnchorMethodNotSupportedError.KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.channelType = properties.channelType;\n\t\tthis.subscriptionType = properties.subscriptionType;\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaNotificationAnchorMethodNotSupportedError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID', KeetaNotificationAnchorMethodNotSupportedError.KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID));\n\t}\n\n\ttoJSON(): KeetaNotificationAnchorMethodNotSupportedErrorJSON {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tchannelType: this.channelType,\n\t\t\tsubscriptionType: this.subscriptionType\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaNotificationAnchorMethodNotSupportedError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\tlet subscriptionType: NotificationSubscriptionType | undefined;\n\t\tif ('intent' in other && other.intent !== undefined) {\n\t\t\tsubscriptionType = assertNotificationSubscriptionType(other.subscriptionType);\n\t\t}\n\n\t\tlet channelType: NotificationChannelType | undefined;\n\t\tif ('channelType' in other && other.channelType !== undefined) {\n\t\t\tchannelType = assertNotificationChannelType(other.channelType);\n\t\t}\n\n\t\tconst error = new this({ subscriptionType, channelType }, message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\nexport const Errors: {\n\tMethodNotSupported: typeof KeetaNotificationAnchorMethodNotSupportedError;\n} = {\n\tMethodNotSupported: KeetaNotificationAnchorMethodNotSupportedError\n};\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/services/notification/common.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,mCAAmC,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,6BAA6B,EAAE,kCAAkC,EAAE,MAAM,uB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mCAAmC;CACxD,CAAC","sourcesContent":["import type { ToJSONSerializable } from '../../lib/utils/json.js';\nimport type { HTTPSignedField } from '../../lib/http-server/common.js';\nimport type { Signable } from '../../lib/utils/signing.js';\nimport type { Account, GenericAccount } from '@keetanetwork/keetanet-client/lib/account.js';\nimport { assertNever } from '../../lib/utils/never.js';\nimport { KeetaAnchorCertificateRequiredError, KeetaAnchorUserError } from '../../lib/error.js';\nimport { assertNotificationChannelType, assertNotificationSubscriptionType } from './common.generated.js';\nimport { KeetaNet } from '../../client/index.js';\nexport * from './common.generated.js';\n\ninterface BaseNotificationChannelArguments<T extends string> {\n\ttype: T;\n}\n\ninterface FCMNotificationChannelArguments extends BaseNotificationChannelArguments<'FCM'> {\n\tappId: string;\n\tfcmToken: string;\n}\n\nexport type NotificationChannelArguments = FCMNotificationChannelArguments;\n\nexport type NotificationChannelType = NotificationChannelArguments['type'];\n\ninterface NotificationChannelServiceMetadata {\n\tFCM: {\n\t\tprojectId: string;\n\t\tmessagingSenderId: string;\n\t\tappId: string;\n\t\tapiKey: string;\n\t\tvapidKey?: string;\n\t\tbundleId?: string;\n\t}\n}\n\ninterface BaseNotificationSubscriptionArguments<T extends string> {\n\ttype: T;\n\n\t// The preferred locale to receive notifications in, if supported by the channel and provider\n\tlocale?: Intl.Locale;\n\n\ttarget: {\n\t\tprovider?: string | undefined;\n\n\t\tids: string[];\n\t}\n}\n\ninterface ReceiveFundsNotificationSubscriptionArguments extends BaseNotificationSubscriptionArguments<'RECEIVE_FUNDS'> {\n\t// Address to listen to incoming transactions for, if omitted will use the requestors address\n\ttoAddress?: GenericAccount;\n}\n\nexport type NotificationSubscriptionArguments = ReceiveFundsNotificationSubscriptionArguments;\nexport type NotificationSubscriptionArgumentsJSON = ToJSONSerializable<Omit<NotificationSubscriptionArguments, 'locale'>> & {\n\tlocale?: string | undefined;\n};\nexport type NotificationSubscriptionType = NotificationSubscriptionArguments['type'];\n\nexport type SupportedChannelConfigurationMetadata = {\n\tFCM: NotificationChannelServiceMetadata['FCM'][];\n}\n\n// API types\n\nexport interface NotificationTargetWithIDResponse {\n\tid: string;\n\tchannel: NotificationChannelArguments;\n}\n\nconst notificationNamespace = '75ed4792-333f-4a50-832f-b9fcc5663d1f';\n\nexport interface KeetaNotificationAnchorRegisterTargetClientRequest {\n\taccount?: Account;\n\tchannel: NotificationChannelArguments;\n}\nexport interface KeetaNotificationAnchorRegisterTargetRequest extends KeetaNotificationAnchorRegisterTargetClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorRegisterTargetRequestJSON = ToJSONSerializable<KeetaNotificationAnchorRegisterTargetRequest>;\n\nexport type KeetaNotificationAnchorRegisterTargetResponseJSON = ({\n\tok: true;\n\tid: string;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport function getNotificationRegisterTargetRequestSignable(request: Pick<KeetaNotificationAnchorRegisterTargetClientRequest, 'channel'>): Signable {\n\tconst parts: Signable = [\n\t\tnotificationNamespace,\n\t\t'REGISTER_TARGET',\n\t\trequest.channel.type\n\t];\n\n\tif (request.channel.type === 'FCM') {\n\t\tparts.push(request.channel.fcmToken, request.channel.appId);\n\t} else {\n\t\tassertNever(request.channel.type);\n\t}\n\n\treturn(parts);\n}\n\nexport interface KeetaNotificationAnchorListTargetsClientRequest { account?: Account; }\ninterface KeetaNotificationAnchorListTargetsRequest extends KeetaNotificationAnchorListTargetsClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorListTargetsRequestJSON = ToJSONSerializable<KeetaNotificationAnchorListTargetsRequest>;\n\nexport type KeetaNotificationAnchorListTargetsResponse = ({\n\tok: true;\n\ttargets: NotificationTargetWithIDResponse[];\n}) | ({\n\tok: false;\n\terror: string;\n});\nexport type KeetaNotificationAnchorListTargetsResponseJSON = ToJSONSerializable<KeetaNotificationAnchorListTargetsResponse>;\n\nexport function getNotificationListTargetsRequestSignable(_ignore_request?: KeetaNotificationAnchorListTargetsClientRequest): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'LIST_TARGETS'\n\t]);\n}\n\n\nexport interface KeetaNotificationAnchorDeleteTargetClientRequest {\n\taccount?: Account;\n\tid: string;\n}\nexport interface KeetaNotificationAnchorDeleteTargetRequest extends KeetaNotificationAnchorDeleteTargetClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorDeleteTargetRequestJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteTargetRequest>;\n\nexport type KeetaNotificationAnchorDeleteTargetResponse = ({\n\tok: true;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorDeleteTargetResponseJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteTargetResponse>;\n\nexport function getNotificationDeleteTargetRequestSignable(request: Pick<KeetaNotificationAnchorDeleteTargetClientRequest, 'id'>): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'DELETE_TARGET',\n\t\trequest.id\n\t]);\n}\n\nexport interface KeetaNotificationAnchorCreateSubscriptionClientRequest {\n\taccount?: Account;\n\tsubscription: NotificationSubscriptionArguments;\n}\n\nexport type KeetaNotificationAnchorCreateSubscriptionRequestJSON = {\n\tsubscription: NotificationSubscriptionArgumentsJSON;\n\taccount: string;\n\tsigned: HTTPSignedField;\n}\n\nexport type KeetaNotificationAnchorCreateSubscriptionResponse = ({\n\tok: true;\n\tid: string;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorCreateSubscriptionResponseJSON = ToJSONSerializable<KeetaNotificationAnchorCreateSubscriptionResponse>;\n\nexport function getNotificationCreateSubscriptionRequestSignable(request: Pick<KeetaNotificationAnchorCreateSubscriptionClientRequest, 'subscription'>): Signable {\n\tconst parts: Signable = [\n\t\tnotificationNamespace,\n\t\t'CREATE_SUBSCRIPTION',\n\t\trequest.subscription.type\n\t];\n\n\tparts.push(request.subscription.locale?.toString() ?? 'NO_LOCALE');\n\n\tif (request.subscription.type === 'RECEIVE_FUNDS') {\n\t\tparts.push(request.subscription.toAddress ?? 'NO_ADDRESS');\n\t} else {\n\t\tassertNever(request.subscription.type);\n\t}\n\n\tparts.push(request.subscription.target.provider ?? 'NO_PROVIDER');\n\n\tparts.push('BEGIN_TARGETS');\n\tfor (const target of request.subscription.target.ids) {\n\t\tparts.push(target);\n\t}\n\tparts.push('END_TARGETS');\n\n\treturn(parts);\n}\n\nexport interface KeetaNotificationAnchorDeleteSubscriptionClientRequest {\n\taccount?: Account;\n\tid: string;\n}\nexport interface KeetaNotificationAnchorDeleteSubscriptionRequest extends KeetaNotificationAnchorDeleteSubscriptionClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorDeleteSubscriptionRequestJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteSubscriptionRequest>;\n\nexport type KeetaNotificationAnchorDeleteSubscriptionResponse = ({\n\tok: true;\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorDeleteSubscriptionResponseJSON = ToJSONSerializable<KeetaNotificationAnchorDeleteSubscriptionResponse>;\n\nexport function getNotificationDeleteSubscriptionRequestSignable(request: Pick<KeetaNotificationAnchorDeleteSubscriptionClientRequest, 'id'>): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'DELETE_SUBSCRIPTION',\n\t\trequest.id\n\t]);\n}\n\nexport interface SubscriptionDetails {\n\tid: string;\n\tsubscription: NotificationSubscriptionArguments;\n}\n\nexport type SubscriptionDetailsJSON = ToJSONSerializable<Omit<SubscriptionDetails, 'subscription'>> & {\n\tsubscription: NotificationSubscriptionArgumentsJSON;\n}\n\nexport function parseSubscriptionDetailsWithID(input: SubscriptionDetailsJSON | SubscriptionDetails): SubscriptionDetails {\n\tlet subscription: NotificationSubscriptionArguments;\n\tif (input.subscription.type === 'RECEIVE_FUNDS') {\n\t\tlet locale;\n\t\tif (input.subscription.locale) {\n\t\t\tif (typeof input.subscription.locale === 'string') {\n\t\t\t\tlocale = new Intl.Locale(input.subscription.locale);\n\t\t\t} else {\n\t\t\t\tlocale = input.subscription.locale;\n\t\t\t}\n\t\t}\n\n\t\tsubscription = {\n\t\t\ttype: 'RECEIVE_FUNDS',\n\t\t\ttarget: input.subscription.target,\n\t\t\t...(locale ? { locale } : {}),\n\t\t\t...(input.subscription.toAddress\n\t\t\t\t? { toAddress: KeetaNet.lib.Account.toAccount(input.subscription.toAddress) }\n\t\t\t\t: {})\n\t\t};\n\t} else {\n\t\tassertNever(input.subscription.type);\n\t}\n\n\treturn({ id: input.id, subscription });\n}\n\nexport interface KeetaNotificationAnchorListSubscriptionsClientRequest { account?: Account; }\ninterface KeetaNotificationAnchorListSubscriptionsRequest extends KeetaNotificationAnchorListSubscriptionsClientRequest {\n\taccount: Account;\n\tsigned: HTTPSignedField;\n}\nexport type KeetaNotificationAnchorListSubscriptionsRequestJSON = ToJSONSerializable<KeetaNotificationAnchorListSubscriptionsRequest>;\n\nexport type KeetaNotificationAnchorListSubscriptionsResponse = ({\n\tok: true;\n\tsubscriptions: SubscriptionDetailsJSON[];\n}) | ({\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaNotificationAnchorListSubscriptionsResponseJSON = ToJSONSerializable<KeetaNotificationAnchorListSubscriptionsResponse>;\n\nexport function getNotificationListSubscriptionsRequestSignable(_ignore_request?: KeetaNotificationAnchorListSubscriptionsClientRequest): Signable {\n\treturn([\n\t\tnotificationNamespace,\n\t\t'LIST_SUBSCRIPTIONS'\n\t]);\n}\n\ninterface KeetaNotificationAnchorMethodNotSupportedErrorProperties {\n\tchannelType?: NotificationChannelType | undefined;\n\tsubscriptionType?: NotificationSubscriptionType | undefined;\n}\n\ntype KeetaNotificationAnchorMethodNotSupportedErrorJSON = ReturnType<KeetaAnchorUserError['toJSON']> & KeetaNotificationAnchorMethodNotSupportedErrorProperties;\n\nclass KeetaNotificationAnchorMethodNotSupportedError extends KeetaAnchorUserError implements KeetaNotificationAnchorMethodNotSupportedErrorProperties {\n\tstatic override readonly name: string = 'KeetaNotificationAnchorMethodNotSupportedError';\n\tprivate readonly KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID!: string;\n\tprivate static readonly KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID = '95268e45-2305-4a75-92af-417feb57fdd6';\n\toverride readonly logLevel = 'INFO';\n\treadonly channelType?: NotificationChannelType | undefined;\n\treadonly subscriptionType?: NotificationSubscriptionType | undefined;\n\n\tconstructor(properties: KeetaNotificationAnchorMethodNotSupportedErrorProperties, message?: string) {\n\t\tsuper(message ?? `Request failed: ${properties.channelType ? `channel type ${properties.channelType}` : `subscription type ${properties.subscriptionType}`} not supported`);\n\t\tthis.statusCode = 400;\n\n\t\tObject.defineProperty(this, 'KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID', {\n\t\t\tvalue: KeetaNotificationAnchorMethodNotSupportedError.KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.channelType = properties.channelType;\n\t\tthis.subscriptionType = properties.subscriptionType;\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaNotificationAnchorMethodNotSupportedError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID', KeetaNotificationAnchorMethodNotSupportedError.KeetaNotificationAnchorMethodNotSupportedErrorObjectTypeID));\n\t}\n\n\ttoJSON(): KeetaNotificationAnchorMethodNotSupportedErrorJSON {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tchannelType: this.channelType,\n\t\t\tsubscriptionType: this.subscriptionType\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaNotificationAnchorMethodNotSupportedError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\tlet subscriptionType: NotificationSubscriptionType | undefined;\n\t\tif ('intent' in other && other.intent !== undefined) {\n\t\t\tsubscriptionType = assertNotificationSubscriptionType(other.subscriptionType);\n\t\t}\n\n\t\tlet channelType: NotificationChannelType | undefined;\n\t\tif ('channelType' in other && other.channelType !== undefined) {\n\t\t\tchannelType = assertNotificationChannelType(other.channelType);\n\t\t}\n\n\t\tconst error = new this({ subscriptionType, channelType }, message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\nexport const Errors: {\n\tMethodNotSupported: typeof KeetaNotificationAnchorMethodNotSupportedError;\n\tCertificateRequired: typeof KeetaAnchorCertificateRequiredError;\n} = {\n\tMethodNotSupported: KeetaNotificationAnchorMethodNotSupportedError,\n\tCertificateRequired: KeetaAnchorCertificateRequiredError\n};\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';
|
|
1
|
+
import type * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';
|
|
2
|
+
import type { KeetaAnchorMetadataServerConfig } from '../../lib/anchor-metadata-server.js';
|
|
2
3
|
import type { KeetaNotificationAnchorRegisterTargetClientRequest, KeetaNotificationAnchorListTargetsClientRequest, NotificationTargetWithIDResponse, KeetaNotificationAnchorDeleteTargetClientRequest, KeetaNotificationAnchorCreateSubscriptionClientRequest, KeetaNotificationAnchorDeleteSubscriptionClientRequest, KeetaNotificationAnchorListSubscriptionsClientRequest, SubscriptionDetails, NotificationSubscriptionType, SupportedChannelConfigurationMetadata } from './common.js';
|
|
3
4
|
import type { ServiceMetadata } from '../../lib/resolver.js';
|
|
4
|
-
import
|
|
5
|
-
export interface KeetaAnchorNotificationServerConfig extends
|
|
5
|
+
import { KeetaAnchorMetadataServer } from '../../lib/anchor-metadata-server.js';
|
|
6
|
+
export interface KeetaAnchorNotificationServerConfig extends KeetaAnchorMetadataServerConfig {
|
|
6
7
|
homepage?: string | (() => Promise<string> | string);
|
|
7
8
|
notification: {
|
|
8
9
|
registerTarget?: (args: Required<KeetaNotificationAnchorRegisterTargetClientRequest>) => Promise<{
|
|
@@ -26,14 +27,14 @@ export interface KeetaAnchorNotificationServerConfig extends KeetaAnchorHTTPServ
|
|
|
26
27
|
supportedChannels?: SupportedChannelConfigurationMetadata;
|
|
27
28
|
supportedSubscriptions?: NotificationSubscriptionType[];
|
|
28
29
|
};
|
|
29
|
-
routes?: Routes;
|
|
30
|
+
routes?: KeetaAnchorHTTPServer.Routes;
|
|
30
31
|
}
|
|
31
|
-
export declare class KeetaNetNotificationAnchorHTTPServer extends
|
|
32
|
+
export declare class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataServer<NonNullable<ServiceMetadata['services']['notification']>[string], KeetaAnchorNotificationServerConfig> {
|
|
32
33
|
readonly homepage: NonNullable<KeetaAnchorNotificationServerConfig['homepage']>;
|
|
33
34
|
readonly notification: KeetaAnchorNotificationServerConfig['notification'];
|
|
34
35
|
readonly routes: NonNullable<KeetaAnchorNotificationServerConfig['routes']>;
|
|
35
36
|
constructor(config: KeetaAnchorNotificationServerConfig);
|
|
36
37
|
protected initRoutes(config: KeetaAnchorNotificationServerConfig): Promise<KeetaAnchorHTTPServer.Routes>;
|
|
37
|
-
|
|
38
|
+
protected buildServiceMetadata(): Promise<NonNullable<ServiceMetadata['services']['notification']>[string]>;
|
|
38
39
|
}
|
|
39
40
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/services/notification/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,qBAAqB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/services/notification/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,qBAAqB,MAAM,gCAAgC,CAAC;AAC7E,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAC;AAC3F,OAAO,KAAK,EACX,kDAAkD,EAClD,+CAA+C,EAC/C,gCAAgC,EAChC,gDAAgD,EAGhD,sDAAsD,EACtD,sDA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qCAAqC,CAAC;QAC1D,sBAAsB,CAAC,EAAE,4BAA4B,EAAE,CAAC;KACxD,CAAC;IACF,MAAM,CAAC,EAAE,qBAAqB,CAAC,MAAM,CAAC;CACtC;AAED,qBAAa,oCAAqC,SAAQ,yBAAyB,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,mCAAmC,CAAC;IACzL,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,mCAAmC,CAAC,UAAU,CAAC,CAAC,CAAC;IAChF,QAAQ,CAAC,YAAY,EAAE,mCAAmC,CAAC,cAAc,CAAC,CAAC;IAC3E,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,mCAAmC,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAEhE,MAAM,EAAE,mCAAmC;cAQvC,UAAU,CAAC,MAAM,EAAE,mCAAmC,GAAG,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC;cA+J9F,oBAAoB,IAAI,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;CA+CjH"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { KeetaNet } from '../../client/index.js';
|
|
2
|
-
import * as KeetaAnchorHTTPServer from '../../lib/http-server/index.js';
|
|
3
2
|
import { getNotificationRegisterTargetRequestSignable, assertKeetaNotificationAnchorRegisterTargetRequestJSON, getNotificationListTargetsRequestSignable, assertKeetaNotificationAnchorDeleteTargetRequestJSON, getNotificationDeleteTargetRequestSignable, assertKeetaNotificationAnchorCreateSubscriptionRequestJSON, getNotificationCreateSubscriptionRequestSignable, assertKeetaNotificationAnchorDeleteSubscriptionRequestJSON, getNotificationDeleteSubscriptionRequestSignable, getNotificationListSubscriptionsRequestSignable } from './common.js';
|
|
3
|
+
import { KeetaAnchorMetadataServer } from '../../lib/anchor-metadata-server.js';
|
|
4
4
|
import { KeetaAnchorUserError } from '../../lib/error.js';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.KeetaNetAnchorHTTPServer {
|
|
5
|
+
import { verifyBodyAuth, verifyURLAuth } from '../../lib/http-server/common.js';
|
|
6
|
+
export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorMetadataServer {
|
|
8
7
|
homepage;
|
|
9
8
|
notification;
|
|
10
9
|
routes;
|
|
@@ -37,17 +36,9 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
37
36
|
const registerTargetHandler = this.notification.registerTarget;
|
|
38
37
|
if (registerTargetHandler) {
|
|
39
38
|
routes['POST /api/target'] = async (_params, body) => {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
...raw,
|
|
44
|
-
account: KeetaNet.lib.Account.toAccount(raw.account)
|
|
45
|
-
});
|
|
46
|
-
})();
|
|
47
|
-
const signatureVerified = await Signing.VerifySignedData(request.account, getNotificationRegisterTargetRequestSignable(request), request.signed);
|
|
48
|
-
if (!signatureVerified) {
|
|
49
|
-
throw (new KeetaAnchorUserError('Invalid signature'));
|
|
50
|
-
}
|
|
39
|
+
const raw = assertKeetaNotificationAnchorRegisterTargetRequestJSON(body);
|
|
40
|
+
const account = await verifyBodyAuth(raw, getNotificationRegisterTargetRequestSignable, this.resolvedCertificateChainRequirement);
|
|
41
|
+
const request = { ...raw, account };
|
|
51
42
|
const registerResponse = await registerTargetHandler(request);
|
|
52
43
|
return ({
|
|
53
44
|
output: JSON.stringify({
|
|
@@ -61,15 +52,8 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
61
52
|
const listTargetsHandler = this.notification.listTargets;
|
|
62
53
|
if (listTargetsHandler) {
|
|
63
54
|
routes['GET /api/targets'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
throw (new KeetaAnchorUserError('Missing signature parameters in URL'));
|
|
67
|
-
}
|
|
68
|
-
const verifiedSignature = await Signing.VerifySignedData(signatureDetails.account, getNotificationListTargetsRequestSignable(), signatureDetails.signedField);
|
|
69
|
-
if (!verifiedSignature) {
|
|
70
|
-
throw (new KeetaAnchorUserError('Invalid signature'));
|
|
71
|
-
}
|
|
72
|
-
const listResponse = await listTargetsHandler({ account: signatureDetails.account });
|
|
55
|
+
const account = await verifyURLAuth(url, function () { return (getNotificationListTargetsRequestSignable()); }, this.resolvedCertificateChainRequirement);
|
|
56
|
+
const listResponse = await listTargetsHandler({ account });
|
|
73
57
|
return ({
|
|
74
58
|
output: JSON.stringify({
|
|
75
59
|
ok: true,
|
|
@@ -83,17 +67,9 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
83
67
|
if (deleteTargetHandler) {
|
|
84
68
|
// XXX:TODO should this be post with body or delete with URL param? Delete with URL param is more RESTful but can be more difficult to call from some clients and doesn't allow for a request body (so all data must be in the URL or signature)
|
|
85
69
|
routes['POST /api/delete-target'] = async (_params, body) => {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
...raw,
|
|
90
|
-
account: KeetaNet.lib.Account.toAccount(raw.account)
|
|
91
|
-
});
|
|
92
|
-
})();
|
|
93
|
-
const verifiedSignature = await Signing.VerifySignedData(request.account, getNotificationDeleteTargetRequestSignable(request), request.signed);
|
|
94
|
-
if (!verifiedSignature) {
|
|
95
|
-
throw (new KeetaAnchorUserError('Invalid signature'));
|
|
96
|
-
}
|
|
70
|
+
const raw = assertKeetaNotificationAnchorDeleteTargetRequestJSON(body);
|
|
71
|
+
const account = await verifyBodyAuth(raw, getNotificationDeleteTargetRequestSignable, this.resolvedCertificateChainRequirement);
|
|
72
|
+
const request = { ...raw, account };
|
|
97
73
|
const deleteResponse = await deleteTargetHandler(request);
|
|
98
74
|
return ({
|
|
99
75
|
output: JSON.stringify(deleteResponse),
|
|
@@ -105,7 +81,6 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
105
81
|
if (createSubscriptionHandler) {
|
|
106
82
|
routes['POST /api/subscription'] = async (_params, body) => {
|
|
107
83
|
const raw = assertKeetaNotificationAnchorCreateSubscriptionRequestJSON(body);
|
|
108
|
-
const account = KeetaNet.lib.Account.fromPublicKeyString(raw.account);
|
|
109
84
|
let subscription;
|
|
110
85
|
if (raw.subscription.type === 'RECEIVE_FUNDS') {
|
|
111
86
|
subscription = {
|
|
@@ -120,11 +95,10 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
120
95
|
else {
|
|
121
96
|
throw (new KeetaAnchorUserError(`Unsupported subscription type`));
|
|
122
97
|
}
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
98
|
+
const account = await verifyBodyAuth(raw, function () {
|
|
99
|
+
return (getNotificationCreateSubscriptionRequestSignable({ subscription }));
|
|
100
|
+
}, this.resolvedCertificateChainRequirement);
|
|
101
|
+
const request = { account, subscription, signed: raw.signed };
|
|
128
102
|
const createResponse = await createSubscriptionHandler(request);
|
|
129
103
|
return ({
|
|
130
104
|
output: JSON.stringify({ ok: true, id: createResponse.id }),
|
|
@@ -135,15 +109,8 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
135
109
|
const listSubscriptionsHandler = this.notification.listSubscriptions;
|
|
136
110
|
if (listSubscriptionsHandler) {
|
|
137
111
|
routes['GET /api/subscriptions'] = async (_ignore_params, _ignore_body, _ignore_headers, url) => {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
throw (new KeetaAnchorUserError('Missing signature parameters in URL'));
|
|
141
|
-
}
|
|
142
|
-
const verifiedSignature = await Signing.VerifySignedData(signatureDetails.account, getNotificationListSubscriptionsRequestSignable(), signatureDetails.signedField);
|
|
143
|
-
if (!verifiedSignature) {
|
|
144
|
-
throw (new KeetaAnchorUserError('Invalid signature'));
|
|
145
|
-
}
|
|
146
|
-
const listResponse = await listSubscriptionsHandler({ account: signatureDetails.account });
|
|
112
|
+
const account = await verifyURLAuth(url, function () { return (getNotificationListSubscriptionsRequestSignable()); }, this.resolvedCertificateChainRequirement);
|
|
113
|
+
const listResponse = await listSubscriptionsHandler({ account });
|
|
147
114
|
const subscriptionsJSON = listResponse.subscriptions.map(function (subscription) {
|
|
148
115
|
const { locale, ...restSubscription } = subscription.subscription;
|
|
149
116
|
return ({
|
|
@@ -166,17 +133,9 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
166
133
|
const deleteSubscriptionHandler = this.notification.deleteSubscription;
|
|
167
134
|
if (deleteSubscriptionHandler) {
|
|
168
135
|
routes['POST /api/delete-subscription'] = async (_params, body) => {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
...raw,
|
|
173
|
-
account: KeetaNet.lib.Account.toAccount(raw.account).assertAccount()
|
|
174
|
-
});
|
|
175
|
-
})();
|
|
176
|
-
const verifiedSignature = await Signing.VerifySignedData(request.account, getNotificationDeleteSubscriptionRequestSignable(request), request.signed);
|
|
177
|
-
if (!verifiedSignature) {
|
|
178
|
-
throw (new KeetaAnchorUserError('Invalid signature'));
|
|
179
|
-
}
|
|
136
|
+
const raw = assertKeetaNotificationAnchorDeleteSubscriptionRequestJSON(body);
|
|
137
|
+
const account = await verifyBodyAuth(raw, getNotificationDeleteSubscriptionRequestSignable, this.resolvedCertificateChainRequirement);
|
|
138
|
+
const request = { ...raw, account };
|
|
180
139
|
const deleteResponse = await deleteSubscriptionHandler(request);
|
|
181
140
|
return ({
|
|
182
141
|
output: JSON.stringify(deleteResponse),
|
|
@@ -186,7 +145,7 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
186
145
|
}
|
|
187
146
|
return (routes);
|
|
188
147
|
}
|
|
189
|
-
async
|
|
148
|
+
async buildServiceMetadata() {
|
|
190
149
|
const retval = { operations: {} };
|
|
191
150
|
const authentication = {
|
|
192
151
|
method: 'keeta-account',
|
|
@@ -216,6 +175,10 @@ export class KeetaNetNotificationAnchorHTTPServer extends KeetaAnchorHTTPServer.
|
|
|
216
175
|
if (this.notification.supportedSubscriptions) {
|
|
217
176
|
retval.supportedSubscriptions = this.notification.supportedSubscriptions;
|
|
218
177
|
}
|
|
178
|
+
const acceptedIssuerDNs = this.acceptedIssuerDNs();
|
|
179
|
+
if (acceptedIssuerDNs !== undefined) {
|
|
180
|
+
retval.acceptedIssuerDNs = acceptedIssuerDNs;
|
|
181
|
+
}
|
|
219
182
|
return (retval);
|
|
220
183
|
}
|
|
221
184
|
}
|