@typeberry/lib 0.1.3-af70ed0 → 0.1.3-b635981
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 +401 -1119
- package/index.d.ts +309 -404
- package/index.js +400 -1118
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -329,6 +329,19 @@ const Result$1 = {
|
|
|
329
329
|
},
|
|
330
330
|
};
|
|
331
331
|
|
|
332
|
+
// about 2GB, the maximum ArrayBuffer length on Chrome confirmed by several sources:
|
|
333
|
+
// - https://issues.chromium.org/issues/40055619
|
|
334
|
+
// - https://stackoverflow.com/a/72124984
|
|
335
|
+
// - https://onnxruntime.ai/docs/tutorials/web/large-models.html#maximum-size-of-arraybuffer
|
|
336
|
+
const MAX_LENGTH$2 = 2145386496;
|
|
337
|
+
function safeAllocUint8Array(length) {
|
|
338
|
+
if (length > MAX_LENGTH$2) {
|
|
339
|
+
// biome-ignore lint/suspicious/noConsole: can't have a dependency on logger here
|
|
340
|
+
console.warn(`Trying to allocate ${length} bytes, which is greater than the maximum of ${MAX_LENGTH$2}.`);
|
|
341
|
+
}
|
|
342
|
+
return new Uint8Array(Math.min(MAX_LENGTH$2, length));
|
|
343
|
+
}
|
|
344
|
+
|
|
332
345
|
/**
|
|
333
346
|
* Utilities for tests.
|
|
334
347
|
*/
|
|
@@ -569,6 +582,7 @@ var index$u = /*#__PURE__*/Object.freeze({
|
|
|
569
582
|
DEFAULT_VERSION: DEFAULT_VERSION,
|
|
570
583
|
ErrorsCollector: ErrorsCollector,
|
|
571
584
|
get GpVersion () { return GpVersion; },
|
|
585
|
+
MAX_LENGTH: MAX_LENGTH$2,
|
|
572
586
|
OK: OK,
|
|
573
587
|
Result: Result$1,
|
|
574
588
|
TEST_COMPARE_USING: TEST_COMPARE_USING,
|
|
@@ -583,6 +597,7 @@ var index$u = /*#__PURE__*/Object.freeze({
|
|
|
583
597
|
isBrowser: isBrowser,
|
|
584
598
|
measure: measure,
|
|
585
599
|
resultToString: resultToString,
|
|
600
|
+
safeAllocUint8Array: safeAllocUint8Array,
|
|
586
601
|
seeThrough: seeThrough,
|
|
587
602
|
workspacePathFix: workspacePathFix
|
|
588
603
|
});
|
|
@@ -606,7 +621,7 @@ class BitVec {
|
|
|
606
621
|
* Create new [`BitVec`] with all values set to `false`.
|
|
607
622
|
*/
|
|
608
623
|
static empty(bitLength) {
|
|
609
|
-
const data =
|
|
624
|
+
const data = safeAllocUint8Array(Math.ceil(bitLength / 8));
|
|
610
625
|
return new BitVec(data, bitLength);
|
|
611
626
|
}
|
|
612
627
|
byteLength;
|
|
@@ -807,7 +822,7 @@ class BytesBlob {
|
|
|
807
822
|
static blobFromParts(v, ...rest) {
|
|
808
823
|
const vArr = v instanceof Uint8Array ? [v] : v;
|
|
809
824
|
const totalLength = vArr.reduce((a, v) => a + v.length, 0) + rest.reduce((a, v) => a + v.length, 0);
|
|
810
|
-
const buffer =
|
|
825
|
+
const buffer = safeAllocUint8Array(totalLength);
|
|
811
826
|
let offset = 0;
|
|
812
827
|
for (const r of vArr) {
|
|
813
828
|
buffer.set(r, offset);
|
|
@@ -880,7 +895,7 @@ class Bytes extends BytesBlob {
|
|
|
880
895
|
}
|
|
881
896
|
/** Create an empty [`Bytes<X>`] of given length. */
|
|
882
897
|
static zero(len) {
|
|
883
|
-
return new Bytes(
|
|
898
|
+
return new Bytes(safeAllocUint8Array(len), len);
|
|
884
899
|
}
|
|
885
900
|
// TODO [ToDr] `fill` should have the argments swapped to align with the rest.
|
|
886
901
|
/** Create a [`Bytes<X>`] with all bytes filled with given input number. */
|
|
@@ -3589,7 +3604,7 @@ async function verify(input) {
|
|
|
3589
3604
|
return Promise.resolve([]);
|
|
3590
3605
|
}
|
|
3591
3606
|
const dataLength = input.reduce((acc, { message, key, signature }) => acc + key.length + signature.length + message.length + 1, 0);
|
|
3592
|
-
const data =
|
|
3607
|
+
const data = safeAllocUint8Array(dataLength);
|
|
3593
3608
|
let offset = 0;
|
|
3594
3609
|
for (const { key, message, signature } of input) {
|
|
3595
3610
|
data.set(key.raw, offset);
|
|
@@ -3636,823 +3651,75 @@ var ed25519 = /*#__PURE__*/Object.freeze({
|
|
|
3636
3651
|
verifyBatch: verifyBatch
|
|
3637
3652
|
});
|
|
3638
3653
|
|
|
3654
|
+
const SEED_SIZE = 32;
|
|
3655
|
+
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
3656
|
+
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
3639
3657
|
/**
|
|
3640
|
-
*
|
|
3641
|
-
*
|
|
3642
|
-
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
3658
|
+
* JIP-5: Secret key derivation
|
|
3643
3659
|
*
|
|
3644
|
-
*/
|
|
3645
|
-
const HASH_SIZE = 32;
|
|
3646
|
-
/** A hash without last byte (useful for trie representation). */
|
|
3647
|
-
const TRUNCATED_HASH_SIZE = 31;
|
|
3648
|
-
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
3660
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
3649
3661
|
/**
|
|
3650
|
-
*
|
|
3651
|
-
*
|
|
3652
|
-
* After calculating the hash these two should be passed together to avoid
|
|
3653
|
-
* unnecessary re-hashing of the data.
|
|
3662
|
+
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
3663
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
3654
3664
|
*/
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
constructor(hash, data) {
|
|
3659
|
-
super();
|
|
3660
|
-
this.hash = hash;
|
|
3661
|
-
this.data = data;
|
|
3662
|
-
}
|
|
3665
|
+
function trivialSeed(s) {
|
|
3666
|
+
const s_le = u32AsLeBytes(s);
|
|
3667
|
+
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();
|
|
3663
3668
|
}
|
|
3664
3669
|
/**
|
|
3665
|
-
*
|
|
3670
|
+
* Derives a Ed25519 secret key from a seed.
|
|
3671
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
3666
3672
|
*/
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
constructor(hash, data, encoded) {
|
|
3670
|
-
super(hash, data);
|
|
3671
|
-
this.encoded = encoded;
|
|
3672
|
-
}
|
|
3673
|
-
}
|
|
3674
|
-
|
|
3675
|
-
/** The simplest allocator returning just a fresh copy of bytes each time. */
|
|
3676
|
-
class SimpleAllocator {
|
|
3677
|
-
emptyHash() {
|
|
3678
|
-
return Bytes.zero(HASH_SIZE);
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
/** An allocator that works by allocating larger (continuous) pages of memory. */
|
|
3682
|
-
class PageAllocator {
|
|
3683
|
-
hashesPerPage;
|
|
3684
|
-
page = new Uint8Array(0);
|
|
3685
|
-
currentHash = 0;
|
|
3686
|
-
// TODO [ToDr] Benchmark the performance!
|
|
3687
|
-
constructor(hashesPerPage) {
|
|
3688
|
-
this.hashesPerPage = hashesPerPage;
|
|
3689
|
-
check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
|
|
3690
|
-
this.resetPage();
|
|
3691
|
-
}
|
|
3692
|
-
resetPage() {
|
|
3693
|
-
const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
|
|
3694
|
-
this.currentHash = 0;
|
|
3695
|
-
this.page = new Uint8Array(pageSizeBytes);
|
|
3696
|
-
}
|
|
3697
|
-
emptyHash() {
|
|
3698
|
-
const startIdx = this.currentHash * HASH_SIZE;
|
|
3699
|
-
const endIdx = startIdx + HASH_SIZE;
|
|
3700
|
-
this.currentHash += 1;
|
|
3701
|
-
if (this.currentHash >= this.hashesPerPage) {
|
|
3702
|
-
this.resetPage();
|
|
3703
|
-
}
|
|
3704
|
-
return Bytes.fromBlob(this.page.subarray(startIdx, endIdx), HASH_SIZE);
|
|
3705
|
-
}
|
|
3673
|
+
function deriveEd25519SecretKey(seed, blake2b) {
|
|
3674
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
3706
3675
|
}
|
|
3707
|
-
const defaultAllocator = new SimpleAllocator();
|
|
3708
|
-
|
|
3709
|
-
function getDefaultExportFromCjs (x) {
|
|
3710
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3711
|
-
}
|
|
3712
|
-
|
|
3713
|
-
var blake2b$3 = {exports: {}};
|
|
3714
|
-
|
|
3715
|
-
var nanoassert;
|
|
3716
|
-
var hasRequiredNanoassert;
|
|
3717
|
-
|
|
3718
|
-
function requireNanoassert () {
|
|
3719
|
-
if (hasRequiredNanoassert) return nanoassert;
|
|
3720
|
-
hasRequiredNanoassert = 1;
|
|
3721
|
-
nanoassert = assert;
|
|
3722
|
-
|
|
3723
|
-
class AssertionError extends Error {}
|
|
3724
|
-
AssertionError.prototype.name = 'AssertionError';
|
|
3725
|
-
|
|
3726
|
-
/**
|
|
3727
|
-
* Minimal assert function
|
|
3728
|
-
* @param {any} t Value to check if falsy
|
|
3729
|
-
* @param {string=} m Optional assertion error message
|
|
3730
|
-
* @throws {AssertionError}
|
|
3731
|
-
*/
|
|
3732
|
-
function assert (t, m) {
|
|
3733
|
-
if (!t) {
|
|
3734
|
-
var err = new AssertionError(m);
|
|
3735
|
-
if (Error.captureStackTrace) Error.captureStackTrace(err, assert);
|
|
3736
|
-
throw err
|
|
3737
|
-
}
|
|
3738
|
-
}
|
|
3739
|
-
return nanoassert;
|
|
3740
|
-
}
|
|
3741
|
-
|
|
3742
|
-
var blake2bWasm = {exports: {}};
|
|
3743
|
-
|
|
3744
|
-
var b4a;
|
|
3745
|
-
var hasRequiredB4a;
|
|
3746
|
-
|
|
3747
|
-
function requireB4a () {
|
|
3748
|
-
if (hasRequiredB4a) return b4a;
|
|
3749
|
-
hasRequiredB4a = 1;
|
|
3750
|
-
function isBuffer (value) {
|
|
3751
|
-
return Buffer.isBuffer(value) || value instanceof Uint8Array
|
|
3752
|
-
}
|
|
3753
|
-
|
|
3754
|
-
function isEncoding (encoding) {
|
|
3755
|
-
return Buffer.isEncoding(encoding)
|
|
3756
|
-
}
|
|
3757
|
-
|
|
3758
|
-
function alloc (size, fill, encoding) {
|
|
3759
|
-
return Buffer.alloc(size, fill, encoding)
|
|
3760
|
-
}
|
|
3761
|
-
|
|
3762
|
-
function allocUnsafe (size) {
|
|
3763
|
-
return Buffer.allocUnsafe(size)
|
|
3764
|
-
}
|
|
3765
|
-
|
|
3766
|
-
function allocUnsafeSlow (size) {
|
|
3767
|
-
return Buffer.allocUnsafeSlow(size)
|
|
3768
|
-
}
|
|
3769
|
-
|
|
3770
|
-
function byteLength (string, encoding) {
|
|
3771
|
-
return Buffer.byteLength(string, encoding)
|
|
3772
|
-
}
|
|
3773
|
-
|
|
3774
|
-
function compare (a, b) {
|
|
3775
|
-
return Buffer.compare(a, b)
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
function concat (buffers, totalLength) {
|
|
3779
|
-
return Buffer.concat(buffers, totalLength)
|
|
3780
|
-
}
|
|
3781
|
-
|
|
3782
|
-
function copy (source, target, targetStart, start, end) {
|
|
3783
|
-
return toBuffer(source).copy(target, targetStart, start, end)
|
|
3784
|
-
}
|
|
3785
|
-
|
|
3786
|
-
function equals (a, b) {
|
|
3787
|
-
return toBuffer(a).equals(b)
|
|
3788
|
-
}
|
|
3789
|
-
|
|
3790
|
-
function fill (buffer, value, offset, end, encoding) {
|
|
3791
|
-
return toBuffer(buffer).fill(value, offset, end, encoding)
|
|
3792
|
-
}
|
|
3793
|
-
|
|
3794
|
-
function from (value, encodingOrOffset, length) {
|
|
3795
|
-
return Buffer.from(value, encodingOrOffset, length)
|
|
3796
|
-
}
|
|
3797
|
-
|
|
3798
|
-
function includes (buffer, value, byteOffset, encoding) {
|
|
3799
|
-
return toBuffer(buffer).includes(value, byteOffset, encoding)
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
function indexOf (buffer, value, byfeOffset, encoding) {
|
|
3803
|
-
return toBuffer(buffer).indexOf(value, byfeOffset, encoding)
|
|
3804
|
-
}
|
|
3805
|
-
|
|
3806
|
-
function lastIndexOf (buffer, value, byteOffset, encoding) {
|
|
3807
|
-
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding)
|
|
3808
|
-
}
|
|
3809
|
-
|
|
3810
|
-
function swap16 (buffer) {
|
|
3811
|
-
return toBuffer(buffer).swap16()
|
|
3812
|
-
}
|
|
3813
|
-
|
|
3814
|
-
function swap32 (buffer) {
|
|
3815
|
-
return toBuffer(buffer).swap32()
|
|
3816
|
-
}
|
|
3817
|
-
|
|
3818
|
-
function swap64 (buffer) {
|
|
3819
|
-
return toBuffer(buffer).swap64()
|
|
3820
|
-
}
|
|
3821
|
-
|
|
3822
|
-
function toBuffer (buffer) {
|
|
3823
|
-
if (Buffer.isBuffer(buffer)) return buffer
|
|
3824
|
-
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
3825
|
-
}
|
|
3826
|
-
|
|
3827
|
-
function toString (buffer, encoding, start, end) {
|
|
3828
|
-
return toBuffer(buffer).toString(encoding, start, end)
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
function write (buffer, string, offset, length, encoding) {
|
|
3832
|
-
return toBuffer(buffer).write(string, offset, length, encoding)
|
|
3833
|
-
}
|
|
3834
|
-
|
|
3835
|
-
function writeDoubleLE (buffer, value, offset) {
|
|
3836
|
-
return toBuffer(buffer).writeDoubleLE(value, offset)
|
|
3837
|
-
}
|
|
3838
|
-
|
|
3839
|
-
function writeFloatLE (buffer, value, offset) {
|
|
3840
|
-
return toBuffer(buffer).writeFloatLE(value, offset)
|
|
3841
|
-
}
|
|
3842
|
-
|
|
3843
|
-
function writeUInt32LE (buffer, value, offset) {
|
|
3844
|
-
return toBuffer(buffer).writeUInt32LE(value, offset)
|
|
3845
|
-
}
|
|
3846
|
-
|
|
3847
|
-
function writeInt32LE (buffer, value, offset) {
|
|
3848
|
-
return toBuffer(buffer).writeInt32LE(value, offset)
|
|
3849
|
-
}
|
|
3850
|
-
|
|
3851
|
-
function readDoubleLE (buffer, offset) {
|
|
3852
|
-
return toBuffer(buffer).readDoubleLE(offset)
|
|
3853
|
-
}
|
|
3854
|
-
|
|
3855
|
-
function readFloatLE (buffer, offset) {
|
|
3856
|
-
return toBuffer(buffer).readFloatLE(offset)
|
|
3857
|
-
}
|
|
3858
|
-
|
|
3859
|
-
function readUInt32LE (buffer, offset) {
|
|
3860
|
-
return toBuffer(buffer).readUInt32LE(offset)
|
|
3861
|
-
}
|
|
3862
|
-
|
|
3863
|
-
function readInt32LE (buffer, offset) {
|
|
3864
|
-
return toBuffer(buffer).readInt32LE(offset)
|
|
3865
|
-
}
|
|
3866
|
-
|
|
3867
|
-
b4a = {
|
|
3868
|
-
isBuffer,
|
|
3869
|
-
isEncoding,
|
|
3870
|
-
alloc,
|
|
3871
|
-
allocUnsafe,
|
|
3872
|
-
allocUnsafeSlow,
|
|
3873
|
-
byteLength,
|
|
3874
|
-
compare,
|
|
3875
|
-
concat,
|
|
3876
|
-
copy,
|
|
3877
|
-
equals,
|
|
3878
|
-
fill,
|
|
3879
|
-
from,
|
|
3880
|
-
includes,
|
|
3881
|
-
indexOf,
|
|
3882
|
-
lastIndexOf,
|
|
3883
|
-
swap16,
|
|
3884
|
-
swap32,
|
|
3885
|
-
swap64,
|
|
3886
|
-
toBuffer,
|
|
3887
|
-
toString,
|
|
3888
|
-
write,
|
|
3889
|
-
writeDoubleLE,
|
|
3890
|
-
writeFloatLE,
|
|
3891
|
-
writeUInt32LE,
|
|
3892
|
-
writeInt32LE,
|
|
3893
|
-
readDoubleLE,
|
|
3894
|
-
readFloatLE,
|
|
3895
|
-
readUInt32LE,
|
|
3896
|
-
readInt32LE
|
|
3897
|
-
};
|
|
3898
|
-
return b4a;
|
|
3899
|
-
}
|
|
3900
|
-
|
|
3901
|
-
var blake2b$2;
|
|
3902
|
-
var hasRequiredBlake2b$1;
|
|
3903
|
-
|
|
3904
|
-
function requireBlake2b$1 () {
|
|
3905
|
-
if (hasRequiredBlake2b$1) return blake2b$2;
|
|
3906
|
-
hasRequiredBlake2b$1 = 1;
|
|
3907
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3908
|
-
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3909
|
-
};
|
|
3910
|
-
var __toBinary = /* @__PURE__ */ (() => {
|
|
3911
|
-
var table = new Uint8Array(128);
|
|
3912
|
-
for (var i = 0; i < 64; i++)
|
|
3913
|
-
table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
3914
|
-
return (base64) => {
|
|
3915
|
-
var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
3916
|
-
for (var i2 = 0, j = 0; i2 < n; ) {
|
|
3917
|
-
var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
|
|
3918
|
-
var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
|
|
3919
|
-
bytes2[j++] = c0 << 2 | c1 >> 4;
|
|
3920
|
-
bytes2[j++] = c1 << 4 | c2 >> 2;
|
|
3921
|
-
bytes2[j++] = c2 << 6 | c3;
|
|
3922
|
-
}
|
|
3923
|
-
return bytes2;
|
|
3924
|
-
};
|
|
3925
|
-
})();
|
|
3926
|
-
|
|
3927
|
-
// wasm-binary:./blake2b.wat
|
|
3928
|
-
var require_blake2b = __commonJS({
|
|
3929
|
-
"wasm-binary:./blake2b.wat"(exports2, module2) {
|
|
3930
|
-
module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwIgfgl/IABBgAFqISEgAEGIAWohIiAAQZABaiEjIABBmAFqISQgAEGgAWohJSAAQagBaiEmIABBsAFqIScgAEG4AWohKCAhKQMAIQEgIikDACECICMpAwAhAyAkKQMAIQQgJSkDACEFICYpAwAhBiAnKQMAIQcgKC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QMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");
|
|
3931
|
-
}
|
|
3932
|
-
});
|
|
3933
|
-
|
|
3934
|
-
// wasm-module:./blake2b.wat
|
|
3935
|
-
var bytes = require_blake2b();
|
|
3936
|
-
var compiled = WebAssembly.compile(bytes);
|
|
3937
|
-
blake2b$2 = async (imports) => {
|
|
3938
|
-
const instance = await WebAssembly.instantiate(await compiled, imports);
|
|
3939
|
-
return instance.exports;
|
|
3940
|
-
};
|
|
3941
|
-
return blake2b$2;
|
|
3942
|
-
}
|
|
3943
|
-
|
|
3944
|
-
var hasRequiredBlake2bWasm;
|
|
3945
|
-
|
|
3946
|
-
function requireBlake2bWasm () {
|
|
3947
|
-
if (hasRequiredBlake2bWasm) return blake2bWasm.exports;
|
|
3948
|
-
hasRequiredBlake2bWasm = 1;
|
|
3949
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
3950
|
-
var b4a = /*@__PURE__*/ requireB4a();
|
|
3951
|
-
|
|
3952
|
-
var wasm = null;
|
|
3953
|
-
var wasmPromise = typeof WebAssembly !== "undefined" && /*@__PURE__*/ requireBlake2b$1()().then(mod => {
|
|
3954
|
-
wasm = mod;
|
|
3955
|
-
});
|
|
3956
|
-
|
|
3957
|
-
var head = 64;
|
|
3958
|
-
var freeList = [];
|
|
3959
|
-
|
|
3960
|
-
blake2bWasm.exports = Blake2b;
|
|
3961
|
-
var BYTES_MIN = blake2bWasm.exports.BYTES_MIN = 16;
|
|
3962
|
-
var BYTES_MAX = blake2bWasm.exports.BYTES_MAX = 64;
|
|
3963
|
-
blake2bWasm.exports.BYTES = 32;
|
|
3964
|
-
var KEYBYTES_MIN = blake2bWasm.exports.KEYBYTES_MIN = 16;
|
|
3965
|
-
var KEYBYTES_MAX = blake2bWasm.exports.KEYBYTES_MAX = 64;
|
|
3966
|
-
blake2bWasm.exports.KEYBYTES = 32;
|
|
3967
|
-
var SALTBYTES = blake2bWasm.exports.SALTBYTES = 16;
|
|
3968
|
-
var PERSONALBYTES = blake2bWasm.exports.PERSONALBYTES = 16;
|
|
3969
|
-
|
|
3970
|
-
function Blake2b (digestLength, key, salt, personal, noAssert) {
|
|
3971
|
-
if (!(this instanceof Blake2b)) return new Blake2b(digestLength, key, salt, personal, noAssert)
|
|
3972
|
-
if (!wasm) throw new Error('WASM not loaded. Wait for Blake2b.ready(cb)')
|
|
3973
|
-
if (!digestLength) digestLength = 32;
|
|
3974
|
-
|
|
3975
|
-
if (noAssert !== true) {
|
|
3976
|
-
assert(digestLength >= BYTES_MIN, 'digestLength must be at least ' + BYTES_MIN + ', was given ' + digestLength);
|
|
3977
|
-
assert(digestLength <= BYTES_MAX, 'digestLength must be at most ' + BYTES_MAX + ', was given ' + digestLength);
|
|
3978
|
-
if (key != null) {
|
|
3979
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
3980
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
3981
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at least ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
3982
|
-
}
|
|
3983
|
-
if (salt != null) {
|
|
3984
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
3985
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
3986
|
-
}
|
|
3987
|
-
if (personal != null) {
|
|
3988
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
3989
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
3990
|
-
}
|
|
3991
|
-
}
|
|
3992
|
-
|
|
3993
|
-
if (!freeList.length) {
|
|
3994
|
-
freeList.push(head);
|
|
3995
|
-
head += 216;
|
|
3996
|
-
}
|
|
3997
|
-
|
|
3998
|
-
this.digestLength = digestLength;
|
|
3999
|
-
this.finalized = false;
|
|
4000
|
-
this.pointer = freeList.pop();
|
|
4001
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4002
|
-
|
|
4003
|
-
this._memory.fill(0, 0, 64);
|
|
4004
|
-
this._memory[0] = this.digestLength;
|
|
4005
|
-
this._memory[1] = key ? key.length : 0;
|
|
4006
|
-
this._memory[2] = 1; // fanout
|
|
4007
|
-
this._memory[3] = 1; // depth
|
|
4008
|
-
|
|
4009
|
-
if (salt) this._memory.set(salt, 32);
|
|
4010
|
-
if (personal) this._memory.set(personal, 48);
|
|
4011
|
-
|
|
4012
|
-
if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216); // we need 216 bytes for the state
|
|
4013
|
-
wasm.blake2b_init(this.pointer, this.digestLength);
|
|
4014
|
-
|
|
4015
|
-
if (key) {
|
|
4016
|
-
this.update(key);
|
|
4017
|
-
this._memory.fill(0, head, head + key.length); // whiteout key
|
|
4018
|
-
this._memory[this.pointer + 200] = 128;
|
|
4019
|
-
}
|
|
4020
|
-
}
|
|
4021
|
-
|
|
4022
|
-
Blake2b.prototype._realloc = function (size) {
|
|
4023
|
-
wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));
|
|
4024
|
-
this._memory = new Uint8Array(wasm.memory.buffer);
|
|
4025
|
-
};
|
|
4026
|
-
|
|
4027
|
-
Blake2b.prototype.update = function (input) {
|
|
4028
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4029
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4030
|
-
|
|
4031
|
-
if (head + input.length > this._memory.length) this._realloc(head + input.length);
|
|
4032
|
-
this._memory.set(input, head);
|
|
4033
|
-
wasm.blake2b_update(this.pointer, head, head + input.length);
|
|
4034
|
-
return this
|
|
4035
|
-
};
|
|
4036
|
-
|
|
4037
|
-
Blake2b.prototype.digest = function (enc) {
|
|
4038
|
-
assert(this.finalized === false, 'Hash instance finalized');
|
|
4039
|
-
this.finalized = true;
|
|
4040
|
-
|
|
4041
|
-
freeList.push(this.pointer);
|
|
4042
|
-
wasm.blake2b_final(this.pointer);
|
|
4043
|
-
|
|
4044
|
-
if (!enc || enc === 'binary') {
|
|
4045
|
-
return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4046
|
-
}
|
|
4047
|
-
|
|
4048
|
-
if (typeof enc === 'string') {
|
|
4049
|
-
return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength)
|
|
4050
|
-
}
|
|
4051
|
-
|
|
4052
|
-
assert(enc instanceof Uint8Array && enc.length >= this.digestLength, 'input must be Uint8Array or Buffer');
|
|
4053
|
-
for (var i = 0; i < this.digestLength; i++) {
|
|
4054
|
-
enc[i] = this._memory[this.pointer + 128 + i];
|
|
4055
|
-
}
|
|
4056
|
-
|
|
4057
|
-
return enc
|
|
4058
|
-
};
|
|
4059
|
-
|
|
4060
|
-
// libsodium compat
|
|
4061
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4062
|
-
|
|
4063
|
-
Blake2b.WASM = wasm;
|
|
4064
|
-
Blake2b.SUPPORTED = typeof WebAssembly !== 'undefined';
|
|
4065
|
-
|
|
4066
|
-
Blake2b.ready = function (cb) {
|
|
4067
|
-
if (!cb) cb = noop;
|
|
4068
|
-
if (!wasmPromise) return cb(new Error('WebAssembly not supported'))
|
|
4069
|
-
return wasmPromise.then(() => cb(), cb)
|
|
4070
|
-
};
|
|
4071
|
-
|
|
4072
|
-
Blake2b.prototype.ready = Blake2b.ready;
|
|
4073
|
-
|
|
4074
|
-
Blake2b.prototype.getPartialHash = function () {
|
|
4075
|
-
return this._memory.slice(this.pointer, this.pointer + 216);
|
|
4076
|
-
};
|
|
4077
|
-
|
|
4078
|
-
Blake2b.prototype.setPartialHash = function (ph) {
|
|
4079
|
-
this._memory.set(ph, this.pointer);
|
|
4080
|
-
};
|
|
4081
|
-
|
|
4082
|
-
function noop () {}
|
|
4083
|
-
return blake2bWasm.exports;
|
|
4084
|
-
}
|
|
4085
|
-
|
|
4086
|
-
var hasRequiredBlake2b;
|
|
4087
|
-
|
|
4088
|
-
function requireBlake2b () {
|
|
4089
|
-
if (hasRequiredBlake2b) return blake2b$3.exports;
|
|
4090
|
-
hasRequiredBlake2b = 1;
|
|
4091
|
-
var assert = /*@__PURE__*/ requireNanoassert();
|
|
4092
|
-
var b2wasm = /*@__PURE__*/ requireBlake2bWasm();
|
|
4093
|
-
|
|
4094
|
-
// 64-bit unsigned addition
|
|
4095
|
-
// Sets v[a,a+1] += v[b,b+1]
|
|
4096
|
-
// v should be a Uint32Array
|
|
4097
|
-
function ADD64AA (v, a, b) {
|
|
4098
|
-
var o0 = v[a] + v[b];
|
|
4099
|
-
var o1 = v[a + 1] + v[b + 1];
|
|
4100
|
-
if (o0 >= 0x100000000) {
|
|
4101
|
-
o1++;
|
|
4102
|
-
}
|
|
4103
|
-
v[a] = o0;
|
|
4104
|
-
v[a + 1] = o1;
|
|
4105
|
-
}
|
|
4106
|
-
|
|
4107
|
-
// 64-bit unsigned addition
|
|
4108
|
-
// Sets v[a,a+1] += b
|
|
4109
|
-
// b0 is the low 32 bits of b, b1 represents the high 32 bits
|
|
4110
|
-
function ADD64AC (v, a, b0, b1) {
|
|
4111
|
-
var o0 = v[a] + b0;
|
|
4112
|
-
if (b0 < 0) {
|
|
4113
|
-
o0 += 0x100000000;
|
|
4114
|
-
}
|
|
4115
|
-
var o1 = v[a + 1] + b1;
|
|
4116
|
-
if (o0 >= 0x100000000) {
|
|
4117
|
-
o1++;
|
|
4118
|
-
}
|
|
4119
|
-
v[a] = o0;
|
|
4120
|
-
v[a + 1] = o1;
|
|
4121
|
-
}
|
|
4122
|
-
|
|
4123
|
-
// Little-endian byte access
|
|
4124
|
-
function B2B_GET32 (arr, i) {
|
|
4125
|
-
return (arr[i] ^
|
|
4126
|
-
(arr[i + 1] << 8) ^
|
|
4127
|
-
(arr[i + 2] << 16) ^
|
|
4128
|
-
(arr[i + 3] << 24))
|
|
4129
|
-
}
|
|
4130
|
-
|
|
4131
|
-
// G Mixing function
|
|
4132
|
-
// The ROTRs are inlined for speed
|
|
4133
|
-
function B2B_G (a, b, c, d, ix, iy) {
|
|
4134
|
-
var x0 = m[ix];
|
|
4135
|
-
var x1 = m[ix + 1];
|
|
4136
|
-
var y0 = m[iy];
|
|
4137
|
-
var y1 = m[iy + 1];
|
|
4138
|
-
|
|
4139
|
-
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
|
|
4140
|
-
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
|
|
4141
|
-
|
|
4142
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
|
|
4143
|
-
var xor0 = v[d] ^ v[a];
|
|
4144
|
-
var xor1 = v[d + 1] ^ v[a + 1];
|
|
4145
|
-
v[d] = xor1;
|
|
4146
|
-
v[d + 1] = xor0;
|
|
4147
|
-
|
|
4148
|
-
ADD64AA(v, c, d);
|
|
4149
|
-
|
|
4150
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
|
|
4151
|
-
xor0 = v[b] ^ v[c];
|
|
4152
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4153
|
-
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
|
|
4154
|
-
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
|
|
4155
|
-
|
|
4156
|
-
ADD64AA(v, a, b);
|
|
4157
|
-
ADD64AC(v, a, y0, y1);
|
|
4158
|
-
|
|
4159
|
-
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
|
|
4160
|
-
xor0 = v[d] ^ v[a];
|
|
4161
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
4162
|
-
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
|
|
4163
|
-
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
|
|
4164
|
-
|
|
4165
|
-
ADD64AA(v, c, d);
|
|
4166
|
-
|
|
4167
|
-
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
|
|
4168
|
-
xor0 = v[b] ^ v[c];
|
|
4169
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
4170
|
-
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
|
|
4171
|
-
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1);
|
|
4172
|
-
}
|
|
4173
|
-
|
|
4174
|
-
// Initialization Vector
|
|
4175
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
4176
|
-
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
|
|
4177
|
-
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
|
|
4178
|
-
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
|
|
4179
|
-
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
|
|
4180
|
-
]);
|
|
4181
|
-
|
|
4182
|
-
var SIGMA8 = [
|
|
4183
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4184
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
4185
|
-
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
4186
|
-
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
4187
|
-
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
4188
|
-
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
4189
|
-
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
4190
|
-
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
4191
|
-
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
4192
|
-
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
4193
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
4194
|
-
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
|
|
4195
|
-
];
|
|
4196
|
-
|
|
4197
|
-
// These are offsets into a uint64 buffer.
|
|
4198
|
-
// Multiply them all by 2 to make them offsets into a uint32 buffer,
|
|
4199
|
-
// because this is Javascript and we don't have uint64s
|
|
4200
|
-
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) { return x * 2 }));
|
|
4201
|
-
|
|
4202
|
-
// Compression function. 'last' flag indicates last block.
|
|
4203
|
-
// Note we're representing 16 uint64s as 32 uint32s
|
|
4204
|
-
var v = new Uint32Array(32);
|
|
4205
|
-
var m = new Uint32Array(32);
|
|
4206
|
-
function blake2bCompress (ctx, last) {
|
|
4207
|
-
var i = 0;
|
|
4208
|
-
|
|
4209
|
-
// init work variables
|
|
4210
|
-
for (i = 0; i < 16; i++) {
|
|
4211
|
-
v[i] = ctx.h[i];
|
|
4212
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
4213
|
-
}
|
|
4214
|
-
|
|
4215
|
-
// low 64 bits of offset
|
|
4216
|
-
v[24] = v[24] ^ ctx.t;
|
|
4217
|
-
v[25] = v[25] ^ (ctx.t / 0x100000000);
|
|
4218
|
-
// high 64 bits not supported, offset may not be higher than 2**53-1
|
|
4219
|
-
|
|
4220
|
-
// last block flag set ?
|
|
4221
|
-
if (last) {
|
|
4222
|
-
v[28] = ~v[28];
|
|
4223
|
-
v[29] = ~v[29];
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
// get little-endian words
|
|
4227
|
-
for (i = 0; i < 32; i++) {
|
|
4228
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
4229
|
-
}
|
|
4230
|
-
|
|
4231
|
-
// twelve rounds of mixing
|
|
4232
|
-
for (i = 0; i < 12; i++) {
|
|
4233
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
4234
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
4235
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
4236
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
4237
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
4238
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
4239
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
4240
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
4241
|
-
}
|
|
4242
|
-
|
|
4243
|
-
for (i = 0; i < 16; i++) {
|
|
4244
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
4245
|
-
}
|
|
4246
|
-
}
|
|
4247
|
-
|
|
4248
|
-
// reusable parameter_block
|
|
4249
|
-
var parameter_block = new Uint8Array([
|
|
4250
|
-
0, 0, 0, 0, // 0: outlen, keylen, fanout, depth
|
|
4251
|
-
0, 0, 0, 0, // 4: leaf length, sequential mode
|
|
4252
|
-
0, 0, 0, 0, // 8: node offset
|
|
4253
|
-
0, 0, 0, 0, // 12: node offset
|
|
4254
|
-
0, 0, 0, 0, // 16: node depth, inner length, rfu
|
|
4255
|
-
0, 0, 0, 0, // 20: rfu
|
|
4256
|
-
0, 0, 0, 0, // 24: rfu
|
|
4257
|
-
0, 0, 0, 0, // 28: rfu
|
|
4258
|
-
0, 0, 0, 0, // 32: salt
|
|
4259
|
-
0, 0, 0, 0, // 36: salt
|
|
4260
|
-
0, 0, 0, 0, // 40: salt
|
|
4261
|
-
0, 0, 0, 0, // 44: salt
|
|
4262
|
-
0, 0, 0, 0, // 48: personal
|
|
4263
|
-
0, 0, 0, 0, // 52: personal
|
|
4264
|
-
0, 0, 0, 0, // 56: personal
|
|
4265
|
-
0, 0, 0, 0 // 60: personal
|
|
4266
|
-
]);
|
|
4267
|
-
|
|
4268
|
-
// Creates a BLAKE2b hashing context
|
|
4269
|
-
// Requires an output length between 1 and 64 bytes
|
|
4270
|
-
// Takes an optional Uint8Array key
|
|
4271
|
-
function Blake2b (outlen, key, salt, personal) {
|
|
4272
|
-
// zero out parameter_block before usage
|
|
4273
|
-
parameter_block.fill(0);
|
|
4274
|
-
// state, 'param block'
|
|
4275
|
-
|
|
4276
|
-
this.b = new Uint8Array(128);
|
|
4277
|
-
this.h = new Uint32Array(16);
|
|
4278
|
-
this.t = 0; // input count
|
|
4279
|
-
this.c = 0; // pointer within buffer
|
|
4280
|
-
this.outlen = outlen; // output length in bytes
|
|
4281
|
-
|
|
4282
|
-
parameter_block[0] = outlen;
|
|
4283
|
-
if (key) parameter_block[1] = key.length;
|
|
4284
|
-
parameter_block[2] = 1; // fanout
|
|
4285
|
-
parameter_block[3] = 1; // depth
|
|
4286
|
-
|
|
4287
|
-
if (salt) parameter_block.set(salt, 32);
|
|
4288
|
-
if (personal) parameter_block.set(personal, 48);
|
|
4289
|
-
|
|
4290
|
-
// initialize hash state
|
|
4291
|
-
for (var i = 0; i < 16; i++) {
|
|
4292
|
-
this.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameter_block, i * 4);
|
|
4293
|
-
}
|
|
4294
|
-
|
|
4295
|
-
// key the hash, if applicable
|
|
4296
|
-
if (key) {
|
|
4297
|
-
blake2bUpdate(this, key);
|
|
4298
|
-
// at the end
|
|
4299
|
-
this.c = 128;
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
|
|
4303
|
-
Blake2b.prototype.update = function (input) {
|
|
4304
|
-
assert(input instanceof Uint8Array, 'input must be Uint8Array or Buffer');
|
|
4305
|
-
blake2bUpdate(this, input);
|
|
4306
|
-
return this
|
|
4307
|
-
};
|
|
4308
|
-
|
|
4309
|
-
Blake2b.prototype.digest = function (out) {
|
|
4310
|
-
var buf = (!out || out === 'binary' || out === 'hex') ? new Uint8Array(this.outlen) : out;
|
|
4311
|
-
assert(buf instanceof Uint8Array, 'out must be "binary", "hex", Uint8Array, or Buffer');
|
|
4312
|
-
assert(buf.length >= this.outlen, 'out must have at least outlen bytes of space');
|
|
4313
|
-
blake2bFinal(this, buf);
|
|
4314
|
-
if (out === 'hex') return hexSlice(buf)
|
|
4315
|
-
return buf
|
|
4316
|
-
};
|
|
4317
|
-
|
|
4318
|
-
Blake2b.prototype.final = Blake2b.prototype.digest;
|
|
4319
|
-
|
|
4320
|
-
Blake2b.ready = function (cb) {
|
|
4321
|
-
b2wasm.ready(function () {
|
|
4322
|
-
cb(); // ignore the error
|
|
4323
|
-
});
|
|
4324
|
-
};
|
|
4325
|
-
|
|
4326
|
-
// Updates a BLAKE2b streaming hash
|
|
4327
|
-
// Requires hash context and Uint8Array (byte array)
|
|
4328
|
-
function blake2bUpdate (ctx, input) {
|
|
4329
|
-
for (var i = 0; i < input.length; i++) {
|
|
4330
|
-
if (ctx.c === 128) { // buffer full ?
|
|
4331
|
-
ctx.t += ctx.c; // add counters
|
|
4332
|
-
blake2bCompress(ctx, false); // compress (not last)
|
|
4333
|
-
ctx.c = 0; // counter to zero
|
|
4334
|
-
}
|
|
4335
|
-
ctx.b[ctx.c++] = input[i];
|
|
4336
|
-
}
|
|
4337
|
-
}
|
|
4338
|
-
|
|
4339
|
-
// Completes a BLAKE2b streaming hash
|
|
4340
|
-
// Returns a Uint8Array containing the message digest
|
|
4341
|
-
function blake2bFinal (ctx, out) {
|
|
4342
|
-
ctx.t += ctx.c; // mark last block offset
|
|
4343
|
-
|
|
4344
|
-
while (ctx.c < 128) { // fill up with zeros
|
|
4345
|
-
ctx.b[ctx.c++] = 0;
|
|
4346
|
-
}
|
|
4347
|
-
blake2bCompress(ctx, true); // final block flag = 1
|
|
4348
|
-
|
|
4349
|
-
for (var i = 0; i < ctx.outlen; i++) {
|
|
4350
|
-
out[i] = ctx.h[i >> 2] >> (8 * (i & 3));
|
|
4351
|
-
}
|
|
4352
|
-
return out
|
|
4353
|
-
}
|
|
4354
|
-
|
|
4355
|
-
function hexSlice (buf) {
|
|
4356
|
-
var str = '';
|
|
4357
|
-
for (var i = 0; i < buf.length; i++) str += toHex(buf[i]);
|
|
4358
|
-
return str
|
|
4359
|
-
}
|
|
4360
|
-
|
|
4361
|
-
function toHex (n) {
|
|
4362
|
-
if (n < 16) return '0' + n.toString(16)
|
|
4363
|
-
return n.toString(16)
|
|
4364
|
-
}
|
|
4365
|
-
|
|
4366
|
-
var Proto = Blake2b;
|
|
4367
|
-
|
|
4368
|
-
blake2b$3.exports = function createHash (outlen, key, salt, personal, noAssert) {
|
|
4369
|
-
if (noAssert !== true) {
|
|
4370
|
-
assert(outlen >= BYTES_MIN, 'outlen must be at least ' + BYTES_MIN + ', was given ' + outlen);
|
|
4371
|
-
assert(outlen <= BYTES_MAX, 'outlen must be at most ' + BYTES_MAX + ', was given ' + outlen);
|
|
4372
|
-
if (key != null) {
|
|
4373
|
-
assert(key instanceof Uint8Array, 'key must be Uint8Array or Buffer');
|
|
4374
|
-
assert(key.length >= KEYBYTES_MIN, 'key must be at least ' + KEYBYTES_MIN + ', was given ' + key.length);
|
|
4375
|
-
assert(key.length <= KEYBYTES_MAX, 'key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length);
|
|
4376
|
-
}
|
|
4377
|
-
if (salt != null) {
|
|
4378
|
-
assert(salt instanceof Uint8Array, 'salt must be Uint8Array or Buffer');
|
|
4379
|
-
assert(salt.length === SALTBYTES, 'salt must be exactly ' + SALTBYTES + ', was given ' + salt.length);
|
|
4380
|
-
}
|
|
4381
|
-
if (personal != null) {
|
|
4382
|
-
assert(personal instanceof Uint8Array, 'personal must be Uint8Array or Buffer');
|
|
4383
|
-
assert(personal.length === PERSONALBYTES, 'personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length);
|
|
4384
|
-
}
|
|
4385
|
-
}
|
|
4386
|
-
|
|
4387
|
-
return new Proto(outlen, key, salt, personal)
|
|
4388
|
-
};
|
|
4389
|
-
|
|
4390
|
-
blake2b$3.exports.ready = function (cb) {
|
|
4391
|
-
b2wasm.ready(function () { // ignore errors
|
|
4392
|
-
cb();
|
|
4393
|
-
});
|
|
4394
|
-
};
|
|
4395
|
-
|
|
4396
|
-
blake2b$3.exports.WASM_SUPPORTED = b2wasm.SUPPORTED;
|
|
4397
|
-
blake2b$3.exports.WASM_LOADED = false;
|
|
4398
|
-
|
|
4399
|
-
var BYTES_MIN = blake2b$3.exports.BYTES_MIN = 16;
|
|
4400
|
-
var BYTES_MAX = blake2b$3.exports.BYTES_MAX = 64;
|
|
4401
|
-
blake2b$3.exports.BYTES = 32;
|
|
4402
|
-
var KEYBYTES_MIN = blake2b$3.exports.KEYBYTES_MIN = 16;
|
|
4403
|
-
var KEYBYTES_MAX = blake2b$3.exports.KEYBYTES_MAX = 64;
|
|
4404
|
-
blake2b$3.exports.KEYBYTES = 32;
|
|
4405
|
-
var SALTBYTES = blake2b$3.exports.SALTBYTES = 16;
|
|
4406
|
-
var PERSONALBYTES = blake2b$3.exports.PERSONALBYTES = 16;
|
|
4407
|
-
|
|
4408
|
-
b2wasm.ready(function (err) {
|
|
4409
|
-
if (!err) {
|
|
4410
|
-
blake2b$3.exports.WASM_LOADED = true;
|
|
4411
|
-
blake2b$3.exports = b2wasm;
|
|
4412
|
-
}
|
|
4413
|
-
});
|
|
4414
|
-
return blake2b$3.exports;
|
|
4415
|
-
}
|
|
4416
|
-
|
|
4417
|
-
var blake2bExports = /*@__PURE__*/ requireBlake2b();
|
|
4418
|
-
var blake2b$1 = /*@__PURE__*/getDefaultExportFromCjs(blake2bExports);
|
|
4419
|
-
|
|
4420
3676
|
/**
|
|
4421
|
-
*
|
|
4422
|
-
*
|
|
4423
|
-
* If empty array is given a zero-hash is returned.
|
|
3677
|
+
* Derives a Bandersnatch secret key from a seed.
|
|
3678
|
+
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4424
3679
|
*/
|
|
4425
|
-
function
|
|
4426
|
-
|
|
4427
|
-
if (r.length === 0) {
|
|
4428
|
-
return out.asOpaque();
|
|
4429
|
-
}
|
|
4430
|
-
const hasher = blake2b$1(HASH_SIZE);
|
|
4431
|
-
for (const v of r) {
|
|
4432
|
-
hasher?.update(v instanceof BytesBlob ? v.raw : v);
|
|
4433
|
-
}
|
|
4434
|
-
hasher?.digest(out.raw);
|
|
4435
|
-
return out.asOpaque();
|
|
3680
|
+
function deriveBandersnatchSecretKey(seed, blake2b) {
|
|
3681
|
+
return blake2b.hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw])).asOpaque();
|
|
4436
3682
|
}
|
|
4437
|
-
/**
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
const out = allocator.emptyHash();
|
|
4443
|
-
hasher?.digest(out.raw);
|
|
4444
|
-
return out;
|
|
3683
|
+
/**
|
|
3684
|
+
* Derive Ed25519 public key from secret seed
|
|
3685
|
+
*/
|
|
3686
|
+
async function deriveEd25519PublicKey(seed) {
|
|
3687
|
+
return (await privateKey(seed)).pubKey;
|
|
4445
3688
|
}
|
|
4446
|
-
/**
|
|
4447
|
-
|
|
4448
|
-
|
|
3689
|
+
/**
|
|
3690
|
+
* Derive Bandersnatch public key from secret seed
|
|
3691
|
+
*/
|
|
3692
|
+
function deriveBandersnatchPublicKey(seed) {
|
|
3693
|
+
return publicKey(seed.raw);
|
|
4449
3694
|
}
|
|
4450
3695
|
|
|
4451
|
-
var
|
|
3696
|
+
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
4452
3697
|
__proto__: null,
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
3698
|
+
SEED_SIZE: SEED_SIZE,
|
|
3699
|
+
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
3700
|
+
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
3701
|
+
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
3702
|
+
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
3703
|
+
trivialSeed: trivialSeed
|
|
3704
|
+
});
|
|
3705
|
+
|
|
3706
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
3707
|
+
__proto__: null,
|
|
3708
|
+
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
3709
|
+
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
3710
|
+
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
3711
|
+
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
3712
|
+
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
3713
|
+
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
3714
|
+
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
3715
|
+
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
3716
|
+
Ed25519Pair: Ed25519Pair,
|
|
3717
|
+
SEED_SIZE: SEED_SIZE,
|
|
3718
|
+
bandersnatch: bandersnatch,
|
|
3719
|
+
bandersnatchWasm: bandersnatch_exports,
|
|
3720
|
+
ed25519: ed25519,
|
|
3721
|
+
initWasm: initAll,
|
|
3722
|
+
keyDerivation: keyDerivation
|
|
4456
3723
|
});
|
|
4457
3724
|
|
|
4458
3725
|
/*!
|
|
@@ -4813,7 +4080,78 @@ function WASMInterface(binary, hashLength) {
|
|
|
4813
4080
|
|
|
4814
4081
|
new Mutex();
|
|
4815
4082
|
|
|
4083
|
+
var name$j = "blake2b";
|
|
4084
|
+
var data$j = "AGFzbQEAAAABEQRgAAF/YAJ/fwBgAX8AYAAAAwoJAAECAwECAgABBQQBAQICBg4CfwFBsIsFC38AQYAICwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACkhhc2hfRmluYWwAAwlIYXNoX0luaXQABQtIYXNoX1VwZGF0ZQAGDUhhc2hfR2V0U3RhdGUABw5IYXNoX0NhbGN1bGF0ZQAIClNUQVRFX1NJWkUDAQrTOAkFAEGACQvrAgIFfwF+AkAgAUEBSA0AAkACQAJAIAFBgAFBACgC4IoBIgJrIgNKDQAgASEEDAELQQBBADYC4IoBAkAgAkH/AEoNACACQeCJAWohBSAAIQRBACEGA0AgBSAELQAAOgAAIARBAWohBCAFQQFqIQUgAyAGQQFqIgZB/wFxSg0ACwtBAEEAKQPAiQEiB0KAAXw3A8CJAUEAQQApA8iJASAHQv9+Vq18NwPIiQFB4IkBEAIgACADaiEAAkAgASADayIEQYEBSA0AIAIgAWohBQNAQQBBACkDwIkBIgdCgAF8NwPAiQFBAEEAKQPIiQEgB0L/flatfDcDyIkBIAAQAiAAQYABaiEAIAVBgH9qIgVBgAJLDQALIAVBgH9qIQQMAQsgBEEATA0BC0EAIQUDQCAFQQAoAuCKAWpB4IkBaiAAIAVqLQAAOgAAIAQgBUEBaiIFQf8BcUoNAAsLQQBBACgC4IoBIARqNgLgigELC78uASR+QQBBACkD0IkBQQApA7CJASIBQQApA5CJAXwgACkDIC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A3AAAgAEH4igFqQgA3AAAgAEHwigFqQgA3AAAgAEEYaiIADQALQQAhAEEAQQApA/CKASIDQoiS853/zPmE6gCFNwOAiQFBAEEAKQP4igFCu86qptjQ67O7f4U3A4iJAUEAQQApA4CLAUKr8NP0r+68tzyFNwOQiQFBAEEAKQOIiwFC8e30+KWn/aelf4U3A5iJAUEAQQApA5CLAULRhZrv+s+Uh9EAhTcDoIkBQQBBACkDmIsBQp/Y+dnCkdqCm3+FNwOoiQFBAEEAKQOgiwFC6/qG2r+19sEfhTcDsIkBQQBBACkDqIsBQvnC+JuRo7Pw2wCFNwO4iQFBACADp0H/AXE2AuSKAQJAIAFBAUgNACACQgA3A3ggAkIANwNwIAJCADcDaCACQgA3A2AgAkIANwNYIAJCADcDUCACQgA3A0ggAkIANwNAIAJCADcDOCACQgA3AzAgAkIANwMoIAJCADcDICACQgA3AxggAkIANwMQIAJCADcDCCACQgA3AwBBACEEA0AgAiAAaiAAQYAJai0AADoAACAAQQFqIQAgBEEBaiIEQf8BcSABSA0ACyACQYABEAELIAJBgAFqJAALEgAgAEEDdkH/P3EgAEEQdhAECwkAQYAJIAAQAQsGAEGAiQELGwAgAUEDdkH/P3EgAUEQdhAEQYAJIAAQARADCwsLAQBBgAgLBPAAAAA=";
|
|
4085
|
+
var hash$j = "c6f286e6";
|
|
4086
|
+
var wasmJson$j = {
|
|
4087
|
+
name: name$j,
|
|
4088
|
+
data: data$j,
|
|
4089
|
+
hash: hash$j
|
|
4090
|
+
};
|
|
4091
|
+
|
|
4816
4092
|
new Mutex();
|
|
4093
|
+
function validateBits$4(bits) {
|
|
4094
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
4095
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
4096
|
+
}
|
|
4097
|
+
return null;
|
|
4098
|
+
}
|
|
4099
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
4100
|
+
return outputBits | (keyBits << 16);
|
|
4101
|
+
}
|
|
4102
|
+
/**
|
|
4103
|
+
* Creates a new BLAKE2b hash instance
|
|
4104
|
+
* @param bits Number of output bits, which has to be a number
|
|
4105
|
+
* divisible by 8, between 8 and 512. Defaults to 512.
|
|
4106
|
+
* @param key Optional key (string, Buffer or TypedArray). Maximum length is 64 bytes.
|
|
4107
|
+
*/
|
|
4108
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
4109
|
+
if (validateBits$4(bits)) {
|
|
4110
|
+
return Promise.reject(validateBits$4(bits));
|
|
4111
|
+
}
|
|
4112
|
+
let keyBuffer = null;
|
|
4113
|
+
let initParam = bits;
|
|
4114
|
+
if (key !== null) {
|
|
4115
|
+
keyBuffer = getUInt8Buffer(key);
|
|
4116
|
+
if (keyBuffer.length > 64) {
|
|
4117
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
4118
|
+
}
|
|
4119
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
4120
|
+
}
|
|
4121
|
+
const outputSize = bits / 8;
|
|
4122
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
4123
|
+
if (initParam > 512) {
|
|
4124
|
+
wasm.writeMemory(keyBuffer);
|
|
4125
|
+
}
|
|
4126
|
+
wasm.init(initParam);
|
|
4127
|
+
const obj = {
|
|
4128
|
+
init: initParam > 512
|
|
4129
|
+
? () => {
|
|
4130
|
+
wasm.writeMemory(keyBuffer);
|
|
4131
|
+
wasm.init(initParam);
|
|
4132
|
+
return obj;
|
|
4133
|
+
}
|
|
4134
|
+
: () => {
|
|
4135
|
+
wasm.init(initParam);
|
|
4136
|
+
return obj;
|
|
4137
|
+
},
|
|
4138
|
+
update: (data) => {
|
|
4139
|
+
wasm.update(data);
|
|
4140
|
+
return obj;
|
|
4141
|
+
},
|
|
4142
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
4143
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
4144
|
+
save: () => wasm.save(),
|
|
4145
|
+
load: (data) => {
|
|
4146
|
+
wasm.load(data);
|
|
4147
|
+
return obj;
|
|
4148
|
+
},
|
|
4149
|
+
blockSize: 128,
|
|
4150
|
+
digestSize: outputSize,
|
|
4151
|
+
};
|
|
4152
|
+
return obj;
|
|
4153
|
+
});
|
|
4154
|
+
}
|
|
4817
4155
|
|
|
4818
4156
|
new Mutex();
|
|
4819
4157
|
|
|
@@ -4903,6 +4241,79 @@ new Mutex();
|
|
|
4903
4241
|
|
|
4904
4242
|
new Mutex();
|
|
4905
4243
|
|
|
4244
|
+
/**
|
|
4245
|
+
* Size of the output of the hash functions.
|
|
4246
|
+
*
|
|
4247
|
+
* https://graypaper.fluffylabs.dev/#/579bd12/073101073c01
|
|
4248
|
+
*
|
|
4249
|
+
*/
|
|
4250
|
+
const HASH_SIZE = 32;
|
|
4251
|
+
/** A hash without last byte (useful for trie representation). */
|
|
4252
|
+
const TRUNCATED_HASH_SIZE = 31;
|
|
4253
|
+
const ZERO_HASH = Bytes.zero(HASH_SIZE);
|
|
4254
|
+
/**
|
|
4255
|
+
* Container for some object with a hash that is related to this object.
|
|
4256
|
+
*
|
|
4257
|
+
* After calculating the hash these two should be passed together to avoid
|
|
4258
|
+
* unnecessary re-hashing of the data.
|
|
4259
|
+
*/
|
|
4260
|
+
class WithHash extends WithDebug {
|
|
4261
|
+
hash;
|
|
4262
|
+
data;
|
|
4263
|
+
constructor(hash, data) {
|
|
4264
|
+
super();
|
|
4265
|
+
this.hash = hash;
|
|
4266
|
+
this.data = data;
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
4269
|
+
/**
|
|
4270
|
+
* Extension of [`WithHash`] additionally containing an encoded version of the object.
|
|
4271
|
+
*/
|
|
4272
|
+
class WithHashAndBytes extends WithHash {
|
|
4273
|
+
encoded;
|
|
4274
|
+
constructor(hash, data, encoded) {
|
|
4275
|
+
super(hash, data);
|
|
4276
|
+
this.encoded = encoded;
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4280
|
+
const zero$1 = Bytes.zero(HASH_SIZE);
|
|
4281
|
+
class Blake2b {
|
|
4282
|
+
hasher;
|
|
4283
|
+
static async createHasher() {
|
|
4284
|
+
return new Blake2b(await createBLAKE2b(HASH_SIZE * 8));
|
|
4285
|
+
}
|
|
4286
|
+
constructor(hasher) {
|
|
4287
|
+
this.hasher = hasher;
|
|
4288
|
+
}
|
|
4289
|
+
/**
|
|
4290
|
+
* Hash given collection of blobs.
|
|
4291
|
+
*
|
|
4292
|
+
* If empty array is given a zero-hash is returned.
|
|
4293
|
+
*/
|
|
4294
|
+
hashBlobs(r) {
|
|
4295
|
+
if (r.length === 0) {
|
|
4296
|
+
return zero$1.asOpaque();
|
|
4297
|
+
}
|
|
4298
|
+
const hasher = this.hasher.init();
|
|
4299
|
+
for (const v of r) {
|
|
4300
|
+
hasher.update(v instanceof BytesBlob ? v.raw : v);
|
|
4301
|
+
}
|
|
4302
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4303
|
+
}
|
|
4304
|
+
/** Hash given blob of bytes. */
|
|
4305
|
+
hashBytes(blob) {
|
|
4306
|
+
const hasher = this.hasher.init();
|
|
4307
|
+
const bytes = blob instanceof BytesBlob ? blob.raw : blob;
|
|
4308
|
+
hasher.update(bytes);
|
|
4309
|
+
return Bytes.fromBlob(hasher.digest("binary"), HASH_SIZE).asOpaque();
|
|
4310
|
+
}
|
|
4311
|
+
/** Convert given string into bytes and hash it. */
|
|
4312
|
+
hashString(str) {
|
|
4313
|
+
return this.hashBytes(BytesBlob.blobFromString(str));
|
|
4314
|
+
}
|
|
4315
|
+
}
|
|
4316
|
+
|
|
4906
4317
|
class KeccakHasher {
|
|
4907
4318
|
hasher;
|
|
4908
4319
|
static async create() {
|
|
@@ -4927,91 +4338,61 @@ var keccak = /*#__PURE__*/Object.freeze({
|
|
|
4927
4338
|
hashBlobs: hashBlobs
|
|
4928
4339
|
});
|
|
4929
4340
|
|
|
4930
|
-
|
|
4341
|
+
// TODO [ToDr] (#213) this should most likely be moved to a separate
|
|
4342
|
+
// package to avoid pulling in unnecessary deps.
|
|
4343
|
+
|
|
4344
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
4931
4345
|
__proto__: null,
|
|
4346
|
+
Blake2b: Blake2b,
|
|
4932
4347
|
HASH_SIZE: HASH_SIZE,
|
|
4933
|
-
PageAllocator: PageAllocator,
|
|
4934
|
-
SimpleAllocator: SimpleAllocator,
|
|
4935
4348
|
TRUNCATED_HASH_SIZE: TRUNCATED_HASH_SIZE,
|
|
4936
4349
|
WithHash: WithHash,
|
|
4937
4350
|
WithHashAndBytes: WithHashAndBytes,
|
|
4938
4351
|
ZERO_HASH: ZERO_HASH,
|
|
4939
|
-
blake2b: blake2b,
|
|
4940
|
-
defaultAllocator: defaultAllocator,
|
|
4941
4352
|
keccak: keccak
|
|
4942
4353
|
});
|
|
4943
4354
|
|
|
4944
|
-
const SEED_SIZE = 32;
|
|
4945
|
-
const ED25519_SECRET_KEY = Bytes.blobFromString("jam_val_key_ed25519");
|
|
4946
|
-
const BANDERSNATCH_SECRET_KEY = Bytes.blobFromString("jam_val_key_bandersnatch");
|
|
4947
|
-
/**
|
|
4948
|
-
* JIP-5: Secret key derivation
|
|
4949
|
-
*
|
|
4950
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md */
|
|
4951
|
-
/**
|
|
4952
|
-
* Deriving a 32-byte seed from a 32-bit unsigned integer
|
|
4953
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#trivial-seeds
|
|
4954
|
-
*/
|
|
4955
|
-
function trivialSeed(s) {
|
|
4956
|
-
const s_le = u32AsLeBytes(s);
|
|
4957
|
-
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();
|
|
4958
|
-
}
|
|
4959
|
-
/**
|
|
4960
|
-
* Derives a Ed25519 secret key from a seed.
|
|
4961
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4962
|
-
*/
|
|
4963
|
-
function deriveEd25519SecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4964
|
-
return hashBytes(BytesBlob.blobFromParts([ED25519_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4965
|
-
}
|
|
4966
|
-
/**
|
|
4967
|
-
* Derives a Bandersnatch secret key from a seed.
|
|
4968
|
-
* https://github.com/polkadot-fellows/JIPs/blob/7048f79edf4f4eb8bfe6fb42e6bbf61900f44c65/JIP-5.md#derivation-method
|
|
4969
|
-
*/
|
|
4970
|
-
function deriveBandersnatchSecretKey(seed, allocator = new SimpleAllocator()) {
|
|
4971
|
-
return hashBytes(BytesBlob.blobFromParts([BANDERSNATCH_SECRET_KEY.raw, seed.raw]), allocator).asOpaque();
|
|
4972
|
-
}
|
|
4973
|
-
/**
|
|
4974
|
-
* Derive Ed25519 public key from secret seed
|
|
4975
|
-
*/
|
|
4976
|
-
async function deriveEd25519PublicKey(seed) {
|
|
4977
|
-
return (await privateKey(seed)).pubKey;
|
|
4978
|
-
}
|
|
4979
4355
|
/**
|
|
4980
|
-
*
|
|
4356
|
+
* A utility class providing a readonly view over a portion of an array without copying it.
|
|
4981
4357
|
*/
|
|
4982
|
-
|
|
4983
|
-
|
|
4358
|
+
class ArrayView {
|
|
4359
|
+
start;
|
|
4360
|
+
end;
|
|
4361
|
+
source;
|
|
4362
|
+
length;
|
|
4363
|
+
constructor(source, start, end) {
|
|
4364
|
+
this.start = start;
|
|
4365
|
+
this.end = end;
|
|
4366
|
+
this.source = source;
|
|
4367
|
+
this.length = end - start;
|
|
4368
|
+
}
|
|
4369
|
+
static from(source, start = 0, end = source.length) {
|
|
4370
|
+
check `
|
|
4371
|
+
${start >= 0 && end <= source.length && start <= end}
|
|
4372
|
+
Invalid start (${start})/end (${end}) for ArrayView
|
|
4373
|
+
`;
|
|
4374
|
+
return new ArrayView(source, start, end);
|
|
4375
|
+
}
|
|
4376
|
+
get(i) {
|
|
4377
|
+
check `
|
|
4378
|
+
${i >= 0 && i < this.length}
|
|
4379
|
+
Index out of bounds: ${i} < ${this.length}
|
|
4380
|
+
`;
|
|
4381
|
+
return this.source[this.start + i];
|
|
4382
|
+
}
|
|
4383
|
+
subview(from, to = this.length) {
|
|
4384
|
+
return ArrayView.from(this.source, this.start + from, this.start + to);
|
|
4385
|
+
}
|
|
4386
|
+
toArray() {
|
|
4387
|
+
return this.source.slice(this.start, this.end);
|
|
4388
|
+
}
|
|
4389
|
+
*[Symbol.iterator]() {
|
|
4390
|
+
for (let i = this.start; i < this.end; i++) {
|
|
4391
|
+
yield this.source[i];
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4984
4394
|
}
|
|
4985
4395
|
|
|
4986
|
-
var keyDerivation = /*#__PURE__*/Object.freeze({
|
|
4987
|
-
__proto__: null,
|
|
4988
|
-
SEED_SIZE: SEED_SIZE,
|
|
4989
|
-
deriveBandersnatchPublicKey: deriveBandersnatchPublicKey,
|
|
4990
|
-
deriveBandersnatchSecretKey: deriveBandersnatchSecretKey,
|
|
4991
|
-
deriveEd25519PublicKey: deriveEd25519PublicKey,
|
|
4992
|
-
deriveEd25519SecretKey: deriveEd25519SecretKey,
|
|
4993
|
-
trivialSeed: trivialSeed
|
|
4994
|
-
});
|
|
4995
|
-
|
|
4996
|
-
var index$o = /*#__PURE__*/Object.freeze({
|
|
4997
|
-
__proto__: null,
|
|
4998
|
-
BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
|
|
4999
|
-
BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
|
|
5000
|
-
BANDERSNATCH_RING_ROOT_BYTES: BANDERSNATCH_RING_ROOT_BYTES,
|
|
5001
|
-
BANDERSNATCH_VRF_SIGNATURE_BYTES: BANDERSNATCH_VRF_SIGNATURE_BYTES,
|
|
5002
|
-
BLS_KEY_BYTES: BLS_KEY_BYTES,
|
|
5003
|
-
ED25519_KEY_BYTES: ED25519_KEY_BYTES,
|
|
5004
|
-
ED25519_PRIV_KEY_BYTES: ED25519_PRIV_KEY_BYTES,
|
|
5005
|
-
ED25519_SIGNATURE_BYTES: ED25519_SIGNATURE_BYTES,
|
|
5006
|
-
Ed25519Pair: Ed25519Pair,
|
|
5007
|
-
SEED_SIZE: SEED_SIZE,
|
|
5008
|
-
bandersnatch: bandersnatch,
|
|
5009
|
-
bandersnatchWasm: bandersnatch_exports,
|
|
5010
|
-
ed25519: ed25519,
|
|
5011
|
-
initWasm: initAll,
|
|
5012
|
-
keyDerivation: keyDerivation
|
|
5013
|
-
});
|
|
5014
|
-
|
|
5015
4396
|
/** A map which uses hashes as keys. */
|
|
5016
4397
|
class HashDictionary {
|
|
5017
4398
|
// TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
|
|
@@ -5599,6 +4980,7 @@ class TruncatedHashDictionary {
|
|
|
5599
4980
|
|
|
5600
4981
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
5601
4982
|
__proto__: null,
|
|
4983
|
+
ArrayView: ArrayView,
|
|
5602
4984
|
FixedSizeArray: FixedSizeArray,
|
|
5603
4985
|
HashDictionary: HashDictionary,
|
|
5604
4986
|
HashSet: HashSet,
|
|
@@ -8560,43 +7942,43 @@ var stateKeys;
|
|
|
8560
7942
|
}
|
|
8561
7943
|
stateKeys.serviceInfo = serviceInfo;
|
|
8562
7944
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bba033bba03?v=0.7.1 */
|
|
8563
|
-
function serviceStorage(serviceId, key) {
|
|
7945
|
+
function serviceStorage(blake2b, serviceId, key) {
|
|
8564
7946
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8565
7947
|
const out = Bytes.zero(HASH_SIZE);
|
|
8566
7948
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 1)), 0);
|
|
8567
7949
|
out.raw.set(key.raw.subarray(0, HASH_SIZE - U32_BYTES), U32_BYTES);
|
|
8568
7950
|
return legacyServiceNested(serviceId, out);
|
|
8569
7951
|
}
|
|
8570
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
7952
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 1), key);
|
|
8571
7953
|
}
|
|
8572
7954
|
stateKeys.serviceStorage = serviceStorage;
|
|
8573
7955
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3bd7033bd703?v=0.7.1 */
|
|
8574
|
-
function servicePreimage(serviceId, hash) {
|
|
7956
|
+
function servicePreimage(blake2b, serviceId, hash) {
|
|
8575
7957
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8576
7958
|
const out = Bytes.zero(HASH_SIZE);
|
|
8577
7959
|
out.raw.set(u32AsLeBytes(tryAsU32(2 ** 32 - 2)), 0);
|
|
8578
7960
|
out.raw.set(hash.raw.subarray(1, HASH_SIZE - U32_BYTES + 1), U32_BYTES);
|
|
8579
7961
|
return legacyServiceNested(serviceId, out);
|
|
8580
7962
|
}
|
|
8581
|
-
return serviceNested(serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
7963
|
+
return serviceNested(blake2b, serviceId, tryAsU32(2 ** 32 - 2), hash);
|
|
8582
7964
|
}
|
|
8583
7965
|
stateKeys.servicePreimage = servicePreimage;
|
|
8584
7966
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b0a043b0a04?v=0.7.1 */
|
|
8585
|
-
function serviceLookupHistory(serviceId, hash, preimageLength) {
|
|
7967
|
+
function serviceLookupHistory(blake2b, serviceId, hash, preimageLength) {
|
|
8586
7968
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
8587
|
-
const doubleHash = hashBytes(hash);
|
|
7969
|
+
const doubleHash = blake2b.hashBytes(hash);
|
|
8588
7970
|
const out = Bytes.zero(HASH_SIZE);
|
|
8589
7971
|
out.raw.set(u32AsLeBytes(preimageLength), 0);
|
|
8590
7972
|
out.raw.set(doubleHash.raw.subarray(2, HASH_SIZE - U32_BYTES + 2), U32_BYTES);
|
|
8591
7973
|
return legacyServiceNested(serviceId, out);
|
|
8592
7974
|
}
|
|
8593
|
-
return serviceNested(serviceId, preimageLength, hash);
|
|
7975
|
+
return serviceNested(blake2b, serviceId, preimageLength, hash);
|
|
8594
7976
|
}
|
|
8595
7977
|
stateKeys.serviceLookupHistory = serviceLookupHistory;
|
|
8596
7978
|
/** https://graypaper.fluffylabs.dev/#/1c979cb/3b88003b8800?v=0.7.1 */
|
|
8597
|
-
function serviceNested(serviceId, numberPrefix, hash) {
|
|
7979
|
+
function serviceNested(blake2b, serviceId, numberPrefix, hash) {
|
|
8598
7980
|
const inputToHash = BytesBlob.blobFromParts(u32AsLeBytes(numberPrefix), hash.raw);
|
|
8599
|
-
const newHash = hashBytes(inputToHash).raw.subarray(0, 28);
|
|
7981
|
+
const newHash = blake2b.hashBytes(inputToHash).raw.subarray(0, 28);
|
|
8600
7982
|
const key = Bytes.zero(HASH_SIZE);
|
|
8601
7983
|
let i = 0;
|
|
8602
7984
|
for (const byte of u32AsLeBytes(serviceId)) {
|
|
@@ -8657,12 +8039,6 @@ function accumulationOutputComparator(a, b) {
|
|
|
8657
8039
|
return Ordering.Equal;
|
|
8658
8040
|
}
|
|
8659
8041
|
|
|
8660
|
-
const codecWithHash = (val) => Descriptor.withView(val.name, val.sizeHint, (e, elem) => val.encode(e, elem.data), (d) => {
|
|
8661
|
-
const decoder2 = d.clone();
|
|
8662
|
-
const encoded = val.skipEncoded(decoder2);
|
|
8663
|
-
const hash = hashBytes(encoded);
|
|
8664
|
-
return new WithHash(hash.asOpaque(), val.decode(d));
|
|
8665
|
-
}, val.skip, val.View);
|
|
8666
8042
|
/**
|
|
8667
8043
|
* Assignment of particular work report to a core.
|
|
8668
8044
|
*
|
|
@@ -8675,7 +8051,7 @@ class AvailabilityAssignment extends WithDebug {
|
|
|
8675
8051
|
workReport;
|
|
8676
8052
|
timeout;
|
|
8677
8053
|
static Codec = codec$1.Class(AvailabilityAssignment, {
|
|
8678
|
-
workReport:
|
|
8054
|
+
workReport: WorkReport.Codec,
|
|
8679
8055
|
timeout: codec$1.u32.asOpaque(),
|
|
8680
8056
|
});
|
|
8681
8057
|
static create({ workReport, timeout }) {
|
|
@@ -9123,6 +8499,23 @@ const zeroSizeHint = {
|
|
|
9123
8499
|
};
|
|
9124
8500
|
/** 0-byte read, return given default value */
|
|
9125
8501
|
const ignoreValueWithDefault = (defaultValue) => Descriptor.new("ignoreValue", zeroSizeHint, (_e, _v) => { }, (_d) => defaultValue, (_s) => { });
|
|
8502
|
+
/** Encode and decode object with leading version number. */
|
|
8503
|
+
const codecWithVersion = (val) => Descriptor.new("withVersion", {
|
|
8504
|
+
bytes: val.sizeHint.bytes + 8,
|
|
8505
|
+
isExact: false,
|
|
8506
|
+
}, (e, v) => {
|
|
8507
|
+
e.varU64(0n);
|
|
8508
|
+
val.encode(e, v);
|
|
8509
|
+
}, (d) => {
|
|
8510
|
+
const version = d.varU64();
|
|
8511
|
+
if (version !== 0n) {
|
|
8512
|
+
throw new Error("Non-zero version is not supported!");
|
|
8513
|
+
}
|
|
8514
|
+
return val.decode(d);
|
|
8515
|
+
}, (s) => {
|
|
8516
|
+
s.varU64();
|
|
8517
|
+
val.skip(s);
|
|
8518
|
+
});
|
|
9126
8519
|
/**
|
|
9127
8520
|
* Service account details.
|
|
9128
8521
|
*
|
|
@@ -10132,6 +9525,7 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
10132
9525
|
ValidatorStatistics: ValidatorStatistics,
|
|
10133
9526
|
accumulationOutputComparator: accumulationOutputComparator,
|
|
10134
9527
|
codecPerCore: codecPerCore,
|
|
9528
|
+
codecWithVersion: codecWithVersion,
|
|
10135
9529
|
hashComparator: hashComparator,
|
|
10136
9530
|
ignoreValueWithDefault: ignoreValueWithDefault,
|
|
10137
9531
|
serviceDataCodec: serviceDataCodec,
|
|
@@ -10292,21 +9686,23 @@ var serialize;
|
|
|
10292
9686
|
/** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
|
|
10293
9687
|
serialize.serviceData = (serviceId) => ({
|
|
10294
9688
|
key: stateKeys.serviceInfo(serviceId),
|
|
10295
|
-
Codec:
|
|
9689
|
+
Codec: Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)
|
|
9690
|
+
? codecWithVersion(ServiceAccountInfo.Codec)
|
|
9691
|
+
: ServiceAccountInfo.Codec,
|
|
10296
9692
|
});
|
|
10297
9693
|
/** https://graypaper.fluffylabs.dev/#/85129da/384803384803?v=0.6.3 */
|
|
10298
|
-
serialize.serviceStorage = (serviceId, key) => ({
|
|
10299
|
-
key: stateKeys.serviceStorage(serviceId, key),
|
|
9694
|
+
serialize.serviceStorage = (blake2b, serviceId, key) => ({
|
|
9695
|
+
key: stateKeys.serviceStorage(blake2b, serviceId, key),
|
|
10300
9696
|
Codec: dumpCodec,
|
|
10301
9697
|
});
|
|
10302
9698
|
/** https://graypaper.fluffylabs.dev/#/85129da/385b03385b03?v=0.6.3 */
|
|
10303
|
-
serialize.servicePreimages = (serviceId, hash) => ({
|
|
10304
|
-
key: stateKeys.servicePreimage(serviceId, hash),
|
|
9699
|
+
serialize.servicePreimages = (blake2b, serviceId, hash) => ({
|
|
9700
|
+
key: stateKeys.servicePreimage(blake2b, serviceId, hash),
|
|
10305
9701
|
Codec: dumpCodec,
|
|
10306
9702
|
});
|
|
10307
9703
|
/** https://graypaper.fluffylabs.dev/#/85129da/387603387603?v=0.6.3 */
|
|
10308
|
-
serialize.serviceLookupHistory = (serviceId, hash, len) => ({
|
|
10309
|
-
key: stateKeys.serviceLookupHistory(serviceId, hash, len),
|
|
9704
|
+
serialize.serviceLookupHistory = (blake2b, serviceId, hash, len) => ({
|
|
9705
|
+
key: stateKeys.serviceLookupHistory(blake2b, serviceId, hash, len),
|
|
10310
9706
|
Codec: readonlyArray(codec$1.sequenceVarLen(codec$1.u32)),
|
|
10311
9707
|
});
|
|
10312
9708
|
})(serialize || (serialize = {}));
|
|
@@ -10329,20 +9725,22 @@ const dumpCodec = Descriptor.new("Dump", { bytes: 64, isExact: false }, (e, v) =
|
|
|
10329
9725
|
*/
|
|
10330
9726
|
class SerializedState {
|
|
10331
9727
|
spec;
|
|
9728
|
+
blake2b;
|
|
10332
9729
|
backend;
|
|
10333
9730
|
_recentServiceIds;
|
|
10334
9731
|
/** Create a state-like object from collection of serialized entries. */
|
|
10335
|
-
static fromStateEntries(spec, state, recentServices = []) {
|
|
10336
|
-
return new SerializedState(spec, state, recentServices);
|
|
9732
|
+
static fromStateEntries(spec, blake2b, state, recentServices = []) {
|
|
9733
|
+
return new SerializedState(spec, blake2b, state, recentServices);
|
|
10337
9734
|
}
|
|
10338
9735
|
/** Create a state-like object backed by some DB. */
|
|
10339
|
-
static new(spec, db, recentServices = []) {
|
|
10340
|
-
return new SerializedState(spec, db, recentServices);
|
|
9736
|
+
static new(spec, blake2b, db, recentServices = []) {
|
|
9737
|
+
return new SerializedState(spec, blake2b, db, recentServices);
|
|
10341
9738
|
}
|
|
10342
|
-
constructor(spec, backend,
|
|
9739
|
+
constructor(spec, blake2b, backend,
|
|
10343
9740
|
/** Best-effort list of recently active services. */
|
|
10344
9741
|
_recentServiceIds) {
|
|
10345
9742
|
this.spec = spec;
|
|
9743
|
+
this.blake2b = blake2b;
|
|
10346
9744
|
this.backend = backend;
|
|
10347
9745
|
this._recentServiceIds = _recentServiceIds;
|
|
10348
9746
|
}
|
|
@@ -10366,7 +9764,7 @@ class SerializedState {
|
|
|
10366
9764
|
if (!this._recentServiceIds.includes(id)) {
|
|
10367
9765
|
this._recentServiceIds.push(id);
|
|
10368
9766
|
}
|
|
10369
|
-
return new SerializedService(id, serviceData, (key) => this.retrieveOptional(key));
|
|
9767
|
+
return new SerializedService(this.blake2b, id, serviceData, (key) => this.retrieveOptional(key));
|
|
10370
9768
|
}
|
|
10371
9769
|
retrieve({ key, Codec }, description) {
|
|
10372
9770
|
const bytes = this.backend.get(key);
|
|
@@ -10442,12 +9840,14 @@ class SerializedState {
|
|
|
10442
9840
|
}
|
|
10443
9841
|
/** Service data representation on a serialized state. */
|
|
10444
9842
|
class SerializedService {
|
|
9843
|
+
blake2b;
|
|
10445
9844
|
serviceId;
|
|
10446
9845
|
accountInfo;
|
|
10447
9846
|
retrieveOptional;
|
|
10448
|
-
constructor(
|
|
9847
|
+
constructor(blake2b,
|
|
10449
9848
|
/** Service id */
|
|
10450
9849
|
serviceId, accountInfo, retrieveOptional) {
|
|
9850
|
+
this.blake2b = blake2b;
|
|
10451
9851
|
this.serviceId = serviceId;
|
|
10452
9852
|
this.accountInfo = accountInfo;
|
|
10453
9853
|
this.retrieveOptional = retrieveOptional;
|
|
@@ -10460,13 +9860,13 @@ class SerializedService {
|
|
|
10460
9860
|
getStorage(rawKey) {
|
|
10461
9861
|
if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
|
|
10462
9862
|
const SERVICE_ID_BYTES = 4;
|
|
10463
|
-
const serviceIdAndKey =
|
|
9863
|
+
const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
|
|
10464
9864
|
serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
|
|
10465
9865
|
serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
|
|
10466
|
-
const key = asOpaqueType(BytesBlob.blobFrom(hashBytes(serviceIdAndKey).raw));
|
|
10467
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, key)) ?? null;
|
|
9866
|
+
const key = asOpaqueType(BytesBlob.blobFrom(this.blake2b.hashBytes(serviceIdAndKey).raw));
|
|
9867
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, key)) ?? null;
|
|
10468
9868
|
}
|
|
10469
|
-
return this.retrieveOptional(serialize.serviceStorage(this.serviceId, rawKey)) ?? null;
|
|
9869
|
+
return this.retrieveOptional(serialize.serviceStorage(this.blake2b, this.serviceId, rawKey)) ?? null;
|
|
10470
9870
|
}
|
|
10471
9871
|
/**
|
|
10472
9872
|
* Check if preimage is present in the DB.
|
|
@@ -10475,15 +9875,15 @@ class SerializedService {
|
|
|
10475
9875
|
*/
|
|
10476
9876
|
hasPreimage(hash) {
|
|
10477
9877
|
// TODO [ToDr] consider optimizing to avoid fetching the whole data.
|
|
10478
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) !== undefined;
|
|
9878
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) !== undefined;
|
|
10479
9879
|
}
|
|
10480
9880
|
/** Retrieve preimage from the DB. */
|
|
10481
9881
|
getPreimage(hash) {
|
|
10482
|
-
return this.retrieveOptional(serialize.servicePreimages(this.serviceId, hash)) ?? null;
|
|
9882
|
+
return this.retrieveOptional(serialize.servicePreimages(this.blake2b, this.serviceId, hash)) ?? null;
|
|
10483
9883
|
}
|
|
10484
9884
|
/** Retrieve preimage lookup history. */
|
|
10485
9885
|
getLookupHistory(hash, len) {
|
|
10486
|
-
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.serviceId, hash, len));
|
|
9886
|
+
const rawSlots = this.retrieveOptional(serialize.serviceLookupHistory(this.blake2b, this.serviceId, hash, len));
|
|
10487
9887
|
if (rawSlots === undefined) {
|
|
10488
9888
|
return null;
|
|
10489
9889
|
}
|
|
@@ -10545,7 +9945,7 @@ class TrieNode {
|
|
|
10545
9945
|
raw;
|
|
10546
9946
|
constructor(
|
|
10547
9947
|
/** Exactly 512 bits / 64 bytes */
|
|
10548
|
-
raw =
|
|
9948
|
+
raw = safeAllocUint8Array(TRIE_NODE_BYTES)) {
|
|
10549
9949
|
this.raw = raw;
|
|
10550
9950
|
}
|
|
10551
9951
|
/** Returns the type of the node */
|
|
@@ -11120,11 +10520,13 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
11120
10520
|
parseInputKey: parseInputKey
|
|
11121
10521
|
});
|
|
11122
10522
|
|
|
11123
|
-
|
|
11124
|
-
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
}
|
|
10523
|
+
function getBlake2bTrieHasher(hasher) {
|
|
10524
|
+
return {
|
|
10525
|
+
hashConcat(n, rest = []) {
|
|
10526
|
+
return hasher.hashBlobs([n, ...rest]);
|
|
10527
|
+
},
|
|
10528
|
+
};
|
|
10529
|
+
}
|
|
11128
10530
|
|
|
11129
10531
|
/** What should be done with that key? */
|
|
11130
10532
|
var StateEntryUpdateAction;
|
|
@@ -11136,14 +10538,14 @@ var StateEntryUpdateAction;
|
|
|
11136
10538
|
})(StateEntryUpdateAction || (StateEntryUpdateAction = {}));
|
|
11137
10539
|
const EMPTY_BLOB = BytesBlob.empty();
|
|
11138
10540
|
/** Serialize given state update into a series of key-value pairs. */
|
|
11139
|
-
function* serializeStateUpdate(spec, update) {
|
|
10541
|
+
function* serializeStateUpdate(spec, blake2b, update) {
|
|
11140
10542
|
// first let's serialize all of the simple entries (if present!)
|
|
11141
10543
|
yield* serializeBasicKeys(spec, update);
|
|
11142
10544
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
11143
10545
|
// then let's proceed with service updates
|
|
11144
|
-
yield* serializeServiceUpdates(update.servicesUpdates, encode);
|
|
11145
|
-
yield* serializePreimages(update.preimages, encode);
|
|
11146
|
-
yield* serializeStorage(update.storage);
|
|
10546
|
+
yield* serializeServiceUpdates(update.servicesUpdates, encode, blake2b);
|
|
10547
|
+
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
10548
|
+
yield* serializeStorage(update.storage, blake2b);
|
|
11147
10549
|
yield* serializeRemovedServices(update.servicesRemoved);
|
|
11148
10550
|
}
|
|
11149
10551
|
function* serializeRemovedServices(servicesRemoved) {
|
|
@@ -11153,18 +10555,18 @@ function* serializeRemovedServices(servicesRemoved) {
|
|
|
11153
10555
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11154
10556
|
}
|
|
11155
10557
|
}
|
|
11156
|
-
function* serializeStorage(storage) {
|
|
10558
|
+
function* serializeStorage(storage, blake2b) {
|
|
11157
10559
|
for (const { action, serviceId } of storage ?? []) {
|
|
11158
10560
|
switch (action.kind) {
|
|
11159
10561
|
case UpdateStorageKind.Set: {
|
|
11160
10562
|
const key = action.storage.key;
|
|
11161
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10563
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11162
10564
|
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11163
10565
|
break;
|
|
11164
10566
|
}
|
|
11165
10567
|
case UpdateStorageKind.Remove: {
|
|
11166
10568
|
const key = action.key;
|
|
11167
|
-
const codec = serialize.serviceStorage(serviceId, key);
|
|
10569
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
11168
10570
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11169
10571
|
break;
|
|
11170
10572
|
}
|
|
@@ -11173,15 +10575,15 @@ function* serializeStorage(storage) {
|
|
|
11173
10575
|
}
|
|
11174
10576
|
}
|
|
11175
10577
|
}
|
|
11176
|
-
function* serializePreimages(preimages, encode) {
|
|
10578
|
+
function* serializePreimages(preimages, encode, blake2b) {
|
|
11177
10579
|
for (const { action, serviceId } of preimages ?? []) {
|
|
11178
10580
|
switch (action.kind) {
|
|
11179
10581
|
case UpdatePreimageKind.Provide: {
|
|
11180
10582
|
const { hash, blob } = action.preimage;
|
|
11181
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10583
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11182
10584
|
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11183
10585
|
if (action.slot !== null) {
|
|
11184
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, tryAsU32(blob.length));
|
|
10586
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
11185
10587
|
yield [
|
|
11186
10588
|
StateEntryUpdateAction.Insert,
|
|
11187
10589
|
codec2.key,
|
|
@@ -11192,15 +10594,15 @@ function* serializePreimages(preimages, encode) {
|
|
|
11192
10594
|
}
|
|
11193
10595
|
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11194
10596
|
const { hash, length, slots } = action.item;
|
|
11195
|
-
const codec = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10597
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11196
10598
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11197
10599
|
break;
|
|
11198
10600
|
}
|
|
11199
10601
|
case UpdatePreimageKind.Remove: {
|
|
11200
10602
|
const { hash, length } = action;
|
|
11201
|
-
const codec = serialize.servicePreimages(serviceId, hash);
|
|
10603
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11202
10604
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11203
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, hash, length);
|
|
10605
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11204
10606
|
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11205
10607
|
break;
|
|
11206
10608
|
}
|
|
@@ -11209,7 +10611,7 @@ function* serializePreimages(preimages, encode) {
|
|
|
11209
10611
|
}
|
|
11210
10612
|
}
|
|
11211
10613
|
}
|
|
11212
|
-
function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
10614
|
+
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11213
10615
|
for (const { action, serviceId } of servicesUpdates ?? []) {
|
|
11214
10616
|
// new service being created or updated
|
|
11215
10617
|
const codec = serialize.serviceData(serviceId);
|
|
@@ -11217,7 +10619,7 @@ function* serializeServiceUpdates(servicesUpdates, encode) {
|
|
|
11217
10619
|
// additional lookup history update
|
|
11218
10620
|
if (action.kind === UpdateServiceKind.Create && action.lookupHistory !== null) {
|
|
11219
10621
|
const { lookupHistory } = action;
|
|
11220
|
-
const codec2 = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10622
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11221
10623
|
yield [StateEntryUpdateAction.Insert, codec2.key, encode(codec2.Codec, lookupHistory.slots)];
|
|
11222
10624
|
}
|
|
11223
10625
|
}
|
|
@@ -11312,8 +10714,8 @@ class StateEntries {
|
|
|
11312
10714
|
},
|
|
11313
10715
|
}, (e, v) => stateEntriesSequenceCodec.encode(e, Array.from(v.entries)), (d) => StateEntries.fromEntriesUnsafe(stateEntriesSequenceCodec.decode(d)), (s) => stateEntriesSequenceCodec.skip(s));
|
|
11314
10716
|
/** Turn in-memory state into it's serialized form. */
|
|
11315
|
-
static serializeInMemory(spec, state) {
|
|
11316
|
-
return new StateEntries(convertInMemoryStateToDictionary(spec, state));
|
|
10717
|
+
static serializeInMemory(spec, blake2b, state) {
|
|
10718
|
+
return new StateEntries(convertInMemoryStateToDictionary(spec, blake2b, state));
|
|
11317
10719
|
}
|
|
11318
10720
|
/**
|
|
11319
10721
|
* Wrap a collection of truncated state entries and treat it as state.
|
|
@@ -11362,7 +10764,8 @@ class StateEntries {
|
|
|
11362
10764
|
}
|
|
11363
10765
|
}
|
|
11364
10766
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/391600391600?v=0.6.4 */
|
|
11365
|
-
getRootHash() {
|
|
10767
|
+
getRootHash(blake2b) {
|
|
10768
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11366
10769
|
const leaves = SortedSet.fromArray(leafComparator);
|
|
11367
10770
|
for (const [key, value] of this) {
|
|
11368
10771
|
leaves.insert(InMemoryTrie.constructLeaf(blake2bTrieHasher, key.asOpaque(), value));
|
|
@@ -11371,7 +10774,7 @@ class StateEntries {
|
|
|
11371
10774
|
}
|
|
11372
10775
|
}
|
|
11373
10776
|
/** https://graypaper.fluffylabs.dev/#/68eaa1f/38a50038a500?v=0.6.4 */
|
|
11374
|
-
function convertInMemoryStateToDictionary(spec, state) {
|
|
10777
|
+
function convertInMemoryStateToDictionary(spec, blake2b, state) {
|
|
11375
10778
|
const serialized = TruncatedHashDictionary.fromEntries([]);
|
|
11376
10779
|
function doSerialize(codec) {
|
|
11377
10780
|
serialized.set(codec.key, Encoder.encodeObject(codec.Codec, codec.extract(state), spec));
|
|
@@ -11399,18 +10802,18 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11399
10802
|
serialized.set(key, Encoder.encodeObject(Codec, service.getInfo()));
|
|
11400
10803
|
// preimages
|
|
11401
10804
|
for (const preimage of service.data.preimages.values()) {
|
|
11402
|
-
const { key, Codec } = serialize.servicePreimages(serviceId, preimage.hash);
|
|
10805
|
+
const { key, Codec } = serialize.servicePreimages(blake2b, serviceId, preimage.hash);
|
|
11403
10806
|
serialized.set(key, Encoder.encodeObject(Codec, preimage.blob));
|
|
11404
10807
|
}
|
|
11405
10808
|
// storage
|
|
11406
10809
|
for (const storage of service.data.storage.values()) {
|
|
11407
|
-
const { key, Codec } = serialize.serviceStorage(serviceId, storage.key);
|
|
10810
|
+
const { key, Codec } = serialize.serviceStorage(blake2b, serviceId, storage.key);
|
|
11408
10811
|
serialized.set(key, Encoder.encodeObject(Codec, storage.value));
|
|
11409
10812
|
}
|
|
11410
10813
|
// lookup history
|
|
11411
10814
|
for (const lookupHistoryList of service.data.lookupHistory.values()) {
|
|
11412
10815
|
for (const lookupHistory of lookupHistoryList) {
|
|
11413
|
-
const { key, Codec } = serialize.serviceLookupHistory(serviceId, lookupHistory.hash, lookupHistory.length);
|
|
10816
|
+
const { key, Codec } = serialize.serviceLookupHistory(blake2b, serviceId, lookupHistory.hash, lookupHistory.length);
|
|
11414
10817
|
serialized.set(key, Encoder.encodeObject(Codec, lookupHistory.slots.slice()));
|
|
11415
10818
|
}
|
|
11416
10819
|
}
|
|
@@ -11418,9 +10821,9 @@ function convertInMemoryStateToDictionary(spec, state) {
|
|
|
11418
10821
|
return serialized;
|
|
11419
10822
|
}
|
|
11420
10823
|
|
|
11421
|
-
function loadState(spec, entries) {
|
|
10824
|
+
function loadState(spec, blake2b, entries) {
|
|
11422
10825
|
const stateEntries = StateEntries.fromEntriesUnsafe(entries);
|
|
11423
|
-
return SerializedState.fromStateEntries(spec, stateEntries);
|
|
10826
|
+
return SerializedState.fromStateEntries(spec, blake2b, stateEntries);
|
|
11424
10827
|
}
|
|
11425
10828
|
|
|
11426
10829
|
/**
|
|
@@ -11528,7 +10931,8 @@ class LeafDb {
|
|
|
11528
10931
|
}
|
|
11529
10932
|
assertNever(val);
|
|
11530
10933
|
}
|
|
11531
|
-
getStateRoot() {
|
|
10934
|
+
getStateRoot(blake2b) {
|
|
10935
|
+
const blake2bTrieHasher = getBlake2bTrieHasher(blake2b);
|
|
11532
10936
|
return InMemoryTrie.computeStateRoot(blake2bTrieHasher, this.leaves).asOpaque();
|
|
11533
10937
|
}
|
|
11534
10938
|
intoStateEntries() {
|
|
@@ -11718,7 +11122,8 @@ class InMemoryStates {
|
|
|
11718
11122
|
}
|
|
11719
11123
|
}
|
|
11720
11124
|
async getStateRoot(state) {
|
|
11721
|
-
|
|
11125
|
+
const blake2b = await Blake2b.createHasher();
|
|
11126
|
+
return StateEntries.serializeInMemory(this.spec, blake2b, state).getRootHash(blake2b);
|
|
11722
11127
|
}
|
|
11723
11128
|
/** Insert a full state into the database. */
|
|
11724
11129
|
async insertState(headerHash, state) {
|
|
@@ -11796,7 +11201,7 @@ function padAndEncodeData(input) {
|
|
|
11796
11201
|
const paddedLength = Math.ceil(input.length / PIECE_SIZE) * PIECE_SIZE;
|
|
11797
11202
|
let padded = input;
|
|
11798
11203
|
if (input.length !== paddedLength) {
|
|
11799
|
-
padded = BytesBlob.blobFrom(
|
|
11204
|
+
padded = BytesBlob.blobFrom(safeAllocUint8Array(paddedLength));
|
|
11800
11205
|
padded.raw.set(input.raw, 0);
|
|
11801
11206
|
}
|
|
11802
11207
|
return chunkingFunction(padded);
|
|
@@ -11842,7 +11247,7 @@ function decodeData(input) {
|
|
|
11842
11247
|
*/
|
|
11843
11248
|
function encodePoints(input) {
|
|
11844
11249
|
const result = [];
|
|
11845
|
-
const data =
|
|
11250
|
+
const data = safeAllocUint8Array(POINT_ALIGNMENT * N_CHUNKS_REQUIRED);
|
|
11846
11251
|
// add original shards to the result
|
|
11847
11252
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11848
11253
|
const pointStart = POINT_LENGTH * i;
|
|
@@ -11858,7 +11263,7 @@ function encodePoints(input) {
|
|
|
11858
11263
|
const encodedData = encodedResult.take_data();
|
|
11859
11264
|
for (let i = 0; i < N_CHUNKS_REDUNDANCY; i++) {
|
|
11860
11265
|
const pointIndex = i * POINT_ALIGNMENT;
|
|
11861
|
-
const redundancyPoint =
|
|
11266
|
+
const redundancyPoint = safeAllocUint8Array(POINT_LENGTH);
|
|
11862
11267
|
for (let j = 0; j < POINT_LENGTH; j++) {
|
|
11863
11268
|
redundancyPoint[j] = encodedData[pointIndex + j * HALF_POINT_SIZE];
|
|
11864
11269
|
}
|
|
@@ -11873,7 +11278,7 @@ function encodePoints(input) {
|
|
|
11873
11278
|
*/
|
|
11874
11279
|
function decodePiece(input) {
|
|
11875
11280
|
const result = Bytes.zero(PIECE_SIZE);
|
|
11876
|
-
const data =
|
|
11281
|
+
const data = safeAllocUint8Array(N_CHUNKS_REQUIRED * POINT_ALIGNMENT);
|
|
11877
11282
|
const indices = new Uint16Array(input.length);
|
|
11878
11283
|
for (let i = 0; i < N_CHUNKS_REQUIRED; i++) {
|
|
11879
11284
|
const [index, points] = input[i];
|
|
@@ -11989,7 +11394,7 @@ function lace(input) {
|
|
|
11989
11394
|
return BytesBlob.empty();
|
|
11990
11395
|
}
|
|
11991
11396
|
const n = input[0].length;
|
|
11992
|
-
const result = BytesBlob.blobFrom(
|
|
11397
|
+
const result = BytesBlob.blobFrom(safeAllocUint8Array(k * n));
|
|
11993
11398
|
for (let i = 0; i < k; i++) {
|
|
11994
11399
|
const entry = input[i].raw;
|
|
11995
11400
|
for (let j = 0; j < n; j++) {
|
|
@@ -13268,7 +12673,7 @@ class Registers {
|
|
|
13268
12673
|
bytes;
|
|
13269
12674
|
asSigned;
|
|
13270
12675
|
asUnsigned;
|
|
13271
|
-
constructor(bytes =
|
|
12676
|
+
constructor(bytes = safeAllocUint8Array(NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT)) {
|
|
13272
12677
|
this.bytes = bytes;
|
|
13273
12678
|
check `${bytes.length === NO_OF_REGISTERS$1 << REGISTER_SIZE_SHIFT} Invalid size of registers array.`;
|
|
13274
12679
|
this.asSigned = new BigInt64Array(bytes.buffer, bytes.byteOffset);
|
|
@@ -13340,10 +12745,16 @@ function signExtend32To64(value) {
|
|
|
13340
12745
|
|
|
13341
12746
|
/** Attempt to convert a number into `HostCallIndex`. */
|
|
13342
12747
|
const tryAsHostCallIndex = (v) => asOpaqueType(tryAsU32(v));
|
|
12748
|
+
/**
|
|
12749
|
+
* Host-call exit reason.
|
|
12750
|
+
*
|
|
12751
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
|
|
12752
|
+
*/
|
|
13343
12753
|
var PvmExecution;
|
|
13344
12754
|
(function (PvmExecution) {
|
|
13345
12755
|
PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
|
|
13346
12756
|
PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
|
|
12757
|
+
PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
|
|
13347
12758
|
})(PvmExecution || (PvmExecution = {}));
|
|
13348
12759
|
/** A utility function to easily trace a bunch of registers. */
|
|
13349
12760
|
function traceRegisters(...regs) {
|
|
@@ -13415,7 +12826,7 @@ class Mask {
|
|
|
13415
12826
|
return Math.min(this.lookupTableForward[index] ?? 0, MAX_INSTRUCTION_DISTANCE);
|
|
13416
12827
|
}
|
|
13417
12828
|
buildLookupTableForward(mask) {
|
|
13418
|
-
const table =
|
|
12829
|
+
const table = safeAllocUint8Array(mask.bitLength);
|
|
13419
12830
|
let lastInstructionOffset = 0;
|
|
13420
12831
|
for (let i = mask.bitLength - 1; i >= 0; i--) {
|
|
13421
12832
|
if (mask.isSet(i)) {
|
|
@@ -16950,7 +16361,7 @@ class HostCalls {
|
|
|
16950
16361
|
const regs = pvmInstance.getRegisters();
|
|
16951
16362
|
const maybeAddress = regs.getLowerU32(7);
|
|
16952
16363
|
const maybeLength = regs.getLowerU32(8);
|
|
16953
|
-
const result =
|
|
16364
|
+
const result = safeAllocUint8Array(maybeLength);
|
|
16954
16365
|
const startAddress = tryAsMemoryIndex(maybeAddress);
|
|
16955
16366
|
const loadResult = memory.loadInto(result, startAddress);
|
|
16956
16367
|
if (loadResult.isError) {
|
|
@@ -16978,8 +16389,9 @@ class HostCalls {
|
|
|
16978
16389
|
const index = tryAsHostCallIndex(hostCallIndex);
|
|
16979
16390
|
const hostCall = this.hostCalls.get(index);
|
|
16980
16391
|
const gasBefore = gas.get();
|
|
16981
|
-
|
|
16982
|
-
const
|
|
16392
|
+
// NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
|
|
16393
|
+
const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
|
|
16394
|
+
const underflow = gas.sub(basicGasCost);
|
|
16983
16395
|
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
16984
16396
|
if (underflow) {
|
|
16985
16397
|
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
@@ -16996,6 +16408,10 @@ class HostCalls {
|
|
|
16996
16408
|
status = Status.PANIC;
|
|
16997
16409
|
return this.getReturnValue(status, pvmInstance);
|
|
16998
16410
|
}
|
|
16411
|
+
if (result === PvmExecution.OOG) {
|
|
16412
|
+
status = Status.OOG;
|
|
16413
|
+
return this.getReturnValue(status, pvmInstance);
|
|
16414
|
+
}
|
|
16999
16415
|
if (result === undefined) {
|
|
17000
16416
|
pvmInstance.runProgram();
|
|
17001
16417
|
status = pvmInstance.getStatus();
|
|
@@ -17294,14 +16710,14 @@ class DebuggerAdapter {
|
|
|
17294
16710
|
const page = this.pvm.getMemoryPage(pageNumber);
|
|
17295
16711
|
if (page === null) {
|
|
17296
16712
|
// page wasn't allocated so we return an empty page
|
|
17297
|
-
return
|
|
16713
|
+
return safeAllocUint8Array(PAGE_SIZE$1);
|
|
17298
16714
|
}
|
|
17299
16715
|
if (page.length === PAGE_SIZE$1) {
|
|
17300
16716
|
// page was allocated and has a proper size so we can simply return it
|
|
17301
16717
|
return page;
|
|
17302
16718
|
}
|
|
17303
16719
|
// page was allocated but it is shorter than PAGE_SIZE so we have to extend it
|
|
17304
|
-
const fullPage =
|
|
16720
|
+
const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
|
|
17305
16721
|
fullPage.set(page);
|
|
17306
16722
|
return fullPage;
|
|
17307
16723
|
}
|
|
@@ -17405,7 +16821,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
17405
16821
|
extractCodeAndMetadata: extractCodeAndMetadata,
|
|
17406
16822
|
getServiceId: getServiceId,
|
|
17407
16823
|
getServiceIdOrCurrent: getServiceIdOrCurrent,
|
|
17408
|
-
hash: index$
|
|
16824
|
+
hash: index$o,
|
|
17409
16825
|
inspect: inspect,
|
|
17410
16826
|
instructionArgumentTypeMap: instructionArgumentTypeMap,
|
|
17411
16827
|
interpreter: index$7,
|
|
@@ -17427,10 +16843,10 @@ const ENTROPY_BYTES = 32;
|
|
|
17427
16843
|
*
|
|
17428
16844
|
* https://graypaper.fluffylabs.dev/#/579bd12/3b9a013b9a01
|
|
17429
16845
|
*/
|
|
17430
|
-
function fisherYatesShuffle(arr, entropy) {
|
|
16846
|
+
function fisherYatesShuffle(blake2b, arr, entropy) {
|
|
17431
16847
|
check `${entropy.length === ENTROPY_BYTES} Expected entropy of length ${ENTROPY_BYTES}, got ${entropy.length}`;
|
|
17432
16848
|
const n = arr.length;
|
|
17433
|
-
const randomNumbers = hashToNumberSequence(entropy, arr.length);
|
|
16849
|
+
const randomNumbers = hashToNumberSequence(blake2b, entropy, arr.length);
|
|
17434
16850
|
const result = new Array(n);
|
|
17435
16851
|
let itemsLeft = n;
|
|
17436
16852
|
for (let i = 0; i < n; i++) {
|
|
@@ -17443,13 +16859,13 @@ function fisherYatesShuffle(arr, entropy) {
|
|
|
17443
16859
|
}
|
|
17444
16860
|
return result;
|
|
17445
16861
|
}
|
|
17446
|
-
function hashToNumberSequence(entropy, length) {
|
|
16862
|
+
function hashToNumberSequence(blake2b, entropy, length) {
|
|
17447
16863
|
const result = new Array(length);
|
|
17448
|
-
const randomBytes =
|
|
16864
|
+
const randomBytes = safeAllocUint8Array(ENTROPY_BYTES + 4);
|
|
17449
16865
|
randomBytes.set(entropy.raw);
|
|
17450
16866
|
for (let i = 0; i < length; i++) {
|
|
17451
16867
|
randomBytes.set(u32AsLeBytes(tryAsU32(Math.floor(i / 8))), ENTROPY_BYTES);
|
|
17452
|
-
const newHash = hashBytes(randomBytes);
|
|
16868
|
+
const newHash = blake2b.hashBytes(randomBytes);
|
|
17453
16869
|
const numberStartIndex = (4 * i) % 32;
|
|
17454
16870
|
const numberEndIndex = numberStartIndex + 4;
|
|
17455
16871
|
const number = leBytesAsU32(newHash.raw.subarray(numberStartIndex, numberEndIndex)) >>> 0;
|
|
@@ -17563,8 +16979,7 @@ const availabilityAssignmentFromJson = json.object({
|
|
|
17563
16979
|
report: workReportFromJson,
|
|
17564
16980
|
timeout: "number",
|
|
17565
16981
|
}, ({ report, timeout }) => {
|
|
17566
|
-
|
|
17567
|
-
return AvailabilityAssignment.create({ workReport: new WithHash(workReportHash, report), timeout });
|
|
16982
|
+
return AvailabilityAssignment.create({ workReport: report, timeout });
|
|
17568
16983
|
});
|
|
17569
16984
|
|
|
17570
16985
|
const disputesRecordsFromJson = json.object({
|
|
@@ -17870,11 +17285,11 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
17870
17285
|
class TransitionHasher {
|
|
17871
17286
|
context;
|
|
17872
17287
|
keccakHasher;
|
|
17873
|
-
|
|
17874
|
-
constructor(context, keccakHasher,
|
|
17288
|
+
blake2b;
|
|
17289
|
+
constructor(context, keccakHasher, blake2b) {
|
|
17875
17290
|
this.context = context;
|
|
17876
17291
|
this.keccakHasher = keccakHasher;
|
|
17877
|
-
this.
|
|
17292
|
+
this.blake2b = blake2b;
|
|
17878
17293
|
}
|
|
17879
17294
|
/** Concatenates two hashes and hash this concatenation */
|
|
17880
17295
|
hashConcat(a, b) {
|
|
@@ -17885,7 +17300,7 @@ class TransitionHasher {
|
|
|
17885
17300
|
}
|
|
17886
17301
|
/** Creates hash from the block header view */
|
|
17887
17302
|
header(header) {
|
|
17888
|
-
return new WithHash(hashBytes(header.encoded()
|
|
17303
|
+
return new WithHash(this.blake2b.hashBytes(header.encoded()).asOpaque(), header);
|
|
17889
17304
|
}
|
|
17890
17305
|
/**
|
|
17891
17306
|
* Merkle commitment of the extrinsic data
|
|
@@ -17898,7 +17313,7 @@ class TransitionHasher {
|
|
|
17898
17313
|
.view()
|
|
17899
17314
|
.map((g) => g.view())
|
|
17900
17315
|
.map((guarantee) => {
|
|
17901
|
-
const reportHash = hashBytes(guarantee.report.encoded()
|
|
17316
|
+
const reportHash = this.blake2b.hashBytes(guarantee.report.encoded()).asOpaque();
|
|
17902
17317
|
return BytesBlob.blobFromParts([
|
|
17903
17318
|
reportHash.raw,
|
|
17904
17319
|
guarantee.slot.encoded().raw,
|
|
@@ -17906,13 +17321,13 @@ class TransitionHasher {
|
|
|
17906
17321
|
]);
|
|
17907
17322
|
});
|
|
17908
17323
|
const guaranteeBlob = Encoder.encodeObject(codec$1.sequenceVarLen(dumpCodec), guarantees, this.context);
|
|
17909
|
-
const et = hashBytes(extrinsicView.tickets.encoded()
|
|
17910
|
-
const ep = hashBytes(extrinsicView.preimages.encoded()
|
|
17911
|
-
const eg = hashBytes(guaranteeBlob
|
|
17912
|
-
const ea = hashBytes(extrinsicView.assurances.encoded()
|
|
17913
|
-
const ed = hashBytes(extrinsicView.disputes.encoded()
|
|
17324
|
+
const et = this.blake2b.hashBytes(extrinsicView.tickets.encoded()).asOpaque();
|
|
17325
|
+
const ep = this.blake2b.hashBytes(extrinsicView.preimages.encoded()).asOpaque();
|
|
17326
|
+
const eg = this.blake2b.hashBytes(guaranteeBlob).asOpaque();
|
|
17327
|
+
const ea = this.blake2b.hashBytes(extrinsicView.assurances.encoded()).asOpaque();
|
|
17328
|
+
const ed = this.blake2b.hashBytes(extrinsicView.disputes.encoded()).asOpaque();
|
|
17914
17329
|
const encoded = BytesBlob.blobFromParts([et.raw, ep.raw, eg.raw, ea.raw, ed.raw]);
|
|
17915
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17330
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), extrinsicView, encoded);
|
|
17916
17331
|
}
|
|
17917
17332
|
/** Creates hash for given WorkPackage */
|
|
17918
17333
|
workPackage(workPackage) {
|
|
@@ -17921,7 +17336,7 @@ class TransitionHasher {
|
|
|
17921
17336
|
encode(codec, data) {
|
|
17922
17337
|
// TODO [ToDr] Use already allocated encoding destination and hash bytes from some arena.
|
|
17923
17338
|
const encoded = Encoder.encodeObject(codec, data, this.context);
|
|
17924
|
-
return new WithHashAndBytes(hashBytes(encoded
|
|
17339
|
+
return new WithHashAndBytes(this.blake2b.hashBytes(encoded).asOpaque(), data, encoded);
|
|
17925
17340
|
}
|
|
17926
17341
|
}
|
|
17927
17342
|
|
|
@@ -17934,8 +17349,10 @@ var PreimagesErrorCode;
|
|
|
17934
17349
|
// TODO [SeKo] consider whether this module is the right place to remove expired preimages
|
|
17935
17350
|
class Preimages {
|
|
17936
17351
|
state;
|
|
17937
|
-
|
|
17352
|
+
blake2b;
|
|
17353
|
+
constructor(state, blake2b) {
|
|
17938
17354
|
this.state = state;
|
|
17355
|
+
this.blake2b = blake2b;
|
|
17939
17356
|
}
|
|
17940
17357
|
integrate(input) {
|
|
17941
17358
|
// make sure lookup extrinsics are sorted and unique
|
|
@@ -17958,7 +17375,7 @@ class Preimages {
|
|
|
17958
17375
|
// select preimages for integration
|
|
17959
17376
|
for (const preimage of preimages) {
|
|
17960
17377
|
const { requester, blob } = preimage;
|
|
17961
|
-
const hash = hashBytes(blob).asOpaque();
|
|
17378
|
+
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
17962
17379
|
const service = this.state.getService(requester);
|
|
17963
17380
|
if (service === null) {
|
|
17964
17381
|
return Result$1.error(PreimagesErrorCode.AccountNotFound);
|
|
@@ -17983,146 +17400,11 @@ class Preimages {
|
|
|
17983
17400
|
}
|
|
17984
17401
|
}
|
|
17985
17402
|
|
|
17986
|
-
class Missing {
|
|
17987
|
-
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
17988
|
-
gasCost = tryAsSmallGas(10);
|
|
17989
|
-
currentServiceId = CURRENT_SERVICE_ID;
|
|
17990
|
-
tracedRegisters = traceRegisters(7);
|
|
17991
|
-
execute(_gas, regs, _memory) {
|
|
17992
|
-
regs.set(7, HostCallResult.WHAT);
|
|
17993
|
-
return Promise.resolve(undefined);
|
|
17994
|
-
}
|
|
17995
|
-
}
|
|
17996
|
-
|
|
17997
|
-
var ServiceExecutorError;
|
|
17998
|
-
(function (ServiceExecutorError) {
|
|
17999
|
-
ServiceExecutorError[ServiceExecutorError["NoLookup"] = 0] = "NoLookup";
|
|
18000
|
-
ServiceExecutorError[ServiceExecutorError["NoState"] = 1] = "NoState";
|
|
18001
|
-
ServiceExecutorError[ServiceExecutorError["NoServiceCode"] = 2] = "NoServiceCode";
|
|
18002
|
-
ServiceExecutorError[ServiceExecutorError["ServiceCodeMismatch"] = 3] = "ServiceCodeMismatch";
|
|
18003
|
-
})(ServiceExecutorError || (ServiceExecutorError = {}));
|
|
18004
|
-
class WorkPackageExecutor {
|
|
18005
|
-
blocks;
|
|
18006
|
-
state;
|
|
18007
|
-
hasher;
|
|
18008
|
-
constructor(blocks, state, hasher) {
|
|
18009
|
-
this.blocks = blocks;
|
|
18010
|
-
this.state = state;
|
|
18011
|
-
this.hasher = hasher;
|
|
18012
|
-
}
|
|
18013
|
-
// TODO [ToDr] this while thing should be triple-checked with the GP.
|
|
18014
|
-
// I'm currently implementing some dirty version for the demo.
|
|
18015
|
-
async executeWorkPackage(pack) {
|
|
18016
|
-
const headerHash = pack.context.lookupAnchor;
|
|
18017
|
-
// execute authorisation first or is it already executed and we just need to check it?
|
|
18018
|
-
const authExec = this.getServiceExecutor(
|
|
18019
|
-
// TODO [ToDr] should this be anchor or lookupAnchor?
|
|
18020
|
-
headerHash, pack.authCodeHost, pack.authCodeHash);
|
|
18021
|
-
if (authExec.isError) {
|
|
18022
|
-
// TODO [ToDr] most likely shouldn't be throw.
|
|
18023
|
-
throw new Error(`Could not get authorization executor: ${authExec.error}`);
|
|
18024
|
-
}
|
|
18025
|
-
const pvm = authExec.ok;
|
|
18026
|
-
const authGas = tryAsGas(15000n);
|
|
18027
|
-
const result = await pvm.run(pack.parametrization, authGas);
|
|
18028
|
-
if (!result.isEqualTo(pack.authorization)) {
|
|
18029
|
-
throw new Error("Authorization is invalid.");
|
|
18030
|
-
}
|
|
18031
|
-
const results = [];
|
|
18032
|
-
for (const item of pack.items) {
|
|
18033
|
-
const exec = this.getServiceExecutor(headerHash, item.service, item.codeHash);
|
|
18034
|
-
if (exec.isError) {
|
|
18035
|
-
throw new Error(`Could not get item executor: ${exec.error}`);
|
|
18036
|
-
}
|
|
18037
|
-
const pvm = exec.ok;
|
|
18038
|
-
const gasRatio = tryAsServiceGas(3000n);
|
|
18039
|
-
const ret = await pvm.run(item.payload, tryAsGas(item.refineGasLimit)); // or accumulateGasLimit?
|
|
18040
|
-
results.push(WorkResult.create({
|
|
18041
|
-
serviceId: item.service,
|
|
18042
|
-
codeHash: item.codeHash,
|
|
18043
|
-
payloadHash: hashBytes(item.payload),
|
|
18044
|
-
gas: gasRatio,
|
|
18045
|
-
result: new WorkExecResult(WorkExecResultKind.ok, ret),
|
|
18046
|
-
load: WorkRefineLoad.create({
|
|
18047
|
-
gasUsed: tryAsServiceGas(5),
|
|
18048
|
-
importedSegments: tryAsU32(0),
|
|
18049
|
-
exportedSegments: tryAsU32(0),
|
|
18050
|
-
extrinsicSize: tryAsU32(0),
|
|
18051
|
-
extrinsicCount: tryAsU32(0),
|
|
18052
|
-
}),
|
|
18053
|
-
}));
|
|
18054
|
-
}
|
|
18055
|
-
const workPackage = this.hasher.workPackage(pack);
|
|
18056
|
-
const workPackageSpec = WorkPackageSpec.create({
|
|
18057
|
-
hash: workPackage.hash,
|
|
18058
|
-
length: tryAsU32(workPackage.encoded.length),
|
|
18059
|
-
erasureRoot: Bytes.zero(HASH_SIZE),
|
|
18060
|
-
exportsRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
18061
|
-
exportsCount: tryAsU16(0),
|
|
18062
|
-
});
|
|
18063
|
-
const coreIndex = tryAsCoreIndex(0);
|
|
18064
|
-
const authorizerHash = Bytes.fill(HASH_SIZE, 5).asOpaque();
|
|
18065
|
-
const workResults = FixedSizeArray.new(results, tryAsWorkItemsCount(results.length));
|
|
18066
|
-
return Promise.resolve(WorkReport.create({
|
|
18067
|
-
workPackageSpec,
|
|
18068
|
-
context: pack.context,
|
|
18069
|
-
coreIndex,
|
|
18070
|
-
authorizerHash,
|
|
18071
|
-
authorizationOutput: pack.authorization,
|
|
18072
|
-
segmentRootLookup: [],
|
|
18073
|
-
results: workResults,
|
|
18074
|
-
authorizationGasUsed: tryAsServiceGas(0),
|
|
18075
|
-
}));
|
|
18076
|
-
}
|
|
18077
|
-
getServiceExecutor(lookupAnchor, serviceId, expectedCodeHash) {
|
|
18078
|
-
const header = this.blocks.getHeader(lookupAnchor);
|
|
18079
|
-
if (header === null) {
|
|
18080
|
-
return Result$1.error(ServiceExecutorError.NoLookup);
|
|
18081
|
-
}
|
|
18082
|
-
const state = this.state.getState(lookupAnchor);
|
|
18083
|
-
if (state === null) {
|
|
18084
|
-
return Result$1.error(ServiceExecutorError.NoState);
|
|
18085
|
-
}
|
|
18086
|
-
const service = state.getService(serviceId);
|
|
18087
|
-
const serviceCodeHash = service?.getInfo().codeHash ?? null;
|
|
18088
|
-
if (serviceCodeHash === null) {
|
|
18089
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18090
|
-
}
|
|
18091
|
-
if (!serviceCodeHash.isEqualTo(expectedCodeHash)) {
|
|
18092
|
-
return Result$1.error(ServiceExecutorError.ServiceCodeMismatch);
|
|
18093
|
-
}
|
|
18094
|
-
const serviceCode = service?.getPreimage(serviceCodeHash.asOpaque()) ?? null;
|
|
18095
|
-
if (serviceCode === null) {
|
|
18096
|
-
return Result$1.error(ServiceExecutorError.NoServiceCode);
|
|
18097
|
-
}
|
|
18098
|
-
return Result$1.ok(new PvmExecutor(serviceCode));
|
|
18099
|
-
}
|
|
18100
|
-
}
|
|
18101
|
-
class PvmExecutor {
|
|
18102
|
-
serviceCode;
|
|
18103
|
-
pvm;
|
|
18104
|
-
hostCalls = new HostCallsManager({ missing: new Missing() });
|
|
18105
|
-
pvmInstanceManager = new InterpreterInstanceManager(4);
|
|
18106
|
-
constructor(serviceCode) {
|
|
18107
|
-
this.serviceCode = serviceCode;
|
|
18108
|
-
this.pvm = new HostCalls(this.pvmInstanceManager, this.hostCalls);
|
|
18109
|
-
}
|
|
18110
|
-
async run(args, gas) {
|
|
18111
|
-
const program = Program.fromSpi(this.serviceCode.raw, args.raw, true);
|
|
18112
|
-
const result = await this.pvm.runProgram(program.code, 5, gas, program.registers, program.memory);
|
|
18113
|
-
if (result.hasMemorySlice()) {
|
|
18114
|
-
return BytesBlob.blobFrom(result.memorySlice);
|
|
18115
|
-
}
|
|
18116
|
-
return BytesBlob.empty();
|
|
18117
|
-
}
|
|
18118
|
-
}
|
|
18119
|
-
|
|
18120
17403
|
var index = /*#__PURE__*/Object.freeze({
|
|
18121
17404
|
__proto__: null,
|
|
18122
17405
|
Preimages: Preimages,
|
|
18123
17406
|
get PreimagesErrorCode () { return PreimagesErrorCode; },
|
|
18124
|
-
TransitionHasher: TransitionHasher
|
|
18125
|
-
WorkPackageExecutor: WorkPackageExecutor
|
|
17407
|
+
TransitionHasher: TransitionHasher
|
|
18126
17408
|
});
|
|
18127
17409
|
|
|
18128
|
-
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$
|
|
17410
|
+
export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$p as crypto, index$d as database, index$c as erasure_coding, index$a as fuzz_proto, index$o as hash, index$9 as jam_host_calls, index$k as json_parser, index$i as logger, index$8 as mmr, index$r as numbers, index$t as ordering, index$3 as pvm, index$6 as pvm_host_calls, index$7 as pvm_interpreter, index$4 as pvm_program, index$5 as pvm_spi_decoder, index$2 as shuffling, index$g as state, index$1 as state_json, index$e as state_merkleization, index as transition, index$f as trie, index$u as utils };
|