@leofcoin/peernet 0.12.1 → 0.12.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/dist/browser/generate-account.js +50 -0
- package/dist/browser/messages.js +439 -0
- package/dist/browser/pako.js +6731 -0
- package/dist/browser/peernet-swarm.js +836 -0
- package/dist/browser/peernet.js +7827 -51606
- package/dist/browser/{160.peernet.js → protons.js} +4 -27
- package/dist/browser/storage.js +12 -0
- package/dist/browser/wrtc.js +28 -0
- package/dist/commonjs/dht-6a1b6246.js +45 -0
- package/dist/commonjs/dht-response-e4a603ea.js +34 -0
- package/dist/commonjs/dht-response.js +3 -23
- package/dist/commonjs/dht.js +3 -34
- package/dist/commonjs/messages-bcb02ee9.js +189 -0
- package/dist/commonjs/{peernet-message.js → peernet-6eef77d5.js} +7 -1
- package/dist/commonjs/peernet.js +42 -1375
- package/dist/commonjs/peernet2.js +8 -0
- package/dist/commonjs/request-95ed03ec.js +33 -0
- package/dist/commonjs/request.js +3 -22
- package/dist/commonjs/response-bae4e2a2.js +33 -0
- package/dist/commonjs/response.js +3 -22
- package/dist/module/messages-421f88db.js +323 -0
- package/dist/module/peernet.js +35 -1479
- package/package.json +7 -11
- package/rollup.config.js +2 -21
- package/src/handlers/message.js +4 -5
- package/src/messages/{chat-message.js → chat.js} +0 -0
- package/src/messages/{peernet-message.js → peernet.js} +0 -0
- package/src/messages.js +11 -0
- package/src/peernet.js +33 -23
- package/webpack.config.js +6 -3
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/commonjs/peernet.js",
|
|
6
|
-
"module": "
|
|
7
|
-
"browser": "dist/browser/peernet.js",
|
|
6
|
+
"module": "src/module/peernet.js",
|
|
8
7
|
"scripts": {
|
|
9
8
|
"build": "npm run c && webpack",
|
|
10
9
|
"test": "node test/index.js",
|
|
@@ -23,13 +22,14 @@
|
|
|
23
22
|
"license": "MIT",
|
|
24
23
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"@leofcoin/codec-format-interface": "^1.
|
|
27
|
-
"@leofcoin/generate-account": "^1.0.
|
|
25
|
+
"@leofcoin/codec-format-interface": "^1.2.0",
|
|
26
|
+
"@leofcoin/generate-account": "^1.0.4",
|
|
28
27
|
"@leofcoin/multi-wallet": "^2.1.2",
|
|
29
|
-
"@leofcoin/peernet-swarm": "^0.3.
|
|
28
|
+
"@leofcoin/peernet-swarm": "^0.3.3",
|
|
30
29
|
"@leofcoin/storage": "^2.3.0",
|
|
31
30
|
"@vandeurenglenn/base32": "^1.1.0",
|
|
32
31
|
"@vandeurenglenn/base58": "^1.1.0",
|
|
32
|
+
"@vandeurenglenn/debug": "^1.0.0",
|
|
33
33
|
"@vandeurenglenn/is-hex": "^1.0.0",
|
|
34
34
|
"@vandeurenglenn/little-pubsub": "^1.3.1",
|
|
35
35
|
"keccak": "^3.0.1",
|
|
@@ -41,10 +41,7 @@
|
|
|
41
41
|
"varint": "^6.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@babel/plugin-proposal-private-methods": "^7.16.11",
|
|
45
|
-
"@rollup/plugin-eslint": "^8.0.1",
|
|
46
44
|
"@rollup/plugin-json": "^4.1.0",
|
|
47
|
-
"@vandeurenglenn/debug": "^1.0.0",
|
|
48
45
|
"coveralls": "^3.1.1",
|
|
49
46
|
"eslint": "^7.31.0",
|
|
50
47
|
"eslint-config-google": "^0.14.0",
|
|
@@ -56,7 +53,6 @@
|
|
|
56
53
|
"tape": "^5.2.2",
|
|
57
54
|
"vm-browserify": "^1.1.2",
|
|
58
55
|
"webpack": "^5.72.0",
|
|
59
|
-
"webpack-cli": "^4.9.2"
|
|
60
|
-
"webpack-node-externals": "^3.0.0"
|
|
56
|
+
"webpack-cli": "^4.9.2"
|
|
61
57
|
}
|
|
62
58
|
}
|
package/rollup.config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
-
import lint from '@rollup/plugin-eslint'
|
|
3
2
|
import json from '@rollup/plugin-json'
|
|
4
3
|
import modify from 'rollup-plugin-modify'
|
|
5
4
|
|
|
@@ -10,7 +9,7 @@ try {
|
|
|
10
9
|
}
|
|
11
10
|
export default [{
|
|
12
11
|
input: ['src/peernet.js', 'src/messages/dht.js',
|
|
13
|
-
'src/messages/peernet
|
|
12
|
+
'src/messages/peernet.js', 'src/messages/dht-response.js', 'src/messages/request.js',
|
|
14
13
|
'src/messages/response.js'],
|
|
15
14
|
output: {
|
|
16
15
|
dir: 'dist/commonjs',
|
|
@@ -26,25 +25,7 @@ export default [{
|
|
|
26
25
|
}, {
|
|
27
26
|
input: 'src/peernet.js',
|
|
28
27
|
output: {
|
|
29
|
-
dir: 'dist/
|
|
30
|
-
format: 'cjs'
|
|
31
|
-
},
|
|
32
|
-
plugins: [
|
|
33
|
-
json(),
|
|
34
|
-
modify({
|
|
35
|
-
"import fetch from 'node-fetch'": '',
|
|
36
|
-
HTTP_IMPORT: ``,
|
|
37
|
-
SUBTLE_IMPORT: `const { subtle } = crypto`
|
|
38
|
-
}),
|
|
39
|
-
// lint({
|
|
40
|
-
// fix: true,
|
|
41
|
-
// exclude: ['package.json', "package-lock.json"]
|
|
42
|
-
// })
|
|
43
|
-
]
|
|
44
|
-
}, {
|
|
45
|
-
input: 'src/peernet.js',
|
|
46
|
-
output: {
|
|
47
|
-
file: 'dist/module/peernet.js',
|
|
28
|
+
dir: 'dist/module',
|
|
48
29
|
format: 'es'
|
|
49
30
|
},
|
|
50
31
|
plugins: [
|
package/src/handlers/message.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import MultiWallet from '
|
|
2
|
-
import { CodecHash
|
|
3
|
-
import PeernetMessage from './../messages/peernet-message.js'
|
|
1
|
+
import MultiWallet from '@leofcoin/multi-wallet'
|
|
2
|
+
import { CodecHash } from '@leofcoin/codec-format-interface'
|
|
4
3
|
|
|
5
4
|
export default class MessageHandler {
|
|
6
5
|
constructor(network) {
|
|
@@ -17,7 +16,7 @@ export default class MessageHandler {
|
|
|
17
16
|
* @return signature
|
|
18
17
|
*/
|
|
19
18
|
async hashAndSignMessage(message) {
|
|
20
|
-
const hasher = new
|
|
19
|
+
const hasher = new CodecHash(message, {name: 'peernet-message'})
|
|
21
20
|
let identity = await walletStore.get('identity')
|
|
22
21
|
identity = JSON.parse(new TextDecoder().decode(identity))
|
|
23
22
|
const wallet = new MultiWallet(this.network)
|
|
@@ -40,7 +39,7 @@ export default class MessageHandler {
|
|
|
40
39
|
data,
|
|
41
40
|
}
|
|
42
41
|
const signature = await this.hashAndSignMessage(message)
|
|
43
|
-
const node = await new
|
|
42
|
+
const node = await new globalThis.peernet.protos['peernet-message']({
|
|
44
43
|
...message,
|
|
45
44
|
signature,
|
|
46
45
|
})
|
|
File without changes
|
|
File without changes
|
package/src/messages.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * as PeernetMessage from './messages/peernet.js'
|
|
2
|
+
export * as DHTMessage from './messages/dht.js'
|
|
3
|
+
export * as DHTMessageResponse from './messages/dht-response.js'
|
|
4
|
+
export * as DataMessage from './messages/data.js'
|
|
5
|
+
export * as PsMessage from './messages/ps.js'
|
|
6
|
+
export * as PeerMessage from './messages/peer.js'
|
|
7
|
+
export * as RequestMessage from './messages/request.js'
|
|
8
|
+
export * as ResponseMessage from './messages/response.js'
|
|
9
|
+
export * as PeerMessageResponse from './messages/peer-response.js'
|
|
10
|
+
export * as DataMessageResponse from './messages/data-response.js'
|
|
11
|
+
export * as ChatMessage from './messages/chat.js'
|
package/src/peernet.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import '@vandeurenglenn/debug'
|
|
2
|
-
import Client from './../node_modules/@leofcoin/peernet-swarm/dist/es/client.js'
|
|
3
|
-
import LeofcoinStorage from '@leofcoin/storage'
|
|
4
|
-
import PeernetMessage from './messages/peernet-message.js'
|
|
5
|
-
import DHTMessage from './messages/dht.js'
|
|
6
|
-
import DHTMessageResponse from './messages/dht-response.js'
|
|
7
|
-
import DataMessage from './messages/data.js'
|
|
8
|
-
import PsMessage from './messages/ps.js'
|
|
9
|
-
import PeerMessage from './messages/peer.js'
|
|
10
|
-
import RequestMessage from './messages/request.js'
|
|
11
|
-
import ResponseMessage from './messages/response.js'
|
|
12
|
-
import PeerMessageResponse from './messages/peer-response.js'
|
|
13
|
-
import DataMessageResponse from './messages/data-response.js'
|
|
14
|
-
import ChatMessage from './messages/chat-message.js'
|
|
15
2
|
import PeerDiscovery from './discovery/peer-discovery'
|
|
16
3
|
import DHT from './dht/dht.js'
|
|
17
|
-
import { CodecHash
|
|
4
|
+
import { CodecHash, codecs} from '@leofcoin/codec-format-interface'
|
|
18
5
|
import { protoFor, target } from './utils/utils.js'
|
|
19
|
-
import generateAccount from './../node_modules/@leofcoin/generate-account/dist/module/generate-account'
|
|
20
6
|
import MessageHandler from './handlers/message.js'
|
|
21
7
|
import dataHandler from './handlers/data.js'
|
|
22
8
|
import { encapsulatedError, dhtError,
|
|
@@ -86,6 +72,10 @@ export default class Peernet {
|
|
|
86
72
|
}
|
|
87
73
|
|
|
88
74
|
async addStore(name, prefix, root, isPrivate = true) {
|
|
75
|
+
if (!globalThis.LeofcoinStorage) {
|
|
76
|
+
const importee = await import(/* webpackChunkName: "storage" */ '@leofcoin/storage')
|
|
77
|
+
globalThis.LeofcoinStorage = importee.default
|
|
78
|
+
}
|
|
89
79
|
if (name === 'block' || name === 'transaction' || name === 'chain' ||
|
|
90
80
|
name === 'data' || name === 'message') isPrivate = false
|
|
91
81
|
|
|
@@ -93,7 +83,7 @@ export default class Peernet {
|
|
|
93
83
|
if (this.hasDaemon) {
|
|
94
84
|
Storage = LeofcoinStorageClient
|
|
95
85
|
} else {
|
|
96
|
-
Storage =
|
|
86
|
+
Storage = LeofcoinStorage
|
|
97
87
|
}
|
|
98
88
|
globalThis[`${name}Store`] = globalThis[`${name}Store`] ||
|
|
99
89
|
await new Storage(name, root)
|
|
@@ -158,6 +148,20 @@ export default class Peernet {
|
|
|
158
148
|
this.storePrefix = options.storePrefix
|
|
159
149
|
this.root = options.root
|
|
160
150
|
|
|
151
|
+
const {
|
|
152
|
+
RequestMessage,
|
|
153
|
+
ResponseMessage,
|
|
154
|
+
PeerMessage,
|
|
155
|
+
PeerMessageResponse,
|
|
156
|
+
PeernetMessage,
|
|
157
|
+
DHTMessage,
|
|
158
|
+
DHTMessageResponse,
|
|
159
|
+
DataMessage,
|
|
160
|
+
DataMessageResponse,
|
|
161
|
+
PsMessage,
|
|
162
|
+
ChatMessage
|
|
163
|
+
} = await import(/* webpackChunkName: "messages" */ './messages.js')
|
|
164
|
+
|
|
161
165
|
/**
|
|
162
166
|
* proto Object containing protos
|
|
163
167
|
* @type {Object}
|
|
@@ -167,6 +171,7 @@ export default class Peernet {
|
|
|
167
171
|
* @property {DataMessage} protos[peernet-data] messageNode
|
|
168
172
|
* @property {DataMessageResponse} protos[peernet-data-response] messageNode
|
|
169
173
|
*/
|
|
174
|
+
|
|
170
175
|
globalThis.peernet.protos = {
|
|
171
176
|
'peernet-request': RequestMessage,
|
|
172
177
|
'peernet-response': ResponseMessage,
|
|
@@ -205,6 +210,9 @@ export default class Peernet {
|
|
|
205
210
|
}
|
|
206
211
|
} catch (e) {
|
|
207
212
|
if (e.code === 'ERR_NOT_FOUND') {
|
|
213
|
+
|
|
214
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')
|
|
215
|
+
const generateAccount = importee.default
|
|
208
216
|
const wallet = {}
|
|
209
217
|
const {identity, accounts, config} = await generateAccount(this.network)
|
|
210
218
|
walletStore.put('version', new TextEncoder().encode(1))
|
|
@@ -238,11 +246,13 @@ export default class Peernet {
|
|
|
238
246
|
*/
|
|
239
247
|
pubsub.subscribe('peer:data', dataHandler)
|
|
240
248
|
|
|
249
|
+
|
|
250
|
+
const importee = await import(/* webpackChunkName: "peernet-swarm" */ '@leofcoin/peernet-swarm')
|
|
241
251
|
/**
|
|
242
252
|
* @access public
|
|
243
253
|
* @type {PeernetClient}
|
|
244
254
|
*/
|
|
245
|
-
this.client = new
|
|
255
|
+
this.client = new importee.default(this.id)
|
|
246
256
|
if (globalThis.onbeforeunload) {
|
|
247
257
|
globalThis.addEventListener('beforeunload', async () => this.client.close());
|
|
248
258
|
}
|
|
@@ -284,7 +294,7 @@ export default class Peernet {
|
|
|
284
294
|
if (store.private) has = false
|
|
285
295
|
else has = await store.has(hash)
|
|
286
296
|
}
|
|
287
|
-
const data = await new
|
|
297
|
+
const data = await new this.protos['peernet-dht-response']({hash, has})
|
|
288
298
|
const node = await this.prepareMessage(from, data.encoded)
|
|
289
299
|
|
|
290
300
|
this.sendMessage(peer, id, node.encoded)
|
|
@@ -300,7 +310,7 @@ export default class Peernet {
|
|
|
300
310
|
data = await store.get(hash)
|
|
301
311
|
|
|
302
312
|
if (data) {
|
|
303
|
-
data = await new
|
|
313
|
+
data = await new this.protos['peernet-data-response']({hash, data});
|
|
304
314
|
|
|
305
315
|
const node = await this.prepareMessage(from, data.encoded)
|
|
306
316
|
this.sendMessage(peer, id, node.encoded)
|
|
@@ -329,7 +339,7 @@ export default class Peernet {
|
|
|
329
339
|
*/
|
|
330
340
|
async walk(hash) {
|
|
331
341
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
332
|
-
const data = await new
|
|
342
|
+
const data = await new this.protos['peernet-dht']({hash})
|
|
333
343
|
const clientId = this.client.id
|
|
334
344
|
const walk = async peer => {
|
|
335
345
|
const node = await this.prepareMessage(peer.peerId, data.encoded)
|
|
@@ -437,7 +447,7 @@ export default class Peernet {
|
|
|
437
447
|
if (peer.peerId === id) return peer
|
|
438
448
|
})
|
|
439
449
|
|
|
440
|
-
let data = await new
|
|
450
|
+
let data = await new this.protos['peernet-data']({hash, store: store?.name ? store?.name : store});
|
|
441
451
|
|
|
442
452
|
const node = await this.prepareMessage(id, data.encoded)
|
|
443
453
|
if (closest[0]) data = await closest[0].request(node.encoded)
|
|
@@ -583,7 +593,7 @@ export default class Peernet {
|
|
|
583
593
|
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic)
|
|
584
594
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data))
|
|
585
595
|
const id = Math.random().toString(36).slice(-12)
|
|
586
|
-
data = await new
|
|
596
|
+
data = await new this.protos['peernet-ps']({data, topic})
|
|
587
597
|
for (const peer of this.connections) {
|
|
588
598
|
if (peer.peerId !== this.peerId) {
|
|
589
599
|
const node = await this.prepareMessage(peer.peerId, data.encoded)
|
|
@@ -594,7 +604,7 @@ export default class Peernet {
|
|
|
594
604
|
}
|
|
595
605
|
|
|
596
606
|
createHash(data, name) {
|
|
597
|
-
return new
|
|
607
|
+
return new CodeHash(data, {name})
|
|
598
608
|
}
|
|
599
609
|
|
|
600
610
|
/**
|
package/webpack.config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const webpack = require('webpack');
|
|
3
3
|
module.exports = [{
|
|
4
|
-
entry: './
|
|
4
|
+
entry: './src/peernet.js',
|
|
5
5
|
mode: 'production',
|
|
6
6
|
plugins: [
|
|
7
7
|
// Work around for Buffer is undefined:
|
|
@@ -26,6 +26,9 @@ module.exports = [{
|
|
|
26
26
|
optimization: {
|
|
27
27
|
minimize: false
|
|
28
28
|
},
|
|
29
|
+
experiments: {
|
|
30
|
+
outputModule: true
|
|
31
|
+
},
|
|
29
32
|
resolve: {
|
|
30
33
|
extensions: [ '.ts', '.js' ],
|
|
31
34
|
fallback: {
|
|
@@ -41,9 +44,9 @@ resolve: {
|
|
|
41
44
|
},
|
|
42
45
|
output: {
|
|
43
46
|
library: {
|
|
44
|
-
|
|
45
|
-
type: 'global'
|
|
47
|
+
type: 'module'
|
|
46
48
|
},
|
|
49
|
+
chunkFilename: '[name].js',
|
|
47
50
|
filename: 'peernet.js',
|
|
48
51
|
path: path.resolve(__dirname, 'dist', 'browser'),
|
|
49
52
|
},
|