@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
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# DWN Server <!-- omit in toc -->
|
|
2
|
+
|
|
3
|
+
Exposes a multi-tenanted DWN (aka Decentralized Web Node) through a JSON-RPC API over `http:` and `ws:`
|
|
4
|
+
|
|
5
|
+
- [Supported DBs](#supported-dbs)
|
|
6
|
+
- [Installation](#installation)
|
|
7
|
+
- [Package usage](#package-usage)
|
|
8
|
+
- [Running The Server](#running-the-server)
|
|
9
|
+
- [JSON-RPC API](#json-rpc-api)
|
|
10
|
+
- [Available Methods](#available-methods)
|
|
11
|
+
- [`dwn.processMessage`](#dwnprocessmessage)
|
|
12
|
+
- [Params](#params)
|
|
13
|
+
- [Example Request Message](#example-request-message)
|
|
14
|
+
- [Example Success Response](#example-success-response)
|
|
15
|
+
- [Example Error Response](#example-error-response)
|
|
16
|
+
- [Transporting large amounts of data](#transporting-large-amounts-of-data)
|
|
17
|
+
- [Receiving large amounts of data](#receiving-large-amounts-of-data)
|
|
18
|
+
- [npm scripts](#npm-scripts)
|
|
19
|
+
- [Configuration](#configuration)
|
|
20
|
+
- [Storage Options](#storage-options)
|
|
21
|
+
|
|
22
|
+
## Supported DBs
|
|
23
|
+
|
|
24
|
+
- LevelDB :heavy_check_mark:
|
|
25
|
+
- SQLite :heavy_check_mark:
|
|
26
|
+
- MySQL :heavy_check_mark:
|
|
27
|
+
- PostgreSQL :heavy_check_mark:
|
|
28
|
+
|
|
29
|
+
See more in [Storage Options](#storage-options)
|
|
30
|
+
|
|
31
|
+
## Running online environment
|
|
32
|
+
|
|
33
|
+
Interested in contributing instantly? You can make your updates directly without cloning in the running CodeSandbox environment.
|
|
34
|
+
|
|
35
|
+
[](https://codesandbox.io/p/github/enboxorg/enbox/dwn-server/main)
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @enbox/dwn-server
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Package usage
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { DwnServer } from '@enbox/dwn-server';
|
|
47
|
+
|
|
48
|
+
const server = new DwnServer();
|
|
49
|
+
|
|
50
|
+
server.start();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Running the server
|
|
54
|
+
|
|
55
|
+
### Running via docker
|
|
56
|
+
|
|
57
|
+
`docker run -p 3000:3000 -v myvolume:/dwn-server/data ghcr.io/enboxorg/enbox/dwn-server:main`
|
|
58
|
+
|
|
59
|
+
This can run on services like AWS, GCP, VPS, home server (with ngrok or cloudflare), fly.io, render.com etc.
|
|
60
|
+
Ideally the volume is persistent so that data is kept (or has to be synced back from another DWN instance).
|
|
61
|
+
|
|
62
|
+
### Running a specific version
|
|
63
|
+
|
|
64
|
+
Running the command above will run the latest version at the time the image is pulled. If you need to run a specific version (and in many cases this is recommended) [you can see the list published images here](https://github.com/enboxorg/enbox/dwn-server/pkgs/container/dwn-server/versions)
|
|
65
|
+
|
|
66
|
+
To run a specific image:
|
|
67
|
+
`docker pull ghcr.io/enboxorg/enbox/dwn-server@sha256:870e0f0f12016e6607060a81ea31458443f7439522fab2688d7a6706ab366c58`
|
|
68
|
+
|
|
69
|
+
### Running Locally for Development
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/enboxorg/enbox/dwn-server.git
|
|
73
|
+
cd dwn-server
|
|
74
|
+
npm install
|
|
75
|
+
npm run server
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Building a docker image locally
|
|
79
|
+
|
|
80
|
+
A docker image is continuously published from this repository, but if you want to build it locally run:
|
|
81
|
+
`docker build -t dwn-server .`
|
|
82
|
+
|
|
83
|
+
## JSON-RPC API
|
|
84
|
+
|
|
85
|
+
[JSON-RPC](https://www.jsonrpc.org/specification) is a lightweight remote procedure call (RPC) protocol that uses JSON as a data format for exchanging information between a client and a server over a network. JSON-RPC is language-independent and transport-agnostic which makes it usable in a variety of contexts (e.g. browser, server-side)
|
|
86
|
+
|
|
87
|
+
With JSON-RPC, a client sends a request message to a server over a network, and the server responds with a response message.
|
|
88
|
+
|
|
89
|
+
The request message consists of:
|
|
90
|
+
|
|
91
|
+
- a method name (`method`)
|
|
92
|
+
- a set of parameters (`params`)
|
|
93
|
+
- an identifier (`id`).
|
|
94
|
+
|
|
95
|
+
The response message contains:
|
|
96
|
+
|
|
97
|
+
- the same identifier that was sent with the request message (`id`)
|
|
98
|
+
- the result of the method invocation (`result`)
|
|
99
|
+
- an error message if the method invocation failed (`error`)
|
|
100
|
+
|
|
101
|
+
### Available Methods
|
|
102
|
+
|
|
103
|
+
#### `dwn.processMessage`
|
|
104
|
+
|
|
105
|
+
Used to send DWeb Messages to the server.
|
|
106
|
+
|
|
107
|
+
##### Params
|
|
108
|
+
|
|
109
|
+
| Property | Required (Y/N) | Description |
|
|
110
|
+
| ------------- | -------------- | ------------------------------------------------------------------------- |
|
|
111
|
+
| `target` | Y | The DID that the message is intended for |
|
|
112
|
+
| `message` | Y | The DWeb Message |
|
|
113
|
+
| `encodedData` | N | Data associated to the message (e.g. data associated to a `RecordsWrite`) |
|
|
114
|
+
|
|
115
|
+
##### Example Request Message
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"jsonrpc": "2.0",
|
|
120
|
+
"id": "b23f9e31-4966-4972-8048-af3eed43cb41",
|
|
121
|
+
"method": "dwn.processMessage",
|
|
122
|
+
"params": {
|
|
123
|
+
"message": {
|
|
124
|
+
"recordId": "bafyreidtix6ghjmsbg7eitexsmwzvjxc7aelagsqasybmql7zrms34ju6i",
|
|
125
|
+
"descriptor": {
|
|
126
|
+
"interface": "Records",
|
|
127
|
+
"method": "Write",
|
|
128
|
+
"dataCid": "bafkreidnfo6aux5qbg3wwzy5hvwexnoyhk3q3v47znka2afa6mf2rffkbi",
|
|
129
|
+
"dataSize": 32,
|
|
130
|
+
"dateCreated": "2023-04-30T22:49:37.713976Z",
|
|
131
|
+
"dateModified": "2023-04-30T22:49:37.713976Z",
|
|
132
|
+
"dataFormat": "application/json"
|
|
133
|
+
},
|
|
134
|
+
"authorization": {
|
|
135
|
+
"payload": "eyJyZWNvcmRJZCI6ImJhZnlyZWlkdGl4Nmdoam1zYmc3ZWl0ZXhzbXd6dmp4YzdhZWxhZ3NxYXN5Ym1xbDd6cm1zMzRqdTZpIiwiZGVzY3JpcHRvckNpZCI6ImJhZnlyZWlheTVwNWZ1bzJhc2hqZXRvbzR1M3p1b282dW02cGlzNHl5NnUzaHE1emxsdmZhN2ZubXY0In0",
|
|
136
|
+
"signatures": [
|
|
137
|
+
{
|
|
138
|
+
"protected": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3UxaDRMZGtoWFczSG5uQktBTnhnVWFRMTYyY3ZXbVJ1emNiZDJZZThWc3RaI2RpZDprZXk6ejZNa3UxaDRMZGtoWFczSG5uQktBTnhnVWFRMTYyY3ZXbVJ1emNiZDJZZThWc3RaI3o2TWt1MWg0TGRraFhXM0hubkJLQU54Z1VhUTE2MmN2V21SdXpjYmQyWWU4VnN0WiJ9",
|
|
139
|
+
"signature": "cy_RtWjjVK2mmKkI_35qiv54_1Pp_f7SjAx0z75PBL4th-fgfjuLZmF-V3czCWwFYMMnN0W4zl3LJ2jEf_t9DQ"
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"target": "did:key:z6Mku1h4LdkhXW3HnnBKANxgUaQ162cvWmRuzcbd2Ye8VstZ",
|
|
145
|
+
"encodedData": "ub3-FwUsSs4GgZWqt5eXSH41RKlwCx41y3dgio9Di74"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
##### Example Success Response
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"jsonrpc": "2.0",
|
|
155
|
+
"id": "18eb421f-4750-4e31-a062-412b71139546",
|
|
156
|
+
"result": {
|
|
157
|
+
"reply": {
|
|
158
|
+
"status": {
|
|
159
|
+
"code": 202,
|
|
160
|
+
"detail": "Accepted"
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
##### Example Error Response
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"jsonrpc": "2.0",
|
|
172
|
+
"id": "1c7f6ed8-eaaf-447c-aaf3-b9e61f3f59af",
|
|
173
|
+
"error": {
|
|
174
|
+
"code": -50400,
|
|
175
|
+
"message": "Unexpected token ';', \";;;;@!#@!$$#!@%\" is not valid JSON"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
##### Transporting large amounts of data
|
|
181
|
+
|
|
182
|
+
`RecordsWrite` data can be of any size. If needed, large amounts of data can be streamed to the server over http by:
|
|
183
|
+
|
|
184
|
+
- including the JSON-RPC request message in a `dwn-request` request header
|
|
185
|
+
- setting the `content-type` request header to `application/octet-stream`
|
|
186
|
+
- sending binary data in the request body.
|
|
187
|
+
|
|
188
|
+
> :bulb: Examples can be found in the [`examples`](./examples) directory.
|
|
189
|
+
|
|
190
|
+
##### Receiving large amounts of data
|
|
191
|
+
|
|
192
|
+
`RecordsWrite` data can be of any size. `RecordsWrite` messages returned as the result of a `RecordsQuery` will include `encodedData` _if_ the `RecordsWrite` data is under `9.77KB`. Data larger than this will need to be fetched using `RecordsRead` which can be done over http. The response to a `RecordsRead` includes:
|
|
193
|
+
|
|
194
|
+
- The JSON-RPC response message in a `dwn-response` header
|
|
195
|
+
- The associated data as binary in the response body.
|
|
196
|
+
|
|
197
|
+
Examples can be found in the `examples` directory.
|
|
198
|
+
|
|
199
|
+
> :bulb: **TODO**: Add examples in `examples` directory
|
|
200
|
+
|
|
201
|
+
## Hosting your own DWN-server
|
|
202
|
+
|
|
203
|
+
By default, when you call `web5.connect()` there will be some bootstrap DWN nodes included which allow people to reach you via your DID.
|
|
204
|
+
|
|
205
|
+
You may want to run a DWN server just for you, or as a public service for you and your friends and family.
|
|
206
|
+
DWNs can be as simple as a docker image or a node process running somewhere.
|
|
207
|
+
|
|
208
|
+
DWN-servers can run anywhere you can run node.js or docker. http and websocket need to be available to the DWN server.
|
|
209
|
+
See below for some suggestions.
|
|
210
|
+
|
|
211
|
+
### Running on render.com
|
|
212
|
+
|
|
213
|
+
You can run an instance on the render.com service:
|
|
214
|
+
|
|
215
|
+
- Create a render.com account
|
|
216
|
+
- Fork this repo
|
|
217
|
+
- Upgrade your render.com account to a paid account
|
|
218
|
+
- Create a new "Web service" type application
|
|
219
|
+
- Choose the forked repo to run (or you can point to the main repo)
|
|
220
|
+
- Choose the "starter" size instance
|
|
221
|
+
- Create a 1GB (or larger) disk, and mount it on /dwn-server/data
|
|
222
|
+
|
|
223
|
+
### Running with ngrok
|
|
224
|
+
|
|
225
|
+
You can run a DWN-server on your local machine or home server and expose it to the internet using ngrok.
|
|
226
|
+
|
|
227
|
+
First, install [ngrok](https://ngrok.com/download)
|
|
228
|
+
|
|
229
|
+
Then run:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
docker run -p 3000:3000 -v myvolume:/dwn-server/data ghcr.io/enboxorg/enbox/dwn-server:main
|
|
233
|
+
|
|
234
|
+
## in another terminal:
|
|
235
|
+
ngrok http 3000
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Note the resulting publicly addressable https url for your DWN instance.
|
|
239
|
+
|
|
240
|
+
### Running with cloudflared
|
|
241
|
+
|
|
242
|
+
Cloudflare has a tunnel service that you can use to expose your DWN server to the internet, if you run it on a server at home.
|
|
243
|
+
With [cloudflared](https://github.com/cloudflare/cloudflared) installed, run the following commands:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
git clone https://github.com/enboxorg/enbox/dwn-server.git
|
|
247
|
+
cd dwn-server
|
|
248
|
+
npm install
|
|
249
|
+
npm run server
|
|
250
|
+
|
|
251
|
+
## in another terminal:
|
|
252
|
+
|
|
253
|
+
cloudflared tunnel --url http://localhost:3000
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Running on GCP
|
|
257
|
+
|
|
258
|
+
... check back soon ...
|
|
259
|
+
(enterprising people I am sure can work it out)
|
|
260
|
+
|
|
261
|
+
## `npm` scripts
|
|
262
|
+
|
|
263
|
+
| Script | Description |
|
|
264
|
+
| ---------------------- | ------------------------------------------------------------------ |
|
|
265
|
+
| `npm run build:esm` | compiles typescript into ESM JS |
|
|
266
|
+
| `npm run build:cjs` | compiles typescript into CommonJS |
|
|
267
|
+
| `npm run build` | compiles typescript into ESM JS & CommonJS |
|
|
268
|
+
| `npm run clean` | deletes compiled JS |
|
|
269
|
+
| `npm run lint` | runs linter |
|
|
270
|
+
| `npm run lint:fix` | runs linter and fixes auto-fixable problems |
|
|
271
|
+
| `npm run test` | runs tests |
|
|
272
|
+
| `npm run server` | starts server |
|
|
273
|
+
| `npm run prepare` | prepares husky for pre-commit hooks (auto-runs with `npm install`) |
|
|
274
|
+
|
|
275
|
+
## Configuration
|
|
276
|
+
|
|
277
|
+
Configuration can be set using environment variables
|
|
278
|
+
|
|
279
|
+
| Env Var | Description | Default |
|
|
280
|
+
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------- |
|
|
281
|
+
| `DS_PORT` | Port that the server listens on | `3000` |
|
|
282
|
+
| `DS_MAX_RECORD_DATA_SIZE` | Maximum size for `RecordsWrite` data. use `b`, `kb`, `mb`, `gb` for value | `1gb` |
|
|
283
|
+
| `DS_WEBSOCKET_SERVER` | Whether to enable listening over `ws:`. values: `on`,`off` | `on` |
|
|
284
|
+
| `DWN_BASE_URL` | Base external URL of this DWN. Used to construct URL paths such as the `Request URI` for the Web5 Connect flow. | `http://localhost` |
|
|
285
|
+
| `DWN_EVENT_STREAM_PLUGIN_PATH` | Path to DWN Event Stream plugin to use. Default single-node implementation will be used if left empty. | unset |
|
|
286
|
+
| `DWN_REGISTRATION_STORE_URL` | URL to use for storage of registered DIDs. Leave unset to if DWN does not require registration (ie. open for all) | unset |
|
|
287
|
+
| `DWN_REGISTRATION_PROOF_OF_WORK_SEED` | Optional seed to generate the challenge nonce from, this allows all DWN instances in a cluster to generate the same challenge. | unset |
|
|
288
|
+
| `DWN_REGISTRATION_PROOF_OF_WORK_ENABLED` | Require new users to complete a proof-of-work challenge | `false` |
|
|
289
|
+
| `DWN_REGISTRATION_PROOF_OF_WORK_INITIAL_MAX_HASH` | Initial maximum allowed hash in 64 char HEX string. The more leading zeros (smaller number) the higher the difficulty. | `000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF` |
|
|
290
|
+
| `DWN_STORAGE` | URL to use for storage by default. See [Storage Options](#storage-options) for details | `level://data` |
|
|
291
|
+
| `DWN_STORAGE_MESSAGES` | Connection URL or file path to custom plugin to use for the message store. | value of `DWN_STORAGE` |
|
|
292
|
+
| `DWN_STORAGE_DATA` | Connection URL or file path to custom plugin to use for the data store. | value of `DWN_STORAGE` |
|
|
293
|
+
| `DWN_STORAGE_RESUMABLE_TASKS` | Connection URL or file path to custom plugin to use for the resumable task store. | value of `DWN_STORAGE` |
|
|
294
|
+
| `DWN_STORAGE_EVENTS` | Connection URL or file path to custom plugin to use for the event store. | value of `DWN_STORAGE` |
|
|
295
|
+
| `DWN_TERMS_OF_SERVICE_FILE_PATH` | Required terms of service agreement if set. Value is path to the terms of service file. | unset |
|
|
296
|
+
| `DWN_TTL_CACHE_URL` | URL of the TTL cache used by the DWN. Currently only supports SQL databases. | `sqlite://` |
|
|
297
|
+
|
|
298
|
+
### Storage Options
|
|
299
|
+
|
|
300
|
+
Several built storage options are supported, and may be configured with the `DWN_STORAGE_*` environment variables:
|
|
301
|
+
|
|
302
|
+
| Database | Example | Notes |
|
|
303
|
+
| ---------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
304
|
+
| LevelDB | `level://data` | use three slashes for absolute paths, two for relative. Example shown uses directory `data` in the current working directory |
|
|
305
|
+
| Sqlite | `sqlite://dwn.db` | use three slashes for absolute paths, two for relative. Example shown creates a file `dwn.db` in the current working directory |
|
|
306
|
+
| MySQL | `mysql://user:pass@host/db?debug=true&timezone=-0700` | [all URL options documented here](https://github.com/mysqljs/mysql#connection-options) |
|
|
307
|
+
| PostgreSQL | `postgres:///dwn` | any options other than the URL scheme (`postgres://`) may also be specified via [standard environment variables](https://node-postgres.com/features/connecting#environment-variables) |
|
|
308
|
+
|
|
309
|
+
### Plugins
|
|
310
|
+
|
|
311
|
+
In some scenarios, you may want to provide a custom implementation of a pluggable module for the DWN Server. The following interfaces defined in `dwn-sdk-js` package are supported:
|
|
312
|
+
|
|
313
|
+
- `DataStore`
|
|
314
|
+
- `MessageStore`
|
|
315
|
+
- `ResumableDataStore`
|
|
316
|
+
- `EventLog`
|
|
317
|
+
- `EventStream`
|
|
318
|
+
|
|
319
|
+
To load your custom plugin, specify the absolute path to the `.js` file of your custom implementation using the corresponding environment variable. For instance, use `DWN_STORAGE_DATA` for a custom DWN Data Store.
|
|
320
|
+
|
|
321
|
+
Refer to the `tests/plugins/*.ts` files for examples of plugin implementations. In summary, you need to:
|
|
322
|
+
|
|
323
|
+
- Implement the corresponding interface from the `dwn-sdk-js` package. For example, implement the `DataStore` interface for a DWN Data Store.
|
|
324
|
+
- Ensure that the built `.js` file that will be referenced by the DWN Server config environment variable contains a class that:
|
|
325
|
+
1. Is a default export. This is how DWN Server locates the correct class for instantiation.
|
|
326
|
+
1. Has a public constructor that does not take any arguments. This is how DWN Server instantiates the plugin.
|
|
327
|
+
|
|
328
|
+
## Registration Requirements
|
|
329
|
+
|
|
330
|
+
There are multiple optional registration gates, each of which can be enabled (all are disabled by default). Tenants (DIDs) must comply with whatever
|
|
331
|
+
requirements are enabled before they are allowed to use the server. Tenants that have not completed the registration requirements will be met with a 401. Note that registration is tracked in a database, and only SQL-based databases are supported (LevelDB is not supported). Current registration
|
|
332
|
+
requirements are available at the `/info` endpoint.
|
|
333
|
+
|
|
334
|
+
- **Proof of Work** (`DWN_REGISTRATION_PROOF_OF_WORK_ENABLED=true`) - new tenants must GET `/registration/proof-of-work` for a challenge, then generate a nonce that produces a string that has a sha256 hex sum starting with the specified (`complexity`) number of zeros (`0`) when added to the end of the challenge (`sha256(challenge + nonce)`). This nonce should be POSTed to `/registration/proof-of-work` with a JSON body including the `challenge`, the nonce in field `response` and `did`. Challenges expire after 5 minutes, and complexity will increase based on the number of successful proof-of-work registrations that have been completed within the last hour. This registration requirement is listed in `/info` as `proof-of-work-sha256-v0`.
|
|
335
|
+
- **Terms of Service** (`DWN_TERMS_OF_SERVICE_FILE_PATH=/path/to/terms-of-service.txt`) - new tenants must GET `/registration/terms-of-service` to fetch the terms. These terms must be displayed to the human end-user, who must actively accept them. When the user accepts the terms, send the sha256 hash of the accepted terms and the user's did via POST `/registration/terms-of-service`. The JSON body should have fields `termsOfServiceHash` and `did`. To change the terms, update the file and restart the server. Users that accepted the old terms will be blocked until they accept the new terms. This registration requirement is listed in `/info` as `terms-of-service`.
|
|
336
|
+
|
|
337
|
+
## Server info
|
|
338
|
+
|
|
339
|
+
the server exposes information about itself via the `/info` endpoint, which returns data in the following format:
|
|
340
|
+
|
|
341
|
+
```json
|
|
342
|
+
{
|
|
343
|
+
"server": "@enbox/dwn-server",
|
|
344
|
+
"maxFileSize": 1073741824,
|
|
345
|
+
"registrationRequirements": ["proof-of-work-sha256-v0", "terms-of-service"],
|
|
346
|
+
"version": "0.1.5",
|
|
347
|
+
"sdkVersion": "0.2.6",
|
|
348
|
+
"webSocketSupport": "true"
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
- `server` is read from the `process.env.npm_package_name` variable that `npm` provides. If that does not exist, it will check for a `DWN_SERVER_PACKAGE_NAME` environment variable set by the user, or otherwise it will default to `@enbox/dwn-server`.
|
|
353
|
+
- `version` and `sdkVersion` are read from the `package.json` file. It will locate the file's path either from the `process.env.npm_package_json` variable that `npm` provides. If that does not exist, it will check for a `DWN_SERVER_PACKAGE_JSON` environment variable set by the user, or otherwise it will default to `/dwn-server/package.json` which is the path within the default Docker container build.
|