@typeberry/lib 0.1.3-ea24911 → 0.2.0-0a3dfd4
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 +1306 -1762
- package/index.d.ts +2058 -1714
- package/index.js +1305 -1761
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@ var GpVersion;
|
|
|
9
9
|
(function (GpVersion) {
|
|
10
10
|
GpVersion["V0_6_7"] = "0.6.7";
|
|
11
11
|
GpVersion["V0_7_0"] = "0.7.0";
|
|
12
|
-
GpVersion["V0_7_1"] = "0.7.1
|
|
12
|
+
GpVersion["V0_7_1"] = "0.7.1";
|
|
13
13
|
GpVersion["V0_7_2"] = "0.7.2-preview";
|
|
14
14
|
})(GpVersion || (GpVersion = {}));
|
|
15
15
|
var TestSuite;
|
|
@@ -18,11 +18,11 @@ var TestSuite;
|
|
|
18
18
|
TestSuite["JAMDUNA"] = "jamduna";
|
|
19
19
|
})(TestSuite || (TestSuite = {}));
|
|
20
20
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
21
|
-
const
|
|
21
|
+
const DEFAULT_VERSION = GpVersion.V0_7_1;
|
|
22
22
|
const env$1 = typeof process === "undefined" ? {} : process.env;
|
|
23
|
-
const DEFAULT_VERSION = GpVersion.V0_7_0;
|
|
24
23
|
let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
|
|
25
24
|
let CURRENT_SUITE = parseCurrentSuite(env$1.TEST_SUITE) ?? DEFAULT_SUITE;
|
|
25
|
+
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
|
|
26
26
|
function parseCurrentVersion(env) {
|
|
27
27
|
if (env === undefined) {
|
|
28
28
|
return undefined;
|
|
@@ -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:
|
|
@@ -303,7 +304,7 @@ function resultToString(res) {
|
|
|
303
304
|
if (res.isOk) {
|
|
304
305
|
return `OK: ${typeof res.ok === "symbol" ? res.ok.toString() : res.ok}`;
|
|
305
306
|
}
|
|
306
|
-
return `${res.details}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
307
|
+
return `${res.details()}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
307
308
|
}
|
|
308
309
|
/** An indication of two possible outcomes returned from a function. */
|
|
309
310
|
const Result$1 = {
|
|
@@ -317,7 +318,7 @@ const Result$1 = {
|
|
|
317
318
|
};
|
|
318
319
|
},
|
|
319
320
|
/** Create new [`Result`] with `Error` status. */
|
|
320
|
-
error: (error, details
|
|
321
|
+
error: (error, details) => {
|
|
321
322
|
check `${error !== undefined} 'Error' type cannot be undefined.`;
|
|
322
323
|
return {
|
|
323
324
|
isOk: false,
|
|
@@ -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
|
*/
|
|
@@ -417,7 +431,7 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
417
431
|
}
|
|
418
432
|
if (actual.isError && expected.isError) {
|
|
419
433
|
deepEqual(actual.error, expected.error, { context: ctx.concat(["error"]), errorsCollector: errors, ignore });
|
|
420
|
-
deepEqual(actual.details, expected.details, {
|
|
434
|
+
deepEqual(actual.details(), expected.details(), {
|
|
421
435
|
context: ctx.concat(["details"]),
|
|
422
436
|
errorsCollector: errors,
|
|
423
437
|
// display details when error does not match
|
|
@@ -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
|
};
|
|
@@ -572,6 +588,7 @@ var index$u = /*#__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$u = /*#__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;
|
|
@@ -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. */
|
|
@@ -2073,6 +2091,9 @@ class ObjectView {
|
|
|
2073
2091
|
toString() {
|
|
2074
2092
|
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2075
2093
|
}
|
|
2094
|
+
[TEST_COMPARE_USING]() {
|
|
2095
|
+
return this.materialize();
|
|
2096
|
+
}
|
|
2076
2097
|
}
|
|
2077
2098
|
/**
|
|
2078
2099
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2358,7 +2379,15 @@ var codec$1;
|
|
|
2358
2379
|
/** Custom encoding / decoding logic. */
|
|
2359
2380
|
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
2360
2381
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
2361
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
2382
|
+
codec.select = ({ name, sizeHint, }, chooser) => {
|
|
2383
|
+
const Self = chooser(null);
|
|
2384
|
+
return Descriptor.withView(name, sizeHint, (e, x) => chooser(e.getContext()).encode(e, x), (d) => chooser(d.getContext()).decode(d), (s) => chooser(s.decoder.getContext()).skip(s), hasUniqueView(Self)
|
|
2385
|
+
? codec.select({
|
|
2386
|
+
name: Self.View.name,
|
|
2387
|
+
sizeHint: Self.View.sizeHint,
|
|
2388
|
+
}, (ctx) => chooser(ctx).View)
|
|
2389
|
+
: Self.View);
|
|
2390
|
+
};
|
|
2362
2391
|
/**
|
|
2363
2392
|
* A descriptor for a more complex POJO.
|
|
2364
2393
|
*
|
|
@@ -3592,7 +3621,7 @@ async function verify(input) {
|
|
|
3592
3621
|
return Promise.resolve([]);
|
|
3593
3622
|
}
|
|
3594
3623
|
const dataLength = input.reduce((acc, { message, key, signature }) => acc + key.length + signature.length + message.length + 1, 0);
|
|
3595
|
-
const data =
|
|
3624
|
+
const data = safeAllocUint8Array(dataLength);
|
|
3596
3625
|
let offset = 0;
|
|
3597
3626
|
for (const { key, message, signature } of input) {
|
|
3598
3627
|
data.set(key.raw, offset);
|
|
@@ -3639,823 +3668,75 @@ var ed25519 = /*#__PURE__*/Object.freeze({
|
|
|
3639
3668
|
verifyBatch: verifyBatch
|
|
3640
3669
|
});
|
|
3641
3670
|
|
|
3671
|
+
const SEED_SIZE = 32;
|
|
3672
|
+
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
3673
|
+
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
3642
3674
|
/**
|
|
3643
|
-
*
|
|
3644
|
-
*
|
|
3645
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
3675
|
+
* JIP-5: Secret key derivation
|
|
3646
3676
|
*
|
|
3647
|
-
*/
|
|
3648
|
-
const HASH_SIZE = 32;
|
|
3649
|
-
/** A hash without last byte (useful for trie representation). */
|
|
3650
|
-
const TRUNCATED_HASH_SIZE = 31;
|
|
3651
|
-
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
3677
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
3652
3678
|
/**
|
|
3653
|
-
*
|
|
3654
|
-
*
|
|
3655
|
-
* After calculating the hash these two should be passed together to avoid
|
|
3656
|
-
* unnecessary re-hashing of the data.
|
|
3679
|
+
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
3680
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
3657
3681
|
*/
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
constructor(hash, data) {
|
|
3662
|
-
super();
|
|
3663
|
-
this.hash = hash;
|
|
3664
|
-
this.data = data;
|
|
3665
|
-
}
|
|
3682
|
+
function trivialSeed(s) {
|
|
3683
|
+
const s_le = u32AsLeBytes(s);
|
|
3684
|
+
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();
|
|
3666
3685
|
}
|
|
3667
3686
|
/**
|
|
3668
|
-
*
|
|
3687
|
+
* Derives a Ed25519 secret key from a seed.
|
|
3688
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
3669
3689
|
*/
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
constructor(hash, data, encoded) {
|
|
3673
|
-
super(hash, data);
|
|
3674
|
-
this.encoded = encoded;
|
|
3675
|
-
}
|
|
3676
|
-
}
|
|
3677
|
-
|
|
3678
|
-
/** The simplest allocator returning just a fresh copy of bytes each time. */
|
|
3679
|
-
class SimpleAllocator {
|
|
3680
|
-
emptyHash() {
|
|
3681
|
-
return Bytes.zero(HASH_SIZE);
|
|
3682
|
-
}
|
|
3683
|
-
}
|
|
3684
|
-
/** An allocator that works by allocating larger (continuous) pages of memory. */
|
|
3685
|
-
class PageAllocator {
|
|
3686
|
-
hashesPerPage;
|
|
3687
|
-
page = new Uint8Array(0);
|
|
3688
|
-
currentHash = 0;
|
|
3689
|
-
// TODO [ToDr] Benchmark the performance!
|
|
3690
|
-
constructor(hashesPerPage) {
|
|
3691
|
-
this.hashesPerPage = hashesPerPage;
|
|
3692
|
-
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
3693
|
-
this.resetPage();
|
|
3694
|
-
}
|
|
3695
|
-
resetPage() {
|
|
3696
|
-
const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
|
|
3697
|
-
this.currentHash = 0;
|
|
3698
|
-
this.page = new Uint8Array(pageSizeBytes);
|
|
3699
|
-
}
|
|
3700
|
-
emptyHash() {
|
|
3701
|
-
const startIdx = this.currentHash * HASH_SIZE;
|
|
3702
|
-
const endIdx = startIdx + HASH_SIZE;
|
|
3703
|
-
this.currentHash += 1;
|
|
3704
|
-
if (this.currentHash >= this.hashesPerPage) {
|
|
3705
|
-
this.resetPage();
|
|
3706
|
-
}
|
|
3707
|
-
return Bytes.fromBlob(this.page.subarray(startIdx, endIdx), HASH_SIZE);
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3710
|
-
const defaultAllocator = new SimpleAllocator();
|
|
3711
|
-
|
|
3712
|
-
function getDefaultExportFromCjs (x) {
|
|
3713
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3714
|
-
}
|
|
3715
|
-
|
|
3716
|
-
var blake2b$3 = {exports: {}};
|
|
3717
|
-
|
|
3718
|
-
var nanoassert;
|
|
3719
|
-
var hasRequiredNanoassert;
|
|
3720
|
-
|
|
3721
|
-
function requireNanoassert () {
|
|
3722
|
-
if (hasRequiredNanoassert) return nanoassert;
|
|
3723
|
-
hasRequiredNanoassert = 1;
|
|
3724
|
-
nanoassert = assert;
|
|
3725
|
-
|
|
3726
|
-
class AssertionError extends Error {}
|
|
3727
|
-
AssertionError.prototype.name = 'AssertionError';
|
|
3728
|
-
|
|
3729
|
-
/**
|
|
3730
|
-
* Minimal assert function
|
|
3731
|
-
* @param {any} t Value to check if falsy
|
|
3732
|
-
* @param {string=} m Optional assertion error message
|
|
3733
|
-
* @throws {AssertionError}
|
|
3734
|
-
*/
|
|
3735
|
-
function assert (t, m) {
|
|
3736
|
-
if (!t) {
|
|
3737
|
-
var err = new AssertionError(m);
|
|
3738
|
-
if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
|
|
3739
|
-
throw err
|
|
3740
|
-
}
|
|
3741
|
-
}
|
|
3742
|
-
return nanoassert;
|
|
3743
|
-
}
|
|
3744
|
-
|
|
3745
|
-
var blake2bWasm = {exports: {}};
|
|
3746
|
-
|
|
3747
|
-
var b4a;
|
|
3748
|
-
var hasRequiredB4a;
|
|
3749
|
-
|
|
3750
|
-
function requireB4a () {
|
|
3751
|
-
if (hasRequiredB4a) return b4a;
|
|
3752
|
-
hasRequiredB4a = 1;
|
|
3753
|
-
function isBuffer (value) {
|
|
3754
|
-
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
3755
|
-
}
|
|
3756
|
-
|
|
3757
|
-
function isEncoding (encoding) {
|
|
3758
|
-
return Buffer.isEncoding(encoding)
|
|
3759
|
-
}
|
|
3760
|
-
|
|
3761
|
-
function alloc (size, fill, encoding) {
|
|
3762
|
-
return Buffer.alloc(size, fill, encoding)
|
|
3763
|
-
}
|
|
3764
|
-
|
|
3765
|
-
function allocUnsafe (size) {
|
|
3766
|
-
return Buffer.allocUnsafe(size)
|
|
3767
|
-
}
|
|
3768
|
-
|
|
3769
|
-
function allocUnsafeSlow (size) {
|
|
3770
|
-
return Buffer.allocUnsafeSlow(size)
|
|
3771
|
-
}
|
|
3772
|
-
|
|
3773
|
-
function byteLength (string, encoding) {
|
|
3774
|
-
return Buffer.byteLength(string, encoding)
|
|
3775
|
-
}
|
|
3776
|
-
|
|
3777
|
-
function compare (a, b) {
|
|
3778
|
-
return Buffer.compare(a, b)
|
|
3779
|
-
}
|
|
3780
|
-
|
|
3781
|
-
function concat (buffers, totalLength) {
|
|
3782
|
-
return Buffer.concat(buffers, totalLength)
|
|
3783
|
-
}
|
|
3784
|
-
|
|
3785
|
-
function copy (source, target, targetStart, start, end) {
|
|
3786
|
-
return toBuffer(source).copy(target, targetStart, start, end)
|
|
3787
|
-
}
|
|
3788
|
-
|
|
3789
|
-
function equals (a, b) {
|
|
3790
|
-
return toBuffer(a).equals(b)
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
function fill (buffer, value, offset, end, encoding) {
|
|
3794
|
-
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
3795
|
-
}
|
|
3796
|
-
|
|
3797
|
-
function from (value, encodingOrOffset, length) {
|
|
3798
|
-
return Buffer.from(value, encodingOrOffset, length)
|
|
3799
|
-
}
|
|
3800
|
-
|
|
3801
|
-
function includes (buffer, value, byteOffset, encoding) {
|
|
3802
|
-
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
3803
|
-
}
|
|
3804
|
-
|
|
3805
|
-
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
3806
|
-
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
3807
|
-
}
|
|
3808
|
-
|
|
3809
|
-
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
3810
|
-
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
3811
|
-
}
|
|
3812
|
-
|
|
3813
|
-
function swap16 (buffer) {
|
|
3814
|
-
return toBuffer(buffer).swap16()
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
function swap32 (buffer) {
|
|
3818
|
-
return toBuffer(buffer).swap32()
|
|
3819
|
-
}
|
|
3820
|
-
|
|
3821
|
-
function swap64 (buffer) {
|
|
3822
|
-
return toBuffer(buffer).swap64()
|
|
3823
|
-
}
|
|
3824
|
-
|
|
3825
|
-
function toBuffer (buffer) {
|
|
3826
|
-
if (Buffer.isBuffer(buffer)) return buffer
|
|
3827
|
-
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
3828
|
-
}
|
|
3829
|
-
|
|
3830
|
-
function toString (buffer, encoding, start, end) {
|
|
3831
|
-
return toBuffer(buffer).toString(encoding, start, end)
|
|
3832
|
-
}
|
|
3833
|
-
|
|
3834
|
-
function write (buffer, string, offset, length, encoding) {
|
|
3835
|
-
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
3836
|
-
}
|
|
3837
|
-
|
|
3838
|
-
function writeDoubleLE (buffer, value, offset) {
|
|
3839
|
-
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
3840
|
-
}
|
|
3841
|
-
|
|
3842
|
-
function writeFloatLE (buffer, value, offset) {
|
|
3843
|
-
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
3844
|
-
}
|
|
3845
|
-
|
|
3846
|
-
function writeUInt32LE (buffer, value, offset) {
|
|
3847
|
-
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
3848
|
-
}
|
|
3849
|
-
|
|
3850
|
-
function writeInt32LE (buffer, value, offset) {
|
|
3851
|
-
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
3852
|
-
}
|
|
3853
|
-
|
|
3854
|
-
function readDoubleLE (buffer, offset) {
|
|
3855
|
-
return toBuffer(buffer).readDoubleLE(offset)
|
|
3856
|
-
}
|
|
3857
|
-
|
|
3858
|
-
function readFloatLE (buffer, offset) {
|
|
3859
|
-
return toBuffer(buffer).readFloatLE(offset)
|
|
3860
|
-
}
|
|
3861
|
-
|
|
3862
|
-
function readUInt32LE (buffer, offset) {
|
|
3863
|
-
return toBuffer(buffer).readUInt32LE(offset)
|
|
3864
|
-
}
|
|
3865
|
-
|
|
3866
|
-
function readInt32LE (buffer, offset) {
|
|
3867
|
-
return toBuffer(buffer).readInt32LE(offset)
|
|
3868
|
-
}
|
|
3869
|
-
|
|
3870
|
-
b4a = {
|
|
3871
|
-
isBuffer,
|
|
3872
|
-
isEncoding,
|
|
3873
|
-
alloc,
|
|
3874
|
-
allocUnsafe,
|
|
3875
|
-
allocUnsafeSlow,
|
|
3876
|
-
byteLength,
|
|
3877
|
-
compare,
|
|
3878
|
-
concat,
|
|
3879
|
-
copy,
|
|
3880
|
-
equals,
|
|
3881
|
-
fill,
|
|
3882
|
-
from,
|
|
3883
|
-
includes,
|
|
3884
|
-
indexOf,
|
|
3885
|
-
lastIndexOf,
|
|
3886
|
-
swap16,
|
|
3887
|
-
swap32,
|
|
3888
|
-
swap64,
|
|
3889
|
-
toBuffer,
|
|
3890
|
-
toString,
|
|
3891
|
-
write,
|
|
3892
|
-
writeDoubleLE,
|
|
3893
|
-
writeFloatLE,
|
|
3894
|
-
writeUInt32LE,
|
|
3895
|
-
writeInt32LE,
|
|
3896
|
-
readDoubleLE,
|
|
3897
|
-
readFloatLE,
|
|
3898
|
-
readUInt32LE,
|
|
3899
|
-
readInt32LE
|
|
3900
|
-
};
|
|
3901
|
-
return b4a;
|
|
3902
|
-
}
|
|
3903
|
-
|
|
3904
|
-
var blake2b$2;
|
|
3905
|
-
var hasRequiredBlake2b$1;
|
|
3906
|
-
|
|
3907
|
-
function requireBlake2b$1 () {
|
|
3908
|
-
if (hasRequiredBlake2b$1) return blake2b$2;
|
|
3909
|
-
hasRequiredBlake2b$1 = 1;
|
|
3910
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3911
|
-
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3912
|
-
};
|
|
3913
|
-
var __toBinary = /* @__PURE__ */ (() => {
|
|
3914
|
-
var table = new Uint8Array(128);
|
|
3915
|
-
for (var i = 0; i < 64; i++)
|
|
3916
|
-
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
3917
|
-
return (base64) => {
|
|
3918
|
-
var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
3919
|
-
for (var i2 = 0, j = 0; i2 < n; ) {
|
|
3920
|
-
var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
3921
|
-
var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
3922
|
-
bytes2[j++] = c0 << 2 | c1 >> 4;
|
|
3923
|
-
bytes2[j++] = c1 << 4 | c2 >> 2;
|
|
3924
|
-
bytes2[j++] = c2 << 6 | c3;
|
|
3925
|
-
}
|
|
3926
|
-
return bytes2;
|
|
3927
|
-
};
|
|
3928
|
-
})();
|
|
3929
|
-
|
|
3930
|
-
// wasm-binary:./blake2b.wat
|
|
3931
|
-
var require_blake2b = __commonJS({
|
|
3932
|
-
"wasm-binary:./blake2b.wat"(exports2, module2) {
|
|
3933
|
-
module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYC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JIA18IQkgBSAJhUI/iiEFIAIgBiAVfHwhAiAOIAKFQiCKIQ4gCiAOfCEKIAYgCoVCGIohBiACIAYgGXx8IQIgDiAChUIQiiEOIAogDnwhCiAGIAqFQj+KIQYgAyAHIBp8fCEDIA8gA4VCIIohDyALIA98IQsgByALhUIYiiEHIAMgByAgfHwhAyAPIAOFQhCKIQ8gCyAPfCELIAcgC4VCP4ohByAEIAggHnx8IQQgECAEhUIgiiEQIAwgEHwhDCAIIAyFQhiKIQggBCAIIBd8fCEEIBAgBIVCEIohECAMIBB8IQwgCCAMhUI/iiEIIAEgBiASfHwhASAQIAGFQiCKIRAgCyAQfCELIAYgC4VCGIohBiABIAYgHXx8IQEgECABhUIQiiEQIAsgEHwhCyAGIAuFQj+KIQYgAiAHIBF8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByATfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggHHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
|
|
3934
|
-
}
|
|
3935
|
-
});
|
|
3936
|
-
|
|
3937
|
-
// wasm-module:./blake2b.wat
|
|
3938
|
-
var bytes = require_blake2b();
|
|
3939
|
-
var compiled = WebAssembly.compile(bytes);
|
|
3940
|
-
blake2b$2 = async (imports) => {
|
|
3941
|
-
const instance = await WebAssembly.instantiate(await compiled, imports);
|
|
3942
|
-
return instance.exports;
|
|
3943
|
-
};
|
|
3944
|
-
return blake2b$2;
|
|
3945
|
-
}
|
|
3946
|
-
|
|
3947
|
-
var hasRequiredBlake2bWasm;
|
|
3948
|
-
|
|
3949
|
-
function requireBlake2bWasm () {
|
|
3950
|
-
if (hasRequiredBlake2bWasm) return blake2bWasm.exports;
|
|
3951
|
-
hasRequiredBlake2bWasm = 1;
|
|
3952
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
3953
|
-
var b4a = /*@__PURE__*/ requireB4a();
|
|
3954
|
-
|
|
3955
|
-
var wasm = null;
|
|
3956
|
-
var wasmPromise = typeof WebAssembly !== "undefined" && /*@__PURE__*/ requireBlake2b$1()().then(mod => {
|
|
3957
|
-
wasm = mod;
|
|
3958
|
-
});
|
|
3959
|
-
|
|
3960
|
-
var head = 64;
|
|
3961
|
-
var freeList = [];
|
|
3962
|
-
|
|
3963
|
-
blake2bWasm.exports = Blake2b;
|
|
3964
|
-
var BYTES_MIN = blake2bWasm.exports.BYTES_MIN = 16;
|
|
3965
|
-
var BYTES_MAX = blake2bWasm.exports.BYTES_MAX = 64;
|
|
3966
|
-
blake2bWasm.exports.BYTES = 32;
|
|
3967
|
-
var KEYBYTES_MIN = blake2bWasm.exports.KEYBYTES_MIN = 16;
|
|
3968
|
-
var KEYBYTES_MAX = blake2bWasm.exports.KEYBYTES_MAX = 64;
|
|
3969
|
-
blake2bWasm.exports.KEYBYTES = 32;
|
|
3970
|
-
var SALTBYTES = blake2bWasm.exports.SALTBYTES = 16;
|
|
3971
|
-
var PERSONALBYTES = blake2bWasm.exports.PERSONALBYTES = 16;
|
|
3972
|
-
|
|
3973
|
-
function Blake2b (digestLength, key, salt, personal, noAssert) {
|
|
3974
|
-
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
|
|
3975
|
-
if (!wasm) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
|
|
3976
|
-
if (!digestLength) digestLength = 32;
|
|
3977
|
-
|
|
3978
|
-
if (noAssert !== true) {
|
|
3979
|
-
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength);
|
|
3980
|
-
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength);
|
|
3981
|
-
if (key != null) {
|
|
3982
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
3983
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
3984
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at least ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
3985
|
-
}
|
|
3986
|
-
if (salt != null) {
|
|
3987
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
3988
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
3989
|
-
}
|
|
3990
|
-
if (personal != null) {
|
|
3991
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
3992
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
3993
|
-
}
|
|
3994
|
-
}
|
|
3995
|
-
|
|
3996
|
-
if (!freeList.length) {
|
|
3997
|
-
freeList.push(head);
|
|
3998
|
-
head += 216;
|
|
3999
|
-
}
|
|
4000
|
-
|
|
4001
|
-
this.digestLength = digestLength;
|
|
4002
|
-
this.finalized = false;
|
|
4003
|
-
this.pointer = freeList.pop();
|
|
4004
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4005
|
-
|
|
4006
|
-
this._memory.fill(0, 0, 64);
|
|
4007
|
-
this._memory[0] = this.digestLength;
|
|
4008
|
-
this._memory[1] = key ? key.length : 0;
|
|
4009
|
-
this._memory[2] = 1; // fanout
|
|
4010
|
-
this._memory[3] = 1; // depth
|
|
4011
|
-
|
|
4012
|
-
if (salt) this._memory.set(salt, 32);
|
|
4013
|
-
if (personal) this._memory.set(personal, 48);
|
|
4014
|
-
|
|
4015
|
-
if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216); // we need 216 bytes for the state
|
|
4016
|
-
wasm.blake2b_init(this.pointer, this.digestLength);
|
|
4017
|
-
|
|
4018
|
-
if (key) {
|
|
4019
|
-
this.update(key);
|
|
4020
|
-
this._memory.fill(0, head, head + key.length); // whiteout key
|
|
4021
|
-
this._memory[this.pointer + 200] = 128;
|
|
4022
|
-
}
|
|
4023
|
-
}
|
|
4024
|
-
|
|
4025
|
-
Blake2b.prototype._realloc = function (size) {
|
|
4026
|
-
wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
|
|
4027
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4028
|
-
};
|
|
4029
|
-
|
|
4030
|
-
Blake2b.prototype.update = function (input) {
|
|
4031
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4032
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4033
|
-
|
|
4034
|
-
if (head + input.length > this._memory.length) this._realloc(head + input.length);
|
|
4035
|
-
this._memory.set(input, head);
|
|
4036
|
-
wasm.blake2b_update(this.pointer, head, head + input.length);
|
|
4037
|
-
return this
|
|
4038
|
-
};
|
|
4039
|
-
|
|
4040
|
-
Blake2b.prototype.digest = function (enc) {
|
|
4041
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4042
|
-
this.finalized = true;
|
|
4043
|
-
|
|
4044
|
-
freeList.push(this.pointer);
|
|
4045
|
-
wasm.blake2b_final(this.pointer);
|
|
4046
|
-
|
|
4047
|
-
if (!enc || enc === 'binary') {
|
|
4048
|
-
return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4049
|
-
}
|
|
4050
|
-
|
|
4051
|
-
if (typeof enc === 'string') {
|
|
4052
|
-
return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4053
|
-
}
|
|
4054
|
-
|
|
4055
|
-
assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
|
|
4056
|
-
for (var i = 0; i < this.digestLength; i++) {
|
|
4057
|
-
enc[i] = this._memory[this.pointer + 128 + i];
|
|
4058
|
-
}
|
|
4059
|
-
|
|
4060
|
-
return enc
|
|
4061
|
-
};
|
|
4062
|
-
|
|
4063
|
-
// libsodium compat
|
|
4064
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4065
|
-
|
|
4066
|
-
Blake2b.WASM = wasm;
|
|
4067
|
-
Blake2b.SUPPORTED = typeof WebAssembly !== 'undefined';
|
|
4068
|
-
|
|
4069
|
-
Blake2b.ready = function (cb) {
|
|
4070
|
-
if (!cb) cb = noop;
|
|
4071
|
-
if (!wasmPromise) return cb(new Error('WebAssembly not supported'))
|
|
4072
|
-
return wasmPromise.then(() => cb(), cb)
|
|
4073
|
-
};
|
|
4074
|
-
|
|
4075
|
-
Blake2b.prototype.ready = Blake2b.ready;
|
|
4076
|
-
|
|
4077
|
-
Blake2b.prototype.getPartialHash = function () {
|
|
4078
|
-
return this._memory.slice(this.pointer, this.pointer + 216);
|
|
4079
|
-
};
|
|
4080
|
-
|
|
4081
|
-
Blake2b.prototype.setPartialHash = function (ph) {
|
|
4082
|
-
this._memory.set(ph, this.pointer);
|
|
4083
|
-
};
|
|
4084
|
-
|
|
4085
|
-
function noop () {}
|
|
4086
|
-
return blake2bWasm.exports;
|
|
4087
|
-
}
|
|
4088
|
-
|
|
4089
|
-
var hasRequiredBlake2b;
|
|
4090
|
-
|
|
4091
|
-
function requireBlake2b () {
|
|
4092
|
-
if (hasRequiredBlake2b) return blake2b$3.exports;
|
|
4093
|
-
hasRequiredBlake2b = 1;
|
|
4094
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
4095
|
-
var b2wasm = /*@__PURE__*/ requireBlake2bWasm();
|
|
4096
|
-
|
|
4097
|
-
// 64-bit unsigned addition
|
|
4098
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
4099
|
-
// v should be a Uint32Array
|
|
4100
|
-
function ADD64AA (v, a, b) {
|
|
4101
|
-
var o0 = v[a] + v[b];
|
|
4102
|
-
var o1 = v[a + 1] + v[b + 1];
|
|
4103
|
-
if (o0 >= 0x100000000) {
|
|
4104
|
-
o1++;
|
|
4105
|
-
}
|
|
4106
|
-
v[a] = o0;
|
|
4107
|
-
v[a + 1] = o1;
|
|
4108
|
-
}
|
|
4109
|
-
|
|
4110
|
-
// 64-bit unsigned addition
|
|
4111
|
-
// Sets v[a,a+1] += b
|
|
4112
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
4113
|
-
function ADD64AC (v, a, b0, b1) {
|
|
4114
|
-
var o0 = v[a] + b0;
|
|
4115
|
-
if (b0 < 0) {
|
|
4116
|
-
o0 += 0x100000000;
|
|
4117
|
-
}
|
|
4118
|
-
var o1 = v[a + 1] + b1;
|
|
4119
|
-
if (o0 >= 0x100000000) {
|
|
4120
|
-
o1++;
|
|
4121
|
-
}
|
|
4122
|
-
v[a] = o0;
|
|
4123
|
-
v[a + 1] = o1;
|
|
4124
|
-
}
|
|
4125
|
-
|
|
4126
|
-
// Little-endian byte access
|
|
4127
|
-
function B2B_GET32 (arr, i) {
|
|
4128
|
-
return (arr[i] ^
|
|
4129
|
-
(arr[i + 1] << 8) ^
|
|
4130
|
-
(arr[i + 2] << 16) ^
|
|
4131
|
-
(arr[i + 3] << 24))
|
|
4132
|
-
}
|
|
4133
|
-
|
|
4134
|
-
// G Mixing function
|
|
4135
|
-
// The ROTRs are inlined for speed
|
|
4136
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
4137
|
-
var x0 = m[ix];
|
|
4138
|
-
var x1 = m[ix + 1];
|
|
4139
|
-
var y0 = m[iy];
|
|
4140
|
-
var y1 = m[iy + 1];
|
|
4141
|
-
|
|
4142
|
-
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
4143
|
-
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
4144
|
-
|
|
4145
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
4146
|
-
var xor0 = v[d] ^ v[a];
|
|
4147
|
-
var xor1 = v[d + 1] ^ v[a + 1];
|
|
4148
|
-
v[d] = xor1;
|
|
4149
|
-
v[d + 1] = xor0;
|
|
4150
|
-
|
|
4151
|
-
ADD64AA(v, c, d);
|
|
4152
|
-
|
|
4153
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
4154
|
-
xor0 = v[b] ^ v[c];
|
|
4155
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4156
|
-
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
4157
|
-
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
4158
|
-
|
|
4159
|
-
ADD64AA(v, a, b);
|
|
4160
|
-
ADD64AC(v, a, y0, y1);
|
|
4161
|
-
|
|
4162
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
4163
|
-
xor0 = v[d] ^ v[a];
|
|
4164
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
4165
|
-
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
4166
|
-
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
4167
|
-
|
|
4168
|
-
ADD64AA(v, c, d);
|
|
4169
|
-
|
|
4170
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
4171
|
-
xor0 = v[b] ^ v[c];
|
|
4172
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4173
|
-
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
4174
|
-
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
4175
|
-
}
|
|
4176
|
-
|
|
4177
|
-
// Initialization Vector
|
|
4178
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
4179
|
-
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
4180
|
-
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
4181
|
-
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
4182
|
-
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
4183
|
-
]);
|
|
4184
|
-
|
|
4185
|
-
var SIGMA8 = [
|
|
4186
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4187
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
4188
|
-
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
4189
|
-
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
4190
|
-
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
4191
|
-
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
4192
|
-
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
4193
|
-
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
4194
|
-
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
4195
|
-
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
4196
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4197
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
4198
|
-
];
|
|
4199
|
-
|
|
4200
|
-
// These are offsets into a uint64 buffer.
|
|
4201
|
-
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
4202
|
-
// because this is Javascript and we don't have uint64s
|
|
4203
|
-
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }));
|
|
4204
|
-
|
|
4205
|
-
// Compression function. 'last' flag indicates last block.
|
|
4206
|
-
// Note we're representing 16 uint64s as 32 uint32s
|
|
4207
|
-
var v = new Uint32Array(32);
|
|
4208
|
-
var m = new Uint32Array(32);
|
|
4209
|
-
function blake2bCompress (ctx, last) {
|
|
4210
|
-
var i = 0;
|
|
4211
|
-
|
|
4212
|
-
// init work variables
|
|
4213
|
-
for (i = 0; i < 16; i++) {
|
|
4214
|
-
v[i] = ctx.h[i];
|
|
4215
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
4216
|
-
}
|
|
4217
|
-
|
|
4218
|
-
// low 64 bits of offset
|
|
4219
|
-
v[24] = v[24] ^ ctx.t;
|
|
4220
|
-
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
4221
|
-
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
4222
|
-
|
|
4223
|
-
// last block flag set ?
|
|
4224
|
-
if (last) {
|
|
4225
|
-
v[28] = ~v[28];
|
|
4226
|
-
v[29] = ~v[29];
|
|
4227
|
-
}
|
|
4228
|
-
|
|
4229
|
-
// get little-endian words
|
|
4230
|
-
for (i = 0; i < 32; i++) {
|
|
4231
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
4232
|
-
}
|
|
4233
|
-
|
|
4234
|
-
// twelve rounds of mixing
|
|
4235
|
-
for (i = 0; i < 12; i++) {
|
|
4236
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
4237
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
4238
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
4239
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
4240
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
4241
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
4242
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
4243
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
4244
|
-
}
|
|
4245
|
-
|
|
4246
|
-
for (i = 0; i < 16; i++) {
|
|
4247
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
4248
|
-
}
|
|
4249
|
-
}
|
|
4250
|
-
|
|
4251
|
-
// reusable parameter_block
|
|
4252
|
-
var parameter_block = new Uint8Array([
|
|
4253
|
-
0, 0, 0, 0, // 0: outlen, keylen, fanout, depth
|
|
4254
|
-
0, 0, 0, 0, // 4: leaf length, sequential mode
|
|
4255
|
-
0, 0, 0, 0, // 8: node offset
|
|
4256
|
-
0, 0, 0, 0, // 12: node offset
|
|
4257
|
-
0, 0, 0, 0, // 16: node depth, inner length, rfu
|
|
4258
|
-
0, 0, 0, 0, // 20: rfu
|
|
4259
|
-
0, 0, 0, 0, // 24: rfu
|
|
4260
|
-
0, 0, 0, 0, // 28: rfu
|
|
4261
|
-
0, 0, 0, 0, // 32: salt
|
|
4262
|
-
0, 0, 0, 0, // 36: salt
|
|
4263
|
-
0, 0, 0, 0, // 40: salt
|
|
4264
|
-
0, 0, 0, 0, // 44: salt
|
|
4265
|
-
0, 0, 0, 0, // 48: personal
|
|
4266
|
-
0, 0, 0, 0, // 52: personal
|
|
4267
|
-
0, 0, 0, 0, // 56: personal
|
|
4268
|
-
0, 0, 0, 0 // 60: personal
|
|
4269
|
-
]);
|
|
4270
|
-
|
|
4271
|
-
// Creates a BLAKE2b hashing context
|
|
4272
|
-
// Requires an output length between 1 and 64 bytes
|
|
4273
|
-
// Takes an optional Uint8Array key
|
|
4274
|
-
function Blake2b (outlen, key, salt, personal) {
|
|
4275
|
-
// zero out parameter_block before usage
|
|
4276
|
-
parameter_block.fill(0);
|
|
4277
|
-
// state, 'param block'
|
|
4278
|
-
|
|
4279
|
-
this.b = new Uint8Array(128);
|
|
4280
|
-
this.h = new Uint32Array(16);
|
|
4281
|
-
this.t = 0; // input count
|
|
4282
|
-
this.c = 0; // pointer within buffer
|
|
4283
|
-
this.outlen = outlen; // output length in bytes
|
|
4284
|
-
|
|
4285
|
-
parameter_block[0] = outlen;
|
|
4286
|
-
if (key) parameter_block[1] = key.length;
|
|
4287
|
-
parameter_block[2] = 1; // fanout
|
|
4288
|
-
parameter_block[3] = 1; // depth
|
|
4289
|
-
|
|
4290
|
-
if (salt) parameter_block.set(salt, 32);
|
|
4291
|
-
if (personal) parameter_block.set(personal, 48);
|
|
4292
|
-
|
|
4293
|
-
// initialize hash state
|
|
4294
|
-
for (var i = 0; i < 16; i++) {
|
|
4295
|
-
this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
|
|
4296
|
-
}
|
|
4297
|
-
|
|
4298
|
-
// key the hash, if applicable
|
|
4299
|
-
if (key) {
|
|
4300
|
-
blake2bUpdate(this, key);
|
|
4301
|
-
// at the end
|
|
4302
|
-
this.c = 128;
|
|
4303
|
-
}
|
|
4304
|
-
}
|
|
4305
|
-
|
|
4306
|
-
Blake2b.prototype.update = function (input) {
|
|
4307
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4308
|
-
blake2bUpdate(this, input);
|
|
4309
|
-
return this
|
|
4310
|
-
};
|
|
4311
|
-
|
|
4312
|
-
Blake2b.prototype.digest = function (out) {
|
|
4313
|
-
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out;
|
|
4314
|
-
assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
|
|
4315
|
-
assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
|
|
4316
|
-
blake2bFinal(this, buf);
|
|
4317
|
-
if (out === 'hex') return hexSlice(buf)
|
|
4318
|
-
return buf
|
|
4319
|
-
};
|
|
4320
|
-
|
|
4321
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4322
|
-
|
|
4323
|
-
Blake2b.ready = function (cb) {
|
|
4324
|
-
b2wasm.ready(function () {
|
|
4325
|
-
cb(); // ignore the error
|
|
4326
|
-
});
|
|
4327
|
-
};
|
|
4328
|
-
|
|
4329
|
-
// Updates a BLAKE2b streaming hash
|
|
4330
|
-
// Requires hash context and Uint8Array (byte array)
|
|
4331
|
-
function blake2bUpdate (ctx, input) {
|
|
4332
|
-
for (var i = 0; i < input.length; i++) {
|
|
4333
|
-
if (ctx.c === 128) { // buffer full ?
|
|
4334
|
-
ctx.t += ctx.c; // add counters
|
|
4335
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
4336
|
-
ctx.c = 0; // counter to zero
|
|
4337
|
-
}
|
|
4338
|
-
ctx.b[ctx.c++] = input[i];
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
|
|
4342
|
-
// Completes a BLAKE2b streaming hash
|
|
4343
|
-
// Returns a Uint8Array containing the message digest
|
|
4344
|
-
function blake2bFinal (ctx, out) {
|
|
4345
|
-
ctx.t += ctx.c; // mark last block offset
|
|
4346
|
-
|
|
4347
|
-
while (ctx.c < 128) { // fill up with zeros
|
|
4348
|
-
ctx.b[ctx.c++] = 0;
|
|
4349
|
-
}
|
|
4350
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
4351
|
-
|
|
4352
|
-
for (var i = 0; i < ctx.outlen; i++) {
|
|
4353
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
4354
|
-
}
|
|
4355
|
-
return out
|
|
4356
|
-
}
|
|
4357
|
-
|
|
4358
|
-
function hexSlice (buf) {
|
|
4359
|
-
var str = '';
|
|
4360
|
-
for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
|
|
4361
|
-
return str
|
|
4362
|
-
}
|
|
4363
|
-
|
|
4364
|
-
function toHex (n) {
|
|
4365
|
-
if (n < 16) return '0' + n.toString(16)
|
|
4366
|
-
return n.toString(16)
|
|
4367
|
-
}
|
|
4368
|
-
|
|
4369
|
-
var Proto = Blake2b;
|
|
4370
|
-
|
|
4371
|
-
blake2b$3.exports = function createHash (outlen, key, salt, personal, noAssert) {
|
|
4372
|
-
if (noAssert !== true) {
|
|
4373
|
-
assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen);
|
|
4374
|
-
assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen);
|
|
4375
|
-
if (key != null) {
|
|
4376
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
4377
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
4378
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
4379
|
-
}
|
|
4380
|
-
if (salt != null) {
|
|
4381
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4382
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4383
|
-
}
|
|
4384
|
-
if (personal != null) {
|
|
4385
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4386
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4387
|
-
}
|
|
4388
|
-
}
|
|
4389
|
-
|
|
4390
|
-
return new Proto(outlen, key, salt, personal)
|
|
4391
|
-
};
|
|
4392
|
-
|
|
4393
|
-
blake2b$3.exports.ready = function (cb) {
|
|
4394
|
-
b2wasm.ready(function () { // ignore errors
|
|
4395
|
-
cb();
|
|
4396
|
-
});
|
|
4397
|
-
};
|
|
4398
|
-
|
|
4399
|
-
blake2b$3.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
|
|
4400
|
-
blake2b$3.exports.WASM_LOADED = false;
|
|
4401
|
-
|
|
4402
|
-
var BYTES_MIN = blake2b$3.exports.BYTES_MIN = 16;
|
|
4403
|
-
var BYTES_MAX = blake2b$3.exports.BYTES_MAX = 64;
|
|
4404
|
-
blake2b$3.exports.BYTES = 32;
|
|
4405
|
-
var KEYBYTES_MIN = blake2b$3.exports.KEYBYTES_MIN = 16;
|
|
4406
|
-
var KEYBYTES_MAX = blake2b$3.exports.KEYBYTES_MAX = 64;
|
|
4407
|
-
blake2b$3.exports.KEYBYTES = 32;
|
|
4408
|
-
var SALTBYTES = blake2b$3.exports.SALTBYTES = 16;
|
|
4409
|
-
var PERSONALBYTES = blake2b$3.exports.PERSONALBYTES = 16;
|
|
4410
|
-
|
|
4411
|
-
b2wasm.ready(function (err) {
|
|
4412
|
-
if (!err) {
|
|
4413
|
-
blake2b$3.exports.WASM_LOADED = true;
|
|
4414
|
-
blake2b$3.exports = b2wasm;
|
|
4415
|
-
}
|
|
4416
|
-
});
|
|
4417
|
-
return blake2b$3.exports;
|
|
3690
|
+
function deriveEd25519SecretKey(seed, blake2b) {
|
|
3691
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4418
3692
|
}
|
|
4419
|
-
|
|
4420
|
-
var blake2bExports = /*@__PURE__*/ requireBlake2b();
|
|
4421
|
-
var blake2b$1 = /*@__PURE__*/getDefaultExportFromCjs(blake2bExports);
|
|
4422
|
-
|
|
4423
3693
|
/**
|
|
4424
|
-
*
|
|
4425
|
-
*
|
|
4426
|
-
* If empty array is given a zero-hash is returned.
|
|
3694
|
+
* Derives a Bandersnatch secret key from a seed.
|
|
3695
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4427
3696
|
*/
|
|
4428
|
-
function
|
|
4429
|
-
|
|
4430
|
-
if (r.length === 0) {
|
|
4431
|
-
return out.asOpaque();
|
|
4432
|
-
}
|
|
4433
|
-
const hasher = blake2b$1(HASH_SIZE);
|
|
4434
|
-
for (const v of r) {
|
|
4435
|
-
hasher?.update(v instanceof BytesBlob ? v.raw : v);
|
|
4436
|
-
}
|
|
4437
|
-
hasher?.digest(out.raw);
|
|
4438
|
-
return out.asOpaque();
|
|
3697
|
+
function deriveBandersnatchSecretKey(seed, blake2b) {
|
|
3698
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4439
3699
|
}
|
|
4440
|
-
/**
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
const out = allocator.emptyHash();
|
|
4446
|
-
hasher?.digest(out.raw);
|
|
4447
|
-
return out;
|
|
3700
|
+
/**
|
|
3701
|
+
* Derive Ed25519 public key from secret seed
|
|
3702
|
+
*/
|
|
3703
|
+
async function deriveEd25519PublicKey(seed) {
|
|
3704
|
+
return (await privateKey(seed)).pubKey;
|
|
4448
3705
|
}
|
|
4449
|
-
/**
|
|
4450
|
-
|
|
4451
|
-
|
|
3706
|
+
/**
|
|
3707
|
+
* Derive Bandersnatch public key from secret seed
|
|
3708
|
+
*/
|
|
3709
|
+
function deriveBandersnatchPublicKey(seed) {
|
|
3710
|
+
return publicKey(seed.raw);
|
|
4452
3711
|
}
|
|
4453
3712
|
|
|
4454
|
-
var
|
|
3713
|
+
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
3714
|
+
__proto__: null,
|
|
3715
|
+
SEED_SIZE: SEED_SIZE,
|
|
3716
|
+
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
3717
|
+
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
3718
|
+
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
3719
|
+
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
3720
|
+
trivialSeed: trivialSeed
|
|
3721
|
+
});
|
|
3722
|
+
|
|
3723
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4455
3724
|
__proto__: null,
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
3725
|
+
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
3726
|
+
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
3727
|
+
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
3728
|
+
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
3729
|
+
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
3730
|
+
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
3731
|
+
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
3732
|
+
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
3733
|
+
Ed25519Pair: Ed25519Pair,
|
|
3734
|
+
SEED_SIZE: SEED_SIZE,
|
|
3735
|
+
bandersnatch: bandersnatch,
|
|
3736
|
+
bandersnatchWasm: bandersnatch_exports,
|
|
3737
|
+
ed25519: ed25519,
|
|
3738
|
+
initWasm: initAll,
|
|
3739
|
+
keyDerivation: keyDerivation
|
|
4459
3740
|
});
|
|
4460
3741
|
|
|
4461
3742
|
/*!
|
|
@@ -4816,18 +4097,89 @@ function WASMInterface(binary, hashLength) {
|
|
|
4816
4097
|
|
|
4817
4098
|
new Mutex();
|
|
4818
4099
|
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
new Mutex();
|
|
4100
|
+
var name$j = "blake2b";
|
|
4101
|
+
var data$j = "AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2hfR2V0U3RhdGUABw5IYXNoX0NhbGN1bGF0ZQAIClNUQVRFX1NJWkUDAQrTOAkFAEGACQvrAgIFfwF+AkAgAUEBSA0AAkACQAJAIAFBgAFBACgC4IoBIgJrIgNKDQAgASEEDAELQQBBADYC4IoBAkAgAkH/AEoNACACQeCJAWohBSAAIQRBACEGA0AgBSAELQAAOgAAIARBAWohBCAFQQFqIQUgAyAGQQFqIgZB/wFxSg0ACwtBAEEAKQPAiQEiB0KAAXw3A8CJAUEAQQApA8iJASAHQv9+Vq18NwPIiQFB4IkBEAIgACADaiEAAkAgASADayIEQYEBSA0AIAIgAWohBQNAQQBBACkDwIkBIgdCgAF8NwPAiQFBAEEAKQPIiQEgB0L/flatfDcDyIkBIAAQAiAAQYABaiEAIAVBgH9qIgVBgAJLDQALIAVBgH9qIQQMAQsgBEEATA0BC0EAIQUDQCAFQQAoAuCKAWpB4IkBaiAAIAVqLQAAOgAAIAQgBUEBaiIFQf8BcUoNAAsLQQBBACgC4IoBIARqNgLgigELC78uASR+QQBBACkD0IkBQQApA7CJASIBQQApA5CJAXwgACkDICICfCIDhULr+obav7X2wR+FQiCJIgRCq/DT9K/uvLc8fCIFIAGFQiiJIgYgA3wgACkDKCIBfCIHIASFQjCJIgggBXwiCSAGhUIBiSIKQQApA8iJAUEAKQOoiQEiBEEAKQOIiQF8IAApAxAiA3wi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tzyFNwOQiQFBAEEAKQOIiwFC8e30+KWn/aelf4U3A5iJAUEAQQApA5CLAULRhZrv+s+Uh9EAhTcDoIkBQQBBACkDmIsBQp/Y+dnCkdqCm3+FNwOoiQFBAEEAKQOgiwFC6/qG2r+19sEfhTcDsIkBQQBBACkDqIsBQvnC+JuRo7Pw2wCFNwO4iQFBACADp0H/AXE2AuSKAQJAIAFBAUgNACACQgA3A3ggAkIANwNwIAJCADcDaCACQgA3A2AgAkIANwNYIAJCADcDUCACQgA3A0ggAkIANwNAIAJCADcDOCACQgA3AzAgAkIANwMoIAJCADcDICACQgA3AxggAkIANwMQIAJCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=";
|
|
4102
|
+
var hash$j = "c6f286e6";
|
|
4103
|
+
var wasmJson$j = {
|
|
4104
|
+
name: name$j,
|
|
4105
|
+
data: data$j,
|
|
4106
|
+
hash: hash$j
|
|
4107
|
+
};
|
|
4828
4108
|
|
|
4829
4109
|
new Mutex();
|
|
4830
|
-
|
|
4110
|
+
function validateBits$4(bits) {
|
|
4111
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
4112
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
4113
|
+
}
|
|
4114
|
+
return null;
|
|
4115
|
+
}
|
|
4116
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
4117
|
+
return outputBits | (keyBits << 16);
|
|
4118
|
+
}
|
|
4119
|
+
/**
|
|
4120
|
+
* Creates a new BLAKE2b hash instance
|
|
4121
|
+
* @param bits Number of output bits, which has to be a number
|
|
4122
|
+
* divisible by 8, between 8 and 512. Defaults to 512.
|
|
4123
|
+
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
|
|
4124
|
+
*/
|
|
4125
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
4126
|
+
if (validateBits$4(bits)) {
|
|
4127
|
+
return Promise.reject(validateBits$4(bits));
|
|
4128
|
+
}
|
|
4129
|
+
let keyBuffer = null;
|
|
4130
|
+
let initParam = bits;
|
|
4131
|
+
if (key !== null) {
|
|
4132
|
+
keyBuffer = getUInt8Buffer(key);
|
|
4133
|
+
if (keyBuffer.length > 64) {
|
|
4134
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
4135
|
+
}
|
|
4136
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
4137
|
+
}
|
|
4138
|
+
const outputSize = bits / 8;
|
|
4139
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
4140
|
+
if (initParam > 512) {
|
|
4141
|
+
wasm.writeMemory(keyBuffer);
|
|
4142
|
+
}
|
|
4143
|
+
wasm.init(initParam);
|
|
4144
|
+
const obj = {
|
|
4145
|
+
init: initParam > 512
|
|
4146
|
+
? () => {
|
|
4147
|
+
wasm.writeMemory(keyBuffer);
|
|
4148
|
+
wasm.init(initParam);
|
|
4149
|
+
return obj;
|
|
4150
|
+
}
|
|
4151
|
+
: () => {
|
|
4152
|
+
wasm.init(initParam);
|
|
4153
|
+
return obj;
|
|
4154
|
+
},
|
|
4155
|
+
update: (data) => {
|
|
4156
|
+
wasm.update(data);
|
|
4157
|
+
return obj;
|
|
4158
|
+
},
|
|
4159
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
4160
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
4161
|
+
save: () => wasm.save(),
|
|
4162
|
+
load: (data) => {
|
|
4163
|
+
wasm.load(data);
|
|
4164
|
+
return obj;
|
|
4165
|
+
},
|
|
4166
|
+
blockSize: 128,
|
|
4167
|
+
digestSize: outputSize,
|
|
4168
|
+
};
|
|
4169
|
+
return obj;
|
|
4170
|
+
});
|
|
4171
|
+
}
|
|
4172
|
+
|
|
4173
|
+
new Mutex();
|
|
4174
|
+
|
|
4175
|
+
new Mutex();
|
|
4176
|
+
|
|
4177
|
+
new Mutex();
|
|
4178
|
+
|
|
4179
|
+
new Mutex();
|
|
4180
|
+
|
|
4181
|
+
new Mutex();
|
|
4182
|
+
|
|
4831
4183
|
new Mutex();
|
|
4832
4184
|
|
|
4833
4185
|
new Mutex();
|
|
@@ -4906,6 +4258,79 @@ new Mutex();
|
|
|
4906
4258
|
|
|
4907
4259
|
new Mutex();
|
|
4908
4260
|
|
|
4261
|
+
/**
|
|
4262
|
+
* Size of the output of the hash functions.
|
|
4263
|
+
*
|
|
4264
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
4265
|
+
*
|
|
4266
|
+
*/
|
|
4267
|
+
const HASH_SIZE = 32;
|
|
4268
|
+
/** A hash without last byte (useful for trie representation). */
|
|
4269
|
+
const TRUNCATED_HASH_SIZE = 31;
|
|
4270
|
+
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
4271
|
+
/**
|
|
4272
|
+
* Container for some object with a hash that is related to this object.
|
|
4273
|
+
*
|
|
4274
|
+
* After calculating the hash these two should be passed together to avoid
|
|
4275
|
+
* unnecessary re-hashing of the data.
|
|
4276
|
+
*/
|
|
4277
|
+
class WithHash extends WithDebug {
|
|
4278
|
+
hash;
|
|
4279
|
+
data;
|
|
4280
|
+
constructor(hash, data) {
|
|
4281
|
+
super();
|
|
4282
|
+
this.hash = hash;
|
|
4283
|
+
this.data = data;
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
/**
|
|
4287
|
+
* Extension of [`WithHash`] additionally containing an encoded version of the object.
|
|
4288
|
+
*/
|
|
4289
|
+
class WithHashAndBytes extends WithHash {
|
|
4290
|
+
encoded;
|
|
4291
|
+
constructor(hash, data, encoded) {
|
|
4292
|
+
super(hash, data);
|
|
4293
|
+
this.encoded = encoded;
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
|
|
4297
|
+
const zero$1 = Bytes.zero(HASH_SIZE);
|
|
4298
|
+
class Blake2b {
|
|
4299
|
+
hasher;
|
|
4300
|
+
static async createHasher() {
|
|
4301
|
+
return new Blake2b(await createBLAKE2b(HASH_SIZE * 8));
|
|
4302
|
+
}
|
|
4303
|
+
constructor(hasher) {
|
|
4304
|
+
this.hasher = hasher;
|
|
4305
|
+
}
|
|
4306
|
+
/**
|
|
4307
|
+
* Hash given collection of blobs.
|
|
4308
|
+
*
|
|
4309
|
+
* If empty array is given a zero-hash is returned.
|
|
4310
|
+
*/
|
|
4311
|
+
hashBlobs(r) {
|
|
4312
|
+
if (r.length === 0) {
|
|
4313
|
+
return zero$1.asOpaque();
|
|
4314
|
+
}
|
|
4315
|
+
const hasher = this.hasher.init();
|
|
4316
|
+
for (const v of r) {
|
|
4317
|
+
hasher.update(v instanceof BytesBlob ? v.raw : v);
|
|
4318
|
+
}
|
|
4319
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4320
|
+
}
|
|
4321
|
+
/** Hash given blob of bytes. */
|
|
4322
|
+
hashBytes(blob) {
|
|
4323
|
+
const hasher = this.hasher.init();
|
|
4324
|
+
const bytes = blob instanceof BytesBlob ? blob.raw : blob;
|
|
4325
|
+
hasher.update(bytes);
|
|
4326
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4327
|
+
}
|
|
4328
|
+
/** Convert given string into bytes and hash it. */
|
|
4329
|
+
hashString(str) {
|
|
4330
|
+
return this.hashBytes(BytesBlob.blobFromString(str));
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
|
|
4909
4334
|
class KeccakHasher {
|
|
4910
4335
|
hasher;
|
|
4911
4336
|
static async create() {
|
|
@@ -4930,91 +4355,61 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4930
4355
|
hashBlobs: hashBlobs
|
|
4931
4356
|
});
|
|
4932
4357
|
|
|
4933
|
-
|
|
4358
|
+
// TODO [ToDr] (#213) this should most likely be moved to a separate
|
|
4359
|
+
// package to avoid pulling in unnecessary deps.
|
|
4360
|
+
|
|
4361
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4934
4362
|
__proto__: null,
|
|
4363
|
+
Blake2b: Blake2b,
|
|
4935
4364
|
HASH_SIZE: HASH_SIZE,
|
|
4936
|
-
PageAllocator: PageAllocator,
|
|
4937
|
-
SimpleAllocator: SimpleAllocator,
|
|
4938
4365
|
TRUNCATED_HASH_SIZE: TRUNCATED_HASH_SIZE,
|
|
4939
4366
|
WithHash: WithHash,
|
|
4940
4367
|
WithHashAndBytes: WithHashAndBytes,
|
|
4941
4368
|
ZERO_HASH: ZERO_HASH,
|
|
4942
|
-
blake2b: blake2b,
|
|
4943
|
-
defaultAllocator: defaultAllocator,
|
|
4944
4369
|
keccak: keccak
|
|
4945
4370
|
});
|
|
4946
4371
|
|
|
4947
|
-
const SEED_SIZE = 32;
|
|
4948
|
-
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
4949
|
-
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
4950
|
-
/**
|
|
4951
|
-
* JIP-5: Secret key derivation
|
|
4952
|
-
*
|
|
4953
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
4954
|
-
/**
|
|
4955
|
-
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
4956
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
4957
|
-
*/
|
|
4958
|
-
function trivialSeed(s) {
|
|
4959
|
-
const s_le = u32AsLeBytes(s);
|
|
4960
|
-
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();
|
|
4961
|
-
}
|
|
4962
|
-
/**
|
|
4963
|
-
* Derives a Ed25519 secret key from a seed.
|
|
4964
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4965
|
-
*/
|
|
4966
|
-
function deriveEd25519SecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4967
|
-
return hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4968
|
-
}
|
|
4969
|
-
/**
|
|
4970
|
-
* Derives a Bandersnatch secret key from a seed.
|
|
4971
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4972
|
-
*/
|
|
4973
|
-
function deriveBandersnatchSecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4974
|
-
return hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4975
|
-
}
|
|
4976
|
-
/**
|
|
4977
|
-
* Derive Ed25519 public key from secret seed
|
|
4978
|
-
*/
|
|
4979
|
-
async function deriveEd25519PublicKey(seed) {
|
|
4980
|
-
return (await privateKey(seed)).pubKey;
|
|
4981
|
-
}
|
|
4982
4372
|
/**
|
|
4983
|
-
*
|
|
4373
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
4984
4374
|
*/
|
|
4985
|
-
|
|
4986
|
-
|
|
4375
|
+
class ArrayView {
|
|
4376
|
+
start;
|
|
4377
|
+
end;
|
|
4378
|
+
source;
|
|
4379
|
+
length;
|
|
4380
|
+
constructor(source, start, end) {
|
|
4381
|
+
this.start = start;
|
|
4382
|
+
this.end = end;
|
|
4383
|
+
this.source = source;
|
|
4384
|
+
this.length = end - start;
|
|
4385
|
+
}
|
|
4386
|
+
static from(source, start = 0, end = source.length) {
|
|
4387
|
+
check `
|
|
4388
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
4389
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
4390
|
+
`;
|
|
4391
|
+
return new ArrayView(source, start, end);
|
|
4392
|
+
}
|
|
4393
|
+
get(i) {
|
|
4394
|
+
check `
|
|
4395
|
+
${i >= 0 && i < this.length}
|
|
4396
|
+
Index out of bounds: ${i} < ${this.length}
|
|
4397
|
+
`;
|
|
4398
|
+
return this.source[this.start + i];
|
|
4399
|
+
}
|
|
4400
|
+
subview(from, to = this.length) {
|
|
4401
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
4402
|
+
}
|
|
4403
|
+
toArray() {
|
|
4404
|
+
return this.source.slice(this.start, this.end);
|
|
4405
|
+
}
|
|
4406
|
+
*[Symbol.iterator]() {
|
|
4407
|
+
for (let i = this.start; i < this.end; i++) {
|
|
4408
|
+
yield this.source[i];
|
|
4409
|
+
}
|
|
4410
|
+
}
|
|
4987
4411
|
}
|
|
4988
4412
|
|
|
4989
|
-
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
4990
|
-
__proto__: null,
|
|
4991
|
-
SEED_SIZE: SEED_SIZE,
|
|
4992
|
-
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
4993
|
-
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
4994
|
-
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
4995
|
-
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
4996
|
-
trivialSeed: trivialSeed
|
|
4997
|
-
});
|
|
4998
|
-
|
|
4999
|
-
var index$o = /*#__PURE__*/Object.freeze({
|
|
5000
|
-
__proto__: null,
|
|
5001
|
-
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
5002
|
-
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
5003
|
-
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
5004
|
-
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
5005
|
-
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
5006
|
-
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
5007
|
-
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
5008
|
-
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
5009
|
-
Ed25519Pair: Ed25519Pair,
|
|
5010
|
-
SEED_SIZE: SEED_SIZE,
|
|
5011
|
-
bandersnatch: bandersnatch,
|
|
5012
|
-
bandersnatchWasm: bandersnatch_exports,
|
|
5013
|
-
ed25519: ed25519,
|
|
5014
|
-
initWasm: initAll,
|
|
5015
|
-
keyDerivation: keyDerivation
|
|
5016
|
-
});
|
|
5017
|
-
|
|
5018
4413
|
/** A map which uses hashes as keys. */
|
|
5019
4414
|
class HashDictionary {
|
|
5020
4415
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
@@ -5602,6 +4997,7 @@ class TruncatedHashDictionary {
|
|
|
5602
4997
|
|
|
5603
4998
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
5604
4999
|
__proto__: null,
|
|
5000
|
+
ArrayView: ArrayView,
|
|
5605
5001
|
FixedSizeArray: FixedSizeArray,
|
|
5606
5002
|
HashDictionary: HashDictionary,
|
|
5607
5003
|
HashSet: HashSet,
|
|
@@ -7290,6 +6686,17 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
7290
6686
|
});
|
|
7291
6687
|
}
|
|
7292
6688
|
|
|
6689
|
+
/**
|
|
6690
|
+
* Take an input data and re-encode that data as view.
|
|
6691
|
+
*
|
|
6692
|
+
* NOTE: this function should NEVER be used in any production code,
|
|
6693
|
+
* it's only a test helper.
|
|
6694
|
+
*/
|
|
6695
|
+
function reencodeAsView(codec, object, chainSpec) {
|
|
6696
|
+
const encoded = Encoder.encodeObject(codec, object, chainSpec);
|
|
6697
|
+
return Decoder.decodeObject(codec.View, encoded, chainSpec);
|
|
6698
|
+
}
|
|
6699
|
+
|
|
7293
6700
|
var index$l = /*#__PURE__*/Object.freeze({
|
|
7294
6701
|
__proto__: null,
|
|
7295
6702
|
Block: Block,
|
|
@@ -7310,6 +6717,7 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
7310
6717
|
guarantees: guarantees,
|
|
7311
6718
|
headerViewWithHashCodec: headerViewWithHashCodec,
|
|
7312
6719
|
preimage: preimage,
|
|
6720
|
+
reencodeAsView: reencodeAsView,
|
|
7313
6721
|
refineContext: refineContext,
|
|
7314
6722
|
tickets: tickets,
|
|
7315
6723
|
tryAsCoreIndex: tryAsCoreIndex,
|
|
@@ -7922,7 +7330,7 @@ var chain_spec$1 = {
|
|
|
7922
7330
|
"0d000000000000000000000000000000000000000000000000000000000000": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
7923
7331
|
"01000000000000000000000000000000000000000000000000000000000000": "080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978",
|
|
7924
7332
|
"10000000000000000000000000000000000000000000000000000000000000": "00",
|
|
7925
|
-
"0c000000000000000000000000000000000000000000000000000000000000": "
|
|
7333
|
+
"0c000000000000000000000000000000000000000000000000000000000000": "000000000000000000000000000000000000000000",
|
|
7926
7334
|
"06000000000000000000000000000000000000000000000000000000000000": "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25bb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aae88bd757ad5b9bedf372d8d3f0cf6c962a469db61a265f6418e1ffed86da29ec",
|
|
7927
7335
|
"0a000000000000000000000000000000000000000000000000000000000000": "0000",
|
|
7928
7336
|
"03000000000000000000000000000000000000000000000000000000000000": "012bf11dc5e1c7b9bbaafc2c8533017abc12daeb0baf22c92509ad50f7875e5716000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
@@ -7970,7 +7378,7 @@ var chain_spec = {
|
|
|
7970
7378
|
"0d000000000000000000000000000000000000000000000000000000000000": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
7971
7379
|
"01000000000000000000000000000000000000000000000000000000000000": "080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978",
|
|
7972
7380
|
"10000000000000000000000000000000000000000000000000000000000000": "00",
|
|
7973
|
-
"0c000000000000000000000000000000000000000000000000000000000000": "
|
|
7381
|
+
"0c000000000000000000000000000000000000000000000000000000000000": "000000000000000000000000000000000000000000",
|
|
7974
7382
|
"06000000000000000000000000000000000000000000000000000000000000": "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25bb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aae88bd757ad5b9bedf372d8d3f0cf6c962a469db61a265f6418e1ffed86da29ec",
|
|
7975
7383
|
"0a000000000000000000000000000000000000000000000000000000000000": "0000",
|
|
7976
7384
|
"03000000000000000000000000000000000000000000000000000000000000": "012bf11dc5e1c7b9bbaafc2c8533017abc12daeb0baf22c92509ad50f7875e5716000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
@@ -8563,43 +7971,43 @@ var stateKeys;
|
|
|
8563
7971
|
}
|
|
8564
7972
|
stateKeys.serviceInfo = serviceInfo;
|
|
8565
7973
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bba033bba03?v=0.7.1 */
|
|
8566
|
-
function serviceStorage(serviceId, key) {
|
|
7974
|
+
function serviceStorage(blake2b, serviceId, key) {
|
|
8567
7975
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8568
7976
|
const out = Bytes.zero(HASH_SIZE);
|
|
8569
7977
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 1)), 0);
|
|
8570
7978
|
out.raw.set(key.raw.subarray(0, HASH_SIZE - U32_BYTES), U32_BYTES);
|
|
8571
7979
|
return legacyServiceNested(serviceId, out);
|
|
8572
7980
|
}
|
|
8573
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
7981
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
8574
7982
|
}
|
|
8575
7983
|
stateKeys.serviceStorage = serviceStorage;
|
|
8576
7984
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bd7033bd703?v=0.7.1 */
|
|
8577
|
-
function servicePreimage(serviceId, hash) {
|
|
7985
|
+
function servicePreimage(blake2b, serviceId, hash) {
|
|
8578
7986
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8579
7987
|
const out = Bytes.zero(HASH_SIZE);
|
|
8580
7988
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 2)), 0);
|
|
8581
7989
|
out.raw.set(hash.raw.subarray(1, HASH_SIZE - U32_BYTES + 1), U32_BYTES);
|
|
8582
7990
|
return legacyServiceNested(serviceId, out);
|
|
8583
7991
|
}
|
|
8584
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
7992
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
8585
7993
|
}
|
|
8586
7994
|
stateKeys.servicePreimage = servicePreimage;
|
|
8587
7995
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b0a043b0a04?v=0.7.1 */
|
|
8588
|
-
function serviceLookupHistory(serviceId, hash, preimageLength) {
|
|
7996
|
+
function serviceLookupHistory(blake2b, serviceId, hash, preimageLength) {
|
|
8589
7997
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8590
|
-
const doubleHash = hashBytes(hash);
|
|
7998
|
+
const doubleHash = blake2b.hashBytes(hash);
|
|
8591
7999
|
const out = Bytes.zero(HASH_SIZE);
|
|
8592
8000
|
out.raw.set(u32AsLeBytes(preimageLength), 0);
|
|
8593
8001
|
out.raw.set(doubleHash.raw.subarray(2, HASH_SIZE - U32_BYTES + 2), U32_BYTES);
|
|
8594
8002
|
return legacyServiceNested(serviceId, out);
|
|
8595
8003
|
}
|
|
8596
|
-
return serviceNested(serviceId, preimageLength, hash);
|
|
8004
|
+
return serviceNested(blake2b, serviceId, preimageLength, hash);
|
|
8597
8005
|
}
|
|
8598
8006
|
stateKeys.serviceLookupHistory = serviceLookupHistory;
|
|
8599
8007
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b88003b8800?v=0.7.1 */
|
|
8600
|
-
function serviceNested(serviceId, numberPrefix, hash) {
|
|
8008
|
+
function serviceNested(blake2b, serviceId, numberPrefix, hash) {
|
|
8601
8009
|
const inputToHash = BytesBlob.blobFromParts(u32AsLeBytes(numberPrefix), hash.raw);
|
|
8602
|
-
const newHash = hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8010
|
+
const newHash = blake2b.hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8603
8011
|
const key = Bytes.zero(HASH_SIZE);
|
|
8604
8012
|
let i = 0;
|
|
8605
8013
|
for (const byte of u32AsLeBytes(serviceId)) {
|
|
@@ -8660,12 +8068,72 @@ function accumulationOutputComparator(a, b) {
|
|
|
8660
8068
|
return Ordering.Equal;
|
|
8661
8069
|
}
|
|
8662
8070
|
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8071
|
+
/** `O`: Maximum number of items in the authorizations pool. */
|
|
8072
|
+
const O = 8;
|
|
8073
|
+
/** `Q`: The number of items in the authorizations queue. */
|
|
8074
|
+
const Q = 80;
|
|
8075
|
+
/** `W_B`: The maximum size of the concatenated variable-size blobs, extrinsics and imported segments of a work-package, in octets */
|
|
8076
|
+
Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) ? 13_791_360 : 13_794_305;
|
|
8077
|
+
/** `W_T`: The size of a transfer memo in octets. */
|
|
8078
|
+
const W_T = 128;
|
|
8079
|
+
/**
|
|
8080
|
+
* `J`: The maximum sum of dependency items in a work-report.
|
|
8081
|
+
*
|
|
8082
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
8083
|
+
*/
|
|
8084
|
+
const MAX_REPORT_DEPENDENCIES = 8;
|
|
8085
|
+
|
|
8086
|
+
/**
|
|
8087
|
+
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
8088
|
+
*
|
|
8089
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
8090
|
+
*/
|
|
8091
|
+
class NotYetAccumulatedReport extends WithDebug {
|
|
8092
|
+
report;
|
|
8093
|
+
dependencies;
|
|
8094
|
+
static Codec = codec$1.Class(NotYetAccumulatedReport, {
|
|
8095
|
+
report: WorkReport.Codec,
|
|
8096
|
+
dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
8097
|
+
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
8098
|
+
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
8099
|
+
minLength: 0,
|
|
8100
|
+
}),
|
|
8101
|
+
});
|
|
8102
|
+
static create({ report, dependencies }) {
|
|
8103
|
+
return new NotYetAccumulatedReport(report, dependencies);
|
|
8104
|
+
}
|
|
8105
|
+
constructor(
|
|
8106
|
+
/**
|
|
8107
|
+
* Each of these were made available at most one epoch ago
|
|
8108
|
+
* but have or had unfulfilled dependencies.
|
|
8109
|
+
*/
|
|
8110
|
+
report,
|
|
8111
|
+
/**
|
|
8112
|
+
* Alongside the work-report itself, we retain its un-accumulated
|
|
8113
|
+
* dependencies, a set of work-package hashes.
|
|
8114
|
+
*
|
|
8115
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
8116
|
+
*/
|
|
8117
|
+
dependencies) {
|
|
8118
|
+
super();
|
|
8119
|
+
this.report = report;
|
|
8120
|
+
this.dependencies = dependencies;
|
|
8121
|
+
}
|
|
8122
|
+
}
|
|
8123
|
+
const accumulationQueueCodec = codecPerEpochBlock(readonlyArray(codec$1.sequenceVarLen(NotYetAccumulatedReport.Codec)));
|
|
8124
|
+
|
|
8125
|
+
/** Check if given array has correct length before casting to the opaque type. */
|
|
8126
|
+
function tryAsPerCore(array, spec) {
|
|
8127
|
+
check `
|
|
8128
|
+
${array.length === spec.coresCount}
|
|
8129
|
+
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
8130
|
+
`;
|
|
8131
|
+
return asOpaqueType(array);
|
|
8132
|
+
}
|
|
8133
|
+
const codecPerCore = (val) => codecWithContext((context) => {
|
|
8134
|
+
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
8135
|
+
});
|
|
8136
|
+
|
|
8669
8137
|
/**
|
|
8670
8138
|
* Assignment of particular work report to a core.
|
|
8671
8139
|
*
|
|
@@ -8678,7 +8146,7 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8678
8146
|
workReport;
|
|
8679
8147
|
timeout;
|
|
8680
8148
|
static Codec = codec$1.Class(AvailabilityAssignment, {
|
|
8681
|
-
workReport:
|
|
8149
|
+
workReport: WorkReport.Codec,
|
|
8682
8150
|
timeout: codec$1.u32.asOpaque(),
|
|
8683
8151
|
});
|
|
8684
8152
|
static create({ workReport, timeout }) {
|
|
@@ -8694,19 +8162,19 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8694
8162
|
this.timeout = timeout;
|
|
8695
8163
|
}
|
|
8696
8164
|
}
|
|
8165
|
+
const availabilityAssignmentsCodec = codecPerCore(codec$1.optional(AvailabilityAssignment.Codec));
|
|
8166
|
+
|
|
8167
|
+
/** `O`: Maximal authorization pool size. */
|
|
8168
|
+
const MAX_AUTH_POOL_SIZE = O;
|
|
8169
|
+
/** `Q`: Size of the authorization queue. */
|
|
8170
|
+
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
8171
|
+
const authPoolsCodec = codecPerCore(codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
8172
|
+
minLength: 0,
|
|
8173
|
+
maxLength: MAX_AUTH_POOL_SIZE,
|
|
8174
|
+
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
8175
|
+
}));
|
|
8176
|
+
const authQueuesCodec = codecPerCore(codecFixedSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
|
|
8697
8177
|
|
|
8698
|
-
/** Check if given array has correct length before casting to the opaque type. */
|
|
8699
|
-
function tryAsPerCore(array, spec) {
|
|
8700
|
-
check `
|
|
8701
|
-
${array.length === spec.coresCount}
|
|
8702
|
-
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
8703
|
-
`;
|
|
8704
|
-
return asOpaqueType(array);
|
|
8705
|
-
}
|
|
8706
|
-
const codecPerCore = (val) => codecWithContext((context) => {
|
|
8707
|
-
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
8708
|
-
});
|
|
8709
|
-
|
|
8710
8178
|
const sortedSetCodec = () => readonlyArray(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE))).convert((input) => input.array, (output) => {
|
|
8711
8179
|
const typed = output.map((x) => x.asOpaque());
|
|
8712
8180
|
return SortedSet.fromSortedArray(hashComparator, typed);
|
|
@@ -8769,81 +8237,10 @@ function hashComparator(a, b) {
|
|
|
8769
8237
|
return a.compare(b);
|
|
8770
8238
|
}
|
|
8771
8239
|
|
|
8772
|
-
|
|
8773
|
-
const
|
|
8774
|
-
|
|
8775
|
-
const
|
|
8776
|
-
/** `W_T`: The size of a transfer memo in octets. */
|
|
8777
|
-
const W_T = 128;
|
|
8778
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
8779
|
-
/**
|
|
8780
|
-
* `J`: The maximum sum of dependency items in a work-report.
|
|
8781
|
-
*
|
|
8782
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
8783
|
-
*/
|
|
8784
|
-
const MAX_REPORT_DEPENDENCIES = 8;
|
|
8785
|
-
/** `Q`: Size of the authorization queue. */
|
|
8786
|
-
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
8787
|
-
/** `O`: Maximal authorization pool size. */
|
|
8788
|
-
const MAX_AUTH_POOL_SIZE = O;
|
|
8789
|
-
|
|
8790
|
-
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8791
|
-
class AutoAccumulate {
|
|
8792
|
-
service;
|
|
8793
|
-
gasLimit;
|
|
8794
|
-
static Codec = codec$1.Class(AutoAccumulate, {
|
|
8795
|
-
service: codec$1.u32.asOpaque(),
|
|
8796
|
-
gasLimit: codec$1.u64.asOpaque(),
|
|
8797
|
-
});
|
|
8798
|
-
static create({ service, gasLimit }) {
|
|
8799
|
-
return new AutoAccumulate(service, gasLimit);
|
|
8800
|
-
}
|
|
8801
|
-
constructor(
|
|
8802
|
-
/** Service id that auto-accumulates. */
|
|
8803
|
-
service,
|
|
8804
|
-
/** Gas limit for auto-accumulation. */
|
|
8805
|
-
gasLimit) {
|
|
8806
|
-
this.service = service;
|
|
8807
|
-
this.gasLimit = gasLimit;
|
|
8808
|
-
}
|
|
8809
|
-
}
|
|
8810
|
-
/**
|
|
8811
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
|
|
8812
|
-
*/
|
|
8813
|
-
class PrivilegedServices {
|
|
8814
|
-
manager;
|
|
8815
|
-
authManager;
|
|
8816
|
-
validatorsManager;
|
|
8817
|
-
autoAccumulateServices;
|
|
8818
|
-
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8819
|
-
manager: codec$1.u32.asOpaque(),
|
|
8820
|
-
authManager: codecPerCore(codec$1.u32.asOpaque()),
|
|
8821
|
-
validatorsManager: codec$1.u32.asOpaque(),
|
|
8822
|
-
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8823
|
-
});
|
|
8824
|
-
static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
|
|
8825
|
-
return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
|
|
8826
|
-
}
|
|
8827
|
-
constructor(
|
|
8828
|
-
/**
|
|
8829
|
-
* `chi_m`: The first, χm, is the index of the manager service which is
|
|
8830
|
-
* the service able to effect an alteration of χ from block to block,
|
|
8831
|
-
* as well as bestow services with storage deposit credits.
|
|
8832
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
|
|
8833
|
-
*/
|
|
8834
|
-
manager,
|
|
8835
|
-
/** `chi_a`: Manages authorization queue one for each core. */
|
|
8836
|
-
authManager,
|
|
8837
|
-
/** `chi_v`: Managers validator keys. */
|
|
8838
|
-
validatorsManager,
|
|
8839
|
-
/** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
8840
|
-
autoAccumulateServices) {
|
|
8841
|
-
this.manager = manager;
|
|
8842
|
-
this.authManager = authManager;
|
|
8843
|
-
this.validatorsManager = validatorsManager;
|
|
8844
|
-
this.autoAccumulateServices = autoAccumulateServices;
|
|
8845
|
-
}
|
|
8846
|
-
}
|
|
8240
|
+
const MAX_VALUE = 4294967295;
|
|
8241
|
+
const MIN_VALUE = -2147483648;
|
|
8242
|
+
const MAX_SHIFT_U32 = 32;
|
|
8243
|
+
const MAX_SHIFT_U64 = 64n;
|
|
8847
8244
|
|
|
8848
8245
|
/**
|
|
8849
8246
|
* `H = 8`: The size of recent history, in blocks.
|
|
@@ -8882,6 +8279,11 @@ class BlockState extends WithDebug {
|
|
|
8882
8279
|
this.reported = reported;
|
|
8883
8280
|
}
|
|
8884
8281
|
}
|
|
8282
|
+
/**
|
|
8283
|
+
* Recent history of blocks.
|
|
8284
|
+
*
|
|
8285
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
8286
|
+
*/
|
|
8885
8287
|
class RecentBlocks extends WithDebug {
|
|
8886
8288
|
blocks;
|
|
8887
8289
|
accumulationLog;
|
|
@@ -8895,6 +8297,11 @@ class RecentBlocks extends WithDebug {
|
|
|
8895
8297
|
peaks: readonlyArray(codec$1.sequenceVarLen(codec$1.optional(codec$1.bytes(HASH_SIZE)))),
|
|
8896
8298
|
}),
|
|
8897
8299
|
});
|
|
8300
|
+
static empty() {
|
|
8301
|
+
return new RecentBlocks(asKnownSize([]), {
|
|
8302
|
+
peaks: [],
|
|
8303
|
+
});
|
|
8304
|
+
}
|
|
8898
8305
|
static create(a) {
|
|
8899
8306
|
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
8900
8307
|
}
|
|
@@ -8914,61 +8321,8 @@ class RecentBlocks extends WithDebug {
|
|
|
8914
8321
|
this.accumulationLog = accumulationLog;
|
|
8915
8322
|
}
|
|
8916
8323
|
}
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
*
|
|
8920
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
8921
|
-
*/
|
|
8922
|
-
class RecentBlocksHistory extends WithDebug {
|
|
8923
|
-
current;
|
|
8924
|
-
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
8925
|
-
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
8926
|
-
return RecentBlocksHistory.create(recentBlocks);
|
|
8927
|
-
}, (skip) => {
|
|
8928
|
-
return RecentBlocks.Codec.skip(skip);
|
|
8929
|
-
});
|
|
8930
|
-
static create(recentBlocks) {
|
|
8931
|
-
return new RecentBlocksHistory(recentBlocks);
|
|
8932
|
-
}
|
|
8933
|
-
static empty() {
|
|
8934
|
-
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
8935
|
-
blocks: asKnownSize([]),
|
|
8936
|
-
accumulationLog: { peaks: [] },
|
|
8937
|
-
}));
|
|
8938
|
-
}
|
|
8939
|
-
/**
|
|
8940
|
-
* Returns the block's BEEFY super peak.
|
|
8941
|
-
*/
|
|
8942
|
-
static accumulationResult(block) {
|
|
8943
|
-
return block.accumulationResult;
|
|
8944
|
-
}
|
|
8945
|
-
constructor(current) {
|
|
8946
|
-
super();
|
|
8947
|
-
this.current = current;
|
|
8948
|
-
}
|
|
8949
|
-
/** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
|
|
8950
|
-
get blocks() {
|
|
8951
|
-
if (this.current !== null) {
|
|
8952
|
-
return this.current.blocks;
|
|
8953
|
-
}
|
|
8954
|
-
throw new Error("RecentBlocksHistory is in invalid state");
|
|
8955
|
-
}
|
|
8956
|
-
asCurrent() {
|
|
8957
|
-
if (this.current === null) {
|
|
8958
|
-
throw new Error("Cannot access current RecentBlocks format");
|
|
8959
|
-
}
|
|
8960
|
-
return this.current;
|
|
8961
|
-
}
|
|
8962
|
-
updateBlocks(blocks) {
|
|
8963
|
-
if (this.current !== null) {
|
|
8964
|
-
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
8965
|
-
...this.current,
|
|
8966
|
-
blocks: asOpaqueType(blocks),
|
|
8967
|
-
}));
|
|
8968
|
-
}
|
|
8969
|
-
throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
|
|
8970
|
-
}
|
|
8971
|
-
}
|
|
8324
|
+
|
|
8325
|
+
const recentlyAccumulatedCodec = codecPerEpochBlock(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
|
|
8972
8326
|
|
|
8973
8327
|
/**
|
|
8974
8328
|
* Fixed size of validator metadata.
|
|
@@ -9011,6 +8365,7 @@ class ValidatorData extends WithDebug {
|
|
|
9011
8365
|
this.metadata = metadata;
|
|
9012
8366
|
}
|
|
9013
8367
|
}
|
|
8368
|
+
const validatorsDataCodec = codecPerValidator(ValidatorData.Codec);
|
|
9014
8369
|
|
|
9015
8370
|
var SafroleSealingKeysKind;
|
|
9016
8371
|
(function (SafroleSealingKeysKind) {
|
|
@@ -9126,6 +8481,23 @@ const zeroSizeHint = {
|
|
|
9126
8481
|
};
|
|
9127
8482
|
/** 0-byte read, return given default value */
|
|
9128
8483
|
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8484
|
+
/** Encode and decode object with leading version number. */
|
|
8485
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8486
|
+
bytes: val.sizeHint.bytes + 8,
|
|
8487
|
+
isExact: false,
|
|
8488
|
+
}, (e, v) => {
|
|
8489
|
+
e.varU64(0n);
|
|
8490
|
+
val.encode(e, v);
|
|
8491
|
+
}, (d) => {
|
|
8492
|
+
const version = d.varU64();
|
|
8493
|
+
if (version !== 0n) {
|
|
8494
|
+
throw new Error("Non-zero version is not supported!");
|
|
8495
|
+
}
|
|
8496
|
+
return val.decode(d);
|
|
8497
|
+
}, (s) => {
|
|
8498
|
+
s.varU64();
|
|
8499
|
+
val.skip(s);
|
|
8500
|
+
});
|
|
9129
8501
|
/**
|
|
9130
8502
|
* Service account details.
|
|
9131
8503
|
*
|
|
@@ -9268,163 +8640,6 @@ class LookupHistoryItem {
|
|
|
9268
8640
|
}
|
|
9269
8641
|
}
|
|
9270
8642
|
|
|
9271
|
-
/**
|
|
9272
|
-
* In addition to the entropy accumulator η_0, we retain
|
|
9273
|
-
* three additional historical values of the accumulator at
|
|
9274
|
-
* the point of each of the three most recently ended epochs,
|
|
9275
|
-
* η_1, η_2 and η_3. The second-oldest of these η2 is utilized to
|
|
9276
|
-
* help ensure future entropy is unbiased (see equation 6.29)
|
|
9277
|
-
* and seed the fallback seal-key generation function with
|
|
9278
|
-
* randomness (see equation 6.24). The oldest is used to re-
|
|
9279
|
-
* generate this randomness when verifying the seal above
|
|
9280
|
-
* (see equations 6.16 and 6.15).
|
|
9281
|
-
*
|
|
9282
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/0ef5010ef501
|
|
9283
|
-
*/
|
|
9284
|
-
const ENTROPY_ENTRIES = 4;
|
|
9285
|
-
|
|
9286
|
-
var UpdatePreimageKind;
|
|
9287
|
-
(function (UpdatePreimageKind) {
|
|
9288
|
-
/** Insert new preimage and optionally update it's lookup history. */
|
|
9289
|
-
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
9290
|
-
/** Remove a preimage and it's lookup history. */
|
|
9291
|
-
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
9292
|
-
/** update or add lookup history for preimage hash/len to given value. */
|
|
9293
|
-
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
9294
|
-
})(UpdatePreimageKind || (UpdatePreimageKind = {}));
|
|
9295
|
-
/**
|
|
9296
|
-
* A preimage update.
|
|
9297
|
-
*
|
|
9298
|
-
* Can be one of the following cases:
|
|
9299
|
-
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
9300
|
-
* 2. Remove (expunge) a preimage and it's lookup history.
|
|
9301
|
-
* 3. Update `LookupHistory` with given value.
|
|
9302
|
-
*/
|
|
9303
|
-
class UpdatePreimage {
|
|
9304
|
-
serviceId;
|
|
9305
|
-
action;
|
|
9306
|
-
constructor(serviceId, action) {
|
|
9307
|
-
this.serviceId = serviceId;
|
|
9308
|
-
this.action = action;
|
|
9309
|
-
}
|
|
9310
|
-
/** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
|
|
9311
|
-
static provide({ serviceId, preimage, slot, }) {
|
|
9312
|
-
return new UpdatePreimage(serviceId, {
|
|
9313
|
-
kind: UpdatePreimageKind.Provide,
|
|
9314
|
-
preimage,
|
|
9315
|
-
slot,
|
|
9316
|
-
});
|
|
9317
|
-
}
|
|
9318
|
-
/** The preimage should be removed completely from the database. */
|
|
9319
|
-
static remove({ serviceId, hash, length }) {
|
|
9320
|
-
return new UpdatePreimage(serviceId, {
|
|
9321
|
-
kind: UpdatePreimageKind.Remove,
|
|
9322
|
-
hash,
|
|
9323
|
-
length,
|
|
9324
|
-
});
|
|
9325
|
-
}
|
|
9326
|
-
/** Update the lookup history of some preimage or add a new one (request). */
|
|
9327
|
-
static updateOrAdd({ serviceId, lookupHistory }) {
|
|
9328
|
-
return new UpdatePreimage(serviceId, {
|
|
9329
|
-
kind: UpdatePreimageKind.UpdateOrAdd,
|
|
9330
|
-
item: lookupHistory,
|
|
9331
|
-
});
|
|
9332
|
-
}
|
|
9333
|
-
get hash() {
|
|
9334
|
-
switch (this.action.kind) {
|
|
9335
|
-
case UpdatePreimageKind.Provide:
|
|
9336
|
-
return this.action.preimage.hash;
|
|
9337
|
-
case UpdatePreimageKind.Remove:
|
|
9338
|
-
return this.action.hash;
|
|
9339
|
-
case UpdatePreimageKind.UpdateOrAdd:
|
|
9340
|
-
return this.action.item.hash;
|
|
9341
|
-
}
|
|
9342
|
-
throw assertNever(this.action);
|
|
9343
|
-
}
|
|
9344
|
-
get length() {
|
|
9345
|
-
switch (this.action.kind) {
|
|
9346
|
-
case UpdatePreimageKind.Provide:
|
|
9347
|
-
return tryAsU32(this.action.preimage.blob.length);
|
|
9348
|
-
case UpdatePreimageKind.Remove:
|
|
9349
|
-
return this.action.length;
|
|
9350
|
-
case UpdatePreimageKind.UpdateOrAdd:
|
|
9351
|
-
return this.action.item.length;
|
|
9352
|
-
}
|
|
9353
|
-
throw assertNever(this.action);
|
|
9354
|
-
}
|
|
9355
|
-
}
|
|
9356
|
-
/** The type of service update. */
|
|
9357
|
-
var UpdateServiceKind;
|
|
9358
|
-
(function (UpdateServiceKind) {
|
|
9359
|
-
/** Just update the `ServiceAccountInfo`. */
|
|
9360
|
-
UpdateServiceKind[UpdateServiceKind["Update"] = 0] = "Update";
|
|
9361
|
-
/** Create a new `Service` instance. */
|
|
9362
|
-
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
9363
|
-
})(UpdateServiceKind || (UpdateServiceKind = {}));
|
|
9364
|
-
/**
|
|
9365
|
-
* Update service info of a particular `ServiceId` or create a new one.
|
|
9366
|
-
*/
|
|
9367
|
-
class UpdateService {
|
|
9368
|
-
serviceId;
|
|
9369
|
-
action;
|
|
9370
|
-
constructor(serviceId, action) {
|
|
9371
|
-
this.serviceId = serviceId;
|
|
9372
|
-
this.action = action;
|
|
9373
|
-
}
|
|
9374
|
-
static update({ serviceId, serviceInfo }) {
|
|
9375
|
-
return new UpdateService(serviceId, {
|
|
9376
|
-
kind: UpdateServiceKind.Update,
|
|
9377
|
-
account: serviceInfo,
|
|
9378
|
-
});
|
|
9379
|
-
}
|
|
9380
|
-
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
9381
|
-
return new UpdateService(serviceId, {
|
|
9382
|
-
kind: UpdateServiceKind.Create,
|
|
9383
|
-
account: serviceInfo,
|
|
9384
|
-
lookupHistory,
|
|
9385
|
-
});
|
|
9386
|
-
}
|
|
9387
|
-
}
|
|
9388
|
-
/** Update service storage kind. */
|
|
9389
|
-
var UpdateStorageKind;
|
|
9390
|
-
(function (UpdateStorageKind) {
|
|
9391
|
-
/** Set a storage value. */
|
|
9392
|
-
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
9393
|
-
/** Remove a storage value. */
|
|
9394
|
-
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
9395
|
-
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
9396
|
-
/**
|
|
9397
|
-
* Update service storage item.
|
|
9398
|
-
*
|
|
9399
|
-
* Can either create/modify an entry or remove it.
|
|
9400
|
-
*/
|
|
9401
|
-
class UpdateStorage {
|
|
9402
|
-
serviceId;
|
|
9403
|
-
action;
|
|
9404
|
-
constructor(serviceId, action) {
|
|
9405
|
-
this.serviceId = serviceId;
|
|
9406
|
-
this.action = action;
|
|
9407
|
-
}
|
|
9408
|
-
static set({ serviceId, storage }) {
|
|
9409
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
9410
|
-
}
|
|
9411
|
-
static remove({ serviceId, key }) {
|
|
9412
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
9413
|
-
}
|
|
9414
|
-
get key() {
|
|
9415
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9416
|
-
return this.action.key;
|
|
9417
|
-
}
|
|
9418
|
-
return this.action.storage.key;
|
|
9419
|
-
}
|
|
9420
|
-
get value() {
|
|
9421
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9422
|
-
return null;
|
|
9423
|
-
}
|
|
9424
|
-
return this.action.storage.value;
|
|
9425
|
-
}
|
|
9426
|
-
}
|
|
9427
|
-
|
|
9428
8643
|
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
9429
8644
|
? codec$1.u32.asOpaque()
|
|
9430
8645
|
: codec$1.varU32.convert((s) => tryAsU32(s), (i) => tryAsServiceId(i));
|
|
@@ -9556,8 +8771,7 @@ class CoreStatistics {
|
|
|
9556
8771
|
* Service statistics.
|
|
9557
8772
|
* Updated per block, based on available work reports (`W`).
|
|
9558
8773
|
*
|
|
9559
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9560
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L77
|
|
8774
|
+
* https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
|
|
9561
8775
|
*/
|
|
9562
8776
|
class ServiceStatistics {
|
|
9563
8777
|
providedCount;
|
|
@@ -9572,22 +8786,8 @@ class ServiceStatistics {
|
|
|
9572
8786
|
accumulateGasUsed;
|
|
9573
8787
|
onTransfersCount;
|
|
9574
8788
|
onTransfersGasUsed;
|
|
9575
|
-
static Codec = Compatibility.
|
|
9576
|
-
|
|
9577
|
-
providedCount: codecVarU16,
|
|
9578
|
-
providedSize: codec$1.varU32,
|
|
9579
|
-
refinementCount: codec$1.varU32,
|
|
9580
|
-
refinementGasUsed: codecVarGas,
|
|
9581
|
-
imports: codecVarU16,
|
|
9582
|
-
extrinsicCount: codecVarU16,
|
|
9583
|
-
extrinsicSize: codec$1.varU32,
|
|
9584
|
-
exports: codecVarU16,
|
|
9585
|
-
accumulateCount: codec$1.varU32,
|
|
9586
|
-
accumulateGasUsed: codecVarGas,
|
|
9587
|
-
onTransfersCount: codec$1.varU32,
|
|
9588
|
-
onTransfersGasUsed: codecVarGas,
|
|
9589
|
-
})
|
|
9590
|
-
: codec$1.Class(ServiceStatistics, {
|
|
8789
|
+
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
8790
|
+
fallback: codec$1.Class(ServiceStatistics, {
|
|
9591
8791
|
providedCount: codecVarU16,
|
|
9592
8792
|
providedSize: codec$1.varU32,
|
|
9593
8793
|
refinementCount: codec$1.varU32,
|
|
@@ -9600,7 +8800,38 @@ class ServiceStatistics {
|
|
|
9600
8800
|
accumulateGasUsed: codecVarGas,
|
|
9601
8801
|
onTransfersCount: codec$1.varU32,
|
|
9602
8802
|
onTransfersGasUsed: codecVarGas,
|
|
9603
|
-
})
|
|
8803
|
+
}),
|
|
8804
|
+
versions: {
|
|
8805
|
+
[GpVersion.V0_7_0]: codec$1.Class(ServiceStatistics, {
|
|
8806
|
+
providedCount: codecVarU16,
|
|
8807
|
+
providedSize: codec$1.varU32,
|
|
8808
|
+
refinementCount: codec$1.varU32,
|
|
8809
|
+
refinementGasUsed: codecVarGas,
|
|
8810
|
+
imports: codecVarU16,
|
|
8811
|
+
extrinsicCount: codecVarU16,
|
|
8812
|
+
extrinsicSize: codec$1.varU32,
|
|
8813
|
+
exports: codecVarU16,
|
|
8814
|
+
accumulateCount: codec$1.varU32,
|
|
8815
|
+
accumulateGasUsed: codecVarGas,
|
|
8816
|
+
onTransfersCount: codec$1.varU32,
|
|
8817
|
+
onTransfersGasUsed: codecVarGas,
|
|
8818
|
+
}),
|
|
8819
|
+
[GpVersion.V0_7_1]: codec$1.Class(ServiceStatistics, {
|
|
8820
|
+
providedCount: codecVarU16,
|
|
8821
|
+
providedSize: codec$1.varU32,
|
|
8822
|
+
refinementCount: codec$1.varU32,
|
|
8823
|
+
refinementGasUsed: codecVarGas,
|
|
8824
|
+
imports: codecVarU16,
|
|
8825
|
+
extrinsicCount: codecVarU16,
|
|
8826
|
+
extrinsicSize: codec$1.varU32,
|
|
8827
|
+
exports: codecVarU16,
|
|
8828
|
+
accumulateCount: codec$1.varU32,
|
|
8829
|
+
accumulateGasUsed: codecVarGas,
|
|
8830
|
+
onTransfersCount: ignoreValueWithDefault(tryAsU32(0)),
|
|
8831
|
+
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
8832
|
+
}),
|
|
8833
|
+
},
|
|
8834
|
+
});
|
|
9604
8835
|
static create(v) {
|
|
9605
8836
|
return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
|
|
9606
8837
|
}
|
|
@@ -9625,9 +8856,9 @@ class ServiceStatistics {
|
|
|
9625
8856
|
accumulateCount,
|
|
9626
8857
|
/** `a.1` */
|
|
9627
8858
|
accumulateGasUsed,
|
|
9628
|
-
/** `t.0` */
|
|
8859
|
+
/** `t.0` @deprecated since 0.7.1 */
|
|
9629
8860
|
onTransfersCount,
|
|
9630
|
-
/** `t.1` */
|
|
8861
|
+
/** `t.1` @deprecated since 0.7.1 */
|
|
9631
8862
|
onTransfersGasUsed) {
|
|
9632
8863
|
this.providedCount = providedCount;
|
|
9633
8864
|
this.providedSize = providedSize;
|
|
@@ -9642,35 +8873,312 @@ class ServiceStatistics {
|
|
|
9642
8873
|
this.onTransfersCount = onTransfersCount;
|
|
9643
8874
|
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
9644
8875
|
}
|
|
9645
|
-
static empty() {
|
|
9646
|
-
const zero = tryAsU32(0);
|
|
9647
|
-
const zero16 = tryAsU16(0);
|
|
9648
|
-
const zeroGas = tryAsServiceGas(0);
|
|
9649
|
-
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
8876
|
+
static empty() {
|
|
8877
|
+
const zero = tryAsU32(0);
|
|
8878
|
+
const zero16 = tryAsU16(0);
|
|
8879
|
+
const zeroGas = tryAsServiceGas(0);
|
|
8880
|
+
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
8881
|
+
}
|
|
8882
|
+
}
|
|
8883
|
+
/** `pi`: Statistics of each validator, cores statistics and services statistics. */
|
|
8884
|
+
class StatisticsData {
|
|
8885
|
+
current;
|
|
8886
|
+
previous;
|
|
8887
|
+
cores;
|
|
8888
|
+
services;
|
|
8889
|
+
static Codec = codec$1.Class(StatisticsData, {
|
|
8890
|
+
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
8891
|
+
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
8892
|
+
cores: codecPerCore(CoreStatistics.Codec),
|
|
8893
|
+
services: codec$1.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
8894
|
+
sortKeys: (a, b) => a - b,
|
|
8895
|
+
}),
|
|
8896
|
+
});
|
|
8897
|
+
static create(v) {
|
|
8898
|
+
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
8899
|
+
}
|
|
8900
|
+
constructor(current, previous, cores, services) {
|
|
8901
|
+
this.current = current;
|
|
8902
|
+
this.previous = previous;
|
|
8903
|
+
this.cores = cores;
|
|
8904
|
+
this.services = services;
|
|
8905
|
+
}
|
|
8906
|
+
}
|
|
8907
|
+
|
|
8908
|
+
class InMemoryStateView {
|
|
8909
|
+
chainSpec;
|
|
8910
|
+
state;
|
|
8911
|
+
constructor(chainSpec, state) {
|
|
8912
|
+
this.chainSpec = chainSpec;
|
|
8913
|
+
this.state = state;
|
|
8914
|
+
}
|
|
8915
|
+
availabilityAssignmentView() {
|
|
8916
|
+
return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
|
|
8917
|
+
}
|
|
8918
|
+
designatedValidatorDataView() {
|
|
8919
|
+
return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
|
|
8920
|
+
}
|
|
8921
|
+
currentValidatorDataView() {
|
|
8922
|
+
return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
|
|
8923
|
+
}
|
|
8924
|
+
previousValidatorDataView() {
|
|
8925
|
+
return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
|
|
8926
|
+
}
|
|
8927
|
+
authPoolsView() {
|
|
8928
|
+
return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
|
|
8929
|
+
}
|
|
8930
|
+
authQueuesView() {
|
|
8931
|
+
return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
|
|
8932
|
+
}
|
|
8933
|
+
recentBlocksView() {
|
|
8934
|
+
return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
|
|
8935
|
+
}
|
|
8936
|
+
statisticsView() {
|
|
8937
|
+
return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
|
|
8938
|
+
}
|
|
8939
|
+
accumulationQueueView() {
|
|
8940
|
+
return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
|
|
8941
|
+
}
|
|
8942
|
+
recentlyAccumulatedView() {
|
|
8943
|
+
return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
|
|
8944
|
+
}
|
|
8945
|
+
safroleDataView() {
|
|
8946
|
+
// TODO [ToDr] Consider exposting `safrole` from state
|
|
8947
|
+
// instead of individual fields
|
|
8948
|
+
const safrole = SafroleData.create({
|
|
8949
|
+
nextValidatorData: this.state.nextValidatorData,
|
|
8950
|
+
epochRoot: this.state.epochRoot,
|
|
8951
|
+
sealingKeySeries: this.state.sealingKeySeries,
|
|
8952
|
+
ticketsAccumulator: this.state.ticketsAccumulator,
|
|
8953
|
+
});
|
|
8954
|
+
return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
|
|
8955
|
+
}
|
|
8956
|
+
getServiceInfoView(id) {
|
|
8957
|
+
const service = this.state.getService(id);
|
|
8958
|
+
if (service === null) {
|
|
8959
|
+
return null;
|
|
8960
|
+
}
|
|
8961
|
+
return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
|
|
8962
|
+
}
|
|
8963
|
+
}
|
|
8964
|
+
|
|
8965
|
+
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8966
|
+
class AutoAccumulate {
|
|
8967
|
+
service;
|
|
8968
|
+
gasLimit;
|
|
8969
|
+
static Codec = codec$1.Class(AutoAccumulate, {
|
|
8970
|
+
service: codec$1.u32.asOpaque(),
|
|
8971
|
+
gasLimit: codec$1.u64.asOpaque(),
|
|
8972
|
+
});
|
|
8973
|
+
static create({ service, gasLimit }) {
|
|
8974
|
+
return new AutoAccumulate(service, gasLimit);
|
|
8975
|
+
}
|
|
8976
|
+
constructor(
|
|
8977
|
+
/** Service id that auto-accumulates. */
|
|
8978
|
+
service,
|
|
8979
|
+
/** Gas limit for auto-accumulation. */
|
|
8980
|
+
gasLimit) {
|
|
8981
|
+
this.service = service;
|
|
8982
|
+
this.gasLimit = gasLimit;
|
|
8983
|
+
}
|
|
8984
|
+
}
|
|
8985
|
+
/**
|
|
8986
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8987
|
+
*/
|
|
8988
|
+
class PrivilegedServices {
|
|
8989
|
+
manager;
|
|
8990
|
+
delegator;
|
|
8991
|
+
registrar;
|
|
8992
|
+
assigners;
|
|
8993
|
+
autoAccumulateServices;
|
|
8994
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
8995
|
+
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8996
|
+
manager: codec$1.u32.asOpaque(),
|
|
8997
|
+
assigners: codecPerCore(codec$1.u32.asOpaque()),
|
|
8998
|
+
delegator: codec$1.u32.asOpaque(),
|
|
8999
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9000
|
+
? codec$1.u32.asOpaque()
|
|
9001
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
9002
|
+
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
9003
|
+
});
|
|
9004
|
+
static create(a) {
|
|
9005
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
9006
|
+
}
|
|
9007
|
+
constructor(
|
|
9008
|
+
/**
|
|
9009
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
9010
|
+
* as well as bestow services with storage deposit credits.
|
|
9011
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9012
|
+
*/
|
|
9013
|
+
manager,
|
|
9014
|
+
/** `χ_V`: Managers validator keys. */
|
|
9015
|
+
delegator,
|
|
9016
|
+
/**
|
|
9017
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
9018
|
+
*
|
|
9019
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
9020
|
+
*/
|
|
9021
|
+
registrar,
|
|
9022
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
9023
|
+
assigners,
|
|
9024
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
9025
|
+
autoAccumulateServices) {
|
|
9026
|
+
this.manager = manager;
|
|
9027
|
+
this.delegator = delegator;
|
|
9028
|
+
this.registrar = registrar;
|
|
9029
|
+
this.assigners = assigners;
|
|
9030
|
+
this.autoAccumulateServices = autoAccumulateServices;
|
|
9031
|
+
}
|
|
9032
|
+
}
|
|
9033
|
+
|
|
9034
|
+
/**
|
|
9035
|
+
* In addition to the entropy accumulator η_0, we retain
|
|
9036
|
+
* three additional historical values of the accumulator at
|
|
9037
|
+
* the point of each of the three most recently ended epochs,
|
|
9038
|
+
* η_1, η_2 and η_3. The second-oldest of these η2 is utilized to
|
|
9039
|
+
* help ensure future entropy is unbiased (see equation 6.29)
|
|
9040
|
+
* and seed the fallback seal-key generation function with
|
|
9041
|
+
* randomness (see equation 6.24). The oldest is used to re-
|
|
9042
|
+
* generate this randomness when verifying the seal above
|
|
9043
|
+
* (see equations 6.16 and 6.15).
|
|
9044
|
+
*
|
|
9045
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/0ef5010ef501
|
|
9046
|
+
*/
|
|
9047
|
+
const ENTROPY_ENTRIES = 4;
|
|
9048
|
+
|
|
9049
|
+
var UpdatePreimageKind;
|
|
9050
|
+
(function (UpdatePreimageKind) {
|
|
9051
|
+
/** Insert new preimage and optionally update it's lookup history. */
|
|
9052
|
+
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
9053
|
+
/** Remove a preimage and it's lookup history. */
|
|
9054
|
+
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
9055
|
+
/** update or add lookup history for preimage hash/len to given value. */
|
|
9056
|
+
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
9057
|
+
})(UpdatePreimageKind || (UpdatePreimageKind = {}));
|
|
9058
|
+
/**
|
|
9059
|
+
* A preimage update.
|
|
9060
|
+
*
|
|
9061
|
+
* Can be one of the following cases:
|
|
9062
|
+
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
9063
|
+
* 2. Remove (expunge) a preimage and it's lookup history.
|
|
9064
|
+
* 3. Update `LookupHistory` with given value.
|
|
9065
|
+
*/
|
|
9066
|
+
class UpdatePreimage {
|
|
9067
|
+
action;
|
|
9068
|
+
constructor(action) {
|
|
9069
|
+
this.action = action;
|
|
9070
|
+
}
|
|
9071
|
+
/** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
|
|
9072
|
+
static provide({ preimage, slot }) {
|
|
9073
|
+
return new UpdatePreimage({
|
|
9074
|
+
kind: UpdatePreimageKind.Provide,
|
|
9075
|
+
preimage,
|
|
9076
|
+
slot,
|
|
9077
|
+
});
|
|
9078
|
+
}
|
|
9079
|
+
/** The preimage should be removed completely from the database. */
|
|
9080
|
+
static remove({ hash, length }) {
|
|
9081
|
+
return new UpdatePreimage({
|
|
9082
|
+
kind: UpdatePreimageKind.Remove,
|
|
9083
|
+
hash,
|
|
9084
|
+
length,
|
|
9085
|
+
});
|
|
9086
|
+
}
|
|
9087
|
+
/** Update the lookup history of some preimage or add a new one (request). */
|
|
9088
|
+
static updateOrAdd({ lookupHistory }) {
|
|
9089
|
+
return new UpdatePreimage({
|
|
9090
|
+
kind: UpdatePreimageKind.UpdateOrAdd,
|
|
9091
|
+
item: lookupHistory,
|
|
9092
|
+
});
|
|
9093
|
+
}
|
|
9094
|
+
get hash() {
|
|
9095
|
+
switch (this.action.kind) {
|
|
9096
|
+
case UpdatePreimageKind.Provide:
|
|
9097
|
+
return this.action.preimage.hash;
|
|
9098
|
+
case UpdatePreimageKind.Remove:
|
|
9099
|
+
return this.action.hash;
|
|
9100
|
+
case UpdatePreimageKind.UpdateOrAdd:
|
|
9101
|
+
return this.action.item.hash;
|
|
9102
|
+
}
|
|
9103
|
+
throw assertNever(this.action);
|
|
9104
|
+
}
|
|
9105
|
+
get length() {
|
|
9106
|
+
switch (this.action.kind) {
|
|
9107
|
+
case UpdatePreimageKind.Provide:
|
|
9108
|
+
return tryAsU32(this.action.preimage.blob.length);
|
|
9109
|
+
case UpdatePreimageKind.Remove:
|
|
9110
|
+
return this.action.length;
|
|
9111
|
+
case UpdatePreimageKind.UpdateOrAdd:
|
|
9112
|
+
return this.action.item.length;
|
|
9113
|
+
}
|
|
9114
|
+
throw assertNever(this.action);
|
|
9115
|
+
}
|
|
9116
|
+
}
|
|
9117
|
+
/** The type of service update. */
|
|
9118
|
+
var UpdateServiceKind;
|
|
9119
|
+
(function (UpdateServiceKind) {
|
|
9120
|
+
/** Just update the `ServiceAccountInfo`. */
|
|
9121
|
+
UpdateServiceKind[UpdateServiceKind["Update"] = 0] = "Update";
|
|
9122
|
+
/** Create a new `Service` instance. */
|
|
9123
|
+
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
9124
|
+
})(UpdateServiceKind || (UpdateServiceKind = {}));
|
|
9125
|
+
/**
|
|
9126
|
+
* Update service info or create a new one.
|
|
9127
|
+
*/
|
|
9128
|
+
class UpdateService {
|
|
9129
|
+
action;
|
|
9130
|
+
constructor(action) {
|
|
9131
|
+
this.action = action;
|
|
9132
|
+
}
|
|
9133
|
+
static update({ serviceInfo }) {
|
|
9134
|
+
return new UpdateService({
|
|
9135
|
+
kind: UpdateServiceKind.Update,
|
|
9136
|
+
account: serviceInfo,
|
|
9137
|
+
});
|
|
9138
|
+
}
|
|
9139
|
+
static create({ serviceInfo, lookupHistory, }) {
|
|
9140
|
+
return new UpdateService({
|
|
9141
|
+
kind: UpdateServiceKind.Create,
|
|
9142
|
+
account: serviceInfo,
|
|
9143
|
+
lookupHistory,
|
|
9144
|
+
});
|
|
9145
|
+
}
|
|
9146
|
+
}
|
|
9147
|
+
/** Update service storage kind. */
|
|
9148
|
+
var UpdateStorageKind;
|
|
9149
|
+
(function (UpdateStorageKind) {
|
|
9150
|
+
/** Set a storage value. */
|
|
9151
|
+
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
9152
|
+
/** Remove a storage value. */
|
|
9153
|
+
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
9154
|
+
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
9155
|
+
/**
|
|
9156
|
+
* Update service storage item.
|
|
9157
|
+
*
|
|
9158
|
+
* Can either create/modify an entry or remove it.
|
|
9159
|
+
*/
|
|
9160
|
+
class UpdateStorage {
|
|
9161
|
+
action;
|
|
9162
|
+
constructor(action) {
|
|
9163
|
+
this.action = action;
|
|
9164
|
+
}
|
|
9165
|
+
static set({ storage }) {
|
|
9166
|
+
return new UpdateStorage({ kind: UpdateStorageKind.Set, storage });
|
|
9650
9167
|
}
|
|
9651
|
-
}
|
|
9652
|
-
|
|
9653
|
-
class StatisticsData {
|
|
9654
|
-
current;
|
|
9655
|
-
previous;
|
|
9656
|
-
cores;
|
|
9657
|
-
services;
|
|
9658
|
-
static Codec = codec$1.Class(StatisticsData, {
|
|
9659
|
-
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
9660
|
-
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
9661
|
-
cores: codecPerCore(CoreStatistics.Codec),
|
|
9662
|
-
services: codec$1.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
9663
|
-
sortKeys: (a, b) => a - b,
|
|
9664
|
-
}),
|
|
9665
|
-
});
|
|
9666
|
-
static create(v) {
|
|
9667
|
-
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
9168
|
+
static remove({ key }) {
|
|
9169
|
+
return new UpdateStorage({ kind: UpdateStorageKind.Remove, key });
|
|
9668
9170
|
}
|
|
9669
|
-
|
|
9670
|
-
this.
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
this.
|
|
9171
|
+
get key() {
|
|
9172
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9173
|
+
return this.action.key;
|
|
9174
|
+
}
|
|
9175
|
+
return this.action.storage.key;
|
|
9176
|
+
}
|
|
9177
|
+
get value() {
|
|
9178
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9179
|
+
return null;
|
|
9180
|
+
}
|
|
9181
|
+
return this.action.storage.value;
|
|
9674
9182
|
}
|
|
9675
9183
|
}
|
|
9676
9184
|
|
|
@@ -9773,9 +9281,10 @@ class InMemoryService extends WithDebug {
|
|
|
9773
9281
|
* A special version of state, stored fully in-memory.
|
|
9774
9282
|
*/
|
|
9775
9283
|
class InMemoryState extends WithDebug {
|
|
9284
|
+
chainSpec;
|
|
9776
9285
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
9777
|
-
static
|
|
9778
|
-
return new InMemoryState(state);
|
|
9286
|
+
static new(chainSpec, state) {
|
|
9287
|
+
return new InMemoryState(chainSpec, state);
|
|
9779
9288
|
}
|
|
9780
9289
|
/**
|
|
9781
9290
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -9791,7 +9300,7 @@ class InMemoryState extends WithDebug {
|
|
|
9791
9300
|
/**
|
|
9792
9301
|
* Create a new `InMemoryState` from some other state object.
|
|
9793
9302
|
*/
|
|
9794
|
-
static copyFrom(other, servicesData) {
|
|
9303
|
+
static copyFrom(chainSpec, other, servicesData) {
|
|
9795
9304
|
const services = new Map();
|
|
9796
9305
|
for (const [id, entries] of servicesData.entries()) {
|
|
9797
9306
|
const service = other.getService(id);
|
|
@@ -9801,7 +9310,7 @@ class InMemoryState extends WithDebug {
|
|
|
9801
9310
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
9802
9311
|
services.set(id, inMemService);
|
|
9803
9312
|
}
|
|
9804
|
-
return InMemoryState.
|
|
9313
|
+
return InMemoryState.new(chainSpec, {
|
|
9805
9314
|
availabilityAssignment: other.availabilityAssignment,
|
|
9806
9315
|
accumulationQueue: other.accumulationQueue,
|
|
9807
9316
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -9842,12 +9351,12 @@ class InMemoryState extends WithDebug {
|
|
|
9842
9351
|
* Modify the state and apply a single state update.
|
|
9843
9352
|
*/
|
|
9844
9353
|
applyUpdate(update) {
|
|
9845
|
-
const {
|
|
9354
|
+
const { removed, created: _, updated, preimages, storage, ...rest } = update;
|
|
9846
9355
|
// just assign all other variables
|
|
9847
9356
|
Object.assign(this, rest);
|
|
9848
9357
|
// and update the services state
|
|
9849
9358
|
let result;
|
|
9850
|
-
result = this.updateServices(
|
|
9359
|
+
result = this.updateServices(updated);
|
|
9851
9360
|
if (result.isError) {
|
|
9852
9361
|
return result;
|
|
9853
9362
|
}
|
|
@@ -9859,7 +9368,7 @@ class InMemoryState extends WithDebug {
|
|
|
9859
9368
|
if (result.isError) {
|
|
9860
9369
|
return result;
|
|
9861
9370
|
}
|
|
9862
|
-
this.removeServices(
|
|
9371
|
+
this.removeServices(removed);
|
|
9863
9372
|
return Result$1.ok(OK);
|
|
9864
9373
|
}
|
|
9865
9374
|
removeServices(servicesRemoved) {
|
|
@@ -9868,89 +9377,102 @@ class InMemoryState extends WithDebug {
|
|
|
9868
9377
|
this.services.delete(serviceId);
|
|
9869
9378
|
}
|
|
9870
9379
|
}
|
|
9871
|
-
updateStorage(
|
|
9872
|
-
|
|
9873
|
-
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9380
|
+
updateStorage(storageUpdates) {
|
|
9381
|
+
if (storageUpdates === undefined) {
|
|
9382
|
+
return Result$1.ok(OK);
|
|
9383
|
+
}
|
|
9384
|
+
for (const [serviceId, updates] of storageUpdates.entries()) {
|
|
9385
|
+
for (const update of updates) {
|
|
9386
|
+
const { kind } = update.action;
|
|
9387
|
+
const service = this.services.get(serviceId);
|
|
9388
|
+
if (service === undefined) {
|
|
9389
|
+
return Result$1.error(UpdateError.NoService, () => `Attempting to update storage of non-existing service: ${serviceId}`);
|
|
9390
|
+
}
|
|
9391
|
+
if (kind === UpdateStorageKind.Set) {
|
|
9392
|
+
const { key, value } = update.action.storage;
|
|
9393
|
+
service.data.storage.set(key.toString(), StorageItem.create({ key, value }));
|
|
9394
|
+
}
|
|
9395
|
+
else if (kind === UpdateStorageKind.Remove) {
|
|
9396
|
+
const { key } = update.action;
|
|
9397
|
+
check `
|
|
9885
9398
|
${service.data.storage.has(key.toString())}
|
|
9886
|
-
Attempting to remove non-existing storage item at ${serviceId}: ${action.key}
|
|
9399
|
+
Attempting to remove non-existing storage item at ${serviceId}: ${update.action.key}
|
|
9887
9400
|
`;
|
|
9888
|
-
|
|
9889
|
-
|
|
9890
|
-
|
|
9891
|
-
|
|
9401
|
+
service.data.storage.delete(key.toString());
|
|
9402
|
+
}
|
|
9403
|
+
else {
|
|
9404
|
+
assertNever(kind);
|
|
9405
|
+
}
|
|
9892
9406
|
}
|
|
9893
9407
|
}
|
|
9894
9408
|
return Result$1.ok(OK);
|
|
9895
9409
|
}
|
|
9896
|
-
updatePreimages(
|
|
9897
|
-
|
|
9410
|
+
updatePreimages(preimagesUpdates) {
|
|
9411
|
+
if (preimagesUpdates === undefined) {
|
|
9412
|
+
return Result$1.ok(OK);
|
|
9413
|
+
}
|
|
9414
|
+
for (const [serviceId, updates] of preimagesUpdates.entries()) {
|
|
9898
9415
|
const service = this.services.get(serviceId);
|
|
9899
9416
|
if (service === undefined) {
|
|
9900
|
-
return Result$1.error(UpdateError.NoService, `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
9417
|
+
return Result$1.error(UpdateError.NoService, () => `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
9901
9418
|
}
|
|
9902
|
-
const
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
|
|
9907
|
-
|
|
9908
|
-
service.data.preimages.set(preimage.hash, preimage);
|
|
9909
|
-
if (slot !== null) {
|
|
9910
|
-
const lookupHistory = service.data.lookupHistory.get(preimage.hash);
|
|
9911
|
-
const length = tryAsU32(preimage.blob.length);
|
|
9912
|
-
const lookup = new LookupHistoryItem(preimage.hash, length, tryAsLookupHistorySlots([slot]));
|
|
9913
|
-
if (lookupHistory === undefined) {
|
|
9914
|
-
// no lookup history for that preimage at all (edge case, should be requested)
|
|
9915
|
-
service.data.lookupHistory.set(preimage.hash, [lookup]);
|
|
9419
|
+
for (const update of updates) {
|
|
9420
|
+
const { kind } = update.action;
|
|
9421
|
+
if (kind === UpdatePreimageKind.Provide) {
|
|
9422
|
+
const { preimage, slot } = update.action;
|
|
9423
|
+
if (service.data.preimages.has(preimage.hash)) {
|
|
9424
|
+
return Result$1.error(UpdateError.PreimageExists, () => `Overwriting existing preimage at ${serviceId}: ${preimage}`);
|
|
9916
9425
|
}
|
|
9917
|
-
|
|
9918
|
-
|
|
9919
|
-
const
|
|
9920
|
-
|
|
9426
|
+
service.data.preimages.set(preimage.hash, preimage);
|
|
9427
|
+
if (slot !== null) {
|
|
9428
|
+
const lookupHistory = service.data.lookupHistory.get(preimage.hash);
|
|
9429
|
+
const length = tryAsU32(preimage.blob.length);
|
|
9430
|
+
const lookup = new LookupHistoryItem(preimage.hash, length, tryAsLookupHistorySlots([slot]));
|
|
9431
|
+
if (lookupHistory === undefined) {
|
|
9432
|
+
// no lookup history for that preimage at all (edge case, should be requested)
|
|
9433
|
+
service.data.lookupHistory.set(preimage.hash, [lookup]);
|
|
9434
|
+
}
|
|
9435
|
+
else {
|
|
9436
|
+
// insert or replace exiting entry
|
|
9437
|
+
const index = lookupHistory.map((x) => x.length).indexOf(length);
|
|
9438
|
+
lookupHistory.splice(index, index === -1 ? 0 : 1, lookup);
|
|
9439
|
+
}
|
|
9921
9440
|
}
|
|
9922
9441
|
}
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9442
|
+
else if (kind === UpdatePreimageKind.Remove) {
|
|
9443
|
+
const { hash, length } = update.action;
|
|
9444
|
+
service.data.preimages.delete(hash);
|
|
9445
|
+
const history = service.data.lookupHistory.get(hash) ?? [];
|
|
9446
|
+
const idx = history.map((x) => x.length).indexOf(length);
|
|
9447
|
+
if (idx !== -1) {
|
|
9448
|
+
history.splice(idx, 1);
|
|
9449
|
+
}
|
|
9450
|
+
}
|
|
9451
|
+
else if (kind === UpdatePreimageKind.UpdateOrAdd) {
|
|
9452
|
+
const { item } = update.action;
|
|
9453
|
+
const history = service.data.lookupHistory.get(item.hash) ?? [];
|
|
9454
|
+
const existingIdx = history.map((x) => x.length).indexOf(item.length);
|
|
9455
|
+
const removeCount = existingIdx === -1 ? 0 : 1;
|
|
9456
|
+
history.splice(existingIdx, removeCount, item);
|
|
9457
|
+
service.data.lookupHistory.set(item.hash, history);
|
|
9458
|
+
}
|
|
9459
|
+
else {
|
|
9460
|
+
assertNever(kind);
|
|
9931
9461
|
}
|
|
9932
|
-
}
|
|
9933
|
-
else if (kind === UpdatePreimageKind.UpdateOrAdd) {
|
|
9934
|
-
const { item } = action;
|
|
9935
|
-
const history = service.data.lookupHistory.get(item.hash) ?? [];
|
|
9936
|
-
const existingIdx = history.map((x) => x.length).indexOf(item.length);
|
|
9937
|
-
const removeCount = existingIdx === -1 ? 0 : 1;
|
|
9938
|
-
history.splice(existingIdx, removeCount, item);
|
|
9939
|
-
service.data.lookupHistory.set(item.hash, history);
|
|
9940
|
-
}
|
|
9941
|
-
else {
|
|
9942
|
-
assertNever(kind);
|
|
9943
9462
|
}
|
|
9944
9463
|
}
|
|
9945
9464
|
return Result$1.ok(OK);
|
|
9946
9465
|
}
|
|
9947
9466
|
updateServices(servicesUpdates) {
|
|
9948
|
-
|
|
9949
|
-
|
|
9467
|
+
if (servicesUpdates === undefined) {
|
|
9468
|
+
return Result$1.ok(OK);
|
|
9469
|
+
}
|
|
9470
|
+
for (const [serviceId, update] of servicesUpdates.entries()) {
|
|
9471
|
+
const { kind, account } = update.action;
|
|
9950
9472
|
if (kind === UpdateServiceKind.Create) {
|
|
9951
|
-
const { lookupHistory } = action;
|
|
9473
|
+
const { lookupHistory } = update.action;
|
|
9952
9474
|
if (this.services.has(serviceId)) {
|
|
9953
|
-
return Result$1.error(UpdateError.DuplicateService, `${serviceId} already exists!`);
|
|
9475
|
+
return Result$1.error(UpdateError.DuplicateService, () => `${serviceId} already exists!`);
|
|
9954
9476
|
}
|
|
9955
9477
|
this.services.set(serviceId, new InMemoryService(serviceId, {
|
|
9956
9478
|
info: account,
|
|
@@ -9962,7 +9484,7 @@ class InMemoryState extends WithDebug {
|
|
|
9962
9484
|
else if (kind === UpdateServiceKind.Update) {
|
|
9963
9485
|
const existingService = this.services.get(serviceId);
|
|
9964
9486
|
if (existingService === undefined) {
|
|
9965
|
-
return Result$1.error(UpdateError.NoService, `Cannot update ${serviceId} because it does not exist.`);
|
|
9487
|
+
return Result$1.error(UpdateError.NoService, () => `Cannot update ${serviceId} because it does not exist.`);
|
|
9966
9488
|
}
|
|
9967
9489
|
existingService.data.info = account;
|
|
9968
9490
|
}
|
|
@@ -9998,8 +9520,9 @@ class InMemoryState extends WithDebug {
|
|
|
9998
9520
|
getService(id) {
|
|
9999
9521
|
return this.services.get(id) ?? null;
|
|
10000
9522
|
}
|
|
10001
|
-
constructor(s) {
|
|
9523
|
+
constructor(chainSpec, s) {
|
|
10002
9524
|
super();
|
|
9525
|
+
this.chainSpec = chainSpec;
|
|
10003
9526
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
10004
9527
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
10005
9528
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -10021,11 +9544,14 @@ class InMemoryState extends WithDebug {
|
|
|
10021
9544
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
10022
9545
|
this.services = s.services;
|
|
10023
9546
|
}
|
|
9547
|
+
view() {
|
|
9548
|
+
return new InMemoryStateView(this.chainSpec, this);
|
|
9549
|
+
}
|
|
10024
9550
|
/**
|
|
10025
9551
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
10026
9552
|
*/
|
|
10027
9553
|
static empty(spec) {
|
|
10028
|
-
return new InMemoryState({
|
|
9554
|
+
return new InMemoryState(spec, {
|
|
10029
9555
|
availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
10030
9556
|
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
|
|
10031
9557
|
bandersnatch: Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
@@ -10061,7 +9587,7 @@ class InMemoryState extends WithDebug {
|
|
|
10061
9587
|
entropy: FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
10062
9588
|
authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => asKnownSize([])), spec),
|
|
10063
9589
|
authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
|
|
10064
|
-
recentBlocks:
|
|
9590
|
+
recentBlocks: RecentBlocks.empty(),
|
|
10065
9591
|
statistics: StatisticsData.create({
|
|
10066
9592
|
current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
10067
9593
|
previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
@@ -10075,8 +9601,9 @@ class InMemoryState extends WithDebug {
|
|
|
10075
9601
|
epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10076
9602
|
privilegedServices: PrivilegedServices.create({
|
|
10077
9603
|
manager: tryAsServiceId(0),
|
|
10078
|
-
|
|
10079
|
-
|
|
9604
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
9605
|
+
delegator: tryAsServiceId(0),
|
|
9606
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10080
9607
|
autoAccumulateServices: [],
|
|
10081
9608
|
}),
|
|
10082
9609
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -10098,6 +9625,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10098
9625
|
|
|
10099
9626
|
var index$g = /*#__PURE__*/Object.freeze({
|
|
10100
9627
|
__proto__: null,
|
|
9628
|
+
AUTHORIZATION_QUEUE_SIZE: AUTHORIZATION_QUEUE_SIZE,
|
|
10101
9629
|
AccumulationOutput: AccumulationOutput,
|
|
10102
9630
|
AutoAccumulate: AutoAccumulate,
|
|
10103
9631
|
AvailabilityAssignment: AvailabilityAssignment,
|
|
@@ -10111,11 +9639,12 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
10111
9639
|
InMemoryService: InMemoryService,
|
|
10112
9640
|
InMemoryState: InMemoryState,
|
|
10113
9641
|
LookupHistoryItem: LookupHistoryItem,
|
|
9642
|
+
MAX_AUTH_POOL_SIZE: MAX_AUTH_POOL_SIZE,
|
|
10114
9643
|
MAX_RECENT_HISTORY: MAX_RECENT_HISTORY,
|
|
9644
|
+
NotYetAccumulatedReport: NotYetAccumulatedReport,
|
|
10115
9645
|
PreimageItem: PreimageItem,
|
|
10116
9646
|
PrivilegedServices: PrivilegedServices,
|
|
10117
9647
|
RecentBlocks: RecentBlocks,
|
|
10118
|
-
RecentBlocksHistory: RecentBlocksHistory,
|
|
10119
9648
|
SafroleData: SafroleData,
|
|
10120
9649
|
SafroleSealingKeysData: SafroleSealingKeysData,
|
|
10121
9650
|
get SafroleSealingKeysKind () { return SafroleSealingKeysKind; },
|
|
@@ -10134,70 +9663,35 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
10134
9663
|
ValidatorData: ValidatorData,
|
|
10135
9664
|
ValidatorStatistics: ValidatorStatistics,
|
|
10136
9665
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
9666
|
+
accumulationQueueCodec: accumulationQueueCodec,
|
|
9667
|
+
authPoolsCodec: authPoolsCodec,
|
|
9668
|
+
authQueuesCodec: authQueuesCodec,
|
|
9669
|
+
availabilityAssignmentsCodec: availabilityAssignmentsCodec,
|
|
10137
9670
|
codecPerCore: codecPerCore,
|
|
9671
|
+
codecWithVersion: codecWithVersion,
|
|
10138
9672
|
hashComparator: hashComparator,
|
|
10139
9673
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
9674
|
+
recentlyAccumulatedCodec: recentlyAccumulatedCodec,
|
|
10140
9675
|
serviceDataCodec: serviceDataCodec,
|
|
10141
9676
|
serviceEntriesCodec: serviceEntriesCodec,
|
|
10142
9677
|
tryAsLookupHistorySlots: tryAsLookupHistorySlots,
|
|
10143
|
-
tryAsPerCore: tryAsPerCore
|
|
9678
|
+
tryAsPerCore: tryAsPerCore,
|
|
9679
|
+
validatorsDataCodec: validatorsDataCodec
|
|
10144
9680
|
});
|
|
10145
9681
|
|
|
10146
|
-
/**
|
|
10147
|
-
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
10148
|
-
*
|
|
10149
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
10150
|
-
*/
|
|
10151
|
-
class NotYetAccumulatedReport extends WithDebug {
|
|
10152
|
-
report;
|
|
10153
|
-
dependencies;
|
|
10154
|
-
static Codec = codec$1.Class(NotYetAccumulatedReport, {
|
|
10155
|
-
report: WorkReport.Codec,
|
|
10156
|
-
dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
10157
|
-
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
10158
|
-
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
10159
|
-
minLength: 0,
|
|
10160
|
-
}),
|
|
10161
|
-
});
|
|
10162
|
-
static create({ report, dependencies }) {
|
|
10163
|
-
return new NotYetAccumulatedReport(report, dependencies);
|
|
10164
|
-
}
|
|
10165
|
-
constructor(
|
|
10166
|
-
/**
|
|
10167
|
-
* Each of these were made available at most one epoch ago
|
|
10168
|
-
* but have or had unfulfilled dependencies.
|
|
10169
|
-
*/
|
|
10170
|
-
report,
|
|
10171
|
-
/**
|
|
10172
|
-
* Alongside the work-report itself, we retain its un-accumulated
|
|
10173
|
-
* dependencies, a set of work-package hashes.
|
|
10174
|
-
*
|
|
10175
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
10176
|
-
*/
|
|
10177
|
-
dependencies) {
|
|
10178
|
-
super();
|
|
10179
|
-
this.report = report;
|
|
10180
|
-
this.dependencies = dependencies;
|
|
10181
|
-
}
|
|
10182
|
-
}
|
|
10183
|
-
|
|
10184
9682
|
/** Serialization for particular state entries. */
|
|
10185
9683
|
var serialize;
|
|
10186
9684
|
(function (serialize) {
|
|
10187
9685
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
10188
9686
|
serialize.authPools = {
|
|
10189
9687
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
10190
|
-
Codec:
|
|
10191
|
-
minLength: 0,
|
|
10192
|
-
maxLength: MAX_AUTH_POOL_SIZE,
|
|
10193
|
-
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
10194
|
-
})),
|
|
9688
|
+
Codec: authPoolsCodec,
|
|
10195
9689
|
extract: (s) => s.authPools,
|
|
10196
9690
|
};
|
|
10197
9691
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
10198
9692
|
serialize.authQueues = {
|
|
10199
9693
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
10200
|
-
Codec:
|
|
9694
|
+
Codec: authQueuesCodec,
|
|
10201
9695
|
extract: (s) => s.authQueues,
|
|
10202
9696
|
};
|
|
10203
9697
|
/**
|
|
@@ -10206,7 +9700,7 @@ var serialize;
|
|
|
10206
9700
|
*/
|
|
10207
9701
|
serialize.recentBlocks = {
|
|
10208
9702
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
10209
|
-
Codec:
|
|
9703
|
+
Codec: RecentBlocks.Codec,
|
|
10210
9704
|
extract: (s) => s.recentBlocks,
|
|
10211
9705
|
};
|
|
10212
9706
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -10235,25 +9729,25 @@ var serialize;
|
|
|
10235
9729
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
10236
9730
|
serialize.designatedValidators = {
|
|
10237
9731
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
10238
|
-
Codec:
|
|
9732
|
+
Codec: validatorsDataCodec,
|
|
10239
9733
|
extract: (s) => s.designatedValidatorData,
|
|
10240
9734
|
};
|
|
10241
9735
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
10242
9736
|
serialize.currentValidators = {
|
|
10243
9737
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
10244
|
-
Codec:
|
|
9738
|
+
Codec: validatorsDataCodec,
|
|
10245
9739
|
extract: (s) => s.currentValidatorData,
|
|
10246
9740
|
};
|
|
10247
9741
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
10248
9742
|
serialize.previousValidators = {
|
|
10249
9743
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
10250
|
-
Codec:
|
|
9744
|
+
Codec: validatorsDataCodec,
|
|
10251
9745
|
extract: (s) => s.previousValidatorData,
|
|
10252
9746
|
};
|
|
10253
9747
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
10254
9748
|
serialize.availabilityAssignment = {
|
|
10255
9749
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
10256
|
-
Codec:
|
|
9750
|
+
Codec: availabilityAssignmentsCodec,
|
|
10257
9751
|
extract: (s) => s.availabilityAssignment,
|
|
10258
9752
|
};
|
|
10259
9753
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -10277,13 +9771,13 @@ var serialize;
|
|
|
10277
9771
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
10278
9772
|
serialize.accumulationQueue = {
|
|
10279
9773
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
10280
|
-
Codec:
|
|
9774
|
+
Codec: accumulationQueueCodec,
|
|
10281
9775
|
extract: (s) => s.accumulationQueue,
|
|
10282
9776
|
};
|
|
10283
9777
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
10284
9778
|
serialize.recentlyAccumulated = {
|
|
10285
9779
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
10286
|
-
Codec:
|
|
9780
|
+
Codec: recentlyAccumulatedCodec,
|
|
10287
9781
|
extract: (s) => s.recentlyAccumulated,
|
|
10288
9782
|
};
|
|
10289
9783
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -10295,21 +9789,23 @@ var serialize;
|
|
|
10295
9789
|
/** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
|
|
10296
9790
|
serialize.serviceData = (serviceId) => ({
|
|
10297
9791
|
key: stateKeys.serviceInfo(serviceId),
|
|
10298
|
-
Codec:
|
|
9792
|
+
Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9793
|
+
? codecWithVersion(ServiceAccountInfo.Codec)
|
|
9794
|
+
: ServiceAccountInfo.Codec,
|
|
10299
9795
|
});
|
|
10300
9796
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
10301
|
-
serialize.serviceStorage = (serviceId, key) => ({
|
|
10302
|
-
key: stateKeys.serviceStorage(serviceId, key),
|
|
9797
|
+
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
9798
|
+
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
10303
9799
|
Codec: dumpCodec,
|
|
10304
9800
|
});
|
|
10305
9801
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
10306
|
-
serialize.servicePreimages = (serviceId, hash) => ({
|
|
10307
|
-
key: stateKeys.servicePreimage(serviceId, hash),
|
|
9802
|
+
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
9803
|
+
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
10308
9804
|
Codec: dumpCodec,
|
|
10309
9805
|
});
|
|
10310
9806
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10311
|
-
serialize.serviceLookupHistory = (serviceId, hash, len) => ({
|
|
10312
|
-
key: stateKeys.serviceLookupHistory(serviceId, hash, len),
|
|
9807
|
+
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
9808
|
+
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10313
9809
|
Codec: readonlyArray(codec$1.sequenceVarLen(codec$1.u32)),
|
|
10314
9810
|
});
|
|
10315
9811
|
})(serialize || (serialize = {}));
|
|
@@ -10322,6 +9818,84 @@ var serialize;
|
|
|
10322
9818
|
*/
|
|
10323
9819
|
const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) => e.bytes(Bytes.fromBlob(v.raw, v.raw.length)), (d) => BytesBlob.blobFrom(d.bytes(d.source.length - d.bytesRead()).raw), (s) => s.bytes(s.decoder.source.length - s.decoder.bytesRead()));
|
|
10324
9820
|
|
|
9821
|
+
class SerializedStateView {
|
|
9822
|
+
spec;
|
|
9823
|
+
backend;
|
|
9824
|
+
recentlyUsedServices;
|
|
9825
|
+
viewCache;
|
|
9826
|
+
constructor(spec, backend,
|
|
9827
|
+
/** Best-effort list of recently active services. */
|
|
9828
|
+
recentlyUsedServices, viewCache) {
|
|
9829
|
+
this.spec = spec;
|
|
9830
|
+
this.backend = backend;
|
|
9831
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
9832
|
+
this.viewCache = viewCache;
|
|
9833
|
+
}
|
|
9834
|
+
retrieveView({ key, Codec }, description) {
|
|
9835
|
+
const cached = this.viewCache.get(key);
|
|
9836
|
+
if (cached !== undefined) {
|
|
9837
|
+
return cached;
|
|
9838
|
+
}
|
|
9839
|
+
const bytes = this.backend.get(key);
|
|
9840
|
+
if (bytes === null) {
|
|
9841
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
|
|
9842
|
+
}
|
|
9843
|
+
// NOTE [ToDr] we are not using `Decoder.decodeObject` here because
|
|
9844
|
+
// it needs to get to the end of the data (skip), yet that's expensive.
|
|
9845
|
+
// we assume that the state data is correct and coherent anyway, so
|
|
9846
|
+
// for performance reasons we simply create the view here.
|
|
9847
|
+
const d = Decoder.fromBytesBlob(bytes);
|
|
9848
|
+
d.attachContext(this.spec);
|
|
9849
|
+
const view = Codec.View.decode(d);
|
|
9850
|
+
this.viewCache.set(key, view);
|
|
9851
|
+
return view;
|
|
9852
|
+
}
|
|
9853
|
+
availabilityAssignmentView() {
|
|
9854
|
+
return this.retrieveView(serialize.availabilityAssignment, "availabilityAssignmentView");
|
|
9855
|
+
}
|
|
9856
|
+
designatedValidatorDataView() {
|
|
9857
|
+
return this.retrieveView(serialize.designatedValidators, "designatedValidatorsView");
|
|
9858
|
+
}
|
|
9859
|
+
currentValidatorDataView() {
|
|
9860
|
+
return this.retrieveView(serialize.currentValidators, "currentValidatorsView");
|
|
9861
|
+
}
|
|
9862
|
+
previousValidatorDataView() {
|
|
9863
|
+
return this.retrieveView(serialize.previousValidators, "previousValidatorsView");
|
|
9864
|
+
}
|
|
9865
|
+
authPoolsView() {
|
|
9866
|
+
return this.retrieveView(serialize.authPools, "authPoolsView");
|
|
9867
|
+
}
|
|
9868
|
+
authQueuesView() {
|
|
9869
|
+
return this.retrieveView(serialize.authQueues, "authQueuesView");
|
|
9870
|
+
}
|
|
9871
|
+
recentBlocksView() {
|
|
9872
|
+
return this.retrieveView(serialize.recentBlocks, "recentBlocksView");
|
|
9873
|
+
}
|
|
9874
|
+
statisticsView() {
|
|
9875
|
+
return this.retrieveView(serialize.statistics, "statisticsView");
|
|
9876
|
+
}
|
|
9877
|
+
accumulationQueueView() {
|
|
9878
|
+
return this.retrieveView(serialize.accumulationQueue, "accumulationQueueView");
|
|
9879
|
+
}
|
|
9880
|
+
recentlyAccumulatedView() {
|
|
9881
|
+
return this.retrieveView(serialize.recentlyAccumulated, "recentlyAccumulatedView");
|
|
9882
|
+
}
|
|
9883
|
+
safroleDataView() {
|
|
9884
|
+
return this.retrieveView(serialize.safrole, "safroleDataView");
|
|
9885
|
+
}
|
|
9886
|
+
getServiceInfoView(id) {
|
|
9887
|
+
const serviceData = serialize.serviceData(id);
|
|
9888
|
+
const bytes = this.backend.get(serviceData.key);
|
|
9889
|
+
if (bytes === null) {
|
|
9890
|
+
return null;
|
|
9891
|
+
}
|
|
9892
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
9893
|
+
this.recentlyUsedServices.push(id);
|
|
9894
|
+
}
|
|
9895
|
+
return Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
|
|
9896
|
+
}
|
|
9897
|
+
}
|
|
9898
|
+
|
|
10325
9899
|
/**
|
|
10326
9900
|
* State object which reads it's entries from some backend.
|
|
10327
9901
|
*
|
|
@@ -10332,58 +9906,74 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10332
9906
|
*/
|
|
10333
9907
|
class SerializedState {
|
|
10334
9908
|
spec;
|
|
9909
|
+
blake2b;
|
|
10335
9910
|
backend;
|
|
10336
|
-
|
|
9911
|
+
recentlyUsedServices;
|
|
10337
9912
|
/** Create a state-like object from collection of serialized entries. */
|
|
10338
|
-
static fromStateEntries(spec, state, recentServices = []) {
|
|
10339
|
-
return new SerializedState(spec, state, recentServices);
|
|
9913
|
+
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9914
|
+
return new SerializedState(spec, blake2b, state, recentServices);
|
|
10340
9915
|
}
|
|
10341
9916
|
/** Create a state-like object backed by some DB. */
|
|
10342
|
-
static new(spec, db, recentServices = []) {
|
|
10343
|
-
return new SerializedState(spec, db, recentServices);
|
|
9917
|
+
static new(spec, blake2b, db, recentServices = []) {
|
|
9918
|
+
return new SerializedState(spec, blake2b, db, recentServices);
|
|
10344
9919
|
}
|
|
10345
|
-
|
|
9920
|
+
dataCache = HashDictionary.new();
|
|
9921
|
+
viewCache = HashDictionary.new();
|
|
9922
|
+
constructor(spec, blake2b, backend,
|
|
10346
9923
|
/** Best-effort list of recently active services. */
|
|
10347
|
-
|
|
9924
|
+
recentlyUsedServices) {
|
|
10348
9925
|
this.spec = spec;
|
|
9926
|
+
this.blake2b = blake2b;
|
|
10349
9927
|
this.backend = backend;
|
|
10350
|
-
this.
|
|
9928
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
10351
9929
|
}
|
|
10352
9930
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
10353
9931
|
[TEST_COMPARE_USING]() {
|
|
10354
9932
|
return this.backend;
|
|
10355
9933
|
}
|
|
9934
|
+
/** Return a non-decoding version of the state. */
|
|
9935
|
+
view() {
|
|
9936
|
+
return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
|
|
9937
|
+
}
|
|
10356
9938
|
// TODO [ToDr] Temporary method to update the state,
|
|
10357
9939
|
// without changing references.
|
|
10358
9940
|
updateBackend(newBackend) {
|
|
10359
9941
|
this.backend = newBackend;
|
|
9942
|
+
this.dataCache = HashDictionary.new();
|
|
9943
|
+
this.viewCache = HashDictionary.new();
|
|
10360
9944
|
}
|
|
10361
9945
|
recentServiceIds() {
|
|
10362
|
-
return this.
|
|
9946
|
+
return this.recentlyUsedServices;
|
|
10363
9947
|
}
|
|
10364
9948
|
getService(id) {
|
|
10365
9949
|
const serviceData = this.retrieveOptional(serialize.serviceData(id));
|
|
10366
9950
|
if (serviceData === undefined) {
|
|
10367
9951
|
return null;
|
|
10368
9952
|
}
|
|
10369
|
-
if (!this.
|
|
10370
|
-
this.
|
|
9953
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
9954
|
+
this.recentlyUsedServices.push(id);
|
|
10371
9955
|
}
|
|
10372
|
-
return new SerializedService(id, serviceData, (key) => this.retrieveOptional(key));
|
|
9956
|
+
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10373
9957
|
}
|
|
10374
|
-
retrieve(
|
|
10375
|
-
const
|
|
10376
|
-
if (
|
|
10377
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
|
|
9958
|
+
retrieve(k, description) {
|
|
9959
|
+
const data = this.retrieveOptional(k);
|
|
9960
|
+
if (data === undefined) {
|
|
9961
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
|
|
10378
9962
|
}
|
|
10379
|
-
return
|
|
9963
|
+
return data;
|
|
10380
9964
|
}
|
|
10381
9965
|
retrieveOptional({ key, Codec }) {
|
|
9966
|
+
const cached = this.dataCache.get(key);
|
|
9967
|
+
if (cached !== undefined) {
|
|
9968
|
+
return cached;
|
|
9969
|
+
}
|
|
10382
9970
|
const bytes = this.backend.get(key);
|
|
10383
9971
|
if (bytes === null) {
|
|
10384
9972
|
return undefined;
|
|
10385
9973
|
}
|
|
10386
|
-
|
|
9974
|
+
const data = Decoder.decodeObject(Codec, bytes, this.spec);
|
|
9975
|
+
this.dataCache.set(key, data);
|
|
9976
|
+
return data;
|
|
10387
9977
|
}
|
|
10388
9978
|
get availabilityAssignment() {
|
|
10389
9979
|
return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
|
|
@@ -10445,12 +10035,14 @@ class SerializedState {
|
|
|
10445
10035
|
}
|
|
10446
10036
|
/** Service data representation on a serialized state. */
|
|
10447
10037
|
class SerializedService {
|
|
10038
|
+
blake2b;
|
|
10448
10039
|
serviceId;
|
|
10449
10040
|
accountInfo;
|
|
10450
10041
|
retrieveOptional;
|
|
10451
|
-
constructor(
|
|
10042
|
+
constructor(blake2b,
|
|
10452
10043
|
/** Service id */
|
|
10453
10044
|
serviceId, accountInfo, retrieveOptional) {
|
|
10045
|
+
this.blake2b = blake2b;
|
|
10454
10046
|
this.serviceId = serviceId;
|
|
10455
10047
|
this.accountInfo = accountInfo;
|
|
10456
10048
|
this.retrieveOptional = retrieveOptional;
|
|
@@ -10463,13 +10055,13 @@ class SerializedService {
|
|
|
10463
10055
|
getStorage(rawKey) {
|
|
10464
10056
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
10465
10057
|
const SERVICE_ID_BYTES = 4;
|
|
10466
|
-
const serviceIdAndKey =
|
|
10058
|
+
const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
10467
10059
|
serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
|
|
10468
10060
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10469
|
-
const key = asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
10470
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, key)) ?? null;
|
|
10061
|
+
const key = asOpaqueType(BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
10062
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10471
10063
|
}
|
|
10472
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, rawKey)) ?? null;
|
|
10064
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10473
10065
|
}
|
|
10474
10066
|
/**
|
|
10475
10067
|
* Check if preimage is present in the DB.
|
|
@@ -10478,15 +10070,15 @@ class SerializedService {
|
|
|
10478
10070
|
*/
|
|
10479
10071
|
hasPreimage(hash) {
|
|
10480
10072
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10481
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) !== undefined;
|
|
10073
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10482
10074
|
}
|
|
10483
10075
|
/** Retrieve preimage from the DB. */
|
|
10484
10076
|
getPreimage(hash) {
|
|
10485
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) ?? null;
|
|
10077
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10486
10078
|
}
|
|
10487
10079
|
/** Retrieve preimage lookup history. */
|
|
10488
10080
|
getLookupHistory(hash, len) {
|
|
10489
|
-
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.serviceId, hash, len));
|
|
10081
|
+
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
10490
10082
|
if (rawSlots === undefined) {
|
|
10491
10083
|
return null;
|
|
10492
10084
|
}
|
|
@@ -10548,7 +10140,7 @@ class TrieNode {
|
|
|
10548
10140
|
raw;
|
|
10549
10141
|
constructor(
|
|
10550
10142
|
/** Exactly 512 bits / 64 bytes */
|
|
10551
|
-
raw =
|
|
10143
|
+
raw = safeAllocUint8Array(TRIE_NODE_BYTES)) {
|
|
10552
10144
|
this.raw = raw;
|
|
10553
10145
|
}
|
|
10554
10146
|
/** Returns the type of the node */
|
|
@@ -11123,11 +10715,13 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
11123
10715
|
parseInputKey: parseInputKey
|
|
11124
10716
|
});
|
|
11125
10717
|
|
|
11126
|
-
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
}
|
|
10718
|
+
function getBlake2bTrieHasher(hasher) {
|
|
10719
|
+
return {
|
|
10720
|
+
hashConcat(n, rest = []) {
|
|
10721
|
+
return hasher.hashBlobs([n, ...rest]);
|
|
10722
|
+
},
|
|
10723
|
+
};
|
|
10724
|
+
}
|
|
11131
10725
|
|
|
11132
10726
|
/** What should be done with that key? */
|
|
11133
10727
|
var StateEntryUpdateAction;
|
|
@@ -11139,88 +10733,100 @@ var StateEntryUpdateAction;
|
|
|
11139
10733
|
})(StateEntryUpdateAction || (StateEntryUpdateAction = {}));
|
|
11140
10734
|
const EMPTY_BLOB = BytesBlob.empty();
|
|
11141
10735
|
/** Serialize given state update into a series of key-value pairs. */
|
|
11142
|
-
function* serializeStateUpdate(spec, update) {
|
|
10736
|
+
function* serializeStateUpdate(spec, blake2b, update) {
|
|
11143
10737
|
// first let's serialize all of the simple entries (if present!)
|
|
11144
10738
|
yield* serializeBasicKeys(spec, update);
|
|
11145
10739
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
11146
10740
|
// then let's proceed with service updates
|
|
11147
|
-
yield* serializeServiceUpdates(update.
|
|
11148
|
-
yield* serializePreimages(update.preimages, encode);
|
|
11149
|
-
yield* serializeStorage(update.storage);
|
|
11150
|
-
yield* serializeRemovedServices(update.
|
|
10741
|
+
yield* serializeServiceUpdates(update.updated, encode, blake2b);
|
|
10742
|
+
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
10743
|
+
yield* serializeStorage(update.storage, blake2b);
|
|
10744
|
+
yield* serializeRemovedServices(update.removed);
|
|
11151
10745
|
}
|
|
11152
10746
|
function* serializeRemovedServices(servicesRemoved) {
|
|
11153
|
-
|
|
10747
|
+
if (servicesRemoved === undefined) {
|
|
10748
|
+
return;
|
|
10749
|
+
}
|
|
10750
|
+
for (const serviceId of servicesRemoved) {
|
|
11154
10751
|
// TODO [ToDr] what about all data associated with a service?
|
|
11155
10752
|
const codec = serialize.serviceData(serviceId);
|
|
11156
10753
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11157
10754
|
}
|
|
11158
10755
|
}
|
|
11159
|
-
function* serializeStorage(
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11163
|
-
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
|
|
10756
|
+
function* serializeStorage(storageUpdates, blake2b) {
|
|
10757
|
+
if (storageUpdates === undefined) {
|
|
10758
|
+
return;
|
|
10759
|
+
}
|
|
10760
|
+
for (const [serviceId, updates] of storageUpdates.entries()) {
|
|
10761
|
+
for (const { action } of updates) {
|
|
10762
|
+
switch (action.kind) {
|
|
10763
|
+
case UpdateStorageKind.Set: {
|
|
10764
|
+
const key = action.storage.key;
|
|
10765
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
10766
|
+
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
10767
|
+
break;
|
|
10768
|
+
}
|
|
10769
|
+
case UpdateStorageKind.Remove: {
|
|
10770
|
+
const key = action.key;
|
|
10771
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
10772
|
+
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
10773
|
+
break;
|
|
10774
|
+
}
|
|
11173
10775
|
}
|
|
11174
|
-
default:
|
|
11175
|
-
assertNever(action);
|
|
11176
10776
|
}
|
|
11177
10777
|
}
|
|
11178
10778
|
}
|
|
11179
|
-
function* serializePreimages(
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11183
|
-
|
|
11184
|
-
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
const
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
10779
|
+
function* serializePreimages(preimagesUpdates, encode, blake2b) {
|
|
10780
|
+
if (preimagesUpdates === undefined) {
|
|
10781
|
+
return;
|
|
10782
|
+
}
|
|
10783
|
+
for (const [serviceId, updates] of preimagesUpdates.entries()) {
|
|
10784
|
+
for (const { action } of updates) {
|
|
10785
|
+
switch (action.kind) {
|
|
10786
|
+
case UpdatePreimageKind.Provide: {
|
|
10787
|
+
const { hash, blob } = action.preimage;
|
|
10788
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
10789
|
+
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
10790
|
+
if (action.slot !== null) {
|
|
10791
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
10792
|
+
yield [
|
|
10793
|
+
StateEntryUpdateAction.Insert,
|
|
10794
|
+
codec2.key,
|
|
10795
|
+
encode(codec2.Codec, tryAsLookupHistorySlots([action.slot])),
|
|
10796
|
+
];
|
|
10797
|
+
}
|
|
10798
|
+
break;
|
|
10799
|
+
}
|
|
10800
|
+
case UpdatePreimageKind.UpdateOrAdd: {
|
|
10801
|
+
const { hash, length, slots } = action.item;
|
|
10802
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
10803
|
+
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
10804
|
+
break;
|
|
10805
|
+
}
|
|
10806
|
+
case UpdatePreimageKind.Remove: {
|
|
10807
|
+
const { hash, length } = action;
|
|
10808
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
10809
|
+
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
10810
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
10811
|
+
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
10812
|
+
break;
|
|
11193
10813
|
}
|
|
11194
|
-
break;
|
|
11195
|
-
}
|
|
11196
|
-
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11197
|
-
const { hash, length, slots } = action.item;
|
|
11198
|
-
const codec = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
11199
|
-
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11200
|
-
break;
|
|
11201
|
-
}
|
|
11202
|
-
case UpdatePreimageKind.Remove: {
|
|
11203
|
-
const { hash, length } = action;
|
|
11204
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
11205
|
-
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11206
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
11207
|
-
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11208
|
-
break;
|
|
11209
10814
|
}
|
|
11210
|
-
default:
|
|
11211
|
-
assertNever(action);
|
|
11212
10815
|
}
|
|
11213
10816
|
}
|
|
11214
10817
|
}
|
|
11215
|
-
function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
11216
|
-
|
|
10818
|
+
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
10819
|
+
if (servicesUpdates === undefined) {
|
|
10820
|
+
return;
|
|
10821
|
+
}
|
|
10822
|
+
for (const [serviceId, { action }] of servicesUpdates.entries()) {
|
|
11217
10823
|
// new service being created or updated
|
|
11218
10824
|
const codec = serialize.serviceData(serviceId);
|
|
11219
10825
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
|
|
11220
10826
|
// additional lookup history update
|
|
11221
10827
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11222
10828
|
const { lookupHistory } = action;
|
|
11223
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10829
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11224
10830
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11225
10831
|
}
|
|
11226
10832
|
}
|
|
@@ -11315,8 +10921,8 @@ class StateEntries {
|
|
|
11315
10921
|
},
|
|
11316
10922
|
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11317
10923
|
/** Turn in-memory state into it's serialized form. */
|
|
11318
|
-
static serializeInMemory(spec, state) {
|
|
11319
|
-
return new StateEntries(convertInMemoryStateToDictionary(spec, state));
|
|
10924
|
+
static serializeInMemory(spec, blake2b, state) {
|
|
10925
|
+
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
11320
10926
|
}
|
|
11321
10927
|
/**
|
|
11322
10928
|
* Wrap a collection of truncated state entries and treat it as state.
|
|
@@ -11365,7 +10971,8 @@ class StateEntries {
|
|
|
11365
10971
|
}
|
|
11366
10972
|
}
|
|
11367
10973
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/391600391600?v=0.6.4 */
|
|
11368
|
-
getRootHash() {
|
|
10974
|
+
getRootHash(blake2b) {
|
|
10975
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11369
10976
|
const leaves = SortedSet.fromArray(leafComparator);
|
|
11370
10977
|
for (const [key, value] of this) {
|
|
11371
10978
|
leaves.insert(InMemoryTrie.constructLeaf(blake2bTrieHasher, key.asOpaque(), value));
|
|
@@ -11374,7 +10981,7 @@ class StateEntries {
|
|
|
11374
10981
|
}
|
|
11375
10982
|
}
|
|
11376
10983
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/38a50038a500?v=0.6.4 */
|
|
11377
|
-
function convertInMemoryStateToDictionary(spec, state) {
|
|
10984
|
+
function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
11378
10985
|
const serialized = TruncatedHashDictionary.fromEntries([]);
|
|
11379
10986
|
function doSerialize(codec) {
|
|
11380
10987
|
serialized.set(codec.key, Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
@@ -11402,18 +11009,18 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11402
11009
|
serialized.set(key, Encoder.encodeObject(Codec, service.getInfo()));
|
|
11403
11010
|
// preimages
|
|
11404
11011
|
for (const preimage of service.data.preimages.values()) {
|
|
11405
|
-
const { key, Codec } = serialize.servicePreimages(serviceId, preimage.hash);
|
|
11012
|
+
const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11406
11013
|
serialized.set(key, Encoder.encodeObject(Codec, preimage.blob));
|
|
11407
11014
|
}
|
|
11408
11015
|
// storage
|
|
11409
11016
|
for (const storage of service.data.storage.values()) {
|
|
11410
|
-
const { key, Codec } = serialize.serviceStorage(serviceId, storage.key);
|
|
11017
|
+
const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11411
11018
|
serialized.set(key, Encoder.encodeObject(Codec, storage.value));
|
|
11412
11019
|
}
|
|
11413
11020
|
// lookup history
|
|
11414
11021
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11415
11022
|
for (const lookupHistory of lookupHistoryList) {
|
|
11416
|
-
const { key, Codec } = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11023
|
+
const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11417
11024
|
serialized.set(key, Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11418
11025
|
}
|
|
11419
11026
|
}
|
|
@@ -11421,9 +11028,9 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11421
11028
|
return serialized;
|
|
11422
11029
|
}
|
|
11423
11030
|
|
|
11424
|
-
function loadState(spec, entries) {
|
|
11031
|
+
function loadState(spec, blake2b, entries) {
|
|
11425
11032
|
const stateEntries = StateEntries.fromEntriesUnsafe(entries);
|
|
11426
|
-
return SerializedState.fromStateEntries(spec, stateEntries);
|
|
11033
|
+
return SerializedState.fromStateEntries(spec, blake2b, stateEntries);
|
|
11427
11034
|
}
|
|
11428
11035
|
|
|
11429
11036
|
/**
|
|
@@ -11456,6 +11063,7 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
11456
11063
|
__proto__: null,
|
|
11457
11064
|
SerializedService: SerializedService,
|
|
11458
11065
|
SerializedState: SerializedState,
|
|
11066
|
+
SerializedStateView: SerializedStateView,
|
|
11459
11067
|
StateEntries: StateEntries,
|
|
11460
11068
|
get StateEntryUpdateAction () { return StateEntryUpdateAction; },
|
|
11461
11069
|
get StateKeyIdx () { return StateKeyIdx; },
|
|
@@ -11487,13 +11095,13 @@ class LeafDb {
|
|
|
11487
11095
|
*/
|
|
11488
11096
|
static fromLeavesBlob(blob, db) {
|
|
11489
11097
|
if (blob.length % TRIE_NODE_BYTES !== 0) {
|
|
11490
|
-
return Result$1.error(LeafDbError.InvalidLeafData, `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
11098
|
+
return Result$1.error(LeafDbError.InvalidLeafData, () => `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
11491
11099
|
}
|
|
11492
11100
|
const leaves = SortedSet.fromArray(leafComparator, []);
|
|
11493
11101
|
for (const nodeData of blob.chunks(TRIE_NODE_BYTES)) {
|
|
11494
11102
|
const node = new TrieNode(nodeData.raw);
|
|
11495
11103
|
if (node.getNodeType() === NodeType.Branch) {
|
|
11496
|
-
return Result$1.error(LeafDbError.InvalidLeafData, `Branch node detected: ${nodeData}`);
|
|
11104
|
+
return Result$1.error(LeafDbError.InvalidLeafData, () => `Branch node detected: ${nodeData}`);
|
|
11497
11105
|
}
|
|
11498
11106
|
leaves.insert(node.asLeafNode());
|
|
11499
11107
|
}
|
|
@@ -11531,7 +11139,8 @@ class LeafDb {
|
|
|
11531
11139
|
}
|
|
11532
11140
|
assertNever(val);
|
|
11533
11141
|
}
|
|
11534
|
-
getStateRoot() {
|
|
11142
|
+
getStateRoot(blake2b) {
|
|
11143
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11535
11144
|
return InMemoryTrie.computeStateRoot(blake2bTrieHasher, this.leaves).asOpaque();
|
|
11536
11145
|
}
|
|
11537
11146
|
intoStateEntries() {
|
|
@@ -11647,7 +11256,11 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
11647
11256
|
return new ServiceWithCodec(serviceId, data);
|
|
11648
11257
|
}
|
|
11649
11258
|
}
|
|
11650
|
-
const inMemoryStateCodec = codec$1.Class(InMemoryState
|
|
11259
|
+
const inMemoryStateCodec = (spec) => codec$1.Class(class State extends InMemoryState {
|
|
11260
|
+
static create(data) {
|
|
11261
|
+
return InMemoryState.new(spec, data);
|
|
11262
|
+
}
|
|
11263
|
+
}, {
|
|
11651
11264
|
// alpha
|
|
11652
11265
|
authPools: serialize.authPools.Codec,
|
|
11653
11266
|
// phi
|
|
@@ -11721,11 +11334,12 @@ class InMemoryStates {
|
|
|
11721
11334
|
}
|
|
11722
11335
|
}
|
|
11723
11336
|
async getStateRoot(state) {
|
|
11724
|
-
|
|
11337
|
+
const blake2b = await Blake2b.createHasher();
|
|
11338
|
+
return StateEntries.serializeInMemory(this.spec, blake2b, state).getRootHash(blake2b);
|
|
11725
11339
|
}
|
|
11726
11340
|
/** Insert a full state into the database. */
|
|
11727
11341
|
async insertState(headerHash, state) {
|
|
11728
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
11342
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
|
|
11729
11343
|
this.db.set(headerHash, encoded);
|
|
11730
11344
|
return Result$1.ok(OK);
|
|
11731
11345
|
}
|
|
@@ -11734,7 +11348,7 @@ class InMemoryStates {
|
|
|
11734
11348
|
if (encodedState === undefined) {
|
|
11735
11349
|
return null;
|
|
11736
11350
|
}
|
|
11737
|
-
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
11351
|
+
return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
|
|
11738
11352
|
}
|
|
11739
11353
|
}
|
|
11740
11354
|
|
|
@@ -11799,7 +11413,7 @@ function padAndEncodeData(input) {
|
|
|
11799
11413
|
const paddedLength = Math.ceil(input.length / PIECE_SIZE) * PIECE_SIZE;
|
|
11800
11414
|
let padded = input;
|
|
11801
11415
|
if (input.length !== paddedLength) {
|
|
11802
|
-
padded = BytesBlob.blobFrom(
|
|
11416
|
+
padded = BytesBlob.blobFrom(safeAllocUint8Array(paddedLength));
|
|
11803
11417
|
padded.raw.set(input.raw, 0);
|
|
11804
11418
|
}
|
|
11805
11419
|
return chunkingFunction(padded);
|
|
@@ -11845,7 +11459,7 @@ function decodeData(input) {
|
|
|
11845
11459
|
*/
|
|
11846
11460
|
function encodePoints(input) {
|
|
11847
11461
|
const result = [];
|
|
11848
|
-
const data =
|
|
11462
|
+
const data = safeAllocUint8Array(POINT_ALIGNMENT * N_CHUNKS_REQUIRED);
|
|
11849
11463
|
// add original shards to the result
|
|
11850
11464
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11851
11465
|
const pointStart = POINT_LENGTH * i;
|
|
@@ -11861,7 +11475,7 @@ function encodePoints(input) {
|
|
|
11861
11475
|
const encodedData = encodedResult.take_data();
|
|
11862
11476
|
for (let i = 0; i < N_CHUNKS_REDUNDANCY; i++) {
|
|
11863
11477
|
const pointIndex = i * POINT_ALIGNMENT;
|
|
11864
|
-
const redundancyPoint =
|
|
11478
|
+
const redundancyPoint = safeAllocUint8Array(POINT_LENGTH);
|
|
11865
11479
|
for (let j = 0; j < POINT_LENGTH; j++) {
|
|
11866
11480
|
redundancyPoint[j] = encodedData[pointIndex + j * HALF_POINT_SIZE];
|
|
11867
11481
|
}
|
|
@@ -11876,7 +11490,7 @@ function encodePoints(input) {
|
|
|
11876
11490
|
*/
|
|
11877
11491
|
function decodePiece(input) {
|
|
11878
11492
|
const result = Bytes.zero(PIECE_SIZE);
|
|
11879
|
-
const data =
|
|
11493
|
+
const data = safeAllocUint8Array(N_CHUNKS_REQUIRED * POINT_ALIGNMENT);
|
|
11880
11494
|
const indices = new Uint16Array(input.length);
|
|
11881
11495
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11882
11496
|
const [index, points] = input[i];
|
|
@@ -11992,7 +11606,7 @@ function lace(input) {
|
|
|
11992
11606
|
return BytesBlob.empty();
|
|
11993
11607
|
}
|
|
11994
11608
|
const n = input[0].length;
|
|
11995
|
-
const result = BytesBlob.blobFrom(
|
|
11609
|
+
const result = BytesBlob.blobFrom(safeAllocUint8Array(k * n));
|
|
11996
11610
|
for (let i = 0; i < k; i++) {
|
|
11997
11611
|
const entry = input[i].raw;
|
|
11998
11612
|
for (let j = 0; j < n; j++) {
|
|
@@ -12671,6 +12285,8 @@ var NewServiceError;
|
|
|
12671
12285
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
12672
12286
|
/** Service is not privileged to set gratis storage. */
|
|
12673
12287
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
12288
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
12289
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
12674
12290
|
})(NewServiceError || (NewServiceError = {}));
|
|
12675
12291
|
var UpdatePrivilegesError;
|
|
12676
12292
|
(function (UpdatePrivilegesError) {
|
|
@@ -12800,6 +12416,14 @@ const NoMachineError = Symbol("Machine index not found.");
|
|
|
12800
12416
|
const SegmentExportError = Symbol("Too many segments already exported.");
|
|
12801
12417
|
|
|
12802
12418
|
const InsufficientFundsError = "insufficient funds";
|
|
12419
|
+
/** Deep clone of a map with array. */
|
|
12420
|
+
function deepCloneMapWithArray(map) {
|
|
12421
|
+
const cloned = [];
|
|
12422
|
+
for (const [k, v] of map.entries()) {
|
|
12423
|
+
cloned.push([k, v.slice()]);
|
|
12424
|
+
}
|
|
12425
|
+
return new Map(cloned);
|
|
12426
|
+
}
|
|
12803
12427
|
/**
|
|
12804
12428
|
* State updates that currently accumulating service produced.
|
|
12805
12429
|
*
|
|
@@ -12829,10 +12453,11 @@ class AccumulationStateUpdate {
|
|
|
12829
12453
|
/** Create new empty state update. */
|
|
12830
12454
|
static empty() {
|
|
12831
12455
|
return new AccumulationStateUpdate({
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
12835
|
-
|
|
12456
|
+
created: [],
|
|
12457
|
+
updated: new Map(),
|
|
12458
|
+
removed: [],
|
|
12459
|
+
preimages: new Map(),
|
|
12460
|
+
storage: new Map(),
|
|
12836
12461
|
}, []);
|
|
12837
12462
|
}
|
|
12838
12463
|
/** Create a state update with some existing, yet uncommited services updates. */
|
|
@@ -12844,10 +12469,13 @@ class AccumulationStateUpdate {
|
|
|
12844
12469
|
/** Create a copy of another `StateUpdate`. Used by checkpoints. */
|
|
12845
12470
|
static copyFrom(from) {
|
|
12846
12471
|
const serviceUpdates = {
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
12472
|
+
// shallow copy
|
|
12473
|
+
created: [...from.services.created],
|
|
12474
|
+
updated: new Map(from.services.updated),
|
|
12475
|
+
removed: [...from.services.removed],
|
|
12476
|
+
// deep copy
|
|
12477
|
+
preimages: deepCloneMapWithArray(from.services.preimages),
|
|
12478
|
+
storage: deepCloneMapWithArray(from.services.storage),
|
|
12851
12479
|
};
|
|
12852
12480
|
const transfers = [...from.transfers];
|
|
12853
12481
|
const update = new AccumulationStateUpdate(serviceUpdates, transfers, new Map(from.yieldedRoots));
|
|
@@ -12861,11 +12489,17 @@ class AccumulationStateUpdate {
|
|
|
12861
12489
|
if (from.privilegedServices !== null) {
|
|
12862
12490
|
update.privilegedServices = PrivilegedServices.create({
|
|
12863
12491
|
...from.privilegedServices,
|
|
12864
|
-
|
|
12492
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
12865
12493
|
});
|
|
12866
12494
|
}
|
|
12867
12495
|
return update;
|
|
12868
12496
|
}
|
|
12497
|
+
/** Retrieve and clear pending transfers. */
|
|
12498
|
+
takeTransfers() {
|
|
12499
|
+
const transfers = this.transfers;
|
|
12500
|
+
this.transfers = [];
|
|
12501
|
+
return transfers;
|
|
12502
|
+
}
|
|
12869
12503
|
}
|
|
12870
12504
|
class PartiallyUpdatedState {
|
|
12871
12505
|
state;
|
|
@@ -12889,9 +12523,9 @@ class PartiallyUpdatedState {
|
|
|
12889
12523
|
if (destination === null) {
|
|
12890
12524
|
return null;
|
|
12891
12525
|
}
|
|
12892
|
-
const
|
|
12893
|
-
if (
|
|
12894
|
-
return
|
|
12526
|
+
const maybeUpdatedServiceInfo = this.stateUpdate.services.updated.get(destination);
|
|
12527
|
+
if (maybeUpdatedServiceInfo !== undefined) {
|
|
12528
|
+
return maybeUpdatedServiceInfo.action.account;
|
|
12895
12529
|
}
|
|
12896
12530
|
const maybeService = this.state.getService(destination);
|
|
12897
12531
|
if (maybeService === null) {
|
|
@@ -12900,7 +12534,8 @@ class PartiallyUpdatedState {
|
|
|
12900
12534
|
return maybeService.getInfo();
|
|
12901
12535
|
}
|
|
12902
12536
|
getStorage(serviceId, rawKey) {
|
|
12903
|
-
const
|
|
12537
|
+
const storages = this.stateUpdate.services.storage.get(serviceId) ?? [];
|
|
12538
|
+
const item = storages.find((x) => x.key.isEqualTo(rawKey));
|
|
12904
12539
|
if (item !== undefined) {
|
|
12905
12540
|
return item.value;
|
|
12906
12541
|
}
|
|
@@ -12915,10 +12550,11 @@ class PartiallyUpdatedState {
|
|
|
12915
12550
|
* the existence in `preimages` map.
|
|
12916
12551
|
*/
|
|
12917
12552
|
hasPreimage(serviceId, hash) {
|
|
12918
|
-
const
|
|
12553
|
+
const preimages = this.stateUpdate.services.preimages.get(serviceId) ?? [];
|
|
12554
|
+
const providedPreimage = preimages.find(
|
|
12919
12555
|
// we ignore the action here, since if there is <any> update on that
|
|
12920
12556
|
// hash it means it has to exist, right?
|
|
12921
|
-
(p) => p.
|
|
12557
|
+
(p) => p.hash.isEqualTo(hash));
|
|
12922
12558
|
if (providedPreimage !== undefined) {
|
|
12923
12559
|
return true;
|
|
12924
12560
|
}
|
|
@@ -12931,7 +12567,8 @@ class PartiallyUpdatedState {
|
|
|
12931
12567
|
}
|
|
12932
12568
|
getPreimage(serviceId, hash) {
|
|
12933
12569
|
// TODO [ToDr] Should we verify availability here?
|
|
12934
|
-
const
|
|
12570
|
+
const preimages = this.stateUpdate.services.preimages.get(serviceId) ?? [];
|
|
12571
|
+
const freshlyProvided = preimages.find((x) => x.hash.isEqualTo(hash));
|
|
12935
12572
|
if (freshlyProvided !== undefined && freshlyProvided.action.kind === UpdatePreimageKind.Provide) {
|
|
12936
12573
|
return freshlyProvided.action.preimage.blob;
|
|
12937
12574
|
}
|
|
@@ -12940,10 +12577,11 @@ class PartiallyUpdatedState {
|
|
|
12940
12577
|
}
|
|
12941
12578
|
/** Get status of a preimage of current service taking into account any updates. */
|
|
12942
12579
|
getLookupHistory(currentTimeslot, serviceId, hash, length) {
|
|
12580
|
+
const preimages = this.stateUpdate.services.preimages.get(serviceId) ?? [];
|
|
12943
12581
|
// TODO [ToDr] This is most likely wrong. We may have `provide` and `remove` within
|
|
12944
12582
|
// the same state update. We should however switch to proper "updated state"
|
|
12945
12583
|
// representation soon.
|
|
12946
|
-
const updatedPreimage =
|
|
12584
|
+
const updatedPreimage = preimages.findLast((update) => update.hash.isEqualTo(hash) && BigInt(update.length) === length);
|
|
12947
12585
|
const stateFallback = () => {
|
|
12948
12586
|
// fallback to state lookup
|
|
12949
12587
|
const service = this.state.getService(serviceId);
|
|
@@ -12980,14 +12618,15 @@ class PartiallyUpdatedState {
|
|
|
12980
12618
|
/* State update functions. */
|
|
12981
12619
|
updateStorage(serviceId, key, value) {
|
|
12982
12620
|
const update = value === null
|
|
12983
|
-
? UpdateStorage.remove({
|
|
12621
|
+
? UpdateStorage.remove({ key })
|
|
12984
12622
|
: UpdateStorage.set({
|
|
12985
|
-
serviceId,
|
|
12986
12623
|
storage: StorageItem.create({ key, value }),
|
|
12987
12624
|
});
|
|
12988
|
-
const
|
|
12625
|
+
const storages = this.stateUpdate.services.storage.get(serviceId) ?? [];
|
|
12626
|
+
const index = storages.findIndex((x) => x.key.isEqualTo(key));
|
|
12989
12627
|
const count = index === -1 ? 0 : 1;
|
|
12990
|
-
|
|
12628
|
+
storages.splice(index, count, update);
|
|
12629
|
+
this.stateUpdate.services.storage.set(serviceId, storages);
|
|
12991
12630
|
}
|
|
12992
12631
|
/**
|
|
12993
12632
|
* Update a preimage.
|
|
@@ -12995,8 +12634,10 @@ class PartiallyUpdatedState {
|
|
|
12995
12634
|
* Note we store all previous entries as well, since there might be a sequence of:
|
|
12996
12635
|
* `provide` -> `remove` and both should update the end state somehow.
|
|
12997
12636
|
*/
|
|
12998
|
-
updatePreimage(newUpdate) {
|
|
12999
|
-
this.stateUpdate.services.preimages.
|
|
12637
|
+
updatePreimage(serviceId, newUpdate) {
|
|
12638
|
+
const updatePreimages = this.stateUpdate.services.preimages.get(serviceId) ?? [];
|
|
12639
|
+
updatePreimages.push(newUpdate);
|
|
12640
|
+
this.stateUpdate.services.preimages.set(serviceId, updatePreimages);
|
|
13000
12641
|
}
|
|
13001
12642
|
updateServiceStorageUtilisation(serviceId, items, bytes, serviceInfo) {
|
|
13002
12643
|
check `${items >= 0} storageUtilisationCount has to be a positive number, got: ${items}`;
|
|
@@ -13005,11 +12646,11 @@ class PartiallyUpdatedState {
|
|
|
13005
12646
|
const overflowBytes = !isU64(bytes);
|
|
13006
12647
|
// TODO [ToDr] this is not specified in GP, but it seems sensible.
|
|
13007
12648
|
if (overflowItems || overflowBytes) {
|
|
13008
|
-
return Result$1.error(InsufficientFundsError);
|
|
12649
|
+
return Result$1.error(InsufficientFundsError, () => `Storage utilisation overflow: items=${overflowItems}, bytes=${overflowBytes}`);
|
|
13009
12650
|
}
|
|
13010
12651
|
const thresholdBalance = ServiceAccountInfo.calculateThresholdBalance(items, bytes, serviceInfo.gratisStorage);
|
|
13011
12652
|
if (serviceInfo.balance < thresholdBalance) {
|
|
13012
|
-
return Result$1.error(InsufficientFundsError);
|
|
12653
|
+
return Result$1.error(InsufficientFundsError, () => `Service balance (${serviceInfo.balance}) below threshold (${thresholdBalance})`);
|
|
13013
12654
|
}
|
|
13014
12655
|
// Update service info with new details.
|
|
13015
12656
|
this.updateServiceInfo(serviceId, ServiceAccountInfo.create({
|
|
@@ -13020,20 +12661,23 @@ class PartiallyUpdatedState {
|
|
|
13020
12661
|
return Result$1.ok(OK);
|
|
13021
12662
|
}
|
|
13022
12663
|
updateServiceInfo(serviceId, newInfo) {
|
|
13023
|
-
const
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
if (existingItem?.action.kind === UpdateServiceKind.Create) {
|
|
13027
|
-
this.stateUpdate.services.servicesUpdates.splice(idx, toRemove, UpdateService.create({
|
|
13028
|
-
serviceId,
|
|
12664
|
+
const existingUpdate = this.stateUpdate.services.updated.get(serviceId);
|
|
12665
|
+
if (existingUpdate?.action.kind === UpdateServiceKind.Create) {
|
|
12666
|
+
this.stateUpdate.services.updated.set(serviceId, UpdateService.create({
|
|
13029
12667
|
serviceInfo: newInfo,
|
|
13030
|
-
lookupHistory:
|
|
12668
|
+
lookupHistory: existingUpdate.action.lookupHistory,
|
|
13031
12669
|
}));
|
|
13032
12670
|
return;
|
|
13033
12671
|
}
|
|
13034
|
-
this.stateUpdate.services.
|
|
13035
|
-
|
|
12672
|
+
this.stateUpdate.services.updated.set(serviceId, UpdateService.update({
|
|
12673
|
+
serviceInfo: newInfo,
|
|
12674
|
+
}));
|
|
12675
|
+
}
|
|
12676
|
+
createService(serviceId, newInfo, newLookupHistory) {
|
|
12677
|
+
this.stateUpdate.services.created.push(serviceId);
|
|
12678
|
+
this.stateUpdate.services.updated.set(serviceId, UpdateService.create({
|
|
13036
12679
|
serviceInfo: newInfo,
|
|
12680
|
+
lookupHistory: newLookupHistory,
|
|
13037
12681
|
}));
|
|
13038
12682
|
}
|
|
13039
12683
|
getPrivilegedServices() {
|
|
@@ -13062,7 +12706,7 @@ const HostCallResult = {
|
|
|
13062
12706
|
OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
13063
12707
|
/** Index unknown. */
|
|
13064
12708
|
WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
13065
|
-
/** Storage full. */
|
|
12709
|
+
/** Storage full or resource already allocated. */
|
|
13066
12710
|
FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
13067
12711
|
/** Core index unknown. */
|
|
13068
12712
|
CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -13070,7 +12714,7 @@ const HostCallResult = {
|
|
|
13070
12714
|
CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
13071
12715
|
/** Gas limit too low. */
|
|
13072
12716
|
LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
13073
|
-
/** The item is already solicited
|
|
12717
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
13074
12718
|
HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
13075
12719
|
/** The return value indicating general success. */
|
|
13076
12720
|
OK: tryAsU64(0n),
|
|
@@ -13271,7 +12915,7 @@ class Registers {
|
|
|
13271
12915
|
bytes;
|
|
13272
12916
|
asSigned;
|
|
13273
12917
|
asUnsigned;
|
|
13274
|
-
constructor(bytes =
|
|
12918
|
+
constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT)) {
|
|
13275
12919
|
this.bytes = bytes;
|
|
13276
12920
|
check `${bytes.length === NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
13277
12921
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
@@ -13424,7 +13068,7 @@ class Mask {
|
|
|
13424
13068
|
return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
|
|
13425
13069
|
}
|
|
13426
13070
|
buildLookupTableForward(mask) {
|
|
13427
|
-
const table =
|
|
13071
|
+
const table = safeAllocUint8Array(mask.bitLength);
|
|
13428
13072
|
let lastInstructionOffset = 0;
|
|
13429
13073
|
for (let i = mask.bitLength - 1; i >= 0; i--) {
|
|
13430
13074
|
if (mask.isSet(i)) {
|
|
@@ -14654,7 +14298,7 @@ class ReadablePage extends MemoryPage {
|
|
|
14654
14298
|
loadInto(result, startIndex, length) {
|
|
14655
14299
|
const endIndex = startIndex + length;
|
|
14656
14300
|
if (endIndex > PAGE_SIZE$1) {
|
|
14657
|
-
return Result$1.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE$1));
|
|
14301
|
+
return Result$1.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE$1), () => `Page fault: read beyond page boundary at ${this.start + PAGE_SIZE$1}`);
|
|
14658
14302
|
}
|
|
14659
14303
|
const bytes = this.data.subarray(startIndex, endIndex);
|
|
14660
14304
|
// we zero the bytes, since data might not yet be initialized at `endIndex`.
|
|
@@ -14663,7 +14307,7 @@ class ReadablePage extends MemoryPage {
|
|
|
14663
14307
|
return Result$1.ok(OK);
|
|
14664
14308
|
}
|
|
14665
14309
|
storeFrom(_address, _data) {
|
|
14666
|
-
return Result$1.error(PageFault.fromMemoryIndex(this.start, true));
|
|
14310
|
+
return Result$1.error(PageFault.fromMemoryIndex(this.start, true), () => `Page fault: attempted to write to read-only page at ${this.start}`);
|
|
14667
14311
|
}
|
|
14668
14312
|
setData(pageIndex, data) {
|
|
14669
14313
|
this.data.set(data, pageIndex);
|
|
@@ -14692,7 +14336,7 @@ class WriteablePage extends MemoryPage {
|
|
|
14692
14336
|
loadInto(result, startIndex, length) {
|
|
14693
14337
|
const endIndex = startIndex + length;
|
|
14694
14338
|
if (endIndex > PAGE_SIZE$1) {
|
|
14695
|
-
return Result$1.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE$1));
|
|
14339
|
+
return Result$1.error(PageFault.fromMemoryIndex(this.start + PAGE_SIZE$1), () => `Page fault: read beyond page boundary at ${this.start + PAGE_SIZE$1}`);
|
|
14696
14340
|
}
|
|
14697
14341
|
const bytes = this.view.subarray(startIndex, endIndex);
|
|
14698
14342
|
// we zero the bytes, since the view might not yet be initialized at `endIndex`.
|
|
@@ -14762,7 +14406,7 @@ class Memory {
|
|
|
14762
14406
|
logger$3.insane `MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`;
|
|
14763
14407
|
const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
|
|
14764
14408
|
if (pagesResult.isError) {
|
|
14765
|
-
return Result$1.error(pagesResult.error);
|
|
14409
|
+
return Result$1.error(pagesResult.error, pagesResult.details);
|
|
14766
14410
|
}
|
|
14767
14411
|
const pages = pagesResult.ok;
|
|
14768
14412
|
let currentPosition = address;
|
|
@@ -14787,14 +14431,14 @@ class Memory {
|
|
|
14787
14431
|
const pages = [];
|
|
14788
14432
|
for (const pageNumber of pageRange) {
|
|
14789
14433
|
if (pageNumber < RESERVED_NUMBER_OF_PAGES) {
|
|
14790
|
-
return Result$1.error(PageFault.fromPageNumber(pageNumber, true));
|
|
14434
|
+
return Result$1.error(PageFault.fromPageNumber(pageNumber, true), () => `Page fault: attempted to access reserved page ${pageNumber}`);
|
|
14791
14435
|
}
|
|
14792
14436
|
const page = this.memory.get(pageNumber);
|
|
14793
14437
|
if (page === undefined) {
|
|
14794
|
-
return Result$1.error(PageFault.fromPageNumber(pageNumber));
|
|
14438
|
+
return Result$1.error(PageFault.fromPageNumber(pageNumber), () => `Page fault: page ${pageNumber} not allocated`);
|
|
14795
14439
|
}
|
|
14796
14440
|
if (accessType === AccessType.WRITE && !page.isWriteable()) {
|
|
14797
|
-
return Result$1.error(PageFault.fromPageNumber(pageNumber, true));
|
|
14441
|
+
return Result$1.error(PageFault.fromPageNumber(pageNumber, true), () => `Page fault: attempted to write to read-only page ${pageNumber}`);
|
|
14798
14442
|
}
|
|
14799
14443
|
pages.push(page);
|
|
14800
14444
|
}
|
|
@@ -14812,7 +14456,7 @@ class Memory {
|
|
|
14812
14456
|
}
|
|
14813
14457
|
const pagesResult = this.getPages(startAddress, result.length, AccessType.READ);
|
|
14814
14458
|
if (pagesResult.isError) {
|
|
14815
|
-
return Result$1.error(pagesResult.error);
|
|
14459
|
+
return Result$1.error(pagesResult.error, pagesResult.details);
|
|
14816
14460
|
}
|
|
14817
14461
|
const pages = pagesResult.ok;
|
|
14818
14462
|
let currentPosition = startAddress;
|
|
@@ -15105,11 +14749,6 @@ class BitOps {
|
|
|
15105
14749
|
}
|
|
15106
14750
|
}
|
|
15107
14751
|
|
|
15108
|
-
const MAX_VALUE = 4294967295;
|
|
15109
|
-
const MIN_VALUE = -2147483648;
|
|
15110
|
-
const MAX_SHIFT_U32 = 32;
|
|
15111
|
-
const MAX_SHIFT_U64 = 64n;
|
|
15112
|
-
|
|
15113
14752
|
/**
|
|
15114
14753
|
* Overflowing addition for two-complement representation of 32-bit signed numbers.
|
|
15115
14754
|
*/
|
|
@@ -16622,7 +16261,7 @@ class ProgramDecoder {
|
|
|
16622
16261
|
}
|
|
16623
16262
|
catch (e) {
|
|
16624
16263
|
logger$2.error `Invalid program: ${e}`;
|
|
16625
|
-
return Result$1.error(ProgramDecoderError.InvalidProgramError);
|
|
16264
|
+
return Result$1.error(ProgramDecoderError.InvalidProgramError, () => `Program decoder error: ${e}`);
|
|
16626
16265
|
}
|
|
16627
16266
|
}
|
|
16628
16267
|
}
|
|
@@ -16859,6 +16498,24 @@ class Interpreter {
|
|
|
16859
16498
|
getMemoryPage(pageNumber) {
|
|
16860
16499
|
return this.memory.getPageDump(tryAsPageNumber(pageNumber));
|
|
16861
16500
|
}
|
|
16501
|
+
calculateBlockGasCost() {
|
|
16502
|
+
const codeLength = this.code.length;
|
|
16503
|
+
const blocks = new Map();
|
|
16504
|
+
let currentBlock = "0";
|
|
16505
|
+
let gasCost = 0;
|
|
16506
|
+
const getNextIstructionIndex = (index) => index + 1 + this.mask.getNoOfBytesToNextInstruction(index + 1);
|
|
16507
|
+
for (let index = 0; index < codeLength; index = getNextIstructionIndex(index)) {
|
|
16508
|
+
const instruction = this.code[index];
|
|
16509
|
+
if (this.basicBlocks.isBeginningOfBasicBlock(index)) {
|
|
16510
|
+
blocks.set(currentBlock, gasCost);
|
|
16511
|
+
currentBlock = index.toString();
|
|
16512
|
+
gasCost = 0;
|
|
16513
|
+
}
|
|
16514
|
+
gasCost += instructionGasMap[instruction];
|
|
16515
|
+
}
|
|
16516
|
+
blocks.set(currentBlock, gasCost);
|
|
16517
|
+
return blocks;
|
|
16518
|
+
}
|
|
16862
16519
|
}
|
|
16863
16520
|
|
|
16864
16521
|
var index$7 = /*#__PURE__*/Object.freeze({
|
|
@@ -16885,7 +16542,7 @@ class HostCallMemory {
|
|
|
16885
16542
|
return Result$1.ok(OK);
|
|
16886
16543
|
}
|
|
16887
16544
|
if (address + tryAsU64(bytes.length) > MEMORY_SIZE) {
|
|
16888
|
-
return Result$1.error(new OutOfBounds());
|
|
16545
|
+
return Result$1.error(new OutOfBounds(), () => `Memory access out of bounds: address ${address} + length ${bytes.length} exceeds memory size`);
|
|
16889
16546
|
}
|
|
16890
16547
|
return this.memory.storeFrom(tryAsMemoryIndex(Number(address)), bytes);
|
|
16891
16548
|
}
|
|
@@ -16894,13 +16551,10 @@ class HostCallMemory {
|
|
|
16894
16551
|
return Result$1.ok(OK);
|
|
16895
16552
|
}
|
|
16896
16553
|
if (startAddress + tryAsU64(result.length) > MEMORY_SIZE) {
|
|
16897
|
-
return Result$1.error(new OutOfBounds());
|
|
16554
|
+
return Result$1.error(new OutOfBounds(), () => `Memory access out of bounds: address ${startAddress} + length ${result.length} exceeds memory size`);
|
|
16898
16555
|
}
|
|
16899
16556
|
return this.memory.loadInto(result, tryAsMemoryIndex(Number(startAddress)));
|
|
16900
16557
|
}
|
|
16901
|
-
getMemory() {
|
|
16902
|
-
return this.memory;
|
|
16903
|
-
}
|
|
16904
16558
|
}
|
|
16905
16559
|
|
|
16906
16560
|
class HostCallRegisters {
|
|
@@ -16959,7 +16613,7 @@ class HostCalls {
|
|
|
16959
16613
|
const regs = pvmInstance.getRegisters();
|
|
16960
16614
|
const maybeAddress = regs.getLowerU32(7);
|
|
16961
16615
|
const maybeLength = regs.getLowerU32(8);
|
|
16962
|
-
const result =
|
|
16616
|
+
const result = safeAllocUint8Array(maybeLength);
|
|
16963
16617
|
const startAddress = tryAsMemoryIndex(maybeAddress);
|
|
16964
16618
|
const loadResult = memory.loadInto(result, startAddress);
|
|
16965
16619
|
if (loadResult.isError) {
|
|
@@ -17308,14 +16962,14 @@ class DebuggerAdapter {
|
|
|
17308
16962
|
const page = this.pvm.getMemoryPage(pageNumber);
|
|
17309
16963
|
if (page === null) {
|
|
17310
16964
|
// page wasn't allocated so we return an empty page
|
|
17311
|
-
return
|
|
16965
|
+
return safeAllocUint8Array(PAGE_SIZE$1);
|
|
17312
16966
|
}
|
|
17313
16967
|
if (page.length === PAGE_SIZE$1) {
|
|
17314
16968
|
// page was allocated and has a proper size so we can simply return it
|
|
17315
16969
|
return page;
|
|
17316
16970
|
}
|
|
17317
16971
|
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
17318
|
-
const fullPage =
|
|
16972
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
|
|
17319
16973
|
fullPage.set(page);
|
|
17320
16974
|
return fullPage;
|
|
17321
16975
|
}
|
|
@@ -17419,7 +17073,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
17419
17073
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
17420
17074
|
getServiceId: getServiceId,
|
|
17421
17075
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
17422
|
-
hash: index$
|
|
17076
|
+
hash: index$o,
|
|
17423
17077
|
inspect: inspect,
|
|
17424
17078
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
17425
17079
|
interpreter: index$7,
|
|
@@ -17441,10 +17095,10 @@ const ENTROPY_BYTES = 32;
|
|
|
17441
17095
|
*
|
|
17442
17096
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
17443
17097
|
*/
|
|
17444
|
-
function fisherYatesShuffle(arr, entropy) {
|
|
17098
|
+
function fisherYatesShuffle(blake2b, arr, entropy) {
|
|
17445
17099
|
check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
17446
17100
|
const n = arr.length;
|
|
17447
|
-
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
17101
|
+
const randomNumbers = hashToNumberSequence(blake2b, entropy, arr.length);
|
|
17448
17102
|
const result = new Array(n);
|
|
17449
17103
|
let itemsLeft = n;
|
|
17450
17104
|
for (let i = 0; i < n; i++) {
|
|
@@ -17457,13 +17111,13 @@ function fisherYatesShuffle(arr, entropy) {
|
|
|
17457
17111
|
}
|
|
17458
17112
|
return result;
|
|
17459
17113
|
}
|
|
17460
|
-
function hashToNumberSequence(entropy, length) {
|
|
17114
|
+
function hashToNumberSequence(blake2b, entropy, length) {
|
|
17461
17115
|
const result = new Array(length);
|
|
17462
|
-
const randomBytes =
|
|
17116
|
+
const randomBytes = safeAllocUint8Array(ENTROPY_BYTES + 4);
|
|
17463
17117
|
randomBytes.set(entropy.raw);
|
|
17464
17118
|
for (let i = 0; i < length; i++) {
|
|
17465
17119
|
randomBytes.set(u32AsLeBytes(tryAsU32(Math.floor(i / 8))), ENTROPY_BYTES);
|
|
17466
|
-
const newHash = hashBytes(randomBytes);
|
|
17120
|
+
const newHash = blake2b.hashBytes(randomBytes);
|
|
17467
17121
|
const numberStartIndex = (4 * i) % 32;
|
|
17468
17122
|
const numberEndIndex = numberStartIndex + 4;
|
|
17469
17123
|
const number = leBytesAsU32(newHash.raw.subarray(numberStartIndex, numberEndIndex)) >>> 0;
|
|
@@ -17479,6 +17133,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
17479
17133
|
|
|
17480
17134
|
class JsonServiceInfo {
|
|
17481
17135
|
static fromJson = json.object({
|
|
17136
|
+
...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
|
|
17482
17137
|
code_hash: fromJson.bytes32(),
|
|
17483
17138
|
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
17484
17139
|
min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
@@ -17503,6 +17158,7 @@ class JsonServiceInfo {
|
|
|
17503
17158
|
parentService: parent_service,
|
|
17504
17159
|
});
|
|
17505
17160
|
});
|
|
17161
|
+
version;
|
|
17506
17162
|
code_hash;
|
|
17507
17163
|
balance;
|
|
17508
17164
|
min_item_gas;
|
|
@@ -17537,23 +17193,35 @@ const lookupMetaFromJson = json.object({
|
|
|
17537
17193
|
},
|
|
17538
17194
|
value: json.array("number"),
|
|
17539
17195
|
}, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
|
|
17196
|
+
const preimageStatusFromJson = json.object({
|
|
17197
|
+
hash: fromJson.bytes32(),
|
|
17198
|
+
status: json.array("number"),
|
|
17199
|
+
}, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
|
|
17540
17200
|
class JsonService {
|
|
17541
17201
|
static fromJson = json.object({
|
|
17542
17202
|
id: "number",
|
|
17543
|
-
data:
|
|
17544
|
-
|
|
17545
|
-
|
|
17546
|
-
|
|
17547
|
-
|
|
17548
|
-
|
|
17203
|
+
data: Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17204
|
+
? {
|
|
17205
|
+
service: JsonServiceInfo.fromJson,
|
|
17206
|
+
preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
17207
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
17208
|
+
lookup_meta: json.optional(json.array(lookupMetaFromJson)),
|
|
17209
|
+
}
|
|
17210
|
+
: {
|
|
17211
|
+
service: JsonServiceInfo.fromJson,
|
|
17212
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
17213
|
+
preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
17214
|
+
preimages_status: json.optional(json.array(preimageStatusFromJson)),
|
|
17215
|
+
},
|
|
17549
17216
|
}, ({ id, data }) => {
|
|
17217
|
+
const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
|
|
17550
17218
|
const lookupHistory = HashDictionary.new();
|
|
17551
|
-
for (const item of data.lookup_meta ?? []) {
|
|
17219
|
+
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
17552
17220
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
17553
|
-
|
|
17221
|
+
const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
17222
|
+
data.push(new LookupHistoryItem(item.hash, length, item.slots));
|
|
17554
17223
|
lookupHistory.set(item.hash, data);
|
|
17555
17224
|
}
|
|
17556
|
-
const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
|
|
17557
17225
|
const storage = new Map();
|
|
17558
17226
|
const entries = (data.storage ?? []).map(({ key, value }) => {
|
|
17559
17227
|
const opaqueKey = asOpaqueType(key);
|
|
@@ -17577,8 +17245,7 @@ const availabilityAssignmentFromJson = json.object({
|
|
|
17577
17245
|
report: workReportFromJson,
|
|
17578
17246
|
timeout: "number",
|
|
17579
17247
|
}, ({ report, timeout }) => {
|
|
17580
|
-
|
|
17581
|
-
return AvailabilityAssignment.create({ workReport: new WithHash(workReportHash, report), timeout });
|
|
17248
|
+
return AvailabilityAssignment.create({ workReport: report, timeout });
|
|
17582
17249
|
});
|
|
17583
17250
|
|
|
17584
17251
|
const disputesRecordsFromJson = json.object({
|
|
@@ -17630,10 +17297,10 @@ const recentBlocksHistoryFromJson = json.object({
|
|
|
17630
17297
|
peaks: json.array(json.nullable(fromJson.bytes32())),
|
|
17631
17298
|
},
|
|
17632
17299
|
}, ({ history, mmr }) => {
|
|
17633
|
-
return
|
|
17300
|
+
return RecentBlocks.create({
|
|
17634
17301
|
blocks: history,
|
|
17635
17302
|
accumulationLog: mmr,
|
|
17636
|
-
})
|
|
17303
|
+
});
|
|
17637
17304
|
});
|
|
17638
17305
|
|
|
17639
17306
|
const ticketFromJson = json.object({
|
|
@@ -17726,8 +17393,12 @@ class JsonServiceStatistics {
|
|
|
17726
17393
|
extrinsic_count: "number",
|
|
17727
17394
|
accumulate_count: "number",
|
|
17728
17395
|
accumulate_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17729
|
-
|
|
17730
|
-
|
|
17396
|
+
...(Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17397
|
+
? {
|
|
17398
|
+
on_transfers_count: "number",
|
|
17399
|
+
on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17400
|
+
}
|
|
17401
|
+
: {}),
|
|
17731
17402
|
}, ({ 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, }) => {
|
|
17732
17403
|
return ServiceStatistics.create({
|
|
17733
17404
|
providedCount: provided_count,
|
|
@@ -17740,8 +17411,8 @@ class JsonServiceStatistics {
|
|
|
17740
17411
|
extrinsicCount: extrinsic_count,
|
|
17741
17412
|
accumulateCount: accumulate_count,
|
|
17742
17413
|
accumulateGasUsed: accumulate_gas_used,
|
|
17743
|
-
onTransfersCount: on_transfers_count,
|
|
17744
|
-
onTransfersGasUsed: on_transfers_gas_used,
|
|
17414
|
+
onTransfersCount: on_transfers_count ?? tryAsU32(0),
|
|
17415
|
+
onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
|
|
17745
17416
|
});
|
|
17746
17417
|
});
|
|
17747
17418
|
provided_count;
|
|
@@ -17812,6 +17483,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17812
17483
|
chi_m: "number",
|
|
17813
17484
|
chi_a: json.array("number"),
|
|
17814
17485
|
chi_v: "number",
|
|
17486
|
+
chi_r: json.optional("number"),
|
|
17815
17487
|
chi_g: json.nullable(json.array({
|
|
17816
17488
|
service: "number",
|
|
17817
17489
|
gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
|
|
@@ -17823,7 +17495,10 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17823
17495
|
theta: json.nullable(json.array(accumulationOutput)),
|
|
17824
17496
|
accounts: json.array(JsonService.fromJson),
|
|
17825
17497
|
}, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
|
|
17826
|
-
|
|
17498
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
17499
|
+
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
17500
|
+
}
|
|
17501
|
+
return InMemoryState.new(spec, {
|
|
17827
17502
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17828
17503
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
17829
17504
|
throw new Error(`AuthPools: expected less than ${MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
|
|
@@ -17836,7 +17511,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17836
17511
|
}
|
|
17837
17512
|
return asKnownSize(perCore);
|
|
17838
17513
|
}), spec),
|
|
17839
|
-
recentBlocks: beta ??
|
|
17514
|
+
recentBlocks: beta ?? RecentBlocks.empty(),
|
|
17840
17515
|
nextValidatorData: gamma.gamma_k,
|
|
17841
17516
|
epochRoot: gamma.gamma_z,
|
|
17842
17517
|
sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
|
|
@@ -17850,8 +17525,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17850
17525
|
timeslot: tau,
|
|
17851
17526
|
privilegedServices: PrivilegedServices.create({
|
|
17852
17527
|
manager: chi.chi_m,
|
|
17853
|
-
|
|
17854
|
-
|
|
17528
|
+
assigners: chi.chi_a,
|
|
17529
|
+
delegator: chi.chi_v,
|
|
17530
|
+
registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
|
|
17855
17531
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
17856
17532
|
}),
|
|
17857
17533
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|
|
@@ -17884,11 +17560,11 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17884
17560
|
class TransitionHasher {
|
|
17885
17561
|
context;
|
|
17886
17562
|
keccakHasher;
|
|
17887
|
-
|
|
17888
|
-
constructor(context, keccakHasher,
|
|
17563
|
+
blake2b;
|
|
17564
|
+
constructor(context, keccakHasher, blake2b) {
|
|
17889
17565
|
this.context = context;
|
|
17890
17566
|
this.keccakHasher = keccakHasher;
|
|
17891
|
-
this.
|
|
17567
|
+
this.blake2b = blake2b;
|
|
17892
17568
|
}
|
|
17893
17569
|
/** Concatenates two hashes and hash this concatenation */
|
|
17894
17570
|
hashConcat(a, b) {
|
|
@@ -17899,7 +17575,7 @@ class TransitionHasher {
|
|
|
17899
17575
|
}
|
|
17900
17576
|
/** Creates hash from the block header view */
|
|
17901
17577
|
header(header) {
|
|
17902
|
-
return new WithHash(hashBytes(header.encoded()
|
|
17578
|
+
return new WithHash(this.blake2b.hashBytes(header.encoded()).asOpaque(), header);
|
|
17903
17579
|
}
|
|
17904
17580
|
/**
|
|
17905
17581
|
* Merkle commitment of the extrinsic data
|
|
@@ -17908,25 +17584,25 @@ class TransitionHasher {
|
|
|
17908
17584
|
*/
|
|
17909
17585
|
extrinsic(extrinsicView) {
|
|
17910
17586
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
17911
|
-
const
|
|
17587
|
+
const guaranteesCount = tryAsU32(extrinsicView.guarantees.view().length);
|
|
17588
|
+
const countEncoded = Encoder.encodeObject(codec$1.varU32, guaranteesCount);
|
|
17589
|
+
const guaranteesBlobs = extrinsicView.guarantees
|
|
17912
17590
|
.view()
|
|
17913
17591
|
.map((g) => g.view())
|
|
17914
|
-
.
|
|
17915
|
-
const reportHash = hashBytes(guarantee.report.encoded()
|
|
17916
|
-
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
const
|
|
17923
|
-
const
|
|
17924
|
-
const
|
|
17925
|
-
const
|
|
17926
|
-
const ea = hashBytes(extrinsicView.assurances.encoded(), this.allocator).asOpaque();
|
|
17927
|
-
const ed = hashBytes(extrinsicView.disputes.encoded(), this.allocator).asOpaque();
|
|
17592
|
+
.reduce((aggregated, guarantee) => {
|
|
17593
|
+
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17594
|
+
aggregated.push(reportHash.raw);
|
|
17595
|
+
aggregated.push(guarantee.slot.encoded().raw);
|
|
17596
|
+
aggregated.push(guarantee.credentials.encoded().raw);
|
|
17597
|
+
return aggregated;
|
|
17598
|
+
}, [countEncoded.raw]);
|
|
17599
|
+
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17600
|
+
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17601
|
+
const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
|
|
17602
|
+
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17603
|
+
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17928
17604
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
17929
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17605
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
17930
17606
|
}
|
|
17931
17607
|
/** Creates hash for given WorkPackage */
|
|
17932
17608
|
workPackage(workPackage) {
|
|
@@ -17935,7 +17611,7 @@ class TransitionHasher {
|
|
|
17935
17611
|
encode(codec, data) {
|
|
17936
17612
|
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
17937
17613
|
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
17938
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17614
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
17939
17615
|
}
|
|
17940
17616
|
}
|
|
17941
17617
|
|
|
@@ -17948,8 +17624,10 @@ var PreimagesErrorCode;
|
|
|
17948
17624
|
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
17949
17625
|
class Preimages {
|
|
17950
17626
|
state;
|
|
17951
|
-
|
|
17627
|
+
blake2b;
|
|
17628
|
+
constructor(state, blake2b) {
|
|
17952
17629
|
this.state = state;
|
|
17630
|
+
this.blake2b = blake2b;
|
|
17953
17631
|
}
|
|
17954
17632
|
integrate(input) {
|
|
17955
17633
|
// make sure lookup extrinsics are sorted and unique
|
|
@@ -17964,32 +17642,33 @@ class Preimages {
|
|
|
17964
17642
|
}
|
|
17965
17643
|
if (prevPreimage.requester > currPreimage.requester ||
|
|
17966
17644
|
currPreimage.blob.compare(prevPreimage.blob).isLessOrEqual()) {
|
|
17967
|
-
return Result$1.error(PreimagesErrorCode.PreimagesNotSortedUnique);
|
|
17645
|
+
return Result$1.error(PreimagesErrorCode.PreimagesNotSortedUnique, () => `Preimages not sorted/unique at index ${i}`);
|
|
17968
17646
|
}
|
|
17969
17647
|
}
|
|
17970
17648
|
const { preimages, slot } = input;
|
|
17971
|
-
const pendingChanges =
|
|
17649
|
+
const pendingChanges = new Map();
|
|
17972
17650
|
// select preimages for integration
|
|
17973
17651
|
for (const preimage of preimages) {
|
|
17974
17652
|
const { requester, blob } = preimage;
|
|
17975
|
-
const hash = hashBytes(blob).asOpaque();
|
|
17653
|
+
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
17976
17654
|
const service = this.state.getService(requester);
|
|
17977
17655
|
if (service === null) {
|
|
17978
|
-
return Result$1.error(PreimagesErrorCode.AccountNotFound);
|
|
17656
|
+
return Result$1.error(PreimagesErrorCode.AccountNotFound, () => `Service not found: ${requester}`);
|
|
17979
17657
|
}
|
|
17980
17658
|
const hasPreimage = service.hasPreimage(hash);
|
|
17981
17659
|
const slots = service.getLookupHistory(hash, tryAsU32(blob.length));
|
|
17982
17660
|
// https://graypaper.fluffylabs.dev/#/5f542d7/181800181900
|
|
17983
17661
|
// https://graypaper.fluffylabs.dev/#/5f542d7/116f0011a500
|
|
17984
17662
|
if (hasPreimage || slots === null || !LookupHistoryItem.isRequested(slots)) {
|
|
17985
|
-
return Result$1.error(PreimagesErrorCode.PreimageUnneeded);
|
|
17663
|
+
return Result$1.error(PreimagesErrorCode.PreimageUnneeded, () => `Preimage unneeded: requester=${requester}, hash=${hash}, hasPreimage=${hasPreimage}, isRequested=${slots !== null && LookupHistoryItem.isRequested(slots)}`);
|
|
17986
17664
|
}
|
|
17987
17665
|
// https://graypaper.fluffylabs.dev/#/5f542d7/18c00018f300
|
|
17988
|
-
pendingChanges.
|
|
17989
|
-
|
|
17666
|
+
const updates = pendingChanges.get(requester) ?? [];
|
|
17667
|
+
updates.push(UpdatePreimage.provide({
|
|
17990
17668
|
preimage: PreimageItem.create({ hash, blob }),
|
|
17991
17669
|
slot,
|
|
17992
17670
|
}));
|
|
17671
|
+
pendingChanges.set(requester, updates);
|
|
17993
17672
|
}
|
|
17994
17673
|
return Result$1.ok({
|
|
17995
17674
|
preimages: pendingChanges,
|
|
@@ -17997,146 +17676,11 @@ class Preimages {
|
|
|
17997
17676
|
}
|
|
17998
17677
|
}
|
|
17999
17678
|
|
|
18000
|
-
class Missing {
|
|
18001
|
-
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
18002
|
-
basicGasCost = tryAsSmallGas(10);
|
|
18003
|
-
currentServiceId = CURRENT_SERVICE_ID;
|
|
18004
|
-
tracedRegisters = traceRegisters(7);
|
|
18005
|
-
execute(_gas, regs, _memory) {
|
|
18006
|
-
regs.set(7, HostCallResult.WHAT);
|
|
18007
|
-
return Promise.resolve(undefined);
|
|
18008
|
-
}
|
|
18009
|
-
}
|
|
18010
|
-
|
|
18011
|
-
var ServiceExecutorError;
|
|
18012
|
-
(function (ServiceExecutorError) {
|
|
18013
|
-
ServiceExecutorError[ServiceExecutorError["NoLookup"] = 0] = "NoLookup";
|
|
18014
|
-
ServiceExecutorError[ServiceExecutorError["NoState"] = 1] = "NoState";
|
|
18015
|
-
ServiceExecutorError[ServiceExecutorError["NoServiceCode"] = 2] = "NoServiceCode";
|
|
18016
|
-
ServiceExecutorError[ServiceExecutorError["ServiceCodeMismatch"] = 3] = "ServiceCodeMismatch";
|
|
18017
|
-
})(ServiceExecutorError || (ServiceExecutorError = {}));
|
|
18018
|
-
class WorkPackageExecutor {
|
|
18019
|
-
blocks;
|
|
18020
|
-
state;
|
|
18021
|
-
hasher;
|
|
18022
|
-
constructor(blocks, state, hasher) {
|
|
18023
|
-
this.blocks = blocks;
|
|
18024
|
-
this.state = state;
|
|
18025
|
-
this.hasher = hasher;
|
|
18026
|
-
}
|
|
18027
|
-
// TODO [ToDr] this while thing should be triple-checked with the GP.
|
|
18028
|
-
// I'm currently implementing some dirty version for the demo.
|
|
18029
|
-
async executeWorkPackage(pack) {
|
|
18030
|
-
const headerHash = pack.context.lookupAnchor;
|
|
18031
|
-
// execute authorisation first or is it already executed and we just need to check it?
|
|
18032
|
-
const authExec = this.getServiceExecutor(
|
|
18033
|
-
// TODO [ToDr] should this be anchor or lookupAnchor?
|
|
18034
|
-
headerHash, pack.authCodeHost, pack.authCodeHash);
|
|
18035
|
-
if (authExec.isError) {
|
|
18036
|
-
// TODO [ToDr] most likely shouldn't be throw.
|
|
18037
|
-
throw new Error(`Could not get authorization executor: ${authExec.error}`);
|
|
18038
|
-
}
|
|
18039
|
-
const pvm = authExec.ok;
|
|
18040
|
-
const authGas = tryAsGas(15000n);
|
|
18041
|
-
const result = await pvm.run(pack.parametrization, authGas);
|
|
18042
|
-
if (!result.isEqualTo(pack.authorization)) {
|
|
18043
|
-
throw new Error("Authorization is invalid.");
|
|
18044
|
-
}
|
|
18045
|
-
const results = [];
|
|
18046
|
-
for (const item of pack.items) {
|
|
18047
|
-
const exec = this.getServiceExecutor(headerHash, item.service, item.codeHash);
|
|
18048
|
-
if (exec.isError) {
|
|
18049
|
-
throw new Error(`Could not get item executor: ${exec.error}`);
|
|
18050
|
-
}
|
|
18051
|
-
const pvm = exec.ok;
|
|
18052
|
-
const gasRatio = tryAsServiceGas(3000n);
|
|
18053
|
-
const ret = await pvm.run(item.payload, tryAsGas(item.refineGasLimit)); // or accumulateGasLimit?
|
|
18054
|
-
results.push(WorkResult.create({
|
|
18055
|
-
serviceId: item.service,
|
|
18056
|
-
codeHash: item.codeHash,
|
|
18057
|
-
payloadHash: hashBytes(item.payload),
|
|
18058
|
-
gas: gasRatio,
|
|
18059
|
-
result: new WorkExecResult(WorkExecResultKind.ok, ret),
|
|
18060
|
-
load: WorkRefineLoad.create({
|
|
18061
|
-
gasUsed: tryAsServiceGas(5),
|
|
18062
|
-
importedSegments: tryAsU32(0),
|
|
18063
|
-
exportedSegments: tryAsU32(0),
|
|
18064
|
-
extrinsicSize: tryAsU32(0),
|
|
18065
|
-
extrinsicCount: tryAsU32(0),
|
|
18066
|
-
}),
|
|
18067
|
-
}));
|
|
18068
|
-
}
|
|
18069
|
-
const workPackage = this.hasher.workPackage(pack);
|
|
18070
|
-
const workPackageSpec = WorkPackageSpec.create({
|
|
18071
|
-
hash: workPackage.hash,
|
|
18072
|
-
length: tryAsU32(workPackage.encoded.length),
|
|
18073
|
-
erasureRoot: Bytes.zero(HASH_SIZE),
|
|
18074
|
-
exportsRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
18075
|
-
exportsCount: tryAsU16(0),
|
|
18076
|
-
});
|
|
18077
|
-
const coreIndex = tryAsCoreIndex(0);
|
|
18078
|
-
const authorizerHash = Bytes.fill(HASH_SIZE, 5).asOpaque();
|
|
18079
|
-
const workResults = FixedSizeArray.new(results, tryAsWorkItemsCount(results.length));
|
|
18080
|
-
return Promise.resolve(WorkReport.create({
|
|
18081
|
-
workPackageSpec,
|
|
18082
|
-
context: pack.context,
|
|
18083
|
-
coreIndex,
|
|
18084
|
-
authorizerHash,
|
|
18085
|
-
authorizationOutput: pack.authorization,
|
|
18086
|
-
segmentRootLookup: [],
|
|
18087
|
-
results: workResults,
|
|
18088
|
-
authorizationGasUsed: tryAsServiceGas(0),
|
|
18089
|
-
}));
|
|
18090
|
-
}
|
|
18091
|
-
getServiceExecutor(lookupAnchor, serviceId, expectedCodeHash) {
|
|
18092
|
-
const header = this.blocks.getHeader(lookupAnchor);
|
|
18093
|
-
if (header === null) {
|
|
18094
|
-
return Result$1.error(ServiceExecutorError.NoLookup);
|
|
18095
|
-
}
|
|
18096
|
-
const state = this.state.getState(lookupAnchor);
|
|
18097
|
-
if (state === null) {
|
|
18098
|
-
return Result$1.error(ServiceExecutorError.NoState);
|
|
18099
|
-
}
|
|
18100
|
-
const service = state.getService(serviceId);
|
|
18101
|
-
const serviceCodeHash = service?.getInfo().codeHash ?? null;
|
|
18102
|
-
if (serviceCodeHash === null) {
|
|
18103
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18104
|
-
}
|
|
18105
|
-
if (!serviceCodeHash.isEqualTo(expectedCodeHash)) {
|
|
18106
|
-
return Result$1.error(ServiceExecutorError.ServiceCodeMismatch);
|
|
18107
|
-
}
|
|
18108
|
-
const serviceCode = service?.getPreimage(serviceCodeHash.asOpaque()) ?? null;
|
|
18109
|
-
if (serviceCode === null) {
|
|
18110
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18111
|
-
}
|
|
18112
|
-
return Result$1.ok(new PvmExecutor(serviceCode));
|
|
18113
|
-
}
|
|
18114
|
-
}
|
|
18115
|
-
class PvmExecutor {
|
|
18116
|
-
serviceCode;
|
|
18117
|
-
pvm;
|
|
18118
|
-
hostCalls = new HostCallsManager({ missing: new Missing() });
|
|
18119
|
-
pvmInstanceManager = new InterpreterInstanceManager(4);
|
|
18120
|
-
constructor(serviceCode) {
|
|
18121
|
-
this.serviceCode = serviceCode;
|
|
18122
|
-
this.pvm = new HostCalls(this.pvmInstanceManager, this.hostCalls);
|
|
18123
|
-
}
|
|
18124
|
-
async run(args, gas) {
|
|
18125
|
-
const program = Program.fromSpi(this.serviceCode.raw, args.raw, true);
|
|
18126
|
-
const result = await this.pvm.runProgram(program.code, 5, gas, program.registers, program.memory);
|
|
18127
|
-
if (result.hasMemorySlice()) {
|
|
18128
|
-
return BytesBlob.blobFrom(result.memorySlice);
|
|
18129
|
-
}
|
|
18130
|
-
return BytesBlob.empty();
|
|
18131
|
-
}
|
|
18132
|
-
}
|
|
18133
|
-
|
|
18134
17679
|
var index = /*#__PURE__*/Object.freeze({
|
|
18135
17680
|
__proto__: null,
|
|
18136
17681
|
Preimages: Preimages,
|
|
18137
17682
|
get PreimagesErrorCode () { return PreimagesErrorCode; },
|
|
18138
|
-
TransitionHasher: TransitionHasher
|
|
18139
|
-
WorkPackageExecutor: WorkPackageExecutor
|
|
17683
|
+
TransitionHasher: TransitionHasher
|
|
18140
17684
|
});
|
|
18141
17685
|
|
|
18142
17686
|
exports.block = index$l;
|
|
@@ -18146,11 +17690,11 @@ exports.codec = index$q;
|
|
|
18146
17690
|
exports.collections = index$n;
|
|
18147
17691
|
exports.config = index$m;
|
|
18148
17692
|
exports.config_node = index$h;
|
|
18149
|
-
exports.crypto = index$
|
|
17693
|
+
exports.crypto = index$p;
|
|
18150
17694
|
exports.database = index$d;
|
|
18151
17695
|
exports.erasure_coding = index$c;
|
|
18152
17696
|
exports.fuzz_proto = index$a;
|
|
18153
|
-
exports.hash = index$
|
|
17697
|
+
exports.hash = index$o;
|
|
18154
17698
|
exports.jam_host_calls = index$9;
|
|
18155
17699
|
exports.json_parser = index$k;
|
|
18156
17700
|
exports.logger = index$i;
|