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