@typeberry/lib 0.1.3-462ca77 → 0.1.3-47d06ae
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 +671 -1354
- package/index.d.ts +777 -815
- package/index.js +670 -1353
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var GpVersion;
|
|
|
6
6
|
(function (GpVersion) {
|
|
7
7
|
GpVersion["V0_6_7"] = "0.6.7";
|
|
8
8
|
GpVersion["V0_7_0"] = "0.7.0";
|
|
9
|
-
GpVersion["V0_7_1"] = "0.7.1
|
|
9
|
+
GpVersion["V0_7_1"] = "0.7.1";
|
|
10
10
|
GpVersion["V0_7_2"] = "0.7.2-preview";
|
|
11
11
|
})(GpVersion || (GpVersion = {}));
|
|
12
12
|
var TestSuite;
|
|
@@ -15,11 +15,11 @@ var TestSuite;
|
|
|
15
15
|
TestSuite["JAMDUNA"] = "jamduna";
|
|
16
16
|
})(TestSuite || (TestSuite = {}));
|
|
17
17
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
18
|
-
const
|
|
18
|
+
const DEFAULT_VERSION = GpVersion.V0_7_1;
|
|
19
19
|
const env$1 = typeof process === "undefined" ? {} : process.env;
|
|
20
|
-
const DEFAULT_VERSION = GpVersion.V0_7_0;
|
|
21
20
|
let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
|
|
22
21
|
let CURRENT_SUITE = parseCurrentSuite(env$1.TEST_SUITE) ?? DEFAULT_SUITE;
|
|
22
|
+
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
|
|
23
23
|
function parseCurrentVersion(env) {
|
|
24
24
|
if (env === undefined) {
|
|
25
25
|
return undefined;
|
|
@@ -35,8 +35,9 @@ function parseCurrentVersion(env) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
function parseCurrentSuite(env) {
|
|
38
|
-
if (env === undefined)
|
|
38
|
+
if (env === undefined) {
|
|
39
39
|
return undefined;
|
|
40
|
+
}
|
|
40
41
|
switch (env) {
|
|
41
42
|
case TestSuite.W3F_DAVXY:
|
|
42
43
|
case TestSuite.JAMDUNA:
|
|
@@ -456,10 +457,12 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
456
457
|
.sort((a, b) => {
|
|
457
458
|
const aKey = `${a.key}`;
|
|
458
459
|
const bKey = `${b.key}`;
|
|
459
|
-
if (aKey < bKey)
|
|
460
|
+
if (aKey < bKey) {
|
|
460
461
|
return -1;
|
|
461
|
-
|
|
462
|
+
}
|
|
463
|
+
if (bKey < aKey) {
|
|
462
464
|
return 1;
|
|
465
|
+
}
|
|
463
466
|
return 0;
|
|
464
467
|
});
|
|
465
468
|
};
|
|
@@ -3651,823 +3654,75 @@ var ed25519 = /*#__PURE__*/Object.freeze({
|
|
|
3651
3654
|
verifyBatch: verifyBatch
|
|
3652
3655
|
});
|
|
3653
3656
|
|
|
3657
|
+
const SEED_SIZE = 32;
|
|
3658
|
+
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
3659
|
+
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
3654
3660
|
/**
|
|
3655
|
-
*
|
|
3656
|
-
*
|
|
3657
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
3661
|
+
* JIP-5: Secret key derivation
|
|
3658
3662
|
*
|
|
3659
|
-
*/
|
|
3660
|
-
const HASH_SIZE = 32;
|
|
3661
|
-
/** A hash without last byte (useful for trie representation). */
|
|
3662
|
-
const TRUNCATED_HASH_SIZE = 31;
|
|
3663
|
-
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
3663
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
3664
3664
|
/**
|
|
3665
|
-
*
|
|
3666
|
-
*
|
|
3667
|
-
* After calculating the hash these two should be passed together to avoid
|
|
3668
|
-
* unnecessary re-hashing of the data.
|
|
3665
|
+
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
3666
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
3669
3667
|
*/
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
constructor(hash, data) {
|
|
3674
|
-
super();
|
|
3675
|
-
this.hash = hash;
|
|
3676
|
-
this.data = data;
|
|
3677
|
-
}
|
|
3668
|
+
function trivialSeed(s) {
|
|
3669
|
+
const s_le = u32AsLeBytes(s);
|
|
3670
|
+
return Bytes.fromBlob(BytesBlob.blobFromParts([s_le, s_le, s_le, s_le, s_le, s_le, s_le, s_le]).raw, SEED_SIZE).asOpaque();
|
|
3678
3671
|
}
|
|
3679
3672
|
/**
|
|
3680
|
-
*
|
|
3673
|
+
* Derives a Ed25519 secret key from a seed.
|
|
3674
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
3681
3675
|
*/
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
constructor(hash, data, encoded) {
|
|
3685
|
-
super(hash, data);
|
|
3686
|
-
this.encoded = encoded;
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
|
|
3690
|
-
/** The simplest allocator returning just a fresh copy of bytes each time. */
|
|
3691
|
-
class SimpleAllocator {
|
|
3692
|
-
emptyHash() {
|
|
3693
|
-
return Bytes.zero(HASH_SIZE);
|
|
3694
|
-
}
|
|
3695
|
-
}
|
|
3696
|
-
/** An allocator that works by allocating larger (continuous) pages of memory. */
|
|
3697
|
-
class PageAllocator {
|
|
3698
|
-
hashesPerPage;
|
|
3699
|
-
page = safeAllocUint8Array(0);
|
|
3700
|
-
currentHash = 0;
|
|
3701
|
-
// TODO [ToDr] Benchmark the performance!
|
|
3702
|
-
constructor(hashesPerPage) {
|
|
3703
|
-
this.hashesPerPage = hashesPerPage;
|
|
3704
|
-
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
3705
|
-
this.resetPage();
|
|
3706
|
-
}
|
|
3707
|
-
resetPage() {
|
|
3708
|
-
const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
|
|
3709
|
-
this.currentHash = 0;
|
|
3710
|
-
this.page = safeAllocUint8Array(pageSizeBytes);
|
|
3711
|
-
}
|
|
3712
|
-
emptyHash() {
|
|
3713
|
-
const startIdx = this.currentHash * HASH_SIZE;
|
|
3714
|
-
const endIdx = startIdx + HASH_SIZE;
|
|
3715
|
-
this.currentHash += 1;
|
|
3716
|
-
if (this.currentHash >= this.hashesPerPage) {
|
|
3717
|
-
this.resetPage();
|
|
3718
|
-
}
|
|
3719
|
-
return Bytes.fromBlob(this.page.subarray(startIdx, endIdx), HASH_SIZE);
|
|
3720
|
-
}
|
|
3721
|
-
}
|
|
3722
|
-
const defaultAllocator = new SimpleAllocator();
|
|
3723
|
-
|
|
3724
|
-
function getDefaultExportFromCjs (x) {
|
|
3725
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3726
|
-
}
|
|
3727
|
-
|
|
3728
|
-
var blake2b$3 = {exports: {}};
|
|
3729
|
-
|
|
3730
|
-
var nanoassert;
|
|
3731
|
-
var hasRequiredNanoassert;
|
|
3732
|
-
|
|
3733
|
-
function requireNanoassert () {
|
|
3734
|
-
if (hasRequiredNanoassert) return nanoassert;
|
|
3735
|
-
hasRequiredNanoassert = 1;
|
|
3736
|
-
nanoassert = assert;
|
|
3737
|
-
|
|
3738
|
-
class AssertionError extends Error {}
|
|
3739
|
-
AssertionError.prototype.name = 'AssertionError';
|
|
3740
|
-
|
|
3741
|
-
/**
|
|
3742
|
-
* Minimal assert function
|
|
3743
|
-
* @param {any} t Value to check if falsy
|
|
3744
|
-
* @param {string=} m Optional assertion error message
|
|
3745
|
-
* @throws {AssertionError}
|
|
3746
|
-
*/
|
|
3747
|
-
function assert (t, m) {
|
|
3748
|
-
if (!t) {
|
|
3749
|
-
var err = new AssertionError(m);
|
|
3750
|
-
if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
|
|
3751
|
-
throw err
|
|
3752
|
-
}
|
|
3753
|
-
}
|
|
3754
|
-
return nanoassert;
|
|
3755
|
-
}
|
|
3756
|
-
|
|
3757
|
-
var blake2bWasm = {exports: {}};
|
|
3758
|
-
|
|
3759
|
-
var b4a;
|
|
3760
|
-
var hasRequiredB4a;
|
|
3761
|
-
|
|
3762
|
-
function requireB4a () {
|
|
3763
|
-
if (hasRequiredB4a) return b4a;
|
|
3764
|
-
hasRequiredB4a = 1;
|
|
3765
|
-
function isBuffer (value) {
|
|
3766
|
-
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
3767
|
-
}
|
|
3768
|
-
|
|
3769
|
-
function isEncoding (encoding) {
|
|
3770
|
-
return Buffer.isEncoding(encoding)
|
|
3771
|
-
}
|
|
3772
|
-
|
|
3773
|
-
function alloc (size, fill, encoding) {
|
|
3774
|
-
return Buffer.alloc(size, fill, encoding)
|
|
3775
|
-
}
|
|
3776
|
-
|
|
3777
|
-
function allocUnsafe (size) {
|
|
3778
|
-
return Buffer.allocUnsafe(size)
|
|
3779
|
-
}
|
|
3780
|
-
|
|
3781
|
-
function allocUnsafeSlow (size) {
|
|
3782
|
-
return Buffer.allocUnsafeSlow(size)
|
|
3783
|
-
}
|
|
3784
|
-
|
|
3785
|
-
function byteLength (string, encoding) {
|
|
3786
|
-
return Buffer.byteLength(string, encoding)
|
|
3787
|
-
}
|
|
3788
|
-
|
|
3789
|
-
function compare (a, b) {
|
|
3790
|
-
return Buffer.compare(a, b)
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
function concat (buffers, totalLength) {
|
|
3794
|
-
return Buffer.concat(buffers, totalLength)
|
|
3795
|
-
}
|
|
3796
|
-
|
|
3797
|
-
function copy (source, target, targetStart, start, end) {
|
|
3798
|
-
return toBuffer(source).copy(target, targetStart, start, end)
|
|
3799
|
-
}
|
|
3800
|
-
|
|
3801
|
-
function equals (a, b) {
|
|
3802
|
-
return toBuffer(a).equals(b)
|
|
3803
|
-
}
|
|
3804
|
-
|
|
3805
|
-
function fill (buffer, value, offset, end, encoding) {
|
|
3806
|
-
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
3807
|
-
}
|
|
3808
|
-
|
|
3809
|
-
function from (value, encodingOrOffset, length) {
|
|
3810
|
-
return Buffer.from(value, encodingOrOffset, length)
|
|
3811
|
-
}
|
|
3812
|
-
|
|
3813
|
-
function includes (buffer, value, byteOffset, encoding) {
|
|
3814
|
-
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
3818
|
-
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
3819
|
-
}
|
|
3820
|
-
|
|
3821
|
-
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
3822
|
-
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
3823
|
-
}
|
|
3824
|
-
|
|
3825
|
-
function swap16 (buffer) {
|
|
3826
|
-
return toBuffer(buffer).swap16()
|
|
3827
|
-
}
|
|
3828
|
-
|
|
3829
|
-
function swap32 (buffer) {
|
|
3830
|
-
return toBuffer(buffer).swap32()
|
|
3831
|
-
}
|
|
3832
|
-
|
|
3833
|
-
function swap64 (buffer) {
|
|
3834
|
-
return toBuffer(buffer).swap64()
|
|
3835
|
-
}
|
|
3836
|
-
|
|
3837
|
-
function toBuffer (buffer) {
|
|
3838
|
-
if (Buffer.isBuffer(buffer)) return buffer
|
|
3839
|
-
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
3840
|
-
}
|
|
3841
|
-
|
|
3842
|
-
function toString (buffer, encoding, start, end) {
|
|
3843
|
-
return toBuffer(buffer).toString(encoding, start, end)
|
|
3844
|
-
}
|
|
3845
|
-
|
|
3846
|
-
function write (buffer, string, offset, length, encoding) {
|
|
3847
|
-
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
3848
|
-
}
|
|
3849
|
-
|
|
3850
|
-
function writeDoubleLE (buffer, value, offset) {
|
|
3851
|
-
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
3852
|
-
}
|
|
3853
|
-
|
|
3854
|
-
function writeFloatLE (buffer, value, offset) {
|
|
3855
|
-
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
3856
|
-
}
|
|
3857
|
-
|
|
3858
|
-
function writeUInt32LE (buffer, value, offset) {
|
|
3859
|
-
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
3860
|
-
}
|
|
3861
|
-
|
|
3862
|
-
function writeInt32LE (buffer, value, offset) {
|
|
3863
|
-
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
3864
|
-
}
|
|
3865
|
-
|
|
3866
|
-
function readDoubleLE (buffer, offset) {
|
|
3867
|
-
return toBuffer(buffer).readDoubleLE(offset)
|
|
3868
|
-
}
|
|
3869
|
-
|
|
3870
|
-
function readFloatLE (buffer, offset) {
|
|
3871
|
-
return toBuffer(buffer).readFloatLE(offset)
|
|
3872
|
-
}
|
|
3873
|
-
|
|
3874
|
-
function readUInt32LE (buffer, offset) {
|
|
3875
|
-
return toBuffer(buffer).readUInt32LE(offset)
|
|
3876
|
-
}
|
|
3877
|
-
|
|
3878
|
-
function readInt32LE (buffer, offset) {
|
|
3879
|
-
return toBuffer(buffer).readInt32LE(offset)
|
|
3880
|
-
}
|
|
3881
|
-
|
|
3882
|
-
b4a = {
|
|
3883
|
-
isBuffer,
|
|
3884
|
-
isEncoding,
|
|
3885
|
-
alloc,
|
|
3886
|
-
allocUnsafe,
|
|
3887
|
-
allocUnsafeSlow,
|
|
3888
|
-
byteLength,
|
|
3889
|
-
compare,
|
|
3890
|
-
concat,
|
|
3891
|
-
copy,
|
|
3892
|
-
equals,
|
|
3893
|
-
fill,
|
|
3894
|
-
from,
|
|
3895
|
-
includes,
|
|
3896
|
-
indexOf,
|
|
3897
|
-
lastIndexOf,
|
|
3898
|
-
swap16,
|
|
3899
|
-
swap32,
|
|
3900
|
-
swap64,
|
|
3901
|
-
toBuffer,
|
|
3902
|
-
toString,
|
|
3903
|
-
write,
|
|
3904
|
-
writeDoubleLE,
|
|
3905
|
-
writeFloatLE,
|
|
3906
|
-
writeUInt32LE,
|
|
3907
|
-
writeInt32LE,
|
|
3908
|
-
readDoubleLE,
|
|
3909
|
-
readFloatLE,
|
|
3910
|
-
readUInt32LE,
|
|
3911
|
-
readInt32LE
|
|
3912
|
-
};
|
|
3913
|
-
return b4a;
|
|
3914
|
-
}
|
|
3915
|
-
|
|
3916
|
-
var blake2b$2;
|
|
3917
|
-
var hasRequiredBlake2b$1;
|
|
3918
|
-
|
|
3919
|
-
function requireBlake2b$1 () {
|
|
3920
|
-
if (hasRequiredBlake2b$1) return blake2b$2;
|
|
3921
|
-
hasRequiredBlake2b$1 = 1;
|
|
3922
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3923
|
-
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3924
|
-
};
|
|
3925
|
-
var __toBinary = /* @__PURE__ */ (() => {
|
|
3926
|
-
var table = new Uint8Array(128);
|
|
3927
|
-
for (var i = 0; i < 64; i++)
|
|
3928
|
-
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
3929
|
-
return (base64) => {
|
|
3930
|
-
var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
3931
|
-
for (var i2 = 0, j = 0; i2 < n; ) {
|
|
3932
|
-
var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
3933
|
-
var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
3934
|
-
bytes2[j++] = c0 << 2 | c1 >> 4;
|
|
3935
|
-
bytes2[j++] = c1 << 4 | c2 >> 2;
|
|
3936
|
-
bytes2[j++] = c2 << 6 | c3;
|
|
3937
|
-
}
|
|
3938
|
-
return bytes2;
|
|
3939
|
-
};
|
|
3940
|
-
})();
|
|
3941
|
-
|
|
3942
|
-
// wasm-binary:./blake2b.wat
|
|
3943
|
-
var require_blake2b = __commonJS({
|
|
3944
|
-
"wasm-binary:./blake2b.wat"(exports2, module2) {
|
|
3945
|
-
module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAI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GIAuFQj+KIQYgAiAHIBF8fCECIA0gAoVCIIohDSAMIA18IQwgByAMhUIYiiEHIAIgByATfHwhAiANIAKFQhCKIQ0gDCANfCEMIAcgDIVCP4ohByADIAggHHx8IQMgDiADhUIgiiEOIAkgDnwhCSAIIAmFQhiKIQggAyAIIBh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
|
|
3946
|
-
}
|
|
3947
|
-
});
|
|
3948
|
-
|
|
3949
|
-
// wasm-module:./blake2b.wat
|
|
3950
|
-
var bytes = require_blake2b();
|
|
3951
|
-
var compiled = WebAssembly.compile(bytes);
|
|
3952
|
-
blake2b$2 = async (imports) => {
|
|
3953
|
-
const instance = await WebAssembly.instantiate(await compiled, imports);
|
|
3954
|
-
return instance.exports;
|
|
3955
|
-
};
|
|
3956
|
-
return blake2b$2;
|
|
3957
|
-
}
|
|
3958
|
-
|
|
3959
|
-
var hasRequiredBlake2bWasm;
|
|
3960
|
-
|
|
3961
|
-
function requireBlake2bWasm () {
|
|
3962
|
-
if (hasRequiredBlake2bWasm) return blake2bWasm.exports;
|
|
3963
|
-
hasRequiredBlake2bWasm = 1;
|
|
3964
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
3965
|
-
var b4a = /*@__PURE__*/ requireB4a();
|
|
3966
|
-
|
|
3967
|
-
var wasm = null;
|
|
3968
|
-
var wasmPromise = typeof WebAssembly !== "undefined" && /*@__PURE__*/ requireBlake2b$1()().then(mod => {
|
|
3969
|
-
wasm = mod;
|
|
3970
|
-
});
|
|
3971
|
-
|
|
3972
|
-
var head = 64;
|
|
3973
|
-
var freeList = [];
|
|
3974
|
-
|
|
3975
|
-
blake2bWasm.exports = Blake2b;
|
|
3976
|
-
var BYTES_MIN = blake2bWasm.exports.BYTES_MIN = 16;
|
|
3977
|
-
var BYTES_MAX = blake2bWasm.exports.BYTES_MAX = 64;
|
|
3978
|
-
blake2bWasm.exports.BYTES = 32;
|
|
3979
|
-
var KEYBYTES_MIN = blake2bWasm.exports.KEYBYTES_MIN = 16;
|
|
3980
|
-
var KEYBYTES_MAX = blake2bWasm.exports.KEYBYTES_MAX = 64;
|
|
3981
|
-
blake2bWasm.exports.KEYBYTES = 32;
|
|
3982
|
-
var SALTBYTES = blake2bWasm.exports.SALTBYTES = 16;
|
|
3983
|
-
var PERSONALBYTES = blake2bWasm.exports.PERSONALBYTES = 16;
|
|
3984
|
-
|
|
3985
|
-
function Blake2b (digestLength, key, salt, personal, noAssert) {
|
|
3986
|
-
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
|
|
3987
|
-
if (!wasm) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
|
|
3988
|
-
if (!digestLength) digestLength = 32;
|
|
3989
|
-
|
|
3990
|
-
if (noAssert !== true) {
|
|
3991
|
-
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength);
|
|
3992
|
-
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength);
|
|
3993
|
-
if (key != null) {
|
|
3994
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
3995
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
3996
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at least ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
3997
|
-
}
|
|
3998
|
-
if (salt != null) {
|
|
3999
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4000
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4001
|
-
}
|
|
4002
|
-
if (personal != null) {
|
|
4003
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4004
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4005
|
-
}
|
|
4006
|
-
}
|
|
4007
|
-
|
|
4008
|
-
if (!freeList.length) {
|
|
4009
|
-
freeList.push(head);
|
|
4010
|
-
head += 216;
|
|
4011
|
-
}
|
|
4012
|
-
|
|
4013
|
-
this.digestLength = digestLength;
|
|
4014
|
-
this.finalized = false;
|
|
4015
|
-
this.pointer = freeList.pop();
|
|
4016
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4017
|
-
|
|
4018
|
-
this._memory.fill(0, 0, 64);
|
|
4019
|
-
this._memory[0] = this.digestLength;
|
|
4020
|
-
this._memory[1] = key ? key.length : 0;
|
|
4021
|
-
this._memory[2] = 1; // fanout
|
|
4022
|
-
this._memory[3] = 1; // depth
|
|
4023
|
-
|
|
4024
|
-
if (salt) this._memory.set(salt, 32);
|
|
4025
|
-
if (personal) this._memory.set(personal, 48);
|
|
4026
|
-
|
|
4027
|
-
if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216); // we need 216 bytes for the state
|
|
4028
|
-
wasm.blake2b_init(this.pointer, this.digestLength);
|
|
4029
|
-
|
|
4030
|
-
if (key) {
|
|
4031
|
-
this.update(key);
|
|
4032
|
-
this._memory.fill(0, head, head + key.length); // whiteout key
|
|
4033
|
-
this._memory[this.pointer + 200] = 128;
|
|
4034
|
-
}
|
|
4035
|
-
}
|
|
4036
|
-
|
|
4037
|
-
Blake2b.prototype._realloc = function (size) {
|
|
4038
|
-
wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
|
|
4039
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4040
|
-
};
|
|
4041
|
-
|
|
4042
|
-
Blake2b.prototype.update = function (input) {
|
|
4043
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4044
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4045
|
-
|
|
4046
|
-
if (head + input.length > this._memory.length) this._realloc(head + input.length);
|
|
4047
|
-
this._memory.set(input, head);
|
|
4048
|
-
wasm.blake2b_update(this.pointer, head, head + input.length);
|
|
4049
|
-
return this
|
|
4050
|
-
};
|
|
4051
|
-
|
|
4052
|
-
Blake2b.prototype.digest = function (enc) {
|
|
4053
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4054
|
-
this.finalized = true;
|
|
4055
|
-
|
|
4056
|
-
freeList.push(this.pointer);
|
|
4057
|
-
wasm.blake2b_final(this.pointer);
|
|
4058
|
-
|
|
4059
|
-
if (!enc || enc === 'binary') {
|
|
4060
|
-
return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4061
|
-
}
|
|
4062
|
-
|
|
4063
|
-
if (typeof enc === 'string') {
|
|
4064
|
-
return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4065
|
-
}
|
|
4066
|
-
|
|
4067
|
-
assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
|
|
4068
|
-
for (var i = 0; i < this.digestLength; i++) {
|
|
4069
|
-
enc[i] = this._memory[this.pointer + 128 + i];
|
|
4070
|
-
}
|
|
4071
|
-
|
|
4072
|
-
return enc
|
|
4073
|
-
};
|
|
4074
|
-
|
|
4075
|
-
// libsodium compat
|
|
4076
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4077
|
-
|
|
4078
|
-
Blake2b.WASM = wasm;
|
|
4079
|
-
Blake2b.SUPPORTED = typeof WebAssembly !== 'undefined';
|
|
4080
|
-
|
|
4081
|
-
Blake2b.ready = function (cb) {
|
|
4082
|
-
if (!cb) cb = noop;
|
|
4083
|
-
if (!wasmPromise) return cb(new Error('WebAssembly not supported'))
|
|
4084
|
-
return wasmPromise.then(() => cb(), cb)
|
|
4085
|
-
};
|
|
4086
|
-
|
|
4087
|
-
Blake2b.prototype.ready = Blake2b.ready;
|
|
4088
|
-
|
|
4089
|
-
Blake2b.prototype.getPartialHash = function () {
|
|
4090
|
-
return this._memory.slice(this.pointer, this.pointer + 216);
|
|
4091
|
-
};
|
|
4092
|
-
|
|
4093
|
-
Blake2b.prototype.setPartialHash = function (ph) {
|
|
4094
|
-
this._memory.set(ph, this.pointer);
|
|
4095
|
-
};
|
|
4096
|
-
|
|
4097
|
-
function noop () {}
|
|
4098
|
-
return blake2bWasm.exports;
|
|
4099
|
-
}
|
|
4100
|
-
|
|
4101
|
-
var hasRequiredBlake2b;
|
|
4102
|
-
|
|
4103
|
-
function requireBlake2b () {
|
|
4104
|
-
if (hasRequiredBlake2b) return blake2b$3.exports;
|
|
4105
|
-
hasRequiredBlake2b = 1;
|
|
4106
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
4107
|
-
var b2wasm = /*@__PURE__*/ requireBlake2bWasm();
|
|
4108
|
-
|
|
4109
|
-
// 64-bit unsigned addition
|
|
4110
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
4111
|
-
// v should be a Uint32Array
|
|
4112
|
-
function ADD64AA (v, a, b) {
|
|
4113
|
-
var o0 = v[a] + v[b];
|
|
4114
|
-
var o1 = v[a + 1] + v[b + 1];
|
|
4115
|
-
if (o0 >= 0x100000000) {
|
|
4116
|
-
o1++;
|
|
4117
|
-
}
|
|
4118
|
-
v[a] = o0;
|
|
4119
|
-
v[a + 1] = o1;
|
|
4120
|
-
}
|
|
4121
|
-
|
|
4122
|
-
// 64-bit unsigned addition
|
|
4123
|
-
// Sets v[a,a+1] += b
|
|
4124
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
4125
|
-
function ADD64AC (v, a, b0, b1) {
|
|
4126
|
-
var o0 = v[a] + b0;
|
|
4127
|
-
if (b0 < 0) {
|
|
4128
|
-
o0 += 0x100000000;
|
|
4129
|
-
}
|
|
4130
|
-
var o1 = v[a + 1] + b1;
|
|
4131
|
-
if (o0 >= 0x100000000) {
|
|
4132
|
-
o1++;
|
|
4133
|
-
}
|
|
4134
|
-
v[a] = o0;
|
|
4135
|
-
v[a + 1] = o1;
|
|
4136
|
-
}
|
|
4137
|
-
|
|
4138
|
-
// Little-endian byte access
|
|
4139
|
-
function B2B_GET32 (arr, i) {
|
|
4140
|
-
return (arr[i] ^
|
|
4141
|
-
(arr[i + 1] << 8) ^
|
|
4142
|
-
(arr[i + 2] << 16) ^
|
|
4143
|
-
(arr[i + 3] << 24))
|
|
4144
|
-
}
|
|
4145
|
-
|
|
4146
|
-
// G Mixing function
|
|
4147
|
-
// The ROTRs are inlined for speed
|
|
4148
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
4149
|
-
var x0 = m[ix];
|
|
4150
|
-
var x1 = m[ix + 1];
|
|
4151
|
-
var y0 = m[iy];
|
|
4152
|
-
var y1 = m[iy + 1];
|
|
4153
|
-
|
|
4154
|
-
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
4155
|
-
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
4156
|
-
|
|
4157
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
4158
|
-
var xor0 = v[d] ^ v[a];
|
|
4159
|
-
var xor1 = v[d + 1] ^ v[a + 1];
|
|
4160
|
-
v[d] = xor1;
|
|
4161
|
-
v[d + 1] = xor0;
|
|
4162
|
-
|
|
4163
|
-
ADD64AA(v, c, d);
|
|
4164
|
-
|
|
4165
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
4166
|
-
xor0 = v[b] ^ v[c];
|
|
4167
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4168
|
-
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
4169
|
-
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
4170
|
-
|
|
4171
|
-
ADD64AA(v, a, b);
|
|
4172
|
-
ADD64AC(v, a, y0, y1);
|
|
4173
|
-
|
|
4174
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
4175
|
-
xor0 = v[d] ^ v[a];
|
|
4176
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
4177
|
-
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
4178
|
-
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
4179
|
-
|
|
4180
|
-
ADD64AA(v, c, d);
|
|
4181
|
-
|
|
4182
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
4183
|
-
xor0 = v[b] ^ v[c];
|
|
4184
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4185
|
-
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
4186
|
-
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
4187
|
-
}
|
|
4188
|
-
|
|
4189
|
-
// Initialization Vector
|
|
4190
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
4191
|
-
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
4192
|
-
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
4193
|
-
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
4194
|
-
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
4195
|
-
]);
|
|
4196
|
-
|
|
4197
|
-
var SIGMA8 = [
|
|
4198
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4199
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
4200
|
-
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
4201
|
-
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
4202
|
-
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
4203
|
-
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
4204
|
-
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
4205
|
-
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
4206
|
-
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
4207
|
-
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
4208
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4209
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
4210
|
-
];
|
|
4211
|
-
|
|
4212
|
-
// These are offsets into a uint64 buffer.
|
|
4213
|
-
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
4214
|
-
// because this is Javascript and we don't have uint64s
|
|
4215
|
-
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }));
|
|
4216
|
-
|
|
4217
|
-
// Compression function. 'last' flag indicates last block.
|
|
4218
|
-
// Note we're representing 16 uint64s as 32 uint32s
|
|
4219
|
-
var v = new Uint32Array(32);
|
|
4220
|
-
var m = new Uint32Array(32);
|
|
4221
|
-
function blake2bCompress (ctx, last) {
|
|
4222
|
-
var i = 0;
|
|
4223
|
-
|
|
4224
|
-
// init work variables
|
|
4225
|
-
for (i = 0; i < 16; i++) {
|
|
4226
|
-
v[i] = ctx.h[i];
|
|
4227
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
4228
|
-
}
|
|
4229
|
-
|
|
4230
|
-
// low 64 bits of offset
|
|
4231
|
-
v[24] = v[24] ^ ctx.t;
|
|
4232
|
-
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
4233
|
-
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
4234
|
-
|
|
4235
|
-
// last block flag set ?
|
|
4236
|
-
if (last) {
|
|
4237
|
-
v[28] = ~v[28];
|
|
4238
|
-
v[29] = ~v[29];
|
|
4239
|
-
}
|
|
4240
|
-
|
|
4241
|
-
// get little-endian words
|
|
4242
|
-
for (i = 0; i < 32; i++) {
|
|
4243
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
4244
|
-
}
|
|
4245
|
-
|
|
4246
|
-
// twelve rounds of mixing
|
|
4247
|
-
for (i = 0; i < 12; i++) {
|
|
4248
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
4249
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
4250
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
4251
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
4252
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
4253
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
4254
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
4255
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
4256
|
-
}
|
|
4257
|
-
|
|
4258
|
-
for (i = 0; i < 16; i++) {
|
|
4259
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
4260
|
-
}
|
|
4261
|
-
}
|
|
4262
|
-
|
|
4263
|
-
// reusable parameter_block
|
|
4264
|
-
var parameter_block = new Uint8Array([
|
|
4265
|
-
0, 0, 0, 0, // 0: outlen, keylen, fanout, depth
|
|
4266
|
-
0, 0, 0, 0, // 4: leaf length, sequential mode
|
|
4267
|
-
0, 0, 0, 0, // 8: node offset
|
|
4268
|
-
0, 0, 0, 0, // 12: node offset
|
|
4269
|
-
0, 0, 0, 0, // 16: node depth, inner length, rfu
|
|
4270
|
-
0, 0, 0, 0, // 20: rfu
|
|
4271
|
-
0, 0, 0, 0, // 24: rfu
|
|
4272
|
-
0, 0, 0, 0, // 28: rfu
|
|
4273
|
-
0, 0, 0, 0, // 32: salt
|
|
4274
|
-
0, 0, 0, 0, // 36: salt
|
|
4275
|
-
0, 0, 0, 0, // 40: salt
|
|
4276
|
-
0, 0, 0, 0, // 44: salt
|
|
4277
|
-
0, 0, 0, 0, // 48: personal
|
|
4278
|
-
0, 0, 0, 0, // 52: personal
|
|
4279
|
-
0, 0, 0, 0, // 56: personal
|
|
4280
|
-
0, 0, 0, 0 // 60: personal
|
|
4281
|
-
]);
|
|
4282
|
-
|
|
4283
|
-
// Creates a BLAKE2b hashing context
|
|
4284
|
-
// Requires an output length between 1 and 64 bytes
|
|
4285
|
-
// Takes an optional Uint8Array key
|
|
4286
|
-
function Blake2b (outlen, key, salt, personal) {
|
|
4287
|
-
// zero out parameter_block before usage
|
|
4288
|
-
parameter_block.fill(0);
|
|
4289
|
-
// state, 'param block'
|
|
4290
|
-
|
|
4291
|
-
this.b = new Uint8Array(128);
|
|
4292
|
-
this.h = new Uint32Array(16);
|
|
4293
|
-
this.t = 0; // input count
|
|
4294
|
-
this.c = 0; // pointer within buffer
|
|
4295
|
-
this.outlen = outlen; // output length in bytes
|
|
4296
|
-
|
|
4297
|
-
parameter_block[0] = outlen;
|
|
4298
|
-
if (key) parameter_block[1] = key.length;
|
|
4299
|
-
parameter_block[2] = 1; // fanout
|
|
4300
|
-
parameter_block[3] = 1; // depth
|
|
4301
|
-
|
|
4302
|
-
if (salt) parameter_block.set(salt, 32);
|
|
4303
|
-
if (personal) parameter_block.set(personal, 48);
|
|
4304
|
-
|
|
4305
|
-
// initialize hash state
|
|
4306
|
-
for (var i = 0; i < 16; i++) {
|
|
4307
|
-
this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
|
|
4308
|
-
}
|
|
4309
|
-
|
|
4310
|
-
// key the hash, if applicable
|
|
4311
|
-
if (key) {
|
|
4312
|
-
blake2bUpdate(this, key);
|
|
4313
|
-
// at the end
|
|
4314
|
-
this.c = 128;
|
|
4315
|
-
}
|
|
4316
|
-
}
|
|
4317
|
-
|
|
4318
|
-
Blake2b.prototype.update = function (input) {
|
|
4319
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4320
|
-
blake2bUpdate(this, input);
|
|
4321
|
-
return this
|
|
4322
|
-
};
|
|
4323
|
-
|
|
4324
|
-
Blake2b.prototype.digest = function (out) {
|
|
4325
|
-
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out;
|
|
4326
|
-
assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
|
|
4327
|
-
assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
|
|
4328
|
-
blake2bFinal(this, buf);
|
|
4329
|
-
if (out === 'hex') return hexSlice(buf)
|
|
4330
|
-
return buf
|
|
4331
|
-
};
|
|
4332
|
-
|
|
4333
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4334
|
-
|
|
4335
|
-
Blake2b.ready = function (cb) {
|
|
4336
|
-
b2wasm.ready(function () {
|
|
4337
|
-
cb(); // ignore the error
|
|
4338
|
-
});
|
|
4339
|
-
};
|
|
4340
|
-
|
|
4341
|
-
// Updates a BLAKE2b streaming hash
|
|
4342
|
-
// Requires hash context and Uint8Array (byte array)
|
|
4343
|
-
function blake2bUpdate (ctx, input) {
|
|
4344
|
-
for (var i = 0; i < input.length; i++) {
|
|
4345
|
-
if (ctx.c === 128) { // buffer full ?
|
|
4346
|
-
ctx.t += ctx.c; // add counters
|
|
4347
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
4348
|
-
ctx.c = 0; // counter to zero
|
|
4349
|
-
}
|
|
4350
|
-
ctx.b[ctx.c++] = input[i];
|
|
4351
|
-
}
|
|
4352
|
-
}
|
|
4353
|
-
|
|
4354
|
-
// Completes a BLAKE2b streaming hash
|
|
4355
|
-
// Returns a Uint8Array containing the message digest
|
|
4356
|
-
function blake2bFinal (ctx, out) {
|
|
4357
|
-
ctx.t += ctx.c; // mark last block offset
|
|
4358
|
-
|
|
4359
|
-
while (ctx.c < 128) { // fill up with zeros
|
|
4360
|
-
ctx.b[ctx.c++] = 0;
|
|
4361
|
-
}
|
|
4362
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
4363
|
-
|
|
4364
|
-
for (var i = 0; i < ctx.outlen; i++) {
|
|
4365
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
4366
|
-
}
|
|
4367
|
-
return out
|
|
4368
|
-
}
|
|
4369
|
-
|
|
4370
|
-
function hexSlice (buf) {
|
|
4371
|
-
var str = '';
|
|
4372
|
-
for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
|
|
4373
|
-
return str
|
|
4374
|
-
}
|
|
4375
|
-
|
|
4376
|
-
function toHex (n) {
|
|
4377
|
-
if (n < 16) return '0' + n.toString(16)
|
|
4378
|
-
return n.toString(16)
|
|
4379
|
-
}
|
|
4380
|
-
|
|
4381
|
-
var Proto = Blake2b;
|
|
4382
|
-
|
|
4383
|
-
blake2b$3.exports = function createHash (outlen, key, salt, personal, noAssert) {
|
|
4384
|
-
if (noAssert !== true) {
|
|
4385
|
-
assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen);
|
|
4386
|
-
assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen);
|
|
4387
|
-
if (key != null) {
|
|
4388
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
4389
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
4390
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
4391
|
-
}
|
|
4392
|
-
if (salt != null) {
|
|
4393
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4394
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4395
|
-
}
|
|
4396
|
-
if (personal != null) {
|
|
4397
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4398
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4399
|
-
}
|
|
4400
|
-
}
|
|
4401
|
-
|
|
4402
|
-
return new Proto(outlen, key, salt, personal)
|
|
4403
|
-
};
|
|
4404
|
-
|
|
4405
|
-
blake2b$3.exports.ready = function (cb) {
|
|
4406
|
-
b2wasm.ready(function () { // ignore errors
|
|
4407
|
-
cb();
|
|
4408
|
-
});
|
|
4409
|
-
};
|
|
4410
|
-
|
|
4411
|
-
blake2b$3.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
|
|
4412
|
-
blake2b$3.exports.WASM_LOADED = false;
|
|
4413
|
-
|
|
4414
|
-
var BYTES_MIN = blake2b$3.exports.BYTES_MIN = 16;
|
|
4415
|
-
var BYTES_MAX = blake2b$3.exports.BYTES_MAX = 64;
|
|
4416
|
-
blake2b$3.exports.BYTES = 32;
|
|
4417
|
-
var KEYBYTES_MIN = blake2b$3.exports.KEYBYTES_MIN = 16;
|
|
4418
|
-
var KEYBYTES_MAX = blake2b$3.exports.KEYBYTES_MAX = 64;
|
|
4419
|
-
blake2b$3.exports.KEYBYTES = 32;
|
|
4420
|
-
var SALTBYTES = blake2b$3.exports.SALTBYTES = 16;
|
|
4421
|
-
var PERSONALBYTES = blake2b$3.exports.PERSONALBYTES = 16;
|
|
4422
|
-
|
|
4423
|
-
b2wasm.ready(function (err) {
|
|
4424
|
-
if (!err) {
|
|
4425
|
-
blake2b$3.exports.WASM_LOADED = true;
|
|
4426
|
-
blake2b$3.exports = b2wasm;
|
|
4427
|
-
}
|
|
4428
|
-
});
|
|
4429
|
-
return blake2b$3.exports;
|
|
3676
|
+
function deriveEd25519SecretKey(seed, blake2b) {
|
|
3677
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4430
3678
|
}
|
|
4431
|
-
|
|
4432
|
-
var blake2bExports = /*@__PURE__*/ requireBlake2b();
|
|
4433
|
-
var blake2b$1 = /*@__PURE__*/getDefaultExportFromCjs(blake2bExports);
|
|
4434
|
-
|
|
4435
3679
|
/**
|
|
4436
|
-
*
|
|
4437
|
-
*
|
|
4438
|
-
* If empty array is given a zero-hash is returned.
|
|
3680
|
+
* Derives a Bandersnatch secret key from a seed.
|
|
3681
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4439
3682
|
*/
|
|
4440
|
-
function
|
|
4441
|
-
|
|
4442
|
-
if (r.length === 0) {
|
|
4443
|
-
return out.asOpaque();
|
|
4444
|
-
}
|
|
4445
|
-
const hasher = blake2b$1(HASH_SIZE);
|
|
4446
|
-
for (const v of r) {
|
|
4447
|
-
hasher?.update(v instanceof BytesBlob ? v.raw : v);
|
|
4448
|
-
}
|
|
4449
|
-
hasher?.digest(out.raw);
|
|
4450
|
-
return out.asOpaque();
|
|
3683
|
+
function deriveBandersnatchSecretKey(seed, blake2b) {
|
|
3684
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4451
3685
|
}
|
|
4452
|
-
/**
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
const out = allocator.emptyHash();
|
|
4458
|
-
hasher?.digest(out.raw);
|
|
4459
|
-
return out;
|
|
3686
|
+
/**
|
|
3687
|
+
* Derive Ed25519 public key from secret seed
|
|
3688
|
+
*/
|
|
3689
|
+
async function deriveEd25519PublicKey(seed) {
|
|
3690
|
+
return (await privateKey(seed)).pubKey;
|
|
4460
3691
|
}
|
|
4461
|
-
/**
|
|
4462
|
-
|
|
4463
|
-
|
|
3692
|
+
/**
|
|
3693
|
+
* Derive Bandersnatch public key from secret seed
|
|
3694
|
+
*/
|
|
3695
|
+
function deriveBandersnatchPublicKey(seed) {
|
|
3696
|
+
return publicKey(seed.raw);
|
|
4464
3697
|
}
|
|
4465
3698
|
|
|
4466
|
-
var
|
|
3699
|
+
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
3700
|
+
__proto__: null,
|
|
3701
|
+
SEED_SIZE: SEED_SIZE,
|
|
3702
|
+
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
3703
|
+
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
3704
|
+
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
3705
|
+
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
3706
|
+
trivialSeed: trivialSeed
|
|
3707
|
+
});
|
|
3708
|
+
|
|
3709
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4467
3710
|
__proto__: null,
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
3711
|
+
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
3712
|
+
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
3713
|
+
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
3714
|
+
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
3715
|
+
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
3716
|
+
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
3717
|
+
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
3718
|
+
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
3719
|
+
Ed25519Pair: Ed25519Pair,
|
|
3720
|
+
SEED_SIZE: SEED_SIZE,
|
|
3721
|
+
bandersnatch: bandersnatch,
|
|
3722
|
+
bandersnatchWasm: bandersnatch_exports,
|
|
3723
|
+
ed25519: ed25519,
|
|
3724
|
+
initWasm: initAll,
|
|
3725
|
+
keyDerivation: keyDerivation
|
|
4471
3726
|
});
|
|
4472
3727
|
|
|
4473
3728
|
/*!
|
|
@@ -4828,24 +4083,95 @@ function WASMInterface(binary, hashLength) {
|
|
|
4828
4083
|
|
|
4829
4084
|
new Mutex();
|
|
4830
4085
|
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
new Mutex();
|
|
4840
|
-
|
|
4841
|
-
new Mutex();
|
|
4842
|
-
|
|
4843
|
-
new Mutex();
|
|
4086
|
+
var name$j = "blake2b";
|
|
4087
|
+
var data$j = "AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2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JCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=";
|
|
4088
|
+
var hash$j = "c6f286e6";
|
|
4089
|
+
var wasmJson$j = {
|
|
4090
|
+
name: name$j,
|
|
4091
|
+
data: data$j,
|
|
4092
|
+
hash: hash$j
|
|
4093
|
+
};
|
|
4844
4094
|
|
|
4845
4095
|
new Mutex();
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4096
|
+
function validateBits$4(bits) {
|
|
4097
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
4098
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
4099
|
+
}
|
|
4100
|
+
return null;
|
|
4101
|
+
}
|
|
4102
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
4103
|
+
return outputBits | (keyBits << 16);
|
|
4104
|
+
}
|
|
4105
|
+
/**
|
|
4106
|
+
* Creates a new BLAKE2b hash instance
|
|
4107
|
+
* @param bits Number of output bits, which has to be a number
|
|
4108
|
+
* divisible by 8, between 8 and 512. Defaults to 512.
|
|
4109
|
+
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
|
|
4110
|
+
*/
|
|
4111
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
4112
|
+
if (validateBits$4(bits)) {
|
|
4113
|
+
return Promise.reject(validateBits$4(bits));
|
|
4114
|
+
}
|
|
4115
|
+
let keyBuffer = null;
|
|
4116
|
+
let initParam = bits;
|
|
4117
|
+
if (key !== null) {
|
|
4118
|
+
keyBuffer = getUInt8Buffer(key);
|
|
4119
|
+
if (keyBuffer.length > 64) {
|
|
4120
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
4121
|
+
}
|
|
4122
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
4123
|
+
}
|
|
4124
|
+
const outputSize = bits / 8;
|
|
4125
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
4126
|
+
if (initParam > 512) {
|
|
4127
|
+
wasm.writeMemory(keyBuffer);
|
|
4128
|
+
}
|
|
4129
|
+
wasm.init(initParam);
|
|
4130
|
+
const obj = {
|
|
4131
|
+
init: initParam > 512
|
|
4132
|
+
? () => {
|
|
4133
|
+
wasm.writeMemory(keyBuffer);
|
|
4134
|
+
wasm.init(initParam);
|
|
4135
|
+
return obj;
|
|
4136
|
+
}
|
|
4137
|
+
: () => {
|
|
4138
|
+
wasm.init(initParam);
|
|
4139
|
+
return obj;
|
|
4140
|
+
},
|
|
4141
|
+
update: (data) => {
|
|
4142
|
+
wasm.update(data);
|
|
4143
|
+
return obj;
|
|
4144
|
+
},
|
|
4145
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
4146
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
4147
|
+
save: () => wasm.save(),
|
|
4148
|
+
load: (data) => {
|
|
4149
|
+
wasm.load(data);
|
|
4150
|
+
return obj;
|
|
4151
|
+
},
|
|
4152
|
+
blockSize: 128,
|
|
4153
|
+
digestSize: outputSize,
|
|
4154
|
+
};
|
|
4155
|
+
return obj;
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
new Mutex();
|
|
4160
|
+
|
|
4161
|
+
new Mutex();
|
|
4162
|
+
|
|
4163
|
+
new Mutex();
|
|
4164
|
+
|
|
4165
|
+
new Mutex();
|
|
4166
|
+
|
|
4167
|
+
new Mutex();
|
|
4168
|
+
|
|
4169
|
+
new Mutex();
|
|
4170
|
+
|
|
4171
|
+
new Mutex();
|
|
4172
|
+
|
|
4173
|
+
var name$b = "sha3";
|
|
4174
|
+
var data$b = "AGFzbQEAAAABFARgAA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3A9iKAUEAQgA3A9CKAUEAQgA3A8iKAUEAQgA3A8CKAUEAQgA3A7iKAUEAQgA3A7CKAUEAQgA3A6iKAUEAQgA3A6CKAUEAQgA3A5iKAUEAQgA3A5CKAUEAQgA3A4iKAUEAQgA3A4CKAUEAQcAMIAFBAXRrQQN2NgKMjQFBAEEANgKIjQEgABACQeQAQQAoAoyNASIAQQF2ayEDAkBBACgCiI0BIgFBAEgNACAAIQQCQCAAIAFGDQAgAUHIiwFqIQVBACEBA0AgBSABakEAOgAAIAFBAWoiASAAQQAoAoiNASIEa0kNAAsLIARByIsBaiIBIAEtAAAgAnI6AAAgAEHHiwFqIgEgAS0AAEGAAXI6AABByIsBIAAQA0EAQYCAgIB4NgKIjQELAkAgA0EESQ0AIANBAnYiAUEDcSEFQQAhBAJAIAFBf2pBA0kNACABQfz///8DcSEAQQAhAUEAIQQDQCABQYAKaiABQYCKAWooAgA2AgAgAUGECmogAUGEigFqKAIANgIAIAFBiApqIAFBiIoBaigCADYCACABQYwKaiABQYyKAWooAgA2AgAgAUEQaiEBIAAgBEEEaiIERw0ACwsgBUUNACAFQQJ0IQAgBEECdCEBA0AgAUGACmogAUGAigFqKAIANgIAIAFBBGohASAAQXxqIgANAAsLCwvYAQEAQYAIC9ABkAEAAAAAAAAAAAAAAAAAAAEAAAAAAAAAgoAAAAAAAACKgAAAAAAAgACAAIAAAACAi4AAAAAAAAABAACAAAAAAIGAAIAAAACACYAAAAAAAICKAAAAAAAAAIgAAAAAAAAACYAAgAAAAAAKAACAAAAAAIuAAIAAAAAAiwAAAAAAAICJgAAAAAAAgAOAAAAAAACAAoAAAAAAAICAAAAAAAAAgAqAAAAAAAAACgAAgAAAAICBgACAAAAAgICAAAAAAACAAQAAgAAAAAAIgACAAAAAgA==";
|
|
4849
4175
|
var hash$b = "fb24e536";
|
|
4850
4176
|
var wasmJson$b = {
|
|
4851
4177
|
name: name$b,
|
|
@@ -4918,6 +4244,79 @@ new Mutex();
|
|
|
4918
4244
|
|
|
4919
4245
|
new Mutex();
|
|
4920
4246
|
|
|
4247
|
+
/**
|
|
4248
|
+
* Size of the output of the hash functions.
|
|
4249
|
+
*
|
|
4250
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
4251
|
+
*
|
|
4252
|
+
*/
|
|
4253
|
+
const HASH_SIZE = 32;
|
|
4254
|
+
/** A hash without last byte (useful for trie representation). */
|
|
4255
|
+
const TRUNCATED_HASH_SIZE = 31;
|
|
4256
|
+
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
4257
|
+
/**
|
|
4258
|
+
* Container for some object with a hash that is related to this object.
|
|
4259
|
+
*
|
|
4260
|
+
* After calculating the hash these two should be passed together to avoid
|
|
4261
|
+
* unnecessary re-hashing of the data.
|
|
4262
|
+
*/
|
|
4263
|
+
class WithHash extends WithDebug {
|
|
4264
|
+
hash;
|
|
4265
|
+
data;
|
|
4266
|
+
constructor(hash, data) {
|
|
4267
|
+
super();
|
|
4268
|
+
this.hash = hash;
|
|
4269
|
+
this.data = data;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
/**
|
|
4273
|
+
* Extension of [`WithHash`] additionally containing an encoded version of the object.
|
|
4274
|
+
*/
|
|
4275
|
+
class WithHashAndBytes extends WithHash {
|
|
4276
|
+
encoded;
|
|
4277
|
+
constructor(hash, data, encoded) {
|
|
4278
|
+
super(hash, data);
|
|
4279
|
+
this.encoded = encoded;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
|
|
4283
|
+
const zero$1 = Bytes.zero(HASH_SIZE);
|
|
4284
|
+
class Blake2b {
|
|
4285
|
+
hasher;
|
|
4286
|
+
static async createHasher() {
|
|
4287
|
+
return new Blake2b(await createBLAKE2b(HASH_SIZE * 8));
|
|
4288
|
+
}
|
|
4289
|
+
constructor(hasher) {
|
|
4290
|
+
this.hasher = hasher;
|
|
4291
|
+
}
|
|
4292
|
+
/**
|
|
4293
|
+
* Hash given collection of blobs.
|
|
4294
|
+
*
|
|
4295
|
+
* If empty array is given a zero-hash is returned.
|
|
4296
|
+
*/
|
|
4297
|
+
hashBlobs(r) {
|
|
4298
|
+
if (r.length === 0) {
|
|
4299
|
+
return zero$1.asOpaque();
|
|
4300
|
+
}
|
|
4301
|
+
const hasher = this.hasher.init();
|
|
4302
|
+
for (const v of r) {
|
|
4303
|
+
hasher.update(v instanceof BytesBlob ? v.raw : v);
|
|
4304
|
+
}
|
|
4305
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4306
|
+
}
|
|
4307
|
+
/** Hash given blob of bytes. */
|
|
4308
|
+
hashBytes(blob) {
|
|
4309
|
+
const hasher = this.hasher.init();
|
|
4310
|
+
const bytes = blob instanceof BytesBlob ? blob.raw : blob;
|
|
4311
|
+
hasher.update(bytes);
|
|
4312
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4313
|
+
}
|
|
4314
|
+
/** Convert given string into bytes and hash it. */
|
|
4315
|
+
hashString(str) {
|
|
4316
|
+
return this.hashBytes(BytesBlob.blobFromString(str));
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4921
4320
|
class KeccakHasher {
|
|
4922
4321
|
hasher;
|
|
4923
4322
|
static async create() {
|
|
@@ -4942,91 +4341,61 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4942
4341
|
hashBlobs: hashBlobs
|
|
4943
4342
|
});
|
|
4944
4343
|
|
|
4945
|
-
|
|
4344
|
+
// TODO [ToDr] (#213) this should most likely be moved to a separate
|
|
4345
|
+
// package to avoid pulling in unnecessary deps.
|
|
4346
|
+
|
|
4347
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4946
4348
|
__proto__: null,
|
|
4349
|
+
Blake2b: Blake2b,
|
|
4947
4350
|
HASH_SIZE: HASH_SIZE,
|
|
4948
|
-
PageAllocator: PageAllocator,
|
|
4949
|
-
SimpleAllocator: SimpleAllocator,
|
|
4950
4351
|
TRUNCATED_HASH_SIZE: TRUNCATED_HASH_SIZE,
|
|
4951
4352
|
WithHash: WithHash,
|
|
4952
4353
|
WithHashAndBytes: WithHashAndBytes,
|
|
4953
4354
|
ZERO_HASH: ZERO_HASH,
|
|
4954
|
-
blake2b: blake2b,
|
|
4955
|
-
defaultAllocator: defaultAllocator,
|
|
4956
4355
|
keccak: keccak
|
|
4957
4356
|
});
|
|
4958
4357
|
|
|
4959
|
-
const SEED_SIZE = 32;
|
|
4960
|
-
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
4961
|
-
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
4962
4358
|
/**
|
|
4963
|
-
*
|
|
4964
|
-
*
|
|
4965
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
4966
|
-
/**
|
|
4967
|
-
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
4968
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
4359
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
4969
4360
|
*/
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
}
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
}
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4361
|
+
class ArrayView {
|
|
4362
|
+
start;
|
|
4363
|
+
end;
|
|
4364
|
+
source;
|
|
4365
|
+
length;
|
|
4366
|
+
constructor(source, start, end) {
|
|
4367
|
+
this.start = start;
|
|
4368
|
+
this.end = end;
|
|
4369
|
+
this.source = source;
|
|
4370
|
+
this.length = end - start;
|
|
4371
|
+
}
|
|
4372
|
+
static from(source, start = 0, end = source.length) {
|
|
4373
|
+
check `
|
|
4374
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
4375
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
4376
|
+
`;
|
|
4377
|
+
return new ArrayView(source, start, end);
|
|
4378
|
+
}
|
|
4379
|
+
get(i) {
|
|
4380
|
+
check `
|
|
4381
|
+
${i >= 0 && i < this.length}
|
|
4382
|
+
Index out of bounds: ${i} < ${this.length}
|
|
4383
|
+
`;
|
|
4384
|
+
return this.source[this.start + i];
|
|
4385
|
+
}
|
|
4386
|
+
subview(from, to = this.length) {
|
|
4387
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
4388
|
+
}
|
|
4389
|
+
toArray() {
|
|
4390
|
+
return this.source.slice(this.start, this.end);
|
|
4391
|
+
}
|
|
4392
|
+
*[Symbol.iterator]() {
|
|
4393
|
+
for (let i = this.start; i < this.end; i++) {
|
|
4394
|
+
yield this.source[i];
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4999
4397
|
}
|
|
5000
4398
|
|
|
5001
|
-
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
5002
|
-
__proto__: null,
|
|
5003
|
-
SEED_SIZE: SEED_SIZE,
|
|
5004
|
-
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
5005
|
-
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
5006
|
-
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
5007
|
-
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
5008
|
-
trivialSeed: trivialSeed
|
|
5009
|
-
});
|
|
5010
|
-
|
|
5011
|
-
var index$o = /*#__PURE__*/Object.freeze({
|
|
5012
|
-
__proto__: null,
|
|
5013
|
-
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
5014
|
-
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
5015
|
-
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
5016
|
-
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
5017
|
-
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
5018
|
-
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
5019
|
-
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
5020
|
-
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
5021
|
-
Ed25519Pair: Ed25519Pair,
|
|
5022
|
-
SEED_SIZE: SEED_SIZE,
|
|
5023
|
-
bandersnatch: bandersnatch,
|
|
5024
|
-
bandersnatchWasm: bandersnatch_exports,
|
|
5025
|
-
ed25519: ed25519,
|
|
5026
|
-
initWasm: initAll,
|
|
5027
|
-
keyDerivation: keyDerivation
|
|
5028
|
-
});
|
|
5029
|
-
|
|
5030
4399
|
/** A map which uses hashes as keys. */
|
|
5031
4400
|
class HashDictionary {
|
|
5032
4401
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
@@ -5614,6 +4983,7 @@ class TruncatedHashDictionary {
|
|
|
5614
4983
|
|
|
5615
4984
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
5616
4985
|
__proto__: null,
|
|
4986
|
+
ArrayView: ArrayView,
|
|
5617
4987
|
FixedSizeArray: FixedSizeArray,
|
|
5618
4988
|
HashDictionary: HashDictionary,
|
|
5619
4989
|
HashSet: HashSet,
|
|
@@ -7934,7 +7304,7 @@ var chain_spec$1 = {
|
|
|
7934
7304
|
"0d000000000000000000000000000000000000000000000000000000000000": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
7935
7305
|
"01000000000000000000000000000000000000000000000000000000000000": "080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978",
|
|
7936
7306
|
"10000000000000000000000000000000000000000000000000000000000000": "00",
|
|
7937
|
-
"0c000000000000000000000000000000000000000000000000000000000000": "
|
|
7307
|
+
"0c000000000000000000000000000000000000000000000000000000000000": "000000000000000000000000000000000000000000",
|
|
7938
7308
|
"06000000000000000000000000000000000000000000000000000000000000": "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25bb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aae88bd757ad5b9bedf372d8d3f0cf6c962a469db61a265f6418e1ffed86da29ec",
|
|
7939
7309
|
"0a000000000000000000000000000000000000000000000000000000000000": "0000",
|
|
7940
7310
|
"03000000000000000000000000000000000000000000000000000000000000": "012bf11dc5e1c7b9bbaafc2c8533017abc12daeb0baf22c92509ad50f7875e5716000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
@@ -7982,7 +7352,7 @@ var chain_spec = {
|
|
|
7982
7352
|
"0d000000000000000000000000000000000000000000000000000000000000": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
7983
7353
|
"01000000000000000000000000000000000000000000000000000000000000": "080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978080868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f9780868db7f54e8b81d3a86438a8865eaf6b108b7992ae41dbc78f401b9acb5f978",
|
|
7984
7354
|
"10000000000000000000000000000000000000000000000000000000000000": "00",
|
|
7985
|
-
"0c000000000000000000000000000000000000000000000000000000000000": "
|
|
7355
|
+
"0c000000000000000000000000000000000000000000000000000000000000": "000000000000000000000000000000000000000000",
|
|
7986
7356
|
"06000000000000000000000000000000000000000000000000000000000000": "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314ee155ace9c40292074cb6aff8c9ccdd273c81648ff1149ef36bcea6ebb8a3e25bb30a42c1e62f0afda5f0a4e8a562f7a13a24cea00ee81917b86b89e801314aae88bd757ad5b9bedf372d8d3f0cf6c962a469db61a265f6418e1ffed86da29ec",
|
|
7987
7357
|
"0a000000000000000000000000000000000000000000000000000000000000": "0000",
|
|
7988
7358
|
"03000000000000000000000000000000000000000000000000000000000000": "012bf11dc5e1c7b9bbaafc2c8533017abc12daeb0baf22c92509ad50f7875e5716000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
@@ -8575,43 +7945,43 @@ var stateKeys;
|
|
|
8575
7945
|
}
|
|
8576
7946
|
stateKeys.serviceInfo = serviceInfo;
|
|
8577
7947
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bba033bba03?v=0.7.1 */
|
|
8578
|
-
function serviceStorage(serviceId, key) {
|
|
7948
|
+
function serviceStorage(blake2b, serviceId, key) {
|
|
8579
7949
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8580
7950
|
const out = Bytes.zero(HASH_SIZE);
|
|
8581
7951
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 1)), 0);
|
|
8582
7952
|
out.raw.set(key.raw.subarray(0, HASH_SIZE - U32_BYTES), U32_BYTES);
|
|
8583
7953
|
return legacyServiceNested(serviceId, out);
|
|
8584
7954
|
}
|
|
8585
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
7955
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
8586
7956
|
}
|
|
8587
7957
|
stateKeys.serviceStorage = serviceStorage;
|
|
8588
7958
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bd7033bd703?v=0.7.1 */
|
|
8589
|
-
function servicePreimage(serviceId, hash) {
|
|
7959
|
+
function servicePreimage(blake2b, serviceId, hash) {
|
|
8590
7960
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8591
7961
|
const out = Bytes.zero(HASH_SIZE);
|
|
8592
7962
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 2)), 0);
|
|
8593
7963
|
out.raw.set(hash.raw.subarray(1, HASH_SIZE - U32_BYTES + 1), U32_BYTES);
|
|
8594
7964
|
return legacyServiceNested(serviceId, out);
|
|
8595
7965
|
}
|
|
8596
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
7966
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
8597
7967
|
}
|
|
8598
7968
|
stateKeys.servicePreimage = servicePreimage;
|
|
8599
7969
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b0a043b0a04?v=0.7.1 */
|
|
8600
|
-
function serviceLookupHistory(serviceId, hash, preimageLength) {
|
|
7970
|
+
function serviceLookupHistory(blake2b, serviceId, hash, preimageLength) {
|
|
8601
7971
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8602
|
-
const doubleHash = hashBytes(hash);
|
|
7972
|
+
const doubleHash = blake2b.hashBytes(hash);
|
|
8603
7973
|
const out = Bytes.zero(HASH_SIZE);
|
|
8604
7974
|
out.raw.set(u32AsLeBytes(preimageLength), 0);
|
|
8605
7975
|
out.raw.set(doubleHash.raw.subarray(2, HASH_SIZE - U32_BYTES + 2), U32_BYTES);
|
|
8606
7976
|
return legacyServiceNested(serviceId, out);
|
|
8607
7977
|
}
|
|
8608
|
-
return serviceNested(serviceId, preimageLength, hash);
|
|
7978
|
+
return serviceNested(blake2b, serviceId, preimageLength, hash);
|
|
8609
7979
|
}
|
|
8610
7980
|
stateKeys.serviceLookupHistory = serviceLookupHistory;
|
|
8611
7981
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b88003b8800?v=0.7.1 */
|
|
8612
|
-
function serviceNested(serviceId, numberPrefix, hash) {
|
|
7982
|
+
function serviceNested(blake2b, serviceId, numberPrefix, hash) {
|
|
8613
7983
|
const inputToHash = BytesBlob.blobFromParts(u32AsLeBytes(numberPrefix), hash.raw);
|
|
8614
|
-
const newHash = hashBytes(inputToHash).raw.subarray(0, 28);
|
|
7984
|
+
const newHash = blake2b.hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8615
7985
|
const key = Bytes.zero(HASH_SIZE);
|
|
8616
7986
|
let i = 0;
|
|
8617
7987
|
for (const byte of u32AsLeBytes(serviceId)) {
|
|
@@ -8672,12 +8042,6 @@ function accumulationOutputComparator(a, b) {
|
|
|
8672
8042
|
return Ordering.Equal;
|
|
8673
8043
|
}
|
|
8674
8044
|
|
|
8675
|
-
const codecWithHash = (val) => Descriptor.withView(val.name, val.sizeHint, (e, elem) => val.encode(e, elem.data), (d) => {
|
|
8676
|
-
const decoder2 = d.clone();
|
|
8677
|
-
const encoded = val.skipEncoded(decoder2);
|
|
8678
|
-
const hash = hashBytes(encoded);
|
|
8679
|
-
return new WithHash(hash.asOpaque(), val.decode(d));
|
|
8680
|
-
}, val.skip, val.View);
|
|
8681
8045
|
/**
|
|
8682
8046
|
* Assignment of particular work report to a core.
|
|
8683
8047
|
*
|
|
@@ -8690,7 +8054,7 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8690
8054
|
workReport;
|
|
8691
8055
|
timeout;
|
|
8692
8056
|
static Codec = codec$1.Class(AvailabilityAssignment, {
|
|
8693
|
-
workReport:
|
|
8057
|
+
workReport: WorkReport.Codec,
|
|
8694
8058
|
timeout: codec$1.u32.asOpaque(),
|
|
8695
8059
|
});
|
|
8696
8060
|
static create({ workReport, timeout }) {
|
|
@@ -8787,7 +8151,6 @@ const O = 8;
|
|
|
8787
8151
|
const Q = 80;
|
|
8788
8152
|
/** `W_T`: The size of a transfer memo in octets. */
|
|
8789
8153
|
const W_T = 128;
|
|
8790
|
-
// TODO [ToDr] Not sure where these should live yet :(
|
|
8791
8154
|
/**
|
|
8792
8155
|
* `J`: The maximum sum of dependency items in a work-report.
|
|
8793
8156
|
*
|
|
@@ -8799,6 +8162,194 @@ const AUTHORIZATION_QUEUE_SIZE = Q;
|
|
|
8799
8162
|
/** `O`: Maximal authorization pool size. */
|
|
8800
8163
|
const MAX_AUTH_POOL_SIZE = O;
|
|
8801
8164
|
|
|
8165
|
+
const MAX_VALUE = 4294967295;
|
|
8166
|
+
const MIN_VALUE = -2147483648;
|
|
8167
|
+
const MAX_SHIFT_U32 = 32;
|
|
8168
|
+
const MAX_SHIFT_U64 = 64n;
|
|
8169
|
+
|
|
8170
|
+
/**
|
|
8171
|
+
* `B_S`: The basic minimum balance which all services require.
|
|
8172
|
+
*
|
|
8173
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
8174
|
+
*/
|
|
8175
|
+
const BASE_SERVICE_BALANCE = 100n;
|
|
8176
|
+
/**
|
|
8177
|
+
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
8178
|
+
*
|
|
8179
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
8180
|
+
*/
|
|
8181
|
+
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
8182
|
+
/**
|
|
8183
|
+
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
8184
|
+
*
|
|
8185
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
8186
|
+
*/
|
|
8187
|
+
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
8188
|
+
const zeroSizeHint = {
|
|
8189
|
+
bytes: 0,
|
|
8190
|
+
isExact: true,
|
|
8191
|
+
};
|
|
8192
|
+
/** 0-byte read, return given default value */
|
|
8193
|
+
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8194
|
+
/** Encode and decode object with leading version number. */
|
|
8195
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8196
|
+
bytes: val.sizeHint.bytes + 8,
|
|
8197
|
+
isExact: false,
|
|
8198
|
+
}, (e, v) => {
|
|
8199
|
+
e.varU64(0n);
|
|
8200
|
+
val.encode(e, v);
|
|
8201
|
+
}, (d) => {
|
|
8202
|
+
const version = d.varU64();
|
|
8203
|
+
if (version !== 0n) {
|
|
8204
|
+
throw new Error("Non-zero version is not supported!");
|
|
8205
|
+
}
|
|
8206
|
+
return val.decode(d);
|
|
8207
|
+
}, (s) => {
|
|
8208
|
+
s.varU64();
|
|
8209
|
+
val.skip(s);
|
|
8210
|
+
});
|
|
8211
|
+
/**
|
|
8212
|
+
* Service account details.
|
|
8213
|
+
*
|
|
8214
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
8215
|
+
*/
|
|
8216
|
+
class ServiceAccountInfo extends WithDebug {
|
|
8217
|
+
codeHash;
|
|
8218
|
+
balance;
|
|
8219
|
+
accumulateMinGas;
|
|
8220
|
+
onTransferMinGas;
|
|
8221
|
+
storageUtilisationBytes;
|
|
8222
|
+
gratisStorage;
|
|
8223
|
+
storageUtilisationCount;
|
|
8224
|
+
created;
|
|
8225
|
+
lastAccumulation;
|
|
8226
|
+
parentService;
|
|
8227
|
+
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
8228
|
+
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8229
|
+
balance: codec$1.u64,
|
|
8230
|
+
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8231
|
+
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
8232
|
+
storageUtilisationBytes: codec$1.u64,
|
|
8233
|
+
gratisStorage: codec$1.u64,
|
|
8234
|
+
storageUtilisationCount: codec$1.u32,
|
|
8235
|
+
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8236
|
+
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
8237
|
+
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
8238
|
+
});
|
|
8239
|
+
static create(a) {
|
|
8240
|
+
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
8241
|
+
}
|
|
8242
|
+
/**
|
|
8243
|
+
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
8244
|
+
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
8245
|
+
*/
|
|
8246
|
+
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
8247
|
+
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
8248
|
+
if (storageCost < 0n) {
|
|
8249
|
+
return tryAsU64(0);
|
|
8250
|
+
}
|
|
8251
|
+
if (storageCost >= 2n ** 64n) {
|
|
8252
|
+
return tryAsU64(2n ** 64n - 1n);
|
|
8253
|
+
}
|
|
8254
|
+
return tryAsU64(storageCost);
|
|
8255
|
+
}
|
|
8256
|
+
constructor(
|
|
8257
|
+
/** `a_c`: Hash of the service code. */
|
|
8258
|
+
codeHash,
|
|
8259
|
+
/** `a_b`: Current account balance. */
|
|
8260
|
+
balance,
|
|
8261
|
+
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
8262
|
+
accumulateMinGas,
|
|
8263
|
+
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
8264
|
+
onTransferMinGas,
|
|
8265
|
+
/** `a_o`: Total number of octets in storage. */
|
|
8266
|
+
storageUtilisationBytes,
|
|
8267
|
+
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
8268
|
+
gratisStorage,
|
|
8269
|
+
/** `a_i`: Number of items in storage. */
|
|
8270
|
+
storageUtilisationCount,
|
|
8271
|
+
/** `a_r`: Creation account time slot. */
|
|
8272
|
+
created,
|
|
8273
|
+
/** `a_a`: Most recent accumulation time slot. */
|
|
8274
|
+
lastAccumulation,
|
|
8275
|
+
/** `a_p`: Parent service ID. */
|
|
8276
|
+
parentService) {
|
|
8277
|
+
super();
|
|
8278
|
+
this.codeHash = codeHash;
|
|
8279
|
+
this.balance = balance;
|
|
8280
|
+
this.accumulateMinGas = accumulateMinGas;
|
|
8281
|
+
this.onTransferMinGas = onTransferMinGas;
|
|
8282
|
+
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
8283
|
+
this.gratisStorage = gratisStorage;
|
|
8284
|
+
this.storageUtilisationCount = storageUtilisationCount;
|
|
8285
|
+
this.created = created;
|
|
8286
|
+
this.lastAccumulation = lastAccumulation;
|
|
8287
|
+
this.parentService = parentService;
|
|
8288
|
+
}
|
|
8289
|
+
}
|
|
8290
|
+
class PreimageItem extends WithDebug {
|
|
8291
|
+
hash;
|
|
8292
|
+
blob;
|
|
8293
|
+
static Codec = codec$1.Class(PreimageItem, {
|
|
8294
|
+
hash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
8295
|
+
blob: codec$1.blob,
|
|
8296
|
+
});
|
|
8297
|
+
static create({ hash, blob }) {
|
|
8298
|
+
return new PreimageItem(hash, blob);
|
|
8299
|
+
}
|
|
8300
|
+
constructor(hash, blob) {
|
|
8301
|
+
super();
|
|
8302
|
+
this.hash = hash;
|
|
8303
|
+
this.blob = blob;
|
|
8304
|
+
}
|
|
8305
|
+
}
|
|
8306
|
+
class StorageItem extends WithDebug {
|
|
8307
|
+
key;
|
|
8308
|
+
value;
|
|
8309
|
+
static Codec = codec$1.Class(StorageItem, {
|
|
8310
|
+
key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
|
|
8311
|
+
value: codec$1.blob,
|
|
8312
|
+
});
|
|
8313
|
+
static create({ key, value }) {
|
|
8314
|
+
return new StorageItem(key, value);
|
|
8315
|
+
}
|
|
8316
|
+
constructor(key, value) {
|
|
8317
|
+
super();
|
|
8318
|
+
this.key = key;
|
|
8319
|
+
this.value = value;
|
|
8320
|
+
}
|
|
8321
|
+
}
|
|
8322
|
+
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
8323
|
+
function tryAsLookupHistorySlots(items) {
|
|
8324
|
+
const knownSize = asKnownSize(items);
|
|
8325
|
+
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
8326
|
+
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
8327
|
+
}
|
|
8328
|
+
return knownSize;
|
|
8329
|
+
}
|
|
8330
|
+
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
8331
|
+
class LookupHistoryItem {
|
|
8332
|
+
hash;
|
|
8333
|
+
length;
|
|
8334
|
+
slots;
|
|
8335
|
+
constructor(hash, length,
|
|
8336
|
+
/**
|
|
8337
|
+
* Preimage availability history as a sequence of time slots.
|
|
8338
|
+
* See PreimageStatus and the following GP fragment for more details.
|
|
8339
|
+
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
8340
|
+
slots) {
|
|
8341
|
+
this.hash = hash;
|
|
8342
|
+
this.length = length;
|
|
8343
|
+
this.slots = slots;
|
|
8344
|
+
}
|
|
8345
|
+
static isRequested(item) {
|
|
8346
|
+
if ("slots" in item) {
|
|
8347
|
+
return item.slots.length === 0;
|
|
8348
|
+
}
|
|
8349
|
+
return item.length === 0;
|
|
8350
|
+
}
|
|
8351
|
+
}
|
|
8352
|
+
|
|
8802
8353
|
/** Dictionary entry of services that auto-accumulate every block. */
|
|
8803
8354
|
class AutoAccumulate {
|
|
8804
8355
|
service;
|
|
@@ -8820,39 +8371,50 @@ class AutoAccumulate {
|
|
|
8820
8371
|
}
|
|
8821
8372
|
}
|
|
8822
8373
|
/**
|
|
8823
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8374
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/114402114402?v=0.7.2
|
|
8824
8375
|
*/
|
|
8825
8376
|
class PrivilegedServices {
|
|
8826
8377
|
manager;
|
|
8827
|
-
|
|
8828
|
-
|
|
8378
|
+
delegator;
|
|
8379
|
+
registrar;
|
|
8380
|
+
assigners;
|
|
8829
8381
|
autoAccumulateServices;
|
|
8382
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/3bbd023bcb02?v=0.7.2 */
|
|
8830
8383
|
static Codec = codec$1.Class(PrivilegedServices, {
|
|
8831
8384
|
manager: codec$1.u32.asOpaque(),
|
|
8832
|
-
|
|
8833
|
-
|
|
8385
|
+
assigners: codecPerCore(codec$1.u32.asOpaque()),
|
|
8386
|
+
delegator: codec$1.u32.asOpaque(),
|
|
8387
|
+
registrar: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
8388
|
+
? codec$1.u32.asOpaque()
|
|
8389
|
+
: ignoreValueWithDefault(tryAsServiceId(2 ** 32 - 1)),
|
|
8834
8390
|
autoAccumulateServices: readonlyArray(codec$1.sequenceVarLen(AutoAccumulate.Codec)),
|
|
8835
8391
|
});
|
|
8836
|
-
static create(
|
|
8837
|
-
return new PrivilegedServices(manager,
|
|
8392
|
+
static create(a) {
|
|
8393
|
+
return new PrivilegedServices(a.manager, a.delegator, a.registrar, a.assigners, a.autoAccumulateServices);
|
|
8838
8394
|
}
|
|
8839
8395
|
constructor(
|
|
8840
8396
|
/**
|
|
8841
|
-
*
|
|
8842
|
-
* the service able to effect an alteration of χ from block to block,
|
|
8397
|
+
* `χ_M`: Manages alteration of χ from block to block,
|
|
8843
8398
|
* as well as bestow services with storage deposit credits.
|
|
8844
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
8399
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111502111902?v=0.7.2
|
|
8845
8400
|
*/
|
|
8846
8401
|
manager,
|
|
8847
|
-
/**
|
|
8848
|
-
|
|
8849
|
-
/**
|
|
8850
|
-
|
|
8851
|
-
|
|
8402
|
+
/** `χ_V`: Managers validator keys. */
|
|
8403
|
+
delegator,
|
|
8404
|
+
/**
|
|
8405
|
+
* `χ_R`: Manages the creation of services in protected range.
|
|
8406
|
+
*
|
|
8407
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/111b02111d02?v=0.7.2
|
|
8408
|
+
*/
|
|
8409
|
+
registrar,
|
|
8410
|
+
/** `χ_A`: Manages authorization queue one for each core. */
|
|
8411
|
+
assigners,
|
|
8412
|
+
/** `χ_Z`: Dictionary of services that auto-accumulate every block with their gas limit. */
|
|
8852
8413
|
autoAccumulateServices) {
|
|
8853
8414
|
this.manager = manager;
|
|
8854
|
-
this.
|
|
8855
|
-
this.
|
|
8415
|
+
this.delegator = delegator;
|
|
8416
|
+
this.registrar = registrar;
|
|
8417
|
+
this.assigners = assigners;
|
|
8856
8418
|
this.autoAccumulateServices = autoAccumulateServices;
|
|
8857
8419
|
}
|
|
8858
8420
|
}
|
|
@@ -9114,172 +8676,6 @@ class SafroleData {
|
|
|
9114
8676
|
}
|
|
9115
8677
|
}
|
|
9116
8678
|
|
|
9117
|
-
/**
|
|
9118
|
-
* `B_S`: The basic minimum balance which all services require.
|
|
9119
|
-
*
|
|
9120
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445800445800?v=0.6.7
|
|
9121
|
-
*/
|
|
9122
|
-
const BASE_SERVICE_BALANCE = 100n;
|
|
9123
|
-
/**
|
|
9124
|
-
* `B_I`: The additional minimum balance required per item of elective service state.
|
|
9125
|
-
*
|
|
9126
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445000445000?v=0.6.7
|
|
9127
|
-
*/
|
|
9128
|
-
const ELECTIVE_ITEM_BALANCE = 10n;
|
|
9129
|
-
/**
|
|
9130
|
-
* `B_L`: The additional minimum balance required per octet of elective service state.
|
|
9131
|
-
*
|
|
9132
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/445400445400?v=0.6.7
|
|
9133
|
-
*/
|
|
9134
|
-
const ELECTIVE_BYTE_BALANCE = 1n;
|
|
9135
|
-
const zeroSizeHint = {
|
|
9136
|
-
bytes: 0,
|
|
9137
|
-
isExact: true,
|
|
9138
|
-
};
|
|
9139
|
-
/** 0-byte read, return given default value */
|
|
9140
|
-
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
9141
|
-
/**
|
|
9142
|
-
* Service account details.
|
|
9143
|
-
*
|
|
9144
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/108301108301?v=0.6.7
|
|
9145
|
-
*/
|
|
9146
|
-
class ServiceAccountInfo extends WithDebug {
|
|
9147
|
-
codeHash;
|
|
9148
|
-
balance;
|
|
9149
|
-
accumulateMinGas;
|
|
9150
|
-
onTransferMinGas;
|
|
9151
|
-
storageUtilisationBytes;
|
|
9152
|
-
gratisStorage;
|
|
9153
|
-
storageUtilisationCount;
|
|
9154
|
-
created;
|
|
9155
|
-
lastAccumulation;
|
|
9156
|
-
parentService;
|
|
9157
|
-
static Codec = codec$1.Class(ServiceAccountInfo, {
|
|
9158
|
-
codeHash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
9159
|
-
balance: codec$1.u64,
|
|
9160
|
-
accumulateMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
9161
|
-
onTransferMinGas: codec$1.u64.convert((x) => x, tryAsServiceGas),
|
|
9162
|
-
storageUtilisationBytes: codec$1.u64,
|
|
9163
|
-
gratisStorage: codec$1.u64,
|
|
9164
|
-
storageUtilisationCount: codec$1.u32,
|
|
9165
|
-
created: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
9166
|
-
lastAccumulation: codec$1.u32.convert((x) => x, tryAsTimeSlot),
|
|
9167
|
-
parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
|
|
9168
|
-
});
|
|
9169
|
-
static create(a) {
|
|
9170
|
-
return new ServiceAccountInfo(a.codeHash, a.balance, a.accumulateMinGas, a.onTransferMinGas, a.storageUtilisationBytes, a.gratisStorage, a.storageUtilisationCount, a.created, a.lastAccumulation, a.parentService);
|
|
9171
|
-
}
|
|
9172
|
-
/**
|
|
9173
|
-
* `a_t = max(0, BS + BI * a_i + BL * a_o - a_f)`
|
|
9174
|
-
* https://graypaper.fluffylabs.dev/#/7e6ff6a/119e01119e01?v=0.6.7
|
|
9175
|
-
*/
|
|
9176
|
-
static calculateThresholdBalance(items, bytes, gratisStorage) {
|
|
9177
|
-
const storageCost = BASE_SERVICE_BALANCE + ELECTIVE_ITEM_BALANCE * BigInt(items) + ELECTIVE_BYTE_BALANCE * bytes - gratisStorage;
|
|
9178
|
-
if (storageCost < 0n) {
|
|
9179
|
-
return tryAsU64(0);
|
|
9180
|
-
}
|
|
9181
|
-
if (storageCost >= 2n ** 64n) {
|
|
9182
|
-
return tryAsU64(2n ** 64n - 1n);
|
|
9183
|
-
}
|
|
9184
|
-
return tryAsU64(storageCost);
|
|
9185
|
-
}
|
|
9186
|
-
constructor(
|
|
9187
|
-
/** `a_c`: Hash of the service code. */
|
|
9188
|
-
codeHash,
|
|
9189
|
-
/** `a_b`: Current account balance. */
|
|
9190
|
-
balance,
|
|
9191
|
-
/** `a_g`: Minimal gas required to execute Accumulate entrypoint. */
|
|
9192
|
-
accumulateMinGas,
|
|
9193
|
-
/** `a_m`: Minimal gas required to execute On Transfer entrypoint. */
|
|
9194
|
-
onTransferMinGas,
|
|
9195
|
-
/** `a_o`: Total number of octets in storage. */
|
|
9196
|
-
storageUtilisationBytes,
|
|
9197
|
-
/** `a_f`: Cost-free storage. Decreases both storage item count and total byte size. */
|
|
9198
|
-
gratisStorage,
|
|
9199
|
-
/** `a_i`: Number of items in storage. */
|
|
9200
|
-
storageUtilisationCount,
|
|
9201
|
-
/** `a_r`: Creation account time slot. */
|
|
9202
|
-
created,
|
|
9203
|
-
/** `a_a`: Most recent accumulation time slot. */
|
|
9204
|
-
lastAccumulation,
|
|
9205
|
-
/** `a_p`: Parent service ID. */
|
|
9206
|
-
parentService) {
|
|
9207
|
-
super();
|
|
9208
|
-
this.codeHash = codeHash;
|
|
9209
|
-
this.balance = balance;
|
|
9210
|
-
this.accumulateMinGas = accumulateMinGas;
|
|
9211
|
-
this.onTransferMinGas = onTransferMinGas;
|
|
9212
|
-
this.storageUtilisationBytes = storageUtilisationBytes;
|
|
9213
|
-
this.gratisStorage = gratisStorage;
|
|
9214
|
-
this.storageUtilisationCount = storageUtilisationCount;
|
|
9215
|
-
this.created = created;
|
|
9216
|
-
this.lastAccumulation = lastAccumulation;
|
|
9217
|
-
this.parentService = parentService;
|
|
9218
|
-
}
|
|
9219
|
-
}
|
|
9220
|
-
class PreimageItem extends WithDebug {
|
|
9221
|
-
hash;
|
|
9222
|
-
blob;
|
|
9223
|
-
static Codec = codec$1.Class(PreimageItem, {
|
|
9224
|
-
hash: codec$1.bytes(HASH_SIZE).asOpaque(),
|
|
9225
|
-
blob: codec$1.blob,
|
|
9226
|
-
});
|
|
9227
|
-
static create({ hash, blob }) {
|
|
9228
|
-
return new PreimageItem(hash, blob);
|
|
9229
|
-
}
|
|
9230
|
-
constructor(hash, blob) {
|
|
9231
|
-
super();
|
|
9232
|
-
this.hash = hash;
|
|
9233
|
-
this.blob = blob;
|
|
9234
|
-
}
|
|
9235
|
-
}
|
|
9236
|
-
class StorageItem extends WithDebug {
|
|
9237
|
-
key;
|
|
9238
|
-
value;
|
|
9239
|
-
static Codec = codec$1.Class(StorageItem, {
|
|
9240
|
-
key: codec$1.blob.convert((i) => i, (o) => asOpaqueType(o)),
|
|
9241
|
-
value: codec$1.blob,
|
|
9242
|
-
});
|
|
9243
|
-
static create({ key, value }) {
|
|
9244
|
-
return new StorageItem(key, value);
|
|
9245
|
-
}
|
|
9246
|
-
constructor(key, value) {
|
|
9247
|
-
super();
|
|
9248
|
-
this.key = key;
|
|
9249
|
-
this.value = value;
|
|
9250
|
-
}
|
|
9251
|
-
}
|
|
9252
|
-
const MAX_LOOKUP_HISTORY_SLOTS = 3;
|
|
9253
|
-
function tryAsLookupHistorySlots(items) {
|
|
9254
|
-
const knownSize = asKnownSize(items);
|
|
9255
|
-
if (knownSize.length > MAX_LOOKUP_HISTORY_SLOTS) {
|
|
9256
|
-
throw new Error(`Lookup history items must contain 0-${MAX_LOOKUP_HISTORY_SLOTS} timeslots.`);
|
|
9257
|
-
}
|
|
9258
|
-
return knownSize;
|
|
9259
|
-
}
|
|
9260
|
-
/** https://graypaper.fluffylabs.dev/#/5f542d7/115400115800 */
|
|
9261
|
-
class LookupHistoryItem {
|
|
9262
|
-
hash;
|
|
9263
|
-
length;
|
|
9264
|
-
slots;
|
|
9265
|
-
constructor(hash, length,
|
|
9266
|
-
/**
|
|
9267
|
-
* Preimage availability history as a sequence of time slots.
|
|
9268
|
-
* See PreimageStatus and the following GP fragment for more details.
|
|
9269
|
-
* https://graypaper.fluffylabs.dev/#/5f542d7/11780011a500 */
|
|
9270
|
-
slots) {
|
|
9271
|
-
this.hash = hash;
|
|
9272
|
-
this.length = length;
|
|
9273
|
-
this.slots = slots;
|
|
9274
|
-
}
|
|
9275
|
-
static isRequested(item) {
|
|
9276
|
-
if ("slots" in item) {
|
|
9277
|
-
return item.slots.length === 0;
|
|
9278
|
-
}
|
|
9279
|
-
return item.length === 0;
|
|
9280
|
-
}
|
|
9281
|
-
}
|
|
9282
|
-
|
|
9283
8679
|
/**
|
|
9284
8680
|
* In addition to the entropy accumulator η_0, we retain
|
|
9285
8681
|
* three additional historical values of the accumulator at
|
|
@@ -9568,8 +8964,7 @@ class CoreStatistics {
|
|
|
9568
8964
|
* Service statistics.
|
|
9569
8965
|
* Updated per block, based on available work reports (`W`).
|
|
9570
8966
|
*
|
|
9571
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9572
|
-
* https://github.com/gavofyork/graypaper/blob/9bffb08f3ea7b67832019176754df4fb36b9557d/text/statistics.tex#L77
|
|
8967
|
+
* https://graypaper.fluffylabs.dev/#/1c979cb/199802199802?v=0.7.1
|
|
9573
8968
|
*/
|
|
9574
8969
|
class ServiceStatistics {
|
|
9575
8970
|
providedCount;
|
|
@@ -9584,22 +8979,8 @@ class ServiceStatistics {
|
|
|
9584
8979
|
accumulateGasUsed;
|
|
9585
8980
|
onTransfersCount;
|
|
9586
8981
|
onTransfersGasUsed;
|
|
9587
|
-
static Codec = Compatibility.
|
|
9588
|
-
|
|
9589
|
-
providedCount: codecVarU16,
|
|
9590
|
-
providedSize: codec$1.varU32,
|
|
9591
|
-
refinementCount: codec$1.varU32,
|
|
9592
|
-
refinementGasUsed: codecVarGas,
|
|
9593
|
-
imports: codecVarU16,
|
|
9594
|
-
extrinsicCount: codecVarU16,
|
|
9595
|
-
extrinsicSize: codec$1.varU32,
|
|
9596
|
-
exports: codecVarU16,
|
|
9597
|
-
accumulateCount: codec$1.varU32,
|
|
9598
|
-
accumulateGasUsed: codecVarGas,
|
|
9599
|
-
onTransfersCount: codec$1.varU32,
|
|
9600
|
-
onTransfersGasUsed: codecVarGas,
|
|
9601
|
-
})
|
|
9602
|
-
: codec$1.Class(ServiceStatistics, {
|
|
8982
|
+
static Codec = Compatibility.selectIfGreaterOrEqual({
|
|
8983
|
+
fallback: codec$1.Class(ServiceStatistics, {
|
|
9603
8984
|
providedCount: codecVarU16,
|
|
9604
8985
|
providedSize: codec$1.varU32,
|
|
9605
8986
|
refinementCount: codec$1.varU32,
|
|
@@ -9612,7 +8993,38 @@ class ServiceStatistics {
|
|
|
9612
8993
|
accumulateGasUsed: codecVarGas,
|
|
9613
8994
|
onTransfersCount: codec$1.varU32,
|
|
9614
8995
|
onTransfersGasUsed: codecVarGas,
|
|
9615
|
-
})
|
|
8996
|
+
}),
|
|
8997
|
+
versions: {
|
|
8998
|
+
[GpVersion.V0_7_0]: codec$1.Class(ServiceStatistics, {
|
|
8999
|
+
providedCount: codecVarU16,
|
|
9000
|
+
providedSize: codec$1.varU32,
|
|
9001
|
+
refinementCount: codec$1.varU32,
|
|
9002
|
+
refinementGasUsed: codecVarGas,
|
|
9003
|
+
imports: codecVarU16,
|
|
9004
|
+
extrinsicCount: codecVarU16,
|
|
9005
|
+
extrinsicSize: codec$1.varU32,
|
|
9006
|
+
exports: codecVarU16,
|
|
9007
|
+
accumulateCount: codec$1.varU32,
|
|
9008
|
+
accumulateGasUsed: codecVarGas,
|
|
9009
|
+
onTransfersCount: codec$1.varU32,
|
|
9010
|
+
onTransfersGasUsed: codecVarGas,
|
|
9011
|
+
}),
|
|
9012
|
+
[GpVersion.V0_7_1]: codec$1.Class(ServiceStatistics, {
|
|
9013
|
+
providedCount: codecVarU16,
|
|
9014
|
+
providedSize: codec$1.varU32,
|
|
9015
|
+
refinementCount: codec$1.varU32,
|
|
9016
|
+
refinementGasUsed: codecVarGas,
|
|
9017
|
+
imports: codecVarU16,
|
|
9018
|
+
extrinsicCount: codecVarU16,
|
|
9019
|
+
extrinsicSize: codec$1.varU32,
|
|
9020
|
+
exports: codecVarU16,
|
|
9021
|
+
accumulateCount: codec$1.varU32,
|
|
9022
|
+
accumulateGasUsed: codecVarGas,
|
|
9023
|
+
onTransfersCount: ignoreValueWithDefault(tryAsU32(0)),
|
|
9024
|
+
onTransfersGasUsed: ignoreValueWithDefault(tryAsServiceGas(0)),
|
|
9025
|
+
}),
|
|
9026
|
+
},
|
|
9027
|
+
});
|
|
9616
9028
|
static create(v) {
|
|
9617
9029
|
return new ServiceStatistics(v.providedCount, v.providedSize, v.refinementCount, v.refinementGasUsed, v.imports, v.exports, v.extrinsicSize, v.extrinsicCount, v.accumulateCount, v.accumulateGasUsed, v.onTransfersCount, v.onTransfersGasUsed);
|
|
9618
9030
|
}
|
|
@@ -9637,9 +9049,9 @@ class ServiceStatistics {
|
|
|
9637
9049
|
accumulateCount,
|
|
9638
9050
|
/** `a.1` */
|
|
9639
9051
|
accumulateGasUsed,
|
|
9640
|
-
/** `t.0` */
|
|
9052
|
+
/** `t.0` @deprecated since 0.7.1 */
|
|
9641
9053
|
onTransfersCount,
|
|
9642
|
-
/** `t.1` */
|
|
9054
|
+
/** `t.1` @deprecated since 0.7.1 */
|
|
9643
9055
|
onTransfersGasUsed) {
|
|
9644
9056
|
this.providedCount = providedCount;
|
|
9645
9057
|
this.providedSize = providedSize;
|
|
@@ -10087,8 +9499,9 @@ class InMemoryState extends WithDebug {
|
|
|
10087
9499
|
epochRoot: Bytes.zero(BANDERSNATCH_RING_ROOT_BYTES).asOpaque(),
|
|
10088
9500
|
privilegedServices: PrivilegedServices.create({
|
|
10089
9501
|
manager: tryAsServiceId(0),
|
|
10090
|
-
|
|
10091
|
-
|
|
9502
|
+
assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
|
|
9503
|
+
delegator: tryAsServiceId(0),
|
|
9504
|
+
registrar: tryAsServiceId(MAX_VALUE),
|
|
10092
9505
|
autoAccumulateServices: [],
|
|
10093
9506
|
}),
|
|
10094
9507
|
accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
|
|
@@ -10147,6 +9560,7 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
10147
9560
|
ValidatorStatistics: ValidatorStatistics,
|
|
10148
9561
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
10149
9562
|
codecPerCore: codecPerCore,
|
|
9563
|
+
codecWithVersion: codecWithVersion,
|
|
10150
9564
|
hashComparator: hashComparator,
|
|
10151
9565
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
10152
9566
|
serviceDataCodec: serviceDataCodec,
|
|
@@ -10307,21 +9721,23 @@ var serialize;
|
|
|
10307
9721
|
/** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
|
|
10308
9722
|
serialize.serviceData = (serviceId) => ({
|
|
10309
9723
|
key: stateKeys.serviceInfo(serviceId),
|
|
10310
|
-
Codec:
|
|
9724
|
+
Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9725
|
+
? codecWithVersion(ServiceAccountInfo.Codec)
|
|
9726
|
+
: ServiceAccountInfo.Codec,
|
|
10311
9727
|
});
|
|
10312
9728
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
10313
|
-
serialize.serviceStorage = (serviceId, key) => ({
|
|
10314
|
-
key: stateKeys.serviceStorage(serviceId, key),
|
|
9729
|
+
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
9730
|
+
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
10315
9731
|
Codec: dumpCodec,
|
|
10316
9732
|
});
|
|
10317
9733
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
10318
|
-
serialize.servicePreimages = (serviceId, hash) => ({
|
|
10319
|
-
key: stateKeys.servicePreimage(serviceId, hash),
|
|
9734
|
+
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
9735
|
+
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
10320
9736
|
Codec: dumpCodec,
|
|
10321
9737
|
});
|
|
10322
9738
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10323
|
-
serialize.serviceLookupHistory = (serviceId, hash, len) => ({
|
|
10324
|
-
key: stateKeys.serviceLookupHistory(serviceId, hash, len),
|
|
9739
|
+
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
9740
|
+
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10325
9741
|
Codec: readonlyArray(codec$1.sequenceVarLen(codec$1.u32)),
|
|
10326
9742
|
});
|
|
10327
9743
|
})(serialize || (serialize = {}));
|
|
@@ -10344,20 +9760,22 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10344
9760
|
*/
|
|
10345
9761
|
class SerializedState {
|
|
10346
9762
|
spec;
|
|
9763
|
+
blake2b;
|
|
10347
9764
|
backend;
|
|
10348
9765
|
_recentServiceIds;
|
|
10349
9766
|
/** Create a state-like object from collection of serialized entries. */
|
|
10350
|
-
static fromStateEntries(spec, state, recentServices = []) {
|
|
10351
|
-
return new SerializedState(spec, state, recentServices);
|
|
9767
|
+
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9768
|
+
return new SerializedState(spec, blake2b, state, recentServices);
|
|
10352
9769
|
}
|
|
10353
9770
|
/** Create a state-like object backed by some DB. */
|
|
10354
|
-
static new(spec, db, recentServices = []) {
|
|
10355
|
-
return new SerializedState(spec, db, recentServices);
|
|
9771
|
+
static new(spec, blake2b, db, recentServices = []) {
|
|
9772
|
+
return new SerializedState(spec, blake2b, db, recentServices);
|
|
10356
9773
|
}
|
|
10357
|
-
constructor(spec, backend,
|
|
9774
|
+
constructor(spec, blake2b, backend,
|
|
10358
9775
|
/** Best-effort list of recently active services. */
|
|
10359
9776
|
_recentServiceIds) {
|
|
10360
9777
|
this.spec = spec;
|
|
9778
|
+
this.blake2b = blake2b;
|
|
10361
9779
|
this.backend = backend;
|
|
10362
9780
|
this._recentServiceIds = _recentServiceIds;
|
|
10363
9781
|
}
|
|
@@ -10381,7 +9799,7 @@ class SerializedState {
|
|
|
10381
9799
|
if (!this._recentServiceIds.includes(id)) {
|
|
10382
9800
|
this._recentServiceIds.push(id);
|
|
10383
9801
|
}
|
|
10384
|
-
return new SerializedService(id, serviceData, (key) => this.retrieveOptional(key));
|
|
9802
|
+
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10385
9803
|
}
|
|
10386
9804
|
retrieve({ key, Codec }, description) {
|
|
10387
9805
|
const bytes = this.backend.get(key);
|
|
@@ -10457,12 +9875,14 @@ class SerializedState {
|
|
|
10457
9875
|
}
|
|
10458
9876
|
/** Service data representation on a serialized state. */
|
|
10459
9877
|
class SerializedService {
|
|
9878
|
+
blake2b;
|
|
10460
9879
|
serviceId;
|
|
10461
9880
|
accountInfo;
|
|
10462
9881
|
retrieveOptional;
|
|
10463
|
-
constructor(
|
|
9882
|
+
constructor(blake2b,
|
|
10464
9883
|
/** Service id */
|
|
10465
9884
|
serviceId, accountInfo, retrieveOptional) {
|
|
9885
|
+
this.blake2b = blake2b;
|
|
10466
9886
|
this.serviceId = serviceId;
|
|
10467
9887
|
this.accountInfo = accountInfo;
|
|
10468
9888
|
this.retrieveOptional = retrieveOptional;
|
|
@@ -10478,10 +9898,10 @@ class SerializedService {
|
|
|
10478
9898
|
const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
10479
9899
|
serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
|
|
10480
9900
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10481
|
-
const key = asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
10482
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, key)) ?? null;
|
|
9901
|
+
const key = asOpaqueType(BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
9902
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10483
9903
|
}
|
|
10484
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, rawKey)) ?? null;
|
|
9904
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10485
9905
|
}
|
|
10486
9906
|
/**
|
|
10487
9907
|
* Check if preimage is present in the DB.
|
|
@@ -10490,15 +9910,15 @@ class SerializedService {
|
|
|
10490
9910
|
*/
|
|
10491
9911
|
hasPreimage(hash) {
|
|
10492
9912
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10493
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) !== undefined;
|
|
9913
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10494
9914
|
}
|
|
10495
9915
|
/** Retrieve preimage from the DB. */
|
|
10496
9916
|
getPreimage(hash) {
|
|
10497
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) ?? null;
|
|
9917
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10498
9918
|
}
|
|
10499
9919
|
/** Retrieve preimage lookup history. */
|
|
10500
9920
|
getLookupHistory(hash, len) {
|
|
10501
|
-
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.serviceId, hash, len));
|
|
9921
|
+
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
10502
9922
|
if (rawSlots === undefined) {
|
|
10503
9923
|
return null;
|
|
10504
9924
|
}
|
|
@@ -11135,11 +10555,13 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
11135
10555
|
parseInputKey: parseInputKey
|
|
11136
10556
|
});
|
|
11137
10557
|
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
}
|
|
10558
|
+
function getBlake2bTrieHasher(hasher) {
|
|
10559
|
+
return {
|
|
10560
|
+
hashConcat(n, rest = []) {
|
|
10561
|
+
return hasher.hashBlobs([n, ...rest]);
|
|
10562
|
+
},
|
|
10563
|
+
};
|
|
10564
|
+
}
|
|
11143
10565
|
|
|
11144
10566
|
/** What should be done with that key? */
|
|
11145
10567
|
var StateEntryUpdateAction;
|
|
@@ -11151,14 +10573,14 @@ var StateEntryUpdateAction;
|
|
|
11151
10573
|
})(StateEntryUpdateAction || (StateEntryUpdateAction = {}));
|
|
11152
10574
|
const EMPTY_BLOB = BytesBlob.empty();
|
|
11153
10575
|
/** Serialize given state update into a series of key-value pairs. */
|
|
11154
|
-
function* serializeStateUpdate(spec, update) {
|
|
10576
|
+
function* serializeStateUpdate(spec, blake2b, update) {
|
|
11155
10577
|
// first let's serialize all of the simple entries (if present!)
|
|
11156
10578
|
yield* serializeBasicKeys(spec, update);
|
|
11157
10579
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
11158
10580
|
// then let's proceed with service updates
|
|
11159
|
-
yield* serializeServiceUpdates(update.servicesUpdates, encode);
|
|
11160
|
-
yield* serializePreimages(update.preimages, encode);
|
|
11161
|
-
yield* serializeStorage(update.storage);
|
|
10581
|
+
yield* serializeServiceUpdates(update.servicesUpdates, encode, blake2b);
|
|
10582
|
+
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
10583
|
+
yield* serializeStorage(update.storage, blake2b);
|
|
11162
10584
|
yield* serializeRemovedServices(update.servicesRemoved);
|
|
11163
10585
|
}
|
|
11164
10586
|
function* serializeRemovedServices(servicesRemoved) {
|
|
@@ -11168,18 +10590,18 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
11168
10590
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11169
10591
|
}
|
|
11170
10592
|
}
|
|
11171
|
-
function* serializeStorage(storage) {
|
|
10593
|
+
function* serializeStorage(storage, blake2b) {
|
|
11172
10594
|
for (const { action, serviceId } of storage ?? []) {
|
|
11173
10595
|
switch (action.kind) {
|
|
11174
10596
|
case UpdateStorageKind.Set: {
|
|
11175
10597
|
const key = action.storage.key;
|
|
11176
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10598
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11177
10599
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11178
10600
|
break;
|
|
11179
10601
|
}
|
|
11180
10602
|
case UpdateStorageKind.Remove: {
|
|
11181
10603
|
const key = action.key;
|
|
11182
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10604
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11183
10605
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11184
10606
|
break;
|
|
11185
10607
|
}
|
|
@@ -11188,15 +10610,15 @@ function* serializeStorage(storage) {
|
|
|
11188
10610
|
}
|
|
11189
10611
|
}
|
|
11190
10612
|
}
|
|
11191
|
-
function* serializePreimages(preimages, encode) {
|
|
10613
|
+
function* serializePreimages(preimages, encode, blake2b) {
|
|
11192
10614
|
for (const { action, serviceId } of preimages ?? []) {
|
|
11193
10615
|
switch (action.kind) {
|
|
11194
10616
|
case UpdatePreimageKind.Provide: {
|
|
11195
10617
|
const { hash, blob } = action.preimage;
|
|
11196
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10618
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11197
10619
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11198
10620
|
if (action.slot !== null) {
|
|
11199
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, tryAsU32(blob.length));
|
|
10621
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
11200
10622
|
yield [
|
|
11201
10623
|
StateEntryUpdateAction.Insert,
|
|
11202
10624
|
codec2.key,
|
|
@@ -11207,15 +10629,15 @@ function* serializePreimages(preimages, encode) {
|
|
|
11207
10629
|
}
|
|
11208
10630
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11209
10631
|
const { hash, length, slots } = action.item;
|
|
11210
|
-
const codec = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10632
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11211
10633
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11212
10634
|
break;
|
|
11213
10635
|
}
|
|
11214
10636
|
case UpdatePreimageKind.Remove: {
|
|
11215
10637
|
const { hash, length } = action;
|
|
11216
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10638
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11217
10639
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11218
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10640
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11219
10641
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11220
10642
|
break;
|
|
11221
10643
|
}
|
|
@@ -11224,7 +10646,7 @@ function* serializePreimages(preimages, encode) {
|
|
|
11224
10646
|
}
|
|
11225
10647
|
}
|
|
11226
10648
|
}
|
|
11227
|
-
function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
10649
|
+
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11228
10650
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
11229
10651
|
// new service being created or updated
|
|
11230
10652
|
const codec = serialize.serviceData(serviceId);
|
|
@@ -11232,7 +10654,7 @@ function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
|
11232
10654
|
// additional lookup history update
|
|
11233
10655
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11234
10656
|
const { lookupHistory } = action;
|
|
11235
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10657
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11236
10658
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11237
10659
|
}
|
|
11238
10660
|
}
|
|
@@ -11327,8 +10749,8 @@ class StateEntries {
|
|
|
11327
10749
|
},
|
|
11328
10750
|
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11329
10751
|
/** Turn in-memory state into it's serialized form. */
|
|
11330
|
-
static serializeInMemory(spec, state) {
|
|
11331
|
-
return new StateEntries(convertInMemoryStateToDictionary(spec, state));
|
|
10752
|
+
static serializeInMemory(spec, blake2b, state) {
|
|
10753
|
+
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
11332
10754
|
}
|
|
11333
10755
|
/**
|
|
11334
10756
|
* Wrap a collection of truncated state entries and treat it as state.
|
|
@@ -11377,7 +10799,8 @@ class StateEntries {
|
|
|
11377
10799
|
}
|
|
11378
10800
|
}
|
|
11379
10801
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/391600391600?v=0.6.4 */
|
|
11380
|
-
getRootHash() {
|
|
10802
|
+
getRootHash(blake2b) {
|
|
10803
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11381
10804
|
const leaves = SortedSet.fromArray(leafComparator);
|
|
11382
10805
|
for (const [key, value] of this) {
|
|
11383
10806
|
leaves.insert(InMemoryTrie.constructLeaf(blake2bTrieHasher, key.asOpaque(), value));
|
|
@@ -11386,7 +10809,7 @@ class StateEntries {
|
|
|
11386
10809
|
}
|
|
11387
10810
|
}
|
|
11388
10811
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/38a50038a500?v=0.6.4 */
|
|
11389
|
-
function convertInMemoryStateToDictionary(spec, state) {
|
|
10812
|
+
function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
11390
10813
|
const serialized = TruncatedHashDictionary.fromEntries([]);
|
|
11391
10814
|
function doSerialize(codec) {
|
|
11392
10815
|
serialized.set(codec.key, Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
@@ -11414,18 +10837,18 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11414
10837
|
serialized.set(key, Encoder.encodeObject(Codec, service.getInfo()));
|
|
11415
10838
|
// preimages
|
|
11416
10839
|
for (const preimage of service.data.preimages.values()) {
|
|
11417
|
-
const { key, Codec } = serialize.servicePreimages(serviceId, preimage.hash);
|
|
10840
|
+
const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11418
10841
|
serialized.set(key, Encoder.encodeObject(Codec, preimage.blob));
|
|
11419
10842
|
}
|
|
11420
10843
|
// storage
|
|
11421
10844
|
for (const storage of service.data.storage.values()) {
|
|
11422
|
-
const { key, Codec } = serialize.serviceStorage(serviceId, storage.key);
|
|
10845
|
+
const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11423
10846
|
serialized.set(key, Encoder.encodeObject(Codec, storage.value));
|
|
11424
10847
|
}
|
|
11425
10848
|
// lookup history
|
|
11426
10849
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11427
10850
|
for (const lookupHistory of lookupHistoryList) {
|
|
11428
|
-
const { key, Codec } = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10851
|
+
const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11429
10852
|
serialized.set(key, Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11430
10853
|
}
|
|
11431
10854
|
}
|
|
@@ -11433,9 +10856,9 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11433
10856
|
return serialized;
|
|
11434
10857
|
}
|
|
11435
10858
|
|
|
11436
|
-
function loadState(spec, entries) {
|
|
10859
|
+
function loadState(spec, blake2b, entries) {
|
|
11437
10860
|
const stateEntries = StateEntries.fromEntriesUnsafe(entries);
|
|
11438
|
-
return SerializedState.fromStateEntries(spec, stateEntries);
|
|
10861
|
+
return SerializedState.fromStateEntries(spec, blake2b, stateEntries);
|
|
11439
10862
|
}
|
|
11440
10863
|
|
|
11441
10864
|
/**
|
|
@@ -11543,7 +10966,8 @@ class LeafDb {
|
|
|
11543
10966
|
}
|
|
11544
10967
|
assertNever(val);
|
|
11545
10968
|
}
|
|
11546
|
-
getStateRoot() {
|
|
10969
|
+
getStateRoot(blake2b) {
|
|
10970
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11547
10971
|
return InMemoryTrie.computeStateRoot(blake2bTrieHasher, this.leaves).asOpaque();
|
|
11548
10972
|
}
|
|
11549
10973
|
intoStateEntries() {
|
|
@@ -11733,7 +11157,8 @@ class InMemoryStates {
|
|
|
11733
11157
|
}
|
|
11734
11158
|
}
|
|
11735
11159
|
async getStateRoot(state) {
|
|
11736
|
-
|
|
11160
|
+
const blake2b = await Blake2b.createHasher();
|
|
11161
|
+
return StateEntries.serializeInMemory(this.spec, blake2b, state).getRootHash(blake2b);
|
|
11737
11162
|
}
|
|
11738
11163
|
/** Insert a full state into the database. */
|
|
11739
11164
|
async insertState(headerHash, state) {
|
|
@@ -12683,6 +12108,8 @@ var NewServiceError;
|
|
|
12683
12108
|
NewServiceError[NewServiceError["InsufficientFunds"] = 0] = "InsufficientFunds";
|
|
12684
12109
|
/** Service is not privileged to set gratis storage. */
|
|
12685
12110
|
NewServiceError[NewServiceError["UnprivilegedService"] = 1] = "UnprivilegedService";
|
|
12111
|
+
/** Registrar attempting to create a service with already existing id. */
|
|
12112
|
+
NewServiceError[NewServiceError["RegistrarServiceIdAlreadyTaken"] = 2] = "RegistrarServiceIdAlreadyTaken";
|
|
12686
12113
|
})(NewServiceError || (NewServiceError = {}));
|
|
12687
12114
|
var UpdatePrivilegesError;
|
|
12688
12115
|
(function (UpdatePrivilegesError) {
|
|
@@ -12873,11 +12300,17 @@ class AccumulationStateUpdate {
|
|
|
12873
12300
|
if (from.privilegedServices !== null) {
|
|
12874
12301
|
update.privilegedServices = PrivilegedServices.create({
|
|
12875
12302
|
...from.privilegedServices,
|
|
12876
|
-
|
|
12303
|
+
assigners: asKnownSize([...from.privilegedServices.assigners]),
|
|
12877
12304
|
});
|
|
12878
12305
|
}
|
|
12879
12306
|
return update;
|
|
12880
12307
|
}
|
|
12308
|
+
/** Retrieve and clear pending transfers. */
|
|
12309
|
+
takeTransfers() {
|
|
12310
|
+
const transfers = this.transfers;
|
|
12311
|
+
this.transfers = [];
|
|
12312
|
+
return transfers;
|
|
12313
|
+
}
|
|
12881
12314
|
}
|
|
12882
12315
|
class PartiallyUpdatedState {
|
|
12883
12316
|
state;
|
|
@@ -13074,7 +12507,7 @@ const HostCallResult = {
|
|
|
13074
12507
|
OOB: tryAsU64(0xfffffffffffffffdn), // 2**64 - 3
|
|
13075
12508
|
/** Index unknown. */
|
|
13076
12509
|
WHO: tryAsU64(0xfffffffffffffffcn), // 2**64 - 4
|
|
13077
|
-
/** Storage full. */
|
|
12510
|
+
/** Storage full or resource already allocated. */
|
|
13078
12511
|
FULL: tryAsU64(0xfffffffffffffffbn), // 2**64 - 5
|
|
13079
12512
|
/** Core index unknown. */
|
|
13080
12513
|
CORE: tryAsU64(0xfffffffffffffffan), // 2**64 - 6
|
|
@@ -13082,7 +12515,7 @@ const HostCallResult = {
|
|
|
13082
12515
|
CASH: tryAsU64(0xfffffffffffffff9n), // 2**64 - 7
|
|
13083
12516
|
/** Gas limit too low. */
|
|
13084
12517
|
LOW: tryAsU64(0xfffffffffffffff8n), // 2**64 - 8
|
|
13085
|
-
/** The item is already solicited
|
|
12518
|
+
/** The item is already solicited, cannot be forgotten or the operation is invalid due to privilege level. */
|
|
13086
12519
|
HUH: tryAsU64(0xfffffffffffffff7n), // 2**64 - 9
|
|
13087
12520
|
/** The return value indicating general success. */
|
|
13088
12521
|
OK: tryAsU64(0n),
|
|
@@ -15117,11 +14550,6 @@ class BitOps {
|
|
|
15117
14550
|
}
|
|
15118
14551
|
}
|
|
15119
14552
|
|
|
15120
|
-
const MAX_VALUE = 4294967295;
|
|
15121
|
-
const MIN_VALUE = -2147483648;
|
|
15122
|
-
const MAX_SHIFT_U32 = 32;
|
|
15123
|
-
const MAX_SHIFT_U64 = 64n;
|
|
15124
|
-
|
|
15125
14553
|
/**
|
|
15126
14554
|
* Overflowing addition for two-complement representation of 32-bit signed numbers.
|
|
15127
14555
|
*/
|
|
@@ -17431,7 +16859,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
17431
16859
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
17432
16860
|
getServiceId: getServiceId,
|
|
17433
16861
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
17434
|
-
hash: index$
|
|
16862
|
+
hash: index$o,
|
|
17435
16863
|
inspect: inspect,
|
|
17436
16864
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
17437
16865
|
interpreter: index$7,
|
|
@@ -17453,10 +16881,10 @@ const ENTROPY_BYTES = 32;
|
|
|
17453
16881
|
*
|
|
17454
16882
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
17455
16883
|
*/
|
|
17456
|
-
function fisherYatesShuffle(arr, entropy) {
|
|
16884
|
+
function fisherYatesShuffle(blake2b, arr, entropy) {
|
|
17457
16885
|
check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
17458
16886
|
const n = arr.length;
|
|
17459
|
-
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
16887
|
+
const randomNumbers = hashToNumberSequence(blake2b, entropy, arr.length);
|
|
17460
16888
|
const result = new Array(n);
|
|
17461
16889
|
let itemsLeft = n;
|
|
17462
16890
|
for (let i = 0; i < n; i++) {
|
|
@@ -17469,13 +16897,13 @@ function fisherYatesShuffle(arr, entropy) {
|
|
|
17469
16897
|
}
|
|
17470
16898
|
return result;
|
|
17471
16899
|
}
|
|
17472
|
-
function hashToNumberSequence(entropy, length) {
|
|
16900
|
+
function hashToNumberSequence(blake2b, entropy, length) {
|
|
17473
16901
|
const result = new Array(length);
|
|
17474
16902
|
const randomBytes = safeAllocUint8Array(ENTROPY_BYTES + 4);
|
|
17475
16903
|
randomBytes.set(entropy.raw);
|
|
17476
16904
|
for (let i = 0; i < length; i++) {
|
|
17477
16905
|
randomBytes.set(u32AsLeBytes(tryAsU32(Math.floor(i / 8))), ENTROPY_BYTES);
|
|
17478
|
-
const newHash = hashBytes(randomBytes);
|
|
16906
|
+
const newHash = blake2b.hashBytes(randomBytes);
|
|
17479
16907
|
const numberStartIndex = (4 * i) % 32;
|
|
17480
16908
|
const numberEndIndex = numberStartIndex + 4;
|
|
17481
16909
|
const number = leBytesAsU32(newHash.raw.subarray(numberStartIndex, numberEndIndex)) >>> 0;
|
|
@@ -17491,6 +16919,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
17491
16919
|
|
|
17492
16920
|
class JsonServiceInfo {
|
|
17493
16921
|
static fromJson = json.object({
|
|
16922
|
+
...(Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? { version: "number" } : {}),
|
|
17494
16923
|
code_hash: fromJson.bytes32(),
|
|
17495
16924
|
balance: json.fromNumber((x) => tryAsU64(x)),
|
|
17496
16925
|
min_item_gas: json.fromNumber((x) => tryAsServiceGas(x)),
|
|
@@ -17515,6 +16944,7 @@ class JsonServiceInfo {
|
|
|
17515
16944
|
parentService: parent_service,
|
|
17516
16945
|
});
|
|
17517
16946
|
});
|
|
16947
|
+
version;
|
|
17518
16948
|
code_hash;
|
|
17519
16949
|
balance;
|
|
17520
16950
|
min_item_gas;
|
|
@@ -17549,23 +16979,35 @@ const lookupMetaFromJson = json.object({
|
|
|
17549
16979
|
},
|
|
17550
16980
|
value: json.array("number"),
|
|
17551
16981
|
}, ({ key, value }) => new LookupHistoryItem(key.hash, key.length, value));
|
|
16982
|
+
const preimageStatusFromJson = json.object({
|
|
16983
|
+
hash: fromJson.bytes32(),
|
|
16984
|
+
status: json.array("number"),
|
|
16985
|
+
}, ({ hash, status }) => new LookupHistoryItem(hash, tryAsU32(0), status));
|
|
17552
16986
|
class JsonService {
|
|
17553
16987
|
static fromJson = json.object({
|
|
17554
16988
|
id: "number",
|
|
17555
|
-
data:
|
|
17556
|
-
|
|
17557
|
-
|
|
17558
|
-
|
|
17559
|
-
|
|
17560
|
-
|
|
16989
|
+
data: Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
16990
|
+
? {
|
|
16991
|
+
service: JsonServiceInfo.fromJson,
|
|
16992
|
+
preimages: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
16993
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
16994
|
+
lookup_meta: json.optional(json.array(lookupMetaFromJson)),
|
|
16995
|
+
}
|
|
16996
|
+
: {
|
|
16997
|
+
service: JsonServiceInfo.fromJson,
|
|
16998
|
+
storage: json.optional(json.array(JsonStorageItem.fromJson)),
|
|
16999
|
+
preimages_blob: json.optional(json.array(JsonPreimageItem.fromJson)),
|
|
17000
|
+
preimages_status: json.optional(json.array(preimageStatusFromJson)),
|
|
17001
|
+
},
|
|
17561
17002
|
}, ({ id, data }) => {
|
|
17003
|
+
const preimages = HashDictionary.fromEntries((data.preimages ?? data.preimages_blob ?? []).map((x) => [x.hash, x]));
|
|
17562
17004
|
const lookupHistory = HashDictionary.new();
|
|
17563
|
-
for (const item of data.lookup_meta ?? []) {
|
|
17005
|
+
for (const item of data.lookup_meta ?? data.preimages_status ?? []) {
|
|
17564
17006
|
const data = lookupHistory.get(item.hash) ?? [];
|
|
17565
|
-
|
|
17007
|
+
const length = tryAsU32(preimages.get(item.hash)?.blob.length ?? item.length);
|
|
17008
|
+
data.push(new LookupHistoryItem(item.hash, length, item.slots));
|
|
17566
17009
|
lookupHistory.set(item.hash, data);
|
|
17567
17010
|
}
|
|
17568
|
-
const preimages = HashDictionary.fromEntries((data.preimages ?? []).map((x) => [x.hash, x]));
|
|
17569
17011
|
const storage = new Map();
|
|
17570
17012
|
const entries = (data.storage ?? []).map(({ key, value }) => {
|
|
17571
17013
|
const opaqueKey = asOpaqueType(key);
|
|
@@ -17589,8 +17031,7 @@ const availabilityAssignmentFromJson = json.object({
|
|
|
17589
17031
|
report: workReportFromJson,
|
|
17590
17032
|
timeout: "number",
|
|
17591
17033
|
}, ({ report, timeout }) => {
|
|
17592
|
-
|
|
17593
|
-
return AvailabilityAssignment.create({ workReport: new WithHash(workReportHash, report), timeout });
|
|
17034
|
+
return AvailabilityAssignment.create({ workReport: report, timeout });
|
|
17594
17035
|
});
|
|
17595
17036
|
|
|
17596
17037
|
const disputesRecordsFromJson = json.object({
|
|
@@ -17738,8 +17179,12 @@ class JsonServiceStatistics {
|
|
|
17738
17179
|
extrinsic_count: "number",
|
|
17739
17180
|
accumulate_count: "number",
|
|
17740
17181
|
accumulate_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17741
|
-
|
|
17742
|
-
|
|
17182
|
+
...(Compatibility.isLessThan(GpVersion.V0_7_1)
|
|
17183
|
+
? {
|
|
17184
|
+
on_transfers_count: "number",
|
|
17185
|
+
on_transfers_gas_used: json.fromNumber(tryAsServiceGas),
|
|
17186
|
+
}
|
|
17187
|
+
: {}),
|
|
17743
17188
|
}, ({ 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, }) => {
|
|
17744
17189
|
return ServiceStatistics.create({
|
|
17745
17190
|
providedCount: provided_count,
|
|
@@ -17752,8 +17197,8 @@ class JsonServiceStatistics {
|
|
|
17752
17197
|
extrinsicCount: extrinsic_count,
|
|
17753
17198
|
accumulateCount: accumulate_count,
|
|
17754
17199
|
accumulateGasUsed: accumulate_gas_used,
|
|
17755
|
-
onTransfersCount: on_transfers_count,
|
|
17756
|
-
onTransfersGasUsed: on_transfers_gas_used,
|
|
17200
|
+
onTransfersCount: on_transfers_count ?? tryAsU32(0),
|
|
17201
|
+
onTransfersGasUsed: on_transfers_gas_used ?? tryAsServiceGas(0),
|
|
17757
17202
|
});
|
|
17758
17203
|
});
|
|
17759
17204
|
provided_count;
|
|
@@ -17824,6 +17269,7 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17824
17269
|
chi_m: "number",
|
|
17825
17270
|
chi_a: json.array("number"),
|
|
17826
17271
|
chi_v: "number",
|
|
17272
|
+
chi_r: json.optional("number"),
|
|
17827
17273
|
chi_g: json.nullable(json.array({
|
|
17828
17274
|
service: "number",
|
|
17829
17275
|
gasLimit: json.fromNumber((v) => tryAsServiceGas(v)),
|
|
@@ -17835,6 +17281,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17835
17281
|
theta: json.nullable(json.array(accumulationOutput)),
|
|
17836
17282
|
accounts: json.array(JsonService.fromJson),
|
|
17837
17283
|
}, ({ alpha, varphi, beta, gamma, psi, eta, iota, kappa, lambda, rho, tau, chi, pi, omega, xi, theta, accounts, }) => {
|
|
17284
|
+
if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && chi.chi_r === undefined) {
|
|
17285
|
+
throw new Error("Registrar is required in Privileges GP ^0.7.1");
|
|
17286
|
+
}
|
|
17838
17287
|
return InMemoryState.create({
|
|
17839
17288
|
authPools: tryAsPerCore(alpha.map((perCore) => {
|
|
17840
17289
|
if (perCore.length > MAX_AUTH_POOL_SIZE) {
|
|
@@ -17862,8 +17311,9 @@ const fullStateDumpFromJson = (spec) => json.object({
|
|
|
17862
17311
|
timeslot: tau,
|
|
17863
17312
|
privilegedServices: PrivilegedServices.create({
|
|
17864
17313
|
manager: chi.chi_m,
|
|
17865
|
-
|
|
17866
|
-
|
|
17314
|
+
assigners: chi.chi_a,
|
|
17315
|
+
delegator: chi.chi_v,
|
|
17316
|
+
registrar: chi.chi_r ?? tryAsServiceId(2 ** 32 - 1),
|
|
17867
17317
|
autoAccumulateServices: chi.chi_g ?? [],
|
|
17868
17318
|
}),
|
|
17869
17319
|
statistics: JsonStatisticsData.toStatisticsData(spec, pi),
|
|
@@ -17896,11 +17346,11 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17896
17346
|
class TransitionHasher {
|
|
17897
17347
|
context;
|
|
17898
17348
|
keccakHasher;
|
|
17899
|
-
|
|
17900
|
-
constructor(context, keccakHasher,
|
|
17349
|
+
blake2b;
|
|
17350
|
+
constructor(context, keccakHasher, blake2b) {
|
|
17901
17351
|
this.context = context;
|
|
17902
17352
|
this.keccakHasher = keccakHasher;
|
|
17903
|
-
this.
|
|
17353
|
+
this.blake2b = blake2b;
|
|
17904
17354
|
}
|
|
17905
17355
|
/** Concatenates two hashes and hash this concatenation */
|
|
17906
17356
|
hashConcat(a, b) {
|
|
@@ -17911,7 +17361,7 @@ class TransitionHasher {
|
|
|
17911
17361
|
}
|
|
17912
17362
|
/** Creates hash from the block header view */
|
|
17913
17363
|
header(header) {
|
|
17914
|
-
return new WithHash(hashBytes(header.encoded()
|
|
17364
|
+
return new WithHash(this.blake2b.hashBytes(header.encoded()).asOpaque(), header);
|
|
17915
17365
|
}
|
|
17916
17366
|
/**
|
|
17917
17367
|
* Merkle commitment of the extrinsic data
|
|
@@ -17924,7 +17374,7 @@ class TransitionHasher {
|
|
|
17924
17374
|
.view()
|
|
17925
17375
|
.map((g) => g.view())
|
|
17926
17376
|
.map((guarantee) => {
|
|
17927
|
-
const reportHash = hashBytes(guarantee.report.encoded()
|
|
17377
|
+
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17928
17378
|
return BytesBlob.blobFromParts([
|
|
17929
17379
|
reportHash.raw,
|
|
17930
17380
|
guarantee.slot.encoded().raw,
|
|
@@ -17932,13 +17382,13 @@ class TransitionHasher {
|
|
|
17932
17382
|
]);
|
|
17933
17383
|
});
|
|
17934
17384
|
const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
17935
|
-
const et = hashBytes(extrinsicView.tickets.encoded()
|
|
17936
|
-
const ep = hashBytes(extrinsicView.preimages.encoded()
|
|
17937
|
-
const eg = hashBytes(guaranteeBlob
|
|
17938
|
-
const ea = hashBytes(extrinsicView.assurances.encoded()
|
|
17939
|
-
const ed = hashBytes(extrinsicView.disputes.encoded()
|
|
17385
|
+
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17386
|
+
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17387
|
+
const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
|
|
17388
|
+
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17389
|
+
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17940
17390
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
17941
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17391
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
17942
17392
|
}
|
|
17943
17393
|
/** Creates hash for given WorkPackage */
|
|
17944
17394
|
workPackage(workPackage) {
|
|
@@ -17947,7 +17397,7 @@ class TransitionHasher {
|
|
|
17947
17397
|
encode(codec, data) {
|
|
17948
17398
|
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
17949
17399
|
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
17950
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17400
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
17951
17401
|
}
|
|
17952
17402
|
}
|
|
17953
17403
|
|
|
@@ -17960,8 +17410,10 @@ var PreimagesErrorCode;
|
|
|
17960
17410
|
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
17961
17411
|
class Preimages {
|
|
17962
17412
|
state;
|
|
17963
|
-
|
|
17413
|
+
blake2b;
|
|
17414
|
+
constructor(state, blake2b) {
|
|
17964
17415
|
this.state = state;
|
|
17416
|
+
this.blake2b = blake2b;
|
|
17965
17417
|
}
|
|
17966
17418
|
integrate(input) {
|
|
17967
17419
|
// make sure lookup extrinsics are sorted and unique
|
|
@@ -17984,7 +17436,7 @@ class Preimages {
|
|
|
17984
17436
|
// select preimages for integration
|
|
17985
17437
|
for (const preimage of preimages) {
|
|
17986
17438
|
const { requester, blob } = preimage;
|
|
17987
|
-
const hash = hashBytes(blob).asOpaque();
|
|
17439
|
+
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
17988
17440
|
const service = this.state.getService(requester);
|
|
17989
17441
|
if (service === null) {
|
|
17990
17442
|
return Result$1.error(PreimagesErrorCode.AccountNotFound);
|
|
@@ -18009,146 +17461,11 @@ class Preimages {
|
|
|
18009
17461
|
}
|
|
18010
17462
|
}
|
|
18011
17463
|
|
|
18012
|
-
class Missing {
|
|
18013
|
-
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
18014
|
-
basicGasCost = tryAsSmallGas(10);
|
|
18015
|
-
currentServiceId = CURRENT_SERVICE_ID;
|
|
18016
|
-
tracedRegisters = traceRegisters(7);
|
|
18017
|
-
execute(_gas, regs, _memory) {
|
|
18018
|
-
regs.set(7, HostCallResult.WHAT);
|
|
18019
|
-
return Promise.resolve(undefined);
|
|
18020
|
-
}
|
|
18021
|
-
}
|
|
18022
|
-
|
|
18023
|
-
var ServiceExecutorError;
|
|
18024
|
-
(function (ServiceExecutorError) {
|
|
18025
|
-
ServiceExecutorError[ServiceExecutorError["NoLookup"] = 0] = "NoLookup";
|
|
18026
|
-
ServiceExecutorError[ServiceExecutorError["NoState"] = 1] = "NoState";
|
|
18027
|
-
ServiceExecutorError[ServiceExecutorError["NoServiceCode"] = 2] = "NoServiceCode";
|
|
18028
|
-
ServiceExecutorError[ServiceExecutorError["ServiceCodeMismatch"] = 3] = "ServiceCodeMismatch";
|
|
18029
|
-
})(ServiceExecutorError || (ServiceExecutorError = {}));
|
|
18030
|
-
class WorkPackageExecutor {
|
|
18031
|
-
blocks;
|
|
18032
|
-
state;
|
|
18033
|
-
hasher;
|
|
18034
|
-
constructor(blocks, state, hasher) {
|
|
18035
|
-
this.blocks = blocks;
|
|
18036
|
-
this.state = state;
|
|
18037
|
-
this.hasher = hasher;
|
|
18038
|
-
}
|
|
18039
|
-
// TODO [ToDr] this while thing should be triple-checked with the GP.
|
|
18040
|
-
// I'm currently implementing some dirty version for the demo.
|
|
18041
|
-
async executeWorkPackage(pack) {
|
|
18042
|
-
const headerHash = pack.context.lookupAnchor;
|
|
18043
|
-
// execute authorisation first or is it already executed and we just need to check it?
|
|
18044
|
-
const authExec = this.getServiceExecutor(
|
|
18045
|
-
// TODO [ToDr] should this be anchor or lookupAnchor?
|
|
18046
|
-
headerHash, pack.authCodeHost, pack.authCodeHash);
|
|
18047
|
-
if (authExec.isError) {
|
|
18048
|
-
// TODO [ToDr] most likely shouldn't be throw.
|
|
18049
|
-
throw new Error(`Could not get authorization executor: ${authExec.error}`);
|
|
18050
|
-
}
|
|
18051
|
-
const pvm = authExec.ok;
|
|
18052
|
-
const authGas = tryAsGas(15000n);
|
|
18053
|
-
const result = await pvm.run(pack.parametrization, authGas);
|
|
18054
|
-
if (!result.isEqualTo(pack.authorization)) {
|
|
18055
|
-
throw new Error("Authorization is invalid.");
|
|
18056
|
-
}
|
|
18057
|
-
const results = [];
|
|
18058
|
-
for (const item of pack.items) {
|
|
18059
|
-
const exec = this.getServiceExecutor(headerHash, item.service, item.codeHash);
|
|
18060
|
-
if (exec.isError) {
|
|
18061
|
-
throw new Error(`Could not get item executor: ${exec.error}`);
|
|
18062
|
-
}
|
|
18063
|
-
const pvm = exec.ok;
|
|
18064
|
-
const gasRatio = tryAsServiceGas(3000n);
|
|
18065
|
-
const ret = await pvm.run(item.payload, tryAsGas(item.refineGasLimit)); // or accumulateGasLimit?
|
|
18066
|
-
results.push(WorkResult.create({
|
|
18067
|
-
serviceId: item.service,
|
|
18068
|
-
codeHash: item.codeHash,
|
|
18069
|
-
payloadHash: hashBytes(item.payload),
|
|
18070
|
-
gas: gasRatio,
|
|
18071
|
-
result: new WorkExecResult(WorkExecResultKind.ok, ret),
|
|
18072
|
-
load: WorkRefineLoad.create({
|
|
18073
|
-
gasUsed: tryAsServiceGas(5),
|
|
18074
|
-
importedSegments: tryAsU32(0),
|
|
18075
|
-
exportedSegments: tryAsU32(0),
|
|
18076
|
-
extrinsicSize: tryAsU32(0),
|
|
18077
|
-
extrinsicCount: tryAsU32(0),
|
|
18078
|
-
}),
|
|
18079
|
-
}));
|
|
18080
|
-
}
|
|
18081
|
-
const workPackage = this.hasher.workPackage(pack);
|
|
18082
|
-
const workPackageSpec = WorkPackageSpec.create({
|
|
18083
|
-
hash: workPackage.hash,
|
|
18084
|
-
length: tryAsU32(workPackage.encoded.length),
|
|
18085
|
-
erasureRoot: Bytes.zero(HASH_SIZE),
|
|
18086
|
-
exportsRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
18087
|
-
exportsCount: tryAsU16(0),
|
|
18088
|
-
});
|
|
18089
|
-
const coreIndex = tryAsCoreIndex(0);
|
|
18090
|
-
const authorizerHash = Bytes.fill(HASH_SIZE, 5).asOpaque();
|
|
18091
|
-
const workResults = FixedSizeArray.new(results, tryAsWorkItemsCount(results.length));
|
|
18092
|
-
return Promise.resolve(WorkReport.create({
|
|
18093
|
-
workPackageSpec,
|
|
18094
|
-
context: pack.context,
|
|
18095
|
-
coreIndex,
|
|
18096
|
-
authorizerHash,
|
|
18097
|
-
authorizationOutput: pack.authorization,
|
|
18098
|
-
segmentRootLookup: [],
|
|
18099
|
-
results: workResults,
|
|
18100
|
-
authorizationGasUsed: tryAsServiceGas(0),
|
|
18101
|
-
}));
|
|
18102
|
-
}
|
|
18103
|
-
getServiceExecutor(lookupAnchor, serviceId, expectedCodeHash) {
|
|
18104
|
-
const header = this.blocks.getHeader(lookupAnchor);
|
|
18105
|
-
if (header === null) {
|
|
18106
|
-
return Result$1.error(ServiceExecutorError.NoLookup);
|
|
18107
|
-
}
|
|
18108
|
-
const state = this.state.getState(lookupAnchor);
|
|
18109
|
-
if (state === null) {
|
|
18110
|
-
return Result$1.error(ServiceExecutorError.NoState);
|
|
18111
|
-
}
|
|
18112
|
-
const service = state.getService(serviceId);
|
|
18113
|
-
const serviceCodeHash = service?.getInfo().codeHash ?? null;
|
|
18114
|
-
if (serviceCodeHash === null) {
|
|
18115
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18116
|
-
}
|
|
18117
|
-
if (!serviceCodeHash.isEqualTo(expectedCodeHash)) {
|
|
18118
|
-
return Result$1.error(ServiceExecutorError.ServiceCodeMismatch);
|
|
18119
|
-
}
|
|
18120
|
-
const serviceCode = service?.getPreimage(serviceCodeHash.asOpaque()) ?? null;
|
|
18121
|
-
if (serviceCode === null) {
|
|
18122
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18123
|
-
}
|
|
18124
|
-
return Result$1.ok(new PvmExecutor(serviceCode));
|
|
18125
|
-
}
|
|
18126
|
-
}
|
|
18127
|
-
class PvmExecutor {
|
|
18128
|
-
serviceCode;
|
|
18129
|
-
pvm;
|
|
18130
|
-
hostCalls = new HostCallsManager({ missing: new Missing() });
|
|
18131
|
-
pvmInstanceManager = new InterpreterInstanceManager(4);
|
|
18132
|
-
constructor(serviceCode) {
|
|
18133
|
-
this.serviceCode = serviceCode;
|
|
18134
|
-
this.pvm = new HostCalls(this.pvmInstanceManager, this.hostCalls);
|
|
18135
|
-
}
|
|
18136
|
-
async run(args, gas) {
|
|
18137
|
-
const program = Program.fromSpi(this.serviceCode.raw, args.raw, true);
|
|
18138
|
-
const result = await this.pvm.runProgram(program.code, 5, gas, program.registers, program.memory);
|
|
18139
|
-
if (result.hasMemorySlice()) {
|
|
18140
|
-
return BytesBlob.blobFrom(result.memorySlice);
|
|
18141
|
-
}
|
|
18142
|
-
return BytesBlob.empty();
|
|
18143
|
-
}
|
|
18144
|
-
}
|
|
18145
|
-
|
|
18146
17464
|
var index = /*#__PURE__*/Object.freeze({
|
|
18147
17465
|
__proto__: null,
|
|
18148
17466
|
Preimages: Preimages,
|
|
18149
17467
|
get PreimagesErrorCode () { return PreimagesErrorCode; },
|
|
18150
|
-
TransitionHasher: TransitionHasher
|
|
18151
|
-
WorkPackageExecutor: WorkPackageExecutor
|
|
17468
|
+
TransitionHasher: TransitionHasher
|
|
18152
17469
|
});
|
|
18153
17470
|
|
|
18154
|
-
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$
|
|
17471
|
+
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$p as crypto, index$d as database, index$c as erasure_coding, index$a as fuzz_proto, index$o as hash, index$9 as jam_host_calls, index$k as json_parser, index$i as logger, index$8 as mmr, index$r as numbers, index$t as ordering, index$3 as pvm, index$6 as pvm_host_calls, index$7 as pvm_interpreter, index$4 as pvm_program, index$5 as pvm_spi_decoder, index$2 as shuffling, index$g as state, index$1 as state_json, index$e as state_merkleization, index as transition, index$f as trie, index$u as utils };
|