@typeberry/lib 0.1.3-ea24911 → 0.2.0-74f246e
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 +1185 -1682
- package/index.d.ts +1034 -751
- package/index.js +1184 -1681
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var GpVersion;
|
|
|
6
6
|
(function (GpVersion) {
|
|
7
7
|
GpVersion["V0_6_7"] = "0.6.7";
|
|
8
8
|
GpVersion["V0_7_0"] = "0.7.0";
|
|
9
|
-
GpVersion["V0_7_1"] = "0.7.1
|
|
9
|
+
GpVersion["V0_7_1"] = "0.7.1";
|
|
10
10
|
GpVersion["V0_7_2"] = "0.7.2-preview";
|
|
11
11
|
})(GpVersion || (GpVersion = {}));
|
|
12
12
|
var TestSuite;
|
|
@@ -15,11 +15,11 @@ var TestSuite;
|
|
|
15
15
|
TestSuite["JAMDUNA"] = "jamduna";
|
|
16
16
|
})(TestSuite || (TestSuite = {}));
|
|
17
17
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
18
|
-
const
|
|
18
|
+
const DEFAULT_VERSION = GpVersion.V0_7_1;
|
|
19
19
|
const env$1 = typeof process === "undefined" ? {} : process.env;
|
|
20
|
-
const DEFAULT_VERSION = GpVersion.V0_7_0;
|
|
21
20
|
let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
|
|
22
21
|
let CURRENT_SUITE = parseCurrentSuite(env$1.TEST_SUITE) ?? DEFAULT_SUITE;
|
|
22
|
+
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
|
|
23
23
|
function parseCurrentVersion(env) {
|
|
24
24
|
if (env === undefined) {
|
|
25
25
|
return undefined;
|
|
@@ -35,8 +35,9 @@ function parseCurrentVersion(env) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
function parseCurrentSuite(env) {
|
|
38
|
-
if (env === undefined)
|
|
38
|
+
if (env === undefined) {
|
|
39
39
|
return undefined;
|
|
40
|
+
}
|
|
40
41
|
switch (env) {
|
|
41
42
|
case TestSuite.W3F_DAVXY:
|
|
42
43
|
case TestSuite.JAMDUNA:
|
|
@@ -329,6 +330,19 @@ const Result$1 = {
|
|
|
329
330
|
},
|
|
330
331
|
};
|
|
331
332
|
|
|
333
|
+
// about 2GB, the maximum ArrayBuffer length on Chrome confirmed by several sources:
|
|
334
|
+
// - https://issues.chromium.org/issues/40055619
|
|
335
|
+
// - https://stackoverflow.com/a/72124984
|
|
336
|
+
// - https://onnxruntime.ai/docs/tutorials/web/large-models.html#maximum-size-of-arraybuffer
|
|
337
|
+
const MAX_LENGTH$2 = 2145386496;
|
|
338
|
+
function safeAllocUint8Array(length) {
|
|
339
|
+
if (length > MAX_LENGTH$2) {
|
|
340
|
+
// biome-ignore lint/suspicious/noConsole: can't have a dependency on logger here
|
|
341
|
+
console.warn(`Trying to allocate ${length} bytes, which is greater than the maximum of ${MAX_LENGTH$2}.`);
|
|
342
|
+
}
|
|
343
|
+
return new Uint8Array(Math.min(MAX_LENGTH$2, length));
|
|
344
|
+
}
|
|
345
|
+
|
|
332
346
|
/**
|
|
333
347
|
* Utilities for tests.
|
|
334
348
|
*/
|
|
@@ -443,10 +457,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
443
457
|
.sort((a, b) => {
|
|
444
458
|
const aKey = `${a.key}`;
|
|
445
459
|
const bKey = `${b.key}`;
|
|
446
|
-
if (aKey < bKey)
|
|
460
|
+
if (aKey < bKey) {
|
|
447
461
|
return -1;
|
|
448
|
-
|
|
462
|
+
}
|
|
463
|
+
if (bKey < aKey) {
|
|
449
464
|
return 1;
|
|
465
|
+
}
|
|
450
466
|
return 0;
|
|
451
467
|
});
|
|
452
468
|
};
|
|
@@ -569,6 +585,7 @@ var index$u = /*#__PURE__*/Object.freeze({
|
|
|
569
585
|
DEFAULT_VERSION: DEFAULT_VERSION,
|
|
570
586
|
ErrorsCollector: ErrorsCollector,
|
|
571
587
|
get GpVersion () { return GpVersion; },
|
|
588
|
+
MAX_LENGTH: MAX_LENGTH$2,
|
|
572
589
|
OK: OK,
|
|
573
590
|
Result: Result$1,
|
|
574
591
|
TEST_COMPARE_USING: TEST_COMPARE_USING,
|
|
@@ -583,6 +600,7 @@ var index$u = /*#__PURE__*/Object.freeze({
|
|
|
583
600
|
isBrowser: isBrowser,
|
|
584
601
|
measure: measure,
|
|
585
602
|
resultToString: resultToString,
|
|
603
|
+
safeAllocUint8Array: safeAllocUint8Array,
|
|
586
604
|
seeThrough: seeThrough,
|
|
587
605
|
workspacePathFix: workspacePathFix
|
|
588
606
|
});
|
|
@@ -606,7 +624,7 @@ class BitVec {
|
|
|
606
624
|
* Create new [`BitVec`] with all values set to `false`.
|
|
607
625
|
*/
|
|
608
626
|
static empty(bitLength) {
|
|
609
|
-
const data =
|
|
627
|
+
const data = safeAllocUint8Array(Math.ceil(bitLength / 8));
|
|
610
628
|
return new BitVec(data, bitLength);
|
|
611
629
|
}
|
|
612
630
|
byteLength;
|
|
@@ -807,7 +825,7 @@ class BytesBlob {
|
|
|
807
825
|
static blobFromParts(v, ...rest) {
|
|
808
826
|
const vArr = v instanceof Uint8Array ? [v] : v;
|
|
809
827
|
const totalLength = vArr.reduce((a, v) => a + v.length, 0) + rest.reduce((a, v) => a + v.length, 0);
|
|
810
|
-
const buffer =
|
|
828
|
+
const buffer = safeAllocUint8Array(totalLength);
|
|
811
829
|
let offset = 0;
|
|
812
830
|
for (const r of vArr) {
|
|
813
831
|
buffer.set(r, offset);
|
|
@@ -880,7 +898,7 @@ class Bytes extends BytesBlob {
|
|
|
880
898
|
}
|
|
881
899
|
/** Create an empty [`Bytes<X>`] of given length. */
|
|
882
900
|
static zero(len) {
|
|
883
|
-
return new Bytes(
|
|
901
|
+
return new Bytes(safeAllocUint8Array(len), len);
|
|
884
902
|
}
|
|
885
903
|
// TODO [ToDr] `fill` should have the argments swapped to align with the rest.
|
|
886
904
|
/** Create a [`Bytes<X>`] with all bytes filled with given input number. */
|
|
@@ -2070,6 +2088,9 @@ class ObjectView {
|
|
|
2070
2088
|
toString() {
|
|
2071
2089
|
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2072
2090
|
}
|
|
2091
|
+
[TEST_COMPARE_USING]() {
|
|
2092
|
+
return this.materialize();
|
|
2093
|
+
}
|
|
2073
2094
|
}
|
|
2074
2095
|
/**
|
|
2075
2096
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2355,7 +2376,15 @@ var codec$1;
|
|
|
2355
2376
|
/** Custom encoding / decoding logic. */
|
|
2356
2377
|
codec.custom = ({ name, sizeHint = { bytes: 0, isExact: false }, }, encode, decode, skip) => Descriptor.new(name, sizeHint, encode, decode, skip);
|
|
2357
2378
|
/** Choose a descriptor depending on the encoding/decoding context. */
|
|
2358
|
-
codec.select = ({ name, sizeHint, }, chooser) =>
|
|
2379
|
+
codec.select = ({ name, sizeHint, }, chooser) => {
|
|
2380
|
+
const Self = chooser(null);
|
|
2381
|
+
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)
|
|
2382
|
+
? codec.select({
|
|
2383
|
+
name: Self.View.name,
|
|
2384
|
+
sizeHint: Self.View.sizeHint,
|
|
2385
|
+
}, (ctx) => chooser(ctx).View)
|
|
2386
|
+
: Self.View);
|
|
2387
|
+
};
|
|
2359
2388
|
/**
|
|
2360
2389
|
* A descriptor for a more complex POJO.
|
|
2361
2390
|
*
|
|
@@ -3589,7 +3618,7 @@ async function verify(input) {
|
|
|
3589
3618
|
return Promise.resolve([]);
|
|
3590
3619
|
}
|
|
3591
3620
|
const dataLength = input.reduce((acc, { message, key, signature }) => acc + key.length + signature.length + message.length + 1, 0);
|
|
3592
|
-
const data =
|
|
3621
|
+
const data = safeAllocUint8Array(dataLength);
|
|
3593
3622
|
let offset = 0;
|
|
3594
3623
|
for (const { key, message, signature } of input) {
|
|
3595
3624
|
data.set(key.raw, offset);
|
|
@@ -3636,823 +3665,75 @@ var ed25519 = /*#__PURE__*/Object.freeze({
|
|
|
3636
3665
|
verifyBatch: verifyBatch
|
|
3637
3666
|
});
|
|
3638
3667
|
|
|
3668
|
+
const SEED_SIZE = 32;
|
|
3669
|
+
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
3670
|
+
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
3639
3671
|
/**
|
|
3640
|
-
*
|
|
3641
|
-
*
|
|
3642
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
3672
|
+
* JIP-5: Secret key derivation
|
|
3643
3673
|
*
|
|
3644
|
-
*/
|
|
3645
|
-
const HASH_SIZE = 32;
|
|
3646
|
-
/** A hash without last byte (useful for trie representation). */
|
|
3647
|
-
const TRUNCATED_HASH_SIZE = 31;
|
|
3648
|
-
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
3674
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
3649
3675
|
/**
|
|
3650
|
-
*
|
|
3651
|
-
*
|
|
3652
|
-
* After calculating the hash these two should be passed together to avoid
|
|
3653
|
-
* unnecessary re-hashing of the data.
|
|
3676
|
+
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
3677
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
3654
3678
|
*/
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
constructor(hash, data) {
|
|
3659
|
-
super();
|
|
3660
|
-
this.hash = hash;
|
|
3661
|
-
this.data = data;
|
|
3662
|
-
}
|
|
3679
|
+
function trivialSeed(s) {
|
|
3680
|
+
const s_le = u32AsLeBytes(s);
|
|
3681
|
+
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();
|
|
3663
3682
|
}
|
|
3664
3683
|
/**
|
|
3665
|
-
*
|
|
3684
|
+
* Derives a Ed25519 secret key from a seed.
|
|
3685
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
3666
3686
|
*/
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
constructor(hash, data, encoded) {
|
|
3670
|
-
super(hash, data);
|
|
3671
|
-
this.encoded = encoded;
|
|
3672
|
-
}
|
|
3673
|
-
}
|
|
3674
|
-
|
|
3675
|
-
/** The simplest allocator returning just a fresh copy of bytes each time. */
|
|
3676
|
-
class SimpleAllocator {
|
|
3677
|
-
emptyHash() {
|
|
3678
|
-
return Bytes.zero(HASH_SIZE);
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
/** An allocator that works by allocating larger (continuous) pages of memory. */
|
|
3682
|
-
class PageAllocator {
|
|
3683
|
-
hashesPerPage;
|
|
3684
|
-
page = new Uint8Array(0);
|
|
3685
|
-
currentHash = 0;
|
|
3686
|
-
// TODO [ToDr] Benchmark the performance!
|
|
3687
|
-
constructor(hashesPerPage) {
|
|
3688
|
-
this.hashesPerPage = hashesPerPage;
|
|
3689
|
-
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
3690
|
-
this.resetPage();
|
|
3691
|
-
}
|
|
3692
|
-
resetPage() {
|
|
3693
|
-
const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
|
|
3694
|
-
this.currentHash = 0;
|
|
3695
|
-
this.page = new Uint8Array(pageSizeBytes);
|
|
3696
|
-
}
|
|
3697
|
-
emptyHash() {
|
|
3698
|
-
const startIdx = this.currentHash * HASH_SIZE;
|
|
3699
|
-
const endIdx = startIdx + HASH_SIZE;
|
|
3700
|
-
this.currentHash += 1;
|
|
3701
|
-
if (this.currentHash >= this.hashesPerPage) {
|
|
3702
|
-
this.resetPage();
|
|
3703
|
-
}
|
|
3704
|
-
return Bytes.fromBlob(this.page.subarray(startIdx, endIdx), HASH_SIZE);
|
|
3705
|
-
}
|
|
3706
|
-
}
|
|
3707
|
-
const defaultAllocator = new SimpleAllocator();
|
|
3708
|
-
|
|
3709
|
-
function getDefaultExportFromCjs (x) {
|
|
3710
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3711
|
-
}
|
|
3712
|
-
|
|
3713
|
-
var blake2b$3 = {exports: {}};
|
|
3714
|
-
|
|
3715
|
-
var nanoassert;
|
|
3716
|
-
var hasRequiredNanoassert;
|
|
3717
|
-
|
|
3718
|
-
function requireNanoassert () {
|
|
3719
|
-
if (hasRequiredNanoassert) return nanoassert;
|
|
3720
|
-
hasRequiredNanoassert = 1;
|
|
3721
|
-
nanoassert = assert;
|
|
3722
|
-
|
|
3723
|
-
class AssertionError extends Error {}
|
|
3724
|
-
AssertionError.prototype.name = 'AssertionError';
|
|
3725
|
-
|
|
3726
|
-
/**
|
|
3727
|
-
* Minimal assert function
|
|
3728
|
-
* @param {any} t Value to check if falsy
|
|
3729
|
-
* @param {string=} m Optional assertion error message
|
|
3730
|
-
* @throws {AssertionError}
|
|
3731
|
-
*/
|
|
3732
|
-
function assert (t, m) {
|
|
3733
|
-
if (!t) {
|
|
3734
|
-
var err = new AssertionError(m);
|
|
3735
|
-
if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
|
|
3736
|
-
throw err
|
|
3737
|
-
}
|
|
3738
|
-
}
|
|
3739
|
-
return nanoassert;
|
|
3740
|
-
}
|
|
3741
|
-
|
|
3742
|
-
var blake2bWasm = {exports: {}};
|
|
3743
|
-
|
|
3744
|
-
var b4a;
|
|
3745
|
-
var hasRequiredB4a;
|
|
3746
|
-
|
|
3747
|
-
function requireB4a () {
|
|
3748
|
-
if (hasRequiredB4a) return b4a;
|
|
3749
|
-
hasRequiredB4a = 1;
|
|
3750
|
-
function isBuffer (value) {
|
|
3751
|
-
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
3752
|
-
}
|
|
3753
|
-
|
|
3754
|
-
function isEncoding (encoding) {
|
|
3755
|
-
return Buffer.isEncoding(encoding)
|
|
3756
|
-
}
|
|
3757
|
-
|
|
3758
|
-
function alloc (size, fill, encoding) {
|
|
3759
|
-
return Buffer.alloc(size, fill, encoding)
|
|
3760
|
-
}
|
|
3761
|
-
|
|
3762
|
-
function allocUnsafe (size) {
|
|
3763
|
-
return Buffer.allocUnsafe(size)
|
|
3764
|
-
}
|
|
3765
|
-
|
|
3766
|
-
function allocUnsafeSlow (size) {
|
|
3767
|
-
return Buffer.allocUnsafeSlow(size)
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3770
|
-
function byteLength (string, encoding) {
|
|
3771
|
-
return Buffer.byteLength(string, encoding)
|
|
3772
|
-
}
|
|
3773
|
-
|
|
3774
|
-
function compare (a, b) {
|
|
3775
|
-
return Buffer.compare(a, b)
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
function concat (buffers, totalLength) {
|
|
3779
|
-
return Buffer.concat(buffers, totalLength)
|
|
3780
|
-
}
|
|
3781
|
-
|
|
3782
|
-
function copy (source, target, targetStart, start, end) {
|
|
3783
|
-
return toBuffer(source).copy(target, targetStart, start, end)
|
|
3784
|
-
}
|
|
3785
|
-
|
|
3786
|
-
function equals (a, b) {
|
|
3787
|
-
return toBuffer(a).equals(b)
|
|
3788
|
-
}
|
|
3789
|
-
|
|
3790
|
-
function fill (buffer, value, offset, end, encoding) {
|
|
3791
|
-
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
3792
|
-
}
|
|
3793
|
-
|
|
3794
|
-
function from (value, encodingOrOffset, length) {
|
|
3795
|
-
return Buffer.from(value, encodingOrOffset, length)
|
|
3796
|
-
}
|
|
3797
|
-
|
|
3798
|
-
function includes (buffer, value, byteOffset, encoding) {
|
|
3799
|
-
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
3803
|
-
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
3804
|
-
}
|
|
3805
|
-
|
|
3806
|
-
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
3807
|
-
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
3808
|
-
}
|
|
3809
|
-
|
|
3810
|
-
function swap16 (buffer) {
|
|
3811
|
-
return toBuffer(buffer).swap16()
|
|
3812
|
-
}
|
|
3813
|
-
|
|
3814
|
-
function swap32 (buffer) {
|
|
3815
|
-
return toBuffer(buffer).swap32()
|
|
3816
|
-
}
|
|
3817
|
-
|
|
3818
|
-
function swap64 (buffer) {
|
|
3819
|
-
return toBuffer(buffer).swap64()
|
|
3820
|
-
}
|
|
3821
|
-
|
|
3822
|
-
function toBuffer (buffer) {
|
|
3823
|
-
if (Buffer.isBuffer(buffer)) return buffer
|
|
3824
|
-
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
3825
|
-
}
|
|
3826
|
-
|
|
3827
|
-
function toString (buffer, encoding, start, end) {
|
|
3828
|
-
return toBuffer(buffer).toString(encoding, start, end)
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
function write (buffer, string, offset, length, encoding) {
|
|
3832
|
-
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
3833
|
-
}
|
|
3834
|
-
|
|
3835
|
-
function writeDoubleLE (buffer, value, offset) {
|
|
3836
|
-
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
3837
|
-
}
|
|
3838
|
-
|
|
3839
|
-
function writeFloatLE (buffer, value, offset) {
|
|
3840
|
-
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
3841
|
-
}
|
|
3842
|
-
|
|
3843
|
-
function writeUInt32LE (buffer, value, offset) {
|
|
3844
|
-
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
3845
|
-
}
|
|
3846
|
-
|
|
3847
|
-
function writeInt32LE (buffer, value, offset) {
|
|
3848
|
-
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
3849
|
-
}
|
|
3850
|
-
|
|
3851
|
-
function readDoubleLE (buffer, offset) {
|
|
3852
|
-
return toBuffer(buffer).readDoubleLE(offset)
|
|
3853
|
-
}
|
|
3854
|
-
|
|
3855
|
-
function readFloatLE (buffer, offset) {
|
|
3856
|
-
return toBuffer(buffer).readFloatLE(offset)
|
|
3857
|
-
}
|
|
3858
|
-
|
|
3859
|
-
function readUInt32LE (buffer, offset) {
|
|
3860
|
-
return toBuffer(buffer).readUInt32LE(offset)
|
|
3861
|
-
}
|
|
3862
|
-
|
|
3863
|
-
function readInt32LE (buffer, offset) {
|
|
3864
|
-
return toBuffer(buffer).readInt32LE(offset)
|
|
3865
|
-
}
|
|
3866
|
-
|
|
3867
|
-
b4a = {
|
|
3868
|
-
isBuffer,
|
|
3869
|
-
isEncoding,
|
|
3870
|
-
alloc,
|
|
3871
|
-
allocUnsafe,
|
|
3872
|
-
allocUnsafeSlow,
|
|
3873
|
-
byteLength,
|
|
3874
|
-
compare,
|
|
3875
|
-
concat,
|
|
3876
|
-
copy,
|
|
3877
|
-
equals,
|
|
3878
|
-
fill,
|
|
3879
|
-
from,
|
|
3880
|
-
includes,
|
|
3881
|
-
indexOf,
|
|
3882
|
-
lastIndexOf,
|
|
3883
|
-
swap16,
|
|
3884
|
-
swap32,
|
|
3885
|
-
swap64,
|
|
3886
|
-
toBuffer,
|
|
3887
|
-
toString,
|
|
3888
|
-
write,
|
|
3889
|
-
writeDoubleLE,
|
|
3890
|
-
writeFloatLE,
|
|
3891
|
-
writeUInt32LE,
|
|
3892
|
-
writeInt32LE,
|
|
3893
|
-
readDoubleLE,
|
|
3894
|
-
readFloatLE,
|
|
3895
|
-
readUInt32LE,
|
|
3896
|
-
readInt32LE
|
|
3897
|
-
};
|
|
3898
|
-
return b4a;
|
|
3899
|
-
}
|
|
3900
|
-
|
|
3901
|
-
var blake2b$2;
|
|
3902
|
-
var hasRequiredBlake2b$1;
|
|
3903
|
-
|
|
3904
|
-
function requireBlake2b$1 () {
|
|
3905
|
-
if (hasRequiredBlake2b$1) return blake2b$2;
|
|
3906
|
-
hasRequiredBlake2b$1 = 1;
|
|
3907
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3908
|
-
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3909
|
-
};
|
|
3910
|
-
var __toBinary = /* @__PURE__ */ (() => {
|
|
3911
|
-
var table = new Uint8Array(128);
|
|
3912
|
-
for (var i = 0; i < 64; i++)
|
|
3913
|
-
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
3914
|
-
return (base64) => {
|
|
3915
|
-
var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
3916
|
-
for (var i2 = 0, j = 0; i2 < n; ) {
|
|
3917
|
-
var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
3918
|
-
var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
3919
|
-
bytes2[j++] = c0 << 2 | c1 >> 4;
|
|
3920
|
-
bytes2[j++] = c1 << 4 | c2 >> 2;
|
|
3921
|
-
bytes2[j++] = c2 << 6 | c3;
|
|
3922
|
-
}
|
|
3923
|
-
return bytes2;
|
|
3924
|
-
};
|
|
3925
|
-
})();
|
|
3926
|
-
|
|
3927
|
-
// wasm-binary:./blake2b.wat
|
|
3928
|
-
var require_blake2b = __commonJS({
|
|
3929
|
-
"wasm-binary:./blake2b.wat"(exports2, module2) {
|
|
3930
|
-
module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFqISEgAEGIAWohIiAAQZABaiEjIABBmAFqISQgAEGgAWohJSAAQagBaiEmIABBsAFqIScgAEG4AWohKCAhKQMAIQEgIikDACECICMpAwAhAyAkKQMAIQQgJSkDACEFICYpAwAhBiAnKQMAIQcgKCkDACEIQoiS853/zPmE6gAhCUK7zqqm2NDrs7t/IQpCq/DT9K/uvLc8I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JCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
|
|
3931
|
-
}
|
|
3932
|
-
});
|
|
3933
|
-
|
|
3934
|
-
// wasm-module:./blake2b.wat
|
|
3935
|
-
var bytes = require_blake2b();
|
|
3936
|
-
var compiled = WebAssembly.compile(bytes);
|
|
3937
|
-
blake2b$2 = async (imports) => {
|
|
3938
|
-
const instance = await WebAssembly.instantiate(await compiled, imports);
|
|
3939
|
-
return instance.exports;
|
|
3940
|
-
};
|
|
3941
|
-
return blake2b$2;
|
|
3942
|
-
}
|
|
3943
|
-
|
|
3944
|
-
var hasRequiredBlake2bWasm;
|
|
3945
|
-
|
|
3946
|
-
function requireBlake2bWasm () {
|
|
3947
|
-
if (hasRequiredBlake2bWasm) return blake2bWasm.exports;
|
|
3948
|
-
hasRequiredBlake2bWasm = 1;
|
|
3949
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
3950
|
-
var b4a = /*@__PURE__*/ requireB4a();
|
|
3951
|
-
|
|
3952
|
-
var wasm = null;
|
|
3953
|
-
var wasmPromise = typeof WebAssembly !== "undefined" && /*@__PURE__*/ requireBlake2b$1()().then(mod => {
|
|
3954
|
-
wasm = mod;
|
|
3955
|
-
});
|
|
3956
|
-
|
|
3957
|
-
var head = 64;
|
|
3958
|
-
var freeList = [];
|
|
3959
|
-
|
|
3960
|
-
blake2bWasm.exports = Blake2b;
|
|
3961
|
-
var BYTES_MIN = blake2bWasm.exports.BYTES_MIN = 16;
|
|
3962
|
-
var BYTES_MAX = blake2bWasm.exports.BYTES_MAX = 64;
|
|
3963
|
-
blake2bWasm.exports.BYTES = 32;
|
|
3964
|
-
var KEYBYTES_MIN = blake2bWasm.exports.KEYBYTES_MIN = 16;
|
|
3965
|
-
var KEYBYTES_MAX = blake2bWasm.exports.KEYBYTES_MAX = 64;
|
|
3966
|
-
blake2bWasm.exports.KEYBYTES = 32;
|
|
3967
|
-
var SALTBYTES = blake2bWasm.exports.SALTBYTES = 16;
|
|
3968
|
-
var PERSONALBYTES = blake2bWasm.exports.PERSONALBYTES = 16;
|
|
3969
|
-
|
|
3970
|
-
function Blake2b (digestLength, key, salt, personal, noAssert) {
|
|
3971
|
-
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
|
|
3972
|
-
if (!wasm) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
|
|
3973
|
-
if (!digestLength) digestLength = 32;
|
|
3974
|
-
|
|
3975
|
-
if (noAssert !== true) {
|
|
3976
|
-
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength);
|
|
3977
|
-
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength);
|
|
3978
|
-
if (key != null) {
|
|
3979
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
3980
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
3981
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at least ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
3982
|
-
}
|
|
3983
|
-
if (salt != null) {
|
|
3984
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
3985
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
3986
|
-
}
|
|
3987
|
-
if (personal != null) {
|
|
3988
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
3989
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
3990
|
-
}
|
|
3991
|
-
}
|
|
3992
|
-
|
|
3993
|
-
if (!freeList.length) {
|
|
3994
|
-
freeList.push(head);
|
|
3995
|
-
head += 216;
|
|
3996
|
-
}
|
|
3997
|
-
|
|
3998
|
-
this.digestLength = digestLength;
|
|
3999
|
-
this.finalized = false;
|
|
4000
|
-
this.pointer = freeList.pop();
|
|
4001
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4002
|
-
|
|
4003
|
-
this._memory.fill(0, 0, 64);
|
|
4004
|
-
this._memory[0] = this.digestLength;
|
|
4005
|
-
this._memory[1] = key ? key.length : 0;
|
|
4006
|
-
this._memory[2] = 1; // fanout
|
|
4007
|
-
this._memory[3] = 1; // depth
|
|
4008
|
-
|
|
4009
|
-
if (salt) this._memory.set(salt, 32);
|
|
4010
|
-
if (personal) this._memory.set(personal, 48);
|
|
4011
|
-
|
|
4012
|
-
if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216); // we need 216 bytes for the state
|
|
4013
|
-
wasm.blake2b_init(this.pointer, this.digestLength);
|
|
4014
|
-
|
|
4015
|
-
if (key) {
|
|
4016
|
-
this.update(key);
|
|
4017
|
-
this._memory.fill(0, head, head + key.length); // whiteout key
|
|
4018
|
-
this._memory[this.pointer + 200] = 128;
|
|
4019
|
-
}
|
|
4020
|
-
}
|
|
4021
|
-
|
|
4022
|
-
Blake2b.prototype._realloc = function (size) {
|
|
4023
|
-
wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
|
|
4024
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4025
|
-
};
|
|
4026
|
-
|
|
4027
|
-
Blake2b.prototype.update = function (input) {
|
|
4028
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4029
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4030
|
-
|
|
4031
|
-
if (head + input.length > this._memory.length) this._realloc(head + input.length);
|
|
4032
|
-
this._memory.set(input, head);
|
|
4033
|
-
wasm.blake2b_update(this.pointer, head, head + input.length);
|
|
4034
|
-
return this
|
|
4035
|
-
};
|
|
4036
|
-
|
|
4037
|
-
Blake2b.prototype.digest = function (enc) {
|
|
4038
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4039
|
-
this.finalized = true;
|
|
4040
|
-
|
|
4041
|
-
freeList.push(this.pointer);
|
|
4042
|
-
wasm.blake2b_final(this.pointer);
|
|
4043
|
-
|
|
4044
|
-
if (!enc || enc === 'binary') {
|
|
4045
|
-
return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4046
|
-
}
|
|
4047
|
-
|
|
4048
|
-
if (typeof enc === 'string') {
|
|
4049
|
-
return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4050
|
-
}
|
|
4051
|
-
|
|
4052
|
-
assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
|
|
4053
|
-
for (var i = 0; i < this.digestLength; i++) {
|
|
4054
|
-
enc[i] = this._memory[this.pointer + 128 + i];
|
|
4055
|
-
}
|
|
4056
|
-
|
|
4057
|
-
return enc
|
|
4058
|
-
};
|
|
4059
|
-
|
|
4060
|
-
// libsodium compat
|
|
4061
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4062
|
-
|
|
4063
|
-
Blake2b.WASM = wasm;
|
|
4064
|
-
Blake2b.SUPPORTED = typeof WebAssembly !== 'undefined';
|
|
4065
|
-
|
|
4066
|
-
Blake2b.ready = function (cb) {
|
|
4067
|
-
if (!cb) cb = noop;
|
|
4068
|
-
if (!wasmPromise) return cb(new Error('WebAssembly not supported'))
|
|
4069
|
-
return wasmPromise.then(() => cb(), cb)
|
|
4070
|
-
};
|
|
4071
|
-
|
|
4072
|
-
Blake2b.prototype.ready = Blake2b.ready;
|
|
4073
|
-
|
|
4074
|
-
Blake2b.prototype.getPartialHash = function () {
|
|
4075
|
-
return this._memory.slice(this.pointer, this.pointer + 216);
|
|
4076
|
-
};
|
|
4077
|
-
|
|
4078
|
-
Blake2b.prototype.setPartialHash = function (ph) {
|
|
4079
|
-
this._memory.set(ph, this.pointer);
|
|
4080
|
-
};
|
|
4081
|
-
|
|
4082
|
-
function noop () {}
|
|
4083
|
-
return blake2bWasm.exports;
|
|
4084
|
-
}
|
|
4085
|
-
|
|
4086
|
-
var hasRequiredBlake2b;
|
|
4087
|
-
|
|
4088
|
-
function requireBlake2b () {
|
|
4089
|
-
if (hasRequiredBlake2b) return blake2b$3.exports;
|
|
4090
|
-
hasRequiredBlake2b = 1;
|
|
4091
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
4092
|
-
var b2wasm = /*@__PURE__*/ requireBlake2bWasm();
|
|
4093
|
-
|
|
4094
|
-
// 64-bit unsigned addition
|
|
4095
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
4096
|
-
// v should be a Uint32Array
|
|
4097
|
-
function ADD64AA (v, a, b) {
|
|
4098
|
-
var o0 = v[a] + v[b];
|
|
4099
|
-
var o1 = v[a + 1] + v[b + 1];
|
|
4100
|
-
if (o0 >= 0x100000000) {
|
|
4101
|
-
o1++;
|
|
4102
|
-
}
|
|
4103
|
-
v[a] = o0;
|
|
4104
|
-
v[a + 1] = o1;
|
|
4105
|
-
}
|
|
4106
|
-
|
|
4107
|
-
// 64-bit unsigned addition
|
|
4108
|
-
// Sets v[a,a+1] += b
|
|
4109
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
4110
|
-
function ADD64AC (v, a, b0, b1) {
|
|
4111
|
-
var o0 = v[a] + b0;
|
|
4112
|
-
if (b0 < 0) {
|
|
4113
|
-
o0 += 0x100000000;
|
|
4114
|
-
}
|
|
4115
|
-
var o1 = v[a + 1] + b1;
|
|
4116
|
-
if (o0 >= 0x100000000) {
|
|
4117
|
-
o1++;
|
|
4118
|
-
}
|
|
4119
|
-
v[a] = o0;
|
|
4120
|
-
v[a + 1] = o1;
|
|
4121
|
-
}
|
|
4122
|
-
|
|
4123
|
-
// Little-endian byte access
|
|
4124
|
-
function B2B_GET32 (arr, i) {
|
|
4125
|
-
return (arr[i] ^
|
|
4126
|
-
(arr[i + 1] << 8) ^
|
|
4127
|
-
(arr[i + 2] << 16) ^
|
|
4128
|
-
(arr[i + 3] << 24))
|
|
4129
|
-
}
|
|
4130
|
-
|
|
4131
|
-
// G Mixing function
|
|
4132
|
-
// The ROTRs are inlined for speed
|
|
4133
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
4134
|
-
var x0 = m[ix];
|
|
4135
|
-
var x1 = m[ix + 1];
|
|
4136
|
-
var y0 = m[iy];
|
|
4137
|
-
var y1 = m[iy + 1];
|
|
4138
|
-
|
|
4139
|
-
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
4140
|
-
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
4141
|
-
|
|
4142
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
4143
|
-
var xor0 = v[d] ^ v[a];
|
|
4144
|
-
var xor1 = v[d + 1] ^ v[a + 1];
|
|
4145
|
-
v[d] = xor1;
|
|
4146
|
-
v[d + 1] = xor0;
|
|
4147
|
-
|
|
4148
|
-
ADD64AA(v, c, d);
|
|
4149
|
-
|
|
4150
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
4151
|
-
xor0 = v[b] ^ v[c];
|
|
4152
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4153
|
-
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
4154
|
-
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
4155
|
-
|
|
4156
|
-
ADD64AA(v, a, b);
|
|
4157
|
-
ADD64AC(v, a, y0, y1);
|
|
4158
|
-
|
|
4159
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
4160
|
-
xor0 = v[d] ^ v[a];
|
|
4161
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
4162
|
-
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
4163
|
-
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
4164
|
-
|
|
4165
|
-
ADD64AA(v, c, d);
|
|
4166
|
-
|
|
4167
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
4168
|
-
xor0 = v[b] ^ v[c];
|
|
4169
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4170
|
-
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
4171
|
-
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
4172
|
-
}
|
|
4173
|
-
|
|
4174
|
-
// Initialization Vector
|
|
4175
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
4176
|
-
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
4177
|
-
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
4178
|
-
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
4179
|
-
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
4180
|
-
]);
|
|
4181
|
-
|
|
4182
|
-
var SIGMA8 = [
|
|
4183
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4184
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
4185
|
-
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
4186
|
-
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
4187
|
-
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
4188
|
-
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
4189
|
-
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
4190
|
-
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
4191
|
-
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
4192
|
-
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
4193
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4194
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
4195
|
-
];
|
|
4196
|
-
|
|
4197
|
-
// These are offsets into a uint64 buffer.
|
|
4198
|
-
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
4199
|
-
// because this is Javascript and we don't have uint64s
|
|
4200
|
-
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }));
|
|
4201
|
-
|
|
4202
|
-
// Compression function. 'last' flag indicates last block.
|
|
4203
|
-
// Note we're representing 16 uint64s as 32 uint32s
|
|
4204
|
-
var v = new Uint32Array(32);
|
|
4205
|
-
var m = new Uint32Array(32);
|
|
4206
|
-
function blake2bCompress (ctx, last) {
|
|
4207
|
-
var i = 0;
|
|
4208
|
-
|
|
4209
|
-
// init work variables
|
|
4210
|
-
for (i = 0; i < 16; i++) {
|
|
4211
|
-
v[i] = ctx.h[i];
|
|
4212
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
4213
|
-
}
|
|
4214
|
-
|
|
4215
|
-
// low 64 bits of offset
|
|
4216
|
-
v[24] = v[24] ^ ctx.t;
|
|
4217
|
-
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
4218
|
-
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
4219
|
-
|
|
4220
|
-
// last block flag set ?
|
|
4221
|
-
if (last) {
|
|
4222
|
-
v[28] = ~v[28];
|
|
4223
|
-
v[29] = ~v[29];
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
// get little-endian words
|
|
4227
|
-
for (i = 0; i < 32; i++) {
|
|
4228
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
4229
|
-
}
|
|
4230
|
-
|
|
4231
|
-
// twelve rounds of mixing
|
|
4232
|
-
for (i = 0; i < 12; i++) {
|
|
4233
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
4234
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
4235
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
4236
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
4237
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
4238
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
4239
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
4240
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
4241
|
-
}
|
|
4242
|
-
|
|
4243
|
-
for (i = 0; i < 16; i++) {
|
|
4244
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
4245
|
-
}
|
|
4246
|
-
}
|
|
4247
|
-
|
|
4248
|
-
// reusable parameter_block
|
|
4249
|
-
var parameter_block = new Uint8Array([
|
|
4250
|
-
0, 0, 0, 0, // 0: outlen, keylen, fanout, depth
|
|
4251
|
-
0, 0, 0, 0, // 4: leaf length, sequential mode
|
|
4252
|
-
0, 0, 0, 0, // 8: node offset
|
|
4253
|
-
0, 0, 0, 0, // 12: node offset
|
|
4254
|
-
0, 0, 0, 0, // 16: node depth, inner length, rfu
|
|
4255
|
-
0, 0, 0, 0, // 20: rfu
|
|
4256
|
-
0, 0, 0, 0, // 24: rfu
|
|
4257
|
-
0, 0, 0, 0, // 28: rfu
|
|
4258
|
-
0, 0, 0, 0, // 32: salt
|
|
4259
|
-
0, 0, 0, 0, // 36: salt
|
|
4260
|
-
0, 0, 0, 0, // 40: salt
|
|
4261
|
-
0, 0, 0, 0, // 44: salt
|
|
4262
|
-
0, 0, 0, 0, // 48: personal
|
|
4263
|
-
0, 0, 0, 0, // 52: personal
|
|
4264
|
-
0, 0, 0, 0, // 56: personal
|
|
4265
|
-
0, 0, 0, 0 // 60: personal
|
|
4266
|
-
]);
|
|
4267
|
-
|
|
4268
|
-
// Creates a BLAKE2b hashing context
|
|
4269
|
-
// Requires an output length between 1 and 64 bytes
|
|
4270
|
-
// Takes an optional Uint8Array key
|
|
4271
|
-
function Blake2b (outlen, key, salt, personal) {
|
|
4272
|
-
// zero out parameter_block before usage
|
|
4273
|
-
parameter_block.fill(0);
|
|
4274
|
-
// state, 'param block'
|
|
4275
|
-
|
|
4276
|
-
this.b = new Uint8Array(128);
|
|
4277
|
-
this.h = new Uint32Array(16);
|
|
4278
|
-
this.t = 0; // input count
|
|
4279
|
-
this.c = 0; // pointer within buffer
|
|
4280
|
-
this.outlen = outlen; // output length in bytes
|
|
4281
|
-
|
|
4282
|
-
parameter_block[0] = outlen;
|
|
4283
|
-
if (key) parameter_block[1] = key.length;
|
|
4284
|
-
parameter_block[2] = 1; // fanout
|
|
4285
|
-
parameter_block[3] = 1; // depth
|
|
4286
|
-
|
|
4287
|
-
if (salt) parameter_block.set(salt, 32);
|
|
4288
|
-
if (personal) parameter_block.set(personal, 48);
|
|
4289
|
-
|
|
4290
|
-
// initialize hash state
|
|
4291
|
-
for (var i = 0; i < 16; i++) {
|
|
4292
|
-
this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
|
|
4293
|
-
}
|
|
4294
|
-
|
|
4295
|
-
// key the hash, if applicable
|
|
4296
|
-
if (key) {
|
|
4297
|
-
blake2bUpdate(this, key);
|
|
4298
|
-
// at the end
|
|
4299
|
-
this.c = 128;
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
|
|
4303
|
-
Blake2b.prototype.update = function (input) {
|
|
4304
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4305
|
-
blake2bUpdate(this, input);
|
|
4306
|
-
return this
|
|
4307
|
-
};
|
|
4308
|
-
|
|
4309
|
-
Blake2b.prototype.digest = function (out) {
|
|
4310
|
-
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out;
|
|
4311
|
-
assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
|
|
4312
|
-
assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
|
|
4313
|
-
blake2bFinal(this, buf);
|
|
4314
|
-
if (out === 'hex') return hexSlice(buf)
|
|
4315
|
-
return buf
|
|
4316
|
-
};
|
|
4317
|
-
|
|
4318
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4319
|
-
|
|
4320
|
-
Blake2b.ready = function (cb) {
|
|
4321
|
-
b2wasm.ready(function () {
|
|
4322
|
-
cb(); // ignore the error
|
|
4323
|
-
});
|
|
4324
|
-
};
|
|
4325
|
-
|
|
4326
|
-
// Updates a BLAKE2b streaming hash
|
|
4327
|
-
// Requires hash context and Uint8Array (byte array)
|
|
4328
|
-
function blake2bUpdate (ctx, input) {
|
|
4329
|
-
for (var i = 0; i < input.length; i++) {
|
|
4330
|
-
if (ctx.c === 128) { // buffer full ?
|
|
4331
|
-
ctx.t += ctx.c; // add counters
|
|
4332
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
4333
|
-
ctx.c = 0; // counter to zero
|
|
4334
|
-
}
|
|
4335
|
-
ctx.b[ctx.c++] = input[i];
|
|
4336
|
-
}
|
|
4337
|
-
}
|
|
4338
|
-
|
|
4339
|
-
// Completes a BLAKE2b streaming hash
|
|
4340
|
-
// Returns a Uint8Array containing the message digest
|
|
4341
|
-
function blake2bFinal (ctx, out) {
|
|
4342
|
-
ctx.t += ctx.c; // mark last block offset
|
|
4343
|
-
|
|
4344
|
-
while (ctx.c < 128) { // fill up with zeros
|
|
4345
|
-
ctx.b[ctx.c++] = 0;
|
|
4346
|
-
}
|
|
4347
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
4348
|
-
|
|
4349
|
-
for (var i = 0; i < ctx.outlen; i++) {
|
|
4350
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
4351
|
-
}
|
|
4352
|
-
return out
|
|
4353
|
-
}
|
|
4354
|
-
|
|
4355
|
-
function hexSlice (buf) {
|
|
4356
|
-
var str = '';
|
|
4357
|
-
for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
|
|
4358
|
-
return str
|
|
4359
|
-
}
|
|
4360
|
-
|
|
4361
|
-
function toHex (n) {
|
|
4362
|
-
if (n < 16) return '0' + n.toString(16)
|
|
4363
|
-
return n.toString(16)
|
|
4364
|
-
}
|
|
4365
|
-
|
|
4366
|
-
var Proto = Blake2b;
|
|
4367
|
-
|
|
4368
|
-
blake2b$3.exports = function createHash (outlen, key, salt, personal, noAssert) {
|
|
4369
|
-
if (noAssert !== true) {
|
|
4370
|
-
assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen);
|
|
4371
|
-
assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen);
|
|
4372
|
-
if (key != null) {
|
|
4373
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
4374
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
4375
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
4376
|
-
}
|
|
4377
|
-
if (salt != null) {
|
|
4378
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4379
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4380
|
-
}
|
|
4381
|
-
if (personal != null) {
|
|
4382
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4383
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4384
|
-
}
|
|
4385
|
-
}
|
|
4386
|
-
|
|
4387
|
-
return new Proto(outlen, key, salt, personal)
|
|
4388
|
-
};
|
|
4389
|
-
|
|
4390
|
-
blake2b$3.exports.ready = function (cb) {
|
|
4391
|
-
b2wasm.ready(function () { // ignore errors
|
|
4392
|
-
cb();
|
|
4393
|
-
});
|
|
4394
|
-
};
|
|
4395
|
-
|
|
4396
|
-
blake2b$3.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
|
|
4397
|
-
blake2b$3.exports.WASM_LOADED = false;
|
|
4398
|
-
|
|
4399
|
-
var BYTES_MIN = blake2b$3.exports.BYTES_MIN = 16;
|
|
4400
|
-
var BYTES_MAX = blake2b$3.exports.BYTES_MAX = 64;
|
|
4401
|
-
blake2b$3.exports.BYTES = 32;
|
|
4402
|
-
var KEYBYTES_MIN = blake2b$3.exports.KEYBYTES_MIN = 16;
|
|
4403
|
-
var KEYBYTES_MAX = blake2b$3.exports.KEYBYTES_MAX = 64;
|
|
4404
|
-
blake2b$3.exports.KEYBYTES = 32;
|
|
4405
|
-
var SALTBYTES = blake2b$3.exports.SALTBYTES = 16;
|
|
4406
|
-
var PERSONALBYTES = blake2b$3.exports.PERSONALBYTES = 16;
|
|
4407
|
-
|
|
4408
|
-
b2wasm.ready(function (err) {
|
|
4409
|
-
if (!err) {
|
|
4410
|
-
blake2b$3.exports.WASM_LOADED = true;
|
|
4411
|
-
blake2b$3.exports = b2wasm;
|
|
4412
|
-
}
|
|
4413
|
-
});
|
|
4414
|
-
return blake2b$3.exports;
|
|
3687
|
+
function deriveEd25519SecretKey(seed, blake2b) {
|
|
3688
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4415
3689
|
}
|
|
4416
|
-
|
|
4417
|
-
var blake2bExports = /*@__PURE__*/ requireBlake2b();
|
|
4418
|
-
var blake2b$1 = /*@__PURE__*/getDefaultExportFromCjs(blake2bExports);
|
|
4419
|
-
|
|
4420
3690
|
/**
|
|
4421
|
-
*
|
|
4422
|
-
*
|
|
4423
|
-
* If empty array is given a zero-hash is returned.
|
|
3691
|
+
* Derives a Bandersnatch secret key from a seed.
|
|
3692
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4424
3693
|
*/
|
|
4425
|
-
function
|
|
4426
|
-
|
|
4427
|
-
if (r.length === 0) {
|
|
4428
|
-
return out.asOpaque();
|
|
4429
|
-
}
|
|
4430
|
-
const hasher = blake2b$1(HASH_SIZE);
|
|
4431
|
-
for (const v of r) {
|
|
4432
|
-
hasher?.update(v instanceof BytesBlob ? v.raw : v);
|
|
4433
|
-
}
|
|
4434
|
-
hasher?.digest(out.raw);
|
|
4435
|
-
return out.asOpaque();
|
|
3694
|
+
function deriveBandersnatchSecretKey(seed, blake2b) {
|
|
3695
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4436
3696
|
}
|
|
4437
|
-
/**
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
const out = allocator.emptyHash();
|
|
4443
|
-
hasher?.digest(out.raw);
|
|
4444
|
-
return out;
|
|
3697
|
+
/**
|
|
3698
|
+
* Derive Ed25519 public key from secret seed
|
|
3699
|
+
*/
|
|
3700
|
+
async function deriveEd25519PublicKey(seed) {
|
|
3701
|
+
return (await privateKey(seed)).pubKey;
|
|
4445
3702
|
}
|
|
4446
|
-
/**
|
|
4447
|
-
|
|
4448
|
-
|
|
3703
|
+
/**
|
|
3704
|
+
* Derive Bandersnatch public key from secret seed
|
|
3705
|
+
*/
|
|
3706
|
+
function deriveBandersnatchPublicKey(seed) {
|
|
3707
|
+
return publicKey(seed.raw);
|
|
4449
3708
|
}
|
|
4450
3709
|
|
|
4451
|
-
var
|
|
3710
|
+
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
3711
|
+
__proto__: null,
|
|
3712
|
+
SEED_SIZE: SEED_SIZE,
|
|
3713
|
+
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
3714
|
+
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
3715
|
+
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
3716
|
+
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
3717
|
+
trivialSeed: trivialSeed
|
|
3718
|
+
});
|
|
3719
|
+
|
|
3720
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4452
3721
|
__proto__: null,
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
3722
|
+
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
3723
|
+
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
3724
|
+
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
3725
|
+
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
3726
|
+
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
3727
|
+
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
3728
|
+
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
3729
|
+
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
3730
|
+
Ed25519Pair: Ed25519Pair,
|
|
3731
|
+
SEED_SIZE: SEED_SIZE,
|
|
3732
|
+
bandersnatch: bandersnatch,
|
|
3733
|
+
bandersnatchWasm: bandersnatch_exports,
|
|
3734
|
+
ed25519: ed25519,
|
|
3735
|
+
initWasm: initAll,
|
|
3736
|
+
keyDerivation: keyDerivation
|
|
4456
3737
|
});
|
|
4457
3738
|
|
|
4458
3739
|
/*!
|
|
@@ -4813,18 +4094,89 @@ function WASMInterface(binary, hashLength) {
|
|
|
4813
4094
|
|
|
4814
4095
|
new Mutex();
|
|
4815
4096
|
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
new Mutex();
|
|
4097
|
+
var name$j = "blake2b";
|
|
4098
|
+
var data$j = "AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2hfR2V0U3RhdGUABw5IYXNoX0NhbGN1bGF0ZQAIClNUQVRFX1NJWkUDAQrTOAkFAEGACQvrAgIFfwF+AkAgAUEBSA0AAkACQAJAIAFBgAFBACgC4IoBIgJrIgNKDQAgASEEDAELQQBBADYC4IoBAkAgAkH/AEoNACACQeCJAWohBSAAIQRBACEGA0AgBSAELQAAOgAAIARBAWohBCAFQQFqIQUgAyAGQQFqIgZB/wFxSg0ACwtBAEEAKQPAiQEiB0KAAXw3A8CJAUEAQQApA8iJASAHQv9+Vq18NwPIiQFB4IkBEAIgACADaiEAAkAgASADayIEQYEBSA0AIAIgAWohBQNAQQBBACkDwIkBIgdCgAF8NwPAiQFBAEEAKQPIiQEgB0L/flatfDcDyIkBIAAQAiAAQYABaiEAIAVBgH9qIgVBgA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AUgNAEEAIQRBACECA0AgBEGACWogACAEai0AADoAACAEQQFqIQQgBSACQQFqIgJB/wFxSg0ACwsgAEHAAGokAAv9AwMBfwF+AX8jAEGAAWsiAiQAQQBBgQI7AfKKAUEAIAE6APGKAUEAIAA6APCKAUGQfiEAA0AgAEGAiwFqQgA3AAAgAEH4igFqQgA3AAAgAEHwigFqQgA3AAAgAEEYaiIADQALQQAhAEEAQQApA/CKASIDQoiS853/zPmE6gCFNwOAiQFBAEEAKQP4igFCu86qptjQ67O7f4U3A4iJAUEAQQApA4CLAUKr8NP0r+68tzyFNwOQiQFBAEEAKQOIiwFC8e30+KWn/aelf4U3A5iJAUEAQQApA5CLAULRhZrv+s+Uh9EAhTcDoIkBQQBBACkDmIsBQp/Y+dnCkdqCm3+FNwOoiQFBAEEAKQOgiwFC6/qG2r+19sEfhTcDsIkBQQBBACkDqIsBQvnC+JuRo7Pw2wCFNwO4iQFBACADp0H/AXE2AuSKAQJAIAFBAUgNACACQgA3A3ggAkIANwNwIAJCADcDaCACQgA3A2AgAkIANwNYIAJCADcDUCACQgA3A0ggAkIANwNAIAJCADcDOCACQgA3AzAgAkIANwMoIAJCADcDICACQgA3AxggAkIANwMQIAJCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=";
|
|
4099
|
+
var hash$j = "c6f286e6";
|
|
4100
|
+
var wasmJson$j = {
|
|
4101
|
+
name: name$j,
|
|
4102
|
+
data: data$j,
|
|
4103
|
+
hash: hash$j
|
|
4104
|
+
};
|
|
4825
4105
|
|
|
4826
4106
|
new Mutex();
|
|
4827
|
-
|
|
4107
|
+
function validateBits$4(bits) {
|
|
4108
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
4109
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
4110
|
+
}
|
|
4111
|
+
return null;
|
|
4112
|
+
}
|
|
4113
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
4114
|
+
return outputBits | (keyBits << 16);
|
|
4115
|
+
}
|
|
4116
|
+
/**
|
|
4117
|
+
* Creates a new BLAKE2b hash instance
|
|
4118
|
+
* @param bits Number of output bits, which has to be a number
|
|
4119
|
+
* divisible by 8, between 8 and 512. Defaults to 512.
|
|
4120
|
+
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
|
|
4121
|
+
*/
|
|
4122
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
4123
|
+
if (validateBits$4(bits)) {
|
|
4124
|
+
return Promise.reject(validateBits$4(bits));
|
|
4125
|
+
}
|
|
4126
|
+
let keyBuffer = null;
|
|
4127
|
+
let initParam = bits;
|
|
4128
|
+
if (key !== null) {
|
|
4129
|
+
keyBuffer = getUInt8Buffer(key);
|
|
4130
|
+
if (keyBuffer.length > 64) {
|
|
4131
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
4132
|
+
}
|
|
4133
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
4134
|
+
}
|
|
4135
|
+
const outputSize = bits / 8;
|
|
4136
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
4137
|
+
if (initParam > 512) {
|
|
4138
|
+
wasm.writeMemory(keyBuffer);
|
|
4139
|
+
}
|
|
4140
|
+
wasm.init(initParam);
|
|
4141
|
+
const obj = {
|
|
4142
|
+
init: initParam > 512
|
|
4143
|
+
? () => {
|
|
4144
|
+
wasm.writeMemory(keyBuffer);
|
|
4145
|
+
wasm.init(initParam);
|
|
4146
|
+
return obj;
|
|
4147
|
+
}
|
|
4148
|
+
: () => {
|
|
4149
|
+
wasm.init(initParam);
|
|
4150
|
+
return obj;
|
|
4151
|
+
},
|
|
4152
|
+
update: (data) => {
|
|
4153
|
+
wasm.update(data);
|
|
4154
|
+
return obj;
|
|
4155
|
+
},
|
|
4156
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
4157
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
4158
|
+
save: () => wasm.save(),
|
|
4159
|
+
load: (data) => {
|
|
4160
|
+
wasm.load(data);
|
|
4161
|
+
return obj;
|
|
4162
|
+
},
|
|
4163
|
+
blockSize: 128,
|
|
4164
|
+
digestSize: outputSize,
|
|
4165
|
+
};
|
|
4166
|
+
return obj;
|
|
4167
|
+
});
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4170
|
+
new Mutex();
|
|
4171
|
+
|
|
4172
|
+
new Mutex();
|
|
4173
|
+
|
|
4174
|
+
new Mutex();
|
|
4175
|
+
|
|
4176
|
+
new Mutex();
|
|
4177
|
+
|
|
4178
|
+
new Mutex();
|
|
4179
|
+
|
|
4828
4180
|
new Mutex();
|
|
4829
4181
|
|
|
4830
4182
|
new Mutex();
|
|
@@ -4903,6 +4255,79 @@ new Mutex();
|
|
|
4903
4255
|
|
|
4904
4256
|
new Mutex();
|
|
4905
4257
|
|
|
4258
|
+
/**
|
|
4259
|
+
* Size of the output of the hash functions.
|
|
4260
|
+
*
|
|
4261
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
4262
|
+
*
|
|
4263
|
+
*/
|
|
4264
|
+
const HASH_SIZE = 32;
|
|
4265
|
+
/** A hash without last byte (useful for trie representation). */
|
|
4266
|
+
const TRUNCATED_HASH_SIZE = 31;
|
|
4267
|
+
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
4268
|
+
/**
|
|
4269
|
+
* Container for some object with a hash that is related to this object.
|
|
4270
|
+
*
|
|
4271
|
+
* After calculating the hash these two should be passed together to avoid
|
|
4272
|
+
* unnecessary re-hashing of the data.
|
|
4273
|
+
*/
|
|
4274
|
+
class WithHash extends WithDebug {
|
|
4275
|
+
hash;
|
|
4276
|
+
data;
|
|
4277
|
+
constructor(hash, data) {
|
|
4278
|
+
super();
|
|
4279
|
+
this.hash = hash;
|
|
4280
|
+
this.data = data;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
/**
|
|
4284
|
+
* Extension of [`WithHash`] additionally containing an encoded version of the object.
|
|
4285
|
+
*/
|
|
4286
|
+
class WithHashAndBytes extends WithHash {
|
|
4287
|
+
encoded;
|
|
4288
|
+
constructor(hash, data, encoded) {
|
|
4289
|
+
super(hash, data);
|
|
4290
|
+
this.encoded = encoded;
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
|
|
4294
|
+
const zero$1 = Bytes.zero(HASH_SIZE);
|
|
4295
|
+
class Blake2b {
|
|
4296
|
+
hasher;
|
|
4297
|
+
static async createHasher() {
|
|
4298
|
+
return new Blake2b(await createBLAKE2b(HASH_SIZE * 8));
|
|
4299
|
+
}
|
|
4300
|
+
constructor(hasher) {
|
|
4301
|
+
this.hasher = hasher;
|
|
4302
|
+
}
|
|
4303
|
+
/**
|
|
4304
|
+
* Hash given collection of blobs.
|
|
4305
|
+
*
|
|
4306
|
+
* If empty array is given a zero-hash is returned.
|
|
4307
|
+
*/
|
|
4308
|
+
hashBlobs(r) {
|
|
4309
|
+
if (r.length === 0) {
|
|
4310
|
+
return zero$1.asOpaque();
|
|
4311
|
+
}
|
|
4312
|
+
const hasher = this.hasher.init();
|
|
4313
|
+
for (const v of r) {
|
|
4314
|
+
hasher.update(v instanceof BytesBlob ? v.raw : v);
|
|
4315
|
+
}
|
|
4316
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4317
|
+
}
|
|
4318
|
+
/** Hash given blob of bytes. */
|
|
4319
|
+
hashBytes(blob) {
|
|
4320
|
+
const hasher = this.hasher.init();
|
|
4321
|
+
const bytes = blob instanceof BytesBlob ? blob.raw : blob;
|
|
4322
|
+
hasher.update(bytes);
|
|
4323
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4324
|
+
}
|
|
4325
|
+
/** Convert given string into bytes and hash it. */
|
|
4326
|
+
hashString(str) {
|
|
4327
|
+
return this.hashBytes(BytesBlob.blobFromString(str));
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
|
|
4906
4331
|
class KeccakHasher {
|
|
4907
4332
|
hasher;
|
|
4908
4333
|
static async create() {
|
|
@@ -4927,91 +4352,61 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4927
4352
|
hashBlobs: hashBlobs
|
|
4928
4353
|
});
|
|
4929
4354
|
|
|
4930
|
-
|
|
4355
|
+
// TODO [ToDr] (#213) this should most likely be moved to a separate
|
|
4356
|
+
// package to avoid pulling in unnecessary deps.
|
|
4357
|
+
|
|
4358
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4931
4359
|
__proto__: null,
|
|
4360
|
+
Blake2b: Blake2b,
|
|
4932
4361
|
HASH_SIZE: HASH_SIZE,
|
|
4933
|
-
PageAllocator: PageAllocator,
|
|
4934
|
-
SimpleAllocator: SimpleAllocator,
|
|
4935
4362
|
TRUNCATED_HASH_SIZE: TRUNCATED_HASH_SIZE,
|
|
4936
4363
|
WithHash: WithHash,
|
|
4937
4364
|
WithHashAndBytes: WithHashAndBytes,
|
|
4938
4365
|
ZERO_HASH: ZERO_HASH,
|
|
4939
|
-
blake2b: blake2b,
|
|
4940
|
-
defaultAllocator: defaultAllocator,
|
|
4941
4366
|
keccak: keccak
|
|
4942
4367
|
});
|
|
4943
4368
|
|
|
4944
|
-
const SEED_SIZE = 32;
|
|
4945
|
-
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
4946
|
-
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
4947
|
-
/**
|
|
4948
|
-
* JIP-5: Secret key derivation
|
|
4949
|
-
*
|
|
4950
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
4951
|
-
/**
|
|
4952
|
-
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
4953
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
4954
|
-
*/
|
|
4955
|
-
function trivialSeed(s) {
|
|
4956
|
-
const s_le = u32AsLeBytes(s);
|
|
4957
|
-
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();
|
|
4958
|
-
}
|
|
4959
|
-
/**
|
|
4960
|
-
* Derives a Ed25519 secret key from a seed.
|
|
4961
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4962
|
-
*/
|
|
4963
|
-
function deriveEd25519SecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4964
|
-
return hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4965
|
-
}
|
|
4966
|
-
/**
|
|
4967
|
-
* Derives a Bandersnatch secret key from a seed.
|
|
4968
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4969
|
-
*/
|
|
4970
|
-
function deriveBandersnatchSecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4971
|
-
return hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4972
|
-
}
|
|
4973
|
-
/**
|
|
4974
|
-
* Derive Ed25519 public key from secret seed
|
|
4975
|
-
*/
|
|
4976
|
-
async function deriveEd25519PublicKey(seed) {
|
|
4977
|
-
return (await privateKey(seed)).pubKey;
|
|
4978
|
-
}
|
|
4979
4369
|
/**
|
|
4980
|
-
*
|
|
4370
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
4981
4371
|
*/
|
|
4982
|
-
|
|
4983
|
-
|
|
4372
|
+
class ArrayView {
|
|
4373
|
+
start;
|
|
4374
|
+
end;
|
|
4375
|
+
source;
|
|
4376
|
+
length;
|
|
4377
|
+
constructor(source, start, end) {
|
|
4378
|
+
this.start = start;
|
|
4379
|
+
this.end = end;
|
|
4380
|
+
this.source = source;
|
|
4381
|
+
this.length = end - start;
|
|
4382
|
+
}
|
|
4383
|
+
static from(source, start = 0, end = source.length) {
|
|
4384
|
+
check `
|
|
4385
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
4386
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
4387
|
+
`;
|
|
4388
|
+
return new ArrayView(source, start, end);
|
|
4389
|
+
}
|
|
4390
|
+
get(i) {
|
|
4391
|
+
check `
|
|
4392
|
+
${i >= 0 && i < this.length}
|
|
4393
|
+
Index out of bounds: ${i} < ${this.length}
|
|
4394
|
+
`;
|
|
4395
|
+
return this.source[this.start + i];
|
|
4396
|
+
}
|
|
4397
|
+
subview(from, to = this.length) {
|
|
4398
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
4399
|
+
}
|
|
4400
|
+
toArray() {
|
|
4401
|
+
return this.source.slice(this.start, this.end);
|
|
4402
|
+
}
|
|
4403
|
+
*[Symbol.iterator]() {
|
|
4404
|
+
for (let i = this.start; i < this.end; i++) {
|
|
4405
|
+
yield this.source[i];
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4984
4408
|
}
|
|
4985
4409
|
|
|
4986
|
-
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
4987
|
-
__proto__: null,
|
|
4988
|
-
SEED_SIZE: SEED_SIZE,
|
|
4989
|
-
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
4990
|
-
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
4991
|
-
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
4992
|
-
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
4993
|
-
trivialSeed: trivialSeed
|
|
4994
|
-
});
|
|
4995
|
-
|
|
4996
|
-
var index$o = /*#__PURE__*/Object.freeze({
|
|
4997
|
-
__proto__: null,
|
|
4998
|
-
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4999
|
-
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
5000
|
-
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
5001
|
-
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
5002
|
-
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
5003
|
-
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
5004
|
-
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
5005
|
-
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
5006
|
-
Ed25519Pair: Ed25519Pair,
|
|
5007
|
-
SEED_SIZE: SEED_SIZE,
|
|
5008
|
-
bandersnatch: bandersnatch,
|
|
5009
|
-
bandersnatchWasm: bandersnatch_exports,
|
|
5010
|
-
ed25519: ed25519,
|
|
5011
|
-
initWasm: initAll,
|
|
5012
|
-
keyDerivation: keyDerivation
|
|
5013
|
-
});
|
|
5014
|
-
|
|
5015
4410
|
/** A map which uses hashes as keys. */
|
|
5016
4411
|
class HashDictionary {
|
|
5017
4412
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
@@ -5599,6 +4994,7 @@ class TruncatedHashDictionary {
|
|
|
5599
4994
|
|
|
5600
4995
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
5601
4996
|
__proto__: null,
|
|
4997
|
+
ArrayView: ArrayView,
|
|
5602
4998
|
FixedSizeArray: FixedSizeArray,
|
|
5603
4999
|
HashDictionary: HashDictionary,
|
|
5604
5000
|
HashSet: HashSet,
|
|
@@ -7287,6 +6683,17 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
7287
6683
|
});
|
|
7288
6684
|
}
|
|
7289
6685
|
|
|
6686
|
+
/**
|
|
6687
|
+
* Take an input data and re-encode that data as view.
|
|
6688
|
+
*
|
|
6689
|
+
* NOTE: this function should NEVER be used in any production code,
|
|
6690
|
+
* it's only a test helper.
|
|
6691
|
+
*/
|
|
6692
|
+
function reencodeAsView(codec, object, chainSpec) {
|
|
6693
|
+
const encoded = Encoder.encodeObject(codec, object, chainSpec);
|
|
6694
|
+
return Decoder.decodeObject(codec.View, encoded, chainSpec);
|
|
6695
|
+
}
|
|
6696
|
+
|
|
7290
6697
|
var index$l = /*#__PURE__*/Object.freeze({
|
|
7291
6698
|
__proto__: null,
|
|
7292
6699
|
Block: Block,
|
|
@@ -7307,6 +6714,7 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
7307
6714
|
guarantees: guarantees,
|
|
7308
6715
|
headerViewWithHashCodec: headerViewWithHashCodec,
|
|
7309
6716
|
preimage: preimage,
|
|
6717
|
+
reencodeAsView: reencodeAsView,
|
|
7310
6718
|
refineContext: refineContext,
|
|
7311
6719
|
tickets: tickets,
|
|
7312
6720
|
tryAsCoreIndex: tryAsCoreIndex,
|
|
@@ -7919,7 +7327,7 @@ var chain_spec$1 = {
|
|
|
7919
7327
|
"0d000000000000000000000000000000000000000000000000000000000000": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
7920
7328
|
"01000000000000000000000000000000000000000000000000000000000000": "080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978",
|
|
7921
7329
|
"10000000000000000000000000000000000000000000000000000000000000": "00",
|
|
7922
|
-
"0c000000000000000000000000000000000000000000000000000000000000": "
|
|
7330
|
+
"0c000000000000000000000000000000000000000000000000000000000000": "000000000000000000000000000000000000000000",
|
|
7923
7331
|
"06000000000000000000000000000000000000000000000000000000000000": "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25bb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aae88bd757ad5b9bedf372d8d3f0cf6c962a469db61a265f6418e1ffed86da29ec",
|
|
7924
7332
|
"0a000000000000000000000000000000000000000000000000000000000000": "0000",
|
|
7925
7333
|
"03000000000000000000000000000000000000000000000000000000000000": "012bf11dc5e1c7b9bbaafc2c8533017abc12daeb0baf22c92509ad50f7875e5716000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
@@ -7967,7 +7375,7 @@ var chain_spec = {
|
|
|
7967
7375
|
"0d000000000000000000000000000000000000000000000000000000000000": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
7968
7376
|
"01000000000000000000000000000000000000000000000000000000000000": "080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978",
|
|
7969
7377
|
"10000000000000000000000000000000000000000000000000000000000000": "00",
|
|
7970
|
-
"0c000000000000000000000000000000000000000000000000000000000000": "
|
|
7378
|
+
"0c000000000000000000000000000000000000000000000000000000000000": "000000000000000000000000000000000000000000",
|
|
7971
7379
|
"06000000000000000000000000000000000000000000000000000000000000": "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25bb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aae88bd757ad5b9bedf372d8d3f0cf6c962a469db61a265f6418e1ffed86da29ec",
|
|
7972
7380
|
"0a000000000000000000000000000000000000000000000000000000000000": "0000",
|
|
7973
7381
|
"03000000000000000000000000000000000000000000000000000000000000": "012bf11dc5e1c7b9bbaafc2c8533017abc12daeb0baf22c92509ad50f7875e5716000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
@@ -8560,43 +7968,43 @@ var stateKeys;
|
|
|
8560
7968
|
}
|
|
8561
7969
|
stateKeys.serviceInfo = serviceInfo;
|
|
8562
7970
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bba033bba03?v=0.7.1 */
|
|
8563
|
-
function serviceStorage(serviceId, key) {
|
|
7971
|
+
function serviceStorage(blake2b, serviceId, key) {
|
|
8564
7972
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8565
7973
|
const out = Bytes.zero(HASH_SIZE);
|
|
8566
7974
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 1)), 0);
|
|
8567
7975
|
out.raw.set(key.raw.subarray(0, HASH_SIZE - U32_BYTES), U32_BYTES);
|
|
8568
7976
|
return legacyServiceNested(serviceId, out);
|
|
8569
7977
|
}
|
|
8570
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
7978
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
8571
7979
|
}
|
|
8572
7980
|
stateKeys.serviceStorage = serviceStorage;
|
|
8573
7981
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bd7033bd703?v=0.7.1 */
|
|
8574
|
-
function servicePreimage(serviceId, hash) {
|
|
7982
|
+
function servicePreimage(blake2b, serviceId, hash) {
|
|
8575
7983
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8576
7984
|
const out = Bytes.zero(HASH_SIZE);
|
|
8577
7985
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 2)), 0);
|
|
8578
7986
|
out.raw.set(hash.raw.subarray(1, HASH_SIZE - U32_BYTES + 1), U32_BYTES);
|
|
8579
7987
|
return legacyServiceNested(serviceId, out);
|
|
8580
7988
|
}
|
|
8581
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
7989
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
8582
7990
|
}
|
|
8583
7991
|
stateKeys.servicePreimage = servicePreimage;
|
|
8584
7992
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b0a043b0a04?v=0.7.1 */
|
|
8585
|
-
function serviceLookupHistory(serviceId, hash, preimageLength) {
|
|
7993
|
+
function serviceLookupHistory(blake2b, serviceId, hash, preimageLength) {
|
|
8586
7994
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8587
|
-
const doubleHash = hashBytes(hash);
|
|
7995
|
+
const doubleHash = blake2b.hashBytes(hash);
|
|
8588
7996
|
const out = Bytes.zero(HASH_SIZE);
|
|
8589
7997
|
out.raw.set(u32AsLeBytes(preimageLength), 0);
|
|
8590
7998
|
out.raw.set(doubleHash.raw.subarray(2, HASH_SIZE - U32_BYTES + 2), U32_BYTES);
|
|
8591
7999
|
return legacyServiceNested(serviceId, out);
|
|
8592
8000
|
}
|
|
8593
|
-
return serviceNested(serviceId, preimageLength, hash);
|
|
8001
|
+
return serviceNested(blake2b, serviceId, preimageLength, hash);
|
|
8594
8002
|
}
|
|
8595
8003
|
stateKeys.serviceLookupHistory = serviceLookupHistory;
|
|
8596
8004
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b88003b8800?v=0.7.1 */
|
|
8597
|
-
function serviceNested(serviceId, numberPrefix, hash) {
|
|
8005
|
+
function serviceNested(blake2b, serviceId, numberPrefix, hash) {
|
|
8598
8006
|
const inputToHash = BytesBlob.blobFromParts(u32AsLeBytes(numberPrefix), hash.raw);
|
|
8599
|
-
const newHash = hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8007
|
+
const newHash = blake2b.hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8600
8008
|
const key = Bytes.zero(HASH_SIZE);
|
|
8601
8009
|
let i = 0;
|
|
8602
8010
|
for (const byte of u32AsLeBytes(serviceId)) {
|
|
@@ -8657,12 +8065,70 @@ function accumulationOutputComparator(a, b) {
|
|
|
8657
8065
|
return Ordering.Equal;
|
|
8658
8066
|
}
|
|
8659
8067
|
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8068
|
+
/** `O`: Maximum number of items in the authorizations pool. */
|
|
8069
|
+
const O = 8;
|
|
8070
|
+
/** `Q`: The number of items in the authorizations queue. */
|
|
8071
|
+
const Q = 80;
|
|
8072
|
+
/** `W_T`: The size of a transfer memo in octets. */
|
|
8073
|
+
const W_T = 128;
|
|
8074
|
+
/**
|
|
8075
|
+
* `J`: The maximum sum of dependency items in a work-report.
|
|
8076
|
+
*
|
|
8077
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
8078
|
+
*/
|
|
8079
|
+
const MAX_REPORT_DEPENDENCIES = 8;
|
|
8080
|
+
|
|
8081
|
+
/**
|
|
8082
|
+
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
8083
|
+
*
|
|
8084
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
8085
|
+
*/
|
|
8086
|
+
class NotYetAccumulatedReport extends WithDebug {
|
|
8087
|
+
report;
|
|
8088
|
+
dependencies;
|
|
8089
|
+
static Codec = codec$1.Class(NotYetAccumulatedReport, {
|
|
8090
|
+
report: WorkReport.Codec,
|
|
8091
|
+
dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
8092
|
+
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
8093
|
+
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
8094
|
+
minLength: 0,
|
|
8095
|
+
}),
|
|
8096
|
+
});
|
|
8097
|
+
static create({ report, dependencies }) {
|
|
8098
|
+
return new NotYetAccumulatedReport(report, dependencies);
|
|
8099
|
+
}
|
|
8100
|
+
constructor(
|
|
8101
|
+
/**
|
|
8102
|
+
* Each of these were made available at most one epoch ago
|
|
8103
|
+
* but have or had unfulfilled dependencies.
|
|
8104
|
+
*/
|
|
8105
|
+
report,
|
|
8106
|
+
/**
|
|
8107
|
+
* Alongside the work-report itself, we retain its un-accumulated
|
|
8108
|
+
* dependencies, a set of work-package hashes.
|
|
8109
|
+
*
|
|
8110
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
8111
|
+
*/
|
|
8112
|
+
dependencies) {
|
|
8113
|
+
super();
|
|
8114
|
+
this.report = report;
|
|
8115
|
+
this.dependencies = dependencies;
|
|
8116
|
+
}
|
|
8117
|
+
}
|
|
8118
|
+
const accumulationQueueCodec = codecPerEpochBlock(readonlyArray(codec$1.sequenceVarLen(NotYetAccumulatedReport.Codec)));
|
|
8119
|
+
|
|
8120
|
+
/** Check if given array has correct length before casting to the opaque type. */
|
|
8121
|
+
function tryAsPerCore(array, spec) {
|
|
8122
|
+
check `
|
|
8123
|
+
${array.length === spec.coresCount}
|
|
8124
|
+
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
8125
|
+
`;
|
|
8126
|
+
return asOpaqueType(array);
|
|
8127
|
+
}
|
|
8128
|
+
const codecPerCore = (val) => codecWithContext((context) => {
|
|
8129
|
+
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
8130
|
+
});
|
|
8131
|
+
|
|
8666
8132
|
/**
|
|
8667
8133
|
* Assignment of particular work report to a core.
|
|
8668
8134
|
*
|
|
@@ -8675,7 +8141,7 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8675
8141
|
workReport;
|
|
8676
8142
|
timeout;
|
|
8677
8143
|
static Codec = codec$1.Class(AvailabilityAssignment, {
|
|
8678
|
-
workReport:
|
|
8144
|
+
workReport: WorkReport.Codec,
|
|
8679
8145
|
timeout: codec$1.u32.asOpaque(),
|
|
8680
8146
|
});
|
|
8681
8147
|
static create({ workReport, timeout }) {
|
|
@@ -8691,19 +8157,19 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8691
8157
|
this.timeout = timeout;
|
|
8692
8158
|
}
|
|
8693
8159
|
}
|
|
8160
|
+
const availabilityAssignmentsCodec = codecPerCore(codec$1.optional(AvailabilityAssignment.Codec));
|
|
8161
|
+
|
|
8162
|
+
/** `O`: Maximal authorization pool size. */
|
|
8163
|
+
const MAX_AUTH_POOL_SIZE = O;
|
|
8164
|
+
/** `Q`: Size of the authorization queue. */
|
|
8165
|
+
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
8166
|
+
const authPoolsCodec = codecPerCore(codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
8167
|
+
minLength: 0,
|
|
8168
|
+
maxLength: MAX_AUTH_POOL_SIZE,
|
|
8169
|
+
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
8170
|
+
}));
|
|
8171
|
+
const authQueuesCodec = codecPerCore(codecFixedSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE));
|
|
8694
8172
|
|
|
8695
|
-
/** Check if given array has correct length before casting to the opaque type. */
|
|
8696
|
-
function tryAsPerCore(array, spec) {
|
|
8697
|
-
check `
|
|
8698
|
-
${array.length === spec.coresCount}
|
|
8699
|
-
Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
|
|
8700
|
-
`;
|
|
8701
|
-
return asOpaqueType(array);
|
|
8702
|
-
}
|
|
8703
|
-
const codecPerCore = (val) => codecWithContext((context) => {
|
|
8704
|
-
return codecKnownSizeArray(val, { fixedLength: context.coresCount });
|
|
8705
|
-
});
|
|
8706
|
-
|
|
8707
8173
|
const sortedSetCodec = () => readonlyArray(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE))).convert((input) => input.array, (output) => {
|
|
8708
8174
|
const typed = output.map((x) => x.asOpaque());
|
|
8709
8175
|
return SortedSet.fromSortedArray(hashComparator, typed);
|
|
@@ -8766,81 +8232,10 @@ function hashComparator(a, b) {
|
|
|
8766
8232
|
return a.compare(b);
|
|
8767
8233
|
}
|
|
8768
8234
|
|
|
8769
|
-
|
|
8770
|
-
const
|
|
8771
|
-
|
|
8772
|
-
const
|
|
8773
|
-
/** `W_T`: The size of a transfer memo in octets. */
|
|
8774
|
-
const W_T = 128;
|
|
8775
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
8776
|
-
/**
|
|
8777
|
-
* `J`: The maximum sum of dependency items in a work-report.
|
|
8778
|
-
*
|
|
8779
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/416a00416a00?v=0.6.2
|
|
8780
|
-
*/
|
|
8781
|
-
const MAX_REPORT_DEPENDENCIES = 8;
|
|
8782
|
-
/** `Q`: Size of the authorization queue. */
|
|
8783
|
-
const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
8784
|
-
/** `O`: Maximal authorization pool size. */
|
|
8785
|
-
const MAX_AUTH_POOL_SIZE = O;
|
|
8786
|
-
|
|
8787
|
-
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8788
|
-
class AutoAccumulate {
|
|
8789
|
-
service;
|
|
8790
|
-
gasLimit;
|
|
8791
|
-
static Codec = codec$1.Class(AutoAccumulate, {
|
|
8792
|
-
service: codec$1.u32.asOpaque(),
|
|
8793
|
-
gasLimit: codec$1.u64.asOpaque(),
|
|
8794
|
-
});
|
|
8795
|
-
static create({ service, gasLimit }) {
|
|
8796
|
-
return new AutoAccumulate(service, gasLimit);
|
|
8797
|
-
}
|
|
8798
|
-
constructor(
|
|
8799
|
-
/** Service id that auto-accumulates. */
|
|
8800
|
-
service,
|
|
8801
|
-
/** Gas limit for auto-accumulation. */
|
|
8802
|
-
gasLimit) {
|
|
8803
|
-
this.service = service;
|
|
8804
|
-
this.gasLimit = gasLimit;
|
|
8805
|
-
}
|
|
8806
|
-
}
|
|
8807
|
-
/**
|
|
8808
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/11da0111da01?v=0.6.7
|
|
8809
|
-
*/
|
|
8810
|
-
class PrivilegedServices {
|
|
8811
|
-
manager;
|
|
8812
|
-
authManager;
|
|
8813
|
-
validatorsManager;
|
|
8814
|
-
autoAccumulateServices;
|
|
8815
|
-
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8816
|
-
manager: codec$1.u32.asOpaque(),
|
|
8817
|
-
authManager: codecPerCore(codec$1.u32.asOpaque()),
|
|
8818
|
-
validatorsManager: codec$1.u32.asOpaque(),
|
|
8819
|
-
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8820
|
-
});
|
|
8821
|
-
static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
|
|
8822
|
-
return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
|
|
8823
|
-
}
|
|
8824
|
-
constructor(
|
|
8825
|
-
/**
|
|
8826
|
-
* `chi_m`: The first, χm, is the index of the manager service which is
|
|
8827
|
-
* the service able to effect an alteration of χ from block to block,
|
|
8828
|
-
* as well as bestow services with storage deposit credits.
|
|
8829
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
|
|
8830
|
-
*/
|
|
8831
|
-
manager,
|
|
8832
|
-
/** `chi_a`: Manages authorization queue one for each core. */
|
|
8833
|
-
authManager,
|
|
8834
|
-
/** `chi_v`: Managers validator keys. */
|
|
8835
|
-
validatorsManager,
|
|
8836
|
-
/** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
8837
|
-
autoAccumulateServices) {
|
|
8838
|
-
this.manager = manager;
|
|
8839
|
-
this.authManager = authManager;
|
|
8840
|
-
this.validatorsManager = validatorsManager;
|
|
8841
|
-
this.autoAccumulateServices = autoAccumulateServices;
|
|
8842
|
-
}
|
|
8843
|
-
}
|
|
8235
|
+
const MAX_VALUE = 4294967295;
|
|
8236
|
+
const MIN_VALUE = -2147483648;
|
|
8237
|
+
const MAX_SHIFT_U32 = 32;
|
|
8238
|
+
const MAX_SHIFT_U64 = 64n;
|
|
8844
8239
|
|
|
8845
8240
|
/**
|
|
8846
8241
|
* `H = 8`: The size of recent history, in blocks.
|
|
@@ -8879,6 +8274,11 @@ class BlockState extends WithDebug {
|
|
|
8879
8274
|
this.reported = reported;
|
|
8880
8275
|
}
|
|
8881
8276
|
}
|
|
8277
|
+
/**
|
|
8278
|
+
* Recent history of blocks.
|
|
8279
|
+
*
|
|
8280
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
8281
|
+
*/
|
|
8882
8282
|
class RecentBlocks extends WithDebug {
|
|
8883
8283
|
blocks;
|
|
8884
8284
|
accumulationLog;
|
|
@@ -8892,6 +8292,11 @@ class RecentBlocks extends WithDebug {
|
|
|
8892
8292
|
peaks: readonlyArray(codec$1.sequenceVarLen(codec$1.optional(codec$1.bytes(HASH_SIZE)))),
|
|
8893
8293
|
}),
|
|
8894
8294
|
});
|
|
8295
|
+
static empty() {
|
|
8296
|
+
return new RecentBlocks(asKnownSize([]), {
|
|
8297
|
+
peaks: [],
|
|
8298
|
+
});
|
|
8299
|
+
}
|
|
8895
8300
|
static create(a) {
|
|
8896
8301
|
return new RecentBlocks(a.blocks, a.accumulationLog);
|
|
8897
8302
|
}
|
|
@@ -8911,61 +8316,8 @@ class RecentBlocks extends WithDebug {
|
|
|
8911
8316
|
this.accumulationLog = accumulationLog;
|
|
8912
8317
|
}
|
|
8913
8318
|
}
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
*
|
|
8917
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/0fc9010fc901?v=0.6.7
|
|
8918
|
-
*/
|
|
8919
|
-
class RecentBlocksHistory extends WithDebug {
|
|
8920
|
-
current;
|
|
8921
|
-
static Codec = Descriptor.new("RecentBlocksHistory", RecentBlocks.Codec.sizeHint, (encoder, value) => RecentBlocks.Codec.encode(encoder, value.asCurrent()), (decoder) => {
|
|
8922
|
-
const recentBlocks = RecentBlocks.Codec.decode(decoder);
|
|
8923
|
-
return RecentBlocksHistory.create(recentBlocks);
|
|
8924
|
-
}, (skip) => {
|
|
8925
|
-
return RecentBlocks.Codec.skip(skip);
|
|
8926
|
-
});
|
|
8927
|
-
static create(recentBlocks) {
|
|
8928
|
-
return new RecentBlocksHistory(recentBlocks);
|
|
8929
|
-
}
|
|
8930
|
-
static empty() {
|
|
8931
|
-
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
8932
|
-
blocks: asKnownSize([]),
|
|
8933
|
-
accumulationLog: { peaks: [] },
|
|
8934
|
-
}));
|
|
8935
|
-
}
|
|
8936
|
-
/**
|
|
8937
|
-
* Returns the block's BEEFY super peak.
|
|
8938
|
-
*/
|
|
8939
|
-
static accumulationResult(block) {
|
|
8940
|
-
return block.accumulationResult;
|
|
8941
|
-
}
|
|
8942
|
-
constructor(current) {
|
|
8943
|
-
super();
|
|
8944
|
-
this.current = current;
|
|
8945
|
-
}
|
|
8946
|
-
/** History of recent blocks with maximum size of `MAX_RECENT_HISTORY` */
|
|
8947
|
-
get blocks() {
|
|
8948
|
-
if (this.current !== null) {
|
|
8949
|
-
return this.current.blocks;
|
|
8950
|
-
}
|
|
8951
|
-
throw new Error("RecentBlocksHistory is in invalid state");
|
|
8952
|
-
}
|
|
8953
|
-
asCurrent() {
|
|
8954
|
-
if (this.current === null) {
|
|
8955
|
-
throw new Error("Cannot access current RecentBlocks format");
|
|
8956
|
-
}
|
|
8957
|
-
return this.current;
|
|
8958
|
-
}
|
|
8959
|
-
updateBlocks(blocks) {
|
|
8960
|
-
if (this.current !== null) {
|
|
8961
|
-
return RecentBlocksHistory.create(RecentBlocks.create({
|
|
8962
|
-
...this.current,
|
|
8963
|
-
blocks: asOpaqueType(blocks),
|
|
8964
|
-
}));
|
|
8965
|
-
}
|
|
8966
|
-
throw new Error("RecentBlocksHistory is in invalid state. Cannot be updated!");
|
|
8967
|
-
}
|
|
8968
|
-
}
|
|
8319
|
+
|
|
8320
|
+
const recentlyAccumulatedCodec = codecPerEpochBlock(codec$1.sequenceVarLen(codec$1.bytes(HASH_SIZE).asOpaque()).convert((x) => Array.from(x), (x) => HashSet.from(x)));
|
|
8969
8321
|
|
|
8970
8322
|
/**
|
|
8971
8323
|
* Fixed size of validator metadata.
|
|
@@ -9008,6 +8360,7 @@ class ValidatorData extends WithDebug {
|
|
|
9008
8360
|
this.metadata = metadata;
|
|
9009
8361
|
}
|
|
9010
8362
|
}
|
|
8363
|
+
const validatorsDataCodec = codecPerValidator(ValidatorData.Codec);
|
|
9011
8364
|
|
|
9012
8365
|
var SafroleSealingKeysKind;
|
|
9013
8366
|
(function (SafroleSealingKeysKind) {
|
|
@@ -9123,6 +8476,23 @@ const zeroSizeHint = {
|
|
|
9123
8476
|
};
|
|
9124
8477
|
/** 0-byte read, return given default value */
|
|
9125
8478
|
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8479
|
+
/** Encode and decode object with leading version number. */
|
|
8480
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8481
|
+
bytes: val.sizeHint.bytes + 8,
|
|
8482
|
+
isExact: false,
|
|
8483
|
+
}, (e, v) => {
|
|
8484
|
+
e.varU64(0n);
|
|
8485
|
+
val.encode(e, v);
|
|
8486
|
+
}, (d) => {
|
|
8487
|
+
const version = d.varU64();
|
|
8488
|
+
if (version !== 0n) {
|
|
8489
|
+
throw new Error("Non-zero version is not supported!");
|
|
8490
|
+
}
|
|
8491
|
+
return val.decode(d);
|
|
8492
|
+
}, (s) => {
|
|
8493
|
+
s.varU64();
|
|
8494
|
+
val.skip(s);
|
|
8495
|
+
});
|
|
9126
8496
|
/**
|
|
9127
8497
|
* Service account details.
|
|
9128
8498
|
*
|
|
@@ -9265,223 +8635,66 @@ class LookupHistoryItem {
|
|
|
9265
8635
|
}
|
|
9266
8636
|
}
|
|
9267
8637
|
|
|
8638
|
+
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
8639
|
+
? codec$1.u32.asOpaque()
|
|
8640
|
+
: codec$1.varU32.convert((s) => tryAsU32(s), (i) => tryAsServiceId(i));
|
|
9268
8641
|
/**
|
|
9269
|
-
*
|
|
9270
|
-
* three additional historical values of the accumulator at
|
|
9271
|
-
* the point of each of the three most recently ended epochs,
|
|
9272
|
-
* η_1, η_2 and η_3. The second-oldest of these η2 is utilized to
|
|
9273
|
-
* help ensure future entropy is unbiased (see equation 6.29)
|
|
9274
|
-
* and seed the fallback seal-key generation function with
|
|
9275
|
-
* randomness (see equation 6.24). The oldest is used to re-
|
|
9276
|
-
* generate this randomness when verifying the seal above
|
|
9277
|
-
* (see equations 6.16 and 6.15).
|
|
9278
|
-
*
|
|
9279
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/0ef5010ef501
|
|
9280
|
-
*/
|
|
9281
|
-
const ENTROPY_ENTRIES = 4;
|
|
9282
|
-
|
|
9283
|
-
var UpdatePreimageKind;
|
|
9284
|
-
(function (UpdatePreimageKind) {
|
|
9285
|
-
/** Insert new preimage and optionally update it's lookup history. */
|
|
9286
|
-
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
9287
|
-
/** Remove a preimage and it's lookup history. */
|
|
9288
|
-
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
9289
|
-
/** update or add lookup history for preimage hash/len to given value. */
|
|
9290
|
-
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
9291
|
-
})(UpdatePreimageKind || (UpdatePreimageKind = {}));
|
|
9292
|
-
/**
|
|
9293
|
-
* A preimage update.
|
|
8642
|
+
* Activity Record of a single validator.
|
|
9294
8643
|
*
|
|
9295
|
-
*
|
|
9296
|
-
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
9297
|
-
* 2. Remove (expunge) a preimage and it's lookup history.
|
|
9298
|
-
* 3. Update `LookupHistory` with given value.
|
|
8644
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
9299
8645
|
*/
|
|
9300
|
-
class
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9307
|
-
|
|
9308
|
-
|
|
9309
|
-
|
|
9310
|
-
|
|
9311
|
-
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
}
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
return new UpdatePreimage(serviceId, {
|
|
9318
|
-
kind: UpdatePreimageKind.Remove,
|
|
9319
|
-
hash,
|
|
9320
|
-
length,
|
|
9321
|
-
});
|
|
9322
|
-
}
|
|
9323
|
-
/** Update the lookup history of some preimage or add a new one (request). */
|
|
9324
|
-
static updateOrAdd({ serviceId, lookupHistory }) {
|
|
9325
|
-
return new UpdatePreimage(serviceId, {
|
|
9326
|
-
kind: UpdatePreimageKind.UpdateOrAdd,
|
|
9327
|
-
item: lookupHistory,
|
|
9328
|
-
});
|
|
8646
|
+
class ValidatorStatistics {
|
|
8647
|
+
blocks;
|
|
8648
|
+
tickets;
|
|
8649
|
+
preImages;
|
|
8650
|
+
preImagesSize;
|
|
8651
|
+
guarantees;
|
|
8652
|
+
assurances;
|
|
8653
|
+
static Codec = codec$1.Class(ValidatorStatistics, {
|
|
8654
|
+
blocks: codec$1.u32,
|
|
8655
|
+
tickets: codec$1.u32,
|
|
8656
|
+
preImages: codec$1.u32,
|
|
8657
|
+
preImagesSize: codec$1.u32,
|
|
8658
|
+
guarantees: codec$1.u32,
|
|
8659
|
+
assurances: codec$1.u32,
|
|
8660
|
+
});
|
|
8661
|
+
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
8662
|
+
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
9329
8663
|
}
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
8664
|
+
constructor(
|
|
8665
|
+
/** The number of blocks produced by the validator. */
|
|
8666
|
+
blocks,
|
|
8667
|
+
/** The number of tickets introduced by the validator. */
|
|
8668
|
+
tickets,
|
|
8669
|
+
/** The number of preimages introduced by the validator. */
|
|
8670
|
+
preImages,
|
|
8671
|
+
/** The total number of octets across all preimages introduced by the validator. */
|
|
8672
|
+
preImagesSize,
|
|
8673
|
+
/** The number of reports guaranteed by the validator. */
|
|
8674
|
+
guarantees,
|
|
8675
|
+
/** The number of availability assurances made by the validator. */
|
|
8676
|
+
assurances) {
|
|
8677
|
+
this.blocks = blocks;
|
|
8678
|
+
this.tickets = tickets;
|
|
8679
|
+
this.preImages = preImages;
|
|
8680
|
+
this.preImagesSize = preImagesSize;
|
|
8681
|
+
this.guarantees = guarantees;
|
|
8682
|
+
this.assurances = assurances;
|
|
9340
8683
|
}
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
return tryAsU32(this.action.preimage.blob.length);
|
|
9345
|
-
case UpdatePreimageKind.Remove:
|
|
9346
|
-
return this.action.length;
|
|
9347
|
-
case UpdatePreimageKind.UpdateOrAdd:
|
|
9348
|
-
return this.action.item.length;
|
|
9349
|
-
}
|
|
9350
|
-
throw assertNever(this.action);
|
|
8684
|
+
static empty() {
|
|
8685
|
+
const zero = tryAsU32(0);
|
|
8686
|
+
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
9351
8687
|
}
|
|
9352
8688
|
}
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
(
|
|
9356
|
-
/** Just update the `ServiceAccountInfo`. */
|
|
9357
|
-
UpdateServiceKind[UpdateServiceKind["Update"] = 0] = "Update";
|
|
9358
|
-
/** Create a new `Service` instance. */
|
|
9359
|
-
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
9360
|
-
})(UpdateServiceKind || (UpdateServiceKind = {}));
|
|
8689
|
+
const codecVarU16 = codec$1.varU32.convert((i) => tryAsU32(i), (o) => tryAsU16(o));
|
|
8690
|
+
/** Encode/decode unsigned gas. */
|
|
8691
|
+
const codecVarGas = codec$1.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
9361
8692
|
/**
|
|
9362
|
-
*
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
constructor(serviceId, action) {
|
|
9368
|
-
this.serviceId = serviceId;
|
|
9369
|
-
this.action = action;
|
|
9370
|
-
}
|
|
9371
|
-
static update({ serviceId, serviceInfo }) {
|
|
9372
|
-
return new UpdateService(serviceId, {
|
|
9373
|
-
kind: UpdateServiceKind.Update,
|
|
9374
|
-
account: serviceInfo,
|
|
9375
|
-
});
|
|
9376
|
-
}
|
|
9377
|
-
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
9378
|
-
return new UpdateService(serviceId, {
|
|
9379
|
-
kind: UpdateServiceKind.Create,
|
|
9380
|
-
account: serviceInfo,
|
|
9381
|
-
lookupHistory,
|
|
9382
|
-
});
|
|
9383
|
-
}
|
|
9384
|
-
}
|
|
9385
|
-
/** Update service storage kind. */
|
|
9386
|
-
var UpdateStorageKind;
|
|
9387
|
-
(function (UpdateStorageKind) {
|
|
9388
|
-
/** Set a storage value. */
|
|
9389
|
-
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
9390
|
-
/** Remove a storage value. */
|
|
9391
|
-
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
9392
|
-
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
9393
|
-
/**
|
|
9394
|
-
* Update service storage item.
|
|
9395
|
-
*
|
|
9396
|
-
* Can either create/modify an entry or remove it.
|
|
9397
|
-
*/
|
|
9398
|
-
class UpdateStorage {
|
|
9399
|
-
serviceId;
|
|
9400
|
-
action;
|
|
9401
|
-
constructor(serviceId, action) {
|
|
9402
|
-
this.serviceId = serviceId;
|
|
9403
|
-
this.action = action;
|
|
9404
|
-
}
|
|
9405
|
-
static set({ serviceId, storage }) {
|
|
9406
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
9407
|
-
}
|
|
9408
|
-
static remove({ serviceId, key }) {
|
|
9409
|
-
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
9410
|
-
}
|
|
9411
|
-
get key() {
|
|
9412
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9413
|
-
return this.action.key;
|
|
9414
|
-
}
|
|
9415
|
-
return this.action.storage.key;
|
|
9416
|
-
}
|
|
9417
|
-
get value() {
|
|
9418
|
-
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9419
|
-
return null;
|
|
9420
|
-
}
|
|
9421
|
-
return this.action.storage.value;
|
|
9422
|
-
}
|
|
9423
|
-
}
|
|
9424
|
-
|
|
9425
|
-
const codecServiceId = Compatibility.isSuite(TestSuite.W3F_DAVXY) || Compatibility.isSuite(TestSuite.JAMDUNA, GpVersion.V0_6_7)
|
|
9426
|
-
? codec$1.u32.asOpaque()
|
|
9427
|
-
: codec$1.varU32.convert((s) => tryAsU32(s), (i) => tryAsServiceId(i));
|
|
9428
|
-
/**
|
|
9429
|
-
* Activity Record of a single validator.
|
|
9430
|
-
*
|
|
9431
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/183701183701
|
|
9432
|
-
*/
|
|
9433
|
-
class ValidatorStatistics {
|
|
9434
|
-
blocks;
|
|
9435
|
-
tickets;
|
|
9436
|
-
preImages;
|
|
9437
|
-
preImagesSize;
|
|
9438
|
-
guarantees;
|
|
9439
|
-
assurances;
|
|
9440
|
-
static Codec = codec$1.Class(ValidatorStatistics, {
|
|
9441
|
-
blocks: codec$1.u32,
|
|
9442
|
-
tickets: codec$1.u32,
|
|
9443
|
-
preImages: codec$1.u32,
|
|
9444
|
-
preImagesSize: codec$1.u32,
|
|
9445
|
-
guarantees: codec$1.u32,
|
|
9446
|
-
assurances: codec$1.u32,
|
|
9447
|
-
});
|
|
9448
|
-
static create({ blocks, tickets, preImages, preImagesSize, guarantees, assurances, }) {
|
|
9449
|
-
return new ValidatorStatistics(blocks, tickets, preImages, preImagesSize, guarantees, assurances);
|
|
9450
|
-
}
|
|
9451
|
-
constructor(
|
|
9452
|
-
/** The number of blocks produced by the validator. */
|
|
9453
|
-
blocks,
|
|
9454
|
-
/** The number of tickets introduced by the validator. */
|
|
9455
|
-
tickets,
|
|
9456
|
-
/** The number of preimages introduced by the validator. */
|
|
9457
|
-
preImages,
|
|
9458
|
-
/** The total number of octets across all preimages introduced by the validator. */
|
|
9459
|
-
preImagesSize,
|
|
9460
|
-
/** The number of reports guaranteed by the validator. */
|
|
9461
|
-
guarantees,
|
|
9462
|
-
/** The number of availability assurances made by the validator. */
|
|
9463
|
-
assurances) {
|
|
9464
|
-
this.blocks = blocks;
|
|
9465
|
-
this.tickets = tickets;
|
|
9466
|
-
this.preImages = preImages;
|
|
9467
|
-
this.preImagesSize = preImagesSize;
|
|
9468
|
-
this.guarantees = guarantees;
|
|
9469
|
-
this.assurances = assurances;
|
|
9470
|
-
}
|
|
9471
|
-
static empty() {
|
|
9472
|
-
const zero = tryAsU32(0);
|
|
9473
|
-
return new ValidatorStatistics(zero, zero, zero, zero, zero, zero);
|
|
9474
|
-
}
|
|
9475
|
-
}
|
|
9476
|
-
const codecVarU16 = codec$1.varU32.convert((i) => tryAsU32(i), (o) => tryAsU16(o));
|
|
9477
|
-
/** Encode/decode unsigned gas. */
|
|
9478
|
-
const codecVarGas = codec$1.varU64.convert((g) => tryAsU64(g), (i) => tryAsServiceGas(i));
|
|
9479
|
-
/**
|
|
9480
|
-
* Single core statistics.
|
|
9481
|
-
* Updated per block, based on incoming work reports (`w`).
|
|
9482
|
-
*
|
|
9483
|
-
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
9484
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
8693
|
+
* Single core statistics.
|
|
8694
|
+
* Updated per block, based on incoming work reports (`w`).
|
|
8695
|
+
*
|
|
8696
|
+
* https://graypaper.fluffylabs.dev/#/68eaa1f/18f10318f103?v=0.6.4
|
|
8697
|
+
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L65
|
|
9485
8698
|
*/
|
|
9486
8699
|
class CoreStatistics {
|
|
9487
8700
|
dataAvailabilityLoad;
|
|
@@ -9553,8 +8766,7 @@ class CoreStatistics {
|
|
|
9553
8766
|
* Service statistics.
|
|
9554
8767
|
* Updated per block, based on available work reports (`W`).
|
|
9555
8768
|
*
|
|
9556
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9557
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L77
|
|
8769
|
+
* https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
|
|
9558
8770
|
*/
|
|
9559
8771
|
class ServiceStatistics {
|
|
9560
8772
|
providedCount;
|
|
@@ -9569,22 +8781,8 @@ class ServiceStatistics {
|
|
|
9569
8781
|
accumulateGasUsed;
|
|
9570
8782
|
onTransfersCount;
|
|
9571
8783
|
onTransfersGasUsed;
|
|
9572
|
-
static Codec = Compatibility.
|
|
9573
|
-
|
|
9574
|
-
providedCount: codecVarU16,
|
|
9575
|
-
providedSize: codec$1.varU32,
|
|
9576
|
-
refinementCount: codec$1.varU32,
|
|
9577
|
-
refinementGasUsed: codecVarGas,
|
|
9578
|
-
imports: codecVarU16,
|
|
9579
|
-
extrinsicCount: codecVarU16,
|
|
9580
|
-
extrinsicSize: codec$1.varU32,
|
|
9581
|
-
exports: codecVarU16,
|
|
9582
|
-
accumulateCount: codec$1.varU32,
|
|
9583
|
-
accumulateGasUsed: codecVarGas,
|
|
9584
|
-
onTransfersCount: codec$1.varU32,
|
|
9585
|
-
onTransfersGasUsed: codecVarGas,
|
|
9586
|
-
})
|
|
9587
|
-
: codec$1.Class(ServiceStatistics, {
|
|
8784
|
+
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
8785
|
+
fallback: codec$1.Class(ServiceStatistics, {
|
|
9588
8786
|
providedCount: codecVarU16,
|
|
9589
8787
|
providedSize: codec$1.varU32,
|
|
9590
8788
|
refinementCount: codec$1.varU32,
|
|
@@ -9597,77 +8795,391 @@ class ServiceStatistics {
|
|
|
9597
8795
|
accumulateGasUsed: codecVarGas,
|
|
9598
8796
|
onTransfersCount: codec$1.varU32,
|
|
9599
8797
|
onTransfersGasUsed: codecVarGas,
|
|
9600
|
-
})
|
|
8798
|
+
}),
|
|
8799
|
+
versions: {
|
|
8800
|
+
[GpVersion.V0_7_0]: codec$1.Class(ServiceStatistics, {
|
|
8801
|
+
providedCount: codecVarU16,
|
|
8802
|
+
providedSize: codec$1.varU32,
|
|
8803
|
+
refinementCount: codec$1.varU32,
|
|
8804
|
+
refinementGasUsed: codecVarGas,
|
|
8805
|
+
imports: codecVarU16,
|
|
8806
|
+
extrinsicCount: codecVarU16,
|
|
8807
|
+
extrinsicSize: codec$1.varU32,
|
|
8808
|
+
exports: codecVarU16,
|
|
8809
|
+
accumulateCount: codec$1.varU32,
|
|
8810
|
+
accumulateGasUsed: codecVarGas,
|
|
8811
|
+
onTransfersCount: codec$1.varU32,
|
|
8812
|
+
onTransfersGasUsed: codecVarGas,
|
|
8813
|
+
}),
|
|
8814
|
+
[GpVersion.V0_7_1]: codec$1.Class(ServiceStatistics, {
|
|
8815
|
+
providedCount: codecVarU16,
|
|
8816
|
+
providedSize: codec$1.varU32,
|
|
8817
|
+
refinementCount: codec$1.varU32,
|
|
8818
|
+
refinementGasUsed: codecVarGas,
|
|
8819
|
+
imports: codecVarU16,
|
|
8820
|
+
extrinsicCount: codecVarU16,
|
|
8821
|
+
extrinsicSize: codec$1.varU32,
|
|
8822
|
+
exports: codecVarU16,
|
|
8823
|
+
accumulateCount: codec$1.varU32,
|
|
8824
|
+
accumulateGasUsed: codecVarGas,
|
|
8825
|
+
onTransfersCount: ignoreValueWithDefault(tryAsU32(0)),
|
|
8826
|
+
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
8827
|
+
}),
|
|
8828
|
+
},
|
|
8829
|
+
});
|
|
9601
8830
|
static create(v) {
|
|
9602
8831
|
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);
|
|
9603
8832
|
}
|
|
9604
|
-
constructor(
|
|
9605
|
-
/** `p.0` */
|
|
9606
|
-
providedCount,
|
|
9607
|
-
/** `p.1` */
|
|
9608
|
-
providedSize,
|
|
9609
|
-
/** `r.0` */
|
|
9610
|
-
refinementCount,
|
|
9611
|
-
/** `r.1` */
|
|
9612
|
-
refinementGasUsed,
|
|
9613
|
-
/** `i` */
|
|
9614
|
-
imports,
|
|
9615
|
-
/** `e` */
|
|
9616
|
-
exports,
|
|
9617
|
-
/** `z` */
|
|
9618
|
-
extrinsicSize,
|
|
9619
|
-
/** `x` */
|
|
9620
|
-
extrinsicCount,
|
|
9621
|
-
/** `a.0` */
|
|
9622
|
-
accumulateCount,
|
|
9623
|
-
/** `a.1` */
|
|
9624
|
-
accumulateGasUsed,
|
|
9625
|
-
/** `t.0` */
|
|
9626
|
-
onTransfersCount,
|
|
9627
|
-
/** `t.1` */
|
|
9628
|
-
onTransfersGasUsed) {
|
|
9629
|
-
this.providedCount = providedCount;
|
|
9630
|
-
this.providedSize = providedSize;
|
|
9631
|
-
this.refinementCount = refinementCount;
|
|
9632
|
-
this.refinementGasUsed = refinementGasUsed;
|
|
9633
|
-
this.imports = imports;
|
|
9634
|
-
this.exports = exports;
|
|
9635
|
-
this.extrinsicSize = extrinsicSize;
|
|
9636
|
-
this.extrinsicCount = extrinsicCount;
|
|
9637
|
-
this.accumulateCount = accumulateCount;
|
|
9638
|
-
this.accumulateGasUsed = accumulateGasUsed;
|
|
9639
|
-
this.onTransfersCount = onTransfersCount;
|
|
9640
|
-
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
8833
|
+
constructor(
|
|
8834
|
+
/** `p.0` */
|
|
8835
|
+
providedCount,
|
|
8836
|
+
/** `p.1` */
|
|
8837
|
+
providedSize,
|
|
8838
|
+
/** `r.0` */
|
|
8839
|
+
refinementCount,
|
|
8840
|
+
/** `r.1` */
|
|
8841
|
+
refinementGasUsed,
|
|
8842
|
+
/** `i` */
|
|
8843
|
+
imports,
|
|
8844
|
+
/** `e` */
|
|
8845
|
+
exports,
|
|
8846
|
+
/** `z` */
|
|
8847
|
+
extrinsicSize,
|
|
8848
|
+
/** `x` */
|
|
8849
|
+
extrinsicCount,
|
|
8850
|
+
/** `a.0` */
|
|
8851
|
+
accumulateCount,
|
|
8852
|
+
/** `a.1` */
|
|
8853
|
+
accumulateGasUsed,
|
|
8854
|
+
/** `t.0` @deprecated since 0.7.1 */
|
|
8855
|
+
onTransfersCount,
|
|
8856
|
+
/** `t.1` @deprecated since 0.7.1 */
|
|
8857
|
+
onTransfersGasUsed) {
|
|
8858
|
+
this.providedCount = providedCount;
|
|
8859
|
+
this.providedSize = providedSize;
|
|
8860
|
+
this.refinementCount = refinementCount;
|
|
8861
|
+
this.refinementGasUsed = refinementGasUsed;
|
|
8862
|
+
this.imports = imports;
|
|
8863
|
+
this.exports = exports;
|
|
8864
|
+
this.extrinsicSize = extrinsicSize;
|
|
8865
|
+
this.extrinsicCount = extrinsicCount;
|
|
8866
|
+
this.accumulateCount = accumulateCount;
|
|
8867
|
+
this.accumulateGasUsed = accumulateGasUsed;
|
|
8868
|
+
this.onTransfersCount = onTransfersCount;
|
|
8869
|
+
this.onTransfersGasUsed = onTransfersGasUsed;
|
|
8870
|
+
}
|
|
8871
|
+
static empty() {
|
|
8872
|
+
const zero = tryAsU32(0);
|
|
8873
|
+
const zero16 = tryAsU16(0);
|
|
8874
|
+
const zeroGas = tryAsServiceGas(0);
|
|
8875
|
+
return new ServiceStatistics(zero16, zero, zero, zeroGas, zero16, zero16, zero, zero16, zero, zeroGas, zero, zeroGas);
|
|
8876
|
+
}
|
|
8877
|
+
}
|
|
8878
|
+
/** `pi`: Statistics of each validator, cores statistics and services statistics. */
|
|
8879
|
+
class StatisticsData {
|
|
8880
|
+
current;
|
|
8881
|
+
previous;
|
|
8882
|
+
cores;
|
|
8883
|
+
services;
|
|
8884
|
+
static Codec = codec$1.Class(StatisticsData, {
|
|
8885
|
+
current: codecPerValidator(ValidatorStatistics.Codec),
|
|
8886
|
+
previous: codecPerValidator(ValidatorStatistics.Codec),
|
|
8887
|
+
cores: codecPerCore(CoreStatistics.Codec),
|
|
8888
|
+
services: codec$1.dictionary(codecServiceId, ServiceStatistics.Codec, {
|
|
8889
|
+
sortKeys: (a, b) => a - b,
|
|
8890
|
+
}),
|
|
8891
|
+
});
|
|
8892
|
+
static create(v) {
|
|
8893
|
+
return new StatisticsData(v.current, v.previous, v.cores, v.services);
|
|
8894
|
+
}
|
|
8895
|
+
constructor(current, previous, cores, services) {
|
|
8896
|
+
this.current = current;
|
|
8897
|
+
this.previous = previous;
|
|
8898
|
+
this.cores = cores;
|
|
8899
|
+
this.services = services;
|
|
8900
|
+
}
|
|
8901
|
+
}
|
|
8902
|
+
|
|
8903
|
+
class InMemoryStateView {
|
|
8904
|
+
chainSpec;
|
|
8905
|
+
state;
|
|
8906
|
+
constructor(chainSpec, state) {
|
|
8907
|
+
this.chainSpec = chainSpec;
|
|
8908
|
+
this.state = state;
|
|
8909
|
+
}
|
|
8910
|
+
availabilityAssignmentView() {
|
|
8911
|
+
return reencodeAsView(availabilityAssignmentsCodec, this.state.availabilityAssignment, this.chainSpec);
|
|
8912
|
+
}
|
|
8913
|
+
designatedValidatorDataView() {
|
|
8914
|
+
return reencodeAsView(validatorsDataCodec, this.state.designatedValidatorData, this.chainSpec);
|
|
8915
|
+
}
|
|
8916
|
+
currentValidatorDataView() {
|
|
8917
|
+
return reencodeAsView(validatorsDataCodec, this.state.currentValidatorData, this.chainSpec);
|
|
8918
|
+
}
|
|
8919
|
+
previousValidatorDataView() {
|
|
8920
|
+
return reencodeAsView(validatorsDataCodec, this.state.previousValidatorData, this.chainSpec);
|
|
8921
|
+
}
|
|
8922
|
+
authPoolsView() {
|
|
8923
|
+
return reencodeAsView(authPoolsCodec, this.state.authPools, this.chainSpec);
|
|
8924
|
+
}
|
|
8925
|
+
authQueuesView() {
|
|
8926
|
+
return reencodeAsView(authQueuesCodec, this.state.authQueues, this.chainSpec);
|
|
8927
|
+
}
|
|
8928
|
+
recentBlocksView() {
|
|
8929
|
+
return reencodeAsView(RecentBlocks.Codec, this.state.recentBlocks, this.chainSpec);
|
|
8930
|
+
}
|
|
8931
|
+
statisticsView() {
|
|
8932
|
+
return reencodeAsView(StatisticsData.Codec, this.state.statistics, this.chainSpec);
|
|
8933
|
+
}
|
|
8934
|
+
accumulationQueueView() {
|
|
8935
|
+
return reencodeAsView(accumulationQueueCodec, this.state.accumulationQueue, this.chainSpec);
|
|
8936
|
+
}
|
|
8937
|
+
recentlyAccumulatedView() {
|
|
8938
|
+
return reencodeAsView(recentlyAccumulatedCodec, this.state.recentlyAccumulated, this.chainSpec);
|
|
8939
|
+
}
|
|
8940
|
+
safroleDataView() {
|
|
8941
|
+
// TODO [ToDr] Consider exposting `safrole` from state
|
|
8942
|
+
// instead of individual fields
|
|
8943
|
+
const safrole = SafroleData.create({
|
|
8944
|
+
nextValidatorData: this.state.nextValidatorData,
|
|
8945
|
+
epochRoot: this.state.epochRoot,
|
|
8946
|
+
sealingKeySeries: this.state.sealingKeySeries,
|
|
8947
|
+
ticketsAccumulator: this.state.ticketsAccumulator,
|
|
8948
|
+
});
|
|
8949
|
+
return reencodeAsView(SafroleData.Codec, safrole, this.chainSpec);
|
|
8950
|
+
}
|
|
8951
|
+
getServiceInfoView(id) {
|
|
8952
|
+
const service = this.state.getService(id);
|
|
8953
|
+
if (service === null) {
|
|
8954
|
+
return null;
|
|
8955
|
+
}
|
|
8956
|
+
return reencodeAsView(ServiceAccountInfo.Codec, service.getInfo(), this.chainSpec);
|
|
8957
|
+
}
|
|
8958
|
+
}
|
|
8959
|
+
|
|
8960
|
+
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8961
|
+
class AutoAccumulate {
|
|
8962
|
+
service;
|
|
8963
|
+
gasLimit;
|
|
8964
|
+
static Codec = codec$1.Class(AutoAccumulate, {
|
|
8965
|
+
service: codec$1.u32.asOpaque(),
|
|
8966
|
+
gasLimit: codec$1.u64.asOpaque(),
|
|
8967
|
+
});
|
|
8968
|
+
static create({ service, gasLimit }) {
|
|
8969
|
+
return new AutoAccumulate(service, gasLimit);
|
|
8970
|
+
}
|
|
8971
|
+
constructor(
|
|
8972
|
+
/** Service id that auto-accumulates. */
|
|
8973
|
+
service,
|
|
8974
|
+
/** Gas limit for auto-accumulation. */
|
|
8975
|
+
gasLimit) {
|
|
8976
|
+
this.service = service;
|
|
8977
|
+
this.gasLimit = gasLimit;
|
|
8978
|
+
}
|
|
8979
|
+
}
|
|
8980
|
+
/**
|
|
8981
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8982
|
+
*/
|
|
8983
|
+
class PrivilegedServices {
|
|
8984
|
+
manager;
|
|
8985
|
+
delegator;
|
|
8986
|
+
registrar;
|
|
8987
|
+
assigners;
|
|
8988
|
+
autoAccumulateServices;
|
|
8989
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
8990
|
+
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8991
|
+
manager: codec$1.u32.asOpaque(),
|
|
8992
|
+
assigners: codecPerCore(codec$1.u32.asOpaque()),
|
|
8993
|
+
delegator: codec$1.u32.asOpaque(),
|
|
8994
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
8995
|
+
? codec$1.u32.asOpaque()
|
|
8996
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
8997
|
+
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8998
|
+
});
|
|
8999
|
+
static create(a) {
|
|
9000
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
9001
|
+
}
|
|
9002
|
+
constructor(
|
|
9003
|
+
/**
|
|
9004
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
9005
|
+
* as well as bestow services with storage deposit credits.
|
|
9006
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
9007
|
+
*/
|
|
9008
|
+
manager,
|
|
9009
|
+
/** `χ_V`: Managers validator keys. */
|
|
9010
|
+
delegator,
|
|
9011
|
+
/**
|
|
9012
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
9013
|
+
*
|
|
9014
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
9015
|
+
*/
|
|
9016
|
+
registrar,
|
|
9017
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
9018
|
+
assigners,
|
|
9019
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
9020
|
+
autoAccumulateServices) {
|
|
9021
|
+
this.manager = manager;
|
|
9022
|
+
this.delegator = delegator;
|
|
9023
|
+
this.registrar = registrar;
|
|
9024
|
+
this.assigners = assigners;
|
|
9025
|
+
this.autoAccumulateServices = autoAccumulateServices;
|
|
9026
|
+
}
|
|
9027
|
+
}
|
|
9028
|
+
|
|
9029
|
+
/**
|
|
9030
|
+
* In addition to the entropy accumulator η_0, we retain
|
|
9031
|
+
* three additional historical values of the accumulator at
|
|
9032
|
+
* the point of each of the three most recently ended epochs,
|
|
9033
|
+
* η_1, η_2 and η_3. The second-oldest of these η2 is utilized to
|
|
9034
|
+
* help ensure future entropy is unbiased (see equation 6.29)
|
|
9035
|
+
* and seed the fallback seal-key generation function with
|
|
9036
|
+
* randomness (see equation 6.24). The oldest is used to re-
|
|
9037
|
+
* generate this randomness when verifying the seal above
|
|
9038
|
+
* (see equations 6.16 and 6.15).
|
|
9039
|
+
*
|
|
9040
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/0ef5010ef501
|
|
9041
|
+
*/
|
|
9042
|
+
const ENTROPY_ENTRIES = 4;
|
|
9043
|
+
|
|
9044
|
+
var UpdatePreimageKind;
|
|
9045
|
+
(function (UpdatePreimageKind) {
|
|
9046
|
+
/** Insert new preimage and optionally update it's lookup history. */
|
|
9047
|
+
UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
|
|
9048
|
+
/** Remove a preimage and it's lookup history. */
|
|
9049
|
+
UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
|
|
9050
|
+
/** update or add lookup history for preimage hash/len to given value. */
|
|
9051
|
+
UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
|
|
9052
|
+
})(UpdatePreimageKind || (UpdatePreimageKind = {}));
|
|
9053
|
+
/**
|
|
9054
|
+
* A preimage update.
|
|
9055
|
+
*
|
|
9056
|
+
* Can be one of the following cases:
|
|
9057
|
+
* 1. Provide a new preimage blob and set the lookup history to available at `slot`.
|
|
9058
|
+
* 2. Remove (expunge) a preimage and it's lookup history.
|
|
9059
|
+
* 3. Update `LookupHistory` with given value.
|
|
9060
|
+
*/
|
|
9061
|
+
class UpdatePreimage {
|
|
9062
|
+
serviceId;
|
|
9063
|
+
action;
|
|
9064
|
+
constructor(serviceId, action) {
|
|
9065
|
+
this.serviceId = serviceId;
|
|
9066
|
+
this.action = action;
|
|
9067
|
+
}
|
|
9068
|
+
/** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
|
|
9069
|
+
static provide({ serviceId, preimage, slot, }) {
|
|
9070
|
+
return new UpdatePreimage(serviceId, {
|
|
9071
|
+
kind: UpdatePreimageKind.Provide,
|
|
9072
|
+
preimage,
|
|
9073
|
+
slot,
|
|
9074
|
+
});
|
|
9075
|
+
}
|
|
9076
|
+
/** The preimage should be removed completely from the database. */
|
|
9077
|
+
static remove({ serviceId, hash, length }) {
|
|
9078
|
+
return new UpdatePreimage(serviceId, {
|
|
9079
|
+
kind: UpdatePreimageKind.Remove,
|
|
9080
|
+
hash,
|
|
9081
|
+
length,
|
|
9082
|
+
});
|
|
9083
|
+
}
|
|
9084
|
+
/** Update the lookup history of some preimage or add a new one (request). */
|
|
9085
|
+
static updateOrAdd({ serviceId, lookupHistory }) {
|
|
9086
|
+
return new UpdatePreimage(serviceId, {
|
|
9087
|
+
kind: UpdatePreimageKind.UpdateOrAdd,
|
|
9088
|
+
item: lookupHistory,
|
|
9089
|
+
});
|
|
9090
|
+
}
|
|
9091
|
+
get hash() {
|
|
9092
|
+
switch (this.action.kind) {
|
|
9093
|
+
case UpdatePreimageKind.Provide:
|
|
9094
|
+
return this.action.preimage.hash;
|
|
9095
|
+
case UpdatePreimageKind.Remove:
|
|
9096
|
+
return this.action.hash;
|
|
9097
|
+
case UpdatePreimageKind.UpdateOrAdd:
|
|
9098
|
+
return this.action.item.hash;
|
|
9099
|
+
}
|
|
9100
|
+
throw assertNever(this.action);
|
|
9101
|
+
}
|
|
9102
|
+
get length() {
|
|
9103
|
+
switch (this.action.kind) {
|
|
9104
|
+
case UpdatePreimageKind.Provide:
|
|
9105
|
+
return tryAsU32(this.action.preimage.blob.length);
|
|
9106
|
+
case UpdatePreimageKind.Remove:
|
|
9107
|
+
return this.action.length;
|
|
9108
|
+
case UpdatePreimageKind.UpdateOrAdd:
|
|
9109
|
+
return this.action.item.length;
|
|
9110
|
+
}
|
|
9111
|
+
throw assertNever(this.action);
|
|
9112
|
+
}
|
|
9113
|
+
}
|
|
9114
|
+
/** The type of service update. */
|
|
9115
|
+
var UpdateServiceKind;
|
|
9116
|
+
(function (UpdateServiceKind) {
|
|
9117
|
+
/** Just update the `ServiceAccountInfo`. */
|
|
9118
|
+
UpdateServiceKind[UpdateServiceKind["Update"] = 0] = "Update";
|
|
9119
|
+
/** Create a new `Service` instance. */
|
|
9120
|
+
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
9121
|
+
})(UpdateServiceKind || (UpdateServiceKind = {}));
|
|
9122
|
+
/**
|
|
9123
|
+
* Update service info of a particular `ServiceId` or create a new one.
|
|
9124
|
+
*/
|
|
9125
|
+
class UpdateService {
|
|
9126
|
+
serviceId;
|
|
9127
|
+
action;
|
|
9128
|
+
constructor(serviceId, action) {
|
|
9129
|
+
this.serviceId = serviceId;
|
|
9130
|
+
this.action = action;
|
|
9131
|
+
}
|
|
9132
|
+
static update({ serviceId, serviceInfo }) {
|
|
9133
|
+
return new UpdateService(serviceId, {
|
|
9134
|
+
kind: UpdateServiceKind.Update,
|
|
9135
|
+
account: serviceInfo,
|
|
9136
|
+
});
|
|
9641
9137
|
}
|
|
9642
|
-
static
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9138
|
+
static create({ serviceId, serviceInfo, lookupHistory, }) {
|
|
9139
|
+
return new UpdateService(serviceId, {
|
|
9140
|
+
kind: UpdateServiceKind.Create,
|
|
9141
|
+
account: serviceInfo,
|
|
9142
|
+
lookupHistory,
|
|
9143
|
+
});
|
|
9647
9144
|
}
|
|
9648
9145
|
}
|
|
9649
|
-
/**
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9146
|
+
/** Update service storage kind. */
|
|
9147
|
+
var UpdateStorageKind;
|
|
9148
|
+
(function (UpdateStorageKind) {
|
|
9149
|
+
/** Set a storage value. */
|
|
9150
|
+
UpdateStorageKind[UpdateStorageKind["Set"] = 0] = "Set";
|
|
9151
|
+
/** Remove a storage value. */
|
|
9152
|
+
UpdateStorageKind[UpdateStorageKind["Remove"] = 1] = "Remove";
|
|
9153
|
+
})(UpdateStorageKind || (UpdateStorageKind = {}));
|
|
9154
|
+
/**
|
|
9155
|
+
* Update service storage item.
|
|
9156
|
+
*
|
|
9157
|
+
* Can either create/modify an entry or remove it.
|
|
9158
|
+
*/
|
|
9159
|
+
class UpdateStorage {
|
|
9160
|
+
serviceId;
|
|
9161
|
+
action;
|
|
9162
|
+
constructor(serviceId, action) {
|
|
9163
|
+
this.serviceId = serviceId;
|
|
9164
|
+
this.action = action;
|
|
9665
9165
|
}
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
|
|
9670
|
-
|
|
9166
|
+
static set({ serviceId, storage }) {
|
|
9167
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Set, storage });
|
|
9168
|
+
}
|
|
9169
|
+
static remove({ serviceId, key }) {
|
|
9170
|
+
return new UpdateStorage(serviceId, { kind: UpdateStorageKind.Remove, key });
|
|
9171
|
+
}
|
|
9172
|
+
get key() {
|
|
9173
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9174
|
+
return this.action.key;
|
|
9175
|
+
}
|
|
9176
|
+
return this.action.storage.key;
|
|
9177
|
+
}
|
|
9178
|
+
get value() {
|
|
9179
|
+
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
9180
|
+
return null;
|
|
9181
|
+
}
|
|
9182
|
+
return this.action.storage.value;
|
|
9671
9183
|
}
|
|
9672
9184
|
}
|
|
9673
9185
|
|
|
@@ -9770,9 +9282,10 @@ class InMemoryService extends WithDebug {
|
|
|
9770
9282
|
* A special version of state, stored fully in-memory.
|
|
9771
9283
|
*/
|
|
9772
9284
|
class InMemoryState extends WithDebug {
|
|
9285
|
+
chainSpec;
|
|
9773
9286
|
/** Create a new `InMemoryState` by providing all required fields. */
|
|
9774
|
-
static
|
|
9775
|
-
return new InMemoryState(state);
|
|
9287
|
+
static new(chainSpec, state) {
|
|
9288
|
+
return new InMemoryState(chainSpec, state);
|
|
9776
9289
|
}
|
|
9777
9290
|
/**
|
|
9778
9291
|
* Create a new `InMemoryState` with a partial state override.
|
|
@@ -9788,7 +9301,7 @@ class InMemoryState extends WithDebug {
|
|
|
9788
9301
|
/**
|
|
9789
9302
|
* Create a new `InMemoryState` from some other state object.
|
|
9790
9303
|
*/
|
|
9791
|
-
static copyFrom(other, servicesData) {
|
|
9304
|
+
static copyFrom(chainSpec, other, servicesData) {
|
|
9792
9305
|
const services = new Map();
|
|
9793
9306
|
for (const [id, entries] of servicesData.entries()) {
|
|
9794
9307
|
const service = other.getService(id);
|
|
@@ -9798,7 +9311,7 @@ class InMemoryState extends WithDebug {
|
|
|
9798
9311
|
const inMemService = InMemoryService.copyFrom(service, entries);
|
|
9799
9312
|
services.set(id, inMemService);
|
|
9800
9313
|
}
|
|
9801
|
-
return InMemoryState.
|
|
9314
|
+
return InMemoryState.new(chainSpec, {
|
|
9802
9315
|
availabilityAssignment: other.availabilityAssignment,
|
|
9803
9316
|
accumulationQueue: other.accumulationQueue,
|
|
9804
9317
|
designatedValidatorData: other.designatedValidatorData,
|
|
@@ -9995,8 +9508,9 @@ class InMemoryState extends WithDebug {
|
|
|
9995
9508
|
getService(id) {
|
|
9996
9509
|
return this.services.get(id) ?? null;
|
|
9997
9510
|
}
|
|
9998
|
-
constructor(s) {
|
|
9511
|
+
constructor(chainSpec, s) {
|
|
9999
9512
|
super();
|
|
9513
|
+
this.chainSpec = chainSpec;
|
|
10000
9514
|
this.availabilityAssignment = s.availabilityAssignment;
|
|
10001
9515
|
this.designatedValidatorData = s.designatedValidatorData;
|
|
10002
9516
|
this.nextValidatorData = s.nextValidatorData;
|
|
@@ -10018,11 +9532,14 @@ class InMemoryState extends WithDebug {
|
|
|
10018
9532
|
this.accumulationOutputLog = s.accumulationOutputLog;
|
|
10019
9533
|
this.services = s.services;
|
|
10020
9534
|
}
|
|
9535
|
+
view() {
|
|
9536
|
+
return new InMemoryStateView(this.chainSpec, this);
|
|
9537
|
+
}
|
|
10021
9538
|
/**
|
|
10022
9539
|
* Create an empty and possibly incoherent `InMemoryState`.
|
|
10023
9540
|
*/
|
|
10024
9541
|
static empty(spec) {
|
|
10025
|
-
return new InMemoryState({
|
|
9542
|
+
return new InMemoryState(spec, {
|
|
10026
9543
|
availabilityAssignment: tryAsPerCore(Array.from({ length: spec.coresCount }, () => null), spec),
|
|
10027
9544
|
designatedValidatorData: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorData.create({
|
|
10028
9545
|
bandersnatch: Bytes.zero(BANDERSNATCH_KEY_BYTES).asOpaque(),
|
|
@@ -10058,7 +9575,7 @@ class InMemoryState extends WithDebug {
|
|
|
10058
9575
|
entropy: FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), ENTROPY_ENTRIES),
|
|
10059
9576
|
authPools: tryAsPerCore(Array.from({ length: spec.coresCount }, () => asKnownSize([])), spec),
|
|
10060
9577
|
authQueues: tryAsPerCore(Array.from({ length: spec.coresCount }, () => FixedSizeArray.fill(() => Bytes.zero(HASH_SIZE).asOpaque(), AUTHORIZATION_QUEUE_SIZE)), spec),
|
|
10061
|
-
recentBlocks:
|
|
9578
|
+
recentBlocks: RecentBlocks.empty(),
|
|
10062
9579
|
statistics: StatisticsData.create({
|
|
10063
9580
|
current: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
10064
9581
|
previous: tryAsPerValidator(Array.from({ length: spec.validatorsCount }, () => ValidatorStatistics.empty()), spec),
|
|
@@ -10072,8 +9589,9 @@ class InMemoryState extends WithDebug {
|
|
|
10072
9589
|
epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10073
9590
|
privilegedServices: PrivilegedServices.create({
|
|
10074
9591
|
manager: tryAsServiceId(0),
|
|
10075
|
-
|
|
10076
|
-
|
|
9592
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
9593
|
+
delegator: tryAsServiceId(0),
|
|
9594
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10077
9595
|
autoAccumulateServices: [],
|
|
10078
9596
|
}),
|
|
10079
9597
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -10095,6 +9613,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10095
9613
|
|
|
10096
9614
|
var index$g = /*#__PURE__*/Object.freeze({
|
|
10097
9615
|
__proto__: null,
|
|
9616
|
+
AUTHORIZATION_QUEUE_SIZE: AUTHORIZATION_QUEUE_SIZE,
|
|
10098
9617
|
AccumulationOutput: AccumulationOutput,
|
|
10099
9618
|
AutoAccumulate: AutoAccumulate,
|
|
10100
9619
|
AvailabilityAssignment: AvailabilityAssignment,
|
|
@@ -10108,11 +9627,12 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
10108
9627
|
InMemoryService: InMemoryService,
|
|
10109
9628
|
InMemoryState: InMemoryState,
|
|
10110
9629
|
LookupHistoryItem: LookupHistoryItem,
|
|
9630
|
+
MAX_AUTH_POOL_SIZE: MAX_AUTH_POOL_SIZE,
|
|
10111
9631
|
MAX_RECENT_HISTORY: MAX_RECENT_HISTORY,
|
|
9632
|
+
NotYetAccumulatedReport: NotYetAccumulatedReport,
|
|
10112
9633
|
PreimageItem: PreimageItem,
|
|
10113
9634
|
PrivilegedServices: PrivilegedServices,
|
|
10114
9635
|
RecentBlocks: RecentBlocks,
|
|
10115
|
-
RecentBlocksHistory: RecentBlocksHistory,
|
|
10116
9636
|
SafroleData: SafroleData,
|
|
10117
9637
|
SafroleSealingKeysData: SafroleSealingKeysData,
|
|
10118
9638
|
get SafroleSealingKeysKind () { return SafroleSealingKeysKind; },
|
|
@@ -10131,70 +9651,35 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
10131
9651
|
ValidatorData: ValidatorData,
|
|
10132
9652
|
ValidatorStatistics: ValidatorStatistics,
|
|
10133
9653
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
9654
|
+
accumulationQueueCodec: accumulationQueueCodec,
|
|
9655
|
+
authPoolsCodec: authPoolsCodec,
|
|
9656
|
+
authQueuesCodec: authQueuesCodec,
|
|
9657
|
+
availabilityAssignmentsCodec: availabilityAssignmentsCodec,
|
|
10134
9658
|
codecPerCore: codecPerCore,
|
|
9659
|
+
codecWithVersion: codecWithVersion,
|
|
10135
9660
|
hashComparator: hashComparator,
|
|
10136
9661
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
9662
|
+
recentlyAccumulatedCodec: recentlyAccumulatedCodec,
|
|
10137
9663
|
serviceDataCodec: serviceDataCodec,
|
|
10138
9664
|
serviceEntriesCodec: serviceEntriesCodec,
|
|
10139
9665
|
tryAsLookupHistorySlots: tryAsLookupHistorySlots,
|
|
10140
|
-
tryAsPerCore: tryAsPerCore
|
|
9666
|
+
tryAsPerCore: tryAsPerCore,
|
|
9667
|
+
validatorsDataCodec: validatorsDataCodec
|
|
10141
9668
|
});
|
|
10142
9669
|
|
|
10143
|
-
/**
|
|
10144
|
-
* Ready (i.e. available and/or audited) but not-yet-accumulated work-reports.
|
|
10145
|
-
*
|
|
10146
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165300165400
|
|
10147
|
-
*/
|
|
10148
|
-
class NotYetAccumulatedReport extends WithDebug {
|
|
10149
|
-
report;
|
|
10150
|
-
dependencies;
|
|
10151
|
-
static Codec = codec$1.Class(NotYetAccumulatedReport, {
|
|
10152
|
-
report: WorkReport.Codec,
|
|
10153
|
-
dependencies: codecKnownSizeArray(codec$1.bytes(HASH_SIZE).asOpaque(), {
|
|
10154
|
-
typicalLength: MAX_REPORT_DEPENDENCIES / 2,
|
|
10155
|
-
maxLength: MAX_REPORT_DEPENDENCIES,
|
|
10156
|
-
minLength: 0,
|
|
10157
|
-
}),
|
|
10158
|
-
});
|
|
10159
|
-
static create({ report, dependencies }) {
|
|
10160
|
-
return new NotYetAccumulatedReport(report, dependencies);
|
|
10161
|
-
}
|
|
10162
|
-
constructor(
|
|
10163
|
-
/**
|
|
10164
|
-
* Each of these were made available at most one epoch ago
|
|
10165
|
-
* but have or had unfulfilled dependencies.
|
|
10166
|
-
*/
|
|
10167
|
-
report,
|
|
10168
|
-
/**
|
|
10169
|
-
* Alongside the work-report itself, we retain its un-accumulated
|
|
10170
|
-
* dependencies, a set of work-package hashes.
|
|
10171
|
-
*
|
|
10172
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/165800165800
|
|
10173
|
-
*/
|
|
10174
|
-
dependencies) {
|
|
10175
|
-
super();
|
|
10176
|
-
this.report = report;
|
|
10177
|
-
this.dependencies = dependencies;
|
|
10178
|
-
}
|
|
10179
|
-
}
|
|
10180
|
-
|
|
10181
9670
|
/** Serialization for particular state entries. */
|
|
10182
9671
|
var serialize;
|
|
10183
9672
|
(function (serialize) {
|
|
10184
9673
|
/** C(1): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b15013b1501?v=0.6.7 */
|
|
10185
9674
|
serialize.authPools = {
|
|
10186
9675
|
key: stateKeys.index(StateKeyIdx.Alpha),
|
|
10187
|
-
Codec:
|
|
10188
|
-
minLength: 0,
|
|
10189
|
-
maxLength: MAX_AUTH_POOL_SIZE,
|
|
10190
|
-
typicalLength: MAX_AUTH_POOL_SIZE,
|
|
10191
|
-
})),
|
|
9676
|
+
Codec: authPoolsCodec,
|
|
10192
9677
|
extract: (s) => s.authPools,
|
|
10193
9678
|
};
|
|
10194
9679
|
/** C(2): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b31013b3101?v=0.6.7 */
|
|
10195
9680
|
serialize.authQueues = {
|
|
10196
9681
|
key: stateKeys.index(StateKeyIdx.Phi),
|
|
10197
|
-
Codec:
|
|
9682
|
+
Codec: authQueuesCodec,
|
|
10198
9683
|
extract: (s) => s.authQueues,
|
|
10199
9684
|
};
|
|
10200
9685
|
/**
|
|
@@ -10203,7 +9688,7 @@ var serialize;
|
|
|
10203
9688
|
*/
|
|
10204
9689
|
serialize.recentBlocks = {
|
|
10205
9690
|
key: stateKeys.index(StateKeyIdx.Beta),
|
|
10206
|
-
Codec:
|
|
9691
|
+
Codec: RecentBlocks.Codec,
|
|
10207
9692
|
extract: (s) => s.recentBlocks,
|
|
10208
9693
|
};
|
|
10209
9694
|
/** C(4): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b63013b6301?v=0.6.7 */
|
|
@@ -10232,25 +9717,25 @@ var serialize;
|
|
|
10232
9717
|
/** C(7): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b00023b0002?v=0.6.7 */
|
|
10233
9718
|
serialize.designatedValidators = {
|
|
10234
9719
|
key: stateKeys.index(StateKeyIdx.Iota),
|
|
10235
|
-
Codec:
|
|
9720
|
+
Codec: validatorsDataCodec,
|
|
10236
9721
|
extract: (s) => s.designatedValidatorData,
|
|
10237
9722
|
};
|
|
10238
9723
|
/** C(8): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b0d023b0d02?v=0.6.7 */
|
|
10239
9724
|
serialize.currentValidators = {
|
|
10240
9725
|
key: stateKeys.index(StateKeyIdx.Kappa),
|
|
10241
|
-
Codec:
|
|
9726
|
+
Codec: validatorsDataCodec,
|
|
10242
9727
|
extract: (s) => s.currentValidatorData,
|
|
10243
9728
|
};
|
|
10244
9729
|
/** C(9): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b1a023b1a02?v=0.6.7 */
|
|
10245
9730
|
serialize.previousValidators = {
|
|
10246
9731
|
key: stateKeys.index(StateKeyIdx.Lambda),
|
|
10247
|
-
Codec:
|
|
9732
|
+
Codec: validatorsDataCodec,
|
|
10248
9733
|
extract: (s) => s.previousValidatorData,
|
|
10249
9734
|
};
|
|
10250
9735
|
/** C(10): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b27023b2702?v=0.6.7 */
|
|
10251
9736
|
serialize.availabilityAssignment = {
|
|
10252
9737
|
key: stateKeys.index(StateKeyIdx.Rho),
|
|
10253
|
-
Codec:
|
|
9738
|
+
Codec: availabilityAssignmentsCodec,
|
|
10254
9739
|
extract: (s) => s.availabilityAssignment,
|
|
10255
9740
|
};
|
|
10256
9741
|
/** C(11): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b3e023b3e02?v=0.6.7 */
|
|
@@ -10274,13 +9759,13 @@ var serialize;
|
|
|
10274
9759
|
/** C(14): https://graypaper.fluffylabs.dev/#/1c979cb/3bf0023bf002?v=0.7.1 */
|
|
10275
9760
|
serialize.accumulationQueue = {
|
|
10276
9761
|
key: stateKeys.index(StateKeyIdx.Omega),
|
|
10277
|
-
Codec:
|
|
9762
|
+
Codec: accumulationQueueCodec,
|
|
10278
9763
|
extract: (s) => s.accumulationQueue,
|
|
10279
9764
|
};
|
|
10280
9765
|
/** C(15): https://graypaper.fluffylabs.dev/#/7e6ff6a/3b96023b9602?v=0.6.7 */
|
|
10281
9766
|
serialize.recentlyAccumulated = {
|
|
10282
9767
|
key: stateKeys.index(StateKeyIdx.Xi),
|
|
10283
|
-
Codec:
|
|
9768
|
+
Codec: recentlyAccumulatedCodec,
|
|
10284
9769
|
extract: (s) => s.recentlyAccumulated,
|
|
10285
9770
|
};
|
|
10286
9771
|
/** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
|
|
@@ -10292,21 +9777,23 @@ var serialize;
|
|
|
10292
9777
|
/** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
|
|
10293
9778
|
serialize.serviceData = (serviceId) => ({
|
|
10294
9779
|
key: stateKeys.serviceInfo(serviceId),
|
|
10295
|
-
Codec:
|
|
9780
|
+
Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9781
|
+
? codecWithVersion(ServiceAccountInfo.Codec)
|
|
9782
|
+
: ServiceAccountInfo.Codec,
|
|
10296
9783
|
});
|
|
10297
9784
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
10298
|
-
serialize.serviceStorage = (serviceId, key) => ({
|
|
10299
|
-
key: stateKeys.serviceStorage(serviceId, key),
|
|
9785
|
+
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
9786
|
+
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
10300
9787
|
Codec: dumpCodec,
|
|
10301
9788
|
});
|
|
10302
9789
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
10303
|
-
serialize.servicePreimages = (serviceId, hash) => ({
|
|
10304
|
-
key: stateKeys.servicePreimage(serviceId, hash),
|
|
9790
|
+
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
9791
|
+
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
10305
9792
|
Codec: dumpCodec,
|
|
10306
9793
|
});
|
|
10307
9794
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10308
|
-
serialize.serviceLookupHistory = (serviceId, hash, len) => ({
|
|
10309
|
-
key: stateKeys.serviceLookupHistory(serviceId, hash, len),
|
|
9795
|
+
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
9796
|
+
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10310
9797
|
Codec: readonlyArray(codec$1.sequenceVarLen(codec$1.u32)),
|
|
10311
9798
|
});
|
|
10312
9799
|
})(serialize || (serialize = {}));
|
|
@@ -10319,6 +9806,84 @@ var serialize;
|
|
|
10319
9806
|
*/
|
|
10320
9807
|
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()));
|
|
10321
9808
|
|
|
9809
|
+
class SerializedStateView {
|
|
9810
|
+
spec;
|
|
9811
|
+
backend;
|
|
9812
|
+
recentlyUsedServices;
|
|
9813
|
+
viewCache;
|
|
9814
|
+
constructor(spec, backend,
|
|
9815
|
+
/** Best-effort list of recently active services. */
|
|
9816
|
+
recentlyUsedServices, viewCache) {
|
|
9817
|
+
this.spec = spec;
|
|
9818
|
+
this.backend = backend;
|
|
9819
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
9820
|
+
this.viewCache = viewCache;
|
|
9821
|
+
}
|
|
9822
|
+
retrieveView({ key, Codec }, description) {
|
|
9823
|
+
const cached = this.viewCache.get(key);
|
|
9824
|
+
if (cached !== undefined) {
|
|
9825
|
+
return cached;
|
|
9826
|
+
}
|
|
9827
|
+
const bytes = this.backend.get(key);
|
|
9828
|
+
if (bytes === null) {
|
|
9829
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing view of key: ${key}`);
|
|
9830
|
+
}
|
|
9831
|
+
// NOTE [ToDr] we are not using `Decoder.decodeObject` here because
|
|
9832
|
+
// it needs to get to the end of the data (skip), yet that's expensive.
|
|
9833
|
+
// we assume that the state data is correct and coherent anyway, so
|
|
9834
|
+
// for performance reasons we simply create the view here.
|
|
9835
|
+
const d = Decoder.fromBytesBlob(bytes);
|
|
9836
|
+
d.attachContext(this.spec);
|
|
9837
|
+
const view = Codec.View.decode(d);
|
|
9838
|
+
this.viewCache.set(key, view);
|
|
9839
|
+
return view;
|
|
9840
|
+
}
|
|
9841
|
+
availabilityAssignmentView() {
|
|
9842
|
+
return this.retrieveView(serialize.availabilityAssignment, "availabilityAssignmentView");
|
|
9843
|
+
}
|
|
9844
|
+
designatedValidatorDataView() {
|
|
9845
|
+
return this.retrieveView(serialize.designatedValidators, "designatedValidatorsView");
|
|
9846
|
+
}
|
|
9847
|
+
currentValidatorDataView() {
|
|
9848
|
+
return this.retrieveView(serialize.currentValidators, "currentValidatorsView");
|
|
9849
|
+
}
|
|
9850
|
+
previousValidatorDataView() {
|
|
9851
|
+
return this.retrieveView(serialize.previousValidators, "previousValidatorsView");
|
|
9852
|
+
}
|
|
9853
|
+
authPoolsView() {
|
|
9854
|
+
return this.retrieveView(serialize.authPools, "authPoolsView");
|
|
9855
|
+
}
|
|
9856
|
+
authQueuesView() {
|
|
9857
|
+
return this.retrieveView(serialize.authQueues, "authQueuesView");
|
|
9858
|
+
}
|
|
9859
|
+
recentBlocksView() {
|
|
9860
|
+
return this.retrieveView(serialize.recentBlocks, "recentBlocksView");
|
|
9861
|
+
}
|
|
9862
|
+
statisticsView() {
|
|
9863
|
+
return this.retrieveView(serialize.statistics, "statisticsView");
|
|
9864
|
+
}
|
|
9865
|
+
accumulationQueueView() {
|
|
9866
|
+
return this.retrieveView(serialize.accumulationQueue, "accumulationQueueView");
|
|
9867
|
+
}
|
|
9868
|
+
recentlyAccumulatedView() {
|
|
9869
|
+
return this.retrieveView(serialize.recentlyAccumulated, "recentlyAccumulatedView");
|
|
9870
|
+
}
|
|
9871
|
+
safroleDataView() {
|
|
9872
|
+
return this.retrieveView(serialize.safrole, "safroleDataView");
|
|
9873
|
+
}
|
|
9874
|
+
getServiceInfoView(id) {
|
|
9875
|
+
const serviceData = serialize.serviceData(id);
|
|
9876
|
+
const bytes = this.backend.get(serviceData.key);
|
|
9877
|
+
if (bytes === null) {
|
|
9878
|
+
return null;
|
|
9879
|
+
}
|
|
9880
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
9881
|
+
this.recentlyUsedServices.push(id);
|
|
9882
|
+
}
|
|
9883
|
+
return Decoder.decodeObject(serviceData.Codec.View, bytes, this.spec);
|
|
9884
|
+
}
|
|
9885
|
+
}
|
|
9886
|
+
|
|
10322
9887
|
/**
|
|
10323
9888
|
* State object which reads it's entries from some backend.
|
|
10324
9889
|
*
|
|
@@ -10329,58 +9894,74 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10329
9894
|
*/
|
|
10330
9895
|
class SerializedState {
|
|
10331
9896
|
spec;
|
|
9897
|
+
blake2b;
|
|
10332
9898
|
backend;
|
|
10333
|
-
|
|
9899
|
+
recentlyUsedServices;
|
|
10334
9900
|
/** Create a state-like object from collection of serialized entries. */
|
|
10335
|
-
static fromStateEntries(spec, state, recentServices = []) {
|
|
10336
|
-
return new SerializedState(spec, state, recentServices);
|
|
9901
|
+
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9902
|
+
return new SerializedState(spec, blake2b, state, recentServices);
|
|
10337
9903
|
}
|
|
10338
9904
|
/** Create a state-like object backed by some DB. */
|
|
10339
|
-
static new(spec, db, recentServices = []) {
|
|
10340
|
-
return new SerializedState(spec, db, recentServices);
|
|
9905
|
+
static new(spec, blake2b, db, recentServices = []) {
|
|
9906
|
+
return new SerializedState(spec, blake2b, db, recentServices);
|
|
10341
9907
|
}
|
|
10342
|
-
|
|
9908
|
+
dataCache = HashDictionary.new();
|
|
9909
|
+
viewCache = HashDictionary.new();
|
|
9910
|
+
constructor(spec, blake2b, backend,
|
|
10343
9911
|
/** Best-effort list of recently active services. */
|
|
10344
|
-
|
|
9912
|
+
recentlyUsedServices) {
|
|
10345
9913
|
this.spec = spec;
|
|
9914
|
+
this.blake2b = blake2b;
|
|
10346
9915
|
this.backend = backend;
|
|
10347
|
-
this.
|
|
9916
|
+
this.recentlyUsedServices = recentlyUsedServices;
|
|
10348
9917
|
}
|
|
10349
9918
|
/** Comparing the serialized states, just means comparing their backends. */
|
|
10350
9919
|
[TEST_COMPARE_USING]() {
|
|
10351
9920
|
return this.backend;
|
|
10352
9921
|
}
|
|
9922
|
+
/** Return a non-decoding version of the state. */
|
|
9923
|
+
view() {
|
|
9924
|
+
return new SerializedStateView(this.spec, this.backend, this.recentlyUsedServices, this.viewCache);
|
|
9925
|
+
}
|
|
10353
9926
|
// TODO [ToDr] Temporary method to update the state,
|
|
10354
9927
|
// without changing references.
|
|
10355
9928
|
updateBackend(newBackend) {
|
|
10356
9929
|
this.backend = newBackend;
|
|
9930
|
+
this.dataCache = HashDictionary.new();
|
|
9931
|
+
this.viewCache = HashDictionary.new();
|
|
10357
9932
|
}
|
|
10358
9933
|
recentServiceIds() {
|
|
10359
|
-
return this.
|
|
9934
|
+
return this.recentlyUsedServices;
|
|
10360
9935
|
}
|
|
10361
9936
|
getService(id) {
|
|
10362
9937
|
const serviceData = this.retrieveOptional(serialize.serviceData(id));
|
|
10363
9938
|
if (serviceData === undefined) {
|
|
10364
9939
|
return null;
|
|
10365
9940
|
}
|
|
10366
|
-
if (!this.
|
|
10367
|
-
this.
|
|
9941
|
+
if (!this.recentlyUsedServices.includes(id)) {
|
|
9942
|
+
this.recentlyUsedServices.push(id);
|
|
10368
9943
|
}
|
|
10369
|
-
return new SerializedService(id, serviceData, (key) => this.retrieveOptional(key));
|
|
9944
|
+
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10370
9945
|
}
|
|
10371
|
-
retrieve(
|
|
10372
|
-
const
|
|
10373
|
-
if (
|
|
10374
|
-
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${key}`);
|
|
9946
|
+
retrieve(k, description) {
|
|
9947
|
+
const data = this.retrieveOptional(k);
|
|
9948
|
+
if (data === undefined) {
|
|
9949
|
+
throw new Error(`Required state entry for ${description} is missing!. Accessing key: ${k.key}`);
|
|
10375
9950
|
}
|
|
10376
|
-
return
|
|
9951
|
+
return data;
|
|
10377
9952
|
}
|
|
10378
9953
|
retrieveOptional({ key, Codec }) {
|
|
9954
|
+
const cached = this.dataCache.get(key);
|
|
9955
|
+
if (cached !== undefined) {
|
|
9956
|
+
return cached;
|
|
9957
|
+
}
|
|
10379
9958
|
const bytes = this.backend.get(key);
|
|
10380
9959
|
if (bytes === null) {
|
|
10381
9960
|
return undefined;
|
|
10382
9961
|
}
|
|
10383
|
-
|
|
9962
|
+
const data = Decoder.decodeObject(Codec, bytes, this.spec);
|
|
9963
|
+
this.dataCache.set(key, data);
|
|
9964
|
+
return data;
|
|
10384
9965
|
}
|
|
10385
9966
|
get availabilityAssignment() {
|
|
10386
9967
|
return this.retrieve(serialize.availabilityAssignment, "availabilityAssignment");
|
|
@@ -10442,12 +10023,14 @@ class SerializedState {
|
|
|
10442
10023
|
}
|
|
10443
10024
|
/** Service data representation on a serialized state. */
|
|
10444
10025
|
class SerializedService {
|
|
10026
|
+
blake2b;
|
|
10445
10027
|
serviceId;
|
|
10446
10028
|
accountInfo;
|
|
10447
10029
|
retrieveOptional;
|
|
10448
|
-
constructor(
|
|
10030
|
+
constructor(blake2b,
|
|
10449
10031
|
/** Service id */
|
|
10450
10032
|
serviceId, accountInfo, retrieveOptional) {
|
|
10033
|
+
this.blake2b = blake2b;
|
|
10451
10034
|
this.serviceId = serviceId;
|
|
10452
10035
|
this.accountInfo = accountInfo;
|
|
10453
10036
|
this.retrieveOptional = retrieveOptional;
|
|
@@ -10460,13 +10043,13 @@ class SerializedService {
|
|
|
10460
10043
|
getStorage(rawKey) {
|
|
10461
10044
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
10462
10045
|
const SERVICE_ID_BYTES = 4;
|
|
10463
|
-
const serviceIdAndKey =
|
|
10046
|
+
const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
10464
10047
|
serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
|
|
10465
10048
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10466
|
-
const key = asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
10467
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, key)) ?? null;
|
|
10049
|
+
const key = asOpaqueType(BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
10050
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10468
10051
|
}
|
|
10469
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, rawKey)) ?? null;
|
|
10052
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10470
10053
|
}
|
|
10471
10054
|
/**
|
|
10472
10055
|
* Check if preimage is present in the DB.
|
|
@@ -10475,15 +10058,15 @@ class SerializedService {
|
|
|
10475
10058
|
*/
|
|
10476
10059
|
hasPreimage(hash) {
|
|
10477
10060
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10478
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) !== undefined;
|
|
10061
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10479
10062
|
}
|
|
10480
10063
|
/** Retrieve preimage from the DB. */
|
|
10481
10064
|
getPreimage(hash) {
|
|
10482
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) ?? null;
|
|
10065
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10483
10066
|
}
|
|
10484
10067
|
/** Retrieve preimage lookup history. */
|
|
10485
10068
|
getLookupHistory(hash, len) {
|
|
10486
|
-
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.serviceId, hash, len));
|
|
10069
|
+
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
10487
10070
|
if (rawSlots === undefined) {
|
|
10488
10071
|
return null;
|
|
10489
10072
|
}
|
|
@@ -10545,7 +10128,7 @@ class TrieNode {
|
|
|
10545
10128
|
raw;
|
|
10546
10129
|
constructor(
|
|
10547
10130
|
/** Exactly 512 bits / 64 bytes */
|
|
10548
|
-
raw =
|
|
10131
|
+
raw = safeAllocUint8Array(TRIE_NODE_BYTES)) {
|
|
10549
10132
|
this.raw = raw;
|
|
10550
10133
|
}
|
|
10551
10134
|
/** Returns the type of the node */
|
|
@@ -11120,11 +10703,13 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
11120
10703
|
parseInputKey: parseInputKey
|
|
11121
10704
|
});
|
|
11122
10705
|
|
|
11123
|
-
|
|
11124
|
-
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
}
|
|
10706
|
+
function getBlake2bTrieHasher(hasher) {
|
|
10707
|
+
return {
|
|
10708
|
+
hashConcat(n, rest = []) {
|
|
10709
|
+
return hasher.hashBlobs([n, ...rest]);
|
|
10710
|
+
},
|
|
10711
|
+
};
|
|
10712
|
+
}
|
|
11128
10713
|
|
|
11129
10714
|
/** What should be done with that key? */
|
|
11130
10715
|
var StateEntryUpdateAction;
|
|
@@ -11136,14 +10721,14 @@ var StateEntryUpdateAction;
|
|
|
11136
10721
|
})(StateEntryUpdateAction || (StateEntryUpdateAction = {}));
|
|
11137
10722
|
const EMPTY_BLOB = BytesBlob.empty();
|
|
11138
10723
|
/** Serialize given state update into a series of key-value pairs. */
|
|
11139
|
-
function* serializeStateUpdate(spec, update) {
|
|
10724
|
+
function* serializeStateUpdate(spec, blake2b, update) {
|
|
11140
10725
|
// first let's serialize all of the simple entries (if present!)
|
|
11141
10726
|
yield* serializeBasicKeys(spec, update);
|
|
11142
10727
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
11143
10728
|
// then let's proceed with service updates
|
|
11144
|
-
yield* serializeServiceUpdates(update.servicesUpdates, encode);
|
|
11145
|
-
yield* serializePreimages(update.preimages, encode);
|
|
11146
|
-
yield* serializeStorage(update.storage);
|
|
10729
|
+
yield* serializeServiceUpdates(update.servicesUpdates, encode, blake2b);
|
|
10730
|
+
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
10731
|
+
yield* serializeStorage(update.storage, blake2b);
|
|
11147
10732
|
yield* serializeRemovedServices(update.servicesRemoved);
|
|
11148
10733
|
}
|
|
11149
10734
|
function* serializeRemovedServices(servicesRemoved) {
|
|
@@ -11153,18 +10738,18 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
11153
10738
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11154
10739
|
}
|
|
11155
10740
|
}
|
|
11156
|
-
function* serializeStorage(storage) {
|
|
10741
|
+
function* serializeStorage(storage, blake2b) {
|
|
11157
10742
|
for (const { action, serviceId } of storage ?? []) {
|
|
11158
10743
|
switch (action.kind) {
|
|
11159
10744
|
case UpdateStorageKind.Set: {
|
|
11160
10745
|
const key = action.storage.key;
|
|
11161
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10746
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11162
10747
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11163
10748
|
break;
|
|
11164
10749
|
}
|
|
11165
10750
|
case UpdateStorageKind.Remove: {
|
|
11166
10751
|
const key = action.key;
|
|
11167
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10752
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11168
10753
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11169
10754
|
break;
|
|
11170
10755
|
}
|
|
@@ -11173,15 +10758,15 @@ function* serializeStorage(storage) {
|
|
|
11173
10758
|
}
|
|
11174
10759
|
}
|
|
11175
10760
|
}
|
|
11176
|
-
function* serializePreimages(preimages, encode) {
|
|
10761
|
+
function* serializePreimages(preimages, encode, blake2b) {
|
|
11177
10762
|
for (const { action, serviceId } of preimages ?? []) {
|
|
11178
10763
|
switch (action.kind) {
|
|
11179
10764
|
case UpdatePreimageKind.Provide: {
|
|
11180
10765
|
const { hash, blob } = action.preimage;
|
|
11181
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10766
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11182
10767
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11183
10768
|
if (action.slot !== null) {
|
|
11184
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, tryAsU32(blob.length));
|
|
10769
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
11185
10770
|
yield [
|
|
11186
10771
|
StateEntryUpdateAction.Insert,
|
|
11187
10772
|
codec2.key,
|
|
@@ -11192,15 +10777,15 @@ function* serializePreimages(preimages, encode) {
|
|
|
11192
10777
|
}
|
|
11193
10778
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11194
10779
|
const { hash, length, slots } = action.item;
|
|
11195
|
-
const codec = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10780
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11196
10781
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11197
10782
|
break;
|
|
11198
10783
|
}
|
|
11199
10784
|
case UpdatePreimageKind.Remove: {
|
|
11200
10785
|
const { hash, length } = action;
|
|
11201
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10786
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11202
10787
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11203
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10788
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11204
10789
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11205
10790
|
break;
|
|
11206
10791
|
}
|
|
@@ -11209,7 +10794,7 @@ function* serializePreimages(preimages, encode) {
|
|
|
11209
10794
|
}
|
|
11210
10795
|
}
|
|
11211
10796
|
}
|
|
11212
|
-
function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
10797
|
+
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11213
10798
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
11214
10799
|
// new service being created or updated
|
|
11215
10800
|
const codec = serialize.serviceData(serviceId);
|
|
@@ -11217,7 +10802,7 @@ function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
|
11217
10802
|
// additional lookup history update
|
|
11218
10803
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11219
10804
|
const { lookupHistory } = action;
|
|
11220
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10805
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11221
10806
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11222
10807
|
}
|
|
11223
10808
|
}
|
|
@@ -11312,8 +10897,8 @@ class StateEntries {
|
|
|
11312
10897
|
},
|
|
11313
10898
|
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11314
10899
|
/** Turn in-memory state into it's serialized form. */
|
|
11315
|
-
static serializeInMemory(spec, state) {
|
|
11316
|
-
return new StateEntries(convertInMemoryStateToDictionary(spec, state));
|
|
10900
|
+
static serializeInMemory(spec, blake2b, state) {
|
|
10901
|
+
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
11317
10902
|
}
|
|
11318
10903
|
/**
|
|
11319
10904
|
* Wrap a collection of truncated state entries and treat it as state.
|
|
@@ -11362,7 +10947,8 @@ class StateEntries {
|
|
|
11362
10947
|
}
|
|
11363
10948
|
}
|
|
11364
10949
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/391600391600?v=0.6.4 */
|
|
11365
|
-
getRootHash() {
|
|
10950
|
+
getRootHash(blake2b) {
|
|
10951
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11366
10952
|
const leaves = SortedSet.fromArray(leafComparator);
|
|
11367
10953
|
for (const [key, value] of this) {
|
|
11368
10954
|
leaves.insert(InMemoryTrie.constructLeaf(blake2bTrieHasher, key.asOpaque(), value));
|
|
@@ -11371,7 +10957,7 @@ class StateEntries {
|
|
|
11371
10957
|
}
|
|
11372
10958
|
}
|
|
11373
10959
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/38a50038a500?v=0.6.4 */
|
|
11374
|
-
function convertInMemoryStateToDictionary(spec, state) {
|
|
10960
|
+
function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
11375
10961
|
const serialized = TruncatedHashDictionary.fromEntries([]);
|
|
11376
10962
|
function doSerialize(codec) {
|
|
11377
10963
|
serialized.set(codec.key, Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
@@ -11399,18 +10985,18 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11399
10985
|
serialized.set(key, Encoder.encodeObject(Codec, service.getInfo()));
|
|
11400
10986
|
// preimages
|
|
11401
10987
|
for (const preimage of service.data.preimages.values()) {
|
|
11402
|
-
const { key, Codec } = serialize.servicePreimages(serviceId, preimage.hash);
|
|
10988
|
+
const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11403
10989
|
serialized.set(key, Encoder.encodeObject(Codec, preimage.blob));
|
|
11404
10990
|
}
|
|
11405
10991
|
// storage
|
|
11406
10992
|
for (const storage of service.data.storage.values()) {
|
|
11407
|
-
const { key, Codec } = serialize.serviceStorage(serviceId, storage.key);
|
|
10993
|
+
const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11408
10994
|
serialized.set(key, Encoder.encodeObject(Codec, storage.value));
|
|
11409
10995
|
}
|
|
11410
10996
|
// lookup history
|
|
11411
10997
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11412
10998
|
for (const lookupHistory of lookupHistoryList) {
|
|
11413
|
-
const { key, Codec } = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10999
|
+
const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11414
11000
|
serialized.set(key, Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11415
11001
|
}
|
|
11416
11002
|
}
|
|
@@ -11418,9 +11004,9 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11418
11004
|
return serialized;
|
|
11419
11005
|
}
|
|
11420
11006
|
|
|
11421
|
-
function loadState(spec, entries) {
|
|
11007
|
+
function loadState(spec, blake2b, entries) {
|
|
11422
11008
|
const stateEntries = StateEntries.fromEntriesUnsafe(entries);
|
|
11423
|
-
return SerializedState.fromStateEntries(spec, stateEntries);
|
|
11009
|
+
return SerializedState.fromStateEntries(spec, blake2b, stateEntries);
|
|
11424
11010
|
}
|
|
11425
11011
|
|
|
11426
11012
|
/**
|
|
@@ -11453,6 +11039,7 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
11453
11039
|
__proto__: null,
|
|
11454
11040
|
SerializedService: SerializedService,
|
|
11455
11041
|
SerializedState: SerializedState,
|
|
11042
|
+
SerializedStateView: SerializedStateView,
|
|
11456
11043
|
StateEntries: StateEntries,
|
|
11457
11044
|
get StateEntryUpdateAction () { return StateEntryUpdateAction; },
|
|
11458
11045
|
get StateKeyIdx () { return StateKeyIdx; },
|
|
@@ -11528,7 +11115,8 @@ class LeafDb {
|
|
|
11528
11115
|
}
|
|
11529
11116
|
assertNever(val);
|
|
11530
11117
|
}
|
|
11531
|
-
getStateRoot() {
|
|
11118
|
+
getStateRoot(blake2b) {
|
|
11119
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11532
11120
|
return InMemoryTrie.computeStateRoot(blake2bTrieHasher, this.leaves).asOpaque();
|
|
11533
11121
|
}
|
|
11534
11122
|
intoStateEntries() {
|
|
@@ -11644,7 +11232,11 @@ class ServiceWithCodec extends InMemoryService {
|
|
|
11644
11232
|
return new ServiceWithCodec(serviceId, data);
|
|
11645
11233
|
}
|
|
11646
11234
|
}
|
|
11647
|
-
const inMemoryStateCodec = codec$1.Class(InMemoryState
|
|
11235
|
+
const inMemoryStateCodec = (spec) => codec$1.Class(class State extends InMemoryState {
|
|
11236
|
+
static create(data) {
|
|
11237
|
+
return InMemoryState.new(spec, data);
|
|
11238
|
+
}
|
|
11239
|
+
}, {
|
|
11648
11240
|
// alpha
|
|
11649
11241
|
authPools: serialize.authPools.Codec,
|
|
11650
11242
|
// phi
|
|
@@ -11718,11 +11310,12 @@ class InMemoryStates {
|
|
|
11718
11310
|
}
|
|
11719
11311
|
}
|
|
11720
11312
|
async getStateRoot(state) {
|
|
11721
|
-
|
|
11313
|
+
const blake2b = await Blake2b.createHasher();
|
|
11314
|
+
return StateEntries.serializeInMemory(this.spec, blake2b, state).getRootHash(blake2b);
|
|
11722
11315
|
}
|
|
11723
11316
|
/** Insert a full state into the database. */
|
|
11724
11317
|
async insertState(headerHash, state) {
|
|
11725
|
-
const encoded = Encoder.encodeObject(inMemoryStateCodec, state, this.spec);
|
|
11318
|
+
const encoded = Encoder.encodeObject(inMemoryStateCodec(this.spec), state, this.spec);
|
|
11726
11319
|
this.db.set(headerHash, encoded);
|
|
11727
11320
|
return Result$1.ok(OK);
|
|
11728
11321
|
}
|
|
@@ -11731,7 +11324,7 @@ class InMemoryStates {
|
|
|
11731
11324
|
if (encodedState === undefined) {
|
|
11732
11325
|
return null;
|
|
11733
11326
|
}
|
|
11734
|
-
return Decoder.decodeObject(inMemoryStateCodec, encodedState, this.spec);
|
|
11327
|
+
return Decoder.decodeObject(inMemoryStateCodec(this.spec), encodedState, this.spec);
|
|
11735
11328
|
}
|
|
11736
11329
|
}
|
|
11737
11330
|
|
|
@@ -11796,7 +11389,7 @@ function padAndEncodeData(input) {
|
|
|
11796
11389
|
const paddedLength = Math.ceil(input.length / PIECE_SIZE) * PIECE_SIZE;
|
|
11797
11390
|
let padded = input;
|
|
11798
11391
|
if (input.length !== paddedLength) {
|
|
11799
|
-
padded = BytesBlob.blobFrom(
|
|
11392
|
+
padded = BytesBlob.blobFrom(safeAllocUint8Array(paddedLength));
|
|
11800
11393
|
padded.raw.set(input.raw, 0);
|
|
11801
11394
|
}
|
|
11802
11395
|
return chunkingFunction(padded);
|
|
@@ -11842,7 +11435,7 @@ function decodeData(input) {
|
|
|
11842
11435
|
*/
|
|
11843
11436
|
function encodePoints(input) {
|
|
11844
11437
|
const result = [];
|
|
11845
|
-
const data =
|
|
11438
|
+
const data = safeAllocUint8Array(POINT_ALIGNMENT * N_CHUNKS_REQUIRED);
|
|
11846
11439
|
// add original shards to the result
|
|
11847
11440
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11848
11441
|
const pointStart = POINT_LENGTH * i;
|
|
@@ -11858,7 +11451,7 @@ function encodePoints(input) {
|
|
|
11858
11451
|
const encodedData = encodedResult.take_data();
|
|
11859
11452
|
for (let i = 0; i < N_CHUNKS_REDUNDANCY; i++) {
|
|
11860
11453
|
const pointIndex = i * POINT_ALIGNMENT;
|
|
11861
|
-
const redundancyPoint =
|
|
11454
|
+
const redundancyPoint = safeAllocUint8Array(POINT_LENGTH);
|
|
11862
11455
|
for (let j = 0; j < POINT_LENGTH; j++) {
|
|
11863
11456
|
redundancyPoint[j] = encodedData[pointIndex + j * HALF_POINT_SIZE];
|
|
11864
11457
|
}
|
|
@@ -11873,7 +11466,7 @@ function encodePoints(input) {
|
|
|
11873
11466
|
*/
|
|
11874
11467
|
function decodePiece(input) {
|
|
11875
11468
|
const result = Bytes.zero(PIECE_SIZE);
|
|
11876
|
-
const data =
|
|
11469
|
+
const data = safeAllocUint8Array(N_CHUNKS_REQUIRED * POINT_ALIGNMENT);
|
|
11877
11470
|
const indices = new Uint16Array(input.length);
|
|
11878
11471
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11879
11472
|
const [index, points] = input[i];
|
|
@@ -11989,7 +11582,7 @@ function lace(input) {
|
|
|
11989
11582
|
return BytesBlob.empty();
|
|
11990
11583
|
}
|
|
11991
11584
|
const n = input[0].length;
|
|
11992
|
-
const result = BytesBlob.blobFrom(
|
|
11585
|
+
const result = BytesBlob.blobFrom(safeAllocUint8Array(k * n));
|
|
11993
11586
|
for (let i = 0; i < k; i++) {
|
|
11994
11587
|
const entry = input[i].raw;
|
|
11995
11588
|
for (let j = 0; j < n; j++) {
|
|
@@ -12668,6 +12261,8 @@ var NewServiceError;
|
|
|
12668
12261
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
12669
12262
|
/** Service is not privileged to set gratis storage. */
|
|
12670
12263
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
12264
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
12265
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
12671
12266
|
})(NewServiceError || (NewServiceError = {}));
|
|
12672
12267
|
var UpdatePrivilegesError;
|
|
12673
12268
|
(function (UpdatePrivilegesError) {
|
|
@@ -12858,11 +12453,17 @@ class AccumulationStateUpdate {
|
|
|
12858
12453
|
if (from.privilegedServices !== null) {
|
|
12859
12454
|
update.privilegedServices = PrivilegedServices.create({
|
|
12860
12455
|
...from.privilegedServices,
|
|
12861
|
-
|
|
12456
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
12862
12457
|
});
|
|
12863
12458
|
}
|
|
12864
12459
|
return update;
|
|
12865
12460
|
}
|
|
12461
|
+
/** Retrieve and clear pending transfers. */
|
|
12462
|
+
takeTransfers() {
|
|
12463
|
+
const transfers = this.transfers;
|
|
12464
|
+
this.transfers = [];
|
|
12465
|
+
return transfers;
|
|
12466
|
+
}
|
|
12866
12467
|
}
|
|
12867
12468
|
class PartiallyUpdatedState {
|
|
12868
12469
|
state;
|
|
@@ -13059,7 +12660,7 @@ const HostCallResult = {
|
|
|
13059
12660
|
OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
13060
12661
|
/** Index unknown. */
|
|
13061
12662
|
WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
13062
|
-
/** Storage full. */
|
|
12663
|
+
/** Storage full or resource already allocated. */
|
|
13063
12664
|
FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
13064
12665
|
/** Core index unknown. */
|
|
13065
12666
|
CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -13067,7 +12668,7 @@ const HostCallResult = {
|
|
|
13067
12668
|
CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
13068
12669
|
/** Gas limit too low. */
|
|
13069
12670
|
LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
13070
|
-
/** The item is already solicited
|
|
12671
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
13071
12672
|
HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
13072
12673
|
/** The return value indicating general success. */
|
|
13073
12674
|
OK: tryAsU64(0n),
|
|
@@ -13268,7 +12869,7 @@ class Registers {
|
|
|
13268
12869
|
bytes;
|
|
13269
12870
|
asSigned;
|
|
13270
12871
|
asUnsigned;
|
|
13271
|
-
constructor(bytes =
|
|
12872
|
+
constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT)) {
|
|
13272
12873
|
this.bytes = bytes;
|
|
13273
12874
|
check `${bytes.length === NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
13274
12875
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
@@ -13421,7 +13022,7 @@ class Mask {
|
|
|
13421
13022
|
return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
|
|
13422
13023
|
}
|
|
13423
13024
|
buildLookupTableForward(mask) {
|
|
13424
|
-
const table =
|
|
13025
|
+
const table = safeAllocUint8Array(mask.bitLength);
|
|
13425
13026
|
let lastInstructionOffset = 0;
|
|
13426
13027
|
for (let i = mask.bitLength - 1; i >= 0; i--) {
|
|
13427
13028
|
if (mask.isSet(i)) {
|
|
@@ -15102,11 +14703,6 @@ class BitOps {
|
|
|
15102
14703
|
}
|
|
15103
14704
|
}
|
|
15104
14705
|
|
|
15105
|
-
const MAX_VALUE = 4294967295;
|
|
15106
|
-
const MIN_VALUE = -2147483648;
|
|
15107
|
-
const MAX_SHIFT_U32 = 32;
|
|
15108
|
-
const MAX_SHIFT_U64 = 64n;
|
|
15109
|
-
|
|
15110
14706
|
/**
|
|
15111
14707
|
* Overflowing addition for two-complement representation of 32-bit signed numbers.
|
|
15112
14708
|
*/
|
|
@@ -16856,6 +16452,24 @@ class Interpreter {
|
|
|
16856
16452
|
getMemoryPage(pageNumber) {
|
|
16857
16453
|
return this.memory.getPageDump(tryAsPageNumber(pageNumber));
|
|
16858
16454
|
}
|
|
16455
|
+
calculateBlockGasCost() {
|
|
16456
|
+
const codeLength = this.code.length;
|
|
16457
|
+
const blocks = new Map();
|
|
16458
|
+
let currentBlock = "0";
|
|
16459
|
+
let gasCost = 0;
|
|
16460
|
+
const getNextIstructionIndex = (index) => index + 1 + this.mask.getNoOfBytesToNextInstruction(index + 1);
|
|
16461
|
+
for (let index = 0; index < codeLength; index = getNextIstructionIndex(index)) {
|
|
16462
|
+
const instruction = this.code[index];
|
|
16463
|
+
if (this.basicBlocks.isBeginningOfBasicBlock(index)) {
|
|
16464
|
+
blocks.set(currentBlock, gasCost);
|
|
16465
|
+
currentBlock = index.toString();
|
|
16466
|
+
gasCost = 0;
|
|
16467
|
+
}
|
|
16468
|
+
gasCost += instructionGasMap[instruction];
|
|
16469
|
+
}
|
|
16470
|
+
blocks.set(currentBlock, gasCost);
|
|
16471
|
+
return blocks;
|
|
16472
|
+
}
|
|
16859
16473
|
}
|
|
16860
16474
|
|
|
16861
16475
|
var index$7 = /*#__PURE__*/Object.freeze({
|
|
@@ -16956,7 +16570,7 @@ class HostCalls {
|
|
|
16956
16570
|
const regs = pvmInstance.getRegisters();
|
|
16957
16571
|
const maybeAddress = regs.getLowerU32(7);
|
|
16958
16572
|
const maybeLength = regs.getLowerU32(8);
|
|
16959
|
-
const result =
|
|
16573
|
+
const result = safeAllocUint8Array(maybeLength);
|
|
16960
16574
|
const startAddress = tryAsMemoryIndex(maybeAddress);
|
|
16961
16575
|
const loadResult = memory.loadInto(result, startAddress);
|
|
16962
16576
|
if (loadResult.isError) {
|
|
@@ -17305,14 +16919,14 @@ class DebuggerAdapter {
|
|
|
17305
16919
|
const page = this.pvm.getMemoryPage(pageNumber);
|
|
17306
16920
|
if (page === null) {
|
|
17307
16921
|
// page wasn't allocated so we return an empty page
|
|
17308
|
-
return
|
|
16922
|
+
return safeAllocUint8Array(PAGE_SIZE$1);
|
|
17309
16923
|
}
|
|
17310
16924
|
if (page.length === PAGE_SIZE$1) {
|
|
17311
16925
|
// page was allocated and has a proper size so we can simply return it
|
|
17312
16926
|
return page;
|
|
17313
16927
|
}
|
|
17314
16928
|
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
17315
|
-
const fullPage =
|
|
16929
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
|
|
17316
16930
|
fullPage.set(page);
|
|
17317
16931
|
return fullPage;
|
|
17318
16932
|
}
|
|
@@ -17416,7 +17030,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
17416
17030
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
17417
17031
|
getServiceId: getServiceId,
|
|
17418
17032
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
17419
|
-
hash: index$
|
|
17033
|
+
hash: index$o,
|
|
17420
17034
|
inspect: inspect,
|
|
17421
17035
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
17422
17036
|
interpreter: index$7,
|
|
@@ -17438,10 +17052,10 @@ const ENTROPY_BYTES = 32;
|
|
|
17438
17052
|
*
|
|
17439
17053
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
17440
17054
|
*/
|
|
17441
|
-
function fisherYatesShuffle(arr, entropy) {
|
|
17055
|
+
function fisherYatesShuffle(blake2b, arr, entropy) {
|
|
17442
17056
|
check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
17443
17057
|
const n = arr.length;
|
|
17444
|
-
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
17058
|
+
const randomNumbers = hashToNumberSequence(blake2b, entropy, arr.length);
|
|
17445
17059
|
const result = new Array(n);
|
|
17446
17060
|
let itemsLeft = n;
|
|
17447
17061
|
for (let i = 0; i < n; i++) {
|
|
@@ -17454,13 +17068,13 @@ function fisherYatesShuffle(arr, entropy) {
|
|
|
17454
17068
|
}
|
|
17455
17069
|
return result;
|
|
17456
17070
|
}
|
|
17457
|
-
function hashToNumberSequence(entropy, length) {
|
|
17071
|
+
function hashToNumberSequence(blake2b, entropy, length) {
|
|
17458
17072
|
const result = new Array(length);
|
|
17459
|
-
const randomBytes =
|
|
17073
|
+
const randomBytes = safeAllocUint8Array(ENTROPY_BYTES + 4);
|
|
17460
17074
|
randomBytes.set(entropy.raw);
|
|
17461
17075
|
for (let i = 0; i < length; i++) {
|
|
17462
17076
|
randomBytes.set(u32AsLeBytes(tryAsU32(Math.floor(i / 8))), ENTROPY_BYTES);
|
|
17463
|
-
const newHash = hashBytes(randomBytes);
|
|
17077
|
+
const newHash = blake2b.hashBytes(randomBytes);
|
|
17464
17078
|
const numberStartIndex = (4 * i) % 32;
|
|
17465
17079
|
const numberEndIndex = numberStartIndex + 4;
|
|
17466
17080
|
const number = leBytesAsU32(newHash.raw.subarray(numberStartIndex, numberEndIndex)) >>> 0;
|
|
@@ -17476,6 +17090,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
17476
17090
|
|
|
17477
17091
|
class JsonServiceInfo {
|
|
17478
17092
|
static fromJson = json.object({
|
|
17093
|
+
...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
|
|
17479
17094
|
code_hash: fromJson.bytes32(),
|
|
17480
17095
|
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
17481
17096
|
min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
@@ -17500,6 +17115,7 @@ class JsonServiceInfo {
|
|
|
17500
17115
|
parentService: parent_service,
|
|
17501
17116
|
});
|
|
17502
17117
|
});
|
|
17118
|
+
version;
|
|
17503
17119
|
code_hash;
|
|
17504
17120
|
balance;
|
|
17505
17121
|
min_item_gas;
|
|
@@ -17534,23 +17150,35 @@ const lookupMetaFromJson = json.object({
|
|
|
17534
17150
|
},
|
|
17535
17151
|
value: json.array("number"),
|
|
17536
17152
|
}, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
|
|
17153
|
+
const preimageStatusFromJson = json.object({
|
|
17154
|
+
hash: fromJson.bytes32(),
|
|
17155
|
+
status: json.array("number"),
|
|
17156
|
+
}, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
|
|
17537
17157
|
class JsonService {
|
|
17538
17158
|
static fromJson = json.object({
|
|
17539
17159
|
id: "number",
|
|
17540
|
-
data:
|
|
17541
|
-
|
|
17542
|
-
|
|
17543
|
-
|
|
17544
|
-
|
|
17545
|
-
|
|
17160
|
+
data: Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17161
|
+
? {
|
|
17162
|
+
service: JsonServiceInfo.fromJson,
|
|
17163
|
+
preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
17164
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
17165
|
+
lookup_meta: json.optional(json.array(lookupMetaFromJson)),
|
|
17166
|
+
}
|
|
17167
|
+
: {
|
|
17168
|
+
service: JsonServiceInfo.fromJson,
|
|
17169
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
17170
|
+
preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
17171
|
+
preimages_status: json.optional(json.array(preimageStatusFromJson)),
|
|
17172
|
+
},
|
|
17546
17173
|
}, ({ id, data }) => {
|
|
17174
|
+
const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
|
|
17547
17175
|
const lookupHistory = HashDictionary.new();
|
|
17548
|
-
for (const item of data.lookup_meta ?? []) {
|
|
17176
|
+
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
17549
17177
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
17550
|
-
|
|
17178
|
+
const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
17179
|
+
data.push(new LookupHistoryItem(item.hash, length, item.slots));
|
|
17551
17180
|
lookupHistory.set(item.hash, data);
|
|
17552
17181
|
}
|
|
17553
|
-
const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
|
|
17554
17182
|
const storage = new Map();
|
|
17555
17183
|
const entries = (data.storage ?? []).map(({ key, value }) => {
|
|
17556
17184
|
const opaqueKey = asOpaqueType(key);
|
|
@@ -17574,8 +17202,7 @@ const availabilityAssignmentFromJson = json.object({
|
|
|
17574
17202
|
report: workReportFromJson,
|
|
17575
17203
|
timeout: "number",
|
|
17576
17204
|
}, ({ report, timeout }) => {
|
|
17577
|
-
|
|
17578
|
-
return AvailabilityAssignment.create({ workReport: new WithHash(workReportHash, report), timeout });
|
|
17205
|
+
return AvailabilityAssignment.create({ workReport: report, timeout });
|
|
17579
17206
|
});
|
|
17580
17207
|
|
|
17581
17208
|
const disputesRecordsFromJson = json.object({
|
|
@@ -17627,10 +17254,10 @@ const recentBlocksHistoryFromJson = json.object({
|
|
|
17627
17254
|
peaks: json.array(json.nullable(fromJson.bytes32())),
|
|
17628
17255
|
},
|
|
17629
17256
|
}, ({ history, mmr }) => {
|
|
17630
|
-
return
|
|
17257
|
+
return RecentBlocks.create({
|
|
17631
17258
|
blocks: history,
|
|
17632
17259
|
accumulationLog: mmr,
|
|
17633
|
-
})
|
|
17260
|
+
});
|
|
17634
17261
|
});
|
|
17635
17262
|
|
|
17636
17263
|
const ticketFromJson = json.object({
|
|
@@ -17723,8 +17350,12 @@ class JsonServiceStatistics {
|
|
|
17723
17350
|
extrinsic_count: "number",
|
|
17724
17351
|
accumulate_count: "number",
|
|
17725
17352
|
accumulate_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17726
|
-
|
|
17727
|
-
|
|
17353
|
+
...(Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17354
|
+
? {
|
|
17355
|
+
on_transfers_count: "number",
|
|
17356
|
+
on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17357
|
+
}
|
|
17358
|
+
: {}),
|
|
17728
17359
|
}, ({ 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, }) => {
|
|
17729
17360
|
return ServiceStatistics.create({
|
|
17730
17361
|
providedCount: provided_count,
|
|
@@ -17737,8 +17368,8 @@ class JsonServiceStatistics {
|
|
|
17737
17368
|
extrinsicCount: extrinsic_count,
|
|
17738
17369
|
accumulateCount: accumulate_count,
|
|
17739
17370
|
accumulateGasUsed: accumulate_gas_used,
|
|
17740
|
-
onTransfersCount: on_transfers_count,
|
|
17741
|
-
onTransfersGasUsed: on_transfers_gas_used,
|
|
17371
|
+
onTransfersCount: on_transfers_count ?? tryAsU32(0),
|
|
17372
|
+
onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
|
|
17742
17373
|
});
|
|
17743
17374
|
});
|
|
17744
17375
|
provided_count;
|
|
@@ -17809,6 +17440,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17809
17440
|
chi_m: "number",
|
|
17810
17441
|
chi_a: json.array("number"),
|
|
17811
17442
|
chi_v: "number",
|
|
17443
|
+
chi_r: json.optional("number"),
|
|
17812
17444
|
chi_g: json.nullable(json.array({
|
|
17813
17445
|
service: "number",
|
|
17814
17446
|
gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
|
|
@@ -17820,7 +17452,10 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17820
17452
|
theta: json.nullable(json.array(accumulationOutput)),
|
|
17821
17453
|
accounts: json.array(JsonService.fromJson),
|
|
17822
17454
|
}, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
|
|
17823
|
-
|
|
17455
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
17456
|
+
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
17457
|
+
}
|
|
17458
|
+
return InMemoryState.new(spec, {
|
|
17824
17459
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17825
17460
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
17826
17461
|
throw new Error(`AuthPools: expected less than ${MAX_AUTH_POOL_SIZE}, got ${perCore.length}`);
|
|
@@ -17833,7 +17468,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17833
17468
|
}
|
|
17834
17469
|
return asKnownSize(perCore);
|
|
17835
17470
|
}), spec),
|
|
17836
|
-
recentBlocks: beta ??
|
|
17471
|
+
recentBlocks: beta ?? RecentBlocks.empty(),
|
|
17837
17472
|
nextValidatorData: gamma.gamma_k,
|
|
17838
17473
|
epochRoot: gamma.gamma_z,
|
|
17839
17474
|
sealingKeySeries: TicketsOrKeys.toSafroleSealingKeys(gamma.gamma_s, spec),
|
|
@@ -17847,8 +17482,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17847
17482
|
timeslot: tau,
|
|
17848
17483
|
privilegedServices: PrivilegedServices.create({
|
|
17849
17484
|
manager: chi.chi_m,
|
|
17850
|
-
|
|
17851
|
-
|
|
17485
|
+
assigners: chi.chi_a,
|
|
17486
|
+
delegator: chi.chi_v,
|
|
17487
|
+
registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
|
|
17852
17488
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
17853
17489
|
}),
|
|
17854
17490
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|
|
@@ -17881,11 +17517,11 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17881
17517
|
class TransitionHasher {
|
|
17882
17518
|
context;
|
|
17883
17519
|
keccakHasher;
|
|
17884
|
-
|
|
17885
|
-
constructor(context, keccakHasher,
|
|
17520
|
+
blake2b;
|
|
17521
|
+
constructor(context, keccakHasher, blake2b) {
|
|
17886
17522
|
this.context = context;
|
|
17887
17523
|
this.keccakHasher = keccakHasher;
|
|
17888
|
-
this.
|
|
17524
|
+
this.blake2b = blake2b;
|
|
17889
17525
|
}
|
|
17890
17526
|
/** Concatenates two hashes and hash this concatenation */
|
|
17891
17527
|
hashConcat(a, b) {
|
|
@@ -17896,7 +17532,7 @@ class TransitionHasher {
|
|
|
17896
17532
|
}
|
|
17897
17533
|
/** Creates hash from the block header view */
|
|
17898
17534
|
header(header) {
|
|
17899
|
-
return new WithHash(hashBytes(header.encoded()
|
|
17535
|
+
return new WithHash(this.blake2b.hashBytes(header.encoded()).asOpaque(), header);
|
|
17900
17536
|
}
|
|
17901
17537
|
/**
|
|
17902
17538
|
* Merkle commitment of the extrinsic data
|
|
@@ -17905,25 +17541,25 @@ class TransitionHasher {
|
|
|
17905
17541
|
*/
|
|
17906
17542
|
extrinsic(extrinsicView) {
|
|
17907
17543
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0cfb000cfb00?v=0.6.5
|
|
17908
|
-
const
|
|
17544
|
+
const guaranteesCount = tryAsU32(extrinsicView.guarantees.view().length);
|
|
17545
|
+
const countEncoded = Encoder.encodeObject(codec$1.varU32, guaranteesCount);
|
|
17546
|
+
const guaranteesBlobs = extrinsicView.guarantees
|
|
17909
17547
|
.view()
|
|
17910
17548
|
.map((g) => g.view())
|
|
17911
|
-
.
|
|
17912
|
-
const reportHash = hashBytes(guarantee.report.encoded()
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
const
|
|
17920
|
-
const
|
|
17921
|
-
const
|
|
17922
|
-
const
|
|
17923
|
-
const ea = hashBytes(extrinsicView.assurances.encoded(), this.allocator).asOpaque();
|
|
17924
|
-
const ed = hashBytes(extrinsicView.disputes.encoded(), this.allocator).asOpaque();
|
|
17549
|
+
.reduce((aggregated, guarantee) => {
|
|
17550
|
+
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17551
|
+
aggregated.push(reportHash.raw);
|
|
17552
|
+
aggregated.push(guarantee.slot.encoded().raw);
|
|
17553
|
+
aggregated.push(guarantee.credentials.encoded().raw);
|
|
17554
|
+
return aggregated;
|
|
17555
|
+
}, [countEncoded.raw]);
|
|
17556
|
+
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17557
|
+
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17558
|
+
const eg = this.blake2b.hashBlobs(guaranteesBlobs).asOpaque();
|
|
17559
|
+
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17560
|
+
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17925
17561
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
17926
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17562
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
17927
17563
|
}
|
|
17928
17564
|
/** Creates hash for given WorkPackage */
|
|
17929
17565
|
workPackage(workPackage) {
|
|
@@ -17932,7 +17568,7 @@ class TransitionHasher {
|
|
|
17932
17568
|
encode(codec, data) {
|
|
17933
17569
|
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
17934
17570
|
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
17935
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17571
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
17936
17572
|
}
|
|
17937
17573
|
}
|
|
17938
17574
|
|
|
@@ -17945,8 +17581,10 @@ var PreimagesErrorCode;
|
|
|
17945
17581
|
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
17946
17582
|
class Preimages {
|
|
17947
17583
|
state;
|
|
17948
|
-
|
|
17584
|
+
blake2b;
|
|
17585
|
+
constructor(state, blake2b) {
|
|
17949
17586
|
this.state = state;
|
|
17587
|
+
this.blake2b = blake2b;
|
|
17950
17588
|
}
|
|
17951
17589
|
integrate(input) {
|
|
17952
17590
|
// make sure lookup extrinsics are sorted and unique
|
|
@@ -17969,7 +17607,7 @@ class Preimages {
|
|
|
17969
17607
|
// select preimages for integration
|
|
17970
17608
|
for (const preimage of preimages) {
|
|
17971
17609
|
const { requester, blob } = preimage;
|
|
17972
|
-
const hash = hashBytes(blob).asOpaque();
|
|
17610
|
+
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
17973
17611
|
const service = this.state.getService(requester);
|
|
17974
17612
|
if (service === null) {
|
|
17975
17613
|
return Result$1.error(PreimagesErrorCode.AccountNotFound);
|
|
@@ -17994,146 +17632,11 @@ class Preimages {
|
|
|
17994
17632
|
}
|
|
17995
17633
|
}
|
|
17996
17634
|
|
|
17997
|
-
class Missing {
|
|
17998
|
-
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
17999
|
-
basicGasCost = tryAsSmallGas(10);
|
|
18000
|
-
currentServiceId = CURRENT_SERVICE_ID;
|
|
18001
|
-
tracedRegisters = traceRegisters(7);
|
|
18002
|
-
execute(_gas, regs, _memory) {
|
|
18003
|
-
regs.set(7, HostCallResult.WHAT);
|
|
18004
|
-
return Promise.resolve(undefined);
|
|
18005
|
-
}
|
|
18006
|
-
}
|
|
18007
|
-
|
|
18008
|
-
var ServiceExecutorError;
|
|
18009
|
-
(function (ServiceExecutorError) {
|
|
18010
|
-
ServiceExecutorError[ServiceExecutorError["NoLookup"] = 0] = "NoLookup";
|
|
18011
|
-
ServiceExecutorError[ServiceExecutorError["NoState"] = 1] = "NoState";
|
|
18012
|
-
ServiceExecutorError[ServiceExecutorError["NoServiceCode"] = 2] = "NoServiceCode";
|
|
18013
|
-
ServiceExecutorError[ServiceExecutorError["ServiceCodeMismatch"] = 3] = "ServiceCodeMismatch";
|
|
18014
|
-
})(ServiceExecutorError || (ServiceExecutorError = {}));
|
|
18015
|
-
class WorkPackageExecutor {
|
|
18016
|
-
blocks;
|
|
18017
|
-
state;
|
|
18018
|
-
hasher;
|
|
18019
|
-
constructor(blocks, state, hasher) {
|
|
18020
|
-
this.blocks = blocks;
|
|
18021
|
-
this.state = state;
|
|
18022
|
-
this.hasher = hasher;
|
|
18023
|
-
}
|
|
18024
|
-
// TODO [ToDr] this while thing should be triple-checked with the GP.
|
|
18025
|
-
// I'm currently implementing some dirty version for the demo.
|
|
18026
|
-
async executeWorkPackage(pack) {
|
|
18027
|
-
const headerHash = pack.context.lookupAnchor;
|
|
18028
|
-
// execute authorisation first or is it already executed and we just need to check it?
|
|
18029
|
-
const authExec = this.getServiceExecutor(
|
|
18030
|
-
// TODO [ToDr] should this be anchor or lookupAnchor?
|
|
18031
|
-
headerHash, pack.authCodeHost, pack.authCodeHash);
|
|
18032
|
-
if (authExec.isError) {
|
|
18033
|
-
// TODO [ToDr] most likely shouldn't be throw.
|
|
18034
|
-
throw new Error(`Could not get authorization executor: ${authExec.error}`);
|
|
18035
|
-
}
|
|
18036
|
-
const pvm = authExec.ok;
|
|
18037
|
-
const authGas = tryAsGas(15000n);
|
|
18038
|
-
const result = await pvm.run(pack.parametrization, authGas);
|
|
18039
|
-
if (!result.isEqualTo(pack.authorization)) {
|
|
18040
|
-
throw new Error("Authorization is invalid.");
|
|
18041
|
-
}
|
|
18042
|
-
const results = [];
|
|
18043
|
-
for (const item of pack.items) {
|
|
18044
|
-
const exec = this.getServiceExecutor(headerHash, item.service, item.codeHash);
|
|
18045
|
-
if (exec.isError) {
|
|
18046
|
-
throw new Error(`Could not get item executor: ${exec.error}`);
|
|
18047
|
-
}
|
|
18048
|
-
const pvm = exec.ok;
|
|
18049
|
-
const gasRatio = tryAsServiceGas(3000n);
|
|
18050
|
-
const ret = await pvm.run(item.payload, tryAsGas(item.refineGasLimit)); // or accumulateGasLimit?
|
|
18051
|
-
results.push(WorkResult.create({
|
|
18052
|
-
serviceId: item.service,
|
|
18053
|
-
codeHash: item.codeHash,
|
|
18054
|
-
payloadHash: hashBytes(item.payload),
|
|
18055
|
-
gas: gasRatio,
|
|
18056
|
-
result: new WorkExecResult(WorkExecResultKind.ok, ret),
|
|
18057
|
-
load: WorkRefineLoad.create({
|
|
18058
|
-
gasUsed: tryAsServiceGas(5),
|
|
18059
|
-
importedSegments: tryAsU32(0),
|
|
18060
|
-
exportedSegments: tryAsU32(0),
|
|
18061
|
-
extrinsicSize: tryAsU32(0),
|
|
18062
|
-
extrinsicCount: tryAsU32(0),
|
|
18063
|
-
}),
|
|
18064
|
-
}));
|
|
18065
|
-
}
|
|
18066
|
-
const workPackage = this.hasher.workPackage(pack);
|
|
18067
|
-
const workPackageSpec = WorkPackageSpec.create({
|
|
18068
|
-
hash: workPackage.hash,
|
|
18069
|
-
length: tryAsU32(workPackage.encoded.length),
|
|
18070
|
-
erasureRoot: Bytes.zero(HASH_SIZE),
|
|
18071
|
-
exportsRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
18072
|
-
exportsCount: tryAsU16(0),
|
|
18073
|
-
});
|
|
18074
|
-
const coreIndex = tryAsCoreIndex(0);
|
|
18075
|
-
const authorizerHash = Bytes.fill(HASH_SIZE, 5).asOpaque();
|
|
18076
|
-
const workResults = FixedSizeArray.new(results, tryAsWorkItemsCount(results.length));
|
|
18077
|
-
return Promise.resolve(WorkReport.create({
|
|
18078
|
-
workPackageSpec,
|
|
18079
|
-
context: pack.context,
|
|
18080
|
-
coreIndex,
|
|
18081
|
-
authorizerHash,
|
|
18082
|
-
authorizationOutput: pack.authorization,
|
|
18083
|
-
segmentRootLookup: [],
|
|
18084
|
-
results: workResults,
|
|
18085
|
-
authorizationGasUsed: tryAsServiceGas(0),
|
|
18086
|
-
}));
|
|
18087
|
-
}
|
|
18088
|
-
getServiceExecutor(lookupAnchor, serviceId, expectedCodeHash) {
|
|
18089
|
-
const header = this.blocks.getHeader(lookupAnchor);
|
|
18090
|
-
if (header === null) {
|
|
18091
|
-
return Result$1.error(ServiceExecutorError.NoLookup);
|
|
18092
|
-
}
|
|
18093
|
-
const state = this.state.getState(lookupAnchor);
|
|
18094
|
-
if (state === null) {
|
|
18095
|
-
return Result$1.error(ServiceExecutorError.NoState);
|
|
18096
|
-
}
|
|
18097
|
-
const service = state.getService(serviceId);
|
|
18098
|
-
const serviceCodeHash = service?.getInfo().codeHash ?? null;
|
|
18099
|
-
if (serviceCodeHash === null) {
|
|
18100
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18101
|
-
}
|
|
18102
|
-
if (!serviceCodeHash.isEqualTo(expectedCodeHash)) {
|
|
18103
|
-
return Result$1.error(ServiceExecutorError.ServiceCodeMismatch);
|
|
18104
|
-
}
|
|
18105
|
-
const serviceCode = service?.getPreimage(serviceCodeHash.asOpaque()) ?? null;
|
|
18106
|
-
if (serviceCode === null) {
|
|
18107
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18108
|
-
}
|
|
18109
|
-
return Result$1.ok(new PvmExecutor(serviceCode));
|
|
18110
|
-
}
|
|
18111
|
-
}
|
|
18112
|
-
class PvmExecutor {
|
|
18113
|
-
serviceCode;
|
|
18114
|
-
pvm;
|
|
18115
|
-
hostCalls = new HostCallsManager({ missing: new Missing() });
|
|
18116
|
-
pvmInstanceManager = new InterpreterInstanceManager(4);
|
|
18117
|
-
constructor(serviceCode) {
|
|
18118
|
-
this.serviceCode = serviceCode;
|
|
18119
|
-
this.pvm = new HostCalls(this.pvmInstanceManager, this.hostCalls);
|
|
18120
|
-
}
|
|
18121
|
-
async run(args, gas) {
|
|
18122
|
-
const program = Program.fromSpi(this.serviceCode.raw, args.raw, true);
|
|
18123
|
-
const result = await this.pvm.runProgram(program.code, 5, gas, program.registers, program.memory);
|
|
18124
|
-
if (result.hasMemorySlice()) {
|
|
18125
|
-
return BytesBlob.blobFrom(result.memorySlice);
|
|
18126
|
-
}
|
|
18127
|
-
return BytesBlob.empty();
|
|
18128
|
-
}
|
|
18129
|
-
}
|
|
18130
|
-
|
|
18131
17635
|
var index = /*#__PURE__*/Object.freeze({
|
|
18132
17636
|
__proto__: null,
|
|
18133
17637
|
Preimages: Preimages,
|
|
18134
17638
|
get PreimagesErrorCode () { return PreimagesErrorCode; },
|
|
18135
|
-
TransitionHasher: TransitionHasher
|
|
18136
|
-
WorkPackageExecutor: WorkPackageExecutor
|
|
17639
|
+
TransitionHasher: TransitionHasher
|
|
18137
17640
|
});
|
|
18138
17641
|
|
|
18139
|
-
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$
|
|
17642
|
+
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$p as crypto, index$d as database, index$c as erasure_coding, index$a as fuzz_proto, index$o as hash, index$9 as jam_host_calls, index$k as json_parser, index$i as logger, index$8 as mmr, index$r as numbers, index$t as ordering, index$3 as pvm, index$6 as pvm_host_calls, index$7 as pvm_interpreter, index$4 as pvm_program, index$5 as pvm_spi_decoder, index$2 as shuffling, index$g as state, index$1 as state_json, index$e as state_merkleization, index as transition, index$f as trie, index$u as utils };
|