tool-db 2.5.1 → 2.5.3
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 +82 -82
- package/bundle.js +1 -1
- package/dist/adapters-base/networkAdapter.d.ts +58 -58
- package/dist/adapters-base/networkAdapter.js +215 -213
- package/dist/adapters-base/networkAdapter.js.map +1 -1
- package/dist/adapters-base/storageAdapter.d.ts +11 -11
- package/dist/adapters-base/storageAdapter.js +35 -35
- package/dist/adapters-base/userAdapter.d.ts +15 -15
- package/dist/adapters-base/userAdapter.js +41 -41
- package/dist/crdt/baseCrdt.d.ts +9 -9
- package/dist/crdt/baseCrdt.js +26 -26
- package/dist/crdt/counterCrdt.d.ts +30 -30
- package/dist/crdt/counterCrdt.js +105 -105
- package/dist/crdt/listCrdt.d.ts +42 -42
- package/dist/crdt/listCrdt.js +158 -158
- package/dist/crdt/mapCrdt.d.ts +32 -32
- package/dist/crdt/mapCrdt.js +117 -117
- package/dist/index.d.ts +34 -34
- package/dist/index.js +82 -82
- package/dist/logger.d.ts +2 -2
- package/dist/logger.js +28 -28
- package/dist/messageHandlers/handleCrdtGet.d.ts +2 -2
- package/dist/messageHandlers/handleCrdtGet.js +28 -28
- package/dist/messageHandlers/handleCrdtPut.d.ts +2 -2
- package/dist/messageHandlers/handleCrdtPut.js +92 -92
- package/dist/messageHandlers/handleGet.d.ts +2 -2
- package/dist/messageHandlers/handleGet.js +28 -28
- package/dist/messageHandlers/handlePing.d.ts +2 -2
- package/dist/messageHandlers/handlePing.js +35 -35
- package/dist/messageHandlers/handlePong.d.ts +2 -2
- package/dist/messageHandlers/handlePong.js +25 -25
- package/dist/messageHandlers/handlePut.d.ts +2 -2
- package/dist/messageHandlers/handlePut.js +56 -56
- package/dist/messageHandlers/handleQuery.d.ts +2 -2
- package/dist/messageHandlers/handleQuery.js +22 -22
- package/dist/messageHandlers/handleSubscribe.d.ts +2 -2
- package/dist/messageHandlers/handleSubscribe.js +43 -43
- package/dist/server.d.ts +1 -1
- package/dist/server.js +8 -8
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +6 -6
- package/dist/toolDbAnonSignIn.d.ts +2 -2
- package/dist/toolDbAnonSignIn.js +6 -6
- package/dist/toolDbClientOnMessage.d.ts +2 -2
- package/dist/toolDbClientOnMessage.js +58 -58
- package/dist/toolDbCrdtGet.d.ts +9 -9
- package/dist/toolDbCrdtGet.js +76 -76
- package/dist/toolDbCrdtPut.d.ts +9 -9
- package/dist/toolDbCrdtPut.js +62 -62
- package/dist/toolDbGet.d.ts +9 -9
- package/dist/toolDbGet.js +76 -76
- package/dist/toolDbKeysSignIn.d.ts +2 -2
- package/dist/toolDbKeysSignIn.js +15 -15
- package/dist/toolDbPut.d.ts +9 -9
- package/dist/toolDbPut.js +68 -68
- package/dist/toolDbQueryKeys.d.ts +8 -8
- package/dist/toolDbQueryKeys.js +65 -65
- package/dist/toolDbSignIn.d.ts +2 -2
- package/dist/toolDbSignIn.js +26 -26
- package/dist/toolDbSignUp.d.ts +2 -2
- package/dist/toolDbSignUp.js +100 -100
- package/dist/toolDbSubscribe.d.ts +9 -9
- package/dist/toolDbSubscribe.js +49 -49
- package/dist/toolDbVerificationWrapper.d.ts +2 -2
- package/dist/toolDbVerificationWrapper.js +97 -97
- package/dist/tooldb.d.ts +108 -108
- package/dist/tooldb.js +285 -283
- package/dist/tooldb.js.map +1 -1
- package/dist/types/message.d.ts +100 -100
- package/dist/types/message.js +16 -16
- package/dist/types/tooldb.d.ts +84 -79
- package/dist/types/tooldb.js +2 -2
- package/dist/utils/catchReturn.d.ts +1 -1
- package/dist/utils/catchReturn.js +7 -7
- package/dist/utils/encoding/arrayBufferToHex.d.ts +1 -1
- package/dist/utils/encoding/arrayBufferToHex.js +18 -18
- package/dist/utils/encoding/arrayBufferToString.d.ts +1 -1
- package/dist/utils/encoding/arrayBufferToString.js +11 -11
- package/dist/utils/encoding/hexToArrayBuffer.d.ts +1 -1
- package/dist/utils/encoding/hexToArrayBuffer.js +14 -14
- package/dist/utils/encoding/hexToString.d.ts +1 -1
- package/dist/utils/encoding/hexToString.js +11 -11
- package/dist/utils/encoding/hexToUint8.d.ts +1 -1
- package/dist/utils/encoding/hexToUint8.js +7 -7
- package/dist/utils/encoding/stringToArrayBuffer.d.ts +1 -1
- package/dist/utils/encoding/stringToArrayBuffer.js +11 -11
- package/dist/utils/getPeerSignature.d.ts +2 -2
- package/dist/utils/getPeerSignature.js +8 -8
- package/dist/utils/getTimestamp.d.ts +1 -1
- package/dist/utils/getTimestamp.js +6 -6
- package/dist/utils/proofOfWork.d.ts +4 -4
- package/dist/utils/proofOfWork.js +15 -15
- package/dist/utils/randomAnimal.d.ts +1 -1
- package/dist/utils/randomAnimal.js +76 -76
- package/dist/utils/sha1.d.ts +1 -1
- package/dist/utils/sha1.js +12 -12
- package/dist/utils/sha256.d.ts +3 -3
- package/dist/utils/sha256.js +12 -12
- package/dist/utils/textRandom.d.ts +1 -1
- package/dist/utils/textRandom.js +14 -14
- package/dist/utils/uniq.d.ts +1 -1
- package/dist/utils/uniq.js +6 -6
- package/dist/utils/verifyMessage.d.ts +8 -8
- package/dist/utils/verifyMessage.js +128 -128
- package/dist/utils/verifyPeer.d.ts +2 -2
- package/dist/utils/verifyPeer.js +14 -14
- package/lib/adapters-base/networkAdapter.ts +217 -215
- package/lib/adapters-base/storageAdapter.ts +35 -35
- package/lib/adapters-base/userAdapter.ts +49 -49
- package/lib/crdt/baseCrdt.ts +21 -21
- package/lib/crdt/counterCrdt.ts +111 -111
- package/lib/crdt/listCrdt.ts +190 -190
- package/lib/crdt/mapCrdt.ts +119 -119
- package/lib/index.ts +42 -42
- package/lib/logger.ts +30 -30
- package/lib/messageHandlers/handleCrdtGet.ts +29 -29
- package/lib/messageHandlers/handleCrdtPut.ts +118 -118
- package/lib/messageHandlers/handleGet.ts +29 -29
- package/lib/messageHandlers/handlePing.ts +40 -40
- package/lib/messageHandlers/handlePong.ts +30 -30
- package/lib/messageHandlers/handlePut.ts +54 -54
- package/lib/messageHandlers/handleQuery.ts +25 -25
- package/lib/messageHandlers/handleSubscribe.ts +46 -46
- package/lib/server.ts +7 -7
- package/lib/shared.ts +5 -5
- package/lib/toolDbAnonSignIn.ts +5 -5
- package/lib/toolDbClientOnMessage.ts +75 -75
- package/lib/toolDbCrdtGet.ts +82 -82
- package/lib/toolDbCrdtPut.ts +77 -77
- package/lib/toolDbGet.ts +80 -80
- package/lib/toolDbKeysSignIn.ts +16 -16
- package/lib/toolDbPut.ts +83 -83
- package/lib/toolDbQueryKeys.ts +64 -64
- package/lib/toolDbSignIn.ts +31 -31
- package/lib/toolDbSignUp.ts +71 -71
- package/lib/toolDbSubscribe.ts +53 -53
- package/lib/toolDbVerificationWrapper.ts +55 -55
- package/lib/tooldb.ts +316 -314
- package/lib/types/message.ts +133 -133
- package/lib/types/tooldb.ts +97 -89
- package/lib/utils/catchReturn.ts +4 -4
- package/lib/utils/encoding/arrayBufferToHex.ts +18 -18
- package/lib/utils/encoding/arrayBufferToString.ts +8 -8
- package/lib/utils/encoding/hexToArrayBuffer.ts +13 -13
- package/lib/utils/encoding/hexToString.ts +8 -8
- package/lib/utils/encoding/hexToUint8.ts +5 -5
- package/lib/utils/encoding/stringToArrayBuffer.ts +8 -8
- package/lib/utils/getPeerSignature.ts +12 -12
- package/lib/utils/getTimestamp.ts +3 -3
- package/lib/utils/proofOfWork.ts +16 -16
- package/lib/utils/randomAnimal.ts +77 -77
- package/lib/utils/sha1.ts +7 -7
- package/lib/utils/sha256.ts +7 -7
- package/lib/utils/textRandom.ts +11 -11
- package/lib/utils/uniq.ts +3 -3
- package/lib/utils/verifyMessage.ts +88 -88
- package/lib/utils/verifyPeer.ts +15 -15
- package/package.json +2 -2
- package/tsconfig.json +14 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default function proofOfWork(value: string, difficulty: number): Promise<{
|
|
2
|
-
nonce: number;
|
|
3
|
-
hash: string;
|
|
4
|
-
}>;
|
|
1
|
+
export default function proofOfWork(value: string, difficulty: number): Promise<{
|
|
2
|
+
nonce: number;
|
|
3
|
+
hash: string;
|
|
4
|
+
}>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var __1 = require("..");
|
|
4
|
-
function proofOfWork(value, difficulty) {
|
|
5
|
-
return new Promise(function (resolve) {
|
|
6
|
-
var nonce = 0;
|
|
7
|
-
var hash = (0, __1.sha256)("".concat(value).concat(nonce));
|
|
8
|
-
while (hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) {
|
|
9
|
-
nonce += 1;
|
|
10
|
-
hash = (0, __1.sha256)("".concat(value).concat(nonce));
|
|
11
|
-
}
|
|
12
|
-
resolve({ nonce: nonce, hash: hash });
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
exports.default = proofOfWork;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var __1 = require("..");
|
|
4
|
+
function proofOfWork(value, difficulty) {
|
|
5
|
+
return new Promise(function (resolve) {
|
|
6
|
+
var nonce = 0;
|
|
7
|
+
var hash = (0, __1.sha256)("".concat(value).concat(nonce));
|
|
8
|
+
while (hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) {
|
|
9
|
+
nonce += 1;
|
|
10
|
+
hash = (0, __1.sha256)("".concat(value).concat(nonce));
|
|
11
|
+
}
|
|
12
|
+
resolve({ nonce: nonce, hash: hash });
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.default = proofOfWork;
|
|
16
16
|
//# sourceMappingURL=proofOfWork.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function randomAnimal(): string;
|
|
1
|
+
export default function randomAnimal(): string;
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var adjectives = [
|
|
4
|
-
"Fast",
|
|
5
|
-
"Slow",
|
|
6
|
-
"Cute",
|
|
7
|
-
"Evil",
|
|
8
|
-
"Anxious",
|
|
9
|
-
"Cursed",
|
|
10
|
-
"Average",
|
|
11
|
-
"Zombie",
|
|
12
|
-
"Smart",
|
|
13
|
-
"Small",
|
|
14
|
-
"Tall",
|
|
15
|
-
"Amazing",
|
|
16
|
-
"Splendid",
|
|
17
|
-
"Fat",
|
|
18
|
-
"Invisible",
|
|
19
|
-
"Regular",
|
|
20
|
-
"Domestic",
|
|
21
|
-
"Unique",
|
|
22
|
-
"Soft",
|
|
23
|
-
"Lazy",
|
|
24
|
-
"Angry",
|
|
25
|
-
"Relaxed",
|
|
26
|
-
"Huge",
|
|
27
|
-
"Shy",
|
|
28
|
-
"Playful",
|
|
29
|
-
"Creepy",
|
|
30
|
-
"Ancient",
|
|
31
|
-
"Beautiful",
|
|
32
|
-
];
|
|
33
|
-
var animals = [
|
|
34
|
-
"Snake",
|
|
35
|
-
"Monkey",
|
|
36
|
-
"Platypus",
|
|
37
|
-
"Fox",
|
|
38
|
-
"Lynx",
|
|
39
|
-
"Pug",
|
|
40
|
-
"Chicken",
|
|
41
|
-
"Slug",
|
|
42
|
-
"Snail",
|
|
43
|
-
"Pig",
|
|
44
|
-
"Cow",
|
|
45
|
-
"Sheep",
|
|
46
|
-
"Horse",
|
|
47
|
-
"Squirrel",
|
|
48
|
-
"Turtle",
|
|
49
|
-
"Unicorn",
|
|
50
|
-
"Dragon",
|
|
51
|
-
"Dolphin",
|
|
52
|
-
"Cat",
|
|
53
|
-
"Chow Chow",
|
|
54
|
-
"Elephant",
|
|
55
|
-
"Meerkat",
|
|
56
|
-
"Polar Bear",
|
|
57
|
-
"Bear",
|
|
58
|
-
"Rabbit",
|
|
59
|
-
"Koala",
|
|
60
|
-
"Parrot",
|
|
61
|
-
"Raven",
|
|
62
|
-
"Frog",
|
|
63
|
-
"Rat",
|
|
64
|
-
"Mouse",
|
|
65
|
-
"Bee",
|
|
66
|
-
"Tiger",
|
|
67
|
-
"Lion",
|
|
68
|
-
"Giraffe",
|
|
69
|
-
"Ant",
|
|
70
|
-
"Spider",
|
|
71
|
-
"Zebra",
|
|
72
|
-
];
|
|
73
|
-
function randomAnimal() {
|
|
74
|
-
return "".concat(adjectives[Math.floor(Math.random() * adjectives.length)], " ").concat(animals[Math.floor(Math.random() * animals.length)]);
|
|
75
|
-
}
|
|
76
|
-
exports.default = randomAnimal;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var adjectives = [
|
|
4
|
+
"Fast",
|
|
5
|
+
"Slow",
|
|
6
|
+
"Cute",
|
|
7
|
+
"Evil",
|
|
8
|
+
"Anxious",
|
|
9
|
+
"Cursed",
|
|
10
|
+
"Average",
|
|
11
|
+
"Zombie",
|
|
12
|
+
"Smart",
|
|
13
|
+
"Small",
|
|
14
|
+
"Tall",
|
|
15
|
+
"Amazing",
|
|
16
|
+
"Splendid",
|
|
17
|
+
"Fat",
|
|
18
|
+
"Invisible",
|
|
19
|
+
"Regular",
|
|
20
|
+
"Domestic",
|
|
21
|
+
"Unique",
|
|
22
|
+
"Soft",
|
|
23
|
+
"Lazy",
|
|
24
|
+
"Angry",
|
|
25
|
+
"Relaxed",
|
|
26
|
+
"Huge",
|
|
27
|
+
"Shy",
|
|
28
|
+
"Playful",
|
|
29
|
+
"Creepy",
|
|
30
|
+
"Ancient",
|
|
31
|
+
"Beautiful",
|
|
32
|
+
];
|
|
33
|
+
var animals = [
|
|
34
|
+
"Snake",
|
|
35
|
+
"Monkey",
|
|
36
|
+
"Platypus",
|
|
37
|
+
"Fox",
|
|
38
|
+
"Lynx",
|
|
39
|
+
"Pug",
|
|
40
|
+
"Chicken",
|
|
41
|
+
"Slug",
|
|
42
|
+
"Snail",
|
|
43
|
+
"Pig",
|
|
44
|
+
"Cow",
|
|
45
|
+
"Sheep",
|
|
46
|
+
"Horse",
|
|
47
|
+
"Squirrel",
|
|
48
|
+
"Turtle",
|
|
49
|
+
"Unicorn",
|
|
50
|
+
"Dragon",
|
|
51
|
+
"Dolphin",
|
|
52
|
+
"Cat",
|
|
53
|
+
"Chow Chow",
|
|
54
|
+
"Elephant",
|
|
55
|
+
"Meerkat",
|
|
56
|
+
"Polar Bear",
|
|
57
|
+
"Bear",
|
|
58
|
+
"Rabbit",
|
|
59
|
+
"Koala",
|
|
60
|
+
"Parrot",
|
|
61
|
+
"Raven",
|
|
62
|
+
"Frog",
|
|
63
|
+
"Rat",
|
|
64
|
+
"Mouse",
|
|
65
|
+
"Bee",
|
|
66
|
+
"Tiger",
|
|
67
|
+
"Lion",
|
|
68
|
+
"Giraffe",
|
|
69
|
+
"Ant",
|
|
70
|
+
"Spider",
|
|
71
|
+
"Zebra",
|
|
72
|
+
];
|
|
73
|
+
function randomAnimal() {
|
|
74
|
+
return "".concat(adjectives[Math.floor(Math.random() * adjectives.length)], " ").concat(animals[Math.floor(Math.random() * animals.length)]);
|
|
75
|
+
}
|
|
76
|
+
exports.default = randomAnimal;
|
|
77
77
|
//# sourceMappingURL=randomAnimal.js.map
|
package/dist/utils/sha1.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function sha1(str: string): string;
|
|
1
|
+
export default function sha1(str: string): string;
|
package/dist/utils/sha1.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var crypto_1 = __importDefault(require("crypto"));
|
|
7
|
-
function sha1(str) {
|
|
8
|
-
var hash = crypto_1.default.createHash("sha1");
|
|
9
|
-
hash.update(str);
|
|
10
|
-
return hash.digest("hex");
|
|
11
|
-
}
|
|
12
|
-
exports.default = sha1;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
function sha1(str) {
|
|
8
|
+
var hash = crypto_1.default.createHash("sha1");
|
|
9
|
+
hash.update(str);
|
|
10
|
+
return hash.digest("hex");
|
|
11
|
+
}
|
|
12
|
+
exports.default = sha1;
|
|
13
13
|
//# sourceMappingURL=sha1.js.map
|
package/dist/utils/sha256.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { BinaryLike } from "crypto";
|
|
3
|
-
export default function sha256(str: BinaryLike): string;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BinaryLike } from "crypto";
|
|
3
|
+
export default function sha256(str: BinaryLike): string;
|
package/dist/utils/sha256.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var crypto_1 = __importDefault(require("crypto"));
|
|
7
|
-
function sha256(str) {
|
|
8
|
-
var hash = crypto_1.default.createHash("sha256");
|
|
9
|
-
hash.update(str);
|
|
10
|
-
return hash.digest("hex");
|
|
11
|
-
}
|
|
12
|
-
exports.default = sha256;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
function sha256(str) {
|
|
8
|
+
var hash = crypto_1.default.createHash("sha256");
|
|
9
|
+
hash.update(str);
|
|
10
|
+
return hash.digest("hex");
|
|
11
|
+
}
|
|
12
|
+
exports.default = sha256;
|
|
13
13
|
//# sourceMappingURL=sha256.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function textRandom(_l?: number, _c?: string): string;
|
|
1
|
+
export default function textRandom(_l?: number, _c?: string): string;
|
package/dist/utils/textRandom.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function textRandom(_l, _c) {
|
|
4
|
-
if (_l === void 0) { _l = 24; }
|
|
5
|
-
var l = _l;
|
|
6
|
-
var s = "";
|
|
7
|
-
var c = _c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";
|
|
8
|
-
while (l > 0) {
|
|
9
|
-
s += c.charAt(Math.floor(Math.random() * c.length));
|
|
10
|
-
l -= 1;
|
|
11
|
-
}
|
|
12
|
-
return s;
|
|
13
|
-
}
|
|
14
|
-
exports.default = textRandom;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function textRandom(_l, _c) {
|
|
4
|
+
if (_l === void 0) { _l = 24; }
|
|
5
|
+
var l = _l;
|
|
6
|
+
var s = "";
|
|
7
|
+
var c = _c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";
|
|
8
|
+
while (l > 0) {
|
|
9
|
+
s += c.charAt(Math.floor(Math.random() * c.length));
|
|
10
|
+
l -= 1;
|
|
11
|
+
}
|
|
12
|
+
return s;
|
|
13
|
+
}
|
|
14
|
+
exports.default = textRandom;
|
|
15
15
|
//# sourceMappingURL=textRandom.js.map
|
package/dist/utils/uniq.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function uniq<T>(array: T[]): T[];
|
|
1
|
+
export default function uniq<T>(array: T[]): T[];
|
package/dist/utils/uniq.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function uniq(array) {
|
|
4
|
-
return Array.from(new Set(array));
|
|
5
|
-
}
|
|
6
|
-
exports.default = uniq;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function uniq(array) {
|
|
4
|
+
return Array.from(new Set(array));
|
|
5
|
+
}
|
|
6
|
+
exports.default = uniq;
|
|
7
7
|
//# sourceMappingURL=uniq.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ToolDb, VerifyResult, VerificationData } from "..";
|
|
2
|
-
/**
|
|
3
|
-
* Verifies a message validity (PoW, Address, timestamp, signatures)
|
|
4
|
-
* @param msg AnyMessage
|
|
5
|
-
* @param pow amount of proof of work required, number of leading zeroes (default is 0/no pow)
|
|
6
|
-
* @returns boolean or undefined if the message type does not match
|
|
7
|
-
*/
|
|
8
|
-
export default function verifyMessage<T>(this: ToolDb, msg: Partial<VerificationData<T>>, pow?: number): Promise<VerifyResult>;
|
|
1
|
+
import { ToolDb, VerifyResult, VerificationData } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* Verifies a message validity (PoW, Address, timestamp, signatures)
|
|
4
|
+
* @param msg AnyMessage
|
|
5
|
+
* @param pow amount of proof of work required, number of leading zeroes (default is 0/no pow)
|
|
6
|
+
* @returns boolean or undefined if the message type does not match
|
|
7
|
+
*/
|
|
8
|
+
export default function verifyMessage<T>(this: ToolDb, msg: Partial<VerificationData<T>>, pow?: number): Promise<VerifyResult>;
|
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var __1 = require("..");
|
|
40
|
-
/**
|
|
41
|
-
* Verifies a message validity (PoW, Address, timestamp, signatures)
|
|
42
|
-
* @param msg AnyMessage
|
|
43
|
-
* @param pow amount of proof of work required, number of leading zeroes (default is 0/no pow)
|
|
44
|
-
* @returns boolean or undefined if the message type does not match
|
|
45
|
-
*/
|
|
46
|
-
function verifyMessage(msg, pow) {
|
|
47
|
-
if (pow === void 0) { pow = 0; }
|
|
48
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
-
var strData, addressNamespace, key, data, verified, _a;
|
|
50
|
-
return __generator(this, function (_b) {
|
|
51
|
-
switch (_b.label) {
|
|
52
|
-
case 0:
|
|
53
|
-
strData = JSON.stringify(msg.v);
|
|
54
|
-
if (msg.t === undefined ||
|
|
55
|
-
msg.k === undefined ||
|
|
56
|
-
msg.h === undefined ||
|
|
57
|
-
msg.a === undefined ||
|
|
58
|
-
msg.s === undefined ||
|
|
59
|
-
msg.c === undefined) {
|
|
60
|
-
return [2 /*return*/, __1.VerifyResult.InvalidData];
|
|
61
|
-
}
|
|
62
|
-
// Max clock shift allowed is 30 seconds.
|
|
63
|
-
// Ten seconds was my original threshold but it failed some times.
|
|
64
|
-
if (msg.t > new Date().getTime() + 30000) {
|
|
65
|
-
// this.logger("Invalid message timestamp.");
|
|
66
|
-
return [2 /*return*/, __1.VerifyResult.InvalidTimestamp];
|
|
67
|
-
}
|
|
68
|
-
addressNamespace = false;
|
|
69
|
-
if (msg.k.slice(0, 1) == ":") {
|
|
70
|
-
addressNamespace = msg.k.split(".")[0].slice(1);
|
|
71
|
-
}
|
|
72
|
-
if (!(msg.k.slice(0, 2) == "==")) return [3 /*break*/, 2];
|
|
73
|
-
key = msg.k;
|
|
74
|
-
return [4 /*yield*/, this.store
|
|
75
|
-
.get(key)
|
|
76
|
-
.then(function (data) {
|
|
77
|
-
try {
|
|
78
|
-
var message = JSON.parse(data);
|
|
79
|
-
return message;
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
.catch(function () {
|
|
86
|
-
return null;
|
|
87
|
-
})];
|
|
88
|
-
case 1:
|
|
89
|
-
data = _b.sent();
|
|
90
|
-
if (data && data.a !== msg.a)
|
|
91
|
-
return [2 /*return*/, __1.VerifyResult.CantOverwrite];
|
|
92
|
-
_b.label = 2;
|
|
93
|
-
case 2:
|
|
94
|
-
if (addressNamespace && addressNamespace !== msg.a) {
|
|
95
|
-
// this.logger("Provided address does not match");
|
|
96
|
-
return [2 /*return*/, __1.VerifyResult.AddressMismatch];
|
|
97
|
-
}
|
|
98
|
-
// Verify hash and nonce (adjust zeroes for difficulty of the network)
|
|
99
|
-
// While this POW does not enforce security per-se, it does make it harder
|
|
100
|
-
// for attackers to spam the network, and could be adjusted by peers.
|
|
101
|
-
// Disabled for now because it is painful on large requests
|
|
102
|
-
if (pow > 0) {
|
|
103
|
-
if (msg.h.slice(0, pow) !== new Array(pow).fill("0").join("")) {
|
|
104
|
-
// this.logger("No valid hash (no pow)");
|
|
105
|
-
return [2 /*return*/, __1.VerifyResult.NoProofOfWork];
|
|
106
|
-
}
|
|
107
|
-
if ((0, __1.sha256)("".concat(strData).concat(msg.a).concat(msg.t).concat(msg.n)) !== msg.h) {
|
|
108
|
-
// this.logger("Specified hash does not generate a valid pow");
|
|
109
|
-
return [2 /*return*/, __1.VerifyResult.InvalidHashNonce];
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (!this.userAccount) return [3 /*break*/, 4];
|
|
113
|
-
return [4 /*yield*/, this.userAccount.verifySignature(msg)];
|
|
114
|
-
case 3:
|
|
115
|
-
_a = _b.sent();
|
|
116
|
-
return [3 /*break*/, 5];
|
|
117
|
-
case 4:
|
|
118
|
-
_a = false;
|
|
119
|
-
_b.label = 5;
|
|
120
|
-
case 5:
|
|
121
|
-
verified = _a;
|
|
122
|
-
// this.logger(`Signature validation: ${verified ? "Sucess" : "Failed"}`);
|
|
123
|
-
return [2 /*return*/, verified ? __1.VerifyResult.Verified : __1.VerifyResult.InvalidSignature];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
exports.default = verifyMessage;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var __1 = require("..");
|
|
40
|
+
/**
|
|
41
|
+
* Verifies a message validity (PoW, Address, timestamp, signatures)
|
|
42
|
+
* @param msg AnyMessage
|
|
43
|
+
* @param pow amount of proof of work required, number of leading zeroes (default is 0/no pow)
|
|
44
|
+
* @returns boolean or undefined if the message type does not match
|
|
45
|
+
*/
|
|
46
|
+
function verifyMessage(msg, pow) {
|
|
47
|
+
if (pow === void 0) { pow = 0; }
|
|
48
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
var strData, addressNamespace, key, data, verified, _a;
|
|
50
|
+
return __generator(this, function (_b) {
|
|
51
|
+
switch (_b.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
strData = JSON.stringify(msg.v);
|
|
54
|
+
if (msg.t === undefined ||
|
|
55
|
+
msg.k === undefined ||
|
|
56
|
+
msg.h === undefined ||
|
|
57
|
+
msg.a === undefined ||
|
|
58
|
+
msg.s === undefined ||
|
|
59
|
+
msg.c === undefined) {
|
|
60
|
+
return [2 /*return*/, __1.VerifyResult.InvalidData];
|
|
61
|
+
}
|
|
62
|
+
// Max clock shift allowed is 30 seconds.
|
|
63
|
+
// Ten seconds was my original threshold but it failed some times.
|
|
64
|
+
if (msg.t > new Date().getTime() + 30000) {
|
|
65
|
+
// this.logger("Invalid message timestamp.");
|
|
66
|
+
return [2 /*return*/, __1.VerifyResult.InvalidTimestamp];
|
|
67
|
+
}
|
|
68
|
+
addressNamespace = false;
|
|
69
|
+
if (msg.k.slice(0, 1) == ":") {
|
|
70
|
+
addressNamespace = msg.k.split(".")[0].slice(1);
|
|
71
|
+
}
|
|
72
|
+
if (!(msg.k.slice(0, 2) == "==")) return [3 /*break*/, 2];
|
|
73
|
+
key = msg.k;
|
|
74
|
+
return [4 /*yield*/, this.store
|
|
75
|
+
.get(key)
|
|
76
|
+
.then(function (data) {
|
|
77
|
+
try {
|
|
78
|
+
var message = JSON.parse(data);
|
|
79
|
+
return message;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
.catch(function () {
|
|
86
|
+
return null;
|
|
87
|
+
})];
|
|
88
|
+
case 1:
|
|
89
|
+
data = _b.sent();
|
|
90
|
+
if (data && data.a !== msg.a)
|
|
91
|
+
return [2 /*return*/, __1.VerifyResult.CantOverwrite];
|
|
92
|
+
_b.label = 2;
|
|
93
|
+
case 2:
|
|
94
|
+
if (addressNamespace && addressNamespace !== msg.a) {
|
|
95
|
+
// this.logger("Provided address does not match");
|
|
96
|
+
return [2 /*return*/, __1.VerifyResult.AddressMismatch];
|
|
97
|
+
}
|
|
98
|
+
// Verify hash and nonce (adjust zeroes for difficulty of the network)
|
|
99
|
+
// While this POW does not enforce security per-se, it does make it harder
|
|
100
|
+
// for attackers to spam the network, and could be adjusted by peers.
|
|
101
|
+
// Disabled for now because it is painful on large requests
|
|
102
|
+
if (pow > 0) {
|
|
103
|
+
if (msg.h.slice(0, pow) !== new Array(pow).fill("0").join("")) {
|
|
104
|
+
// this.logger("No valid hash (no pow)");
|
|
105
|
+
return [2 /*return*/, __1.VerifyResult.NoProofOfWork];
|
|
106
|
+
}
|
|
107
|
+
if ((0, __1.sha256)("".concat(strData).concat(msg.a).concat(msg.t).concat(msg.n)) !== msg.h) {
|
|
108
|
+
// this.logger("Specified hash does not generate a valid pow");
|
|
109
|
+
return [2 /*return*/, __1.VerifyResult.InvalidHashNonce];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!this.userAccount) return [3 /*break*/, 4];
|
|
113
|
+
return [4 /*yield*/, this.userAccount.verifySignature(msg)];
|
|
114
|
+
case 3:
|
|
115
|
+
_a = _b.sent();
|
|
116
|
+
return [3 /*break*/, 5];
|
|
117
|
+
case 4:
|
|
118
|
+
_a = false;
|
|
119
|
+
_b.label = 5;
|
|
120
|
+
case 5:
|
|
121
|
+
verified = _a;
|
|
122
|
+
// this.logger(`Signature validation: ${verified ? "Sucess" : "Failed"}`);
|
|
123
|
+
return [2 /*return*/, verified ? __1.VerifyResult.Verified : __1.VerifyResult.InvalidSignature];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
exports.default = verifyMessage;
|
|
129
129
|
//# sourceMappingURL=verifyMessage.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ToolDb, Peer } from "..";
|
|
2
|
-
export default function verifyPeer(tooldb: ToolDb, peer: Peer): Promise<import("..").VerifyResult>;
|
|
1
|
+
import { ToolDb, Peer } from "..";
|
|
2
|
+
export default function verifyPeer(tooldb: ToolDb, peer: Peer): Promise<import("..").VerifyResult>;
|
package/dist/utils/verifyPeer.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var __1 = require("..");
|
|
4
|
-
function verifyPeer(tooldb, peer) {
|
|
5
|
-
var data = (0, __1.sha256)("".concat(peer.topic, "-").concat(peer.timestamp, "-").concat(peer.host, ":").concat(peer.port));
|
|
6
|
-
// its not really a message but this function works with a Partial
|
|
7
|
-
// I want to keep it like this so the signature verification is in a single place
|
|
8
|
-
return tooldb.verifyMessage({
|
|
9
|
-
h: data,
|
|
10
|
-
a: peer.address,
|
|
11
|
-
s: peer.sig,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
exports.default = verifyPeer;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var __1 = require("..");
|
|
4
|
+
function verifyPeer(tooldb, peer) {
|
|
5
|
+
var data = (0, __1.sha256)("".concat(peer.topic, "-").concat(peer.timestamp, "-").concat(peer.host, ":").concat(peer.port));
|
|
6
|
+
// its not really a message but this function works with a Partial
|
|
7
|
+
// I want to keep it like this so the signature verification is in a single place
|
|
8
|
+
return tooldb.verifyMessage({
|
|
9
|
+
h: data,
|
|
10
|
+
a: peer.address,
|
|
11
|
+
s: peer.sig,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.default = verifyPeer;
|
|
15
15
|
//# sourceMappingURL=verifyPeer.js.map
|