@leofcoin/chain 1.4.78 → 1.4.80
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 +122 -196
- package/exports/browser/chain.js +282 -246
- package/exports/browser/{index-502d190c-60cfcc02.js → index-5f6ba5a4-78b5c5ea.js} +2 -2
- package/exports/browser/index-6311966e-b5f647d8.js +37 -0
- package/exports/browser/{index-fa2c6beb.js → index-c3f4012c.js} +2 -0
- package/exports/browser/messages-54aa3cad-5309745b.js +225 -0
- package/exports/browser/messages-5569e6ce-833af778.js +225 -0
- package/exports/browser/{node-browser-b35d8f46.js → node-browser-3cbee72b.js} +200 -195
- package/exports/browser/node-browser-5fe4a30f.js +21003 -0
- package/exports/browser/node-browser.js +2 -2
- package/exports/browser/workers/block-worker.js +2 -0
- package/exports/browser/workers/machine-worker.js +2 -0
- package/exports/chain.js +278 -242
- package/exports/typings/sync-controller.d.ts +13 -0
- package/exports/typings/types.d.ts +1 -0
- package/package.json +2 -1
- package/exports/browser/messages-cd01524c-8d88d84b.js +0 -205
- package/exports/typings/chain.d.ts +0 -71
- package/exports/typings/config/config.d.ts +0 -1
- package/exports/typings/config/main.d.ts +0 -5
- package/exports/typings/config/protocol.d.ts +0 -6
- package/exports/typings/contract.d.ts +0 -31
- package/exports/typings/fee/config.d.ts +0 -4
- package/exports/typings/machine.d.ts +0 -26
- package/exports/typings/typer.d.ts +0 -6
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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}`)
|
|
1
|
+
const encode = (string) => {
|
|
2
|
+
if (typeof string === 'string')
|
|
3
|
+
return new TextEncoder().encode(string);
|
|
4
|
+
throw Error(`expected typeof String instead got ${string}`);
|
|
18
5
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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}`)
|
|
6
|
+
const decode = (uint8Array) => {
|
|
7
|
+
if (uint8Array instanceof Uint8Array)
|
|
8
|
+
return new TextDecoder().decode(uint8Array);
|
|
9
|
+
throw Error(`expected typeof uint8Array instead got ${uint8Array}`);
|
|
29
10
|
};
|
|
30
11
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
12
|
+
const pathSepS = '/';
|
|
13
|
+
class KeyPath {
|
|
14
|
+
uint8Array;
|
|
15
|
+
constructor(input) {
|
|
16
|
+
if (typeof input === 'string') {
|
|
17
|
+
this.uint8Array = encode(input);
|
|
18
|
+
}
|
|
19
|
+
else if (input instanceof Uint8Array) {
|
|
20
|
+
this.uint8Array = input;
|
|
21
|
+
}
|
|
22
|
+
else if (input instanceof KeyPath) {
|
|
23
|
+
this.uint8Array = input.uint8Array;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath');
|
|
27
|
+
}
|
|
45
28
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
29
|
+
isKeyPath() {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
toString() {
|
|
33
|
+
return decode(this.uint8Array);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the `list` representation of this path.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```js
|
|
40
|
+
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
41
|
+
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
list() {
|
|
45
|
+
return this.toString().split(pathSepS).slice(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
61
48
|
|
|
49
|
+
class KeyValue {
|
|
50
|
+
uint8Array;
|
|
51
|
+
constructor(input) {
|
|
52
|
+
if (typeof input === 'string') {
|
|
53
|
+
this.uint8Array = encode(input);
|
|
54
|
+
}
|
|
55
|
+
else if (input instanceof Uint8Array) {
|
|
56
|
+
this.uint8Array = input;
|
|
57
|
+
}
|
|
58
|
+
else if (input instanceof KeyValue) {
|
|
59
|
+
this.uint8Array = input.uint8Array;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error('Invalid KeyValue, should be a String, Uint8Array or KeyValue');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
isKeyValue() {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
toString() {
|
|
69
|
+
return decode(this.uint8Array);
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
|
|
@@ -376,149 +385,66 @@ replaceTraps((oldTraps) => ({
|
|
|
376
385
|
},
|
|
377
386
|
}));
|
|
378
387
|
|
|
379
|
-
// import base32 from '@vandeurenglenn/base32'
|
|
380
|
-
// import base58 from '@vandeurenglenn/base58'
|
|
381
|
-
|
|
382
|
-
// export const encodings = {
|
|
383
|
-
// base58,
|
|
384
|
-
// base32
|
|
385
|
-
// }
|
|
386
|
-
|
|
387
|
-
const encode = (string, encoding = 'utf-8') => {
|
|
388
|
-
if (typeof string === 'string') {
|
|
389
|
-
let encoded;
|
|
390
|
-
|
|
391
|
-
// if (encodings[encoding]) encoded = encodings[encoding].encode(encoded)
|
|
392
|
-
encoded = new TextEncoder().encode(string);
|
|
393
|
-
return encoded
|
|
394
|
-
}
|
|
395
|
-
throw Error(`expected typeof String instead got ${string}`)
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
const decode = (uint8Array, encoding) => {
|
|
399
|
-
if (uint8Array instanceof Uint8Array) {
|
|
400
|
-
let decoded;
|
|
401
|
-
// if (encodings[encoding]) decoded = encodings[encoding].decode(decoded)
|
|
402
|
-
decoded = new TextDecoder().decode(uint8Array);
|
|
403
|
-
|
|
404
|
-
return decoded
|
|
405
|
-
}
|
|
406
|
-
throw Error(`expected typeof uint8Array instead got ${uint8Array}`)
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
const pathSepS = '/';
|
|
410
|
-
class KeyPath {
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* @param {string | Uint8Array} input
|
|
414
|
-
*/
|
|
415
|
-
constructor(input) {
|
|
416
|
-
if (typeof input === 'string') {
|
|
417
|
-
this.uint8Array = encode(input);
|
|
418
|
-
} else if (input instanceof Uint8Array) {
|
|
419
|
-
this.uint8Array = input;
|
|
420
|
-
} else if (input instanceof KeyPath) {
|
|
421
|
-
this.uint8Array = input.uint8Array;
|
|
422
|
-
} else {
|
|
423
|
-
throw new Error('Invalid keyPath, should be a String, Uint8Array or KeyPath')
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
isKeyPath() {
|
|
428
|
-
return true
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Convert to the string representation
|
|
433
|
-
*
|
|
434
|
-
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use.
|
|
435
|
-
* @returns {string}
|
|
436
|
-
*/
|
|
437
|
-
toString(encoding = 'hex') {
|
|
438
|
-
return decode(this.uint8Array)
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Returns the `list` representation of this path.
|
|
443
|
-
*
|
|
444
|
-
* @returns string[]
|
|
445
|
-
*
|
|
446
|
-
* @example
|
|
447
|
-
* ```js
|
|
448
|
-
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list()
|
|
449
|
-
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese']
|
|
450
|
-
* ```
|
|
451
|
-
*/
|
|
452
|
-
list() {
|
|
453
|
-
return this.toString().split(pathSepS).slice(1)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
388
|
class BrowerStore {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
return key.toString('base32')
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
toKeyValue(value) {
|
|
476
|
-
if (!value.isKeyValue()) value = new KeyValue(value);
|
|
477
|
-
return value.uint8Array
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
async get(key) {
|
|
481
|
-
return (await this.db).get(this.name, this.toKeyPath(key))
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
async put(key, value) {
|
|
485
|
-
return (await this.db).put(this.name, this.toKeyValue(value), this.toKeyPath(key))
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
async delete(key) {
|
|
489
|
-
return (await this.db).delete(this.name, this.toKeyPath(key))
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
async clear() {
|
|
493
|
-
return (await this.db).clear(this.name)
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
async values(limit = -1) {
|
|
497
|
-
const values = [];
|
|
498
|
-
const tx = (await this.db).transaction(this.name);
|
|
499
|
-
|
|
500
|
-
for await (const cursor of tx.store) {
|
|
501
|
-
values.push(cursor.value);
|
|
502
|
-
if (limit && values.length === limit) return values
|
|
389
|
+
db;
|
|
390
|
+
name;
|
|
391
|
+
root;
|
|
392
|
+
version;
|
|
393
|
+
constructor(name = 'storage', root = '.leofcoin', version = '1') {
|
|
394
|
+
this.version = version;
|
|
395
|
+
this.name = name;
|
|
396
|
+
this.root = root;
|
|
397
|
+
this.db = openDB(`${root}/${name}`, Number(version), {
|
|
398
|
+
upgrade(db) {
|
|
399
|
+
db.createObjectStore(name);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
503
402
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
403
|
+
toKeyPath(key) {
|
|
404
|
+
if (!key.isKeyPath())
|
|
405
|
+
key = new KeyPath(key);
|
|
406
|
+
return key.toString('base32');
|
|
407
|
+
}
|
|
408
|
+
toKeyValue(value) {
|
|
409
|
+
if (!value.isKeyValue())
|
|
410
|
+
value = new KeyValue(value);
|
|
411
|
+
return value.uint8Array;
|
|
412
|
+
}
|
|
413
|
+
async get(key) {
|
|
414
|
+
return (await this.db).get(this.name, this.toKeyPath(key));
|
|
415
|
+
}
|
|
416
|
+
async put(key, value) {
|
|
417
|
+
return (await this.db).put(this.name, this.toKeyValue(value), this.toKeyPath(key));
|
|
418
|
+
}
|
|
419
|
+
async delete(key) {
|
|
420
|
+
return (await this.db).delete(this.name, this.toKeyPath(key));
|
|
421
|
+
}
|
|
422
|
+
async clear() {
|
|
423
|
+
return (await this.db).clear(this.name);
|
|
424
|
+
}
|
|
425
|
+
async values(limit = -1) {
|
|
426
|
+
const values = [];
|
|
427
|
+
const tx = (await this.db).transaction(this.name);
|
|
428
|
+
for await (const cursor of tx.store) {
|
|
429
|
+
values.push(cursor.value);
|
|
430
|
+
if (limit && values.length === limit)
|
|
431
|
+
return values;
|
|
432
|
+
}
|
|
433
|
+
return values;
|
|
434
|
+
}
|
|
435
|
+
async keys(limit = -1) {
|
|
436
|
+
const keys = [];
|
|
437
|
+
const tx = (await this.db).transaction(this.name);
|
|
438
|
+
for await (const cursor of tx.store) {
|
|
439
|
+
keys.push(cursor.key);
|
|
440
|
+
if (limit && keys.length === limit)
|
|
441
|
+
return keys;
|
|
442
|
+
}
|
|
443
|
+
return keys;
|
|
444
|
+
}
|
|
445
|
+
async iterate() {
|
|
446
|
+
return (await this.db).transaction(this.name).store;
|
|
514
447
|
}
|
|
515
|
-
return keys
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
async iterate() {
|
|
519
|
-
return (await this.db).transaction(this.name).store
|
|
520
|
-
}
|
|
521
|
-
|
|
522
448
|
}
|
|
523
449
|
|
|
524
450
|
export { BrowerStore as default };
|