@leofcoin/peernet 1.1.46 → 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-b203939f.js → index-96b718dc.js} +1 -2
- package/exports/browser/messages-591e0b2c.js +224 -0
- package/exports/browser/{peernet-4dde5a19.js → peernet-20a06ecc.js} +176 -339
- 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-7138679c.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
|
}
|
|
@@ -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
|
|
|
@@ -4816,7 +4814,7 @@ const toType = (data) => {
|
|
|
4816
4814
|
return new TextEncoder().encode(data.toString());
|
|
4817
4815
|
throw new Error(`unsuported type ${typeof data || data}`);
|
|
4818
4816
|
};
|
|
4819
|
-
const encode$
|
|
4817
|
+
const encode$2 = (proto, input, compress) => {
|
|
4820
4818
|
const keys = Object.keys(proto);
|
|
4821
4819
|
const values = Object.values(proto);
|
|
4822
4820
|
const set = [];
|
|
@@ -4833,7 +4831,7 @@ const encode$3 = (proto, input, compress) => {
|
|
|
4833
4831
|
}
|
|
4834
4832
|
return index$6(set);
|
|
4835
4833
|
};
|
|
4836
|
-
const decode$
|
|
4834
|
+
const decode$3 = (proto, uint8Array, compressed) => {
|
|
4837
4835
|
let deconcated = index$5(uint8Array);
|
|
4838
4836
|
const output = {};
|
|
4839
4837
|
const keys = Object.keys(proto);
|
|
@@ -4864,8 +4862,8 @@ const decode$4 = (proto, uint8Array, compressed) => {
|
|
|
4864
4862
|
return output;
|
|
4865
4863
|
};
|
|
4866
4864
|
var index$1 = {
|
|
4867
|
-
encode: encode$
|
|
4868
|
-
decode: decode$
|
|
4865
|
+
encode: encode$2,
|
|
4866
|
+
decode: decode$3
|
|
4869
4867
|
};
|
|
4870
4868
|
|
|
4871
4869
|
/*!
|
|
@@ -6048,55 +6046,54 @@ const FormatInterface = FormatInterface$1;
|
|
|
6048
6046
|
const Codec = Codec$1;
|
|
6049
6047
|
|
|
6050
6048
|
const BufferToUint8Array = data => {
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6049
|
+
if (data.type === 'Buffer') {
|
|
6050
|
+
data = new Uint8Array(data.data);
|
|
6051
|
+
}
|
|
6052
|
+
return data
|
|
6055
6053
|
};
|
|
6054
|
+
|
|
6056
6055
|
const protoFor = (message) => {
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
throw (new Error(`No proto defined for ${codec.name}`));
|
|
6063
|
-
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)
|
|
6064
6061
|
};
|
|
6062
|
+
|
|
6065
6063
|
/**
|
|
6066
6064
|
* wether or not a peernet daemon is active
|
|
6067
6065
|
* @return {Boolean}
|
|
6068
6066
|
*/
|
|
6069
6067
|
const hasDaemon = async () => {
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
}
|
|
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
|
+
}
|
|
6078
6075
|
};
|
|
6076
|
+
|
|
6079
6077
|
const https = () => {
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
return Boolean(globalThis.location.protocol === 'https:');
|
|
6078
|
+
if (!globalThis.location) return false;
|
|
6079
|
+
return Boolean(globalThis.location.protocol === 'https:')
|
|
6083
6080
|
};
|
|
6081
|
+
|
|
6084
6082
|
/**
|
|
6085
6083
|
* Get current environment
|
|
6086
6084
|
* @return {String} current environment [node, electron, browser]
|
|
6087
6085
|
*/
|
|
6088
6086
|
const environment = () => {
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
return 'browser';
|
|
6098
|
-
}
|
|
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
|
+
}
|
|
6099
6095
|
};
|
|
6096
|
+
|
|
6100
6097
|
/**
|
|
6101
6098
|
* * Get current environment
|
|
6102
6099
|
* @return {Object} result
|
|
@@ -6104,84 +6101,84 @@ const environment = () => {
|
|
|
6104
6101
|
* @property {Boolean} reult.environment Current environment
|
|
6105
6102
|
*/
|
|
6106
6103
|
const target = async () => {
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6104
|
+
let daemon = false;
|
|
6105
|
+
if (!https()) daemon = await hasDaemon();
|
|
6106
|
+
|
|
6107
|
+
return {daemon, environment: environment()}
|
|
6111
6108
|
};
|
|
6112
6109
|
|
|
6113
6110
|
class PeerDiscovery {
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
}
|
|
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
|
+
}
|
|
6126
6122
|
}
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
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
|
+
}
|
|
6149
6145
|
}
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
const data = await new peernet.protos['peernet-peer-response']({ id: this.id });
|
|
6167
|
-
const node = await peernet.prepareMessage(from, data.encoded);
|
|
6168
|
-
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);
|
|
6169
6162
|
}
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
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);
|
|
6183
6178
|
}
|
|
6179
|
+
}
|
|
6184
6180
|
}
|
|
6181
|
+
}
|
|
6185
6182
|
}
|
|
6186
6183
|
|
|
6187
6184
|
/**
|
|
@@ -6294,219 +6291,56 @@ class DhtEarth {
|
|
|
6294
6291
|
}
|
|
6295
6292
|
|
|
6296
6293
|
class MessageHandler {
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
}
|
|
6300
|
-
/**
|
|
6301
|
-
* hash and sign message
|
|
6302
|
-
*
|
|
6303
|
-
* @param {object} message
|
|
6304
|
-
* @param {Buffer} message.from peer id
|
|
6305
|
-
* @param {Buffer} message.to peer id
|
|
6306
|
-
* @param {string} message.data Peernet message
|
|
6307
|
-
* (PeernetMessage excluded) encoded as a string
|
|
6308
|
-
* @return message
|
|
6309
|
-
*/
|
|
6310
|
-
async hashAndSignMessage(message) {
|
|
6311
|
-
const hash = await message.peernetHash;
|
|
6312
|
-
message.decoded.signature = globalThis.identity.sign(hash.buffer);
|
|
6313
|
-
return message;
|
|
6314
|
-
}
|
|
6315
|
-
/**
|
|
6316
|
-
* @param {String} from - peer id
|
|
6317
|
-
* @param {String} to - peer id
|
|
6318
|
-
* @param {String|PeernetMessage} data - data encoded message string
|
|
6319
|
-
* or the messageNode itself
|
|
6320
|
-
*/
|
|
6321
|
-
async prepareMessage(message) {
|
|
6322
|
-
if (message.keys.includes('signature')) {
|
|
6323
|
-
message = await this.hashAndSignMessage(message);
|
|
6324
|
-
}
|
|
6325
|
-
return message;
|
|
6326
|
-
}
|
|
6327
|
-
}
|
|
6328
|
-
|
|
6329
|
-
const dataHandler = async (message) => {
|
|
6330
|
-
if (!message)
|
|
6331
|
-
return;
|
|
6332
|
-
const { data, id, from, peer } = message;
|
|
6333
|
-
const proto = await protoFor(data);
|
|
6334
|
-
peernet._protoHandler({ id, proto }, peernet.connections[from] || peer, from);
|
|
6335
|
-
};
|
|
6336
|
-
|
|
6337
|
-
const dhtError = (proto) => {
|
|
6338
|
-
const text = `Received proto ${proto.name} expected peernet-dht-response`;
|
|
6339
|
-
return new Error(`Routing error: ${text}`);
|
|
6340
|
-
};
|
|
6341
|
-
const nothingFoundError = (hash) => {
|
|
6342
|
-
return new Error(`nothing found for ${hash}`);
|
|
6343
|
-
};
|
|
6344
|
-
|
|
6345
|
-
// import base32 from '@vandeurenglenn/base32'
|
|
6346
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
6347
|
-
|
|
6348
|
-
// export const encodings = {
|
|
6349
|
-
// base58,
|
|
6350
|
-
// base32
|
|
6351
|
-
// }
|
|
6352
|
-
|
|
6353
|
-
const encode$2 = (string, encoding = 'utf-8') => {
|
|
6354
|
-
if (typeof string === 'string') {
|
|
6355
|
-
let encoded;
|
|
6356
|
-
|
|
6357
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
6358
|
-
encoded = new TextEncoder().encode(string);
|
|
6359
|
-
return encoded
|
|
6360
|
-
}
|
|
6361
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
6362
|
-
};
|
|
6363
|
-
|
|
6364
|
-
const decode$3 = (uint8Array, encoding) => {
|
|
6365
|
-
if (uint8Array instanceof Uint8Array) {
|
|
6366
|
-
let decoded;
|
|
6367
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
6368
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
6369
|
-
|
|
6370
|
-
return decoded
|
|
6294
|
+
constructor(network) {
|
|
6295
|
+
this.network = network;
|
|
6371
6296
|
}
|
|
6372
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
6373
|
-
};
|
|
6374
|
-
|
|
6375
|
-
const pathSepS = '/';
|
|
6376
|
-
class KeyPath {
|
|
6377
|
-
|
|
6378
|
-
/**
|
|
6379
|
-
* @param {string | Uint8Array} input
|
|
6380
|
-
*/
|
|
6381
|
-
constructor(input) {
|
|
6382
|
-
if (typeof input === 'string') {
|
|
6383
|
-
this.uint8Array = encode$2(input);
|
|
6384
|
-
} else if (input instanceof Uint8Array) {
|
|
6385
|
-
this.uint8Array = input;
|
|
6386
|
-
} else if (input instanceof KeyPath) {
|
|
6387
|
-
this.uint8Array = input.uint8Array;
|
|
6388
|
-
} else {
|
|
6389
|
-
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
6390
|
-
}
|
|
6391
|
-
}
|
|
6392
|
-
|
|
6393
|
-
isKeyPath() {
|
|
6394
|
-
return true
|
|
6395
|
-
}
|
|
6396
|
-
|
|
6397
6297
|
/**
|
|
6398
|
-
*
|
|
6298
|
+
* hash and sign message
|
|
6399
6299
|
*
|
|
6400
|
-
* @param {
|
|
6401
|
-
* @
|
|
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
|
|
6402
6306
|
*/
|
|
6403
|
-
|
|
6404
|
-
|
|
6307
|
+
async hashAndSignMessage(message) {
|
|
6308
|
+
const hash = await message.peernetHash;
|
|
6309
|
+
message.decoded.signature = globalThis.identity.sign(hash.buffer);
|
|
6310
|
+
return message
|
|
6405
6311
|
}
|
|
6406
6312
|
|
|
6407
6313
|
/**
|
|
6408
|
-
*
|
|
6409
|
-
*
|
|
6410
|
-
* @
|
|
6411
|
-
*
|
|
6412
|
-
* @example
|
|
6413
|
-
* ```js
|
|
6414
|
-
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
6415
|
-
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
6416
|
-
* ```
|
|
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
|
|
6417
6318
|
*/
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
}
|
|
6423
|
-
|
|
6424
|
-
class LeofcoinStorage {
|
|
6425
|
-
|
|
6426
|
-
constructor(name = 'storage', root = '.leofcoin') {
|
|
6427
|
-
this.name = name;
|
|
6428
|
-
this.root = root;
|
|
6429
|
-
}
|
|
6430
|
-
|
|
6431
|
-
async init(name, root) {
|
|
6432
|
-
const importee = await import(globalThis.navigator ? './browser-store.js' : './store.js');
|
|
6433
|
-
const Store = importee.default;
|
|
6434
|
-
this.db = new Store(this.name, this.root);
|
|
6435
|
-
}
|
|
6436
|
-
|
|
6437
|
-
async get(key) {
|
|
6438
|
-
if (typeof key === 'object') return this.many('get', key);
|
|
6439
|
-
return this.db.get(new KeyPath(key))
|
|
6440
|
-
}
|
|
6441
|
-
|
|
6442
|
-
/**
|
|
6443
|
-
*
|
|
6444
|
-
* @param {*} key
|
|
6445
|
-
* @param {*} value
|
|
6446
|
-
* @returns Promise
|
|
6447
|
-
*/
|
|
6448
|
-
put(key, value) {
|
|
6449
|
-
if (typeof key === 'object') return this.many('put', key);
|
|
6450
|
-
return this.db.put(new KeyPath(key), new KeyValue(value));
|
|
6451
|
-
}
|
|
6452
|
-
|
|
6453
|
-
async has(key) {
|
|
6454
|
-
if (typeof key === 'object') return this.many('has', key);
|
|
6455
|
-
|
|
6456
|
-
try {
|
|
6457
|
-
const has = await this.db.get(new KeyPath(key));
|
|
6458
|
-
|
|
6459
|
-
return Boolean(has);
|
|
6460
|
-
} catch (e) {
|
|
6461
|
-
return false
|
|
6319
|
+
async prepareMessage(message) {
|
|
6320
|
+
if (message.keys.includes('signature')) {
|
|
6321
|
+
message = await this.hashAndSignMessage(message);
|
|
6462
6322
|
}
|
|
6463
|
-
}
|
|
6464
6323
|
|
|
6465
|
-
|
|
6466
|
-
return this.db.delete(new KeyPath(key))
|
|
6467
|
-
}
|
|
6468
|
-
|
|
6469
|
-
keys(limit = -1) {
|
|
6470
|
-
return this.db.keys(limit)
|
|
6471
|
-
}
|
|
6472
|
-
|
|
6473
|
-
async values(limit = -1) {
|
|
6474
|
-
return this.db.values(limit)
|
|
6475
|
-
}
|
|
6476
|
-
|
|
6477
|
-
async many(type, _value) {
|
|
6478
|
-
const jobs = [];
|
|
6479
|
-
|
|
6480
|
-
for (const key of Object.keys(_value)) {
|
|
6481
|
-
jobs.push(this[type](key, _value[key]));
|
|
6482
|
-
}
|
|
6483
|
-
|
|
6484
|
-
return Promise.all(jobs)
|
|
6485
|
-
}
|
|
6486
|
-
|
|
6487
|
-
async length() {
|
|
6488
|
-
const keys = await this.keys();
|
|
6489
|
-
return keys.length
|
|
6324
|
+
return message
|
|
6490
6325
|
}
|
|
6326
|
+
}
|
|
6491
6327
|
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
const query = await this.db.iterate();
|
|
6495
|
-
for await (const item of query) {
|
|
6496
|
-
size += item.value ? item.value.length : item[1].length;
|
|
6497
|
-
}
|
|
6498
|
-
return size
|
|
6499
|
-
}
|
|
6328
|
+
const dataHandler = async message => {
|
|
6329
|
+
if (!message) return
|
|
6500
6330
|
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
}
|
|
6331
|
+
const {data, id, from, peer} = message;
|
|
6332
|
+
const proto = await protoFor(data);
|
|
6333
|
+
peernet._protoHandler({id, proto}, peernet.connections[from] || peer, from);
|
|
6334
|
+
};
|
|
6504
6335
|
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
}
|
|
6336
|
+
const dhtError = (proto) => {
|
|
6337
|
+
const text = `Received proto ${proto.name} expected peernet-dht-response`;
|
|
6338
|
+
return new Error(`Routing error: ${text}`)
|
|
6339
|
+
};
|
|
6508
6340
|
|
|
6509
|
-
|
|
6341
|
+
const nothingFoundError = (hash) => {
|
|
6342
|
+
return new Error(`nothing found for ${hash}`)
|
|
6343
|
+
};
|
|
6510
6344
|
|
|
6511
6345
|
const randombytes = strength => crypto.getRandomValues(new Uint8Array(strength));
|
|
6512
6346
|
|
|
@@ -20178,7 +20012,7 @@ class Identity {
|
|
|
20178
20012
|
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
20179
20013
|
}
|
|
20180
20014
|
else {
|
|
20181
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
20015
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-96b718dc.js');
|
|
20182
20016
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
20183
20017
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
20184
20018
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -20218,8 +20052,8 @@ class Identity {
|
|
|
20218
20052
|
|
|
20219
20053
|
globalThis.LeofcoinStorage = LeofcoinStorage;
|
|
20220
20054
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
20221
|
-
|
|
20222
|
-
|
|
20055
|
+
pubsub = pubsub || new LittlePubSub();
|
|
20056
|
+
globalSub = globalSub || new LittlePubSub();
|
|
20223
20057
|
/**
|
|
20224
20058
|
* @access public
|
|
20225
20059
|
* @example
|
|
@@ -20239,11 +20073,14 @@ class Peernet {
|
|
|
20239
20073
|
stars;
|
|
20240
20074
|
networkVersion;
|
|
20241
20075
|
bw;
|
|
20076
|
+
hasDaemon = false;
|
|
20242
20077
|
autoStart = true;
|
|
20243
20078
|
#starting = false;
|
|
20244
20079
|
#started = false;
|
|
20245
20080
|
#connections = {};
|
|
20246
20081
|
requestProtos = {};
|
|
20082
|
+
_messageHandler;
|
|
20083
|
+
protos;
|
|
20247
20084
|
/**
|
|
20248
20085
|
* @access public
|
|
20249
20086
|
* @param {Object} options
|
|
@@ -20273,7 +20110,7 @@ class Peernet {
|
|
|
20273
20110
|
if (!options.root) {
|
|
20274
20111
|
parts[1] ? options.root = `.${parts[0]}/${parts[1]}` : options.root = `.${this.network}`;
|
|
20275
20112
|
}
|
|
20276
|
-
|
|
20113
|
+
peernet = this;
|
|
20277
20114
|
this.bw = {
|
|
20278
20115
|
up: 0,
|
|
20279
20116
|
down: 0,
|
|
@@ -20349,7 +20186,7 @@ class Peernet {
|
|
|
20349
20186
|
this.root = options.root;
|
|
20350
20187
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
20351
20188
|
// FolderMessageResponse
|
|
20352
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
20189
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-591e0b2c.js');
|
|
20353
20190
|
/**
|
|
20354
20191
|
* proto Object containing protos
|
|
20355
20192
|
* @type {Object}
|