@typeberry/lib 0.1.3-3f7b9cf → 0.1.3-6759174
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 +367 -1116
- package/index.d.ts +257 -396
- package/index.js +366 -1115
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -332,6 +332,19 @@ const Result$1 = {
|
|
|
332
332
|
},
|
|
333
333
|
};
|
|
334
334
|
|
|
335
|
+
// about 2GB, the maximum ArrayBuffer length on Chrome confirmed by several sources:
|
|
336
|
+
// - https://issues.chromium.org/issues/40055619
|
|
337
|
+
// - https://stackoverflow.com/a/72124984
|
|
338
|
+
// - https://onnxruntime.ai/docs/tutorials/web/large-models.html#maximum-size-of-arraybuffer
|
|
339
|
+
const MAX_LENGTH$2 = 2145386496;
|
|
340
|
+
function safeAllocUint8Array(length) {
|
|
341
|
+
if (length > MAX_LENGTH$2) {
|
|
342
|
+
// biome-ignore lint/suspicious/noConsole: can't have a dependency on logger here
|
|
343
|
+
console.warn(`Trying to allocate ${length} bytes, which is greater than the maximum of ${MAX_LENGTH$2}.`);
|
|
344
|
+
}
|
|
345
|
+
return new Uint8Array(Math.min(MAX_LENGTH$2, length));
|
|
346
|
+
}
|
|
347
|
+
|
|
335
348
|
/**
|
|
336
349
|
* Utilities for tests.
|
|
337
350
|
*/
|
|
@@ -572,6 +585,7 @@ var index$u = /*#__PURE__*/Object.freeze({
|
|
|
572
585
|
DEFAULT_VERSION: DEFAULT_VERSION,
|
|
573
586
|
ErrorsCollector: ErrorsCollector,
|
|
574
587
|
get GpVersion () { return GpVersion; },
|
|
588
|
+
MAX_LENGTH: MAX_LENGTH$2,
|
|
575
589
|
OK: OK,
|
|
576
590
|
Result: Result$1,
|
|
577
591
|
TEST_COMPARE_USING: TEST_COMPARE_USING,
|
|
@@ -586,6 +600,7 @@ var index$u = /*#__PURE__*/Object.freeze({
|
|
|
586
600
|
isBrowser: isBrowser,
|
|
587
601
|
measure: measure,
|
|
588
602
|
resultToString: resultToString,
|
|
603
|
+
safeAllocUint8Array: safeAllocUint8Array,
|
|
589
604
|
seeThrough: seeThrough,
|
|
590
605
|
workspacePathFix: workspacePathFix
|
|
591
606
|
});
|
|
@@ -609,7 +624,7 @@ class BitVec {
|
|
|
609
624
|
* Create new [`BitVec`] with all values set to `false`.
|
|
610
625
|
*/
|
|
611
626
|
static empty(bitLength) {
|
|
612
|
-
const data =
|
|
627
|
+
const data = safeAllocUint8Array(Math.ceil(bitLength / 8));
|
|
613
628
|
return new BitVec(data, bitLength);
|
|
614
629
|
}
|
|
615
630
|
byteLength;
|
|
@@ -810,7 +825,7 @@ class BytesBlob {
|
|
|
810
825
|
static blobFromParts(v, ...rest) {
|
|
811
826
|
const vArr = v instanceof Uint8Array ? [v] : v;
|
|
812
827
|
const totalLength = vArr.reduce((a, v) => a + v.length, 0) + rest.reduce((a, v) => a + v.length, 0);
|
|
813
|
-
const buffer =
|
|
828
|
+
const buffer = safeAllocUint8Array(totalLength);
|
|
814
829
|
let offset = 0;
|
|
815
830
|
for (const r of vArr) {
|
|
816
831
|
buffer.set(r, offset);
|
|
@@ -883,7 +898,7 @@ class Bytes extends BytesBlob {
|
|
|
883
898
|
}
|
|
884
899
|
/** Create an empty [`Bytes<X>`] of given length. */
|
|
885
900
|
static zero(len) {
|
|
886
|
-
return new Bytes(
|
|
901
|
+
return new Bytes(safeAllocUint8Array(len), len);
|
|
887
902
|
}
|
|
888
903
|
// TODO [ToDr] `fill` should have the argments swapped to align with the rest.
|
|
889
904
|
/** Create a [`Bytes<X>`] with all bytes filled with given input number. */
|
|
@@ -3592,7 +3607,7 @@ async function verify(input) {
|
|
|
3592
3607
|
return Promise.resolve([]);
|
|
3593
3608
|
}
|
|
3594
3609
|
const dataLength = input.reduce((acc, { message, key, signature }) => acc + key.length + signature.length + message.length + 1, 0);
|
|
3595
|
-
const data =
|
|
3610
|
+
const data = safeAllocUint8Array(dataLength);
|
|
3596
3611
|
let offset = 0;
|
|
3597
3612
|
for (const { key, message, signature } of input) {
|
|
3598
3613
|
data.set(key.raw, offset);
|
|
@@ -3639,823 +3654,75 @@ var ed25519 = /*#__PURE__*/Object.freeze({
|
|
|
3639
3654
|
verifyBatch: verifyBatch
|
|
3640
3655
|
});
|
|
3641
3656
|
|
|
3657
|
+
const SEED_SIZE = 32;
|
|
3658
|
+
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
3659
|
+
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
3642
3660
|
/**
|
|
3643
|
-
*
|
|
3644
|
-
*
|
|
3645
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
3661
|
+
* JIP-5: Secret key derivation
|
|
3646
3662
|
*
|
|
3647
|
-
*/
|
|
3648
|
-
const HASH_SIZE = 32;
|
|
3649
|
-
/** A hash without last byte (useful for trie representation). */
|
|
3650
|
-
const TRUNCATED_HASH_SIZE = 31;
|
|
3651
|
-
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
3663
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
3652
3664
|
/**
|
|
3653
|
-
*
|
|
3654
|
-
*
|
|
3655
|
-
* After calculating the hash these two should be passed together to avoid
|
|
3656
|
-
* unnecessary re-hashing of the data.
|
|
3665
|
+
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
3666
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
3657
3667
|
*/
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
constructor(hash, data) {
|
|
3662
|
-
super();
|
|
3663
|
-
this.hash = hash;
|
|
3664
|
-
this.data = data;
|
|
3665
|
-
}
|
|
3668
|
+
function trivialSeed(s) {
|
|
3669
|
+
const s_le = u32AsLeBytes(s);
|
|
3670
|
+
return Bytes.fromBlob(BytesBlob.blobFromParts([s_le, s_le, s_le, s_le, s_le, s_le, s_le, s_le]).raw, SEED_SIZE).asOpaque();
|
|
3666
3671
|
}
|
|
3667
3672
|
/**
|
|
3668
|
-
*
|
|
3673
|
+
* Derives a Ed25519 secret key from a seed.
|
|
3674
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
3669
3675
|
*/
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
constructor(hash, data, encoded) {
|
|
3673
|
-
super(hash, data);
|
|
3674
|
-
this.encoded = encoded;
|
|
3675
|
-
}
|
|
3676
|
-
}
|
|
3677
|
-
|
|
3678
|
-
/** The simplest allocator returning just a fresh copy of bytes each time. */
|
|
3679
|
-
class SimpleAllocator {
|
|
3680
|
-
emptyHash() {
|
|
3681
|
-
return Bytes.zero(HASH_SIZE);
|
|
3682
|
-
}
|
|
3683
|
-
}
|
|
3684
|
-
/** An allocator that works by allocating larger (continuous) pages of memory. */
|
|
3685
|
-
class PageAllocator {
|
|
3686
|
-
hashesPerPage;
|
|
3687
|
-
page = new Uint8Array(0);
|
|
3688
|
-
currentHash = 0;
|
|
3689
|
-
// TODO [ToDr] Benchmark the performance!
|
|
3690
|
-
constructor(hashesPerPage) {
|
|
3691
|
-
this.hashesPerPage = hashesPerPage;
|
|
3692
|
-
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
3693
|
-
this.resetPage();
|
|
3694
|
-
}
|
|
3695
|
-
resetPage() {
|
|
3696
|
-
const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
|
|
3697
|
-
this.currentHash = 0;
|
|
3698
|
-
this.page = new Uint8Array(pageSizeBytes);
|
|
3699
|
-
}
|
|
3700
|
-
emptyHash() {
|
|
3701
|
-
const startIdx = this.currentHash * HASH_SIZE;
|
|
3702
|
-
const endIdx = startIdx + HASH_SIZE;
|
|
3703
|
-
this.currentHash += 1;
|
|
3704
|
-
if (this.currentHash >= this.hashesPerPage) {
|
|
3705
|
-
this.resetPage();
|
|
3706
|
-
}
|
|
3707
|
-
return Bytes.fromBlob(this.page.subarray(startIdx, endIdx), HASH_SIZE);
|
|
3708
|
-
}
|
|
3709
|
-
}
|
|
3710
|
-
const defaultAllocator = new SimpleAllocator();
|
|
3711
|
-
|
|
3712
|
-
function getDefaultExportFromCjs (x) {
|
|
3713
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3714
|
-
}
|
|
3715
|
-
|
|
3716
|
-
var blake2b$3 = {exports: {}};
|
|
3717
|
-
|
|
3718
|
-
var nanoassert;
|
|
3719
|
-
var hasRequiredNanoassert;
|
|
3720
|
-
|
|
3721
|
-
function requireNanoassert () {
|
|
3722
|
-
if (hasRequiredNanoassert) return nanoassert;
|
|
3723
|
-
hasRequiredNanoassert = 1;
|
|
3724
|
-
nanoassert = assert;
|
|
3725
|
-
|
|
3726
|
-
class AssertionError extends Error {}
|
|
3727
|
-
AssertionError.prototype.name = 'AssertionError';
|
|
3728
|
-
|
|
3729
|
-
/**
|
|
3730
|
-
* Minimal assert function
|
|
3731
|
-
* @param {any} t Value to check if falsy
|
|
3732
|
-
* @param {string=} m Optional assertion error message
|
|
3733
|
-
* @throws {AssertionError}
|
|
3734
|
-
*/
|
|
3735
|
-
function assert (t, m) {
|
|
3736
|
-
if (!t) {
|
|
3737
|
-
var err = new AssertionError(m);
|
|
3738
|
-
if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
|
|
3739
|
-
throw err
|
|
3740
|
-
}
|
|
3741
|
-
}
|
|
3742
|
-
return nanoassert;
|
|
3743
|
-
}
|
|
3744
|
-
|
|
3745
|
-
var blake2bWasm = {exports: {}};
|
|
3746
|
-
|
|
3747
|
-
var b4a;
|
|
3748
|
-
var hasRequiredB4a;
|
|
3749
|
-
|
|
3750
|
-
function requireB4a () {
|
|
3751
|
-
if (hasRequiredB4a) return b4a;
|
|
3752
|
-
hasRequiredB4a = 1;
|
|
3753
|
-
function isBuffer (value) {
|
|
3754
|
-
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
3755
|
-
}
|
|
3756
|
-
|
|
3757
|
-
function isEncoding (encoding) {
|
|
3758
|
-
return Buffer.isEncoding(encoding)
|
|
3759
|
-
}
|
|
3760
|
-
|
|
3761
|
-
function alloc (size, fill, encoding) {
|
|
3762
|
-
return Buffer.alloc(size, fill, encoding)
|
|
3763
|
-
}
|
|
3764
|
-
|
|
3765
|
-
function allocUnsafe (size) {
|
|
3766
|
-
return Buffer.allocUnsafe(size)
|
|
3767
|
-
}
|
|
3768
|
-
|
|
3769
|
-
function allocUnsafeSlow (size) {
|
|
3770
|
-
return Buffer.allocUnsafeSlow(size)
|
|
3771
|
-
}
|
|
3772
|
-
|
|
3773
|
-
function byteLength (string, encoding) {
|
|
3774
|
-
return Buffer.byteLength(string, encoding)
|
|
3775
|
-
}
|
|
3776
|
-
|
|
3777
|
-
function compare (a, b) {
|
|
3778
|
-
return Buffer.compare(a, b)
|
|
3779
|
-
}
|
|
3780
|
-
|
|
3781
|
-
function concat (buffers, totalLength) {
|
|
3782
|
-
return Buffer.concat(buffers, totalLength)
|
|
3783
|
-
}
|
|
3784
|
-
|
|
3785
|
-
function copy (source, target, targetStart, start, end) {
|
|
3786
|
-
return toBuffer(source).copy(target, targetStart, start, end)
|
|
3787
|
-
}
|
|
3788
|
-
|
|
3789
|
-
function equals (a, b) {
|
|
3790
|
-
return toBuffer(a).equals(b)
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
function fill (buffer, value, offset, end, encoding) {
|
|
3794
|
-
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
3795
|
-
}
|
|
3796
|
-
|
|
3797
|
-
function from (value, encodingOrOffset, length) {
|
|
3798
|
-
return Buffer.from(value, encodingOrOffset, length)
|
|
3799
|
-
}
|
|
3800
|
-
|
|
3801
|
-
function includes (buffer, value, byteOffset, encoding) {
|
|
3802
|
-
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
3803
|
-
}
|
|
3804
|
-
|
|
3805
|
-
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
3806
|
-
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
3807
|
-
}
|
|
3808
|
-
|
|
3809
|
-
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
3810
|
-
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
3811
|
-
}
|
|
3812
|
-
|
|
3813
|
-
function swap16 (buffer) {
|
|
3814
|
-
return toBuffer(buffer).swap16()
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
function swap32 (buffer) {
|
|
3818
|
-
return toBuffer(buffer).swap32()
|
|
3819
|
-
}
|
|
3820
|
-
|
|
3821
|
-
function swap64 (buffer) {
|
|
3822
|
-
return toBuffer(buffer).swap64()
|
|
3823
|
-
}
|
|
3824
|
-
|
|
3825
|
-
function toBuffer (buffer) {
|
|
3826
|
-
if (Buffer.isBuffer(buffer)) return buffer
|
|
3827
|
-
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
3828
|
-
}
|
|
3829
|
-
|
|
3830
|
-
function toString (buffer, encoding, start, end) {
|
|
3831
|
-
return toBuffer(buffer).toString(encoding, start, end)
|
|
3832
|
-
}
|
|
3833
|
-
|
|
3834
|
-
function write (buffer, string, offset, length, encoding) {
|
|
3835
|
-
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
3836
|
-
}
|
|
3837
|
-
|
|
3838
|
-
function writeDoubleLE (buffer, value, offset) {
|
|
3839
|
-
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
3840
|
-
}
|
|
3841
|
-
|
|
3842
|
-
function writeFloatLE (buffer, value, offset) {
|
|
3843
|
-
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
3844
|
-
}
|
|
3845
|
-
|
|
3846
|
-
function writeUInt32LE (buffer, value, offset) {
|
|
3847
|
-
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
3848
|
-
}
|
|
3849
|
-
|
|
3850
|
-
function writeInt32LE (buffer, value, offset) {
|
|
3851
|
-
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
3852
|
-
}
|
|
3853
|
-
|
|
3854
|
-
function readDoubleLE (buffer, offset) {
|
|
3855
|
-
return toBuffer(buffer).readDoubleLE(offset)
|
|
3856
|
-
}
|
|
3857
|
-
|
|
3858
|
-
function readFloatLE (buffer, offset) {
|
|
3859
|
-
return toBuffer(buffer).readFloatLE(offset)
|
|
3860
|
-
}
|
|
3861
|
-
|
|
3862
|
-
function readUInt32LE (buffer, offset) {
|
|
3863
|
-
return toBuffer(buffer).readUInt32LE(offset)
|
|
3864
|
-
}
|
|
3865
|
-
|
|
3866
|
-
function readInt32LE (buffer, offset) {
|
|
3867
|
-
return toBuffer(buffer).readInt32LE(offset)
|
|
3868
|
-
}
|
|
3869
|
-
|
|
3870
|
-
b4a = {
|
|
3871
|
-
isBuffer,
|
|
3872
|
-
isEncoding,
|
|
3873
|
-
alloc,
|
|
3874
|
-
allocUnsafe,
|
|
3875
|
-
allocUnsafeSlow,
|
|
3876
|
-
byteLength,
|
|
3877
|
-
compare,
|
|
3878
|
-
concat,
|
|
3879
|
-
copy,
|
|
3880
|
-
equals,
|
|
3881
|
-
fill,
|
|
3882
|
-
from,
|
|
3883
|
-
includes,
|
|
3884
|
-
indexOf,
|
|
3885
|
-
lastIndexOf,
|
|
3886
|
-
swap16,
|
|
3887
|
-
swap32,
|
|
3888
|
-
swap64,
|
|
3889
|
-
toBuffer,
|
|
3890
|
-
toString,
|
|
3891
|
-
write,
|
|
3892
|
-
writeDoubleLE,
|
|
3893
|
-
writeFloatLE,
|
|
3894
|
-
writeUInt32LE,
|
|
3895
|
-
writeInt32LE,
|
|
3896
|
-
readDoubleLE,
|
|
3897
|
-
readFloatLE,
|
|
3898
|
-
readUInt32LE,
|
|
3899
|
-
readInt32LE
|
|
3900
|
-
};
|
|
3901
|
-
return b4a;
|
|
3902
|
-
}
|
|
3903
|
-
|
|
3904
|
-
var blake2b$2;
|
|
3905
|
-
var hasRequiredBlake2b$1;
|
|
3906
|
-
|
|
3907
|
-
function requireBlake2b$1 () {
|
|
3908
|
-
if (hasRequiredBlake2b$1) return blake2b$2;
|
|
3909
|
-
hasRequiredBlake2b$1 = 1;
|
|
3910
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3911
|
-
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3912
|
-
};
|
|
3913
|
-
var __toBinary = /* @__PURE__ */ (() => {
|
|
3914
|
-
var table = new Uint8Array(128);
|
|
3915
|
-
for (var i = 0; i < 64; i++)
|
|
3916
|
-
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
3917
|
-
return (base64) => {
|
|
3918
|
-
var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
3919
|
-
for (var i2 = 0, j = 0; i2 < n; ) {
|
|
3920
|
-
var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
3921
|
-
var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
3922
|
-
bytes2[j++] = c0 << 2 | c1 >> 4;
|
|
3923
|
-
bytes2[j++] = c1 << 4 | c2 >> 2;
|
|
3924
|
-
bytes2[j++] = c2 << 6 | c3;
|
|
3925
|
-
}
|
|
3926
|
-
return bytes2;
|
|
3927
|
-
};
|
|
3928
|
-
})();
|
|
3929
|
-
|
|
3930
|
-
// wasm-binary:./blake2b.wat
|
|
3931
|
-
var require_blake2b = __commonJS({
|
|
3932
|
-
"wasm-binary:./blake2b.wat"(exports2, module2) {
|
|
3933
|
-
module2.exports = __toBinary("AGFzbQEAAAABEANg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iAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
|
|
3934
|
-
}
|
|
3935
|
-
});
|
|
3936
|
-
|
|
3937
|
-
// wasm-module:./blake2b.wat
|
|
3938
|
-
var bytes = require_blake2b();
|
|
3939
|
-
var compiled = WebAssembly.compile(bytes);
|
|
3940
|
-
blake2b$2 = async (imports) => {
|
|
3941
|
-
const instance = await WebAssembly.instantiate(await compiled, imports);
|
|
3942
|
-
return instance.exports;
|
|
3943
|
-
};
|
|
3944
|
-
return blake2b$2;
|
|
3945
|
-
}
|
|
3946
|
-
|
|
3947
|
-
var hasRequiredBlake2bWasm;
|
|
3948
|
-
|
|
3949
|
-
function requireBlake2bWasm () {
|
|
3950
|
-
if (hasRequiredBlake2bWasm) return blake2bWasm.exports;
|
|
3951
|
-
hasRequiredBlake2bWasm = 1;
|
|
3952
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
3953
|
-
var b4a = /*@__PURE__*/ requireB4a();
|
|
3954
|
-
|
|
3955
|
-
var wasm = null;
|
|
3956
|
-
var wasmPromise = typeof WebAssembly !== "undefined" && /*@__PURE__*/ requireBlake2b$1()().then(mod => {
|
|
3957
|
-
wasm = mod;
|
|
3958
|
-
});
|
|
3959
|
-
|
|
3960
|
-
var head = 64;
|
|
3961
|
-
var freeList = [];
|
|
3962
|
-
|
|
3963
|
-
blake2bWasm.exports = Blake2b;
|
|
3964
|
-
var BYTES_MIN = blake2bWasm.exports.BYTES_MIN = 16;
|
|
3965
|
-
var BYTES_MAX = blake2bWasm.exports.BYTES_MAX = 64;
|
|
3966
|
-
blake2bWasm.exports.BYTES = 32;
|
|
3967
|
-
var KEYBYTES_MIN = blake2bWasm.exports.KEYBYTES_MIN = 16;
|
|
3968
|
-
var KEYBYTES_MAX = blake2bWasm.exports.KEYBYTES_MAX = 64;
|
|
3969
|
-
blake2bWasm.exports.KEYBYTES = 32;
|
|
3970
|
-
var SALTBYTES = blake2bWasm.exports.SALTBYTES = 16;
|
|
3971
|
-
var PERSONALBYTES = blake2bWasm.exports.PERSONALBYTES = 16;
|
|
3972
|
-
|
|
3973
|
-
function Blake2b (digestLength, key, salt, personal, noAssert) {
|
|
3974
|
-
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
|
|
3975
|
-
if (!wasm) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
|
|
3976
|
-
if (!digestLength) digestLength = 32;
|
|
3977
|
-
|
|
3978
|
-
if (noAssert !== true) {
|
|
3979
|
-
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength);
|
|
3980
|
-
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength);
|
|
3981
|
-
if (key != null) {
|
|
3982
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
3983
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
3984
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at least ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
3985
|
-
}
|
|
3986
|
-
if (salt != null) {
|
|
3987
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
3988
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
3989
|
-
}
|
|
3990
|
-
if (personal != null) {
|
|
3991
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
3992
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
3993
|
-
}
|
|
3994
|
-
}
|
|
3995
|
-
|
|
3996
|
-
if (!freeList.length) {
|
|
3997
|
-
freeList.push(head);
|
|
3998
|
-
head += 216;
|
|
3999
|
-
}
|
|
4000
|
-
|
|
4001
|
-
this.digestLength = digestLength;
|
|
4002
|
-
this.finalized = false;
|
|
4003
|
-
this.pointer = freeList.pop();
|
|
4004
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4005
|
-
|
|
4006
|
-
this._memory.fill(0, 0, 64);
|
|
4007
|
-
this._memory[0] = this.digestLength;
|
|
4008
|
-
this._memory[1] = key ? key.length : 0;
|
|
4009
|
-
this._memory[2] = 1; // fanout
|
|
4010
|
-
this._memory[3] = 1; // depth
|
|
4011
|
-
|
|
4012
|
-
if (salt) this._memory.set(salt, 32);
|
|
4013
|
-
if (personal) this._memory.set(personal, 48);
|
|
4014
|
-
|
|
4015
|
-
if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216); // we need 216 bytes for the state
|
|
4016
|
-
wasm.blake2b_init(this.pointer, this.digestLength);
|
|
4017
|
-
|
|
4018
|
-
if (key) {
|
|
4019
|
-
this.update(key);
|
|
4020
|
-
this._memory.fill(0, head, head + key.length); // whiteout key
|
|
4021
|
-
this._memory[this.pointer + 200] = 128;
|
|
4022
|
-
}
|
|
4023
|
-
}
|
|
4024
|
-
|
|
4025
|
-
Blake2b.prototype._realloc = function (size) {
|
|
4026
|
-
wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
|
|
4027
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4028
|
-
};
|
|
4029
|
-
|
|
4030
|
-
Blake2b.prototype.update = function (input) {
|
|
4031
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4032
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4033
|
-
|
|
4034
|
-
if (head + input.length > this._memory.length) this._realloc(head + input.length);
|
|
4035
|
-
this._memory.set(input, head);
|
|
4036
|
-
wasm.blake2b_update(this.pointer, head, head + input.length);
|
|
4037
|
-
return this
|
|
4038
|
-
};
|
|
4039
|
-
|
|
4040
|
-
Blake2b.prototype.digest = function (enc) {
|
|
4041
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4042
|
-
this.finalized = true;
|
|
4043
|
-
|
|
4044
|
-
freeList.push(this.pointer);
|
|
4045
|
-
wasm.blake2b_final(this.pointer);
|
|
4046
|
-
|
|
4047
|
-
if (!enc || enc === 'binary') {
|
|
4048
|
-
return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4049
|
-
}
|
|
4050
|
-
|
|
4051
|
-
if (typeof enc === 'string') {
|
|
4052
|
-
return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4053
|
-
}
|
|
4054
|
-
|
|
4055
|
-
assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
|
|
4056
|
-
for (var i = 0; i < this.digestLength; i++) {
|
|
4057
|
-
enc[i] = this._memory[this.pointer + 128 + i];
|
|
4058
|
-
}
|
|
4059
|
-
|
|
4060
|
-
return enc
|
|
4061
|
-
};
|
|
4062
|
-
|
|
4063
|
-
// libsodium compat
|
|
4064
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4065
|
-
|
|
4066
|
-
Blake2b.WASM = wasm;
|
|
4067
|
-
Blake2b.SUPPORTED = typeof WebAssembly !== 'undefined';
|
|
4068
|
-
|
|
4069
|
-
Blake2b.ready = function (cb) {
|
|
4070
|
-
if (!cb) cb = noop;
|
|
4071
|
-
if (!wasmPromise) return cb(new Error('WebAssembly not supported'))
|
|
4072
|
-
return wasmPromise.then(() => cb(), cb)
|
|
4073
|
-
};
|
|
4074
|
-
|
|
4075
|
-
Blake2b.prototype.ready = Blake2b.ready;
|
|
4076
|
-
|
|
4077
|
-
Blake2b.prototype.getPartialHash = function () {
|
|
4078
|
-
return this._memory.slice(this.pointer, this.pointer + 216);
|
|
4079
|
-
};
|
|
4080
|
-
|
|
4081
|
-
Blake2b.prototype.setPartialHash = function (ph) {
|
|
4082
|
-
this._memory.set(ph, this.pointer);
|
|
4083
|
-
};
|
|
4084
|
-
|
|
4085
|
-
function noop () {}
|
|
4086
|
-
return blake2bWasm.exports;
|
|
4087
|
-
}
|
|
4088
|
-
|
|
4089
|
-
var hasRequiredBlake2b;
|
|
4090
|
-
|
|
4091
|
-
function requireBlake2b () {
|
|
4092
|
-
if (hasRequiredBlake2b) return blake2b$3.exports;
|
|
4093
|
-
hasRequiredBlake2b = 1;
|
|
4094
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
4095
|
-
var b2wasm = /*@__PURE__*/ requireBlake2bWasm();
|
|
4096
|
-
|
|
4097
|
-
// 64-bit unsigned addition
|
|
4098
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
4099
|
-
// v should be a Uint32Array
|
|
4100
|
-
function ADD64AA (v, a, b) {
|
|
4101
|
-
var o0 = v[a] + v[b];
|
|
4102
|
-
var o1 = v[a + 1] + v[b + 1];
|
|
4103
|
-
if (o0 >= 0x100000000) {
|
|
4104
|
-
o1++;
|
|
4105
|
-
}
|
|
4106
|
-
v[a] = o0;
|
|
4107
|
-
v[a + 1] = o1;
|
|
4108
|
-
}
|
|
4109
|
-
|
|
4110
|
-
// 64-bit unsigned addition
|
|
4111
|
-
// Sets v[a,a+1] += b
|
|
4112
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
4113
|
-
function ADD64AC (v, a, b0, b1) {
|
|
4114
|
-
var o0 = v[a] + b0;
|
|
4115
|
-
if (b0 < 0) {
|
|
4116
|
-
o0 += 0x100000000;
|
|
4117
|
-
}
|
|
4118
|
-
var o1 = v[a + 1] + b1;
|
|
4119
|
-
if (o0 >= 0x100000000) {
|
|
4120
|
-
o1++;
|
|
4121
|
-
}
|
|
4122
|
-
v[a] = o0;
|
|
4123
|
-
v[a + 1] = o1;
|
|
4124
|
-
}
|
|
4125
|
-
|
|
4126
|
-
// Little-endian byte access
|
|
4127
|
-
function B2B_GET32 (arr, i) {
|
|
4128
|
-
return (arr[i] ^
|
|
4129
|
-
(arr[i + 1] << 8) ^
|
|
4130
|
-
(arr[i + 2] << 16) ^
|
|
4131
|
-
(arr[i + 3] << 24))
|
|
4132
|
-
}
|
|
4133
|
-
|
|
4134
|
-
// G Mixing function
|
|
4135
|
-
// The ROTRs are inlined for speed
|
|
4136
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
4137
|
-
var x0 = m[ix];
|
|
4138
|
-
var x1 = m[ix + 1];
|
|
4139
|
-
var y0 = m[iy];
|
|
4140
|
-
var y1 = m[iy + 1];
|
|
4141
|
-
|
|
4142
|
-
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
4143
|
-
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
4144
|
-
|
|
4145
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
4146
|
-
var xor0 = v[d] ^ v[a];
|
|
4147
|
-
var xor1 = v[d + 1] ^ v[a + 1];
|
|
4148
|
-
v[d] = xor1;
|
|
4149
|
-
v[d + 1] = xor0;
|
|
4150
|
-
|
|
4151
|
-
ADD64AA(v, c, d);
|
|
4152
|
-
|
|
4153
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
4154
|
-
xor0 = v[b] ^ v[c];
|
|
4155
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4156
|
-
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
4157
|
-
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
4158
|
-
|
|
4159
|
-
ADD64AA(v, a, b);
|
|
4160
|
-
ADD64AC(v, a, y0, y1);
|
|
4161
|
-
|
|
4162
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
4163
|
-
xor0 = v[d] ^ v[a];
|
|
4164
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
4165
|
-
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
4166
|
-
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
4167
|
-
|
|
4168
|
-
ADD64AA(v, c, d);
|
|
4169
|
-
|
|
4170
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
4171
|
-
xor0 = v[b] ^ v[c];
|
|
4172
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4173
|
-
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
4174
|
-
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
4175
|
-
}
|
|
4176
|
-
|
|
4177
|
-
// Initialization Vector
|
|
4178
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
4179
|
-
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
4180
|
-
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
4181
|
-
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
4182
|
-
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
4183
|
-
]);
|
|
4184
|
-
|
|
4185
|
-
var SIGMA8 = [
|
|
4186
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4187
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
4188
|
-
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
4189
|
-
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
4190
|
-
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
4191
|
-
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
4192
|
-
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
4193
|
-
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
4194
|
-
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
4195
|
-
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
4196
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4197
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
4198
|
-
];
|
|
4199
|
-
|
|
4200
|
-
// These are offsets into a uint64 buffer.
|
|
4201
|
-
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
4202
|
-
// because this is Javascript and we don't have uint64s
|
|
4203
|
-
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }));
|
|
4204
|
-
|
|
4205
|
-
// Compression function. 'last' flag indicates last block.
|
|
4206
|
-
// Note we're representing 16 uint64s as 32 uint32s
|
|
4207
|
-
var v = new Uint32Array(32);
|
|
4208
|
-
var m = new Uint32Array(32);
|
|
4209
|
-
function blake2bCompress (ctx, last) {
|
|
4210
|
-
var i = 0;
|
|
4211
|
-
|
|
4212
|
-
// init work variables
|
|
4213
|
-
for (i = 0; i < 16; i++) {
|
|
4214
|
-
v[i] = ctx.h[i];
|
|
4215
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
4216
|
-
}
|
|
4217
|
-
|
|
4218
|
-
// low 64 bits of offset
|
|
4219
|
-
v[24] = v[24] ^ ctx.t;
|
|
4220
|
-
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
4221
|
-
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
4222
|
-
|
|
4223
|
-
// last block flag set ?
|
|
4224
|
-
if (last) {
|
|
4225
|
-
v[28] = ~v[28];
|
|
4226
|
-
v[29] = ~v[29];
|
|
4227
|
-
}
|
|
4228
|
-
|
|
4229
|
-
// get little-endian words
|
|
4230
|
-
for (i = 0; i < 32; i++) {
|
|
4231
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
4232
|
-
}
|
|
4233
|
-
|
|
4234
|
-
// twelve rounds of mixing
|
|
4235
|
-
for (i = 0; i < 12; i++) {
|
|
4236
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
4237
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
4238
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
4239
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
4240
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
4241
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
4242
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
4243
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
4244
|
-
}
|
|
4245
|
-
|
|
4246
|
-
for (i = 0; i < 16; i++) {
|
|
4247
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
4248
|
-
}
|
|
4249
|
-
}
|
|
4250
|
-
|
|
4251
|
-
// reusable parameter_block
|
|
4252
|
-
var parameter_block = new Uint8Array([
|
|
4253
|
-
0, 0, 0, 0, // 0: outlen, keylen, fanout, depth
|
|
4254
|
-
0, 0, 0, 0, // 4: leaf length, sequential mode
|
|
4255
|
-
0, 0, 0, 0, // 8: node offset
|
|
4256
|
-
0, 0, 0, 0, // 12: node offset
|
|
4257
|
-
0, 0, 0, 0, // 16: node depth, inner length, rfu
|
|
4258
|
-
0, 0, 0, 0, // 20: rfu
|
|
4259
|
-
0, 0, 0, 0, // 24: rfu
|
|
4260
|
-
0, 0, 0, 0, // 28: rfu
|
|
4261
|
-
0, 0, 0, 0, // 32: salt
|
|
4262
|
-
0, 0, 0, 0, // 36: salt
|
|
4263
|
-
0, 0, 0, 0, // 40: salt
|
|
4264
|
-
0, 0, 0, 0, // 44: salt
|
|
4265
|
-
0, 0, 0, 0, // 48: personal
|
|
4266
|
-
0, 0, 0, 0, // 52: personal
|
|
4267
|
-
0, 0, 0, 0, // 56: personal
|
|
4268
|
-
0, 0, 0, 0 // 60: personal
|
|
4269
|
-
]);
|
|
4270
|
-
|
|
4271
|
-
// Creates a BLAKE2b hashing context
|
|
4272
|
-
// Requires an output length between 1 and 64 bytes
|
|
4273
|
-
// Takes an optional Uint8Array key
|
|
4274
|
-
function Blake2b (outlen, key, salt, personal) {
|
|
4275
|
-
// zero out parameter_block before usage
|
|
4276
|
-
parameter_block.fill(0);
|
|
4277
|
-
// state, 'param block'
|
|
4278
|
-
|
|
4279
|
-
this.b = new Uint8Array(128);
|
|
4280
|
-
this.h = new Uint32Array(16);
|
|
4281
|
-
this.t = 0; // input count
|
|
4282
|
-
this.c = 0; // pointer within buffer
|
|
4283
|
-
this.outlen = outlen; // output length in bytes
|
|
4284
|
-
|
|
4285
|
-
parameter_block[0] = outlen;
|
|
4286
|
-
if (key) parameter_block[1] = key.length;
|
|
4287
|
-
parameter_block[2] = 1; // fanout
|
|
4288
|
-
parameter_block[3] = 1; // depth
|
|
4289
|
-
|
|
4290
|
-
if (salt) parameter_block.set(salt, 32);
|
|
4291
|
-
if (personal) parameter_block.set(personal, 48);
|
|
4292
|
-
|
|
4293
|
-
// initialize hash state
|
|
4294
|
-
for (var i = 0; i < 16; i++) {
|
|
4295
|
-
this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
|
|
4296
|
-
}
|
|
4297
|
-
|
|
4298
|
-
// key the hash, if applicable
|
|
4299
|
-
if (key) {
|
|
4300
|
-
blake2bUpdate(this, key);
|
|
4301
|
-
// at the end
|
|
4302
|
-
this.c = 128;
|
|
4303
|
-
}
|
|
4304
|
-
}
|
|
4305
|
-
|
|
4306
|
-
Blake2b.prototype.update = function (input) {
|
|
4307
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4308
|
-
blake2bUpdate(this, input);
|
|
4309
|
-
return this
|
|
4310
|
-
};
|
|
4311
|
-
|
|
4312
|
-
Blake2b.prototype.digest = function (out) {
|
|
4313
|
-
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out;
|
|
4314
|
-
assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
|
|
4315
|
-
assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
|
|
4316
|
-
blake2bFinal(this, buf);
|
|
4317
|
-
if (out === 'hex') return hexSlice(buf)
|
|
4318
|
-
return buf
|
|
4319
|
-
};
|
|
4320
|
-
|
|
4321
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4322
|
-
|
|
4323
|
-
Blake2b.ready = function (cb) {
|
|
4324
|
-
b2wasm.ready(function () {
|
|
4325
|
-
cb(); // ignore the error
|
|
4326
|
-
});
|
|
4327
|
-
};
|
|
4328
|
-
|
|
4329
|
-
// Updates a BLAKE2b streaming hash
|
|
4330
|
-
// Requires hash context and Uint8Array (byte array)
|
|
4331
|
-
function blake2bUpdate (ctx, input) {
|
|
4332
|
-
for (var i = 0; i < input.length; i++) {
|
|
4333
|
-
if (ctx.c === 128) { // buffer full ?
|
|
4334
|
-
ctx.t += ctx.c; // add counters
|
|
4335
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
4336
|
-
ctx.c = 0; // counter to zero
|
|
4337
|
-
}
|
|
4338
|
-
ctx.b[ctx.c++] = input[i];
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
|
|
4342
|
-
// Completes a BLAKE2b streaming hash
|
|
4343
|
-
// Returns a Uint8Array containing the message digest
|
|
4344
|
-
function blake2bFinal (ctx, out) {
|
|
4345
|
-
ctx.t += ctx.c; // mark last block offset
|
|
4346
|
-
|
|
4347
|
-
while (ctx.c < 128) { // fill up with zeros
|
|
4348
|
-
ctx.b[ctx.c++] = 0;
|
|
4349
|
-
}
|
|
4350
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
4351
|
-
|
|
4352
|
-
for (var i = 0; i < ctx.outlen; i++) {
|
|
4353
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
4354
|
-
}
|
|
4355
|
-
return out
|
|
4356
|
-
}
|
|
4357
|
-
|
|
4358
|
-
function hexSlice (buf) {
|
|
4359
|
-
var str = '';
|
|
4360
|
-
for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
|
|
4361
|
-
return str
|
|
4362
|
-
}
|
|
4363
|
-
|
|
4364
|
-
function toHex (n) {
|
|
4365
|
-
if (n < 16) return '0' + n.toString(16)
|
|
4366
|
-
return n.toString(16)
|
|
4367
|
-
}
|
|
4368
|
-
|
|
4369
|
-
var Proto = Blake2b;
|
|
4370
|
-
|
|
4371
|
-
blake2b$3.exports = function createHash (outlen, key, salt, personal, noAssert) {
|
|
4372
|
-
if (noAssert !== true) {
|
|
4373
|
-
assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen);
|
|
4374
|
-
assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen);
|
|
4375
|
-
if (key != null) {
|
|
4376
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
4377
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
4378
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
4379
|
-
}
|
|
4380
|
-
if (salt != null) {
|
|
4381
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4382
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4383
|
-
}
|
|
4384
|
-
if (personal != null) {
|
|
4385
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4386
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4387
|
-
}
|
|
4388
|
-
}
|
|
4389
|
-
|
|
4390
|
-
return new Proto(outlen, key, salt, personal)
|
|
4391
|
-
};
|
|
4392
|
-
|
|
4393
|
-
blake2b$3.exports.ready = function (cb) {
|
|
4394
|
-
b2wasm.ready(function () { // ignore errors
|
|
4395
|
-
cb();
|
|
4396
|
-
});
|
|
4397
|
-
};
|
|
4398
|
-
|
|
4399
|
-
blake2b$3.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
|
|
4400
|
-
blake2b$3.exports.WASM_LOADED = false;
|
|
4401
|
-
|
|
4402
|
-
var BYTES_MIN = blake2b$3.exports.BYTES_MIN = 16;
|
|
4403
|
-
var BYTES_MAX = blake2b$3.exports.BYTES_MAX = 64;
|
|
4404
|
-
blake2b$3.exports.BYTES = 32;
|
|
4405
|
-
var KEYBYTES_MIN = blake2b$3.exports.KEYBYTES_MIN = 16;
|
|
4406
|
-
var KEYBYTES_MAX = blake2b$3.exports.KEYBYTES_MAX = 64;
|
|
4407
|
-
blake2b$3.exports.KEYBYTES = 32;
|
|
4408
|
-
var SALTBYTES = blake2b$3.exports.SALTBYTES = 16;
|
|
4409
|
-
var PERSONALBYTES = blake2b$3.exports.PERSONALBYTES = 16;
|
|
4410
|
-
|
|
4411
|
-
b2wasm.ready(function (err) {
|
|
4412
|
-
if (!err) {
|
|
4413
|
-
blake2b$3.exports.WASM_LOADED = true;
|
|
4414
|
-
blake2b$3.exports = b2wasm;
|
|
4415
|
-
}
|
|
4416
|
-
});
|
|
4417
|
-
return blake2b$3.exports;
|
|
3676
|
+
function deriveEd25519SecretKey(seed, blake2b) {
|
|
3677
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4418
3678
|
}
|
|
4419
|
-
|
|
4420
|
-
var blake2bExports = /*@__PURE__*/ requireBlake2b();
|
|
4421
|
-
var blake2b$1 = /*@__PURE__*/getDefaultExportFromCjs(blake2bExports);
|
|
4422
|
-
|
|
4423
3679
|
/**
|
|
4424
|
-
*
|
|
4425
|
-
*
|
|
4426
|
-
* If empty array is given a zero-hash is returned.
|
|
3680
|
+
* Derives a Bandersnatch secret key from a seed.
|
|
3681
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4427
3682
|
*/
|
|
4428
|
-
function
|
|
4429
|
-
|
|
4430
|
-
if (r.length === 0) {
|
|
4431
|
-
return out.asOpaque();
|
|
4432
|
-
}
|
|
4433
|
-
const hasher = blake2b$1(HASH_SIZE);
|
|
4434
|
-
for (const v of r) {
|
|
4435
|
-
hasher?.update(v instanceof BytesBlob ? v.raw : v);
|
|
4436
|
-
}
|
|
4437
|
-
hasher?.digest(out.raw);
|
|
4438
|
-
return out.asOpaque();
|
|
3683
|
+
function deriveBandersnatchSecretKey(seed, blake2b) {
|
|
3684
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4439
3685
|
}
|
|
4440
|
-
/**
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
const out = allocator.emptyHash();
|
|
4446
|
-
hasher?.digest(out.raw);
|
|
4447
|
-
return out;
|
|
3686
|
+
/**
|
|
3687
|
+
* Derive Ed25519 public key from secret seed
|
|
3688
|
+
*/
|
|
3689
|
+
async function deriveEd25519PublicKey(seed) {
|
|
3690
|
+
return (await privateKey(seed)).pubKey;
|
|
4448
3691
|
}
|
|
4449
|
-
/**
|
|
4450
|
-
|
|
4451
|
-
|
|
3692
|
+
/**
|
|
3693
|
+
* Derive Bandersnatch public key from secret seed
|
|
3694
|
+
*/
|
|
3695
|
+
function deriveBandersnatchPublicKey(seed) {
|
|
3696
|
+
return publicKey(seed.raw);
|
|
4452
3697
|
}
|
|
4453
3698
|
|
|
4454
|
-
var
|
|
3699
|
+
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
3700
|
+
__proto__: null,
|
|
3701
|
+
SEED_SIZE: SEED_SIZE,
|
|
3702
|
+
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
3703
|
+
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
3704
|
+
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
3705
|
+
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
3706
|
+
trivialSeed: trivialSeed
|
|
3707
|
+
});
|
|
3708
|
+
|
|
3709
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
4455
3710
|
__proto__: null,
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
3711
|
+
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
3712
|
+
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
3713
|
+
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
3714
|
+
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
3715
|
+
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
3716
|
+
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
3717
|
+
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
3718
|
+
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
3719
|
+
Ed25519Pair: Ed25519Pair,
|
|
3720
|
+
SEED_SIZE: SEED_SIZE,
|
|
3721
|
+
bandersnatch: bandersnatch,
|
|
3722
|
+
bandersnatchWasm: bandersnatch_exports,
|
|
3723
|
+
ed25519: ed25519,
|
|
3724
|
+
initWasm: initAll,
|
|
3725
|
+
keyDerivation: keyDerivation
|
|
4459
3726
|
});
|
|
4460
3727
|
|
|
4461
3728
|
/*!
|
|
@@ -4816,7 +4083,78 @@ function WASMInterface(binary, hashLength) {
|
|
|
4816
4083
|
|
|
4817
4084
|
new Mutex();
|
|
4818
4085
|
|
|
4086
|
+
var name$j = "blake2b";
|
|
4087
|
+
var data$j = "AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2hfR2V0U3RhdGUABw5IYXNoX0NhbGN1bGF0ZQAIClNUQVRFX1NJWkUDAQrTOAkFAEGACQvrAgIFfwF+AkAgAUEBSA0AAkACQAJAIAFBgAFBACgC4IoBIgJrIgNKDQAgASEEDAELQQBBADYC4IoBAkAgAkH/AEoNACACQeCJAWohBSAAIQRBACEGA0AgBSAELQAAOgAAIARBAWohBCAFQQFqIQUgAyAGQQFqIgZB/wFxSg0ACwtBAEEAKQPAiQEiB0KAAXw3A8CJAUEAQQApA8iJASAHQv9+Vq18NwPIiQFB4IkBEAIgACADaiEAAkAgASADayIEQYEBSA0AIAIgAWohBQNAQQBBACkDwIkBIgdCgAF8NwPAiQFBAEEAKQPIiQEgB0L/flatfDcDyIkBIAAQAiAAQYABaiEAIAVBgH9qIgVBgAJLDQALIAVBgH9qIQQMAQsgBEEATA0BC0EAIQUDQCAFQQAoAuCKAWpB4IkBaiAAIAVqLQAAOgAAIAQgBUEBaiIFQf8BcUoNAAsLQQBBACgC4IoBIARqNgLgigELC78uASR+QQBBACkD0IkBQQApA7CJASIBQQApA5CJAXwgAC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qQgA3AAAgAEH4igFqQgA3AAAgAEHwigFqQgA3AAAgAEEYaiIADQALQQAhAEEAQQApA/CKASIDQoiS853/zPmE6gCFNwOAiQFBAEEAKQP4igFCu86qptjQ67O7f4U3A4iJAUEAQQApA4CLAUKr8NP0r+68tzyFNwOQiQFBAEEAKQOIiwFC8e30+KWn/aelf4U3A5iJAUEAQQApA5CLAULRhZrv+s+Uh9EAhTcDoIkBQQBBACkDmIsBQp/Y+dnCkdqCm3+FNwOoiQFBAEEAKQOgiwFC6/qG2r+19sEfhTcDsIkBQQBBACkDqIsBQvnC+JuRo7Pw2wCFNwO4iQFBACADp0H/AXE2AuSKAQJAIAFBAUgNACACQgA3A3ggAkIANwNwIAJCADcDaCACQgA3A2AgAkIANwNYIAJCADcDUCACQgA3A0ggAkIANwNAIAJCADcDOCACQgA3AzAgAkIANwMoIAJCADcDICACQgA3AxggAkIANwMQIAJCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=";
|
|
4088
|
+
var hash$j = "c6f286e6";
|
|
4089
|
+
var wasmJson$j = {
|
|
4090
|
+
name: name$j,
|
|
4091
|
+
data: data$j,
|
|
4092
|
+
hash: hash$j
|
|
4093
|
+
};
|
|
4094
|
+
|
|
4819
4095
|
new Mutex();
|
|
4096
|
+
function validateBits$4(bits) {
|
|
4097
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
4098
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
4099
|
+
}
|
|
4100
|
+
return null;
|
|
4101
|
+
}
|
|
4102
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
4103
|
+
return outputBits | (keyBits << 16);
|
|
4104
|
+
}
|
|
4105
|
+
/**
|
|
4106
|
+
* Creates a new BLAKE2b hash instance
|
|
4107
|
+
* @param bits Number of output bits, which has to be a number
|
|
4108
|
+
* divisible by 8, between 8 and 512. Defaults to 512.
|
|
4109
|
+
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
|
|
4110
|
+
*/
|
|
4111
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
4112
|
+
if (validateBits$4(bits)) {
|
|
4113
|
+
return Promise.reject(validateBits$4(bits));
|
|
4114
|
+
}
|
|
4115
|
+
let keyBuffer = null;
|
|
4116
|
+
let initParam = bits;
|
|
4117
|
+
if (key !== null) {
|
|
4118
|
+
keyBuffer = getUInt8Buffer(key);
|
|
4119
|
+
if (keyBuffer.length > 64) {
|
|
4120
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
4121
|
+
}
|
|
4122
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
4123
|
+
}
|
|
4124
|
+
const outputSize = bits / 8;
|
|
4125
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
4126
|
+
if (initParam > 512) {
|
|
4127
|
+
wasm.writeMemory(keyBuffer);
|
|
4128
|
+
}
|
|
4129
|
+
wasm.init(initParam);
|
|
4130
|
+
const obj = {
|
|
4131
|
+
init: initParam > 512
|
|
4132
|
+
? () => {
|
|
4133
|
+
wasm.writeMemory(keyBuffer);
|
|
4134
|
+
wasm.init(initParam);
|
|
4135
|
+
return obj;
|
|
4136
|
+
}
|
|
4137
|
+
: () => {
|
|
4138
|
+
wasm.init(initParam);
|
|
4139
|
+
return obj;
|
|
4140
|
+
},
|
|
4141
|
+
update: (data) => {
|
|
4142
|
+
wasm.update(data);
|
|
4143
|
+
return obj;
|
|
4144
|
+
},
|
|
4145
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
4146
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
4147
|
+
save: () => wasm.save(),
|
|
4148
|
+
load: (data) => {
|
|
4149
|
+
wasm.load(data);
|
|
4150
|
+
return obj;
|
|
4151
|
+
},
|
|
4152
|
+
blockSize: 128,
|
|
4153
|
+
digestSize: outputSize,
|
|
4154
|
+
};
|
|
4155
|
+
return obj;
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4820
4158
|
|
|
4821
4159
|
new Mutex();
|
|
4822
4160
|
|
|
@@ -4906,6 +4244,79 @@ new Mutex();
|
|
|
4906
4244
|
|
|
4907
4245
|
new Mutex();
|
|
4908
4246
|
|
|
4247
|
+
/**
|
|
4248
|
+
* Size of the output of the hash functions.
|
|
4249
|
+
*
|
|
4250
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
4251
|
+
*
|
|
4252
|
+
*/
|
|
4253
|
+
const HASH_SIZE = 32;
|
|
4254
|
+
/** A hash without last byte (useful for trie representation). */
|
|
4255
|
+
const TRUNCATED_HASH_SIZE = 31;
|
|
4256
|
+
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
4257
|
+
/**
|
|
4258
|
+
* Container for some object with a hash that is related to this object.
|
|
4259
|
+
*
|
|
4260
|
+
* After calculating the hash these two should be passed together to avoid
|
|
4261
|
+
* unnecessary re-hashing of the data.
|
|
4262
|
+
*/
|
|
4263
|
+
class WithHash extends WithDebug {
|
|
4264
|
+
hash;
|
|
4265
|
+
data;
|
|
4266
|
+
constructor(hash, data) {
|
|
4267
|
+
super();
|
|
4268
|
+
this.hash = hash;
|
|
4269
|
+
this.data = data;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
/**
|
|
4273
|
+
* Extension of [`WithHash`] additionally containing an encoded version of the object.
|
|
4274
|
+
*/
|
|
4275
|
+
class WithHashAndBytes extends WithHash {
|
|
4276
|
+
encoded;
|
|
4277
|
+
constructor(hash, data, encoded) {
|
|
4278
|
+
super(hash, data);
|
|
4279
|
+
this.encoded = encoded;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
|
|
4283
|
+
const zero$1 = Bytes.zero(HASH_SIZE);
|
|
4284
|
+
class Blake2b {
|
|
4285
|
+
hasher;
|
|
4286
|
+
static async createHasher() {
|
|
4287
|
+
return new Blake2b(await createBLAKE2b(HASH_SIZE * 8));
|
|
4288
|
+
}
|
|
4289
|
+
constructor(hasher) {
|
|
4290
|
+
this.hasher = hasher;
|
|
4291
|
+
}
|
|
4292
|
+
/**
|
|
4293
|
+
* Hash given collection of blobs.
|
|
4294
|
+
*
|
|
4295
|
+
* If empty array is given a zero-hash is returned.
|
|
4296
|
+
*/
|
|
4297
|
+
hashBlobs(r) {
|
|
4298
|
+
if (r.length === 0) {
|
|
4299
|
+
return zero$1.asOpaque();
|
|
4300
|
+
}
|
|
4301
|
+
const hasher = this.hasher.init();
|
|
4302
|
+
for (const v of r) {
|
|
4303
|
+
hasher.update(v instanceof BytesBlob ? v.raw : v);
|
|
4304
|
+
}
|
|
4305
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4306
|
+
}
|
|
4307
|
+
/** Hash given blob of bytes. */
|
|
4308
|
+
hashBytes(blob) {
|
|
4309
|
+
const hasher = this.hasher.init();
|
|
4310
|
+
const bytes = blob instanceof BytesBlob ? blob.raw : blob;
|
|
4311
|
+
hasher.update(bytes);
|
|
4312
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4313
|
+
}
|
|
4314
|
+
/** Convert given string into bytes and hash it. */
|
|
4315
|
+
hashString(str) {
|
|
4316
|
+
return this.hashBytes(BytesBlob.blobFromString(str));
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4909
4320
|
class KeccakHasher {
|
|
4910
4321
|
hasher;
|
|
4911
4322
|
static async create() {
|
|
@@ -4930,91 +4341,61 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4930
4341
|
hashBlobs: hashBlobs
|
|
4931
4342
|
});
|
|
4932
4343
|
|
|
4933
|
-
|
|
4344
|
+
// TODO [ToDr] (#213) this should most likely be moved to a separate
|
|
4345
|
+
// package to avoid pulling in unnecessary deps.
|
|
4346
|
+
|
|
4347
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4934
4348
|
__proto__: null,
|
|
4349
|
+
Blake2b: Blake2b,
|
|
4935
4350
|
HASH_SIZE: HASH_SIZE,
|
|
4936
|
-
PageAllocator: PageAllocator,
|
|
4937
|
-
SimpleAllocator: SimpleAllocator,
|
|
4938
4351
|
TRUNCATED_HASH_SIZE: TRUNCATED_HASH_SIZE,
|
|
4939
4352
|
WithHash: WithHash,
|
|
4940
4353
|
WithHashAndBytes: WithHashAndBytes,
|
|
4941
4354
|
ZERO_HASH: ZERO_HASH,
|
|
4942
|
-
blake2b: blake2b,
|
|
4943
|
-
defaultAllocator: defaultAllocator,
|
|
4944
4355
|
keccak: keccak
|
|
4945
4356
|
});
|
|
4946
4357
|
|
|
4947
|
-
const SEED_SIZE = 32;
|
|
4948
|
-
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
4949
|
-
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
4950
|
-
/**
|
|
4951
|
-
* JIP-5: Secret key derivation
|
|
4952
|
-
*
|
|
4953
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
4954
|
-
/**
|
|
4955
|
-
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
4956
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
4957
|
-
*/
|
|
4958
|
-
function trivialSeed(s) {
|
|
4959
|
-
const s_le = u32AsLeBytes(s);
|
|
4960
|
-
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();
|
|
4961
|
-
}
|
|
4962
|
-
/**
|
|
4963
|
-
* Derives a Ed25519 secret key from a seed.
|
|
4964
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4965
|
-
*/
|
|
4966
|
-
function deriveEd25519SecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4967
|
-
return hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4968
|
-
}
|
|
4969
|
-
/**
|
|
4970
|
-
* Derives a Bandersnatch secret key from a seed.
|
|
4971
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4972
|
-
*/
|
|
4973
|
-
function deriveBandersnatchSecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4974
|
-
return hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4975
|
-
}
|
|
4976
|
-
/**
|
|
4977
|
-
* Derive Ed25519 public key from secret seed
|
|
4978
|
-
*/
|
|
4979
|
-
async function deriveEd25519PublicKey(seed) {
|
|
4980
|
-
return (await privateKey(seed)).pubKey;
|
|
4981
|
-
}
|
|
4982
4358
|
/**
|
|
4983
|
-
*
|
|
4359
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
4984
4360
|
*/
|
|
4985
|
-
|
|
4986
|
-
|
|
4361
|
+
class ArrayView {
|
|
4362
|
+
start;
|
|
4363
|
+
end;
|
|
4364
|
+
source;
|
|
4365
|
+
length;
|
|
4366
|
+
constructor(source, start, end) {
|
|
4367
|
+
this.start = start;
|
|
4368
|
+
this.end = end;
|
|
4369
|
+
this.source = source;
|
|
4370
|
+
this.length = end - start;
|
|
4371
|
+
}
|
|
4372
|
+
static from(source, start = 0, end = source.length) {
|
|
4373
|
+
check `
|
|
4374
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
4375
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
4376
|
+
`;
|
|
4377
|
+
return new ArrayView(source, start, end);
|
|
4378
|
+
}
|
|
4379
|
+
get(i) {
|
|
4380
|
+
check `
|
|
4381
|
+
${i >= 0 && i < this.length}
|
|
4382
|
+
Index out of bounds: ${i} < ${this.length}
|
|
4383
|
+
`;
|
|
4384
|
+
return this.source[this.start + i];
|
|
4385
|
+
}
|
|
4386
|
+
subview(from, to = this.length) {
|
|
4387
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
4388
|
+
}
|
|
4389
|
+
toArray() {
|
|
4390
|
+
return this.source.slice(this.start, this.end);
|
|
4391
|
+
}
|
|
4392
|
+
*[Symbol.iterator]() {
|
|
4393
|
+
for (let i = this.start; i < this.end; i++) {
|
|
4394
|
+
yield this.source[i];
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4987
4397
|
}
|
|
4988
4398
|
|
|
4989
|
-
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
4990
|
-
__proto__: null,
|
|
4991
|
-
SEED_SIZE: SEED_SIZE,
|
|
4992
|
-
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
4993
|
-
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
4994
|
-
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
4995
|
-
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
4996
|
-
trivialSeed: trivialSeed
|
|
4997
|
-
});
|
|
4998
|
-
|
|
4999
|
-
var index$o = /*#__PURE__*/Object.freeze({
|
|
5000
|
-
__proto__: null,
|
|
5001
|
-
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
5002
|
-
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
5003
|
-
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
5004
|
-
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
5005
|
-
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
5006
|
-
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
5007
|
-
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
5008
|
-
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
5009
|
-
Ed25519Pair: Ed25519Pair,
|
|
5010
|
-
SEED_SIZE: SEED_SIZE,
|
|
5011
|
-
bandersnatch: bandersnatch,
|
|
5012
|
-
bandersnatchWasm: bandersnatch_exports,
|
|
5013
|
-
ed25519: ed25519,
|
|
5014
|
-
initWasm: initAll,
|
|
5015
|
-
keyDerivation: keyDerivation
|
|
5016
|
-
});
|
|
5017
|
-
|
|
5018
4399
|
/** A map which uses hashes as keys. */
|
|
5019
4400
|
class HashDictionary {
|
|
5020
4401
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
@@ -5602,6 +4983,7 @@ class TruncatedHashDictionary {
|
|
|
5602
4983
|
|
|
5603
4984
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
5604
4985
|
__proto__: null,
|
|
4986
|
+
ArrayView: ArrayView,
|
|
5605
4987
|
FixedSizeArray: FixedSizeArray,
|
|
5606
4988
|
HashDictionary: HashDictionary,
|
|
5607
4989
|
HashSet: HashSet,
|
|
@@ -8563,43 +7945,43 @@ var stateKeys;
|
|
|
8563
7945
|
}
|
|
8564
7946
|
stateKeys.serviceInfo = serviceInfo;
|
|
8565
7947
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bba033bba03?v=0.7.1 */
|
|
8566
|
-
function serviceStorage(serviceId, key) {
|
|
7948
|
+
function serviceStorage(blake2b, serviceId, key) {
|
|
8567
7949
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8568
7950
|
const out = Bytes.zero(HASH_SIZE);
|
|
8569
7951
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 1)), 0);
|
|
8570
7952
|
out.raw.set(key.raw.subarray(0, HASH_SIZE - U32_BYTES), U32_BYTES);
|
|
8571
7953
|
return legacyServiceNested(serviceId, out);
|
|
8572
7954
|
}
|
|
8573
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
7955
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
8574
7956
|
}
|
|
8575
7957
|
stateKeys.serviceStorage = serviceStorage;
|
|
8576
7958
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bd7033bd703?v=0.7.1 */
|
|
8577
|
-
function servicePreimage(serviceId, hash) {
|
|
7959
|
+
function servicePreimage(blake2b, serviceId, hash) {
|
|
8578
7960
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8579
7961
|
const out = Bytes.zero(HASH_SIZE);
|
|
8580
7962
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 2)), 0);
|
|
8581
7963
|
out.raw.set(hash.raw.subarray(1, HASH_SIZE - U32_BYTES + 1), U32_BYTES);
|
|
8582
7964
|
return legacyServiceNested(serviceId, out);
|
|
8583
7965
|
}
|
|
8584
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
7966
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
8585
7967
|
}
|
|
8586
7968
|
stateKeys.servicePreimage = servicePreimage;
|
|
8587
7969
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b0a043b0a04?v=0.7.1 */
|
|
8588
|
-
function serviceLookupHistory(serviceId, hash, preimageLength) {
|
|
7970
|
+
function serviceLookupHistory(blake2b, serviceId, hash, preimageLength) {
|
|
8589
7971
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8590
|
-
const doubleHash = hashBytes(hash);
|
|
7972
|
+
const doubleHash = blake2b.hashBytes(hash);
|
|
8591
7973
|
const out = Bytes.zero(HASH_SIZE);
|
|
8592
7974
|
out.raw.set(u32AsLeBytes(preimageLength), 0);
|
|
8593
7975
|
out.raw.set(doubleHash.raw.subarray(2, HASH_SIZE - U32_BYTES + 2), U32_BYTES);
|
|
8594
7976
|
return legacyServiceNested(serviceId, out);
|
|
8595
7977
|
}
|
|
8596
|
-
return serviceNested(serviceId, preimageLength, hash);
|
|
7978
|
+
return serviceNested(blake2b, serviceId, preimageLength, hash);
|
|
8597
7979
|
}
|
|
8598
7980
|
stateKeys.serviceLookupHistory = serviceLookupHistory;
|
|
8599
7981
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b88003b8800?v=0.7.1 */
|
|
8600
|
-
function serviceNested(serviceId, numberPrefix, hash) {
|
|
7982
|
+
function serviceNested(blake2b, serviceId, numberPrefix, hash) {
|
|
8601
7983
|
const inputToHash = BytesBlob.blobFromParts(u32AsLeBytes(numberPrefix), hash.raw);
|
|
8602
|
-
const newHash = hashBytes(inputToHash).raw.subarray(0, 28);
|
|
7984
|
+
const newHash = blake2b.hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8603
7985
|
const key = Bytes.zero(HASH_SIZE);
|
|
8604
7986
|
let i = 0;
|
|
8605
7987
|
for (const byte of u32AsLeBytes(serviceId)) {
|
|
@@ -8660,12 +8042,6 @@ function accumulationOutputComparator(a, b) {
|
|
|
8660
8042
|
return Ordering.Equal;
|
|
8661
8043
|
}
|
|
8662
8044
|
|
|
8663
|
-
const codecWithHash = (val) => Descriptor.withView(val.name, val.sizeHint, (e, elem) => val.encode(e, elem.data), (d) => {
|
|
8664
|
-
const decoder2 = d.clone();
|
|
8665
|
-
const encoded = val.skipEncoded(decoder2);
|
|
8666
|
-
const hash = hashBytes(encoded);
|
|
8667
|
-
return new WithHash(hash.asOpaque(), val.decode(d));
|
|
8668
|
-
}, val.skip, val.View);
|
|
8669
8045
|
/**
|
|
8670
8046
|
* Assignment of particular work report to a core.
|
|
8671
8047
|
*
|
|
@@ -8678,7 +8054,7 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8678
8054
|
workReport;
|
|
8679
8055
|
timeout;
|
|
8680
8056
|
static Codec = codec$1.Class(AvailabilityAssignment, {
|
|
8681
|
-
workReport:
|
|
8057
|
+
workReport: WorkReport.Codec,
|
|
8682
8058
|
timeout: codec$1.u32.asOpaque(),
|
|
8683
8059
|
});
|
|
8684
8060
|
static create({ workReport, timeout }) {
|
|
@@ -10298,18 +9674,18 @@ var serialize;
|
|
|
10298
9674
|
Codec: ServiceAccountInfo.Codec,
|
|
10299
9675
|
});
|
|
10300
9676
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
10301
|
-
serialize.serviceStorage = (serviceId, key) => ({
|
|
10302
|
-
key: stateKeys.serviceStorage(serviceId, key),
|
|
9677
|
+
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
9678
|
+
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
10303
9679
|
Codec: dumpCodec,
|
|
10304
9680
|
});
|
|
10305
9681
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
10306
|
-
serialize.servicePreimages = (serviceId, hash) => ({
|
|
10307
|
-
key: stateKeys.servicePreimage(serviceId, hash),
|
|
9682
|
+
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
9683
|
+
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
10308
9684
|
Codec: dumpCodec,
|
|
10309
9685
|
});
|
|
10310
9686
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10311
|
-
serialize.serviceLookupHistory = (serviceId, hash, len) => ({
|
|
10312
|
-
key: stateKeys.serviceLookupHistory(serviceId, hash, len),
|
|
9687
|
+
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
9688
|
+
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10313
9689
|
Codec: readonlyArray(codec$1.sequenceVarLen(codec$1.u32)),
|
|
10314
9690
|
});
|
|
10315
9691
|
})(serialize || (serialize = {}));
|
|
@@ -10332,20 +9708,22 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10332
9708
|
*/
|
|
10333
9709
|
class SerializedState {
|
|
10334
9710
|
spec;
|
|
9711
|
+
blake2b;
|
|
10335
9712
|
backend;
|
|
10336
9713
|
_recentServiceIds;
|
|
10337
9714
|
/** Create a state-like object from collection of serialized entries. */
|
|
10338
|
-
static fromStateEntries(spec, state, recentServices = []) {
|
|
10339
|
-
return new SerializedState(spec, state, recentServices);
|
|
9715
|
+
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9716
|
+
return new SerializedState(spec, blake2b, state, recentServices);
|
|
10340
9717
|
}
|
|
10341
9718
|
/** Create a state-like object backed by some DB. */
|
|
10342
|
-
static new(spec, db, recentServices = []) {
|
|
10343
|
-
return new SerializedState(spec, db, recentServices);
|
|
9719
|
+
static new(spec, blake2b, db, recentServices = []) {
|
|
9720
|
+
return new SerializedState(spec, blake2b, db, recentServices);
|
|
10344
9721
|
}
|
|
10345
|
-
constructor(spec, backend,
|
|
9722
|
+
constructor(spec, blake2b, backend,
|
|
10346
9723
|
/** Best-effort list of recently active services. */
|
|
10347
9724
|
_recentServiceIds) {
|
|
10348
9725
|
this.spec = spec;
|
|
9726
|
+
this.blake2b = blake2b;
|
|
10349
9727
|
this.backend = backend;
|
|
10350
9728
|
this._recentServiceIds = _recentServiceIds;
|
|
10351
9729
|
}
|
|
@@ -10369,7 +9747,7 @@ class SerializedState {
|
|
|
10369
9747
|
if (!this._recentServiceIds.includes(id)) {
|
|
10370
9748
|
this._recentServiceIds.push(id);
|
|
10371
9749
|
}
|
|
10372
|
-
return new SerializedService(id, serviceData, (key) => this.retrieveOptional(key));
|
|
9750
|
+
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10373
9751
|
}
|
|
10374
9752
|
retrieve({ key, Codec }, description) {
|
|
10375
9753
|
const bytes = this.backend.get(key);
|
|
@@ -10445,12 +9823,14 @@ class SerializedState {
|
|
|
10445
9823
|
}
|
|
10446
9824
|
/** Service data representation on a serialized state. */
|
|
10447
9825
|
class SerializedService {
|
|
9826
|
+
blake2b;
|
|
10448
9827
|
serviceId;
|
|
10449
9828
|
accountInfo;
|
|
10450
9829
|
retrieveOptional;
|
|
10451
|
-
constructor(
|
|
9830
|
+
constructor(blake2b,
|
|
10452
9831
|
/** Service id */
|
|
10453
9832
|
serviceId, accountInfo, retrieveOptional) {
|
|
9833
|
+
this.blake2b = blake2b;
|
|
10454
9834
|
this.serviceId = serviceId;
|
|
10455
9835
|
this.accountInfo = accountInfo;
|
|
10456
9836
|
this.retrieveOptional = retrieveOptional;
|
|
@@ -10463,13 +9843,13 @@ class SerializedService {
|
|
|
10463
9843
|
getStorage(rawKey) {
|
|
10464
9844
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
10465
9845
|
const SERVICE_ID_BYTES = 4;
|
|
10466
|
-
const serviceIdAndKey =
|
|
9846
|
+
const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
10467
9847
|
serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
|
|
10468
9848
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10469
|
-
const key = asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
10470
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, key)) ?? null;
|
|
9849
|
+
const key = asOpaqueType(BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
9850
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10471
9851
|
}
|
|
10472
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, rawKey)) ?? null;
|
|
9852
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10473
9853
|
}
|
|
10474
9854
|
/**
|
|
10475
9855
|
* Check if preimage is present in the DB.
|
|
@@ -10478,15 +9858,15 @@ class SerializedService {
|
|
|
10478
9858
|
*/
|
|
10479
9859
|
hasPreimage(hash) {
|
|
10480
9860
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10481
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) !== undefined;
|
|
9861
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10482
9862
|
}
|
|
10483
9863
|
/** Retrieve preimage from the DB. */
|
|
10484
9864
|
getPreimage(hash) {
|
|
10485
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) ?? null;
|
|
9865
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10486
9866
|
}
|
|
10487
9867
|
/** Retrieve preimage lookup history. */
|
|
10488
9868
|
getLookupHistory(hash, len) {
|
|
10489
|
-
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.serviceId, hash, len));
|
|
9869
|
+
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
10490
9870
|
if (rawSlots === undefined) {
|
|
10491
9871
|
return null;
|
|
10492
9872
|
}
|
|
@@ -10548,7 +9928,7 @@ class TrieNode {
|
|
|
10548
9928
|
raw;
|
|
10549
9929
|
constructor(
|
|
10550
9930
|
/** Exactly 512 bits / 64 bytes */
|
|
10551
|
-
raw =
|
|
9931
|
+
raw = safeAllocUint8Array(TRIE_NODE_BYTES)) {
|
|
10552
9932
|
this.raw = raw;
|
|
10553
9933
|
}
|
|
10554
9934
|
/** Returns the type of the node */
|
|
@@ -11123,11 +10503,13 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
11123
10503
|
parseInputKey: parseInputKey
|
|
11124
10504
|
});
|
|
11125
10505
|
|
|
11126
|
-
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
}
|
|
10506
|
+
function getBlake2bTrieHasher(hasher) {
|
|
10507
|
+
return {
|
|
10508
|
+
hashConcat(n, rest = []) {
|
|
10509
|
+
return hasher.hashBlobs([n, ...rest]);
|
|
10510
|
+
},
|
|
10511
|
+
};
|
|
10512
|
+
}
|
|
11131
10513
|
|
|
11132
10514
|
/** What should be done with that key? */
|
|
11133
10515
|
var StateEntryUpdateAction;
|
|
@@ -11139,14 +10521,14 @@ var StateEntryUpdateAction;
|
|
|
11139
10521
|
})(StateEntryUpdateAction || (StateEntryUpdateAction = {}));
|
|
11140
10522
|
const EMPTY_BLOB = BytesBlob.empty();
|
|
11141
10523
|
/** Serialize given state update into a series of key-value pairs. */
|
|
11142
|
-
function* serializeStateUpdate(spec, update) {
|
|
10524
|
+
function* serializeStateUpdate(spec, blake2b, update) {
|
|
11143
10525
|
// first let's serialize all of the simple entries (if present!)
|
|
11144
10526
|
yield* serializeBasicKeys(spec, update);
|
|
11145
10527
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
11146
10528
|
// then let's proceed with service updates
|
|
11147
|
-
yield* serializeServiceUpdates(update.servicesUpdates, encode);
|
|
11148
|
-
yield* serializePreimages(update.preimages, encode);
|
|
11149
|
-
yield* serializeStorage(update.storage);
|
|
10529
|
+
yield* serializeServiceUpdates(update.servicesUpdates, encode, blake2b);
|
|
10530
|
+
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
10531
|
+
yield* serializeStorage(update.storage, blake2b);
|
|
11150
10532
|
yield* serializeRemovedServices(update.servicesRemoved);
|
|
11151
10533
|
}
|
|
11152
10534
|
function* serializeRemovedServices(servicesRemoved) {
|
|
@@ -11156,18 +10538,18 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
11156
10538
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11157
10539
|
}
|
|
11158
10540
|
}
|
|
11159
|
-
function* serializeStorage(storage) {
|
|
10541
|
+
function* serializeStorage(storage, blake2b) {
|
|
11160
10542
|
for (const { action, serviceId } of storage ?? []) {
|
|
11161
10543
|
switch (action.kind) {
|
|
11162
10544
|
case UpdateStorageKind.Set: {
|
|
11163
10545
|
const key = action.storage.key;
|
|
11164
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10546
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11165
10547
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11166
10548
|
break;
|
|
11167
10549
|
}
|
|
11168
10550
|
case UpdateStorageKind.Remove: {
|
|
11169
10551
|
const key = action.key;
|
|
11170
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10552
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11171
10553
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11172
10554
|
break;
|
|
11173
10555
|
}
|
|
@@ -11176,15 +10558,15 @@ function* serializeStorage(storage) {
|
|
|
11176
10558
|
}
|
|
11177
10559
|
}
|
|
11178
10560
|
}
|
|
11179
|
-
function* serializePreimages(preimages, encode) {
|
|
10561
|
+
function* serializePreimages(preimages, encode, blake2b) {
|
|
11180
10562
|
for (const { action, serviceId } of preimages ?? []) {
|
|
11181
10563
|
switch (action.kind) {
|
|
11182
10564
|
case UpdatePreimageKind.Provide: {
|
|
11183
10565
|
const { hash, blob } = action.preimage;
|
|
11184
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10566
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11185
10567
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11186
10568
|
if (action.slot !== null) {
|
|
11187
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, tryAsU32(blob.length));
|
|
10569
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
11188
10570
|
yield [
|
|
11189
10571
|
StateEntryUpdateAction.Insert,
|
|
11190
10572
|
codec2.key,
|
|
@@ -11195,15 +10577,15 @@ function* serializePreimages(preimages, encode) {
|
|
|
11195
10577
|
}
|
|
11196
10578
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11197
10579
|
const { hash, length, slots } = action.item;
|
|
11198
|
-
const codec = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10580
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11199
10581
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11200
10582
|
break;
|
|
11201
10583
|
}
|
|
11202
10584
|
case UpdatePreimageKind.Remove: {
|
|
11203
10585
|
const { hash, length } = action;
|
|
11204
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10586
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11205
10587
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11206
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10588
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11207
10589
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11208
10590
|
break;
|
|
11209
10591
|
}
|
|
@@ -11212,7 +10594,7 @@ function* serializePreimages(preimages, encode) {
|
|
|
11212
10594
|
}
|
|
11213
10595
|
}
|
|
11214
10596
|
}
|
|
11215
|
-
function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
10597
|
+
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11216
10598
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
11217
10599
|
// new service being created or updated
|
|
11218
10600
|
const codec = serialize.serviceData(serviceId);
|
|
@@ -11220,7 +10602,7 @@ function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
|
11220
10602
|
// additional lookup history update
|
|
11221
10603
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11222
10604
|
const { lookupHistory } = action;
|
|
11223
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10605
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11224
10606
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11225
10607
|
}
|
|
11226
10608
|
}
|
|
@@ -11315,8 +10697,8 @@ class StateEntries {
|
|
|
11315
10697
|
},
|
|
11316
10698
|
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11317
10699
|
/** Turn in-memory state into it's serialized form. */
|
|
11318
|
-
static serializeInMemory(spec, state) {
|
|
11319
|
-
return new StateEntries(convertInMemoryStateToDictionary(spec, state));
|
|
10700
|
+
static serializeInMemory(spec, blake2b, state) {
|
|
10701
|
+
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
11320
10702
|
}
|
|
11321
10703
|
/**
|
|
11322
10704
|
* Wrap a collection of truncated state entries and treat it as state.
|
|
@@ -11365,7 +10747,8 @@ class StateEntries {
|
|
|
11365
10747
|
}
|
|
11366
10748
|
}
|
|
11367
10749
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/391600391600?v=0.6.4 */
|
|
11368
|
-
getRootHash() {
|
|
10750
|
+
getRootHash(blake2b) {
|
|
10751
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11369
10752
|
const leaves = SortedSet.fromArray(leafComparator);
|
|
11370
10753
|
for (const [key, value] of this) {
|
|
11371
10754
|
leaves.insert(InMemoryTrie.constructLeaf(blake2bTrieHasher, key.asOpaque(), value));
|
|
@@ -11374,7 +10757,7 @@ class StateEntries {
|
|
|
11374
10757
|
}
|
|
11375
10758
|
}
|
|
11376
10759
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/38a50038a500?v=0.6.4 */
|
|
11377
|
-
function convertInMemoryStateToDictionary(spec, state) {
|
|
10760
|
+
function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
11378
10761
|
const serialized = TruncatedHashDictionary.fromEntries([]);
|
|
11379
10762
|
function doSerialize(codec) {
|
|
11380
10763
|
serialized.set(codec.key, Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
@@ -11402,18 +10785,18 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11402
10785
|
serialized.set(key, Encoder.encodeObject(Codec, service.getInfo()));
|
|
11403
10786
|
// preimages
|
|
11404
10787
|
for (const preimage of service.data.preimages.values()) {
|
|
11405
|
-
const { key, Codec } = serialize.servicePreimages(serviceId, preimage.hash);
|
|
10788
|
+
const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11406
10789
|
serialized.set(key, Encoder.encodeObject(Codec, preimage.blob));
|
|
11407
10790
|
}
|
|
11408
10791
|
// storage
|
|
11409
10792
|
for (const storage of service.data.storage.values()) {
|
|
11410
|
-
const { key, Codec } = serialize.serviceStorage(serviceId, storage.key);
|
|
10793
|
+
const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11411
10794
|
serialized.set(key, Encoder.encodeObject(Codec, storage.value));
|
|
11412
10795
|
}
|
|
11413
10796
|
// lookup history
|
|
11414
10797
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11415
10798
|
for (const lookupHistory of lookupHistoryList) {
|
|
11416
|
-
const { key, Codec } = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10799
|
+
const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11417
10800
|
serialized.set(key, Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11418
10801
|
}
|
|
11419
10802
|
}
|
|
@@ -11421,9 +10804,9 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11421
10804
|
return serialized;
|
|
11422
10805
|
}
|
|
11423
10806
|
|
|
11424
|
-
function loadState(spec, entries) {
|
|
10807
|
+
function loadState(spec, blake2b, entries) {
|
|
11425
10808
|
const stateEntries = StateEntries.fromEntriesUnsafe(entries);
|
|
11426
|
-
return SerializedState.fromStateEntries(spec, stateEntries);
|
|
10809
|
+
return SerializedState.fromStateEntries(spec, blake2b, stateEntries);
|
|
11427
10810
|
}
|
|
11428
10811
|
|
|
11429
10812
|
/**
|
|
@@ -11531,7 +10914,8 @@ class LeafDb {
|
|
|
11531
10914
|
}
|
|
11532
10915
|
assertNever(val);
|
|
11533
10916
|
}
|
|
11534
|
-
getStateRoot() {
|
|
10917
|
+
getStateRoot(blake2b) {
|
|
10918
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11535
10919
|
return InMemoryTrie.computeStateRoot(blake2bTrieHasher, this.leaves).asOpaque();
|
|
11536
10920
|
}
|
|
11537
10921
|
intoStateEntries() {
|
|
@@ -11721,7 +11105,8 @@ class InMemoryStates {
|
|
|
11721
11105
|
}
|
|
11722
11106
|
}
|
|
11723
11107
|
async getStateRoot(state) {
|
|
11724
|
-
|
|
11108
|
+
const blake2b = await Blake2b.createHasher();
|
|
11109
|
+
return StateEntries.serializeInMemory(this.spec, blake2b, state).getRootHash(blake2b);
|
|
11725
11110
|
}
|
|
11726
11111
|
/** Insert a full state into the database. */
|
|
11727
11112
|
async insertState(headerHash, state) {
|
|
@@ -11799,7 +11184,7 @@ function padAndEncodeData(input) {
|
|
|
11799
11184
|
const paddedLength = Math.ceil(input.length / PIECE_SIZE) * PIECE_SIZE;
|
|
11800
11185
|
let padded = input;
|
|
11801
11186
|
if (input.length !== paddedLength) {
|
|
11802
|
-
padded = BytesBlob.blobFrom(
|
|
11187
|
+
padded = BytesBlob.blobFrom(safeAllocUint8Array(paddedLength));
|
|
11803
11188
|
padded.raw.set(input.raw, 0);
|
|
11804
11189
|
}
|
|
11805
11190
|
return chunkingFunction(padded);
|
|
@@ -11845,7 +11230,7 @@ function decodeData(input) {
|
|
|
11845
11230
|
*/
|
|
11846
11231
|
function encodePoints(input) {
|
|
11847
11232
|
const result = [];
|
|
11848
|
-
const data =
|
|
11233
|
+
const data = safeAllocUint8Array(POINT_ALIGNMENT * N_CHUNKS_REQUIRED);
|
|
11849
11234
|
// add original shards to the result
|
|
11850
11235
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11851
11236
|
const pointStart = POINT_LENGTH * i;
|
|
@@ -11861,7 +11246,7 @@ function encodePoints(input) {
|
|
|
11861
11246
|
const encodedData = encodedResult.take_data();
|
|
11862
11247
|
for (let i = 0; i < N_CHUNKS_REDUNDANCY; i++) {
|
|
11863
11248
|
const pointIndex = i * POINT_ALIGNMENT;
|
|
11864
|
-
const redundancyPoint =
|
|
11249
|
+
const redundancyPoint = safeAllocUint8Array(POINT_LENGTH);
|
|
11865
11250
|
for (let j = 0; j < POINT_LENGTH; j++) {
|
|
11866
11251
|
redundancyPoint[j] = encodedData[pointIndex + j * HALF_POINT_SIZE];
|
|
11867
11252
|
}
|
|
@@ -11876,7 +11261,7 @@ function encodePoints(input) {
|
|
|
11876
11261
|
*/
|
|
11877
11262
|
function decodePiece(input) {
|
|
11878
11263
|
const result = Bytes.zero(PIECE_SIZE);
|
|
11879
|
-
const data =
|
|
11264
|
+
const data = safeAllocUint8Array(N_CHUNKS_REQUIRED * POINT_ALIGNMENT);
|
|
11880
11265
|
const indices = new Uint16Array(input.length);
|
|
11881
11266
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11882
11267
|
const [index, points] = input[i];
|
|
@@ -11992,7 +11377,7 @@ function lace(input) {
|
|
|
11992
11377
|
return BytesBlob.empty();
|
|
11993
11378
|
}
|
|
11994
11379
|
const n = input[0].length;
|
|
11995
|
-
const result = BytesBlob.blobFrom(
|
|
11380
|
+
const result = BytesBlob.blobFrom(safeAllocUint8Array(k * n));
|
|
11996
11381
|
for (let i = 0; i < k; i++) {
|
|
11997
11382
|
const entry = input[i].raw;
|
|
11998
11383
|
for (let j = 0; j < n; j++) {
|
|
@@ -13271,7 +12656,7 @@ class Registers {
|
|
|
13271
12656
|
bytes;
|
|
13272
12657
|
asSigned;
|
|
13273
12658
|
asUnsigned;
|
|
13274
|
-
constructor(bytes =
|
|
12659
|
+
constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT)) {
|
|
13275
12660
|
this.bytes = bytes;
|
|
13276
12661
|
check `${bytes.length === NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
13277
12662
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
@@ -13424,7 +12809,7 @@ class Mask {
|
|
|
13424
12809
|
return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
|
|
13425
12810
|
}
|
|
13426
12811
|
buildLookupTableForward(mask) {
|
|
13427
|
-
const table =
|
|
12812
|
+
const table = safeAllocUint8Array(mask.bitLength);
|
|
13428
12813
|
let lastInstructionOffset = 0;
|
|
13429
12814
|
for (let i = mask.bitLength - 1; i >= 0; i--) {
|
|
13430
12815
|
if (mask.isSet(i)) {
|
|
@@ -16959,7 +16344,7 @@ class HostCalls {
|
|
|
16959
16344
|
const regs = pvmInstance.getRegisters();
|
|
16960
16345
|
const maybeAddress = regs.getLowerU32(7);
|
|
16961
16346
|
const maybeLength = regs.getLowerU32(8);
|
|
16962
|
-
const result =
|
|
16347
|
+
const result = safeAllocUint8Array(maybeLength);
|
|
16963
16348
|
const startAddress = tryAsMemoryIndex(maybeAddress);
|
|
16964
16349
|
const loadResult = memory.loadInto(result, startAddress);
|
|
16965
16350
|
if (loadResult.isError) {
|
|
@@ -17308,14 +16693,14 @@ class DebuggerAdapter {
|
|
|
17308
16693
|
const page = this.pvm.getMemoryPage(pageNumber);
|
|
17309
16694
|
if (page === null) {
|
|
17310
16695
|
// page wasn't allocated so we return an empty page
|
|
17311
|
-
return
|
|
16696
|
+
return safeAllocUint8Array(PAGE_SIZE$1);
|
|
17312
16697
|
}
|
|
17313
16698
|
if (page.length === PAGE_SIZE$1) {
|
|
17314
16699
|
// page was allocated and has a proper size so we can simply return it
|
|
17315
16700
|
return page;
|
|
17316
16701
|
}
|
|
17317
16702
|
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
17318
|
-
const fullPage =
|
|
16703
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
|
|
17319
16704
|
fullPage.set(page);
|
|
17320
16705
|
return fullPage;
|
|
17321
16706
|
}
|
|
@@ -17419,7 +16804,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
17419
16804
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
17420
16805
|
getServiceId: getServiceId,
|
|
17421
16806
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
17422
|
-
hash: index$
|
|
16807
|
+
hash: index$o,
|
|
17423
16808
|
inspect: inspect,
|
|
17424
16809
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
17425
16810
|
interpreter: index$7,
|
|
@@ -17441,10 +16826,10 @@ const ENTROPY_BYTES = 32;
|
|
|
17441
16826
|
*
|
|
17442
16827
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
17443
16828
|
*/
|
|
17444
|
-
function fisherYatesShuffle(arr, entropy) {
|
|
16829
|
+
function fisherYatesShuffle(blake2b, arr, entropy) {
|
|
17445
16830
|
check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
17446
16831
|
const n = arr.length;
|
|
17447
|
-
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
16832
|
+
const randomNumbers = hashToNumberSequence(blake2b, entropy, arr.length);
|
|
17448
16833
|
const result = new Array(n);
|
|
17449
16834
|
let itemsLeft = n;
|
|
17450
16835
|
for (let i = 0; i < n; i++) {
|
|
@@ -17457,13 +16842,13 @@ function fisherYatesShuffle(arr, entropy) {
|
|
|
17457
16842
|
}
|
|
17458
16843
|
return result;
|
|
17459
16844
|
}
|
|
17460
|
-
function hashToNumberSequence(entropy, length) {
|
|
16845
|
+
function hashToNumberSequence(blake2b, entropy, length) {
|
|
17461
16846
|
const result = new Array(length);
|
|
17462
|
-
const randomBytes =
|
|
16847
|
+
const randomBytes = safeAllocUint8Array(ENTROPY_BYTES + 4);
|
|
17463
16848
|
randomBytes.set(entropy.raw);
|
|
17464
16849
|
for (let i = 0; i < length; i++) {
|
|
17465
16850
|
randomBytes.set(u32AsLeBytes(tryAsU32(Math.floor(i / 8))), ENTROPY_BYTES);
|
|
17466
|
-
const newHash = hashBytes(randomBytes);
|
|
16851
|
+
const newHash = blake2b.hashBytes(randomBytes);
|
|
17467
16852
|
const numberStartIndex = (4 * i) % 32;
|
|
17468
16853
|
const numberEndIndex = numberStartIndex + 4;
|
|
17469
16854
|
const number = leBytesAsU32(newHash.raw.subarray(numberStartIndex, numberEndIndex)) >>> 0;
|
|
@@ -17577,8 +16962,7 @@ const availabilityAssignmentFromJson = json.object({
|
|
|
17577
16962
|
report: workReportFromJson,
|
|
17578
16963
|
timeout: "number",
|
|
17579
16964
|
}, ({ report, timeout }) => {
|
|
17580
|
-
|
|
17581
|
-
return AvailabilityAssignment.create({ workReport: new WithHash(workReportHash, report), timeout });
|
|
16965
|
+
return AvailabilityAssignment.create({ workReport: report, timeout });
|
|
17582
16966
|
});
|
|
17583
16967
|
|
|
17584
16968
|
const disputesRecordsFromJson = json.object({
|
|
@@ -17884,11 +17268,11 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17884
17268
|
class TransitionHasher {
|
|
17885
17269
|
context;
|
|
17886
17270
|
keccakHasher;
|
|
17887
|
-
|
|
17888
|
-
constructor(context, keccakHasher,
|
|
17271
|
+
blake2b;
|
|
17272
|
+
constructor(context, keccakHasher, blake2b) {
|
|
17889
17273
|
this.context = context;
|
|
17890
17274
|
this.keccakHasher = keccakHasher;
|
|
17891
|
-
this.
|
|
17275
|
+
this.blake2b = blake2b;
|
|
17892
17276
|
}
|
|
17893
17277
|
/** Concatenates two hashes and hash this concatenation */
|
|
17894
17278
|
hashConcat(a, b) {
|
|
@@ -17899,7 +17283,7 @@ class TransitionHasher {
|
|
|
17899
17283
|
}
|
|
17900
17284
|
/** Creates hash from the block header view */
|
|
17901
17285
|
header(header) {
|
|
17902
|
-
return new WithHash(hashBytes(header.encoded()
|
|
17286
|
+
return new WithHash(this.blake2b.hashBytes(header.encoded()).asOpaque(), header);
|
|
17903
17287
|
}
|
|
17904
17288
|
/**
|
|
17905
17289
|
* Merkle commitment of the extrinsic data
|
|
@@ -17912,7 +17296,7 @@ class TransitionHasher {
|
|
|
17912
17296
|
.view()
|
|
17913
17297
|
.map((g) => g.view())
|
|
17914
17298
|
.map((guarantee) => {
|
|
17915
|
-
const reportHash = hashBytes(guarantee.report.encoded()
|
|
17299
|
+
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17916
17300
|
return BytesBlob.blobFromParts([
|
|
17917
17301
|
reportHash.raw,
|
|
17918
17302
|
guarantee.slot.encoded().raw,
|
|
@@ -17920,13 +17304,13 @@ class TransitionHasher {
|
|
|
17920
17304
|
]);
|
|
17921
17305
|
});
|
|
17922
17306
|
const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
17923
|
-
const et = hashBytes(extrinsicView.tickets.encoded()
|
|
17924
|
-
const ep = hashBytes(extrinsicView.preimages.encoded()
|
|
17925
|
-
const eg = hashBytes(guaranteeBlob
|
|
17926
|
-
const ea = hashBytes(extrinsicView.assurances.encoded()
|
|
17927
|
-
const ed = hashBytes(extrinsicView.disputes.encoded()
|
|
17307
|
+
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17308
|
+
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17309
|
+
const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
|
|
17310
|
+
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17311
|
+
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17928
17312
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
17929
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17313
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
17930
17314
|
}
|
|
17931
17315
|
/** Creates hash for given WorkPackage */
|
|
17932
17316
|
workPackage(workPackage) {
|
|
@@ -17935,7 +17319,7 @@ class TransitionHasher {
|
|
|
17935
17319
|
encode(codec, data) {
|
|
17936
17320
|
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
17937
17321
|
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
17938
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17322
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
17939
17323
|
}
|
|
17940
17324
|
}
|
|
17941
17325
|
|
|
@@ -17948,8 +17332,10 @@ var PreimagesErrorCode;
|
|
|
17948
17332
|
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
17949
17333
|
class Preimages {
|
|
17950
17334
|
state;
|
|
17951
|
-
|
|
17335
|
+
blake2b;
|
|
17336
|
+
constructor(state, blake2b) {
|
|
17952
17337
|
this.state = state;
|
|
17338
|
+
this.blake2b = blake2b;
|
|
17953
17339
|
}
|
|
17954
17340
|
integrate(input) {
|
|
17955
17341
|
// make sure lookup extrinsics are sorted and unique
|
|
@@ -17972,7 +17358,7 @@ class Preimages {
|
|
|
17972
17358
|
// select preimages for integration
|
|
17973
17359
|
for (const preimage of preimages) {
|
|
17974
17360
|
const { requester, blob } = preimage;
|
|
17975
|
-
const hash = hashBytes(blob).asOpaque();
|
|
17361
|
+
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
17976
17362
|
const service = this.state.getService(requester);
|
|
17977
17363
|
if (service === null) {
|
|
17978
17364
|
return Result$1.error(PreimagesErrorCode.AccountNotFound);
|
|
@@ -17997,146 +17383,11 @@ class Preimages {
|
|
|
17997
17383
|
}
|
|
17998
17384
|
}
|
|
17999
17385
|
|
|
18000
|
-
class Missing {
|
|
18001
|
-
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
18002
|
-
basicGasCost = tryAsSmallGas(10);
|
|
18003
|
-
currentServiceId = CURRENT_SERVICE_ID;
|
|
18004
|
-
tracedRegisters = traceRegisters(7);
|
|
18005
|
-
execute(_gas, regs, _memory) {
|
|
18006
|
-
regs.set(7, HostCallResult.WHAT);
|
|
18007
|
-
return Promise.resolve(undefined);
|
|
18008
|
-
}
|
|
18009
|
-
}
|
|
18010
|
-
|
|
18011
|
-
var ServiceExecutorError;
|
|
18012
|
-
(function (ServiceExecutorError) {
|
|
18013
|
-
ServiceExecutorError[ServiceExecutorError["NoLookup"] = 0] = "NoLookup";
|
|
18014
|
-
ServiceExecutorError[ServiceExecutorError["NoState"] = 1] = "NoState";
|
|
18015
|
-
ServiceExecutorError[ServiceExecutorError["NoServiceCode"] = 2] = "NoServiceCode";
|
|
18016
|
-
ServiceExecutorError[ServiceExecutorError["ServiceCodeMismatch"] = 3] = "ServiceCodeMismatch";
|
|
18017
|
-
})(ServiceExecutorError || (ServiceExecutorError = {}));
|
|
18018
|
-
class WorkPackageExecutor {
|
|
18019
|
-
blocks;
|
|
18020
|
-
state;
|
|
18021
|
-
hasher;
|
|
18022
|
-
constructor(blocks, state, hasher) {
|
|
18023
|
-
this.blocks = blocks;
|
|
18024
|
-
this.state = state;
|
|
18025
|
-
this.hasher = hasher;
|
|
18026
|
-
}
|
|
18027
|
-
// TODO [ToDr] this while thing should be triple-checked with the GP.
|
|
18028
|
-
// I'm currently implementing some dirty version for the demo.
|
|
18029
|
-
async executeWorkPackage(pack) {
|
|
18030
|
-
const headerHash = pack.context.lookupAnchor;
|
|
18031
|
-
// execute authorisation first or is it already executed and we just need to check it?
|
|
18032
|
-
const authExec = this.getServiceExecutor(
|
|
18033
|
-
// TODO [ToDr] should this be anchor or lookupAnchor?
|
|
18034
|
-
headerHash, pack.authCodeHost, pack.authCodeHash);
|
|
18035
|
-
if (authExec.isError) {
|
|
18036
|
-
// TODO [ToDr] most likely shouldn't be throw.
|
|
18037
|
-
throw new Error(`Could not get authorization executor: ${authExec.error}`);
|
|
18038
|
-
}
|
|
18039
|
-
const pvm = authExec.ok;
|
|
18040
|
-
const authGas = tryAsGas(15000n);
|
|
18041
|
-
const result = await pvm.run(pack.parametrization, authGas);
|
|
18042
|
-
if (!result.isEqualTo(pack.authorization)) {
|
|
18043
|
-
throw new Error("Authorization is invalid.");
|
|
18044
|
-
}
|
|
18045
|
-
const results = [];
|
|
18046
|
-
for (const item of pack.items) {
|
|
18047
|
-
const exec = this.getServiceExecutor(headerHash, item.service, item.codeHash);
|
|
18048
|
-
if (exec.isError) {
|
|
18049
|
-
throw new Error(`Could not get item executor: ${exec.error}`);
|
|
18050
|
-
}
|
|
18051
|
-
const pvm = exec.ok;
|
|
18052
|
-
const gasRatio = tryAsServiceGas(3000n);
|
|
18053
|
-
const ret = await pvm.run(item.payload, tryAsGas(item.refineGasLimit)); // or accumulateGasLimit?
|
|
18054
|
-
results.push(WorkResult.create({
|
|
18055
|
-
serviceId: item.service,
|
|
18056
|
-
codeHash: item.codeHash,
|
|
18057
|
-
payloadHash: hashBytes(item.payload),
|
|
18058
|
-
gas: gasRatio,
|
|
18059
|
-
result: new WorkExecResult(WorkExecResultKind.ok, ret),
|
|
18060
|
-
load: WorkRefineLoad.create({
|
|
18061
|
-
gasUsed: tryAsServiceGas(5),
|
|
18062
|
-
importedSegments: tryAsU32(0),
|
|
18063
|
-
exportedSegments: tryAsU32(0),
|
|
18064
|
-
extrinsicSize: tryAsU32(0),
|
|
18065
|
-
extrinsicCount: tryAsU32(0),
|
|
18066
|
-
}),
|
|
18067
|
-
}));
|
|
18068
|
-
}
|
|
18069
|
-
const workPackage = this.hasher.workPackage(pack);
|
|
18070
|
-
const workPackageSpec = WorkPackageSpec.create({
|
|
18071
|
-
hash: workPackage.hash,
|
|
18072
|
-
length: tryAsU32(workPackage.encoded.length),
|
|
18073
|
-
erasureRoot: Bytes.zero(HASH_SIZE),
|
|
18074
|
-
exportsRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
18075
|
-
exportsCount: tryAsU16(0),
|
|
18076
|
-
});
|
|
18077
|
-
const coreIndex = tryAsCoreIndex(0);
|
|
18078
|
-
const authorizerHash = Bytes.fill(HASH_SIZE, 5).asOpaque();
|
|
18079
|
-
const workResults = FixedSizeArray.new(results, tryAsWorkItemsCount(results.length));
|
|
18080
|
-
return Promise.resolve(WorkReport.create({
|
|
18081
|
-
workPackageSpec,
|
|
18082
|
-
context: pack.context,
|
|
18083
|
-
coreIndex,
|
|
18084
|
-
authorizerHash,
|
|
18085
|
-
authorizationOutput: pack.authorization,
|
|
18086
|
-
segmentRootLookup: [],
|
|
18087
|
-
results: workResults,
|
|
18088
|
-
authorizationGasUsed: tryAsServiceGas(0),
|
|
18089
|
-
}));
|
|
18090
|
-
}
|
|
18091
|
-
getServiceExecutor(lookupAnchor, serviceId, expectedCodeHash) {
|
|
18092
|
-
const header = this.blocks.getHeader(lookupAnchor);
|
|
18093
|
-
if (header === null) {
|
|
18094
|
-
return Result$1.error(ServiceExecutorError.NoLookup);
|
|
18095
|
-
}
|
|
18096
|
-
const state = this.state.getState(lookupAnchor);
|
|
18097
|
-
if (state === null) {
|
|
18098
|
-
return Result$1.error(ServiceExecutorError.NoState);
|
|
18099
|
-
}
|
|
18100
|
-
const service = state.getService(serviceId);
|
|
18101
|
-
const serviceCodeHash = service?.getInfo().codeHash ?? null;
|
|
18102
|
-
if (serviceCodeHash === null) {
|
|
18103
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18104
|
-
}
|
|
18105
|
-
if (!serviceCodeHash.isEqualTo(expectedCodeHash)) {
|
|
18106
|
-
return Result$1.error(ServiceExecutorError.ServiceCodeMismatch);
|
|
18107
|
-
}
|
|
18108
|
-
const serviceCode = service?.getPreimage(serviceCodeHash.asOpaque()) ?? null;
|
|
18109
|
-
if (serviceCode === null) {
|
|
18110
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18111
|
-
}
|
|
18112
|
-
return Result$1.ok(new PvmExecutor(serviceCode));
|
|
18113
|
-
}
|
|
18114
|
-
}
|
|
18115
|
-
class PvmExecutor {
|
|
18116
|
-
serviceCode;
|
|
18117
|
-
pvm;
|
|
18118
|
-
hostCalls = new HostCallsManager({ missing: new Missing() });
|
|
18119
|
-
pvmInstanceManager = new InterpreterInstanceManager(4);
|
|
18120
|
-
constructor(serviceCode) {
|
|
18121
|
-
this.serviceCode = serviceCode;
|
|
18122
|
-
this.pvm = new HostCalls(this.pvmInstanceManager, this.hostCalls);
|
|
18123
|
-
}
|
|
18124
|
-
async run(args, gas) {
|
|
18125
|
-
const program = Program.fromSpi(this.serviceCode.raw, args.raw, true);
|
|
18126
|
-
const result = await this.pvm.runProgram(program.code, 5, gas, program.registers, program.memory);
|
|
18127
|
-
if (result.hasMemorySlice()) {
|
|
18128
|
-
return BytesBlob.blobFrom(result.memorySlice);
|
|
18129
|
-
}
|
|
18130
|
-
return BytesBlob.empty();
|
|
18131
|
-
}
|
|
18132
|
-
}
|
|
18133
|
-
|
|
18134
17386
|
var index = /*#__PURE__*/Object.freeze({
|
|
18135
17387
|
__proto__: null,
|
|
18136
17388
|
Preimages: Preimages,
|
|
18137
17389
|
get PreimagesErrorCode () { return PreimagesErrorCode; },
|
|
18138
|
-
TransitionHasher: TransitionHasher
|
|
18139
|
-
WorkPackageExecutor: WorkPackageExecutor
|
|
17390
|
+
TransitionHasher: TransitionHasher
|
|
18140
17391
|
});
|
|
18141
17392
|
|
|
18142
17393
|
exports.block = index$l;
|
|
@@ -18146,11 +17397,11 @@ exports.codec = index$q;
|
|
|
18146
17397
|
exports.collections = index$n;
|
|
18147
17398
|
exports.config = index$m;
|
|
18148
17399
|
exports.config_node = index$h;
|
|
18149
|
-
exports.crypto = index$
|
|
17400
|
+
exports.crypto = index$p;
|
|
18150
17401
|
exports.database = index$d;
|
|
18151
17402
|
exports.erasure_coding = index$c;
|
|
18152
17403
|
exports.fuzz_proto = index$a;
|
|
18153
|
-
exports.hash = index$
|
|
17404
|
+
exports.hash = index$o;
|
|
18154
17405
|
exports.jam_host_calls = index$9;
|
|
18155
17406
|
exports.json_parser = index$k;
|
|
18156
17407
|
exports.logger = index$i;
|