@waku/core 0.0.34-66cf711.0 → 0.0.34-6cb9c9c.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/base_protocol-Bp5a9PNG.js +152 -0
- package/bundle/{index-BIW3qNYx.js → index-G1eRBjeI.js} +118 -204
- package/bundle/index.js +1895 -178
- package/bundle/lib/base_protocol.js +2 -2
- package/bundle/lib/message/version_0.js +2 -2
- package/bundle/{version_0-CdmZMfkQ.js → version_0-DJZG2fB2.js} +283 -45
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +3 -23
- package/dist/lib/base_protocol.js +3 -47
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager/connection_manager.d.ts +118 -0
- package/dist/lib/{connection_manager.js → connection_manager/connection_manager.js} +136 -36
- package/dist/lib/connection_manager/connection_manager.js.map +1 -0
- package/dist/lib/connection_manager/index.d.ts +1 -0
- package/dist/lib/connection_manager/index.js +2 -0
- package/dist/lib/connection_manager/index.js.map +1 -0
- package/dist/lib/{keep_alive_manager.d.ts → connection_manager/keep_alive_manager.d.ts} +4 -2
- package/dist/lib/{keep_alive_manager.js → connection_manager/keep_alive_manager.js} +2 -2
- package/dist/lib/connection_manager/keep_alive_manager.js.map +1 -0
- package/dist/lib/connection_manager/utils.d.ts +7 -0
- package/dist/lib/connection_manager/utils.js +22 -0
- package/dist/lib/connection_manager/utils.js.map +1 -0
- package/dist/lib/filter/filter.d.ts +18 -0
- package/dist/lib/filter/filter.js +209 -0
- package/dist/lib/filter/filter.js.map +1 -0
- package/dist/lib/filter/index.d.ts +1 -18
- package/dist/lib/filter/index.js +1 -208
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +1 -15
- package/dist/lib/light_push/index.js +1 -143
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/light_push.d.ts +15 -0
- package/dist/lib/light_push/light_push.js +144 -0
- package/dist/lib/light_push/light_push.js.map +1 -0
- package/dist/lib/light_push/utils.d.ts +0 -2
- package/dist/lib/light_push/utils.js +9 -17
- package/dist/lib/light_push/utils.js.map +1 -1
- package/dist/lib/metadata/index.d.ts +1 -3
- package/dist/lib/metadata/index.js +1 -118
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/metadata/metadata.d.ts +3 -0
- package/dist/lib/metadata/metadata.js +119 -0
- package/dist/lib/metadata/metadata.js.map +1 -0
- package/dist/lib/store/index.d.ts +1 -9
- package/dist/lib/store/index.js +1 -82
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/store/store.d.ts +9 -0
- package/dist/lib/store/store.js +83 -0
- package/dist/lib/store/store.js.map +1 -0
- package/dist/lib/stream_manager/stream_manager.d.ts +2 -2
- package/dist/lib/stream_manager/stream_manager.js +16 -17
- package/dist/lib/stream_manager/stream_manager.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -4
- package/src/lib/base_protocol.ts +3 -76
- package/src/lib/{connection_manager.ts → connection_manager/connection_manager.ts} +168 -63
- package/src/lib/connection_manager/index.ts +1 -0
- package/src/lib/{keep_alive_manager.ts → connection_manager/keep_alive_manager.ts} +7 -3
- package/src/lib/connection_manager/utils.ts +25 -0
- package/src/lib/filter/filter.ts +315 -0
- package/src/lib/filter/index.ts +1 -315
- package/src/lib/light_push/index.ts +1 -188
- package/src/lib/light_push/light_push.ts +188 -0
- package/src/lib/light_push/utils.ts +13 -21
- package/src/lib/metadata/index.ts +1 -182
- package/src/lib/metadata/metadata.ts +182 -0
- package/src/lib/store/index.ts +1 -136
- package/src/lib/store/store.ts +136 -0
- package/src/lib/stream_manager/stream_manager.ts +16 -18
- package/bundle/base_protocol-Dzv-QHPR.js +0 -275
- package/dist/lib/connection_manager.d.ts +0 -62
- package/dist/lib/connection_manager.js.map +0 -1
- package/dist/lib/filterPeers.d.ts +0 -13
- package/dist/lib/filterPeers.js +0 -38
- package/dist/lib/filterPeers.js.map +0 -1
- package/dist/lib/health_manager.d.ts +0 -14
- package/dist/lib/health_manager.js +0 -70
- package/dist/lib/health_manager.js.map +0 -1
- package/dist/lib/keep_alive_manager.js.map +0 -1
- package/src/lib/filterPeers.ts +0 -51
- package/src/lib/health_manager.ts +0 -90
@@ -1,2 +1,2 @@
|
|
1
|
-
export { B as BaseProtocol } from '../base_protocol-
|
2
|
-
import '../index-
|
1
|
+
export { B as BaseProtocol } from '../base_protocol-Bp5a9PNG.js';
|
2
|
+
import '../index-G1eRBjeI.js';
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { D as DecodedMessage,
|
2
|
-
import '../../index-
|
1
|
+
export { D as DecodedMessage, r as Decoder, E as Encoder, V as Version, o as createDecoder, k as createEncoder, q as proto } from '../../version_0-DJZG2fB2.js';
|
2
|
+
import '../../index-G1eRBjeI.js';
|
@@ -1,4 +1,20 @@
|
|
1
|
-
import {
|
1
|
+
import { i as identityBase, g as base2, h as base8, j as base10, k as base16, l as base32, m as base36, n as base58, o as base64, p as base256emoji, L as Logger } from './index-G1eRBjeI.js';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Returns a `Uint8Array` of the requested size. Referenced memory will
|
5
|
+
* be initialized to 0.
|
6
|
+
*/
|
7
|
+
function alloc$1(size = 0) {
|
8
|
+
return new Uint8Array(size);
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* Where possible returns a Uint8Array of the requested size that references
|
12
|
+
* uninitialized memory. Only use if you are certain you will immediately
|
13
|
+
* overwrite every value in the returned `Uint8Array`.
|
14
|
+
*/
|
15
|
+
function allocUnsafe(size = 0) {
|
16
|
+
return new Uint8Array(size);
|
17
|
+
}
|
2
18
|
|
3
19
|
/* eslint-disable no-fallthrough */
|
4
20
|
const N1 = Math.pow(2, 7);
|
@@ -916,6 +932,69 @@ function decodeMessage(buf, codec, opts) {
|
|
916
932
|
return codec.decode(reader, undefined, opts);
|
917
933
|
}
|
918
934
|
|
935
|
+
const bases = { ...identityBase, ...base2, ...base8, ...base10, ...base16, ...base32, ...base36, ...base58, ...base64, ...base256emoji };
|
936
|
+
|
937
|
+
function createCodec$1(name, prefix, encode, decode) {
|
938
|
+
return {
|
939
|
+
name,
|
940
|
+
prefix,
|
941
|
+
encoder: {
|
942
|
+
name,
|
943
|
+
prefix,
|
944
|
+
encode
|
945
|
+
},
|
946
|
+
decoder: {
|
947
|
+
decode
|
948
|
+
}
|
949
|
+
};
|
950
|
+
}
|
951
|
+
const string = createCodec$1('utf8', 'u', (buf) => {
|
952
|
+
const decoder = new TextDecoder('utf8');
|
953
|
+
return 'u' + decoder.decode(buf);
|
954
|
+
}, (str) => {
|
955
|
+
const encoder = new TextEncoder();
|
956
|
+
return encoder.encode(str.substring(1));
|
957
|
+
});
|
958
|
+
const ascii = createCodec$1('ascii', 'a', (buf) => {
|
959
|
+
let string = 'a';
|
960
|
+
for (let i = 0; i < buf.length; i++) {
|
961
|
+
string += String.fromCharCode(buf[i]);
|
962
|
+
}
|
963
|
+
return string;
|
964
|
+
}, (str) => {
|
965
|
+
str = str.substring(1);
|
966
|
+
const buf = allocUnsafe(str.length);
|
967
|
+
for (let i = 0; i < str.length; i++) {
|
968
|
+
buf[i] = str.charCodeAt(i);
|
969
|
+
}
|
970
|
+
return buf;
|
971
|
+
});
|
972
|
+
const BASES = {
|
973
|
+
utf8: string,
|
974
|
+
'utf-8': string,
|
975
|
+
hex: bases.base16,
|
976
|
+
latin1: ascii,
|
977
|
+
ascii,
|
978
|
+
binary: ascii,
|
979
|
+
...bases
|
980
|
+
};
|
981
|
+
|
982
|
+
/**
|
983
|
+
* Create a `Uint8Array` from the passed string
|
984
|
+
*
|
985
|
+
* Supports `utf8`, `utf-8`, `hex`, and any encoding supported by the multiformats module.
|
986
|
+
*
|
987
|
+
* Also `ascii` which is similar to node's 'binary' encoding.
|
988
|
+
*/
|
989
|
+
function fromString(string, encoding = 'utf8') {
|
990
|
+
const base = BASES[encoding];
|
991
|
+
if (base == null) {
|
992
|
+
throw new Error(`Unsupported encoding "${encoding}"`);
|
993
|
+
}
|
994
|
+
// add multibase prefix
|
995
|
+
return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions
|
996
|
+
}
|
997
|
+
|
919
998
|
/**
|
920
999
|
* A general purpose buffer pool
|
921
1000
|
*/
|
@@ -3750,31 +3829,141 @@ var WakuMetadataResponse;
|
|
3750
3829
|
};
|
3751
3830
|
})(WakuMetadataResponse || (WakuMetadataResponse = {}));
|
3752
3831
|
|
3753
|
-
|
3832
|
+
/* eslint-disable import/export */
|
3833
|
+
/* eslint-disable complexity */
|
3834
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
3835
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
3836
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
3837
|
+
var SdsMessage;
|
3838
|
+
(function (SdsMessage) {
|
3839
|
+
let _codec;
|
3840
|
+
SdsMessage.codec = () => {
|
3841
|
+
if (_codec == null) {
|
3842
|
+
_codec = message$1((obj, w, opts = {}) => {
|
3843
|
+
if (opts.lengthDelimited !== false) {
|
3844
|
+
w.fork();
|
3845
|
+
}
|
3846
|
+
if ((obj.messageId != null && obj.messageId !== '')) {
|
3847
|
+
w.uint32(18);
|
3848
|
+
w.string(obj.messageId);
|
3849
|
+
}
|
3850
|
+
if ((obj.channelId != null && obj.channelId !== '')) {
|
3851
|
+
w.uint32(26);
|
3852
|
+
w.string(obj.channelId);
|
3853
|
+
}
|
3854
|
+
if (obj.lamportTimestamp != null) {
|
3855
|
+
w.uint32(80);
|
3856
|
+
w.int32(obj.lamportTimestamp);
|
3857
|
+
}
|
3858
|
+
if (obj.causalHistory != null) {
|
3859
|
+
for (const value of obj.causalHistory) {
|
3860
|
+
w.uint32(90);
|
3861
|
+
w.string(value);
|
3862
|
+
}
|
3863
|
+
}
|
3864
|
+
if (obj.bloomFilter != null) {
|
3865
|
+
w.uint32(98);
|
3866
|
+
w.bytes(obj.bloomFilter);
|
3867
|
+
}
|
3868
|
+
if (obj.content != null) {
|
3869
|
+
w.uint32(162);
|
3870
|
+
w.bytes(obj.content);
|
3871
|
+
}
|
3872
|
+
if (opts.lengthDelimited !== false) {
|
3873
|
+
w.ldelim();
|
3874
|
+
}
|
3875
|
+
}, (reader, length, opts = {}) => {
|
3876
|
+
const obj = {
|
3877
|
+
messageId: '',
|
3878
|
+
channelId: '',
|
3879
|
+
causalHistory: []
|
3880
|
+
};
|
3881
|
+
const end = length == null ? reader.len : reader.pos + length;
|
3882
|
+
while (reader.pos < end) {
|
3883
|
+
const tag = reader.uint32();
|
3884
|
+
switch (tag >>> 3) {
|
3885
|
+
case 2: {
|
3886
|
+
obj.messageId = reader.string();
|
3887
|
+
break;
|
3888
|
+
}
|
3889
|
+
case 3: {
|
3890
|
+
obj.channelId = reader.string();
|
3891
|
+
break;
|
3892
|
+
}
|
3893
|
+
case 10: {
|
3894
|
+
obj.lamportTimestamp = reader.int32();
|
3895
|
+
break;
|
3896
|
+
}
|
3897
|
+
case 11: {
|
3898
|
+
if (opts.limits?.causalHistory != null && obj.causalHistory.length === opts.limits.causalHistory) {
|
3899
|
+
throw new MaxLengthError('Decode error - map field "causalHistory" had too many elements');
|
3900
|
+
}
|
3901
|
+
obj.causalHistory.push(reader.string());
|
3902
|
+
break;
|
3903
|
+
}
|
3904
|
+
case 12: {
|
3905
|
+
obj.bloomFilter = reader.bytes();
|
3906
|
+
break;
|
3907
|
+
}
|
3908
|
+
case 20: {
|
3909
|
+
obj.content = reader.bytes();
|
3910
|
+
break;
|
3911
|
+
}
|
3912
|
+
default: {
|
3913
|
+
reader.skipType(tag & 7);
|
3914
|
+
break;
|
3915
|
+
}
|
3916
|
+
}
|
3917
|
+
}
|
3918
|
+
return obj;
|
3919
|
+
});
|
3920
|
+
}
|
3921
|
+
return _codec;
|
3922
|
+
};
|
3923
|
+
SdsMessage.encode = (obj) => {
|
3924
|
+
return encodeMessage(obj, SdsMessage.codec());
|
3925
|
+
};
|
3926
|
+
SdsMessage.decode = (buf, opts) => {
|
3927
|
+
return decodeMessage(buf, SdsMessage.codec(), opts);
|
3928
|
+
};
|
3929
|
+
})(SdsMessage || (SdsMessage = {}));
|
3930
|
+
|
3931
|
+
/**
|
3932
|
+
* Internal assertion helpers.
|
3933
|
+
* @module
|
3934
|
+
*/
|
3935
|
+
/** Asserts something is positive integer. */
|
3936
|
+
/** Is number an Uint8Array? Copied from utils for perf. */
|
3754
3937
|
function isBytes(a) {
|
3755
|
-
return
|
3756
|
-
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
3938
|
+
return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
|
3757
3939
|
}
|
3758
|
-
|
3940
|
+
/** Asserts something is Uint8Array. */
|
3941
|
+
function abytes(b, ...lengths) {
|
3759
3942
|
if (!isBytes(b))
|
3760
3943
|
throw new Error('Uint8Array expected');
|
3761
3944
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
3762
|
-
throw new Error(
|
3945
|
+
throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
|
3763
3946
|
}
|
3764
|
-
|
3947
|
+
/** Asserts a hash instance has not been destroyed / finished */
|
3948
|
+
function aexists(instance, checkFinished = true) {
|
3765
3949
|
if (instance.destroyed)
|
3766
3950
|
throw new Error('Hash instance has been destroyed');
|
3767
3951
|
if (checkFinished && instance.finished)
|
3768
3952
|
throw new Error('Hash#digest() has already been called');
|
3769
3953
|
}
|
3770
|
-
|
3771
|
-
|
3954
|
+
/** Asserts output is properly-sized byte array */
|
3955
|
+
function aoutput(out, instance) {
|
3956
|
+
abytes(out);
|
3772
3957
|
const min = instance.outputLen;
|
3773
3958
|
if (out.length < min) {
|
3774
|
-
throw new Error(
|
3959
|
+
throw new Error('digestInto() expects output buffer of length at least ' + min);
|
3775
3960
|
}
|
3776
3961
|
}
|
3777
3962
|
|
3963
|
+
/**
|
3964
|
+
* Utilities for hex, bytes, CSPRNG.
|
3965
|
+
* @module
|
3966
|
+
*/
|
3778
3967
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
3779
3968
|
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
3780
3969
|
// node.js versions earlier than v19 don't declare it in global scope.
|
@@ -3783,16 +3972,20 @@ function output(out, instance) {
|
|
3783
3972
|
// Makes the utils un-importable in browsers without a bundler.
|
3784
3973
|
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
3785
3974
|
// Cast array to view
|
3786
|
-
|
3787
|
-
|
3788
|
-
|
3789
|
-
|
3975
|
+
function createView(arr) {
|
3976
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
3977
|
+
}
|
3978
|
+
/** The rotate right (circular right shift) operation for uint32 */
|
3979
|
+
function rotr(word, shift) {
|
3980
|
+
return (word << (32 - shift)) | (word >>> shift);
|
3981
|
+
}
|
3790
3982
|
/**
|
3983
|
+
* Convert JS string to byte array.
|
3791
3984
|
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
3792
3985
|
*/
|
3793
|
-
function utf8ToBytes(str) {
|
3986
|
+
function utf8ToBytes$1(str) {
|
3794
3987
|
if (typeof str !== 'string')
|
3795
|
-
throw new Error(
|
3988
|
+
throw new Error('utf8ToBytes expected string, got ' + typeof str);
|
3796
3989
|
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
3797
3990
|
}
|
3798
3991
|
/**
|
@@ -3802,17 +3995,18 @@ function utf8ToBytes(str) {
|
|
3802
3995
|
*/
|
3803
3996
|
function toBytes(data) {
|
3804
3997
|
if (typeof data === 'string')
|
3805
|
-
data = utf8ToBytes(data);
|
3806
|
-
|
3998
|
+
data = utf8ToBytes$1(data);
|
3999
|
+
abytes(data);
|
3807
4000
|
return data;
|
3808
4001
|
}
|
3809
|
-
|
4002
|
+
/** For runtime check if class implements interface */
|
3810
4003
|
class Hash {
|
3811
4004
|
// Safe version that clones internal state
|
3812
4005
|
clone() {
|
3813
4006
|
return this._cloneInto();
|
3814
4007
|
}
|
3815
4008
|
}
|
4009
|
+
/** Wraps hash function, creating an interface on top of it */
|
3816
4010
|
function wrapConstructor(hashCons) {
|
3817
4011
|
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
3818
4012
|
const tmp = hashCons();
|
@@ -3823,8 +4017,10 @@ function wrapConstructor(hashCons) {
|
|
3823
4017
|
}
|
3824
4018
|
|
3825
4019
|
/**
|
3826
|
-
*
|
4020
|
+
* Internal Merkle-Damgard hash utils.
|
4021
|
+
* @module
|
3827
4022
|
*/
|
4023
|
+
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
3828
4024
|
function setBigUint64(view, byteOffset, value, isLE) {
|
3829
4025
|
if (typeof view.setBigUint64 === 'function')
|
3830
4026
|
return view.setBigUint64(byteOffset, value, isLE);
|
@@ -3837,14 +4033,14 @@ function setBigUint64(view, byteOffset, value, isLE) {
|
|
3837
4033
|
view.setUint32(byteOffset + h, wh, isLE);
|
3838
4034
|
view.setUint32(byteOffset + l, wl, isLE);
|
3839
4035
|
}
|
3840
|
-
/**
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3844
|
-
/**
|
3845
|
-
|
3846
|
-
|
3847
|
-
|
4036
|
+
/** Choice: a ? b : c */
|
4037
|
+
function Chi(a, b, c) {
|
4038
|
+
return (a & b) ^ (~a & c);
|
4039
|
+
}
|
4040
|
+
/** Majority function, true if any two inputs is true. */
|
4041
|
+
function Maj(a, b, c) {
|
4042
|
+
return (a & b) ^ (a & c) ^ (b & c);
|
4043
|
+
}
|
3848
4044
|
/**
|
3849
4045
|
* Merkle-Damgard hash construction base class.
|
3850
4046
|
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
@@ -3864,7 +4060,7 @@ class HashMD extends Hash {
|
|
3864
4060
|
this.view = createView(this.buffer);
|
3865
4061
|
}
|
3866
4062
|
update(data) {
|
3867
|
-
|
4063
|
+
aexists(this);
|
3868
4064
|
const { view, buffer, blockLen } = this;
|
3869
4065
|
data = toBytes(data);
|
3870
4066
|
const len = data.length;
|
@@ -3890,8 +4086,8 @@ class HashMD extends Hash {
|
|
3890
4086
|
return this;
|
3891
4087
|
}
|
3892
4088
|
digestInto(out) {
|
3893
|
-
|
3894
|
-
|
4089
|
+
aexists(this);
|
4090
|
+
aoutput(out, this);
|
3895
4091
|
this.finished = true;
|
3896
4092
|
// Padding
|
3897
4093
|
// We can avoid allocation of buffer for padding completely if it
|
@@ -3948,10 +4144,16 @@ class HashMD extends Hash {
|
|
3948
4144
|
}
|
3949
4145
|
}
|
3950
4146
|
|
3951
|
-
|
3952
|
-
|
3953
|
-
|
3954
|
-
|
4147
|
+
/**
|
4148
|
+
* SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
|
4149
|
+
*
|
4150
|
+
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
4151
|
+
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
4152
|
+
*
|
4153
|
+
* Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
4154
|
+
* @module
|
4155
|
+
*/
|
4156
|
+
/** Round constants: first 32 bits of fractional parts of the cube roots of the first 64 primes 2..311). */
|
3955
4157
|
// prettier-ignore
|
3956
4158
|
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
3957
4159
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
@@ -3963,14 +4165,15 @@ const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
3963
4165
|
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
3964
4166
|
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
3965
4167
|
]);
|
3966
|
-
|
3967
|
-
// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
|
4168
|
+
/** Initial state: first 32 bits of fractional parts of the square roots of the first 8 primes 2..19. */
|
3968
4169
|
// prettier-ignore
|
3969
4170
|
const SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
3970
4171
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
3971
4172
|
]);
|
3972
|
-
|
3973
|
-
|
4173
|
+
/**
|
4174
|
+
* Temporary buffer, not used to store anything between runs.
|
4175
|
+
* Named this way because it matches specification.
|
4176
|
+
*/
|
3974
4177
|
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
3975
4178
|
class SHA256 extends HashMD {
|
3976
4179
|
constructor() {
|
@@ -4047,10 +4250,7 @@ class SHA256 extends HashMD {
|
|
4047
4250
|
this.buffer.fill(0);
|
4048
4251
|
}
|
4049
4252
|
}
|
4050
|
-
/**
|
4051
|
-
* SHA2-256 hash function
|
4052
|
-
* @param message - data that would be hashed
|
4053
|
-
*/
|
4253
|
+
/** SHA2-256 hash function */
|
4054
4254
|
const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
4055
4255
|
|
4056
4256
|
/**
|
@@ -4058,6 +4258,44 @@ const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
4058
4258
|
*/
|
4059
4259
|
const DEFAULT_CLUSTER_ID = 1;
|
4060
4260
|
|
4261
|
+
/**
|
4262
|
+
* Turns a `Uint8Array` into a string.
|
4263
|
+
*
|
4264
|
+
* Supports `utf8`, `utf-8` and any encoding supported by the multibase module.
|
4265
|
+
*
|
4266
|
+
* Also `ascii` which is similar to node's 'binary' encoding.
|
4267
|
+
*/
|
4268
|
+
function toString(array, encoding = 'utf8') {
|
4269
|
+
const base = BASES[encoding];
|
4270
|
+
if (base == null) {
|
4271
|
+
throw new Error(`Unsupported encoding "${encoding}"`);
|
4272
|
+
}
|
4273
|
+
// strip multibase prefix
|
4274
|
+
return base.encoder.encode(array).substring(1);
|
4275
|
+
}
|
4276
|
+
|
4277
|
+
/**
|
4278
|
+
* Decode byte array to utf-8 string.
|
4279
|
+
*/
|
4280
|
+
const bytesToUtf8 = (b) => toString(b, "utf8");
|
4281
|
+
/**
|
4282
|
+
* Encode utf-8 string to byte array.
|
4283
|
+
*/
|
4284
|
+
const utf8ToBytes = (s) => fromString(s, "utf8");
|
4285
|
+
/**
|
4286
|
+
* Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
|
4287
|
+
*/
|
4288
|
+
function concat(byteArrays, totalLength) {
|
4289
|
+
const len = byteArrays.reduce((acc, curr) => acc + curr.length, 0);
|
4290
|
+
const res = new Uint8Array(len);
|
4291
|
+
let offset = 0;
|
4292
|
+
for (const bytes of byteArrays) {
|
4293
|
+
res.set(bytes, offset);
|
4294
|
+
offset += bytes.length;
|
4295
|
+
}
|
4296
|
+
return res;
|
4297
|
+
}
|
4298
|
+
|
4061
4299
|
const singleShardInfoToPubsubTopic = (shardInfo) => {
|
4062
4300
|
if (shardInfo.shard === undefined)
|
4063
4301
|
throw new Error("Invalid shard");
|
@@ -4174,7 +4412,7 @@ function ensureValidContentTopic(contentTopic) {
|
|
4174
4412
|
*/
|
4175
4413
|
function contentTopicToShardIndex(contentTopic, networkShards = 8) {
|
4176
4414
|
const { application, version } = ensureValidContentTopic(contentTopic);
|
4177
|
-
const digest = sha256(concat([utf8ToBytes
|
4415
|
+
const digest = sha256(concat([utf8ToBytes(application), utf8ToBytes(version)]));
|
4178
4416
|
const dataview = new DataView(digest.buffer.slice(-8));
|
4179
4417
|
return Number(dataview.getBigUint64(0, false) % BigInt(networkShards));
|
4180
4418
|
}
|
@@ -4351,4 +4589,4 @@ var version_0 = /*#__PURE__*/Object.freeze({
|
|
4351
4589
|
proto: message
|
4352
4590
|
});
|
4353
4591
|
|
4354
|
-
export { DecodedMessage as D, Encoder as E, FilterSubscribeRequest as F, MessagePush as M, PushRpc$1 as P, StoreQueryRequest$1 as S, Version as V, WakuMetadataRequest as W,
|
4592
|
+
export { DecodedMessage as D, Encoder as E, FilterSubscribeRequest as F, MessagePush as M, PushRpc$1 as P, StoreQueryRequest$1 as S, Version as V, WakuMetadataRequest as W, allocUnsafe as a, alloc$1 as b, encode as c, decode as d, encodingLength as e, FilterSubscribeResponse$1 as f, PushResponse as g, StoreQueryResponse$1 as h, bases as i, fromString as j, createEncoder as k, bytesToUtf8 as l, pubsubTopicsToShardInfo as m, WakuMetadataResponse as n, createDecoder as o, pubsubTopicToSingleShardInfo as p, message as q, Decoder as r, shardInfoToPubsubTopics as s, toString as t, utf8ToBytes as u, version_0 as v };
|