@leofcoin/peernet 1.1.45 → 1.1.47
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/exports/browser/browser-store.js +62 -1
- package/exports/browser/{index-502d190c.js → index-96b718dc.js} +1 -2
- package/exports/browser/messages-591e0b2c.js +224 -0
- package/exports/browser/{peernet-bdde86d9.js → peernet-20a06ecc.js} +229 -388
- package/exports/browser/peernet.d.ts +233 -0
- package/exports/browser/peernet.js +1 -2
- package/exports/messages-dc960cb3.js +224 -0
- package/exports/peernet.js +150 -146
- package/exports/types/peernet.d.ts +233 -0
- package/package.json +3 -2
- package/rollup.config.js +2 -2
- package/src/peernet.ts +23 -8
- package/tsconfig.json +1 -0
- package/exports/browser/discovery/peer-discovery.d.ts +0 -7
- package/exports/browser/errors/errors.d.ts +0 -3
- package/exports/browser/handlers/data.d.ts +0 -2
- package/exports/browser/handlers/message.d.ts +0 -30
- package/exports/browser/messages/chat.d.ts +0 -6
- package/exports/browser/messages/data-response.d.ts +0 -6
- package/exports/browser/messages/data.d.ts +0 -10
- package/exports/browser/messages/dht-response.d.ts +0 -6
- package/exports/browser/messages/dht.d.ts +0 -14
- package/exports/browser/messages/file-link.d.ts +0 -10
- package/exports/browser/messages/file.d.ts +0 -10
- package/exports/browser/messages/peer-response.d.ts +0 -6
- package/exports/browser/messages/peer.d.ts +0 -6
- package/exports/browser/messages/peernet.d.ts +0 -6
- package/exports/browser/messages/ps.d.ts +0 -6
- package/exports/browser/messages/request.d.ts +0 -6
- package/exports/browser/messages/response.d.ts +0 -6
- package/exports/browser/messages-cd01524c.js +0 -205
- package/exports/browser/messages.d.ts +0 -12
- package/exports/browser/peer-info.d.ts +0 -4
- package/exports/browser/prompts/password/browser.d.ts +0 -2
- package/exports/browser/prompts/password/node.d.ts +0 -2
- package/exports/browser/proto/chat-message.proto.d.ts +0 -7
- package/exports/browser/proto/data-response.proto.d.ts +0 -5
- package/exports/browser/proto/data.proto.d.ts +0 -5
- package/exports/browser/proto/dht-response.proto.d.ts +0 -5
- package/exports/browser/proto/dht.proto.d.ts +0 -5
- package/exports/browser/proto/file-link.proto.d.ts +0 -6
- package/exports/browser/proto/file.proto.d.ts +0 -6
- package/exports/browser/proto/peer-response.proto.d.ts +0 -4
- package/exports/browser/proto/peer.proto.d.ts +0 -4
- package/exports/browser/proto/peernet.proto.d.ts +0 -8
- package/exports/browser/proto/ps.proto.d.ts +0 -5
- package/exports/browser/proto/request.proto.d.ts +0 -5
- package/exports/browser/proto/response.proto.d.ts +0 -4
- package/exports/browser/utils/utils.d.ts +0 -7
- package/exports/browser/value-157ab062.js +0 -64
- package/exports/discovery/peer-discovery.d.ts +0 -7
- package/exports/errors/errors.d.ts +0 -3
- package/exports/handlers/data.d.ts +0 -2
- package/exports/handlers/message.d.ts +0 -30
- package/exports/messages/chat.d.ts +0 -6
- package/exports/messages/data-response.d.ts +0 -6
- package/exports/messages/data.d.ts +0 -10
- package/exports/messages/dht-response.d.ts +0 -6
- package/exports/messages/dht.d.ts +0 -14
- package/exports/messages/file-link.d.ts +0 -10
- package/exports/messages/file.d.ts +0 -10
- package/exports/messages/peer-response.d.ts +0 -6
- package/exports/messages/peer.d.ts +0 -6
- package/exports/messages/peernet.d.ts +0 -6
- package/exports/messages/ps.d.ts +0 -6
- package/exports/messages/request.d.ts +0 -6
- package/exports/messages/response.d.ts +0 -6
- package/exports/messages-6645d42e.js +0 -204
- package/exports/messages.d.ts +0 -12
- package/exports/peer-info.d.ts +0 -4
- package/exports/prompts/password/browser.d.ts +0 -2
- package/exports/prompts/password/node.d.ts +0 -2
- package/exports/proto/chat-message.proto.d.ts +0 -7
- package/exports/proto/data-response.proto.d.ts +0 -5
- package/exports/proto/data.proto.d.ts +0 -5
- package/exports/proto/dht-response.proto.d.ts +0 -5
- package/exports/proto/dht.proto.d.ts +0 -5
- package/exports/proto/file-link.proto.d.ts +0 -6
- package/exports/proto/file.proto.d.ts +0 -6
- package/exports/proto/peer-response.proto.d.ts +0 -4
- package/exports/proto/peer.proto.d.ts +0 -4
- package/exports/proto/peernet.proto.d.ts +0 -8
- package/exports/proto/ps.proto.d.ts +0 -5
- package/exports/proto/request.proto.d.ts +0 -5
- package/exports/proto/response.proto.d.ts +0 -4
- package/exports/utils/utils.d.ts +0 -7
- /package/exports/{dht → types/dht}/dht.d.ts +0 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { K as KeyValue } from './value-157ab062.js';
|
|
2
|
-
|
|
3
1
|
if (!globalThis.DEBUG) {
|
|
4
2
|
if (globalThis.localStorage) globalThis.DEBUG = Boolean(globalThis.localStorage.getItem('DEBUG') === 'true');
|
|
5
3
|
}
|
|
@@ -8,55 +6,55 @@ globalThis.debug = text => {
|
|
|
8
6
|
if (globalThis.DEBUG) console.log('\x1b[34m\x1b[1m%s', text, '\x1b[0m'); // bright blue
|
|
9
7
|
};
|
|
10
8
|
|
|
11
|
-
class LittlePubSub {
|
|
12
|
-
subscribers = {};
|
|
13
|
-
verbose;
|
|
14
|
-
constructor(verbose
|
|
15
|
-
this.verbose = verbose;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (typeof context === 'undefined') {
|
|
19
|
-
context = handler;
|
|
20
|
-
}
|
|
21
|
-
return context;
|
|
22
|
-
}
|
|
23
|
-
hasSubscribers(event) {
|
|
24
|
-
return this.subscribers[event] ? true : false;
|
|
25
|
-
}
|
|
26
|
-
subscribe(event, handler, context) {
|
|
27
|
-
if (!this.hasSubscribers(event))
|
|
28
|
-
this.subscribers[event] = { handlers: [], value: undefined };
|
|
29
|
-
context = this
|
|
30
|
-
this.subscribers[event].handlers.push(handler.bind(context));
|
|
31
|
-
}
|
|
32
|
-
unsubscribe(event, handler, context) {
|
|
33
|
-
if (!this.hasSubscribers(event))
|
|
34
|
-
return;
|
|
35
|
-
context = this
|
|
36
|
-
const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
|
|
37
|
-
this.subscribers[event].handlers.splice(index);
|
|
38
|
-
if (this.subscribers[event].handlers.length === 0)
|
|
39
|
-
delete this.subscribers[event];
|
|
40
|
-
}
|
|
41
|
-
publish(event, change) {
|
|
42
|
-
if (!this.hasSubscribers(event))
|
|
43
|
-
return;
|
|
44
|
-
if (this.verbose || this.subscribers[event]
|
|
45
|
-
this.subscribers[event].value = change;
|
|
46
|
-
this.subscribers[event].handlers.forEach((handler) => {
|
|
47
|
-
handler(change, this.subscribers[event].value);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
once(event) {
|
|
52
|
-
return new Promise((resolve) => {
|
|
53
|
-
const cb = (value) => {
|
|
54
|
-
this.unsubscribe(event, cb);
|
|
55
|
-
resolve(value);
|
|
56
|
-
};
|
|
57
|
-
this.subscribe(event, cb);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
9
|
+
class LittlePubSub {
|
|
10
|
+
subscribers = {};
|
|
11
|
+
verbose;
|
|
12
|
+
constructor(verbose) {
|
|
13
|
+
this.verbose = verbose;
|
|
14
|
+
}
|
|
15
|
+
_handleContext(handler, context) {
|
|
16
|
+
if (typeof context === 'undefined') {
|
|
17
|
+
context = handler;
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
hasSubscribers(event) {
|
|
22
|
+
return this.subscribers[event] ? true : false;
|
|
23
|
+
}
|
|
24
|
+
subscribe(event, handler, context) {
|
|
25
|
+
if (!this.hasSubscribers(event))
|
|
26
|
+
this.subscribers[event] = { handlers: [], value: undefined };
|
|
27
|
+
context = this._handleContext(handler, context);
|
|
28
|
+
this.subscribers[event].handlers.push(handler.bind(context));
|
|
29
|
+
}
|
|
30
|
+
unsubscribe(event, handler, context) {
|
|
31
|
+
if (!this.hasSubscribers(event))
|
|
32
|
+
return;
|
|
33
|
+
context = this._handleContext(handler, context);
|
|
34
|
+
const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
|
|
35
|
+
this.subscribers[event].handlers.splice(index);
|
|
36
|
+
if (this.subscribers[event].handlers.length === 0)
|
|
37
|
+
delete this.subscribers[event];
|
|
38
|
+
}
|
|
39
|
+
publish(event, change) {
|
|
40
|
+
if (!this.hasSubscribers(event))
|
|
41
|
+
return;
|
|
42
|
+
if (this.verbose || this.subscribers[event]?.value !== change) {
|
|
43
|
+
this.subscribers[event].value = change;
|
|
44
|
+
this.subscribers[event].handlers.forEach((handler) => {
|
|
45
|
+
handler(change, this.subscribers[event].value);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
once(event) {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
const cb = (value) => {
|
|
52
|
+
this.unsubscribe(event, cb);
|
|
53
|
+
resolve(value);
|
|
54
|
+
};
|
|
55
|
+
this.subscribe(event, cb);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
// base-x encoding / decoding
|
|
@@ -206,16 +204,16 @@ const ALPHABET$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
|
206
204
|
const ALPHABET_HEX$1 = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
|
|
207
205
|
const base32 = base$1(ALPHABET$3);
|
|
208
206
|
const base32Hex = base$1(ALPHABET_HEX$1);
|
|
209
|
-
const decode$
|
|
207
|
+
const decode$8 = base32.decode;
|
|
210
208
|
const decodeHex$2 = base32Hex.decode;
|
|
211
|
-
const encode$
|
|
209
|
+
const encode$7 = base32.encode;
|
|
212
210
|
const encodeHex$2 = base32Hex.encode;
|
|
213
211
|
const isBase32 = (string, hex = false) => {
|
|
214
212
|
try {
|
|
215
213
|
if (hex)
|
|
216
214
|
decodeHex$2(string);
|
|
217
215
|
else
|
|
218
|
-
decode$
|
|
216
|
+
decode$8(string);
|
|
219
217
|
return true;
|
|
220
218
|
}
|
|
221
219
|
catch (e) {
|
|
@@ -226,8 +224,8 @@ const isBase32Hex = (string) => {
|
|
|
226
224
|
return isBase32(string, true);
|
|
227
225
|
};
|
|
228
226
|
var index$8 = {
|
|
229
|
-
encode: encode$
|
|
230
|
-
decode: decode$
|
|
227
|
+
encode: encode$7,
|
|
228
|
+
decode: decode$8,
|
|
231
229
|
encodeHex: encodeHex$2,
|
|
232
230
|
decodeHex: decodeHex$2,
|
|
233
231
|
isBase32,
|
|
@@ -238,13 +236,13 @@ var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
|
238
236
|
var ALPHABET_HEX = '0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv';
|
|
239
237
|
var base58 = base$1(ALPHABET$2);
|
|
240
238
|
var base58Hex = base$1(ALPHABET_HEX);
|
|
241
|
-
var encode$
|
|
242
|
-
var decode$
|
|
239
|
+
var encode$6 = base58.encode;
|
|
240
|
+
var decode$7 = base58.decode;
|
|
243
241
|
var encodeHex$1 = base58Hex.encode;
|
|
244
242
|
var decodeHex$1 = base58Hex.decode;
|
|
245
243
|
var isBase58 = function (string) {
|
|
246
244
|
try {
|
|
247
|
-
decode$
|
|
245
|
+
decode$7(string);
|
|
248
246
|
return true;
|
|
249
247
|
}
|
|
250
248
|
catch (e) {
|
|
@@ -262,7 +260,7 @@ var isBase58Hex = function (string) {
|
|
|
262
260
|
};
|
|
263
261
|
var whatType = function (string) {
|
|
264
262
|
try {
|
|
265
|
-
decode$
|
|
263
|
+
decode$7(string);
|
|
266
264
|
return 'base58';
|
|
267
265
|
}
|
|
268
266
|
catch (e) {
|
|
@@ -275,15 +273,15 @@ var whatType = function (string) {
|
|
|
275
273
|
}
|
|
276
274
|
}
|
|
277
275
|
};
|
|
278
|
-
var base58$1 = { encode: encode$
|
|
276
|
+
var base58$1 = { encode: encode$6, decode: decode$7, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$1, decodeHex: decodeHex$1, whatType: whatType };
|
|
279
277
|
|
|
280
278
|
const MSB$1 = 0x80;
|
|
281
279
|
const REST$1 = 0x7F;
|
|
282
280
|
const MSBALL = ~REST$1;
|
|
283
281
|
const INT = Math.pow(2, 31);
|
|
284
|
-
const encode$
|
|
282
|
+
const encode$5 = (num, out, offset) => {
|
|
285
283
|
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
|
|
286
|
-
encode$
|
|
284
|
+
encode$5.bytes = 0;
|
|
287
285
|
throw new RangeError('Could not encode varint');
|
|
288
286
|
}
|
|
289
287
|
out = out || [];
|
|
@@ -298,13 +296,13 @@ const encode$6 = (num, out, offset) => {
|
|
|
298
296
|
num >>>= 7;
|
|
299
297
|
}
|
|
300
298
|
out[offset] = num | 0;
|
|
301
|
-
encode$
|
|
299
|
+
encode$5.bytes = offset - oldOffset + 1;
|
|
302
300
|
return out;
|
|
303
301
|
};
|
|
304
302
|
|
|
305
303
|
const MSB = 0x80;
|
|
306
304
|
const REST = 0x7F;
|
|
307
|
-
const decode$
|
|
305
|
+
const decode$6 = (buf, offset) => {
|
|
308
306
|
offset = offset || 0;
|
|
309
307
|
const l = buf.length;
|
|
310
308
|
let counter = offset;
|
|
@@ -313,7 +311,7 @@ const decode$7 = (buf, offset) => {
|
|
|
313
311
|
let b;
|
|
314
312
|
do {
|
|
315
313
|
if (counter >= l || shift > 49) {
|
|
316
|
-
decode$
|
|
314
|
+
decode$6.bytes = 0;
|
|
317
315
|
throw new RangeError('Could not decode varint');
|
|
318
316
|
}
|
|
319
317
|
b = buf[counter++];
|
|
@@ -322,7 +320,7 @@ const decode$7 = (buf, offset) => {
|
|
|
322
320
|
: (b & REST) * Math.pow(2, shift);
|
|
323
321
|
shift += 7;
|
|
324
322
|
} while (b >= MSB);
|
|
325
|
-
decode$
|
|
323
|
+
decode$6.bytes = counter - offset;
|
|
326
324
|
return result;
|
|
327
325
|
};
|
|
328
326
|
|
|
@@ -347,8 +345,8 @@ var encodingLength = (value) => (value < N1 ? 1
|
|
|
347
345
|
: 10);
|
|
348
346
|
|
|
349
347
|
var index$7 = {
|
|
350
|
-
encode: encode$
|
|
351
|
-
decode: decode$
|
|
348
|
+
encode: encode$5,
|
|
349
|
+
decode: decode$6,
|
|
352
350
|
encodingLength
|
|
353
351
|
};
|
|
354
352
|
|
|
@@ -398,11 +396,11 @@ var index$5 = (typedArray, prefix) => {
|
|
|
398
396
|
|
|
399
397
|
const ALPHABET$1 = '0123456789ABCDEF';
|
|
400
398
|
const base16 = base$1(ALPHABET$1);
|
|
401
|
-
const decode$
|
|
402
|
-
const encode$
|
|
399
|
+
const decode$5 = base16.decode;
|
|
400
|
+
const encode$4 = base16.encode;
|
|
403
401
|
const isBase16 = (string) => {
|
|
404
402
|
try {
|
|
405
|
-
decode$
|
|
403
|
+
decode$5(string);
|
|
406
404
|
return true;
|
|
407
405
|
}
|
|
408
406
|
catch (e) {
|
|
@@ -410,18 +408,18 @@ const isBase16 = (string) => {
|
|
|
410
408
|
}
|
|
411
409
|
};
|
|
412
410
|
var index$4 = {
|
|
413
|
-
encode: encode$
|
|
414
|
-
decode: decode$
|
|
411
|
+
encode: encode$4,
|
|
412
|
+
decode: decode$5,
|
|
415
413
|
isBase16
|
|
416
414
|
};
|
|
417
415
|
|
|
418
416
|
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
419
417
|
const base64 = base$1(ALPHABET);
|
|
420
|
-
const decode$
|
|
421
|
-
const encode$
|
|
418
|
+
const decode$4 = base64.decode;
|
|
419
|
+
const encode$3 = base64.encode;
|
|
422
420
|
const isBase64 = (string) => {
|
|
423
421
|
try {
|
|
424
|
-
decode$
|
|
422
|
+
decode$4(string);
|
|
425
423
|
return true;
|
|
426
424
|
}
|
|
427
425
|
catch (e) {
|
|
@@ -429,8 +427,8 @@ const isBase64 = (string) => {
|
|
|
429
427
|
}
|
|
430
428
|
};
|
|
431
429
|
var index$3 = {
|
|
432
|
-
encode: encode$
|
|
433
|
-
decode: decode$
|
|
430
|
+
encode: encode$3,
|
|
431
|
+
decode: decode$4,
|
|
434
432
|
isBase64
|
|
435
433
|
};
|
|
436
434
|
|
|
@@ -691,6 +689,8 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
|
|
|
691
689
|
|
|
692
690
|
var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
|
|
693
691
|
|
|
692
|
+
bn$1.exports;
|
|
693
|
+
|
|
694
694
|
(function (module) {
|
|
695
695
|
(function (module, exports) {
|
|
696
696
|
|
|
@@ -4814,7 +4814,7 @@ const toType = (data) => {
|
|
|
4814
4814
|
return new TextEncoder().encode(data.toString());
|
|
4815
4815
|
throw new Error(`unsuported type ${typeof data || data}`);
|
|
4816
4816
|
};
|
|
4817
|
-
const encode$
|
|
4817
|
+
const encode$2 = (proto, input, compress) => {
|
|
4818
4818
|
const keys = Object.keys(proto);
|
|
4819
4819
|
const values = Object.values(proto);
|
|
4820
4820
|
const set = [];
|
|
@@ -4831,7 +4831,7 @@ const encode$3 = (proto, input, compress) => {
|
|
|
4831
4831
|
}
|
|
4832
4832
|
return index$6(set);
|
|
4833
4833
|
};
|
|
4834
|
-
const decode$
|
|
4834
|
+
const decode$3 = (proto, uint8Array, compressed) => {
|
|
4835
4835
|
let deconcated = index$5(uint8Array);
|
|
4836
4836
|
const output = {};
|
|
4837
4837
|
const keys = Object.keys(proto);
|
|
@@ -4862,8 +4862,8 @@ const decode$4 = (proto, uint8Array, compressed) => {
|
|
|
4862
4862
|
return output;
|
|
4863
4863
|
};
|
|
4864
4864
|
var index$1 = {
|
|
4865
|
-
encode: encode$
|
|
4866
|
-
decode: decode$
|
|
4865
|
+
encode: encode$2,
|
|
4866
|
+
decode: decode$3
|
|
4867
4867
|
};
|
|
4868
4868
|
|
|
4869
4869
|
/*!
|
|
@@ -6046,55 +6046,54 @@ const FormatInterface = FormatInterface$1;
|
|
|
6046
6046
|
const Codec = Codec$1;
|
|
6047
6047
|
|
|
6048
6048
|
const BufferToUint8Array = data => {
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6049
|
+
if (data.type === 'Buffer') {
|
|
6050
|
+
data = new Uint8Array(data.data);
|
|
6051
|
+
}
|
|
6052
|
+
return data
|
|
6053
6053
|
};
|
|
6054
|
+
|
|
6054
6055
|
const protoFor = (message) => {
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
throw (new Error(`No proto defined for ${codec.name}`));
|
|
6061
|
-
return new Proto(message);
|
|
6056
|
+
const codec = new Codec(message);
|
|
6057
|
+
if (!codec.name) throw new Error('proto not found')
|
|
6058
|
+
const Proto = globalThis.peernet.protos[codec.name];
|
|
6059
|
+
if (!Proto) throw (new Error(`No proto defined for ${codec.name}`))
|
|
6060
|
+
return new Proto(message)
|
|
6062
6061
|
};
|
|
6062
|
+
|
|
6063
6063
|
/**
|
|
6064
6064
|
* wether or not a peernet daemon is active
|
|
6065
6065
|
* @return {Boolean}
|
|
6066
6066
|
*/
|
|
6067
6067
|
const hasDaemon = async () => {
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
}
|
|
6068
|
+
try {
|
|
6069
|
+
let response = await fetch('http://127.0.0.1:1000/api/version');
|
|
6070
|
+
response = await response.json();
|
|
6071
|
+
return Boolean(response.client === '@peernet/api/http')
|
|
6072
|
+
} catch (e) {
|
|
6073
|
+
return false
|
|
6074
|
+
}
|
|
6076
6075
|
};
|
|
6076
|
+
|
|
6077
6077
|
const https = () => {
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
return Boolean(globalThis.location.protocol === 'https:');
|
|
6078
|
+
if (!globalThis.location) return false;
|
|
6079
|
+
return Boolean(globalThis.location.protocol === 'https:')
|
|
6081
6080
|
};
|
|
6081
|
+
|
|
6082
6082
|
/**
|
|
6083
6083
|
* Get current environment
|
|
6084
6084
|
* @return {String} current environment [node, electron, browser]
|
|
6085
6085
|
*/
|
|
6086
6086
|
const environment = () => {
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
return 'browser';
|
|
6096
|
-
}
|
|
6087
|
+
const _navigator = globalThis.navigator;
|
|
6088
|
+
if (!_navigator) {
|
|
6089
|
+
return 'node'
|
|
6090
|
+
} else if (_navigator && /electron/i.test(_navigator.userAgent)) {
|
|
6091
|
+
return 'electron'
|
|
6092
|
+
} else {
|
|
6093
|
+
return 'browser'
|
|
6094
|
+
}
|
|
6097
6095
|
};
|
|
6096
|
+
|
|
6098
6097
|
/**
|
|
6099
6098
|
* * Get current environment
|
|
6100
6099
|
* @return {Object} result
|
|
@@ -6102,84 +6101,84 @@ const environment = () => {
|
|
|
6102
6101
|
* @property {Boolean} reult.environment Current environment
|
|
6103
6102
|
*/
|
|
6104
6103
|
const target = async () => {
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6104
|
+
let daemon = false;
|
|
6105
|
+
if (!https()) daemon = await hasDaemon();
|
|
6106
|
+
|
|
6107
|
+
return {daemon, environment: environment()}
|
|
6109
6108
|
};
|
|
6110
6109
|
|
|
6111
6110
|
class PeerDiscovery {
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
}
|
|
6111
|
+
constructor(id) {
|
|
6112
|
+
this.id = id;
|
|
6113
|
+
}
|
|
6114
|
+
|
|
6115
|
+
_getPeerId(id) {
|
|
6116
|
+
if (!peernet.peerMap || peernet.peerMap && peernet.peerMap.size === 0) return false
|
|
6117
|
+
|
|
6118
|
+
for (const entry of [...peernet.peerMap.entries()]) {
|
|
6119
|
+
for (const _id of entry[1]) {
|
|
6120
|
+
if (_id === id) return entry[0]
|
|
6121
|
+
}
|
|
6124
6122
|
}
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6123
|
+
}
|
|
6124
|
+
|
|
6125
|
+
async discover(peer) {
|
|
6126
|
+
let id = this._getPeerId(peer.id);
|
|
6127
|
+
if (id) return id
|
|
6128
|
+
const data = await new peernet.protos['peernet-peer']({id: this.id});
|
|
6129
|
+
const node = await peernet.prepareMessage(peer.id, data.encoded);
|
|
6130
|
+
|
|
6131
|
+
let response = await peer.request(node.encoded);
|
|
6132
|
+
response = await protoFor(response);
|
|
6133
|
+
response = await new peernet.protos['peernet-peer-response'](response.decoded.data);
|
|
6134
|
+
|
|
6135
|
+
id = response.decoded.id;
|
|
6136
|
+
if (id === this.id) return;
|
|
6137
|
+
|
|
6138
|
+
if (!peernet.peerMap.has(id)) peernet.peerMap.set(id, [peer.id]);
|
|
6139
|
+
else {
|
|
6140
|
+
const connections = peernet.peerMap.get(id);
|
|
6141
|
+
if (connections.indexOf(peer.id) === -1) {
|
|
6142
|
+
connections.push(peer.id);
|
|
6143
|
+
peernet.peerMap.set(peer.id, connections);
|
|
6144
|
+
}
|
|
6147
6145
|
}
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
const data = await new peernet.protos['peernet-peer-response']({ id: this.id });
|
|
6165
|
-
const node = await peernet.prepareMessage(from, data.encoded);
|
|
6166
|
-
peer.write(Buffer.from(JSON.stringify({ id, data: node.encoded })));
|
|
6146
|
+
return id
|
|
6147
|
+
}
|
|
6148
|
+
|
|
6149
|
+
async discoverHandler(message, peer) {
|
|
6150
|
+
const {id, proto} = message;
|
|
6151
|
+
// if (typeof message.data === 'string') message.data = Buffer.from(message.data)
|
|
6152
|
+
if (proto.name === 'peernet-peer') {
|
|
6153
|
+
const from = proto.decoded.id;
|
|
6154
|
+
if (from === this.id) return;
|
|
6155
|
+
|
|
6156
|
+
if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id]);
|
|
6157
|
+
else {
|
|
6158
|
+
const connections = peernet.peerMap.get(from);
|
|
6159
|
+
if (connections.indexOf(peer.id) === -1) {
|
|
6160
|
+
connections.push(peer.id);
|
|
6161
|
+
peernet.peerMap.set(from, connections);
|
|
6167
6162
|
}
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6163
|
+
}
|
|
6164
|
+
const data = await new peernet.protos['peernet-peer-response']({id: this.id});
|
|
6165
|
+
const node = await peernet.prepareMessage(from, data.encoded);
|
|
6166
|
+
|
|
6167
|
+
peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
|
|
6168
|
+
} else if (proto.name === 'peernet-peer-response') {
|
|
6169
|
+
const from = proto.decoded.id;
|
|
6170
|
+
if (from === this.id) return;
|
|
6171
|
+
|
|
6172
|
+
if (!peernet.peerMap.has(from)) peernet.peerMap.set(from, [peer.id]);
|
|
6173
|
+
else {
|
|
6174
|
+
const connections = peernet.peerMap.get(from);
|
|
6175
|
+
if (connections.indexOf(peer.id) === -1) {
|
|
6176
|
+
connections.push(peer.id);
|
|
6177
|
+
peernet.peerMap.set(from, connections);
|
|
6181
6178
|
}
|
|
6179
|
+
}
|
|
6182
6180
|
}
|
|
6181
|
+
}
|
|
6183
6182
|
}
|
|
6184
6183
|
|
|
6185
6184
|
/**
|
|
@@ -6292,219 +6291,56 @@ class DhtEarth {
|
|
|
6292
6291
|
}
|
|
6293
6292
|
|
|
6294
6293
|
class MessageHandler {
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
}
|
|
6298
|
-
/**
|
|
6299
|
-
* hash and sign message
|
|
6300
|
-
*
|
|
6301
|
-
* @param {object} message
|
|
6302
|
-
* @param {Buffer} message.from peer id
|
|
6303
|
-
* @param {Buffer} message.to peer id
|
|
6304
|
-
* @param {string} message.data Peernet message
|
|
6305
|
-
* (PeernetMessage excluded) encoded as a string
|
|
6306
|
-
* @return message
|
|
6307
|
-
*/
|
|
6308
|
-
async hashAndSignMessage(message) {
|
|
6309
|
-
const hash = await message.peernetHash;
|
|
6310
|
-
message.decoded.signature = globalThis.identity.sign(hash.buffer);
|
|
6311
|
-
return message;
|
|
6312
|
-
}
|
|
6313
|
-
/**
|
|
6314
|
-
* @param {String} from - peer id
|
|
6315
|
-
* @param {String} to - peer id
|
|
6316
|
-
* @param {String|PeernetMessage} data - data encoded message string
|
|
6317
|
-
* or the messageNode itself
|
|
6318
|
-
*/
|
|
6319
|
-
async prepareMessage(message) {
|
|
6320
|
-
if (message.keys.includes('signature')) {
|
|
6321
|
-
message = await this.hashAndSignMessage(message);
|
|
6322
|
-
}
|
|
6323
|
-
return message;
|
|
6324
|
-
}
|
|
6325
|
-
}
|
|
6326
|
-
|
|
6327
|
-
const dataHandler = async (message) => {
|
|
6328
|
-
if (!message)
|
|
6329
|
-
return;
|
|
6330
|
-
const { data, id, from, peer } = message;
|
|
6331
|
-
const proto = await protoFor(data);
|
|
6332
|
-
peernet._protoHandler({ id, proto }, peernet.connections[from] || peer, from);
|
|
6333
|
-
};
|
|
6334
|
-
|
|
6335
|
-
const dhtError = (proto) => {
|
|
6336
|
-
const text = `Received proto ${proto.name} expected peernet-dht-response`;
|
|
6337
|
-
return new Error(`Routing error: ${text}`);
|
|
6338
|
-
};
|
|
6339
|
-
const nothingFoundError = (hash) => {
|
|
6340
|
-
return new Error(`nothing found for ${hash}`);
|
|
6341
|
-
};
|
|
6342
|
-
|
|
6343
|
-
// import base32 from '@vandeurenglenn/base32'
|
|
6344
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
6345
|
-
|
|
6346
|
-
// export const encodings = {
|
|
6347
|
-
// base58,
|
|
6348
|
-
// base32
|
|
6349
|
-
// }
|
|
6350
|
-
|
|
6351
|
-
const encode$2 = (string, encoding = 'utf-8') => {
|
|
6352
|
-
if (typeof string === 'string') {
|
|
6353
|
-
let encoded;
|
|
6354
|
-
|
|
6355
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
6356
|
-
encoded = new TextEncoder().encode(string);
|
|
6357
|
-
return encoded
|
|
6358
|
-
}
|
|
6359
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
6360
|
-
};
|
|
6361
|
-
|
|
6362
|
-
const decode$3 = (uint8Array, encoding) => {
|
|
6363
|
-
if (uint8Array instanceof Uint8Array) {
|
|
6364
|
-
let decoded;
|
|
6365
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
6366
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
6367
|
-
|
|
6368
|
-
return decoded
|
|
6369
|
-
}
|
|
6370
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
6371
|
-
};
|
|
6372
|
-
|
|
6373
|
-
const pathSepS = '/';
|
|
6374
|
-
class KeyPath {
|
|
6375
|
-
|
|
6376
|
-
/**
|
|
6377
|
-
* @param {string | Uint8Array} input
|
|
6378
|
-
*/
|
|
6379
|
-
constructor(input) {
|
|
6380
|
-
if (typeof input === 'string') {
|
|
6381
|
-
this.uint8Array = encode$2(input);
|
|
6382
|
-
} else if (input instanceof Uint8Array) {
|
|
6383
|
-
this.uint8Array = input;
|
|
6384
|
-
} else if (input instanceof KeyPath) {
|
|
6385
|
-
this.uint8Array = input.uint8Array;
|
|
6386
|
-
} else {
|
|
6387
|
-
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
6388
|
-
}
|
|
6389
|
-
}
|
|
6390
|
-
|
|
6391
|
-
isKeyPath() {
|
|
6392
|
-
return true
|
|
6393
|
-
}
|
|
6394
|
-
|
|
6395
|
-
/**
|
|
6396
|
-
* Convert to the string representation
|
|
6397
|
-
*
|
|
6398
|
-
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
6399
|
-
* @returns {string}
|
|
6400
|
-
*/
|
|
6401
|
-
toString(encoding = 'hex') {
|
|
6402
|
-
return decode$3(this.uint8Array)
|
|
6294
|
+
constructor(network) {
|
|
6295
|
+
this.network = network;
|
|
6403
6296
|
}
|
|
6404
|
-
|
|
6405
6297
|
/**
|
|
6406
|
-
*
|
|
6298
|
+
* hash and sign message
|
|
6407
6299
|
*
|
|
6408
|
-
* @
|
|
6409
|
-
*
|
|
6410
|
-
* @
|
|
6411
|
-
*
|
|
6412
|
-
*
|
|
6413
|
-
*
|
|
6414
|
-
* ```
|
|
6300
|
+
* @param {object} message
|
|
6301
|
+
* @param {Buffer} message.from peer id
|
|
6302
|
+
* @param {Buffer} message.to peer id
|
|
6303
|
+
* @param {string} message.data Peernet message
|
|
6304
|
+
* (PeernetMessage excluded) encoded as a string
|
|
6305
|
+
* @return message
|
|
6415
6306
|
*/
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
}
|
|
6421
|
-
|
|
6422
|
-
class LeofcoinStorage {
|
|
6423
|
-
|
|
6424
|
-
constructor(name = 'storage', root = '.leofcoin') {
|
|
6425
|
-
this.name = name;
|
|
6426
|
-
this.root = root;
|
|
6427
|
-
}
|
|
6428
|
-
|
|
6429
|
-
async init(name, root) {
|
|
6430
|
-
const importee = await import(globalThis.navigator ? './browser-store.js' : './store.js');
|
|
6431
|
-
const Store = importee.default;
|
|
6432
|
-
this.db = new Store(this.name, this.root);
|
|
6307
|
+
async hashAndSignMessage(message) {
|
|
6308
|
+
const hash = await message.peernetHash;
|
|
6309
|
+
message.decoded.signature = globalThis.identity.sign(hash.buffer);
|
|
6310
|
+
return message
|
|
6433
6311
|
}
|
|
6434
6312
|
|
|
6435
|
-
async get(key) {
|
|
6436
|
-
if (typeof key === 'object') return this.many('get', key);
|
|
6437
|
-
return this.db.get(new KeyPath(key))
|
|
6438
|
-
}
|
|
6439
|
-
|
|
6440
6313
|
/**
|
|
6441
|
-
*
|
|
6442
|
-
* @param {
|
|
6443
|
-
* @param {
|
|
6444
|
-
*
|
|
6314
|
+
* @param {String} from - peer id
|
|
6315
|
+
* @param {String} to - peer id
|
|
6316
|
+
* @param {String|PeernetMessage} data - data encoded message string
|
|
6317
|
+
* or the messageNode itself
|
|
6445
6318
|
*/
|
|
6446
|
-
|
|
6447
|
-
if (
|
|
6448
|
-
|
|
6449
|
-
}
|
|
6450
|
-
|
|
6451
|
-
async has(key) {
|
|
6452
|
-
if (typeof key === 'object') return this.many('has', key);
|
|
6453
|
-
|
|
6454
|
-
try {
|
|
6455
|
-
const has = await this.db.get(new KeyPath(key));
|
|
6456
|
-
|
|
6457
|
-
return Boolean(has);
|
|
6458
|
-
} catch (e) {
|
|
6459
|
-
return false
|
|
6460
|
-
}
|
|
6461
|
-
}
|
|
6462
|
-
|
|
6463
|
-
async delete(key) {
|
|
6464
|
-
return this.db.delete(new KeyPath(key))
|
|
6465
|
-
}
|
|
6466
|
-
|
|
6467
|
-
keys(limit = -1) {
|
|
6468
|
-
return this.db.keys(limit)
|
|
6469
|
-
}
|
|
6470
|
-
|
|
6471
|
-
async values(limit = -1) {
|
|
6472
|
-
return this.db.values(limit)
|
|
6473
|
-
}
|
|
6474
|
-
|
|
6475
|
-
async many(type, _value) {
|
|
6476
|
-
const jobs = [];
|
|
6477
|
-
|
|
6478
|
-
for (const key of Object.keys(_value)) {
|
|
6479
|
-
jobs.push(this[type](key, _value[key]));
|
|
6319
|
+
async prepareMessage(message) {
|
|
6320
|
+
if (message.keys.includes('signature')) {
|
|
6321
|
+
message = await this.hashAndSignMessage(message);
|
|
6480
6322
|
}
|
|
6481
6323
|
|
|
6482
|
-
return
|
|
6324
|
+
return message
|
|
6483
6325
|
}
|
|
6326
|
+
}
|
|
6484
6327
|
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
return keys.length
|
|
6488
|
-
}
|
|
6328
|
+
const dataHandler = async message => {
|
|
6329
|
+
if (!message) return
|
|
6489
6330
|
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
size += item.value ? item.value.length : item[1].length;
|
|
6495
|
-
}
|
|
6496
|
-
return size
|
|
6497
|
-
}
|
|
6498
|
-
|
|
6499
|
-
async clear() {
|
|
6500
|
-
return this.db.clear()
|
|
6501
|
-
}
|
|
6331
|
+
const {data, id, from, peer} = message;
|
|
6332
|
+
const proto = await protoFor(data);
|
|
6333
|
+
peernet._protoHandler({id, proto}, peernet.connections[from] || peer, from);
|
|
6334
|
+
};
|
|
6502
6335
|
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
}
|
|
6336
|
+
const dhtError = (proto) => {
|
|
6337
|
+
const text = `Received proto ${proto.name} expected peernet-dht-response`;
|
|
6338
|
+
return new Error(`Routing error: ${text}`)
|
|
6339
|
+
};
|
|
6506
6340
|
|
|
6507
|
-
|
|
6341
|
+
const nothingFoundError = (hash) => {
|
|
6342
|
+
return new Error(`nothing found for ${hash}`)
|
|
6343
|
+
};
|
|
6508
6344
|
|
|
6509
6345
|
const randombytes = strength => crypto.getRandomValues(new Uint8Array(strength));
|
|
6510
6346
|
|
|
@@ -7149,6 +6985,8 @@ var utils$o = {};
|
|
|
7149
6985
|
|
|
7150
6986
|
var bn = {exports: {}};
|
|
7151
6987
|
|
|
6988
|
+
bn.exports;
|
|
6989
|
+
|
|
7152
6990
|
(function (module) {
|
|
7153
6991
|
(function (module, exports) {
|
|
7154
6992
|
|
|
@@ -20174,7 +20012,7 @@ class Identity {
|
|
|
20174
20012
|
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
20175
20013
|
}
|
|
20176
20014
|
else {
|
|
20177
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
20015
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-96b718dc.js');
|
|
20178
20016
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
20179
20017
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
20180
20018
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -20214,8 +20052,8 @@ class Identity {
|
|
|
20214
20052
|
|
|
20215
20053
|
globalThis.LeofcoinStorage = LeofcoinStorage;
|
|
20216
20054
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
20217
|
-
|
|
20218
|
-
|
|
20055
|
+
pubsub = pubsub || new LittlePubSub();
|
|
20056
|
+
globalSub = globalSub || new LittlePubSub();
|
|
20219
20057
|
/**
|
|
20220
20058
|
* @access public
|
|
20221
20059
|
* @example
|
|
@@ -20235,11 +20073,14 @@ class Peernet {
|
|
|
20235
20073
|
stars;
|
|
20236
20074
|
networkVersion;
|
|
20237
20075
|
bw;
|
|
20076
|
+
hasDaemon = false;
|
|
20238
20077
|
autoStart = true;
|
|
20239
20078
|
#starting = false;
|
|
20240
20079
|
#started = false;
|
|
20241
20080
|
#connections = {};
|
|
20242
20081
|
requestProtos = {};
|
|
20082
|
+
_messageHandler;
|
|
20083
|
+
protos;
|
|
20243
20084
|
/**
|
|
20244
20085
|
* @access public
|
|
20245
20086
|
* @param {Object} options
|
|
@@ -20269,7 +20110,7 @@ class Peernet {
|
|
|
20269
20110
|
if (!options.root) {
|
|
20270
20111
|
parts[1] ? options.root = `.${parts[0]}/${parts[1]}` : options.root = `.${this.network}`;
|
|
20271
20112
|
}
|
|
20272
|
-
|
|
20113
|
+
peernet = this;
|
|
20273
20114
|
this.bw = {
|
|
20274
20115
|
up: 0,
|
|
20275
20116
|
down: 0,
|
|
@@ -20345,7 +20186,7 @@ class Peernet {
|
|
|
20345
20186
|
this.root = options.root;
|
|
20346
20187
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
20347
20188
|
// FolderMessageResponse
|
|
20348
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
20189
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-591e0b2c.js');
|
|
20349
20190
|
/**
|
|
20350
20191
|
* proto Object containing protos
|
|
20351
20192
|
* @type {Object}
|