@sumsub/gtr-gateway 0.0.0-stage → 0.1.0
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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +171 -2
- package/dist/adapters.d.ts +10 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +80 -0
- package/dist/adapters.js.map +1 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +53 -0
- package/dist/errors.js.map +1 -0
- package/dist/gateway.d.ts +51 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +303 -0
- package/dist/gateway.js.map +1 -0
- package/dist/gtr/client.d.ts +39 -0
- package/dist/gtr/client.d.ts.map +1 -0
- package/dist/gtr/client.js +109 -0
- package/dist/gtr/client.js.map +1 -0
- package/dist/gtr/crypto.d.ts +24 -0
- package/dist/gtr/crypto.d.ts.map +1 -0
- package/dist/gtr/crypto.js +111 -0
- package/dist/gtr/crypto.js.map +1 -0
- package/dist/gtr/sodium.d.ts +3 -0
- package/dist/gtr/sodium.d.ts.map +1 -0
- package/dist/gtr/sodium.js +6 -0
- package/dist/gtr/sodium.js.map +1 -0
- package/dist/gtr/types.d.ts +38 -0
- package/dist/gtr/types.d.ts.map +1 -0
- package/dist/gtr/types.js +2 -0
- package/dist/gtr/types.js.map +1 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +24 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/sumsub/appToken.d.ts +11 -0
- package/dist/sumsub/appToken.d.ts.map +1 -0
- package/dist/sumsub/appToken.js +22 -0
- package/dist/sumsub/appToken.js.map +1 -0
- package/dist/sumsub/client.d.ts +22 -0
- package/dist/sumsub/client.d.ts.map +1 -0
- package/dist/sumsub/client.js +37 -0
- package/dist/sumsub/client.js.map +1 -0
- package/dist/sumsub/pgp.d.ts +21 -0
- package/dist/sumsub/pgp.d.ts.map +1 -0
- package/dist/sumsub/pgp.js +77 -0
- package/dist/sumsub/pgp.js.map +1 -0
- package/dist/sumsub/signature.d.ts +30 -0
- package/dist/sumsub/signature.d.ts.map +1 -0
- package/dist/sumsub/signature.js +62 -0
- package/dist/sumsub/signature.js.map +1 -0
- package/package.json +61 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# TypeScript library changelog
|
|
2
|
+
|
|
3
|
+
Releases are git tags of the form `typescript/vX.Y.Z`, published to npm as `@sumsub/gtr-gateway`.
|
|
4
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
|
+
|
|
6
|
+
## 0.1.0 — 2026-10-08
|
|
7
|
+
|
|
8
|
+
Implements [gateway contract 1.0](https://github.com/sumsub/gtr-gateway/blob/main/docs/gateway-contract.md).
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- First release of `@sumsub/gtr-gateway`: `createGateway` with a framework-agnostic `handle`, the
|
|
13
|
+
`GtrClient` and PII envelope, `createSignatureVerifier`, `createPgpDecryptor`, app-token signing and
|
|
14
|
+
the `SumsubClient`. Extracted from the TypeScript example, which now builds on the library.
|
|
15
|
+
- `createNodeHandler` and `createFetchHandler` mount the gateway on Express, NestJS, `http`, Next.js,
|
|
16
|
+
Hono and Deno.
|
|
17
|
+
- Request signatures cover `X-Payload-Timestamp`, and requests or PGP signatures older than five minutes
|
|
18
|
+
are rejected. A second secret key and several PGP keys are accepted during a rotation.
|
|
19
|
+
- `createGateway` accepts plain options for the GTR client, the Sumsub client and the PGP decryptor,
|
|
20
|
+
validates them at start-up and logs errors to the console by default.
|
|
21
|
+
- `openpgp` is an optional peer dependency; GTR and Sumsub calls time out after 15 seconds by default.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sum and Substance Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# GTR gateway — TypeScript library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@sumsub/gtr-gateway` implements the [GTR gateway contract](https://github.com/sumsub/gtr-gateway/blob/main/docs/gateway-contract.md) for Node.js
|
|
4
|
+
22.12+: verification and decryption of the requests Sumsub sends, the GTR API client with its PII
|
|
5
|
+
envelope, and a framework-agnostic request handler that serves the gateway routes. The
|
|
6
|
+
[TypeScript example](https://github.com/sumsub/gtr-gateway/tree/main/examples/typescript) is a complete gateway built on it.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @sumsub/gtr-gateway
|
|
10
|
+
npm install openpgp # only if you enable payload encryption in the dashboard
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The package ships as ES modules with type declarations; CommonJS projects load it with a plain
|
|
14
|
+
`require('@sumsub/gtr-gateway')`. Requests go through `undici` and the PII envelope through
|
|
15
|
+
`libsodium-wrappers`. `openpgp`, licensed LGPL-3.0, is an optional peer dependency loaded only when you
|
|
16
|
+
configure payload encryption, so a gateway without it depends on MIT and ISC packages only.
|
|
17
|
+
|
|
18
|
+
## Configure
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { readFileSync } from 'node:fs'
|
|
22
|
+
import { createGateway, GTR_PRODUCTION_API_URL } from '@sumsub/gtr-gateway'
|
|
23
|
+
|
|
24
|
+
const gateway = await createGateway({
|
|
25
|
+
gtr: {
|
|
26
|
+
apiUrl: GTR_PRODUCTION_API_URL,
|
|
27
|
+
vaspCode,
|
|
28
|
+
accessKey,
|
|
29
|
+
secretKey,
|
|
30
|
+
clientCertificate: readFileSync('secrets/certificate.p12'),
|
|
31
|
+
clientCertificatePassword,
|
|
32
|
+
},
|
|
33
|
+
keyPair: ed25519PrivateKeyBase64,
|
|
34
|
+
sumsubSecretKey,
|
|
35
|
+
sumsub: { apiUrl: 'https://api.sumsub.com', appToken, appSecret },
|
|
36
|
+
pgp: { privateKeys: gatewayPgpPrivateKey, sumsubPublicKey: sumsubPgpPublicKey },
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- `createGateway` refuses to start with an empty secret key or one shorter than 16 characters, and with
|
|
41
|
+
an invalid Ed25519 key, so a missing environment variable cannot switch authentication off.
|
|
42
|
+
- `gtr` takes the client options or your own `GtrApi` implementation. `GTR_PRODUCTION_API_URL` pairs with
|
|
43
|
+
the Sumsub production environment and `GTR_UAT_API_URL` with the Sandbox. Calls time out after
|
|
44
|
+
`DEFAULT_TIMEOUT_MS`, below the 20 seconds Sumsub waits for the gateway; `timeoutMs` overrides it.
|
|
45
|
+
- `keyPair` takes the base64 Ed25519 key from GTR, either the 32-byte seed or the 64-byte libsodium
|
|
46
|
+
secret key, or an `Ed25519KeyPair`.
|
|
47
|
+
- `sumsubSecretKey` is the secret key configured in the Sumsub dashboard. Every request is verified
|
|
48
|
+
against it and its timestamp before anything else happens. During a rotation pass
|
|
49
|
+
`[newKey, previousKey]`; `timestampToleranceSeconds` defaults to five minutes.
|
|
50
|
+
- `sumsub` may be omitted: the inbound callback route is then not served and GTR cannot deliver
|
|
51
|
+
incoming Travel Rule requests. The credentials come from
|
|
52
|
+
_Marketplace → Global Travel Rule → Generate API token_.
|
|
53
|
+
- `pgp` may be omitted while payload encryption is off in the dashboard. Once it is on, requests arrive
|
|
54
|
+
as PGP messages and a gateway without a decryptor answers `422 crypto_failed`. `privateKeys` may hold
|
|
55
|
+
several armored keys, which is how the key pair is rotated without downtime.
|
|
56
|
+
- `routePrefix` defaults to `/tr/gtr`; configure the same URLs in the dashboard.
|
|
57
|
+
- `logger` receives warnings and errors and defaults to the console.
|
|
58
|
+
|
|
59
|
+
Call `gateway.close()` on shutdown to close the GTR connection pool.
|
|
60
|
+
|
|
61
|
+
## Mount
|
|
62
|
+
|
|
63
|
+
The gateway needs the raw request bytes: the signature covers them, so nothing may parse or
|
|
64
|
+
re-serialize the body first. Mount it before body parsers, next to your existing routes or as its own
|
|
65
|
+
service; it holds no state besides the GTR session token. If a parser got there first, the gateway
|
|
66
|
+
answers 500 with a message that says so, and **Test connection** in the dashboard shows it.
|
|
67
|
+
|
|
68
|
+
**Express, NestJS, Connect and `http.createServer`** take `createNodeHandler`, which reads the body
|
|
69
|
+
itself:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
const express = require('express')
|
|
73
|
+
const { createGateway, createNodeHandler } = require('@sumsub/gtr-gateway')
|
|
74
|
+
|
|
75
|
+
async function main() {
|
|
76
|
+
const handler = createNodeHandler(await createGateway(options))
|
|
77
|
+
const app = express()
|
|
78
|
+
app.use('/tr/gtr', handler)
|
|
79
|
+
app.get('/health', handler)
|
|
80
|
+
app.use(express.json())
|
|
81
|
+
app.listen(8080)
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
In NestJS the same two lines go into `main.ts`, before `app.listen()`:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const app = await NestFactory.create(AppModule)
|
|
89
|
+
app.use('/tr/gtr', createNodeHandler(await createGateway(options)))
|
|
90
|
+
await app.listen(8080)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Next.js route handlers, Hono and Deno** take `createFetchHandler`. In Next.js pin the Node.js
|
|
94
|
+
runtime, since the library uses Node APIs:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { createFetchHandler, createGateway } from '@sumsub/gtr-gateway'
|
|
98
|
+
|
|
99
|
+
export const runtime = 'nodejs'
|
|
100
|
+
|
|
101
|
+
const handler = createGateway(options).then(createFetchHandler)
|
|
102
|
+
|
|
103
|
+
export async function POST(request: Request) {
|
|
104
|
+
return (await handler)(request)
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Fastify** parses bodies itself, so register the gateway in its own plugin scope; the raw-body parser
|
|
109
|
+
then applies to the gateway routes only:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
await app.register((scope, _options, done) => {
|
|
113
|
+
scope.removeAllContentTypeParsers()
|
|
114
|
+
scope.addContentTypeParser('*', { parseAs: 'buffer' }, (_request, body, done) => done(null, body))
|
|
115
|
+
scope.all('/*', async (request, reply) => {
|
|
116
|
+
const response = await gateway.handle({
|
|
117
|
+
method: request.method,
|
|
118
|
+
path: request.url.split('?')[0] ?? request.url,
|
|
119
|
+
headers: request.headers,
|
|
120
|
+
body: request.body,
|
|
121
|
+
})
|
|
122
|
+
return reply.code(response.status).headers(response.headers).send(response.body)
|
|
123
|
+
})
|
|
124
|
+
done()
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Anything else follows the same three steps: collect the raw body, pass method, path and headers to
|
|
129
|
+
`gateway.handle`, write back the status, headers and body it returns. TypeScript projects resolve the
|
|
130
|
+
package with `moduleResolution` `nodenext` or `bundler`.
|
|
131
|
+
|
|
132
|
+
## Building blocks
|
|
133
|
+
|
|
134
|
+
If you route requests yourself, the pieces the handler is made of are exported:
|
|
135
|
+
|
|
136
|
+
- `createSignatureVerifier({ secretKeys })` returns a verifier whose `verify(headers, rawBody)` checks
|
|
137
|
+
`X-Payload-Digest` in constant time and the age of `X-Payload-Timestamp`. Verify the raw bytes before
|
|
138
|
+
parsing or decrypting anything.
|
|
139
|
+
- `(await createPgpDecryptor(options)).decrypt(armored)` returns the plaintext of a request sent with
|
|
140
|
+
`X-Encryption: true` and rejects anything not signed by the Sumsub key within the tolerance or larger
|
|
141
|
+
than 1 MiB once decompressed.
|
|
142
|
+
- `encryptPayload` / `decryptPayload` implement the PII envelope between two VASP identities.
|
|
143
|
+
`parseEd25519PrivateKey` accepts the 32-byte seed or the 64-byte libsodium secret key; call
|
|
144
|
+
`initCrypto()` before any of them.
|
|
145
|
+
- `GtrClient` exposes `vaspDetail`, `autoAddressVaspDetection`, `oneStep`, `submitTxId` and
|
|
146
|
+
`endTravelRule`; `GtrApi` is the interface to substitute in tests.
|
|
147
|
+
- `signedSumsubHeaders` produces `X-App-Token`, `X-App-Access-Ts` and `X-App-Access-Sig` for a request
|
|
148
|
+
to Sumsub.
|
|
149
|
+
|
|
150
|
+
Errors extend `GatewayError` with `statusCode` and `code`: `InvalidSignatureError` (401),
|
|
151
|
+
`InvalidRequestError` (400), `PayloadTooLargeError` (413), `CryptoError` (422), `GtrUnreachableError`,
|
|
152
|
+
`GtrLoginError` and `SumsubUnreachableError` (502). `handle` maps them to the status codes of §7 and
|
|
153
|
+
§6.3. Unusable options raise `GatewayConfigurationError` at start-up.
|
|
154
|
+
|
|
155
|
+
## Versioning
|
|
156
|
+
|
|
157
|
+
Releases are git tags of the form `typescript/vX.Y.Z` and are published to npm as
|
|
158
|
+
`@sumsub/gtr-gateway`. Before `1.0.0` the API may change between minor versions: pin a version and read
|
|
159
|
+
[CHANGELOG.md](https://github.com/sumsub/gtr-gateway/blob/main/typescript/CHANGELOG.md) before upgrading. CI runs the tests and `npm audit` on Node.js 22 and 24.
|
|
160
|
+
|
|
161
|
+
## Tests
|
|
162
|
+
|
|
163
|
+
From the repository root, which is an npm workspace:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npm ci
|
|
167
|
+
npm run lint && npm run typecheck && npm test
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The tests run the shared [test vectors](https://github.com/sumsub/gtr-gateway/tree/main/test-vectors): `request-signature.json` for the request
|
|
171
|
+
signature, `crypto-box.json` for the PII envelope and `pgp.json` for request decryption and signature
|
|
172
|
+
checks.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { type Gateway } from './gateway.js';
|
|
3
|
+
/**
|
|
4
|
+
* Serves the gateway from `http.createServer`, Express, NestJS or Connect. It reads the raw body
|
|
5
|
+
* itself; when a body parser already consumed the stream, it uses the bytes that parser left.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createNodeHandler(gateway: Gateway): (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
8
|
+
/** Serves the gateway from a Fetch API runtime: Next.js route handlers, Hono, Bun or Deno. */
|
|
9
|
+
export declare function createFetchHandler(gateway: Gateway): (request: Request) => Promise<Response>;
|
|
10
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAEhE,OAAO,EAAqB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAI9D;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,GACf,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAkBvE;AAED,8FAA8F;AAC9F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAa5F"}
|
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { MAX_REQUEST_BYTES } from './gateway.js';
|
|
2
|
+
/**
|
|
3
|
+
* Serves the gateway from `http.createServer`, Express, NestJS or Connect. It reads the raw body
|
|
4
|
+
* itself; when a body parser already consumed the stream, it uses the bytes that parser left.
|
|
5
|
+
*/
|
|
6
|
+
export function createNodeHandler(gateway) {
|
|
7
|
+
return async (request, response) => {
|
|
8
|
+
try {
|
|
9
|
+
const body = request.readableEnded ? request.body : await readNodeBody(request);
|
|
10
|
+
const url = request.originalUrl ?? request.url ?? '/';
|
|
11
|
+
const result = await gateway.handle({
|
|
12
|
+
method: request.method ?? 'GET',
|
|
13
|
+
path: url.split('?')[0] ?? url,
|
|
14
|
+
headers: request.headers,
|
|
15
|
+
body,
|
|
16
|
+
});
|
|
17
|
+
response.writeHead(result.status, result.headers);
|
|
18
|
+
response.end(result.body);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
response.writeHead(500, { 'content-type': 'application/json; charset=utf-8' });
|
|
22
|
+
response.end(JSON.stringify({ error: 'internal_error', message: 'Internal error' }));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Serves the gateway from a Fetch API runtime: Next.js route handlers, Hono, Bun or Deno. */
|
|
27
|
+
export function createFetchHandler(gateway) {
|
|
28
|
+
return async (request) => {
|
|
29
|
+
const result = await gateway.handle({
|
|
30
|
+
method: request.method,
|
|
31
|
+
path: new URL(request.url).pathname,
|
|
32
|
+
headers: Object.fromEntries(request.headers),
|
|
33
|
+
body: await readFetchBody(request),
|
|
34
|
+
});
|
|
35
|
+
return new Response(result.body === '' ? null : result.body, {
|
|
36
|
+
status: result.status,
|
|
37
|
+
headers: result.headers,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function readNodeBody(request) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const chunks = [];
|
|
44
|
+
let size = 0;
|
|
45
|
+
request.on('data', (chunk) => {
|
|
46
|
+
if (size <= MAX_REQUEST_BYTES) {
|
|
47
|
+
chunks.push(chunk);
|
|
48
|
+
}
|
|
49
|
+
size += chunk.length;
|
|
50
|
+
});
|
|
51
|
+
request.on('end', () => resolve(Buffer.concat(chunks)));
|
|
52
|
+
request.on('error', reject);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function readFetchBody(request) {
|
|
56
|
+
if (!request.body) {
|
|
57
|
+
return Buffer.alloc(0);
|
|
58
|
+
}
|
|
59
|
+
const reader = request.body.getReader();
|
|
60
|
+
const chunks = [];
|
|
61
|
+
let size = 0;
|
|
62
|
+
for (;;) {
|
|
63
|
+
const result = await reader.read();
|
|
64
|
+
if (result.done) {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
const chunk = result.value;
|
|
68
|
+
if (!(chunk instanceof Uint8Array)) {
|
|
69
|
+
throw new TypeError('Request body chunks must be bytes');
|
|
70
|
+
}
|
|
71
|
+
chunks.push(chunk);
|
|
72
|
+
size += chunk.length;
|
|
73
|
+
if (size > MAX_REQUEST_BYTES) {
|
|
74
|
+
await reader.cancel();
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return Buffer.concat(chunks);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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C3C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACxB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAA;IACvC,MAAM,MAAM,GAAiB,EAAE,CAAA;IAC/B,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,SAAS,CAAC;QACR,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAClC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAChB,MAAK;QACP,CAAC;QACD,MAAM,KAAK,GAAY,MAAM,CAAC,KAAK,CAAA;QACnC,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAA;QAC1D,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAClB,IAAI,IAAI,KAAK,CAAC,MAAM,CAAA;QACpB,IAAI,IAAI,GAAG,iBAAiB,EAAE,CAAC;YAC7B,MAAM,MAAM,CAAC,MAAM,EAAE,CAAA;YACrB,MAAK;QACP,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare class GatewayError extends Error {
|
|
2
|
+
readonly statusCode: number;
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(statusCode: number, code: string, message: string, options?: ErrorOptions);
|
|
5
|
+
}
|
|
6
|
+
export declare class InvalidSignatureError extends GatewayError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class InvalidRequestError extends GatewayError {
|
|
10
|
+
constructor(message: string, options?: ErrorOptions);
|
|
11
|
+
}
|
|
12
|
+
export declare class PayloadTooLargeError extends GatewayError {
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
15
|
+
export declare class CryptoError extends GatewayError {
|
|
16
|
+
constructor(message: string, options?: ErrorOptions);
|
|
17
|
+
}
|
|
18
|
+
export declare class GtrUnreachableError extends GatewayError {
|
|
19
|
+
constructor(cause: unknown);
|
|
20
|
+
}
|
|
21
|
+
export declare class GtrLoginError extends GatewayError {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class SumsubUnreachableError extends GatewayError {
|
|
25
|
+
constructor(cause: unknown);
|
|
26
|
+
}
|
|
27
|
+
/** Thrown at start-up when the gateway options cannot work, for example an empty secret key. */
|
|
28
|
+
export declare class GatewayConfigurationError extends Error {
|
|
29
|
+
constructor(message: string, options?: ErrorOptions);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IAEnC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM;gBADZ,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY;CAKzB;AAED,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,OAAO,SAA4C;CAGhE;AAED,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGpD;AAED,qBAAa,oBAAqB,SAAQ,YAAY;;CAIrD;AAED,qBAAa,WAAY,SAAQ,YAAY;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAGpD;AAED,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,KAAK,EAAE,OAAO;CAG3B;AAED,qBAAa,aAAc,SAAQ,YAAY;gBACjC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,sBAAuB,SAAQ,YAAY;gBAC1C,KAAK,EAAE,OAAO;CAG3B;AAED,gGAAgG;AAChG,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class GatewayError extends Error {
|
|
2
|
+
statusCode;
|
|
3
|
+
code;
|
|
4
|
+
constructor(statusCode, code, message, options) {
|
|
5
|
+
super(message, options);
|
|
6
|
+
this.statusCode = statusCode;
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = new.target.name;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class InvalidSignatureError extends GatewayError {
|
|
12
|
+
constructor(message = 'Request signature is missing or invalid') {
|
|
13
|
+
super(401, 'invalid_signature', message);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class InvalidRequestError extends GatewayError {
|
|
17
|
+
constructor(message, options) {
|
|
18
|
+
super(400, 'invalid_request', message, options);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class PayloadTooLargeError extends GatewayError {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(413, 'invalid_request', 'Request body is too large');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class CryptoError extends GatewayError {
|
|
27
|
+
constructor(message, options) {
|
|
28
|
+
super(422, 'crypto_failed', message, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class GtrUnreachableError extends GatewayError {
|
|
32
|
+
constructor(cause) {
|
|
33
|
+
super(502, 'gtr_unreachable', 'GTR API is unreachable', { cause });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class GtrLoginError extends GatewayError {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super(502, 'gtr_login_failed', message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class SumsubUnreachableError extends GatewayError {
|
|
42
|
+
constructor(cause) {
|
|
43
|
+
super(502, 'sumsub_unreachable', 'Sumsub API is unreachable', { cause });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Thrown at start-up when the gateway options cannot work, for example an empty secret key. */
|
|
47
|
+
export class GatewayConfigurationError extends Error {
|
|
48
|
+
constructor(message, options) {
|
|
49
|
+
super(message, options);
|
|
50
|
+
this.name = 'GatewayConfigurationError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAE1B;IACA;IAFX,YACW,UAAkB,EAClB,IAAY,EACrB,OAAe,EACf,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QALd,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAQ;QAKrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACrD,YAAY,OAAO,GAAG,yCAAyC;QAC7D,KAAK,CAAC,GAAG,EAAE,mBAAmB,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACnD,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,GAAG,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IACpD;QACE,KAAK,CAAC,GAAG,EAAE,iBAAiB,EAAE,2BAA2B,CAAC,CAAA;IAC5D,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,YAAY;IAC3C,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC/C,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACnD,YAAY,KAAc;QACxB,KAAK,CAAC,GAAG,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IACpE,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAA;IACzC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,YAAY;IACtD,YAAY,KAAc;QACxB,KAAK,CAAC,GAAG,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1E,CAAC;CACF;AAED,gGAAgG;AAChG,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type GtrClientOptions } from './gtr/client.js';
|
|
2
|
+
import { type Ed25519KeyPair } from './gtr/crypto.js';
|
|
3
|
+
import type { GtrApi } from './gtr/types.js';
|
|
4
|
+
import { type SumsubApi, type SumsubClientOptions } from './sumsub/client.js';
|
|
5
|
+
import { type PgpDecryptor, type PgpDecryptorOptions } from './sumsub/pgp.js';
|
|
6
|
+
export declare const DEFAULT_ROUTE_PREFIX = "/tr/gtr";
|
|
7
|
+
export declare const MAX_REQUEST_BYTES: number;
|
|
8
|
+
export type GatewayHeaders = Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
9
|
+
export interface GatewayRequest {
|
|
10
|
+
readonly method: string;
|
|
11
|
+
/** Path without the query string, e.g. `/tr/gtr/verify/one-step`. */
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly headers: GatewayHeaders;
|
|
14
|
+
/** The raw body as a Buffer, Uint8Array or string: the signature covers these exact bytes. */
|
|
15
|
+
readonly body?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface GatewayResponse {
|
|
18
|
+
readonly status: number;
|
|
19
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
20
|
+
readonly body: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GatewayLogger {
|
|
23
|
+
warn(message: string, details?: unknown): void;
|
|
24
|
+
error(message: string, details?: unknown): void;
|
|
25
|
+
}
|
|
26
|
+
export interface GatewayOptions {
|
|
27
|
+
/** A GTR client, or the options to build one. */
|
|
28
|
+
readonly gtr: GtrApi | GtrClientOptions;
|
|
29
|
+
/** The Ed25519 key registered with GTR: a key pair, or the base64 seed or libsodium secret key. */
|
|
30
|
+
readonly keyPair: Ed25519KeyPair | string;
|
|
31
|
+
/** The dashboard secret key; during a rotation the current key and the previous one. */
|
|
32
|
+
readonly sumsubSecretKey: string | readonly string[];
|
|
33
|
+
readonly timestampToleranceSeconds?: number;
|
|
34
|
+
/** Forwards GTR callbacks; when absent the inbound route is not served. */
|
|
35
|
+
readonly sumsub?: SumsubApi | SumsubClientOptions;
|
|
36
|
+
/** Decrypts requests when payload encryption is enabled in the dashboard (contract §2.1). */
|
|
37
|
+
readonly pgp?: PgpDecryptor | PgpDecryptorOptions;
|
|
38
|
+
readonly routePrefix?: string;
|
|
39
|
+
/** Receives warnings and errors; defaults to the console. */
|
|
40
|
+
readonly logger?: GatewayLogger;
|
|
41
|
+
readonly now?: () => Date;
|
|
42
|
+
}
|
|
43
|
+
export interface Gateway {
|
|
44
|
+
readonly routePrefix: string;
|
|
45
|
+
handle(request: GatewayRequest): Promise<GatewayResponse>;
|
|
46
|
+
/** Closes the GTR connection pool when the gateway created the client itself. */
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/** Validates the options and fails at start-up instead of on the first request. */
|
|
50
|
+
export declare function createGateway(options: GatewayOptions): Promise<Gateway>;
|
|
51
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAQA,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,MAAM,EAAkC,MAAM,gBAAgB,CAAA;AAC5E,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,mBAAmB,EAEzB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAA;AAGxB,eAAO,MAAM,oBAAoB,YAAY,CAAA;AAC7C,eAAO,MAAM,iBAAiB,QAAc,CAAA;AAE5C,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAA;AAE7F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM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