@typeberry/lib 0.1.2-ef67dce → 0.1.3-0eba10b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +1254 -1466
- package/index.d.ts +1984 -1432
- package/index.js +1235 -1448
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -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
|
};
|
|
@@ -560,7 +576,7 @@ function isResult(x) {
|
|
|
560
576
|
* as an afterthought.
|
|
561
577
|
*/
|
|
562
578
|
|
|
563
|
-
var index$
|
|
579
|
+
var index$u = /*#__PURE__*/Object.freeze({
|
|
564
580
|
__proto__: null,
|
|
565
581
|
get CURRENT_SUITE () { return CURRENT_SUITE; },
|
|
566
582
|
get CURRENT_VERSION () { return CURRENT_VERSION; },
|
|
@@ -569,6 +585,7 @@ var index$s = /*#__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$s = /*#__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;
|
|
@@ -714,7 +732,7 @@ class Ordering {
|
|
|
714
732
|
}
|
|
715
733
|
}
|
|
716
734
|
|
|
717
|
-
var index$
|
|
735
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
718
736
|
__proto__: null,
|
|
719
737
|
Ordering: Ordering
|
|
720
738
|
});
|
|
@@ -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. */
|
|
@@ -965,7 +983,7 @@ function u8ArraySameLengthEqual(self, other) {
|
|
|
965
983
|
}
|
|
966
984
|
const bytesBlobComparator = (a, b) => a.compare(b);
|
|
967
985
|
|
|
968
|
-
var index$
|
|
986
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
969
987
|
__proto__: null,
|
|
970
988
|
BitVec: BitVec,
|
|
971
989
|
Bytes: Bytes,
|
|
@@ -1067,7 +1085,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
|
|
|
1067
1085
|
/** Get the biggest value between U64 a and values given as input parameters. */
|
|
1068
1086
|
const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
|
|
1069
1087
|
|
|
1070
|
-
var index$
|
|
1088
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
1071
1089
|
__proto__: null,
|
|
1072
1090
|
isU16: isU16,
|
|
1073
1091
|
isU32: isU32,
|
|
@@ -1944,13 +1962,15 @@ function validateLength(range, length, context) {
|
|
|
1944
1962
|
|
|
1945
1963
|
/** A caching wrapper for either object or sequence item. */
|
|
1946
1964
|
class ViewField {
|
|
1965
|
+
name;
|
|
1947
1966
|
getView;
|
|
1948
1967
|
getValue;
|
|
1949
1968
|
getEncoded;
|
|
1950
1969
|
cachedValue;
|
|
1951
1970
|
cachedView;
|
|
1952
1971
|
cachedBlob;
|
|
1953
|
-
constructor(getView, getValue, getEncoded) {
|
|
1972
|
+
constructor(name, getView, getValue, getEncoded) {
|
|
1973
|
+
this.name = name;
|
|
1954
1974
|
this.getView = getView;
|
|
1955
1975
|
this.getValue = getValue;
|
|
1956
1976
|
this.getEncoded = getEncoded;
|
|
@@ -1976,6 +1996,9 @@ class ViewField {
|
|
|
1976
1996
|
}
|
|
1977
1997
|
return this.cachedBlob;
|
|
1978
1998
|
}
|
|
1999
|
+
toString() {
|
|
2000
|
+
return `ViewField<${this.name}>`;
|
|
2001
|
+
}
|
|
1979
2002
|
}
|
|
1980
2003
|
/**
|
|
1981
2004
|
* A base class for all the lazy views.
|
|
@@ -2050,7 +2073,7 @@ class ObjectView {
|
|
|
2050
2073
|
const fieldDecoder = skipper.decoder.clone();
|
|
2051
2074
|
const field = this.descriptorsKeys[i];
|
|
2052
2075
|
const type = this.descriptors[field];
|
|
2053
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2076
|
+
lastItem = new ViewField(`${this.toString()}.${String(field)}`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2054
2077
|
// skip the field
|
|
2055
2078
|
type.skip(skipper);
|
|
2056
2079
|
// cache data
|
|
@@ -2062,6 +2085,9 @@ class ObjectView {
|
|
|
2062
2085
|
}
|
|
2063
2086
|
return lastItem;
|
|
2064
2087
|
}
|
|
2088
|
+
toString() {
|
|
2089
|
+
return `View<${this.materializedConstructor.name}>(cache: ${this.cache.size})`;
|
|
2090
|
+
}
|
|
2065
2091
|
}
|
|
2066
2092
|
/**
|
|
2067
2093
|
* A lazy-evaluated decoder of a sequence.
|
|
@@ -2150,7 +2176,7 @@ class SequenceView {
|
|
|
2150
2176
|
// create new cached prop
|
|
2151
2177
|
const fieldDecoder = skipper.decoder.clone();
|
|
2152
2178
|
const type = this.descriptor;
|
|
2153
|
-
lastItem = new ViewField(() => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2179
|
+
lastItem = new ViewField(`${this.toString()}[${index}]`, () => type.View.decode(fieldDecoder.clone()), () => type.decode(fieldDecoder.clone()), () => type.skipEncoded(fieldDecoder.clone()));
|
|
2154
2180
|
// skip the field
|
|
2155
2181
|
type.skip(skipper);
|
|
2156
2182
|
// cache data
|
|
@@ -2162,6 +2188,9 @@ class SequenceView {
|
|
|
2162
2188
|
}
|
|
2163
2189
|
return lastItem;
|
|
2164
2190
|
}
|
|
2191
|
+
toString() {
|
|
2192
|
+
return `SequenceView<${this.descriptor.name}>(cache: ${this.cache.size})`;
|
|
2193
|
+
}
|
|
2165
2194
|
}
|
|
2166
2195
|
|
|
2167
2196
|
/**
|
|
@@ -2477,7 +2506,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
|
|
|
2477
2506
|
}, skipper);
|
|
2478
2507
|
}
|
|
2479
2508
|
|
|
2480
|
-
var index$
|
|
2509
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
2481
2510
|
__proto__: null,
|
|
2482
2511
|
Decoder: Decoder,
|
|
2483
2512
|
Descriptor: Descriptor,
|
|
@@ -3578,7 +3607,7 @@ async function verify(input) {
|
|
|
3578
3607
|
return Promise.resolve([]);
|
|
3579
3608
|
}
|
|
3580
3609
|
const dataLength = input.reduce((acc, { message, key, signature }) => acc + key.length + signature.length + message.length + 1, 0);
|
|
3581
|
-
const data =
|
|
3610
|
+
const data = safeAllocUint8Array(dataLength);
|
|
3582
3611
|
let offset = 0;
|
|
3583
3612
|
for (const { key, message, signature } of input) {
|
|
3584
3613
|
data.set(key.raw, offset);
|
|
@@ -3625,823 +3654,75 @@ var ed25519 = /*#__PURE__*/Object.freeze({
|
|
|
3625
3654
|
verifyBatch: verifyBatch
|
|
3626
3655
|
});
|
|
3627
3656
|
|
|
3657
|
+
const SEED_SIZE = 32;
|
|
3658
|
+
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
3659
|
+
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
3628
3660
|
/**
|
|
3629
|
-
*
|
|
3630
|
-
*
|
|
3631
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
3661
|
+
* JIP-5: Secret key derivation
|
|
3632
3662
|
*
|
|
3633
|
-
*/
|
|
3634
|
-
const HASH_SIZE = 32;
|
|
3635
|
-
/** A hash without last byte (useful for trie representation). */
|
|
3636
|
-
const TRUNCATED_HASH_SIZE = 31;
|
|
3637
|
-
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
3663
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
3638
3664
|
/**
|
|
3639
|
-
*
|
|
3640
|
-
*
|
|
3641
|
-
* After calculating the hash these two should be passed together to avoid
|
|
3642
|
-
* unnecessary re-hashing of the data.
|
|
3665
|
+
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
3666
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
3643
3667
|
*/
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
constructor(hash, data) {
|
|
3648
|
-
super();
|
|
3649
|
-
this.hash = hash;
|
|
3650
|
-
this.data = data;
|
|
3651
|
-
}
|
|
3668
|
+
function trivialSeed(s) {
|
|
3669
|
+
const s_le = u32AsLeBytes(s);
|
|
3670
|
+
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();
|
|
3652
3671
|
}
|
|
3653
3672
|
/**
|
|
3654
|
-
*
|
|
3673
|
+
* Derives a Ed25519 secret key from a seed.
|
|
3674
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
3655
3675
|
*/
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
constructor(hash, data, encoded) {
|
|
3659
|
-
super(hash, data);
|
|
3660
|
-
this.encoded = encoded;
|
|
3661
|
-
}
|
|
3662
|
-
}
|
|
3663
|
-
|
|
3664
|
-
/** The simplest allocator returning just a fresh copy of bytes each time. */
|
|
3665
|
-
class SimpleAllocator {
|
|
3666
|
-
emptyHash() {
|
|
3667
|
-
return Bytes.zero(HASH_SIZE);
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
/** An allocator that works by allocating larger (continuous) pages of memory. */
|
|
3671
|
-
class PageAllocator {
|
|
3672
|
-
hashesPerPage;
|
|
3673
|
-
page = new Uint8Array(0);
|
|
3674
|
-
currentHash = 0;
|
|
3675
|
-
// TODO [ToDr] Benchmark the performance!
|
|
3676
|
-
constructor(hashesPerPage) {
|
|
3677
|
-
this.hashesPerPage = hashesPerPage;
|
|
3678
|
-
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
3679
|
-
this.resetPage();
|
|
3680
|
-
}
|
|
3681
|
-
resetPage() {
|
|
3682
|
-
const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
|
|
3683
|
-
this.currentHash = 0;
|
|
3684
|
-
this.page = new Uint8Array(pageSizeBytes);
|
|
3685
|
-
}
|
|
3686
|
-
emptyHash() {
|
|
3687
|
-
const startIdx = this.currentHash * HASH_SIZE;
|
|
3688
|
-
const endIdx = startIdx + HASH_SIZE;
|
|
3689
|
-
this.currentHash += 1;
|
|
3690
|
-
if (this.currentHash >= this.hashesPerPage) {
|
|
3691
|
-
this.resetPage();
|
|
3692
|
-
}
|
|
3693
|
-
return Bytes.fromBlob(this.page.subarray(startIdx, endIdx), HASH_SIZE);
|
|
3694
|
-
}
|
|
3695
|
-
}
|
|
3696
|
-
const defaultAllocator = new SimpleAllocator();
|
|
3697
|
-
|
|
3698
|
-
function getDefaultExportFromCjs (x) {
|
|
3699
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3700
|
-
}
|
|
3701
|
-
|
|
3702
|
-
var blake2b$3 = {exports: {}};
|
|
3703
|
-
|
|
3704
|
-
var nanoassert;
|
|
3705
|
-
var hasRequiredNanoassert;
|
|
3706
|
-
|
|
3707
|
-
function requireNanoassert () {
|
|
3708
|
-
if (hasRequiredNanoassert) return nanoassert;
|
|
3709
|
-
hasRequiredNanoassert = 1;
|
|
3710
|
-
nanoassert = assert;
|
|
3711
|
-
|
|
3712
|
-
class AssertionError extends Error {}
|
|
3713
|
-
AssertionError.prototype.name = 'AssertionError';
|
|
3714
|
-
|
|
3715
|
-
/**
|
|
3716
|
-
* Minimal assert function
|
|
3717
|
-
* @param {any} t Value to check if falsy
|
|
3718
|
-
* @param {string=} m Optional assertion error message
|
|
3719
|
-
* @throws {AssertionError}
|
|
3720
|
-
*/
|
|
3721
|
-
function assert (t, m) {
|
|
3722
|
-
if (!t) {
|
|
3723
|
-
var err = new AssertionError(m);
|
|
3724
|
-
if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
|
|
3725
|
-
throw err
|
|
3726
|
-
}
|
|
3727
|
-
}
|
|
3728
|
-
return nanoassert;
|
|
3729
|
-
}
|
|
3730
|
-
|
|
3731
|
-
var blake2bWasm = {exports: {}};
|
|
3732
|
-
|
|
3733
|
-
var b4a;
|
|
3734
|
-
var hasRequiredB4a;
|
|
3735
|
-
|
|
3736
|
-
function requireB4a () {
|
|
3737
|
-
if (hasRequiredB4a) return b4a;
|
|
3738
|
-
hasRequiredB4a = 1;
|
|
3739
|
-
function isBuffer (value) {
|
|
3740
|
-
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
3741
|
-
}
|
|
3742
|
-
|
|
3743
|
-
function isEncoding (encoding) {
|
|
3744
|
-
return Buffer.isEncoding(encoding)
|
|
3745
|
-
}
|
|
3746
|
-
|
|
3747
|
-
function alloc (size, fill, encoding) {
|
|
3748
|
-
return Buffer.alloc(size, fill, encoding)
|
|
3749
|
-
}
|
|
3750
|
-
|
|
3751
|
-
function allocUnsafe (size) {
|
|
3752
|
-
return Buffer.allocUnsafe(size)
|
|
3753
|
-
}
|
|
3754
|
-
|
|
3755
|
-
function allocUnsafeSlow (size) {
|
|
3756
|
-
return Buffer.allocUnsafeSlow(size)
|
|
3757
|
-
}
|
|
3758
|
-
|
|
3759
|
-
function byteLength (string, encoding) {
|
|
3760
|
-
return Buffer.byteLength(string, encoding)
|
|
3761
|
-
}
|
|
3762
|
-
|
|
3763
|
-
function compare (a, b) {
|
|
3764
|
-
return Buffer.compare(a, b)
|
|
3765
|
-
}
|
|
3766
|
-
|
|
3767
|
-
function concat (buffers, totalLength) {
|
|
3768
|
-
return Buffer.concat(buffers, totalLength)
|
|
3769
|
-
}
|
|
3770
|
-
|
|
3771
|
-
function copy (source, target, targetStart, start, end) {
|
|
3772
|
-
return toBuffer(source).copy(target, targetStart, start, end)
|
|
3773
|
-
}
|
|
3774
|
-
|
|
3775
|
-
function equals (a, b) {
|
|
3776
|
-
return toBuffer(a).equals(b)
|
|
3777
|
-
}
|
|
3778
|
-
|
|
3779
|
-
function fill (buffer, value, offset, end, encoding) {
|
|
3780
|
-
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
3781
|
-
}
|
|
3782
|
-
|
|
3783
|
-
function from (value, encodingOrOffset, length) {
|
|
3784
|
-
return Buffer.from(value, encodingOrOffset, length)
|
|
3785
|
-
}
|
|
3786
|
-
|
|
3787
|
-
function includes (buffer, value, byteOffset, encoding) {
|
|
3788
|
-
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
3789
|
-
}
|
|
3790
|
-
|
|
3791
|
-
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
3792
|
-
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
3793
|
-
}
|
|
3794
|
-
|
|
3795
|
-
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
3796
|
-
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
3797
|
-
}
|
|
3798
|
-
|
|
3799
|
-
function swap16 (buffer) {
|
|
3800
|
-
return toBuffer(buffer).swap16()
|
|
3801
|
-
}
|
|
3802
|
-
|
|
3803
|
-
function swap32 (buffer) {
|
|
3804
|
-
return toBuffer(buffer).swap32()
|
|
3805
|
-
}
|
|
3806
|
-
|
|
3807
|
-
function swap64 (buffer) {
|
|
3808
|
-
return toBuffer(buffer).swap64()
|
|
3809
|
-
}
|
|
3810
|
-
|
|
3811
|
-
function toBuffer (buffer) {
|
|
3812
|
-
if (Buffer.isBuffer(buffer)) return buffer
|
|
3813
|
-
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
3814
|
-
}
|
|
3815
|
-
|
|
3816
|
-
function toString (buffer, encoding, start, end) {
|
|
3817
|
-
return toBuffer(buffer).toString(encoding, start, end)
|
|
3818
|
-
}
|
|
3819
|
-
|
|
3820
|
-
function write (buffer, string, offset, length, encoding) {
|
|
3821
|
-
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
3822
|
-
}
|
|
3823
|
-
|
|
3824
|
-
function writeDoubleLE (buffer, value, offset) {
|
|
3825
|
-
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
3826
|
-
}
|
|
3827
|
-
|
|
3828
|
-
function writeFloatLE (buffer, value, offset) {
|
|
3829
|
-
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
3830
|
-
}
|
|
3831
|
-
|
|
3832
|
-
function writeUInt32LE (buffer, value, offset) {
|
|
3833
|
-
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
3834
|
-
}
|
|
3835
|
-
|
|
3836
|
-
function writeInt32LE (buffer, value, offset) {
|
|
3837
|
-
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
3838
|
-
}
|
|
3839
|
-
|
|
3840
|
-
function readDoubleLE (buffer, offset) {
|
|
3841
|
-
return toBuffer(buffer).readDoubleLE(offset)
|
|
3842
|
-
}
|
|
3843
|
-
|
|
3844
|
-
function readFloatLE (buffer, offset) {
|
|
3845
|
-
return toBuffer(buffer).readFloatLE(offset)
|
|
3846
|
-
}
|
|
3847
|
-
|
|
3848
|
-
function readUInt32LE (buffer, offset) {
|
|
3849
|
-
return toBuffer(buffer).readUInt32LE(offset)
|
|
3850
|
-
}
|
|
3851
|
-
|
|
3852
|
-
function readInt32LE (buffer, offset) {
|
|
3853
|
-
return toBuffer(buffer).readInt32LE(offset)
|
|
3854
|
-
}
|
|
3855
|
-
|
|
3856
|
-
b4a = {
|
|
3857
|
-
isBuffer,
|
|
3858
|
-
isEncoding,
|
|
3859
|
-
alloc,
|
|
3860
|
-
allocUnsafe,
|
|
3861
|
-
allocUnsafeSlow,
|
|
3862
|
-
byteLength,
|
|
3863
|
-
compare,
|
|
3864
|
-
concat,
|
|
3865
|
-
copy,
|
|
3866
|
-
equals,
|
|
3867
|
-
fill,
|
|
3868
|
-
from,
|
|
3869
|
-
includes,
|
|
3870
|
-
indexOf,
|
|
3871
|
-
lastIndexOf,
|
|
3872
|
-
swap16,
|
|
3873
|
-
swap32,
|
|
3874
|
-
swap64,
|
|
3875
|
-
toBuffer,
|
|
3876
|
-
toString,
|
|
3877
|
-
write,
|
|
3878
|
-
writeDoubleLE,
|
|
3879
|
-
writeFloatLE,
|
|
3880
|
-
writeUInt32LE,
|
|
3881
|
-
writeInt32LE,
|
|
3882
|
-
readDoubleLE,
|
|
3883
|
-
readFloatLE,
|
|
3884
|
-
readUInt32LE,
|
|
3885
|
-
readInt32LE
|
|
3886
|
-
};
|
|
3887
|
-
return b4a;
|
|
3888
|
-
}
|
|
3889
|
-
|
|
3890
|
-
var blake2b$2;
|
|
3891
|
-
var hasRequiredBlake2b$1;
|
|
3892
|
-
|
|
3893
|
-
function requireBlake2b$1 () {
|
|
3894
|
-
if (hasRequiredBlake2b$1) return blake2b$2;
|
|
3895
|
-
hasRequiredBlake2b$1 = 1;
|
|
3896
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3897
|
-
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3898
|
-
};
|
|
3899
|
-
var __toBinary = /* @__PURE__ */ (() => {
|
|
3900
|
-
var table = new Uint8Array(128);
|
|
3901
|
-
for (var i = 0; i < 64; i++)
|
|
3902
|
-
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
3903
|
-
return (base64) => {
|
|
3904
|
-
var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
3905
|
-
for (var i2 = 0, j = 0; i2 < n; ) {
|
|
3906
|
-
var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
3907
|
-
var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
3908
|
-
bytes2[j++] = c0 << 2 | c1 >> 4;
|
|
3909
|
-
bytes2[j++] = c1 << 4 | c2 >> 2;
|
|
3910
|
-
bytes2[j++] = c2 << 6 | c3;
|
|
3911
|
-
}
|
|
3912
|
-
return bytes2;
|
|
3913
|
-
};
|
|
3914
|
-
})();
|
|
3915
|
-
|
|
3916
|
-
// wasm-binary:./blake2b.wat
|
|
3917
|
-
var require_blake2b = __commonJS({
|
|
3918
|
-
"wasm-binary:./blake2b.wat"(exports2, module2) {
|
|
3919
|
-
module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFqISEgAEGIAWohIiAAQZABaiEjIABBmAFqISQgAEGgA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WfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
|
|
3920
|
-
}
|
|
3921
|
-
});
|
|
3922
|
-
|
|
3923
|
-
// wasm-module:./blake2b.wat
|
|
3924
|
-
var bytes = require_blake2b();
|
|
3925
|
-
var compiled = WebAssembly.compile(bytes);
|
|
3926
|
-
blake2b$2 = async (imports) => {
|
|
3927
|
-
const instance = await WebAssembly.instantiate(await compiled, imports);
|
|
3928
|
-
return instance.exports;
|
|
3929
|
-
};
|
|
3930
|
-
return blake2b$2;
|
|
3931
|
-
}
|
|
3932
|
-
|
|
3933
|
-
var hasRequiredBlake2bWasm;
|
|
3934
|
-
|
|
3935
|
-
function requireBlake2bWasm () {
|
|
3936
|
-
if (hasRequiredBlake2bWasm) return blake2bWasm.exports;
|
|
3937
|
-
hasRequiredBlake2bWasm = 1;
|
|
3938
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
3939
|
-
var b4a = /*@__PURE__*/ requireB4a();
|
|
3940
|
-
|
|
3941
|
-
var wasm = null;
|
|
3942
|
-
var wasmPromise = typeof WebAssembly !== "undefined" && /*@__PURE__*/ requireBlake2b$1()().then(mod => {
|
|
3943
|
-
wasm = mod;
|
|
3944
|
-
});
|
|
3945
|
-
|
|
3946
|
-
var head = 64;
|
|
3947
|
-
var freeList = [];
|
|
3948
|
-
|
|
3949
|
-
blake2bWasm.exports = Blake2b;
|
|
3950
|
-
var BYTES_MIN = blake2bWasm.exports.BYTES_MIN = 16;
|
|
3951
|
-
var BYTES_MAX = blake2bWasm.exports.BYTES_MAX = 64;
|
|
3952
|
-
blake2bWasm.exports.BYTES = 32;
|
|
3953
|
-
var KEYBYTES_MIN = blake2bWasm.exports.KEYBYTES_MIN = 16;
|
|
3954
|
-
var KEYBYTES_MAX = blake2bWasm.exports.KEYBYTES_MAX = 64;
|
|
3955
|
-
blake2bWasm.exports.KEYBYTES = 32;
|
|
3956
|
-
var SALTBYTES = blake2bWasm.exports.SALTBYTES = 16;
|
|
3957
|
-
var PERSONALBYTES = blake2bWasm.exports.PERSONALBYTES = 16;
|
|
3958
|
-
|
|
3959
|
-
function Blake2b (digestLength, key, salt, personal, noAssert) {
|
|
3960
|
-
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
|
|
3961
|
-
if (!wasm) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
|
|
3962
|
-
if (!digestLength) digestLength = 32;
|
|
3963
|
-
|
|
3964
|
-
if (noAssert !== true) {
|
|
3965
|
-
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength);
|
|
3966
|
-
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength);
|
|
3967
|
-
if (key != null) {
|
|
3968
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
3969
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
3970
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at least ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
3971
|
-
}
|
|
3972
|
-
if (salt != null) {
|
|
3973
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
3974
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
3975
|
-
}
|
|
3976
|
-
if (personal != null) {
|
|
3977
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
3978
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
3979
|
-
}
|
|
3980
|
-
}
|
|
3981
|
-
|
|
3982
|
-
if (!freeList.length) {
|
|
3983
|
-
freeList.push(head);
|
|
3984
|
-
head += 216;
|
|
3985
|
-
}
|
|
3986
|
-
|
|
3987
|
-
this.digestLength = digestLength;
|
|
3988
|
-
this.finalized = false;
|
|
3989
|
-
this.pointer = freeList.pop();
|
|
3990
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
3991
|
-
|
|
3992
|
-
this._memory.fill(0, 0, 64);
|
|
3993
|
-
this._memory[0] = this.digestLength;
|
|
3994
|
-
this._memory[1] = key ? key.length : 0;
|
|
3995
|
-
this._memory[2] = 1; // fanout
|
|
3996
|
-
this._memory[3] = 1; // depth
|
|
3997
|
-
|
|
3998
|
-
if (salt) this._memory.set(salt, 32);
|
|
3999
|
-
if (personal) this._memory.set(personal, 48);
|
|
4000
|
-
|
|
4001
|
-
if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216); // we need 216 bytes for the state
|
|
4002
|
-
wasm.blake2b_init(this.pointer, this.digestLength);
|
|
4003
|
-
|
|
4004
|
-
if (key) {
|
|
4005
|
-
this.update(key);
|
|
4006
|
-
this._memory.fill(0, head, head + key.length); // whiteout key
|
|
4007
|
-
this._memory[this.pointer + 200] = 128;
|
|
4008
|
-
}
|
|
4009
|
-
}
|
|
4010
|
-
|
|
4011
|
-
Blake2b.prototype._realloc = function (size) {
|
|
4012
|
-
wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
|
|
4013
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4014
|
-
};
|
|
4015
|
-
|
|
4016
|
-
Blake2b.prototype.update = function (input) {
|
|
4017
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4018
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4019
|
-
|
|
4020
|
-
if (head + input.length > this._memory.length) this._realloc(head + input.length);
|
|
4021
|
-
this._memory.set(input, head);
|
|
4022
|
-
wasm.blake2b_update(this.pointer, head, head + input.length);
|
|
4023
|
-
return this
|
|
4024
|
-
};
|
|
4025
|
-
|
|
4026
|
-
Blake2b.prototype.digest = function (enc) {
|
|
4027
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4028
|
-
this.finalized = true;
|
|
4029
|
-
|
|
4030
|
-
freeList.push(this.pointer);
|
|
4031
|
-
wasm.blake2b_final(this.pointer);
|
|
4032
|
-
|
|
4033
|
-
if (!enc || enc === 'binary') {
|
|
4034
|
-
return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4035
|
-
}
|
|
4036
|
-
|
|
4037
|
-
if (typeof enc === 'string') {
|
|
4038
|
-
return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4039
|
-
}
|
|
4040
|
-
|
|
4041
|
-
assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
|
|
4042
|
-
for (var i = 0; i < this.digestLength; i++) {
|
|
4043
|
-
enc[i] = this._memory[this.pointer + 128 + i];
|
|
4044
|
-
}
|
|
4045
|
-
|
|
4046
|
-
return enc
|
|
4047
|
-
};
|
|
4048
|
-
|
|
4049
|
-
// libsodium compat
|
|
4050
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4051
|
-
|
|
4052
|
-
Blake2b.WASM = wasm;
|
|
4053
|
-
Blake2b.SUPPORTED = typeof WebAssembly !== 'undefined';
|
|
4054
|
-
|
|
4055
|
-
Blake2b.ready = function (cb) {
|
|
4056
|
-
if (!cb) cb = noop;
|
|
4057
|
-
if (!wasmPromise) return cb(new Error('WebAssembly not supported'))
|
|
4058
|
-
return wasmPromise.then(() => cb(), cb)
|
|
4059
|
-
};
|
|
4060
|
-
|
|
4061
|
-
Blake2b.prototype.ready = Blake2b.ready;
|
|
4062
|
-
|
|
4063
|
-
Blake2b.prototype.getPartialHash = function () {
|
|
4064
|
-
return this._memory.slice(this.pointer, this.pointer + 216);
|
|
4065
|
-
};
|
|
4066
|
-
|
|
4067
|
-
Blake2b.prototype.setPartialHash = function (ph) {
|
|
4068
|
-
this._memory.set(ph, this.pointer);
|
|
4069
|
-
};
|
|
4070
|
-
|
|
4071
|
-
function noop () {}
|
|
4072
|
-
return blake2bWasm.exports;
|
|
4073
|
-
}
|
|
4074
|
-
|
|
4075
|
-
var hasRequiredBlake2b;
|
|
4076
|
-
|
|
4077
|
-
function requireBlake2b () {
|
|
4078
|
-
if (hasRequiredBlake2b) return blake2b$3.exports;
|
|
4079
|
-
hasRequiredBlake2b = 1;
|
|
4080
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
4081
|
-
var b2wasm = /*@__PURE__*/ requireBlake2bWasm();
|
|
4082
|
-
|
|
4083
|
-
// 64-bit unsigned addition
|
|
4084
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
4085
|
-
// v should be a Uint32Array
|
|
4086
|
-
function ADD64AA (v, a, b) {
|
|
4087
|
-
var o0 = v[a] + v[b];
|
|
4088
|
-
var o1 = v[a + 1] + v[b + 1];
|
|
4089
|
-
if (o0 >= 0x100000000) {
|
|
4090
|
-
o1++;
|
|
4091
|
-
}
|
|
4092
|
-
v[a] = o0;
|
|
4093
|
-
v[a + 1] = o1;
|
|
4094
|
-
}
|
|
4095
|
-
|
|
4096
|
-
// 64-bit unsigned addition
|
|
4097
|
-
// Sets v[a,a+1] += b
|
|
4098
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
4099
|
-
function ADD64AC (v, a, b0, b1) {
|
|
4100
|
-
var o0 = v[a] + b0;
|
|
4101
|
-
if (b0 < 0) {
|
|
4102
|
-
o0 += 0x100000000;
|
|
4103
|
-
}
|
|
4104
|
-
var o1 = v[a + 1] + b1;
|
|
4105
|
-
if (o0 >= 0x100000000) {
|
|
4106
|
-
o1++;
|
|
4107
|
-
}
|
|
4108
|
-
v[a] = o0;
|
|
4109
|
-
v[a + 1] = o1;
|
|
4110
|
-
}
|
|
4111
|
-
|
|
4112
|
-
// Little-endian byte access
|
|
4113
|
-
function B2B_GET32 (arr, i) {
|
|
4114
|
-
return (arr[i] ^
|
|
4115
|
-
(arr[i + 1] << 8) ^
|
|
4116
|
-
(arr[i + 2] << 16) ^
|
|
4117
|
-
(arr[i + 3] << 24))
|
|
4118
|
-
}
|
|
4119
|
-
|
|
4120
|
-
// G Mixing function
|
|
4121
|
-
// The ROTRs are inlined for speed
|
|
4122
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
4123
|
-
var x0 = m[ix];
|
|
4124
|
-
var x1 = m[ix + 1];
|
|
4125
|
-
var y0 = m[iy];
|
|
4126
|
-
var y1 = m[iy + 1];
|
|
4127
|
-
|
|
4128
|
-
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
4129
|
-
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
4130
|
-
|
|
4131
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
4132
|
-
var xor0 = v[d] ^ v[a];
|
|
4133
|
-
var xor1 = v[d + 1] ^ v[a + 1];
|
|
4134
|
-
v[d] = xor1;
|
|
4135
|
-
v[d + 1] = xor0;
|
|
4136
|
-
|
|
4137
|
-
ADD64AA(v, c, d);
|
|
4138
|
-
|
|
4139
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
4140
|
-
xor0 = v[b] ^ v[c];
|
|
4141
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4142
|
-
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
4143
|
-
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
4144
|
-
|
|
4145
|
-
ADD64AA(v, a, b);
|
|
4146
|
-
ADD64AC(v, a, y0, y1);
|
|
4147
|
-
|
|
4148
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
4149
|
-
xor0 = v[d] ^ v[a];
|
|
4150
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
4151
|
-
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
4152
|
-
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
4153
|
-
|
|
4154
|
-
ADD64AA(v, c, d);
|
|
4155
|
-
|
|
4156
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
4157
|
-
xor0 = v[b] ^ v[c];
|
|
4158
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4159
|
-
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
4160
|
-
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
4161
|
-
}
|
|
4162
|
-
|
|
4163
|
-
// Initialization Vector
|
|
4164
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
4165
|
-
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
4166
|
-
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
4167
|
-
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
4168
|
-
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
4169
|
-
]);
|
|
4170
|
-
|
|
4171
|
-
var SIGMA8 = [
|
|
4172
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4173
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
4174
|
-
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
4175
|
-
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
4176
|
-
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
4177
|
-
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
4178
|
-
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
4179
|
-
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
4180
|
-
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
4181
|
-
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
4182
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4183
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
4184
|
-
];
|
|
4185
|
-
|
|
4186
|
-
// These are offsets into a uint64 buffer.
|
|
4187
|
-
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
4188
|
-
// because this is Javascript and we don't have uint64s
|
|
4189
|
-
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }));
|
|
4190
|
-
|
|
4191
|
-
// Compression function. 'last' flag indicates last block.
|
|
4192
|
-
// Note we're representing 16 uint64s as 32 uint32s
|
|
4193
|
-
var v = new Uint32Array(32);
|
|
4194
|
-
var m = new Uint32Array(32);
|
|
4195
|
-
function blake2bCompress (ctx, last) {
|
|
4196
|
-
var i = 0;
|
|
4197
|
-
|
|
4198
|
-
// init work variables
|
|
4199
|
-
for (i = 0; i < 16; i++) {
|
|
4200
|
-
v[i] = ctx.h[i];
|
|
4201
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
4202
|
-
}
|
|
4203
|
-
|
|
4204
|
-
// low 64 bits of offset
|
|
4205
|
-
v[24] = v[24] ^ ctx.t;
|
|
4206
|
-
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
4207
|
-
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
4208
|
-
|
|
4209
|
-
// last block flag set ?
|
|
4210
|
-
if (last) {
|
|
4211
|
-
v[28] = ~v[28];
|
|
4212
|
-
v[29] = ~v[29];
|
|
4213
|
-
}
|
|
4214
|
-
|
|
4215
|
-
// get little-endian words
|
|
4216
|
-
for (i = 0; i < 32; i++) {
|
|
4217
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
4218
|
-
}
|
|
4219
|
-
|
|
4220
|
-
// twelve rounds of mixing
|
|
4221
|
-
for (i = 0; i < 12; i++) {
|
|
4222
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
4223
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
4224
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
4225
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
4226
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
4227
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
4228
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
4229
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
4230
|
-
}
|
|
4231
|
-
|
|
4232
|
-
for (i = 0; i < 16; i++) {
|
|
4233
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
4234
|
-
}
|
|
4235
|
-
}
|
|
4236
|
-
|
|
4237
|
-
// reusable parameter_block
|
|
4238
|
-
var parameter_block = new Uint8Array([
|
|
4239
|
-
0, 0, 0, 0, // 0: outlen, keylen, fanout, depth
|
|
4240
|
-
0, 0, 0, 0, // 4: leaf length, sequential mode
|
|
4241
|
-
0, 0, 0, 0, // 8: node offset
|
|
4242
|
-
0, 0, 0, 0, // 12: node offset
|
|
4243
|
-
0, 0, 0, 0, // 16: node depth, inner length, rfu
|
|
4244
|
-
0, 0, 0, 0, // 20: rfu
|
|
4245
|
-
0, 0, 0, 0, // 24: rfu
|
|
4246
|
-
0, 0, 0, 0, // 28: rfu
|
|
4247
|
-
0, 0, 0, 0, // 32: salt
|
|
4248
|
-
0, 0, 0, 0, // 36: salt
|
|
4249
|
-
0, 0, 0, 0, // 40: salt
|
|
4250
|
-
0, 0, 0, 0, // 44: salt
|
|
4251
|
-
0, 0, 0, 0, // 48: personal
|
|
4252
|
-
0, 0, 0, 0, // 52: personal
|
|
4253
|
-
0, 0, 0, 0, // 56: personal
|
|
4254
|
-
0, 0, 0, 0 // 60: personal
|
|
4255
|
-
]);
|
|
4256
|
-
|
|
4257
|
-
// Creates a BLAKE2b hashing context
|
|
4258
|
-
// Requires an output length between 1 and 64 bytes
|
|
4259
|
-
// Takes an optional Uint8Array key
|
|
4260
|
-
function Blake2b (outlen, key, salt, personal) {
|
|
4261
|
-
// zero out parameter_block before usage
|
|
4262
|
-
parameter_block.fill(0);
|
|
4263
|
-
// state, 'param block'
|
|
4264
|
-
|
|
4265
|
-
this.b = new Uint8Array(128);
|
|
4266
|
-
this.h = new Uint32Array(16);
|
|
4267
|
-
this.t = 0; // input count
|
|
4268
|
-
this.c = 0; // pointer within buffer
|
|
4269
|
-
this.outlen = outlen; // output length in bytes
|
|
4270
|
-
|
|
4271
|
-
parameter_block[0] = outlen;
|
|
4272
|
-
if (key) parameter_block[1] = key.length;
|
|
4273
|
-
parameter_block[2] = 1; // fanout
|
|
4274
|
-
parameter_block[3] = 1; // depth
|
|
4275
|
-
|
|
4276
|
-
if (salt) parameter_block.set(salt, 32);
|
|
4277
|
-
if (personal) parameter_block.set(personal, 48);
|
|
4278
|
-
|
|
4279
|
-
// initialize hash state
|
|
4280
|
-
for (var i = 0; i < 16; i++) {
|
|
4281
|
-
this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
|
|
4282
|
-
}
|
|
4283
|
-
|
|
4284
|
-
// key the hash, if applicable
|
|
4285
|
-
if (key) {
|
|
4286
|
-
blake2bUpdate(this, key);
|
|
4287
|
-
// at the end
|
|
4288
|
-
this.c = 128;
|
|
4289
|
-
}
|
|
4290
|
-
}
|
|
4291
|
-
|
|
4292
|
-
Blake2b.prototype.update = function (input) {
|
|
4293
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4294
|
-
blake2bUpdate(this, input);
|
|
4295
|
-
return this
|
|
4296
|
-
};
|
|
4297
|
-
|
|
4298
|
-
Blake2b.prototype.digest = function (out) {
|
|
4299
|
-
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out;
|
|
4300
|
-
assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
|
|
4301
|
-
assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
|
|
4302
|
-
blake2bFinal(this, buf);
|
|
4303
|
-
if (out === 'hex') return hexSlice(buf)
|
|
4304
|
-
return buf
|
|
4305
|
-
};
|
|
4306
|
-
|
|
4307
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4308
|
-
|
|
4309
|
-
Blake2b.ready = function (cb) {
|
|
4310
|
-
b2wasm.ready(function () {
|
|
4311
|
-
cb(); // ignore the error
|
|
4312
|
-
});
|
|
4313
|
-
};
|
|
4314
|
-
|
|
4315
|
-
// Updates a BLAKE2b streaming hash
|
|
4316
|
-
// Requires hash context and Uint8Array (byte array)
|
|
4317
|
-
function blake2bUpdate (ctx, input) {
|
|
4318
|
-
for (var i = 0; i < input.length; i++) {
|
|
4319
|
-
if (ctx.c === 128) { // buffer full ?
|
|
4320
|
-
ctx.t += ctx.c; // add counters
|
|
4321
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
4322
|
-
ctx.c = 0; // counter to zero
|
|
4323
|
-
}
|
|
4324
|
-
ctx.b[ctx.c++] = input[i];
|
|
4325
|
-
}
|
|
4326
|
-
}
|
|
4327
|
-
|
|
4328
|
-
// Completes a BLAKE2b streaming hash
|
|
4329
|
-
// Returns a Uint8Array containing the message digest
|
|
4330
|
-
function blake2bFinal (ctx, out) {
|
|
4331
|
-
ctx.t += ctx.c; // mark last block offset
|
|
4332
|
-
|
|
4333
|
-
while (ctx.c < 128) { // fill up with zeros
|
|
4334
|
-
ctx.b[ctx.c++] = 0;
|
|
4335
|
-
}
|
|
4336
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
4337
|
-
|
|
4338
|
-
for (var i = 0; i < ctx.outlen; i++) {
|
|
4339
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
4340
|
-
}
|
|
4341
|
-
return out
|
|
4342
|
-
}
|
|
4343
|
-
|
|
4344
|
-
function hexSlice (buf) {
|
|
4345
|
-
var str = '';
|
|
4346
|
-
for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
|
|
4347
|
-
return str
|
|
4348
|
-
}
|
|
4349
|
-
|
|
4350
|
-
function toHex (n) {
|
|
4351
|
-
if (n < 16) return '0' + n.toString(16)
|
|
4352
|
-
return n.toString(16)
|
|
4353
|
-
}
|
|
4354
|
-
|
|
4355
|
-
var Proto = Blake2b;
|
|
4356
|
-
|
|
4357
|
-
blake2b$3.exports = function createHash (outlen, key, salt, personal, noAssert) {
|
|
4358
|
-
if (noAssert !== true) {
|
|
4359
|
-
assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen);
|
|
4360
|
-
assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen);
|
|
4361
|
-
if (key != null) {
|
|
4362
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
4363
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
4364
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
4365
|
-
}
|
|
4366
|
-
if (salt != null) {
|
|
4367
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4368
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4369
|
-
}
|
|
4370
|
-
if (personal != null) {
|
|
4371
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4372
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4373
|
-
}
|
|
4374
|
-
}
|
|
4375
|
-
|
|
4376
|
-
return new Proto(outlen, key, salt, personal)
|
|
4377
|
-
};
|
|
4378
|
-
|
|
4379
|
-
blake2b$3.exports.ready = function (cb) {
|
|
4380
|
-
b2wasm.ready(function () { // ignore errors
|
|
4381
|
-
cb();
|
|
4382
|
-
});
|
|
4383
|
-
};
|
|
4384
|
-
|
|
4385
|
-
blake2b$3.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
|
|
4386
|
-
blake2b$3.exports.WASM_LOADED = false;
|
|
4387
|
-
|
|
4388
|
-
var BYTES_MIN = blake2b$3.exports.BYTES_MIN = 16;
|
|
4389
|
-
var BYTES_MAX = blake2b$3.exports.BYTES_MAX = 64;
|
|
4390
|
-
blake2b$3.exports.BYTES = 32;
|
|
4391
|
-
var KEYBYTES_MIN = blake2b$3.exports.KEYBYTES_MIN = 16;
|
|
4392
|
-
var KEYBYTES_MAX = blake2b$3.exports.KEYBYTES_MAX = 64;
|
|
4393
|
-
blake2b$3.exports.KEYBYTES = 32;
|
|
4394
|
-
var SALTBYTES = blake2b$3.exports.SALTBYTES = 16;
|
|
4395
|
-
var PERSONALBYTES = blake2b$3.exports.PERSONALBYTES = 16;
|
|
4396
|
-
|
|
4397
|
-
b2wasm.ready(function (err) {
|
|
4398
|
-
if (!err) {
|
|
4399
|
-
blake2b$3.exports.WASM_LOADED = true;
|
|
4400
|
-
blake2b$3.exports = b2wasm;
|
|
4401
|
-
}
|
|
4402
|
-
});
|
|
4403
|
-
return blake2b$3.exports;
|
|
3676
|
+
function deriveEd25519SecretKey(seed, blake2b) {
|
|
3677
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4404
3678
|
}
|
|
4405
|
-
|
|
4406
|
-
var blake2bExports = /*@__PURE__*/ requireBlake2b();
|
|
4407
|
-
var blake2b$1 = /*@__PURE__*/getDefaultExportFromCjs(blake2bExports);
|
|
4408
|
-
|
|
4409
3679
|
/**
|
|
4410
|
-
*
|
|
4411
|
-
*
|
|
4412
|
-
* If empty array is given a zero-hash is returned.
|
|
3680
|
+
* Derives a Bandersnatch secret key from a seed.
|
|
3681
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4413
3682
|
*/
|
|
4414
|
-
function
|
|
4415
|
-
|
|
4416
|
-
if (r.length === 0) {
|
|
4417
|
-
return out.asOpaque();
|
|
4418
|
-
}
|
|
4419
|
-
const hasher = blake2b$1(HASH_SIZE);
|
|
4420
|
-
for (const v of r) {
|
|
4421
|
-
hasher?.update(v instanceof BytesBlob ? v.raw : v);
|
|
4422
|
-
}
|
|
4423
|
-
hasher?.digest(out.raw);
|
|
4424
|
-
return out.asOpaque();
|
|
3683
|
+
function deriveBandersnatchSecretKey(seed, blake2b) {
|
|
3684
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4425
3685
|
}
|
|
4426
|
-
/**
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
const out = allocator.emptyHash();
|
|
4432
|
-
hasher?.digest(out.raw);
|
|
4433
|
-
return out;
|
|
3686
|
+
/**
|
|
3687
|
+
* Derive Ed25519 public key from secret seed
|
|
3688
|
+
*/
|
|
3689
|
+
async function deriveEd25519PublicKey(seed) {
|
|
3690
|
+
return (await privateKey(seed)).pubKey;
|
|
4434
3691
|
}
|
|
4435
|
-
/**
|
|
4436
|
-
|
|
4437
|
-
|
|
3692
|
+
/**
|
|
3693
|
+
* Derive Bandersnatch public key from secret seed
|
|
3694
|
+
*/
|
|
3695
|
+
function deriveBandersnatchPublicKey(seed) {
|
|
3696
|
+
return publicKey(seed.raw);
|
|
4438
3697
|
}
|
|
4439
3698
|
|
|
4440
|
-
var
|
|
3699
|
+
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
3700
|
+
__proto__: null,
|
|
3701
|
+
SEED_SIZE: SEED_SIZE,
|
|
3702
|
+
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
3703
|
+
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
3704
|
+
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
3705
|
+
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
3706
|
+
trivialSeed: trivialSeed
|
|
3707
|
+
});
|
|
3708
|
+
|
|
3709
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4441
3710
|
__proto__: null,
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
3711
|
+
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
3712
|
+
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
3713
|
+
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
3714
|
+
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
3715
|
+
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
3716
|
+
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
3717
|
+
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
3718
|
+
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
3719
|
+
Ed25519Pair: Ed25519Pair,
|
|
3720
|
+
SEED_SIZE: SEED_SIZE,
|
|
3721
|
+
bandersnatch: bandersnatch,
|
|
3722
|
+
bandersnatchWasm: bandersnatch_exports,
|
|
3723
|
+
ed25519: ed25519,
|
|
3724
|
+
initWasm: initAll,
|
|
3725
|
+
keyDerivation: keyDerivation
|
|
4445
3726
|
});
|
|
4446
3727
|
|
|
4447
3728
|
/*!
|
|
@@ -4802,7 +4083,78 @@ function WASMInterface(binary, hashLength) {
|
|
|
4802
4083
|
|
|
4803
4084
|
new Mutex();
|
|
4804
4085
|
|
|
4086
|
+
var name$j = "blake2b";
|
|
4087
|
+
var data$j = "AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2hfR2V0U3RhdGUABw5IYXNoX0NhbGN1bGF0ZQAIClNUQVRFX1NJWkUDAQrTOAkFAEGACQvrAgIFfwF+AkAgAUEBSA0AAkACQAJAIAFBgAFBACgC4IoBIgJrIgNKDQAgASEEDAELQQBBADYC4IoBAkAgAkH/AEoNACACQeCJAWohBSAAIQRBACEGA0AgBSAELQAAOgAAIARBAWohBCAFQQFqIQUgAyAGQQFqIgZB/wFxSg0ACwtBAEEAKQPAiQEiB0KAAXw3A8CJAUEAQQApA8iJASAHQv9+Vq18NwPIiQFB4IkBEAIgACADaiEAAkAgASADayIEQYEBSA0AIAIgAWohBQNAQQBBACkDwIkBIgdCgAF8NwPAiQFBAEEAKQPIiQEgB0L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AKQOwiQE3AzAgAEEAKQO4iQE3AzhBACgC5IoBIgVBAUgNAEEAIQRBACECA0AgBEGACWogACAEai0AADoAACAEQQFqIQQgBSACQQFqIgJB/wFxSg0ACwsgAEHAAGokAAv9AwMBfwF+AX8jAEGAAWsiAiQAQQBBgQI7AfKKAUEAIAE6APGKAUEAIAA6APCKAUGQfiEAA0AgAEGAiwFqQgA3AAAgAEH4igFqQgA3AAAgAEHwigFqQgA3AAAgAEEYaiIADQALQQAhAEEAQQApA/CKASIDQoiS853/zPmE6gCFNwOAiQFBAEEAKQP4igFCu86qptjQ67O7f4U3A4iJAUEAQQApA4CLAUKr8NP0r+68tzyFNwOQiQFBAEEAKQOIiwFC8e30+KWn/aelf4U3A5iJAUEAQQApA5CLAULRhZrv+s+Uh9EAhTcDoIkBQQBBACkDmIsBQp/Y+dnCkdqCm3+FNwOoiQFBAEEAKQOgiwFC6/qG2r+19sEfhTcDsIkBQQBBACkDqIsBQvnC+JuRo7Pw2wCFNwO4iQFBACADp0H/AXE2AuSKAQJAIAFBAUgNACACQgA3A3ggAkIANwNwIAJCADcDaCACQgA3A2AgAkIANwNYIAJCADcDUCACQgA3A0ggAkIANwNAIAJCADcDOCACQgA3AzAgAkIANwMoIAJCADcDICACQgA3AxggAkIANwMQIAJCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=";
|
|
4088
|
+
var hash$j = "c6f286e6";
|
|
4089
|
+
var wasmJson$j = {
|
|
4090
|
+
name: name$j,
|
|
4091
|
+
data: data$j,
|
|
4092
|
+
hash: hash$j
|
|
4093
|
+
};
|
|
4094
|
+
|
|
4805
4095
|
new Mutex();
|
|
4096
|
+
function validateBits$4(bits) {
|
|
4097
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
4098
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
4099
|
+
}
|
|
4100
|
+
return null;
|
|
4101
|
+
}
|
|
4102
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
4103
|
+
return outputBits | (keyBits << 16);
|
|
4104
|
+
}
|
|
4105
|
+
/**
|
|
4106
|
+
* Creates a new BLAKE2b hash instance
|
|
4107
|
+
* @param bits Number of output bits, which has to be a number
|
|
4108
|
+
* divisible by 8, between 8 and 512. Defaults to 512.
|
|
4109
|
+
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
|
|
4110
|
+
*/
|
|
4111
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
4112
|
+
if (validateBits$4(bits)) {
|
|
4113
|
+
return Promise.reject(validateBits$4(bits));
|
|
4114
|
+
}
|
|
4115
|
+
let keyBuffer = null;
|
|
4116
|
+
let initParam = bits;
|
|
4117
|
+
if (key !== null) {
|
|
4118
|
+
keyBuffer = getUInt8Buffer(key);
|
|
4119
|
+
if (keyBuffer.length > 64) {
|
|
4120
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
4121
|
+
}
|
|
4122
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
4123
|
+
}
|
|
4124
|
+
const outputSize = bits / 8;
|
|
4125
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
4126
|
+
if (initParam > 512) {
|
|
4127
|
+
wasm.writeMemory(keyBuffer);
|
|
4128
|
+
}
|
|
4129
|
+
wasm.init(initParam);
|
|
4130
|
+
const obj = {
|
|
4131
|
+
init: initParam > 512
|
|
4132
|
+
? () => {
|
|
4133
|
+
wasm.writeMemory(keyBuffer);
|
|
4134
|
+
wasm.init(initParam);
|
|
4135
|
+
return obj;
|
|
4136
|
+
}
|
|
4137
|
+
: () => {
|
|
4138
|
+
wasm.init(initParam);
|
|
4139
|
+
return obj;
|
|
4140
|
+
},
|
|
4141
|
+
update: (data) => {
|
|
4142
|
+
wasm.update(data);
|
|
4143
|
+
return obj;
|
|
4144
|
+
},
|
|
4145
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
4146
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
4147
|
+
save: () => wasm.save(),
|
|
4148
|
+
load: (data) => {
|
|
4149
|
+
wasm.load(data);
|
|
4150
|
+
return obj;
|
|
4151
|
+
},
|
|
4152
|
+
blockSize: 128,
|
|
4153
|
+
digestSize: outputSize,
|
|
4154
|
+
};
|
|
4155
|
+
return obj;
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4806
4158
|
|
|
4807
4159
|
new Mutex();
|
|
4808
4160
|
|
|
@@ -4892,6 +4244,79 @@ new Mutex();
|
|
|
4892
4244
|
|
|
4893
4245
|
new Mutex();
|
|
4894
4246
|
|
|
4247
|
+
/**
|
|
4248
|
+
* Size of the output of the hash functions.
|
|
4249
|
+
*
|
|
4250
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
4251
|
+
*
|
|
4252
|
+
*/
|
|
4253
|
+
const HASH_SIZE = 32;
|
|
4254
|
+
/** A hash without last byte (useful for trie representation). */
|
|
4255
|
+
const TRUNCATED_HASH_SIZE = 31;
|
|
4256
|
+
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
4257
|
+
/**
|
|
4258
|
+
* Container for some object with a hash that is related to this object.
|
|
4259
|
+
*
|
|
4260
|
+
* After calculating the hash these two should be passed together to avoid
|
|
4261
|
+
* unnecessary re-hashing of the data.
|
|
4262
|
+
*/
|
|
4263
|
+
class WithHash extends WithDebug {
|
|
4264
|
+
hash;
|
|
4265
|
+
data;
|
|
4266
|
+
constructor(hash, data) {
|
|
4267
|
+
super();
|
|
4268
|
+
this.hash = hash;
|
|
4269
|
+
this.data = data;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
/**
|
|
4273
|
+
* Extension of [`WithHash`] additionally containing an encoded version of the object.
|
|
4274
|
+
*/
|
|
4275
|
+
class WithHashAndBytes extends WithHash {
|
|
4276
|
+
encoded;
|
|
4277
|
+
constructor(hash, data, encoded) {
|
|
4278
|
+
super(hash, data);
|
|
4279
|
+
this.encoded = encoded;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
|
|
4283
|
+
const zero$1 = Bytes.zero(HASH_SIZE);
|
|
4284
|
+
class Blake2b {
|
|
4285
|
+
hasher;
|
|
4286
|
+
static async createHasher() {
|
|
4287
|
+
return new Blake2b(await createBLAKE2b(HASH_SIZE * 8));
|
|
4288
|
+
}
|
|
4289
|
+
constructor(hasher) {
|
|
4290
|
+
this.hasher = hasher;
|
|
4291
|
+
}
|
|
4292
|
+
/**
|
|
4293
|
+
* Hash given collection of blobs.
|
|
4294
|
+
*
|
|
4295
|
+
* If empty array is given a zero-hash is returned.
|
|
4296
|
+
*/
|
|
4297
|
+
hashBlobs(r) {
|
|
4298
|
+
if (r.length === 0) {
|
|
4299
|
+
return zero$1.asOpaque();
|
|
4300
|
+
}
|
|
4301
|
+
const hasher = this.hasher.init();
|
|
4302
|
+
for (const v of r) {
|
|
4303
|
+
hasher.update(v instanceof BytesBlob ? v.raw : v);
|
|
4304
|
+
}
|
|
4305
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4306
|
+
}
|
|
4307
|
+
/** Hash given blob of bytes. */
|
|
4308
|
+
hashBytes(blob) {
|
|
4309
|
+
const hasher = this.hasher.init();
|
|
4310
|
+
const bytes = blob instanceof BytesBlob ? blob.raw : blob;
|
|
4311
|
+
hasher.update(bytes);
|
|
4312
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4313
|
+
}
|
|
4314
|
+
/** Convert given string into bytes and hash it. */
|
|
4315
|
+
hashString(str) {
|
|
4316
|
+
return this.hashBytes(BytesBlob.blobFromString(str));
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4895
4320
|
class KeccakHasher {
|
|
4896
4321
|
hasher;
|
|
4897
4322
|
static async create() {
|
|
@@ -4916,91 +4341,61 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4916
4341
|
hashBlobs: hashBlobs
|
|
4917
4342
|
});
|
|
4918
4343
|
|
|
4919
|
-
|
|
4344
|
+
// TODO [ToDr] (#213) this should most likely be moved to a separate
|
|
4345
|
+
// package to avoid pulling in unnecessary deps.
|
|
4346
|
+
|
|
4347
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4920
4348
|
__proto__: null,
|
|
4349
|
+
Blake2b: Blake2b,
|
|
4921
4350
|
HASH_SIZE: HASH_SIZE,
|
|
4922
|
-
PageAllocator: PageAllocator,
|
|
4923
|
-
SimpleAllocator: SimpleAllocator,
|
|
4924
4351
|
TRUNCATED_HASH_SIZE: TRUNCATED_HASH_SIZE,
|
|
4925
4352
|
WithHash: WithHash,
|
|
4926
4353
|
WithHashAndBytes: WithHashAndBytes,
|
|
4927
4354
|
ZERO_HASH: ZERO_HASH,
|
|
4928
|
-
blake2b: blake2b,
|
|
4929
|
-
defaultAllocator: defaultAllocator,
|
|
4930
4355
|
keccak: keccak
|
|
4931
4356
|
});
|
|
4932
4357
|
|
|
4933
|
-
const SEED_SIZE = 32;
|
|
4934
|
-
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
4935
|
-
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
4936
|
-
/**
|
|
4937
|
-
* JIP-5: Secret key derivation
|
|
4938
|
-
*
|
|
4939
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
4940
|
-
/**
|
|
4941
|
-
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
4942
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
4943
|
-
*/
|
|
4944
|
-
function trivialSeed(s) {
|
|
4945
|
-
const s_le = u32AsLeBytes(s);
|
|
4946
|
-
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();
|
|
4947
|
-
}
|
|
4948
|
-
/**
|
|
4949
|
-
* Derives a Ed25519 secret key from a seed.
|
|
4950
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4951
|
-
*/
|
|
4952
|
-
function deriveEd25519SecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4953
|
-
return hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4954
|
-
}
|
|
4955
|
-
/**
|
|
4956
|
-
* Derives a Bandersnatch secret key from a seed.
|
|
4957
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4958
|
-
*/
|
|
4959
|
-
function deriveBandersnatchSecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4960
|
-
return hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4961
|
-
}
|
|
4962
|
-
/**
|
|
4963
|
-
* Derive Ed25519 public key from secret seed
|
|
4964
|
-
*/
|
|
4965
|
-
async function deriveEd25519PublicKey(seed) {
|
|
4966
|
-
return (await privateKey(seed)).pubKey;
|
|
4967
|
-
}
|
|
4968
4358
|
/**
|
|
4969
|
-
*
|
|
4359
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
4970
4360
|
*/
|
|
4971
|
-
|
|
4972
|
-
|
|
4361
|
+
class ArrayView {
|
|
4362
|
+
start;
|
|
4363
|
+
end;
|
|
4364
|
+
source;
|
|
4365
|
+
length;
|
|
4366
|
+
constructor(source, start, end) {
|
|
4367
|
+
this.start = start;
|
|
4368
|
+
this.end = end;
|
|
4369
|
+
this.source = source;
|
|
4370
|
+
this.length = end - start;
|
|
4371
|
+
}
|
|
4372
|
+
static from(source, start = 0, end = source.length) {
|
|
4373
|
+
check `
|
|
4374
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
4375
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
4376
|
+
`;
|
|
4377
|
+
return new ArrayView(source, start, end);
|
|
4378
|
+
}
|
|
4379
|
+
get(i) {
|
|
4380
|
+
check `
|
|
4381
|
+
${i >= 0 && i < this.length}
|
|
4382
|
+
Index out of bounds: ${i} < ${this.length}
|
|
4383
|
+
`;
|
|
4384
|
+
return this.source[this.start + i];
|
|
4385
|
+
}
|
|
4386
|
+
subview(from, to = this.length) {
|
|
4387
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
4388
|
+
}
|
|
4389
|
+
toArray() {
|
|
4390
|
+
return this.source.slice(this.start, this.end);
|
|
4391
|
+
}
|
|
4392
|
+
*[Symbol.iterator]() {
|
|
4393
|
+
for (let i = this.start; i < this.end; i++) {
|
|
4394
|
+
yield this.source[i];
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4973
4397
|
}
|
|
4974
4398
|
|
|
4975
|
-
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
4976
|
-
__proto__: null,
|
|
4977
|
-
SEED_SIZE: SEED_SIZE,
|
|
4978
|
-
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
4979
|
-
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
4980
|
-
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
4981
|
-
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
4982
|
-
trivialSeed: trivialSeed
|
|
4983
|
-
});
|
|
4984
|
-
|
|
4985
|
-
var index$m = /*#__PURE__*/Object.freeze({
|
|
4986
|
-
__proto__: null,
|
|
4987
|
-
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4988
|
-
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
4989
|
-
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
4990
|
-
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
4991
|
-
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
4992
|
-
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
4993
|
-
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
4994
|
-
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
4995
|
-
Ed25519Pair: Ed25519Pair,
|
|
4996
|
-
SEED_SIZE: SEED_SIZE,
|
|
4997
|
-
bandersnatch: bandersnatch,
|
|
4998
|
-
bandersnatchWasm: bandersnatch_exports,
|
|
4999
|
-
ed25519: ed25519,
|
|
5000
|
-
initWasm: initAll,
|
|
5001
|
-
keyDerivation: keyDerivation
|
|
5002
|
-
});
|
|
5003
|
-
|
|
5004
4399
|
/** A map which uses hashes as keys. */
|
|
5005
4400
|
class HashDictionary {
|
|
5006
4401
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
@@ -5586,8 +4981,9 @@ class TruncatedHashDictionary {
|
|
|
5586
4981
|
}
|
|
5587
4982
|
}
|
|
5588
4983
|
|
|
5589
|
-
var index$
|
|
4984
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
5590
4985
|
__proto__: null,
|
|
4986
|
+
ArrayView: ArrayView,
|
|
5591
4987
|
FixedSizeArray: FixedSizeArray,
|
|
5592
4988
|
HashDictionary: HashDictionary,
|
|
5593
4989
|
HashSet: HashSet,
|
|
@@ -5781,7 +5177,7 @@ class Bootnode {
|
|
|
5781
5177
|
}
|
|
5782
5178
|
}
|
|
5783
5179
|
|
|
5784
|
-
var index$
|
|
5180
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
5785
5181
|
__proto__: null,
|
|
5786
5182
|
Bootnode: Bootnode,
|
|
5787
5183
|
ChainSpec: ChainSpec,
|
|
@@ -7276,7 +6672,7 @@ function emptyBlock(slot = tryAsTimeSlot(0)) {
|
|
|
7276
6672
|
});
|
|
7277
6673
|
}
|
|
7278
6674
|
|
|
7279
|
-
var index$
|
|
6675
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
7280
6676
|
__proto__: null,
|
|
7281
6677
|
Block: Block,
|
|
7282
6678
|
EpochMarker: EpochMarker,
|
|
@@ -7532,7 +6928,7 @@ var json;
|
|
|
7532
6928
|
json.object = object;
|
|
7533
6929
|
})(json || (json = {}));
|
|
7534
6930
|
|
|
7535
|
-
var index$
|
|
6931
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
7536
6932
|
__proto__: null,
|
|
7537
6933
|
get json () { return json; },
|
|
7538
6934
|
parseFromJson: parseFromJson
|
|
@@ -7802,7 +7198,7 @@ const blockFromJson = (spec) => json.object({
|
|
|
7802
7198
|
extrinsic: getExtrinsicFromJson(spec),
|
|
7803
7199
|
}, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
|
|
7804
7200
|
|
|
7805
|
-
var index$
|
|
7201
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
7806
7202
|
__proto__: null,
|
|
7807
7203
|
blockFromJson: blockFromJson,
|
|
7808
7204
|
disputesExtrinsicFromJson: disputesExtrinsicFromJson,
|
|
@@ -8300,7 +7696,7 @@ class Logger {
|
|
|
8300
7696
|
}
|
|
8301
7697
|
}
|
|
8302
7698
|
|
|
8303
|
-
var index$
|
|
7699
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
8304
7700
|
__proto__: null,
|
|
8305
7701
|
get Level () { return Level; },
|
|
8306
7702
|
Logger: Logger,
|
|
@@ -8323,7 +7719,7 @@ class AuthorshipOptions {
|
|
|
8323
7719
|
}
|
|
8324
7720
|
}
|
|
8325
7721
|
|
|
8326
|
-
const logger$
|
|
7722
|
+
const logger$5 = Logger.new(import.meta.filename, "config");
|
|
8327
7723
|
/** Development config. Will accept unsealed blocks for now. */
|
|
8328
7724
|
const DEV_CONFIG = "dev";
|
|
8329
7725
|
/** Default config file. */
|
|
@@ -8382,15 +7778,15 @@ class NodeConfiguration {
|
|
|
8382
7778
|
}
|
|
8383
7779
|
function loadConfig(configPath) {
|
|
8384
7780
|
if (configPath === DEFAULT_CONFIG) {
|
|
8385
|
-
logger$
|
|
7781
|
+
logger$5.log `🔧 Loading DEFAULT config`;
|
|
8386
7782
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
8387
7783
|
}
|
|
8388
7784
|
if (configPath === DEV_CONFIG) {
|
|
8389
|
-
logger$
|
|
7785
|
+
logger$5.log `🔧 Loading DEV config`;
|
|
8390
7786
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
8391
7787
|
}
|
|
8392
7788
|
try {
|
|
8393
|
-
logger$
|
|
7789
|
+
logger$5.log `🔧 Loading config from ${configPath}`;
|
|
8394
7790
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
8395
7791
|
const parsed = JSON.parse(configFile);
|
|
8396
7792
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -8400,7 +7796,7 @@ function loadConfig(configPath) {
|
|
|
8400
7796
|
}
|
|
8401
7797
|
}
|
|
8402
7798
|
|
|
8403
|
-
var index$
|
|
7799
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
8404
7800
|
__proto__: null,
|
|
8405
7801
|
DEFAULT_CONFIG: DEFAULT_CONFIG,
|
|
8406
7802
|
DEV_CONFIG: DEV_CONFIG,
|
|
@@ -8549,43 +7945,43 @@ var stateKeys;
|
|
|
8549
7945
|
}
|
|
8550
7946
|
stateKeys.serviceInfo = serviceInfo;
|
|
8551
7947
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bba033bba03?v=0.7.1 */
|
|
8552
|
-
function serviceStorage(serviceId, key) {
|
|
7948
|
+
function serviceStorage(blake2b, serviceId, key) {
|
|
8553
7949
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8554
7950
|
const out = Bytes.zero(HASH_SIZE);
|
|
8555
7951
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 1)), 0);
|
|
8556
7952
|
out.raw.set(key.raw.subarray(0, HASH_SIZE - U32_BYTES), U32_BYTES);
|
|
8557
7953
|
return legacyServiceNested(serviceId, out);
|
|
8558
7954
|
}
|
|
8559
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
7955
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
8560
7956
|
}
|
|
8561
7957
|
stateKeys.serviceStorage = serviceStorage;
|
|
8562
7958
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bd7033bd703?v=0.7.1 */
|
|
8563
|
-
function servicePreimage(serviceId, hash) {
|
|
7959
|
+
function servicePreimage(blake2b, serviceId, hash) {
|
|
8564
7960
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8565
7961
|
const out = Bytes.zero(HASH_SIZE);
|
|
8566
7962
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 2)), 0);
|
|
8567
7963
|
out.raw.set(hash.raw.subarray(1, HASH_SIZE - U32_BYTES + 1), U32_BYTES);
|
|
8568
7964
|
return legacyServiceNested(serviceId, out);
|
|
8569
7965
|
}
|
|
8570
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
7966
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
8571
7967
|
}
|
|
8572
7968
|
stateKeys.servicePreimage = servicePreimage;
|
|
8573
7969
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b0a043b0a04?v=0.7.1 */
|
|
8574
|
-
function serviceLookupHistory(serviceId, hash, preimageLength) {
|
|
7970
|
+
function serviceLookupHistory(blake2b, serviceId, hash, preimageLength) {
|
|
8575
7971
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8576
|
-
const doubleHash = hashBytes(hash);
|
|
7972
|
+
const doubleHash = blake2b.hashBytes(hash);
|
|
8577
7973
|
const out = Bytes.zero(HASH_SIZE);
|
|
8578
7974
|
out.raw.set(u32AsLeBytes(preimageLength), 0);
|
|
8579
7975
|
out.raw.set(doubleHash.raw.subarray(2, HASH_SIZE - U32_BYTES + 2), U32_BYTES);
|
|
8580
7976
|
return legacyServiceNested(serviceId, out);
|
|
8581
7977
|
}
|
|
8582
|
-
return serviceNested(serviceId, preimageLength, hash);
|
|
7978
|
+
return serviceNested(blake2b, serviceId, preimageLength, hash);
|
|
8583
7979
|
}
|
|
8584
7980
|
stateKeys.serviceLookupHistory = serviceLookupHistory;
|
|
8585
7981
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b88003b8800?v=0.7.1 */
|
|
8586
|
-
function serviceNested(serviceId, numberPrefix, hash) {
|
|
7982
|
+
function serviceNested(blake2b, serviceId, numberPrefix, hash) {
|
|
8587
7983
|
const inputToHash = BytesBlob.blobFromParts(u32AsLeBytes(numberPrefix), hash.raw);
|
|
8588
|
-
const newHash = hashBytes(inputToHash).raw.subarray(0, 28);
|
|
7984
|
+
const newHash = blake2b.hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8589
7985
|
const key = Bytes.zero(HASH_SIZE);
|
|
8590
7986
|
let i = 0;
|
|
8591
7987
|
for (const byte of u32AsLeBytes(serviceId)) {
|
|
@@ -8646,12 +8042,6 @@ function accumulationOutputComparator(a, b) {
|
|
|
8646
8042
|
return Ordering.Equal;
|
|
8647
8043
|
}
|
|
8648
8044
|
|
|
8649
|
-
const codecWithHash = (val) => Descriptor.withView(val.name, val.sizeHint, (e, elem) => val.encode(e, elem.data), (d) => {
|
|
8650
|
-
const decoder2 = d.clone();
|
|
8651
|
-
const encoded = val.skipEncoded(decoder2);
|
|
8652
|
-
const hash = hashBytes(encoded);
|
|
8653
|
-
return new WithHash(hash.asOpaque(), val.decode(d));
|
|
8654
|
-
}, val.skip, val.View);
|
|
8655
8045
|
/**
|
|
8656
8046
|
* Assignment of particular work report to a core.
|
|
8657
8047
|
*
|
|
@@ -8664,7 +8054,7 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8664
8054
|
workReport;
|
|
8665
8055
|
timeout;
|
|
8666
8056
|
static Codec = codec$1.Class(AvailabilityAssignment, {
|
|
8667
|
-
workReport:
|
|
8057
|
+
workReport: WorkReport.Codec,
|
|
8668
8058
|
timeout: codec$1.u32.asOpaque(),
|
|
8669
8059
|
});
|
|
8670
8060
|
static create({ workReport, timeout }) {
|
|
@@ -8717,6 +8107,10 @@ class DisputesRecords {
|
|
|
8717
8107
|
static create({ goodSet, badSet, wonkySet, punishSet }) {
|
|
8718
8108
|
return new DisputesRecords(goodSet, badSet, wonkySet, punishSet);
|
|
8719
8109
|
}
|
|
8110
|
+
goodSetDict;
|
|
8111
|
+
badSetDict;
|
|
8112
|
+
wonkySetDict;
|
|
8113
|
+
punishSetDict;
|
|
8720
8114
|
constructor(
|
|
8721
8115
|
/** `goodSet`: all work-reports hashes which were judged to be correct */
|
|
8722
8116
|
goodSet,
|
|
@@ -8730,6 +8124,18 @@ class DisputesRecords {
|
|
|
8730
8124
|
this.badSet = badSet;
|
|
8731
8125
|
this.wonkySet = wonkySet;
|
|
8732
8126
|
this.punishSet = punishSet;
|
|
8127
|
+
this.goodSetDict = HashSet.from(goodSet.array);
|
|
8128
|
+
this.badSetDict = HashSet.from(badSet.array);
|
|
8129
|
+
this.wonkySetDict = HashSet.from(wonkySet.array);
|
|
8130
|
+
this.punishSetDict = HashSet.from(punishSet.array);
|
|
8131
|
+
}
|
|
8132
|
+
asDictionaries() {
|
|
8133
|
+
return {
|
|
8134
|
+
goodSet: this.goodSetDict,
|
|
8135
|
+
badSet: this.badSetDict,
|
|
8136
|
+
wonkySet: this.wonkySetDict,
|
|
8137
|
+
punishSet: this.punishSetDict,
|
|
8138
|
+
};
|
|
8733
8139
|
}
|
|
8734
8140
|
static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
|
|
8735
8141
|
return new DisputesRecords(SortedSet.fromSortedArray(hashComparator, goodSet), SortedSet.fromSortedArray(hashComparator, badSet), SortedSet.fromSortedArray(hashComparator, wonkySet), SortedSet.fromSortedArray(hashComparator, punishSet));
|
|
@@ -8745,7 +8151,6 @@ const O = 8;
|
|
|
8745
8151
|
const Q = 80;
|
|
8746
8152
|
/** `W_T`: The size of a transfer memo in octets. */
|
|
8747
8153
|
const W_T = 128;
|
|
8748
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
8749
8154
|
/**
|
|
8750
8155
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
8751
8156
|
*
|
|
@@ -8757,89 +8162,288 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
8757
8162
|
/** `O`: Maximal authorization pool size. */
|
|
8758
8163
|
const MAX_AUTH_POOL_SIZE = O;
|
|
8759
8164
|
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
service: codec$1.u32.asOpaque(),
|
|
8766
|
-
gasLimit: codec$1.u64.asOpaque(),
|
|
8767
|
-
});
|
|
8768
|
-
static create({ service, gasLimit }) {
|
|
8769
|
-
return new AutoAccumulate(service, gasLimit);
|
|
8770
|
-
}
|
|
8771
|
-
constructor(
|
|
8772
|
-
/** Service id that auto-accumulates. */
|
|
8773
|
-
service,
|
|
8774
|
-
/** Gas limit for auto-accumulation. */
|
|
8775
|
-
gasLimit) {
|
|
8776
|
-
this.service = service;
|
|
8777
|
-
this.gasLimit = gasLimit;
|
|
8778
|
-
}
|
|
8779
|
-
}
|
|
8165
|
+
const MAX_VALUE = 4294967295;
|
|
8166
|
+
const MIN_VALUE = -2147483648;
|
|
8167
|
+
const MAX_SHIFT_U32 = 32;
|
|
8168
|
+
const MAX_SHIFT_U64 = 64n;
|
|
8169
|
+
|
|
8780
8170
|
/**
|
|
8781
|
-
*
|
|
8171
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
8172
|
+
*
|
|
8173
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
8782
8174
|
*/
|
|
8783
|
-
|
|
8784
|
-
manager;
|
|
8785
|
-
authManager;
|
|
8786
|
-
validatorsManager;
|
|
8787
|
-
autoAccumulateServices;
|
|
8788
|
-
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8789
|
-
manager: codec$1.u32.asOpaque(),
|
|
8790
|
-
authManager: codecPerCore(codec$1.u32.asOpaque()),
|
|
8791
|
-
validatorsManager: codec$1.u32.asOpaque(),
|
|
8792
|
-
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8793
|
-
});
|
|
8794
|
-
static create({ manager, authManager, validatorsManager, autoAccumulateServices }) {
|
|
8795
|
-
return new PrivilegedServices(manager, authManager, validatorsManager, autoAccumulateServices);
|
|
8796
|
-
}
|
|
8797
|
-
constructor(
|
|
8798
|
-
/**
|
|
8799
|
-
* `chi_m`: The first, χm, is the index of the manager service which is
|
|
8800
|
-
* the service able to effect an alteration of χ from block to block,
|
|
8801
|
-
* as well as bestow services with storage deposit credits.
|
|
8802
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/11a40111a801?v=0.6.7
|
|
8803
|
-
*/
|
|
8804
|
-
manager,
|
|
8805
|
-
/** `chi_a`: Manages authorization queue one for each core. */
|
|
8806
|
-
authManager,
|
|
8807
|
-
/** `chi_v`: Managers validator keys. */
|
|
8808
|
-
validatorsManager,
|
|
8809
|
-
/** `chi_g`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
8810
|
-
autoAccumulateServices) {
|
|
8811
|
-
this.manager = manager;
|
|
8812
|
-
this.authManager = authManager;
|
|
8813
|
-
this.validatorsManager = validatorsManager;
|
|
8814
|
-
this.autoAccumulateServices = autoAccumulateServices;
|
|
8815
|
-
}
|
|
8816
|
-
}
|
|
8817
|
-
|
|
8175
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
8818
8176
|
/**
|
|
8819
|
-
* `
|
|
8177
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
8820
8178
|
*
|
|
8821
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8179
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
8822
8180
|
*/
|
|
8823
|
-
const
|
|
8824
|
-
/**
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8181
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
8182
|
+
/**
|
|
8183
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
8184
|
+
*
|
|
8185
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
8186
|
+
*/
|
|
8187
|
+
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
8188
|
+
const zeroSizeHint = {
|
|
8189
|
+
bytes: 0,
|
|
8190
|
+
isExact: true,
|
|
8191
|
+
};
|
|
8192
|
+
/** 0-byte read, return given default value */
|
|
8193
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8194
|
+
/** Encode and decode object with leading version number. */
|
|
8195
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8196
|
+
bytes: val.sizeHint.bytes + 8,
|
|
8197
|
+
isExact: false,
|
|
8198
|
+
}, (e, v) => {
|
|
8199
|
+
e.varU64(0n);
|
|
8200
|
+
val.encode(e, v);
|
|
8201
|
+
}, (d) => {
|
|
8202
|
+
const version = d.varU64();
|
|
8203
|
+
if (version !== 0n) {
|
|
8204
|
+
throw new Error("Non-zero version is not supported!");
|
|
8205
|
+
}
|
|
8206
|
+
return val.decode(d);
|
|
8207
|
+
}, (s) => {
|
|
8208
|
+
s.varU64();
|
|
8209
|
+
val.skip(s);
|
|
8210
|
+
});
|
|
8211
|
+
/**
|
|
8212
|
+
* Service account details.
|
|
8213
|
+
*
|
|
8214
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
8215
|
+
*/
|
|
8216
|
+
class ServiceAccountInfo extends WithDebug {
|
|
8217
|
+
codeHash;
|
|
8218
|
+
balance;
|
|
8219
|
+
accumulateMinGas;
|
|
8220
|
+
onTransferMinGas;
|
|
8221
|
+
storageUtilisationBytes;
|
|
8222
|
+
gratisStorage;
|
|
8223
|
+
storageUtilisationCount;
|
|
8224
|
+
created;
|
|
8225
|
+
lastAccumulation;
|
|
8226
|
+
parentService;
|
|
8227
|
+
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
8228
|
+
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8229
|
+
balance: codec$1.u64,
|
|
8230
|
+
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8231
|
+
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8232
|
+
storageUtilisationBytes: codec$1.u64,
|
|
8233
|
+
gratisStorage: codec$1.u64,
|
|
8234
|
+
storageUtilisationCount: codec$1.u32,
|
|
8235
|
+
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8236
|
+
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8237
|
+
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
8238
|
+
});
|
|
8239
|
+
static create(a) {
|
|
8240
|
+
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
8241
|
+
}
|
|
8242
|
+
/**
|
|
8243
|
+
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
8244
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
8245
|
+
*/
|
|
8246
|
+
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
8247
|
+
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
8248
|
+
if (storageCost < 0n) {
|
|
8249
|
+
return tryAsU64(0);
|
|
8250
|
+
}
|
|
8251
|
+
if (storageCost >= 2n ** 64n) {
|
|
8252
|
+
return tryAsU64(2n ** 64n - 1n);
|
|
8253
|
+
}
|
|
8254
|
+
return tryAsU64(storageCost);
|
|
8255
|
+
}
|
|
8256
|
+
constructor(
|
|
8257
|
+
/** `a_c`: Hash of the service code. */
|
|
8258
|
+
codeHash,
|
|
8259
|
+
/** `a_b`: Current account balance. */
|
|
8260
|
+
balance,
|
|
8261
|
+
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
8262
|
+
accumulateMinGas,
|
|
8263
|
+
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
8264
|
+
onTransferMinGas,
|
|
8265
|
+
/** `a_o`: Total number of octets in storage. */
|
|
8266
|
+
storageUtilisationBytes,
|
|
8267
|
+
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
8268
|
+
gratisStorage,
|
|
8269
|
+
/** `a_i`: Number of items in storage. */
|
|
8270
|
+
storageUtilisationCount,
|
|
8271
|
+
/** `a_r`: Creation account time slot. */
|
|
8272
|
+
created,
|
|
8273
|
+
/** `a_a`: Most recent accumulation time slot. */
|
|
8274
|
+
lastAccumulation,
|
|
8275
|
+
/** `a_p`: Parent service ID. */
|
|
8276
|
+
parentService) {
|
|
8277
|
+
super();
|
|
8278
|
+
this.codeHash = codeHash;
|
|
8279
|
+
this.balance = balance;
|
|
8280
|
+
this.accumulateMinGas = accumulateMinGas;
|
|
8281
|
+
this.onTransferMinGas = onTransferMinGas;
|
|
8282
|
+
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
8283
|
+
this.gratisStorage = gratisStorage;
|
|
8284
|
+
this.storageUtilisationCount = storageUtilisationCount;
|
|
8285
|
+
this.created = created;
|
|
8286
|
+
this.lastAccumulation = lastAccumulation;
|
|
8287
|
+
this.parentService = parentService;
|
|
8288
|
+
}
|
|
8289
|
+
}
|
|
8290
|
+
class PreimageItem extends WithDebug {
|
|
8291
|
+
hash;
|
|
8292
|
+
blob;
|
|
8293
|
+
static Codec = codec$1.Class(PreimageItem, {
|
|
8294
|
+
hash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8295
|
+
blob: codec$1.blob,
|
|
8296
|
+
});
|
|
8297
|
+
static create({ hash, blob }) {
|
|
8298
|
+
return new PreimageItem(hash, blob);
|
|
8299
|
+
}
|
|
8300
|
+
constructor(hash, blob) {
|
|
8301
|
+
super();
|
|
8302
|
+
this.hash = hash;
|
|
8303
|
+
this.blob = blob;
|
|
8304
|
+
}
|
|
8305
|
+
}
|
|
8306
|
+
class StorageItem extends WithDebug {
|
|
8307
|
+
key;
|
|
8308
|
+
value;
|
|
8309
|
+
static Codec = codec$1.Class(StorageItem, {
|
|
8310
|
+
key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
|
|
8311
|
+
value: codec$1.blob,
|
|
8312
|
+
});
|
|
8313
|
+
static create({ key, value }) {
|
|
8314
|
+
return new StorageItem(key, value);
|
|
8315
|
+
}
|
|
8316
|
+
constructor(key, value) {
|
|
8317
|
+
super();
|
|
8318
|
+
this.key = key;
|
|
8319
|
+
this.value = value;
|
|
8320
|
+
}
|
|
8321
|
+
}
|
|
8322
|
+
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
8323
|
+
function tryAsLookupHistorySlots(items) {
|
|
8324
|
+
const knownSize = asKnownSize(items);
|
|
8325
|
+
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
8326
|
+
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
8327
|
+
}
|
|
8328
|
+
return knownSize;
|
|
8329
|
+
}
|
|
8330
|
+
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
8331
|
+
class LookupHistoryItem {
|
|
8332
|
+
hash;
|
|
8333
|
+
length;
|
|
8334
|
+
slots;
|
|
8335
|
+
constructor(hash, length,
|
|
8336
|
+
/**
|
|
8337
|
+
* Preimage availability history as a sequence of time slots.
|
|
8338
|
+
* See PreimageStatus and the following GP fragment for more details.
|
|
8339
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
8340
|
+
slots) {
|
|
8341
|
+
this.hash = hash;
|
|
8342
|
+
this.length = length;
|
|
8343
|
+
this.slots = slots;
|
|
8344
|
+
}
|
|
8345
|
+
static isRequested(item) {
|
|
8346
|
+
if ("slots" in item) {
|
|
8347
|
+
return item.slots.length === 0;
|
|
8348
|
+
}
|
|
8349
|
+
return item.length === 0;
|
|
8350
|
+
}
|
|
8351
|
+
}
|
|
8352
|
+
|
|
8353
|
+
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8354
|
+
class AutoAccumulate {
|
|
8355
|
+
service;
|
|
8356
|
+
gasLimit;
|
|
8357
|
+
static Codec = codec$1.Class(AutoAccumulate, {
|
|
8358
|
+
service: codec$1.u32.asOpaque(),
|
|
8359
|
+
gasLimit: codec$1.u64.asOpaque(),
|
|
8360
|
+
});
|
|
8361
|
+
static create({ service, gasLimit }) {
|
|
8362
|
+
return new AutoAccumulate(service, gasLimit);
|
|
8363
|
+
}
|
|
8364
|
+
constructor(
|
|
8365
|
+
/** Service id that auto-accumulates. */
|
|
8366
|
+
service,
|
|
8367
|
+
/** Gas limit for auto-accumulation. */
|
|
8368
|
+
gasLimit) {
|
|
8369
|
+
this.service = service;
|
|
8370
|
+
this.gasLimit = gasLimit;
|
|
8371
|
+
}
|
|
8372
|
+
}
|
|
8373
|
+
/**
|
|
8374
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8375
|
+
*/
|
|
8376
|
+
class PrivilegedServices {
|
|
8377
|
+
manager;
|
|
8378
|
+
delegator;
|
|
8379
|
+
registrar;
|
|
8380
|
+
assigners;
|
|
8381
|
+
autoAccumulateServices;
|
|
8382
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
8383
|
+
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8384
|
+
manager: codec$1.u32.asOpaque(),
|
|
8385
|
+
assigners: codecPerCore(codec$1.u32.asOpaque()),
|
|
8386
|
+
delegator: codec$1.u32.asOpaque(),
|
|
8387
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
8388
|
+
? codec$1.u32.asOpaque()
|
|
8389
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
8390
|
+
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8391
|
+
});
|
|
8392
|
+
static create(a) {
|
|
8393
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
8394
|
+
}
|
|
8395
|
+
constructor(
|
|
8396
|
+
/**
|
|
8397
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
8398
|
+
* as well as bestow services with storage deposit credits.
|
|
8399
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
8400
|
+
*/
|
|
8401
|
+
manager,
|
|
8402
|
+
/** `χ_V`: Managers validator keys. */
|
|
8403
|
+
delegator,
|
|
8404
|
+
/**
|
|
8405
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
8406
|
+
*
|
|
8407
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
8408
|
+
*/
|
|
8409
|
+
registrar,
|
|
8410
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
8411
|
+
assigners,
|
|
8412
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
8413
|
+
autoAccumulateServices) {
|
|
8414
|
+
this.manager = manager;
|
|
8415
|
+
this.delegator = delegator;
|
|
8416
|
+
this.registrar = registrar;
|
|
8417
|
+
this.assigners = assigners;
|
|
8418
|
+
this.autoAccumulateServices = autoAccumulateServices;
|
|
8419
|
+
}
|
|
8420
|
+
}
|
|
8421
|
+
|
|
8422
|
+
/**
|
|
8423
|
+
* `H = 8`: The size of recent history, in blocks.
|
|
8424
|
+
*
|
|
8425
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/416300416500
|
|
8426
|
+
*/
|
|
8427
|
+
const MAX_RECENT_HISTORY = 8;
|
|
8428
|
+
/** Recent history of a single block. */
|
|
8429
|
+
class BlockState extends WithDebug {
|
|
8430
|
+
headerHash;
|
|
8431
|
+
accumulationResult;
|
|
8432
|
+
postStateRoot;
|
|
8433
|
+
reported;
|
|
8434
|
+
static Codec = codec$1.Class(BlockState, {
|
|
8435
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8436
|
+
accumulationResult: codec$1.bytes(HASH_SIZE),
|
|
8437
|
+
postStateRoot: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8438
|
+
reported: codecHashDictionary(WorkPackageInfo.Codec, (x) => x.workPackageHash),
|
|
8439
|
+
});
|
|
8440
|
+
static create({ headerHash, accumulationResult, postStateRoot, reported }) {
|
|
8441
|
+
return new BlockState(headerHash, accumulationResult, postStateRoot, reported);
|
|
8442
|
+
}
|
|
8443
|
+
constructor(
|
|
8444
|
+
/** Header hash. */
|
|
8445
|
+
headerHash,
|
|
8446
|
+
/** Merkle mountain belt of accumulation result. */
|
|
8843
8447
|
accumulationResult,
|
|
8844
8448
|
/** Posterior state root filled in with a 1-block delay. */
|
|
8845
8449
|
postStateRoot,
|
|
@@ -9036,205 +8640,39 @@ class SafroleSealingKeysData extends WithDebug {
|
|
|
9036
8640
|
return new SafroleSealingKeysData(SafroleSealingKeysKind.Tickets, undefined, tickets);
|
|
9037
8641
|
}
|
|
9038
8642
|
constructor(kind, keys, tickets) {
|
|
9039
|
-
super();
|
|
9040
|
-
this.kind = kind;
|
|
9041
|
-
this.keys = keys;
|
|
9042
|
-
this.tickets = tickets;
|
|
9043
|
-
}
|
|
9044
|
-
}
|
|
9045
|
-
class SafroleData {
|
|
9046
|
-
nextValidatorData;
|
|
9047
|
-
epochRoot;
|
|
9048
|
-
sealingKeySeries;
|
|
9049
|
-
ticketsAccumulator;
|
|
9050
|
-
static Codec = codec$1.Class(SafroleData, {
|
|
9051
|
-
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
9052
|
-
epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
9053
|
-
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
9054
|
-
ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
|
|
9055
|
-
});
|
|
9056
|
-
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
9057
|
-
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
9058
|
-
}
|
|
9059
|
-
constructor(
|
|
9060
|
-
/** gamma_k */
|
|
9061
|
-
nextValidatorData,
|
|
9062
|
-
/** gamma_z */
|
|
9063
|
-
epochRoot,
|
|
9064
|
-
/** gamma_s */
|
|
9065
|
-
sealingKeySeries,
|
|
9066
|
-
/** gamma_a */
|
|
9067
|
-
ticketsAccumulator) {
|
|
9068
|
-
this.nextValidatorData = nextValidatorData;
|
|
9069
|
-
this.epochRoot = epochRoot;
|
|
9070
|
-
this.sealingKeySeries = sealingKeySeries;
|
|
9071
|
-
this.ticketsAccumulator = ticketsAccumulator;
|
|
9072
|
-
}
|
|
9073
|
-
}
|
|
9074
|
-
|
|
9075
|
-
/**
|
|
9076
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
9077
|
-
*
|
|
9078
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9079
|
-
*/
|
|
9080
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
9081
|
-
/**
|
|
9082
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9083
|
-
*
|
|
9084
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9085
|
-
*/
|
|
9086
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9087
|
-
/**
|
|
9088
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9089
|
-
*
|
|
9090
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9091
|
-
*/
|
|
9092
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9093
|
-
const zeroSizeHint = {
|
|
9094
|
-
bytes: 0,
|
|
9095
|
-
isExact: true,
|
|
9096
|
-
};
|
|
9097
|
-
/** 0-byte read, return given default value */
|
|
9098
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
9099
|
-
/**
|
|
9100
|
-
* Service account details.
|
|
9101
|
-
*
|
|
9102
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
9103
|
-
*/
|
|
9104
|
-
class ServiceAccountInfo extends WithDebug {
|
|
9105
|
-
codeHash;
|
|
9106
|
-
balance;
|
|
9107
|
-
accumulateMinGas;
|
|
9108
|
-
onTransferMinGas;
|
|
9109
|
-
storageUtilisationBytes;
|
|
9110
|
-
gratisStorage;
|
|
9111
|
-
storageUtilisationCount;
|
|
9112
|
-
created;
|
|
9113
|
-
lastAccumulation;
|
|
9114
|
-
parentService;
|
|
9115
|
-
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
9116
|
-
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
9117
|
-
balance: codec$1.u64,
|
|
9118
|
-
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
9119
|
-
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
9120
|
-
storageUtilisationBytes: codec$1.u64,
|
|
9121
|
-
gratisStorage: codec$1.u64,
|
|
9122
|
-
storageUtilisationCount: codec$1.u32,
|
|
9123
|
-
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
9124
|
-
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
9125
|
-
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
9126
|
-
});
|
|
9127
|
-
static create(a) {
|
|
9128
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
9129
|
-
}
|
|
9130
|
-
/**
|
|
9131
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
9132
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
9133
|
-
*/
|
|
9134
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
9135
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
9136
|
-
if (storageCost < 0n) {
|
|
9137
|
-
return tryAsU64(0);
|
|
9138
|
-
}
|
|
9139
|
-
if (storageCost >= 2n ** 64n) {
|
|
9140
|
-
return tryAsU64(2n ** 64n - 1n);
|
|
9141
|
-
}
|
|
9142
|
-
return tryAsU64(storageCost);
|
|
9143
|
-
}
|
|
9144
|
-
constructor(
|
|
9145
|
-
/** `a_c`: Hash of the service code. */
|
|
9146
|
-
codeHash,
|
|
9147
|
-
/** `a_b`: Current account balance. */
|
|
9148
|
-
balance,
|
|
9149
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
9150
|
-
accumulateMinGas,
|
|
9151
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
9152
|
-
onTransferMinGas,
|
|
9153
|
-
/** `a_o`: Total number of octets in storage. */
|
|
9154
|
-
storageUtilisationBytes,
|
|
9155
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
9156
|
-
gratisStorage,
|
|
9157
|
-
/** `a_i`: Number of items in storage. */
|
|
9158
|
-
storageUtilisationCount,
|
|
9159
|
-
/** `a_r`: Creation account time slot. */
|
|
9160
|
-
created,
|
|
9161
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
9162
|
-
lastAccumulation,
|
|
9163
|
-
/** `a_p`: Parent service ID. */
|
|
9164
|
-
parentService) {
|
|
9165
|
-
super();
|
|
9166
|
-
this.codeHash = codeHash;
|
|
9167
|
-
this.balance = balance;
|
|
9168
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
9169
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
9170
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
9171
|
-
this.gratisStorage = gratisStorage;
|
|
9172
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
9173
|
-
this.created = created;
|
|
9174
|
-
this.lastAccumulation = lastAccumulation;
|
|
9175
|
-
this.parentService = parentService;
|
|
9176
|
-
}
|
|
9177
|
-
}
|
|
9178
|
-
class PreimageItem extends WithDebug {
|
|
9179
|
-
hash;
|
|
9180
|
-
blob;
|
|
9181
|
-
static Codec = codec$1.Class(PreimageItem, {
|
|
9182
|
-
hash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
9183
|
-
blob: codec$1.blob,
|
|
9184
|
-
});
|
|
9185
|
-
static create({ hash, blob }) {
|
|
9186
|
-
return new PreimageItem(hash, blob);
|
|
9187
|
-
}
|
|
9188
|
-
constructor(hash, blob) {
|
|
9189
|
-
super();
|
|
9190
|
-
this.hash = hash;
|
|
9191
|
-
this.blob = blob;
|
|
9192
|
-
}
|
|
9193
|
-
}
|
|
9194
|
-
class StorageItem extends WithDebug {
|
|
9195
|
-
key;
|
|
9196
|
-
value;
|
|
9197
|
-
static Codec = codec$1.Class(StorageItem, {
|
|
9198
|
-
key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
|
|
9199
|
-
value: codec$1.blob,
|
|
9200
|
-
});
|
|
9201
|
-
static create({ key, value }) {
|
|
9202
|
-
return new StorageItem(key, value);
|
|
9203
|
-
}
|
|
9204
|
-
constructor(key, value) {
|
|
9205
|
-
super();
|
|
9206
|
-
this.key = key;
|
|
9207
|
-
this.value = value;
|
|
9208
|
-
}
|
|
9209
|
-
}
|
|
9210
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
9211
|
-
function tryAsLookupHistorySlots(items) {
|
|
9212
|
-
const knownSize = asKnownSize(items);
|
|
9213
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
9214
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
8643
|
+
super();
|
|
8644
|
+
this.kind = kind;
|
|
8645
|
+
this.keys = keys;
|
|
8646
|
+
this.tickets = tickets;
|
|
9215
8647
|
}
|
|
9216
|
-
return knownSize;
|
|
9217
8648
|
}
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
this.slots = slots;
|
|
8649
|
+
class SafroleData {
|
|
8650
|
+
nextValidatorData;
|
|
8651
|
+
epochRoot;
|
|
8652
|
+
sealingKeySeries;
|
|
8653
|
+
ticketsAccumulator;
|
|
8654
|
+
static Codec = codec$1.Class(SafroleData, {
|
|
8655
|
+
nextValidatorData: codecPerValidator(ValidatorData.Codec),
|
|
8656
|
+
epochRoot: codec$1.bytes(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
8657
|
+
sealingKeySeries: SafroleSealingKeysData.Codec,
|
|
8658
|
+
ticketsAccumulator: readonlyArray(codec$1.sequenceVarLen(Ticket.Codec)).convert(seeThrough, asKnownSize),
|
|
8659
|
+
});
|
|
8660
|
+
static create({ nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator }) {
|
|
8661
|
+
return new SafroleData(nextValidatorData, epochRoot, sealingKeySeries, ticketsAccumulator);
|
|
9232
8662
|
}
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
8663
|
+
constructor(
|
|
8664
|
+
/** gamma_k */
|
|
8665
|
+
nextValidatorData,
|
|
8666
|
+
/** gamma_z */
|
|
8667
|
+
epochRoot,
|
|
8668
|
+
/** gamma_s */
|
|
8669
|
+
sealingKeySeries,
|
|
8670
|
+
/** gamma_a */
|
|
8671
|
+
ticketsAccumulator) {
|
|
8672
|
+
this.nextValidatorData = nextValidatorData;
|
|
8673
|
+
this.epochRoot = epochRoot;
|
|
8674
|
+
this.sealingKeySeries = sealingKeySeries;
|
|
8675
|
+
this.ticketsAccumulator = ticketsAccumulator;
|
|
9238
8676
|
}
|
|
9239
8677
|
}
|
|
9240
8678
|
|
|
@@ -10045,8 +9483,9 @@ class InMemoryState extends WithDebug {
|
|
|
10045
9483
|
epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10046
9484
|
privilegedServices: PrivilegedServices.create({
|
|
10047
9485
|
manager: tryAsServiceId(0),
|
|
10048
|
-
|
|
10049
|
-
|
|
9486
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
9487
|
+
delegator: tryAsServiceId(0),
|
|
9488
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10050
9489
|
autoAccumulateServices: [],
|
|
10051
9490
|
}),
|
|
10052
9491
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -10066,7 +9505,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
|
|
|
10066
9505
|
sortKeys: (a, b) => a - b,
|
|
10067
9506
|
});
|
|
10068
9507
|
|
|
10069
|
-
var index$
|
|
9508
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
10070
9509
|
__proto__: null,
|
|
10071
9510
|
AccumulationOutput: AccumulationOutput,
|
|
10072
9511
|
AutoAccumulate: AutoAccumulate,
|
|
@@ -10105,6 +9544,7 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
10105
9544
|
ValidatorStatistics: ValidatorStatistics,
|
|
10106
9545
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
10107
9546
|
codecPerCore: codecPerCore,
|
|
9547
|
+
codecWithVersion: codecWithVersion,
|
|
10108
9548
|
hashComparator: hashComparator,
|
|
10109
9549
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
10110
9550
|
serviceDataCodec: serviceDataCodec,
|
|
@@ -10265,21 +9705,23 @@ var serialize;
|
|
|
10265
9705
|
/** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
|
|
10266
9706
|
serialize.serviceData = (serviceId) => ({
|
|
10267
9707
|
key: stateKeys.serviceInfo(serviceId),
|
|
10268
|
-
Codec:
|
|
9708
|
+
Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9709
|
+
? codecWithVersion(ServiceAccountInfo.Codec)
|
|
9710
|
+
: ServiceAccountInfo.Codec,
|
|
10269
9711
|
});
|
|
10270
9712
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
10271
|
-
serialize.serviceStorage = (serviceId, key) => ({
|
|
10272
|
-
key: stateKeys.serviceStorage(serviceId, key),
|
|
9713
|
+
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
9714
|
+
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
10273
9715
|
Codec: dumpCodec,
|
|
10274
9716
|
});
|
|
10275
9717
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
10276
|
-
serialize.servicePreimages = (serviceId, hash) => ({
|
|
10277
|
-
key: stateKeys.servicePreimage(serviceId, hash),
|
|
9718
|
+
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
9719
|
+
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
10278
9720
|
Codec: dumpCodec,
|
|
10279
9721
|
});
|
|
10280
9722
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10281
|
-
serialize.serviceLookupHistory = (serviceId, hash, len) => ({
|
|
10282
|
-
key: stateKeys.serviceLookupHistory(serviceId, hash, len),
|
|
9723
|
+
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
9724
|
+
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10283
9725
|
Codec: readonlyArray(codec$1.sequenceVarLen(codec$1.u32)),
|
|
10284
9726
|
});
|
|
10285
9727
|
})(serialize || (serialize = {}));
|
|
@@ -10302,20 +9744,22 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10302
9744
|
*/
|
|
10303
9745
|
class SerializedState {
|
|
10304
9746
|
spec;
|
|
9747
|
+
blake2b;
|
|
10305
9748
|
backend;
|
|
10306
9749
|
_recentServiceIds;
|
|
10307
9750
|
/** Create a state-like object from collection of serialized entries. */
|
|
10308
|
-
static fromStateEntries(spec, state, recentServices = []) {
|
|
10309
|
-
return new SerializedState(spec, state, recentServices);
|
|
9751
|
+
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9752
|
+
return new SerializedState(spec, blake2b, state, recentServices);
|
|
10310
9753
|
}
|
|
10311
9754
|
/** Create a state-like object backed by some DB. */
|
|
10312
|
-
static new(spec, db, recentServices = []) {
|
|
10313
|
-
return new SerializedState(spec, db, recentServices);
|
|
9755
|
+
static new(spec, blake2b, db, recentServices = []) {
|
|
9756
|
+
return new SerializedState(spec, blake2b, db, recentServices);
|
|
10314
9757
|
}
|
|
10315
|
-
constructor(spec, backend,
|
|
9758
|
+
constructor(spec, blake2b, backend,
|
|
10316
9759
|
/** Best-effort list of recently active services. */
|
|
10317
9760
|
_recentServiceIds) {
|
|
10318
9761
|
this.spec = spec;
|
|
9762
|
+
this.blake2b = blake2b;
|
|
10319
9763
|
this.backend = backend;
|
|
10320
9764
|
this._recentServiceIds = _recentServiceIds;
|
|
10321
9765
|
}
|
|
@@ -10339,7 +9783,7 @@ class SerializedState {
|
|
|
10339
9783
|
if (!this._recentServiceIds.includes(id)) {
|
|
10340
9784
|
this._recentServiceIds.push(id);
|
|
10341
9785
|
}
|
|
10342
|
-
return new SerializedService(id, serviceData, (key) => this.retrieveOptional(key));
|
|
9786
|
+
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10343
9787
|
}
|
|
10344
9788
|
retrieve({ key, Codec }, description) {
|
|
10345
9789
|
const bytes = this.backend.get(key);
|
|
@@ -10415,12 +9859,14 @@ class SerializedState {
|
|
|
10415
9859
|
}
|
|
10416
9860
|
/** Service data representation on a serialized state. */
|
|
10417
9861
|
class SerializedService {
|
|
9862
|
+
blake2b;
|
|
10418
9863
|
serviceId;
|
|
10419
9864
|
accountInfo;
|
|
10420
9865
|
retrieveOptional;
|
|
10421
|
-
constructor(
|
|
9866
|
+
constructor(blake2b,
|
|
10422
9867
|
/** Service id */
|
|
10423
9868
|
serviceId, accountInfo, retrieveOptional) {
|
|
9869
|
+
this.blake2b = blake2b;
|
|
10424
9870
|
this.serviceId = serviceId;
|
|
10425
9871
|
this.accountInfo = accountInfo;
|
|
10426
9872
|
this.retrieveOptional = retrieveOptional;
|
|
@@ -10433,13 +9879,13 @@ class SerializedService {
|
|
|
10433
9879
|
getStorage(rawKey) {
|
|
10434
9880
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
10435
9881
|
const SERVICE_ID_BYTES = 4;
|
|
10436
|
-
const serviceIdAndKey =
|
|
9882
|
+
const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
10437
9883
|
serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
|
|
10438
9884
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10439
|
-
const key = asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
10440
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, key)) ?? null;
|
|
9885
|
+
const key = asOpaqueType(BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
9886
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10441
9887
|
}
|
|
10442
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, rawKey)) ?? null;
|
|
9888
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10443
9889
|
}
|
|
10444
9890
|
/**
|
|
10445
9891
|
* Check if preimage is present in the DB.
|
|
@@ -10448,15 +9894,15 @@ class SerializedService {
|
|
|
10448
9894
|
*/
|
|
10449
9895
|
hasPreimage(hash) {
|
|
10450
9896
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10451
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) !== undefined;
|
|
9897
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10452
9898
|
}
|
|
10453
9899
|
/** Retrieve preimage from the DB. */
|
|
10454
9900
|
getPreimage(hash) {
|
|
10455
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) ?? null;
|
|
9901
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10456
9902
|
}
|
|
10457
9903
|
/** Retrieve preimage lookup history. */
|
|
10458
9904
|
getLookupHistory(hash, len) {
|
|
10459
|
-
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.serviceId, hash, len));
|
|
9905
|
+
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
10460
9906
|
if (rawSlots === undefined) {
|
|
10461
9907
|
return null;
|
|
10462
9908
|
}
|
|
@@ -10518,7 +9964,7 @@ class TrieNode {
|
|
|
10518
9964
|
raw;
|
|
10519
9965
|
constructor(
|
|
10520
9966
|
/** Exactly 512 bits / 64 bytes */
|
|
10521
|
-
raw =
|
|
9967
|
+
raw = safeAllocUint8Array(TRIE_NODE_BYTES)) {
|
|
10522
9968
|
this.raw = raw;
|
|
10523
9969
|
}
|
|
10524
9970
|
/** Returns the type of the node */
|
|
@@ -11076,7 +10522,7 @@ const bitLookup = [
|
|
|
11076
10522
|
[0b00000000, 8],
|
|
11077
10523
|
];
|
|
11078
10524
|
|
|
11079
|
-
var index$
|
|
10525
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
11080
10526
|
__proto__: null,
|
|
11081
10527
|
BranchNode: BranchNode,
|
|
11082
10528
|
InMemoryTrie: InMemoryTrie,
|
|
@@ -11093,11 +10539,13 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
11093
10539
|
parseInputKey: parseInputKey
|
|
11094
10540
|
});
|
|
11095
10541
|
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
}
|
|
10542
|
+
function getBlake2bTrieHasher(hasher) {
|
|
10543
|
+
return {
|
|
10544
|
+
hashConcat(n, rest = []) {
|
|
10545
|
+
return hasher.hashBlobs([n, ...rest]);
|
|
10546
|
+
},
|
|
10547
|
+
};
|
|
10548
|
+
}
|
|
11101
10549
|
|
|
11102
10550
|
/** What should be done with that key? */
|
|
11103
10551
|
var StateEntryUpdateAction;
|
|
@@ -11109,14 +10557,14 @@ var StateEntryUpdateAction;
|
|
|
11109
10557
|
})(StateEntryUpdateAction || (StateEntryUpdateAction = {}));
|
|
11110
10558
|
const EMPTY_BLOB = BytesBlob.empty();
|
|
11111
10559
|
/** Serialize given state update into a series of key-value pairs. */
|
|
11112
|
-
function* serializeStateUpdate(spec, update) {
|
|
10560
|
+
function* serializeStateUpdate(spec, blake2b, update) {
|
|
11113
10561
|
// first let's serialize all of the simple entries (if present!)
|
|
11114
10562
|
yield* serializeBasicKeys(spec, update);
|
|
11115
10563
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
11116
10564
|
// then let's proceed with service updates
|
|
11117
|
-
yield* serializeServiceUpdates(update.servicesUpdates, encode);
|
|
11118
|
-
yield* serializePreimages(update.preimages, encode);
|
|
11119
|
-
yield* serializeStorage(update.storage);
|
|
10565
|
+
yield* serializeServiceUpdates(update.servicesUpdates, encode, blake2b);
|
|
10566
|
+
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
10567
|
+
yield* serializeStorage(update.storage, blake2b);
|
|
11120
10568
|
yield* serializeRemovedServices(update.servicesRemoved);
|
|
11121
10569
|
}
|
|
11122
10570
|
function* serializeRemovedServices(servicesRemoved) {
|
|
@@ -11126,18 +10574,18 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
11126
10574
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11127
10575
|
}
|
|
11128
10576
|
}
|
|
11129
|
-
function* serializeStorage(storage) {
|
|
10577
|
+
function* serializeStorage(storage, blake2b) {
|
|
11130
10578
|
for (const { action, serviceId } of storage ?? []) {
|
|
11131
10579
|
switch (action.kind) {
|
|
11132
10580
|
case UpdateStorageKind.Set: {
|
|
11133
10581
|
const key = action.storage.key;
|
|
11134
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10582
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11135
10583
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11136
10584
|
break;
|
|
11137
10585
|
}
|
|
11138
10586
|
case UpdateStorageKind.Remove: {
|
|
11139
10587
|
const key = action.key;
|
|
11140
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10588
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11141
10589
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11142
10590
|
break;
|
|
11143
10591
|
}
|
|
@@ -11146,15 +10594,15 @@ function* serializeStorage(storage) {
|
|
|
11146
10594
|
}
|
|
11147
10595
|
}
|
|
11148
10596
|
}
|
|
11149
|
-
function* serializePreimages(preimages, encode) {
|
|
10597
|
+
function* serializePreimages(preimages, encode, blake2b) {
|
|
11150
10598
|
for (const { action, serviceId } of preimages ?? []) {
|
|
11151
10599
|
switch (action.kind) {
|
|
11152
10600
|
case UpdatePreimageKind.Provide: {
|
|
11153
10601
|
const { hash, blob } = action.preimage;
|
|
11154
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10602
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11155
10603
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11156
10604
|
if (action.slot !== null) {
|
|
11157
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, tryAsU32(blob.length));
|
|
10605
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
11158
10606
|
yield [
|
|
11159
10607
|
StateEntryUpdateAction.Insert,
|
|
11160
10608
|
codec2.key,
|
|
@@ -11165,15 +10613,15 @@ function* serializePreimages(preimages, encode) {
|
|
|
11165
10613
|
}
|
|
11166
10614
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11167
10615
|
const { hash, length, slots } = action.item;
|
|
11168
|
-
const codec = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10616
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11169
10617
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11170
10618
|
break;
|
|
11171
10619
|
}
|
|
11172
10620
|
case UpdatePreimageKind.Remove: {
|
|
11173
10621
|
const { hash, length } = action;
|
|
11174
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10622
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11175
10623
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11176
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10624
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11177
10625
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11178
10626
|
break;
|
|
11179
10627
|
}
|
|
@@ -11182,7 +10630,7 @@ function* serializePreimages(preimages, encode) {
|
|
|
11182
10630
|
}
|
|
11183
10631
|
}
|
|
11184
10632
|
}
|
|
11185
|
-
function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
10633
|
+
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11186
10634
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
11187
10635
|
// new service being created or updated
|
|
11188
10636
|
const codec = serialize.serviceData(serviceId);
|
|
@@ -11190,7 +10638,7 @@ function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
|
11190
10638
|
// additional lookup history update
|
|
11191
10639
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11192
10640
|
const { lookupHistory } = action;
|
|
11193
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10641
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11194
10642
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11195
10643
|
}
|
|
11196
10644
|
}
|
|
@@ -11285,8 +10733,8 @@ class StateEntries {
|
|
|
11285
10733
|
},
|
|
11286
10734
|
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11287
10735
|
/** Turn in-memory state into it's serialized form. */
|
|
11288
|
-
static serializeInMemory(spec, state) {
|
|
11289
|
-
return new StateEntries(convertInMemoryStateToDictionary(spec, state));
|
|
10736
|
+
static serializeInMemory(spec, blake2b, state) {
|
|
10737
|
+
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
11290
10738
|
}
|
|
11291
10739
|
/**
|
|
11292
10740
|
* Wrap a collection of truncated state entries and treat it as state.
|
|
@@ -11335,7 +10783,8 @@ class StateEntries {
|
|
|
11335
10783
|
}
|
|
11336
10784
|
}
|
|
11337
10785
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/391600391600?v=0.6.4 */
|
|
11338
|
-
getRootHash() {
|
|
10786
|
+
getRootHash(blake2b) {
|
|
10787
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11339
10788
|
const leaves = SortedSet.fromArray(leafComparator);
|
|
11340
10789
|
for (const [key, value] of this) {
|
|
11341
10790
|
leaves.insert(InMemoryTrie.constructLeaf(blake2bTrieHasher, key.asOpaque(), value));
|
|
@@ -11344,7 +10793,7 @@ class StateEntries {
|
|
|
11344
10793
|
}
|
|
11345
10794
|
}
|
|
11346
10795
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/38a50038a500?v=0.6.4 */
|
|
11347
|
-
function convertInMemoryStateToDictionary(spec, state) {
|
|
10796
|
+
function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
11348
10797
|
const serialized = TruncatedHashDictionary.fromEntries([]);
|
|
11349
10798
|
function doSerialize(codec) {
|
|
11350
10799
|
serialized.set(codec.key, Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
@@ -11372,18 +10821,18 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11372
10821
|
serialized.set(key, Encoder.encodeObject(Codec, service.getInfo()));
|
|
11373
10822
|
// preimages
|
|
11374
10823
|
for (const preimage of service.data.preimages.values()) {
|
|
11375
|
-
const { key, Codec } = serialize.servicePreimages(serviceId, preimage.hash);
|
|
10824
|
+
const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11376
10825
|
serialized.set(key, Encoder.encodeObject(Codec, preimage.blob));
|
|
11377
10826
|
}
|
|
11378
10827
|
// storage
|
|
11379
10828
|
for (const storage of service.data.storage.values()) {
|
|
11380
|
-
const { key, Codec } = serialize.serviceStorage(serviceId, storage.key);
|
|
10829
|
+
const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11381
10830
|
serialized.set(key, Encoder.encodeObject(Codec, storage.value));
|
|
11382
10831
|
}
|
|
11383
10832
|
// lookup history
|
|
11384
10833
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11385
10834
|
for (const lookupHistory of lookupHistoryList) {
|
|
11386
|
-
const { key, Codec } = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10835
|
+
const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11387
10836
|
serialized.set(key, Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11388
10837
|
}
|
|
11389
10838
|
}
|
|
@@ -11391,9 +10840,9 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11391
10840
|
return serialized;
|
|
11392
10841
|
}
|
|
11393
10842
|
|
|
11394
|
-
function loadState(spec, entries) {
|
|
10843
|
+
function loadState(spec, blake2b, entries) {
|
|
11395
10844
|
const stateEntries = StateEntries.fromEntriesUnsafe(entries);
|
|
11396
|
-
return SerializedState.fromStateEntries(spec, stateEntries);
|
|
10845
|
+
return SerializedState.fromStateEntries(spec, blake2b, stateEntries);
|
|
11397
10846
|
}
|
|
11398
10847
|
|
|
11399
10848
|
/**
|
|
@@ -11422,7 +10871,7 @@ function loadState(spec, entries) {
|
|
|
11422
10871
|
* hashmap of `key -> value` entries.
|
|
11423
10872
|
*/
|
|
11424
10873
|
|
|
11425
|
-
var index$
|
|
10874
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
11426
10875
|
__proto__: null,
|
|
11427
10876
|
SerializedService: SerializedService,
|
|
11428
10877
|
SerializedState: SerializedState,
|
|
@@ -11501,7 +10950,8 @@ class LeafDb {
|
|
|
11501
10950
|
}
|
|
11502
10951
|
assertNever(val);
|
|
11503
10952
|
}
|
|
11504
|
-
getStateRoot() {
|
|
10953
|
+
getStateRoot(blake2b) {
|
|
10954
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11505
10955
|
return InMemoryTrie.computeStateRoot(blake2bTrieHasher, this.leaves).asOpaque();
|
|
11506
10956
|
}
|
|
11507
10957
|
intoStateEntries() {
|
|
@@ -11691,7 +11141,8 @@ class InMemoryStates {
|
|
|
11691
11141
|
}
|
|
11692
11142
|
}
|
|
11693
11143
|
async getStateRoot(state) {
|
|
11694
|
-
|
|
11144
|
+
const blake2b = await Blake2b.createHasher();
|
|
11145
|
+
return StateEntries.serializeInMemory(this.spec, blake2b, state).getRootHash(blake2b);
|
|
11695
11146
|
}
|
|
11696
11147
|
/** Insert a full state into the database. */
|
|
11697
11148
|
async insertState(headerHash, state) {
|
|
@@ -11708,7 +11159,7 @@ class InMemoryStates {
|
|
|
11708
11159
|
}
|
|
11709
11160
|
}
|
|
11710
11161
|
|
|
11711
|
-
var index$
|
|
11162
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
11712
11163
|
__proto__: null,
|
|
11713
11164
|
InMemoryBlocks: InMemoryBlocks,
|
|
11714
11165
|
InMemoryStates: InMemoryStates,
|
|
@@ -11769,7 +11220,7 @@ function padAndEncodeData(input) {
|
|
|
11769
11220
|
const paddedLength = Math.ceil(input.length / PIECE_SIZE) * PIECE_SIZE;
|
|
11770
11221
|
let padded = input;
|
|
11771
11222
|
if (input.length !== paddedLength) {
|
|
11772
|
-
padded = BytesBlob.blobFrom(
|
|
11223
|
+
padded = BytesBlob.blobFrom(safeAllocUint8Array(paddedLength));
|
|
11773
11224
|
padded.raw.set(input.raw, 0);
|
|
11774
11225
|
}
|
|
11775
11226
|
return chunkingFunction(padded);
|
|
@@ -11815,7 +11266,7 @@ function decodeData(input) {
|
|
|
11815
11266
|
*/
|
|
11816
11267
|
function encodePoints(input) {
|
|
11817
11268
|
const result = [];
|
|
11818
|
-
const data =
|
|
11269
|
+
const data = safeAllocUint8Array(POINT_ALIGNMENT * N_CHUNKS_REQUIRED);
|
|
11819
11270
|
// add original shards to the result
|
|
11820
11271
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11821
11272
|
const pointStart = POINT_LENGTH * i;
|
|
@@ -11831,7 +11282,7 @@ function encodePoints(input) {
|
|
|
11831
11282
|
const encodedData = encodedResult.take_data();
|
|
11832
11283
|
for (let i = 0; i < N_CHUNKS_REDUNDANCY; i++) {
|
|
11833
11284
|
const pointIndex = i * POINT_ALIGNMENT;
|
|
11834
|
-
const redundancyPoint =
|
|
11285
|
+
const redundancyPoint = safeAllocUint8Array(POINT_LENGTH);
|
|
11835
11286
|
for (let j = 0; j < POINT_LENGTH; j++) {
|
|
11836
11287
|
redundancyPoint[j] = encodedData[pointIndex + j * HALF_POINT_SIZE];
|
|
11837
11288
|
}
|
|
@@ -11846,7 +11297,7 @@ function encodePoints(input) {
|
|
|
11846
11297
|
*/
|
|
11847
11298
|
function decodePiece(input) {
|
|
11848
11299
|
const result = Bytes.zero(PIECE_SIZE);
|
|
11849
|
-
const data =
|
|
11300
|
+
const data = safeAllocUint8Array(N_CHUNKS_REQUIRED * POINT_ALIGNMENT);
|
|
11850
11301
|
const indices = new Uint16Array(input.length);
|
|
11851
11302
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11852
11303
|
const [index, points] = input[i];
|
|
@@ -11962,7 +11413,7 @@ function lace(input) {
|
|
|
11962
11413
|
return BytesBlob.empty();
|
|
11963
11414
|
}
|
|
11964
11415
|
const n = input[0].length;
|
|
11965
|
-
const result = BytesBlob.blobFrom(
|
|
11416
|
+
const result = BytesBlob.blobFrom(safeAllocUint8Array(k * n));
|
|
11966
11417
|
for (let i = 0; i < k; i++) {
|
|
11967
11418
|
const entry = input[i].raw;
|
|
11968
11419
|
for (let j = 0; j < n; j++) {
|
|
@@ -12070,7 +11521,7 @@ const initEc = async () => {
|
|
|
12070
11521
|
await init.reedSolomon();
|
|
12071
11522
|
};
|
|
12072
11523
|
|
|
12073
|
-
var index$
|
|
11524
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
12074
11525
|
__proto__: null,
|
|
12075
11526
|
N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
|
|
12076
11527
|
N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
|
|
@@ -12094,6 +11545,439 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
12094
11545
|
unzip: unzip
|
|
12095
11546
|
});
|
|
12096
11547
|
|
|
11548
|
+
/**
|
|
11549
|
+
* Version ::= SEQUENCE {
|
|
11550
|
+
* major INTEGER (0..255),
|
|
11551
|
+
* minor INTEGER (0..255),
|
|
11552
|
+
* patch INTEGER (0..255)
|
|
11553
|
+
* }
|
|
11554
|
+
*/
|
|
11555
|
+
class Version extends WithDebug {
|
|
11556
|
+
major;
|
|
11557
|
+
minor;
|
|
11558
|
+
patch;
|
|
11559
|
+
static Codec = codec$1.Class(Version, {
|
|
11560
|
+
major: codec$1.u8,
|
|
11561
|
+
minor: codec$1.u8,
|
|
11562
|
+
patch: codec$1.u8,
|
|
11563
|
+
});
|
|
11564
|
+
static tryFromString(str) {
|
|
11565
|
+
const parse = (v) => tryAsU8(Number(v));
|
|
11566
|
+
try {
|
|
11567
|
+
const [major, minor, patch] = str.trim().split(".").map(parse);
|
|
11568
|
+
return Version.create({
|
|
11569
|
+
major,
|
|
11570
|
+
minor,
|
|
11571
|
+
patch,
|
|
11572
|
+
});
|
|
11573
|
+
}
|
|
11574
|
+
catch (e) {
|
|
11575
|
+
throw new Error(`Unable to parse ${str} as Version: ${e}`);
|
|
11576
|
+
}
|
|
11577
|
+
}
|
|
11578
|
+
static create({ major, minor, patch }) {
|
|
11579
|
+
return new Version(major, minor, patch);
|
|
11580
|
+
}
|
|
11581
|
+
constructor(major, minor, patch) {
|
|
11582
|
+
super();
|
|
11583
|
+
this.major = major;
|
|
11584
|
+
this.minor = minor;
|
|
11585
|
+
this.patch = patch;
|
|
11586
|
+
}
|
|
11587
|
+
}
|
|
11588
|
+
/**
|
|
11589
|
+
* Fuzzer Protocol V1
|
|
11590
|
+
* Reference: https://github.com/davxy/jam-conformance/blob/main/fuzz-proto/fuzz.asn
|
|
11591
|
+
*/
|
|
11592
|
+
// Feature bit constants
|
|
11593
|
+
var Features;
|
|
11594
|
+
(function (Features) {
|
|
11595
|
+
Features[Features["Ancestry"] = 1] = "Ancestry";
|
|
11596
|
+
Features[Features["Fork"] = 2] = "Fork";
|
|
11597
|
+
Features[Features["Reserved"] = 2147483648] = "Reserved";
|
|
11598
|
+
})(Features || (Features = {}));
|
|
11599
|
+
/**
|
|
11600
|
+
* PeerInfo ::= SEQUENCE {
|
|
11601
|
+
* fuzz-version U8,
|
|
11602
|
+
* features Features,
|
|
11603
|
+
* jam-version Version,
|
|
11604
|
+
* app-version Version,
|
|
11605
|
+
* name UTF8String
|
|
11606
|
+
* }
|
|
11607
|
+
*/
|
|
11608
|
+
class PeerInfo extends WithDebug {
|
|
11609
|
+
fuzzVersion;
|
|
11610
|
+
features;
|
|
11611
|
+
jamVersion;
|
|
11612
|
+
appVersion;
|
|
11613
|
+
name;
|
|
11614
|
+
static Codec = codec$1.Class(PeerInfo, {
|
|
11615
|
+
fuzzVersion: codec$1.u8,
|
|
11616
|
+
features: codec$1.u32,
|
|
11617
|
+
jamVersion: Version.Codec,
|
|
11618
|
+
appVersion: Version.Codec,
|
|
11619
|
+
name: codec$1.string,
|
|
11620
|
+
});
|
|
11621
|
+
static create({ fuzzVersion, features, appVersion, jamVersion, name }) {
|
|
11622
|
+
return new PeerInfo(fuzzVersion, features, jamVersion, appVersion, name);
|
|
11623
|
+
}
|
|
11624
|
+
constructor(fuzzVersion, features, jamVersion, appVersion, name) {
|
|
11625
|
+
super();
|
|
11626
|
+
this.fuzzVersion = fuzzVersion;
|
|
11627
|
+
this.features = features;
|
|
11628
|
+
this.jamVersion = jamVersion;
|
|
11629
|
+
this.appVersion = appVersion;
|
|
11630
|
+
this.name = name;
|
|
11631
|
+
}
|
|
11632
|
+
}
|
|
11633
|
+
/**
|
|
11634
|
+
* AncestryItem ::= SEQUENCE {
|
|
11635
|
+
* slot TimeSlot,
|
|
11636
|
+
* header-hash HeaderHash
|
|
11637
|
+
* }
|
|
11638
|
+
*/
|
|
11639
|
+
class AncestryItem extends WithDebug {
|
|
11640
|
+
slot;
|
|
11641
|
+
headerHash;
|
|
11642
|
+
static Codec = codec$1.Class(AncestryItem, {
|
|
11643
|
+
slot: codec$1.u32.asOpaque(),
|
|
11644
|
+
headerHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
11645
|
+
});
|
|
11646
|
+
static create({ slot, headerHash }) {
|
|
11647
|
+
return new AncestryItem(slot, headerHash);
|
|
11648
|
+
}
|
|
11649
|
+
constructor(slot, headerHash) {
|
|
11650
|
+
super();
|
|
11651
|
+
this.slot = slot;
|
|
11652
|
+
this.headerHash = headerHash;
|
|
11653
|
+
}
|
|
11654
|
+
}
|
|
11655
|
+
/**
|
|
11656
|
+
* KeyValue ::= SEQUENCE {
|
|
11657
|
+
* key TrieKey,
|
|
11658
|
+
* value OCTET STRING
|
|
11659
|
+
* }
|
|
11660
|
+
*/
|
|
11661
|
+
class KeyValue extends WithDebug {
|
|
11662
|
+
key;
|
|
11663
|
+
value;
|
|
11664
|
+
static Codec = codec$1.Class(KeyValue, {
|
|
11665
|
+
key: codec$1.bytes(TRUNCATED_HASH_SIZE),
|
|
11666
|
+
value: codec$1.blob,
|
|
11667
|
+
});
|
|
11668
|
+
static create({ key, value }) {
|
|
11669
|
+
return new KeyValue(key, value);
|
|
11670
|
+
}
|
|
11671
|
+
constructor(key, value) {
|
|
11672
|
+
super();
|
|
11673
|
+
this.key = key;
|
|
11674
|
+
this.value = value;
|
|
11675
|
+
}
|
|
11676
|
+
}
|
|
11677
|
+
/** State ::= SEQUENCE OF KeyValue */
|
|
11678
|
+
const stateCodec = codec$1.sequenceVarLen(KeyValue.Codec);
|
|
11679
|
+
/**
|
|
11680
|
+
* Ancestry ::= SEQUENCE (SIZE(0..24)) OF AncestryItem
|
|
11681
|
+
* Empty when `feature-ancestry` is not supported by both parties
|
|
11682
|
+
*/
|
|
11683
|
+
const ancestryCodec = codec$1.sequenceVarLen(AncestryItem.Codec, {
|
|
11684
|
+
minLength: 0,
|
|
11685
|
+
maxLength: 24,
|
|
11686
|
+
});
|
|
11687
|
+
/**
|
|
11688
|
+
* Initialize ::= SEQUENCE {
|
|
11689
|
+
* header Header,
|
|
11690
|
+
* keyvals State,
|
|
11691
|
+
* ancestry Ancestry
|
|
11692
|
+
* }
|
|
11693
|
+
*/
|
|
11694
|
+
class Initialize extends WithDebug {
|
|
11695
|
+
header;
|
|
11696
|
+
keyvals;
|
|
11697
|
+
ancestry;
|
|
11698
|
+
static Codec = codec$1.Class(Initialize, {
|
|
11699
|
+
header: Header.Codec,
|
|
11700
|
+
keyvals: stateCodec,
|
|
11701
|
+
ancestry: ancestryCodec,
|
|
11702
|
+
});
|
|
11703
|
+
static create({ header, keyvals, ancestry }) {
|
|
11704
|
+
return new Initialize(header, keyvals, ancestry);
|
|
11705
|
+
}
|
|
11706
|
+
constructor(header, keyvals, ancestry) {
|
|
11707
|
+
super();
|
|
11708
|
+
this.header = header;
|
|
11709
|
+
this.keyvals = keyvals;
|
|
11710
|
+
this.ancestry = ancestry;
|
|
11711
|
+
}
|
|
11712
|
+
}
|
|
11713
|
+
/** GetState ::= HeaderHash */
|
|
11714
|
+
const getStateCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
11715
|
+
/** StateRoot ::= StateRootHash */
|
|
11716
|
+
const stateRootCodec = codec$1.bytes(HASH_SIZE).asOpaque();
|
|
11717
|
+
/** Error ::= UTF8String */
|
|
11718
|
+
class ErrorMessage extends WithDebug {
|
|
11719
|
+
message;
|
|
11720
|
+
static Codec = codec$1.Class(ErrorMessage, {
|
|
11721
|
+
message: codec$1.string,
|
|
11722
|
+
});
|
|
11723
|
+
static create({ message }) {
|
|
11724
|
+
return new ErrorMessage(message);
|
|
11725
|
+
}
|
|
11726
|
+
constructor(message) {
|
|
11727
|
+
super();
|
|
11728
|
+
this.message = message;
|
|
11729
|
+
}
|
|
11730
|
+
}
|
|
11731
|
+
/** Message choice type tags */
|
|
11732
|
+
var MessageType;
|
|
11733
|
+
(function (MessageType) {
|
|
11734
|
+
MessageType[MessageType["PeerInfo"] = 0] = "PeerInfo";
|
|
11735
|
+
MessageType[MessageType["Initialize"] = 1] = "Initialize";
|
|
11736
|
+
MessageType[MessageType["StateRoot"] = 2] = "StateRoot";
|
|
11737
|
+
MessageType[MessageType["ImportBlock"] = 3] = "ImportBlock";
|
|
11738
|
+
MessageType[MessageType["GetState"] = 4] = "GetState";
|
|
11739
|
+
MessageType[MessageType["State"] = 5] = "State";
|
|
11740
|
+
MessageType[MessageType["Error"] = 255] = "Error";
|
|
11741
|
+
})(MessageType || (MessageType = {}));
|
|
11742
|
+
/**
|
|
11743
|
+
* Message ::= CHOICE {
|
|
11744
|
+
* peer-info [0] PeerInfo,
|
|
11745
|
+
* initialize [1] Initialize,
|
|
11746
|
+
* state-root [2] StateRoot,
|
|
11747
|
+
* import-block [3] ImportBlock,
|
|
11748
|
+
* get-state [4] GetState,
|
|
11749
|
+
* state [5] State,
|
|
11750
|
+
* error [255] Error
|
|
11751
|
+
* }
|
|
11752
|
+
*/
|
|
11753
|
+
const messageCodec = codec$1.custom({
|
|
11754
|
+
name: "Message",
|
|
11755
|
+
sizeHint: { bytes: 1, isExact: false },
|
|
11756
|
+
}, (e, msg) => {
|
|
11757
|
+
e.i8(msg.type);
|
|
11758
|
+
switch (msg.type) {
|
|
11759
|
+
case MessageType.PeerInfo:
|
|
11760
|
+
PeerInfo.Codec.encode(e, msg.value);
|
|
11761
|
+
break;
|
|
11762
|
+
case MessageType.Initialize:
|
|
11763
|
+
Initialize.Codec.encode(e, msg.value);
|
|
11764
|
+
break;
|
|
11765
|
+
case MessageType.StateRoot:
|
|
11766
|
+
stateRootCodec.encode(e, msg.value);
|
|
11767
|
+
break;
|
|
11768
|
+
case MessageType.ImportBlock:
|
|
11769
|
+
Block.Codec.View.encode(e, msg.value);
|
|
11770
|
+
break;
|
|
11771
|
+
case MessageType.GetState:
|
|
11772
|
+
getStateCodec.encode(e, msg.value);
|
|
11773
|
+
break;
|
|
11774
|
+
case MessageType.State:
|
|
11775
|
+
stateCodec.encode(e, msg.value);
|
|
11776
|
+
break;
|
|
11777
|
+
case MessageType.Error:
|
|
11778
|
+
ErrorMessage.Codec.encode(e, msg.value);
|
|
11779
|
+
break;
|
|
11780
|
+
default:
|
|
11781
|
+
throw new Error(`Unknown message type: ${msg}`);
|
|
11782
|
+
}
|
|
11783
|
+
}, (d) => {
|
|
11784
|
+
const type = d.u8();
|
|
11785
|
+
switch (type) {
|
|
11786
|
+
case MessageType.PeerInfo:
|
|
11787
|
+
return { type: MessageType.PeerInfo, value: PeerInfo.Codec.decode(d) };
|
|
11788
|
+
case MessageType.Initialize:
|
|
11789
|
+
return { type: MessageType.Initialize, value: Initialize.Codec.decode(d) };
|
|
11790
|
+
case MessageType.StateRoot:
|
|
11791
|
+
return { type: MessageType.StateRoot, value: stateRootCodec.decode(d) };
|
|
11792
|
+
case MessageType.ImportBlock:
|
|
11793
|
+
return { type: MessageType.ImportBlock, value: Block.Codec.View.decode(d) };
|
|
11794
|
+
case MessageType.GetState:
|
|
11795
|
+
return { type: MessageType.GetState, value: getStateCodec.decode(d) };
|
|
11796
|
+
case MessageType.State:
|
|
11797
|
+
return { type: MessageType.State, value: stateCodec.decode(d) };
|
|
11798
|
+
case MessageType.Error:
|
|
11799
|
+
return { type: MessageType.Error, value: ErrorMessage.Codec.decode(d) };
|
|
11800
|
+
default:
|
|
11801
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
11802
|
+
}
|
|
11803
|
+
}, (s) => {
|
|
11804
|
+
const type = s.decoder.u8();
|
|
11805
|
+
switch (type) {
|
|
11806
|
+
case MessageType.PeerInfo:
|
|
11807
|
+
PeerInfo.Codec.View.skip(s);
|
|
11808
|
+
break;
|
|
11809
|
+
case MessageType.Initialize:
|
|
11810
|
+
Initialize.Codec.View.skip(s);
|
|
11811
|
+
break;
|
|
11812
|
+
case MessageType.StateRoot:
|
|
11813
|
+
stateRootCodec.View.skip(s);
|
|
11814
|
+
break;
|
|
11815
|
+
case MessageType.ImportBlock:
|
|
11816
|
+
Block.Codec.View.skip(s);
|
|
11817
|
+
break;
|
|
11818
|
+
case MessageType.GetState:
|
|
11819
|
+
getStateCodec.View.skip(s);
|
|
11820
|
+
break;
|
|
11821
|
+
case MessageType.State:
|
|
11822
|
+
stateCodec.View.skip(s);
|
|
11823
|
+
break;
|
|
11824
|
+
case MessageType.Error:
|
|
11825
|
+
ErrorMessage.Codec.View.skip(s);
|
|
11826
|
+
break;
|
|
11827
|
+
default:
|
|
11828
|
+
throw new Error(`Unknown message type: ${type}`);
|
|
11829
|
+
}
|
|
11830
|
+
});
|
|
11831
|
+
|
|
11832
|
+
const logger$4 = Logger.new(import.meta.filename, "ext-ipc-fuzz-v1");
|
|
11833
|
+
class FuzzTarget {
|
|
11834
|
+
msgHandler;
|
|
11835
|
+
sender;
|
|
11836
|
+
spec;
|
|
11837
|
+
sessionFeatures = 0;
|
|
11838
|
+
constructor(msgHandler, sender, spec) {
|
|
11839
|
+
this.msgHandler = msgHandler;
|
|
11840
|
+
this.sender = sender;
|
|
11841
|
+
this.spec = spec;
|
|
11842
|
+
}
|
|
11843
|
+
async onSocketMessage(msg) {
|
|
11844
|
+
// attempt to decode the messsage
|
|
11845
|
+
try {
|
|
11846
|
+
const message = Decoder.decodeObject(messageCodec, msg, this.spec);
|
|
11847
|
+
logger$4.log `[${message.type}] incoming message`;
|
|
11848
|
+
await this.processAndRespond(message);
|
|
11849
|
+
}
|
|
11850
|
+
catch (e) {
|
|
11851
|
+
logger$4.error `Error while processing fuzz v1 message: ${e}`;
|
|
11852
|
+
logger$4.error `${e}`;
|
|
11853
|
+
if (e instanceof Error) {
|
|
11854
|
+
logger$4.error `${e.stack ?? ""}`;
|
|
11855
|
+
}
|
|
11856
|
+
this.sender.close();
|
|
11857
|
+
}
|
|
11858
|
+
}
|
|
11859
|
+
async processAndRespond(message) {
|
|
11860
|
+
let response = null;
|
|
11861
|
+
switch (message.type) {
|
|
11862
|
+
case MessageType.PeerInfo: {
|
|
11863
|
+
// only support V1
|
|
11864
|
+
if (message.value.fuzzVersion !== 1) {
|
|
11865
|
+
logger$4.warn `Unsupported fuzzer protocol version: ${message.value.fuzzVersion}. Closing`;
|
|
11866
|
+
this.sender.close();
|
|
11867
|
+
return;
|
|
11868
|
+
}
|
|
11869
|
+
// Handle handshake
|
|
11870
|
+
const ourPeerInfo = await this.msgHandler.getPeerInfo(message.value);
|
|
11871
|
+
// Calculate session features (intersection of both peer features)
|
|
11872
|
+
this.sessionFeatures = message.value.features & ourPeerInfo.features;
|
|
11873
|
+
logger$4.info `Handshake completed. Shared features: 0b${this.sessionFeatures.toString(2)}`;
|
|
11874
|
+
logger$4.log `Feature ancestry: ${(this.sessionFeatures & Features.Ancestry) !== 0}`;
|
|
11875
|
+
logger$4.log `Feature fork: ${(this.sessionFeatures & Features.Fork) !== 0}`;
|
|
11876
|
+
response = {
|
|
11877
|
+
type: MessageType.PeerInfo,
|
|
11878
|
+
value: ourPeerInfo,
|
|
11879
|
+
};
|
|
11880
|
+
break;
|
|
11881
|
+
}
|
|
11882
|
+
case MessageType.Initialize: {
|
|
11883
|
+
const stateRoot = await this.msgHandler.initialize(message.value);
|
|
11884
|
+
response = {
|
|
11885
|
+
type: MessageType.StateRoot,
|
|
11886
|
+
value: stateRoot,
|
|
11887
|
+
};
|
|
11888
|
+
break;
|
|
11889
|
+
}
|
|
11890
|
+
case MessageType.ImportBlock: {
|
|
11891
|
+
const result = await this.msgHandler.importBlock(message.value);
|
|
11892
|
+
if (result.isOk) {
|
|
11893
|
+
response = {
|
|
11894
|
+
type: MessageType.StateRoot,
|
|
11895
|
+
value: result.ok,
|
|
11896
|
+
};
|
|
11897
|
+
}
|
|
11898
|
+
else {
|
|
11899
|
+
response = {
|
|
11900
|
+
type: MessageType.Error,
|
|
11901
|
+
value: result.error,
|
|
11902
|
+
};
|
|
11903
|
+
}
|
|
11904
|
+
break;
|
|
11905
|
+
}
|
|
11906
|
+
case MessageType.GetState: {
|
|
11907
|
+
const state = await this.msgHandler.getSerializedState(message.value);
|
|
11908
|
+
response = {
|
|
11909
|
+
type: MessageType.State,
|
|
11910
|
+
value: state,
|
|
11911
|
+
};
|
|
11912
|
+
break;
|
|
11913
|
+
}
|
|
11914
|
+
case MessageType.StateRoot: {
|
|
11915
|
+
logger$4.log `--> Received unexpected 'StateRoot' message from the fuzzer. Closing.`;
|
|
11916
|
+
this.sender.close();
|
|
11917
|
+
return;
|
|
11918
|
+
}
|
|
11919
|
+
case MessageType.State: {
|
|
11920
|
+
logger$4.log `--> Received unexpected 'State' message from the fuzzer. Closing.`;
|
|
11921
|
+
this.sender.close();
|
|
11922
|
+
return;
|
|
11923
|
+
}
|
|
11924
|
+
case MessageType.Error: {
|
|
11925
|
+
logger$4.log `--> Received unexpected 'Error' message from the fuzzer. Closing.`;
|
|
11926
|
+
this.sender.close();
|
|
11927
|
+
return;
|
|
11928
|
+
}
|
|
11929
|
+
default: {
|
|
11930
|
+
logger$4.log `--> Received unexpected message type ${JSON.stringify(message)} from the fuzzer. Closing.`;
|
|
11931
|
+
this.sender.close();
|
|
11932
|
+
try {
|
|
11933
|
+
assertNever(message);
|
|
11934
|
+
}
|
|
11935
|
+
catch {
|
|
11936
|
+
return;
|
|
11937
|
+
}
|
|
11938
|
+
}
|
|
11939
|
+
}
|
|
11940
|
+
if (response !== null) {
|
|
11941
|
+
logger$4.trace `<-- responding with: ${response.type}`;
|
|
11942
|
+
const encoded = Encoder.encodeObject(messageCodec, response, this.spec);
|
|
11943
|
+
this.sender.send(encoded);
|
|
11944
|
+
}
|
|
11945
|
+
else {
|
|
11946
|
+
logger$4.warn `<-- no response generated for: ${message.type}`;
|
|
11947
|
+
}
|
|
11948
|
+
}
|
|
11949
|
+
onClose({ error }) {
|
|
11950
|
+
logger$4.log `Closing the v1 handler. Reason: ${error !== undefined ? error.message : "close"}.`;
|
|
11951
|
+
}
|
|
11952
|
+
/** Check if a specific feature is enabled in the session */
|
|
11953
|
+
hasFeature(feature) {
|
|
11954
|
+
return (this.sessionFeatures & feature) !== 0;
|
|
11955
|
+
}
|
|
11956
|
+
}
|
|
11957
|
+
|
|
11958
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
11959
|
+
__proto__: null,
|
|
11960
|
+
AncestryItem: AncestryItem,
|
|
11961
|
+
ErrorMessage: ErrorMessage,
|
|
11962
|
+
get Features () { return Features; },
|
|
11963
|
+
FuzzTarget: FuzzTarget,
|
|
11964
|
+
Initialize: Initialize,
|
|
11965
|
+
KeyValue: KeyValue,
|
|
11966
|
+
get MessageType () { return MessageType; },
|
|
11967
|
+
PeerInfo: PeerInfo,
|
|
11968
|
+
Version: Version,
|
|
11969
|
+
ancestryCodec: ancestryCodec,
|
|
11970
|
+
getStateCodec: getStateCodec,
|
|
11971
|
+
messageCodec: messageCodec,
|
|
11972
|
+
stateCodec: stateCodec,
|
|
11973
|
+
stateRootCodec: stateRootCodec
|
|
11974
|
+
});
|
|
11975
|
+
|
|
11976
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
11977
|
+
__proto__: null,
|
|
11978
|
+
v1: index$b
|
|
11979
|
+
});
|
|
11980
|
+
|
|
12097
11981
|
/** Size of the transfer memo. */
|
|
12098
11982
|
const TRANSFER_MEMO_BYTES = W_T;
|
|
12099
11983
|
/**
|
|
@@ -12208,6 +12092,8 @@ var NewServiceError;
|
|
|
12208
12092
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
12209
12093
|
/** Service is not privileged to set gratis storage. */
|
|
12210
12094
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
12095
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
12096
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
12211
12097
|
})(NewServiceError || (NewServiceError = {}));
|
|
12212
12098
|
var UpdatePrivilegesError;
|
|
12213
12099
|
(function (UpdatePrivilegesError) {
|
|
@@ -12398,11 +12284,17 @@ class AccumulationStateUpdate {
|
|
|
12398
12284
|
if (from.privilegedServices !== null) {
|
|
12399
12285
|
update.privilegedServices = PrivilegedServices.create({
|
|
12400
12286
|
...from.privilegedServices,
|
|
12401
|
-
|
|
12287
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
12402
12288
|
});
|
|
12403
12289
|
}
|
|
12404
12290
|
return update;
|
|
12405
12291
|
}
|
|
12292
|
+
/** Retrieve and clear pending transfers. */
|
|
12293
|
+
takeTransfers() {
|
|
12294
|
+
const transfers = this.transfers;
|
|
12295
|
+
this.transfers = [];
|
|
12296
|
+
return transfers;
|
|
12297
|
+
}
|
|
12406
12298
|
}
|
|
12407
12299
|
class PartiallyUpdatedState {
|
|
12408
12300
|
state;
|
|
@@ -12599,7 +12491,7 @@ const HostCallResult = {
|
|
|
12599
12491
|
OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
12600
12492
|
/** Index unknown. */
|
|
12601
12493
|
WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
12602
|
-
/** Storage full. */
|
|
12494
|
+
/** Storage full or resource already allocated. */
|
|
12603
12495
|
FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
12604
12496
|
/** Core index unknown. */
|
|
12605
12497
|
CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -12607,7 +12499,7 @@ const HostCallResult = {
|
|
|
12607
12499
|
CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
12608
12500
|
/** Gas limit too low. */
|
|
12609
12501
|
LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
12610
|
-
/** The item is already solicited
|
|
12502
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
12611
12503
|
HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
12612
12504
|
/** The return value indicating general success. */
|
|
12613
12505
|
OK: tryAsU64(0n),
|
|
@@ -12808,7 +12700,7 @@ class Registers {
|
|
|
12808
12700
|
bytes;
|
|
12809
12701
|
asSigned;
|
|
12810
12702
|
asUnsigned;
|
|
12811
|
-
constructor(bytes =
|
|
12703
|
+
constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT)) {
|
|
12812
12704
|
this.bytes = bytes;
|
|
12813
12705
|
check `${bytes.length === NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
12814
12706
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
@@ -12880,10 +12772,16 @@ function signExtend32To64(value) {
|
|
|
12880
12772
|
|
|
12881
12773
|
/** Attempt to convert a number into `HostCallIndex`. */
|
|
12882
12774
|
const tryAsHostCallIndex = (v) => asOpaqueType(tryAsU32(v));
|
|
12775
|
+
/**
|
|
12776
|
+
* Host-call exit reason.
|
|
12777
|
+
*
|
|
12778
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
|
|
12779
|
+
*/
|
|
12883
12780
|
var PvmExecution;
|
|
12884
12781
|
(function (PvmExecution) {
|
|
12885
12782
|
PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
|
|
12886
12783
|
PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
|
|
12784
|
+
PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
|
|
12887
12785
|
})(PvmExecution || (PvmExecution = {}));
|
|
12888
12786
|
/** A utility function to easily trace a bunch of registers. */
|
|
12889
12787
|
function traceRegisters(...regs) {
|
|
@@ -12955,7 +12853,7 @@ class Mask {
|
|
|
12955
12853
|
return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
|
|
12956
12854
|
}
|
|
12957
12855
|
buildLookupTableForward(mask) {
|
|
12958
|
-
const table =
|
|
12856
|
+
const table = safeAllocUint8Array(mask.bitLength);
|
|
12959
12857
|
let lastInstructionOffset = 0;
|
|
12960
12858
|
for (let i = mask.bitLength - 1; i >= 0; i--) {
|
|
12961
12859
|
if (mask.isSet(i)) {
|
|
@@ -14636,11 +14534,6 @@ class BitOps {
|
|
|
14636
14534
|
}
|
|
14637
14535
|
}
|
|
14638
14536
|
|
|
14639
|
-
const MAX_VALUE = 4294967295;
|
|
14640
|
-
const MIN_VALUE = -2147483648;
|
|
14641
|
-
const MAX_SHIFT_U32 = 32;
|
|
14642
|
-
const MAX_SHIFT_U64 = 64n;
|
|
14643
|
-
|
|
14644
14537
|
/**
|
|
14645
14538
|
* Overflowing addition for two-complement representation of 32-bit signed numbers.
|
|
14646
14539
|
*/
|
|
@@ -16490,7 +16383,7 @@ class HostCalls {
|
|
|
16490
16383
|
const regs = pvmInstance.getRegisters();
|
|
16491
16384
|
const maybeAddress = regs.getLowerU32(7);
|
|
16492
16385
|
const maybeLength = regs.getLowerU32(8);
|
|
16493
|
-
const result =
|
|
16386
|
+
const result = safeAllocUint8Array(maybeLength);
|
|
16494
16387
|
const startAddress = tryAsMemoryIndex(maybeAddress);
|
|
16495
16388
|
const loadResult = memory.loadInto(result, startAddress);
|
|
16496
16389
|
if (loadResult.isError) {
|
|
@@ -16518,8 +16411,9 @@ class HostCalls {
|
|
|
16518
16411
|
const index = tryAsHostCallIndex(hostCallIndex);
|
|
16519
16412
|
const hostCall = this.hostCalls.get(index);
|
|
16520
16413
|
const gasBefore = gas.get();
|
|
16521
|
-
|
|
16522
|
-
const
|
|
16414
|
+
// NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
|
|
16415
|
+
const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
|
|
16416
|
+
const underflow = gas.sub(basicGasCost);
|
|
16523
16417
|
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
16524
16418
|
if (underflow) {
|
|
16525
16419
|
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
@@ -16536,6 +16430,10 @@ class HostCalls {
|
|
|
16536
16430
|
status = Status.PANIC;
|
|
16537
16431
|
return this.getReturnValue(status, pvmInstance);
|
|
16538
16432
|
}
|
|
16433
|
+
if (result === PvmExecution.OOG) {
|
|
16434
|
+
status = Status.OOG;
|
|
16435
|
+
return this.getReturnValue(status, pvmInstance);
|
|
16436
|
+
}
|
|
16539
16437
|
if (result === undefined) {
|
|
16540
16438
|
pvmInstance.runProgram();
|
|
16541
16439
|
status = pvmInstance.getStatus();
|
|
@@ -16834,14 +16732,14 @@ class DebuggerAdapter {
|
|
|
16834
16732
|
const page = this.pvm.getMemoryPage(pageNumber);
|
|
16835
16733
|
if (page === null) {
|
|
16836
16734
|
// page wasn't allocated so we return an empty page
|
|
16837
|
-
return
|
|
16735
|
+
return safeAllocUint8Array(PAGE_SIZE$1);
|
|
16838
16736
|
}
|
|
16839
16737
|
if (page.length === PAGE_SIZE$1) {
|
|
16840
16738
|
// page was allocated and has a proper size so we can simply return it
|
|
16841
16739
|
return page;
|
|
16842
16740
|
}
|
|
16843
16741
|
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
16844
|
-
const fullPage =
|
|
16742
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
|
|
16845
16743
|
fullPage.set(page);
|
|
16846
16744
|
return fullPage;
|
|
16847
16745
|
}
|
|
@@ -16936,8 +16834,8 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16936
16834
|
asOpaqueType: asOpaqueType,
|
|
16937
16835
|
assertEmpty: assertEmpty,
|
|
16938
16836
|
assertNever: assertNever,
|
|
16939
|
-
block: index$
|
|
16940
|
-
bytes: index$
|
|
16837
|
+
block: index$l,
|
|
16838
|
+
bytes: index$s,
|
|
16941
16839
|
check: check,
|
|
16942
16840
|
clampU64ToU32: clampU64ToU32,
|
|
16943
16841
|
createResults: createResults,
|
|
@@ -16945,13 +16843,13 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
16945
16843
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
16946
16844
|
getServiceId: getServiceId,
|
|
16947
16845
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
16948
|
-
hash: index$
|
|
16846
|
+
hash: index$o,
|
|
16949
16847
|
inspect: inspect,
|
|
16950
16848
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
16951
16849
|
interpreter: index$7,
|
|
16952
16850
|
isBrowser: isBrowser,
|
|
16953
16851
|
measure: measure,
|
|
16954
|
-
numbers: index$
|
|
16852
|
+
numbers: index$r,
|
|
16955
16853
|
resultToString: resultToString,
|
|
16956
16854
|
seeThrough: seeThrough,
|
|
16957
16855
|
slotsToPreimageStatus: slotsToPreimageStatus,
|
|
@@ -16967,10 +16865,10 @@ const ENTROPY_BYTES = 32;
|
|
|
16967
16865
|
*
|
|
16968
16866
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
16969
16867
|
*/
|
|
16970
|
-
function fisherYatesShuffle(arr, entropy) {
|
|
16868
|
+
function fisherYatesShuffle(blake2b, arr, entropy) {
|
|
16971
16869
|
check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
16972
16870
|
const n = arr.length;
|
|
16973
|
-
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
16871
|
+
const randomNumbers = hashToNumberSequence(blake2b, entropy, arr.length);
|
|
16974
16872
|
const result = new Array(n);
|
|
16975
16873
|
let itemsLeft = n;
|
|
16976
16874
|
for (let i = 0; i < n; i++) {
|
|
@@ -16983,13 +16881,13 @@ function fisherYatesShuffle(arr, entropy) {
|
|
|
16983
16881
|
}
|
|
16984
16882
|
return result;
|
|
16985
16883
|
}
|
|
16986
|
-
function hashToNumberSequence(entropy, length) {
|
|
16884
|
+
function hashToNumberSequence(blake2b, entropy, length) {
|
|
16987
16885
|
const result = new Array(length);
|
|
16988
|
-
const randomBytes =
|
|
16886
|
+
const randomBytes = safeAllocUint8Array(ENTROPY_BYTES + 4);
|
|
16989
16887
|
randomBytes.set(entropy.raw);
|
|
16990
16888
|
for (let i = 0; i < length; i++) {
|
|
16991
16889
|
randomBytes.set(u32AsLeBytes(tryAsU32(Math.floor(i / 8))), ENTROPY_BYTES);
|
|
16992
|
-
const newHash = hashBytes(randomBytes);
|
|
16890
|
+
const newHash = blake2b.hashBytes(randomBytes);
|
|
16993
16891
|
const numberStartIndex = (4 * i) % 32;
|
|
16994
16892
|
const numberEndIndex = numberStartIndex + 4;
|
|
16995
16893
|
const number = leBytesAsU32(newHash.raw.subarray(numberStartIndex, numberEndIndex)) >>> 0;
|
|
@@ -17005,6 +16903,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
17005
16903
|
|
|
17006
16904
|
class JsonServiceInfo {
|
|
17007
16905
|
static fromJson = json.object({
|
|
16906
|
+
...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
|
|
17008
16907
|
code_hash: fromJson.bytes32(),
|
|
17009
16908
|
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
17010
16909
|
min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
@@ -17029,6 +16928,7 @@ class JsonServiceInfo {
|
|
|
17029
16928
|
parentService: parent_service,
|
|
17030
16929
|
});
|
|
17031
16930
|
});
|
|
16931
|
+
version;
|
|
17032
16932
|
code_hash;
|
|
17033
16933
|
balance;
|
|
17034
16934
|
min_item_gas;
|
|
@@ -17063,23 +16963,35 @@ const lookupMetaFromJson = json.object({
|
|
|
17063
16963
|
},
|
|
17064
16964
|
value: json.array("number"),
|
|
17065
16965
|
}, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
|
|
16966
|
+
const preimageStatusFromJson = json.object({
|
|
16967
|
+
hash: fromJson.bytes32(),
|
|
16968
|
+
status: json.array("number"),
|
|
16969
|
+
}, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
|
|
17066
16970
|
class JsonService {
|
|
17067
16971
|
static fromJson = json.object({
|
|
17068
16972
|
id: "number",
|
|
17069
|
-
data:
|
|
17070
|
-
|
|
17071
|
-
|
|
17072
|
-
|
|
17073
|
-
|
|
17074
|
-
|
|
16973
|
+
data: Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
16974
|
+
? {
|
|
16975
|
+
service: JsonServiceInfo.fromJson,
|
|
16976
|
+
preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
16977
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
16978
|
+
lookup_meta: json.optional(json.array(lookupMetaFromJson)),
|
|
16979
|
+
}
|
|
16980
|
+
: {
|
|
16981
|
+
service: JsonServiceInfo.fromJson,
|
|
16982
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
16983
|
+
preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
16984
|
+
preimages_status: json.optional(json.array(preimageStatusFromJson)),
|
|
16985
|
+
},
|
|
17075
16986
|
}, ({ id, data }) => {
|
|
16987
|
+
const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
|
|
17076
16988
|
const lookupHistory = HashDictionary.new();
|
|
17077
|
-
for (const item of data.lookup_meta ?? []) {
|
|
16989
|
+
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
17078
16990
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
17079
|
-
|
|
16991
|
+
const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
16992
|
+
data.push(new LookupHistoryItem(item.hash, length, item.slots));
|
|
17080
16993
|
lookupHistory.set(item.hash, data);
|
|
17081
16994
|
}
|
|
17082
|
-
const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
|
|
17083
16995
|
const storage = new Map();
|
|
17084
16996
|
const entries = (data.storage ?? []).map(({ key, value }) => {
|
|
17085
16997
|
const opaqueKey = asOpaqueType(key);
|
|
@@ -17103,8 +17015,7 @@ const availabilityAssignmentFromJson = json.object({
|
|
|
17103
17015
|
report: workReportFromJson,
|
|
17104
17016
|
timeout: "number",
|
|
17105
17017
|
}, ({ report, timeout }) => {
|
|
17106
|
-
|
|
17107
|
-
return AvailabilityAssignment.create({ workReport: new WithHash(workReportHash, report), timeout });
|
|
17018
|
+
return AvailabilityAssignment.create({ workReport: report, timeout });
|
|
17108
17019
|
});
|
|
17109
17020
|
|
|
17110
17021
|
const disputesRecordsFromJson = json.object({
|
|
@@ -17252,8 +17163,12 @@ class JsonServiceStatistics {
|
|
|
17252
17163
|
extrinsic_count: "number",
|
|
17253
17164
|
accumulate_count: "number",
|
|
17254
17165
|
accumulate_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17255
|
-
|
|
17256
|
-
|
|
17166
|
+
...(Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17167
|
+
? {
|
|
17168
|
+
on_transfers_count: "number",
|
|
17169
|
+
on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17170
|
+
}
|
|
17171
|
+
: {}),
|
|
17257
17172
|
}, ({ 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, }) => {
|
|
17258
17173
|
return ServiceStatistics.create({
|
|
17259
17174
|
providedCount: provided_count,
|
|
@@ -17266,8 +17181,8 @@ class JsonServiceStatistics {
|
|
|
17266
17181
|
extrinsicCount: extrinsic_count,
|
|
17267
17182
|
accumulateCount: accumulate_count,
|
|
17268
17183
|
accumulateGasUsed: accumulate_gas_used,
|
|
17269
|
-
onTransfersCount: on_transfers_count,
|
|
17270
|
-
onTransfersGasUsed: on_transfers_gas_used,
|
|
17184
|
+
onTransfersCount: on_transfers_count ?? tryAsU32(0),
|
|
17185
|
+
onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
|
|
17271
17186
|
});
|
|
17272
17187
|
});
|
|
17273
17188
|
provided_count;
|
|
@@ -17338,6 +17253,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17338
17253
|
chi_m: "number",
|
|
17339
17254
|
chi_a: json.array("number"),
|
|
17340
17255
|
chi_v: "number",
|
|
17256
|
+
chi_r: json.optional("number"),
|
|
17341
17257
|
chi_g: json.nullable(json.array({
|
|
17342
17258
|
service: "number",
|
|
17343
17259
|
gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
|
|
@@ -17349,6 +17265,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17349
17265
|
theta: json.nullable(json.array(accumulationOutput)),
|
|
17350
17266
|
accounts: json.array(JsonService.fromJson),
|
|
17351
17267
|
}, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
|
|
17268
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
17269
|
+
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
17270
|
+
}
|
|
17352
17271
|
return InMemoryState.create({
|
|
17353
17272
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17354
17273
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
@@ -17376,8 +17295,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17376
17295
|
timeslot: tau,
|
|
17377
17296
|
privilegedServices: PrivilegedServices.create({
|
|
17378
17297
|
manager: chi.chi_m,
|
|
17379
|
-
|
|
17380
|
-
|
|
17298
|
+
assigners: chi.chi_a,
|
|
17299
|
+
delegator: chi.chi_v,
|
|
17300
|
+
registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
|
|
17381
17301
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
17382
17302
|
}),
|
|
17383
17303
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|
|
@@ -17410,11 +17330,11 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17410
17330
|
class TransitionHasher {
|
|
17411
17331
|
context;
|
|
17412
17332
|
keccakHasher;
|
|
17413
|
-
|
|
17414
|
-
constructor(context, keccakHasher,
|
|
17333
|
+
blake2b;
|
|
17334
|
+
constructor(context, keccakHasher, blake2b) {
|
|
17415
17335
|
this.context = context;
|
|
17416
17336
|
this.keccakHasher = keccakHasher;
|
|
17417
|
-
this.
|
|
17337
|
+
this.blake2b = blake2b;
|
|
17418
17338
|
}
|
|
17419
17339
|
/** Concatenates two hashes and hash this concatenation */
|
|
17420
17340
|
hashConcat(a, b) {
|
|
@@ -17425,7 +17345,7 @@ class TransitionHasher {
|
|
|
17425
17345
|
}
|
|
17426
17346
|
/** Creates hash from the block header view */
|
|
17427
17347
|
header(header) {
|
|
17428
|
-
return new WithHash(hashBytes(header.encoded()
|
|
17348
|
+
return new WithHash(this.blake2b.hashBytes(header.encoded()).asOpaque(), header);
|
|
17429
17349
|
}
|
|
17430
17350
|
/**
|
|
17431
17351
|
* Merkle commitment of the extrinsic data
|
|
@@ -17438,7 +17358,7 @@ class TransitionHasher {
|
|
|
17438
17358
|
.view()
|
|
17439
17359
|
.map((g) => g.view())
|
|
17440
17360
|
.map((guarantee) => {
|
|
17441
|
-
const reportHash = hashBytes(guarantee.report.encoded()
|
|
17361
|
+
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17442
17362
|
return BytesBlob.blobFromParts([
|
|
17443
17363
|
reportHash.raw,
|
|
17444
17364
|
guarantee.slot.encoded().raw,
|
|
@@ -17446,13 +17366,13 @@ class TransitionHasher {
|
|
|
17446
17366
|
]);
|
|
17447
17367
|
});
|
|
17448
17368
|
const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
17449
|
-
const et = hashBytes(extrinsicView.tickets.encoded()
|
|
17450
|
-
const ep = hashBytes(extrinsicView.preimages.encoded()
|
|
17451
|
-
const eg = hashBytes(guaranteeBlob
|
|
17452
|
-
const ea = hashBytes(extrinsicView.assurances.encoded()
|
|
17453
|
-
const ed = hashBytes(extrinsicView.disputes.encoded()
|
|
17369
|
+
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17370
|
+
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17371
|
+
const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
|
|
17372
|
+
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17373
|
+
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17454
17374
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
17455
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17375
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
17456
17376
|
}
|
|
17457
17377
|
/** Creates hash for given WorkPackage */
|
|
17458
17378
|
workPackage(workPackage) {
|
|
@@ -17461,7 +17381,7 @@ class TransitionHasher {
|
|
|
17461
17381
|
encode(codec, data) {
|
|
17462
17382
|
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
17463
17383
|
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
17464
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17384
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
17465
17385
|
}
|
|
17466
17386
|
}
|
|
17467
17387
|
|
|
@@ -17474,8 +17394,10 @@ var PreimagesErrorCode;
|
|
|
17474
17394
|
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
17475
17395
|
class Preimages {
|
|
17476
17396
|
state;
|
|
17477
|
-
|
|
17397
|
+
blake2b;
|
|
17398
|
+
constructor(state, blake2b) {
|
|
17478
17399
|
this.state = state;
|
|
17400
|
+
this.blake2b = blake2b;
|
|
17479
17401
|
}
|
|
17480
17402
|
integrate(input) {
|
|
17481
17403
|
// make sure lookup extrinsics are sorted and unique
|
|
@@ -17498,7 +17420,7 @@ class Preimages {
|
|
|
17498
17420
|
// select preimages for integration
|
|
17499
17421
|
for (const preimage of preimages) {
|
|
17500
17422
|
const { requester, blob } = preimage;
|
|
17501
|
-
const hash = hashBytes(blob).asOpaque();
|
|
17423
|
+
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
17502
17424
|
const service = this.state.getService(requester);
|
|
17503
17425
|
if (service === null) {
|
|
17504
17426
|
return Result$1.error(PreimagesErrorCode.AccountNotFound);
|
|
@@ -17523,146 +17445,11 @@ class Preimages {
|
|
|
17523
17445
|
}
|
|
17524
17446
|
}
|
|
17525
17447
|
|
|
17526
|
-
class Missing {
|
|
17527
|
-
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
17528
|
-
gasCost = tryAsSmallGas(10);
|
|
17529
|
-
currentServiceId = CURRENT_SERVICE_ID;
|
|
17530
|
-
tracedRegisters = traceRegisters(7);
|
|
17531
|
-
execute(_gas, regs, _memory) {
|
|
17532
|
-
regs.set(7, HostCallResult.WHAT);
|
|
17533
|
-
return Promise.resolve(undefined);
|
|
17534
|
-
}
|
|
17535
|
-
}
|
|
17536
|
-
|
|
17537
|
-
var ServiceExecutorError;
|
|
17538
|
-
(function (ServiceExecutorError) {
|
|
17539
|
-
ServiceExecutorError[ServiceExecutorError["NoLookup"] = 0] = "NoLookup";
|
|
17540
|
-
ServiceExecutorError[ServiceExecutorError["NoState"] = 1] = "NoState";
|
|
17541
|
-
ServiceExecutorError[ServiceExecutorError["NoServiceCode"] = 2] = "NoServiceCode";
|
|
17542
|
-
ServiceExecutorError[ServiceExecutorError["ServiceCodeMismatch"] = 3] = "ServiceCodeMismatch";
|
|
17543
|
-
})(ServiceExecutorError || (ServiceExecutorError = {}));
|
|
17544
|
-
class WorkPackageExecutor {
|
|
17545
|
-
blocks;
|
|
17546
|
-
state;
|
|
17547
|
-
hasher;
|
|
17548
|
-
constructor(blocks, state, hasher) {
|
|
17549
|
-
this.blocks = blocks;
|
|
17550
|
-
this.state = state;
|
|
17551
|
-
this.hasher = hasher;
|
|
17552
|
-
}
|
|
17553
|
-
// TODO [ToDr] this while thing should be triple-checked with the GP.
|
|
17554
|
-
// I'm currently implementing some dirty version for the demo.
|
|
17555
|
-
async executeWorkPackage(pack) {
|
|
17556
|
-
const headerHash = pack.context.lookupAnchor;
|
|
17557
|
-
// execute authorisation first or is it already executed and we just need to check it?
|
|
17558
|
-
const authExec = this.getServiceExecutor(
|
|
17559
|
-
// TODO [ToDr] should this be anchor or lookupAnchor?
|
|
17560
|
-
headerHash, pack.authCodeHost, pack.authCodeHash);
|
|
17561
|
-
if (authExec.isError) {
|
|
17562
|
-
// TODO [ToDr] most likely shouldn't be throw.
|
|
17563
|
-
throw new Error(`Could not get authorization executor: ${authExec.error}`);
|
|
17564
|
-
}
|
|
17565
|
-
const pvm = authExec.ok;
|
|
17566
|
-
const authGas = tryAsGas(15000n);
|
|
17567
|
-
const result = await pvm.run(pack.parametrization, authGas);
|
|
17568
|
-
if (!result.isEqualTo(pack.authorization)) {
|
|
17569
|
-
throw new Error("Authorization is invalid.");
|
|
17570
|
-
}
|
|
17571
|
-
const results = [];
|
|
17572
|
-
for (const item of pack.items) {
|
|
17573
|
-
const exec = this.getServiceExecutor(headerHash, item.service, item.codeHash);
|
|
17574
|
-
if (exec.isError) {
|
|
17575
|
-
throw new Error(`Could not get item executor: ${exec.error}`);
|
|
17576
|
-
}
|
|
17577
|
-
const pvm = exec.ok;
|
|
17578
|
-
const gasRatio = tryAsServiceGas(3000n);
|
|
17579
|
-
const ret = await pvm.run(item.payload, tryAsGas(item.refineGasLimit)); // or accumulateGasLimit?
|
|
17580
|
-
results.push(WorkResult.create({
|
|
17581
|
-
serviceId: item.service,
|
|
17582
|
-
codeHash: item.codeHash,
|
|
17583
|
-
payloadHash: hashBytes(item.payload),
|
|
17584
|
-
gas: gasRatio,
|
|
17585
|
-
result: new WorkExecResult(WorkExecResultKind.ok, ret),
|
|
17586
|
-
load: WorkRefineLoad.create({
|
|
17587
|
-
gasUsed: tryAsServiceGas(5),
|
|
17588
|
-
importedSegments: tryAsU32(0),
|
|
17589
|
-
exportedSegments: tryAsU32(0),
|
|
17590
|
-
extrinsicSize: tryAsU32(0),
|
|
17591
|
-
extrinsicCount: tryAsU32(0),
|
|
17592
|
-
}),
|
|
17593
|
-
}));
|
|
17594
|
-
}
|
|
17595
|
-
const workPackage = this.hasher.workPackage(pack);
|
|
17596
|
-
const workPackageSpec = WorkPackageSpec.create({
|
|
17597
|
-
hash: workPackage.hash,
|
|
17598
|
-
length: tryAsU32(workPackage.encoded.length),
|
|
17599
|
-
erasureRoot: Bytes.zero(HASH_SIZE),
|
|
17600
|
-
exportsRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
17601
|
-
exportsCount: tryAsU16(0),
|
|
17602
|
-
});
|
|
17603
|
-
const coreIndex = tryAsCoreIndex(0);
|
|
17604
|
-
const authorizerHash = Bytes.fill(HASH_SIZE, 5).asOpaque();
|
|
17605
|
-
const workResults = FixedSizeArray.new(results, tryAsWorkItemsCount(results.length));
|
|
17606
|
-
return Promise.resolve(WorkReport.create({
|
|
17607
|
-
workPackageSpec,
|
|
17608
|
-
context: pack.context,
|
|
17609
|
-
coreIndex,
|
|
17610
|
-
authorizerHash,
|
|
17611
|
-
authorizationOutput: pack.authorization,
|
|
17612
|
-
segmentRootLookup: [],
|
|
17613
|
-
results: workResults,
|
|
17614
|
-
authorizationGasUsed: tryAsServiceGas(0),
|
|
17615
|
-
}));
|
|
17616
|
-
}
|
|
17617
|
-
getServiceExecutor(lookupAnchor, serviceId, expectedCodeHash) {
|
|
17618
|
-
const header = this.blocks.getHeader(lookupAnchor);
|
|
17619
|
-
if (header === null) {
|
|
17620
|
-
return Result$1.error(ServiceExecutorError.NoLookup);
|
|
17621
|
-
}
|
|
17622
|
-
const state = this.state.getState(lookupAnchor);
|
|
17623
|
-
if (state === null) {
|
|
17624
|
-
return Result$1.error(ServiceExecutorError.NoState);
|
|
17625
|
-
}
|
|
17626
|
-
const service = state.getService(serviceId);
|
|
17627
|
-
const serviceCodeHash = service?.getInfo().codeHash ?? null;
|
|
17628
|
-
if (serviceCodeHash === null) {
|
|
17629
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
17630
|
-
}
|
|
17631
|
-
if (!serviceCodeHash.isEqualTo(expectedCodeHash)) {
|
|
17632
|
-
return Result$1.error(ServiceExecutorError.ServiceCodeMismatch);
|
|
17633
|
-
}
|
|
17634
|
-
const serviceCode = service?.getPreimage(serviceCodeHash.asOpaque()) ?? null;
|
|
17635
|
-
if (serviceCode === null) {
|
|
17636
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
17637
|
-
}
|
|
17638
|
-
return Result$1.ok(new PvmExecutor(serviceCode));
|
|
17639
|
-
}
|
|
17640
|
-
}
|
|
17641
|
-
class PvmExecutor {
|
|
17642
|
-
serviceCode;
|
|
17643
|
-
pvm;
|
|
17644
|
-
hostCalls = new HostCallsManager({ missing: new Missing() });
|
|
17645
|
-
pvmInstanceManager = new InterpreterInstanceManager(4);
|
|
17646
|
-
constructor(serviceCode) {
|
|
17647
|
-
this.serviceCode = serviceCode;
|
|
17648
|
-
this.pvm = new HostCalls(this.pvmInstanceManager, this.hostCalls);
|
|
17649
|
-
}
|
|
17650
|
-
async run(args, gas) {
|
|
17651
|
-
const program = Program.fromSpi(this.serviceCode.raw, args.raw, true);
|
|
17652
|
-
const result = await this.pvm.runProgram(program.code, 5, gas, program.registers, program.memory);
|
|
17653
|
-
if (result.hasMemorySlice()) {
|
|
17654
|
-
return BytesBlob.blobFrom(result.memorySlice);
|
|
17655
|
-
}
|
|
17656
|
-
return BytesBlob.empty();
|
|
17657
|
-
}
|
|
17658
|
-
}
|
|
17659
|
-
|
|
17660
17448
|
var index = /*#__PURE__*/Object.freeze({
|
|
17661
17449
|
__proto__: null,
|
|
17662
17450
|
Preimages: Preimages,
|
|
17663
17451
|
get PreimagesErrorCode () { return PreimagesErrorCode; },
|
|
17664
|
-
TransitionHasher: TransitionHasher
|
|
17665
|
-
WorkPackageExecutor: WorkPackageExecutor
|
|
17452
|
+
TransitionHasher: TransitionHasher
|
|
17666
17453
|
});
|
|
17667
17454
|
|
|
17668
|
-
export { index$
|
|
17455
|
+
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 };
|