tool-db 1.4.5 → 2.0.2
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 +21 -45
- package/bundle.js +85559 -44902
- package/dist/chain/Block.d.ts +3 -2
- package/dist/chain/Block.js +12 -1
- package/dist/chain/Block.js.map +1 -1
- package/dist/chain/ToolChain.d.ts +6 -4
- package/dist/chain/ToolChain.js +35 -13
- package/dist/chain/ToolChain.js.map +1 -1
- package/dist/chain/Tx.d.ts +34 -0
- package/dist/chain/Tx.js +111 -0
- package/dist/chain/Tx.js.map +1 -0
- 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 +9 -24
- package/dist/index.js +19 -64
- package/dist/index.js.map +1 -1
- package/dist/loadCrdtDocument.js +4 -9
- package/dist/loadCrdtDocument.js.map +1 -1
- package/dist/messageHandlers/handleCrdt.d.ts +2 -1
- package/dist/messageHandlers/handleCrdt.js +1 -5
- package/dist/messageHandlers/handleCrdt.js.map +1 -1
- package/dist/messageHandlers/handleCrdtGet.d.ts +2 -1
- package/dist/messageHandlers/handleCrdtGet.js +21 -14
- package/dist/messageHandlers/handleCrdtGet.js.map +1 -1
- package/dist/messageHandlers/handleCrdtPut.d.ts +2 -1
- package/dist/messageHandlers/handleCrdtPut.js +52 -65
- package/dist/messageHandlers/handleCrdtPut.js.map +1 -1
- package/dist/messageHandlers/handleGet.d.ts +2 -1
- package/dist/messageHandlers/handleGet.js +1 -1
- package/dist/messageHandlers/handleGet.js.map +1 -1
- package/dist/messageHandlers/handleJoin.d.ts +2 -1
- package/dist/messageHandlers/handleJoin.js +20 -24
- package/dist/messageHandlers/handleJoin.js.map +1 -1
- package/dist/messageHandlers/handlePing.d.ts +2 -1
- package/dist/messageHandlers/handlePing.js +10 -3
- package/dist/messageHandlers/handlePing.js.map +1 -1
- package/dist/messageHandlers/handlePong.d.ts +2 -1
- package/dist/messageHandlers/handlePong.js +22 -20
- package/dist/messageHandlers/handlePong.js.map +1 -1
- package/dist/messageHandlers/handlePut.d.ts +2 -1
- package/dist/messageHandlers/handlePut.js +3 -2
- package/dist/messageHandlers/handlePut.js.map +1 -1
- package/dist/messageHandlers/handleQuery.d.ts +2 -1
- package/dist/messageHandlers/handleQuery.js.map +1 -1
- package/dist/messageHandlers/handleServers.d.ts +2 -1
- package/dist/messageHandlers/handleServers.js +8 -9
- package/dist/messageHandlers/handleServers.js.map +1 -1
- package/dist/messageHandlers/handleSubscribe.d.ts +2 -1
- package/dist/messageHandlers/handleSubscribe.js +1 -20
- package/dist/messageHandlers/handleSubscribe.js.map +1 -1
- package/dist/toolDbAnonSignIn.d.ts +1 -4
- package/dist/toolDbAnonSignIn.js +2 -16
- package/dist/toolDbAnonSignIn.js.map +1 -1
- package/dist/toolDbClientOnMessage.js +3 -7
- package/dist/toolDbClientOnMessage.js.map +1 -1
- package/dist/toolDbCrdtGet.d.ts +4 -2
- package/dist/toolDbCrdtGet.js +26 -11
- package/dist/toolDbCrdtGet.js.map +1 -1
- package/dist/toolDbCrdtPut.d.ts +3 -3
- package/dist/toolDbCrdtPut.js +24 -69
- package/dist/toolDbCrdtPut.js.map +1 -1
- package/dist/toolDbGet.d.ts +1 -1
- package/dist/toolDbGet.js +3 -4
- package/dist/toolDbGet.js.map +1 -1
- package/dist/toolDbKeysSignIn.d.ts +1 -7
- package/dist/toolDbKeysSignIn.js +5 -18
- package/dist/toolDbKeysSignIn.js.map +1 -1
- package/dist/toolDbNetwork.js +7 -5
- package/dist/toolDbNetwork.js.map +1 -1
- package/dist/toolDbPut.d.ts +1 -1
- package/dist/toolDbPut.js +27 -73
- package/dist/toolDbPut.js.map +1 -1
- package/dist/toolDbQueryKeys.js +2 -3
- package/dist/toolDbQueryKeys.js.map +1 -1
- package/dist/toolDbSignIn.d.ts +2 -4
- package/dist/toolDbSignIn.js +7 -113
- package/dist/toolDbSignIn.js.map +1 -1
- package/dist/toolDbSignUp.d.ts +1 -1
- package/dist/toolDbSignUp.js +37 -70
- 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.js +23 -10
- package/dist/toolDbVerificationWrapper.js.map +1 -1
- package/dist/toolDbWebrtc.js +68 -16
- package/dist/toolDbWebrtc.js.map +1 -1
- package/dist/tooldb.d.ts +26 -25
- package/dist/tooldb.js +45 -40
- package/dist/tooldb.js.map +1 -1
- package/dist/types/message.d.ts +36 -10
- package/dist/types/message.js +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/types/tooldb.d.ts +53 -11
- package/dist/types/tooldb.js.map +1 -1
- package/dist/utils/crypto/decodeKeyString.d.ts +1 -1
- package/dist/utils/crypto/decodeKeyString.js +3 -4
- package/dist/utils/crypto/decodeKeyString.js.map +1 -1
- package/dist/utils/crypto/decryptData.js +3 -3
- package/dist/utils/crypto/decryptData.js.map +1 -1
- package/dist/utils/crypto/decryptWithPass.d.ts +1 -1
- package/dist/utils/crypto/decryptWithPass.js +2 -3
- package/dist/utils/crypto/decryptWithPass.js.map +1 -1
- package/dist/utils/crypto/encodeKeyString.js +3 -4
- package/dist/utils/crypto/encodeKeyString.js.map +1 -1
- package/dist/utils/crypto/encryptData.d.ts +1 -1
- package/dist/utils/crypto/encryptData.js +1 -6
- package/dist/utils/crypto/encryptData.js.map +1 -1
- package/dist/utils/crypto/encryptWithPass.d.ts +1 -1
- package/dist/utils/crypto/encryptWithPass.js +1 -5
- package/dist/utils/crypto/encryptWithPass.js.map +1 -1
- package/dist/utils/crypto/generateKeyFromPassword.js +1 -1
- package/dist/utils/crypto/generateKeyFromPassword.js.map +1 -1
- package/dist/utils/crypto/loadKeysComb.js +10 -10
- package/dist/utils/crypto/loadKeysComb.js.map +1 -1
- package/dist/utils/crypto/recoverPubKey.d.ts +1 -1
- package/dist/utils/crypto/recoverPubKey.js +12 -6
- package/dist/utils/crypto/recoverPubKey.js.map +1 -1
- package/dist/utils/crypto/saveSignKeys.d.ts +1 -1
- package/dist/utils/crypto/saveSignKeys.js +2 -2
- package/dist/utils/crypto/verifyData.js +1 -1
- package/dist/utils/crypto/verifyData.js.map +1 -1
- package/dist/utils/encoding/arrayBufferToHex.js +1 -1
- package/dist/utils/encoding/base64ToHex.js +1 -1
- package/dist/utils/encoding/uint8ArrayToHex.d.ts +1 -2
- package/dist/utils/encoding/uint8ArrayToHex.js +1 -1
- 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/getPeerSignature.d.ts +2 -1
- package/dist/utils/getPeerSignature.js +7 -4
- package/dist/utils/getPeerSignature.js.map +1 -1
- package/dist/utils/leveldb.js +2 -0
- package/dist/utils/leveldb.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/signData.js +1 -1
- package/dist/utils/signData.js.map +1 -1
- package/dist/utils/verifyMessage.d.ts +1 -1
- package/dist/utils/verifyMessage.js +12 -21
- package/dist/utils/verifyMessage.js.map +1 -1
- package/dist/utils/verifyPeer.d.ts +2 -1
- package/dist/utils/verifyPeer.js +9 -8
- package/dist/utils/verifyPeer.js.map +1 -1
- package/package.json +3 -3
- package/test-alice/000269.ldb +0 -0
- package/test-alice/000271.ldb +0 -0
- package/test-alice/000274.ldb +0 -0
- package/test-alice/000277.ldb +0 -0
- package/test-alice/000278.log +0 -0
- package/test-alice/CURRENT +1 -1
- package/test-alice/LOG +5 -5
- package/test-alice/LOG.old +5 -5
- package/test-alice/MANIFEST-000276 +0 -0
- package/test-alice-speed/000185.ldb +0 -0
- package/test-alice-speed/000187.ldb +0 -0
- package/test-alice-speed/000188.log +0 -0
- package/test-alice-speed/CURRENT +1 -0
- package/{test-keys-a → test-alice-speed}/LOCK +0 -0
- package/test-alice-speed/LOG +5 -0
- package/test-alice-speed/LOG.old +14 -0
- package/test-alice-speed/MANIFEST-000186 +0 -0
- package/test-bob/000269.ldb +0 -0
- package/test-bob/000271.ldb +0 -0
- package/test-bob/000274.ldb +0 -0
- package/test-bob/000277.ldb +0 -0
- package/test-bob/000278.log +0 -0
- package/test-bob/CURRENT +1 -1
- package/test-bob/LOG +5 -5
- package/test-bob/LOG.old +5 -5
- package/test-bob/MANIFEST-000276 +0 -0
- package/test-node-a/000269.ldb +0 -0
- package/test-node-a/000271.ldb +0 -0
- package/test-node-a/000274.ldb +0 -0
- package/test-node-a/000277.ldb +0 -0
- package/test-node-a/000278.log +0 -0
- package/test-node-a/CURRENT +1 -1
- package/test-node-a/LOG +5 -5
- package/test-node-a/LOG.old +5 -5
- package/test-node-a/MANIFEST-000276 +0 -0
- package/test-node-b/000269.ldb +0 -0
- package/test-node-b/000271.ldb +0 -0
- package/test-node-b/000274.ldb +0 -0
- package/test-node-b/000277.ldb +0 -0
- package/test-node-b/000278.log +0 -0
- package/test-node-b/CURRENT +1 -1
- package/test-node-b/LOG +5 -5
- package/test-node-b/LOG.old +5 -5
- package/test-node-b/MANIFEST-000276 +0 -0
- package/test-verify-a/000026.ldb +0 -0
- package/test-verify-a/000029.ldb +0 -0
- package/test-verify-a/000031.ldb +0 -0
- package/test-verify-a/000033.ldb +0 -0
- package/{test-keys-a/000593.log → test-verify-a/000182.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-000181 +0 -0
- package/test-alice/000858.ldb +0 -0
- package/test-alice/000860.ldb +0 -0
- package/test-alice/000863.ldb +0 -0
- package/test-alice/000864.log +0 -0
- package/test-alice/MANIFEST-000862 +0 -0
- package/test-bob/000785.ldb +0 -0
- package/test-bob/000787.ldb +0 -0
- package/test-bob/000790.ldb +0 -0
- package/test-bob/000791.log +0 -0
- package/test-bob/MANIFEST-000789 +0 -0
- package/test-keys-a/CURRENT +0 -1
- package/test-keys-a/LOG +0 -3
- package/test-keys-a/LOG.old +0 -3
- package/test-keys-a/MANIFEST-000592 +0 -0
- package/test-keys-b/000593.log +0 -0
- package/test-keys-b/CURRENT +0 -1
- package/test-keys-b/LOCK +0 -0
- package/test-keys-b/LOG +0 -3
- package/test-keys-b/LOG.old +0 -3
- package/test-keys-b/MANIFEST-000592 +0 -0
- package/test-node-a/000871.ldb +0 -0
- package/test-node-a/000873.ldb +0 -0
- package/test-node-a/000876.ldb +0 -0
- package/test-node-a/000879.ldb +0 -0
- package/test-node-a/000880.log +0 -0
- package/test-node-a/MANIFEST-000878 +0 -0
- package/test-node-b/000871.ldb +0 -0
- package/test-node-b/000873.ldb +0 -0
- package/test-node-b/000876.ldb +0 -0
- package/test-node-b/000879.ldb +0 -0
- package/test-node-b/000880.log +0 -0
- package/test-node-b/MANIFEST-000878 +0 -0
- package/test-verify-a/000725.log +0 -0
- package/test-verify-a/MANIFEST-000724 +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
|
|
|
@@ -57,34 +63,34 @@ These are the options you can pass to the constructor:
|
|
|
57
63
|
|
|
58
64
|
```
|
|
59
65
|
{
|
|
60
|
-
// Database name to use
|
|
66
|
+
// Database name to use (default "tooldb")
|
|
61
67
|
db: string;
|
|
62
68
|
|
|
63
|
-
// Show debug console logs
|
|
69
|
+
// Show debug console logs (default false)
|
|
64
70
|
debug: boolean;
|
|
65
71
|
|
|
66
72
|
// Array of peers to connect to, each one in the form of { host: "127.0.0.1", port: 9000 }
|
|
67
73
|
peers: { host: "127.0.0.1", port: 9000 }[];
|
|
68
74
|
|
|
69
|
-
// Max number of tries when a connection fails
|
|
75
|
+
// Max number of tries when a connection fails (default 5)
|
|
70
76
|
maxRetries: number;
|
|
71
77
|
|
|
72
|
-
// How long to wait (max) for a debounced key listener recv
|
|
78
|
+
// How long to wait (max) for a debounced key listener recv (default 100)
|
|
73
79
|
triggerDebouce: number;
|
|
74
80
|
|
|
75
|
-
// How long to wait between retries
|
|
81
|
+
// How long to wait between retries (default 2000)
|
|
76
82
|
wait: number;
|
|
77
83
|
|
|
78
|
-
// If you want to force a Proof of Work on all messages, set how much (zero is no POW)
|
|
84
|
+
// If you want to force a Proof of Work on all messages, set how much (zero is no POW, default 0)
|
|
79
85
|
pow: number;
|
|
80
86
|
|
|
81
|
-
//
|
|
87
|
+
// Whether we are a server or not (default false)
|
|
82
88
|
server: boolean;
|
|
83
89
|
|
|
84
90
|
// Our hostname (server only)
|
|
85
91
|
host: string
|
|
86
92
|
|
|
87
|
-
// Port to listen incoming connections (server only)
|
|
93
|
+
// Port to listen incoming connections (server only, default is 8080)
|
|
88
94
|
port: number;
|
|
89
95
|
|
|
90
96
|
// A server instance like Express (server only)
|
|
@@ -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
|
-
//
|
|
103
|
-
id: string;
|
|
104
|
-
|
|
105
|
-
// The namespace/topic of our app
|
|
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,11 +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.
|
|
127
|
-
// or
|
|
128
|
-
client.user?.pubKey
|
|
124
|
+
client.getAddress();
|
|
129
125
|
```
|
|
130
126
|
|
|
131
127
|
You can check if you are correctly logged in by checking if the user field exists or not;
|
|
@@ -149,7 +145,7 @@ You can use `client.getUserNamespacedKey(key)` to convert any key to a private n
|
|
|
149
145
|
|
|
150
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.
|
|
151
147
|
|
|
152
|
-
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.
|
|
153
149
|
```
|
|
154
150
|
const listenerId = client.addKeyListener("value", console.log);
|
|
155
151
|
client.removeKeyListener(listenerId);
|
|
@@ -181,7 +177,7 @@ client.queryKeys(keyPrefix, userNamespaced?, timeout?).then()
|
|
|
181
177
|
```
|
|
182
178
|
|
|
183
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.
|
|
184
|
-
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.
|
|
185
181
|
|
|
186
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.
|
|
187
183
|
|
|
@@ -195,31 +191,11 @@ client.subscribeData("key", userNamespaced?);
|
|
|
195
191
|
|
|
196
192
|
This will relay back to you all Put and CrdtPut messages on that key.
|
|
197
193
|
|
|
198
|
-
When subscribing to a CRDT document you will need to load the data like so;
|
|
199
|
-
```
|
|
200
|
-
window.toolDb.addKeyListener("documentKey", handleDocumentKeyCrdt);
|
|
201
|
-
function handleDocumentKeyCrdt(msg) {
|
|
202
|
-
if (msg && msg.type === "crdt") {
|
|
203
|
-
// Load the document from the message (msg.doc)
|
|
204
|
-
const incomingDocument = Automerge.load(
|
|
205
|
-
base64ToBinaryDocument(msg.doc)
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
if (globalData.myCrdtDocument) {
|
|
209
|
-
// Merge the local doc vs the incoming one and store it somewhere locally
|
|
210
|
-
globalData.myCrdtDocument = Automerge.merge(globalData.myCrdtDocument, incomingDocument);
|
|
211
|
-
} else {
|
|
212
|
-
// New document! Just store it
|
|
213
|
-
globalData.myCrdtDocument = incomingDocument;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
```
|
|
218
|
-
|
|
219
194
|
## Events
|
|
220
195
|
|
|
221
196
|
If you need to check when you are connected to a server peer or not you can use the following method replacements;
|
|
197
|
+
|
|
222
198
|
```
|
|
223
|
-
client.onConnect = () => { /* Your code here */ };
|
|
199
|
+
client.onConnect = (remotePeerId: string) => { /* Your code here */ };
|
|
224
200
|
client.onDisconnect = () => { /* Your code here */ };
|
|
225
201
|
```
|