@leofcoin/peernet 0.13.4 → 0.14.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/peernet.js +10531 -9455
- package/dist/commonjs/peernet.js +115 -27
- package/dist/module/{messages-bce1b91d.js → messages-1b12e93b.js} +27 -14
- package/dist/module/peernet.js +148 -35
- package/index.html +2 -2
- package/package.json +11 -5
- package/rollup.config.js +3 -1
- package/src/handlers/message.js +5 -2
- package/src/peer-info.js +9 -9
- package/src/peernet.js +21 -24
- package/webpack.config.js +13 -7
- package/dist/browser/generate-account.js +0 -50
- package/dist/browser/messages.js +0 -404
- package/dist/browser/pako.js +0 -6731
- package/dist/browser/peernet-swarm.js +0 -836
- package/dist/browser/protons.js +0 -3829
- package/dist/browser/storage.js +0 -12
- package/dist/browser/wrtc.js +0 -28
package/dist/commonjs/peernet.js
CHANGED
|
@@ -4,8 +4,6 @@ require('@vandeurenglenn/debug');
|
|
|
4
4
|
var PubSub = require('@vandeurenglenn/little-pubsub');
|
|
5
5
|
var fetch = require('node-fetch');
|
|
6
6
|
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
7
|
-
var MultiWallet = require('@leofcoin/multi-wallet');
|
|
8
|
-
require('path');
|
|
9
7
|
|
|
10
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
9
|
|
|
@@ -29,7 +27,6 @@ function _interopNamespace(e) {
|
|
|
29
27
|
|
|
30
28
|
var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
|
|
31
29
|
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
32
|
-
var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet);
|
|
33
30
|
|
|
34
31
|
const protoFor = (data) => {
|
|
35
32
|
if (!Buffer.isBuffer(data)) data = Buffer.from(data);
|
|
@@ -282,6 +279,94 @@ class DhtEarth {
|
|
|
282
279
|
}
|
|
283
280
|
}
|
|
284
281
|
|
|
282
|
+
var codecs = {
|
|
283
|
+
// just a hash
|
|
284
|
+
'disco-hash': {
|
|
285
|
+
codec: parseInt('30', 16),
|
|
286
|
+
hashAlg: 'dbl-keccak-256', // ,
|
|
287
|
+
// testnet: 'olivia'
|
|
288
|
+
},
|
|
289
|
+
'peernet-peer-response': {
|
|
290
|
+
codec: parseInt('707072', 16),
|
|
291
|
+
hashAlg: 'keccak-256',
|
|
292
|
+
},
|
|
293
|
+
'peernet-peer': {
|
|
294
|
+
codec: parseInt('7070', 16),
|
|
295
|
+
hashAlg: 'keccak-256',
|
|
296
|
+
},
|
|
297
|
+
'peernet-dht': {
|
|
298
|
+
codec: parseInt('706468', 16),
|
|
299
|
+
hashAlg: 'keccak-256',
|
|
300
|
+
},
|
|
301
|
+
'peernet-dht-response': {
|
|
302
|
+
codec: parseInt('706472', 16),
|
|
303
|
+
hashAlg: 'keccak-256',
|
|
304
|
+
},
|
|
305
|
+
// data
|
|
306
|
+
'peernet-data': {
|
|
307
|
+
codec: parseInt('706461', 16),
|
|
308
|
+
hashAlg: 'keccak-256',
|
|
309
|
+
},
|
|
310
|
+
'peernet-data-response': {
|
|
311
|
+
codec: parseInt('70646172', 16),
|
|
312
|
+
hashAlg: 'keccak-256',
|
|
313
|
+
},
|
|
314
|
+
// message
|
|
315
|
+
'peernet-message': {
|
|
316
|
+
codec: parseInt('706d65', 16),
|
|
317
|
+
hashAlg: 'keccak-256',
|
|
318
|
+
},
|
|
319
|
+
// pubsub
|
|
320
|
+
'peernet-ps': {
|
|
321
|
+
codec: parseInt('707073', 16),
|
|
322
|
+
hashAlg: 'keccak-256',
|
|
323
|
+
},
|
|
324
|
+
'peernet-response': {
|
|
325
|
+
codec: parseInt('7072', 16),
|
|
326
|
+
hashAlg: 'keccak-256',
|
|
327
|
+
},
|
|
328
|
+
'peernet-request': {
|
|
329
|
+
codec: parseInt('707271', 16),
|
|
330
|
+
hashAlg: 'keccak-256',
|
|
331
|
+
},
|
|
332
|
+
// normal block
|
|
333
|
+
'leofcoin-block': {
|
|
334
|
+
codec: parseInt('6c62', 16),
|
|
335
|
+
hashAlg: 'dbl-keccak-512', // ,
|
|
336
|
+
// testnet: 'olivia'
|
|
337
|
+
},
|
|
338
|
+
'leofcoin-tx': {
|
|
339
|
+
codec: parseInt('6c74', 16),
|
|
340
|
+
hashAlg: 'dbl-keccak-512', // ,
|
|
341
|
+
// testnet: 'olivia'
|
|
342
|
+
},
|
|
343
|
+
// itx
|
|
344
|
+
'leofcoin-itx': {
|
|
345
|
+
codec: parseInt('6c69', 16),
|
|
346
|
+
hashAlg: 'keccak-512', // ,
|
|
347
|
+
// testnet: 'olivia'
|
|
348
|
+
},
|
|
349
|
+
// peer reputation
|
|
350
|
+
'leofcoin-pr': {
|
|
351
|
+
codec: parseInt('6c70', 16),
|
|
352
|
+
hashAlg: 'keccak-256', // ,
|
|
353
|
+
// testnet: 'olivia'
|
|
354
|
+
},
|
|
355
|
+
// chat message
|
|
356
|
+
'chat-message': {
|
|
357
|
+
codec: parseInt('636d', 16),
|
|
358
|
+
hashAlg: 'dbl-keccak-256',
|
|
359
|
+
},
|
|
360
|
+
'peernet-file' : {
|
|
361
|
+
codec: parseInt('7066', 16),
|
|
362
|
+
hashAlg: 'keccak-256',
|
|
363
|
+
},
|
|
364
|
+
'peernet-file-response' : {
|
|
365
|
+
codec: parseInt('706672', 16),
|
|
366
|
+
hashAlg: 'keccak-256',
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
285
370
|
class MessageHandler {
|
|
286
371
|
constructor(network) {
|
|
287
372
|
this.network = network;
|
|
@@ -299,8 +384,12 @@ class MessageHandler {
|
|
|
299
384
|
async hashAndSignMessage(message) {
|
|
300
385
|
const hasher = new codecFormatInterface.CodecHash(message, {name: 'peernet-message'});
|
|
301
386
|
let identity = await walletStore.get('identity');
|
|
302
|
-
identity = JSON.parse(
|
|
303
|
-
|
|
387
|
+
identity = JSON.parse(identity);
|
|
388
|
+
if (!globalThis.MultiWallet) {
|
|
389
|
+
const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "multi-wallet" */ '@leofcoin/multi-wallet')); });
|
|
390
|
+
globalThis.MultiWallet = importee.default;
|
|
391
|
+
}
|
|
392
|
+
const wallet = new MultiWallet(this.network);
|
|
304
393
|
wallet.recover(identity.mnemonic);
|
|
305
394
|
return wallet.sign(Buffer.from(hasher.hash).slice(0, 32))
|
|
306
395
|
}
|
|
@@ -403,7 +492,7 @@ class Peernet {
|
|
|
403
492
|
}
|
|
404
493
|
|
|
405
494
|
get codecs() {
|
|
406
|
-
return
|
|
495
|
+
return codecs
|
|
407
496
|
}
|
|
408
497
|
|
|
409
498
|
addProto(name, proto) {
|
|
@@ -541,35 +630,33 @@ class Peernet {
|
|
|
541
630
|
await this.addStore(store, options.storePrefix, options.root);
|
|
542
631
|
}
|
|
543
632
|
|
|
544
|
-
|
|
633
|
+
const accountExists = await accountStore.has('public');
|
|
634
|
+
if (accountExists) {
|
|
545
635
|
const pub = await accountStore.get('public');
|
|
546
|
-
this.id = JSON.parse(
|
|
636
|
+
this.id = JSON.parse(pub).walletId;
|
|
547
637
|
let accounts = await walletStore.get('accounts');
|
|
548
|
-
|
|
638
|
+
|
|
639
|
+
|
|
549
640
|
|
|
550
641
|
// fixing account issue (string while needs to be a JSON)
|
|
551
642
|
// TODO: remove when on mainnet
|
|
552
643
|
try {
|
|
553
|
-
this.accounts = JSON.parse(
|
|
644
|
+
this.accounts = JSON.parse(accounts);
|
|
554
645
|
} catch (e) {
|
|
555
646
|
this.accounts = [accounts.split(',')];
|
|
556
647
|
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
this.id = identity.walletId;
|
|
570
|
-
} else {
|
|
571
|
-
throw e
|
|
572
|
-
}
|
|
648
|
+
} else {
|
|
649
|
+
const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')); });
|
|
650
|
+
const generateAccount = importee.default;
|
|
651
|
+
const {identity, accounts, config} = await generateAccount(this.network);
|
|
652
|
+
// await accountStore.put('config', JSON.stringify(config));
|
|
653
|
+
await accountStore.put('public', JSON.stringify({walletId: identity.walletId}));
|
|
654
|
+
|
|
655
|
+
await walletStore.put('version', String(1));
|
|
656
|
+
await walletStore.put('accounts', JSON.stringify(accounts));
|
|
657
|
+
await walletStore.put('identity', JSON.stringify(identity));
|
|
658
|
+
|
|
659
|
+
this.id = identity.walletId;
|
|
573
660
|
}
|
|
574
661
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
575
662
|
this.peerId = this.id;
|
|
@@ -1043,6 +1130,7 @@ class Peernet {
|
|
|
1043
1130
|
// }
|
|
1044
1131
|
//
|
|
1045
1132
|
// }
|
|
1046
|
-
}
|
|
1133
|
+
}
|
|
1134
|
+
globalThis.Peernet = Peernet;
|
|
1047
1135
|
|
|
1048
1136
|
module.exports = Peernet;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
2
4
|
|
|
3
5
|
var proto$b = `
|
|
4
6
|
// PeernetMessage
|
|
@@ -10,7 +12,7 @@ message PeernetMessage {
|
|
|
10
12
|
optional string id = 5;
|
|
11
13
|
}`;
|
|
12
14
|
|
|
13
|
-
class PeernetMessage extends FormatInterface {
|
|
15
|
+
class PeernetMessage extends codecFormatInterface.FormatInterface {
|
|
14
16
|
get keys() {
|
|
15
17
|
return ['data', 'signature', 'from', 'to', 'id']
|
|
16
18
|
}
|
|
@@ -41,7 +43,7 @@ message PeernetDHTMessage {
|
|
|
41
43
|
message = new DHTMessage('hashmvbs124xcfd...', 'block')
|
|
42
44
|
`
|
|
43
45
|
*/
|
|
44
|
-
class DHTMessage extends FormatInterface {
|
|
46
|
+
class DHTMessage extends codecFormatInterface.FormatInterface {
|
|
45
47
|
/**
|
|
46
48
|
*
|
|
47
49
|
*/
|
|
@@ -67,7 +69,7 @@ message PeernetDHTMessageResponse {
|
|
|
67
69
|
}
|
|
68
70
|
`;
|
|
69
71
|
|
|
70
|
-
class DHTMessageResponse extends FormatInterface {
|
|
72
|
+
class DHTMessageResponse extends codecFormatInterface.FormatInterface {
|
|
71
73
|
get keys() {
|
|
72
74
|
return ['hash', 'has']
|
|
73
75
|
}
|
|
@@ -93,7 +95,7 @@ message PeernetDataMessage {
|
|
|
93
95
|
/**
|
|
94
96
|
* @extends {CodecFormat}
|
|
95
97
|
*/
|
|
96
|
-
class DataMessage extends FormatInterface {
|
|
98
|
+
class DataMessage extends codecFormatInterface.FormatInterface {
|
|
97
99
|
get keys() {
|
|
98
100
|
return ['hash', 'store']
|
|
99
101
|
}
|
|
@@ -116,7 +118,7 @@ message PsMessage {
|
|
|
116
118
|
required bytes topic = 2;
|
|
117
119
|
}`;
|
|
118
120
|
|
|
119
|
-
class PsMessage extends FormatInterface {
|
|
121
|
+
class PsMessage extends codecFormatInterface.FormatInterface {
|
|
120
122
|
get keys() {
|
|
121
123
|
return ['data', 'topic']
|
|
122
124
|
}
|
|
@@ -138,7 +140,7 @@ message PeernetPeerMessage {
|
|
|
138
140
|
}
|
|
139
141
|
`;
|
|
140
142
|
|
|
141
|
-
class PeerMessage extends FormatInterface {
|
|
143
|
+
class PeerMessage extends codecFormatInterface.FormatInterface {
|
|
142
144
|
get keys() {
|
|
143
145
|
return ['id']
|
|
144
146
|
}
|
|
@@ -160,7 +162,7 @@ message PeernetRequestMessage {
|
|
|
160
162
|
}
|
|
161
163
|
`;
|
|
162
164
|
|
|
163
|
-
class RequestMessage extends FormatInterface {
|
|
165
|
+
class RequestMessage extends codecFormatInterface.FormatInterface {
|
|
164
166
|
get keys() {
|
|
165
167
|
return ['request']
|
|
166
168
|
}
|
|
@@ -182,7 +184,7 @@ message PeernetResponseMessage {
|
|
|
182
184
|
}
|
|
183
185
|
`;
|
|
184
186
|
|
|
185
|
-
class ResponseMessage extends FormatInterface {
|
|
187
|
+
class ResponseMessage extends codecFormatInterface.FormatInterface {
|
|
186
188
|
get keys() {
|
|
187
189
|
return ['response']
|
|
188
190
|
}
|
|
@@ -204,7 +206,7 @@ message PeernetPeerMessageResponse {
|
|
|
204
206
|
}
|
|
205
207
|
`;
|
|
206
208
|
|
|
207
|
-
class PeerMessageResponse extends FormatInterface {
|
|
209
|
+
class PeerMessageResponse extends codecFormatInterface.FormatInterface {
|
|
208
210
|
get keys() {
|
|
209
211
|
return ['id']
|
|
210
212
|
}
|
|
@@ -227,7 +229,7 @@ message PeernetDataMessageResponse {
|
|
|
227
229
|
}
|
|
228
230
|
`;
|
|
229
231
|
|
|
230
|
-
class DataMessageResponse extends FormatInterface {
|
|
232
|
+
class DataMessageResponse extends codecFormatInterface.FormatInterface {
|
|
231
233
|
get keys() {
|
|
232
234
|
return ['hash', 'data']
|
|
233
235
|
}
|
|
@@ -250,7 +252,7 @@ message ChatMessage {
|
|
|
250
252
|
repeated string files = 4;
|
|
251
253
|
}`;
|
|
252
254
|
|
|
253
|
-
class ChatMessage extends FormatInterface {
|
|
255
|
+
class ChatMessage extends codecFormatInterface.FormatInterface {
|
|
254
256
|
get keys() {
|
|
255
257
|
return ['author', 'value', 'timestamp', 'files']
|
|
256
258
|
}
|
|
@@ -283,7 +285,7 @@ message PeernetFile {
|
|
|
283
285
|
/**
|
|
284
286
|
* @extends {CodecFormat}
|
|
285
287
|
*/
|
|
286
|
-
class PeernetFile extends FormatInterface {
|
|
288
|
+
class PeernetFile extends codecFormatInterface.FormatInterface {
|
|
287
289
|
get keys() {
|
|
288
290
|
return ['path', 'content', 'links']
|
|
289
291
|
}
|
|
@@ -299,4 +301,15 @@ class PeernetFile extends FormatInterface {
|
|
|
299
301
|
}
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
|
|
304
|
+
exports.ChatMessage = ChatMessage;
|
|
305
|
+
exports.DHTMessage = DHTMessage;
|
|
306
|
+
exports.DHTMessageResponse = DHTMessageResponse;
|
|
307
|
+
exports.DataMessage = DataMessage;
|
|
308
|
+
exports.DataMessageResponse = DataMessageResponse;
|
|
309
|
+
exports.PeerMessage = PeerMessage;
|
|
310
|
+
exports.PeerMessageResponse = PeerMessageResponse;
|
|
311
|
+
exports.PeernetFile = PeernetFile;
|
|
312
|
+
exports.PeernetMessage = PeernetMessage;
|
|
313
|
+
exports.PsMessage = PsMessage;
|
|
314
|
+
exports.RequestMessage = RequestMessage;
|
|
315
|
+
exports.ResponseMessage = ResponseMessage;
|
package/dist/module/peernet.js
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@vandeurenglenn/debug');
|
|
4
|
+
var PubSub = require('@vandeurenglenn/little-pubsub');
|
|
5
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n["default"] = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
|
|
6
28
|
|
|
7
29
|
const protoFor = (data) => {
|
|
8
30
|
if (!Buffer.isBuffer(data)) data = Buffer.from(data);
|
|
9
|
-
const codec = new Codec(data);
|
|
31
|
+
const codec = new codecFormatInterface.Codec(data);
|
|
10
32
|
if (!codec.name) throw new Error('proto not found')
|
|
11
33
|
const Proto = globalThis.peernet.protos[codec.name];
|
|
12
34
|
if (!Proto) throw (new Error(`No proto defined for ${codec.name}`))
|
|
@@ -255,6 +277,94 @@ class DhtEarth {
|
|
|
255
277
|
}
|
|
256
278
|
}
|
|
257
279
|
|
|
280
|
+
var codecs = {
|
|
281
|
+
// just a hash
|
|
282
|
+
'disco-hash': {
|
|
283
|
+
codec: parseInt('30', 16),
|
|
284
|
+
hashAlg: 'dbl-keccak-256', // ,
|
|
285
|
+
// testnet: 'olivia'
|
|
286
|
+
},
|
|
287
|
+
'peernet-peer-response': {
|
|
288
|
+
codec: parseInt('707072', 16),
|
|
289
|
+
hashAlg: 'keccak-256',
|
|
290
|
+
},
|
|
291
|
+
'peernet-peer': {
|
|
292
|
+
codec: parseInt('7070', 16),
|
|
293
|
+
hashAlg: 'keccak-256',
|
|
294
|
+
},
|
|
295
|
+
'peernet-dht': {
|
|
296
|
+
codec: parseInt('706468', 16),
|
|
297
|
+
hashAlg: 'keccak-256',
|
|
298
|
+
},
|
|
299
|
+
'peernet-dht-response': {
|
|
300
|
+
codec: parseInt('706472', 16),
|
|
301
|
+
hashAlg: 'keccak-256',
|
|
302
|
+
},
|
|
303
|
+
// data
|
|
304
|
+
'peernet-data': {
|
|
305
|
+
codec: parseInt('706461', 16),
|
|
306
|
+
hashAlg: 'keccak-256',
|
|
307
|
+
},
|
|
308
|
+
'peernet-data-response': {
|
|
309
|
+
codec: parseInt('70646172', 16),
|
|
310
|
+
hashAlg: 'keccak-256',
|
|
311
|
+
},
|
|
312
|
+
// message
|
|
313
|
+
'peernet-message': {
|
|
314
|
+
codec: parseInt('706d65', 16),
|
|
315
|
+
hashAlg: 'keccak-256',
|
|
316
|
+
},
|
|
317
|
+
// pubsub
|
|
318
|
+
'peernet-ps': {
|
|
319
|
+
codec: parseInt('707073', 16),
|
|
320
|
+
hashAlg: 'keccak-256',
|
|
321
|
+
},
|
|
322
|
+
'peernet-response': {
|
|
323
|
+
codec: parseInt('7072', 16),
|
|
324
|
+
hashAlg: 'keccak-256',
|
|
325
|
+
},
|
|
326
|
+
'peernet-request': {
|
|
327
|
+
codec: parseInt('707271', 16),
|
|
328
|
+
hashAlg: 'keccak-256',
|
|
329
|
+
},
|
|
330
|
+
// normal block
|
|
331
|
+
'leofcoin-block': {
|
|
332
|
+
codec: parseInt('6c62', 16),
|
|
333
|
+
hashAlg: 'dbl-keccak-512', // ,
|
|
334
|
+
// testnet: 'olivia'
|
|
335
|
+
},
|
|
336
|
+
'leofcoin-tx': {
|
|
337
|
+
codec: parseInt('6c74', 16),
|
|
338
|
+
hashAlg: 'dbl-keccak-512', // ,
|
|
339
|
+
// testnet: 'olivia'
|
|
340
|
+
},
|
|
341
|
+
// itx
|
|
342
|
+
'leofcoin-itx': {
|
|
343
|
+
codec: parseInt('6c69', 16),
|
|
344
|
+
hashAlg: 'keccak-512', // ,
|
|
345
|
+
// testnet: 'olivia'
|
|
346
|
+
},
|
|
347
|
+
// peer reputation
|
|
348
|
+
'leofcoin-pr': {
|
|
349
|
+
codec: parseInt('6c70', 16),
|
|
350
|
+
hashAlg: 'keccak-256', // ,
|
|
351
|
+
// testnet: 'olivia'
|
|
352
|
+
},
|
|
353
|
+
// chat message
|
|
354
|
+
'chat-message': {
|
|
355
|
+
codec: parseInt('636d', 16),
|
|
356
|
+
hashAlg: 'dbl-keccak-256',
|
|
357
|
+
},
|
|
358
|
+
'peernet-file' : {
|
|
359
|
+
codec: parseInt('7066', 16),
|
|
360
|
+
hashAlg: 'keccak-256',
|
|
361
|
+
},
|
|
362
|
+
'peernet-file-response' : {
|
|
363
|
+
codec: parseInt('706672', 16),
|
|
364
|
+
hashAlg: 'keccak-256',
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
258
368
|
class MessageHandler {
|
|
259
369
|
constructor(network) {
|
|
260
370
|
this.network = network;
|
|
@@ -270,9 +380,13 @@ class MessageHandler {
|
|
|
270
380
|
* @return signature
|
|
271
381
|
*/
|
|
272
382
|
async hashAndSignMessage(message) {
|
|
273
|
-
const hasher = new CodecHash(message, {name: 'peernet-message'});
|
|
383
|
+
const hasher = new codecFormatInterface.CodecHash(message, {name: 'peernet-message'});
|
|
274
384
|
let identity = await walletStore.get('identity');
|
|
275
|
-
identity = JSON.parse(
|
|
385
|
+
identity = JSON.parse(identity);
|
|
386
|
+
if (!globalThis.MultiWallet) {
|
|
387
|
+
const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "multi-wallet" */ '@leofcoin/multi-wallet')); });
|
|
388
|
+
globalThis.MultiWallet = importee.default;
|
|
389
|
+
}
|
|
276
390
|
const wallet = new MultiWallet(this.network);
|
|
277
391
|
wallet.recover(identity.mnemonic);
|
|
278
392
|
return wallet.sign(Buffer.from(hasher.hash).slice(0, 32))
|
|
@@ -328,8 +442,8 @@ const nothingFoundError = (hash) => {
|
|
|
328
442
|
};
|
|
329
443
|
|
|
330
444
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
331
|
-
globalThis.pubsub = globalThis.pubsub || new
|
|
332
|
-
globalThis.globalSub = globalThis.globalSub || new
|
|
445
|
+
globalThis.pubsub = globalThis.pubsub || new PubSub__default["default"]();
|
|
446
|
+
globalThis.globalSub = globalThis.globalSub || new PubSub__default["default"]({verbose: true});
|
|
333
447
|
|
|
334
448
|
/**
|
|
335
449
|
* @access public
|
|
@@ -389,7 +503,7 @@ class Peernet {
|
|
|
389
503
|
|
|
390
504
|
async addStore(name, prefix, root, isPrivate = true) {
|
|
391
505
|
if (!globalThis.LeofcoinStorage) {
|
|
392
|
-
const importee = await
|
|
506
|
+
const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "storage" */ '@leofcoin/storage')); });
|
|
393
507
|
globalThis.LeofcoinStorage = importee.default;
|
|
394
508
|
}
|
|
395
509
|
if (name === 'block' || name === 'transaction' || name === 'chain' ||
|
|
@@ -478,7 +592,7 @@ class Peernet {
|
|
|
478
592
|
ChatMessage,
|
|
479
593
|
PeernetFile
|
|
480
594
|
// FolderMessageResponse
|
|
481
|
-
} = await
|
|
595
|
+
} = await Promise.resolve().then(function () { return require(/* webpackChunkName: "messages" */ './messages-1b12e93b.js'); });
|
|
482
596
|
|
|
483
597
|
/**
|
|
484
598
|
* proto Object containing protos
|
|
@@ -514,35 +628,33 @@ class Peernet {
|
|
|
514
628
|
await this.addStore(store, options.storePrefix, options.root);
|
|
515
629
|
}
|
|
516
630
|
|
|
517
|
-
|
|
631
|
+
const accountExists = await accountStore.has('public');
|
|
632
|
+
if (accountExists) {
|
|
518
633
|
const pub = await accountStore.get('public');
|
|
519
|
-
this.id = JSON.parse(
|
|
634
|
+
this.id = JSON.parse(pub).walletId;
|
|
520
635
|
let accounts = await walletStore.get('accounts');
|
|
521
|
-
|
|
636
|
+
|
|
637
|
+
|
|
522
638
|
|
|
523
639
|
// fixing account issue (string while needs to be a JSON)
|
|
524
640
|
// TODO: remove when on mainnet
|
|
525
641
|
try {
|
|
526
|
-
this.accounts = JSON.parse(
|
|
642
|
+
this.accounts = JSON.parse(accounts);
|
|
527
643
|
} catch (e) {
|
|
528
644
|
this.accounts = [accounts.split(',')];
|
|
529
645
|
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
this.id = identity.walletId;
|
|
543
|
-
} else {
|
|
544
|
-
throw e
|
|
545
|
-
}
|
|
646
|
+
} else {
|
|
647
|
+
const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "generate-account" */ '@leofcoin/generate-account')); });
|
|
648
|
+
const generateAccount = importee.default;
|
|
649
|
+
const {identity, accounts, config} = await generateAccount(this.network);
|
|
650
|
+
// await accountStore.put('config', JSON.stringify(config));
|
|
651
|
+
await accountStore.put('public', JSON.stringify({walletId: identity.walletId}));
|
|
652
|
+
|
|
653
|
+
await walletStore.put('version', String(1));
|
|
654
|
+
await walletStore.put('accounts', JSON.stringify(accounts));
|
|
655
|
+
await walletStore.put('identity', JSON.stringify(identity));
|
|
656
|
+
|
|
657
|
+
this.id = identity.walletId;
|
|
546
658
|
}
|
|
547
659
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
548
660
|
this.peerId = this.id;
|
|
@@ -565,7 +677,7 @@ class Peernet {
|
|
|
565
677
|
pubsub.subscribe('peer:data', dataHandler);
|
|
566
678
|
|
|
567
679
|
|
|
568
|
-
const importee = await
|
|
680
|
+
const importee = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackChunkName: "peernet-swarm" */ '@leofcoin/peernet-swarm')); });
|
|
569
681
|
/**
|
|
570
682
|
* @access public
|
|
571
683
|
* @type {PeernetClient}
|
|
@@ -1016,6 +1128,7 @@ class Peernet {
|
|
|
1016
1128
|
// }
|
|
1017
1129
|
//
|
|
1018
1130
|
// }
|
|
1019
|
-
}
|
|
1131
|
+
}
|
|
1132
|
+
globalThis.Peernet = Peernet;
|
|
1020
1133
|
|
|
1021
|
-
|
|
1134
|
+
module.exports = Peernet;
|
package/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<script src="./dist/browser/peernet.js">
|
|
9
9
|
</script>
|
|
10
10
|
|
|
11
|
-
<script>
|
|
12
|
-
|
|
11
|
+
<script >
|
|
12
|
+
// import Peernet from './dist/browser/peernet.js';
|
|
13
13
|
(async () => {
|
|
14
14
|
const peernet = await new Peernet()
|
|
15
15
|
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: new TextEncoder().encode(100)}))
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "",
|
|
5
|
+
"source": "src/peernet.js",
|
|
5
6
|
"main": "dist/commonjs/peernet.js",
|
|
6
|
-
"module": "
|
|
7
|
+
"module": "dist/module/peernet.js",
|
|
8
|
+
"targets": [
|
|
9
|
+
"browser"
|
|
10
|
+
],
|
|
7
11
|
"scripts": {
|
|
8
12
|
"build": "npm run c && webpack",
|
|
9
13
|
"test": "node test/index.js",
|
|
@@ -15,18 +19,20 @@
|
|
|
15
19
|
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
|
16
20
|
"c": "rollup -c",
|
|
17
21
|
"w": "rollup -c -w",
|
|
18
|
-
"
|
|
22
|
+
"watch": "parcel watch",
|
|
23
|
+
"parcel-build": "parcel build",
|
|
24
|
+
"b": "browserify dist/module/peernet.js -o dist/module/peernet.js --standalone Peernet && rm browser.js"
|
|
19
25
|
},
|
|
20
26
|
"keywords": [],
|
|
21
27
|
"author": "",
|
|
22
28
|
"license": "MIT",
|
|
23
|
-
"browserslist": ">
|
|
29
|
+
"browserslist": "> 5%, last 2 versions, not dead",
|
|
24
30
|
"dependencies": {
|
|
25
31
|
"@leofcoin/codec-format-interface": "^1.2.5",
|
|
26
32
|
"@leofcoin/generate-account": "^1.0.4",
|
|
27
33
|
"@leofcoin/multi-wallet": "^2.1.2",
|
|
28
34
|
"@leofcoin/peernet-swarm": "^0.3.3",
|
|
29
|
-
"@leofcoin/storage": "^
|
|
35
|
+
"@leofcoin/storage": "^3.0.0",
|
|
30
36
|
"@vandeurenglenn/base32": "^1.1.0",
|
|
31
37
|
"@vandeurenglenn/base58": "^1.1.0",
|
|
32
38
|
"@vandeurenglenn/debug": "^1.0.0",
|
package/rollup.config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
2
|
import json from '@rollup/plugin-json'
|
|
3
3
|
import modify from 'rollup-plugin-modify'
|
|
4
|
+
import resolve from 'rollup-plugin-node-resolve'
|
|
4
5
|
|
|
5
6
|
try {
|
|
6
7
|
execSync('rm dist -r')
|
|
@@ -26,7 +27,8 @@ export default [{
|
|
|
26
27
|
input: 'src/peernet.js',
|
|
27
28
|
output: {
|
|
28
29
|
dir: 'dist/module',
|
|
29
|
-
format: '
|
|
30
|
+
format: 'cjs',
|
|
31
|
+
externals: ["@leofcoin/storage"]
|
|
30
32
|
},
|
|
31
33
|
plugins: [
|
|
32
34
|
json(),
|
package/src/handlers/message.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import MultiWallet from '@leofcoin/multi-wallet'
|
|
2
1
|
import { CodecHash } from '@leofcoin/codec-format-interface'
|
|
3
2
|
|
|
4
3
|
export default class MessageHandler {
|
|
@@ -18,7 +17,11 @@ export default class MessageHandler {
|
|
|
18
17
|
async hashAndSignMessage(message) {
|
|
19
18
|
const hasher = new CodecHash(message, {name: 'peernet-message'})
|
|
20
19
|
let identity = await walletStore.get('identity')
|
|
21
|
-
identity = JSON.parse(
|
|
20
|
+
identity = JSON.parse(identity)
|
|
21
|
+
if (!globalThis.MultiWallet) {
|
|
22
|
+
const importee = await import(/* webpackChunkName: "multi-wallet" */ '@leofcoin/multi-wallet')
|
|
23
|
+
globalThis.MultiWallet = importee.default
|
|
24
|
+
}
|
|
22
25
|
const wallet = new MultiWallet(this.network)
|
|
23
26
|
wallet.recover(identity.mnemonic)
|
|
24
27
|
return wallet.sign(Buffer.from(hasher.hash).slice(0, 32))
|