@enbox/dwn-server 0.0.1
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/LICENSE +201 -0
- package/README.md +353 -0
- package/dist/cjs/index.js +6811 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/src/config.d.ts +55 -0
- package/dist/esm/src/config.d.ts.map +1 -0
- package/dist/esm/src/config.js +60 -0
- package/dist/esm/src/config.js.map +1 -0
- package/dist/esm/src/connection/connection-manager.d.ts +25 -0
- package/dist/esm/src/connection/connection-manager.d.ts.map +1 -0
- package/dist/esm/src/connection/connection-manager.js +26 -0
- package/dist/esm/src/connection/connection-manager.js.map +1 -0
- package/dist/esm/src/connection/socket-connection.d.ts +65 -0
- package/dist/esm/src/connection/socket-connection.d.ts.map +1 -0
- package/dist/esm/src/connection/socket-connection.js +180 -0
- package/dist/esm/src/connection/socket-connection.js.map +1 -0
- package/dist/esm/src/dwn-error.d.ts +29 -0
- package/dist/esm/src/dwn-error.d.ts.map +1 -0
- package/dist/esm/src/dwn-error.js +36 -0
- package/dist/esm/src/dwn-error.js.map +1 -0
- package/dist/esm/src/dwn-server.d.ts +60 -0
- package/dist/esm/src/dwn-server.d.ts.map +1 -0
- package/dist/esm/src/dwn-server.js +130 -0
- package/dist/esm/src/dwn-server.js.map +1 -0
- package/dist/esm/src/http-api.d.ts +26 -0
- package/dist/esm/src/http-api.d.ts.map +1 -0
- package/dist/esm/src/http-api.js +474 -0
- package/dist/esm/src/http-api.js.map +1 -0
- package/dist/esm/src/index.d.ts +7 -0
- package/dist/esm/src/index.d.ts.map +1 -0
- package/dist/esm/src/index.js +6 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/json-rpc-api.d.ts +3 -0
- package/dist/esm/src/json-rpc-api.d.ts.map +1 -0
- package/dist/esm/src/json-rpc-api.js +8 -0
- package/dist/esm/src/json-rpc-api.js.map +1 -0
- package/dist/esm/src/json-rpc-handlers/dwn/index.d.ts +2 -0
- package/dist/esm/src/json-rpc-handlers/dwn/index.d.ts.map +1 -0
- package/dist/esm/src/json-rpc-handlers/dwn/index.js +2 -0
- package/dist/esm/src/json-rpc-handlers/dwn/index.js.map +1 -0
- package/dist/esm/src/json-rpc-handlers/dwn/process-message.d.ts +3 -0
- package/dist/esm/src/json-rpc-handlers/dwn/process-message.d.ts.map +1 -0
- package/dist/esm/src/json-rpc-handlers/dwn/process-message.js +73 -0
- package/dist/esm/src/json-rpc-handlers/dwn/process-message.js.map +1 -0
- package/dist/esm/src/json-rpc-handlers/subscription/close.d.ts +10 -0
- package/dist/esm/src/json-rpc-handlers/subscription/close.d.ts.map +1 -0
- package/dist/esm/src/json-rpc-handlers/subscription/close.js +39 -0
- package/dist/esm/src/json-rpc-handlers/subscription/close.js.map +1 -0
- package/dist/esm/src/json-rpc-handlers/subscription/index.d.ts +2 -0
- package/dist/esm/src/json-rpc-handlers/subscription/index.d.ts.map +1 -0
- package/dist/esm/src/json-rpc-handlers/subscription/index.js +2 -0
- package/dist/esm/src/json-rpc-handlers/subscription/index.js.map +1 -0
- package/dist/esm/src/json-rpc-socket.d.ts +39 -0
- package/dist/esm/src/json-rpc-socket.d.ts.map +1 -0
- package/dist/esm/src/json-rpc-socket.js +125 -0
- package/dist/esm/src/json-rpc-socket.js.map +1 -0
- package/dist/esm/src/lib/http-server-shutdown-handler.d.ts +10 -0
- package/dist/esm/src/lib/http-server-shutdown-handler.d.ts.map +1 -0
- package/dist/esm/src/lib/http-server-shutdown-handler.js +65 -0
- package/dist/esm/src/lib/http-server-shutdown-handler.js.map +1 -0
- package/dist/esm/src/lib/json-rpc-router.d.ts +30 -0
- package/dist/esm/src/lib/json-rpc-router.d.ts.map +1 -0
- package/dist/esm/src/lib/json-rpc-router.js +14 -0
- package/dist/esm/src/lib/json-rpc-router.js.map +1 -0
- package/dist/esm/src/lib/json-rpc.d.ts +54 -0
- package/dist/esm/src/lib/json-rpc.d.ts.map +1 -0
- package/dist/esm/src/lib/json-rpc.js +60 -0
- package/dist/esm/src/lib/json-rpc.js.map +1 -0
- package/dist/esm/src/main.d.ts +3 -0
- package/dist/esm/src/main.d.ts.map +1 -0
- package/dist/esm/src/main.js +11 -0
- package/dist/esm/src/main.js.map +1 -0
- package/dist/esm/src/metrics.d.ts +4 -0
- package/dist/esm/src/metrics.d.ts.map +1 -0
- package/dist/esm/src/metrics.js +13 -0
- package/dist/esm/src/metrics.js.map +1 -0
- package/dist/esm/src/plugin-loader.d.ts +10 -0
- package/dist/esm/src/plugin-loader.d.ts.map +1 -0
- package/dist/esm/src/plugin-loader.js +19 -0
- package/dist/esm/src/plugin-loader.js.map +1 -0
- package/dist/esm/src/process-handlers.d.ts +11 -0
- package/dist/esm/src/process-handlers.d.ts.map +1 -0
- package/dist/esm/src/process-handlers.js +40 -0
- package/dist/esm/src/process-handlers.js.map +1 -0
- package/dist/esm/src/registration/proof-of-work-manager.d.ts +93 -0
- package/dist/esm/src/registration/proof-of-work-manager.d.ts.map +1 -0
- package/dist/esm/src/registration/proof-of-work-manager.js +243 -0
- package/dist/esm/src/registration/proof-of-work-manager.js.map +1 -0
- package/dist/esm/src/registration/proof-of-work-types.d.ts +8 -0
- package/dist/esm/src/registration/proof-of-work-types.d.ts.map +1 -0
- package/dist/esm/src/registration/proof-of-work-types.js +2 -0
- package/dist/esm/src/registration/proof-of-work-types.js.map +1 -0
- package/dist/esm/src/registration/proof-of-work.d.ts +41 -0
- package/dist/esm/src/registration/proof-of-work.d.ts.map +1 -0
- package/dist/esm/src/registration/proof-of-work.js +69 -0
- package/dist/esm/src/registration/proof-of-work.js.map +1 -0
- package/dist/esm/src/registration/registration-manager.d.ts +55 -0
- package/dist/esm/src/registration/registration-manager.d.ts.map +1 -0
- package/dist/esm/src/registration/registration-manager.js +121 -0
- package/dist/esm/src/registration/registration-manager.js.map +1 -0
- package/dist/esm/src/registration/registration-store.d.ts +24 -0
- package/dist/esm/src/registration/registration-store.d.ts.map +1 -0
- package/dist/esm/src/registration/registration-store.js +56 -0
- package/dist/esm/src/registration/registration-store.js.map +1 -0
- package/dist/esm/src/registration/registration-types.d.ts +18 -0
- package/dist/esm/src/registration/registration-types.d.ts.map +1 -0
- package/dist/esm/src/registration/registration-types.js +2 -0
- package/dist/esm/src/registration/registration-types.js.map +1 -0
- package/dist/esm/src/storage.d.ts +24 -0
- package/dist/esm/src/storage.d.ts.map +1 -0
- package/dist/esm/src/storage.js +146 -0
- package/dist/esm/src/storage.js.map +1 -0
- package/dist/esm/src/web5-connect/sql-ttl-cache.d.ts +39 -0
- package/dist/esm/src/web5-connect/sql-ttl-cache.d.ts.map +1 -0
- package/dist/esm/src/web5-connect/sql-ttl-cache.js +106 -0
- package/dist/esm/src/web5-connect/sql-ttl-cache.js.map +1 -0
- package/dist/esm/src/web5-connect/web5-connect-server.d.ts +58 -0
- package/dist/esm/src/web5-connect/web5-connect-server.d.ts.map +1 -0
- package/dist/esm/src/web5-connect/web5-connect-server.js +77 -0
- package/dist/esm/src/web5-connect/web5-connect-server.js.map +1 -0
- package/dist/esm/src/ws-api.d.ts +13 -0
- package/dist/esm/src/ws-api.d.ts.map +1 -0
- package/dist/esm/src/ws-api.js +31 -0
- package/dist/esm/src/ws-api.js.map +1 -0
- package/dist/esm/tests/common-scenario-validator.d.ts +11 -0
- package/dist/esm/tests/common-scenario-validator.d.ts.map +1 -0
- package/dist/esm/tests/common-scenario-validator.js +114 -0
- package/dist/esm/tests/common-scenario-validator.js.map +1 -0
- package/dist/esm/tests/connection/connection-manager.spec.d.ts +2 -0
- package/dist/esm/tests/connection/connection-manager.spec.d.ts.map +1 -0
- package/dist/esm/tests/connection/connection-manager.spec.js +47 -0
- package/dist/esm/tests/connection/connection-manager.spec.js.map +1 -0
- package/dist/esm/tests/connection/socket-connection.spec.d.ts +2 -0
- package/dist/esm/tests/connection/socket-connection.spec.d.ts.map +1 -0
- package/dist/esm/tests/connection/socket-connection.spec.js +125 -0
- package/dist/esm/tests/connection/socket-connection.spec.js.map +1 -0
- package/dist/esm/tests/cors/http-api.browser.d.ts +2 -0
- package/dist/esm/tests/cors/http-api.browser.d.ts.map +1 -0
- package/dist/esm/tests/cors/http-api.browser.js +60 -0
- package/dist/esm/tests/cors/http-api.browser.js.map +1 -0
- package/dist/esm/tests/cors/ping.browser.d.ts +2 -0
- package/dist/esm/tests/cors/ping.browser.d.ts.map +1 -0
- package/dist/esm/tests/cors/ping.browser.js +7 -0
- package/dist/esm/tests/cors/ping.browser.js.map +1 -0
- package/dist/esm/tests/dwn-process-message.spec.d.ts +2 -0
- package/dist/esm/tests/dwn-process-message.spec.d.ts.map +1 -0
- package/dist/esm/tests/dwn-process-message.spec.js +172 -0
- package/dist/esm/tests/dwn-process-message.spec.js.map +1 -0
- package/dist/esm/tests/dwn-server.spec.d.ts +2 -0
- package/dist/esm/tests/dwn-server.spec.d.ts.map +1 -0
- package/dist/esm/tests/dwn-server.spec.js +49 -0
- package/dist/esm/tests/dwn-server.spec.js.map +1 -0
- package/dist/esm/tests/http-api.spec.d.ts +2 -0
- package/dist/esm/tests/http-api.spec.d.ts.map +1 -0
- package/dist/esm/tests/http-api.spec.js +775 -0
- package/dist/esm/tests/http-api.spec.js.map +1 -0
- package/dist/esm/tests/json-rpc-socket.spec.d.ts +2 -0
- package/dist/esm/tests/json-rpc-socket.spec.d.ts.map +1 -0
- package/dist/esm/tests/json-rpc-socket.spec.js +225 -0
- package/dist/esm/tests/json-rpc-socket.spec.js.map +1 -0
- package/dist/esm/tests/plugins/data-store-sqlite.d.ts +17 -0
- package/dist/esm/tests/plugins/data-store-sqlite.d.ts.map +1 -0
- package/dist/esm/tests/plugins/data-store-sqlite.js +23 -0
- package/dist/esm/tests/plugins/data-store-sqlite.js.map +1 -0
- package/dist/esm/tests/plugins/event-log-sqlite.d.ts +17 -0
- package/dist/esm/tests/plugins/event-log-sqlite.d.ts.map +1 -0
- package/dist/esm/tests/plugins/event-log-sqlite.js +23 -0
- package/dist/esm/tests/plugins/event-log-sqlite.js.map +1 -0
- package/dist/esm/tests/plugins/event-stream-in-memory.d.ts +17 -0
- package/dist/esm/tests/plugins/event-stream-in-memory.d.ts.map +1 -0
- package/dist/esm/tests/plugins/event-stream-in-memory.js +21 -0
- package/dist/esm/tests/plugins/event-stream-in-memory.js.map +1 -0
- package/dist/esm/tests/plugins/message-store-sqlite.d.ts +17 -0
- package/dist/esm/tests/plugins/message-store-sqlite.d.ts.map +1 -0
- package/dist/esm/tests/plugins/message-store-sqlite.js +23 -0
- package/dist/esm/tests/plugins/message-store-sqlite.js.map +1 -0
- package/dist/esm/tests/plugins/resumable-task-store-sqlite.d.ts +17 -0
- package/dist/esm/tests/plugins/resumable-task-store-sqlite.d.ts.map +1 -0
- package/dist/esm/tests/plugins/resumable-task-store-sqlite.js +23 -0
- package/dist/esm/tests/plugins/resumable-task-store-sqlite.js.map +1 -0
- package/dist/esm/tests/process-handler.spec.d.ts +2 -0
- package/dist/esm/tests/process-handler.spec.d.ts.map +1 -0
- package/dist/esm/tests/process-handler.spec.js +60 -0
- package/dist/esm/tests/process-handler.spec.js.map +1 -0
- package/dist/esm/tests/registration/proof-of-work-manager.spec.d.ts +2 -0
- package/dist/esm/tests/registration/proof-of-work-manager.spec.d.ts.map +1 -0
- package/dist/esm/tests/registration/proof-of-work-manager.spec.js +157 -0
- package/dist/esm/tests/registration/proof-of-work-manager.spec.js.map +1 -0
- package/dist/esm/tests/rpc-subscribe-close.spec.d.ts +2 -0
- package/dist/esm/tests/rpc-subscribe-close.spec.d.ts.map +1 -0
- package/dist/esm/tests/rpc-subscribe-close.spec.js +81 -0
- package/dist/esm/tests/rpc-subscribe-close.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.d.ts +2 -0
- package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.d.ts.map +1 -0
- package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.js +73 -0
- package/dist/esm/tests/scenarios/dynamic-plugin-loading.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/registration.spec.d.ts +2 -0
- package/dist/esm/tests/scenarios/registration.spec.d.ts.map +1 -0
- package/dist/esm/tests/scenarios/registration.spec.js +507 -0
- package/dist/esm/tests/scenarios/registration.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/web5-connect.spec.d.ts +2 -0
- package/dist/esm/tests/scenarios/web5-connect.spec.d.ts.map +1 -0
- package/dist/esm/tests/scenarios/web5-connect.spec.js +137 -0
- package/dist/esm/tests/scenarios/web5-connect.spec.js.map +1 -0
- package/dist/esm/tests/test-dwn.d.ts +7 -0
- package/dist/esm/tests/test-dwn.d.ts.map +1 -0
- package/dist/esm/tests/test-dwn.js +34 -0
- package/dist/esm/tests/test-dwn.js.map +1 -0
- package/dist/esm/tests/utils.d.ts +46 -0
- package/dist/esm/tests/utils.d.ts.map +1 -0
- package/dist/esm/tests/utils.js +116 -0
- package/dist/esm/tests/utils.js.map +1 -0
- package/dist/esm/tests/ws-api.spec.d.ts +2 -0
- package/dist/esm/tests/ws-api.spec.d.ts.map +1 -0
- package/dist/esm/tests/ws-api.spec.js +327 -0
- package/dist/esm/tests/ws-api.spec.js.map +1 -0
- package/package.json +119 -0
- package/src/config.ts +71 -0
- package/src/connection/connection-manager.ts +39 -0
- package/src/connection/socket-connection.ts +221 -0
- package/src/dwn-error.ts +38 -0
- package/src/dwn-server.ts +178 -0
- package/src/http-api.ts +541 -0
- package/src/index.ts +6 -0
- package/src/json-rpc-api.ts +11 -0
- package/src/json-rpc-handlers/dwn/index.ts +1 -0
- package/src/json-rpc-handlers/dwn/process-message.ts +123 -0
- package/src/json-rpc-handlers/subscription/close.ts +59 -0
- package/src/json-rpc-handlers/subscription/index.ts +1 -0
- package/src/json-rpc-socket.ts +155 -0
- package/src/lib/http-server-shutdown-handler.ts +79 -0
- package/src/lib/json-rpc-router.ts +52 -0
- package/src/lib/json-rpc.ts +126 -0
- package/src/main.ts +14 -0
- package/src/metrics.ts +14 -0
- package/src/plugin-loader.ts +17 -0
- package/src/process-handlers.ts +65 -0
- package/src/registration/proof-of-work-manager.ts +317 -0
- package/src/registration/proof-of-work-types.ts +7 -0
- package/src/registration/proof-of-work.ts +100 -0
- package/src/registration/registration-manager.ts +153 -0
- package/src/registration/registration-store.ts +79 -0
- package/src/registration/registration-types.ts +18 -0
- package/src/storage.ts +213 -0
- package/src/web5-connect/sql-ttl-cache.ts +137 -0
- package/src/web5-connect/web5-connect-server.ts +122 -0
- package/src/ws-api.ts +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type DwnServerConfig = typeof config;
|
|
2
|
+
export declare const config: {
|
|
3
|
+
/**
|
|
4
|
+
* Used to populate the `server` property returned by the `/info` endpoint.
|
|
5
|
+
*
|
|
6
|
+
* If running using `npm` the `process.env.npm_package_name` variable exists and we use that,
|
|
7
|
+
* otherwise we fall back on the use defined `DWN_SERVER_PACKAGE_NAME` or `@enbox/dwn-server`.
|
|
8
|
+
*/
|
|
9
|
+
serverName: string;
|
|
10
|
+
/**
|
|
11
|
+
* The base external URL of this DWN.
|
|
12
|
+
* This is used to construct URL paths such as the `Request URI` in the Web5 Connect flow.
|
|
13
|
+
* Should NOT be pointing to `localhost` for production use.
|
|
14
|
+
*/
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
/**
|
|
17
|
+
* Port that server listens on.
|
|
18
|
+
*/
|
|
19
|
+
port: number;
|
|
20
|
+
/**
|
|
21
|
+
* The URL of the TTL cache used by the DWN.
|
|
22
|
+
* NOTE: Used for session/state keeping, thus requires the cache to be commonly addressable by nodes in a cloud cluster environment.
|
|
23
|
+
*
|
|
24
|
+
* Currently only supports SQL databases, e.g.
|
|
25
|
+
* Postgres: 'postgres://root:dwn@localhost:5432/dwn'
|
|
26
|
+
* MySQL: 'mysql://root:dwn@localhost:3306/dwn'
|
|
27
|
+
*/
|
|
28
|
+
ttlCacheUrl: string;
|
|
29
|
+
/**
|
|
30
|
+
* Used to populate the `version` and `sdkVersion` properties returned by the `/info` endpoint.
|
|
31
|
+
*
|
|
32
|
+
* The `version` and `sdkVersion` are pulled from `package.json` at runtime.
|
|
33
|
+
* If running using `npm` the `process.env.npm_package_json` variable exists as the filepath, so we use that.
|
|
34
|
+
* Otherwise we check to see if a specific `DWN_SERVER_PACKAGE_JSON` exists, if it does we use that.
|
|
35
|
+
* Finally if both of those options don't exist we resort to the path within the docker server image, located at `/dwn-server/package.json`
|
|
36
|
+
*/
|
|
37
|
+
packageJsonPath: string;
|
|
38
|
+
maxRecordDataSize: number;
|
|
39
|
+
webSocketSupport: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Path to DWN Event Stream plugin to use. Default single-node implementation will be used if left empty.
|
|
42
|
+
*/
|
|
43
|
+
eventStreamPluginPath: string;
|
|
44
|
+
messageStore: string;
|
|
45
|
+
dataStore: string;
|
|
46
|
+
eventLog: string;
|
|
47
|
+
resumableTaskStore: string;
|
|
48
|
+
registrationStoreUrl: string;
|
|
49
|
+
registrationProofOfWorkSeed: string;
|
|
50
|
+
registrationProofOfWorkEnabled: boolean;
|
|
51
|
+
registrationProofOfWorkInitialMaxHash: string;
|
|
52
|
+
termsOfServiceFilePath: string;
|
|
53
|
+
logLevel: string;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG,OAAO,MAAM,CAAC;AAE5C,eAAO,MAAM,MAAM;IACjB;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;OAEG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;;;IAQH;;OAEG;;;;;;;;;;;;CAkBJ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import bytes from 'bytes';
|
|
2
|
+
export const config = {
|
|
3
|
+
/**
|
|
4
|
+
* Used to populate the `server` property returned by the `/info` endpoint.
|
|
5
|
+
*
|
|
6
|
+
* If running using `npm` the `process.env.npm_package_name` variable exists and we use that,
|
|
7
|
+
* otherwise we fall back on the use defined `DWN_SERVER_PACKAGE_NAME` or `@enbox/dwn-server`.
|
|
8
|
+
*/
|
|
9
|
+
serverName: process.env.npm_package_name || process.env.DWN_SERVER_PACKAGE_NAME || '@enbox/dwn-server',
|
|
10
|
+
/**
|
|
11
|
+
* The base external URL of this DWN.
|
|
12
|
+
* This is used to construct URL paths such as the `Request URI` in the Web5 Connect flow.
|
|
13
|
+
* Should NOT be pointing to `localhost` for production use.
|
|
14
|
+
*/
|
|
15
|
+
baseUrl: process.env.DWN_BASE_URL || 'http://localhost:3000',
|
|
16
|
+
/**
|
|
17
|
+
* Port that server listens on.
|
|
18
|
+
*/
|
|
19
|
+
port: parseInt(process.env.DS_PORT || '3000'),
|
|
20
|
+
/**
|
|
21
|
+
* The URL of the TTL cache used by the DWN.
|
|
22
|
+
* NOTE: Used for session/state keeping, thus requires the cache to be commonly addressable by nodes in a cloud cluster environment.
|
|
23
|
+
*
|
|
24
|
+
* Currently only supports SQL databases, e.g.
|
|
25
|
+
* Postgres: 'postgres://root:dwn@localhost:5432/dwn'
|
|
26
|
+
* MySQL: 'mysql://root:dwn@localhost:3306/dwn'
|
|
27
|
+
*/
|
|
28
|
+
ttlCacheUrl: process.env.DWN_TTL_CACHE_URL || 'sqlite://',
|
|
29
|
+
/**
|
|
30
|
+
* Used to populate the `version` and `sdkVersion` properties returned by the `/info` endpoint.
|
|
31
|
+
*
|
|
32
|
+
* The `version` and `sdkVersion` are pulled from `package.json` at runtime.
|
|
33
|
+
* If running using `npm` the `process.env.npm_package_json` variable exists as the filepath, so we use that.
|
|
34
|
+
* Otherwise we check to see if a specific `DWN_SERVER_PACKAGE_JSON` exists, if it does we use that.
|
|
35
|
+
* Finally if both of those options don't exist we resort to the path within the docker server image, located at `/dwn-server/package.json`
|
|
36
|
+
*/
|
|
37
|
+
packageJsonPath: process.env.npm_package_json || process.env.DWN_SERVER_PACKAGE_JSON || '/dwn-server/package.json',
|
|
38
|
+
// max size of data that can be provided with a RecordsWrite
|
|
39
|
+
maxRecordDataSize: bytes(process.env.MAX_RECORD_DATA_SIZE || '1gb'),
|
|
40
|
+
// whether to enable 'ws:'
|
|
41
|
+
webSocketSupport: { on: true, off: false }[process.env.DS_WEBSOCKET_SERVER] ?? true,
|
|
42
|
+
/**
|
|
43
|
+
* Path to DWN Event Stream plugin to use. Default single-node implementation will be used if left empty.
|
|
44
|
+
*/
|
|
45
|
+
eventStreamPluginPath: process.env.DWN_EVENT_STREAM_PLUGIN_PATH,
|
|
46
|
+
// where to store persistent data
|
|
47
|
+
messageStore: process.env.DWN_STORAGE_MESSAGES || process.env.DWN_STORAGE || 'level://data',
|
|
48
|
+
dataStore: process.env.DWN_STORAGE_DATA || process.env.DWN_STORAGE || 'level://data',
|
|
49
|
+
eventLog: process.env.DWN_STORAGE_EVENTS || process.env.DWN_STORAGE || 'level://data',
|
|
50
|
+
resumableTaskStore: process.env.DWN_STORAGE_RESUMABLE_TASKS || process.env.DWN_STORAGE || 'level://data',
|
|
51
|
+
// tenant registration feature configuration
|
|
52
|
+
registrationStoreUrl: process.env.DWN_REGISTRATION_STORE_URL || process.env.DWN_STORAGE,
|
|
53
|
+
registrationProofOfWorkSeed: process.env.DWN_REGISTRATION_PROOF_OF_WORK_SEED,
|
|
54
|
+
registrationProofOfWorkEnabled: process.env.DWN_REGISTRATION_PROOF_OF_WORK_ENABLED === 'true',
|
|
55
|
+
registrationProofOfWorkInitialMaxHash: process.env.DWN_REGISTRATION_PROOF_OF_WORK_INITIAL_MAX_HASH,
|
|
56
|
+
termsOfServiceFilePath: process.env.DWN_TERMS_OF_SERVICE_FILE_PATH,
|
|
57
|
+
// log level - trace/debug/info/warn/error
|
|
58
|
+
logLevel: process.env.DWN_SERVER_LOG_LEVEL || 'INFO',
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=config.js.map
|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kBAAkB,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,cAAc;IACrF,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,cAAc;IAExG,4CAA4C;IAC5C,oBAAoB,EAAE,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW;IACvF,2BAA2B,EAAE,OAAO,CAAC,GAAG,CAAC,mCAAmC;IAC5E,8BAA8B,EAAE,OAAO,CAAC,GAAG,CAAC,sCAAsC,KAAK,MAAM;IAC7F,qCAAqC,EAAE,OAAO,CAAC,GAAG,CAAC,+CAA+C;IAClG,sBAAsB,EAAE,OAAO,CAAC,GAAG,CAAC,8BAA8B;IAElE,0CAA0C;IAC1C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,MAAM;CACrD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Dwn } from "@enbox/dwn-sdk-js";
|
|
2
|
+
import type { IncomingMessage } from "http";
|
|
3
|
+
import type { WebSocket } from 'ws';
|
|
4
|
+
import { SocketConnection } from "./socket-connection.js";
|
|
5
|
+
/**
|
|
6
|
+
* Interface for managing `WebSocket` connections as they arrive.
|
|
7
|
+
*/
|
|
8
|
+
export interface ConnectionManager {
|
|
9
|
+
/** connect handler used for the `WebSockets` `'connection'` event. */
|
|
10
|
+
connect(socket: WebSocket, request?: IncomingMessage): Promise<void>;
|
|
11
|
+
/** closes all of the connections */
|
|
12
|
+
closeAll(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A Simple In Memory ConnectionManager implementation.
|
|
16
|
+
* It uses a `Map<WebSocket, SocketConnection>` to manage connections.
|
|
17
|
+
*/
|
|
18
|
+
export declare class InMemoryConnectionManager implements ConnectionManager {
|
|
19
|
+
private dwn;
|
|
20
|
+
private connections;
|
|
21
|
+
constructor(dwn: Dwn, connections?: Map<WebSocket, SocketConnection>);
|
|
22
|
+
connect(socket: WebSocket): Promise<void>;
|
|
23
|
+
closeAll(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=connection-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../../../src/connection/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,oCAAoC;IACpC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAED;;;GAGG;AACH,qBAAa,yBAA0B,YAAW,iBAAiB;IACrD,OAAO,CAAC,GAAG;IAAO,OAAO,CAAC,WAAW;gBAA7B,GAAG,EAAE,GAAG,EAAU,WAAW,GAAE,GAAG,CAAC,SAAS,EAAE,gBAAgB,CAAa;IAEzF,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IASzC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAKhC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SocketConnection } from "./socket-connection.js";
|
|
2
|
+
/**
|
|
3
|
+
* A Simple In Memory ConnectionManager implementation.
|
|
4
|
+
* It uses a `Map<WebSocket, SocketConnection>` to manage connections.
|
|
5
|
+
*/
|
|
6
|
+
export class InMemoryConnectionManager {
|
|
7
|
+
dwn;
|
|
8
|
+
connections;
|
|
9
|
+
constructor(dwn, connections = new Map()) {
|
|
10
|
+
this.dwn = dwn;
|
|
11
|
+
this.connections = connections;
|
|
12
|
+
}
|
|
13
|
+
async connect(socket) {
|
|
14
|
+
const connection = new SocketConnection(socket, this.dwn, () => {
|
|
15
|
+
// this is the onClose handler to clean up any closed connections.
|
|
16
|
+
this.connections.delete(socket);
|
|
17
|
+
});
|
|
18
|
+
this.connections.set(socket, connection);
|
|
19
|
+
}
|
|
20
|
+
async closeAll() {
|
|
21
|
+
const closePromises = [];
|
|
22
|
+
this.connections.forEach(connection => closePromises.push(connection.close()));
|
|
23
|
+
await Promise.all(closePromises);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=connection-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../../../src/connection/connection-manager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAY1D;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IAChB;IAAkB;IAAtC,YAAoB,GAAQ,EAAU,cAAgD,IAAI,GAAG,EAAE;QAA3E,QAAG,GAAH,GAAG,CAAK;QAAU,gBAAW,GAAX,WAAW,CAA8C;IAAG,CAAC;IAEnG,KAAK,CAAC,OAAO,CAAC,MAAiB;QAC7B,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE;YAC7D,kEAAkE;YAClE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,aAAa,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/E,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Dwn } from "@enbox/dwn-sdk-js";
|
|
2
|
+
import type { WebSocket } from "ws";
|
|
3
|
+
import type { JsonRpcId, JsonRpcSubscription } from "../lib/json-rpc.js";
|
|
4
|
+
/**
|
|
5
|
+
* SocketConnection handles a WebSocket connection to a DWN using JSON RPC.
|
|
6
|
+
* It also manages references to the long running RPC subscriptions for the connection.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SocketConnection {
|
|
9
|
+
private socket;
|
|
10
|
+
private dwn;
|
|
11
|
+
private onClose?;
|
|
12
|
+
private heartbeatInterval;
|
|
13
|
+
private subscriptions;
|
|
14
|
+
private isAlive;
|
|
15
|
+
constructor(socket: WebSocket, dwn: Dwn, onClose?: () => void);
|
|
16
|
+
/**
|
|
17
|
+
* Checks to see if the incoming `JsonRpcId` is already in use for a subscription.
|
|
18
|
+
*/
|
|
19
|
+
hasSubscription(id: JsonRpcId): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Adds a reference for the JSON RPC Subscription to this connection.
|
|
22
|
+
* Used for cleanup if the connection is closed.
|
|
23
|
+
*/
|
|
24
|
+
addSubscription(subscription: JsonRpcSubscription): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Closes and removes the reference for a given subscription from this connection.
|
|
27
|
+
*
|
|
28
|
+
* @param id the `JsonRpcId` of the JSON RPC subscription request.
|
|
29
|
+
*/
|
|
30
|
+
closeSubscription(id: JsonRpcId): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Closes the existing connection and cleans up any listeners or subscriptions.
|
|
33
|
+
*/
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Pong messages are automatically sent in response to ping messages as required by
|
|
37
|
+
* the websocket spec. So, no need to send explicit pongs.
|
|
38
|
+
*/
|
|
39
|
+
private pong;
|
|
40
|
+
/**
|
|
41
|
+
* Log the error and close the connection.
|
|
42
|
+
*/
|
|
43
|
+
private error;
|
|
44
|
+
/**
|
|
45
|
+
* Handles a `JSON RPC 2.0` encoded message.
|
|
46
|
+
*/
|
|
47
|
+
private message;
|
|
48
|
+
/**
|
|
49
|
+
* Sends a JSON encoded Buffer through the Websocket.
|
|
50
|
+
*/
|
|
51
|
+
private send;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a subscription handler to send messages matching the subscription requested.
|
|
54
|
+
*
|
|
55
|
+
* Wraps the incoming `message` in a `JSON RPC Success Response` using the original subscription`JSON RPC Id` to send through the WebSocket.
|
|
56
|
+
*/
|
|
57
|
+
private createSubscriptionHandler;
|
|
58
|
+
/**
|
|
59
|
+
* Builds a `RequestContext` object to use with the `JSON RPC API`.
|
|
60
|
+
*
|
|
61
|
+
* Adds a `subscriptionHandler` for `Subscribe` messages.
|
|
62
|
+
*/
|
|
63
|
+
private buildRequestContext;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=socket-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-connection.d.ts","sourceRoot":"","sources":["../../../../src/connection/socket-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAgC,MAAM,mBAAmB,CAAC;AAG3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAKpC,OAAO,KAAK,EAAwB,SAAS,EAAmC,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAShI;;;GAGG;AACH,qBAAa,gBAAgB;IAMzB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,OAAO,CAAC;IAPlB,OAAO,CAAC,iBAAiB,CAAe;IACxC,OAAO,CAAC,aAAa,CAAkD;IACvE,OAAO,CAAC,OAAO,CAAU;gBAGf,MAAM,EAAE,SAAS,EACjB,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE,MAAM,IAAI;IAsB9B;;OAEG;IACH,eAAe,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO;IAIvC;;;OAGG;IACG,eAAe,CAAC,YAAY,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvE;;;;OAIG;IACG,iBAAiB,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAarD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAwB5B;;;OAGG;IACH,OAAO,CAAC,IAAI;IAIZ;;OAEG;YACW,KAAK;IAMnB;;OAEG;YACW,OAAO;IAmCrB;;OAEG;IACH,OAAO,CAAC,IAAI;IAIZ;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;IAOjC;;;;OAIG;YACW,mBAAmB;CAuBlC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { DwnMethodName } from "@enbox/dwn-sdk-js";
|
|
2
|
+
import log from 'loglevel';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { requestCounter } from "../metrics.js";
|
|
5
|
+
import { jsonRpcRouter } from "../json-rpc-api.js";
|
|
6
|
+
import { JsonRpcErrorCodes, createJsonRpcErrorResponse, createJsonRpcSuccessResponse } from "../lib/json-rpc.js";
|
|
7
|
+
import { DwnServerError, DwnServerErrorCode } from "../dwn-error.js";
|
|
8
|
+
const HEARTBEAT_INTERVAL = 30_000;
|
|
9
|
+
/**
|
|
10
|
+
* SocketConnection handles a WebSocket connection to a DWN using JSON RPC.
|
|
11
|
+
* It also manages references to the long running RPC subscriptions for the connection.
|
|
12
|
+
*/
|
|
13
|
+
export class SocketConnection {
|
|
14
|
+
socket;
|
|
15
|
+
dwn;
|
|
16
|
+
onClose;
|
|
17
|
+
heartbeatInterval;
|
|
18
|
+
subscriptions = new Map();
|
|
19
|
+
isAlive;
|
|
20
|
+
constructor(socket, dwn, onClose) {
|
|
21
|
+
this.socket = socket;
|
|
22
|
+
this.dwn = dwn;
|
|
23
|
+
this.onClose = onClose;
|
|
24
|
+
socket.on('message', this.message.bind(this));
|
|
25
|
+
socket.on('close', this.close.bind(this));
|
|
26
|
+
socket.on('error', this.error.bind(this));
|
|
27
|
+
socket.on('pong', this.pong.bind(this));
|
|
28
|
+
// Sometimes connections between client <-> server can get borked in such a way that
|
|
29
|
+
// leaves both unaware of the borkage. ping messages can be used as a means to verify
|
|
30
|
+
// that the remote endpoint is still responsive. Server will ping each socket every 30s
|
|
31
|
+
// if a pong hasn't received from a socket by the next ping, the server will terminate
|
|
32
|
+
// the socket connection
|
|
33
|
+
this.isAlive = true;
|
|
34
|
+
this.heartbeatInterval = setInterval(() => {
|
|
35
|
+
if (this.isAlive === false) {
|
|
36
|
+
this.close();
|
|
37
|
+
}
|
|
38
|
+
this.isAlive = false;
|
|
39
|
+
this.socket.ping();
|
|
40
|
+
}, HEARTBEAT_INTERVAL);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks to see if the incoming `JsonRpcId` is already in use for a subscription.
|
|
44
|
+
*/
|
|
45
|
+
hasSubscription(id) {
|
|
46
|
+
return this.subscriptions.has(id);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Adds a reference for the JSON RPC Subscription to this connection.
|
|
50
|
+
* Used for cleanup if the connection is closed.
|
|
51
|
+
*/
|
|
52
|
+
async addSubscription(subscription) {
|
|
53
|
+
if (this.subscriptions.has(subscription.id)) {
|
|
54
|
+
throw new DwnServerError(DwnServerErrorCode.ConnectionSubscriptionJsonRpcIdExists, `the subscription with id ${subscription.id} already exists`);
|
|
55
|
+
}
|
|
56
|
+
this.subscriptions.set(subscription.id, subscription);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Closes and removes the reference for a given subscription from this connection.
|
|
60
|
+
*
|
|
61
|
+
* @param id the `JsonRpcId` of the JSON RPC subscription request.
|
|
62
|
+
*/
|
|
63
|
+
async closeSubscription(id) {
|
|
64
|
+
if (!this.subscriptions.has(id)) {
|
|
65
|
+
throw new DwnServerError(DwnServerErrorCode.ConnectionSubscriptionJsonRpcIdNotFound, `the subscription with id ${id} was not found`);
|
|
66
|
+
}
|
|
67
|
+
const connection = this.subscriptions.get(id);
|
|
68
|
+
await connection.close();
|
|
69
|
+
this.subscriptions.delete(id);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Closes the existing connection and cleans up any listeners or subscriptions.
|
|
73
|
+
*/
|
|
74
|
+
async close() {
|
|
75
|
+
clearInterval(this.heartbeatInterval);
|
|
76
|
+
// clean up all socket event listeners
|
|
77
|
+
this.socket.removeAllListeners();
|
|
78
|
+
const closePromises = [];
|
|
79
|
+
for (const [id, subscription] of this.subscriptions) {
|
|
80
|
+
closePromises.push(subscription.close());
|
|
81
|
+
this.subscriptions.delete(id);
|
|
82
|
+
}
|
|
83
|
+
// close all of the associated subscriptions
|
|
84
|
+
await Promise.all(closePromises);
|
|
85
|
+
// close the socket.
|
|
86
|
+
this.socket.close();
|
|
87
|
+
// if there was a close handler passed call it after the connection has been closed
|
|
88
|
+
if (this.onClose !== undefined) {
|
|
89
|
+
this.onClose();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Pong messages are automatically sent in response to ping messages as required by
|
|
94
|
+
* the websocket spec. So, no need to send explicit pongs.
|
|
95
|
+
*/
|
|
96
|
+
pong() {
|
|
97
|
+
this.isAlive = true;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Log the error and close the connection.
|
|
101
|
+
*/
|
|
102
|
+
async error(error) {
|
|
103
|
+
log.error(`SocketConnection error, terminating connection`, error);
|
|
104
|
+
this.socket.terminate();
|
|
105
|
+
await this.close();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Handles a `JSON RPC 2.0` encoded message.
|
|
109
|
+
*/
|
|
110
|
+
async message(dataBuffer) {
|
|
111
|
+
const requestData = dataBuffer.toString();
|
|
112
|
+
if (!requestData) {
|
|
113
|
+
return this.send(createJsonRpcErrorResponse(uuidv4(), JsonRpcErrorCodes.BadRequest, 'request payload required.'));
|
|
114
|
+
}
|
|
115
|
+
let jsonRequest;
|
|
116
|
+
try {
|
|
117
|
+
jsonRequest = JSON.parse(requestData);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const errorResponse = createJsonRpcErrorResponse(uuidv4(), JsonRpcErrorCodes.BadRequest, error.message);
|
|
121
|
+
return this.send(errorResponse);
|
|
122
|
+
}
|
|
123
|
+
;
|
|
124
|
+
const requestContext = await this.buildRequestContext(jsonRequest);
|
|
125
|
+
const { jsonRpcResponse } = await jsonRpcRouter.handle(jsonRequest, requestContext);
|
|
126
|
+
if (jsonRpcResponse.error) {
|
|
127
|
+
requestCounter.inc({ method: jsonRequest.method, error: 1 });
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
requestCounter.inc({
|
|
131
|
+
method: jsonRequest.method,
|
|
132
|
+
status: jsonRpcResponse?.result?.reply?.status?.code || 0,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
this.send(jsonRpcResponse);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Sends a JSON encoded Buffer through the Websocket.
|
|
139
|
+
*/
|
|
140
|
+
send(response) {
|
|
141
|
+
this.socket.send(JSON.stringify(response));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Creates a subscription handler to send messages matching the subscription requested.
|
|
145
|
+
*
|
|
146
|
+
* Wraps the incoming `message` in a `JSON RPC Success Response` using the original subscription`JSON RPC Id` to send through the WebSocket.
|
|
147
|
+
*/
|
|
148
|
+
createSubscriptionHandler(id) {
|
|
149
|
+
return (event) => {
|
|
150
|
+
const response = createJsonRpcSuccessResponse(id, { event });
|
|
151
|
+
this.send(response);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Builds a `RequestContext` object to use with the `JSON RPC API`.
|
|
156
|
+
*
|
|
157
|
+
* Adds a `subscriptionHandler` for `Subscribe` messages.
|
|
158
|
+
*/
|
|
159
|
+
async buildRequestContext(request) {
|
|
160
|
+
const { params, method, subscription } = request;
|
|
161
|
+
const requestContext = {
|
|
162
|
+
transport: 'ws',
|
|
163
|
+
dwn: this.dwn,
|
|
164
|
+
socketConnection: this,
|
|
165
|
+
};
|
|
166
|
+
// methods that expect a long-running subscription begin with `rpc.subscribe.`
|
|
167
|
+
if (method.startsWith('rpc.subscribe.') && subscription) {
|
|
168
|
+
const { message } = params;
|
|
169
|
+
if (message?.descriptor.method === DwnMethodName.Subscribe) {
|
|
170
|
+
const handlerFunc = this.createSubscriptionHandler(subscription.id);
|
|
171
|
+
requestContext.subscriptionRequest = {
|
|
172
|
+
id: subscription.id,
|
|
173
|
+
subscriptionHandler: (message) => handlerFunc(message),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return requestContext;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=socket-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-connection.js","sourceRoot":"","sources":["../../../../src/connection/socket-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAKpC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,cAAc,EAAE,kBAAk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AY,EAAE,CAAC;YACxD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAsC,CAAC;YAC3D,IAAI,OAAO,EAAE,UAAU,CAAC,MAAM,KAAK,aAAa,CAAC,SAAS,EAAE,CAAC;gBAC3D,MAAM,WAAW,GAAG,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;gBACpE,cAAc,CAAC,mBAAmB,GAAG;oBACnC,EAAE,EAAE,YAAY,CAAC,EAAE;oBACnB,mBAAmB,EAAE,CAAC,OAAO,EAAQ,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC;iBAC7D,CAAA;YACH,CAAC;QACH,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that represents a DWN Server error.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DwnServerError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
constructor(code: string, message: string);
|
|
7
|
+
/**
|
|
8
|
+
* Called by `JSON.stringify(...)` automatically.
|
|
9
|
+
*/
|
|
10
|
+
toJSON(): {
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* DWN Server error codes.
|
|
17
|
+
*/
|
|
18
|
+
export declare enum DwnServerErrorCode {
|
|
19
|
+
ConnectionSubscriptionJsonRpcIdExists = "ConnectionSubscriptionJsonRpcIdExists",
|
|
20
|
+
ConnectionSubscriptionJsonRpcIdNotFound = "ConnectionSubscriptionJsonRpcIdNotFound",
|
|
21
|
+
ProofOfWorkInsufficientSolutionNonce = "ProofOfWorkInsufficientSolutionNonce",
|
|
22
|
+
ProofOfWorkInvalidOrExpiredChallenge = "ProofOfWorkInvalidOrExpiredChallenge",
|
|
23
|
+
ProofOfWorkManagerInvalidChallengeNonce = "ProofOfWorkManagerInvalidChallengeNonce",
|
|
24
|
+
ProofOfWorkManagerInvalidResponseNonceFormat = "ProofOfWorkManagerInvalidResponseNonceFormat",
|
|
25
|
+
ProofOfWorkManagerResponseNonceReused = "ProofOfWorkManagerResponseNonceReused",
|
|
26
|
+
RegistrationManagerInvalidOrOutdatedTermsOfServiceHash = "RegistrationManagerInvalidOrOutdatedTermsOfServiceHash",
|
|
27
|
+
TenantRegistrationOutdatedTermsOfService = "TenantRegistrationOutdatedTermsOfService"
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=dwn-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dwn-error.d.ts","sourceRoot":"","sources":["../../../src/dwn-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAE9B,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM;IAOjB;;OAEG;IACI,MAAM,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;CAMnD;AAED;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,qCAAqC,0CAA0C;IAC/E,uCAAuC,4CAA4C;IACnF,oCAAoC,yCAAyC;IAC7E,oCAAoC,yCAAyC;IAC7E,uCAAuC,4CAA4C;IACnF,4CAA4C,iDAAiD;IAC7F,qCAAqC,0CAA0C;IAC/E,sDAAsD,2DAA2D;IACjH,wCAAwC,6CAA6C;CACtF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that represents a DWN Server error.
|
|
3
|
+
*/
|
|
4
|
+
export class DwnServerError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message) {
|
|
7
|
+
super(`${code}: ${message}`);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.name = 'DwnServerError';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Called by `JSON.stringify(...)` automatically.
|
|
13
|
+
*/
|
|
14
|
+
toJSON() {
|
|
15
|
+
return {
|
|
16
|
+
code: this.code,
|
|
17
|
+
message: this.message,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* DWN Server error codes.
|
|
23
|
+
*/
|
|
24
|
+
export var DwnServerErrorCode;
|
|
25
|
+
(function (DwnServerErrorCode) {
|
|
26
|
+
DwnServerErrorCode["ConnectionSubscriptionJsonRpcIdExists"] = "ConnectionSubscriptionJsonRpcIdExists";
|
|
27
|
+
DwnServerErrorCode["ConnectionSubscriptionJsonRpcIdNotFound"] = "ConnectionSubscriptionJsonRpcIdNotFound";
|
|
28
|
+
DwnServerErrorCode["ProofOfWorkInsufficientSolutionNonce"] = "ProofOfWorkInsufficientSolutionNonce";
|
|
29
|
+
DwnServerErrorCode["ProofOfWorkInvalidOrExpiredChallenge"] = "ProofOfWorkInvalidOrExpiredChallenge";
|
|
30
|
+
DwnServerErrorCode["ProofOfWorkManagerInvalidChallengeNonce"] = "ProofOfWorkManagerInvalidChallengeNonce";
|
|
31
|
+
DwnServerErrorCode["ProofOfWorkManagerInvalidResponseNonceFormat"] = "ProofOfWorkManagerInvalidResponseNonceFormat";
|
|
32
|
+
DwnServerErrorCode["ProofOfWorkManagerResponseNonceReused"] = "ProofOfWorkManagerResponseNonceReused";
|
|
33
|
+
DwnServerErrorCode["RegistrationManagerInvalidOrOutdatedTermsOfServiceHash"] = "RegistrationManagerInvalidOrOutdatedTermsOfServiceHash";
|
|
34
|
+
DwnServerErrorCode["TenantRegistrationOutdatedTermsOfService"] = "TenantRegistrationOutdatedTermsOfService";
|
|
35
|
+
})(DwnServerErrorCode || (DwnServerErrorCode = {}));
|
|
36
|
+
//# sourceMappingURL=dwn-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dwn-error.js","sourceRoot":"","sources":["../../../src/dwn-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAE9B;IADT,YACS,IAAY,EACnB,OAAe;QAEf,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAHtB,SAAI,GAAJ,IAAI,CAAQ;QAKnB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,MAAM;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC5B,qGAA+E,CAAA;IAC/E,yGAAmF,CAAA;IACnF,mGAA6E,CAAA;IAC7E,mGAA6E,CAAA;IAC7E,yGAAmF,CAAA;IACnF,mHAA6F,CAAA;IAC7F,qGAA+E,CAAA;IAC/E,uIAAiH,CAAA;IACjH,2GAAqF,CAAA;AACvF,CAAC,EAVW,kBAAkB,KAAlB,kBAAkB,QAU7B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { DidResolver } from '@enbox/dids';
|
|
2
|
+
import type { ProcessHandlers } from './process-handlers.js';
|
|
3
|
+
import type { Server } from 'http';
|
|
4
|
+
import type { WebSocketServer } from 'ws';
|
|
5
|
+
import type { DwnServerConfig } from './config.js';
|
|
6
|
+
import { RegistrationManager } from './registration/registration-manager.js';
|
|
7
|
+
import { Dwn } from '@enbox/dwn-sdk-js';
|
|
8
|
+
/**
|
|
9
|
+
* Options for the DwnServer constructor.
|
|
10
|
+
* This is different to DwnServerConfig in that the DwnServerConfig defines configuration that come from environment variables so (more) user facing.
|
|
11
|
+
* Where as DwnServerOptions wraps DwnServerConfig with additional overrides that can be used for testing.
|
|
12
|
+
*/
|
|
13
|
+
export type DwnServerOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* A custom DID resolver to use in the DWN.
|
|
16
|
+
* Mainly for testing purposes. Ignored if `dwn` is provided.
|
|
17
|
+
*/
|
|
18
|
+
didResolver?: DidResolver;
|
|
19
|
+
dwn?: Dwn;
|
|
20
|
+
config?: DwnServerConfig;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* State of the DwnServer, either Stopped or Started, to help short-circuit start and stop logic.
|
|
24
|
+
*/
|
|
25
|
+
declare enum DwnServerState {
|
|
26
|
+
Stopped = 0,
|
|
27
|
+
Started = 1
|
|
28
|
+
}
|
|
29
|
+
export declare class DwnServer {
|
|
30
|
+
#private;
|
|
31
|
+
serverState: DwnServerState;
|
|
32
|
+
processHandlers: ProcessHandlers;
|
|
33
|
+
/**
|
|
34
|
+
* A custom DID resolver to use in the DWN.
|
|
35
|
+
* Mainly for testing purposes. Ignored if `dwn` is provided.
|
|
36
|
+
*/
|
|
37
|
+
didResolver?: DidResolver;
|
|
38
|
+
dwn?: Dwn;
|
|
39
|
+
config: DwnServerConfig;
|
|
40
|
+
/**
|
|
41
|
+
* @param options.dwn - Dwn instance to use as an override. Registration endpoint will not be enabled if this is provided.
|
|
42
|
+
*/
|
|
43
|
+
constructor(options?: DwnServerOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Starts the DWN server.
|
|
46
|
+
*/
|
|
47
|
+
start(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Stops the DWN server.
|
|
50
|
+
*/
|
|
51
|
+
stop(): Promise<void>;
|
|
52
|
+
get httpServer(): Server;
|
|
53
|
+
get wsServer(): WebSocketServer | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the RegistrationManager for testing purposes.
|
|
56
|
+
*/
|
|
57
|
+
get registrationManager(): RegistrationManager;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=dwn-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dwn-server.d.ts","sourceRoot":"","sources":["../../../src/dwn-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,C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