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