tool-db 2.0.1 → 2.1.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/README.md +10 -33
- package/bundle.js +1 -124687
- package/dist/chain/Block.d.ts +16 -8
- package/dist/chain/Block.js +81 -20
- package/dist/chain/Block.js.map +1 -1
- package/dist/chain/ToolChain.d.ts +18 -3
- package/dist/chain/ToolChain.js +191 -24
- package/dist/chain/ToolChain.js.map +1 -1
- package/dist/chain/Tx.d.ts +46 -30
- package/dist/chain/Tx.js +47 -104
- package/dist/chain/Tx.js.map +1 -1
- package/dist/chain/isValidChain.d.ts +1 -2
- package/dist/chain/isValidChain.js +24 -7
- package/dist/chain/isValidChain.js.map +1 -1
- package/dist/crdt/baseCrdt.d.ts +9 -0
- package/dist/crdt/baseCrdt.js +27 -0
- package/dist/crdt/baseCrdt.js.map +1 -0
- package/dist/crdt/counterCrdt.d.ts +30 -0
- package/dist/crdt/counterCrdt.js +124 -0
- package/dist/crdt/counterCrdt.js.map +1 -0
- package/dist/crdt/listCrdt.d.ts +42 -0
- package/dist/crdt/listCrdt.js +177 -0
- package/dist/crdt/listCrdt.js.map +1 -0
- package/dist/crdt/mapCrdt.d.ts +32 -0
- package/dist/crdt/mapCrdt.js +136 -0
- package/dist/crdt/mapCrdt.js.map +1 -0
- package/dist/index.d.ts +4 -12
- package/dist/index.js +9 -35
- package/dist/index.js.map +1 -1
- package/{test-verify-a/000068.log → dist/infuraFilecoin.d.ts} +0 -0
- package/dist/infuraFilecoin.js +2 -0
- package/dist/infuraFilecoin.js.map +1 -0
- package/dist/makeTx.d.ts +1 -0
- package/dist/makeTx.js +27 -0
- package/dist/makeTx.js.map +1 -0
- package/dist/messageHandlers/handleCrdtGet.js +17 -15
- package/dist/messageHandlers/handleCrdtGet.js.map +1 -1
- package/dist/messageHandlers/handleCrdtPut.js +67 -72
- package/dist/messageHandlers/handleCrdtPut.js.map +1 -1
- package/dist/messageHandlers/handleGet.js +6 -12
- package/dist/messageHandlers/handleGet.js.map +1 -1
- package/dist/messageHandlers/handleJoin.js +1 -1
- package/dist/messageHandlers/handleJoin.js.map +1 -1
- package/dist/messageHandlers/handlePut.js +13 -22
- package/dist/messageHandlers/handlePut.js.map +1 -1
- package/dist/messageHandlers/handleServers.js +1 -1
- package/dist/messageHandlers/handleServers.js.map +1 -1
- package/dist/messageHandlers/handleSubscribe.js +14 -34
- package/dist/messageHandlers/handleSubscribe.js.map +1 -1
- package/dist/test.d.ts +1 -0
- package/dist/test.js +17 -0
- package/dist/test.js.map +1 -0
- package/dist/toolChainServer.d.ts +8 -0
- package/dist/toolChainServer.js +60 -0
- package/dist/toolChainServer.js.map +1 -0
- package/dist/toolDbAnonSignIn.js +1 -1
- package/dist/toolDbAnonSignIn.js.map +1 -1
- package/dist/toolDbClientOnMessage.js +3 -4
- package/dist/toolDbClientOnMessage.js.map +1 -1
- package/dist/toolDbCrdtGet.d.ts +4 -2
- package/dist/toolDbCrdtGet.js +28 -19
- package/dist/toolDbCrdtGet.js.map +1 -1
- package/dist/toolDbCrdtPut.d.ts +3 -3
- package/dist/toolDbCrdtPut.js +17 -22
- package/dist/toolDbCrdtPut.js.map +1 -1
- package/dist/toolDbGet.d.ts +1 -1
- package/dist/toolDbGet.js +8 -5
- package/dist/toolDbGet.js.map +1 -1
- package/dist/toolDbKeysSignIn.js +1 -1
- package/dist/toolDbKeysSignIn.js.map +1 -1
- package/dist/toolDbNetwork.js +4 -4
- package/dist/toolDbNetwork.js.map +1 -1
- package/dist/toolDbPut.d.ts +1 -1
- package/dist/toolDbPut.js +15 -18
- package/dist/toolDbPut.js.map +1 -1
- package/dist/toolDbQueryKeys.js +2 -2
- package/dist/toolDbQueryKeys.js.map +1 -1
- package/dist/toolDbSignIn.js +10 -16
- package/dist/toolDbSignIn.js.map +1 -1
- package/dist/toolDbSignUp.js +33 -52
- package/dist/toolDbSignUp.js.map +1 -1
- package/dist/toolDbSubscribe.d.ts +1 -1
- package/dist/toolDbSubscribe.js +3 -22
- package/dist/toolDbSubscribe.js.map +1 -1
- package/dist/toolDbVerificationWrapper.d.ts +2 -2
- package/dist/toolDbVerificationWrapper.js.map +1 -1
- package/dist/toolchain.d.ts +1 -0
- package/dist/toolchain.js +8 -0
- package/dist/toolchain.js.map +1 -0
- package/dist/tooldb.d.ts +15 -17
- package/dist/tooldb.js +27 -20
- package/dist/tooldb.js.map +1 -1
- package/dist/types/message.d.ts +11 -22
- package/dist/types/message.js +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/types/tooldb.d.ts +0 -19
- package/dist/utils/encoding/uint8ArrayToHex.d.ts +1 -2
- package/dist/utils/encoding/uint8ArrayToHex.js.map +1 -1
- package/dist/utils/encoding/uint8ToBase64.d.ts +1 -2
- package/dist/utils/encoding/uint8ToBase64.js.map +1 -1
- package/dist/utils/sha1.d.ts +1 -1
- package/dist/utils/sha1.js +2 -3
- package/dist/utils/sha1.js.map +1 -1
- package/dist/utils/sha256.d.ts +1 -1
- package/dist/utils/sha256.js +2 -3
- package/dist/utils/sha256.js.map +1 -1
- package/dist/utils/verifyMessage.d.ts +1 -1
- package/dist/utils/verifyMessage.js +8 -7
- package/dist/utils/verifyMessage.js.map +1 -1
- package/dist/utils/verifyPeer.d.ts +2 -2
- package/dist/utils/verifyPeer.js +2 -2
- package/dist/utils/verifyPeer.js.map +1 -1
- package/package.json +5 -6
- package/test-alice/000424.log +0 -0
- package/test-alice/000425.ldb +0 -0
- package/test-alice/CURRENT +1 -1
- package/test-alice/LOG +14 -5
- package/test-alice/LOG.old +5 -5
- package/test-alice/MANIFEST-000422 +0 -0
- package/test-alice-speed/000224.ldb +0 -0
- package/test-alice-speed/000226.ldb +0 -0
- package/test-alice-speed/000229.ldb +0 -0
- package/test-alice-speed/000230.log +0 -0
- package/test-alice-speed/CURRENT +1 -1
- package/test-alice-speed/LOG +5 -1
- package/test-alice-speed/LOG.old +5 -0
- package/test-alice-speed/MANIFEST-000228 +0 -0
- package/test-bob/000424.log +0 -0
- package/test-bob/000425.ldb +0 -0
- package/test-bob/CURRENT +1 -1
- package/test-bob/LOG +14 -5
- package/test-bob/LOG.old +5 -5
- package/test-bob/MANIFEST-000422 +0 -0
- package/test-node-a/000424.log +0 -0
- package/test-node-a/000425.ldb +0 -0
- package/test-node-a/CURRENT +1 -1
- package/test-node-a/LOG +14 -5
- package/test-node-a/LOG.old +5 -5
- package/test-node-a/MANIFEST-000422 +0 -0
- package/test-node-b/000424.log +0 -0
- package/test-node-b/000425.ldb +0 -0
- package/test-node-b/CURRENT +1 -1
- package/test-node-b/LOG +14 -5
- package/test-node-b/LOG.old +5 -5
- package/test-node-b/MANIFEST-000422 +0 -0
- package/test-verify-a/000208.log +0 -0
- package/test-verify-a/CURRENT +1 -1
- package/test-verify-a/LOG +3 -3
- package/test-verify-a/LOG.old +3 -3
- package/test-verify-a/{MANIFEST-000067 → MANIFEST-000207} +0 -0
- package/pvutils-tests-replacement.js +0 -777
- package/test-alice/000087.ldb +0 -0
- package/test-alice/000089.ldb +0 -0
- package/test-alice/000092.ldb +0 -0
- package/test-alice/000093.log +0 -0
- package/test-alice/MANIFEST-000091 +0 -0
- package/test-alice-speed/000003.log +0 -0
- package/test-alice-speed/MANIFEST-000002 +0 -0
- package/test-bob/000087.ldb +0 -0
- package/test-bob/000089.ldb +0 -0
- package/test-bob/000092.ldb +0 -0
- package/test-bob/000093.log +0 -0
- package/test-bob/MANIFEST-000091 +0 -0
- package/test-node-a/000087.ldb +0 -0
- package/test-node-a/000089.ldb +0 -0
- package/test-node-a/000092.ldb +0 -0
- package/test-node-a/000093.log +0 -0
- package/test-node-a/MANIFEST-000091 +0 -0
- package/test-node-b/000087.ldb +0 -0
- package/test-node-b/000089.ldb +0 -0
- package/test-node-b/000092.ldb +0 -0
- package/test-node-b/000093.log +0 -0
- package/test-node-b/MANIFEST-000091 +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
|
|
122
|
+
To retrieve your address; (only if logged in)
|
|
125
123
|
```
|
|
126
|
-
client.
|
|
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
|
|
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 ":" +
|
|
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;
|