@leofcoin/peernet 1.1.47 → 1.1.49
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 +1 -62
- package/exports/browser/{index-96b718dc.js → index-5f6ba5a4.js} +2 -1
- package/exports/browser/{messages-591e0b2c.js → messages-5569e6ce.js} +2 -1
- package/exports/browser/{peernet-20a06ecc.js → peernet-9c2a381a.js} +205 -37
- package/exports/browser/peernet.d.ts +1 -1
- package/exports/browser/peernet.js +2 -1
- package/exports/browser/value-157ab062.js +64 -0
- package/exports/peernet.js +4 -3
- package/exports/types/peernet.d.ts +1 -1
- package/package.json +1 -1
- package/src/peernet.ts +4 -4
|
@@ -1,65 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
3
|
-
|
|
4
|
-
// export const encodings = {
|
|
5
|
-
// base58,
|
|
6
|
-
// base32
|
|
7
|
-
// }
|
|
8
|
-
|
|
9
|
-
const encode$1 = (string, encoding = 'utf-8') => {
|
|
10
|
-
if (typeof string === 'string') {
|
|
11
|
-
let encoded;
|
|
12
|
-
|
|
13
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
14
|
-
encoded = new TextEncoder().encode(string);
|
|
15
|
-
return encoded
|
|
16
|
-
}
|
|
17
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const decode$1 = (uint8Array, encoding) => {
|
|
21
|
-
if (uint8Array instanceof Uint8Array) {
|
|
22
|
-
let decoded;
|
|
23
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
24
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
25
|
-
|
|
26
|
-
return decoded
|
|
27
|
-
}
|
|
28
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
class KeyValue {
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {string | Uint8Array} input
|
|
35
|
-
*/
|
|
36
|
-
constructor(input) {
|
|
37
|
-
if (typeof input === 'string') {
|
|
38
|
-
this.uint8Array = encode$1(input);
|
|
39
|
-
} else if (input instanceof Uint8Array) {
|
|
40
|
-
this.uint8Array = input;
|
|
41
|
-
} else if (input instanceof KeyValue) {
|
|
42
|
-
this.uint8Array = input.uint8Array;
|
|
43
|
-
} else {
|
|
44
|
-
throw new Error('Invalid KeyValue, should be a String, Uint8Array or KeyValue')
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
isKeyValue() {
|
|
49
|
-
return true
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Convert to the string representation
|
|
54
|
-
*
|
|
55
|
-
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
56
|
-
* @returns {string}
|
|
57
|
-
*/
|
|
58
|
-
toString(encoding = 'utf8') {
|
|
59
|
-
return decode$1(this.uint8Array)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
}
|
|
1
|
+
import { K as KeyValue } from './value-157ab062.js';
|
|
63
2
|
|
|
64
3
|
const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
65
4
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { K as KeyValue } from './value-157ab062.js';
|
|
2
|
+
|
|
1
3
|
if (!globalThis.DEBUG) {
|
|
2
4
|
if (globalThis.localStorage) globalThis.DEBUG = Boolean(globalThis.localStorage.getItem('DEBUG') === 'true');
|
|
3
5
|
}
|
|
@@ -204,16 +206,16 @@ const ALPHABET$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
|
204
206
|
const ALPHABET_HEX$1 = '0123456789ABCDEFGHIJKLMNOPQRSTUV';
|
|
205
207
|
const base32 = base$1(ALPHABET$3);
|
|
206
208
|
const base32Hex = base$1(ALPHABET_HEX$1);
|
|
207
|
-
const decode$
|
|
209
|
+
const decode$9 = base32.decode;
|
|
208
210
|
const decodeHex$2 = base32Hex.decode;
|
|
209
|
-
const encode$
|
|
211
|
+
const encode$8 = base32.encode;
|
|
210
212
|
const encodeHex$2 = base32Hex.encode;
|
|
211
213
|
const isBase32 = (string, hex = false) => {
|
|
212
214
|
try {
|
|
213
215
|
if (hex)
|
|
214
216
|
decodeHex$2(string);
|
|
215
217
|
else
|
|
216
|
-
decode$
|
|
218
|
+
decode$9(string);
|
|
217
219
|
return true;
|
|
218
220
|
}
|
|
219
221
|
catch (e) {
|
|
@@ -224,8 +226,8 @@ const isBase32Hex = (string) => {
|
|
|
224
226
|
return isBase32(string, true);
|
|
225
227
|
};
|
|
226
228
|
var index$8 = {
|
|
227
|
-
encode: encode$
|
|
228
|
-
decode: decode$
|
|
229
|
+
encode: encode$8,
|
|
230
|
+
decode: decode$9,
|
|
229
231
|
encodeHex: encodeHex$2,
|
|
230
232
|
decodeHex: decodeHex$2,
|
|
231
233
|
isBase32,
|
|
@@ -236,13 +238,13 @@ var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
|
236
238
|
var ALPHABET_HEX = '0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv';
|
|
237
239
|
var base58 = base$1(ALPHABET$2);
|
|
238
240
|
var base58Hex = base$1(ALPHABET_HEX);
|
|
239
|
-
var encode$
|
|
240
|
-
var decode$
|
|
241
|
+
var encode$7 = base58.encode;
|
|
242
|
+
var decode$8 = base58.decode;
|
|
241
243
|
var encodeHex$1 = base58Hex.encode;
|
|
242
244
|
var decodeHex$1 = base58Hex.decode;
|
|
243
245
|
var isBase58 = function (string) {
|
|
244
246
|
try {
|
|
245
|
-
decode$
|
|
247
|
+
decode$8(string);
|
|
246
248
|
return true;
|
|
247
249
|
}
|
|
248
250
|
catch (e) {
|
|
@@ -260,7 +262,7 @@ var isBase58Hex = function (string) {
|
|
|
260
262
|
};
|
|
261
263
|
var whatType = function (string) {
|
|
262
264
|
try {
|
|
263
|
-
decode$
|
|
265
|
+
decode$8(string);
|
|
264
266
|
return 'base58';
|
|
265
267
|
}
|
|
266
268
|
catch (e) {
|
|
@@ -273,15 +275,15 @@ var whatType = function (string) {
|
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
};
|
|
276
|
-
var base58$1 = { encode: encode$
|
|
278
|
+
var base58$1 = { encode: encode$7, decode: decode$8, isBase58: isBase58, isBase58Hex: isBase58Hex, encodeHex: encodeHex$1, decodeHex: decodeHex$1, whatType: whatType };
|
|
277
279
|
|
|
278
280
|
const MSB$1 = 0x80;
|
|
279
281
|
const REST$1 = 0x7F;
|
|
280
282
|
const MSBALL = ~REST$1;
|
|
281
283
|
const INT = Math.pow(2, 31);
|
|
282
|
-
const encode$
|
|
284
|
+
const encode$6 = (num, out, offset) => {
|
|
283
285
|
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
|
|
284
|
-
encode$
|
|
286
|
+
encode$6.bytes = 0;
|
|
285
287
|
throw new RangeError('Could not encode varint');
|
|
286
288
|
}
|
|
287
289
|
out = out || [];
|
|
@@ -296,13 +298,13 @@ const encode$5 = (num, out, offset) => {
|
|
|
296
298
|
num >>>= 7;
|
|
297
299
|
}
|
|
298
300
|
out[offset] = num | 0;
|
|
299
|
-
encode$
|
|
301
|
+
encode$6.bytes = offset - oldOffset + 1;
|
|
300
302
|
return out;
|
|
301
303
|
};
|
|
302
304
|
|
|
303
305
|
const MSB = 0x80;
|
|
304
306
|
const REST = 0x7F;
|
|
305
|
-
const decode$
|
|
307
|
+
const decode$7 = (buf, offset) => {
|
|
306
308
|
offset = offset || 0;
|
|
307
309
|
const l = buf.length;
|
|
308
310
|
let counter = offset;
|
|
@@ -311,7 +313,7 @@ const decode$6 = (buf, offset) => {
|
|
|
311
313
|
let b;
|
|
312
314
|
do {
|
|
313
315
|
if (counter >= l || shift > 49) {
|
|
314
|
-
decode$
|
|
316
|
+
decode$7.bytes = 0;
|
|
315
317
|
throw new RangeError('Could not decode varint');
|
|
316
318
|
}
|
|
317
319
|
b = buf[counter++];
|
|
@@ -320,7 +322,7 @@ const decode$6 = (buf, offset) => {
|
|
|
320
322
|
: (b & REST) * Math.pow(2, shift);
|
|
321
323
|
shift += 7;
|
|
322
324
|
} while (b >= MSB);
|
|
323
|
-
decode$
|
|
325
|
+
decode$7.bytes = counter - offset;
|
|
324
326
|
return result;
|
|
325
327
|
};
|
|
326
328
|
|
|
@@ -345,8 +347,8 @@ var encodingLength = (value) => (value < N1 ? 1
|
|
|
345
347
|
: 10);
|
|
346
348
|
|
|
347
349
|
var index$7 = {
|
|
348
|
-
encode: encode$
|
|
349
|
-
decode: decode$
|
|
350
|
+
encode: encode$6,
|
|
351
|
+
decode: decode$7,
|
|
350
352
|
encodingLength
|
|
351
353
|
};
|
|
352
354
|
|
|
@@ -396,11 +398,11 @@ var index$5 = (typedArray, prefix) => {
|
|
|
396
398
|
|
|
397
399
|
const ALPHABET$1 = '0123456789ABCDEF';
|
|
398
400
|
const base16 = base$1(ALPHABET$1);
|
|
399
|
-
const decode$
|
|
400
|
-
const encode$
|
|
401
|
+
const decode$6 = base16.decode;
|
|
402
|
+
const encode$5 = base16.encode;
|
|
401
403
|
const isBase16 = (string) => {
|
|
402
404
|
try {
|
|
403
|
-
decode$
|
|
405
|
+
decode$6(string);
|
|
404
406
|
return true;
|
|
405
407
|
}
|
|
406
408
|
catch (e) {
|
|
@@ -408,18 +410,18 @@ const isBase16 = (string) => {
|
|
|
408
410
|
}
|
|
409
411
|
};
|
|
410
412
|
var index$4 = {
|
|
411
|
-
encode: encode$
|
|
412
|
-
decode: decode$
|
|
413
|
+
encode: encode$5,
|
|
414
|
+
decode: decode$6,
|
|
413
415
|
isBase16
|
|
414
416
|
};
|
|
415
417
|
|
|
416
418
|
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
417
419
|
const base64 = base$1(ALPHABET);
|
|
418
|
-
const decode$
|
|
419
|
-
const encode$
|
|
420
|
+
const decode$5 = base64.decode;
|
|
421
|
+
const encode$4 = base64.encode;
|
|
420
422
|
const isBase64 = (string) => {
|
|
421
423
|
try {
|
|
422
|
-
decode$
|
|
424
|
+
decode$5(string);
|
|
423
425
|
return true;
|
|
424
426
|
}
|
|
425
427
|
catch (e) {
|
|
@@ -427,8 +429,8 @@ const isBase64 = (string) => {
|
|
|
427
429
|
}
|
|
428
430
|
};
|
|
429
431
|
var index$3 = {
|
|
430
|
-
encode: encode$
|
|
431
|
-
decode: decode$
|
|
432
|
+
encode: encode$4,
|
|
433
|
+
decode: decode$5,
|
|
432
434
|
isBase64
|
|
433
435
|
};
|
|
434
436
|
|
|
@@ -4814,7 +4816,7 @@ const toType = (data) => {
|
|
|
4814
4816
|
return new TextEncoder().encode(data.toString());
|
|
4815
4817
|
throw new Error(`unsuported type ${typeof data || data}`);
|
|
4816
4818
|
};
|
|
4817
|
-
const encode$
|
|
4819
|
+
const encode$3 = (proto, input, compress) => {
|
|
4818
4820
|
const keys = Object.keys(proto);
|
|
4819
4821
|
const values = Object.values(proto);
|
|
4820
4822
|
const set = [];
|
|
@@ -4831,7 +4833,7 @@ const encode$2 = (proto, input, compress) => {
|
|
|
4831
4833
|
}
|
|
4832
4834
|
return index$6(set);
|
|
4833
4835
|
};
|
|
4834
|
-
const decode$
|
|
4836
|
+
const decode$4 = (proto, uint8Array, compressed) => {
|
|
4835
4837
|
let deconcated = index$5(uint8Array);
|
|
4836
4838
|
const output = {};
|
|
4837
4839
|
const keys = Object.keys(proto);
|
|
@@ -4862,8 +4864,8 @@ const decode$3 = (proto, uint8Array, compressed) => {
|
|
|
4862
4864
|
return output;
|
|
4863
4865
|
};
|
|
4864
4866
|
var index$1 = {
|
|
4865
|
-
encode: encode$
|
|
4866
|
-
decode: decode$
|
|
4867
|
+
encode: encode$3,
|
|
4868
|
+
decode: decode$4
|
|
4867
4869
|
};
|
|
4868
4870
|
|
|
4869
4871
|
/*!
|
|
@@ -6342,6 +6344,172 @@ const nothingFoundError = (hash) => {
|
|
|
6342
6344
|
return new Error(`nothing found for ${hash}`)
|
|
6343
6345
|
};
|
|
6344
6346
|
|
|
6347
|
+
// import base32 from '@vandeurenglenn/base32'
|
|
6348
|
+
// import base58 from '@vandeurenglenn/base58'
|
|
6349
|
+
|
|
6350
|
+
// export const encodings = {
|
|
6351
|
+
// base58,
|
|
6352
|
+
// base32
|
|
6353
|
+
// }
|
|
6354
|
+
|
|
6355
|
+
const encode$2 = (string, encoding = 'utf-8') => {
|
|
6356
|
+
if (typeof string === 'string') {
|
|
6357
|
+
let encoded;
|
|
6358
|
+
|
|
6359
|
+
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
6360
|
+
encoded = new TextEncoder().encode(string);
|
|
6361
|
+
return encoded
|
|
6362
|
+
}
|
|
6363
|
+
throw Error(`expected typeof String instead got ${string}`)
|
|
6364
|
+
};
|
|
6365
|
+
|
|
6366
|
+
const decode$3 = (uint8Array, encoding) => {
|
|
6367
|
+
if (uint8Array instanceof Uint8Array) {
|
|
6368
|
+
let decoded;
|
|
6369
|
+
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
6370
|
+
decoded = new TextDecoder().decode(uint8Array);
|
|
6371
|
+
|
|
6372
|
+
return decoded
|
|
6373
|
+
}
|
|
6374
|
+
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
6375
|
+
};
|
|
6376
|
+
|
|
6377
|
+
const pathSepS = '/';
|
|
6378
|
+
class KeyPath {
|
|
6379
|
+
|
|
6380
|
+
/**
|
|
6381
|
+
* @param {string | Uint8Array} input
|
|
6382
|
+
*/
|
|
6383
|
+
constructor(input) {
|
|
6384
|
+
if (typeof input === 'string') {
|
|
6385
|
+
this.uint8Array = encode$2(input);
|
|
6386
|
+
} else if (input instanceof Uint8Array) {
|
|
6387
|
+
this.uint8Array = input;
|
|
6388
|
+
} else if (input instanceof KeyPath) {
|
|
6389
|
+
this.uint8Array = input.uint8Array;
|
|
6390
|
+
} else {
|
|
6391
|
+
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
6392
|
+
}
|
|
6393
|
+
}
|
|
6394
|
+
|
|
6395
|
+
isKeyPath() {
|
|
6396
|
+
return true
|
|
6397
|
+
}
|
|
6398
|
+
|
|
6399
|
+
/**
|
|
6400
|
+
* Convert to the string representation
|
|
6401
|
+
*
|
|
6402
|
+
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
6403
|
+
* @returns {string}
|
|
6404
|
+
*/
|
|
6405
|
+
toString(encoding = 'hex') {
|
|
6406
|
+
return decode$3(this.uint8Array)
|
|
6407
|
+
}
|
|
6408
|
+
|
|
6409
|
+
/**
|
|
6410
|
+
* Returns the `list` representation of this path.
|
|
6411
|
+
*
|
|
6412
|
+
* @returns string[]
|
|
6413
|
+
*
|
|
6414
|
+
* @example
|
|
6415
|
+
* ```js
|
|
6416
|
+
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
6417
|
+
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
6418
|
+
* ```
|
|
6419
|
+
*/
|
|
6420
|
+
list() {
|
|
6421
|
+
return this.toString().split(pathSepS).slice(1)
|
|
6422
|
+
}
|
|
6423
|
+
|
|
6424
|
+
}
|
|
6425
|
+
|
|
6426
|
+
let LeofcoinStorage$1 = class LeofcoinStorage {
|
|
6427
|
+
|
|
6428
|
+
constructor(name = 'storage', root = '.leofcoin') {
|
|
6429
|
+
this.name = name;
|
|
6430
|
+
this.root = root;
|
|
6431
|
+
}
|
|
6432
|
+
|
|
6433
|
+
async init(name, root) {
|
|
6434
|
+
const importee = await import(globalThis.navigator ? './browser-store.js' : './store.js');
|
|
6435
|
+
const Store = importee.default;
|
|
6436
|
+
this.db = new Store(this.name, this.root);
|
|
6437
|
+
}
|
|
6438
|
+
|
|
6439
|
+
async get(key) {
|
|
6440
|
+
if (typeof key === 'object') return this.many('get', key);
|
|
6441
|
+
return this.db.get(new KeyPath(key))
|
|
6442
|
+
}
|
|
6443
|
+
|
|
6444
|
+
/**
|
|
6445
|
+
*
|
|
6446
|
+
* @param {*} key
|
|
6447
|
+
* @param {*} value
|
|
6448
|
+
* @returns Promise
|
|
6449
|
+
*/
|
|
6450
|
+
put(key, value) {
|
|
6451
|
+
if (typeof key === 'object') return this.many('put', key);
|
|
6452
|
+
return this.db.put(new KeyPath(key), new KeyValue(value));
|
|
6453
|
+
}
|
|
6454
|
+
|
|
6455
|
+
async has(key) {
|
|
6456
|
+
if (typeof key === 'object') return this.many('has', key);
|
|
6457
|
+
|
|
6458
|
+
try {
|
|
6459
|
+
const has = await this.db.get(new KeyPath(key));
|
|
6460
|
+
|
|
6461
|
+
return Boolean(has);
|
|
6462
|
+
} catch (e) {
|
|
6463
|
+
return false
|
|
6464
|
+
}
|
|
6465
|
+
}
|
|
6466
|
+
|
|
6467
|
+
async delete(key) {
|
|
6468
|
+
return this.db.delete(new KeyPath(key))
|
|
6469
|
+
}
|
|
6470
|
+
|
|
6471
|
+
keys(limit = -1) {
|
|
6472
|
+
return this.db.keys(limit)
|
|
6473
|
+
}
|
|
6474
|
+
|
|
6475
|
+
async values(limit = -1) {
|
|
6476
|
+
return this.db.values(limit)
|
|
6477
|
+
}
|
|
6478
|
+
|
|
6479
|
+
async many(type, _value) {
|
|
6480
|
+
const jobs = [];
|
|
6481
|
+
|
|
6482
|
+
for (const key of Object.keys(_value)) {
|
|
6483
|
+
jobs.push(this[type](key, _value[key]));
|
|
6484
|
+
}
|
|
6485
|
+
|
|
6486
|
+
return Promise.all(jobs)
|
|
6487
|
+
}
|
|
6488
|
+
|
|
6489
|
+
async length() {
|
|
6490
|
+
const keys = await this.keys();
|
|
6491
|
+
return keys.length
|
|
6492
|
+
}
|
|
6493
|
+
|
|
6494
|
+
async size() {
|
|
6495
|
+
let size = 0;
|
|
6496
|
+
const query = await this.db.iterate();
|
|
6497
|
+
for await (const item of query) {
|
|
6498
|
+
size += item.value ? item.value.length : item[1].length;
|
|
6499
|
+
}
|
|
6500
|
+
return size
|
|
6501
|
+
}
|
|
6502
|
+
|
|
6503
|
+
async clear() {
|
|
6504
|
+
return this.db.clear()
|
|
6505
|
+
}
|
|
6506
|
+
|
|
6507
|
+
async iterate() {
|
|
6508
|
+
return this.db.iterate()
|
|
6509
|
+
}
|
|
6510
|
+
|
|
6511
|
+
};
|
|
6512
|
+
|
|
6345
6513
|
const randombytes = strength => crypto.getRandomValues(new Uint8Array(strength));
|
|
6346
6514
|
|
|
6347
6515
|
const {subtle} = crypto;
|
|
@@ -20012,7 +20180,7 @@ class Identity {
|
|
|
20012
20180
|
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
20013
20181
|
}
|
|
20014
20182
|
else {
|
|
20015
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
20183
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-5f6ba5a4.js');
|
|
20016
20184
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
20017
20185
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
20018
20186
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -20050,10 +20218,10 @@ class Identity {
|
|
|
20050
20218
|
}
|
|
20051
20219
|
}
|
|
20052
20220
|
|
|
20053
|
-
globalThis.LeofcoinStorage = LeofcoinStorage;
|
|
20221
|
+
globalThis.LeofcoinStorage = LeofcoinStorage$1;
|
|
20054
20222
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
20055
|
-
pubsub = pubsub || new LittlePubSub();
|
|
20056
|
-
globalSub = globalSub || new LittlePubSub();
|
|
20223
|
+
globalThis.pubsub = globalThis.pubsub || new LittlePubSub();
|
|
20224
|
+
globalThis.globalSub = globalThis.globalSub || new LittlePubSub();
|
|
20057
20225
|
/**
|
|
20058
20226
|
* @access public
|
|
20059
20227
|
* @example
|
|
@@ -20186,7 +20354,7 @@ class Peernet {
|
|
|
20186
20354
|
this.root = options.root;
|
|
20187
20355
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
20188
20356
|
// FolderMessageResponse
|
|
20189
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
20357
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-5569e6ce.js');
|
|
20190
20358
|
/**
|
|
20191
20359
|
* proto Object containing protos
|
|
20192
20360
|
* @type {Object}
|
|
@@ -3,7 +3,7 @@ import '@vandeurenglenn/debug';
|
|
|
3
3
|
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
4
4
|
import DHT from './dht/dht.js';
|
|
5
5
|
import MessageHandler from './handlers/message.js';
|
|
6
|
-
import
|
|
6
|
+
import LeofcoinStorageClass from '@leofcoin/storage';
|
|
7
7
|
import Identity from './identity.js';
|
|
8
8
|
declare global {
|
|
9
9
|
var globalSub: PubSub;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { P as default } from './peernet-
|
|
1
|
+
export { P as default } from './peernet-9c2a381a.js';
|
|
2
|
+
import './value-157ab062.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// import base32 from '@vandeurenglenn/base32'
|
|
2
|
+
// import base58 from '@vandeurenglenn/base58'
|
|
3
|
+
|
|
4
|
+
// export const encodings = {
|
|
5
|
+
// base58,
|
|
6
|
+
// base32
|
|
7
|
+
// }
|
|
8
|
+
|
|
9
|
+
const encode = (string, encoding = 'utf-8') => {
|
|
10
|
+
if (typeof string === 'string') {
|
|
11
|
+
let encoded;
|
|
12
|
+
|
|
13
|
+
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
14
|
+
encoded = new TextEncoder().encode(string);
|
|
15
|
+
return encoded
|
|
16
|
+
}
|
|
17
|
+
throw Error(`expected typeof String instead got ${string}`)
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const decode = (uint8Array, encoding) => {
|
|
21
|
+
if (uint8Array instanceof Uint8Array) {
|
|
22
|
+
let decoded;
|
|
23
|
+
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
24
|
+
decoded = new TextDecoder().decode(uint8Array);
|
|
25
|
+
|
|
26
|
+
return decoded
|
|
27
|
+
}
|
|
28
|
+
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class KeyValue {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {string | Uint8Array} input
|
|
35
|
+
*/
|
|
36
|
+
constructor(input) {
|
|
37
|
+
if (typeof input === 'string') {
|
|
38
|
+
this.uint8Array = encode(input);
|
|
39
|
+
} else if (input instanceof Uint8Array) {
|
|
40
|
+
this.uint8Array = input;
|
|
41
|
+
} else if (input instanceof KeyValue) {
|
|
42
|
+
this.uint8Array = input.uint8Array;
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error('Invalid KeyValue, should be a String, Uint8Array or KeyValue')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
isKeyValue() {
|
|
49
|
+
return true
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Convert to the string representation
|
|
54
|
+
*
|
|
55
|
+
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
56
|
+
* @returns {string}
|
|
57
|
+
*/
|
|
58
|
+
toString(encoding = 'utf8') {
|
|
59
|
+
return decode(this.uint8Array)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { KeyValue as K };
|
package/exports/peernet.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import '@vandeurenglenn/debug';
|
|
2
2
|
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
3
3
|
import { Codec } from '@leofcoin/codec-format-interface';
|
|
4
|
+
import LeofcoinStorageClass from '@leofcoin/storage';
|
|
4
5
|
import { utils } from '@leofcoin/codecs';
|
|
5
6
|
import MultiWallet from '@leofcoin/multi-wallet';
|
|
6
7
|
import base58 from '@vandeurenglenn/base58';
|
|
@@ -380,10 +381,10 @@ class Identity {
|
|
|
380
381
|
}
|
|
381
382
|
}
|
|
382
383
|
|
|
383
|
-
globalThis.LeofcoinStorage =
|
|
384
|
+
globalThis.LeofcoinStorage = LeofcoinStorageClass;
|
|
384
385
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
385
|
-
pubsub = pubsub || new PubSub();
|
|
386
|
-
globalSub = globalSub || new PubSub();
|
|
386
|
+
globalThis.pubsub = globalThis.pubsub || new PubSub();
|
|
387
|
+
globalThis.globalSub = globalThis.globalSub || new PubSub();
|
|
387
388
|
/**
|
|
388
389
|
* @access public
|
|
389
390
|
* @example
|
|
@@ -3,7 +3,7 @@ import '@vandeurenglenn/debug';
|
|
|
3
3
|
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
4
4
|
import DHT from './dht/dht.js';
|
|
5
5
|
import MessageHandler from './handlers/message.js';
|
|
6
|
-
import
|
|
6
|
+
import LeofcoinStorageClass from '@leofcoin/storage';
|
|
7
7
|
import Identity from './identity.js';
|
|
8
8
|
declare global {
|
|
9
9
|
var globalSub: PubSub;
|
package/package.json
CHANGED
package/src/peernet.ts
CHANGED
|
@@ -8,7 +8,7 @@ import dataHandler from './handlers/data.js'
|
|
|
8
8
|
import { encapsulatedError, dhtError,
|
|
9
9
|
nothingFoundError } from './errors/errors.js'
|
|
10
10
|
|
|
11
|
-
import
|
|
11
|
+
import LeofcoinStorageClass from '@leofcoin/storage'
|
|
12
12
|
import { utils as codecUtils } from '@leofcoin/codecs'
|
|
13
13
|
import Identity from './identity.js'
|
|
14
14
|
|
|
@@ -21,11 +21,11 @@ declare global {
|
|
|
21
21
|
var LeofcoinStorageClient
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
globalThis.LeofcoinStorage =
|
|
24
|
+
globalThis.LeofcoinStorage = LeofcoinStorageClass
|
|
25
25
|
|
|
26
26
|
globalThis.leofcoin = globalThis.leofcoin || {}
|
|
27
|
-
pubsub = pubsub || new PubSub()
|
|
28
|
-
globalSub = globalSub || new PubSub()
|
|
27
|
+
globalThis.pubsub = globalThis.pubsub || new PubSub()
|
|
28
|
+
globalThis.globalSub = globalThis.globalSub || new PubSub()
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
/**
|