tool-db 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +10 -33
  2. package/bundle.js +1 -124672
  3. package/dist/chain/Block.d.ts +16 -8
  4. package/dist/chain/Block.js +81 -20
  5. package/dist/chain/Block.js.map +1 -1
  6. package/dist/chain/ToolChain.d.ts +18 -3
  7. package/dist/chain/ToolChain.js +191 -24
  8. package/dist/chain/ToolChain.js.map +1 -1
  9. package/dist/chain/Tx.d.ts +46 -30
  10. package/dist/chain/Tx.js +47 -104
  11. package/dist/chain/Tx.js.map +1 -1
  12. package/dist/chain/isValidChain.d.ts +1 -2
  13. package/dist/chain/isValidChain.js +24 -7
  14. package/dist/chain/isValidChain.js.map +1 -1
  15. package/dist/crdt/baseCrdt.d.ts +9 -0
  16. package/dist/crdt/baseCrdt.js +27 -0
  17. package/dist/crdt/baseCrdt.js.map +1 -0
  18. package/dist/crdt/counterCrdt.d.ts +30 -0
  19. package/dist/crdt/counterCrdt.js +124 -0
  20. package/dist/crdt/counterCrdt.js.map +1 -0
  21. package/dist/crdt/listCrdt.d.ts +42 -0
  22. package/dist/crdt/listCrdt.js +177 -0
  23. package/dist/crdt/listCrdt.js.map +1 -0
  24. package/dist/crdt/mapCrdt.d.ts +32 -0
  25. package/dist/crdt/mapCrdt.js +136 -0
  26. package/dist/crdt/mapCrdt.js.map +1 -0
  27. package/dist/index.d.ts +4 -12
  28. package/dist/index.js +9 -35
  29. package/dist/index.js.map +1 -1
  30. package/{test-verify-a/000066.log → dist/infuraFilecoin.d.ts} +0 -0
  31. package/dist/infuraFilecoin.js +2 -0
  32. package/dist/infuraFilecoin.js.map +1 -0
  33. package/dist/makeTx.d.ts +1 -0
  34. package/dist/makeTx.js +27 -0
  35. package/dist/makeTx.js.map +1 -0
  36. package/dist/messageHandlers/handleCrdtGet.js +17 -15
  37. package/dist/messageHandlers/handleCrdtGet.js.map +1 -1
  38. package/dist/messageHandlers/handleCrdtPut.js +53 -72
  39. package/dist/messageHandlers/handleCrdtPut.js.map +1 -1
  40. package/dist/messageHandlers/handleGet.js +6 -12
  41. package/dist/messageHandlers/handleGet.js.map +1 -1
  42. package/dist/messageHandlers/handlePut.js +12 -22
  43. package/dist/messageHandlers/handlePut.js.map +1 -1
  44. package/dist/messageHandlers/handleSubscribe.js +14 -34
  45. package/dist/messageHandlers/handleSubscribe.js.map +1 -1
  46. package/dist/test.d.ts +1 -0
  47. package/dist/test.js +17 -0
  48. package/dist/test.js.map +1 -0
  49. package/dist/toolChainServer.d.ts +8 -0
  50. package/dist/toolChainServer.js +60 -0
  51. package/dist/toolChainServer.js.map +1 -0
  52. package/dist/toolDbClientOnMessage.js +3 -4
  53. package/dist/toolDbClientOnMessage.js.map +1 -1
  54. package/dist/toolDbCrdtGet.d.ts +4 -2
  55. package/dist/toolDbCrdtGet.js +26 -19
  56. package/dist/toolDbCrdtGet.js.map +1 -1
  57. package/dist/toolDbCrdtPut.d.ts +3 -3
  58. package/dist/toolDbCrdtPut.js +17 -22
  59. package/dist/toolDbCrdtPut.js.map +1 -1
  60. package/dist/toolDbGet.d.ts +1 -1
  61. package/dist/toolDbGet.js +5 -4
  62. package/dist/toolDbGet.js.map +1 -1
  63. package/dist/toolDbNetwork.js +4 -4
  64. package/dist/toolDbNetwork.js.map +1 -1
  65. package/dist/toolDbPut.d.ts +1 -1
  66. package/dist/toolDbPut.js +15 -18
  67. package/dist/toolDbPut.js.map +1 -1
  68. package/dist/toolDbQueryKeys.js +2 -2
  69. package/dist/toolDbQueryKeys.js.map +1 -1
  70. package/dist/toolDbSignIn.js +10 -16
  71. package/dist/toolDbSignIn.js.map +1 -1
  72. package/dist/toolDbSignUp.js +10 -24
  73. package/dist/toolDbSignUp.js.map +1 -1
  74. package/dist/toolDbSubscribe.d.ts +1 -1
  75. package/dist/toolDbSubscribe.js +3 -22
  76. package/dist/toolDbSubscribe.js.map +1 -1
  77. package/dist/toolDbVerificationWrapper.d.ts +2 -2
  78. package/dist/toolDbVerificationWrapper.js.map +1 -1
  79. package/dist/toolDbWebrtc.js +16 -1
  80. package/dist/toolDbWebrtc.js.map +1 -1
  81. package/dist/toolchain.d.ts +1 -0
  82. package/dist/toolchain.js +8 -0
  83. package/dist/toolchain.js.map +1 -0
  84. package/dist/tooldb.d.ts +8 -15
  85. package/dist/tooldb.js +3 -15
  86. package/dist/tooldb.js.map +1 -1
  87. package/dist/types/message.d.ts +11 -22
  88. package/dist/types/message.js +1 -1
  89. package/dist/types/message.js.map +1 -1
  90. package/dist/types/tooldb.d.ts +0 -19
  91. package/dist/utils/encoding/uint8ArrayToHex.d.ts +1 -2
  92. package/dist/utils/encoding/uint8ArrayToHex.js.map +1 -1
  93. package/dist/utils/encoding/uint8ToBase64.d.ts +1 -2
  94. package/dist/utils/encoding/uint8ToBase64.js.map +1 -1
  95. package/dist/utils/sha1.d.ts +1 -1
  96. package/dist/utils/sha1.js +2 -3
  97. package/dist/utils/sha1.js.map +1 -1
  98. package/dist/utils/sha256.d.ts +1 -1
  99. package/dist/utils/sha256.js +2 -3
  100. package/dist/utils/sha256.js.map +1 -1
  101. package/dist/utils/verifyMessage.d.ts +1 -1
  102. package/dist/utils/verifyMessage.js +8 -7
  103. package/dist/utils/verifyMessage.js.map +1 -1
  104. package/package.json +4 -6
  105. package/test-alice/000347.ldb +0 -0
  106. package/test-alice/000349.ldb +0 -0
  107. package/test-alice/000352.ldb +0 -0
  108. package/test-alice/000355.ldb +0 -0
  109. package/test-alice/000356.log +0 -0
  110. package/test-alice/CURRENT +1 -1
  111. package/test-alice/LOG +5 -5
  112. package/test-alice/LOG.old +5 -14
  113. package/test-alice/MANIFEST-000354 +0 -0
  114. package/test-alice-speed/000198.ldb +0 -0
  115. package/test-alice-speed/000200.ldb +0 -0
  116. package/test-alice-speed/000203.ldb +0 -0
  117. package/test-alice-speed/000206.ldb +0 -0
  118. package/test-alice-speed/000207.log +0 -0
  119. package/test-alice-speed/CURRENT +1 -1
  120. package/test-alice-speed/LOG +5 -5
  121. package/test-alice-speed/LOG.old +5 -5
  122. package/test-alice-speed/MANIFEST-000205 +0 -0
  123. package/test-bob/000347.ldb +0 -0
  124. package/test-bob/000349.ldb +0 -0
  125. package/test-bob/000352.ldb +0 -0
  126. package/test-bob/000355.ldb +0 -0
  127. package/test-bob/000356.log +0 -0
  128. package/test-bob/CURRENT +1 -1
  129. package/test-bob/LOG +5 -5
  130. package/test-bob/LOG.old +5 -14
  131. package/test-bob/MANIFEST-000354 +0 -0
  132. package/test-node-a/000347.ldb +0 -0
  133. package/test-node-a/000349.ldb +0 -0
  134. package/test-node-a/000352.ldb +0 -0
  135. package/test-node-a/000355.ldb +0 -0
  136. package/test-node-a/000356.log +0 -0
  137. package/test-node-a/CURRENT +1 -1
  138. package/test-node-a/LOG +5 -5
  139. package/test-node-a/LOG.old +5 -14
  140. package/test-node-a/MANIFEST-000354 +0 -0
  141. package/test-node-b/000347.ldb +0 -0
  142. package/test-node-b/000349.ldb +0 -0
  143. package/test-node-b/000352.ldb +0 -0
  144. package/test-node-b/000355.ldb +0 -0
  145. package/test-node-b/000356.log +0 -0
  146. package/test-node-b/CURRENT +1 -1
  147. package/test-node-b/LOG +5 -5
  148. package/test-node-b/LOG.old +5 -14
  149. package/test-node-b/MANIFEST-000354 +0 -0
  150. package/test-verify-a/000194.log +0 -0
  151. package/test-verify-a/CURRENT +1 -1
  152. package/test-verify-a/LOG +3 -3
  153. package/test-verify-a/LOG.old +3 -3
  154. package/test-verify-a/{MANIFEST-000065 → MANIFEST-000193} +0 -0
  155. package/pvutils-tests-replacement.js +0 -777
  156. package/test-alice/000087.ldb +0 -0
  157. package/test-alice/000089.ldb +0 -0
  158. package/test-alice/000090.log +0 -0
  159. package/test-alice/MANIFEST-000088 +0 -0
  160. package/test-alice-speed/000029.ldb +0 -0
  161. package/test-alice-speed/000031.ldb +0 -0
  162. package/test-alice-speed/000034.ldb +0 -0
  163. package/test-alice-speed/000035.log +0 -0
  164. package/test-alice-speed/MANIFEST-000033 +0 -0
  165. package/test-bob/000087.ldb +0 -0
  166. package/test-bob/000089.ldb +0 -0
  167. package/test-bob/000090.log +0 -0
  168. package/test-bob/MANIFEST-000088 +0 -0
  169. package/test-node-a/000087.ldb +0 -0
  170. package/test-node-a/000089.ldb +0 -0
  171. package/test-node-a/000090.log +0 -0
  172. package/test-node-a/MANIFEST-000088 +0 -0
  173. package/test-node-b/000087.ldb +0 -0
  174. package/test-node-b/000089.ldb +0 -0
  175. package/test-node-b/000090.log +0 -0
  176. package/test-node-b/MANIFEST-000088 +0 -0
