From 5ec18fb4735a822c8f39e1ccb96415895bdb6281 Mon Sep 17 00:00:00 2001 From: SionoiS Date: Thu, 7 May 2026 14:43:12 -0400 Subject: [PATCH] update to latest libp2p --- apps/chat2/chat2.nim | 8 +- apps/chat2disco/chat2disco.nim | 8 +- apps/chat2mix/chat2mix.nim | 8 +- apps/networkmonitor/networkmonitor.nim | 2 +- apps/wakucanary/wakucanary.nim | 4 +- config.nims | 3 +- examples/filter_subscriber.nim | 4 +- .../lightpush_mix/lightpush_publisher_mix.nim | 8 +- examples/lightpush_publisher.nim | 4 +- examples/publisher.nim | 4 +- examples/subscriber.nim | 4 +- nimble.lock | 607 ------------------ tests/node/test_wakunode_filter.nim | 4 +- tests/node/test_wakunode_relay_rln.nim | 8 +- tests/test_helpers.nim | 12 +- tests/test_waku_dnsdisc.nim | 2 +- tests/test_waku_keystore.nim | 40 +- tests/test_waku_keystore_keyfile.nim | 20 +- tests/test_waku_noise.nim | 178 ++--- tests/test_waku_noise_sessions.nim | 38 +- tests/testlib/common.nim | 12 +- tests/testlib/wakucore.nim | 6 +- tests/waku_discv5/test_waku_discv5.nim | 10 +- tests/waku_rln_relay/utils_onchain.nim | 4 +- tests/wakunode_rest/test_rest_cors.nim | 2 +- tests/wakunode_rest/test_rest_debug.nim | 2 +- tests/wakunode_rest/test_rest_health.nim | 2 +- waku.nimble | 3 +- waku/api/types.nim | 4 +- waku/discovery/autonat_service.nim | 4 +- waku/discovery/waku_discv5.nim | 8 +- waku/discovery/waku_kademlia.nim | 3 +- waku/factory/builder.nim | 6 +- .../factory/conf_builder/mix_conf_builder.nim | 2 +- .../conf_builder/waku_conf_builder.nim | 6 +- waku/factory/node_factory.nim | 6 +- waku/factory/waku.nim | 4 +- waku/node/kernel_api/lightpush.nim | 2 +- waku/node/peer_manager/waku_peer_store.nim | 3 +- waku/node/waku_node.nim | 9 +- waku/node/waku_switch.nim | 4 +- waku/utils/requests.nim | 6 +- waku/waku_enr/capabilities.nim | 2 +- waku/waku_filter_v2/client.nim | 10 +- waku/waku_lightpush/client.nim | 6 +- waku/waku_lightpush/protocol.nim | 6 +- waku/waku_lightpush_legacy/client.nim | 6 +- waku/waku_lightpush_legacy/protocol.nim | 6 +- waku/waku_mix/protocol.nim | 12 +- waku/waku_noise/noise.nim | 6 +- .../waku_noise/noise_handshake_processing.nim | 6 +- waku/waku_noise/noise_utils.nim | 22 +- waku/waku_relay/protocol.nim | 3 +- waku/waku_rendezvous/client.nim | 8 +- waku/waku_rendezvous/protocol.nim | 12 +- waku/waku_store/client.nim | 6 +- waku/waku_store/protocol.nim | 5 +- 57 files changed, 294 insertions(+), 896 deletions(-) delete mode 100644 nimble.lock diff --git a/apps/chat2/chat2.nim b/apps/chat2/chat2.nim index e76c7be17..5da722e3a 100644 --- a/apps/chat2/chat2.nim +++ b/apps/chat2/chat2.nim @@ -12,7 +12,7 @@ import chronicles, chronos, eth/keys, - bearssl, + stew/[byteutils, results], metrics, metrics/chronos_httpserver @@ -301,7 +301,7 @@ proc readInput(wfd: AsyncFD) {.thread, raises: [Defect, CatchableError].} = {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError -proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = +proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} = let transp = fromPipe(rfd) conf = Chat2Conf.load() @@ -309,7 +309,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = if conf.nodekey.isSome(): conf.nodekey.get() else: - PrivateKey.random(Secp256k1, rng[]).tryGet() + PrivateKey.random(Secp256k1, rng).tryGet() # set log level if conf.logLevel != LogLevel.NONE: @@ -564,7 +564,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = runForever() -proc main(rng: ref HmacDrbgContext) {.async.} = +proc main(rng: crypto.Rng) {.async.} = let (rfd, wfd) = createAsyncPipe() if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe: raise newException(ValueError, "Could not initialize pipe!") diff --git a/apps/chat2disco/chat2disco.nim b/apps/chat2disco/chat2disco.nim index dbe7b99cc..3ac01eb1f 100644 --- a/apps/chat2disco/chat2disco.nim +++ b/apps/chat2disco/chat2disco.nim @@ -13,7 +13,7 @@ import chronicles, chronos, eth/keys, - bearssl, + stew/byteutils, results, metrics, @@ -286,7 +286,7 @@ proc readInput(wfd: AsyncFD) {.thread, raises: [Defect, CatchableError].} = discard waitFor transp.write(line & "\r\n") {.pop.} -proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = +proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} = let transp = fromPipe(rfd) conf = Chat2DiscoConf.load() @@ -294,7 +294,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = if conf.nodekey.isSome(): conf.nodekey.get() else: - PrivateKey.random(Secp256k1, rng[]).tryGet() + PrivateKey.random(Secp256k1, rng).tryGet() # set log level if conf.logLevel != LogLevel.NONE: @@ -418,7 +418,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = runForever() -proc main(rng: ref HmacDrbgContext) {.async.} = +proc main(rng: crypto.Rng) {.async.} = let (rfd, wfd) = createAsyncPipe() if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe: raise newException(ValueError, "Could not initialize pipe!") diff --git a/apps/chat2mix/chat2mix.nim b/apps/chat2mix/chat2mix.nim index 374f670b8..10e15d4a5 100644 --- a/apps/chat2mix/chat2mix.nim +++ b/apps/chat2mix/chat2mix.nim @@ -12,7 +12,7 @@ import chronicles, chronos, eth/keys, - bearssl, + results, stew/[byteutils], metrics, @@ -391,7 +391,7 @@ proc maintainSubscription( {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError -proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = +proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} = let transp = fromPipe(rfd) conf = Chat2Conf.load() @@ -399,7 +399,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = if conf.nodekey.isSome(): conf.nodekey.get() else: - PrivateKey.random(Secp256k1, rng[]).tryGet() + PrivateKey.random(Secp256k1, rng).tryGet() # set log level if conf.logLevel != LogLevel.NONE: @@ -655,7 +655,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = runForever() -proc main(rng: ref HmacDrbgContext) {.async.} = +proc main(rng: crypto.Rng) {.async.} = let (rfd, wfd) = createAsyncPipe() if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe: raise newException(ValueError, "Could not initialize pipe!") diff --git a/apps/networkmonitor/networkmonitor.nim b/apps/networkmonitor/networkmonitor.nim index 23607b118..5b37e80f4 100644 --- a/apps/networkmonitor/networkmonitor.nim +++ b/apps/networkmonitor/networkmonitor.nim @@ -423,7 +423,7 @@ proc initAndStartApp( let # some hardcoded parameters rng = keys.newRng() - key = crypto.PrivateKey.random(Secp256k1, rng[])[] + key = crypto.PrivateKey.random(Secp256k1, rng)[] nodeTcpPort = Port(60000) nodeUdpPort = Port(9000) flags = CapabilitiesBitfield.init( diff --git a/apps/wakucanary/wakucanary.nim b/apps/wakucanary/wakucanary.nim index e7b1ff9aa..96dfb19c4 100644 --- a/apps/wakucanary/wakucanary.nim +++ b/apps/wakucanary/wakucanary.nim @@ -159,7 +159,7 @@ proc pingNode( error "Failed to ping the peer", peer = peerInfo, err = msg return false -proc main(rng: ref HmacDrbgContext): Future[int] {.async.} = +proc main(rng: crypto.Rng): Future[int] {.async.} = let conf: WakuCanaryConf = WakuCanaryConf.load() # create dns resolver @@ -190,7 +190,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} = quit(QuitFailure) let - nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[] + nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[] bindIp = parseIpAddress("0.0.0.0") wsBindPort = Port(conf.nodePort + WebSocketPortOffset) nodeTcpPort = Port(conf.nodePort) diff --git a/config.nims b/config.nims index 796716d3b..5346a8d8b 100644 --- a/config.nims +++ b/config.nims @@ -5,6 +5,8 @@ if defined(release): else: switch("nimcache", "nimcache/debug/$projectName") +switch("passL", getCurrentDir() / "librln_v0.9.0.a") + if defined(windows): switch("passL", "rln.lib") switch("define", "postgres=false") @@ -120,7 +122,6 @@ if defined(android): switch("passL", "--sysroot=" & sysRoot) switch("cincludes", sysRoot & "/usr/include/") # begin Nimble config (version 2) ---noNimblePath when withDir(thisDir(), system.fileExists("nimble.paths")): include "nimble.paths" # end Nimble config diff --git a/examples/filter_subscriber.nim b/examples/filter_subscriber.nim index 03a5de4eb..1b3ed6e17 100644 --- a/examples/filter_subscriber.nim +++ b/examples/filter_subscriber.nim @@ -43,13 +43,13 @@ proc messagePushHandler( contentTopic = message.contentTopic, timestamp = message.timestamp -proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} = +proc setupAndSubscribe(rng: crypto.Rng) {.async.} = # use notice to filter all waku messaging setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT) notice "starting subscriber", wakuPort = wakuPort let - nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[] + nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[] ip = parseIpAddress("0.0.0.0") flags = CapabilitiesBitfield.init(relay = true) diff --git a/examples/lightpush_mix/lightpush_publisher_mix.nim b/examples/lightpush_mix/lightpush_publisher_mix.nim index 104de8552..b9bc26c4f 100644 --- a/examples/lightpush_mix/lightpush_publisher_mix.nim +++ b/examples/lightpush_mix/lightpush_publisher_mix.nim @@ -7,8 +7,8 @@ import confutils, libp2p/crypto/crypto, libp2p/crypto/curve25519, - libp2p/protocols/mix, - libp2p/protocols/mix/curve25519, + libp2p_mix, + libp2p_mix/curve25519, libp2p/multiaddress, eth/keys, eth/p2p/discoveryv5/enr, @@ -48,13 +48,13 @@ proc splitPeerIdAndAddr(maddr: string): (string, string) = peerId = parts[1] return (address, peerId) -proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.} = +proc setupAndPublish(rng: crypto.Rng, conf: LightPushMixConf) {.async.} = # use notice to filter all waku messaging setupLog(logging.LogLevel.DEBUG, logging.LogFormat.TEXT) notice "starting publisher", wakuPort = conf.port let - nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get() + nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get() ip = parseIpAddress("0.0.0.0") flags = CapabilitiesBitfield.init(relay = true) diff --git a/examples/lightpush_publisher.nim b/examples/lightpush_publisher.nim index c7eacdd30..e55fcc9b1 100644 --- a/examples/lightpush_publisher.nim +++ b/examples/lightpush_publisher.nim @@ -35,13 +35,13 @@ const LightpushPubsubTopic = PubsubTopic("/waku/2/rs/1/0") LightpushContentTopic = ContentTopic("/examples/1/light-pubsub-example/proto") -proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} = +proc setupAndPublish(rng: crypto.Rng) {.async.} = # use notice to filter all waku messaging setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT) notice "starting publisher", wakuPort = wakuPort let - nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get() + nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get() ip = parseIpAddress("0.0.0.0") flags = CapabilitiesBitfield.init(relay = true) diff --git a/examples/publisher.nim b/examples/publisher.nim index 6f5d34bc4..d3ee032a3 100644 --- a/examples/publisher.nim +++ b/examples/publisher.nim @@ -37,13 +37,13 @@ const bootstrapNode = const wakuPort = 60000 const discv5Port = 9000 -proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} = +proc setupAndPublish(rng: crypto.Rng) {.async.} = # use notice to filter all waku messaging setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT) notice "starting publisher", wakuPort = wakuPort, discv5Port = discv5Port let - nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get() + nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get() ip = parseIpAddress("0.0.0.0") flags = CapabilitiesBitfield.init(relay = true) diff --git a/examples/subscriber.nim b/examples/subscriber.nim index ce64bb803..36bc4554c 100644 --- a/examples/subscriber.nim +++ b/examples/subscriber.nim @@ -35,13 +35,13 @@ const bootstrapNode = const wakuPort = 50000 const discv5Port = 8000 -proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} = +proc setupAndSubscribe(rng: crypto.Rng) {.async.} = # use notice to filter all waku messaging setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT) notice "starting subscriber", wakuPort = wakuPort, discv5Port = discv5Port let - nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[] + nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[] ip = parseIpAddress("0.0.0.0") flags = CapabilitiesBitfield.init(relay = true) diff --git a/nimble.lock b/nimble.lock deleted file mode 100644 index 7c76f7fa9..000000000 --- a/nimble.lock +++ /dev/null @@ -1,607 +0,0 @@ -{ - "version": 2, - "packages": { - "nim": { - "version": "2.2.4", - "vcsRevision": "911e0dbb1f76de61fa0215ab1bb85af5334cc9a8", - "url": "https://github.com/nim-lang/Nim.git", - "downloadMethod": "git", - "dependencies": [], - "checksums": { - "sha1": "68bb85cbfb1832ce4db43943911b046c3af3caab" - } - }, - "unittest2": { - "version": "0.2.5", - "vcsRevision": "26f2ef3ae0ec72a2a75bfe557e02e88f6a31c189", - "url": "https://github.com/status-im/nim-unittest2", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "02bb3751ba9ddc3c17bfd89f2e41cb6bfb8fc0c9" - } - }, - "bearssl": { - "version": "0.2.8", - "vcsRevision": "22c6a76ce015bc07e011562bdcfc51d9446c1e82", - "url": "https://github.com/status-im/nim-bearssl", - "downloadMethod": "git", - "dependencies": [ - "nim", - "unittest2" - ], - "checksums": { - "sha1": "da4dd7ae96d536bdaf42dca9c85d7aed024b6a86" - } - }, - "bearssl_pkey_decoder": { - "version": "#21dd3710df9345ed2ad8bf8f882761e07863b8e0", - "vcsRevision": "21dd3710df9345ed2ad8bf8f882761e07863b8e0", - "url": "https://github.com/vacp2p/bearssl_pkey_decoder", - "downloadMethod": "git", - "dependencies": [ - "nim", - "bearssl" - ], - "checksums": { - "sha1": "21b42e2e6ddca6c875d3fc50f36a5115abf51714" - } - }, - "jwt": { - "version": "#18f8378de52b241f321c1f9ea905456e89b95c6f", - "vcsRevision": "18f8378de52b241f321c1f9ea905456e89b95c6f", - "url": "https://github.com/vacp2p/nim-jwt.git", - "downloadMethod": "git", - "dependencies": [ - "nim", - "bearssl", - "bearssl_pkey_decoder" - ], - "checksums": { - "sha1": "bcfd6fc9c5e10a52b87117219b7ab5c98136bc8e" - } - }, - "testutils": { - "version": "0.8.1", - "vcsRevision": "6ce5e5e2301ccbc04b09d27ff78741ff4d352b4d", - "url": "https://github.com/status-im/nim-testutils", - "downloadMethod": "git", - "dependencies": [ - "nim", - "unittest2" - ], - "checksums": { - "sha1": "96a11cf8b84fa9bd12d4a553afa1cc4b7f9df4e3" - } - }, - "db_connector": { - "version": "0.1.0", - "vcsRevision": "29450a2063970712422e1ab857695c12d80112a6", - "url": "https://github.com/nim-lang/db_connector", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "4f2e67d0e4b61af9ac5575509305660b473f01a4" - } - }, - "results": { - "version": "0.5.1", - "vcsRevision": "df8113dda4c2d74d460a8fa98252b0b771bf1f27", - "url": "https://github.com/arnetheduck/nim-results", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "a9c011f74bc9ed5c91103917b9f382b12e82a9e7" - } - }, - "nat_traversal": { - "version": "0.0.1", - "vcsRevision": "860e18c37667b5dd005b94c63264560c35d88004", - "url": "https://github.com/status-im/nim-nat-traversal", - "downloadMethod": "git", - "dependencies": [ - "nim", - "results" - ], - "checksums": { - "sha1": "1a376d3e710590ef2c48748a546369755f0a7c97" - } - }, - "stew": { - "version": "0.5.0", - "vcsRevision": "4382b18f04b3c43c8409bfcd6b62063773b2bbaa", - "url": "https://github.com/status-im/nim-stew", - "downloadMethod": "git", - "dependencies": [ - "nim", - "results", - "unittest2" - ], - "checksums": { - "sha1": "db22942939773ab7d5a0f2b2668c237240c67dd6" - } - }, - "zlib": { - "version": "0.1.0", - "vcsRevision": "e680f269fb01af2c34a2ba879ff281795a5258fe", - "url": "https://github.com/status-im/nim-zlib", - "downloadMethod": "git", - "dependencies": [ - "nim", - "stew", - "results" - ], - "checksums": { - "sha1": "bbde4f5a97a84b450fef7d107461e5f35cf2b47f" - } - }, - "httputils": { - "version": "0.4.1", - "vcsRevision": "f142cb2e8bd812dd002a6493b6082827bb248592", - "url": "https://github.com/status-im/nim-http-utils", - "downloadMethod": "git", - "dependencies": [ - "nim", - "stew", - "results", - "unittest2" - ], - "checksums": { - "sha1": "016774ab31c3afff9a423f7d80584905ee59c570" - } - }, - "chronos": { - "version": "4.2.2", - "vcsRevision": "45f43a9ad8bd8bcf5903b42f365c1c879bd54240", - "url": "https://github.com/status-im/nim-chronos", - "downloadMethod": "git", - "dependencies": [ - "nim", - "results", - "stew", - "bearssl", - "httputils", - "unittest2" - ], - "checksums": { - "sha1": "3a4c9477df8cef20a04e4f1b54a2d74fdfc2a3d0" - } - }, - "metrics": { - "version": "0.2.1", - "vcsRevision": "a1296caf3ebb5f30f51a5feae7749a30df2824c2", - "url": "https://github.com/status-im/nim-metrics", - "downloadMethod": "git", - "dependencies": [ - "nim", - "chronos", - "results", - "stew" - ], - "checksums": { - "sha1": "84bb09873d7677c06046f391c7b473cd2fcff8a2" - } - }, - "faststreams": { - "version": "0.5.0", - "vcsRevision": "ce27581a3e881f782f482cb66dc5b07a02bd615e", - "url": "https://github.com/status-im/nim-faststreams", - "downloadMethod": "git", - "dependencies": [ - "nim", - "stew", - "unittest2" - ], - "checksums": { - "sha1": "ee61e507b805ae1df7ec936f03f2d101b0d72383" - } - }, - "snappy": { - "version": "0.1.0", - "vcsRevision": "00bfcef94f8ef6981df5d5b994897f6695badfb2", - "url": "https://github.com/status-im/nim-snappy", - "downloadMethod": "git", - "dependencies": [ - "nim", - "faststreams", - "unittest2", - "results", - "stew" - ], - "checksums": { - "sha1": "e572d60d6a3178c5b1cde2400c51ad771812cd3d" - } - }, - "serialization": { - "version": "0.5.2", - "vcsRevision": "b0f2fa32960ea532a184394b0f27be37bd80248b", - "url": "https://github.com/status-im/nim-serialization", - "downloadMethod": "git", - "dependencies": [ - "nim", - "faststreams", - "unittest2", - "stew" - ], - "checksums": { - "sha1": "fa35c1bb76a0a02a2379fe86eaae0957c7527cb8" - } - }, - "toml_serialization": { - "version": "0.2.18", - "vcsRevision": "b5b387e6fb2a7cc75d54a269b07cc6218361bd46", - "url": "https://github.com/status-im/nim-toml-serialization", - "downloadMethod": "git", - "dependencies": [ - "nim", - "faststreams", - "serialization", - "stew" - ], - "checksums": { - "sha1": "76ae1c2af5dd092849b41750ff29217980dc9ca3" - } - }, - "confutils": { - "version": "0.1.0", - "vcsRevision": "7728f6bd81a1eedcfe277d02ea85fdb805bcc05a", - "url": "https://github.com/status-im/nim-confutils", - "downloadMethod": "git", - "dependencies": [ - "nim", - "stew", - "serialization", - "results" - ], - "checksums": { - "sha1": "8bc8c30b107fdba73b677e5f257c6c42ae1cdc8e" - } - }, - "json_serialization": { - "version": "0.4.4", - "vcsRevision": "c343b0e243d9e17e2c40f3a8a24340f7c4a71d44", - "url": "https://github.com/status-im/nim-json-serialization", - "downloadMethod": "git", - "dependencies": [ - "nim", - "faststreams", - "serialization", - "stew", - "results" - ], - "checksums": { - "sha1": "8b3115354104858a0ac9019356fb29720529c2bd" - } - }, - "chronicles": { - "version": "0.12.2", - "vcsRevision": "27ec507429a4eb81edc20f28292ee8ec420be05b", - "url": "https://github.com/status-im/nim-chronicles", - "downloadMethod": "git", - "dependencies": [ - "nim", - "faststreams", - "serialization", - "json_serialization", - "testutils" - ], - "checksums": { - "sha1": "02febb20d088120b2836d3306cfa21f434f88f65" - } - }, - "presto": { - "version": "0.1.1", - "vcsRevision": "d66043dd7ede146442e6c39720c76a20bde5225f", - "url": "https://github.com/status-im/nim-presto", - "downloadMethod": "git", - "dependencies": [ - "nim", - "chronos", - "chronicles", - "metrics", - "results", - "stew" - ], - "checksums": { - "sha1": "8df97c45683abe2337bdff43b844c4fbcc124ca2" - } - }, - "stint": { - "version": "0.8.2", - "vcsRevision": "470b7892561b5179ab20bd389a69217d6213fe58", - "url": "https://github.com/status-im/nim-stint", - "downloadMethod": "git", - "dependencies": [ - "nim", - "stew", - "unittest2" - ], - "checksums": { - "sha1": "d8f871fd617e7857192d4609fe003b48942a8ae5" - } - }, - "minilru": { - "version": "0.1.0", - "vcsRevision": "6dd93feb60f4cded3c05e7af7209cf63fb677893", - "url": "https://github.com/status-im/nim-minilru", - "downloadMethod": "git", - "dependencies": [ - "nim", - "results", - "unittest2" - ], - "checksums": { - "sha1": "0be03a5da29fdd4409ea74a60fd0ccce882601b4" - } - }, - "sqlite3_abi": { - "version": "3.53.0.0", - "vcsRevision": "8240e8e2819dfce1b67fa2733135d01b5cc80ae0", - "url": "https://github.com/arnetheduck/nim-sqlite3-abi", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "fb7a6e6f36fc4eb4dfa6634dbcbf5cd0dfd0ebf0" - } - }, - "dnsclient": { - "version": "0.3.4", - "vcsRevision": "23214235d4784d24aceed99bbfe153379ea557c8", - "url": "https://github.com/ba0f3/dnsclient.nim", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "65262c7e533ff49d6aca5539da4bc6c6ce132f40" - } - }, - "unicodedb": { - "version": "0.13.2", - "vcsRevision": "66f2458710dc641dd4640368f9483c8a0ec70561", - "url": "https://github.com/nitely/nim-unicodedb", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "739102d885d99bb4571b1955f5f12aee423c935b" - } - }, - "regex": { - "version": "0.26.3", - "vcsRevision": "4593305ed1e49731fc75af1dc572dd2559aad19c", - "url": "https://github.com/nitely/nim-regex", - "downloadMethod": "git", - "dependencies": [ - "nim", - "unicodedb" - ], - "checksums": { - "sha1": "4d24e7d7441137cd202e16f2359a5807ddbdc31f" - } - }, - "nimcrypto": { - "version": "0.6.4", - "vcsRevision": "721fb99ee099b632eb86dfad1f0d96ee87583774", - "url": "https://github.com/cheatfate/nimcrypto", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "f9ab24fa940ed03d0fb09729a7303feb50b7eaec" - } - }, - "websock": { - "version": "0.3.0", - "vcsRevision": "c105d98e6522e0e2cbe3dfa11b07a273e9fd0e7b", - "url": "https://github.com/status-im/nim-websock", - "downloadMethod": "git", - "dependencies": [ - "nim", - "chronos", - "httputils", - "chronicles", - "stew", - "nimcrypto", - "bearssl", - "results", - "zlib" - ], - "checksums": { - "sha1": "1294a66520fa4541e261dec8a6a84f774fb8c0ac" - } - }, - "json_rpc": { - "version": "#43bbf499143eb45046c83ac9794c9e3280a2b8e7", - "vcsRevision": "43bbf499143eb45046c83ac9794c9e3280a2b8e7", - "url": "https://github.com/status-im/nim-json-rpc.git", - "downloadMethod": "git", - "dependencies": [ - "nim", - "stew", - "nimcrypto", - "stint", - "chronos", - "httputils", - "chronicles", - "websock", - "serialization", - "json_serialization", - "unittest2" - ], - "checksums": { - "sha1": "30ff6ead115b88c79862c5c7e37b1c9852eea59f" - } - }, - "lsquic": { - "version": "0.0.1", - "vcsRevision": "4fb03ee7bfb39aecb3316889fdcb60bec3d0936f", - "url": "https://github.com/vacp2p/nim-lsquic", - "downloadMethod": "git", - "dependencies": [ - "nim", - "zlib", - "stew", - "chronos", - "nimcrypto", - "unittest2", - "chronicles" - ], - "checksums": { - "sha1": "f465fa994346490d0924d162f53d9b5aec62f948" - } - }, - "secp256k1": { - "version": "0.6.0.3.2", - "vcsRevision": "d8f1288b7c72f00be5fc2c5ea72bf5cae1eafb15", - "url": "https://github.com/status-im/nim-secp256k1", - "downloadMethod": "git", - "dependencies": [ - "nim", - "stew", - "results", - "nimcrypto" - ], - "checksums": { - "sha1": "6618ef9de17121846a8c1d0317026b0ce8584e10" - } - }, - "eth": { - "version": "0.9.0", - "vcsRevision": "d9135e6c3c5d6d819afdfb566aa8d958756b73a8", - "url": "https://github.com/status-im/nim-eth", - "downloadMethod": "git", - "dependencies": [ - "nim", - "nimcrypto", - "stint", - "secp256k1", - "chronos", - "chronicles", - "stew", - "nat_traversal", - "metrics", - "sqlite3_abi", - "confutils", - "testutils", - "unittest2", - "results", - "minilru", - "snappy" - ], - "checksums": { - "sha1": "2e01b0cfff9523d110562af70d19948280f8013e" - } - }, - "web3": { - "version": "0.8.0", - "vcsRevision": "cdfe5601d2812a58e54faf53ee634452d01e5918", - "url": "https://github.com/status-im/nim-web3", - "downloadMethod": "git", - "dependencies": [ - "nim", - "chronicles", - "chronos", - "bearssl", - "eth", - "faststreams", - "json_rpc", - "serialization", - "json_serialization", - "nimcrypto", - "stew", - "stint", - "results" - ], - "checksums": { - "sha1": "26a112af032ef1536f97da2ca7364af618a11b80" - } - }, - "dnsdisc": { - "version": "0.1.0", - "vcsRevision": "38f2e0f52c0a8f032ef4530835e519d550706d9e", - "url": "https://github.com/status-im/nim-dnsdisc", - "downloadMethod": "git", - "dependencies": [ - "nim", - "bearssl", - "chronicles", - "chronos", - "eth", - "secp256k1", - "stew", - "testutils", - "unittest2", - "nimcrypto", - "results" - ], - "checksums": { - "sha1": "055b882a0f6b1d1e57a25a7af99d2e5ac6268154" - } - }, - "libp2p": { - "version": "#ff8d51857b4b79a68468e7bcc27b2026cca02996", - "vcsRevision": "ff8d51857b4b79a68468e7bcc27b2026cca02996", - "url": "https://github.com/vacp2p/nim-libp2p.git", - "downloadMethod": "git", - "dependencies": [ - "nim", - "nimcrypto", - "dnsclient", - "bearssl", - "chronicles", - "chronos", - "metrics", - "secp256k1", - "stew", - "websock", - "unittest2", - "results", - "serialization", - "lsquic", - "jwt" - ], - "checksums": { - "sha1": "fa2a7552c6ec860717b77ce34cf0b7afe4570234" - } - }, - "taskpools": { - "version": "0.1.0", - "vcsRevision": "9e8ccc754631ac55ac2fd495e167e74e86293edb", - "url": "https://github.com/status-im/nim-taskpools", - "downloadMethod": "git", - "dependencies": [ - "nim" - ], - "checksums": { - "sha1": "09e1b2fdad55b973724d61227971afc0df0b7a81" - } - }, - "ffi": { - "version": "0.1.3", - "vcsRevision": "06111de155253b34e47ed2aaed1d61d08d62cc1b", - "url": "https://github.com/logos-messaging/nim-ffi", - "downloadMethod": "git", - "dependencies": [ - "nim", - "chronos", - "chronicles", - "taskpools" - ], - "checksums": { - "sha1": "6f9d49375ea1dc71add55c72ac80a808f238e5b0" - } - } - }, - "tasks": {} -} diff --git a/tests/node/test_wakunode_filter.nim b/tests/node/test_wakunode_filter.nim index 2777b0124..2deaa8833 100644 --- a/tests/node/test_wakunode_filter.nim +++ b/tests/node/test_wakunode_filter.nim @@ -21,9 +21,9 @@ import ../testlib/[common, wakucore, wakunode, testasync, futures, testutils], ../waku_filter_v2/waku_filter_utils -proc generateRequestId(rng: ref HmacDrbgContext): string = +proc generateRequestId(rng: crypto.Rng): string = var bytes: array[10, byte] - hmacDrbgGenerate(rng[], bytes) + rng.generate(bytes) return toHex(bytes) proc createRequest( diff --git a/tests/node/test_wakunode_relay_rln.nim b/tests/node/test_wakunode_relay_rln.nim index c8ca9b43d..1169ce7b3 100644 --- a/tests/node/test_wakunode_relay_rln.nim +++ b/tests/node/test_wakunode_relay_rln.nim @@ -35,10 +35,10 @@ from ../../waku/waku_noise/noise_utils import randomSeqByte proc buildRandomIdentityCredentials(): IdentityCredential = # We generate a random identity credential (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) IdentityCredential( idTrapdoor: idTrapdoor, diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index bd1d837b6..a2ec045ea 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -1,4 +1,4 @@ -import chronos, bearssl/rand, eth/[keys, p2p] +import chronos, eth/[keys, p2p] import libp2p/crypto/crypto @@ -9,10 +9,10 @@ proc localAddress*(port: int): Address = result = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("127.0.0.1")) proc setupTestNode*( - rng: ref HmacDrbgContext, capabilities: varargs[ProtocolInfo, `protocolInfo`] + rng: crypto.Rng, capabilities: varargs[ProtocolInfo, `protocolInfo`] ): EthereumNode = let - keys1 = keys.KeyPair.random(rng[]) + keys1 = keys.KeyPair.random(rng) address = localAddress(nextPort) result = newEthereumNode( keys1, @@ -29,11 +29,11 @@ proc setupTestNode*( # Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28 type RngWrap = object - rng: ref rand.HmacDrbgContext + rng: Rng var rngVar: RngWrap -proc getRng(): ref rand.HmacDrbgContext = +proc getRng(): Rng = # TODO if `rngVar` is a threadvar like it should be, there are random and # spurious compile failures on mac - this is not gcsafe but for the # purpose of the tests, it's ok as long as we only use a single thread @@ -42,5 +42,5 @@ proc getRng(): ref rand.HmacDrbgContext = rngVar.rng = crypto.newRng() rngVar.rng -template rng*(): ref rand.HmacDrbgContext = +template rng*(): Rng = getRng() diff --git a/tests/test_waku_dnsdisc.nim b/tests/test_waku_dnsdisc.nim index 758bdb3ca..9c6dde7d6 100644 --- a/tests/test_waku_dnsdisc.nim +++ b/tests/test_waku_dnsdisc.nim @@ -52,7 +52,7 @@ suite "Waku DNS Discovery": ) .get() # No link entries - let treeKeys = keys.KeyPair.random(rng[]) + let treeKeys = keys.KeyPair.random(rng) # Sign tree check: diff --git a/tests/test_waku_keystore.nim b/tests/test_waku_keystore.nim index 8fd8ad297..83536b062 100644 --- a/tests/test_waku_keystore.nim +++ b/tests/test_waku_keystore.nim @@ -46,10 +46,10 @@ procSuite "Credentials test suite": # We generate a random identity credential (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) var - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) var idCredential = IdentityCredential( idTrapdoor: idTrapdoor, @@ -85,10 +85,10 @@ procSuite "Credentials test suite": # We generate two random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) var - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, @@ -141,10 +141,10 @@ procSuite "Credentials test suite": # We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, @@ -193,10 +193,10 @@ procSuite "Credentials test suite": # We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, @@ -254,10 +254,10 @@ procSuite "Credentials test suite": # We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, diff --git a/tests/test_waku_keystore_keyfile.nim b/tests/test_waku_keystore_keyfile.nim index afdb7e44b..cd187baf6 100644 --- a/tests/test_waku_keystore_keyfile.nim +++ b/tests/test_waku_keystore_keyfile.nim @@ -16,7 +16,7 @@ suite "KeyFile test suite": removeFile(filepath) # The secret - var secret = randomSeqByte(rng[], 300) + var secret = randomSeqByte(rng, 300) # We create a keyfile encrypting the secret with password let keyfile = createKeyFileJson(secret, password) @@ -42,9 +42,9 @@ suite "KeyFile test suite": test "Create/Save/Load multiple keyfiles in same file": # We set different passwords for different keyfiles that will be stored in same file - let password1 = string.fromBytes(randomSeqByte(rng[], 20)) + let password1 = string.fromBytes(randomSeqByte(rng, 20)) let password2 = "" - let password3 = string.fromBytes(randomSeqByte(rng[], 20)) + let password3 = string.fromBytes(randomSeqByte(rng, 20)) var keyfile: KfResult[JsonNode] let filepath = "./test.keyfile" @@ -53,40 +53,40 @@ suite "KeyFile test suite": # We generate 6 different secrets and we encrypt them using 3 different passwords, and we store the obtained keystore - let secret1 = randomSeqByte(rng[], 300) + let secret1 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret1, password1) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() - let secret2 = randomSeqByte(rng[], 300) + let secret2 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret2, password2) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() - let secret3 = randomSeqByte(rng[], 300) + let secret3 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret3, password3) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() # We encrypt secret4 with password3 - let secret4 = randomSeqByte(rng[], 300) + let secret4 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret4, password3) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() # We encrypt secret5 with password1 - let secret5 = randomSeqByte(rng[], 300) + let secret5 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret5, password1) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() # We encrypt secret6 with password1 - let secret6 = randomSeqByte(rng[], 300) + let secret6 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret6, password1) check: keyfile.isOk() @@ -343,7 +343,7 @@ suite "KeyFile test suite (adapted from nim-eth keyfile tests)": test "Scrypt keyfiles": let - expectedSecret = randomSeqByte(rng[], 300) + expectedSecret = randomSeqByte(rng, 300) password = "miawmiawcat" # By default, keyfiles' encryption key is derived from password using PBKDF2. diff --git a/tests/test_waku_noise.nim b/tests/test_waku_noise.nim index 6566f9eed..6dbb3a2f9 100644 --- a/tests/test_waku_noise.nim +++ b/tests/test_waku_noise.nim @@ -27,7 +27,7 @@ procSuite "Waku Noise": let maxMessageLength = 3 * NoisePaddingBlockSize for messageLen in 0 .. maxMessageLength: let - message = randomSeqByte(rng[], messageLen) + message = randomSeqByte(rng, messageLen) padded = pkcs7_pad(message, NoisePaddingBlockSize) unpadded = pkcs7_unpad(padded, NoisePaddingBlockSize) @@ -37,11 +37,11 @@ procSuite "Waku Noise": message == unpadded test "ChaChaPoly Encryption/Decryption: random byte sequences": - let cipherState = randomChaChaPolyCipherState(rng[]) + let cipherState = randomChaChaPolyCipherState(rng) # We encrypt/decrypt random byte sequences let - plaintext: seq[byte] = randomSeqByte(rng[], rand(1 .. 128)) + plaintext: seq[byte] = randomSeqByte(rng, rand(1 .. 128)) ciphertext: ChaChaPolyCiphertext = encrypt(cipherState, plaintext) decryptedCiphertext: seq[byte] = decrypt(cipherState, ciphertext) @@ -49,7 +49,7 @@ procSuite "Waku Noise": plaintext == decryptedCiphertext test "ChaChaPoly Encryption/Decryption: random strings": - let cipherState = randomChaChaPolyCipherState(rng[]) + let cipherState = randomChaChaPolyCipherState(rng) # We encrypt/decrypt random strings var plaintext: string @@ -64,10 +64,10 @@ procSuite "Waku Noise": plaintext.toBytes() == decryptedCiphertext test "Noise public keys: encrypt and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk) @@ -75,20 +75,20 @@ procSuite "Waku Noise": noisePublicKey == decryptedPk test "Noise public keys: decrypt an unencrypted public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, noisePublicKey) check: noisePublicKey == decryptedPk test "Noise public keys: encrypt an encrypted public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) encryptedPk2: NoisePublicKey = encryptNoisePublicKey(cs, encryptedPk) @@ -96,10 +96,10 @@ procSuite "Waku Noise": encryptedPk == encryptedPk2 test "Noise public keys: encrypt, decrypt and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk) decryptedPk2: NoisePublicKey = decryptNoisePublicKey(cs, decryptedPk) @@ -109,7 +109,7 @@ procSuite "Waku Noise": test "Noise public keys: serialize and deserialize an unencrypted public key": let - noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(noisePublicKey) deserializedNoisePublicKey: NoisePublicKey = intoNoisePublicKey(serializedNoisePublicKey) @@ -118,10 +118,10 @@ procSuite "Waku Noise": noisePublicKey == deserializedNoisePublicKey test "Noise public keys: encrypt, serialize, deserialize and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(encryptedPk) deserializedNoisePublicKey: NoisePublicKey = @@ -134,7 +134,7 @@ procSuite "Waku Noise": test "PayloadV2: serialize/deserialize PayloadV2 to byte sequence": let - payload2: PayloadV2 = randomPayloadV2(rng[]) + payload2: PayloadV2 = randomPayloadV2(rng) serializedPayload = serializePayloadV2(payload2) check: @@ -149,7 +149,7 @@ procSuite "Waku Noise": test "PayloadV2: Encode/Decode a Waku Message (version 2) to a PayloadV2": # We encode to a WakuMessage a random PayloadV2 let - payload2 = randomPayloadV2(rng[]) + payload2 = randomPayloadV2(rng) msg = encodePayloadV2(payload2) check: @@ -173,8 +173,8 @@ procSuite "Waku Noise": test "Noise State Machine: Diffie-Hellman operation": #We generate random keypairs let - aliceKey = genKeyPair(rng[]) - bobKey = genKeyPair(rng[]) + aliceKey = genKeyPair(rng) + bobKey = genKeyPair(rng) # A Diffie-Hellman operation between Alice's private key and Bob's public key must be equal to # a Diffie-hellman operation between Alice's public key and Bob's private key @@ -188,10 +188,10 @@ procSuite "Waku Noise": test "Noise State Machine: Cipher State primitives": # We generate a random Cipher State, associated data ad and plaintext var - cipherState: CipherState = randomCipherState(rng[]) + cipherState: CipherState = randomCipherState(rng) nonce: uint64 = uint64(rand(0 .. int.high)) - ad: seq[byte] = randomSeqByte(rng[], rand(1 .. 128)) - plaintext: seq[byte] = randomSeqByte(rng[], rand(1 .. 128)) + ad: seq[byte] = randomSeqByte(rng, rand(1 .. 128)) + plaintext: seq[byte] = randomSeqByte(rng, rand(1 .. 128)) # We set the random nonce generated in the cipher state setNonce(cipherState, nonce) @@ -218,7 +218,7 @@ procSuite "Waku Noise": setCipherStateKey(cipherState, EmptyKey) nonce = getNonce(cipherState) - plaintext = randomSeqByte(rng[], rand(1 .. 128)) + plaintext = randomSeqByte(rng, rand(1 .. 128)) ciphertext = encryptWithAd(cipherState, ad, plaintext) check: @@ -230,7 +230,7 @@ procSuite "Waku Noise": nonce = getNonce(cipherState) # Note that we set ciphertext minimum length to 16 to not trigger checks on authentication tag length - ciphertext = randomSeqByte(rng[], rand(16 .. 128)) + ciphertext = randomSeqByte(rng, rand(16 .. 128)) plaintext = decryptWithAd(cipherState, ad, ciphertext) check: @@ -241,9 +241,9 @@ procSuite "Waku Noise": # Note that NonceMax is uint64.high - 1 = 2^64-1-1 and that nonce is increased after each encryption and decryption operation # We generate a test Cipher State with nonce set to MaxNonce - cipherState = randomCipherState(rng[]) + cipherState = randomCipherState(rng) setNonce(cipherState, NonceMax) - plaintext = randomSeqByte(rng[], rand(1 .. 128)) + plaintext = randomSeqByte(rng, rand(1 .. 128)) # We test if encryption fails with a NoiseNonceMaxError error. Any subsequent encryption call over the Cipher State should fail similarly and leave the nonce unchanged for _ in [1 .. 5]: @@ -257,9 +257,9 @@ procSuite "Waku Noise": # Since nonce is increased after decryption as well, we need to generate a proper ciphertext in order to test MaxNonceError error handling # We cannot call encryptWithAd to encrypt a plaintext using a nonce equal MaxNonce, since this will trigger a MaxNonceError. # To perform such test, we then need to encrypt a test plaintext using directly ChaChaPoly primitive - cipherState = randomCipherState(rng[]) + cipherState = randomCipherState(rng) setNonce(cipherState, NonceMax) - plaintext = randomSeqByte(rng[], rand(1 .. 128)) + plaintext = randomSeqByte(rng, rand(1 .. 128)) # We perform encryption using the Cipher State key, NonceMax and ad # By Noise specification the nonce is 8 bytes long out of the 12 bytes supported by ChaChaPoly, thus we copy the Little endian conversion of the nonce to a ChaChaPolyNonce @@ -308,7 +308,7 @@ procSuite "Waku Noise": ######################################## # We generate a random byte sequence and execute a mixHash over it - mixHash(symmetricState, randomSeqByte(rng[], rand(1 .. 128))) + mixHash(symmetricState, randomSeqByte(rng, rand(1 .. 128))) # mixHash changes only the handshake hash value of the Symmetric state check: @@ -324,7 +324,7 @@ procSuite "Waku Noise": ######################################## # We generate random input key material and we execute mixKey - var inputKeyMaterial = randomSeqByte(rng[], rand(1 .. 128)) + var inputKeyMaterial = randomSeqByte(rng, rand(1 .. 128)) mixKey(symmetricState, inputKeyMaterial) # mixKey changes the Symmetric State's chaining key and encryption key of the embedded Cipher State @@ -345,7 +345,7 @@ procSuite "Waku Noise": ######################################## # We generate random input key material and we execute mixKeyAndHash - inputKeyMaterial = randomSeqByte(rng[], rand(1 .. 128)) + inputKeyMaterial = randomSeqByte(rng, rand(1 .. 128)) mixKeyAndHash(symmetricState, inputKeyMaterial) # mixKeyAndHash executes a mixKey and a mixHash using the input key material @@ -368,7 +368,7 @@ procSuite "Waku Noise": var initialSymmetricState = symmetricState # We generate random plaintext and we execute encryptAndHash - var plaintext = randomChaChaPolyKey(rng[]) + var plaintext = randomChaChaPolyKey(rng) var nonce = getNonce(getCipherState(symmetricState)) var ciphertext = encryptAndHash(symmetricState, plaintext) @@ -421,11 +421,11 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["XX"] # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) var aliceHS = initialize(hsPattern = hsPattern, staticKey = aliceStaticKey, initiator = true) - let bobStaticKey = genKeyPair(rng[]) + let bobStaticKey = genKeyPair(rng) var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey) var @@ -440,15 +440,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -458,13 +458,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -474,14 +474,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -494,13 +494,13 @@ procSuite "Waku Noise": let prevBobHS = bobHS let bobStep1 = - stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() let aliceStep1 = - stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep1.payload2).get() + stepHandshake(rng, aliceHS, readPayloadV2 = bobStep1.payload2).get() let aliceStep2 = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() let bobStep2 = - stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep2.payload2).get() + stepHandshake(rng, bobHS, readPayloadV2 = aliceStep2.payload2).get() check: aliceStep1 == default(HandshakeStepResult) @@ -529,7 +529,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -538,7 +538,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() @@ -550,15 +550,15 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["XXpsk0"] # We generate a random psk - let psk = randomSeqByte(rng[], 32) + let psk = randomSeqByte(rng, 32) # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) var aliceHS = initialize( hsPattern = hsPattern, staticKey = aliceStaticKey, psk = psk, initiator = true ) - let bobStaticKey = genKeyPair(rng[]) + let bobStaticKey = genKeyPair(rng) var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey, psk = psk) var @@ -573,15 +573,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -591,13 +591,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -607,14 +607,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transportMessage alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -640,7 +640,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -649,7 +649,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() @@ -661,8 +661,8 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["K1K1"] # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - let bobStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) + let bobStaticKey = genKeyPair(rng) # This handshake has the following pre-message pattern: # -> s @@ -696,15 +696,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -714,13 +714,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -730,14 +730,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake_message and the (encrypted) transportMessage aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transportMessage alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -763,7 +763,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -772,7 +772,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() @@ -784,8 +784,8 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["XK1"] # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - let bobStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) + let bobStaticKey = genKeyPair(rng) # This handshake has the following pre-message pattern: # <- s @@ -816,15 +816,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -834,13 +834,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -850,14 +850,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -883,7 +883,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -892,7 +892,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() diff --git a/tests/test_waku_noise_sessions.nim b/tests/test_waku_noise_sessions.nim index 543653982..61eaa0038 100644 --- a/tests/test_waku_noise_sessions.nim +++ b/tests/test_waku_noise_sessions.nim @@ -25,22 +25,22 @@ procSuite "Waku Noise Sessions": let hsPattern = NoiseHandshakePatterns["WakuPairing"] # Alice static/ephemeral key initialization and commitment - let aliceStaticKey = genKeyPair(rng[]) - let aliceEphemeralKey = genKeyPair(rng[]) - let s = randomSeqByte(rng[], 32) + let aliceStaticKey = genKeyPair(rng) + let aliceEphemeralKey = genKeyPair(rng) + let s = randomSeqByte(rng, 32) let aliceCommittedStaticKey = commitPublicKey(getPublicKey(aliceStaticKey), s) # Bob static/ephemeral key initialization and commitment - let bobStaticKey = genKeyPair(rng[]) - let bobEphemeralKey = genKeyPair(rng[]) - let r = randomSeqByte(rng[], 32) + let bobStaticKey = genKeyPair(rng) + let bobEphemeralKey = genKeyPair(rng) + let r = randomSeqByte(rng, 32) let bobCommittedStaticKey = commitPublicKey(getPublicKey(bobStaticKey), r) # Content Topic information let applicationName = "waku-noise-sessions" let applicationVersion = "0.1" let shardId = "10" - let qrMessageNametag = randomSeqByte(rng[], MessageNametagLength) + let qrMessageNametag = randomSeqByte(rng, MessageNametagLength) # Out-of-band Communication @@ -133,7 +133,7 @@ procSuite "Waku Noise Sessions": # and the (encrypted) transport message # The message is sent with a messageNametag equal to the one received through the QR code aliceStep = stepHandshake( - rng[], + rng, aliceHS, transportMessage = sentTransportMessage, messageNametag = qrMessageNametag, @@ -168,7 +168,7 @@ procSuite "Waku Noise Sessions": # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him # Note that Bob verifies if the received payloadv2 has the expected messageNametag set bobStep = stepHandshake( - rng[], bobHS, readPayloadV2 = readPayloadV2, messageNametag = qrMessageNametag + rng, bobHS, readPayloadV2 = readPayloadV2, messageNametag = qrMessageNametag ) .get() @@ -199,7 +199,7 @@ procSuite "Waku Noise Sessions": # At this step, Bob writes and returns a payload bobStep = stepHandshake( - rng[], + rng, bobHS, transportMessage = sentTransportMessage, messageNametag = bobMessageNametag, @@ -233,7 +233,7 @@ procSuite "Waku Noise Sessions": # While Alice reads and returns the (decrypted) transport message aliceStep = stepHandshake( - rng[], + rng, aliceHS, readPayloadV2 = readPayloadV2, messageNametag = aliceMessageNametag, @@ -265,7 +265,7 @@ procSuite "Waku Noise Sessions": # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = stepHandshake( - rng[], + rng, aliceHS, transportMessage = sentTransportMessage, messageNametag = aliceMessageNametag, @@ -299,7 +299,7 @@ procSuite "Waku Noise Sessions": # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him bobStep = stepHandshake( - rng[], bobHS, readPayloadV2 = readPayloadV2, messageNametag = bobMessageNametag + rng, bobHS, readPayloadV2 = readPayloadV2, messageNametag = bobMessageNametag ) .get() @@ -333,7 +333,7 @@ procSuite "Waku Noise Sessions": # Note that we exchange more than the number of messages contained in the nametag buffer to test if they are filled correctly as the communication proceeds for i in 0 .. 10 * MessageNametagBufferSize: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, @@ -350,7 +350,7 @@ procSuite "Waku Noise Sessions": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( bobHSResult, message, @@ -368,13 +368,13 @@ procSuite "Waku Noise Sessions": # We test how nametag buffers help in detecting lost messages # Alice writes two messages to Bob, but only the second is received - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound, ) - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, @@ -390,7 +390,7 @@ procSuite "Waku Noise Sessions": # We adjust bob nametag buffer for next test (i.e. the missed message is correctly recovered) delete(bobHSResult.nametagsInbound, 2) - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( bobHSResult, message, outboundMessageNametagBuffer = bobHSResult.nametagsOutbound ) @@ -405,7 +405,7 @@ procSuite "Waku Noise Sessions": message == readMessage # We test if a missing nametag is correctly detected - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, diff --git a/tests/testlib/common.nim b/tests/testlib/common.nim index 216320692..78a3409db 100644 --- a/tests/testlib/common.nim +++ b/tests/testlib/common.nim @@ -1,4 +1,4 @@ -import std/[times, random], bearssl/rand, libp2p/crypto/crypto +import std/[times, random], libp2p/crypto/crypto ## Randomization @@ -11,14 +11,14 @@ proc randomize*() = ## RNG # Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28 -type Rng = object - rng: ref HmacDrbgContext +type RngState = object + rng: Rng # Typically having a module variable is considered bad design. This case should # be considered as an exception and it should be used only in the tests. -var rngVar: Rng +var rngVar: RngState -proc getRng(): ref HmacDrbgContext = +proc getRng(): Rng = # TODO: if `rngVar` is a threadvar like it should be, there are random and # spurious compile failures on mac - this is not gcsafe but for the # purpose of the tests, it's ok as long as we only use a single thread @@ -28,5 +28,5 @@ proc getRng(): ref HmacDrbgContext = rngVar.rng -template rng*(): ref HmacDrbgContext = +template rng*(): Rng = getRng() diff --git a/tests/testlib/wakucore.nim b/tests/testlib/wakucore.nim index 0c5b5199d..879ff8d32 100644 --- a/tests/testlib/wakucore.nim +++ b/tests/testlib/wakucore.nim @@ -22,13 +22,13 @@ proc ts*(offset = 0, origin = now()): Timestamp = # Switch proc generateEcdsaKey*(): libp2p_keys.PrivateKey = - libp2p_keys.PrivateKey.random(ECDSA, rng[]).get() + libp2p_keys.PrivateKey.random(ECDSA, rng).get() proc generateEcdsaKeyPair*(): libp2p_keys.KeyPair = - libp2p_keys.KeyPair.random(ECDSA, rng[]).get() + libp2p_keys.KeyPair.random(ECDSA, rng).get() proc generateSecp256k1Key*(): libp2p_keys.PrivateKey = - libp2p_keys.PrivateKey.random(Secp256k1, rng[]).get() + libp2p_keys.PrivateKey.random(Secp256k1, rng).get() proc ethSecp256k1Key*(hex: string): eth_keys.PrivateKey = eth_keys.PrivateKey.fromHex(hex).get() diff --git a/tests/waku_discv5/test_waku_discv5.nim b/tests/waku_discv5/test_waku_discv5.nim index 20a0c6965..cefeb4bd2 100644 --- a/tests/waku_discv5/test_waku_discv5.nim +++ b/tests/waku_discv5/test_waku_discv5.nim @@ -38,8 +38,8 @@ suite "Waku Discovery v5": let rng = eth_keys.newRng() - pk1 = eth_keys.PrivateKey.random(rng[]) - pk2 = eth_keys.PrivateKey.random(rng[]) + pk1 = eth_keys.PrivateKey.random(rng) + pk2 = eth_keys.PrivateKey.random(rng) suite "shardingPredicate": var @@ -423,7 +423,7 @@ suite "Waku Discovery v5": let myRng = libp2p_keys.newRng() var confBuilder = defaultTestWakuConfBuilder() - confBuilder.withNodeKey(libp2p_keys.PrivateKey.random(Secp256k1, myRng[])[]) + confBuilder.withNodeKey(libp2p_keys.PrivateKey.random(Secp256k1, myRng)) confBuilder.discv5Conf.withEnabled(true) confBuilder.discv5Conf.withUdpPort(9000.Port) let conf = confBuilder.build().valueOr: @@ -434,7 +434,7 @@ suite "Waku Discovery v5": (waitFor startWaku(addr waku0)).isOkOr: raiseAssert error - confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng[])[]) + confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng)) confBuilder.discv5Conf.withBootstrapNodes(@[waku0.node.enr.toURI()]) confBuilder.discv5Conf.withEnabled(true) confBuilder.discv5Conf.withUdpPort(9001.Port) @@ -454,7 +454,7 @@ suite "Waku Discovery v5": confBuilder.discv5Conf.withBootstrapNodes(@[waku1.node.enr.toURI()]) confBuilder.withP2pTcpPort(60003.Port) confBuilder.discv5Conf.withUdpPort(9003.Port) - confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng[])[]) + confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng)) let conf2 = confBuilder.build().valueOr: raiseAssert error diff --git a/tests/waku_rln_relay/utils_onchain.nim b/tests/waku_rln_relay/utils_onchain.nim index db07d3cd6..636790184 100644 --- a/tests/waku_rln_relay/utils_onchain.nim +++ b/tests/waku_rln_relay/utils_onchain.nim @@ -446,7 +446,7 @@ proc createEthAccount*( let gasPrice = Quantity(await web3.provider.eth_gasPrice()) web3.defaultAccount = accounts[0] - let pk = keys.PrivateKey.random(rng[]) + let pk = keys.PrivateKey.random(rng) let acc = Address(toCanonicalAddress(pk.toPublicKey())) var tx: TransactionArgs @@ -464,7 +464,7 @@ proc createEthAccount*( return (pk, acc) proc createEthAccount*(web3: Web3): (keys.PrivateKey, Address) = - let pk = keys.PrivateKey.random(rng[]) + let pk = keys.PrivateKey.random(rng) let acc = Address(toCanonicalAddress(pk.toPublicKey())) return (pk, acc) diff --git a/tests/wakunode_rest/test_rest_cors.nim b/tests/wakunode_rest/test_rest_cors.nim index 0393b0d72..1a965bbcb 100644 --- a/tests/wakunode_rest/test_rest_cors.nim +++ b/tests/wakunode_rest/test_rest_cors.nim @@ -22,7 +22,7 @@ type TestResponseTuple = tuple[status: int, data: string, headers: HttpTable] proc testWakuNode(): WakuNode = let - privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet() + privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet() bindIp = parseIpAddress("0.0.0.0") extIp = parseIpAddress("127.0.0.1") port = Port(0) diff --git a/tests/wakunode_rest/test_rest_debug.nim b/tests/wakunode_rest/test_rest_debug.nim index 4bd2e8c02..649c9b176 100644 --- a/tests/wakunode_rest/test_rest_debug.nim +++ b/tests/wakunode_rest/test_rest_debug.nim @@ -24,7 +24,7 @@ import proc testWakuNode(): WakuNode = let - privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet() + privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet() bindIp = parseIpAddress("0.0.0.0") extIp = parseIpAddress("127.0.0.1") port = Port(0) diff --git a/tests/wakunode_rest/test_rest_health.nim b/tests/wakunode_rest/test_rest_health.nim index 0bdb93123..08d0c518f 100644 --- a/tests/wakunode_rest/test_rest_health.nim +++ b/tests/wakunode_rest/test_rest_health.nim @@ -29,7 +29,7 @@ import proc testWakuNode(): WakuNode = let - privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet() + privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet() bindIp = parseIpAddress("0.0.0.0") extIp = parseIpAddress("127.0.0.1") port = Port(0) diff --git a/waku.nimble b/waku.nimble index f18e8d1a3..4e0991308 100644 --- a/waku.nimble +++ b/waku.nimble @@ -27,7 +27,7 @@ requires "nim >= 2.2.4", "toml_serialization", "faststreams", # Networking & P2P - "https://github.com/vacp2p/nim-libp2p.git#df777fc66cc100191dbefd3c222a4472b4d3b924", + "https://github.com/vacp2p/nim-libp2p.git#e41a3ab8ff143fa30e75357f81200545590f0ec6", "eth", "nat_traversal", "dnsdisc", @@ -60,6 +60,7 @@ requires "nim >= 2.2.4", # Packages not on nimble (use git URLs) requires "https://github.com/logos-messaging/nim-ffi" +requires "https://github.com/logos-co/nim-libp2p-mix" requires "https://github.com/vacp2p/nim-lsquic" requires "https://github.com/vacp2p/nim-jwt.git#057ec95eb5af0eea9c49bfe9025b3312c95dc5f2" diff --git a/waku/api/types.nim b/waku/api/types.nim index 9eae503c8..4b0348fad 100644 --- a/waku/api/types.nim +++ b/waku/api/types.nim @@ -1,6 +1,6 @@ {.push raises: [].} -import bearssl/rand, std/times, chronos +import std/times, chronos, libp2p/crypto/crypto import stew/byteutils import waku/utils/requests as request_utils import waku/waku_core/[topics/content_topic, message/message, time] @@ -19,7 +19,7 @@ type PartiallyConnected Connected -proc new*(T: typedesc[RequestId], rng: ref HmacDrbgContext): T = +proc new*(T: typedesc[RequestId], rng: crypto.Rng): T = ## Generate a new RequestId using the provided RNG. RequestId(request_utils.generateRequestId(rng)) diff --git a/waku/discovery/autonat_service.nim b/waku/discovery/autonat_service.nim index fb1f7dbc3..16d014708 100644 --- a/waku/discovery/autonat_service.nim +++ b/waku/discovery/autonat_service.nim @@ -1,13 +1,13 @@ import chronos, chronicles, - bearssl/rand, + libp2p/crypto/crypto, libp2p/protocols/connectivity/autonat/client, libp2p/protocols/connectivity/autonat/service const AutonatCheckInterval = Opt.some(chronos.seconds(30)) -proc getAutonatService*(rng: ref HmacDrbgContext): AutonatService = +proc getAutonatService*(rng: crypto.Rng): AutonatService = ## AutonatService request other peers to dial us back ## flagging us as Reachable or NotReachable. ## minConfidence is used as threshold to determine the state. diff --git a/waku/discovery/waku_discv5.nim b/waku/discovery/waku_discv5.nim index 0eb329fa4..de239508f 100644 --- a/waku/discovery/waku_discv5.nim +++ b/waku/discovery/waku_discv5.nim @@ -7,6 +7,8 @@ import chronicles, metrics, libp2p/multiaddress, + libp2p/crypto/crypto, + libp2p/crypto/rng, eth/keys as eth_keys, eth/p2p/discoveryv5/node, eth/p2p/discoveryv5/protocol @@ -80,7 +82,7 @@ proc shardingPredicate*( proc new*( T: type WakuDiscoveryV5, - rng: ref HmacDrbgContext, + rng: crypto.Rng, conf: WakuDiscoveryV5Config, record: Option[waku_enr.Record], peerManager: Option[PeerManager] = none(PeerManager), @@ -88,7 +90,7 @@ proc new*( newAsyncEventQueue[SubscriptionEvent](30), ): T = let protocol = newProtocol( - rng = rng, + rng = bearSslDrbgRef(rng), config = conf.discv5Config.get(protocol.defaultDiscoveryConfig), bindPort = conf.port, bindIp = conf.address, @@ -405,7 +407,7 @@ proc setupDiscoveryV5*( nodeTopicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent], conf: Discv5Conf, dynamicBootstrapNodes: seq[RemotePeerInfo], - rng: ref HmacDrbgContext, + rng: crypto.Rng, key: crypto.PrivateKey, p2pListenAddress: IpAddress, portsShift: uint16, diff --git a/waku/discovery/waku_kademlia.nim b/waku/discovery/waku_kademlia.nim index f88430a40..a0488fb45 100644 --- a/waku/discovery/waku_kademlia.nim +++ b/waku/discovery/waku_kademlia.nim @@ -7,7 +7,7 @@ import results, libp2p/crypto/curve25519, libp2p/crypto/crypto, - libp2p/protocols/mix/mix_protocol, + libp2p_mix/mix_protocol, libp2p/[peerid, multiaddress, switch], libp2p/extended_peer_record, libp2p/protocols/[kademlia, service_discovery], @@ -174,6 +174,7 @@ proc new*( selector = ExtEntrySelector(), disableBootstrapping = disableBootstrapping, ), + rng = switch.rng, # change from defaults for local testing discoConfig = ServiceDiscoveryConfig.new(advertExpiry = 60.secs, ipSimCoefficient = 0.0), diff --git a/waku/factory/builder.nim b/waku/factory/builder.nim index 5bd343223..b333150ae 100644 --- a/waku/factory/builder.nim +++ b/waku/factory/builder.nim @@ -21,7 +21,7 @@ import type WakuNodeBuilder* = object # General - nodeRng: Option[ref crypto.HmacDrbgContext] + nodeRng: Option[crypto.Rng] nodeKey: Option[crypto.PrivateKey] netConfig: Option[NetConfig] record: Option[enr.Record] @@ -57,7 +57,7 @@ proc init*(T: type WakuNodeBuilder): WakuNodeBuilder = ## General -proc withRng*(builder: var WakuNodeBuilder, rng: ref crypto.HmacDrbgContext) = +proc withRng*(builder: var WakuNodeBuilder, rng: crypto.Rng) = builder.nodeRng = some(rng) proc withNodeKey*(builder: var WakuNodeBuilder, nodeKey: crypto.PrivateKey) = @@ -157,7 +157,7 @@ proc withSwitchConfiguration*( ## Build proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] = - var rng: ref crypto.HmacDrbgContext + var rng: crypto.Rng if builder.nodeRng.isNone(): rng = crypto.newRng() else: diff --git a/waku/factory/conf_builder/mix_conf_builder.nim b/waku/factory/conf_builder/mix_conf_builder.nim index 8a4f5b5f1..b3198a309 100644 --- a/waku/factory/conf_builder/mix_conf_builder.nim +++ b/waku/factory/conf_builder/mix_conf_builder.nim @@ -1,5 +1,5 @@ import chronicles, std/options, results -import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p/protocols/mix/curve25519 +import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p_mix/curve25519 import ../waku_conf, waku/waku_mix logScope: diff --git a/waku/factory/conf_builder/waku_conf_builder.nim b/waku/factory/conf_builder/waku_conf_builder.nim index 78dbd9eb9..1e30b6e24 100644 --- a/waku/factory/conf_builder/waku_conf_builder.nim +++ b/waku/factory/conf_builder/waku_conf_builder.nim @@ -283,13 +283,13 @@ proc withStaticNodes*(builder: var WakuConfBuilder, staticNodes: seq[string]) = ## Building proc nodeKey( - builder: WakuConfBuilder, rng: ref HmacDrbgContext + builder: WakuConfBuilder, rng: crypto.Rng ): Result[crypto.PrivateKey, string] = if builder.nodeKey.isSome(): return ok(builder.nodeKey.get()) else: warn "missing node key, generating new set" - let nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).valueOr: + let nodeKey = crypto.PrivateKey.random(Secp256k1, rng).valueOr: error "Failed to generate key", error = error return err("Failed to generate key: " & $error) return ok(nodeKey) @@ -433,7 +433,7 @@ proc applyNetworkConf(builder: var WakuConfBuilder) = warn "Failed to process entry nodes from network conf", error = processed.error() proc build*( - builder: var WakuConfBuilder, rng: ref HmacDrbgContext = crypto.newRng() + builder: var WakuConfBuilder, rng: crypto.Rng = crypto.newRng() ): Result[WakuConf, string] = ## Return a WakuConf that contains all mandatory parameters ## Applies some sane defaults that are applicable across any usage diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index dce6322f1..c742e1c29 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -9,7 +9,7 @@ import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p/extended_peer_record, - libp2p/protocols/mix/mix_protocol + libp2p_mix/mix_protocol import ./internal_config, @@ -57,7 +57,7 @@ proc setupPeerStorage(): Result[Option[WakuPeerStorage], string] = proc initNode( conf: WakuConf, netConfig: NetConfig, - rng: ref HmacDrbgContext, + rng: crypto.Rng, record: enr.Record, peerStore: Option[WakuPeerStorage], relay: Relay, @@ -483,7 +483,7 @@ proc startNode*( return ok() proc setupNode*( - wakuConf: WakuConf, rng: ref HmacDrbgContext = crypto.newRng(), relay: Relay + wakuConf: WakuConf, rng: crypto.Rng = crypto.newRng(), relay: Relay ): Future[Result[WakuNode, string]] {.async.} = let netConfig = ( await networkConfiguration( diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 45e0edee0..66bb71fcb 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -59,7 +59,7 @@ const git_version* {.strdefine.} = "n/a" type Waku* = ref object stateInfo*: WakuStateInfo conf*: WakuConf - rng*: ref HmacDrbgContext + rng*: crypto.Rng key: crypto.PrivateKey @@ -81,7 +81,7 @@ type Waku* = ref object brokerCtx*: BrokerContext proc setupSwitchServices( - waku: Waku, conf: WakuConf, circuitRelay: Relay, rng: ref HmacDrbgContext + waku: Waku, conf: WakuConf, circuitRelay: Relay, rng: crypto.Rng ) = proc onReservation(addresses: seq[MultiAddress]) {.gcsafe, raises: [].} = info "circuit relay handler new reserve event", diff --git a/waku/node/kernel_api/lightpush.nim b/waku/node/kernel_api/lightpush.nim index ffe2afdac..b3ef68eba 100644 --- a/waku/node/kernel_api/lightpush.nim +++ b/waku/node/kernel_api/lightpush.nim @@ -17,7 +17,7 @@ import libp2p/transports/tcptransport, libp2p/transports/wstransport, libp2p/utility, - libp2p/protocols/mix + libp2p_mix import ../waku_node, diff --git a/waku/node/peer_manager/waku_peer_store.nim b/waku/node/peer_manager/waku_peer_store.nim index 93ac9ad2e..fbfd0041d 100644 --- a/waku/node/peer_manager/waku_peer_store.nim +++ b/waku/node/peer_manager/waku_peer_store.nim @@ -7,7 +7,8 @@ import eth/p2p/discoveryv5/enr, libp2p/builders, libp2p/peerstore, - libp2p/crypto/curve25519 + libp2p/crypto/curve25519, + libp2p_mix/pool import ../../waku_core, diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index e15153785..78f2949cc 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -8,7 +8,6 @@ import results, eth/keys, nimcrypto, - bearssl/rand, stew/byteutils, eth/p2p/discoveryv5/enr, libp2p/crypto/crypto, @@ -23,8 +22,8 @@ import libp2p/transports/wstransport, libp2p/utility, libp2p/utils/offsettedseq, - libp2p/protocols/mix, - libp2p/protocols/mix/mix_protocol + libp2p_mix, + libp2p_mix/mix_protocol import waku/[ @@ -126,7 +125,7 @@ type wakuAutoSharding*: Option[Sharding] enr*: enr.Record libp2pPing*: Ping - rng*: ref rand.HmacDrbgContext + rng*: crypto.Rng brokerCtx*: BrokerContext wakuRendezvous*: WakuRendezVous wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient @@ -206,7 +205,7 @@ proc new*( peerManager: PeerManager, rateLimitSettings: ProtocolRateLimitSettings = DefaultProtocolRateLimit, # TODO: make this argument required after tests are updated - rng: ref HmacDrbgContext = crypto.newRng(), + rng: crypto.Rng = crypto.newRng(), ): T {.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} = ## Creates a Waku Node instance. diff --git a/waku/node/waku_switch.nim b/waku/node/waku_switch.nim index e658bd0e4..dda378030 100644 --- a/waku/node/waku_switch.nim +++ b/waku/node/waku_switch.nim @@ -64,7 +64,7 @@ proc newWakuSwitch*( wsAddress = none(MultiAddress), secureManagers: openarray[SecureProtocol] = [SecureProtocol.Noise], transportFlags: set[ServerFlags] = {}, - rng: ref HmacDrbgContext, + rng: crypto.Rng, inTimeout: Duration = 5.minutes, outTimeout: Duration = 5.minutes, maxConnections = MaxConnections, @@ -78,7 +78,7 @@ proc newWakuSwitch*( secureCertPath: string = "", agentString = none(string), # defaults to nim-libp2p version peerStoreCapacity = none(int), # defaults to 1.25 maxConnections - rendezvous: RendezVous = nil, + rendezvous: RendezVousConfig = nil, circuitRelay: Relay, maxNumRelays: int = 5, ): Switch {.raises: [Defect, IOError, LPError].} = diff --git a/waku/utils/requests.nim b/waku/utils/requests.nim index d9afd2887..a7fd9a2a9 100644 --- a/waku/utils/requests.nim +++ b/waku/utils/requests.nim @@ -2,9 +2,9 @@ {.push raises: [].} -import bearssl/rand, stew/byteutils +import libp2p/crypto/crypto, stew/byteutils -proc generateRequestId*(rng: ref HmacDrbgContext): string = +proc generateRequestId*(rng: crypto.Rng): string = var bytes: array[10, byte] - hmacDrbgGenerate(rng[], bytes) + rng.generate(bytes) return byteutils.toHex(bytes) diff --git a/waku/waku_enr/capabilities.nim b/waku/waku_enr/capabilities.nim index 26899fbb4..6a5b5338f 100644 --- a/waku/waku_enr/capabilities.nim +++ b/waku/waku_enr/capabilities.nim @@ -3,7 +3,7 @@ import std/[options, bitops, sequtils, net, tables], results, eth/keys, libp2p/crypto/crypto import ../common/enr, ../waku_core/codecs -import libp2p/protocols/mix +import libp2p_mix const CapabilitiesEnrField* = "waku2" diff --git a/waku/waku_filter_v2/client.nim b/waku/waku_filter_v2/client.nim index 265bf5e7b..439cfd29e 100644 --- a/waku/waku_filter_v2/client.nim +++ b/waku/waku_filter_v2/client.nim @@ -7,7 +7,7 @@ import chronicles, chronos, libp2p/protocols/protocol, - bearssl/rand, + libp2p/crypto/crypto, stew/byteutils import waku/ @@ -22,13 +22,13 @@ logScope: type WakuFilterClient* = ref object of LPProtocol brokerCtx: BrokerContext - rng: ref HmacDrbgContext + rng: Rng peerManager: PeerManager pushHandlers: seq[FilterPushHandler] -func generateRequestId(rng: ref HmacDrbgContext): string = +func generateRequestId(rng: crypto.Rng): string = var bytes: array[10, byte] - hmacDrbgGenerate(rng[], bytes) + rng.generate(bytes) return byteutils.toHex(bytes) proc sendSubscribeRequest( @@ -210,7 +210,7 @@ proc initProtocolHandler(wfc: WakuFilterClient) = wfc.codec = WakuFilterPushCodec proc new*( - T: type WakuFilterClient, peerManager: PeerManager, rng: ref HmacDrbgContext + T: type WakuFilterClient, peerManager: PeerManager, rng: crypto.Rng ): T = let brokerCtx = globalBrokerContext() let wfc = WakuFilterClient( diff --git a/waku/waku_lightpush/client.nim b/waku/waku_lightpush/client.nim index fd12c49d2..e0c46d403 100644 --- a/waku/waku_lightpush/client.nim +++ b/waku/waku_lightpush/client.nim @@ -1,6 +1,6 @@ {.push raises: [].} -import std/options, results, chronicles, chronos, metrics, bearssl/rand, stew/byteutils +import std/options, results, chronicles, chronos, metrics, libp2p/crypto/crypto, stew/byteutils import libp2p/peerid, libp2p/stream/connection import ../waku_core/peers, @@ -16,11 +16,11 @@ logScope: topics = "waku lightpush client" type WakuLightPushClient* = ref object - rng*: ref rand.HmacDrbgContext + rng*: Rng peerManager*: PeerManager proc new*( - T: type WakuLightPushClient, peerManager: PeerManager, rng: ref rand.HmacDrbgContext + T: type WakuLightPushClient, peerManager: PeerManager, rng: crypto.Rng ): T = WakuLightPushClient(peerManager: peerManager, rng: rng) diff --git a/waku/waku_lightpush/protocol.nim b/waku/waku_lightpush/protocol.nim index 8336f4dfc..a8e8173e0 100644 --- a/waku/waku_lightpush/protocol.nim +++ b/waku/waku_lightpush/protocol.nim @@ -7,7 +7,7 @@ import chronicles, chronos, metrics, - bearssl/rand + libp2p/crypto/crypto import ../node/peer_manager/peer_manager, ../waku_core, @@ -22,7 +22,7 @@ logScope: topics = "waku lightpush" type WakuLightPush* = ref object of LPProtocol - rng*: ref rand.HmacDrbgContext + rng*: Rng peerManager*: PeerManager pushHandler*: PushMessageHandler requestRateLimiter*: RequestRateLimiter @@ -156,7 +156,7 @@ proc initProtocolHandler(wl: WakuLightPush) = proc new*( T: type WakuLightPush, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, pushHandler: PushMessageHandler, autoSharding: Option[Sharding], rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](), diff --git a/waku/waku_lightpush_legacy/client.nim b/waku/waku_lightpush_legacy/client.nim index ab489bec9..ce69bee60 100644 --- a/waku/waku_lightpush_legacy/client.nim +++ b/waku/waku_lightpush_legacy/client.nim @@ -1,6 +1,6 @@ {.push raises: [].} -import std/options, results, chronicles, chronos, metrics, bearssl/rand, stew/byteutils +import std/options, results, chronicles, chronos, metrics, libp2p/crypto/crypto, stew/byteutils import libp2p/peerid import ../waku_core/peers, @@ -17,12 +17,12 @@ logScope: type WakuLegacyLightPushClient* = ref object peerManager*: PeerManager - rng*: ref rand.HmacDrbgContext + rng*: Rng proc new*( T: type WakuLegacyLightPushClient, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, ): T = WakuLegacyLightPushClient(peerManager: peerManager, rng: rng) diff --git a/waku/waku_lightpush_legacy/protocol.nim b/waku/waku_lightpush_legacy/protocol.nim index f5ed60134..47fb9030b 100644 --- a/waku/waku_lightpush_legacy/protocol.nim +++ b/waku/waku_lightpush_legacy/protocol.nim @@ -1,6 +1,6 @@ {.push raises: [].} -import std/options, results, stew/byteutils, chronicles, chronos, metrics, bearssl/rand +import std/options, results, stew/byteutils, chronicles, chronos, metrics, libp2p/crypto/crypto import ../node/peer_manager/peer_manager, ../waku_core, @@ -14,7 +14,7 @@ logScope: topics = "waku lightpush legacy" type WakuLegacyLightPush* = ref object of LPProtocol - rng*: ref rand.HmacDrbgContext + rng*: Rng peerManager*: PeerManager pushHandler*: PushMessageHandler requestRateLimiter*: RequestRateLimiter @@ -116,7 +116,7 @@ proc initProtocolHandler(wl: WakuLegacyLightPush) = proc new*( T: type WakuLegacyLightPush, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, pushHandler: PushMessageHandler, rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](), ): T = diff --git a/waku/waku_mix/protocol.nim b/waku/waku_mix/protocol.nim index fb6b7ef6d..ddaa384c1 100644 --- a/waku/waku_mix/protocol.nim +++ b/waku/waku_mix/protocol.nim @@ -5,12 +5,12 @@ import chronicles, std/options, chronos, results, metrics import libp2p/crypto/curve25519, libp2p/crypto/crypto, - libp2p/protocols/mix, - libp2p/protocols/mix/mix_node, - libp2p/protocols/mix/mix_protocol, - libp2p/protocols/mix/mix_metrics, - libp2p/protocols/mix/delay_strategy, - libp2p/protocols/mix/delay, + libp2p_mix, + libp2p_mix/mix_node, + libp2p_mix/mix_protocol, + libp2p_mix/mix_metrics, + libp2p_mix/delay_strategy, + libp2p_mix/delay, libp2p/[multiaddress, peerid, switch], libp2p/extended_peer_record, eth/common/keys diff --git a/waku/waku_noise/noise.nim b/waku/waku_noise/noise.nim index 9c5dd76e7..c8a08468b 100644 --- a/waku/waku_noise/noise.nim +++ b/waku/waku_noise/noise.nim @@ -12,7 +12,7 @@ import std/[options, strutils] import stew/byteutils import chronos import chronicles -import bearssl/rand +import libp2p/crypto/crypto import stew/endians2 import nimcrypto/[sha2, hmac] @@ -168,9 +168,9 @@ proc setCipherStateKey*(cs: var CipherState, key: ChaChaPolyKey) = cs.k = key # Generates a random Symmetric Cipher State for test purposes -proc randomCipherState*(rng: var HmacDrbgContext, nonce: uint64 = 0): CipherState = +proc randomCipherState*(rng: crypto.Rng, nonce: uint64 = 0): CipherState = var randomCipherState: CipherState - hmacDrbgGenerate(rng, randomCipherState.k) + rng.generate(randomCipherState.k) setNonce(randomCipherState, nonce) return randomCipherState diff --git a/waku/waku_noise/noise_handshake_processing.nim b/waku/waku_noise/noise_handshake_processing.nim index 8b84bf958..5a2262e32 100644 --- a/waku/waku_noise/noise_handshake_processing.nim +++ b/waku/waku_noise/noise_handshake_processing.nim @@ -7,7 +7,7 @@ import std/[options, strutils, tables] import chronos import chronicles -import bearssl/rand +import libp2p/crypto/crypto import results import libp2p/crypto/[chacha20poly1305, curve25519] @@ -237,7 +237,7 @@ proc processMessagePatternPayload( # We process an input handshake message according to current handshake state and we return the next handshake step's handshake message proc processMessagePatternTokens( - rng: var rand.HmacDrbgContext, + rng: crypto.Rng, hs: var HandshakeState, inputHandshakeMessage: seq[NoisePublicKey] = @[], ): Result[seq[NoisePublicKey], cstring] {. @@ -480,7 +480,7 @@ proc initialize*( # If the user is writing the handshake message, the transport message (if not empty) and eventually a non-empty message nametag has to be passed to transportMessage and messageNametag and readPayloadV2 can be left to its default value # It the user is reading the handshake message, the read payload v2 has to be passed to readPayloadV2 and the transportMessage can be left to its default values. Decryption is skipped if the payloadv2 read doesn't have a message nametag equal to messageNametag (empty input nametags are converted to all-0 MessageNametagLength bytes arrays) proc stepHandshake*( - rng: var rand.HmacDrbgContext, + rng: crypto.Rng, hs: var HandshakeState, readPayloadV2: PayloadV2 = default(PayloadV2), transportMessage: seq[byte] = @[], diff --git a/waku/waku_noise/noise_utils.nim b/waku/waku_noise/noise_utils.nim index 177dc6557..e168f47ed 100644 --- a/waku/waku_noise/noise_utils.nim +++ b/waku/waku_noise/noise_utils.nim @@ -8,7 +8,7 @@ import std/[algorithm, base64, oids, options, strutils, tables, sequtils] import chronos import chronicles -import bearssl/rand +import libp2p/crypto/crypto import results import stew/[endians2, byteutils] import nimcrypto/sha2 @@ -28,9 +28,9 @@ logScope: ################################# # Generates random byte sequences of given size -proc randomSeqByte*(rng: var HmacDrbgContext, size: int): seq[byte] = +proc randomSeqByte*(rng: crypto.Rng, size: int): seq[byte] = var output = newSeq[byte](size.uint32) - hmacDrbgGenerate(rng, output) + rng.generate(output) return output # Pads a payload according to PKCS#7 as per RFC 5652 https://datatracker.ietf.org/doc/html/rfc5652#section-6.3 @@ -149,7 +149,7 @@ proc isDefault*[T](value: T): bool = ################################# # Generate random (public, private) Elliptic Curve key pairs -proc genKeyPair*(rng: var HmacDrbgContext): KeyPair = +proc genKeyPair*(rng: crypto.Rng): KeyPair = var keyPair: KeyPair keyPair.privateKey = EllipticCurveKey.random(rng) keyPair.publicKey = keyPair.privateKey.public() @@ -319,18 +319,18 @@ proc dh*(private: EllipticCurveKey, public: EllipticCurveKey): EllipticCurveKey ################################# # Generates a random ChaChaPolyKey for testing encryption/decryption -proc randomChaChaPolyKey*(rng: var HmacDrbgContext): ChaChaPolyKey = +proc randomChaChaPolyKey*(rng: crypto.Rng): ChaChaPolyKey = var key: ChaChaPolyKey - hmacDrbgGenerate(rng, key) + rng.generate(key) return key # Generates a random ChaChaPoly Cipher State for testing encryption/decryption -proc randomChaChaPolyCipherState*(rng: var HmacDrbgContext): ChaChaPolyCipherState = +proc randomChaChaPolyCipherState*(rng: crypto.Rng): ChaChaPolyCipherState = var randomCipherState: ChaChaPolyCipherState randomCipherState.k = randomChaChaPolyKey(rng) - hmacDrbgGenerate(rng, randomCipherState.nonce) + rng.generate(randomCipherState.nonce) randomCipherState.ad = newSeq[byte](32) - hmacDrbgGenerate(rng, randomCipherState.ad) + rng.generate(randomCipherState.ad) return randomCipherState ################################################################# @@ -351,7 +351,7 @@ proc toNoisePublicKey*(publicKey: EllipticCurveKey): NoisePublicKey = return noisePublicKey # Generates a random Noise public key -proc genNoisePublicKey*(rng: var HmacDrbgContext): NoisePublicKey = +proc genNoisePublicKey*(rng: crypto.Rng): NoisePublicKey = var noisePublicKey: NoisePublicKey # We generate a random key pair let keyPair: KeyPair = genKeyPair(rng) @@ -446,7 +446,7 @@ proc `==`*(p1, p2: PayloadV2): bool = (p1.transportMessage == p2.transportMessage) # Generates a random PayloadV2 -proc randomPayloadV2*(rng: var HmacDrbgContext): PayloadV2 = +proc randomPayloadV2*(rng: crypto.Rng): PayloadV2 = var payload2: PayloadV2 # We set a random messageNametag let randMessageNametag = randomSeqByte(rng, MessageNametagLength) diff --git a/waku/waku_relay/protocol.nim b/waku/waku_relay/protocol.nim index e7b2c99cb..e8377438e 100644 --- a/waku/waku_relay/protocol.nim +++ b/waku/waku_relay/protocol.nim @@ -366,7 +366,8 @@ proc new*( triggerSelf = true, msgIdProvider = defaultMessageIdProvider, maxMessageSize = maxMessageSize, - parameters = GossipsubParameters, + rng = switch.rng, + parameters = GossipSubParams.init(), ) w.brokerCtx = globalBrokerContext() diff --git a/waku/waku_rendezvous/client.nim b/waku/waku_rendezvous/client.nim index 62c0de848..bf43a4a71 100644 --- a/waku/waku_rendezvous/client.nim +++ b/waku/waku_rendezvous/client.nim @@ -106,10 +106,10 @@ proc new*( switch: switch, rng: rng, sema: newAsyncSemaphore(MaxSimultanesousAdvertisements), - minDuration: rendezvous.MinimumAcceptedDuration, - maxDuration: rendezvous.MaximumDuration, - minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64, - maxTTL: rendezvous.MaximumDuration.seconds.uint64, + config: RendezVousConfig.new( + minDuration = rendezvous.MinimumDuration, + maxDuration = rendezvous.MaximumDuration, + ), peers: @[], # Will be populated from selectPeer calls cookiesSaved: initTable[PeerId, Table[string, seq[byte]]](), peerRecordValidator: checkWakuPeerRecord, diff --git a/waku/waku_rendezvous/protocol.nim b/waku/waku_rendezvous/protocol.nim index 0e9b0aa76..9d5acb46d 100644 --- a/waku/waku_rendezvous/protocol.nim +++ b/waku/waku_rendezvous/protocol.nim @@ -50,7 +50,7 @@ proc advertise*( self: WakuRendezVous, namespace: string, peers: seq[PeerId], - ttl: timer.Duration = self.minDuration, + ttl: timer.Duration = rendezvous.MinimumDuration, ): Future[Result[void, string]] {.async: (raises: []).} = trace "advertising via waku rendezvous", namespace = namespace, ttl = ttl, peers = $peers, peerRecord = $self.getPeerRecord() @@ -153,14 +153,14 @@ proc new*( let rng = newRng() let wrv = T( rng: rng, - salt: string.fromBytes(generateBytes(rng[], 8)), + salt: string.fromBytes(generateBytes(rng, 8)), registered: initOffsettedSeq[RegisteredData](), expiredDT: Moment.now() - 1.days, sema: newAsyncSemaphore(SemaphoreDefaultSize), - minDuration: rendezvous.MinimumAcceptedDuration, - maxDuration: rendezvous.MaximumDuration, - minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64, - maxTTL: rendezvous.MaximumDuration.seconds.uint64, + config: RendezVousConfig.new( + minDuration = rendezvous.MinimumDuration, + maxDuration = rendezvous.MaximumDuration, + ), peerRecordValidator: checkWakuPeerRecord, ) diff --git a/waku/waku_store/client.nim b/waku/waku_store/client.nim index 5b261af47..857a5e0bf 100644 --- a/waku/waku_store/client.nim +++ b/waku/waku_store/client.nim @@ -6,7 +6,7 @@ import chronicles, chronos, metrics, - bearssl/rand + libp2p/crypto/crypto import ../node/peer_manager, ../utils/requests, ./protocol_metrics, ./common, ./rpc_codec @@ -20,11 +20,11 @@ const MaxQueryRetries = 5 # Maximum number of store peers to try before giving u type WakuStoreClient* = ref object peerManager: PeerManager - rng: ref rand.HmacDrbgContext + rng: Rng storeMsgMetricsPerShard*: Table[string, float64] proc new*( - T: type WakuStoreClient, peerManager: PeerManager, rng: ref rand.HmacDrbgContext + T: type WakuStoreClient, peerManager: PeerManager, rng: crypto.Rng ): T {.gcsafe.} = WakuStoreClient(peerManager: peerManager, rng: rng) diff --git a/waku/waku_store/protocol.nim b/waku/waku_store/protocol.nim index 891c6a93c..c40e3667a 100644 --- a/waku/waku_store/protocol.nim +++ b/waku/waku_store/protocol.nim @@ -8,7 +8,6 @@ import results, chronicles, chronos, - bearssl/rand, libp2p/crypto/crypto, libp2p/protocols/protocol, libp2p/protobuf/minprotobuf, @@ -30,7 +29,7 @@ type StoreQueryRequestHandler* = type WakuStore* = ref object of LPProtocol peerManager: PeerManager - rng: ref rand.HmacDrbgContext + rng: Rng requestHandler*: StoreQueryRequestHandler requestRateLimiter*: RequestRateLimiter @@ -154,7 +153,7 @@ proc initProtocolHandler(self: WakuStore) = proc new*( T: type WakuStore, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, requestHandler: StoreQueryRequestHandler, rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](), ): T =