@typeberry/lib 0.1.2 → 0.1.3-0eba10b
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/index.cjs +1273 -1454
- package/index.d.ts +2003 -1430
- package/index.js +1254 -1436
- package/package.json +1 -1
- package/bin/lib/index.d.ts +0 -29
- package/configs/index.d.ts +0 -76
package/index.cjs
CHANGED
|
@@ -38,8 +38,9 @@ function parseCurrentVersion(env) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
function parseCurrentSuite(env) {
|
|
41
|
-
if (env === undefined)
|
|
41
|
+
if (env === undefined) {
|
|
42
42
|
return undefined;
|
|
43
|
+
}
|
|
43
44
|
switch (env) {
|
|
44
45
|
case TestSuite.W3F_DAVXY:
|
|
45
46
|
case TestSuite.JAMDUNA:
|
|
@@ -332,6 +333,19 @@ const Result$1 = {
|
|
|
332
333
|
},
|
|
333
334
|
};
|
|
334
335
|
|
|
336
|
+
// about 2GB, the maximum ArrayBuffer length on Chrome confirmed by several sources:
|
|
337
|
+
// - https://issues.chromium.org/issues/40055619
|
|
338
|
+
// - https://stackoverflow.com/a/72124984
|
|
339
|
+
// - https://onnxruntime.ai/docs/tutorials/web/large-models.html#maximum-size-of-arraybuffer
|
|
340
|
+
const MAX_LENGTH$2 = 2145386496;
|
|
341
|
+
function safeAllocUint8Array(length) {
|
|
342
|
+
if (length > MAX_LENGTH$2) {
|
|
343
|
+
// biome-ignore lint/suspicious/noConsole: can't have a dependency on logger here
|
|
344
|
+
console.warn(`Trying to allocate ${length} bytes, which is greater than the maximum of ${MAX_LENGTH$2}.`);
|
|
345
|
+
}
|
|
346
|
+
return new Uint8Array(Math.min(MAX_LENGTH$2, length));
|
|
347
|
+
}
|
|
348
|
+
|
|
335
349
|
/**
|
|
336
350
|
* Utilities for tests.
|
|
337
351
|
*/
|
|
@@ -446,10 +460,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
446
460
|
.sort((a, b) => {
|
|
447
461
|
const aKey = `${a.key}`;
|
|
448
462
|
const bKey = `${b.key}`;
|
|
449
|
-
if (aKey < bKey)
|
|
463
|
+
if (aKey < bKey) {
|
|
450
464
|
return -1;
|
|
451
|
-
|
|
465
|
+
}
|
|
466
|
+
if (bKey < aKey) {
|
|
452
467
|
return 1;
|
|
468
|
+
}
|
|
453
469
|
return 0;
|
|
454
470
|
});
|
|
455
471
|
};
|
|
@@ -563,7 +579,7 @@ function isResult(x) {
|
|
|
563
579
|
* as an afterthought.
|
|
564
580
|
*/
|
|
565
581
|
|
|
566
|
-
var index$
|
|
582
|
+
var index$u = /*#__PURE__*/Object.freeze({
|
|
567
583
|
__proto__: null,
|
|
568
584
|
get CURRENT_SUITE () { return CURRENT_SUITE; },
|
|
569
585
|
get CURRENT_VERSION () { return CURRENT_VERSION; },
|
|
@@ -572,6 +588,7 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
572
588
|
DEFAULT_VERSION: DEFAULT_VERSION,
|
|
573
589
|
ErrorsCollector: ErrorsCollector,
|
|
574
590
|
get GpVersion () { return GpVersion; },
|
|
591
|
+
MAX_LENGTH: MAX_LENGTH$2,
|
|
575
592
|
OK: OK,
|
|
576
593
|
Result: Result$1,
|
|
577
594
|
TEST_COMPARE_USING: TEST_COMPARE_USING,
|
|
@@ -586,6 +603,7 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
586
603
|
isBrowser: isBrowser,
|
|
587
604
|
measure: measure,
|
|
588
605
|
resultToString: resultToString,
|
|
606
|
+
safeAllocUint8Array: safeAllocUint8Array,
|
|
589
607
|
seeThrough: seeThrough,
|
|
590
608
|
workspacePathFix: workspacePathFix
|
|
591
609
|
});
|
|
@@ -609,7 +627,7 @@ class BitVec {
|
|
|
609
627
|
* Create new [`BitVec`] with all values set to `false`.
|
|
610
628
|
*/
|
|
611
629
|
static empty(bitLength) {
|
|
612
|
-
const data =
|
|
630
|
+
const data = safeAllocUint8Array(Math.ceil(bitLength / 8));
|
|
613
631
|
return new BitVec(data, bitLength);
|
|
614
632
|
}
|
|
615
633
|
byteLength;
|
|
@@ -717,7 +735,7 @@ class Ordering {
|
|
|
717
735
|
}
|
|
718
736
|
}
|
|
719
737
|
|
|
720
|
-
var index$
|
|
738
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
721
739
|
__proto__: null,
|
|
722
740
|
Ordering: Ordering
|
|
723
741
|
});
|
|
@@ -810,7 +828,7 @@ class BytesBlob {
|
|
|
810
828
|
static blobFromParts(v, ...rest) {
|
|
811
829
|
const vArr = v instanceof Uint8Array ? [v] : v;
|
|
812
830
|
const totalLength = vArr.reduce((a, v) => a + v.length, 0) + rest.reduce((a, v) => a + v.length, 0);
|
|
813
|
-
const buffer =
|
|
831
|
+
const buffer = safeAllocUint8Array(totalLength);
|
|
814
832
|
let offset = 0;
|
|
815
833
|
for (const r of vArr) {
|
|
816
834
|
buffer.set(r, offset);
|
|
@@ -883,7 +901,7 @@ class Bytes extends BytesBlob {
|
|
|
883
901
|
}
|
|
884
902
|
/** Create an empty [`Bytes<X>`] of given length. */
|
|
885
903
|
static zero(len) {
|
|
886
|
-
return new Bytes(
|
|
904
|
+
return new Bytes(safeAllocUint8Array(len), len);
|
|
887
905
|
}
|
|
888
906
|
// TODO [ToDr] `fill` should have the argments swapped to align with the rest.
|
|
889
907
|
/** Create a [`Bytes<X>`] with all bytes filled with given input number. */
|
|
@@ -968,7 +986,7 @@ function u8ArraySameLengthEqual(self, other) {
|
|
|
968
986
|
}
|
|
969
987
|
const bytesBlobComparator = (a, b) => a.compare(b);
|
|
970
988
|
|
|
971
|
-
var index$
|
|
989
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
972
990
|
__proto__: null,
|
|
973
991
|
BitVec: BitVec,
|
|
974
992
|
Bytes: Bytes,
|
|
@@ -1070,7 +1088,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
|
|
|
1070
1088
|
/** Get the biggest value between U64 a and values given as input parameters. */
|
|
1071
1089
|
const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
|
|
1072
1090
|
|
|
1073
|
-
var index$
|
|
1091
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
1074
1092
|
__proto__: null,
|
|
1075
1093
|
isU16: isU16,
|
|
1076
1094
|
isU32: isU32,
|
|
@@ -1947,13 +1965,15 @@ function validateLength(range, length, context) {
|
|
|
1947
1965
|
|
|
1948
1966
|
/** A caching wrapper for either object or sequence item. */
|
|
1949
1967
|
class ViewField {
|
|
1968
|
+
name;
|
|
1950
1969
|
getView;
|
|
1951
1970
|
getValue;
|
|
1952
1971
|
getEncoded;
|
|
1953
1972
|
cachedValue;
|
|
1954
1973
|
cachedView;
|
|
1955
1974
|
cachedBlob;
|
|
1956
|
-
constructor(getView, getValue, getEncoded) {
|
|
1975
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
1976
|
+
this.name = name;
|
|
1957
1977
|
this.getView = getView;
|
|
1958
1978
|
this.getValue = getValue;
|
|
1959
1979
|
this.getEncoded = getEncoded;
|
|
@@ -1979,6 +1999,9 @@ class ViewField {
|
|
|
1979
1999
|
}
|
|
1980
2000
|
return this.cachedBlob;
|
|
1981
2001
|
}
|
|
2002
|
+
toString() {
|
|
2003
|
+
return `ViewField<${this.name}>`;
|
|
2004
|
+
}
|
|
1982
2005
|
}
|
|
1983
2006
|
/**
|
|
1984
2007
|
* A base class for all the lazy views.
|
|
@@ -2053,7 +2076,7 @@ class ObjectView {
|
|
|
2053
2076
|
const fieldDecoder = skipper.decoder.clone();
|
|
2054
2077
|
const field = this.descriptorsKeys[i];
|
|
2055
2078
|
const type = this.descriptors[field];
|
|
2056
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2079
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2057
2080
|
// skip the field
|
|
2058
2081
|
type.skip(skipper);
|
|
2059
2082
|
// cache data
|
|
@@ -2065,6 +2088,9 @@ class ObjectView {
|
|
|
2065
2088
|
}
|
|
2066
2089
|
return lastItem;
|
|
2067
2090
|
}
|
|
2091
|
+
toString() {
|
|
2092
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2093
|
+
}
|
|
2068
2094
|
}
|
|
2069
2095
|
/**
|
|
2070
2096
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2153,7 +2179,7 @@ class SequenceView {
|
|
|
2153
2179
|
// create new cached prop
|
|
2154
2180
|
const fieldDecoder = skipper.decoder.clone();
|
|
2155
2181
|
const type = this.descriptor;
|
|
2156
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2182
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2157
2183
|
// skip the field
|
|
2158
2184
|
type.skip(skipper);
|
|
2159
2185
|
// cache data
|
|
@@ -2165,6 +2191,9 @@ class SequenceView {
|
|
|
2165
2191
|
}
|
|
2166
2192
|
return lastItem;
|
|
2167
2193
|
}
|
|
2194
|
+
toString() {
|
|
2195
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2196
|
+
}
|
|
2168
2197
|
}
|
|
2169
2198
|
|
|
2170
2199
|
/**
|
|
@@ -2480,7 +2509,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
2480
2509
|
}, skipper);
|
|
2481
2510
|
}
|
|
2482
2511
|
|
|
2483
|
-
var index$
|
|
2512
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
2484
2513
|
__proto__: null,
|
|
2485
2514
|
Decoder: Decoder,
|
|
2486
2515
|
Descriptor: Descriptor,
|
|
@@ -3581,7 +3610,7 @@ async function verify(input) {
|
|
|
3581
3610
|
return Promise.resolve([]);
|
|
3582
3611
|
}
|
|
3583
3612
|
const dataLength = input.reduce((acc, { message, key, signature }) => acc + key.length + signature.length + message.length + 1, 0);
|
|
3584
|
-
const data =
|
|
3613
|
+
const data = safeAllocUint8Array(dataLength);
|
|
3585
3614
|
let offset = 0;
|
|
3586
3615
|
for (const { key, message, signature } of input) {
|
|
3587
3616
|
data.set(key.raw, offset);
|
|
@@ -3628,823 +3657,75 @@ var ed25519 = /*#__PURE__*/Object.freeze({
|
|
|
3628
3657
|
verifyBatch: verifyBatch
|
|
3629
3658
|
});
|
|
3630
3659
|
|
|
3660
|
+
const SEED_SIZE = 32;
|
|
3661
|
+
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
3662
|
+
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
3631
3663
|
/**
|
|
3632
|
-
*
|
|
3633
|
-
*
|
|
3634
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
3664
|
+
* JIP-5: Secret key derivation
|
|
3635
3665
|
*
|
|
3636
|
-
*/
|
|
3637
|
-
const HASH_SIZE = 32;
|
|
3638
|
-
/** A hash without last byte (useful for trie representation). */
|
|
3639
|
-
const TRUNCATED_HASH_SIZE = 31;
|
|
3640
|
-
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
3666
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
3641
3667
|
/**
|
|
3642
|
-
*
|
|
3643
|
-
*
|
|
3644
|
-
* After calculating the hash these two should be passed together to avoid
|
|
3645
|
-
* unnecessary re-hashing of the data.
|
|
3668
|
+
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
3669
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
3646
3670
|
*/
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
constructor(hash, data) {
|
|
3651
|
-
super();
|
|
3652
|
-
this.hash = hash;
|
|
3653
|
-
this.data = data;
|
|
3654
|
-
}
|
|
3671
|
+
function trivialSeed(s) {
|
|
3672
|
+
const s_le = u32AsLeBytes(s);
|
|
3673
|
+
return Bytes.fromBlob(BytesBlob.blobFromParts([s_le, s_le, s_le, s_le, s_le, s_le, s_le, s_le]).raw, SEED_SIZE).asOpaque();
|
|
3655
3674
|
}
|
|
3656
3675
|
/**
|
|
3657
|
-
*
|
|
3676
|
+
* Derives a Ed25519 secret key from a seed.
|
|
3677
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
3658
3678
|
*/
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
constructor(hash, data, encoded) {
|
|
3662
|
-
super(hash, data);
|
|
3663
|
-
this.encoded = encoded;
|
|
3664
|
-
}
|
|
3665
|
-
}
|
|
3666
|
-
|
|
3667
|
-
/** The simplest allocator returning just a fresh copy of bytes each time. */
|
|
3668
|
-
class SimpleAllocator {
|
|
3669
|
-
emptyHash() {
|
|
3670
|
-
return Bytes.zero(HASH_SIZE);
|
|
3671
|
-
}
|
|
3672
|
-
}
|
|
3673
|
-
/** An allocator that works by allocating larger (continuous) pages of memory. */
|
|
3674
|
-
class PageAllocator {
|
|
3675
|
-
hashesPerPage;
|
|
3676
|
-
page = new Uint8Array(0);
|
|
3677
|
-
currentHash = 0;
|
|
3678
|
-
// TODO [ToDr] Benchmark the performance!
|
|
3679
|
-
constructor(hashesPerPage) {
|
|
3680
|
-
this.hashesPerPage = hashesPerPage;
|
|
3681
|
-
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
3682
|
-
this.resetPage();
|
|
3683
|
-
}
|
|
3684
|
-
resetPage() {
|
|
3685
|
-
const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
|
|
3686
|
-
this.currentHash = 0;
|
|
3687
|
-
this.page = new Uint8Array(pageSizeBytes);
|
|
3688
|
-
}
|
|
3689
|
-
emptyHash() {
|
|
3690
|
-
const startIdx = this.currentHash * HASH_SIZE;
|
|
3691
|
-
const endIdx = startIdx + HASH_SIZE;
|
|
3692
|
-
this.currentHash += 1;
|
|
3693
|
-
if (this.currentHash >= this.hashesPerPage) {
|
|
3694
|
-
this.resetPage();
|
|
3695
|
-
}
|
|
3696
|
-
return Bytes.fromBlob(this.page.subarray(startIdx, endIdx), HASH_SIZE);
|
|
3697
|
-
}
|
|
3698
|
-
}
|
|
3699
|
-
const defaultAllocator = new SimpleAllocator();
|
|
3700
|
-
|
|
3701
|
-
function getDefaultExportFromCjs (x) {
|
|
3702
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3703
|
-
}
|
|
3704
|
-
|
|
3705
|
-
var blake2b$3 = {exports: {}};
|
|
3706
|
-
|
|
3707
|
-
var nanoassert;
|
|
3708
|
-
var hasRequiredNanoassert;
|
|
3709
|
-
|
|
3710
|
-
function requireNanoassert () {
|
|
3711
|
-
if (hasRequiredNanoassert) return nanoassert;
|
|
3712
|
-
hasRequiredNanoassert = 1;
|
|
3713
|
-
nanoassert = assert;
|
|
3714
|
-
|
|
3715
|
-
class AssertionError extends Error {}
|
|
3716
|
-
AssertionError.prototype.name = 'AssertionError';
|
|
3717
|
-
|
|
3718
|
-
/**
|
|
3719
|
-
* Minimal assert function
|
|
3720
|
-
* @param {any} t Value to check if falsy
|
|
3721
|
-
* @param {string=} m Optional assertion error message
|
|
3722
|
-
* @throws {AssertionError}
|
|
3723
|
-
*/
|
|
3724
|
-
function assert (t, m) {
|
|
3725
|
-
if (!t) {
|
|
3726
|
-
var err = new AssertionError(m);
|
|
3727
|
-
if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
|
|
3728
|
-
throw err
|
|
3729
|
-
}
|
|
3730
|
-
}
|
|
3731
|
-
return nanoassert;
|
|
3732
|
-
}
|
|
3733
|
-
|
|
3734
|
-
var blake2bWasm = {exports: {}};
|
|
3735
|
-
|
|
3736
|
-
var b4a;
|
|
3737
|
-
var hasRequiredB4a;
|
|
3738
|
-
|
|
3739
|
-
function requireB4a () {
|
|
3740
|
-
if (hasRequiredB4a) return b4a;
|
|
3741
|
-
hasRequiredB4a = 1;
|
|
3742
|
-
function isBuffer (value) {
|
|
3743
|
-
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
3744
|
-
}
|
|
3745
|
-
|
|
3746
|
-
function isEncoding (encoding) {
|
|
3747
|
-
return Buffer.isEncoding(encoding)
|
|
3748
|
-
}
|
|
3749
|
-
|
|
3750
|
-
function alloc (size, fill, encoding) {
|
|
3751
|
-
return Buffer.alloc(size, fill, encoding)
|
|
3752
|
-
}
|
|
3753
|
-
|
|
3754
|
-
function allocUnsafe (size) {
|
|
3755
|
-
return Buffer.allocUnsafe(size)
|
|
3756
|
-
}
|
|
3757
|
-
|
|
3758
|
-
function allocUnsafeSlow (size) {
|
|
3759
|
-
return Buffer.allocUnsafeSlow(size)
|
|
3760
|
-
}
|
|
3761
|
-
|
|
3762
|
-
function byteLength (string, encoding) {
|
|
3763
|
-
return Buffer.byteLength(string, encoding)
|
|
3764
|
-
}
|
|
3765
|
-
|
|
3766
|
-
function compare (a, b) {
|
|
3767
|
-
return Buffer.compare(a, b)
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3770
|
-
function concat (buffers, totalLength) {
|
|
3771
|
-
return Buffer.concat(buffers, totalLength)
|
|
3772
|
-
}
|
|
3773
|
-
|
|
3774
|
-
function copy (source, target, targetStart, start, end) {
|
|
3775
|
-
return toBuffer(source).copy(target, targetStart, start, end)
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
function equals (a, b) {
|
|
3779
|
-
return toBuffer(a).equals(b)
|
|
3780
|
-
}
|
|
3781
|
-
|
|
3782
|
-
function fill (buffer, value, offset, end, encoding) {
|
|
3783
|
-
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
3784
|
-
}
|
|
3785
|
-
|
|
3786
|
-
function from (value, encodingOrOffset, length) {
|
|
3787
|
-
return Buffer.from(value, encodingOrOffset, length)
|
|
3788
|
-
}
|
|
3789
|
-
|
|
3790
|
-
function includes (buffer, value, byteOffset, encoding) {
|
|
3791
|
-
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
3792
|
-
}
|
|
3793
|
-
|
|
3794
|
-
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
3795
|
-
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
3796
|
-
}
|
|
3797
|
-
|
|
3798
|
-
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
3799
|
-
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
function swap16 (buffer) {
|
|
3803
|
-
return toBuffer(buffer).swap16()
|
|
3804
|
-
}
|
|
3805
|
-
|
|
3806
|
-
function swap32 (buffer) {
|
|
3807
|
-
return toBuffer(buffer).swap32()
|
|
3808
|
-
}
|
|
3809
|
-
|
|
3810
|
-
function swap64 (buffer) {
|
|
3811
|
-
return toBuffer(buffer).swap64()
|
|
3812
|
-
}
|
|
3813
|
-
|
|
3814
|
-
function toBuffer (buffer) {
|
|
3815
|
-
if (Buffer.isBuffer(buffer)) return buffer
|
|
3816
|
-
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
3817
|
-
}
|
|
3818
|
-
|
|
3819
|
-
function toString (buffer, encoding, start, end) {
|
|
3820
|
-
return toBuffer(buffer).toString(encoding, start, end)
|
|
3821
|
-
}
|
|
3822
|
-
|
|
3823
|
-
function write (buffer, string, offset, length, encoding) {
|
|
3824
|
-
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
3825
|
-
}
|
|
3826
|
-
|
|
3827
|
-
function writeDoubleLE (buffer, value, offset) {
|
|
3828
|
-
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
function writeFloatLE (buffer, value, offset) {
|
|
3832
|
-
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
3833
|
-
}
|
|
3834
|
-
|
|
3835
|
-
function writeUInt32LE (buffer, value, offset) {
|
|
3836
|
-
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
3837
|
-
}
|
|
3838
|
-
|
|
3839
|
-
function writeInt32LE (buffer, value, offset) {
|
|
3840
|
-
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
3841
|
-
}
|
|
3842
|
-
|
|
3843
|
-
function readDoubleLE (buffer, offset) {
|
|
3844
|
-
return toBuffer(buffer).readDoubleLE(offset)
|
|
3845
|
-
}
|
|
3846
|
-
|
|
3847
|
-
function readFloatLE (buffer, offset) {
|
|
3848
|
-
return toBuffer(buffer).readFloatLE(offset)
|
|
3849
|
-
}
|
|
3850
|
-
|
|
3851
|
-
function readUInt32LE (buffer, offset) {
|
|
3852
|
-
return toBuffer(buffer).readUInt32LE(offset)
|
|
3853
|
-
}
|
|
3854
|
-
|
|
3855
|
-
function readInt32LE (buffer, offset) {
|
|
3856
|
-
return toBuffer(buffer).readInt32LE(offset)
|
|
3857
|
-
}
|
|
3858
|
-
|
|
3859
|
-
b4a = {
|
|
3860
|
-
isBuffer,
|
|
3861
|
-
isEncoding,
|
|
3862
|
-
alloc,
|
|
3863
|
-
allocUnsafe,
|
|
3864
|
-
allocUnsafeSlow,
|
|
3865
|
-
byteLength,
|
|
3866
|
-
compare,
|
|
3867
|
-
concat,
|
|
3868
|
-
copy,
|
|
3869
|
-
equals,
|
|
3870
|
-
fill,
|
|
3871
|
-
from,
|
|
3872
|
-
includes,
|
|
3873
|
-
indexOf,
|
|
3874
|
-
lastIndexOf,
|
|
3875
|
-
swap16,
|
|
3876
|
-
swap32,
|
|
3877
|
-
swap64,
|
|
3878
|
-
toBuffer,
|
|
3879
|
-
toString,
|
|
3880
|
-
write,
|
|
3881
|
-
writeDoubleLE,
|
|
3882
|
-
writeFloatLE,
|
|
3883
|
-
writeUInt32LE,
|
|
3884
|
-
writeInt32LE,
|
|
3885
|
-
readDoubleLE,
|
|
3886
|
-
readFloatLE,
|
|
3887
|
-
readUInt32LE,
|
|
3888
|
-
readInt32LE
|
|
3889
|
-
};
|
|
3890
|
-
return b4a;
|
|
3891
|
-
}
|
|
3892
|
-
|
|
3893
|
-
var blake2b$2;
|
|
3894
|
-
var hasRequiredBlake2b$1;
|
|
3895
|
-
|
|
3896
|
-
function requireBlake2b$1 () {
|
|
3897
|
-
if (hasRequiredBlake2b$1) return blake2b$2;
|
|
3898
|
-
hasRequiredBlake2b$1 = 1;
|
|
3899
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3900
|
-
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3901
|
-
};
|
|
3902
|
-
var __toBinary = /* @__PURE__ */ (() => {
|
|
3903
|
-
var table = new Uint8Array(128);
|
|
3904
|
-
for (var i = 0; i < 64; i++)
|
|
3905
|
-
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
3906
|
-
return (base64) => {
|
|
3907
|
-
var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
3908
|
-
for (var i2 = 0, j = 0; i2 < n; ) {
|
|
3909
|
-
var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
3910
|
-
var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
3911
|
-
bytes2[j++] = c0 << 2 | c1 >> 4;
|
|
3912
|
-
bytes2[j++] = c1 << 4 | c2 >> 2;
|
|
3913
|
-
bytes2[j++] = c2 << 6 | c3;
|
|
3914
|
-
}
|
|
3915
|
-
return bytes2;
|
|
3916
|
-
};
|
|
3917
|
-
})();
|
|
3918
|
-
|
|
3919
|
-
// wasm-binary:./blake2b.wat
|
|
3920
|
-
var require_blake2b = __commonJS({
|
|
3921
|
-
"wasm-binary:./blake2b.wat"(exports2, module2) {
|
|
3922
|
-
module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFq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4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
|
|
3923
|
-
}
|
|
3924
|
-
});
|
|
3925
|
-
|
|
3926
|
-
// wasm-module:./blake2b.wat
|
|
3927
|
-
var bytes = require_blake2b();
|
|
3928
|
-
var compiled = WebAssembly.compile(bytes);
|
|
3929
|
-
blake2b$2 = async (imports) => {
|
|
3930
|
-
const instance = await WebAssembly.instantiate(await compiled, imports);
|
|
3931
|
-
return instance.exports;
|
|
3932
|
-
};
|
|
3933
|
-
return blake2b$2;
|
|
3934
|
-
}
|
|
3935
|
-
|
|
3936
|
-
var hasRequiredBlake2bWasm;
|
|
3937
|
-
|
|
3938
|
-
function requireBlake2bWasm () {
|
|
3939
|
-
if (hasRequiredBlake2bWasm) return blake2bWasm.exports;
|
|
3940
|
-
hasRequiredBlake2bWasm = 1;
|
|
3941
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
3942
|
-
var b4a = /*@__PURE__*/ requireB4a();
|
|
3943
|
-
|
|
3944
|
-
var wasm = null;
|
|
3945
|
-
var wasmPromise = typeof WebAssembly !== "undefined" && /*@__PURE__*/ requireBlake2b$1()().then(mod => {
|
|
3946
|
-
wasm = mod;
|
|
3947
|
-
});
|
|
3948
|
-
|
|
3949
|
-
var head = 64;
|
|
3950
|
-
var freeList = [];
|
|
3951
|
-
|
|
3952
|
-
blake2bWasm.exports = Blake2b;
|
|
3953
|
-
var BYTES_MIN = blake2bWasm.exports.BYTES_MIN = 16;
|
|
3954
|
-
var BYTES_MAX = blake2bWasm.exports.BYTES_MAX = 64;
|
|
3955
|
-
blake2bWasm.exports.BYTES = 32;
|
|
3956
|
-
var KEYBYTES_MIN = blake2bWasm.exports.KEYBYTES_MIN = 16;
|
|
3957
|
-
var KEYBYTES_MAX = blake2bWasm.exports.KEYBYTES_MAX = 64;
|
|
3958
|
-
blake2bWasm.exports.KEYBYTES = 32;
|
|
3959
|
-
var SALTBYTES = blake2bWasm.exports.SALTBYTES = 16;
|
|
3960
|
-
var PERSONALBYTES = blake2bWasm.exports.PERSONALBYTES = 16;
|
|
3961
|
-
|
|
3962
|
-
function Blake2b (digestLength, key, salt, personal, noAssert) {
|
|
3963
|
-
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
|
|
3964
|
-
if (!wasm) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
|
|
3965
|
-
if (!digestLength) digestLength = 32;
|
|
3966
|
-
|
|
3967
|
-
if (noAssert !== true) {
|
|
3968
|
-
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength);
|
|
3969
|
-
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength);
|
|
3970
|
-
if (key != null) {
|
|
3971
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
3972
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
3973
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at least ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
3974
|
-
}
|
|
3975
|
-
if (salt != null) {
|
|
3976
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
3977
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
3978
|
-
}
|
|
3979
|
-
if (personal != null) {
|
|
3980
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
3981
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
3982
|
-
}
|
|
3983
|
-
}
|
|
3984
|
-
|
|
3985
|
-
if (!freeList.length) {
|
|
3986
|
-
freeList.push(head);
|
|
3987
|
-
head += 216;
|
|
3988
|
-
}
|
|
3989
|
-
|
|
3990
|
-
this.digestLength = digestLength;
|
|
3991
|
-
this.finalized = false;
|
|
3992
|
-
this.pointer = freeList.pop();
|
|
3993
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
3994
|
-
|
|
3995
|
-
this._memory.fill(0, 0, 64);
|
|
3996
|
-
this._memory[0] = this.digestLength;
|
|
3997
|
-
this._memory[1] = key ? key.length : 0;
|
|
3998
|
-
this._memory[2] = 1; // fanout
|
|
3999
|
-
this._memory[3] = 1; // depth
|
|
4000
|
-
|
|
4001
|
-
if (salt) this._memory.set(salt, 32);
|
|
4002
|
-
if (personal) this._memory.set(personal, 48);
|
|
4003
|
-
|
|
4004
|
-
if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216); // we need 216 bytes for the state
|
|
4005
|
-
wasm.blake2b_init(this.pointer, this.digestLength);
|
|
4006
|
-
|
|
4007
|
-
if (key) {
|
|
4008
|
-
this.update(key);
|
|
4009
|
-
this._memory.fill(0, head, head + key.length); // whiteout key
|
|
4010
|
-
this._memory[this.pointer + 200] = 128;
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
|
-
|
|
4014
|
-
Blake2b.prototype._realloc = function (size) {
|
|
4015
|
-
wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
|
|
4016
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4017
|
-
};
|
|
4018
|
-
|
|
4019
|
-
Blake2b.prototype.update = function (input) {
|
|
4020
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4021
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4022
|
-
|
|
4023
|
-
if (head + input.length > this._memory.length) this._realloc(head + input.length);
|
|
4024
|
-
this._memory.set(input, head);
|
|
4025
|
-
wasm.blake2b_update(this.pointer, head, head + input.length);
|
|
4026
|
-
return this
|
|
4027
|
-
};
|
|
4028
|
-
|
|
4029
|
-
Blake2b.prototype.digest = function (enc) {
|
|
4030
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4031
|
-
this.finalized = true;
|
|
4032
|
-
|
|
4033
|
-
freeList.push(this.pointer);
|
|
4034
|
-
wasm.blake2b_final(this.pointer);
|
|
4035
|
-
|
|
4036
|
-
if (!enc || enc === 'binary') {
|
|
4037
|
-
return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4038
|
-
}
|
|
4039
|
-
|
|
4040
|
-
if (typeof enc === 'string') {
|
|
4041
|
-
return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4042
|
-
}
|
|
4043
|
-
|
|
4044
|
-
assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
|
|
4045
|
-
for (var i = 0; i < this.digestLength; i++) {
|
|
4046
|
-
enc[i] = this._memory[this.pointer + 128 + i];
|
|
4047
|
-
}
|
|
4048
|
-
|
|
4049
|
-
return enc
|
|
4050
|
-
};
|
|
4051
|
-
|
|
4052
|
-
// libsodium compat
|
|
4053
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4054
|
-
|
|
4055
|
-
Blake2b.WASM = wasm;
|
|
4056
|
-
Blake2b.SUPPORTED = typeof WebAssembly !== 'undefined';
|
|
4057
|
-
|
|
4058
|
-
Blake2b.ready = function (cb) {
|
|
4059
|
-
if (!cb) cb = noop;
|
|
4060
|
-
if (!wasmPromise) return cb(new Error('WebAssembly not supported'))
|
|
4061
|
-
return wasmPromise.then(() => cb(), cb)
|
|
4062
|
-
};
|
|
4063
|
-
|
|
4064
|
-
Blake2b.prototype.ready = Blake2b.ready;
|
|
4065
|
-
|
|
4066
|
-
Blake2b.prototype.getPartialHash = function () {
|
|
4067
|
-
return this._memory.slice(this.pointer, this.pointer + 216);
|
|
4068
|
-
};
|
|
4069
|
-
|
|
4070
|
-
Blake2b.prototype.setPartialHash = function (ph) {
|
|
4071
|
-
this._memory.set(ph, this.pointer);
|
|
4072
|
-
};
|
|
4073
|
-
|
|
4074
|
-
function noop () {}
|
|
4075
|
-
return blake2bWasm.exports;
|
|
4076
|
-
}
|
|
4077
|
-
|
|
4078
|
-
var hasRequiredBlake2b;
|
|
4079
|
-
|
|
4080
|
-
function requireBlake2b () {
|
|
4081
|
-
if (hasRequiredBlake2b) return blake2b$3.exports;
|
|
4082
|
-
hasRequiredBlake2b = 1;
|
|
4083
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
4084
|
-
var b2wasm = /*@__PURE__*/ requireBlake2bWasm();
|
|
4085
|
-
|
|
4086
|
-
// 64-bit unsigned addition
|
|
4087
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
4088
|
-
// v should be a Uint32Array
|
|
4089
|
-
function ADD64AA (v, a, b) {
|
|
4090
|
-
var o0 = v[a] + v[b];
|
|
4091
|
-
var o1 = v[a + 1] + v[b + 1];
|
|
4092
|
-
if (o0 >= 0x100000000) {
|
|
4093
|
-
o1++;
|
|
4094
|
-
}
|
|
4095
|
-
v[a] = o0;
|
|
4096
|
-
v[a + 1] = o1;
|
|
4097
|
-
}
|
|
4098
|
-
|
|
4099
|
-
// 64-bit unsigned addition
|
|
4100
|
-
// Sets v[a,a+1] += b
|
|
4101
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
4102
|
-
function ADD64AC (v, a, b0, b1) {
|
|
4103
|
-
var o0 = v[a] + b0;
|
|
4104
|
-
if (b0 < 0) {
|
|
4105
|
-
o0 += 0x100000000;
|
|
4106
|
-
}
|
|
4107
|
-
var o1 = v[a + 1] + b1;
|
|
4108
|
-
if (o0 >= 0x100000000) {
|
|
4109
|
-
o1++;
|
|
4110
|
-
}
|
|
4111
|
-
v[a] = o0;
|
|
4112
|
-
v[a + 1] = o1;
|
|
4113
|
-
}
|
|
4114
|
-
|
|
4115
|
-
// Little-endian byte access
|
|
4116
|
-
function B2B_GET32 (arr, i) {
|
|
4117
|
-
return (arr[i] ^
|
|
4118
|
-
(arr[i + 1] << 8) ^
|
|
4119
|
-
(arr[i + 2] << 16) ^
|
|
4120
|
-
(arr[i + 3] << 24))
|
|
4121
|
-
}
|
|
4122
|
-
|
|
4123
|
-
// G Mixing function
|
|
4124
|
-
// The ROTRs are inlined for speed
|
|
4125
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
4126
|
-
var x0 = m[ix];
|
|
4127
|
-
var x1 = m[ix + 1];
|
|
4128
|
-
var y0 = m[iy];
|
|
4129
|
-
var y1 = m[iy + 1];
|
|
4130
|
-
|
|
4131
|
-
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
4132
|
-
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
4133
|
-
|
|
4134
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
4135
|
-
var xor0 = v[d] ^ v[a];
|
|
4136
|
-
var xor1 = v[d + 1] ^ v[a + 1];
|
|
4137
|
-
v[d] = xor1;
|
|
4138
|
-
v[d + 1] = xor0;
|
|
4139
|
-
|
|
4140
|
-
ADD64AA(v, c, d);
|
|
4141
|
-
|
|
4142
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
4143
|
-
xor0 = v[b] ^ v[c];
|
|
4144
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4145
|
-
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
4146
|
-
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
4147
|
-
|
|
4148
|
-
ADD64AA(v, a, b);
|
|
4149
|
-
ADD64AC(v, a, y0, y1);
|
|
4150
|
-
|
|
4151
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
4152
|
-
xor0 = v[d] ^ v[a];
|
|
4153
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
4154
|
-
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
4155
|
-
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
4156
|
-
|
|
4157
|
-
ADD64AA(v, c, d);
|
|
4158
|
-
|
|
4159
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
4160
|
-
xor0 = v[b] ^ v[c];
|
|
4161
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4162
|
-
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
4163
|
-
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
4164
|
-
}
|
|
4165
|
-
|
|
4166
|
-
// Initialization Vector
|
|
4167
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
4168
|
-
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
4169
|
-
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
4170
|
-
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
4171
|
-
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
4172
|
-
]);
|
|
4173
|
-
|
|
4174
|
-
var SIGMA8 = [
|
|
4175
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4176
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
4177
|
-
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
4178
|
-
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
4179
|
-
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
4180
|
-
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
4181
|
-
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
4182
|
-
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
4183
|
-
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
4184
|
-
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
4185
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4186
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
4187
|
-
];
|
|
4188
|
-
|
|
4189
|
-
// These are offsets into a uint64 buffer.
|
|
4190
|
-
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
4191
|
-
// because this is Javascript and we don't have uint64s
|
|
4192
|
-
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }));
|
|
4193
|
-
|
|
4194
|
-
// Compression function. 'last' flag indicates last block.
|
|
4195
|
-
// Note we're representing 16 uint64s as 32 uint32s
|
|
4196
|
-
var v = new Uint32Array(32);
|
|
4197
|
-
var m = new Uint32Array(32);
|
|
4198
|
-
function blake2bCompress (ctx, last) {
|
|
4199
|
-
var i = 0;
|
|
4200
|
-
|
|
4201
|
-
// init work variables
|
|
4202
|
-
for (i = 0; i < 16; i++) {
|
|
4203
|
-
v[i] = ctx.h[i];
|
|
4204
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
4205
|
-
}
|
|
4206
|
-
|
|
4207
|
-
// low 64 bits of offset
|
|
4208
|
-
v[24] = v[24] ^ ctx.t;
|
|
4209
|
-
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
4210
|
-
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
4211
|
-
|
|
4212
|
-
// last block flag set ?
|
|
4213
|
-
if (last) {
|
|
4214
|
-
v[28] = ~v[28];
|
|
4215
|
-
v[29] = ~v[29];
|
|
4216
|
-
}
|
|
4217
|
-
|
|
4218
|
-
// get little-endian words
|
|
4219
|
-
for (i = 0; i < 32; i++) {
|
|
4220
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
4221
|
-
}
|
|
4222
|
-
|
|
4223
|
-
// twelve rounds of mixing
|
|
4224
|
-
for (i = 0; i < 12; i++) {
|
|
4225
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
4226
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
4227
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
4228
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
4229
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
4230
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
4231
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
4232
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
4233
|
-
}
|
|
4234
|
-
|
|
4235
|
-
for (i = 0; i < 16; i++) {
|
|
4236
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
4237
|
-
}
|
|
4238
|
-
}
|
|
4239
|
-
|
|
4240
|
-
// reusable parameter_block
|
|
4241
|
-
var parameter_block = new Uint8Array([
|
|
4242
|
-
0, 0, 0, 0, // 0: outlen, keylen, fanout, depth
|
|
4243
|
-
0, 0, 0, 0, // 4: leaf length, sequential mode
|
|
4244
|
-
0, 0, 0, 0, // 8: node offset
|
|
4245
|
-
0, 0, 0, 0, // 12: node offset
|
|
4246
|
-
0, 0, 0, 0, // 16: node depth, inner length, rfu
|
|
4247
|
-
0, 0, 0, 0, // 20: rfu
|
|
4248
|
-
0, 0, 0, 0, // 24: rfu
|
|
4249
|
-
0, 0, 0, 0, // 28: rfu
|
|
4250
|
-
0, 0, 0, 0, // 32: salt
|
|
4251
|
-
0, 0, 0, 0, // 36: salt
|
|
4252
|
-
0, 0, 0, 0, // 40: salt
|
|
4253
|
-
0, 0, 0, 0, // 44: salt
|
|
4254
|
-
0, 0, 0, 0, // 48: personal
|
|
4255
|
-
0, 0, 0, 0, // 52: personal
|
|
4256
|
-
0, 0, 0, 0, // 56: personal
|
|
4257
|
-
0, 0, 0, 0 // 60: personal
|
|
4258
|
-
]);
|
|
4259
|
-
|
|
4260
|
-
// Creates a BLAKE2b hashing context
|
|
4261
|
-
// Requires an output length between 1 and 64 bytes
|
|
4262
|
-
// Takes an optional Uint8Array key
|
|
4263
|
-
function Blake2b (outlen, key, salt, personal) {
|
|
4264
|
-
// zero out parameter_block before usage
|
|
4265
|
-
parameter_block.fill(0);
|
|
4266
|
-
// state, 'param block'
|
|
4267
|
-
|
|
4268
|
-
this.b = new Uint8Array(128);
|
|
4269
|
-
this.h = new Uint32Array(16);
|
|
4270
|
-
this.t = 0; // input count
|
|
4271
|
-
this.c = 0; // pointer within buffer
|
|
4272
|
-
this.outlen = outlen; // output length in bytes
|
|
4273
|
-
|
|
4274
|
-
parameter_block[0] = outlen;
|
|
4275
|
-
if (key) parameter_block[1] = key.length;
|
|
4276
|
-
parameter_block[2] = 1; // fanout
|
|
4277
|
-
parameter_block[3] = 1; // depth
|
|
4278
|
-
|
|
4279
|
-
if (salt) parameter_block.set(salt, 32);
|
|
4280
|
-
if (personal) parameter_block.set(personal, 48);
|
|
4281
|
-
|
|
4282
|
-
// initialize hash state
|
|
4283
|
-
for (var i = 0; i < 16; i++) {
|
|
4284
|
-
this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
|
|
4285
|
-
}
|
|
4286
|
-
|
|
4287
|
-
// key the hash, if applicable
|
|
4288
|
-
if (key) {
|
|
4289
|
-
blake2bUpdate(this, key);
|
|
4290
|
-
// at the end
|
|
4291
|
-
this.c = 128;
|
|
4292
|
-
}
|
|
4293
|
-
}
|
|
4294
|
-
|
|
4295
|
-
Blake2b.prototype.update = function (input) {
|
|
4296
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4297
|
-
blake2bUpdate(this, input);
|
|
4298
|
-
return this
|
|
4299
|
-
};
|
|
4300
|
-
|
|
4301
|
-
Blake2b.prototype.digest = function (out) {
|
|
4302
|
-
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out;
|
|
4303
|
-
assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
|
|
4304
|
-
assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
|
|
4305
|
-
blake2bFinal(this, buf);
|
|
4306
|
-
if (out === 'hex') return hexSlice(buf)
|
|
4307
|
-
return buf
|
|
4308
|
-
};
|
|
4309
|
-
|
|
4310
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4311
|
-
|
|
4312
|
-
Blake2b.ready = function (cb) {
|
|
4313
|
-
b2wasm.ready(function () {
|
|
4314
|
-
cb(); // ignore the error
|
|
4315
|
-
});
|
|
4316
|
-
};
|
|
4317
|
-
|
|
4318
|
-
// Updates a BLAKE2b streaming hash
|
|
4319
|
-
// Requires hash context and Uint8Array (byte array)
|
|
4320
|
-
function blake2bUpdate (ctx, input) {
|
|
4321
|
-
for (var i = 0; i < input.length; i++) {
|
|
4322
|
-
if (ctx.c === 128) { // buffer full ?
|
|
4323
|
-
ctx.t += ctx.c; // add counters
|
|
4324
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
4325
|
-
ctx.c = 0; // counter to zero
|
|
4326
|
-
}
|
|
4327
|
-
ctx.b[ctx.c++] = input[i];
|
|
4328
|
-
}
|
|
4329
|
-
}
|
|
4330
|
-
|
|
4331
|
-
// Completes a BLAKE2b streaming hash
|
|
4332
|
-
// Returns a Uint8Array containing the message digest
|
|
4333
|
-
function blake2bFinal (ctx, out) {
|
|
4334
|
-
ctx.t += ctx.c; // mark last block offset
|
|
4335
|
-
|
|
4336
|
-
while (ctx.c < 128) { // fill up with zeros
|
|
4337
|
-
ctx.b[ctx.c++] = 0;
|
|
4338
|
-
}
|
|
4339
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
4340
|
-
|
|
4341
|
-
for (var i = 0; i < ctx.outlen; i++) {
|
|
4342
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
4343
|
-
}
|
|
4344
|
-
return out
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
|
-
function hexSlice (buf) {
|
|
4348
|
-
var str = '';
|
|
4349
|
-
for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
|
|
4350
|
-
return str
|
|
4351
|
-
}
|
|
4352
|
-
|
|
4353
|
-
function toHex (n) {
|
|
4354
|
-
if (n < 16) return '0' + n.toString(16)
|
|
4355
|
-
return n.toString(16)
|
|
4356
|
-
}
|
|
4357
|
-
|
|
4358
|
-
var Proto = Blake2b;
|
|
4359
|
-
|
|
4360
|
-
blake2b$3.exports = function createHash (outlen, key, salt, personal, noAssert) {
|
|
4361
|
-
if (noAssert !== true) {
|
|
4362
|
-
assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen);
|
|
4363
|
-
assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen);
|
|
4364
|
-
if (key != null) {
|
|
4365
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
4366
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
4367
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
4368
|
-
}
|
|
4369
|
-
if (salt != null) {
|
|
4370
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4371
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4372
|
-
}
|
|
4373
|
-
if (personal != null) {
|
|
4374
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4375
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4376
|
-
}
|
|
4377
|
-
}
|
|
4378
|
-
|
|
4379
|
-
return new Proto(outlen, key, salt, personal)
|
|
4380
|
-
};
|
|
4381
|
-
|
|
4382
|
-
blake2b$3.exports.ready = function (cb) {
|
|
4383
|
-
b2wasm.ready(function () { // ignore errors
|
|
4384
|
-
cb();
|
|
4385
|
-
});
|
|
4386
|
-
};
|
|
4387
|
-
|
|
4388
|
-
blake2b$3.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
|
|
4389
|
-
blake2b$3.exports.WASM_LOADED = false;
|
|
4390
|
-
|
|
4391
|
-
var BYTES_MIN = blake2b$3.exports.BYTES_MIN = 16;
|
|
4392
|
-
var BYTES_MAX = blake2b$3.exports.BYTES_MAX = 64;
|
|
4393
|
-
blake2b$3.exports.BYTES = 32;
|
|
4394
|
-
var KEYBYTES_MIN = blake2b$3.exports.KEYBYTES_MIN = 16;
|
|
4395
|
-
var KEYBYTES_MAX = blake2b$3.exports.KEYBYTES_MAX = 64;
|
|
4396
|
-
blake2b$3.exports.KEYBYTES = 32;
|
|
4397
|
-
var SALTBYTES = blake2b$3.exports.SALTBYTES = 16;
|
|
4398
|
-
var PERSONALBYTES = blake2b$3.exports.PERSONALBYTES = 16;
|
|
4399
|
-
|
|
4400
|
-
b2wasm.ready(function (err) {
|
|
4401
|
-
if (!err) {
|
|
4402
|
-
blake2b$3.exports.WASM_LOADED = true;
|
|
4403
|
-
blake2b$3.exports = b2wasm;
|
|
4404
|
-
}
|
|
4405
|
-
});
|
|
4406
|
-
return blake2b$3.exports;
|
|
3679
|
+
function deriveEd25519SecretKey(seed, blake2b) {
|
|
3680
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4407
3681
|
}
|
|
4408
|
-
|
|
4409
|
-
var blake2bExports = /*@__PURE__*/ requireBlake2b();
|
|
4410
|
-
var blake2b$1 = /*@__PURE__*/getDefaultExportFromCjs(blake2bExports);
|
|
4411
|
-
|
|
4412
3682
|
/**
|
|
4413
|
-
*
|
|
4414
|
-
*
|
|
4415
|
-
* If empty array is given a zero-hash is returned.
|
|
3683
|
+
* Derives a Bandersnatch secret key from a seed.
|
|
3684
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4416
3685
|
*/
|
|
4417
|
-
function
|
|
4418
|
-
|
|
4419
|
-
if (r.length === 0) {
|
|
4420
|
-
return out.asOpaque();
|
|
4421
|
-
}
|
|
4422
|
-
const hasher = blake2b$1(HASH_SIZE);
|
|
4423
|
-
for (const v of r) {
|
|
4424
|
-
hasher?.update(v instanceof BytesBlob ? v.raw : v);
|
|
4425
|
-
}
|
|
4426
|
-
hasher?.digest(out.raw);
|
|
4427
|
-
return out.asOpaque();
|
|
3686
|
+
function deriveBandersnatchSecretKey(seed, blake2b) {
|
|
3687
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4428
3688
|
}
|
|
4429
|
-
/**
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
const out = allocator.emptyHash();
|
|
4435
|
-
hasher?.digest(out.raw);
|
|
4436
|
-
return out;
|
|
3689
|
+
/**
|
|
3690
|
+
* Derive Ed25519 public key from secret seed
|
|
3691
|
+
*/
|
|
3692
|
+
async function deriveEd25519PublicKey(seed) {
|
|
3693
|
+
return (await privateKey(seed)).pubKey;
|
|
4437
3694
|
}
|
|
4438
|
-
/**
|
|
4439
|
-
|
|
4440
|
-
|
|
3695
|
+
/**
|
|
3696
|
+
* Derive Bandersnatch public key from secret seed
|
|
3697
|
+
*/
|
|
3698
|
+
function deriveBandersnatchPublicKey(seed) {
|
|
3699
|
+
return publicKey(seed.raw);
|
|
4441
3700
|
}
|
|
4442
3701
|
|
|
4443
|
-
var
|
|
3702
|
+
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
3703
|
+
__proto__: null,
|
|
3704
|
+
SEED_SIZE: SEED_SIZE,
|
|
3705
|
+
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
3706
|
+
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
3707
|
+
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
3708
|
+
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
3709
|
+
trivialSeed: trivialSeed
|
|
3710
|
+
});
|
|
3711
|
+
|
|
3712
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4444
3713
|
__proto__: null,
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
3714
|
+
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
3715
|
+
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
3716
|
+
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
3717
|
+
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
3718
|
+
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
3719
|
+
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
3720
|
+
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
3721
|
+
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
3722
|
+
Ed25519Pair: Ed25519Pair,
|
|
3723
|
+
SEED_SIZE: SEED_SIZE,
|
|
3724
|
+
bandersnatch: bandersnatch,
|
|
3725
|
+
bandersnatchWasm: bandersnatch_exports,
|
|
3726
|
+
ed25519: ed25519,
|
|
3727
|
+
initWasm: initAll,
|
|
3728
|
+
keyDerivation: keyDerivation
|
|
4448
3729
|
});
|
|
4449
3730
|
|
|
4450
3731
|
/*!
|
|
@@ -4805,7 +4086,78 @@ function WASMInterface(binary, hashLength) {
|
|
|
4805
4086
|
|
|
4806
4087
|
new Mutex();
|
|
4807
4088
|
|
|
4089
|
+
var name$j = "blake2b";
|
|
4090
|
+
var data$j = "AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2hfR2V0U3RhdGUABw5IYXNoX0NhbGN1bGF0ZQAIClNUQVRFX1NJWkUDAQrTOAkFAEGACQvrAgIFfwF+AkAgAUEBSA0AAkACQAJAIAFBgAFBACgC4IoBIgJrIgNKDQAgASEEDAELQQBBADYC4IoBAkAgAkH/AEoNACACQeCJAWohBSAAIQRBACEGA0AgBSAELQAAOgAAIARBAWohBCAFQQFqIQUgAyAGQQFqIgZB/wFxSg0ACwtBAEEAKQPAiQEiB0KAAXw3A8CJAUEAQQApA8iJASAHQv9+Vq18NwPIiQFB4IkBEAIgACADaiEAAkAgASADayIEQYEBSA0AIAIgAWohBQNAQQBBACk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xggAEEAKQOgiQE3AyAgAEEAKQOoiQE3AyggAEEAKQOwiQE3AzAgAEEAKQO4iQE3AzhBACgC5IoBIgVBAUgNAEEAIQRBACECA0AgBEGACWogACAEai0AADoAACAEQQFqIQQgBSACQQFqIgJB/wFxSg0ACwsgAEHAAGokAAv9AwMBfwF+AX8jAEGAAWsiAiQAQQBBgQI7AfKKAUEAIAE6APGKAUEAIAA6APCKAUGQfiEAA0AgAEGAiwFqQgA3AAAgAEH4igFqQgA3AAAgAEHwigFqQgA3AAAgAEEYaiIADQALQQAhAEEAQQApA/CKASIDQoiS853/zPmE6gCFNwOAiQFBAEEAKQP4igFCu86qptjQ67O7f4U3A4iJAUEAQQApA4CLAUKr8NP0r+68tzyFNwOQiQFBAEEAKQOIiwFC8e30+KWn/aelf4U3A5iJAUEAQQApA5CLAULRhZrv+s+Uh9EAhTcDoIkBQQBBACkDmIsBQp/Y+dnCkdqCm3+FNwOoiQFBAEEAKQOgiwFC6/qG2r+19sEfhTcDsIkBQQBBACkDqIsBQvnC+JuRo7Pw2wCFNwO4iQFBACADp0H/AXE2AuSKAQJAIAFBAUgNACACQgA3A3ggAkIANwNwIAJCADcDaCACQgA3A2AgAkIANwNYIAJCADcDUCACQgA3A0ggAkIANwNAIAJCADcDOCACQgA3AzAgAkIANwMoIAJCADcDICACQgA3AxggAkIANwMQIAJCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=";
|
|
4091
|
+
var hash$j = "c6f286e6";
|
|
4092
|
+
var wasmJson$j = {
|
|
4093
|
+
name: name$j,
|
|
4094
|
+
data: data$j,
|
|
4095
|
+
hash: hash$j
|
|
4096
|
+
};
|
|
4097
|
+
|
|
4808
4098
|
new Mutex();
|
|
4099
|
+
function validateBits$4(bits) {
|
|
4100
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
4101
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
4102
|
+
}
|
|
4103
|
+
return null;
|
|
4104
|
+
}
|
|
4105
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
4106
|
+
return outputBits | (keyBits << 16);
|
|
4107
|
+
}
|
|
4108
|
+
/**
|
|
4109
|
+
* Creates a new BLAKE2b hash instance
|
|
4110
|
+
* @param bits Number of output bits, which has to be a number
|
|
4111
|
+
* divisible by 8, between 8 and 512. Defaults to 512.
|
|
4112
|
+
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
|
|
4113
|
+
*/
|
|
4114
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
4115
|
+
if (validateBits$4(bits)) {
|
|
4116
|
+
return Promise.reject(validateBits$4(bits));
|
|
4117
|
+
}
|
|
4118
|
+
let keyBuffer = null;
|
|
4119
|
+
let initParam = bits;
|
|
4120
|
+
if (key !== null) {
|
|
4121
|
+
keyBuffer = getUInt8Buffer(key);
|
|
4122
|
+
if (keyBuffer.length > 64) {
|
|
4123
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
4124
|
+
}
|
|
4125
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
4126
|
+
}
|
|
4127
|
+
const outputSize = bits / 8;
|
|
4128
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
4129
|
+
if (initParam > 512) {
|
|
4130
|
+
wasm.writeMemory(keyBuffer);
|
|
4131
|
+
}
|
|
4132
|
+
wasm.init(initParam);
|
|
4133
|
+
const obj = {
|
|
4134
|
+
init: initParam > 512
|
|
4135
|
+
? () => {
|
|
4136
|
+
wasm.writeMemory(keyBuffer);
|
|
4137
|
+
wasm.init(initParam);
|
|
4138
|
+
return obj;
|
|
4139
|
+
}
|
|
4140
|
+
: () => {
|
|
4141
|
+
wasm.init(initParam);
|
|
4142
|
+
return obj;
|
|
4143
|
+
},
|
|
4144
|
+
update: (data) => {
|
|
4145
|
+
wasm.update(data);
|
|
4146
|
+
return obj;
|
|
4147
|
+
},
|
|
4148
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
4149
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
4150
|
+
save: () => wasm.save(),
|
|
4151
|
+
load: (data) => {
|
|
4152
|
+
wasm.load(data);
|
|
4153
|
+
return obj;
|
|
4154
|
+
},
|
|
4155
|
+
blockSize: 128,
|
|
4156
|
+
digestSize: outputSize,
|
|
4157
|
+
};
|
|
4158
|
+
return obj;
|
|
4159
|
+
});
|
|
4160
|
+
}
|
|
4809
4161
|
|
|
4810
4162
|
new Mutex();
|
|
4811
4163
|
|
|
@@ -4895,6 +4247,79 @@ new Mutex();
|
|
|
4895
4247
|
|
|
4896
4248
|
new Mutex();
|
|
4897
4249
|
|
|
4250
|
+
/**
|
|
4251
|
+
* Size of the output of the hash functions.
|
|
4252
|
+
*
|
|
4253
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
4254
|
+
*
|
|
4255
|
+
*/
|
|
4256
|
+
const HASH_SIZE = 32;
|
|
4257
|
+
/** A hash without last byte (useful for trie representation). */
|
|
4258
|
+
const TRUNCATED_HASH_SIZE = 31;
|
|
4259
|
+
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
4260
|
+
/**
|
|
4261
|
+
* Container for some object with a hash that is related to this object.
|
|
4262
|
+
*
|
|
4263
|
+
* After calculating the hash these two should be passed together to avoid
|
|
4264
|
+
* unnecessary re-hashing of the data.
|
|
4265
|
+
*/
|
|
4266
|
+
class WithHash extends WithDebug {
|
|
4267
|
+
hash;
|
|
4268
|
+
data;
|
|
4269
|
+
constructor(hash, data) {
|
|
4270
|
+
super();
|
|
4271
|
+
this.hash = hash;
|
|
4272
|
+
this.data = data;
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
/**
|
|
4276
|
+
* Extension of [`WithHash`] additionally containing an encoded version of the object.
|
|
4277
|
+
*/
|
|
4278
|
+
class WithHashAndBytes extends WithHash {
|
|
4279
|
+
encoded;
|
|
4280
|
+
constructor(hash, data, encoded) {
|
|
4281
|
+
super(hash, data);
|
|
4282
|
+
this.encoded = encoded;
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
|
|
4286
|
+
const zero$1 = Bytes.zero(HASH_SIZE);
|
|
4287
|
+
class Blake2b {
|
|
4288
|
+
hasher;
|
|
4289
|
+
static async createHasher() {
|
|
4290
|
+
return new Blake2b(await createBLAKE2b(HASH_SIZE * 8));
|
|
4291
|
+
}
|
|
4292
|
+
constructor(hasher) {
|
|
4293
|
+
this.hasher = hasher;
|
|
4294
|
+
}
|
|
4295
|
+
/**
|
|
4296
|
+
* Hash given collection of blobs.
|
|
4297
|
+
*
|
|
4298
|
+
* If empty array is given a zero-hash is returned.
|
|
4299
|
+
*/
|
|
4300
|
+
hashBlobs(r) {
|
|
4301
|
+
if (r.length === 0) {
|
|
4302
|
+
return zero$1.asOpaque();
|
|
4303
|
+
}
|
|
4304
|
+
const hasher = this.hasher.init();
|
|
4305
|
+
for (const v of r) {
|
|
4306
|
+
hasher.update(v instanceof BytesBlob ? v.raw : v);
|
|
4307
|
+
}
|
|
4308
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4309
|
+
}
|
|
4310
|
+
/** Hash given blob of bytes. */
|
|
4311
|
+
hashBytes(blob) {
|
|
4312
|
+
const hasher = this.hasher.init();
|
|
4313
|
+
const bytes = blob instanceof BytesBlob ? blob.raw : blob;
|
|
4314
|
+
hasher.update(bytes);
|
|
4315
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4316
|
+
}
|
|
4317
|
+
/** Convert given string into bytes and hash it. */
|
|
4318
|
+
hashString(str) {
|
|
4319
|
+
return this.hashBytes(BytesBlob.blobFromString(str));
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
|
|
4898
4323
|
class KeccakHasher {
|
|
4899
4324
|
hasher;
|
|
4900
4325
|
static async create() {
|
|
@@ -4919,91 +4344,61 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4919
4344
|
hashBlobs: hashBlobs
|
|
4920
4345
|
});
|
|
4921
4346
|
|
|
4922
|
-
|
|
4347
|
+
// TODO [ToDr] (#213) this should most likely be moved to a separate
|
|
4348
|
+
// package to avoid pulling in unnecessary deps.
|
|
4349
|
+
|
|
4350
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4923
4351
|
__proto__: null,
|
|
4352
|
+
Blake2b: Blake2b,
|
|
4924
4353
|
HASH_SIZE: HASH_SIZE,
|
|
4925
|
-
PageAllocator: PageAllocator,
|
|
4926
|
-
SimpleAllocator: SimpleAllocator,
|
|
4927
4354
|
TRUNCATED_HASH_SIZE: TRUNCATED_HASH_SIZE,
|
|
4928
4355
|
WithHash: WithHash,
|
|
4929
4356
|
WithHashAndBytes: WithHashAndBytes,
|
|
4930
4357
|
ZERO_HASH: ZERO_HASH,
|
|
4931
|
-
blake2b: blake2b,
|
|
4932
|
-
defaultAllocator: defaultAllocator,
|
|
4933
4358
|
keccak: keccak
|
|
4934
4359
|
});
|
|
4935
4360
|
|
|
4936
|
-
const SEED_SIZE = 32;
|
|
4937
|
-
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
4938
|
-
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
4939
|
-
/**
|
|
4940
|
-
* JIP-5: Secret key derivation
|
|
4941
|
-
*
|
|
4942
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
4943
|
-
/**
|
|
4944
|
-
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
4945
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
4946
|
-
*/
|
|
4947
|
-
function trivialSeed(s) {
|
|
4948
|
-
const s_le = u32AsLeBytes(s);
|
|
4949
|
-
return Bytes.fromBlob(BytesBlob.blobFromParts([s_le, s_le, s_le, s_le, s_le, s_le, s_le, s_le]).raw, SEED_SIZE).asOpaque();
|
|
4950
|
-
}
|
|
4951
|
-
/**
|
|
4952
|
-
* Derives a Ed25519 secret key from a seed.
|
|
4953
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4954
|
-
*/
|
|
4955
|
-
function deriveEd25519SecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4956
|
-
return hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4957
|
-
}
|
|
4958
|
-
/**
|
|
4959
|
-
* Derives a Bandersnatch secret key from a seed.
|
|
4960
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4961
|
-
*/
|
|
4962
|
-
function deriveBandersnatchSecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4963
|
-
return hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4964
|
-
}
|
|
4965
|
-
/**
|
|
4966
|
-
* Derive Ed25519 public key from secret seed
|
|
4967
|
-
*/
|
|
4968
|
-
async function deriveEd25519PublicKey(seed) {
|
|
4969
|
-
return (await privateKey(seed)).pubKey;
|
|
4970
|
-
}
|
|
4971
4361
|
/**
|
|
4972
|
-
*
|
|
4362
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
4973
4363
|
*/
|
|
4974
|
-
|
|
4975
|
-
|
|
4364
|
+
class ArrayView {
|
|
4365
|
+
start;
|
|
4366
|
+
end;
|
|
4367
|
+
source;
|
|
4368
|
+
length;
|
|
4369
|
+
constructor(source, start, end) {
|
|
4370
|
+
this.start = start;
|
|
4371
|
+
this.end = end;
|
|
4372
|
+
this.source = source;
|
|
4373
|
+
this.length = end - start;
|
|
4374
|
+
}
|
|
4375
|
+
static from(source, start = 0, end = source.length) {
|
|
4376
|
+
check `
|
|
4377
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
4378
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
4379
|
+
`;
|
|
4380
|
+
return new ArrayView(source, start, end);
|
|
4381
|
+
}
|
|
4382
|
+
get(i) {
|
|
4383
|
+
check `
|
|
4384
|
+
${i >= 0 && i < this.length}
|
|
4385
|
+
Index out of bounds: ${i} < ${this.length}
|
|
4386
|
+
`;
|
|
4387
|
+
return this.source[this.start + i];
|
|
4388
|
+
}
|
|
4389
|
+
subview(from, to = this.length) {
|
|
4390
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
4391
|
+
}
|
|
4392
|
+
toArray() {
|
|
4393
|
+
return this.source.slice(this.start, this.end);
|
|
4394
|
+
}
|
|
4395
|
+
*[Symbol.iterator]() {
|
|
4396
|
+
for (let i = this.start; i < this.end; i++) {
|
|
4397
|
+
yield this.source[i];
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4976
4400
|
}
|
|
4977
4401
|
|
|
4978
|
-
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
4979
|
-
__proto__: null,
|
|
4980
|
-
SEED_SIZE: SEED_SIZE,
|
|
4981
|
-
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
4982
|
-
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
4983
|
-
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
4984
|
-
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
4985
|
-
trivialSeed: trivialSeed
|
|
4986
|
-
});
|
|
4987
|
-
|
|
4988
|
-
var index$m = /*#__PURE__*/Object.freeze({
|
|
4989
|
-
__proto__: null,
|
|
4990
|
-
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4991
|
-
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
4992
|
-
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
4993
|
-
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
4994
|
-
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
4995
|
-
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
4996
|
-
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
4997
|
-
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
4998
|
-
Ed25519Pair: Ed25519Pair,
|
|
4999
|
-
SEED_SIZE: SEED_SIZE,
|
|
5000
|
-
bandersnatch: bandersnatch,
|
|
5001
|
-
bandersnatchWasm: bandersnatch_exports,
|
|
5002
|
-
ed25519: ed25519,
|
|
5003
|
-
initWasm: initAll,
|
|
5004
|
-
keyDerivation: keyDerivation
|
|
5005
|
-
});
|
|
5006
|
-
|
|
5007
4402
|
/** A map which uses hashes as keys. */
|
|
5008
4403
|
class HashDictionary {
|
|
5009
4404
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
@@ -5589,8 +4984,9 @@ class TruncatedHashDictionary {
|
|
|
5589
4984
|
}
|
|
5590
4985
|
}
|
|
5591
4986
|
|
|
5592
|
-
var index$
|
|
4987
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
5593
4988
|
__proto__: null,
|
|
4989
|
+
ArrayView: ArrayView,
|
|
5594
4990
|
FixedSizeArray: FixedSizeArray,
|
|
5595
4991
|
HashDictionary: HashDictionary,
|
|
5596
4992
|
HashSet: HashSet,
|
|
@@ -5784,7 +5180,7 @@ class Bootnode {
|
|
|
5784
5180
|
}
|
|
5785
5181
|
}
|
|
5786
5182
|
|
|
5787
|
-
var index$
|
|
5183
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
5788
5184
|
__proto__: null,
|
|
5789
5185
|
Bootnode: Bootnode,
|
|
5790
5186
|
ChainSpec: ChainSpec,
|
|
@@ -5957,6 +5353,40 @@ var assurances = /*#__PURE__*/Object.freeze({
|
|
|
5957
5353
|
assurancesExtrinsicCodec: assurancesExtrinsicCodec
|
|
5958
5354
|
});
|
|
5959
5355
|
|
|
5356
|
+
/** Attempt to convert a number into `TimeSlot`. */
|
|
5357
|
+
const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
|
|
5358
|
+
/** Attempt to convert a number into `ValidatorIndex`. */
|
|
5359
|
+
const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
5360
|
+
/** Attempt to convert a number into `ServiceId`. */
|
|
5361
|
+
const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
|
|
5362
|
+
const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
|
|
5363
|
+
/** Attempt to convert a number into `CoreIndex`. */
|
|
5364
|
+
const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
5365
|
+
/** Attempt to convert a number into `Epoch`. */
|
|
5366
|
+
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
5367
|
+
function tryAsPerValidator(array, spec) {
|
|
5368
|
+
check `
|
|
5369
|
+
${array.length === spec.validatorsCount}
|
|
5370
|
+
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
5371
|
+
`;
|
|
5372
|
+
return asKnownSize(array);
|
|
5373
|
+
}
|
|
5374
|
+
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
5375
|
+
return codecKnownSizeArray(val, {
|
|
5376
|
+
fixedLength: context.validatorsCount,
|
|
5377
|
+
});
|
|
5378
|
+
});
|
|
5379
|
+
function tryAsPerEpochBlock(array, spec) {
|
|
5380
|
+
check `
|
|
5381
|
+
${array.length === spec.epochLength}
|
|
5382
|
+
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
5383
|
+
`;
|
|
5384
|
+
return asKnownSize(array);
|
|
5385
|
+
}
|
|
5386
|
+
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
5387
|
+
return codecKnownSizeArray(val, { fixedLength: context.epochLength });
|
|
5388
|
+
});
|
|
5389
|
+
|
|
5960
5390
|
/**
|
|
5961
5391
|
* Proof of signing a contradictory [`Judgement`] of a work report.
|
|
5962
5392
|
*/
|
|
@@ -6148,40 +5578,6 @@ var disputes = /*#__PURE__*/Object.freeze({
|
|
|
6148
5578
|
Verdict: Verdict
|
|
6149
5579
|
});
|
|
6150
5580
|
|
|
6151
|
-
/** Attempt to convert a number into `TimeSlot`. */
|
|
6152
|
-
const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
|
|
6153
|
-
/** Attempt to convert a number into `ValidatorIndex`. */
|
|
6154
|
-
const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
6155
|
-
/** Attempt to convert a number into `ServiceId`. */
|
|
6156
|
-
const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
|
|
6157
|
-
const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
|
|
6158
|
-
/** Attempt to convert a number into `CoreIndex`. */
|
|
6159
|
-
const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
|
|
6160
|
-
/** Attempt to convert a number into `Epoch`. */
|
|
6161
|
-
const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
|
|
6162
|
-
function tryAsPerValidator(array, spec) {
|
|
6163
|
-
check `
|
|
6164
|
-
${array.length === spec.validatorsCount}
|
|
6165
|
-
Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
|
|
6166
|
-
`;
|
|
6167
|
-
return asKnownSize(array);
|
|
6168
|
-
}
|
|
6169
|
-
const codecPerValidator = (val) => codecWithContext((context) => {
|
|
6170
|
-
return codecKnownSizeArray(val, {
|
|
6171
|
-
fixedLength: context.validatorsCount,
|
|
6172
|
-
});
|
|
6173
|
-
});
|
|
6174
|
-
function tryAsPerEpochBlock(array, spec) {
|
|
6175
|
-
check `
|
|
6176
|
-
${array.length === spec.epochLength}
|
|
6177
|
-
Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
|
|
6178
|
-
`;
|
|
6179
|
-
return asKnownSize(array);
|
|
6180
|
-
}
|
|
6181
|
-
const codecPerEpochBlock = (val) => codecWithContext((context) => {
|
|
6182
|
-
return codecKnownSizeArray(val, { fixedLength: context.epochLength });
|
|
6183
|
-
});
|
|
6184
|
-
|
|
6185
5581
|
/**
|
|
6186
5582
|
* Mapping between work package hash and root hash of it's exports.
|
|
6187
5583
|
*
|
|
@@ -7260,8 +6656,26 @@ class Block extends WithDebug {
|
|
|
7260
6656
|
this.extrinsic = extrinsic;
|
|
7261
6657
|
}
|
|
7262
6658
|
}
|
|
6659
|
+
function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
6660
|
+
const header = Header.empty();
|
|
6661
|
+
header.timeSlotIndex = slot;
|
|
6662
|
+
return Block.create({
|
|
6663
|
+
header,
|
|
6664
|
+
extrinsic: Extrinsic.create({
|
|
6665
|
+
tickets: asKnownSize([]),
|
|
6666
|
+
preimages: [],
|
|
6667
|
+
assurances: asKnownSize([]),
|
|
6668
|
+
guarantees: asKnownSize([]),
|
|
6669
|
+
disputes: {
|
|
6670
|
+
verdicts: [],
|
|
6671
|
+
culprits: [],
|
|
6672
|
+
faults: [],
|
|
6673
|
+
},
|
|
6674
|
+
}),
|
|
6675
|
+
});
|
|
6676
|
+
}
|
|
7263
6677
|
|
|
7264
|
-
var index$
|
|
6678
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
7265
6679
|
__proto__: null,
|
|
7266
6680
|
Block: Block,
|
|
7267
6681
|
EpochMarker: EpochMarker,
|
|
@@ -7276,6 +6690,7 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
7276
6690
|
codecPerValidator: codecPerValidator,
|
|
7277
6691
|
codecUtils: codec,
|
|
7278
6692
|
disputes: disputes,
|
|
6693
|
+
emptyBlock: emptyBlock,
|
|
7279
6694
|
encodeUnsealedHeader: encodeUnsealedHeader,
|
|
7280
6695
|
guarantees: guarantees,
|
|
7281
6696
|
headerViewWithHashCodec: headerViewWithHashCodec,
|
|
@@ -7516,7 +6931,7 @@ var json;
|
|
|
7516
6931
|
json.object = object;
|
|
7517
6932
|
})(json || (json = {}));
|
|
7518
6933
|
|
|
7519
|
-
var index$
|
|
6934
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
7520
6935
|
__proto__: null,
|
|
7521
6936
|
get json () { return json; },
|
|
7522
6937
|
parseFromJson: parseFromJson
|
|
@@ -7786,7 +7201,7 @@ const blockFromJson = (spec) => json.object({
|
|
|
7786
7201
|
extrinsic: getExtrinsicFromJson(spec),
|
|
7787
7202
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
7788
7203
|
|
|
7789
|
-
var index$
|
|
7204
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
7790
7205
|
__proto__: null,
|
|
7791
7206
|
blockFromJson: blockFromJson,
|
|
7792
7207
|
disputesExtrinsicFromJson: disputesExtrinsicFromJson,
|
|
@@ -8052,8 +7467,8 @@ function print(level, levelAndName, strings, data) {
|
|
|
8052
7467
|
return;
|
|
8053
7468
|
}
|
|
8054
7469
|
const lvlText = Level[level].padEnd(5);
|
|
8055
|
-
const val = strings.map((v, idx) => `${v}${data[idx]}`);
|
|
8056
|
-
const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
|
|
7470
|
+
const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
|
|
7471
|
+
const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
|
|
8057
7472
|
if (level === Level.WARN) {
|
|
8058
7473
|
console.warn(msg);
|
|
8059
7474
|
}
|
|
@@ -8284,7 +7699,7 @@ class Logger {
|
|
|
8284
7699
|
}
|
|
8285
7700
|
}
|
|
8286
7701
|
|
|
8287
|
-
var index$
|
|
7702
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
8288
7703
|
__proto__: null,
|
|
8289
7704
|
get Level () { return Level; },
|
|
8290
7705
|
Logger: Logger,
|
|
@@ -8307,7 +7722,7 @@ class AuthorshipOptions {
|
|
|
8307
7722
|
}
|
|
8308
7723
|
}
|
|
8309
7724
|
|
|
8310
|
-
const logger$
|
|
7725
|
+
const logger$5 = Logger.new(undefined, "config");
|
|
8311
7726
|
/** Development config. Will accept unsealed blocks for now. */
|
|
8312
7727
|
const DEV_CONFIG = "dev";
|
|
8313
7728
|
/** Default config file. */
|
|
@@ -8366,15 +7781,15 @@ class NodeConfiguration {
|
|
|
8366
7781
|
}
|
|
8367
7782
|
function loadConfig(configPath) {
|
|
8368
7783
|
if (configPath === DEFAULT_CONFIG) {
|
|
8369
|
-
logger$
|
|
7784
|
+
logger$5.log `🔧 Loading DEFAULT config`;
|
|
8370
7785
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
8371
7786
|
}
|
|
8372
7787
|
if (configPath === DEV_CONFIG) {
|
|
8373
|
-
logger$
|
|
7788
|
+
logger$5.log `🔧 Loading DEV config`;
|
|
8374
7789
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
8375
7790
|
}
|
|
8376
7791
|
try {
|
|
8377
|
-
logger$
|
|
7792
|
+
logger$5.log `🔧 Loading config from ${configPath}`;
|
|
8378
7793
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
8379
7794
|
const parsed = JSON.parse(configFile);
|
|
8380
7795
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -8384,7 +7799,7 @@ function loadConfig(configPath) {
|
|
|
8384
7799
|
}
|
|
8385
7800
|
}
|
|
8386
7801
|
|
|
8387
|
-
var index$
|
|
7802
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
8388
7803
|
__proto__: null,
|
|
8389
7804
|
DEFAULT_CONFIG: DEFAULT_CONFIG,
|
|
8390
7805
|
DEV_CONFIG: DEV_CONFIG,
|
|
@@ -8533,43 +7948,43 @@ var stateKeys;
|
|
|
8533
7948
|
}
|
|
8534
7949
|
stateKeys.serviceInfo = serviceInfo;
|
|
8535
7950
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bba033bba03?v=0.7.1 */
|
|
8536
|
-
function serviceStorage(serviceId, key) {
|
|
7951
|
+
function serviceStorage(blake2b, serviceId, key) {
|
|
8537
7952
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8538
7953
|
const out = Bytes.zero(HASH_SIZE);
|
|
8539
7954
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 1)), 0);
|
|
8540
7955
|
out.raw.set(key.raw.subarray(0, HASH_SIZE - U32_BYTES), U32_BYTES);
|
|
8541
7956
|
return legacyServiceNested(serviceId, out);
|
|
8542
7957
|
}
|
|
8543
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
7958
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
8544
7959
|
}
|
|
8545
7960
|
stateKeys.serviceStorage = serviceStorage;
|
|
8546
7961
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bd7033bd703?v=0.7.1 */
|
|
8547
|
-
function servicePreimage(serviceId, hash) {
|
|
7962
|
+
function servicePreimage(blake2b, serviceId, hash) {
|
|
8548
7963
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8549
7964
|
const out = Bytes.zero(HASH_SIZE);
|
|
8550
7965
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 2)), 0);
|
|
8551
7966
|
out.raw.set(hash.raw.subarray(1, HASH_SIZE - U32_BYTES + 1), U32_BYTES);
|
|
8552
7967
|
return legacyServiceNested(serviceId, out);
|
|
8553
7968
|
}
|
|
8554
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
7969
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
8555
7970
|
}
|
|
8556
7971
|
stateKeys.servicePreimage = servicePreimage;
|
|
8557
7972
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b0a043b0a04?v=0.7.1 */
|
|
8558
|
-
function serviceLookupHistory(serviceId, hash, preimageLength) {
|
|
7973
|
+
function serviceLookupHistory(blake2b, serviceId, hash, preimageLength) {
|
|
8559
7974
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8560
|
-
const doubleHash = hashBytes(hash);
|
|
7975
|
+
const doubleHash = blake2b.hashBytes(hash);
|
|
8561
7976
|
const out = Bytes.zero(HASH_SIZE);
|
|
8562
7977
|
out.raw.set(u32AsLeBytes(preimageLength), 0);
|
|
8563
7978
|
out.raw.set(doubleHash.raw.subarray(2, HASH_SIZE - U32_BYTES + 2), U32_BYTES);
|
|
8564
7979
|
return legacyServiceNested(serviceId, out);
|
|
8565
7980
|
}
|
|
8566
|
-
return serviceNested(serviceId, preimageLength, hash);
|
|
7981
|
+
return serviceNested(blake2b, serviceId, preimageLength, hash);
|
|
8567
7982
|
}
|
|
8568
7983
|
stateKeys.serviceLookupHistory = serviceLookupHistory;
|
|
8569
7984
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b88003b8800?v=0.7.1 */
|
|
8570
|
-
function serviceNested(serviceId, numberPrefix, hash) {
|
|
7985
|
+
function serviceNested(blake2b, serviceId, numberPrefix, hash) {
|
|
8571
7986
|
const inputToHash = BytesBlob.blobFromParts(u32AsLeBytes(numberPrefix), hash.raw);
|
|
8572
|
-
const newHash = hashBytes(inputToHash).raw.subarray(0, 28);
|
|
7987
|
+
const newHash = blake2b.hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8573
7988
|
const key = Bytes.zero(HASH_SIZE);
|
|
8574
7989
|
let i = 0;
|
|
8575
7990
|
for (const byte of u32AsLeBytes(serviceId)) {
|
|
@@ -8630,12 +8045,6 @@ function accumulationOutputComparator(a, b) {
|
|
|
8630
8045
|
return Ordering.Equal;
|
|
8631
8046
|
}
|
|
8632
8047
|
|
|
8633
|
-
const codecWithHash = (val) => Descriptor.withView(val.name, val.sizeHint, (e, elem) => val.encode(e, elem.data), (d) => {
|
|
8634
|
-
const decoder2 = d.clone();
|
|
8635
|
-
const encoded = val.skipEncoded(decoder2);
|
|
8636
|
-
const hash = hashBytes(encoded);
|
|
8637
|
-
return new WithHash(hash.asOpaque(), val.decode(d));
|
|
8638
|
-
}, val.skip, val.View);
|
|
8639
8048
|
/**
|
|
8640
8049
|
* Assignment of particular work report to a core.
|
|
8641
8050
|
*
|
|
@@ -8648,7 +8057,7 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8648
8057
|
workReport;
|
|
8649
8058
|
timeout;
|
|
8650
8059
|
static Codec = codec$1.Class(AvailabilityAssignment, {
|
|
8651
|
-
workReport:
|
|
8060
|
+
workReport: WorkReport.Codec,
|
|
8652
8061
|
timeout: codec$1.u32.asOpaque(),
|
|
8653
8062
|
});
|
|
8654
8063
|
static create({ workReport, timeout }) {
|
|
@@ -8701,6 +8110,10 @@ class DisputesRecords {
|
|
|
8701
8110
|
static create({ goodSet, badSet, wonkySet, punishSet }) {
|
|
8702
8111
|
return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
|
|
8703
8112
|
}
|
|
8113
|
+
goodSetDict;
|
|
8114
|
+
badSetDict;
|
|
8115
|
+
wonkySetDict;
|
|
8116
|
+
punishSetDict;
|
|
8704
8117
|
constructor(
|
|
8705
8118
|
/** `goodSet`: all work-reports hashes which were judged to be correct */
|
|
8706
8119
|
goodSet,
|
|
@@ -8714,6 +8127,18 @@ class DisputesRecords {
|
|
|
8714
8127
|
this.badSet = badSet;
|
|
8715
8128
|
this.wonkySet = wonkySet;
|
|
8716
8129
|
this.punishSet = punishSet;
|
|
8130
|
+
this.goodSetDict = HashSet.from(goodSet.array);
|
|
8131
|
+
this.badSetDict = HashSet.from(badSet.array);
|
|
8132
|
+
this.wonkySetDict = HashSet.from(wonkySet.array);
|
|
8133
|
+
this.punishSetDict = HashSet.from(punishSet.array);
|
|
8134
|
+
}
|
|
8135
|
+
asDictionaries() {
|
|
8136
|
+
return {
|
|
8137
|
+
goodSet: this.goodSetDict,
|
|
8138
|
+
badSet: this.badSetDict,
|
|
8139
|
+
wonkySet: this.wonkySetDict,
|
|
8140
|
+
punishSet: this.punishSetDict,
|
|
8141
|
+
};
|
|
8717
8142
|
}
|
|
8718
8143
|
static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
|
|
8719
8144
|
return new DisputesRecords(SortedSet.fromSortedArray(hashComparator, goodSet), SortedSet.fromSortedArray(hashComparator, badSet), SortedSet.fromSortedArray(hashComparator, wonkySet), SortedSet.fromSortedArray(hashComparator, punishSet));
|
|
@@ -8729,7 +8154,6 @@ const O = 8;
|
|
|
8729
8154
|
const Q = 80;
|
|
8730
8155
|
/** `W_T`: The size of a transfer memo in octets. */
|
|
8731
8156
|
const W_T = 128;
|
|
8732
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
8733
8157
|
/**
|
|
8734
8158
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
8735
8159
|
*
|
|
@@ -8741,6 +8165,194 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
8741
8165
|
/** `O`: Maximal authorization pool size. */
|
|
8742
8166
|
const MAX_AUTH_POOL_SIZE = O;
|
|
8743
8167
|
|
|
8168
|
+
const MAX_VALUE = 4294967295;
|
|
8169
|
+
const MIN_VALUE = -2147483648;
|
|
8170
|
+
const MAX_SHIFT_U32 = 32;
|
|
8171
|
+
const MAX_SHIFT_U64 = 64n;
|
|
8172
|
+
|
|
8173
|
+
/**
|
|
8174
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
8175
|
+
*
|
|
8176
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
8177
|
+
*/
|
|
8178
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
8179
|
+
/**
|
|
8180
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
8181
|
+
*
|
|
8182
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
8183
|
+
*/
|
|
8184
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
8185
|
+
/**
|
|
8186
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
8187
|
+
*
|
|
8188
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
8189
|
+
*/
|
|
8190
|
+
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
8191
|
+
const zeroSizeHint = {
|
|
8192
|
+
bytes: 0,
|
|
8193
|
+
isExact: true,
|
|
8194
|
+
};
|
|
8195
|
+
/** 0-byte read, return given default value */
|
|
8196
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8197
|
+
/** Encode and decode object with leading version number. */
|
|
8198
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8199
|
+
bytes: val.sizeHint.bytes + 8,
|
|
8200
|
+
isExact: false,
|
|
8201
|
+
}, (e, v) => {
|
|
8202
|
+
e.varU64(0n);
|
|
8203
|
+
val.encode(e, v);
|
|
8204
|
+
}, (d) => {
|
|
8205
|
+
const version = d.varU64();
|
|
8206
|
+
if (version !== 0n) {
|
|
8207
|
+
throw new Error("Non-zero version is not supported!");
|
|
8208
|
+
}
|
|
8209
|
+
return val.decode(d);
|
|
8210
|
+
}, (s) => {
|
|
8211
|
+
s.varU64();
|
|
8212
|
+
val.skip(s);
|
|
8213
|
+
});
|
|
8214
|
+
/**
|
|
8215
|
+
* Service account details.
|
|
8216
|
+
*
|
|
8217
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
8218
|
+
*/
|
|
8219
|
+
class ServiceAccountInfo extends WithDebug {
|
|
8220
|
+
codeHash;
|
|
8221
|
+
balance;
|
|
8222
|
+
accumulateMinGas;
|
|
8223
|
+
onTransferMinGas;
|
|
8224
|
+
storageUtilisationBytes;
|
|
8225
|
+
gratisStorage;
|
|
8226
|
+
storageUtilisationCount;
|
|
8227
|
+
created;
|
|
8228
|
+
lastAccumulation;
|
|
8229
|
+
parentService;
|
|
8230
|
+
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
8231
|
+
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8232
|
+
balance: codec$1.u64,
|
|
8233
|
+
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8234
|
+
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8235
|
+
storageUtilisationBytes: codec$1.u64,
|
|
8236
|
+
gratisStorage: codec$1.u64,
|
|
8237
|
+
storageUtilisationCount: codec$1.u32,
|
|
8238
|
+
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8239
|
+
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8240
|
+
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
8241
|
+
});
|
|
8242
|
+
static create(a) {
|
|
8243
|
+
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
8244
|
+
}
|
|
8245
|
+
/**
|
|
8246
|
+
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
8247
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
8248
|
+
*/
|
|
8249
|
+
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
8250
|
+
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
8251
|
+
if (storageCost < 0n) {
|
|
8252
|
+
return tryAsU64(0);
|
|
8253
|
+
}
|
|
8254
|
+
if (storageCost >= 2n ** 64n) {
|
|
8255
|
+
return tryAsU64(2n ** 64n - 1n);
|
|
8256
|
+
}
|
|
8257
|
+
return tryAsU64(storageCost);
|
|
8258
|
+
}
|
|
8259
|
+
constructor(
|
|
8260
|
+
/** `a_c`: Hash of the service code. */
|
|
8261
|
+
codeHash,
|
|
8262
|
+
/** `a_b`: Current account balance. */
|
|
8263
|
+
balance,
|
|
8264
|
+
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
8265
|
+
accumulateMinGas,
|
|
8266
|
+
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
8267
|
+
onTransferMinGas,
|
|
8268
|
+
/** `a_o`: Total number of octets in storage. */
|
|
8269
|
+
storageUtilisationBytes,
|
|
8270
|
+
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
8271
|
+
gratisStorage,
|
|
8272
|
+
/** `a_i`: Number of items in storage. */
|
|
8273
|
+
storageUtilisationCount,
|
|
8274
|
+
/** `a_r`: Creation account time slot. */
|
|
8275
|
+
created,
|
|
8276
|
+
/** `a_a`: Most recent accumulation time slot. */
|
|
8277
|
+
lastAccumulation,
|
|
8278
|
+
/** `a_p`: Parent service ID. */
|
|
8279
|
+
parentService) {
|
|
8280
|
+
super();
|
|
8281
|
+
this.codeHash = codeHash;
|
|
8282
|
+
this.balance = balance;
|
|
8283
|
+
this.accumulateMinGas = accumulateMinGas;
|
|
8284
|
+
this.onTransferMinGas = onTransferMinGas;
|
|
8285
|
+
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
8286
|
+
this.gratisStorage = gratisStorage;
|
|
8287
|
+
this.storageUtilisationCount = storageUtilisationCount;
|
|
8288
|
+
this.created = created;
|
|
8289
|
+
this.lastAccumulation = lastAccumulation;
|
|
8290
|
+
this.parentService = parentService;
|
|
8291
|
+
}
|
|
8292
|
+
}
|
|
8293
|
+
class PreimageItem extends WithDebug {
|
|
8294
|
+
hash;
|
|
8295
|
+
blob;
|
|
8296
|
+
static Codec = codec$1.Class(PreimageItem, {
|
|
8297
|
+
hash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8298
|
+
blob: codec$1.blob,
|
|
8299
|
+
});
|
|
8300
|
+
static create({ hash, blob }) {
|
|
8301
|
+
return new PreimageItem(hash, blob);
|
|
8302
|
+
}
|
|
8303
|
+
constructor(hash, blob) {
|
|
8304
|
+
super();
|
|
8305
|
+
this.hash = hash;
|
|
8306
|
+
this.blob = blob;
|
|
8307
|
+
}
|
|
8308
|
+
}
|
|
8309
|
+
class StorageItem extends WithDebug {
|
|
8310
|
+
key;
|
|
8311
|
+
value;
|
|
8312
|
+
static Codec = codec$1.Class(StorageItem, {
|
|
8313
|
+
key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
|
|
8314
|
+
value: codec$1.blob,
|
|
8315
|
+
});
|
|
8316
|
+
static create({ key, value }) {
|
|
8317
|
+
return new StorageItem(key, value);
|
|
8318
|
+
}
|
|
8319
|
+
constructor(key, value) {
|
|
8320
|
+
super();
|
|
8321
|
+
this.key = key;
|
|
8322
|
+
this.value = value;
|
|
8323
|
+
}
|
|
8324
|
+
}
|
|
8325
|
+
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
8326
|
+
function tryAsLookupHistorySlots(items) {
|
|
8327
|
+
const knownSize = asKnownSize(items);
|
|
8328
|
+
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
8329
|
+
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
8330
|
+
}
|
|
8331
|
+
return knownSize;
|
|
8332
|
+
}
|
|
8333
|
+
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
8334
|
+
class LookupHistoryItem {
|
|
8335
|
+
hash;
|
|
8336
|
+
length;
|
|
8337
|
+
slots;
|
|
8338
|
+
constructor(hash, length,
|
|
8339
|
+
/**
|
|
8340
|
+
* Preimage availability history as a sequence of time slots.
|
|
8341
|
+
* See PreimageStatus and the following GP fragment for more details.
|
|
8342
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
8343
|
+
slots) {
|
|
8344
|
+
this.hash = hash;
|
|
8345
|
+
this.length = length;
|
|
8346
|
+
this.slots = slots;
|
|
8347
|
+
}
|
|
8348
|
+
static isRequested(item) {
|
|
8349
|
+
if ("slots" in item) {
|
|
8350
|
+
return item.slots.length === 0;
|
|
8351
|
+
}
|
|
8352
|
+
return item.length === 0;
|
|
8353
|
+
}
|
|
8354
|
+
}
|
|
8355
|
+
|
|
8744
8356
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8745
8357
|
class AutoAccumulate {
|
|
8746
8358
|
service;
|
|
@@ -8762,39 +8374,50 @@ class AutoAccumulate {
|
|
|
8762
8374
|
}
|
|
8763
8375
|
}
|
|
8764
8376
|
/**
|
|
8765
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8377
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8766
8378
|
*/
|
|
8767
8379
|
class PrivilegedServices {
|
|
8768
8380
|
manager;
|
|
8769
|
-
|
|
8770
|
-
|
|
8381
|
+
delegator;
|
|
8382
|
+
registrar;
|
|
8383
|
+
assigners;
|
|
8771
8384
|
autoAccumulateServices;
|
|
8385
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
8772
8386
|
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8773
8387
|
manager: codec$1.u32.asOpaque(),
|
|
8774
|
-
|
|
8775
|
-
|
|
8388
|
+
assigners: codecPerCore(codec$1.u32.asOpaque()),
|
|
8389
|
+
delegator: codec$1.u32.asOpaque(),
|
|
8390
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
8391
|
+
? codec$1.u32.asOpaque()
|
|
8392
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
8776
8393
|
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8777
8394
|
});
|
|
8778
|
-
static create(
|
|
8779
|
-
return new PrivilegedServices(manager,
|
|
8395
|
+
static create(a) {
|
|
8396
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
8780
8397
|
}
|
|
8781
8398
|
constructor(
|
|
8782
8399
|
/**
|
|
8783
|
-
*
|
|
8784
|
-
* the service able to effect an alteration of χ from block to block,
|
|
8400
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
8785
8401
|
* as well as bestow services with storage deposit credits.
|
|
8786
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8402
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
8787
8403
|
*/
|
|
8788
8404
|
manager,
|
|
8789
|
-
/**
|
|
8790
|
-
|
|
8791
|
-
/**
|
|
8792
|
-
|
|
8793
|
-
|
|
8405
|
+
/** `χ_V`: Managers validator keys. */
|
|
8406
|
+
delegator,
|
|
8407
|
+
/**
|
|
8408
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
8409
|
+
*
|
|
8410
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
8411
|
+
*/
|
|
8412
|
+
registrar,
|
|
8413
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
8414
|
+
assigners,
|
|
8415
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
8794
8416
|
autoAccumulateServices) {
|
|
8795
8417
|
this.manager = manager;
|
|
8796
|
-
this.
|
|
8797
|
-
this.
|
|
8418
|
+
this.delegator = delegator;
|
|
8419
|
+
this.registrar = registrar;
|
|
8420
|
+
this.assigners = assigners;
|
|
8798
8421
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
8799
8422
|
}
|
|
8800
8423
|
}
|
|
@@ -9013,212 +8636,46 @@ class SafroleSealingKeysData extends WithDebug {
|
|
|
9013
8636
|
throw new Error(`Unexpected safrole sealing keys kind: ${kind}`);
|
|
9014
8637
|
});
|
|
9015
8638
|
});
|
|
9016
|
-
static keys(keys) {
|
|
9017
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
9018
|
-
}
|
|
9019
|
-
static tickets(tickets) {
|
|
9020
|
-
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
9021
|
-
}
|
|
9022
|
-
constructor(kind, keys, tickets) {
|
|
9023
|
-
super();
|
|
9024
|
-
this.kind = kind;
|
|
9025
|
-
this.keys = keys;
|
|
9026
|
-
this.tickets = tickets;
|
|
9027
|
-
}
|
|
9028
|
-
}
|
|
9029
|
-
class SafroleData {
|
|
9030
|
-
nextValidatorData;
|
|
9031
|
-
epochRoot;
|
|
9032
|
-
sealingKeySeries;
|
|
9033
|
-
ticketsAccumulator;
|
|
9034
|
-
static Codec = codec$1.Class(SafroleData, {
|
|
9035
|
-
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
9036
|
-
epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
9037
|
-
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
9038
|
-
ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
|
|
9039
|
-
});
|
|
9040
|
-
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
9041
|
-
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
9042
|
-
}
|
|
9043
|
-
constructor(
|
|
9044
|
-
/** gamma_k */
|
|
9045
|
-
nextValidatorData,
|
|
9046
|
-
/** gamma_z */
|
|
9047
|
-
epochRoot,
|
|
9048
|
-
/** gamma_s */
|
|
9049
|
-
sealingKeySeries,
|
|
9050
|
-
/** gamma_a */
|
|
9051
|
-
ticketsAccumulator) {
|
|
9052
|
-
this.nextValidatorData = nextValidatorData;
|
|
9053
|
-
this.epochRoot = epochRoot;
|
|
9054
|
-
this.sealingKeySeries = sealingKeySeries;
|
|
9055
|
-
this.ticketsAccumulator = ticketsAccumulator;
|
|
9056
|
-
}
|
|
9057
|
-
}
|
|
9058
|
-
|
|
9059
|
-
/**
|
|
9060
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
9061
|
-
*
|
|
9062
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9063
|
-
*/
|
|
9064
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
9065
|
-
/**
|
|
9066
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9067
|
-
*
|
|
9068
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9069
|
-
*/
|
|
9070
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9071
|
-
/**
|
|
9072
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9073
|
-
*
|
|
9074
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9075
|
-
*/
|
|
9076
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9077
|
-
const zeroSizeHint = {
|
|
9078
|
-
bytes: 0,
|
|
9079
|
-
isExact: true,
|
|
9080
|
-
};
|
|
9081
|
-
/** 0-byte read, return given default value */
|
|
9082
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
9083
|
-
/**
|
|
9084
|
-
* Service account details.
|
|
9085
|
-
*
|
|
9086
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
9087
|
-
*/
|
|
9088
|
-
class ServiceAccountInfo extends WithDebug {
|
|
9089
|
-
codeHash;
|
|
9090
|
-
balance;
|
|
9091
|
-
accumulateMinGas;
|
|
9092
|
-
onTransferMinGas;
|
|
9093
|
-
storageUtilisationBytes;
|
|
9094
|
-
gratisStorage;
|
|
9095
|
-
storageUtilisationCount;
|
|
9096
|
-
created;
|
|
9097
|
-
lastAccumulation;
|
|
9098
|
-
parentService;
|
|
9099
|
-
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
9100
|
-
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
9101
|
-
balance: codec$1.u64,
|
|
9102
|
-
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
9103
|
-
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
9104
|
-
storageUtilisationBytes: codec$1.u64,
|
|
9105
|
-
gratisStorage: codec$1.u64,
|
|
9106
|
-
storageUtilisationCount: codec$1.u32,
|
|
9107
|
-
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
9108
|
-
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
9109
|
-
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
9110
|
-
});
|
|
9111
|
-
static create(a) {
|
|
9112
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
9113
|
-
}
|
|
9114
|
-
/**
|
|
9115
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
9116
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
9117
|
-
*/
|
|
9118
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
9119
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
9120
|
-
if (storageCost < 0n) {
|
|
9121
|
-
return tryAsU64(0);
|
|
9122
|
-
}
|
|
9123
|
-
if (storageCost >= 2n ** 64n) {
|
|
9124
|
-
return tryAsU64(2n ** 64n - 1n);
|
|
9125
|
-
}
|
|
9126
|
-
return tryAsU64(storageCost);
|
|
9127
|
-
}
|
|
9128
|
-
constructor(
|
|
9129
|
-
/** `a_c`: Hash of the service code. */
|
|
9130
|
-
codeHash,
|
|
9131
|
-
/** `a_b`: Current account balance. */
|
|
9132
|
-
balance,
|
|
9133
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
9134
|
-
accumulateMinGas,
|
|
9135
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
9136
|
-
onTransferMinGas,
|
|
9137
|
-
/** `a_o`: Total number of octets in storage. */
|
|
9138
|
-
storageUtilisationBytes,
|
|
9139
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
9140
|
-
gratisStorage,
|
|
9141
|
-
/** `a_i`: Number of items in storage. */
|
|
9142
|
-
storageUtilisationCount,
|
|
9143
|
-
/** `a_r`: Creation account time slot. */
|
|
9144
|
-
created,
|
|
9145
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
9146
|
-
lastAccumulation,
|
|
9147
|
-
/** `a_p`: Parent service ID. */
|
|
9148
|
-
parentService) {
|
|
9149
|
-
super();
|
|
9150
|
-
this.codeHash = codeHash;
|
|
9151
|
-
this.balance = balance;
|
|
9152
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
9153
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
9154
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
9155
|
-
this.gratisStorage = gratisStorage;
|
|
9156
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
9157
|
-
this.created = created;
|
|
9158
|
-
this.lastAccumulation = lastAccumulation;
|
|
9159
|
-
this.parentService = parentService;
|
|
9160
|
-
}
|
|
9161
|
-
}
|
|
9162
|
-
class PreimageItem extends WithDebug {
|
|
9163
|
-
hash;
|
|
9164
|
-
blob;
|
|
9165
|
-
static Codec = codec$1.Class(PreimageItem, {
|
|
9166
|
-
hash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
9167
|
-
blob: codec$1.blob,
|
|
9168
|
-
});
|
|
9169
|
-
static create({ hash, blob }) {
|
|
9170
|
-
return new PreimageItem(hash, blob);
|
|
9171
|
-
}
|
|
9172
|
-
constructor(hash, blob) {
|
|
9173
|
-
super();
|
|
9174
|
-
this.hash = hash;
|
|
9175
|
-
this.blob = blob;
|
|
9176
|
-
}
|
|
9177
|
-
}
|
|
9178
|
-
class StorageItem extends WithDebug {
|
|
9179
|
-
key;
|
|
9180
|
-
value;
|
|
9181
|
-
static Codec = codec$1.Class(StorageItem, {
|
|
9182
|
-
key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
|
|
9183
|
-
value: codec$1.blob,
|
|
9184
|
-
});
|
|
9185
|
-
static create({ key, value }) {
|
|
9186
|
-
return new StorageItem(key, value);
|
|
9187
|
-
}
|
|
9188
|
-
constructor(key, value) {
|
|
9189
|
-
super();
|
|
9190
|
-
this.key = key;
|
|
9191
|
-
this.value = value;
|
|
9192
|
-
}
|
|
9193
|
-
}
|
|
9194
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
9195
|
-
function tryAsLookupHistorySlots(items) {
|
|
9196
|
-
const knownSize = asKnownSize(items);
|
|
9197
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
9198
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
9199
|
-
}
|
|
9200
|
-
return knownSize;
|
|
9201
|
-
}
|
|
9202
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
9203
|
-
class LookupHistoryItem {
|
|
9204
|
-
hash;
|
|
9205
|
-
length;
|
|
9206
|
-
slots;
|
|
9207
|
-
constructor(hash, length,
|
|
9208
|
-
/**
|
|
9209
|
-
* Preimage availability history as a sequence of time slots.
|
|
9210
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
9211
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
9212
|
-
slots) {
|
|
9213
|
-
this.hash = hash;
|
|
9214
|
-
this.length = length;
|
|
9215
|
-
this.slots = slots;
|
|
8639
|
+
static keys(keys) {
|
|
8640
|
+
return new SafroleSealingKeysData(SafroleSealingKeysKind.Keys, keys, undefined);
|
|
9216
8641
|
}
|
|
9217
|
-
static
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
8642
|
+
static tickets(tickets) {
|
|
8643
|
+
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
8644
|
+
}
|
|
8645
|
+
constructor(kind, keys, tickets) {
|
|
8646
|
+
super();
|
|
8647
|
+
this.kind = kind;
|
|
8648
|
+
this.keys = keys;
|
|
8649
|
+
this.tickets = tickets;
|
|
8650
|
+
}
|
|
8651
|
+
}
|
|
8652
|
+
class SafroleData {
|
|
8653
|
+
nextValidatorData;
|
|
8654
|
+
epochRoot;
|
|
8655
|
+
sealingKeySeries;
|
|
8656
|
+
ticketsAccumulator;
|
|
8657
|
+
static Codec = codec$1.Class(SafroleData, {
|
|
8658
|
+
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
8659
|
+
epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
8660
|
+
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
8661
|
+
ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
|
|
8662
|
+
});
|
|
8663
|
+
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
8664
|
+
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
8665
|
+
}
|
|
8666
|
+
constructor(
|
|
8667
|
+
/** gamma_k */
|
|
8668
|
+
nextValidatorData,
|
|
8669
|
+
/** gamma_z */
|
|
8670
|
+
epochRoot,
|
|
8671
|
+
/** gamma_s */
|
|
8672
|
+
sealingKeySeries,
|
|
8673
|
+
/** gamma_a */
|
|
8674
|
+
ticketsAccumulator) {
|
|
8675
|
+
this.nextValidatorData = nextValidatorData;
|
|
8676
|
+
this.epochRoot = epochRoot;
|
|
8677
|
+
this.sealingKeySeries = sealingKeySeries;
|
|
8678
|
+
this.ticketsAccumulator = ticketsAccumulator;
|
|
9222
8679
|
}
|
|
9223
8680
|
}
|
|
9224
8681
|
|
|
@@ -10029,8 +9486,9 @@ class InMemoryState extends WithDebug {
|
|
|
10029
9486
|
epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10030
9487
|
privilegedServices: PrivilegedServices.create({
|
|
10031
9488
|
manager: tryAsServiceId(0),
|
|
10032
|
-
|
|
10033
|
-
|
|
9489
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
9490
|
+
delegator: tryAsServiceId(0),
|
|
9491
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10034
9492
|
autoAccumulateServices: [],
|
|
10035
9493
|
}),
|
|
10036
9494
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -10050,7 +9508,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10050
9508
|
sortKeys: (a, b) => a - b,
|
|
10051
9509
|
});
|
|
10052
9510
|
|
|
10053
|
-
var index$
|
|
9511
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
10054
9512
|
__proto__: null,
|
|
10055
9513
|
AccumulationOutput: AccumulationOutput,
|
|
10056
9514
|
AutoAccumulate: AutoAccumulate,
|
|
@@ -10089,6 +9547,7 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
10089
9547
|
ValidatorStatistics: ValidatorStatistics,
|
|
10090
9548
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
10091
9549
|
codecPerCore: codecPerCore,
|
|
9550
|
+
codecWithVersion: codecWithVersion,
|
|
10092
9551
|
hashComparator: hashComparator,
|
|
10093
9552
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
10094
9553
|
serviceDataCodec: serviceDataCodec,
|
|
@@ -10249,21 +9708,23 @@ var serialize;
|
|
|
10249
9708
|
/** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
|
|
10250
9709
|
serialize.serviceData = (serviceId) => ({
|
|
10251
9710
|
key: stateKeys.serviceInfo(serviceId),
|
|
10252
|
-
Codec:
|
|
9711
|
+
Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9712
|
+
? codecWithVersion(ServiceAccountInfo.Codec)
|
|
9713
|
+
: ServiceAccountInfo.Codec,
|
|
10253
9714
|
});
|
|
10254
9715
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
10255
|
-
serialize.serviceStorage = (serviceId, key) => ({
|
|
10256
|
-
key: stateKeys.serviceStorage(serviceId, key),
|
|
9716
|
+
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
9717
|
+
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
10257
9718
|
Codec: dumpCodec,
|
|
10258
9719
|
});
|
|
10259
9720
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
10260
|
-
serialize.servicePreimages = (serviceId, hash) => ({
|
|
10261
|
-
key: stateKeys.servicePreimage(serviceId, hash),
|
|
9721
|
+
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
9722
|
+
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
10262
9723
|
Codec: dumpCodec,
|
|
10263
9724
|
});
|
|
10264
9725
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10265
|
-
serialize.serviceLookupHistory = (serviceId, hash, len) => ({
|
|
10266
|
-
key: stateKeys.serviceLookupHistory(serviceId, hash, len),
|
|
9726
|
+
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
9727
|
+
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10267
9728
|
Codec: readonlyArray(codec$1.sequenceVarLen(codec$1.u32)),
|
|
10268
9729
|
});
|
|
10269
9730
|
})(serialize || (serialize = {}));
|
|
@@ -10286,20 +9747,22 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10286
9747
|
*/
|
|
10287
9748
|
class SerializedState {
|
|
10288
9749
|
spec;
|
|
9750
|
+
blake2b;
|
|
10289
9751
|
backend;
|
|
10290
9752
|
_recentServiceIds;
|
|
10291
9753
|
/** Create a state-like object from collection of serialized entries. */
|
|
10292
|
-
static fromStateEntries(spec, state, recentServices = []) {
|
|
10293
|
-
return new SerializedState(spec, state, recentServices);
|
|
9754
|
+
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9755
|
+
return new SerializedState(spec, blake2b, state, recentServices);
|
|
10294
9756
|
}
|
|
10295
9757
|
/** Create a state-like object backed by some DB. */
|
|
10296
|
-
static new(spec, db, recentServices = []) {
|
|
10297
|
-
return new SerializedState(spec, db, recentServices);
|
|
9758
|
+
static new(spec, blake2b, db, recentServices = []) {
|
|
9759
|
+
return new SerializedState(spec, blake2b, db, recentServices);
|
|
10298
9760
|
}
|
|
10299
|
-
constructor(spec, backend,
|
|
9761
|
+
constructor(spec, blake2b, backend,
|
|
10300
9762
|
/** Best-effort list of recently active services. */
|
|
10301
9763
|
_recentServiceIds) {
|
|
10302
9764
|
this.spec = spec;
|
|
9765
|
+
this.blake2b = blake2b;
|
|
10303
9766
|
this.backend = backend;
|
|
10304
9767
|
this._recentServiceIds = _recentServiceIds;
|
|
10305
9768
|
}
|
|
@@ -10323,7 +9786,7 @@ class SerializedState {
|
|
|
10323
9786
|
if (!this._recentServiceIds.includes(id)) {
|
|
10324
9787
|
this._recentServiceIds.push(id);
|
|
10325
9788
|
}
|
|
10326
|
-
return new SerializedService(id, serviceData, (key) => this.retrieveOptional(key));
|
|
9789
|
+
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10327
9790
|
}
|
|
10328
9791
|
retrieve({ key, Codec }, description) {
|
|
10329
9792
|
const bytes = this.backend.get(key);
|
|
@@ -10399,12 +9862,14 @@ class SerializedState {
|
|
|
10399
9862
|
}
|
|
10400
9863
|
/** Service data representation on a serialized state. */
|
|
10401
9864
|
class SerializedService {
|
|
9865
|
+
blake2b;
|
|
10402
9866
|
serviceId;
|
|
10403
9867
|
accountInfo;
|
|
10404
9868
|
retrieveOptional;
|
|
10405
|
-
constructor(
|
|
9869
|
+
constructor(blake2b,
|
|
10406
9870
|
/** Service id */
|
|
10407
9871
|
serviceId, accountInfo, retrieveOptional) {
|
|
9872
|
+
this.blake2b = blake2b;
|
|
10408
9873
|
this.serviceId = serviceId;
|
|
10409
9874
|
this.accountInfo = accountInfo;
|
|
10410
9875
|
this.retrieveOptional = retrieveOptional;
|
|
@@ -10417,13 +9882,13 @@ class SerializedService {
|
|
|
10417
9882
|
getStorage(rawKey) {
|
|
10418
9883
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
10419
9884
|
const SERVICE_ID_BYTES = 4;
|
|
10420
|
-
const serviceIdAndKey =
|
|
9885
|
+
const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
10421
9886
|
serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
|
|
10422
9887
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10423
|
-
const key = asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
10424
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, key)) ?? null;
|
|
9888
|
+
const key = asOpaqueType(BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
9889
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10425
9890
|
}
|
|
10426
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, rawKey)) ?? null;
|
|
9891
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10427
9892
|
}
|
|
10428
9893
|
/**
|
|
10429
9894
|
* Check if preimage is present in the DB.
|
|
@@ -10432,15 +9897,15 @@ class SerializedService {
|
|
|
10432
9897
|
*/
|
|
10433
9898
|
hasPreimage(hash) {
|
|
10434
9899
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10435
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) !== undefined;
|
|
9900
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10436
9901
|
}
|
|
10437
9902
|
/** Retrieve preimage from the DB. */
|
|
10438
9903
|
getPreimage(hash) {
|
|
10439
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) ?? null;
|
|
9904
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10440
9905
|
}
|
|
10441
9906
|
/** Retrieve preimage lookup history. */
|
|
10442
9907
|
getLookupHistory(hash, len) {
|
|
10443
|
-
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.serviceId, hash, len));
|
|
9908
|
+
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
10444
9909
|
if (rawSlots === undefined) {
|
|
10445
9910
|
return null;
|
|
10446
9911
|
}
|
|
@@ -10502,7 +9967,7 @@ class TrieNode {
|
|
|
10502
9967
|
raw;
|
|
10503
9968
|
constructor(
|
|
10504
9969
|
/** Exactly 512 bits / 64 bytes */
|
|
10505
|
-
raw =
|
|
9970
|
+
raw = safeAllocUint8Array(TRIE_NODE_BYTES)) {
|
|
10506
9971
|
this.raw = raw;
|
|
10507
9972
|
}
|
|
10508
9973
|
/** Returns the type of the node */
|
|
@@ -11060,7 +10525,7 @@ const bitLookup = [
|
|
|
11060
10525
|
[0b00000000, 8],
|
|
11061
10526
|
];
|
|
11062
10527
|
|
|
11063
|
-
var index$
|
|
10528
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
11064
10529
|
__proto__: null,
|
|
11065
10530
|
BranchNode: BranchNode,
|
|
11066
10531
|
InMemoryTrie: InMemoryTrie,
|
|
@@ -11077,11 +10542,13 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
11077
10542
|
parseInputKey: parseInputKey
|
|
11078
10543
|
});
|
|
11079
10544
|
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
}
|
|
10545
|
+
function getBlake2bTrieHasher(hasher) {
|
|
10546
|
+
return {
|
|
10547
|
+
hashConcat(n, rest = []) {
|
|
10548
|
+
return hasher.hashBlobs([n, ...rest]);
|
|
10549
|
+
},
|
|
10550
|
+
};
|
|
10551
|
+
}
|
|
11085
10552
|
|
|
11086
10553
|
/** What should be done with that key? */
|
|
11087
10554
|
var StateEntryUpdateAction;
|
|
@@ -11093,14 +10560,14 @@ var StateEntryUpdateAction;
|
|
|
11093
10560
|
})(StateEntryUpdateAction || (StateEntryUpdateAction = {}));
|
|
11094
10561
|
const EMPTY_BLOB = BytesBlob.empty();
|
|
11095
10562
|
/** Serialize given state update into a series of key-value pairs. */
|
|
11096
|
-
function* serializeStateUpdate(spec, update) {
|
|
10563
|
+
function* serializeStateUpdate(spec, blake2b, update) {
|
|
11097
10564
|
// first let's serialize all of the simple entries (if present!)
|
|
11098
10565
|
yield* serializeBasicKeys(spec, update);
|
|
11099
10566
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
11100
10567
|
// then let's proceed with service updates
|
|
11101
|
-
yield* serializeServiceUpdates(update.servicesUpdates, encode);
|
|
11102
|
-
yield* serializePreimages(update.preimages, encode);
|
|
11103
|
-
yield* serializeStorage(update.storage);
|
|
10568
|
+
yield* serializeServiceUpdates(update.servicesUpdates, encode, blake2b);
|
|
10569
|
+
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
10570
|
+
yield* serializeStorage(update.storage, blake2b);
|
|
11104
10571
|
yield* serializeRemovedServices(update.servicesRemoved);
|
|
11105
10572
|
}
|
|
11106
10573
|
function* serializeRemovedServices(servicesRemoved) {
|
|
@@ -11110,18 +10577,18 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
11110
10577
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11111
10578
|
}
|
|
11112
10579
|
}
|
|
11113
|
-
function* serializeStorage(storage) {
|
|
10580
|
+
function* serializeStorage(storage, blake2b) {
|
|
11114
10581
|
for (const { action, serviceId } of storage ?? []) {
|
|
11115
10582
|
switch (action.kind) {
|
|
11116
10583
|
case UpdateStorageKind.Set: {
|
|
11117
10584
|
const key = action.storage.key;
|
|
11118
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10585
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11119
10586
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11120
10587
|
break;
|
|
11121
10588
|
}
|
|
11122
10589
|
case UpdateStorageKind.Remove: {
|
|
11123
10590
|
const key = action.key;
|
|
11124
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10591
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11125
10592
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11126
10593
|
break;
|
|
11127
10594
|
}
|
|
@@ -11130,15 +10597,15 @@ function* serializeStorage(storage) {
|
|
|
11130
10597
|
}
|
|
11131
10598
|
}
|
|
11132
10599
|
}
|
|
11133
|
-
function* serializePreimages(preimages, encode) {
|
|
10600
|
+
function* serializePreimages(preimages, encode, blake2b) {
|
|
11134
10601
|
for (const { action, serviceId } of preimages ?? []) {
|
|
11135
10602
|
switch (action.kind) {
|
|
11136
10603
|
case UpdatePreimageKind.Provide: {
|
|
11137
10604
|
const { hash, blob } = action.preimage;
|
|
11138
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10605
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11139
10606
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11140
10607
|
if (action.slot !== null) {
|
|
11141
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, tryAsU32(blob.length));
|
|
10608
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
11142
10609
|
yield [
|
|
11143
10610
|
StateEntryUpdateAction.Insert,
|
|
11144
10611
|
codec2.key,
|
|
@@ -11149,15 +10616,15 @@ function* serializePreimages(preimages, encode) {
|
|
|
11149
10616
|
}
|
|
11150
10617
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11151
10618
|
const { hash, length, slots } = action.item;
|
|
11152
|
-
const codec = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10619
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11153
10620
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11154
10621
|
break;
|
|
11155
10622
|
}
|
|
11156
10623
|
case UpdatePreimageKind.Remove: {
|
|
11157
10624
|
const { hash, length } = action;
|
|
11158
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10625
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11159
10626
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11160
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10627
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11161
10628
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11162
10629
|
break;
|
|
11163
10630
|
}
|
|
@@ -11166,7 +10633,7 @@ function* serializePreimages(preimages, encode) {
|
|
|
11166
10633
|
}
|
|
11167
10634
|
}
|
|
11168
10635
|
}
|
|
11169
|
-
function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
10636
|
+
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11170
10637
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
11171
10638
|
// new service being created or updated
|
|
11172
10639
|
const codec = serialize.serviceData(serviceId);
|
|
@@ -11174,7 +10641,7 @@ function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
|
11174
10641
|
// additional lookup history update
|
|
11175
10642
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11176
10643
|
const { lookupHistory } = action;
|
|
11177
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10644
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11178
10645
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11179
10646
|
}
|
|
11180
10647
|
}
|
|
@@ -11269,8 +10736,8 @@ class StateEntries {
|
|
|
11269
10736
|
},
|
|
11270
10737
|
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11271
10738
|
/** Turn in-memory state into it's serialized form. */
|
|
11272
|
-
static serializeInMemory(spec, state) {
|
|
11273
|
-
return new StateEntries(convertInMemoryStateToDictionary(spec, state));
|
|
10739
|
+
static serializeInMemory(spec, blake2b, state) {
|
|
10740
|
+
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
11274
10741
|
}
|
|
11275
10742
|
/**
|
|
11276
10743
|
* Wrap a collection of truncated state entries and treat it as state.
|
|
@@ -11319,7 +10786,8 @@ class StateEntries {
|
|
|
11319
10786
|
}
|
|
11320
10787
|
}
|
|
11321
10788
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/391600391600?v=0.6.4 */
|
|
11322
|
-
getRootHash() {
|
|
10789
|
+
getRootHash(blake2b) {
|
|
10790
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11323
10791
|
const leaves = SortedSet.fromArray(leafComparator);
|
|
11324
10792
|
for (const [key, value] of this) {
|
|
11325
10793
|
leaves.insert(InMemoryTrie.constructLeaf(blake2bTrieHasher, key.asOpaque(), value));
|
|
@@ -11328,7 +10796,7 @@ class StateEntries {
|
|
|
11328
10796
|
}
|
|
11329
10797
|
}
|
|
11330
10798
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/38a50038a500?v=0.6.4 */
|
|
11331
|
-
function convertInMemoryStateToDictionary(spec, state) {
|
|
10799
|
+
function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
11332
10800
|
const serialized = TruncatedHashDictionary.fromEntries([]);
|
|
11333
10801
|
function doSerialize(codec) {
|
|
11334
10802
|
serialized.set(codec.key, Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
@@ -11356,18 +10824,18 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11356
10824
|
serialized.set(key, Encoder.encodeObject(Codec, service.getInfo()));
|
|
11357
10825
|
// preimages
|
|
11358
10826
|
for (const preimage of service.data.preimages.values()) {
|
|
11359
|
-
const { key, Codec } = serialize.servicePreimages(serviceId, preimage.hash);
|
|
10827
|
+
const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11360
10828
|
serialized.set(key, Encoder.encodeObject(Codec, preimage.blob));
|
|
11361
10829
|
}
|
|
11362
10830
|
// storage
|
|
11363
10831
|
for (const storage of service.data.storage.values()) {
|
|
11364
|
-
const { key, Codec } = serialize.serviceStorage(serviceId, storage.key);
|
|
10832
|
+
const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11365
10833
|
serialized.set(key, Encoder.encodeObject(Codec, storage.value));
|
|
11366
10834
|
}
|
|
11367
10835
|
// lookup history
|
|
11368
10836
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11369
10837
|
for (const lookupHistory of lookupHistoryList) {
|
|
11370
|
-
const { key, Codec } = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10838
|
+
const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11371
10839
|
serialized.set(key, Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11372
10840
|
}
|
|
11373
10841
|
}
|
|
@@ -11375,9 +10843,9 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11375
10843
|
return serialized;
|
|
11376
10844
|
}
|
|
11377
10845
|
|
|
11378
|
-
function loadState(spec, entries) {
|
|
10846
|
+
function loadState(spec, blake2b, entries) {
|
|
11379
10847
|
const stateEntries = StateEntries.fromEntriesUnsafe(entries);
|
|
11380
|
-
return SerializedState.fromStateEntries(spec, stateEntries);
|
|
10848
|
+
return SerializedState.fromStateEntries(spec, blake2b, stateEntries);
|
|
11381
10849
|
}
|
|
11382
10850
|
|
|
11383
10851
|
/**
|
|
@@ -11406,7 +10874,7 @@ function loadState(spec, entries) {
|
|
|
11406
10874
|
* hashmap of `key -> value` entries.
|
|
11407
10875
|
*/
|
|
11408
10876
|
|
|
11409
|
-
var index$
|
|
10877
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
11410
10878
|
__proto__: null,
|
|
11411
10879
|
SerializedService: SerializedService,
|
|
11412
10880
|
SerializedState: SerializedState,
|
|
@@ -11485,7 +10953,8 @@ class LeafDb {
|
|
|
11485
10953
|
}
|
|
11486
10954
|
assertNever(val);
|
|
11487
10955
|
}
|
|
11488
|
-
getStateRoot() {
|
|
10956
|
+
getStateRoot(blake2b) {
|
|
10957
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11489
10958
|
return InMemoryTrie.computeStateRoot(blake2bTrieHasher, this.leaves).asOpaque();
|
|
11490
10959
|
}
|
|
11491
10960
|
intoStateEntries() {
|
|
@@ -11675,7 +11144,8 @@ class InMemoryStates {
|
|
|
11675
11144
|
}
|
|
11676
11145
|
}
|
|
11677
11146
|
async getStateRoot(state) {
|
|
11678
|
-
|
|
11147
|
+
const blake2b = await Blake2b.createHasher();
|
|
11148
|
+
return StateEntries.serializeInMemory(this.spec, blake2b, state).getRootHash(blake2b);
|
|
11679
11149
|
}
|
|
11680
11150
|
/** Insert a full state into the database. */
|
|
11681
11151
|
async insertState(headerHash, state) {
|
|
@@ -11692,7 +11162,7 @@ class InMemoryStates {
|
|
|
11692
11162
|
}
|
|
11693
11163
|
}
|
|
11694
11164
|
|
|
11695
|
-
var index$
|
|
11165
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
11696
11166
|
__proto__: null,
|
|
11697
11167
|
InMemoryBlocks: InMemoryBlocks,
|
|
11698
11168
|
InMemoryStates: InMemoryStates,
|
|
@@ -11753,7 +11223,7 @@ function padAndEncodeData(input) {
|
|
|
11753
11223
|
const paddedLength = Math.ceil(input.length / PIECE_SIZE) * PIECE_SIZE;
|
|
11754
11224
|
let padded = input;
|
|
11755
11225
|
if (input.length !== paddedLength) {
|
|
11756
|
-
padded = BytesBlob.blobFrom(
|
|
11226
|
+
padded = BytesBlob.blobFrom(safeAllocUint8Array(paddedLength));
|
|
11757
11227
|
padded.raw.set(input.raw, 0);
|
|
11758
11228
|
}
|
|
11759
11229
|
return chunkingFunction(padded);
|
|
@@ -11799,7 +11269,7 @@ function decodeData(input) {
|
|
|
11799
11269
|
*/
|
|
11800
11270
|
function encodePoints(input) {
|
|
11801
11271
|
const result = [];
|
|
11802
|
-
const data =
|
|
11272
|
+
const data = safeAllocUint8Array(POINT_ALIGNMENT * N_CHUNKS_REQUIRED);
|
|
11803
11273
|
// add original shards to the result
|
|
11804
11274
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11805
11275
|
const pointStart = POINT_LENGTH * i;
|
|
@@ -11815,7 +11285,7 @@ function encodePoints(input) {
|
|
|
11815
11285
|
const encodedData = encodedResult.take_data();
|
|
11816
11286
|
for (let i = 0; i < N_CHUNKS_REDUNDANCY; i++) {
|
|
11817
11287
|
const pointIndex = i * POINT_ALIGNMENT;
|
|
11818
|
-
const redundancyPoint =
|
|
11288
|
+
const redundancyPoint = safeAllocUint8Array(POINT_LENGTH);
|
|
11819
11289
|
for (let j = 0; j < POINT_LENGTH; j++) {
|
|
11820
11290
|
redundancyPoint[j] = encodedData[pointIndex + j * HALF_POINT_SIZE];
|
|
11821
11291
|
}
|
|
@@ -11830,7 +11300,7 @@ function encodePoints(input) {
|
|
|
11830
11300
|
*/
|
|
11831
11301
|
function decodePiece(input) {
|
|
11832
11302
|
const result = Bytes.zero(PIECE_SIZE);
|
|
11833
|
-
const data =
|
|
11303
|
+
const data = safeAllocUint8Array(N_CHUNKS_REQUIRED * POINT_ALIGNMENT);
|
|
11834
11304
|
const indices = new Uint16Array(input.length);
|
|
11835
11305
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11836
11306
|
const [index, points] = input[i];
|
|
@@ -11946,7 +11416,7 @@ function lace(input) {
|
|
|
11946
11416
|
return BytesBlob.empty();
|
|
11947
11417
|
}
|
|
11948
11418
|
const n = input[0].length;
|
|
11949
|
-
const result = BytesBlob.blobFrom(
|
|
11419
|
+
const result = BytesBlob.blobFrom(safeAllocUint8Array(k * n));
|
|
11950
11420
|
for (let i = 0; i < k; i++) {
|
|
11951
11421
|
const entry = input[i].raw;
|
|
11952
11422
|
for (let j = 0; j < n; j++) {
|
|
@@ -12054,7 +11524,7 @@ const initEc = async () => {
|
|
|
12054
11524
|
await init.reedSolomon();
|
|
12055
11525
|
};
|
|
12056
11526
|
|
|
12057
|
-
var index$
|
|
11527
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
12058
11528
|
__proto__: null,
|
|
12059
11529
|
N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
|
|
12060
11530
|
N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
|
|
@@ -12078,6 +11548,439 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12078
11548
|
unzip: unzip
|
|
12079
11549
|
});
|
|
12080
11550
|
|
|
11551
|
+
/**
|
|
11552
|
+
* Version ::= SEQUENCE {
|
|
11553
|
+
* major INTEGER (0..255),
|
|
11554
|
+
* minor INTEGER (0..255),
|
|
11555
|
+
* patch INTEGER (0..255)
|
|
11556
|
+
* }
|
|
11557
|
+
*/
|
|
11558
|
+
class Version extends WithDebug {
|
|
11559
|
+
major;
|
|
11560
|
+
minor;
|
|
11561
|
+
patch;
|
|
11562
|
+
static Codec = codec$1.Class(Version, {
|
|
11563
|
+
major: codec$1.u8,
|
|
11564
|
+
minor: codec$1.u8,
|
|
11565
|
+
patch: codec$1.u8,
|
|
11566
|
+
});
|
|
11567
|
+
static tryFromString(str) {
|
|
11568
|
+
const parse = (v) => tryAsU8(Number(v));
|
|
11569
|
+
try {
|
|
11570
|
+
const [major, minor, patch] = str.trim().split(".").map(parse);
|
|
11571
|
+
return Version.create({
|
|
11572
|
+
major,
|
|
11573
|
+
minor,
|
|
11574
|
+
patch,
|
|
11575
|
+
});
|
|
11576
|
+
}
|
|
11577
|
+
catch (e) {
|
|
11578
|
+
throw new Error(`Unable to parse ${str} as Version: ${e}`);
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11581
|
+
static create({ major, minor, patch }) {
|
|
11582
|
+
return new Version(major, minor, patch);
|
|
11583
|
+
}
|
|
11584
|
+
constructor(major, minor, patch) {
|
|
11585
|
+
super();
|
|
11586
|
+
this.major = major;
|
|
11587
|
+
this.minor = minor;
|
|
11588
|
+
this.patch = patch;
|
|
11589
|
+
}
|
|
11590
|
+
}
|
|
11591
|
+
/**
|
|
11592
|
+
* Fuzzer Protocol V1
|
|
11593
|
+
* Reference: https://github.com/davxy/jam-conformance/blob/main/fuzz-proto/fuzz.asn
|
|
11594
|
+
*/
|
|
11595
|
+
// Feature bit constants
|
|
11596
|
+
var Features;
|
|
11597
|
+
(function (Features) {
|
|
11598
|
+
Features[Features["Ancestry"] = 1] = "Ancestry";
|
|
11599
|
+
Features[Features["Fork"] = 2] = "Fork";
|
|
11600
|
+
Features[Features["Reserved"] = 2147483648] = "Reserved";
|
|
11601
|
+
})(Features || (Features = {}));
|
|
11602
|
+
/**
|
|
11603
|
+
* PeerInfo ::= SEQUENCE {
|
|
11604
|
+
* fuzz-version U8,
|
|
11605
|
+
* features Features,
|
|
11606
|
+
* jam-version Version,
|
|
11607
|
+
* app-version Version,
|
|
11608
|
+
* name UTF8String
|
|
11609
|
+
* }
|
|
11610
|
+
*/
|
|
11611
|
+
class PeerInfo extends WithDebug {
|
|
11612
|
+
fuzzVersion;
|
|
11613
|
+
features;
|
|
11614
|
+
jamVersion;
|
|
11615
|
+
appVersion;
|
|
11616
|
+
name;
|
|
11617
|
+
static Codec = codec$1.Class(PeerInfo, {
|
|
11618
|
+
fuzzVersion: codec$1.u8,
|
|
11619
|
+
features: codec$1.u32,
|
|
11620
|
+
jamVersion: Version.Codec,
|
|
11621
|
+
appVersion: Version.Codec,
|
|
11622
|
+
name: codec$1.string,
|
|
11623
|
+
});
|
|
11624
|
+
static create({ fuzzVersion, features, appVersion, jamVersion, name }) {
|
|
11625
|
+
return new PeerInfo(fuzzVersion, features, jamVersion, appVersion, name);
|
|
11626
|
+
}
|
|
11627
|
+
constructor(fuzzVersion, features, jamVersion, appVersion, name) {
|
|
11628
|
+
super();
|
|
11629
|
+
this.fuzzVersion = fuzzVersion;
|
|
11630
|
+
this.features = features;
|
|
11631
|
+
this.jamVersion = jamVersion;
|
|
11632
|
+
this.appVersion = appVersion;
|
|
11633
|
+
this.name = name;
|
|
11634
|
+
}
|
|
11635
|
+
}
|
|
11636
|
+
/**
|
|
11637
|
+
* AncestryItem ::= SEQUENCE {
|
|
11638
|
+
* slot TimeSlot,
|
|
11639
|
+
* header-hash HeaderHash
|
|
11640
|
+
* }
|
|
11641
|
+
*/
|
|
11642
|
+
class AncestryItem extends WithDebug {
|
|
11643
|
+
slot;
|
|
11644
|
+
headerHash;
|
|
11645
|
+
static Codec = codec$1.Class(AncestryItem, {
|
|
11646
|
+
slot: codec$1.u32.asOpaque(),
|
|
11647
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
11648
|
+
});
|
|
11649
|
+
static create({ slot, headerHash }) {
|
|
11650
|
+
return new AncestryItem(slot, headerHash);
|
|
11651
|
+
}
|
|
11652
|
+
constructor(slot, headerHash) {
|
|
11653
|
+
super();
|
|
11654
|
+
this.slot = slot;
|
|
11655
|
+
this.headerHash = headerHash;
|
|
11656
|
+
}
|
|
11657
|
+
}
|
|
11658
|
+
/**
|
|
11659
|
+
* KeyValue ::= SEQUENCE {
|
|
11660
|
+
* key TrieKey,
|
|
11661
|
+
* value OCTET STRING
|
|
11662
|
+
* }
|
|
11663
|
+
*/
|
|
11664
|
+
class KeyValue extends WithDebug {
|
|
11665
|
+
key;
|
|
11666
|
+
value;
|
|
11667
|
+
static Codec = codec$1.Class(KeyValue, {
|
|
11668
|
+
key: codec$1.bytes(TRUNCATED_HASH_SIZE),
|
|
11669
|
+
value: codec$1.blob,
|
|
11670
|
+
});
|
|
11671
|
+
static create({ key, value }) {
|
|
11672
|
+
return new KeyValue(key, value);
|
|
11673
|
+
}
|
|
11674
|
+
constructor(key, value) {
|
|
11675
|
+
super();
|
|
11676
|
+
this.key = key;
|
|
11677
|
+
this.value = value;
|
|
11678
|
+
}
|
|
11679
|
+
}
|
|
11680
|
+
/** State ::= SEQUENCE OF KeyValue */
|
|
11681
|
+
const stateCodec = codec$1.sequenceVarLen(KeyValue.Codec);
|
|
11682
|
+
/**
|
|
11683
|
+
* Ancestry ::= SEQUENCE (SIZE(0..24)) OF AncestryItem
|
|
11684
|
+
* Empty when `feature-ancestry` is not supported by both parties
|
|
11685
|
+
*/
|
|
11686
|
+
const ancestryCodec = codec$1.sequenceVarLen(AncestryItem.Codec, {
|
|
11687
|
+
minLength: 0,
|
|
11688
|
+
maxLength: 24,
|
|
11689
|
+
});
|
|
11690
|
+
/**
|
|
11691
|
+
* Initialize ::= SEQUENCE {
|
|
11692
|
+
* header Header,
|
|
11693
|
+
* keyvals State,
|
|
11694
|
+
* ancestry Ancestry
|
|
11695
|
+
* }
|
|
11696
|
+
*/
|
|
11697
|
+
class Initialize extends WithDebug {
|
|
11698
|
+
header;
|
|
11699
|
+
keyvals;
|
|
11700
|
+
ancestry;
|
|
11701
|
+
static Codec = codec$1.Class(Initialize, {
|
|
11702
|
+
header: Header.Codec,
|
|
11703
|
+
keyvals: stateCodec,
|
|
11704
|
+
ancestry: ancestryCodec,
|
|
11705
|
+
});
|
|
11706
|
+
static create({ header, keyvals, ancestry }) {
|
|
11707
|
+
return new Initialize(header, keyvals, ancestry);
|
|
11708
|
+
}
|
|
11709
|
+
constructor(header, keyvals, ancestry) {
|
|
11710
|
+
super();
|
|
11711
|
+
this.header = header;
|
|
11712
|
+
this.keyvals = keyvals;
|
|
11713
|
+
this.ancestry = ancestry;
|
|
11714
|
+
}
|
|
11715
|
+
}
|
|
11716
|
+
/** GetState ::= HeaderHash */
|
|
11717
|
+
const getStateCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
11718
|
+
/** StateRoot ::= StateRootHash */
|
|
11719
|
+
const stateRootCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
11720
|
+
/** Error ::= UTF8String */
|
|
11721
|
+
class ErrorMessage extends WithDebug {
|
|
11722
|
+
message;
|
|
11723
|
+
static Codec = codec$1.Class(ErrorMessage, {
|
|
11724
|
+
message: codec$1.string,
|
|
11725
|
+
});
|
|
11726
|
+
static create({ message }) {
|
|
11727
|
+
return new ErrorMessage(message);
|
|
11728
|
+
}
|
|
11729
|
+
constructor(message) {
|
|
11730
|
+
super();
|
|
11731
|
+
this.message = message;
|
|
11732
|
+
}
|
|
11733
|
+
}
|
|
11734
|
+
/** Message choice type tags */
|
|
11735
|
+
var MessageType;
|
|
11736
|
+
(function (MessageType) {
|
|
11737
|
+
MessageType[MessageType["PeerInfo"] = 0] = "PeerInfo";
|
|
11738
|
+
MessageType[MessageType["Initialize"] = 1] = "Initialize";
|
|
11739
|
+
MessageType[MessageType["StateRoot"] = 2] = "StateRoot";
|
|
11740
|
+
MessageType[MessageType["ImportBlock"] = 3] = "ImportBlock";
|
|
11741
|
+
MessageType[MessageType["GetState"] = 4] = "GetState";
|
|
11742
|
+
MessageType[MessageType["State"] = 5] = "State";
|
|
11743
|
+
MessageType[MessageType["Error"] = 255] = "Error";
|
|
11744
|
+
})(MessageType || (MessageType = {}));
|
|
11745
|
+
/**
|
|
11746
|
+
* Message ::= CHOICE {
|
|
11747
|
+
* peer-info [0] PeerInfo,
|
|
11748
|
+
* initialize [1] Initialize,
|
|
11749
|
+
* state-root [2] StateRoot,
|
|
11750
|
+
* import-block [3] ImportBlock,
|
|
11751
|
+
* get-state [4] GetState,
|
|
11752
|
+
* state [5] State,
|
|
11753
|
+
* error [255] Error
|
|
11754
|
+
* }
|
|
11755
|
+
*/
|
|
11756
|
+
const messageCodec = codec$1.custom({
|
|
11757
|
+
name: "Message",
|
|
11758
|
+
sizeHint: { bytes: 1, isExact: false },
|
|
11759
|
+
}, (e, msg) => {
|
|
11760
|
+
e.i8(msg.type);
|
|
11761
|
+
switch (msg.type) {
|
|
11762
|
+
case MessageType.PeerInfo:
|
|
11763
|
+
PeerInfo.Codec.encode(e, msg.value);
|
|
11764
|
+
break;
|
|
11765
|
+
case MessageType.Initialize:
|
|
11766
|
+
Initialize.Codec.encode(e, msg.value);
|
|
11767
|
+
break;
|
|
11768
|
+
case MessageType.StateRoot:
|
|
11769
|
+
stateRootCodec.encode(e, msg.value);
|
|
11770
|
+
break;
|
|
11771
|
+
case MessageType.ImportBlock:
|
|
11772
|
+
Block.Codec.View.encode(e, msg.value);
|
|
11773
|
+
break;
|
|
11774
|
+
case MessageType.GetState:
|
|
11775
|
+
getStateCodec.encode(e, msg.value);
|
|
11776
|
+
break;
|
|
11777
|
+
case MessageType.State:
|
|
11778
|
+
stateCodec.encode(e, msg.value);
|
|
11779
|
+
break;
|
|
11780
|
+
case MessageType.Error:
|
|
11781
|
+
ErrorMessage.Codec.encode(e, msg.value);
|
|
11782
|
+
break;
|
|
11783
|
+
default:
|
|
11784
|
+
throw new Error(`Unknown message type: ${msg}`);
|
|
11785
|
+
}
|
|
11786
|
+
}, (d) => {
|
|
11787
|
+
const type = d.u8();
|
|
11788
|
+
switch (type) {
|
|
11789
|
+
case MessageType.PeerInfo:
|
|
11790
|
+
return { type: MessageType.PeerInfo, value: PeerInfo.Codec.decode(d) };
|
|
11791
|
+
case MessageType.Initialize:
|
|
11792
|
+
return { type: MessageType.Initialize, value: Initialize.Codec.decode(d) };
|
|
11793
|
+
case MessageType.StateRoot:
|
|
11794
|
+
return { type: MessageType.StateRoot, value: stateRootCodec.decode(d) };
|
|
11795
|
+
case MessageType.ImportBlock:
|
|
11796
|
+
return { type: MessageType.ImportBlock, value: Block.Codec.View.decode(d) };
|
|
11797
|
+
case MessageType.GetState:
|
|
11798
|
+
return { type: MessageType.GetState, value: getStateCodec.decode(d) };
|
|
11799
|
+
case MessageType.State:
|
|
11800
|
+
return { type: MessageType.State, value: stateCodec.decode(d) };
|
|
11801
|
+
case MessageType.Error:
|
|
11802
|
+
return { type: MessageType.Error, value: ErrorMessage.Codec.decode(d) };
|
|
11803
|
+
default:
|
|
11804
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
11805
|
+
}
|
|
11806
|
+
}, (s) => {
|
|
11807
|
+
const type = s.decoder.u8();
|
|
11808
|
+
switch (type) {
|
|
11809
|
+
case MessageType.PeerInfo:
|
|
11810
|
+
PeerInfo.Codec.View.skip(s);
|
|
11811
|
+
break;
|
|
11812
|
+
case MessageType.Initialize:
|
|
11813
|
+
Initialize.Codec.View.skip(s);
|
|
11814
|
+
break;
|
|
11815
|
+
case MessageType.StateRoot:
|
|
11816
|
+
stateRootCodec.View.skip(s);
|
|
11817
|
+
break;
|
|
11818
|
+
case MessageType.ImportBlock:
|
|
11819
|
+
Block.Codec.View.skip(s);
|
|
11820
|
+
break;
|
|
11821
|
+
case MessageType.GetState:
|
|
11822
|
+
getStateCodec.View.skip(s);
|
|
11823
|
+
break;
|
|
11824
|
+
case MessageType.State:
|
|
11825
|
+
stateCodec.View.skip(s);
|
|
11826
|
+
break;
|
|
11827
|
+
case MessageType.Error:
|
|
11828
|
+
ErrorMessage.Codec.View.skip(s);
|
|
11829
|
+
break;
|
|
11830
|
+
default:
|
|
11831
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
11832
|
+
}
|
|
11833
|
+
});
|
|
11834
|
+
|
|
11835
|
+
const logger$4 = Logger.new(undefined, "ext-ipc-fuzz-v1");
|
|
11836
|
+
class FuzzTarget {
|
|
11837
|
+
msgHandler;
|
|
11838
|
+
sender;
|
|
11839
|
+
spec;
|
|
11840
|
+
sessionFeatures = 0;
|
|
11841
|
+
constructor(msgHandler, sender, spec) {
|
|
11842
|
+
this.msgHandler = msgHandler;
|
|
11843
|
+
this.sender = sender;
|
|
11844
|
+
this.spec = spec;
|
|
11845
|
+
}
|
|
11846
|
+
async onSocketMessage(msg) {
|
|
11847
|
+
// attempt to decode the messsage
|
|
11848
|
+
try {
|
|
11849
|
+
const message = Decoder.decodeObject(messageCodec, msg, this.spec);
|
|
11850
|
+
logger$4.log `[${message.type}] incoming message`;
|
|
11851
|
+
await this.processAndRespond(message);
|
|
11852
|
+
}
|
|
11853
|
+
catch (e) {
|
|
11854
|
+
logger$4.error `Error while processing fuzz v1 message: ${e}`;
|
|
11855
|
+
logger$4.error `${e}`;
|
|
11856
|
+
if (e instanceof Error) {
|
|
11857
|
+
logger$4.error `${e.stack ?? ""}`;
|
|
11858
|
+
}
|
|
11859
|
+
this.sender.close();
|
|
11860
|
+
}
|
|
11861
|
+
}
|
|
11862
|
+
async processAndRespond(message) {
|
|
11863
|
+
let response = null;
|
|
11864
|
+
switch (message.type) {
|
|
11865
|
+
case MessageType.PeerInfo: {
|
|
11866
|
+
// only support V1
|
|
11867
|
+
if (message.value.fuzzVersion !== 1) {
|
|
11868
|
+
logger$4.warn `Unsupported fuzzer protocol version: ${message.value.fuzzVersion}. Closing`;
|
|
11869
|
+
this.sender.close();
|
|
11870
|
+
return;
|
|
11871
|
+
}
|
|
11872
|
+
// Handle handshake
|
|
11873
|
+
const ourPeerInfo = await this.msgHandler.getPeerInfo(message.value);
|
|
11874
|
+
// Calculate session features (intersection of both peer features)
|
|
11875
|
+
this.sessionFeatures = message.value.features & ourPeerInfo.features;
|
|
11876
|
+
logger$4.info `Handshake completed. Shared features: 0b${this.sessionFeatures.toString(2)}`;
|
|
11877
|
+
logger$4.log `Feature ancestry: ${(this.sessionFeatures & Features.Ancestry) !== 0}`;
|
|
11878
|
+
logger$4.log `Feature fork: ${(this.sessionFeatures & Features.Fork) !== 0}`;
|
|
11879
|
+
response = {
|
|
11880
|
+
type: MessageType.PeerInfo,
|
|
11881
|
+
value: ourPeerInfo,
|
|
11882
|
+
};
|
|
11883
|
+
break;
|
|
11884
|
+
}
|
|
11885
|
+
case MessageType.Initialize: {
|
|
11886
|
+
const stateRoot = await this.msgHandler.initialize(message.value);
|
|
11887
|
+
response = {
|
|
11888
|
+
type: MessageType.StateRoot,
|
|
11889
|
+
value: stateRoot,
|
|
11890
|
+
};
|
|
11891
|
+
break;
|
|
11892
|
+
}
|
|
11893
|
+
case MessageType.ImportBlock: {
|
|
11894
|
+
const result = await this.msgHandler.importBlock(message.value);
|
|
11895
|
+
if (result.isOk) {
|
|
11896
|
+
response = {
|
|
11897
|
+
type: MessageType.StateRoot,
|
|
11898
|
+
value: result.ok,
|
|
11899
|
+
};
|
|
11900
|
+
}
|
|
11901
|
+
else {
|
|
11902
|
+
response = {
|
|
11903
|
+
type: MessageType.Error,
|
|
11904
|
+
value: result.error,
|
|
11905
|
+
};
|
|
11906
|
+
}
|
|
11907
|
+
break;
|
|
11908
|
+
}
|
|
11909
|
+
case MessageType.GetState: {
|
|
11910
|
+
const state = await this.msgHandler.getSerializedState(message.value);
|
|
11911
|
+
response = {
|
|
11912
|
+
type: MessageType.State,
|
|
11913
|
+
value: state,
|
|
11914
|
+
};
|
|
11915
|
+
break;
|
|
11916
|
+
}
|
|
11917
|
+
case MessageType.StateRoot: {
|
|
11918
|
+
logger$4.log `--> Received unexpected 'StateRoot' message from the fuzzer. Closing.`;
|
|
11919
|
+
this.sender.close();
|
|
11920
|
+
return;
|
|
11921
|
+
}
|
|
11922
|
+
case MessageType.State: {
|
|
11923
|
+
logger$4.log `--> Received unexpected 'State' message from the fuzzer. Closing.`;
|
|
11924
|
+
this.sender.close();
|
|
11925
|
+
return;
|
|
11926
|
+
}
|
|
11927
|
+
case MessageType.Error: {
|
|
11928
|
+
logger$4.log `--> Received unexpected 'Error' message from the fuzzer. Closing.`;
|
|
11929
|
+
this.sender.close();
|
|
11930
|
+
return;
|
|
11931
|
+
}
|
|
11932
|
+
default: {
|
|
11933
|
+
logger$4.log `--> Received unexpected message type ${JSON.stringify(message)} from the fuzzer. Closing.`;
|
|
11934
|
+
this.sender.close();
|
|
11935
|
+
try {
|
|
11936
|
+
assertNever(message);
|
|
11937
|
+
}
|
|
11938
|
+
catch {
|
|
11939
|
+
return;
|
|
11940
|
+
}
|
|
11941
|
+
}
|
|
11942
|
+
}
|
|
11943
|
+
if (response !== null) {
|
|
11944
|
+
logger$4.trace `<-- responding with: ${response.type}`;
|
|
11945
|
+
const encoded = Encoder.encodeObject(messageCodec, response, this.spec);
|
|
11946
|
+
this.sender.send(encoded);
|
|
11947
|
+
}
|
|
11948
|
+
else {
|
|
11949
|
+
logger$4.warn `<-- no response generated for: ${message.type}`;
|
|
11950
|
+
}
|
|
11951
|
+
}
|
|
11952
|
+
onClose({ error }) {
|
|
11953
|
+
logger$4.log `Closing the v1 handler. Reason: ${error !== undefined ? error.message : "close"}.`;
|
|
11954
|
+
}
|
|
11955
|
+
/** Check if a specific feature is enabled in the session */
|
|
11956
|
+
hasFeature(feature) {
|
|
11957
|
+
return (this.sessionFeatures & feature) !== 0;
|
|
11958
|
+
}
|
|
11959
|
+
}
|
|
11960
|
+
|
|
11961
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
11962
|
+
__proto__: null,
|
|
11963
|
+
AncestryItem: AncestryItem,
|
|
11964
|
+
ErrorMessage: ErrorMessage,
|
|
11965
|
+
get Features () { return Features; },
|
|
11966
|
+
FuzzTarget: FuzzTarget,
|
|
11967
|
+
Initialize: Initialize,
|
|
11968
|
+
KeyValue: KeyValue,
|
|
11969
|
+
get MessageType () { return MessageType; },
|
|
11970
|
+
PeerInfo: PeerInfo,
|
|
11971
|
+
Version: Version,
|
|
11972
|
+
ancestryCodec: ancestryCodec,
|
|
11973
|
+
getStateCodec: getStateCodec,
|
|
11974
|
+
messageCodec: messageCodec,
|
|
11975
|
+
stateCodec: stateCodec,
|
|
11976
|
+
stateRootCodec: stateRootCodec
|
|
11977
|
+
});
|
|
11978
|
+
|
|
11979
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
11980
|
+
__proto__: null,
|
|
11981
|
+
v1: index$b
|
|
11982
|
+
});
|
|
11983
|
+
|
|
12081
11984
|
/** Size of the transfer memo. */
|
|
12082
11985
|
const TRANSFER_MEMO_BYTES = W_T;
|
|
12083
11986
|
/**
|
|
@@ -12192,6 +12095,8 @@ var NewServiceError;
|
|
|
12192
12095
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
12193
12096
|
/** Service is not privileged to set gratis storage. */
|
|
12194
12097
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
12098
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
12099
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
12195
12100
|
})(NewServiceError || (NewServiceError = {}));
|
|
12196
12101
|
var UpdatePrivilegesError;
|
|
12197
12102
|
(function (UpdatePrivilegesError) {
|
|
@@ -12382,11 +12287,17 @@ class AccumulationStateUpdate {
|
|
|
12382
12287
|
if (from.privilegedServices !== null) {
|
|
12383
12288
|
update.privilegedServices = PrivilegedServices.create({
|
|
12384
12289
|
...from.privilegedServices,
|
|
12385
|
-
|
|
12290
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
12386
12291
|
});
|
|
12387
12292
|
}
|
|
12388
12293
|
return update;
|
|
12389
12294
|
}
|
|
12295
|
+
/** Retrieve and clear pending transfers. */
|
|
12296
|
+
takeTransfers() {
|
|
12297
|
+
const transfers = this.transfers;
|
|
12298
|
+
this.transfers = [];
|
|
12299
|
+
return transfers;
|
|
12300
|
+
}
|
|
12390
12301
|
}
|
|
12391
12302
|
class PartiallyUpdatedState {
|
|
12392
12303
|
state;
|
|
@@ -12583,7 +12494,7 @@ const HostCallResult = {
|
|
|
12583
12494
|
OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
12584
12495
|
/** Index unknown. */
|
|
12585
12496
|
WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
12586
|
-
/** Storage full. */
|
|
12497
|
+
/** Storage full or resource already allocated. */
|
|
12587
12498
|
FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
12588
12499
|
/** Core index unknown. */
|
|
12589
12500
|
CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -12591,7 +12502,7 @@ const HostCallResult = {
|
|
|
12591
12502
|
CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
12592
12503
|
/** Gas limit too low. */
|
|
12593
12504
|
LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
12594
|
-
/** The item is already solicited
|
|
12505
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
12595
12506
|
HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
12596
12507
|
/** The return value indicating general success. */
|
|
12597
12508
|
OK: tryAsU64(0n),
|
|
@@ -12792,7 +12703,7 @@ class Registers {
|
|
|
12792
12703
|
bytes;
|
|
12793
12704
|
asSigned;
|
|
12794
12705
|
asUnsigned;
|
|
12795
|
-
constructor(bytes =
|
|
12706
|
+
constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT)) {
|
|
12796
12707
|
this.bytes = bytes;
|
|
12797
12708
|
check `${bytes.length === NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
12798
12709
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
@@ -12864,10 +12775,16 @@ function signExtend32To64(value) {
|
|
|
12864
12775
|
|
|
12865
12776
|
/** Attempt to convert a number into `HostCallIndex`. */
|
|
12866
12777
|
const tryAsHostCallIndex = (v) => asOpaqueType(tryAsU32(v));
|
|
12778
|
+
/**
|
|
12779
|
+
* Host-call exit reason.
|
|
12780
|
+
*
|
|
12781
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
|
|
12782
|
+
*/
|
|
12867
12783
|
var PvmExecution;
|
|
12868
12784
|
(function (PvmExecution) {
|
|
12869
12785
|
PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
|
|
12870
12786
|
PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
|
|
12787
|
+
PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
|
|
12871
12788
|
})(PvmExecution || (PvmExecution = {}));
|
|
12872
12789
|
/** A utility function to easily trace a bunch of registers. */
|
|
12873
12790
|
function traceRegisters(...regs) {
|
|
@@ -12939,7 +12856,7 @@ class Mask {
|
|
|
12939
12856
|
return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
|
|
12940
12857
|
}
|
|
12941
12858
|
buildLookupTableForward(mask) {
|
|
12942
|
-
const table =
|
|
12859
|
+
const table = safeAllocUint8Array(mask.bitLength);
|
|
12943
12860
|
let lastInstructionOffset = 0;
|
|
12944
12861
|
for (let i = mask.bitLength - 1; i >= 0; i--) {
|
|
12945
12862
|
if (mask.isSet(i)) {
|
|
@@ -14125,6 +14042,17 @@ class PageRange {
|
|
|
14125
14042
|
}
|
|
14126
14043
|
return new PageRange(start, length);
|
|
14127
14044
|
}
|
|
14045
|
+
/** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
|
|
14046
|
+
isWrapped() {
|
|
14047
|
+
return this.start >= this.end && !this.isEmpty();
|
|
14048
|
+
}
|
|
14049
|
+
/** Checks if given page number is within the range */
|
|
14050
|
+
isInRange(page) {
|
|
14051
|
+
if (this.isWrapped()) {
|
|
14052
|
+
return page >= this.start || page < this.end;
|
|
14053
|
+
}
|
|
14054
|
+
return page >= this.start && page < this.end;
|
|
14055
|
+
}
|
|
14128
14056
|
/** Checks if a range is empty (`length === 0`) */
|
|
14129
14057
|
isEmpty() {
|
|
14130
14058
|
return this.length === 0;
|
|
@@ -14465,10 +14393,11 @@ class MemoryBuilder {
|
|
|
14465
14393
|
startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
|
|
14466
14394
|
`;
|
|
14467
14395
|
this.ensureNotFinalized();
|
|
14468
|
-
const
|
|
14469
|
-
const
|
|
14470
|
-
|
|
14471
|
-
|
|
14396
|
+
const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
|
|
14397
|
+
const heapPagesRange = PageRange.fromMemoryRange(heapRange);
|
|
14398
|
+
const initializedPageNumbers = Array.from(this.initialMemory.keys());
|
|
14399
|
+
for (const pageNumber of initializedPageNumbers) {
|
|
14400
|
+
if (heapPagesRange.isInRange(pageNumber)) {
|
|
14472
14401
|
throw new IncorrectSbrkIndex();
|
|
14473
14402
|
}
|
|
14474
14403
|
}
|
|
@@ -14608,11 +14537,6 @@ class BitOps {
|
|
|
14608
14537
|
}
|
|
14609
14538
|
}
|
|
14610
14539
|
|
|
14611
|
-
const MAX_VALUE = 4294967295;
|
|
14612
|
-
const MIN_VALUE = -2147483648;
|
|
14613
|
-
const MAX_SHIFT_U32 = 32;
|
|
14614
|
-
const MAX_SHIFT_U64 = 64n;
|
|
14615
|
-
|
|
14616
14540
|
/**
|
|
14617
14541
|
* Overflowing addition for two-complement representation of 32-bit signed numbers.
|
|
14618
14542
|
*/
|
|
@@ -16462,7 +16386,7 @@ class HostCalls {
|
|
|
16462
16386
|
const regs = pvmInstance.getRegisters();
|
|
16463
16387
|
const maybeAddress = regs.getLowerU32(7);
|
|
16464
16388
|
const maybeLength = regs.getLowerU32(8);
|
|
16465
|
-
const result =
|
|
16389
|
+
const result = safeAllocUint8Array(maybeLength);
|
|
16466
16390
|
const startAddress = tryAsMemoryIndex(maybeAddress);
|
|
16467
16391
|
const loadResult = memory.loadInto(result, startAddress);
|
|
16468
16392
|
if (loadResult.isError) {
|
|
@@ -16490,8 +16414,9 @@ class HostCalls {
|
|
|
16490
16414
|
const index = tryAsHostCallIndex(hostCallIndex);
|
|
16491
16415
|
const hostCall = this.hostCalls.get(index);
|
|
16492
16416
|
const gasBefore = gas.get();
|
|
16493
|
-
|
|
16494
|
-
const
|
|
16417
|
+
// NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
|
|
16418
|
+
const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
|
|
16419
|
+
const underflow = gas.sub(basicGasCost);
|
|
16495
16420
|
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
16496
16421
|
if (underflow) {
|
|
16497
16422
|
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
@@ -16508,6 +16433,10 @@ class HostCalls {
|
|
|
16508
16433
|
status = Status.PANIC;
|
|
16509
16434
|
return this.getReturnValue(status, pvmInstance);
|
|
16510
16435
|
}
|
|
16436
|
+
if (result === PvmExecution.OOG) {
|
|
16437
|
+
status = Status.OOG;
|
|
16438
|
+
return this.getReturnValue(status, pvmInstance);
|
|
16439
|
+
}
|
|
16511
16440
|
if (result === undefined) {
|
|
16512
16441
|
pvmInstance.runProgram();
|
|
16513
16442
|
status = pvmInstance.getStatus();
|
|
@@ -16806,14 +16735,14 @@ class DebuggerAdapter {
|
|
|
16806
16735
|
const page = this.pvm.getMemoryPage(pageNumber);
|
|
16807
16736
|
if (page === null) {
|
|
16808
16737
|
// page wasn't allocated so we return an empty page
|
|
16809
|
-
return
|
|
16738
|
+
return safeAllocUint8Array(PAGE_SIZE$1);
|
|
16810
16739
|
}
|
|
16811
16740
|
if (page.length === PAGE_SIZE$1) {
|
|
16812
16741
|
// page was allocated and has a proper size so we can simply return it
|
|
16813
16742
|
return page;
|
|
16814
16743
|
}
|
|
16815
16744
|
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
16816
|
-
const fullPage =
|
|
16745
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
|
|
16817
16746
|
fullPage.set(page);
|
|
16818
16747
|
return fullPage;
|
|
16819
16748
|
}
|
|
@@ -16908,8 +16837,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16908
16837
|
asOpaqueType: asOpaqueType,
|
|
16909
16838
|
assertEmpty: assertEmpty,
|
|
16910
16839
|
assertNever: assertNever,
|
|
16911
|
-
block: index$
|
|
16912
|
-
bytes: index$
|
|
16840
|
+
block: index$l,
|
|
16841
|
+
bytes: index$s,
|
|
16913
16842
|
check: check,
|
|
16914
16843
|
clampU64ToU32: clampU64ToU32,
|
|
16915
16844
|
createResults: createResults,
|
|
@@ -16917,13 +16846,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16917
16846
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
16918
16847
|
getServiceId: getServiceId,
|
|
16919
16848
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
16920
|
-
hash: index$
|
|
16849
|
+
hash: index$o,
|
|
16921
16850
|
inspect: inspect,
|
|
16922
16851
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
16923
16852
|
interpreter: index$7,
|
|
16924
16853
|
isBrowser: isBrowser,
|
|
16925
16854
|
measure: measure,
|
|
16926
|
-
numbers: index$
|
|
16855
|
+
numbers: index$r,
|
|
16927
16856
|
resultToString: resultToString,
|
|
16928
16857
|
seeThrough: seeThrough,
|
|
16929
16858
|
slotsToPreimageStatus: slotsToPreimageStatus,
|
|
@@ -16939,10 +16868,10 @@ const ENTROPY_BYTES = 32;
|
|
|
16939
16868
|
*
|
|
16940
16869
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
16941
16870
|
*/
|
|
16942
|
-
function fisherYatesShuffle(arr, entropy) {
|
|
16871
|
+
function fisherYatesShuffle(blake2b, arr, entropy) {
|
|
16943
16872
|
check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
16944
16873
|
const n = arr.length;
|
|
16945
|
-
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
16874
|
+
const randomNumbers = hashToNumberSequence(blake2b, entropy, arr.length);
|
|
16946
16875
|
const result = new Array(n);
|
|
16947
16876
|
let itemsLeft = n;
|
|
16948
16877
|
for (let i = 0; i < n; i++) {
|
|
@@ -16955,13 +16884,13 @@ function fisherYatesShuffle(arr, entropy) {
|
|
|
16955
16884
|
}
|
|
16956
16885
|
return result;
|
|
16957
16886
|
}
|
|
16958
|
-
function hashToNumberSequence(entropy, length) {
|
|
16887
|
+
function hashToNumberSequence(blake2b, entropy, length) {
|
|
16959
16888
|
const result = new Array(length);
|
|
16960
|
-
const randomBytes =
|
|
16889
|
+
const randomBytes = safeAllocUint8Array(ENTROPY_BYTES + 4);
|
|
16961
16890
|
randomBytes.set(entropy.raw);
|
|
16962
16891
|
for (let i = 0; i < length; i++) {
|
|
16963
16892
|
randomBytes.set(u32AsLeBytes(tryAsU32(Math.floor(i / 8))), ENTROPY_BYTES);
|
|
16964
|
-
const newHash = hashBytes(randomBytes);
|
|
16893
|
+
const newHash = blake2b.hashBytes(randomBytes);
|
|
16965
16894
|
const numberStartIndex = (4 * i) % 32;
|
|
16966
16895
|
const numberEndIndex = numberStartIndex + 4;
|
|
16967
16896
|
const number = leBytesAsU32(newHash.raw.subarray(numberStartIndex, numberEndIndex)) >>> 0;
|
|
@@ -16977,6 +16906,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
16977
16906
|
|
|
16978
16907
|
class JsonServiceInfo {
|
|
16979
16908
|
static fromJson = json.object({
|
|
16909
|
+
...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
|
|
16980
16910
|
code_hash: fromJson.bytes32(),
|
|
16981
16911
|
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
16982
16912
|
min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
@@ -17001,6 +16931,7 @@ class JsonServiceInfo {
|
|
|
17001
16931
|
parentService: parent_service,
|
|
17002
16932
|
});
|
|
17003
16933
|
});
|
|
16934
|
+
version;
|
|
17004
16935
|
code_hash;
|
|
17005
16936
|
balance;
|
|
17006
16937
|
min_item_gas;
|
|
@@ -17035,23 +16966,35 @@ const lookupMetaFromJson = json.object({
|
|
|
17035
16966
|
},
|
|
17036
16967
|
value: json.array("number"),
|
|
17037
16968
|
}, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
|
|
16969
|
+
const preimageStatusFromJson = json.object({
|
|
16970
|
+
hash: fromJson.bytes32(),
|
|
16971
|
+
status: json.array("number"),
|
|
16972
|
+
}, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
|
|
17038
16973
|
class JsonService {
|
|
17039
16974
|
static fromJson = json.object({
|
|
17040
16975
|
id: "number",
|
|
17041
|
-
data:
|
|
17042
|
-
|
|
17043
|
-
|
|
17044
|
-
|
|
17045
|
-
|
|
17046
|
-
|
|
16976
|
+
data: Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
16977
|
+
? {
|
|
16978
|
+
service: JsonServiceInfo.fromJson,
|
|
16979
|
+
preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
16980
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
16981
|
+
lookup_meta: json.optional(json.array(lookupMetaFromJson)),
|
|
16982
|
+
}
|
|
16983
|
+
: {
|
|
16984
|
+
service: JsonServiceInfo.fromJson,
|
|
16985
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
16986
|
+
preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
16987
|
+
preimages_status: json.optional(json.array(preimageStatusFromJson)),
|
|
16988
|
+
},
|
|
17047
16989
|
}, ({ id, data }) => {
|
|
16990
|
+
const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
|
|
17048
16991
|
const lookupHistory = HashDictionary.new();
|
|
17049
|
-
for (const item of data.lookup_meta ?? []) {
|
|
16992
|
+
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
17050
16993
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
17051
|
-
|
|
16994
|
+
const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
16995
|
+
data.push(new LookupHistoryItem(item.hash, length, item.slots));
|
|
17052
16996
|
lookupHistory.set(item.hash, data);
|
|
17053
16997
|
}
|
|
17054
|
-
const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
|
|
17055
16998
|
const storage = new Map();
|
|
17056
16999
|
const entries = (data.storage ?? []).map(({ key, value }) => {
|
|
17057
17000
|
const opaqueKey = asOpaqueType(key);
|
|
@@ -17075,8 +17018,7 @@ const availabilityAssignmentFromJson = json.object({
|
|
|
17075
17018
|
report: workReportFromJson,
|
|
17076
17019
|
timeout: "number",
|
|
17077
17020
|
}, ({ report, timeout }) => {
|
|
17078
|
-
|
|
17079
|
-
return AvailabilityAssignment.create({ workReport: new WithHash(workReportHash, report), timeout });
|
|
17021
|
+
return AvailabilityAssignment.create({ workReport: report, timeout });
|
|
17080
17022
|
});
|
|
17081
17023
|
|
|
17082
17024
|
const disputesRecordsFromJson = json.object({
|
|
@@ -17224,8 +17166,12 @@ class JsonServiceStatistics {
|
|
|
17224
17166
|
extrinsic_count: "number",
|
|
17225
17167
|
accumulate_count: "number",
|
|
17226
17168
|
accumulate_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17227
|
-
|
|
17228
|
-
|
|
17169
|
+
...(Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17170
|
+
? {
|
|
17171
|
+
on_transfers_count: "number",
|
|
17172
|
+
on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17173
|
+
}
|
|
17174
|
+
: {}),
|
|
17229
17175
|
}, ({ provided_count, provided_size, refinement_count, refinement_gas_used, imports, exports, extrinsic_size, extrinsic_count, accumulate_count, accumulate_gas_used, on_transfers_count, on_transfers_gas_used, }) => {
|
|
17230
17176
|
return ServiceStatistics.create({
|
|
17231
17177
|
providedCount: provided_count,
|
|
@@ -17238,8 +17184,8 @@ class JsonServiceStatistics {
|
|
|
17238
17184
|
extrinsicCount: extrinsic_count,
|
|
17239
17185
|
accumulateCount: accumulate_count,
|
|
17240
17186
|
accumulateGasUsed: accumulate_gas_used,
|
|
17241
|
-
onTransfersCount: on_transfers_count,
|
|
17242
|
-
onTransfersGasUsed: on_transfers_gas_used,
|
|
17187
|
+
onTransfersCount: on_transfers_count ?? tryAsU32(0),
|
|
17188
|
+
onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
|
|
17243
17189
|
});
|
|
17244
17190
|
});
|
|
17245
17191
|
provided_count;
|
|
@@ -17310,6 +17256,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17310
17256
|
chi_m: "number",
|
|
17311
17257
|
chi_a: json.array("number"),
|
|
17312
17258
|
chi_v: "number",
|
|
17259
|
+
chi_r: json.optional("number"),
|
|
17313
17260
|
chi_g: json.nullable(json.array({
|
|
17314
17261
|
service: "number",
|
|
17315
17262
|
gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
|
|
@@ -17321,6 +17268,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17321
17268
|
theta: json.nullable(json.array(accumulationOutput)),
|
|
17322
17269
|
accounts: json.array(JsonService.fromJson),
|
|
17323
17270
|
}, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
|
|
17271
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
17272
|
+
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
17273
|
+
}
|
|
17324
17274
|
return InMemoryState.create({
|
|
17325
17275
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17326
17276
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
@@ -17348,8 +17298,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17348
17298
|
timeslot: tau,
|
|
17349
17299
|
privilegedServices: PrivilegedServices.create({
|
|
17350
17300
|
manager: chi.chi_m,
|
|
17351
|
-
|
|
17352
|
-
|
|
17301
|
+
assigners: chi.chi_a,
|
|
17302
|
+
delegator: chi.chi_v,
|
|
17303
|
+
registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
|
|
17353
17304
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
17354
17305
|
}),
|
|
17355
17306
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|
|
@@ -17382,11 +17333,11 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17382
17333
|
class TransitionHasher {
|
|
17383
17334
|
context;
|
|
17384
17335
|
keccakHasher;
|
|
17385
|
-
|
|
17386
|
-
constructor(context, keccakHasher,
|
|
17336
|
+
blake2b;
|
|
17337
|
+
constructor(context, keccakHasher, blake2b) {
|
|
17387
17338
|
this.context = context;
|
|
17388
17339
|
this.keccakHasher = keccakHasher;
|
|
17389
|
-
this.
|
|
17340
|
+
this.blake2b = blake2b;
|
|
17390
17341
|
}
|
|
17391
17342
|
/** Concatenates two hashes and hash this concatenation */
|
|
17392
17343
|
hashConcat(a, b) {
|
|
@@ -17397,7 +17348,7 @@ class TransitionHasher {
|
|
|
17397
17348
|
}
|
|
17398
17349
|
/** Creates hash from the block header view */
|
|
17399
17350
|
header(header) {
|
|
17400
|
-
return new WithHash(hashBytes(header.encoded()
|
|
17351
|
+
return new WithHash(this.blake2b.hashBytes(header.encoded()).asOpaque(), header);
|
|
17401
17352
|
}
|
|
17402
17353
|
/**
|
|
17403
17354
|
* Merkle commitment of the extrinsic data
|
|
@@ -17410,7 +17361,7 @@ class TransitionHasher {
|
|
|
17410
17361
|
.view()
|
|
17411
17362
|
.map((g) => g.view())
|
|
17412
17363
|
.map((guarantee) => {
|
|
17413
|
-
const reportHash = hashBytes(guarantee.report.encoded()
|
|
17364
|
+
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17414
17365
|
return BytesBlob.blobFromParts([
|
|
17415
17366
|
reportHash.raw,
|
|
17416
17367
|
guarantee.slot.encoded().raw,
|
|
@@ -17418,13 +17369,13 @@ class TransitionHasher {
|
|
|
17418
17369
|
]);
|
|
17419
17370
|
});
|
|
17420
17371
|
const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
17421
|
-
const et = hashBytes(extrinsicView.tickets.encoded()
|
|
17422
|
-
const ep = hashBytes(extrinsicView.preimages.encoded()
|
|
17423
|
-
const eg = hashBytes(guaranteeBlob
|
|
17424
|
-
const ea = hashBytes(extrinsicView.assurances.encoded()
|
|
17425
|
-
const ed = hashBytes(extrinsicView.disputes.encoded()
|
|
17372
|
+
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17373
|
+
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17374
|
+
const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
|
|
17375
|
+
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17376
|
+
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17426
17377
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
17427
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17378
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
17428
17379
|
}
|
|
17429
17380
|
/** Creates hash for given WorkPackage */
|
|
17430
17381
|
workPackage(workPackage) {
|
|
@@ -17433,7 +17384,7 @@ class TransitionHasher {
|
|
|
17433
17384
|
encode(codec, data) {
|
|
17434
17385
|
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
17435
17386
|
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
17436
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17387
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
17437
17388
|
}
|
|
17438
17389
|
}
|
|
17439
17390
|
|
|
@@ -17446,8 +17397,10 @@ var PreimagesErrorCode;
|
|
|
17446
17397
|
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
17447
17398
|
class Preimages {
|
|
17448
17399
|
state;
|
|
17449
|
-
|
|
17400
|
+
blake2b;
|
|
17401
|
+
constructor(state, blake2b) {
|
|
17450
17402
|
this.state = state;
|
|
17403
|
+
this.blake2b = blake2b;
|
|
17451
17404
|
}
|
|
17452
17405
|
integrate(input) {
|
|
17453
17406
|
// make sure lookup extrinsics are sorted and unique
|
|
@@ -17470,7 +17423,7 @@ class Preimages {
|
|
|
17470
17423
|
// select preimages for integration
|
|
17471
17424
|
for (const preimage of preimages) {
|
|
17472
17425
|
const { requester, blob } = preimage;
|
|
17473
|
-
const hash = hashBytes(blob).asOpaque();
|
|
17426
|
+
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
17474
17427
|
const service = this.state.getService(requester);
|
|
17475
17428
|
if (service === null) {
|
|
17476
17429
|
return Result$1.error(PreimagesErrorCode.AccountNotFound);
|
|
@@ -17495,174 +17448,40 @@ class Preimages {
|
|
|
17495
17448
|
}
|
|
17496
17449
|
}
|
|
17497
17450
|
|
|
17498
|
-
class Missing {
|
|
17499
|
-
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
17500
|
-
gasCost = tryAsSmallGas(10);
|
|
17501
|
-
currentServiceId = CURRENT_SERVICE_ID;
|
|
17502
|
-
tracedRegisters = traceRegisters(7);
|
|
17503
|
-
execute(_gas, regs, _memory) {
|
|
17504
|
-
regs.set(7, HostCallResult.WHAT);
|
|
17505
|
-
return Promise.resolve(undefined);
|
|
17506
|
-
}
|
|
17507
|
-
}
|
|
17508
|
-
|
|
17509
|
-
var ServiceExecutorError;
|
|
17510
|
-
(function (ServiceExecutorError) {
|
|
17511
|
-
ServiceExecutorError[ServiceExecutorError["NoLookup"] = 0] = "NoLookup";
|
|
17512
|
-
ServiceExecutorError[ServiceExecutorError["NoState"] = 1] = "NoState";
|
|
17513
|
-
ServiceExecutorError[ServiceExecutorError["NoServiceCode"] = 2] = "NoServiceCode";
|
|
17514
|
-
ServiceExecutorError[ServiceExecutorError["ServiceCodeMismatch"] = 3] = "ServiceCodeMismatch";
|
|
17515
|
-
})(ServiceExecutorError || (ServiceExecutorError = {}));
|
|
17516
|
-
class WorkPackageExecutor {
|
|
17517
|
-
blocks;
|
|
17518
|
-
state;
|
|
17519
|
-
hasher;
|
|
17520
|
-
constructor(blocks, state, hasher) {
|
|
17521
|
-
this.blocks = blocks;
|
|
17522
|
-
this.state = state;
|
|
17523
|
-
this.hasher = hasher;
|
|
17524
|
-
}
|
|
17525
|
-
// TODO [ToDr] this while thing should be triple-checked with the GP.
|
|
17526
|
-
// I'm currently implementing some dirty version for the demo.
|
|
17527
|
-
async executeWorkPackage(pack) {
|
|
17528
|
-
const headerHash = pack.context.lookupAnchor;
|
|
17529
|
-
// execute authorisation first or is it already executed and we just need to check it?
|
|
17530
|
-
const authExec = this.getServiceExecutor(
|
|
17531
|
-
// TODO [ToDr] should this be anchor or lookupAnchor?
|
|
17532
|
-
headerHash, pack.authCodeHost, pack.authCodeHash);
|
|
17533
|
-
if (authExec.isError) {
|
|
17534
|
-
// TODO [ToDr] most likely shouldn't be throw.
|
|
17535
|
-
throw new Error(`Could not get authorization executor: ${authExec.error}`);
|
|
17536
|
-
}
|
|
17537
|
-
const pvm = authExec.ok;
|
|
17538
|
-
const authGas = tryAsGas(15000n);
|
|
17539
|
-
const result = await pvm.run(pack.parametrization, authGas);
|
|
17540
|
-
if (!result.isEqualTo(pack.authorization)) {
|
|
17541
|
-
throw new Error("Authorization is invalid.");
|
|
17542
|
-
}
|
|
17543
|
-
const results = [];
|
|
17544
|
-
for (const item of pack.items) {
|
|
17545
|
-
const exec = this.getServiceExecutor(headerHash, item.service, item.codeHash);
|
|
17546
|
-
if (exec.isError) {
|
|
17547
|
-
throw new Error(`Could not get item executor: ${exec.error}`);
|
|
17548
|
-
}
|
|
17549
|
-
const pvm = exec.ok;
|
|
17550
|
-
const gasRatio = tryAsServiceGas(3000n);
|
|
17551
|
-
const ret = await pvm.run(item.payload, tryAsGas(item.refineGasLimit)); // or accumulateGasLimit?
|
|
17552
|
-
results.push(WorkResult.create({
|
|
17553
|
-
serviceId: item.service,
|
|
17554
|
-
codeHash: item.codeHash,
|
|
17555
|
-
payloadHash: hashBytes(item.payload),
|
|
17556
|
-
gas: gasRatio,
|
|
17557
|
-
result: new WorkExecResult(WorkExecResultKind.ok, ret),
|
|
17558
|
-
load: WorkRefineLoad.create({
|
|
17559
|
-
gasUsed: tryAsServiceGas(5),
|
|
17560
|
-
importedSegments: tryAsU32(0),
|
|
17561
|
-
exportedSegments: tryAsU32(0),
|
|
17562
|
-
extrinsicSize: tryAsU32(0),
|
|
17563
|
-
extrinsicCount: tryAsU32(0),
|
|
17564
|
-
}),
|
|
17565
|
-
}));
|
|
17566
|
-
}
|
|
17567
|
-
const workPackage = this.hasher.workPackage(pack);
|
|
17568
|
-
const workPackageSpec = WorkPackageSpec.create({
|
|
17569
|
-
hash: workPackage.hash,
|
|
17570
|
-
length: tryAsU32(workPackage.encoded.length),
|
|
17571
|
-
erasureRoot: Bytes.zero(HASH_SIZE),
|
|
17572
|
-
exportsRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
17573
|
-
exportsCount: tryAsU16(0),
|
|
17574
|
-
});
|
|
17575
|
-
const coreIndex = tryAsCoreIndex(0);
|
|
17576
|
-
const authorizerHash = Bytes.fill(HASH_SIZE, 5).asOpaque();
|
|
17577
|
-
const workResults = FixedSizeArray.new(results, tryAsWorkItemsCount(results.length));
|
|
17578
|
-
return Promise.resolve(WorkReport.create({
|
|
17579
|
-
workPackageSpec,
|
|
17580
|
-
context: pack.context,
|
|
17581
|
-
coreIndex,
|
|
17582
|
-
authorizerHash,
|
|
17583
|
-
authorizationOutput: pack.authorization,
|
|
17584
|
-
segmentRootLookup: [],
|
|
17585
|
-
results: workResults,
|
|
17586
|
-
authorizationGasUsed: tryAsServiceGas(0),
|
|
17587
|
-
}));
|
|
17588
|
-
}
|
|
17589
|
-
getServiceExecutor(lookupAnchor, serviceId, expectedCodeHash) {
|
|
17590
|
-
const header = this.blocks.getHeader(lookupAnchor);
|
|
17591
|
-
if (header === null) {
|
|
17592
|
-
return Result$1.error(ServiceExecutorError.NoLookup);
|
|
17593
|
-
}
|
|
17594
|
-
const state = this.state.getState(lookupAnchor);
|
|
17595
|
-
if (state === null) {
|
|
17596
|
-
return Result$1.error(ServiceExecutorError.NoState);
|
|
17597
|
-
}
|
|
17598
|
-
const service = state.getService(serviceId);
|
|
17599
|
-
const serviceCodeHash = service?.getInfo().codeHash ?? null;
|
|
17600
|
-
if (serviceCodeHash === null) {
|
|
17601
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
17602
|
-
}
|
|
17603
|
-
if (!serviceCodeHash.isEqualTo(expectedCodeHash)) {
|
|
17604
|
-
return Result$1.error(ServiceExecutorError.ServiceCodeMismatch);
|
|
17605
|
-
}
|
|
17606
|
-
const serviceCode = service?.getPreimage(serviceCodeHash.asOpaque()) ?? null;
|
|
17607
|
-
if (serviceCode === null) {
|
|
17608
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
17609
|
-
}
|
|
17610
|
-
return Result$1.ok(new PvmExecutor(serviceCode));
|
|
17611
|
-
}
|
|
17612
|
-
}
|
|
17613
|
-
class PvmExecutor {
|
|
17614
|
-
serviceCode;
|
|
17615
|
-
pvm;
|
|
17616
|
-
hostCalls = new HostCallsManager({ missing: new Missing() });
|
|
17617
|
-
pvmInstanceManager = new InterpreterInstanceManager(4);
|
|
17618
|
-
constructor(serviceCode) {
|
|
17619
|
-
this.serviceCode = serviceCode;
|
|
17620
|
-
this.pvm = new HostCalls(this.pvmInstanceManager, this.hostCalls);
|
|
17621
|
-
}
|
|
17622
|
-
async run(args, gas) {
|
|
17623
|
-
const program = Program.fromSpi(this.serviceCode.raw, args.raw, true);
|
|
17624
|
-
const result = await this.pvm.runProgram(program.code, 5, gas, program.registers, program.memory);
|
|
17625
|
-
if (result.hasMemorySlice()) {
|
|
17626
|
-
return BytesBlob.blobFrom(result.memorySlice);
|
|
17627
|
-
}
|
|
17628
|
-
return BytesBlob.empty();
|
|
17629
|
-
}
|
|
17630
|
-
}
|
|
17631
|
-
|
|
17632
17451
|
var index = /*#__PURE__*/Object.freeze({
|
|
17633
17452
|
__proto__: null,
|
|
17634
17453
|
Preimages: Preimages,
|
|
17635
17454
|
get PreimagesErrorCode () { return PreimagesErrorCode; },
|
|
17636
|
-
TransitionHasher: TransitionHasher
|
|
17637
|
-
WorkPackageExecutor: WorkPackageExecutor
|
|
17455
|
+
TransitionHasher: TransitionHasher
|
|
17638
17456
|
});
|
|
17639
17457
|
|
|
17640
|
-
exports.block = index$
|
|
17641
|
-
exports.block_json = index$
|
|
17642
|
-
exports.bytes = index$
|
|
17643
|
-
exports.codec = index$
|
|
17644
|
-
exports.collections = index$
|
|
17645
|
-
exports.config = index$
|
|
17646
|
-
exports.config_node = index$
|
|
17647
|
-
exports.crypto = index$
|
|
17648
|
-
exports.database = index$
|
|
17649
|
-
exports.erasure_coding = index$
|
|
17650
|
-
exports.
|
|
17458
|
+
exports.block = index$l;
|
|
17459
|
+
exports.block_json = index$j;
|
|
17460
|
+
exports.bytes = index$s;
|
|
17461
|
+
exports.codec = index$q;
|
|
17462
|
+
exports.collections = index$n;
|
|
17463
|
+
exports.config = index$m;
|
|
17464
|
+
exports.config_node = index$h;
|
|
17465
|
+
exports.crypto = index$p;
|
|
17466
|
+
exports.database = index$d;
|
|
17467
|
+
exports.erasure_coding = index$c;
|
|
17468
|
+
exports.fuzz_proto = index$a;
|
|
17469
|
+
exports.hash = index$o;
|
|
17651
17470
|
exports.jam_host_calls = index$9;
|
|
17652
|
-
exports.json_parser = index$
|
|
17653
|
-
exports.logger = index$
|
|
17471
|
+
exports.json_parser = index$k;
|
|
17472
|
+
exports.logger = index$i;
|
|
17654
17473
|
exports.mmr = index$8;
|
|
17655
|
-
exports.numbers = index$
|
|
17656
|
-
exports.ordering = index$
|
|
17474
|
+
exports.numbers = index$r;
|
|
17475
|
+
exports.ordering = index$t;
|
|
17657
17476
|
exports.pvm = index$3;
|
|
17658
17477
|
exports.pvm_host_calls = index$6;
|
|
17659
17478
|
exports.pvm_interpreter = index$7;
|
|
17660
17479
|
exports.pvm_program = index$4;
|
|
17661
17480
|
exports.pvm_spi_decoder = index$5;
|
|
17662
17481
|
exports.shuffling = index$2;
|
|
17663
|
-
exports.state = index$
|
|
17482
|
+
exports.state = index$g;
|
|
17664
17483
|
exports.state_json = index$1;
|
|
17665
|
-
exports.state_merkleization = index$
|
|
17484
|
+
exports.state_merkleization = index$e;
|
|
17666
17485
|
exports.transition = index;
|
|
17667
|
-
exports.trie = index$
|
|
17668
|
-
exports.utils = index$
|
|
17486
|
+
exports.trie = index$f;
|
|
17487
|
+
exports.utils = index$u;
|