package/README.md CHANGED
@@ -11,6 +11,12 @@ It is the mix of a lot of cool concepts into one;
11
11
  - Key-value/document storage.
12
12
  - Works in the Browser and Nodejs seamlessly.
13
13
 
14
+ For a more detailed documentation head here;
15
+
16
+ [https://github.com/Manwe-777/tool-db-docs](https://github.com/Manwe-777/tool-db-docs)
17
+
18
+ _(No live version just yet!, until the protocol is more finalized)_
19
+
14
20
  We push towards of the concept of federated servers, where we set up a p2p mesh network between any servers who want to join the swarm, and have those servers manage the connection and data sharing between them, while allowing client peers to connect to them to push updates to the database.
15
21
  This setup IS NOT a requirement! It is just what I think is the best and most reliable way of creating a p2p network for dApps using both desktop and web compatible technologies. Any peer has the capability of connecting to any other peer trough websockets, and modifiying the code to allow webRtc connections between web peers is absolutely possible.
16
22
 
@@ -99,16 +105,8 @@ These are the options you can pass to the constructor:
99
105
  // A custom storage adapter function
100
106
  storageAdapter: ToolDbStorageAdapter;
101
107
 
102
- // Our client ID (defaults to a generated publicKey)
103
- id: string;
104
-
105
108
  // The namespace/topic of our app (default is "tool-db-default")
106
109
  topic: string;
107
-
108
- // Public and private (ECDSA) keys of our client. In the default network adapter these are used to sign
109
- // our messages as we join and leave the network, public key should match the client ID (as a base64 exported string).
110
- publicKey: CryptoKey | undefined;
111
- privateKey: CryptoKey | undefined;
112
110
  }
