@waku/core 0.0.38 → 0.0.39-47a074f.0
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/bundle/index.js +90 -876
- package/bundle/lib/message/version_0.js +1 -1
- package/bundle/{version_0-CGLjyYN6.js → version_0-DV1Db0r-.js} +808 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/lib/connection_manager/connection_limiter.js +4 -5
- package/dist/lib/connection_manager/connection_limiter.js.map +1 -1
- package/dist/lib/connection_manager/network_monitor.js +2 -1
- package/dist/lib/connection_manager/network_monitor.js.map +1 -1
- package/dist/lib/message/version_0.d.ts +4 -0
- package/dist/lib/message/version_0.js +16 -0
- package/dist/lib/message/version_0.js.map +1 -1
- package/package.json +1 -125
- package/src/lib/connection_manager/connection_limiter.ts +8 -6
- package/src/lib/connection_manager/network_monitor.ts +2 -2
- package/src/lib/message/version_0.ts +20 -0
package/bundle/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as equals$2, c as coerce, b as base32, a as base58btc, d as base36,
|
|
2
|
-
export {
|
|
1
|
+
import { e as equals$2, c as coerce, b as base32, a as base58btc, d as base36, s as sha256$1, f as concat$1, u as utf8ToBytes, v as version_0, g as allocUnsafe, h as alloc, i as encodingLength$1, j as encode$3, k as decode$4, L as Logger, F as FilterSubscribeRequest, l as FilterSubscribeResponse$1, M as MessagePush, P as PushRpc$1, m as PushResponse, S as StoreQueryRequest$1, n as StoreQueryResponse$1, o as createEncoder, t as toString, p as fromString, q as hexToBytes, r as isBytes, w as abytes, x as bytesToHex, y as concatBytes, z as anumber, A as randomBytes, B as sha512, C as enumeration, D as message, E as encodeMessage, G as decodeMessage, H as Hash, I as ahash, J as toBytes, K as clean, N as aexists, O as sha256$2, Q as bases, R as base64url, T as encodeUint8Array, U as bytesToUtf8, W as WakuMetadataRequest, V as WakuMetadataResponse } from './version_0-DV1Db0r-.js';
|
|
2
|
+
export { X as createDecoder, Y as messageHash, Z as messageHashStr } from './version_0-DV1Db0r-.js';
|
|
3
3
|
|
|
4
4
|
/* eslint-disable */
|
|
5
5
|
var encode_1 = encode$2;
|
|
@@ -191,7 +191,7 @@ class Hasher {
|
|
|
191
191
|
function sha(name) {
|
|
192
192
|
return async (data) => new Uint8Array(await crypto.subtle.digest(name, data));
|
|
193
193
|
}
|
|
194
|
-
const sha256
|
|
194
|
+
const sha256 = from({
|
|
195
195
|
name: 'sha2-256',
|
|
196
196
|
code: 0x12,
|
|
197
197
|
encode: sha('SHA-256')
|
|
@@ -560,10 +560,6 @@ function encodeCID(version, code, multihash) {
|
|
|
560
560
|
}
|
|
561
561
|
const cidSymbol = Symbol.for('@ipld/js-cid/CID');
|
|
562
562
|
|
|
563
|
-
function isDefined(value) {
|
|
564
|
-
return Boolean(value);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
563
|
const MB = 1024 ** 2;
|
|
568
564
|
const SIZE_CAP_IN_MB = 1;
|
|
569
565
|
/**
|
|
@@ -581,714 +577,88 @@ async function isMessageSizeUnderCap(encoder, message) {
|
|
|
581
577
|
}
|
|
582
578
|
const isWireSizeUnderCap = (buf) => buf.length / MB <= SIZE_CAP_IN_MB;
|
|
583
579
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* Utilities for hex, bytes, CSPRNG.
|
|
588
|
-
* @module
|
|
589
|
-
*/
|
|
590
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
591
|
-
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
|
592
|
-
// node.js versions earlier than v19 don't declare it in global scope.
|
|
593
|
-
// For node.js, package.json#exports field mapping rewrites import
|
|
594
|
-
// from `crypto` to `cryptoNode`, which imports native module.
|
|
595
|
-
// Makes the utils un-importable in browsers without a bundler.
|
|
596
|
-
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
|
597
|
-
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
598
|
-
function isBytes(a) {
|
|
599
|
-
return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
|
|
600
|
-
}
|
|
601
|
-
/** Asserts something is positive integer. */
|
|
602
|
-
function anumber(n) {
|
|
603
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
604
|
-
throw new Error('positive integer expected, got ' + n);
|
|
605
|
-
}
|
|
606
|
-
/** Asserts something is Uint8Array. */
|
|
607
|
-
function abytes(b, ...lengths) {
|
|
608
|
-
if (!isBytes(b))
|
|
609
|
-
throw new Error('Uint8Array expected');
|
|
610
|
-
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
611
|
-
throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
|
|
612
|
-
}
|
|
613
|
-
/** Asserts something is hash */
|
|
614
|
-
function ahash(h) {
|
|
615
|
-
if (typeof h !== 'function' || typeof h.create !== 'function')
|
|
616
|
-
throw new Error('Hash should be wrapped by utils.createHasher');
|
|
617
|
-
anumber(h.outputLen);
|
|
618
|
-
anumber(h.blockLen);
|
|
619
|
-
}
|
|
620
|
-
/** Asserts a hash instance has not been destroyed / finished */
|
|
621
|
-
function aexists(instance, checkFinished = true) {
|
|
622
|
-
if (instance.destroyed)
|
|
623
|
-
throw new Error('Hash instance has been destroyed');
|
|
624
|
-
if (checkFinished && instance.finished)
|
|
625
|
-
throw new Error('Hash#digest() has already been called');
|
|
626
|
-
}
|
|
627
|
-
/** Asserts output is properly-sized byte array */
|
|
628
|
-
function aoutput(out, instance) {
|
|
629
|
-
abytes(out);
|
|
630
|
-
const min = instance.outputLen;
|
|
631
|
-
if (out.length < min) {
|
|
632
|
-
throw new Error('digestInto() expects output buffer of length at least ' + min);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
636
|
-
function clean(...arrays) {
|
|
637
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
638
|
-
arrays[i].fill(0);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
/** Create DataView of an array for easy byte-level manipulation. */
|
|
642
|
-
function createView(arr) {
|
|
643
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
644
|
-
}
|
|
645
|
-
/** The rotate right (circular right shift) operation for uint32 */
|
|
646
|
-
function rotr(word, shift) {
|
|
647
|
-
return (word << (32 - shift)) | (word >>> shift);
|
|
648
|
-
}
|
|
649
|
-
// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
|
|
650
|
-
const hasHexBuiltin = /* @__PURE__ */ (() =>
|
|
651
|
-
// @ts-ignore
|
|
652
|
-
typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
|
|
653
|
-
// Array where index 0xf0 (240) is mapped to string 'f0'
|
|
654
|
-
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
|
|
655
|
-
/**
|
|
656
|
-
* Convert byte array to hex string. Uses built-in function, when available.
|
|
657
|
-
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
658
|
-
*/
|
|
659
|
-
function bytesToHex$1(bytes) {
|
|
660
|
-
abytes(bytes);
|
|
661
|
-
// @ts-ignore
|
|
662
|
-
if (hasHexBuiltin)
|
|
663
|
-
return bytes.toHex();
|
|
664
|
-
// pre-caching improves the speed 6x
|
|
665
|
-
let hex = '';
|
|
666
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
667
|
-
hex += hexes[bytes[i]];
|
|
668
|
-
}
|
|
669
|
-
return hex;
|
|
670
|
-
}
|
|
671
|
-
// We use optimized technique to convert hex string to byte array
|
|
672
|
-
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
673
|
-
function asciiToBase16(ch) {
|
|
674
|
-
if (ch >= asciis._0 && ch <= asciis._9)
|
|
675
|
-
return ch - asciis._0; // '2' => 50-48
|
|
676
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
677
|
-
return ch - (asciis.A - 10); // 'B' => 66-(65-10)
|
|
678
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
679
|
-
return ch - (asciis.a - 10); // 'b' => 98-(97-10)
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Convert hex string to byte array. Uses built-in function, when available.
|
|
684
|
-
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
685
|
-
*/
|
|
686
|
-
function hexToBytes(hex) {
|
|
687
|
-
if (typeof hex !== 'string')
|
|
688
|
-
throw new Error('hex string expected, got ' + typeof hex);
|
|
689
|
-
// @ts-ignore
|
|
690
|
-
if (hasHexBuiltin)
|
|
691
|
-
return Uint8Array.fromHex(hex);
|
|
692
|
-
const hl = hex.length;
|
|
693
|
-
const al = hl / 2;
|
|
694
|
-
if (hl % 2)
|
|
695
|
-
throw new Error('hex string expected, got unpadded hex of length ' + hl);
|
|
696
|
-
const array = new Uint8Array(al);
|
|
697
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
698
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
699
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
700
|
-
if (n1 === undefined || n2 === undefined) {
|
|
701
|
-
const char = hex[hi] + hex[hi + 1];
|
|
702
|
-
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
703
|
-
}
|
|
704
|
-
array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
|
|
705
|
-
}
|
|
706
|
-
return array;
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Converts string to bytes using UTF8 encoding.
|
|
710
|
-
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
|
711
|
-
*/
|
|
712
|
-
function utf8ToBytes$1(str) {
|
|
713
|
-
if (typeof str !== 'string')
|
|
714
|
-
throw new Error('string expected');
|
|
715
|
-
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
716
|
-
}
|
|
717
|
-
/**
|
|
718
|
-
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
719
|
-
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
720
|
-
* Keep in mind for future mutable operations.
|
|
721
|
-
*/
|
|
722
|
-
function toBytes(data) {
|
|
723
|
-
if (typeof data === 'string')
|
|
724
|
-
data = utf8ToBytes$1(data);
|
|
725
|
-
abytes(data);
|
|
726
|
-
return data;
|
|
727
|
-
}
|
|
728
|
-
/** Copies several Uint8Arrays into one. */
|
|
729
|
-
function concatBytes(...arrays) {
|
|
730
|
-
let sum = 0;
|
|
731
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
732
|
-
const a = arrays[i];
|
|
733
|
-
abytes(a);
|
|
734
|
-
sum += a.length;
|
|
735
|
-
}
|
|
736
|
-
const res = new Uint8Array(sum);
|
|
737
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
738
|
-
const a = arrays[i];
|
|
739
|
-
res.set(a, pad);
|
|
740
|
-
pad += a.length;
|
|
741
|
-
}
|
|
742
|
-
return res;
|
|
743
|
-
}
|
|
744
|
-
/** For runtime check if class implements interface */
|
|
745
|
-
class Hash {
|
|
746
|
-
}
|
|
747
|
-
/** Wraps hash function, creating an interface on top of it */
|
|
748
|
-
function createHasher(hashCons) {
|
|
749
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
750
|
-
const tmp = hashCons();
|
|
751
|
-
hashC.outputLen = tmp.outputLen;
|
|
752
|
-
hashC.blockLen = tmp.blockLen;
|
|
753
|
-
hashC.create = () => hashCons();
|
|
754
|
-
return hashC;
|
|
755
|
-
}
|
|
756
|
-
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
757
|
-
function randomBytes(bytesLength = 32) {
|
|
758
|
-
if (crypto$1 && typeof crypto$1.getRandomValues === 'function') {
|
|
759
|
-
return crypto$1.getRandomValues(new Uint8Array(bytesLength));
|
|
760
|
-
}
|
|
761
|
-
// Legacy Node.js compatibility
|
|
762
|
-
if (crypto$1 && typeof crypto$1.randomBytes === 'function') {
|
|
763
|
-
return Uint8Array.from(crypto$1.randomBytes(bytesLength));
|
|
764
|
-
}
|
|
765
|
-
throw new Error('crypto.getRandomValues must be defined');
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
/**
|
|
769
|
-
* Internal Merkle-Damgard hash utils.
|
|
770
|
-
* @module
|
|
771
|
-
*/
|
|
772
|
-
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
|
773
|
-
function setBigUint64(view, byteOffset, value, isLE) {
|
|
774
|
-
if (typeof view.setBigUint64 === 'function')
|
|
775
|
-
return view.setBigUint64(byteOffset, value, isLE);
|
|
776
|
-
const _32n = BigInt(32);
|
|
777
|
-
const _u32_max = BigInt(0xffffffff);
|
|
778
|
-
const wh = Number((value >> _32n) & _u32_max);
|
|
779
|
-
const wl = Number(value & _u32_max);
|
|
780
|
-
const h = isLE ? 4 : 0;
|
|
781
|
-
const l = isLE ? 0 : 4;
|
|
782
|
-
view.setUint32(byteOffset + h, wh, isLE);
|
|
783
|
-
view.setUint32(byteOffset + l, wl, isLE);
|
|
784
|
-
}
|
|
785
|
-
/** Choice: a ? b : c */
|
|
786
|
-
function Chi(a, b, c) {
|
|
787
|
-
return (a & b) ^ (~a & c);
|
|
788
|
-
}
|
|
789
|
-
/** Majority function, true if any two inputs is true. */
|
|
790
|
-
function Maj(a, b, c) {
|
|
791
|
-
return (a & b) ^ (a & c) ^ (b & c);
|
|
792
|
-
}
|
|
793
|
-
/**
|
|
794
|
-
* Merkle-Damgard hash construction base class.
|
|
795
|
-
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
796
|
-
*/
|
|
797
|
-
class HashMD extends Hash {
|
|
798
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
799
|
-
super();
|
|
800
|
-
this.finished = false;
|
|
801
|
-
this.length = 0;
|
|
802
|
-
this.pos = 0;
|
|
803
|
-
this.destroyed = false;
|
|
804
|
-
this.blockLen = blockLen;
|
|
805
|
-
this.outputLen = outputLen;
|
|
806
|
-
this.padOffset = padOffset;
|
|
807
|
-
this.isLE = isLE;
|
|
808
|
-
this.buffer = new Uint8Array(blockLen);
|
|
809
|
-
this.view = createView(this.buffer);
|
|
810
|
-
}
|
|
811
|
-
update(data) {
|
|
812
|
-
aexists(this);
|
|
813
|
-
data = toBytes(data);
|
|
814
|
-
abytes(data);
|
|
815
|
-
const { view, buffer, blockLen } = this;
|
|
816
|
-
const len = data.length;
|
|
817
|
-
for (let pos = 0; pos < len;) {
|
|
818
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
819
|
-
// Fast path: we have at least one block in input, cast it to view and process
|
|
820
|
-
if (take === blockLen) {
|
|
821
|
-
const dataView = createView(data);
|
|
822
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
823
|
-
this.process(dataView, pos);
|
|
824
|
-
continue;
|
|
825
|
-
}
|
|
826
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
827
|
-
this.pos += take;
|
|
828
|
-
pos += take;
|
|
829
|
-
if (this.pos === blockLen) {
|
|
830
|
-
this.process(view, 0);
|
|
831
|
-
this.pos = 0;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
this.length += data.length;
|
|
835
|
-
this.roundClean();
|
|
836
|
-
return this;
|
|
837
|
-
}
|
|
838
|
-
digestInto(out) {
|
|
839
|
-
aexists(this);
|
|
840
|
-
aoutput(out, this);
|
|
841
|
-
this.finished = true;
|
|
842
|
-
// Padding
|
|
843
|
-
// We can avoid allocation of buffer for padding completely if it
|
|
844
|
-
// was previously not allocated here. But it won't change performance.
|
|
845
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
846
|
-
let { pos } = this;
|
|
847
|
-
// append the bit '1' to the message
|
|
848
|
-
buffer[pos++] = 0b10000000;
|
|
849
|
-
clean(this.buffer.subarray(pos));
|
|
850
|
-
// we have less than padOffset left in buffer, so we cannot put length in
|
|
851
|
-
// current block, need process it and pad again
|
|
852
|
-
if (this.padOffset > blockLen - pos) {
|
|
853
|
-
this.process(view, 0);
|
|
854
|
-
pos = 0;
|
|
855
|
-
}
|
|
856
|
-
// Pad until full block byte with zeros
|
|
857
|
-
for (let i = pos; i < blockLen; i++)
|
|
858
|
-
buffer[i] = 0;
|
|
859
|
-
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
860
|
-
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
861
|
-
// So we just write lowest 64 bits of that value.
|
|
862
|
-
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
863
|
-
this.process(view, 0);
|
|
864
|
-
const oview = createView(out);
|
|
865
|
-
const len = this.outputLen;
|
|
866
|
-
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
|
867
|
-
if (len % 4)
|
|
868
|
-
throw new Error('_sha2: outputLen should be aligned to 32bit');
|
|
869
|
-
const outLen = len / 4;
|
|
870
|
-
const state = this.get();
|
|
871
|
-
if (outLen > state.length)
|
|
872
|
-
throw new Error('_sha2: outputLen bigger than state');
|
|
873
|
-
for (let i = 0; i < outLen; i++)
|
|
874
|
-
oview.setUint32(4 * i, state[i], isLE);
|
|
875
|
-
}
|
|
876
|
-
digest() {
|
|
877
|
-
const { buffer, outputLen } = this;
|
|
878
|
-
this.digestInto(buffer);
|
|
879
|
-
const res = buffer.slice(0, outputLen);
|
|
880
|
-
this.destroy();
|
|
881
|
-
return res;
|
|
882
|
-
}
|
|
883
|
-
_cloneInto(to) {
|
|
884
|
-
to || (to = new this.constructor());
|
|
885
|
-
to.set(...this.get());
|
|
886
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
887
|
-
to.destroyed = destroyed;
|
|
888
|
-
to.finished = finished;
|
|
889
|
-
to.length = length;
|
|
890
|
-
to.pos = pos;
|
|
891
|
-
if (length % blockLen)
|
|
892
|
-
to.buffer.set(buffer);
|
|
893
|
-
return to;
|
|
894
|
-
}
|
|
895
|
-
clone() {
|
|
896
|
-
return this._cloneInto();
|
|
897
|
-
}
|
|
580
|
+
function isAutoSharding(config) {
|
|
581
|
+
return "clusterId" in config && "numShardsInCluster" in config;
|
|
898
582
|
}
|
|
899
|
-
/**
|
|
900
|
-
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
901
|
-
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
902
|
-
*/
|
|
903
|
-
/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
|
|
904
|
-
const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
905
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
906
|
-
]);
|
|
907
|
-
/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
|
|
908
|
-
const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
909
|
-
0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,
|
|
910
|
-
0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,
|
|
911
|
-
]);
|
|
912
|
-
|
|
913
|
-
/**
|
|
914
|
-
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
915
|
-
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
916
|
-
* @module
|
|
917
|
-
*/
|
|
918
|
-
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
919
|
-
const _32n = /* @__PURE__ */ BigInt(32);
|
|
920
|
-
function fromBig(n, le = false) {
|
|
921
|
-
if (le)
|
|
922
|
-
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
923
|
-
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
924
|
-
}
|
|
925
|
-
function split(lst, le = false) {
|
|
926
|
-
const len = lst.length;
|
|
927
|
-
let Ah = new Uint32Array(len);
|
|
928
|
-
let Al = new Uint32Array(len);
|
|
929
|
-
for (let i = 0; i < len; i++) {
|
|
930
|
-
const { h, l } = fromBig(lst[i], le);
|
|
931
|
-
[Ah[i], Al[i]] = [h, l];
|
|
932
|
-
}
|
|
933
|
-
return [Ah, Al];
|
|
934
|
-
}
|
|
935
|
-
// for Shift in [0, 32)
|
|
936
|
-
const shrSH = (h, _l, s) => h >>> s;
|
|
937
|
-
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
938
|
-
// Right rotate for Shift in [1, 32)
|
|
939
|
-
const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
|
|
940
|
-
const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
941
|
-
// Right rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
942
|
-
const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
|
|
943
|
-
const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
|
|
944
|
-
// JS uses 32-bit signed integers for bitwise operations which means we cannot
|
|
945
|
-
// simple take carry out of low bit sum by shift, we need to use division.
|
|
946
|
-
function add(Ah, Al, Bh, Bl) {
|
|
947
|
-
const l = (Al >>> 0) + (Bl >>> 0);
|
|
948
|
-
return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
|
|
949
|
-
}
|
|
950
|
-
// Addition with more than 2 elements
|
|
951
|
-
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
952
|
-
const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
|
|
953
|
-
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
954
|
-
const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
|
|
955
|
-
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
956
|
-
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
|
|
957
583
|
|
|
584
|
+
const formatPubsubTopic = (clusterId, shard) => {
|
|
585
|
+
return `/waku/2/rs/${clusterId}/${shard}`;
|
|
586
|
+
};
|
|
958
587
|
/**
|
|
959
|
-
*
|
|
960
|
-
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
|
961
|
-
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
|
962
|
-
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
963
|
-
* @module
|
|
588
|
+
* @deprecated will be removed
|
|
964
589
|
*/
|
|
590
|
+
const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
|
|
591
|
+
const parts = pubsubTopics.split("/");
|
|
592
|
+
if (parts.length != 6 ||
|
|
593
|
+
parts[1] !== "waku" ||
|
|
594
|
+
parts[2] !== "2" ||
|
|
595
|
+
parts[3] !== "rs")
|
|
596
|
+
throw new Error("Invalid pubsub topic");
|
|
597
|
+
const clusterId = parseInt(parts[4]);
|
|
598
|
+
const shard = parseInt(parts[5]);
|
|
599
|
+
if (isNaN(clusterId) || isNaN(shard))
|
|
600
|
+
throw new Error("Invalid clusterId or shard");
|
|
601
|
+
return {
|
|
602
|
+
clusterId,
|
|
603
|
+
shard
|
|
604
|
+
};
|
|
605
|
+
};
|
|
965
606
|
/**
|
|
966
|
-
*
|
|
967
|
-
*
|
|
607
|
+
* Given a string, will throw an error if it is not formatted as a valid content topic for autosharding based on https://rfc.vac.dev/spec/51/
|
|
608
|
+
* @param contentTopic String to validate
|
|
609
|
+
* @returns Object with each content topic field as an attribute
|
|
968
610
|
*/
|
|
969
|
-
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
974
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
975
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
976
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
977
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
978
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
979
|
-
]);
|
|
980
|
-
/** Reusable temporary buffer. "W" comes straight from spec. */
|
|
981
|
-
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
982
|
-
class SHA256 extends HashMD {
|
|
983
|
-
constructor(outputLen = 32) {
|
|
984
|
-
super(64, outputLen, 8, false);
|
|
985
|
-
// We cannot use array here since array allows indexing by variable
|
|
986
|
-
// which means optimizer/compiler cannot use registers.
|
|
987
|
-
this.A = SHA256_IV[0] | 0;
|
|
988
|
-
this.B = SHA256_IV[1] | 0;
|
|
989
|
-
this.C = SHA256_IV[2] | 0;
|
|
990
|
-
this.D = SHA256_IV[3] | 0;
|
|
991
|
-
this.E = SHA256_IV[4] | 0;
|
|
992
|
-
this.F = SHA256_IV[5] | 0;
|
|
993
|
-
this.G = SHA256_IV[6] | 0;
|
|
994
|
-
this.H = SHA256_IV[7] | 0;
|
|
995
|
-
}
|
|
996
|
-
get() {
|
|
997
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
998
|
-
return [A, B, C, D, E, F, G, H];
|
|
999
|
-
}
|
|
1000
|
-
// prettier-ignore
|
|
1001
|
-
set(A, B, C, D, E, F, G, H) {
|
|
1002
|
-
this.A = A | 0;
|
|
1003
|
-
this.B = B | 0;
|
|
1004
|
-
this.C = C | 0;
|
|
1005
|
-
this.D = D | 0;
|
|
1006
|
-
this.E = E | 0;
|
|
1007
|
-
this.F = F | 0;
|
|
1008
|
-
this.G = G | 0;
|
|
1009
|
-
this.H = H | 0;
|
|
1010
|
-
}
|
|
1011
|
-
process(view, offset) {
|
|
1012
|
-
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
|
1013
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
1014
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
1015
|
-
for (let i = 16; i < 64; i++) {
|
|
1016
|
-
const W15 = SHA256_W[i - 15];
|
|
1017
|
-
const W2 = SHA256_W[i - 2];
|
|
1018
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
|
|
1019
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
|
|
1020
|
-
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
|
1021
|
-
}
|
|
1022
|
-
// Compression function main loop, 64 rounds
|
|
1023
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
1024
|
-
for (let i = 0; i < 64; i++) {
|
|
1025
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
1026
|
-
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
1027
|
-
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
1028
|
-
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
|
1029
|
-
H = G;
|
|
1030
|
-
G = F;
|
|
1031
|
-
F = E;
|
|
1032
|
-
E = (D + T1) | 0;
|
|
1033
|
-
D = C;
|
|
1034
|
-
C = B;
|
|
1035
|
-
B = A;
|
|
1036
|
-
A = (T1 + T2) | 0;
|
|
1037
|
-
}
|
|
1038
|
-
// Add the compressed chunk to the current hash value
|
|
1039
|
-
A = (A + this.A) | 0;
|
|
1040
|
-
B = (B + this.B) | 0;
|
|
1041
|
-
C = (C + this.C) | 0;
|
|
1042
|
-
D = (D + this.D) | 0;
|
|
1043
|
-
E = (E + this.E) | 0;
|
|
1044
|
-
F = (F + this.F) | 0;
|
|
1045
|
-
G = (G + this.G) | 0;
|
|
1046
|
-
H = (H + this.H) | 0;
|
|
1047
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
1048
|
-
}
|
|
1049
|
-
roundClean() {
|
|
1050
|
-
clean(SHA256_W);
|
|
1051
|
-
}
|
|
1052
|
-
destroy() {
|
|
1053
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
1054
|
-
clean(this.buffer);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
// SHA2-512 is slower than sha256 in js because u64 operations are slow.
|
|
1058
|
-
// Round contants
|
|
1059
|
-
// First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409
|
|
1060
|
-
// prettier-ignore
|
|
1061
|
-
const K512 = /* @__PURE__ */ (() => split([
|
|
1062
|
-
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
|
|
1063
|
-
'0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
|
|
1064
|
-
'0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
|
|
1065
|
-
'0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
|
|
1066
|
-
'0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
|
|
1067
|
-
'0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
|
|
1068
|
-
'0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
|
|
1069
|
-
'0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
|
|
1070
|
-
'0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
|
|
1071
|
-
'0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
|
|
1072
|
-
'0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
|
|
1073
|
-
'0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
|
|
1074
|
-
'0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
|
|
1075
|
-
'0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
|
|
1076
|
-
'0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
|
|
1077
|
-
'0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
|
|
1078
|
-
'0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
|
|
1079
|
-
'0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
|
|
1080
|
-
'0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
|
|
1081
|
-
'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
|
|
1082
|
-
].map(n => BigInt(n))))();
|
|
1083
|
-
const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
1084
|
-
const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
1085
|
-
// Reusable temporary buffers
|
|
1086
|
-
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
1087
|
-
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
1088
|
-
class SHA512 extends HashMD {
|
|
1089
|
-
constructor(outputLen = 64) {
|
|
1090
|
-
super(128, outputLen, 16, false);
|
|
1091
|
-
// We cannot use array here since array allows indexing by variable
|
|
1092
|
-
// which means optimizer/compiler cannot use registers.
|
|
1093
|
-
// h -- high 32 bits, l -- low 32 bits
|
|
1094
|
-
this.Ah = SHA512_IV[0] | 0;
|
|
1095
|
-
this.Al = SHA512_IV[1] | 0;
|
|
1096
|
-
this.Bh = SHA512_IV[2] | 0;
|
|
1097
|
-
this.Bl = SHA512_IV[3] | 0;
|
|
1098
|
-
this.Ch = SHA512_IV[4] | 0;
|
|
1099
|
-
this.Cl = SHA512_IV[5] | 0;
|
|
1100
|
-
this.Dh = SHA512_IV[6] | 0;
|
|
1101
|
-
this.Dl = SHA512_IV[7] | 0;
|
|
1102
|
-
this.Eh = SHA512_IV[8] | 0;
|
|
1103
|
-
this.El = SHA512_IV[9] | 0;
|
|
1104
|
-
this.Fh = SHA512_IV[10] | 0;
|
|
1105
|
-
this.Fl = SHA512_IV[11] | 0;
|
|
1106
|
-
this.Gh = SHA512_IV[12] | 0;
|
|
1107
|
-
this.Gl = SHA512_IV[13] | 0;
|
|
1108
|
-
this.Hh = SHA512_IV[14] | 0;
|
|
1109
|
-
this.Hl = SHA512_IV[15] | 0;
|
|
1110
|
-
}
|
|
1111
|
-
// prettier-ignore
|
|
1112
|
-
get() {
|
|
1113
|
-
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1114
|
-
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
611
|
+
function ensureValidContentTopic(contentTopic) {
|
|
612
|
+
const parts = contentTopic.split("/");
|
|
613
|
+
if (parts.length < 5 || parts.length > 6) {
|
|
614
|
+
throw Error(`Content topic format is invalid: ${contentTopic}`);
|
|
1115
615
|
}
|
|
1116
|
-
//
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
this.Eh = Eh | 0;
|
|
1127
|
-
this.El = El | 0;
|
|
1128
|
-
this.Fh = Fh | 0;
|
|
1129
|
-
this.Fl = Fl | 0;
|
|
1130
|
-
this.Gh = Gh | 0;
|
|
1131
|
-
this.Gl = Gl | 0;
|
|
1132
|
-
this.Hh = Hh | 0;
|
|
1133
|
-
this.Hl = Hl | 0;
|
|
1134
|
-
}
|
|
1135
|
-
process(view, offset) {
|
|
1136
|
-
// Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
|
|
1137
|
-
for (let i = 0; i < 16; i++, offset += 4) {
|
|
1138
|
-
SHA512_W_H[i] = view.getUint32(offset);
|
|
1139
|
-
SHA512_W_L[i] = view.getUint32((offset += 4));
|
|
1140
|
-
}
|
|
1141
|
-
for (let i = 16; i < 80; i++) {
|
|
1142
|
-
// s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
|
|
1143
|
-
const W15h = SHA512_W_H[i - 15] | 0;
|
|
1144
|
-
const W15l = SHA512_W_L[i - 15] | 0;
|
|
1145
|
-
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
1146
|
-
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
1147
|
-
// s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
|
|
1148
|
-
const W2h = SHA512_W_H[i - 2] | 0;
|
|
1149
|
-
const W2l = SHA512_W_L[i - 2] | 0;
|
|
1150
|
-
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
1151
|
-
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
1152
|
-
// SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
|
|
1153
|
-
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
1154
|
-
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
1155
|
-
SHA512_W_H[i] = SUMh | 0;
|
|
1156
|
-
SHA512_W_L[i] = SUMl | 0;
|
|
1157
|
-
}
|
|
1158
|
-
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
1159
|
-
// Compression function main loop, 80 rounds
|
|
1160
|
-
for (let i = 0; i < 80; i++) {
|
|
1161
|
-
// S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
|
|
1162
|
-
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
1163
|
-
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
1164
|
-
//const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
1165
|
-
const CHIh = (Eh & Fh) ^ (~Eh & Gh);
|
|
1166
|
-
const CHIl = (El & Fl) ^ (~El & Gl);
|
|
1167
|
-
// T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
|
|
1168
|
-
// prettier-ignore
|
|
1169
|
-
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
1170
|
-
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
1171
|
-
const T1l = T1ll | 0;
|
|
1172
|
-
// S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
|
|
1173
|
-
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
1174
|
-
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
1175
|
-
const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
|
|
1176
|
-
const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
|
|
1177
|
-
Hh = Gh | 0;
|
|
1178
|
-
Hl = Gl | 0;
|
|
1179
|
-
Gh = Fh | 0;
|
|
1180
|
-
Gl = Fl | 0;
|
|
1181
|
-
Fh = Eh | 0;
|
|
1182
|
-
Fl = El | 0;
|
|
1183
|
-
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
1184
|
-
Dh = Ch | 0;
|
|
1185
|
-
Dl = Cl | 0;
|
|
1186
|
-
Ch = Bh | 0;
|
|
1187
|
-
Cl = Bl | 0;
|
|
1188
|
-
Bh = Ah | 0;
|
|
1189
|
-
Bl = Al | 0;
|
|
1190
|
-
const All = add3L(T1l, sigma0l, MAJl);
|
|
1191
|
-
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
1192
|
-
Al = All | 0;
|
|
1193
|
-
}
|
|
1194
|
-
// Add the compressed chunk to the current hash value
|
|
1195
|
-
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
1196
|
-
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
1197
|
-
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
1198
|
-
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
1199
|
-
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
1200
|
-
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
1201
|
-
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
1202
|
-
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
1203
|
-
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
1204
|
-
}
|
|
1205
|
-
roundClean() {
|
|
1206
|
-
clean(SHA512_W_H, SHA512_W_L);
|
|
616
|
+
// Validate generation field if present
|
|
617
|
+
let generation = 0;
|
|
618
|
+
if (parts.length == 6) {
|
|
619
|
+
generation = parseInt(parts[1]);
|
|
620
|
+
if (isNaN(generation)) {
|
|
621
|
+
throw new Error(`Invalid generation field in content topic: ${contentTopic}`);
|
|
622
|
+
}
|
|
623
|
+
if (generation > 0) {
|
|
624
|
+
throw new Error(`Generation greater than 0 is not supported: ${contentTopic}`);
|
|
625
|
+
}
|
|
1207
626
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
627
|
+
// Validate remaining fields
|
|
628
|
+
const fields = parts.splice(-4);
|
|
629
|
+
// Validate application field
|
|
630
|
+
if (fields[0].length == 0) {
|
|
631
|
+
throw new Error(`Application field cannot be empty: ${contentTopic}`);
|
|
1211
632
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
*
|
|
1216
|
-
* It is the fastest JS hash, even faster than Blake3.
|
|
1217
|
-
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
1218
|
-
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
1219
|
-
*/
|
|
1220
|
-
const sha256$1 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
1221
|
-
/** SHA2-512 hash function from RFC 4634. */
|
|
1222
|
-
const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
1223
|
-
|
|
1224
|
-
/**
|
|
1225
|
-
* SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
|
|
1226
|
-
*
|
|
1227
|
-
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
1228
|
-
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
1229
|
-
*
|
|
1230
|
-
* Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
1231
|
-
* @module
|
|
1232
|
-
* @deprecated
|
|
1233
|
-
*/
|
|
1234
|
-
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
1235
|
-
const sha256 = sha256$1;
|
|
1236
|
-
|
|
1237
|
-
/**
|
|
1238
|
-
* Turns a `Uint8Array` into a string.
|
|
1239
|
-
*
|
|
1240
|
-
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
|
|
1241
|
-
*
|
|
1242
|
-
* Also `ascii` which is similar to node's 'binary' encoding.
|
|
1243
|
-
*/
|
|
1244
|
-
function toString(array, encoding = 'utf8') {
|
|
1245
|
-
const base = BASES[encoding];
|
|
1246
|
-
if (base == null) {
|
|
1247
|
-
throw new Error(`Unsupported encoding "${encoding}"`);
|
|
633
|
+
// Validate version field
|
|
634
|
+
if (fields[1].length == 0) {
|
|
635
|
+
throw new Error(`Version field cannot be empty: ${contentTopic}`);
|
|
1248
636
|
}
|
|
1249
|
-
//
|
|
1250
|
-
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
function numberToBytes(value) {
|
|
1254
|
-
const buffer = new ArrayBuffer(8);
|
|
1255
|
-
const view = new DataView(buffer);
|
|
1256
|
-
if (typeof value === "number") {
|
|
1257
|
-
view.setFloat64(0, value, false);
|
|
637
|
+
// Validate topic name field
|
|
638
|
+
if (fields[2].length == 0) {
|
|
639
|
+
throw new Error(`Topic name field cannot be empty: ${contentTopic}`);
|
|
1258
640
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
641
|
+
// Validate encoding field
|
|
642
|
+
if (fields[3].length == 0) {
|
|
643
|
+
throw new Error(`Encoding field cannot be empty: ${contentTopic}`);
|
|
1261
644
|
}
|
|
1262
|
-
return
|
|
645
|
+
return {
|
|
646
|
+
generation,
|
|
647
|
+
application: fields[0],
|
|
648
|
+
version: fields[1],
|
|
649
|
+
topicName: fields[2],
|
|
650
|
+
encoding: fields[3]
|
|
651
|
+
};
|
|
1263
652
|
}
|
|
1264
653
|
/**
|
|
1265
|
-
*
|
|
1266
|
-
|
|
1267
|
-
const bytesToHex = (bytes) => toString(bytes, "base16");
|
|
1268
|
-
/**
|
|
1269
|
-
* Decode byte array to utf-8 string.
|
|
1270
|
-
*/
|
|
1271
|
-
const bytesToUtf8 = (b) => toString(b, "utf8");
|
|
1272
|
-
/**
|
|
1273
|
-
* Encode utf-8 string to byte array.
|
|
1274
|
-
*/
|
|
1275
|
-
const utf8ToBytes = (s) => fromString(s, "utf8");
|
|
1276
|
-
/**
|
|
1277
|
-
* Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
|
|
654
|
+
* Given a string, determines which autoshard index to use for its pubsub topic.
|
|
655
|
+
* Based on the algorithm described in the RFC: https://rfc.vac.dev/spec/51//#algorithm
|
|
1278
656
|
*/
|
|
1279
|
-
function
|
|
1280
|
-
const
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
res.set(bytes, offset);
|
|
1285
|
-
offset += bytes.length;
|
|
1286
|
-
}
|
|
1287
|
-
return res;
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
function isAutoSharding(config) {
|
|
1291
|
-
return "clusterId" in config && "numShardsInCluster" in config;
|
|
657
|
+
function contentTopicToShardIndex(contentTopic, numShardsInCluster) {
|
|
658
|
+
const { application, version } = ensureValidContentTopic(contentTopic);
|
|
659
|
+
const digest = sha256$1(concat$1([utf8ToBytes(application), utf8ToBytes(version)]));
|
|
660
|
+
const dataview = new DataView(digest.buffer.slice(-8));
|
|
661
|
+
return Number(dataview.getBigUint64(0, false) % BigInt(numShardsInCluster));
|
|
1292
662
|
}
|
|
1293
663
|
|
|
1294
664
|
class BaseRoutingInfo {
|
|
@@ -1401,86 +771,6 @@ function createRoutingInfo(networkConfig, options) {
|
|
|
1401
771
|
}
|
|
1402
772
|
}
|
|
1403
773
|
|
|
1404
|
-
const formatPubsubTopic = (clusterId, shard) => {
|
|
1405
|
-
return `/waku/2/rs/${clusterId}/${shard}`;
|
|
1406
|
-
};
|
|
1407
|
-
/**
|
|
1408
|
-
* @deprecated will be removed
|
|
1409
|
-
*/
|
|
1410
|
-
const pubsubTopicToSingleShardInfo = (pubsubTopics) => {
|
|
1411
|
-
const parts = pubsubTopics.split("/");
|
|
1412
|
-
if (parts.length != 6 ||
|
|
1413
|
-
parts[1] !== "waku" ||
|
|
1414
|
-
parts[2] !== "2" ||
|
|
1415
|
-
parts[3] !== "rs")
|
|
1416
|
-
throw new Error("Invalid pubsub topic");
|
|
1417
|
-
const clusterId = parseInt(parts[4]);
|
|
1418
|
-
const shard = parseInt(parts[5]);
|
|
1419
|
-
if (isNaN(clusterId) || isNaN(shard))
|
|
1420
|
-
throw new Error("Invalid clusterId or shard");
|
|
1421
|
-
return {
|
|
1422
|
-
clusterId,
|
|
1423
|
-
shard
|
|
1424
|
-
};
|
|
1425
|
-
};
|
|
1426
|
-
/**
|
|
1427
|
-
* Given a string, will throw an error if it is not formatted as a valid content topic for autosharding based on https://rfc.vac.dev/spec/51/
|
|
1428
|
-
* @param contentTopic String to validate
|
|
1429
|
-
* @returns Object with each content topic field as an attribute
|
|
1430
|
-
*/
|
|
1431
|
-
function ensureValidContentTopic(contentTopic) {
|
|
1432
|
-
const parts = contentTopic.split("/");
|
|
1433
|
-
if (parts.length < 5 || parts.length > 6) {
|
|
1434
|
-
throw Error(`Content topic format is invalid: ${contentTopic}`);
|
|
1435
|
-
}
|
|
1436
|
-
// Validate generation field if present
|
|
1437
|
-
let generation = 0;
|
|
1438
|
-
if (parts.length == 6) {
|
|
1439
|
-
generation = parseInt(parts[1]);
|
|
1440
|
-
if (isNaN(generation)) {
|
|
1441
|
-
throw new Error(`Invalid generation field in content topic: ${contentTopic}`);
|
|
1442
|
-
}
|
|
1443
|
-
if (generation > 0) {
|
|
1444
|
-
throw new Error(`Generation greater than 0 is not supported: ${contentTopic}`);
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
// Validate remaining fields
|
|
1448
|
-
const fields = parts.splice(-4);
|
|
1449
|
-
// Validate application field
|
|
1450
|
-
if (fields[0].length == 0) {
|
|
1451
|
-
throw new Error(`Application field cannot be empty: ${contentTopic}`);
|
|
1452
|
-
}
|
|
1453
|
-
// Validate version field
|
|
1454
|
-
if (fields[1].length == 0) {
|
|
1455
|
-
throw new Error(`Version field cannot be empty: ${contentTopic}`);
|
|
1456
|
-
}
|
|
1457
|
-
// Validate topic name field
|
|
1458
|
-
if (fields[2].length == 0) {
|
|
1459
|
-
throw new Error(`Topic name field cannot be empty: ${contentTopic}`);
|
|
1460
|
-
}
|
|
1461
|
-
// Validate encoding field
|
|
1462
|
-
if (fields[3].length == 0) {
|
|
1463
|
-
throw new Error(`Encoding field cannot be empty: ${contentTopic}`);
|
|
1464
|
-
}
|
|
1465
|
-
return {
|
|
1466
|
-
generation,
|
|
1467
|
-
application: fields[0],
|
|
1468
|
-
version: fields[1],
|
|
1469
|
-
topicName: fields[2],
|
|
1470
|
-
encoding: fields[3]
|
|
1471
|
-
};
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Given a string, determines which autoshard index to use for its pubsub topic.
|
|
1475
|
-
* Based on the algorithm described in the RFC: https://rfc.vac.dev/spec/51//#algorithm
|
|
1476
|
-
*/
|
|
1477
|
-
function contentTopicToShardIndex(contentTopic, numShardsInCluster) {
|
|
1478
|
-
const { application, version } = ensureValidContentTopic(contentTopic);
|
|
1479
|
-
const digest = sha256(concat$1([utf8ToBytes(application), utf8ToBytes(version)]));
|
|
1480
|
-
const dataview = new DataView(digest.buffer.slice(-8));
|
|
1481
|
-
return Number(dataview.getBigUint64(0, false) % BigInt(numShardsInCluster));
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
774
|
const decodeRelayShard = (bytes) => {
|
|
1485
775
|
// explicitly converting to Uint8Array to avoid Buffer
|
|
1486
776
|
// https://github.com/libp2p/js-libp2p/issues/2146
|
|
@@ -1631,6 +921,12 @@ var ProtocolError;
|
|
|
1631
921
|
ProtocolError["INVALID_DECODER_TOPICS"] = "Invalid decoder topics";
|
|
1632
922
|
})(ProtocolError || (ProtocolError = {}));
|
|
1633
923
|
|
|
924
|
+
var WakuEvent;
|
|
925
|
+
(function (WakuEvent) {
|
|
926
|
+
WakuEvent["Connection"] = "waku:connection";
|
|
927
|
+
WakuEvent["Health"] = "waku:health";
|
|
928
|
+
})(WakuEvent || (WakuEvent = {}));
|
|
929
|
+
|
|
1634
930
|
// Peer tags
|
|
1635
931
|
var Tags;
|
|
1636
932
|
(function (Tags) {
|
|
@@ -4132,7 +3428,7 @@ class ConnectionLimiter {
|
|
|
4132
3428
|
this.connectionMonitorInterval === null) {
|
|
4133
3429
|
this.connectionMonitorInterval = setInterval(() => void this.maintainConnections(), DEFAULT_CONNECTION_MONITOR_INTERVAL);
|
|
4134
3430
|
}
|
|
4135
|
-
this.events.addEventListener(
|
|
3431
|
+
this.events.addEventListener(WakuEvent.Connection, this.onWakuConnectionEvent);
|
|
4136
3432
|
/**
|
|
4137
3433
|
* NOTE: Event is not being emitted on closing nor losing a connection.
|
|
4138
3434
|
* @see https://github.com/libp2p/js-libp2p/issues/939
|
|
@@ -4147,7 +3443,7 @@ class ConnectionLimiter {
|
|
|
4147
3443
|
this.libp2p.addEventListener("peer:disconnect", this.onDisconnectedEvent);
|
|
4148
3444
|
}
|
|
4149
3445
|
stop() {
|
|
4150
|
-
this.events.removeEventListener(
|
|
3446
|
+
this.events.removeEventListener(WakuEvent.Connection, this.onWakuConnectionEvent);
|
|
4151
3447
|
this.libp2p.removeEventListener("peer:disconnect", this.onDisconnectedEvent);
|
|
4152
3448
|
if (this.connectionMonitorInterval) {
|
|
4153
3449
|
clearInterval(this.connectionMonitorInterval);
|
|
@@ -4263,8 +3559,7 @@ class ConnectionLimiter {
|
|
|
4263
3559
|
.getConnections()
|
|
4264
3560
|
.map((conn) => conn.remotePeer)
|
|
4265
3561
|
.map((id) => this.getPeer(id)));
|
|
4266
|
-
|
|
4267
|
-
return bootstrapPeers;
|
|
3562
|
+
return peers.filter((peer) => peer && peer.tags.has(Tags.BOOTSTRAP));
|
|
4268
3563
|
}
|
|
4269
3564
|
async getPeer(peerId) {
|
|
4270
3565
|
try {
|
|
@@ -4704,7 +3999,7 @@ class NetworkMonitor {
|
|
|
4704
3999
|
}
|
|
4705
4000
|
}
|
|
4706
4001
|
dispatchNetworkEvent() {
|
|
4707
|
-
this.events.dispatchEvent(new CustomEvent(
|
|
4002
|
+
this.events.dispatchEvent(new CustomEvent(WakuEvent.Connection, {
|
|
4708
4003
|
detail: this.isConnected()
|
|
4709
4004
|
}));
|
|
4710
4005
|
}
|
|
@@ -5175,11 +4470,11 @@ function hexToNumber(hex) {
|
|
|
5175
4470
|
}
|
|
5176
4471
|
// BE: Big Endian, LE: Little Endian
|
|
5177
4472
|
function bytesToNumberBE(bytes) {
|
|
5178
|
-
return hexToNumber(bytesToHex
|
|
4473
|
+
return hexToNumber(bytesToHex(bytes));
|
|
5179
4474
|
}
|
|
5180
4475
|
function bytesToNumberLE(bytes) {
|
|
5181
4476
|
abytes(bytes);
|
|
5182
|
-
return hexToNumber(bytesToHex
|
|
4477
|
+
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
5183
4478
|
}
|
|
5184
4479
|
function numberToBytesBE(n, len) {
|
|
5185
4480
|
return hexToBytes(n.toString(16).padStart(len * 2, '0'));
|
|
@@ -6453,7 +5748,7 @@ function edwards(CURVE, curveOpts = {}) {
|
|
|
6453
5748
|
return this.toBytes();
|
|
6454
5749
|
}
|
|
6455
5750
|
toHex() {
|
|
6456
|
-
return bytesToHex
|
|
5751
|
+
return bytesToHex(this.toBytes());
|
|
6457
5752
|
}
|
|
6458
5753
|
toString() {
|
|
6459
5754
|
return `<Point ${this.is0() ? 'ZERO' : this.toHex()}>`;
|
|
@@ -7723,7 +7018,7 @@ function weierstrassN(CURVE, curveOpts = {}) {
|
|
|
7723
7018
|
return this.toBytes(isCompressed);
|
|
7724
7019
|
}
|
|
7725
7020
|
toHex(isCompressed = true) {
|
|
7726
|
-
return bytesToHex
|
|
7021
|
+
return bytesToHex(this.toBytes(isCompressed));
|
|
7727
7022
|
}
|
|
7728
7023
|
toString() {
|
|
7729
7024
|
return `<Point ${this.is0() ? 'ZERO' : this.toHex()}>`;
|
|
@@ -7853,14 +7148,14 @@ function ecdsa(Point, ecdsaOpts, curveOpts = {}) {
|
|
|
7853
7148
|
return this.toBytes('der');
|
|
7854
7149
|
}
|
|
7855
7150
|
toDERHex() {
|
|
7856
|
-
return bytesToHex
|
|
7151
|
+
return bytesToHex(this.toBytes('der'));
|
|
7857
7152
|
}
|
|
7858
7153
|
// padded bytes of r, then padded bytes of s
|
|
7859
7154
|
toCompactRawBytes() {
|
|
7860
7155
|
return this.toBytes('compact');
|
|
7861
7156
|
}
|
|
7862
7157
|
toCompactHex() {
|
|
7863
|
-
return bytesToHex
|
|
7158
|
+
return bytesToHex(this.toBytes('compact'));
|
|
7864
7159
|
}
|
|
7865
7160
|
}
|
|
7866
7161
|
const normPrivateKeyToScalar = _legacyHelperNormPriv(Fn, curveOpts.allowedPrivateKeyLengths, curveOpts.wrapPrivateKey);
|
|
@@ -8308,13 +7603,13 @@ const secp256k1 = createCurve({
|
|
|
8308
7603
|
return { k1neg, k1, k2neg, k2 };
|
|
8309
7604
|
},
|
|
8310
7605
|
},
|
|
8311
|
-
}, sha256$
|
|
7606
|
+
}, sha256$2);
|
|
8312
7607
|
|
|
8313
7608
|
/**
|
|
8314
7609
|
* Hash message and verify signature with public key
|
|
8315
7610
|
*/
|
|
8316
7611
|
function hashAndVerify(key, sig, msg, options) {
|
|
8317
|
-
const p = sha256
|
|
7612
|
+
const p = sha256.digest(msg instanceof Uint8Array ? msg : msg.subarray());
|
|
8318
7613
|
if (isPromise(p)) {
|
|
8319
7614
|
return p
|
|
8320
7615
|
.then(({ digest }) => {
|
|
@@ -8645,7 +7940,7 @@ function isIdentityMultihash(multihash) {
|
|
|
8645
7940
|
return multihash.code === identity.code;
|
|
8646
7941
|
}
|
|
8647
7942
|
function isSha256Multihash(multihash) {
|
|
8648
|
-
return multihash.code === sha256
|
|
7943
|
+
return multihash.code === sha256.code;
|
|
8649
7944
|
}
|
|
8650
7945
|
|
|
8651
7946
|
/**
|
|
@@ -10297,85 +9592,4 @@ function wakuMetadata(clusterId) {
|
|
|
10297
9592
|
return (components) => new Metadata(clusterId, components);
|
|
10298
9593
|
}
|
|
10299
9594
|
|
|
10300
|
-
|
|
10301
|
-
* Deterministic Message Hashing as defined in
|
|
10302
|
-
* [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/#deterministic-message-hashing)
|
|
10303
|
-
*
|
|
10304
|
-
* Computes a SHA-256 hash of the concatenation of pubsub topic, payload, content topic, meta, and timestamp.
|
|
10305
|
-
*
|
|
10306
|
-
* @param pubsubTopic - The pubsub topic string
|
|
10307
|
-
* @param message - The message to be hashed
|
|
10308
|
-
* @returns A Uint8Array containing the SHA-256 hash
|
|
10309
|
-
*
|
|
10310
|
-
* @example
|
|
10311
|
-
* ```typescript
|
|
10312
|
-
* import { messageHash } from "@waku/core";
|
|
10313
|
-
*
|
|
10314
|
-
* const pubsubTopic = "/waku/2/default-waku/proto";
|
|
10315
|
-
* const message = {
|
|
10316
|
-
* payload: new Uint8Array([1, 2, 3, 4]),
|
|
10317
|
-
* contentTopic: "/waku/2/default-content/proto",
|
|
10318
|
-
* meta: new Uint8Array([5, 6, 7, 8]),
|
|
10319
|
-
* timestamp: new Date()
|
|
10320
|
-
* };
|
|
10321
|
-
*
|
|
10322
|
-
* const hash = messageHash(pubsubTopic, message);
|
|
10323
|
-
* ```
|
|
10324
|
-
*/
|
|
10325
|
-
function messageHash(pubsubTopic, message) {
|
|
10326
|
-
const pubsubTopicBytes = utf8ToBytes(pubsubTopic);
|
|
10327
|
-
const contentTopicBytes = utf8ToBytes(message.contentTopic);
|
|
10328
|
-
const timestampBytes = tryConvertTimestampToBytes(message.timestamp);
|
|
10329
|
-
const bytes = concat$1([
|
|
10330
|
-
pubsubTopicBytes,
|
|
10331
|
-
message.payload,
|
|
10332
|
-
contentTopicBytes,
|
|
10333
|
-
message.meta,
|
|
10334
|
-
timestampBytes
|
|
10335
|
-
].filter(isDefined));
|
|
10336
|
-
return sha256(bytes);
|
|
10337
|
-
}
|
|
10338
|
-
function tryConvertTimestampToBytes(timestamp) {
|
|
10339
|
-
if (!timestamp) {
|
|
10340
|
-
return;
|
|
10341
|
-
}
|
|
10342
|
-
let bigIntTimestamp;
|
|
10343
|
-
if (typeof timestamp === "bigint") {
|
|
10344
|
-
bigIntTimestamp = timestamp;
|
|
10345
|
-
}
|
|
10346
|
-
else {
|
|
10347
|
-
bigIntTimestamp = BigInt(timestamp.valueOf()) * 1000000n;
|
|
10348
|
-
}
|
|
10349
|
-
return numberToBytes(bigIntTimestamp);
|
|
10350
|
-
}
|
|
10351
|
-
/**
|
|
10352
|
-
* Computes a deterministic message hash and returns it as a hexadecimal string.
|
|
10353
|
-
* This is a convenience wrapper around messageHash that converts the result to a hex string.
|
|
10354
|
-
*
|
|
10355
|
-
* @param pubsubTopic - The pubsub topic string
|
|
10356
|
-
* @param message - The message to be hashed
|
|
10357
|
-
* @returns A string containing the hex representation of the SHA-256 hash
|
|
10358
|
-
*
|
|
10359
|
-
* @example
|
|
10360
|
-
* ```typescript
|
|
10361
|
-
* import { messageHashStr } from "@waku/core";
|
|
10362
|
-
*
|
|
10363
|
-
* const pubsubTopic = "/waku/2/default-waku/proto";
|
|
10364
|
-
* const message = {
|
|
10365
|
-
* payload: new Uint8Array([1, 2, 3, 4]),
|
|
10366
|
-
* contentTopic: "/waku/2/default-content/proto",
|
|
10367
|
-
* meta: new Uint8Array([5, 6, 7, 8]),
|
|
10368
|
-
* timestamp: new Date()
|
|
10369
|
-
* };
|
|
10370
|
-
*
|
|
10371
|
-
* const hashString = messageHashStr(pubsubTopic, message);
|
|
10372
|
-
* console.log(hashString); // e.g. "a1b2c3d4..."
|
|
10373
|
-
* ```
|
|
10374
|
-
*/
|
|
10375
|
-
function messageHashStr(pubsubTopic, message) {
|
|
10376
|
-
const hash = messageHash(pubsubTopic, message);
|
|
10377
|
-
const hashStr = bytesToHex(hash);
|
|
10378
|
-
return hashStr;
|
|
10379
|
-
}
|
|
10380
|
-
|
|
10381
|
-
export { ConnectionManager, FilterCodecs, FilterCore, LightPushCodec, LightPushCore, MetadataCodec, StoreCodec, StoreCore, StreamManager, createEncoder, index$3 as message, messageHash, messageHashStr, wakuMetadata, index$2 as waku_filter, index$1 as waku_light_push, index as waku_store };
|
|
9595
|
+
export { ConnectionManager, FilterCodecs, FilterCore, LightPushCodec, LightPushCore, MetadataCodec, StoreCodec, StoreCore, StreamManager, createEncoder, index$3 as message, wakuMetadata, index$2 as waku_filter, index$1 as waku_light_push, index as waku_store };
|