@leofcoin/peernet 1.1.57 → 1.1.58
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/.esdoc.json +10 -10
- package/.eslintrc.json +24 -24
- package/.gitattributes +2 -2
- package/.travis.yml +27 -27
- package/BREAKING_CHANGES.md +34 -34
- package/LICENSE +21 -21
- package/README.md +72 -72
- package/deploy.js +8 -8
- package/exports/browser/{index-329e0324.js → index-8868bdd8.js} +1 -1
- package/exports/browser/{messages-000b7f84.js → messages-eb6e5c71.js} +174 -174
- package/exports/browser/{peernet-bfbe6fff.js → peernet-87ea02a4.js} +2005 -1915
- package/exports/browser/peernet.d.ts +13 -11
- package/exports/browser/peernet.js +1 -1
- package/exports/{messages-dc960cb3.js → messages-b9a32987.js} +173 -173
- package/exports/peernet.js +288 -246
- package/exports/src/prompts/password.js +3 -3
- package/exports/store.js +7 -8
- package/exports/types/peernet.d.ts +13 -11
- package/index.html +19 -19
- package/package.json +70 -70
- package/rollup.config.js +76 -69
- package/src/dht/dht.ts +141 -141
- package/src/discovery/peer-discovery.js +75 -75
- package/src/errors/errors.js +12 -12
- package/src/handlers/data.js +11 -11
- package/src/handlers/message.js +34 -34
- package/src/identity.ts +101 -101
- package/src/messages/chat.js +14 -14
- package/src/messages/data-response.js +14 -14
- package/src/messages/data.js +18 -18
- package/src/messages/dht-response.js +14 -14
- package/src/messages/dht.js +22 -22
- package/src/messages/file-link.js +18 -18
- package/src/messages/file.js +18 -18
- package/src/messages/peer-response.js +14 -14
- package/src/messages/peer.js +13 -13
- package/src/messages/peernet.js +14 -14
- package/src/messages/ps.js +13 -13
- package/src/messages/request.js +14 -14
- package/src/messages/response.js +14 -14
- package/src/messages.js +13 -13
- package/src/peer-info.js +9 -9
- package/src/peernet.ts +848 -776
- package/src/prompts/password/node.js +5 -5
- package/src/proto/chat-message.proto.js +6 -6
- package/src/proto/data-response.proto.js +4 -4
- package/src/proto/data.proto.js +4 -4
- package/src/proto/dht-response.proto.js +4 -4
- package/src/proto/dht.proto.js +4 -4
- package/src/proto/file-link.proto.js +5 -5
- package/src/proto/file.proto.js +5 -5
- package/src/proto/peer-response.proto.js +3 -3
- package/src/proto/peer.proto.js +3 -3
- package/src/proto/peernet.proto.js +7 -7
- package/src/proto/ps.proto.js +4 -4
- package/src/proto/request.proto.js +4 -4
- package/src/proto/response.proto.js +3 -3
- package/src/types.ts +27 -27
- package/src/utils/utils.js +78 -78
- package/test/client.js +14 -14
- package/test/codec.js +56 -56
- package/test/hash.js +13 -13
- package/test/index.js +3 -3
- package/test/lastBlock.js +7 -7
- package/test/messages.js +26 -26
- package/test/peernet.js +17 -17
- package/test.js +64 -64
- package/test2.js +9 -9
- package/test3.js +15 -15
- package/test4.js +7 -7
- package/tsconfig.json +12 -12
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
|
|
3
|
-
var node = async () => {
|
|
4
|
-
const answers = await inquirer.prompt({type: 'password', name: 'password', message: 'Enter password'});
|
|
5
|
-
return answers.password
|
|
3
|
+
var node = async () => {
|
|
4
|
+
const answers = await inquirer.prompt({type: 'password', name: 'password', message: 'Enter password'});
|
|
5
|
+
return answers.password
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export { node as default };
|
package/exports/store.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { homedir } from 'os';
|
|
3
|
-
import {
|
|
4
|
-
import { mkdirp } from 'mkdirp';
|
|
3
|
+
import { readdir, mkdir } from 'fs/promises';
|
|
5
4
|
import { ClassicLevel } from 'classic-level';
|
|
6
5
|
|
|
7
6
|
const encode = (string) => {
|
|
@@ -76,16 +75,16 @@ class KeyValue {
|
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
const init = (root, home = true) => {
|
|
78
|
+
const init = async (root, home = true) => {
|
|
80
79
|
let _root = root;
|
|
81
80
|
if (home)
|
|
82
81
|
_root = join(homedir(), root);
|
|
83
|
-
if (
|
|
82
|
+
if (readdir)
|
|
84
83
|
try {
|
|
85
|
-
|
|
84
|
+
await readdir(_root);
|
|
86
85
|
}
|
|
87
86
|
catch (e) {
|
|
88
|
-
|
|
87
|
+
await mkdir(_root, { recursive: true });
|
|
89
88
|
}
|
|
90
89
|
return _root;
|
|
91
90
|
};
|
|
@@ -95,9 +94,9 @@ class Store {
|
|
|
95
94
|
name;
|
|
96
95
|
root;
|
|
97
96
|
version;
|
|
98
|
-
|
|
97
|
+
async init(name, root, version) {
|
|
99
98
|
this.name = name;
|
|
100
|
-
this.root = init(root);
|
|
99
|
+
this.root = await init(root);
|
|
101
100
|
this.version = version;
|
|
102
101
|
this.db = new ClassicLevel(join(this.root, this.name), { valueEncoding: 'view' });
|
|
103
102
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import
|
|
3
|
-
import PubSub from
|
|
4
|
-
import PeerDiscovery from
|
|
5
|
-
import DHT from
|
|
6
|
-
import MessageHandler from
|
|
7
|
-
import LeofcoinStorageClass from
|
|
8
|
-
import Identity from
|
|
9
|
-
import swarm from
|
|
10
|
-
import P2PTPeer from
|
|
2
|
+
import "@vandeurenglenn/debug";
|
|
3
|
+
import PubSub from "@vandeurenglenn/little-pubsub";
|
|
4
|
+
import PeerDiscovery from "./discovery/peer-discovery.js";
|
|
5
|
+
import DHT from "./dht/dht.js";
|
|
6
|
+
import MessageHandler from "./handlers/message.js";
|
|
7
|
+
import LeofcoinStorageClass from "@leofcoin/storage";
|
|
8
|
+
import Identity from "./identity.js";
|
|
9
|
+
import swarm from "@netpeer/p2pt-swarm";
|
|
10
|
+
import P2PTPeer from "@netpeer/p2pt-swarm/peer";
|
|
11
11
|
declare global {
|
|
12
12
|
var LeofcoinStorage: typeof LeofcoinStorageClass;
|
|
13
13
|
var peernet: Peernet;
|
|
@@ -68,11 +68,13 @@ export default class Peernet {
|
|
|
68
68
|
constructor(options: any, password: any);
|
|
69
69
|
get id(): string;
|
|
70
70
|
get selectedAccount(): string;
|
|
71
|
-
get accounts(): Promise<[
|
|
71
|
+
get accounts(): Promise<[
|
|
72
|
+
[name: string, externalAddress: string, internalAddress: string]
|
|
73
|
+
]>;
|
|
72
74
|
get defaultStores(): string[];
|
|
73
75
|
selectAccount(account: string): Promise<void> | Promise<IDBValidKey> | Promise<any[]>;
|
|
74
76
|
addProto(name: any, proto: any): void;
|
|
75
|
-
addCodec(codec: any):
|
|
77
|
+
addCodec(codec: any): void;
|
|
76
78
|
addStore(name: any, prefix: any, root: any, isPrivate?: boolean): Promise<void>;
|
|
77
79
|
/**
|
|
78
80
|
* @see MessageHandler
|
package/index.html
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en" dir="ltr">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title></title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<!-- <script src="./dist/browser/peernet.js">
|
|
9
|
-
</script> -->
|
|
10
|
-
|
|
11
|
-
<script type="module">
|
|
12
|
-
import './exports/browser/peernet.js';
|
|
13
|
-
(async () => {
|
|
14
|
-
const peernet = await new Peernet({network: 'leofcoin:peach', networkVersion: 'peach'})
|
|
15
|
-
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: new TextEncoder().encode(100)}))
|
|
16
|
-
})()
|
|
17
|
-
</script>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" dir="ltr">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title></title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<!-- <script src="./dist/browser/peernet.js">
|
|
9
|
+
</script> -->
|
|
10
|
+
|
|
11
|
+
<script type="module">
|
|
12
|
+
import './exports/browser/peernet.js';
|
|
13
|
+
(async () => {
|
|
14
|
+
const peernet = await new Peernet({network: 'leofcoin:peach', networkVersion: 'peach'})
|
|
15
|
+
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: new TextEncoder().encode(100)}))
|
|
16
|
+
})()
|
|
17
|
+
</script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "src/peernet.js",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"import": "./exports/peernet.js",
|
|
9
|
-
"require": "./exports/commonjs/peernet.js",
|
|
10
|
-
"types": "./exports/types/peernet.d.ts"
|
|
11
|
-
},
|
|
12
|
-
"./browser": "./exports/browser/peernet.js"
|
|
13
|
-
},
|
|
14
|
-
"type": "module",
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=19.0.0"
|
|
17
|
-
},
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "rollup -c",
|
|
20
|
-
"watch": "rollup -c -w",
|
|
21
|
-
"set-flags": "set NODE_OPTIONS=--openssl-legacy-provider",
|
|
22
|
-
"test": "npm run set-flags && node test/index.js",
|
|
23
|
-
"server": "discovery-swarm-webrtc --port=4000",
|
|
24
|
-
"demo": "jsproject --serve ./ --port 6868",
|
|
25
|
-
"lint": "./node_modules/.bin/eslint src/**/**.js --fix"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [],
|
|
28
|
-
"author": "",
|
|
29
|
-
"license": "MIT",
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"@leofcoin/codec-format-interface": "^1.6.0",
|
|
32
|
-
"@leofcoin/codecs": "^1.0.0",
|
|
33
|
-
"@leofcoin/generate-account": "^2.0.0",
|
|
34
|
-
"@leofcoin/identity-utils": "^1.0.2",
|
|
35
|
-
"@leofcoin/multi-wallet": "^3.1.4",
|
|
36
|
-
"@leofcoin/peernet-swarm": "^1.1.0",
|
|
37
|
-
"@leofcoin/storage": "^3.0.0",
|
|
38
|
-
"@netpeer/p2pt-swarm": "^1.3.2",
|
|
39
|
-
"@types/node": "^18.11.18",
|
|
40
|
-
"@vandeurenglenn/base32": "^1.1.0",
|
|
41
|
-
"@vandeurenglenn/base58": "^1.1.0",
|
|
42
|
-
"@vandeurenglenn/debug": "^1.0.0",
|
|
43
|
-
"@vandeurenglenn/is-hex": "^1.0.0",
|
|
44
|
-
"@vandeurenglenn/little-pubsub": "^1.3.1",
|
|
45
|
-
"events": "^3.3.0",
|
|
46
|
-
"inquirer": "^9.1.4",
|
|
47
|
-
"multi-signature": "^1.3.1",
|
|
48
|
-
"qr-scanner": "^1.4.2",
|
|
49
|
-
"qrcode": "^1.5.1",
|
|
50
|
-
"socket-request-client": "^1.5.0",
|
|
51
|
-
"socket-request-server": "^1.5.0"
|
|
52
|
-
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@rollup/plugin-commonjs": "^24.0.1",
|
|
55
|
-
"@rollup/plugin-json": "^6.0.0",
|
|
56
|
-
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
57
|
-
"@rollup/plugin-wasm": "^6.1.1",
|
|
58
|
-
"@types/bs58check": "^2.1.0",
|
|
59
|
-
"@types/qrcode": "^1.5.2",
|
|
60
|
-
"@types/secp256k1": "^4.0.3",
|
|
61
|
-
"@types/varint": "^6.0.1",
|
|
62
|
-
"browserify": "^17.0.0",
|
|
63
|
-
"eslint": "^8.29.0",
|
|
64
|
-
"eslint-plugin-unicorn": "^45.0.1",
|
|
65
|
-
"node-stdlib-browser": "^1.2.0",
|
|
66
|
-
"rollup": "^3.12.0",
|
|
67
|
-
"rollup-plugin-modify": "^3.0.0",
|
|
68
|
-
"webpack-cli": "^5.0.1"
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@leofcoin/peernet",
|
|
3
|
+
"version": "1.1.58",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/peernet.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./exports/peernet.js",
|
|
9
|
+
"require": "./exports/commonjs/peernet.js",
|
|
10
|
+
"types": "./exports/types/peernet.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./browser": "./exports/browser/peernet.js"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=19.0.0"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rollup -c",
|
|
20
|
+
"watch": "rollup -c -w",
|
|
21
|
+
"set-flags": "set NODE_OPTIONS=--openssl-legacy-provider",
|
|
22
|
+
"test": "npm run set-flags && node test/index.js",
|
|
23
|
+
"server": "discovery-swarm-webrtc --port=4000",
|
|
24
|
+
"demo": "jsproject --serve ./ --port 6868",
|
|
25
|
+
"lint": "./node_modules/.bin/eslint src/**/**.js --fix"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [],
|
|
28
|
+
"author": "",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@leofcoin/codec-format-interface": "^1.6.0",
|
|
32
|
+
"@leofcoin/codecs": "^1.0.0",
|
|
33
|
+
"@leofcoin/generate-account": "^2.0.0",
|
|
34
|
+
"@leofcoin/identity-utils": "^1.0.2",
|
|
35
|
+
"@leofcoin/multi-wallet": "^3.1.4",
|
|
36
|
+
"@leofcoin/peernet-swarm": "^1.1.0",
|
|
37
|
+
"@leofcoin/storage": "^3.0.0",
|
|
38
|
+
"@netpeer/p2pt-swarm": "^1.3.2",
|
|
39
|
+
"@types/node": "^18.11.18",
|
|
40
|
+
"@vandeurenglenn/base32": "^1.1.0",
|
|
41
|
+
"@vandeurenglenn/base58": "^1.1.0",
|
|
42
|
+
"@vandeurenglenn/debug": "^1.0.0",
|
|
43
|
+
"@vandeurenglenn/is-hex": "^1.0.0",
|
|
44
|
+
"@vandeurenglenn/little-pubsub": "^1.3.1",
|
|
45
|
+
"events": "^3.3.0",
|
|
46
|
+
"inquirer": "^9.1.4",
|
|
47
|
+
"multi-signature": "^1.3.1",
|
|
48
|
+
"qr-scanner": "^1.4.2",
|
|
49
|
+
"qrcode": "^1.5.1",
|
|
50
|
+
"socket-request-client": "^1.5.0",
|
|
51
|
+
"socket-request-server": "^1.5.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@rollup/plugin-commonjs": "^24.0.1",
|
|
55
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
57
|
+
"@rollup/plugin-wasm": "^6.1.1",
|
|
58
|
+
"@types/bs58check": "^2.1.0",
|
|
59
|
+
"@types/qrcode": "^1.5.2",
|
|
60
|
+
"@types/secp256k1": "^4.0.3",
|
|
61
|
+
"@types/varint": "^6.0.1",
|
|
62
|
+
"browserify": "^17.0.0",
|
|
63
|
+
"eslint": "^8.29.0",
|
|
64
|
+
"eslint-plugin-unicorn": "^45.0.1",
|
|
65
|
+
"node-stdlib-browser": "^1.2.0",
|
|
66
|
+
"rollup": "^3.12.0",
|
|
67
|
+
"rollup-plugin-modify": "^3.0.0",
|
|
68
|
+
"webpack-cli": "^5.0.1"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/rollup.config.js
CHANGED
|
@@ -1,69 +1,76 @@
|
|
|
1
|
-
import resolve, { nodeResolve } from
|
|
2
|
-
import commonjs from
|
|
3
|
-
import json from
|
|
4
|
-
import wasm from
|
|
5
|
-
import rimraf from
|
|
6
|
-
import typescript from
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
1
|
+
import resolve, { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
2
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
3
|
+
import json from "@rollup/plugin-json";
|
|
4
|
+
import wasm from "@rollup/plugin-wasm";
|
|
5
|
+
import rimraf from "rimraf";
|
|
6
|
+
import typescript from "@rollup/plugin-typescript";
|
|
7
|
+
import modify from "rollup-plugin-modify";
|
|
8
|
+
|
|
9
|
+
rimraf.sync("./exports/**");
|
|
10
|
+
|
|
11
|
+
export default [
|
|
12
|
+
{
|
|
13
|
+
input: [
|
|
14
|
+
"./src/peernet.ts",
|
|
15
|
+
"./node_modules/@leofcoin/storage/exports/browser-store.js",
|
|
16
|
+
],
|
|
17
|
+
output: {
|
|
18
|
+
format: "es",
|
|
19
|
+
dir: "./exports/browser",
|
|
20
|
+
},
|
|
21
|
+
plugins: [
|
|
22
|
+
json(),
|
|
23
|
+
wasm(),
|
|
24
|
+
modify({
|
|
25
|
+
"@netpeer/p2pt-swarm": "@netpeer/p2pt-swarm/browser",
|
|
26
|
+
}),
|
|
27
|
+
resolve({
|
|
28
|
+
browser: true,
|
|
29
|
+
preferBuiltins: false,
|
|
30
|
+
mainFields: ["browser", "module", "main"],
|
|
31
|
+
}),
|
|
32
|
+
commonjs({
|
|
33
|
+
mainFields: ["browser", "module", "main"],
|
|
34
|
+
}),
|
|
35
|
+
|
|
36
|
+
typescript({ compilerOptions: { outDir: "./exports/browser" } }),
|
|
37
|
+
],
|
|
38
|
+
external: ["./prompts/password.js"],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
input: [
|
|
42
|
+
"./src/peernet.ts",
|
|
43
|
+
"./node_modules/@leofcoin/storage/exports/store.js",
|
|
44
|
+
],
|
|
45
|
+
output: {
|
|
46
|
+
format: "es",
|
|
47
|
+
dir: "./exports",
|
|
48
|
+
},
|
|
49
|
+
plugins: [
|
|
50
|
+
modify({
|
|
51
|
+
"@netpeer/p2pt-swarm": "@netpeer/p2pt-swarm",
|
|
52
|
+
}),
|
|
53
|
+
typescript({
|
|
54
|
+
compilerOptions: {
|
|
55
|
+
outDir: "./exports",
|
|
56
|
+
declarationDir: "./exports/types",
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
external: ["./prompts/password.js"],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
input: ["./src/prompts/password/browser.js"],
|
|
64
|
+
output: {
|
|
65
|
+
format: "es",
|
|
66
|
+
file: "./exports/browser/src/prompts/password.js",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
input: ["./src/prompts/password/node.js"],
|
|
71
|
+
output: {
|
|
72
|
+
format: "es",
|
|
73
|
+
file: "./exports/src/prompts/password.js",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|