113
111
  ```
114
112
  Notice you can use your own network and storage modules if you would like to implement custom solutions for peers discovery, connections, storage, etc, the default adapters will work both on nodejs and the browser.
@@ -121,9 +119,9 @@ client.signIn(user, pass).then(keys);
121
119
  client.anonSignIn().then();
122
120
  ```
123
121
 
124
- To retrieve your public key; (only if logged in)
122
+ To retrieve your address; (only if logged in)
125
123
  ```
126
- client.getPubKey();
124
+ client.getAddress();
127
125
  ```
128
126
 
129
127
  You can check if you are correctly logged in by checking if the user field exists or not;
@@ -147,7 +145,7 @@ You can use `client.getUserNamespacedKey(key)` to convert any key to a private n
147
145
 
148
146
  Note the third function (putCrdt); For p2p networks some times you want to have conflict resolution on certain documents, to do this we use [automerge](https://github.com/automerge/automerge). Please take a look at it to know how it works in detail! The only thing you need to know on Tool Db is that you have to send an `Automerge.BinaryChange[]` (you get it using `Automerge.change()`). The recieving peer will process the changes, compare it to its stored documents and generate a new document with JSON CRDT applied to it, then relay the final document back to you.
149
147
 
150
- To listen for a value changes you can set up a listener on a key. Beware the listener will check for all keys *starting with* the supplied key, so for example, if you use "value." as your listener if will execute on every key that starts with "value.". This is useful for checking against a public key or namespace.
148
+ To listen for a value changes you can set up a listener on a key. Beware the listener will check for all keys *starting with* the supplied key, so for example, if you use "value." as your listener if will execute on every key that starts with "value.". This is useful for checking against an address or namespace.
151
149
  ```
152
150
  const listenerId = client.addKeyListener("value", console.log);
153
151
  client.removeKeyListener(listenerId);
@@ -179,7 +177,7 @@ client.queryKeys(keyPrefix, userNamespaced?, timeout?).then()
179
177
  ```
180
178
 
181
179
  Just like previous methods you can configure the namespace and timeout and returns a promise, but in this case the value is always an array with the found keys.
182
- Using for example ":" + publicKey as our prefix would return all keys stored for that specific user namespace; you can also create keys for very specific use cases like "post-1" and query again "post-" to get a list of all available posts.
180
+ Using for example ":" + address as our prefix would return all keys stored for that specific user namespace; you can also create keys for very specific use cases like "post-1" and query again "post-" to get a list of all available posts.
183
181
 
184
182
  Keep in mind this can be an intensive thing to do if your indexes are too big, and not recommended to be used very frequently.
185
183
 
@@ -193,27 +191,6 @@ client.subscribeData("key", userNamespaced?);
193
191
 
194
192
  This will relay back to you all Put and CrdtPut messages on that key.
195
193
 
196
- When subscribing to a CRDT document you will need to load the data like so;
197
- ```
198
- window.toolDb.addKeyListener("documentKey", handleDocumentKeyCrdt);
199
- function handleDocumentKeyCrdt(msg) {
200
- if (msg && msg.type === "crdt") {
201
- // Load the document from the message (msg.doc)
202
- const incomingDocument = Automerge.load(
203
- base64ToBinaryDocument(msg.doc)
204
- );
205
-
206
- if (globalData.myCrdtDocument) {
207
- // Merge the local doc vs the incoming one and store it somewhere locally
208
- globalData.myCrdtDocument = Automerge.merge(globalData.myCrdtDocument, incomingDocument);
209
- } else {
210
- // New document! Just store it
211
- globalData.myCrdtDocument = incomingDocument;
212
- }
213
- }
214
- }
215
- ```
216
-
217
194
  ## Events
218
195
 
219
196
  If you need to check when you are connected to a server peer or not you can use the following method replacements;