mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-04 05:00:02 +00:00
update to latest libp2p
This commit is contained in:
parent
16d89492ea
commit
55e752c526
@ -12,7 +12,7 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
bearssl,
|
|
||||||
stew/[byteutils, results],
|
stew/[byteutils, results],
|
||||||
metrics,
|
metrics,
|
||||||
metrics/chronos_httpserver
|
metrics/chronos_httpserver
|
||||||
@ -301,7 +301,7 @@ proc readInput(wfd: AsyncFD) {.thread, raises: [Defect, CatchableError].} =
|
|||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
|
# @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
|
let
|
||||||
transp = fromPipe(rfd)
|
transp = fromPipe(rfd)
|
||||||
conf = Chat2Conf.load()
|
conf = Chat2Conf.load()
|
||||||
@ -309,7 +309,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
|||||||
if conf.nodekey.isSome():
|
if conf.nodekey.isSome():
|
||||||
conf.nodekey.get()
|
conf.nodekey.get()
|
||||||
else:
|
else:
|
||||||
PrivateKey.random(Secp256k1, rng[]).tryGet()
|
PrivateKey.random(Secp256k1, rng).tryGet()
|
||||||
|
|
||||||
# set log level
|
# set log level
|
||||||
if conf.logLevel != LogLevel.NONE:
|
if conf.logLevel != LogLevel.NONE:
|
||||||
@ -564,7 +564,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
|||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
||||||
proc main(rng: ref HmacDrbgContext) {.async.} =
|
proc main(rng: crypto.Rng) {.async.} =
|
||||||
let (rfd, wfd) = createAsyncPipe()
|
let (rfd, wfd) = createAsyncPipe()
|
||||||
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
||||||
raise newException(ValueError, "Could not initialize pipe!")
|
raise newException(ValueError, "Could not initialize pipe!")
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
bearssl,
|
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
results,
|
results,
|
||||||
metrics,
|
metrics,
|
||||||
@ -286,7 +286,7 @@ proc readInput(wfd: AsyncFD) {.thread, raises: [Defect, CatchableError].} =
|
|||||||
discard waitFor transp.write(line & "\r\n")
|
discard waitFor transp.write(line & "\r\n")
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||||
let
|
let
|
||||||
transp = fromPipe(rfd)
|
transp = fromPipe(rfd)
|
||||||
conf = Chat2DiscoConf.load()
|
conf = Chat2DiscoConf.load()
|
||||||
@ -294,7 +294,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
|||||||
if conf.nodekey.isSome():
|
if conf.nodekey.isSome():
|
||||||
conf.nodekey.get()
|
conf.nodekey.get()
|
||||||
else:
|
else:
|
||||||
PrivateKey.random(Secp256k1, rng[]).tryGet()
|
PrivateKey.random(Secp256k1, rng).tryGet()
|
||||||
|
|
||||||
# set log level
|
# set log level
|
||||||
if conf.logLevel != LogLevel.NONE:
|
if conf.logLevel != LogLevel.NONE:
|
||||||
@ -418,7 +418,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
|||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
||||||
proc main(rng: ref HmacDrbgContext) {.async.} =
|
proc main(rng: crypto.Rng) {.async.} =
|
||||||
let (rfd, wfd) = createAsyncPipe()
|
let (rfd, wfd) = createAsyncPipe()
|
||||||
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
||||||
raise newException(ValueError, "Could not initialize pipe!")
|
raise newException(ValueError, "Could not initialize pipe!")
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
bearssl,
|
|
||||||
results,
|
results,
|
||||||
stew/[byteutils],
|
stew/[byteutils],
|
||||||
metrics,
|
metrics,
|
||||||
@ -391,7 +391,7 @@ proc maintainSubscription(
|
|||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
|
# @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
|
let
|
||||||
transp = fromPipe(rfd)
|
transp = fromPipe(rfd)
|
||||||
conf = Chat2Conf.load()
|
conf = Chat2Conf.load()
|
||||||
@ -399,7 +399,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
|||||||
if conf.nodekey.isSome():
|
if conf.nodekey.isSome():
|
||||||
conf.nodekey.get()
|
conf.nodekey.get()
|
||||||
else:
|
else:
|
||||||
PrivateKey.random(Secp256k1, rng[]).tryGet()
|
PrivateKey.random(Secp256k1, rng).tryGet()
|
||||||
|
|
||||||
# set log level
|
# set log level
|
||||||
if conf.logLevel != LogLevel.NONE:
|
if conf.logLevel != LogLevel.NONE:
|
||||||
@ -655,7 +655,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
|||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
||||||
proc main(rng: ref HmacDrbgContext) {.async.} =
|
proc main(rng: crypto.Rng) {.async.} =
|
||||||
let (rfd, wfd) = createAsyncPipe()
|
let (rfd, wfd) = createAsyncPipe()
|
||||||
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe:
|
||||||
raise newException(ValueError, "Could not initialize pipe!")
|
raise newException(ValueError, "Could not initialize pipe!")
|
||||||
|
|||||||
@ -423,7 +423,7 @@ proc initAndStartApp(
|
|||||||
let
|
let
|
||||||
# some hardcoded parameters
|
# some hardcoded parameters
|
||||||
rng = keys.newRng()
|
rng = keys.newRng()
|
||||||
key = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
key = crypto.PrivateKey.random(Secp256k1, rng)[]
|
||||||
nodeTcpPort = Port(60000)
|
nodeTcpPort = Port(60000)
|
||||||
nodeUdpPort = Port(9000)
|
nodeUdpPort = Port(9000)
|
||||||
flags = CapabilitiesBitfield.init(
|
flags = CapabilitiesBitfield.init(
|
||||||
|
|||||||
@ -159,7 +159,7 @@ proc pingNode(
|
|||||||
error "Failed to ping the peer", peer = peerInfo, err = msg
|
error "Failed to ping the peer", peer = peerInfo, err = msg
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
proc main(rng: crypto.Rng): Future[int] {.async.} =
|
||||||
let conf: WakuCanaryConf = WakuCanaryConf.load()
|
let conf: WakuCanaryConf = WakuCanaryConf.load()
|
||||||
|
|
||||||
# create dns resolver
|
# create dns resolver
|
||||||
@ -190,7 +190,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} =
|
|||||||
quit(QuitFailure)
|
quit(QuitFailure)
|
||||||
|
|
||||||
let
|
let
|
||||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[]
|
||||||
bindIp = parseIpAddress("0.0.0.0")
|
bindIp = parseIpAddress("0.0.0.0")
|
||||||
wsBindPort = Port(conf.nodePort + WebSocketPortOffset)
|
wsBindPort = Port(conf.nodePort + WebSocketPortOffset)
|
||||||
nodeTcpPort = Port(conf.nodePort)
|
nodeTcpPort = Port(conf.nodePort)
|
||||||
|
|||||||
@ -5,6 +5,8 @@ if defined(release):
|
|||||||
else:
|
else:
|
||||||
switch("nimcache", "nimcache/debug/$projectName")
|
switch("nimcache", "nimcache/debug/$projectName")
|
||||||
|
|
||||||
|
switch("passL", getCurrentDir() / "librln_v0.9.0.a")
|
||||||
|
|
||||||
if defined(windows):
|
if defined(windows):
|
||||||
switch("passL", "rln.lib")
|
switch("passL", "rln.lib")
|
||||||
switch("define", "postgres=false")
|
switch("define", "postgres=false")
|
||||||
@ -120,7 +122,6 @@ if defined(android):
|
|||||||
switch("passL", "--sysroot=" & sysRoot)
|
switch("passL", "--sysroot=" & sysRoot)
|
||||||
switch("cincludes", sysRoot & "/usr/include/")
|
switch("cincludes", sysRoot & "/usr/include/")
|
||||||
# begin Nimble config (version 2)
|
# begin Nimble config (version 2)
|
||||||
--noNimblePath
|
|
||||||
when withDir(thisDir(), system.fileExists("nimble.paths")):
|
when withDir(thisDir(), system.fileExists("nimble.paths")):
|
||||||
include "nimble.paths"
|
include "nimble.paths"
|
||||||
# end Nimble config
|
# end Nimble config
|
||||||
|
|||||||
@ -43,13 +43,13 @@ proc messagePushHandler(
|
|||||||
contentTopic = message.contentTopic,
|
contentTopic = message.contentTopic,
|
||||||
timestamp = message.timestamp
|
timestamp = message.timestamp
|
||||||
|
|
||||||
proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
proc setupAndSubscribe(rng: crypto.Rng) {.async.} =
|
||||||
# use notice to filter all waku messaging
|
# use notice to filter all waku messaging
|
||||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||||
|
|
||||||
notice "starting subscriber", wakuPort = wakuPort
|
notice "starting subscriber", wakuPort = wakuPort
|
||||||
let
|
let
|
||||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[]
|
||||||
ip = parseIpAddress("0.0.0.0")
|
ip = parseIpAddress("0.0.0.0")
|
||||||
flags = CapabilitiesBitfield.init(relay = true)
|
flags = CapabilitiesBitfield.init(relay = true)
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,8 @@ import
|
|||||||
confutils,
|
confutils,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/crypto/curve25519,
|
libp2p/crypto/curve25519,
|
||||||
libp2p/protocols/mix,
|
libp2p_mix,
|
||||||
libp2p/protocols/mix/curve25519,
|
libp2p_mix/curve25519,
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
eth/p2p/discoveryv5/enr,
|
eth/p2p/discoveryv5/enr,
|
||||||
@ -48,13 +48,13 @@ proc splitPeerIdAndAddr(maddr: string): (string, string) =
|
|||||||
peerId = parts[1]
|
peerId = parts[1]
|
||||||
return (address, peerId)
|
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
|
# use notice to filter all waku messaging
|
||||||
setupLog(logging.LogLevel.DEBUG, logging.LogFormat.TEXT)
|
setupLog(logging.LogLevel.DEBUG, logging.LogFormat.TEXT)
|
||||||
notice "starting publisher", wakuPort = conf.port
|
notice "starting publisher", wakuPort = conf.port
|
||||||
|
|
||||||
let
|
let
|
||||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get()
|
||||||
ip = parseIpAddress("0.0.0.0")
|
ip = parseIpAddress("0.0.0.0")
|
||||||
flags = CapabilitiesBitfield.init(relay = true)
|
flags = CapabilitiesBitfield.init(relay = true)
|
||||||
|
|
||||||
|
|||||||
@ -35,13 +35,13 @@ const
|
|||||||
LightpushPubsubTopic = PubsubTopic("/waku/2/rs/1/0")
|
LightpushPubsubTopic = PubsubTopic("/waku/2/rs/1/0")
|
||||||
LightpushContentTopic = ContentTopic("/examples/1/light-pubsub-example/proto")
|
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
|
# use notice to filter all waku messaging
|
||||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||||
|
|
||||||
notice "starting publisher", wakuPort = wakuPort
|
notice "starting publisher", wakuPort = wakuPort
|
||||||
let
|
let
|
||||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get()
|
||||||
ip = parseIpAddress("0.0.0.0")
|
ip = parseIpAddress("0.0.0.0")
|
||||||
flags = CapabilitiesBitfield.init(relay = true)
|
flags = CapabilitiesBitfield.init(relay = true)
|
||||||
|
|
||||||
|
|||||||
@ -37,13 +37,13 @@ const bootstrapNode =
|
|||||||
const wakuPort = 60000
|
const wakuPort = 60000
|
||||||
const discv5Port = 9000
|
const discv5Port = 9000
|
||||||
|
|
||||||
proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
proc setupAndPublish(rng: crypto.Rng) {.async.} =
|
||||||
# use notice to filter all waku messaging
|
# use notice to filter all waku messaging
|
||||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||||
|
|
||||||
notice "starting publisher", wakuPort = wakuPort, discv5Port = discv5Port
|
notice "starting publisher", wakuPort = wakuPort, discv5Port = discv5Port
|
||||||
let
|
let
|
||||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get()
|
||||||
ip = parseIpAddress("0.0.0.0")
|
ip = parseIpAddress("0.0.0.0")
|
||||||
flags = CapabilitiesBitfield.init(relay = true)
|
flags = CapabilitiesBitfield.init(relay = true)
|
||||||
|
|
||||||
|
|||||||
@ -35,13 +35,13 @@ const bootstrapNode =
|
|||||||
const wakuPort = 50000
|
const wakuPort = 50000
|
||||||
const discv5Port = 8000
|
const discv5Port = 8000
|
||||||
|
|
||||||
proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
proc setupAndSubscribe(rng: crypto.Rng) {.async.} =
|
||||||
# use notice to filter all waku messaging
|
# use notice to filter all waku messaging
|
||||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||||
|
|
||||||
notice "starting subscriber", wakuPort = wakuPort, discv5Port = discv5Port
|
notice "starting subscriber", wakuPort = wakuPort, discv5Port = discv5Port
|
||||||
let
|
let
|
||||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[]
|
||||||
ip = parseIpAddress("0.0.0.0")
|
ip = parseIpAddress("0.0.0.0")
|
||||||
flags = CapabilitiesBitfield.init(relay = true)
|
flags = CapabilitiesBitfield.init(relay = true)
|
||||||
|
|
||||||
|
|||||||
627
nimble.lock
627
nimble.lock
@ -1,627 +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"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sds": {
|
|
||||||
"version": "#2e9a7683f0e180bf112135fae3a3803eed8490d4",
|
|
||||||
"vcsRevision": "2e9a7683f0e180bf112135fae3a3803eed8490d4",
|
|
||||||
"url": "https://github.com/logos-messaging/nim-sds.git",
|
|
||||||
"downloadMethod": "git",
|
|
||||||
"dependencies": [
|
|
||||||
"nim",
|
|
||||||
"chronos",
|
|
||||||
"libp2p",
|
|
||||||
"chronicles",
|
|
||||||
"stew",
|
|
||||||
"stint",
|
|
||||||
"metrics",
|
|
||||||
"results",
|
|
||||||
"taskpools"
|
|
||||||
],
|
|
||||||
"checksums": {
|
|
||||||
"sha1": "d13f1bf8d1b90b27e9edfc063b043831242cda19"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"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": {}
|
|
||||||
}
|
|
||||||
@ -21,9 +21,9 @@ import
|
|||||||
../testlib/[common, wakucore, wakunode, testasync, futures, testutils],
|
../testlib/[common, wakucore, wakunode, testasync, futures, testutils],
|
||||||
../waku_filter_v2/waku_filter_utils
|
../waku_filter_v2/waku_filter_utils
|
||||||
|
|
||||||
proc generateRequestId(rng: ref HmacDrbgContext): string =
|
proc generateRequestId(rng: crypto.Rng): string =
|
||||||
var bytes: array[10, byte]
|
var bytes: array[10, byte]
|
||||||
hmacDrbgGenerate(rng[], bytes)
|
rng.generate(bytes)
|
||||||
return toHex(bytes)
|
return toHex(bytes)
|
||||||
|
|
||||||
proc createRequest(
|
proc createRequest(
|
||||||
|
|||||||
@ -35,10 +35,10 @@ from ../../waku/waku_noise/noise_utils import randomSeqByte
|
|||||||
proc buildRandomIdentityCredentials(): IdentityCredential =
|
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)
|
# We generate a random identity credential (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen)
|
||||||
let
|
let
|
||||||
idTrapdoor = randomSeqByte(rng[], 32)
|
idTrapdoor = randomSeqByte(rng, 32)
|
||||||
idNullifier = randomSeqByte(rng[], 32)
|
idNullifier = randomSeqByte(rng, 32)
|
||||||
idSecretHash = randomSeqByte(rng[], 32)
|
idSecretHash = randomSeqByte(rng, 32)
|
||||||
idCommitment = randomSeqByte(rng[], 32)
|
idCommitment = randomSeqByte(rng, 32)
|
||||||
|
|
||||||
IdentityCredential(
|
IdentityCredential(
|
||||||
idTrapdoor: idTrapdoor,
|
idTrapdoor: idTrapdoor,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import chronos, bearssl/rand, eth/[keys, p2p]
|
import chronos, eth/[keys, p2p]
|
||||||
|
|
||||||
import libp2p/crypto/crypto
|
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"))
|
result = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("127.0.0.1"))
|
||||||
|
|
||||||
proc setupTestNode*(
|
proc setupTestNode*(
|
||||||
rng: ref HmacDrbgContext, capabilities: varargs[ProtocolInfo, `protocolInfo`]
|
rng: crypto.Rng, capabilities: varargs[ProtocolInfo, `protocolInfo`]
|
||||||
): EthereumNode =
|
): EthereumNode =
|
||||||
let
|
let
|
||||||
keys1 = keys.KeyPair.random(rng[])
|
keys1 = keys.KeyPair.random(rng)
|
||||||
address = localAddress(nextPort)
|
address = localAddress(nextPort)
|
||||||
result = newEthereumNode(
|
result = newEthereumNode(
|
||||||
keys1,
|
keys1,
|
||||||
@ -29,11 +29,11 @@ proc setupTestNode*(
|
|||||||
|
|
||||||
# Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28
|
# Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28
|
||||||
type RngWrap = object
|
type RngWrap = object
|
||||||
rng: ref rand.HmacDrbgContext
|
rng: Rng
|
||||||
|
|
||||||
var rngVar: RngWrap
|
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
|
# 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
|
# 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
|
# 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 = crypto.newRng()
|
||||||
rngVar.rng
|
rngVar.rng
|
||||||
|
|
||||||
template rng*(): ref rand.HmacDrbgContext =
|
template rng*(): Rng =
|
||||||
getRng()
|
getRng()
|
||||||
|
|||||||
@ -52,7 +52,7 @@ suite "Waku DNS Discovery":
|
|||||||
)
|
)
|
||||||
.get() # No link entries
|
.get() # No link entries
|
||||||
|
|
||||||
let treeKeys = keys.KeyPair.random(rng[])
|
let treeKeys = keys.KeyPair.random(rng)
|
||||||
|
|
||||||
# Sign tree
|
# Sign tree
|
||||||
check:
|
check:
|
||||||
|
|||||||
@ -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)
|
# We generate a random identity credential (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen)
|
||||||
var
|
var
|
||||||
idTrapdoor = randomSeqByte(rng[], 32)
|
idTrapdoor = randomSeqByte(rng, 32)
|
||||||
idNullifier = randomSeqByte(rng[], 32)
|
idNullifier = randomSeqByte(rng, 32)
|
||||||
idSecretHash = randomSeqByte(rng[], 32)
|
idSecretHash = randomSeqByte(rng, 32)
|
||||||
idCommitment = randomSeqByte(rng[], 32)
|
idCommitment = randomSeqByte(rng, 32)
|
||||||
|
|
||||||
var idCredential = IdentityCredential(
|
var idCredential = IdentityCredential(
|
||||||
idTrapdoor: idTrapdoor,
|
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)
|
# We generate two random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen)
|
||||||
var
|
var
|
||||||
idTrapdoor = randomSeqByte(rng[], 32)
|
idTrapdoor = randomSeqByte(rng, 32)
|
||||||
idNullifier = randomSeqByte(rng[], 32)
|
idNullifier = randomSeqByte(rng, 32)
|
||||||
idSecretHash = randomSeqByte(rng[], 32)
|
idSecretHash = randomSeqByte(rng, 32)
|
||||||
idCommitment = randomSeqByte(rng[], 32)
|
idCommitment = randomSeqByte(rng, 32)
|
||||||
idCredential = IdentityCredential(
|
idCredential = IdentityCredential(
|
||||||
idTrapdoor: idTrapdoor,
|
idTrapdoor: idTrapdoor,
|
||||||
idNullifier: idNullifier,
|
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)
|
# We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen)
|
||||||
let
|
let
|
||||||
idTrapdoor = randomSeqByte(rng[], 32)
|
idTrapdoor = randomSeqByte(rng, 32)
|
||||||
idNullifier = randomSeqByte(rng[], 32)
|
idNullifier = randomSeqByte(rng, 32)
|
||||||
idSecretHash = randomSeqByte(rng[], 32)
|
idSecretHash = randomSeqByte(rng, 32)
|
||||||
idCommitment = randomSeqByte(rng[], 32)
|
idCommitment = randomSeqByte(rng, 32)
|
||||||
idCredential = IdentityCredential(
|
idCredential = IdentityCredential(
|
||||||
idTrapdoor: idTrapdoor,
|
idTrapdoor: idTrapdoor,
|
||||||
idNullifier: idNullifier,
|
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)
|
# We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen)
|
||||||
let
|
let
|
||||||
idTrapdoor = randomSeqByte(rng[], 32)
|
idTrapdoor = randomSeqByte(rng, 32)
|
||||||
idNullifier = randomSeqByte(rng[], 32)
|
idNullifier = randomSeqByte(rng, 32)
|
||||||
idSecretHash = randomSeqByte(rng[], 32)
|
idSecretHash = randomSeqByte(rng, 32)
|
||||||
idCommitment = randomSeqByte(rng[], 32)
|
idCommitment = randomSeqByte(rng, 32)
|
||||||
idCredential = IdentityCredential(
|
idCredential = IdentityCredential(
|
||||||
idTrapdoor: idTrapdoor,
|
idTrapdoor: idTrapdoor,
|
||||||
idNullifier: idNullifier,
|
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)
|
# We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen)
|
||||||
let
|
let
|
||||||
idTrapdoor = randomSeqByte(rng[], 32)
|
idTrapdoor = randomSeqByte(rng, 32)
|
||||||
idNullifier = randomSeqByte(rng[], 32)
|
idNullifier = randomSeqByte(rng, 32)
|
||||||
idSecretHash = randomSeqByte(rng[], 32)
|
idSecretHash = randomSeqByte(rng, 32)
|
||||||
idCommitment = randomSeqByte(rng[], 32)
|
idCommitment = randomSeqByte(rng, 32)
|
||||||
idCredential = IdentityCredential(
|
idCredential = IdentityCredential(
|
||||||
idTrapdoor: idTrapdoor,
|
idTrapdoor: idTrapdoor,
|
||||||
idNullifier: idNullifier,
|
idNullifier: idNullifier,
|
||||||
|
|||||||
@ -16,7 +16,7 @@ suite "KeyFile test suite":
|
|||||||
removeFile(filepath)
|
removeFile(filepath)
|
||||||
|
|
||||||
# The secret
|
# The secret
|
||||||
var secret = randomSeqByte(rng[], 300)
|
var secret = randomSeqByte(rng, 300)
|
||||||
|
|
||||||
# We create a keyfile encrypting the secret with password
|
# We create a keyfile encrypting the secret with password
|
||||||
let keyfile = createKeyFileJson(secret, password)
|
let keyfile = createKeyFileJson(secret, password)
|
||||||
@ -42,9 +42,9 @@ suite "KeyFile test suite":
|
|||||||
|
|
||||||
test "Create/Save/Load multiple keyfiles in same file":
|
test "Create/Save/Load multiple keyfiles in same file":
|
||||||
# We set different passwords for different keyfiles that will be stored 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 password2 = ""
|
||||||
let password3 = string.fromBytes(randomSeqByte(rng[], 20))
|
let password3 = string.fromBytes(randomSeqByte(rng, 20))
|
||||||
var keyfile: KfResult[JsonNode]
|
var keyfile: KfResult[JsonNode]
|
||||||
|
|
||||||
let filepath = "./test.keyfile"
|
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
|
# 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)
|
keyfile = createKeyFileJson(secret1, password1)
|
||||||
check:
|
check:
|
||||||
keyfile.isOk()
|
keyfile.isOk()
|
||||||
saveKeyFile(filepath, keyfile.get()).isOk()
|
saveKeyFile(filepath, keyfile.get()).isOk()
|
||||||
|
|
||||||
let secret2 = randomSeqByte(rng[], 300)
|
let secret2 = randomSeqByte(rng, 300)
|
||||||
keyfile = createKeyFileJson(secret2, password2)
|
keyfile = createKeyFileJson(secret2, password2)
|
||||||
check:
|
check:
|
||||||
keyfile.isOk()
|
keyfile.isOk()
|
||||||
saveKeyFile(filepath, keyfile.get()).isOk()
|
saveKeyFile(filepath, keyfile.get()).isOk()
|
||||||
|
|
||||||
let secret3 = randomSeqByte(rng[], 300)
|
let secret3 = randomSeqByte(rng, 300)
|
||||||
keyfile = createKeyFileJson(secret3, password3)
|
keyfile = createKeyFileJson(secret3, password3)
|
||||||
check:
|
check:
|
||||||
keyfile.isOk()
|
keyfile.isOk()
|
||||||
saveKeyFile(filepath, keyfile.get()).isOk()
|
saveKeyFile(filepath, keyfile.get()).isOk()
|
||||||
|
|
||||||
# We encrypt secret4 with password3
|
# We encrypt secret4 with password3
|
||||||
let secret4 = randomSeqByte(rng[], 300)
|
let secret4 = randomSeqByte(rng, 300)
|
||||||
keyfile = createKeyFileJson(secret4, password3)
|
keyfile = createKeyFileJson(secret4, password3)
|
||||||
check:
|
check:
|
||||||
keyfile.isOk()
|
keyfile.isOk()
|
||||||
saveKeyFile(filepath, keyfile.get()).isOk()
|
saveKeyFile(filepath, keyfile.get()).isOk()
|
||||||
|
|
||||||
# We encrypt secret5 with password1
|
# We encrypt secret5 with password1
|
||||||
let secret5 = randomSeqByte(rng[], 300)
|
let secret5 = randomSeqByte(rng, 300)
|
||||||
keyfile = createKeyFileJson(secret5, password1)
|
keyfile = createKeyFileJson(secret5, password1)
|
||||||
check:
|
check:
|
||||||
keyfile.isOk()
|
keyfile.isOk()
|
||||||
saveKeyFile(filepath, keyfile.get()).isOk()
|
saveKeyFile(filepath, keyfile.get()).isOk()
|
||||||
|
|
||||||
# We encrypt secret6 with password1
|
# We encrypt secret6 with password1
|
||||||
let secret6 = randomSeqByte(rng[], 300)
|
let secret6 = randomSeqByte(rng, 300)
|
||||||
keyfile = createKeyFileJson(secret6, password1)
|
keyfile = createKeyFileJson(secret6, password1)
|
||||||
check:
|
check:
|
||||||
keyfile.isOk()
|
keyfile.isOk()
|
||||||
@ -343,7 +343,7 @@ suite "KeyFile test suite (adapted from nim-eth keyfile tests)":
|
|||||||
|
|
||||||
test "Scrypt keyfiles":
|
test "Scrypt keyfiles":
|
||||||
let
|
let
|
||||||
expectedSecret = randomSeqByte(rng[], 300)
|
expectedSecret = randomSeqByte(rng, 300)
|
||||||
password = "miawmiawcat"
|
password = "miawmiawcat"
|
||||||
|
|
||||||
# By default, keyfiles' encryption key is derived from password using PBKDF2.
|
# By default, keyfiles' encryption key is derived from password using PBKDF2.
|
||||||
|
|||||||
@ -27,7 +27,7 @@ procSuite "Waku Noise":
|
|||||||
let maxMessageLength = 3 * NoisePaddingBlockSize
|
let maxMessageLength = 3 * NoisePaddingBlockSize
|
||||||
for messageLen in 0 .. maxMessageLength:
|
for messageLen in 0 .. maxMessageLength:
|
||||||
let
|
let
|
||||||
message = randomSeqByte(rng[], messageLen)
|
message = randomSeqByte(rng, messageLen)
|
||||||
padded = pkcs7_pad(message, NoisePaddingBlockSize)
|
padded = pkcs7_pad(message, NoisePaddingBlockSize)
|
||||||
unpadded = pkcs7_unpad(padded, NoisePaddingBlockSize)
|
unpadded = pkcs7_unpad(padded, NoisePaddingBlockSize)
|
||||||
|
|
||||||
@ -37,11 +37,11 @@ procSuite "Waku Noise":
|
|||||||
message == unpadded
|
message == unpadded
|
||||||
|
|
||||||
test "ChaChaPoly Encryption/Decryption: random byte sequences":
|
test "ChaChaPoly Encryption/Decryption: random byte sequences":
|
||||||
let cipherState = randomChaChaPolyCipherState(rng[])
|
let cipherState = randomChaChaPolyCipherState(rng)
|
||||||
|
|
||||||
# We encrypt/decrypt random byte sequences
|
# We encrypt/decrypt random byte sequences
|
||||||
let
|
let
|
||||||
plaintext: seq[byte] = randomSeqByte(rng[], rand(1 .. 128))
|
plaintext: seq[byte] = randomSeqByte(rng, rand(1 .. 128))
|
||||||
ciphertext: ChaChaPolyCiphertext = encrypt(cipherState, plaintext)
|
ciphertext: ChaChaPolyCiphertext = encrypt(cipherState, plaintext)
|
||||||
decryptedCiphertext: seq[byte] = decrypt(cipherState, ciphertext)
|
decryptedCiphertext: seq[byte] = decrypt(cipherState, ciphertext)
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ procSuite "Waku Noise":
|
|||||||
plaintext == decryptedCiphertext
|
plaintext == decryptedCiphertext
|
||||||
|
|
||||||
test "ChaChaPoly Encryption/Decryption: random strings":
|
test "ChaChaPoly Encryption/Decryption: random strings":
|
||||||
let cipherState = randomChaChaPolyCipherState(rng[])
|
let cipherState = randomChaChaPolyCipherState(rng)
|
||||||
|
|
||||||
# We encrypt/decrypt random strings
|
# We encrypt/decrypt random strings
|
||||||
var plaintext: string
|
var plaintext: string
|
||||||
@ -64,10 +64,10 @@ procSuite "Waku Noise":
|
|||||||
plaintext.toBytes() == decryptedCiphertext
|
plaintext.toBytes() == decryptedCiphertext
|
||||||
|
|
||||||
test "Noise public keys: encrypt and decrypt a public key":
|
test "Noise public keys: encrypt and decrypt a public key":
|
||||||
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[])
|
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng)
|
||||||
|
|
||||||
let
|
let
|
||||||
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[])
|
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng)
|
||||||
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
||||||
decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk)
|
decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk)
|
||||||
|
|
||||||
@ -75,20 +75,20 @@ procSuite "Waku Noise":
|
|||||||
noisePublicKey == decryptedPk
|
noisePublicKey == decryptedPk
|
||||||
|
|
||||||
test "Noise public keys: decrypt an unencrypted public key":
|
test "Noise public keys: decrypt an unencrypted public key":
|
||||||
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[])
|
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng)
|
||||||
|
|
||||||
let
|
let
|
||||||
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[])
|
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng)
|
||||||
decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, noisePublicKey)
|
decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, noisePublicKey)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
noisePublicKey == decryptedPk
|
noisePublicKey == decryptedPk
|
||||||
|
|
||||||
test "Noise public keys: encrypt an encrypted public key":
|
test "Noise public keys: encrypt an encrypted public key":
|
||||||
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[])
|
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng)
|
||||||
|
|
||||||
let
|
let
|
||||||
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[])
|
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng)
|
||||||
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
||||||
encryptedPk2: NoisePublicKey = encryptNoisePublicKey(cs, encryptedPk)
|
encryptedPk2: NoisePublicKey = encryptNoisePublicKey(cs, encryptedPk)
|
||||||
|
|
||||||
@ -96,10 +96,10 @@ procSuite "Waku Noise":
|
|||||||
encryptedPk == encryptedPk2
|
encryptedPk == encryptedPk2
|
||||||
|
|
||||||
test "Noise public keys: encrypt, decrypt and decrypt a public key":
|
test "Noise public keys: encrypt, decrypt and decrypt a public key":
|
||||||
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[])
|
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng)
|
||||||
|
|
||||||
let
|
let
|
||||||
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[])
|
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng)
|
||||||
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
||||||
decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk)
|
decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk)
|
||||||
decryptedPk2: NoisePublicKey = decryptNoisePublicKey(cs, decryptedPk)
|
decryptedPk2: NoisePublicKey = decryptNoisePublicKey(cs, decryptedPk)
|
||||||
@ -109,7 +109,7 @@ procSuite "Waku Noise":
|
|||||||
|
|
||||||
test "Noise public keys: serialize and deserialize an unencrypted public key":
|
test "Noise public keys: serialize and deserialize an unencrypted public key":
|
||||||
let
|
let
|
||||||
noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[])
|
noisePublicKey: NoisePublicKey = genNoisePublicKey(rng)
|
||||||
serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(noisePublicKey)
|
serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(noisePublicKey)
|
||||||
deserializedNoisePublicKey: NoisePublicKey =
|
deserializedNoisePublicKey: NoisePublicKey =
|
||||||
intoNoisePublicKey(serializedNoisePublicKey)
|
intoNoisePublicKey(serializedNoisePublicKey)
|
||||||
@ -118,10 +118,10 @@ procSuite "Waku Noise":
|
|||||||
noisePublicKey == deserializedNoisePublicKey
|
noisePublicKey == deserializedNoisePublicKey
|
||||||
|
|
||||||
test "Noise public keys: encrypt, serialize, deserialize and decrypt a public key":
|
test "Noise public keys: encrypt, serialize, deserialize and decrypt a public key":
|
||||||
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[])
|
let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng)
|
||||||
|
|
||||||
let
|
let
|
||||||
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[])
|
cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng)
|
||||||
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey)
|
||||||
serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(encryptedPk)
|
serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(encryptedPk)
|
||||||
deserializedNoisePublicKey: NoisePublicKey =
|
deserializedNoisePublicKey: NoisePublicKey =
|
||||||
@ -134,7 +134,7 @@ procSuite "Waku Noise":
|
|||||||
|
|
||||||
test "PayloadV2: serialize/deserialize PayloadV2 to byte sequence":
|
test "PayloadV2: serialize/deserialize PayloadV2 to byte sequence":
|
||||||
let
|
let
|
||||||
payload2: PayloadV2 = randomPayloadV2(rng[])
|
payload2: PayloadV2 = randomPayloadV2(rng)
|
||||||
serializedPayload = serializePayloadV2(payload2)
|
serializedPayload = serializePayloadV2(payload2)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
@ -149,7 +149,7 @@ procSuite "Waku Noise":
|
|||||||
test "PayloadV2: Encode/Decode a Waku Message (version 2) to a PayloadV2":
|
test "PayloadV2: Encode/Decode a Waku Message (version 2) to a PayloadV2":
|
||||||
# We encode to a WakuMessage a random PayloadV2
|
# We encode to a WakuMessage a random PayloadV2
|
||||||
let
|
let
|
||||||
payload2 = randomPayloadV2(rng[])
|
payload2 = randomPayloadV2(rng)
|
||||||
msg = encodePayloadV2(payload2)
|
msg = encodePayloadV2(payload2)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
@ -173,8 +173,8 @@ procSuite "Waku Noise":
|
|||||||
test "Noise State Machine: Diffie-Hellman operation":
|
test "Noise State Machine: Diffie-Hellman operation":
|
||||||
#We generate random keypairs
|
#We generate random keypairs
|
||||||
let
|
let
|
||||||
aliceKey = genKeyPair(rng[])
|
aliceKey = genKeyPair(rng)
|
||||||
bobKey = 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 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
|
# 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":
|
test "Noise State Machine: Cipher State primitives":
|
||||||
# We generate a random Cipher State, associated data ad and plaintext
|
# We generate a random Cipher State, associated data ad and plaintext
|
||||||
var
|
var
|
||||||
cipherState: CipherState = randomCipherState(rng[])
|
cipherState: CipherState = randomCipherState(rng)
|
||||||
nonce: uint64 = uint64(rand(0 .. int.high))
|
nonce: uint64 = uint64(rand(0 .. int.high))
|
||||||
ad: seq[byte] = randomSeqByte(rng[], rand(1 .. 128))
|
ad: seq[byte] = randomSeqByte(rng, rand(1 .. 128))
|
||||||
plaintext: 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
|
# We set the random nonce generated in the cipher state
|
||||||
setNonce(cipherState, nonce)
|
setNonce(cipherState, nonce)
|
||||||
@ -218,7 +218,7 @@ procSuite "Waku Noise":
|
|||||||
setCipherStateKey(cipherState, EmptyKey)
|
setCipherStateKey(cipherState, EmptyKey)
|
||||||
nonce = getNonce(cipherState)
|
nonce = getNonce(cipherState)
|
||||||
|
|
||||||
plaintext = randomSeqByte(rng[], rand(1 .. 128))
|
plaintext = randomSeqByte(rng, rand(1 .. 128))
|
||||||
ciphertext = encryptWithAd(cipherState, ad, plaintext)
|
ciphertext = encryptWithAd(cipherState, ad, plaintext)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
@ -230,7 +230,7 @@ procSuite "Waku Noise":
|
|||||||
nonce = getNonce(cipherState)
|
nonce = getNonce(cipherState)
|
||||||
|
|
||||||
# Note that we set ciphertext minimum length to 16 to not trigger checks on authentication tag length
|
# 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)
|
plaintext = decryptWithAd(cipherState, ad, ciphertext)
|
||||||
|
|
||||||
check:
|
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
|
# 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
|
# We generate a test Cipher State with nonce set to MaxNonce
|
||||||
cipherState = randomCipherState(rng[])
|
cipherState = randomCipherState(rng)
|
||||||
setNonce(cipherState, NonceMax)
|
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
|
# 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]:
|
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
|
# 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.
|
# 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
|
# 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)
|
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
|
# 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
|
# 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
|
# 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
|
# mixHash changes only the handshake hash value of the Symmetric state
|
||||||
check:
|
check:
|
||||||
@ -324,7 +324,7 @@ procSuite "Waku Noise":
|
|||||||
########################################
|
########################################
|
||||||
|
|
||||||
# We generate random input key material and we execute mixKey
|
# 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(symmetricState, inputKeyMaterial)
|
||||||
|
|
||||||
# mixKey changes the Symmetric State's chaining key and encryption key of the embedded Cipher State
|
# 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
|
# 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(symmetricState, inputKeyMaterial)
|
||||||
|
|
||||||
# mixKeyAndHash executes a mixKey and a mixHash using the input key material
|
# mixKeyAndHash executes a mixKey and a mixHash using the input key material
|
||||||
@ -368,7 +368,7 @@ procSuite "Waku Noise":
|
|||||||
var initialSymmetricState = symmetricState
|
var initialSymmetricState = symmetricState
|
||||||
|
|
||||||
# We generate random plaintext and we execute encryptAndHash
|
# We generate random plaintext and we execute encryptAndHash
|
||||||
var plaintext = randomChaChaPolyKey(rng[])
|
var plaintext = randomChaChaPolyKey(rng)
|
||||||
var nonce = getNonce(getCipherState(symmetricState))
|
var nonce = getNonce(getCipherState(symmetricState))
|
||||||
var ciphertext = encryptAndHash(symmetricState, plaintext)
|
var ciphertext = encryptAndHash(symmetricState, plaintext)
|
||||||
|
|
||||||
@ -421,11 +421,11 @@ procSuite "Waku Noise":
|
|||||||
let hsPattern = NoiseHandshakePatterns["XX"]
|
let hsPattern = NoiseHandshakePatterns["XX"]
|
||||||
|
|
||||||
# We initialize Alice's and Bob's Handshake State
|
# We initialize Alice's and Bob's Handshake State
|
||||||
let aliceStaticKey = genKeyPair(rng[])
|
let aliceStaticKey = genKeyPair(rng)
|
||||||
var aliceHS =
|
var aliceHS =
|
||||||
initialize(hsPattern = hsPattern, staticKey = aliceStaticKey, initiator = true)
|
initialize(hsPattern = hsPattern, staticKey = aliceStaticKey, initiator = true)
|
||||||
|
|
||||||
let bobStaticKey = genKeyPair(rng[])
|
let bobStaticKey = genKeyPair(rng)
|
||||||
var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey)
|
var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey)
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -440,15 +440,15 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message
|
||||||
# and the (encrypted) transport message
|
# and the (encrypted) transport message
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -458,13 +458,13 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# We generate a random transport message
|
||||||
sentTransportMessage = randomSeqByte(rng[], 32)
|
sentTransportMessage = randomSeqByte(rng, 32)
|
||||||
|
|
||||||
# At this step, Bob writes and returns a payload
|
# 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
|
# 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:
|
check:
|
||||||
aliceStep.transportMessage == sentTransportMessage
|
aliceStep.transportMessage == sentTransportMessage
|
||||||
@ -474,14 +474,14 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -494,13 +494,13 @@ procSuite "Waku Noise":
|
|||||||
let prevBobHS = bobHS
|
let prevBobHS = bobHS
|
||||||
|
|
||||||
let bobStep1 =
|
let bobStep1 =
|
||||||
stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get()
|
stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get()
|
||||||
let aliceStep1 =
|
let aliceStep1 =
|
||||||
stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep1.payload2).get()
|
stepHandshake(rng, aliceHS, readPayloadV2 = bobStep1.payload2).get()
|
||||||
let aliceStep2 =
|
let aliceStep2 =
|
||||||
stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get()
|
stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get()
|
||||||
let bobStep2 =
|
let bobStep2 =
|
||||||
stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep2.payload2).get()
|
stepHandshake(rng, bobHS, readPayloadV2 = aliceStep2.payload2).get()
|
||||||
|
|
||||||
check:
|
check:
|
||||||
aliceStep1 == default(HandshakeStepResult)
|
aliceStep1 == default(HandshakeStepResult)
|
||||||
@ -529,7 +529,7 @@ procSuite "Waku Noise":
|
|||||||
|
|
||||||
for _ in 0 .. 10:
|
for _ in 0 .. 10:
|
||||||
# Alice writes to Bob
|
# Alice writes to Bob
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
@ -538,7 +538,7 @@ procSuite "Waku Noise":
|
|||||||
message == readMessage
|
message == readMessage
|
||||||
|
|
||||||
# Bob writes to Alice
|
# Bob writes to Alice
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
@ -550,15 +550,15 @@ procSuite "Waku Noise":
|
|||||||
let hsPattern = NoiseHandshakePatterns["XXpsk0"]
|
let hsPattern = NoiseHandshakePatterns["XXpsk0"]
|
||||||
|
|
||||||
# We generate a random psk
|
# We generate a random psk
|
||||||
let psk = randomSeqByte(rng[], 32)
|
let psk = randomSeqByte(rng, 32)
|
||||||
|
|
||||||
# We initialize Alice's and Bob's Handshake State
|
# We initialize Alice's and Bob's Handshake State
|
||||||
let aliceStaticKey = genKeyPair(rng[])
|
let aliceStaticKey = genKeyPair(rng)
|
||||||
var aliceHS = initialize(
|
var aliceHS = initialize(
|
||||||
hsPattern = hsPattern, staticKey = aliceStaticKey, psk = psk, initiator = true
|
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 bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey, psk = psk)
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -573,15 +573,15 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message
|
||||||
# and the (encrypted) transport message
|
# and the (encrypted) transport message
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -591,13 +591,13 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# We generate a random transport message
|
||||||
sentTransportMessage = randomSeqByte(rng[], 32)
|
sentTransportMessage = randomSeqByte(rng, 32)
|
||||||
|
|
||||||
# At this step, Bob writes and returns a payload
|
# 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
|
# 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:
|
check:
|
||||||
aliceStep.transportMessage == sentTransportMessage
|
aliceStep.transportMessage == sentTransportMessage
|
||||||
@ -607,14 +607,14 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -640,7 +640,7 @@ procSuite "Waku Noise":
|
|||||||
|
|
||||||
for _ in 0 .. 10:
|
for _ in 0 .. 10:
|
||||||
# Alice writes to Bob
|
# Alice writes to Bob
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
@ -649,7 +649,7 @@ procSuite "Waku Noise":
|
|||||||
message == readMessage
|
message == readMessage
|
||||||
|
|
||||||
# Bob writes to Alice
|
# Bob writes to Alice
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
@ -661,8 +661,8 @@ procSuite "Waku Noise":
|
|||||||
let hsPattern = NoiseHandshakePatterns["K1K1"]
|
let hsPattern = NoiseHandshakePatterns["K1K1"]
|
||||||
|
|
||||||
# We initialize Alice's and Bob's Handshake State
|
# We initialize Alice's and Bob's Handshake State
|
||||||
let aliceStaticKey = genKeyPair(rng[])
|
let aliceStaticKey = genKeyPair(rng)
|
||||||
let bobStaticKey = genKeyPair(rng[])
|
let bobStaticKey = genKeyPair(rng)
|
||||||
|
|
||||||
# This handshake has the following pre-message pattern:
|
# This handshake has the following pre-message pattern:
|
||||||
# -> s
|
# -> s
|
||||||
@ -696,15 +696,15 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message
|
||||||
# and the (encrypted) transport message
|
# and the (encrypted) transport message
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -714,13 +714,13 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# We generate a random transport message
|
||||||
sentTransportMessage = randomSeqByte(rng[], 32)
|
sentTransportMessage = randomSeqByte(rng, 32)
|
||||||
|
|
||||||
# At this step, Bob writes and returns a payload
|
# 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
|
# 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:
|
check:
|
||||||
aliceStep.transportMessage == sentTransportMessage
|
aliceStep.transportMessage == sentTransportMessage
|
||||||
@ -730,14 +730,14 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# Similarly as in first step, Alice writes a Waku2 payload containing the handshake_message and the (encrypted) transportMessage
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -763,7 +763,7 @@ procSuite "Waku Noise":
|
|||||||
|
|
||||||
for _ in 0 .. 10:
|
for _ in 0 .. 10:
|
||||||
# Alice writes to Bob
|
# Alice writes to Bob
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
@ -772,7 +772,7 @@ procSuite "Waku Noise":
|
|||||||
message == readMessage
|
message == readMessage
|
||||||
|
|
||||||
# Bob writes to Alice
|
# Bob writes to Alice
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
@ -784,8 +784,8 @@ procSuite "Waku Noise":
|
|||||||
let hsPattern = NoiseHandshakePatterns["XK1"]
|
let hsPattern = NoiseHandshakePatterns["XK1"]
|
||||||
|
|
||||||
# We initialize Alice's and Bob's Handshake State
|
# We initialize Alice's and Bob's Handshake State
|
||||||
let aliceStaticKey = genKeyPair(rng[])
|
let aliceStaticKey = genKeyPair(rng)
|
||||||
let bobStaticKey = genKeyPair(rng[])
|
let bobStaticKey = genKeyPair(rng)
|
||||||
|
|
||||||
# This handshake has the following pre-message pattern:
|
# This handshake has the following pre-message pattern:
|
||||||
# <- s
|
# <- s
|
||||||
@ -816,15 +816,15 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message
|
||||||
# and the (encrypted) transport message
|
# and the (encrypted) transport message
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -834,13 +834,13 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# We generate a random transport message
|
||||||
sentTransportMessage = randomSeqByte(rng[], 32)
|
sentTransportMessage = randomSeqByte(rng, 32)
|
||||||
|
|
||||||
# At this step, Bob writes and returns a payload
|
# 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
|
# 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:
|
check:
|
||||||
aliceStep.transportMessage == sentTransportMessage
|
aliceStep.transportMessage == sentTransportMessage
|
||||||
@ -850,14 +850,14 @@ procSuite "Waku Noise":
|
|||||||
###############
|
###############
|
||||||
|
|
||||||
# We generate a random transport message
|
# 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
|
# Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message
|
||||||
aliceStep =
|
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
|
# 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:
|
check:
|
||||||
bobStep.transportMessage == sentTransportMessage
|
bobStep.transportMessage == sentTransportMessage
|
||||||
@ -883,7 +883,7 @@ procSuite "Waku Noise":
|
|||||||
|
|
||||||
for _ in 0 .. 10:
|
for _ in 0 .. 10:
|
||||||
# Alice writes to Bob
|
# Alice writes to Bob
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
@ -892,7 +892,7 @@ procSuite "Waku Noise":
|
|||||||
message == readMessage
|
message == readMessage
|
||||||
|
|
||||||
# Bob writes to Alice
|
# Bob writes to Alice
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer)
|
||||||
readMessage =
|
readMessage =
|
||||||
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get()
|
||||||
|
|||||||
@ -25,22 +25,22 @@ procSuite "Waku Noise Sessions":
|
|||||||
let hsPattern = NoiseHandshakePatterns["WakuPairing"]
|
let hsPattern = NoiseHandshakePatterns["WakuPairing"]
|
||||||
|
|
||||||
# Alice static/ephemeral key initialization and commitment
|
# Alice static/ephemeral key initialization and commitment
|
||||||
let aliceStaticKey = genKeyPair(rng[])
|
let aliceStaticKey = genKeyPair(rng)
|
||||||
let aliceEphemeralKey = genKeyPair(rng[])
|
let aliceEphemeralKey = genKeyPair(rng)
|
||||||
let s = randomSeqByte(rng[], 32)
|
let s = randomSeqByte(rng, 32)
|
||||||
let aliceCommittedStaticKey = commitPublicKey(getPublicKey(aliceStaticKey), s)
|
let aliceCommittedStaticKey = commitPublicKey(getPublicKey(aliceStaticKey), s)
|
||||||
|
|
||||||
# Bob static/ephemeral key initialization and commitment
|
# Bob static/ephemeral key initialization and commitment
|
||||||
let bobStaticKey = genKeyPair(rng[])
|
let bobStaticKey = genKeyPair(rng)
|
||||||
let bobEphemeralKey = genKeyPair(rng[])
|
let bobEphemeralKey = genKeyPair(rng)
|
||||||
let r = randomSeqByte(rng[], 32)
|
let r = randomSeqByte(rng, 32)
|
||||||
let bobCommittedStaticKey = commitPublicKey(getPublicKey(bobStaticKey), r)
|
let bobCommittedStaticKey = commitPublicKey(getPublicKey(bobStaticKey), r)
|
||||||
|
|
||||||
# Content Topic information
|
# Content Topic information
|
||||||
let applicationName = "waku-noise-sessions"
|
let applicationName = "waku-noise-sessions"
|
||||||
let applicationVersion = "0.1"
|
let applicationVersion = "0.1"
|
||||||
let shardId = "10"
|
let shardId = "10"
|
||||||
let qrMessageNametag = randomSeqByte(rng[], MessageNametagLength)
|
let qrMessageNametag = randomSeqByte(rng, MessageNametagLength)
|
||||||
|
|
||||||
# Out-of-band Communication
|
# Out-of-band Communication
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ procSuite "Waku Noise Sessions":
|
|||||||
# and the (encrypted) transport message
|
# and the (encrypted) transport message
|
||||||
# The message is sent with a messageNametag equal to the one received through the QR code
|
# The message is sent with a messageNametag equal to the one received through the QR code
|
||||||
aliceStep = stepHandshake(
|
aliceStep = stepHandshake(
|
||||||
rng[],
|
rng,
|
||||||
aliceHS,
|
aliceHS,
|
||||||
transportMessage = sentTransportMessage,
|
transportMessage = sentTransportMessage,
|
||||||
messageNametag = qrMessageNametag,
|
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
|
# 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
|
# Note that Bob verifies if the received payloadv2 has the expected messageNametag set
|
||||||
bobStep = stepHandshake(
|
bobStep = stepHandshake(
|
||||||
rng[], bobHS, readPayloadV2 = readPayloadV2, messageNametag = qrMessageNametag
|
rng, bobHS, readPayloadV2 = readPayloadV2, messageNametag = qrMessageNametag
|
||||||
)
|
)
|
||||||
.get()
|
.get()
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ procSuite "Waku Noise Sessions":
|
|||||||
|
|
||||||
# At this step, Bob writes and returns a payload
|
# At this step, Bob writes and returns a payload
|
||||||
bobStep = stepHandshake(
|
bobStep = stepHandshake(
|
||||||
rng[],
|
rng,
|
||||||
bobHS,
|
bobHS,
|
||||||
transportMessage = sentTransportMessage,
|
transportMessage = sentTransportMessage,
|
||||||
messageNametag = bobMessageNametag,
|
messageNametag = bobMessageNametag,
|
||||||
@ -233,7 +233,7 @@ procSuite "Waku Noise Sessions":
|
|||||||
|
|
||||||
# While Alice reads and returns the (decrypted) transport message
|
# While Alice reads and returns the (decrypted) transport message
|
||||||
aliceStep = stepHandshake(
|
aliceStep = stepHandshake(
|
||||||
rng[],
|
rng,
|
||||||
aliceHS,
|
aliceHS,
|
||||||
readPayloadV2 = readPayloadV2,
|
readPayloadV2 = readPayloadV2,
|
||||||
messageNametag = aliceMessageNametag,
|
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
|
# Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message
|
||||||
aliceStep = stepHandshake(
|
aliceStep = stepHandshake(
|
||||||
rng[],
|
rng,
|
||||||
aliceHS,
|
aliceHS,
|
||||||
transportMessage = sentTransportMessage,
|
transportMessage = sentTransportMessage,
|
||||||
messageNametag = aliceMessageNametag,
|
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
|
# Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him
|
||||||
bobStep = stepHandshake(
|
bobStep = stepHandshake(
|
||||||
rng[], bobHS, readPayloadV2 = readPayloadV2, messageNametag = bobMessageNametag
|
rng, bobHS, readPayloadV2 = readPayloadV2, messageNametag = bobMessageNametag
|
||||||
)
|
)
|
||||||
.get()
|
.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
|
# 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:
|
for i in 0 .. 10 * MessageNametagBufferSize:
|
||||||
# Alice writes to Bob
|
# Alice writes to Bob
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(
|
payload2 = writeMessage(
|
||||||
aliceHSResult,
|
aliceHSResult,
|
||||||
message,
|
message,
|
||||||
@ -350,7 +350,7 @@ procSuite "Waku Noise Sessions":
|
|||||||
message == readMessage
|
message == readMessage
|
||||||
|
|
||||||
# Bob writes to Alice
|
# Bob writes to Alice
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(
|
payload2 = writeMessage(
|
||||||
bobHSResult,
|
bobHSResult,
|
||||||
message,
|
message,
|
||||||
@ -368,13 +368,13 @@ procSuite "Waku Noise Sessions":
|
|||||||
|
|
||||||
# We test how nametag buffers help in detecting lost messages
|
# We test how nametag buffers help in detecting lost messages
|
||||||
# Alice writes two messages to Bob, but only the second is received
|
# Alice writes two messages to Bob, but only the second is received
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(
|
payload2 = writeMessage(
|
||||||
aliceHSResult,
|
aliceHSResult,
|
||||||
message,
|
message,
|
||||||
outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound,
|
outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound,
|
||||||
)
|
)
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(
|
payload2 = writeMessage(
|
||||||
aliceHSResult,
|
aliceHSResult,
|
||||||
message,
|
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)
|
# We adjust bob nametag buffer for next test (i.e. the missed message is correctly recovered)
|
||||||
delete(bobHSResult.nametagsInbound, 2)
|
delete(bobHSResult.nametagsInbound, 2)
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(
|
payload2 = writeMessage(
|
||||||
bobHSResult, message, outboundMessageNametagBuffer = bobHSResult.nametagsOutbound
|
bobHSResult, message, outboundMessageNametagBuffer = bobHSResult.nametagsOutbound
|
||||||
)
|
)
|
||||||
@ -405,7 +405,7 @@ procSuite "Waku Noise Sessions":
|
|||||||
message == readMessage
|
message == readMessage
|
||||||
|
|
||||||
# We test if a missing nametag is correctly detected
|
# We test if a missing nametag is correctly detected
|
||||||
message = randomSeqByte(rng[], 32)
|
message = randomSeqByte(rng, 32)
|
||||||
payload2 = writeMessage(
|
payload2 = writeMessage(
|
||||||
aliceHSResult,
|
aliceHSResult,
|
||||||
message,
|
message,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import std/[times, random], bearssl/rand, libp2p/crypto/crypto
|
import std/[times, random], libp2p/crypto/crypto
|
||||||
|
|
||||||
## Randomization
|
## Randomization
|
||||||
|
|
||||||
@ -11,14 +11,14 @@ proc randomize*() =
|
|||||||
## RNG
|
## RNG
|
||||||
# Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28
|
# Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28
|
||||||
|
|
||||||
type Rng = object
|
type RngState = object
|
||||||
rng: ref HmacDrbgContext
|
rng: Rng
|
||||||
|
|
||||||
# Typically having a module variable is considered bad design. This case should
|
# 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.
|
# 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
|
# 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
|
# 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
|
# 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
|
rngVar.rng
|
||||||
|
|
||||||
template rng*(): ref HmacDrbgContext =
|
template rng*(): Rng =
|
||||||
getRng()
|
getRng()
|
||||||
|
|||||||
@ -22,13 +22,13 @@ proc ts*(offset = 0, origin = now()): Timestamp =
|
|||||||
# Switch
|
# Switch
|
||||||
|
|
||||||
proc generateEcdsaKey*(): libp2p_keys.PrivateKey =
|
proc generateEcdsaKey*(): libp2p_keys.PrivateKey =
|
||||||
libp2p_keys.PrivateKey.random(ECDSA, rng[]).get()
|
libp2p_keys.PrivateKey.random(ECDSA, rng).get()
|
||||||
|
|
||||||
proc generateEcdsaKeyPair*(): libp2p_keys.KeyPair =
|
proc generateEcdsaKeyPair*(): libp2p_keys.KeyPair =
|
||||||
libp2p_keys.KeyPair.random(ECDSA, rng[]).get()
|
libp2p_keys.KeyPair.random(ECDSA, rng).get()
|
||||||
|
|
||||||
proc generateSecp256k1Key*(): libp2p_keys.PrivateKey =
|
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 =
|
proc ethSecp256k1Key*(hex: string): eth_keys.PrivateKey =
|
||||||
eth_keys.PrivateKey.fromHex(hex).get()
|
eth_keys.PrivateKey.fromHex(hex).get()
|
||||||
|
|||||||
@ -38,8 +38,8 @@ suite "Waku Discovery v5":
|
|||||||
|
|
||||||
let
|
let
|
||||||
rng = eth_keys.newRng()
|
rng = eth_keys.newRng()
|
||||||
pk1 = eth_keys.PrivateKey.random(rng[])
|
pk1 = eth_keys.PrivateKey.random(rng)
|
||||||
pk2 = eth_keys.PrivateKey.random(rng[])
|
pk2 = eth_keys.PrivateKey.random(rng)
|
||||||
|
|
||||||
suite "shardingPredicate":
|
suite "shardingPredicate":
|
||||||
var
|
var
|
||||||
@ -423,7 +423,7 @@ suite "Waku Discovery v5":
|
|||||||
let myRng = libp2p_keys.newRng()
|
let myRng = libp2p_keys.newRng()
|
||||||
var confBuilder = defaultTestWakuConfBuilder()
|
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.withEnabled(true)
|
||||||
confBuilder.discv5Conf.withUdpPort(9000.Port)
|
confBuilder.discv5Conf.withUdpPort(9000.Port)
|
||||||
let conf = confBuilder.build().valueOr:
|
let conf = confBuilder.build().valueOr:
|
||||||
@ -434,7 +434,7 @@ suite "Waku Discovery v5":
|
|||||||
(waitFor startWaku(addr waku0)).isOkOr:
|
(waitFor startWaku(addr waku0)).isOkOr:
|
||||||
raiseAssert error
|
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.withBootstrapNodes(@[waku0.node.enr.toURI()])
|
||||||
confBuilder.discv5Conf.withEnabled(true)
|
confBuilder.discv5Conf.withEnabled(true)
|
||||||
confBuilder.discv5Conf.withUdpPort(9001.Port)
|
confBuilder.discv5Conf.withUdpPort(9001.Port)
|
||||||
@ -454,7 +454,7 @@ suite "Waku Discovery v5":
|
|||||||
confBuilder.discv5Conf.withBootstrapNodes(@[waku1.node.enr.toURI()])
|
confBuilder.discv5Conf.withBootstrapNodes(@[waku1.node.enr.toURI()])
|
||||||
confBuilder.withP2pTcpPort(60003.Port)
|
confBuilder.withP2pTcpPort(60003.Port)
|
||||||
confBuilder.discv5Conf.withUdpPort(9003.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:
|
let conf2 = confBuilder.build().valueOr:
|
||||||
raiseAssert error
|
raiseAssert error
|
||||||
|
|||||||
@ -446,7 +446,7 @@ proc createEthAccount*(
|
|||||||
let gasPrice = Quantity(await web3.provider.eth_gasPrice())
|
let gasPrice = Quantity(await web3.provider.eth_gasPrice())
|
||||||
web3.defaultAccount = accounts[0]
|
web3.defaultAccount = accounts[0]
|
||||||
|
|
||||||
let pk = keys.PrivateKey.random(rng[])
|
let pk = keys.PrivateKey.random(rng)
|
||||||
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
|
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
|
||||||
|
|
||||||
var tx: TransactionArgs
|
var tx: TransactionArgs
|
||||||
@ -464,7 +464,7 @@ proc createEthAccount*(
|
|||||||
return (pk, acc)
|
return (pk, acc)
|
||||||
|
|
||||||
proc createEthAccount*(web3: Web3): (keys.PrivateKey, Address) =
|
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()))
|
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
|
||||||
|
|
||||||
return (pk, acc)
|
return (pk, acc)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ type TestResponseTuple = tuple[status: int, data: string, headers: HttpTable]
|
|||||||
|
|
||||||
proc testWakuNode(): WakuNode =
|
proc testWakuNode(): WakuNode =
|
||||||
let
|
let
|
||||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet()
|
||||||
bindIp = parseIpAddress("0.0.0.0")
|
bindIp = parseIpAddress("0.0.0.0")
|
||||||
extIp = parseIpAddress("127.0.0.1")
|
extIp = parseIpAddress("127.0.0.1")
|
||||||
port = Port(0)
|
port = Port(0)
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import
|
|||||||
|
|
||||||
proc testWakuNode(): WakuNode =
|
proc testWakuNode(): WakuNode =
|
||||||
let
|
let
|
||||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet()
|
||||||
bindIp = parseIpAddress("0.0.0.0")
|
bindIp = parseIpAddress("0.0.0.0")
|
||||||
extIp = parseIpAddress("127.0.0.1")
|
extIp = parseIpAddress("127.0.0.1")
|
||||||
port = Port(0)
|
port = Port(0)
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import
|
|||||||
|
|
||||||
proc testWakuNode(): WakuNode =
|
proc testWakuNode(): WakuNode =
|
||||||
let
|
let
|
||||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet()
|
||||||
bindIp = parseIpAddress("0.0.0.0")
|
bindIp = parseIpAddress("0.0.0.0")
|
||||||
extIp = parseIpAddress("127.0.0.1")
|
extIp = parseIpAddress("127.0.0.1")
|
||||||
port = Port(0)
|
port = Port(0)
|
||||||
|
|||||||
@ -27,7 +27,7 @@ requires "nim >= 2.2.4",
|
|||||||
"toml_serialization",
|
"toml_serialization",
|
||||||
"faststreams",
|
"faststreams",
|
||||||
# Networking & P2P
|
# Networking & P2P
|
||||||
"https://github.com/vacp2p/nim-libp2p.git#df777fc66cc100191dbefd3c222a4472b4d3b924",
|
"https://github.com/vacp2p/nim-libp2p.git#e41a3ab8ff143fa30e75357f81200545590f0ec6",
|
||||||
"eth",
|
"eth",
|
||||||
"nat_traversal",
|
"nat_traversal",
|
||||||
"dnsdisc",
|
"dnsdisc",
|
||||||
@ -60,6 +60,7 @@ requires "nim >= 2.2.4",
|
|||||||
|
|
||||||
# Packages not on nimble (use git URLs)
|
# Packages not on nimble (use git URLs)
|
||||||
requires "https://github.com/logos-messaging/nim-ffi"
|
requires "https://github.com/logos-messaging/nim-ffi"
|
||||||
|
requires "https://github.com/logos-co/nim-libp2p-mix"
|
||||||
|
|
||||||
requires "https://github.com/logos-messaging/nim-sds.git#2e9a7683f0e180bf112135fae3a3803eed8490d4"
|
requires "https://github.com/logos-messaging/nim-sds.git#2e9a7683f0e180bf112135fae3a3803eed8490d4"
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import bearssl/rand, std/times, chronos
|
import std/times, chronos, libp2p/crypto/crypto
|
||||||
import stew/byteutils
|
import stew/byteutils
|
||||||
import waku/utils/requests as request_utils
|
import waku/utils/requests as request_utils
|
||||||
import waku/waku_core/[topics/content_topic, message/message, time]
|
import waku/waku_core/[topics/content_topic, message/message, time]
|
||||||
@ -19,7 +19,7 @@ type
|
|||||||
PartiallyConnected
|
PartiallyConnected
|
||||||
Connected
|
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.
|
## Generate a new RequestId using the provided RNG.
|
||||||
RequestId(request_utils.generateRequestId(rng))
|
RequestId(request_utils.generateRequestId(rng))
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import
|
import
|
||||||
chronos,
|
chronos,
|
||||||
chronicles,
|
chronicles,
|
||||||
bearssl/rand,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/connectivity/autonat/client,
|
libp2p/protocols/connectivity/autonat/client,
|
||||||
libp2p/protocols/connectivity/autonat/service
|
libp2p/protocols/connectivity/autonat/service
|
||||||
|
|
||||||
const AutonatCheckInterval = Opt.some(chronos.seconds(30))
|
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
|
## AutonatService request other peers to dial us back
|
||||||
## flagging us as Reachable or NotReachable.
|
## flagging us as Reachable or NotReachable.
|
||||||
## minConfidence is used as threshold to determine the state.
|
## minConfidence is used as threshold to determine the state.
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
metrics,
|
metrics,
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
|
libp2p/crypto/crypto,
|
||||||
|
libp2p/crypto/rng,
|
||||||
eth/keys as eth_keys,
|
eth/keys as eth_keys,
|
||||||
eth/p2p/discoveryv5/node,
|
eth/p2p/discoveryv5/node,
|
||||||
eth/p2p/discoveryv5/protocol
|
eth/p2p/discoveryv5/protocol
|
||||||
@ -80,7 +82,7 @@ proc shardingPredicate*(
|
|||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuDiscoveryV5,
|
T: type WakuDiscoveryV5,
|
||||||
rng: ref HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
conf: WakuDiscoveryV5Config,
|
conf: WakuDiscoveryV5Config,
|
||||||
record: Option[waku_enr.Record],
|
record: Option[waku_enr.Record],
|
||||||
peerManager: Option[PeerManager] = none(PeerManager),
|
peerManager: Option[PeerManager] = none(PeerManager),
|
||||||
@ -88,7 +90,7 @@ proc new*(
|
|||||||
newAsyncEventQueue[SubscriptionEvent](30),
|
newAsyncEventQueue[SubscriptionEvent](30),
|
||||||
): T =
|
): T =
|
||||||
let protocol = newProtocol(
|
let protocol = newProtocol(
|
||||||
rng = rng,
|
rng = bearSslDrbgRef(rng),
|
||||||
config = conf.discv5Config.get(protocol.defaultDiscoveryConfig),
|
config = conf.discv5Config.get(protocol.defaultDiscoveryConfig),
|
||||||
bindPort = conf.port,
|
bindPort = conf.port,
|
||||||
bindIp = conf.address,
|
bindIp = conf.address,
|
||||||
@ -405,7 +407,7 @@ proc setupDiscoveryV5*(
|
|||||||
nodeTopicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent],
|
nodeTopicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent],
|
||||||
conf: Discv5Conf,
|
conf: Discv5Conf,
|
||||||
dynamicBootstrapNodes: seq[RemotePeerInfo],
|
dynamicBootstrapNodes: seq[RemotePeerInfo],
|
||||||
rng: ref HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
key: crypto.PrivateKey,
|
key: crypto.PrivateKey,
|
||||||
p2pListenAddress: IpAddress,
|
p2pListenAddress: IpAddress,
|
||||||
portsShift: uint16,
|
portsShift: uint16,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import
|
|||||||
results,
|
results,
|
||||||
libp2p/crypto/curve25519,
|
libp2p/crypto/curve25519,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/mix/mix_protocol,
|
libp2p_mix/mix_protocol,
|
||||||
libp2p/[peerid, multiaddress, switch],
|
libp2p/[peerid, multiaddress, switch],
|
||||||
libp2p/extended_peer_record,
|
libp2p/extended_peer_record,
|
||||||
libp2p/protocols/[kademlia, service_discovery],
|
libp2p/protocols/[kademlia, service_discovery],
|
||||||
@ -174,6 +174,7 @@ proc new*(
|
|||||||
selector = ExtEntrySelector(),
|
selector = ExtEntrySelector(),
|
||||||
disableBootstrapping = disableBootstrapping,
|
disableBootstrapping = disableBootstrapping,
|
||||||
),
|
),
|
||||||
|
rng = switch.rng,
|
||||||
# change from defaults for local testing
|
# change from defaults for local testing
|
||||||
discoConfig =
|
discoConfig =
|
||||||
ServiceDiscoveryConfig.new(advertExpiry = 60.secs, ipSimCoefficient = 0.0),
|
ServiceDiscoveryConfig.new(advertExpiry = 60.secs, ipSimCoefficient = 0.0),
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import
|
|||||||
|
|
||||||
type
|
type
|
||||||
WakuNodeBuilder* = object # General
|
WakuNodeBuilder* = object # General
|
||||||
nodeRng: Option[ref crypto.HmacDrbgContext]
|
nodeRng: Option[crypto.Rng]
|
||||||
nodeKey: Option[crypto.PrivateKey]
|
nodeKey: Option[crypto.PrivateKey]
|
||||||
netConfig: Option[NetConfig]
|
netConfig: Option[NetConfig]
|
||||||
record: Option[enr.Record]
|
record: Option[enr.Record]
|
||||||
@ -57,7 +57,7 @@ proc init*(T: type WakuNodeBuilder): WakuNodeBuilder =
|
|||||||
|
|
||||||
## General
|
## General
|
||||||
|
|
||||||
proc withRng*(builder: var WakuNodeBuilder, rng: ref crypto.HmacDrbgContext) =
|
proc withRng*(builder: var WakuNodeBuilder, rng: crypto.Rng) =
|
||||||
builder.nodeRng = some(rng)
|
builder.nodeRng = some(rng)
|
||||||
|
|
||||||
proc withNodeKey*(builder: var WakuNodeBuilder, nodeKey: crypto.PrivateKey) =
|
proc withNodeKey*(builder: var WakuNodeBuilder, nodeKey: crypto.PrivateKey) =
|
||||||
@ -157,7 +157,7 @@ proc withSwitchConfiguration*(
|
|||||||
## Build
|
## Build
|
||||||
|
|
||||||
proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] =
|
proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] =
|
||||||
var rng: ref crypto.HmacDrbgContext
|
var rng: crypto.Rng
|
||||||
if builder.nodeRng.isNone():
|
if builder.nodeRng.isNone():
|
||||||
rng = crypto.newRng()
|
rng = crypto.newRng()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import chronicles, std/options, results
|
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
|
import ../waku_conf, waku/waku_mix
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
|||||||
@ -287,13 +287,13 @@ proc withStaticNodes*(builder: var WakuConfBuilder, staticNodes: seq[string]) =
|
|||||||
## Building
|
## Building
|
||||||
|
|
||||||
proc nodeKey(
|
proc nodeKey(
|
||||||
builder: WakuConfBuilder, rng: ref HmacDrbgContext
|
builder: WakuConfBuilder, rng: crypto.Rng
|
||||||
): Result[crypto.PrivateKey, string] =
|
): Result[crypto.PrivateKey, string] =
|
||||||
if builder.nodeKey.isSome():
|
if builder.nodeKey.isSome():
|
||||||
return ok(builder.nodeKey.get())
|
return ok(builder.nodeKey.get())
|
||||||
else:
|
else:
|
||||||
warn "missing node key, generating new set"
|
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
|
error "Failed to generate key", error = error
|
||||||
return err("Failed to generate key: " & $error)
|
return err("Failed to generate key: " & $error)
|
||||||
return ok(nodeKey)
|
return ok(nodeKey)
|
||||||
@ -437,7 +437,7 @@ proc applyNetworkConf(builder: var WakuConfBuilder) =
|
|||||||
warn "Failed to process entry nodes from network conf", error = processed.error()
|
warn "Failed to process entry nodes from network conf", error = processed.error()
|
||||||
|
|
||||||
proc build*(
|
proc build*(
|
||||||
builder: var WakuConfBuilder, rng: ref HmacDrbgContext = crypto.newRng()
|
builder: var WakuConfBuilder, rng: crypto.Rng = crypto.newRng()
|
||||||
): Result[WakuConf, string] =
|
): Result[WakuConf, string] =
|
||||||
## Return a WakuConf that contains all mandatory parameters
|
## Return a WakuConf that contains all mandatory parameters
|
||||||
## Applies some sane defaults that are applicable across any usage
|
## Applies some sane defaults that are applicable across any usage
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import
|
|||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/crypto/curve25519,
|
libp2p/crypto/curve25519,
|
||||||
libp2p/extended_peer_record,
|
libp2p/extended_peer_record,
|
||||||
libp2p/protocols/mix/mix_protocol
|
libp2p_mix/mix_protocol
|
||||||
|
|
||||||
import
|
import
|
||||||
./internal_config,
|
./internal_config,
|
||||||
@ -57,7 +57,7 @@ proc setupPeerStorage(): Result[Option[WakuPeerStorage], string] =
|
|||||||
proc initNode(
|
proc initNode(
|
||||||
conf: WakuConf,
|
conf: WakuConf,
|
||||||
netConfig: NetConfig,
|
netConfig: NetConfig,
|
||||||
rng: ref HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
record: enr.Record,
|
record: enr.Record,
|
||||||
peerStore: Option[WakuPeerStorage],
|
peerStore: Option[WakuPeerStorage],
|
||||||
relay: Relay,
|
relay: Relay,
|
||||||
@ -483,7 +483,7 @@ proc startNode*(
|
|||||||
return ok()
|
return ok()
|
||||||
|
|
||||||
proc setupNode*(
|
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.} =
|
): Future[Result[WakuNode, string]] {.async.} =
|
||||||
let netConfig = (
|
let netConfig = (
|
||||||
await networkConfiguration(
|
await networkConfiguration(
|
||||||
|
|||||||
@ -59,7 +59,7 @@ const git_version* {.strdefine.} = "n/a"
|
|||||||
type Waku* = ref object
|
type Waku* = ref object
|
||||||
stateInfo*: WakuStateInfo
|
stateInfo*: WakuStateInfo
|
||||||
conf*: WakuConf
|
conf*: WakuConf
|
||||||
rng*: ref HmacDrbgContext
|
rng*: crypto.Rng
|
||||||
|
|
||||||
key: crypto.PrivateKey
|
key: crypto.PrivateKey
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ type Waku* = ref object
|
|||||||
brokerCtx*: BrokerContext
|
brokerCtx*: BrokerContext
|
||||||
|
|
||||||
proc setupSwitchServices(
|
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: [].} =
|
proc onReservation(addresses: seq[MultiAddress]) {.gcsafe, raises: [].} =
|
||||||
info "circuit relay handler new reserve event",
|
info "circuit relay handler new reserve event",
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import
|
|||||||
libp2p/transports/tcptransport,
|
libp2p/transports/tcptransport,
|
||||||
libp2p/transports/wstransport,
|
libp2p/transports/wstransport,
|
||||||
libp2p/utility,
|
libp2p/utility,
|
||||||
libp2p/protocols/mix
|
libp2p_mix
|
||||||
|
|
||||||
import
|
import
|
||||||
../waku_node,
|
../waku_node,
|
||||||
|
|||||||
@ -7,7 +7,8 @@ import
|
|||||||
eth/p2p/discoveryv5/enr,
|
eth/p2p/discoveryv5/enr,
|
||||||
libp2p/builders,
|
libp2p/builders,
|
||||||
libp2p/peerstore,
|
libp2p/peerstore,
|
||||||
libp2p/crypto/curve25519
|
libp2p/crypto/curve25519,
|
||||||
|
libp2p_mix/pool
|
||||||
|
|
||||||
import
|
import
|
||||||
../../waku_core,
|
../../waku_core,
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import
|
|||||||
results,
|
results,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
nimcrypto,
|
nimcrypto,
|
||||||
bearssl/rand,
|
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
eth/p2p/discoveryv5/enr,
|
eth/p2p/discoveryv5/enr,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
@ -23,8 +22,8 @@ import
|
|||||||
libp2p/transports/wstransport,
|
libp2p/transports/wstransport,
|
||||||
libp2p/utility,
|
libp2p/utility,
|
||||||
libp2p/utils/offsettedseq,
|
libp2p/utils/offsettedseq,
|
||||||
libp2p/protocols/mix,
|
libp2p_mix,
|
||||||
libp2p/protocols/mix/mix_protocol
|
libp2p_mix/mix_protocol
|
||||||
|
|
||||||
import
|
import
|
||||||
waku/[
|
waku/[
|
||||||
@ -126,7 +125,7 @@ type
|
|||||||
wakuAutoSharding*: Option[Sharding]
|
wakuAutoSharding*: Option[Sharding]
|
||||||
enr*: enr.Record
|
enr*: enr.Record
|
||||||
libp2pPing*: Ping
|
libp2pPing*: Ping
|
||||||
rng*: ref rand.HmacDrbgContext
|
rng*: crypto.Rng
|
||||||
brokerCtx*: BrokerContext
|
brokerCtx*: BrokerContext
|
||||||
wakuRendezvous*: WakuRendezVous
|
wakuRendezvous*: WakuRendezVous
|
||||||
wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient
|
wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient
|
||||||
@ -207,7 +206,7 @@ proc new*(
|
|||||||
peerManager: PeerManager,
|
peerManager: PeerManager,
|
||||||
rateLimitSettings: ProtocolRateLimitSettings = DefaultProtocolRateLimit,
|
rateLimitSettings: ProtocolRateLimitSettings = DefaultProtocolRateLimit,
|
||||||
# TODO: make this argument required after tests are updated
|
# 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].} =
|
): T {.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} =
|
||||||
## Creates a Waku Node instance.
|
## Creates a Waku Node instance.
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ proc newWakuSwitch*(
|
|||||||
wsAddress = none(MultiAddress),
|
wsAddress = none(MultiAddress),
|
||||||
secureManagers: openarray[SecureProtocol] = [SecureProtocol.Noise],
|
secureManagers: openarray[SecureProtocol] = [SecureProtocol.Noise],
|
||||||
transportFlags: set[ServerFlags] = {},
|
transportFlags: set[ServerFlags] = {},
|
||||||
rng: ref HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
inTimeout: Duration = 5.minutes,
|
inTimeout: Duration = 5.minutes,
|
||||||
outTimeout: Duration = 5.minutes,
|
outTimeout: Duration = 5.minutes,
|
||||||
maxConnections = MaxConnections,
|
maxConnections = MaxConnections,
|
||||||
@ -78,7 +78,7 @@ proc newWakuSwitch*(
|
|||||||
secureCertPath: string = "",
|
secureCertPath: string = "",
|
||||||
agentString = none(string), # defaults to nim-libp2p version
|
agentString = none(string), # defaults to nim-libp2p version
|
||||||
peerStoreCapacity = none(int), # defaults to 1.25 maxConnections
|
peerStoreCapacity = none(int), # defaults to 1.25 maxConnections
|
||||||
rendezvous: RendezVous = nil,
|
rendezvous: RendezVousConfig = nil,
|
||||||
circuitRelay: Relay,
|
circuitRelay: Relay,
|
||||||
maxNumRelays: int = 5,
|
maxNumRelays: int = 5,
|
||||||
): Switch {.raises: [Defect, IOError, LPError].} =
|
): Switch {.raises: [Defect, IOError, LPError].} =
|
||||||
|
|||||||
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
{.push raises: [].}
|
{.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]
|
var bytes: array[10, byte]
|
||||||
hmacDrbgGenerate(rng[], bytes)
|
rng.generate(bytes)
|
||||||
return byteutils.toHex(bytes)
|
return byteutils.toHex(bytes)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
import
|
import
|
||||||
std/[options, bitops, sequtils, net, tables], results, eth/keys, libp2p/crypto/crypto
|
std/[options, bitops, sequtils, net, tables], results, eth/keys, libp2p/crypto/crypto
|
||||||
import ../common/enr, ../waku_core/codecs
|
import ../common/enr, ../waku_core/codecs
|
||||||
import libp2p/protocols/mix
|
import libp2p_mix
|
||||||
|
|
||||||
const CapabilitiesEnrField* = "waku2"
|
const CapabilitiesEnrField* = "waku2"
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
libp2p/protocols/protocol,
|
libp2p/protocols/protocol,
|
||||||
bearssl/rand,
|
libp2p/crypto/crypto,
|
||||||
stew/byteutils
|
stew/byteutils
|
||||||
import
|
import
|
||||||
waku/
|
waku/
|
||||||
@ -22,13 +22,13 @@ logScope:
|
|||||||
|
|
||||||
type WakuFilterClient* = ref object of LPProtocol
|
type WakuFilterClient* = ref object of LPProtocol
|
||||||
brokerCtx: BrokerContext
|
brokerCtx: BrokerContext
|
||||||
rng: ref HmacDrbgContext
|
rng: Rng
|
||||||
peerManager: PeerManager
|
peerManager: PeerManager
|
||||||
pushHandlers: seq[FilterPushHandler]
|
pushHandlers: seq[FilterPushHandler]
|
||||||
|
|
||||||
func generateRequestId(rng: ref HmacDrbgContext): string =
|
func generateRequestId(rng: crypto.Rng): string =
|
||||||
var bytes: array[10, byte]
|
var bytes: array[10, byte]
|
||||||
hmacDrbgGenerate(rng[], bytes)
|
rng.generate(bytes)
|
||||||
return byteutils.toHex(bytes)
|
return byteutils.toHex(bytes)
|
||||||
|
|
||||||
proc sendSubscribeRequest(
|
proc sendSubscribeRequest(
|
||||||
@ -210,7 +210,7 @@ proc initProtocolHandler(wfc: WakuFilterClient) =
|
|||||||
wfc.codec = WakuFilterPushCodec
|
wfc.codec = WakuFilterPushCodec
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuFilterClient, peerManager: PeerManager, rng: ref HmacDrbgContext
|
T: type WakuFilterClient, peerManager: PeerManager, rng: crypto.Rng
|
||||||
): T =
|
): T =
|
||||||
let brokerCtx = globalBrokerContext()
|
let brokerCtx = globalBrokerContext()
|
||||||
let wfc = WakuFilterClient(
|
let wfc = WakuFilterClient(
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{.push raises: [].}
|
{.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 libp2p/peerid, libp2p/stream/connection
|
||||||
import
|
import
|
||||||
../waku_core/peers,
|
../waku_core/peers,
|
||||||
@ -16,11 +16,11 @@ logScope:
|
|||||||
topics = "waku lightpush client"
|
topics = "waku lightpush client"
|
||||||
|
|
||||||
type WakuLightPushClient* = ref object
|
type WakuLightPushClient* = ref object
|
||||||
rng*: ref rand.HmacDrbgContext
|
rng*: Rng
|
||||||
peerManager*: PeerManager
|
peerManager*: PeerManager
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuLightPushClient, peerManager: PeerManager, rng: ref rand.HmacDrbgContext
|
T: type WakuLightPushClient, peerManager: PeerManager, rng: crypto.Rng
|
||||||
): T =
|
): T =
|
||||||
WakuLightPushClient(peerManager: peerManager, rng: rng)
|
WakuLightPushClient(peerManager: peerManager, rng: rng)
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
metrics,
|
metrics,
|
||||||
bearssl/rand
|
libp2p/crypto/crypto
|
||||||
import
|
import
|
||||||
../node/peer_manager/peer_manager,
|
../node/peer_manager/peer_manager,
|
||||||
../waku_core,
|
../waku_core,
|
||||||
@ -22,7 +22,7 @@ logScope:
|
|||||||
topics = "waku lightpush"
|
topics = "waku lightpush"
|
||||||
|
|
||||||
type WakuLightPush* = ref object of LPProtocol
|
type WakuLightPush* = ref object of LPProtocol
|
||||||
rng*: ref rand.HmacDrbgContext
|
rng*: Rng
|
||||||
peerManager*: PeerManager
|
peerManager*: PeerManager
|
||||||
pushHandler*: PushMessageHandler
|
pushHandler*: PushMessageHandler
|
||||||
requestRateLimiter*: RequestRateLimiter
|
requestRateLimiter*: RequestRateLimiter
|
||||||
@ -156,7 +156,7 @@ proc initProtocolHandler(wl: WakuLightPush) =
|
|||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuLightPush,
|
T: type WakuLightPush,
|
||||||
peerManager: PeerManager,
|
peerManager: PeerManager,
|
||||||
rng: ref rand.HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
pushHandler: PushMessageHandler,
|
pushHandler: PushMessageHandler,
|
||||||
autoSharding: Option[Sharding],
|
autoSharding: Option[Sharding],
|
||||||
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
|
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{.push raises: [].}
|
{.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 libp2p/peerid
|
||||||
import
|
import
|
||||||
../waku_core/peers,
|
../waku_core/peers,
|
||||||
@ -17,12 +17,12 @@ logScope:
|
|||||||
|
|
||||||
type WakuLegacyLightPushClient* = ref object
|
type WakuLegacyLightPushClient* = ref object
|
||||||
peerManager*: PeerManager
|
peerManager*: PeerManager
|
||||||
rng*: ref rand.HmacDrbgContext
|
rng*: Rng
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuLegacyLightPushClient,
|
T: type WakuLegacyLightPushClient,
|
||||||
peerManager: PeerManager,
|
peerManager: PeerManager,
|
||||||
rng: ref rand.HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
): T =
|
): T =
|
||||||
WakuLegacyLightPushClient(peerManager: peerManager, rng: rng)
|
WakuLegacyLightPushClient(peerManager: peerManager, rng: rng)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{.push raises: [].}
|
{.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
|
import
|
||||||
../node/peer_manager/peer_manager,
|
../node/peer_manager/peer_manager,
|
||||||
../waku_core,
|
../waku_core,
|
||||||
@ -14,7 +14,7 @@ logScope:
|
|||||||
topics = "waku lightpush legacy"
|
topics = "waku lightpush legacy"
|
||||||
|
|
||||||
type WakuLegacyLightPush* = ref object of LPProtocol
|
type WakuLegacyLightPush* = ref object of LPProtocol
|
||||||
rng*: ref rand.HmacDrbgContext
|
rng*: Rng
|
||||||
peerManager*: PeerManager
|
peerManager*: PeerManager
|
||||||
pushHandler*: PushMessageHandler
|
pushHandler*: PushMessageHandler
|
||||||
requestRateLimiter*: RequestRateLimiter
|
requestRateLimiter*: RequestRateLimiter
|
||||||
@ -116,7 +116,7 @@ proc initProtocolHandler(wl: WakuLegacyLightPush) =
|
|||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuLegacyLightPush,
|
T: type WakuLegacyLightPush,
|
||||||
peerManager: PeerManager,
|
peerManager: PeerManager,
|
||||||
rng: ref rand.HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
pushHandler: PushMessageHandler,
|
pushHandler: PushMessageHandler,
|
||||||
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
|
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
|
||||||
): T =
|
): T =
|
||||||
|
|||||||
@ -5,12 +5,12 @@ import chronicles, std/options, chronos, results, metrics
|
|||||||
import
|
import
|
||||||
libp2p/crypto/curve25519,
|
libp2p/crypto/curve25519,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/mix,
|
libp2p_mix,
|
||||||
libp2p/protocols/mix/mix_node,
|
libp2p_mix/mix_node,
|
||||||
libp2p/protocols/mix/mix_protocol,
|
libp2p_mix/mix_protocol,
|
||||||
libp2p/protocols/mix/mix_metrics,
|
libp2p_mix/mix_metrics,
|
||||||
libp2p/protocols/mix/delay_strategy,
|
libp2p_mix/delay_strategy,
|
||||||
libp2p/protocols/mix/delay,
|
libp2p_mix/delay,
|
||||||
libp2p/[multiaddress, peerid, switch],
|
libp2p/[multiaddress, peerid, switch],
|
||||||
libp2p/extended_peer_record,
|
libp2p/extended_peer_record,
|
||||||
eth/common/keys
|
eth/common/keys
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import std/[options, strutils]
|
|||||||
import stew/byteutils
|
import stew/byteutils
|
||||||
import chronos
|
import chronos
|
||||||
import chronicles
|
import chronicles
|
||||||
import bearssl/rand
|
import libp2p/crypto/crypto
|
||||||
import stew/endians2
|
import stew/endians2
|
||||||
import nimcrypto/[sha2, hmac]
|
import nimcrypto/[sha2, hmac]
|
||||||
|
|
||||||
@ -168,9 +168,9 @@ proc setCipherStateKey*(cs: var CipherState, key: ChaChaPolyKey) =
|
|||||||
cs.k = key
|
cs.k = key
|
||||||
|
|
||||||
# Generates a random Symmetric Cipher State for test purposes
|
# 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
|
var randomCipherState: CipherState
|
||||||
hmacDrbgGenerate(rng, randomCipherState.k)
|
rng.generate(randomCipherState.k)
|
||||||
setNonce(randomCipherState, nonce)
|
setNonce(randomCipherState, nonce)
|
||||||
return randomCipherState
|
return randomCipherState
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
import std/[options, strutils, tables]
|
import std/[options, strutils, tables]
|
||||||
import chronos
|
import chronos
|
||||||
import chronicles
|
import chronicles
|
||||||
import bearssl/rand
|
import libp2p/crypto/crypto
|
||||||
import results
|
import results
|
||||||
|
|
||||||
import libp2p/crypto/[chacha20poly1305, curve25519]
|
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
|
# We process an input handshake message according to current handshake state and we return the next handshake step's handshake message
|
||||||
proc processMessagePatternTokens(
|
proc processMessagePatternTokens(
|
||||||
rng: var rand.HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
hs: var HandshakeState,
|
hs: var HandshakeState,
|
||||||
inputHandshakeMessage: seq[NoisePublicKey] = @[],
|
inputHandshakeMessage: seq[NoisePublicKey] = @[],
|
||||||
): Result[seq[NoisePublicKey], cstring] {.
|
): 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
|
# 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)
|
# 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*(
|
proc stepHandshake*(
|
||||||
rng: var rand.HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
hs: var HandshakeState,
|
hs: var HandshakeState,
|
||||||
readPayloadV2: PayloadV2 = default(PayloadV2),
|
readPayloadV2: PayloadV2 = default(PayloadV2),
|
||||||
transportMessage: seq[byte] = @[],
|
transportMessage: seq[byte] = @[],
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
import std/[algorithm, base64, oids, options, strutils, tables, sequtils]
|
import std/[algorithm, base64, oids, options, strutils, tables, sequtils]
|
||||||
import chronos
|
import chronos
|
||||||
import chronicles
|
import chronicles
|
||||||
import bearssl/rand
|
import libp2p/crypto/crypto
|
||||||
import results
|
import results
|
||||||
import stew/[endians2, byteutils]
|
import stew/[endians2, byteutils]
|
||||||
import nimcrypto/sha2
|
import nimcrypto/sha2
|
||||||
@ -28,9 +28,9 @@ logScope:
|
|||||||
#################################
|
#################################
|
||||||
|
|
||||||
# Generates random byte sequences of given size
|
# 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)
|
var output = newSeq[byte](size.uint32)
|
||||||
hmacDrbgGenerate(rng, output)
|
rng.generate(output)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
# Pads a payload according to PKCS#7 as per RFC 5652 https://datatracker.ietf.org/doc/html/rfc5652#section-6.3
|
# 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
|
# Generate random (public, private) Elliptic Curve key pairs
|
||||||
proc genKeyPair*(rng: var HmacDrbgContext): KeyPair =
|
proc genKeyPair*(rng: crypto.Rng): KeyPair =
|
||||||
var keyPair: KeyPair
|
var keyPair: KeyPair
|
||||||
keyPair.privateKey = EllipticCurveKey.random(rng)
|
keyPair.privateKey = EllipticCurveKey.random(rng)
|
||||||
keyPair.publicKey = keyPair.privateKey.public()
|
keyPair.publicKey = keyPair.privateKey.public()
|
||||||
@ -319,18 +319,18 @@ proc dh*(private: EllipticCurveKey, public: EllipticCurveKey): EllipticCurveKey
|
|||||||
#################################
|
#################################
|
||||||
|
|
||||||
# Generates a random ChaChaPolyKey for testing encryption/decryption
|
# Generates a random ChaChaPolyKey for testing encryption/decryption
|
||||||
proc randomChaChaPolyKey*(rng: var HmacDrbgContext): ChaChaPolyKey =
|
proc randomChaChaPolyKey*(rng: crypto.Rng): ChaChaPolyKey =
|
||||||
var key: ChaChaPolyKey
|
var key: ChaChaPolyKey
|
||||||
hmacDrbgGenerate(rng, key)
|
rng.generate(key)
|
||||||
return key
|
return key
|
||||||
|
|
||||||
# Generates a random ChaChaPoly Cipher State for testing encryption/decryption
|
# 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
|
var randomCipherState: ChaChaPolyCipherState
|
||||||
randomCipherState.k = randomChaChaPolyKey(rng)
|
randomCipherState.k = randomChaChaPolyKey(rng)
|
||||||
hmacDrbgGenerate(rng, randomCipherState.nonce)
|
rng.generate(randomCipherState.nonce)
|
||||||
randomCipherState.ad = newSeq[byte](32)
|
randomCipherState.ad = newSeq[byte](32)
|
||||||
hmacDrbgGenerate(rng, randomCipherState.ad)
|
rng.generate(randomCipherState.ad)
|
||||||
return randomCipherState
|
return randomCipherState
|
||||||
|
|
||||||
#################################################################
|
#################################################################
|
||||||
@ -351,7 +351,7 @@ proc toNoisePublicKey*(publicKey: EllipticCurveKey): NoisePublicKey =
|
|||||||
return noisePublicKey
|
return noisePublicKey
|
||||||
|
|
||||||
# Generates a random Noise public key
|
# Generates a random Noise public key
|
||||||
proc genNoisePublicKey*(rng: var HmacDrbgContext): NoisePublicKey =
|
proc genNoisePublicKey*(rng: crypto.Rng): NoisePublicKey =
|
||||||
var noisePublicKey: NoisePublicKey
|
var noisePublicKey: NoisePublicKey
|
||||||
# We generate a random key pair
|
# We generate a random key pair
|
||||||
let keyPair: KeyPair = genKeyPair(rng)
|
let keyPair: KeyPair = genKeyPair(rng)
|
||||||
@ -446,7 +446,7 @@ proc `==`*(p1, p2: PayloadV2): bool =
|
|||||||
(p1.transportMessage == p2.transportMessage)
|
(p1.transportMessage == p2.transportMessage)
|
||||||
|
|
||||||
# Generates a random PayloadV2
|
# Generates a random PayloadV2
|
||||||
proc randomPayloadV2*(rng: var HmacDrbgContext): PayloadV2 =
|
proc randomPayloadV2*(rng: crypto.Rng): PayloadV2 =
|
||||||
var payload2: PayloadV2
|
var payload2: PayloadV2
|
||||||
# We set a random messageNametag
|
# We set a random messageNametag
|
||||||
let randMessageNametag = randomSeqByte(rng, MessageNametagLength)
|
let randMessageNametag = randomSeqByte(rng, MessageNametagLength)
|
||||||
|
|||||||
@ -366,7 +366,8 @@ proc new*(
|
|||||||
triggerSelf = true,
|
triggerSelf = true,
|
||||||
msgIdProvider = defaultMessageIdProvider,
|
msgIdProvider = defaultMessageIdProvider,
|
||||||
maxMessageSize = maxMessageSize,
|
maxMessageSize = maxMessageSize,
|
||||||
parameters = GossipsubParameters,
|
rng = switch.rng,
|
||||||
|
parameters = GossipSubParams.init(),
|
||||||
)
|
)
|
||||||
w.brokerCtx = globalBrokerContext()
|
w.brokerCtx = globalBrokerContext()
|
||||||
|
|
||||||
|
|||||||
@ -106,10 +106,10 @@ proc new*(
|
|||||||
switch: switch,
|
switch: switch,
|
||||||
rng: rng,
|
rng: rng,
|
||||||
sema: newAsyncSemaphore(MaxSimultanesousAdvertisements),
|
sema: newAsyncSemaphore(MaxSimultanesousAdvertisements),
|
||||||
minDuration: rendezvous.MinimumAcceptedDuration,
|
config: RendezVousConfig.new(
|
||||||
maxDuration: rendezvous.MaximumDuration,
|
minDuration = rendezvous.MinimumDuration,
|
||||||
minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64,
|
maxDuration = rendezvous.MaximumDuration,
|
||||||
maxTTL: rendezvous.MaximumDuration.seconds.uint64,
|
),
|
||||||
peers: @[], # Will be populated from selectPeer calls
|
peers: @[], # Will be populated from selectPeer calls
|
||||||
cookiesSaved: initTable[PeerId, Table[string, seq[byte]]](),
|
cookiesSaved: initTable[PeerId, Table[string, seq[byte]]](),
|
||||||
peerRecordValidator: checkWakuPeerRecord,
|
peerRecordValidator: checkWakuPeerRecord,
|
||||||
|
|||||||
@ -50,7 +50,7 @@ proc advertise*(
|
|||||||
self: WakuRendezVous,
|
self: WakuRendezVous,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
peers: seq[PeerId],
|
peers: seq[PeerId],
|
||||||
ttl: timer.Duration = self.minDuration,
|
ttl: timer.Duration = rendezvous.MinimumDuration,
|
||||||
): Future[Result[void, string]] {.async: (raises: []).} =
|
): Future[Result[void, string]] {.async: (raises: []).} =
|
||||||
trace "advertising via waku rendezvous",
|
trace "advertising via waku rendezvous",
|
||||||
namespace = namespace, ttl = ttl, peers = $peers, peerRecord = $self.getPeerRecord()
|
namespace = namespace, ttl = ttl, peers = $peers, peerRecord = $self.getPeerRecord()
|
||||||
@ -153,14 +153,14 @@ proc new*(
|
|||||||
let rng = newRng()
|
let rng = newRng()
|
||||||
let wrv = T(
|
let wrv = T(
|
||||||
rng: rng,
|
rng: rng,
|
||||||
salt: string.fromBytes(generateBytes(rng[], 8)),
|
salt: string.fromBytes(generateBytes(rng, 8)),
|
||||||
registered: initOffsettedSeq[RegisteredData](),
|
registered: initOffsettedSeq[RegisteredData](),
|
||||||
expiredDT: Moment.now() - 1.days,
|
expiredDT: Moment.now() - 1.days,
|
||||||
sema: newAsyncSemaphore(SemaphoreDefaultSize),
|
sema: newAsyncSemaphore(SemaphoreDefaultSize),
|
||||||
minDuration: rendezvous.MinimumAcceptedDuration,
|
config: RendezVousConfig.new(
|
||||||
maxDuration: rendezvous.MaximumDuration,
|
minDuration = rendezvous.MinimumDuration,
|
||||||
minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64,
|
maxDuration = rendezvous.MaximumDuration,
|
||||||
maxTTL: rendezvous.MaximumDuration.seconds.uint64,
|
),
|
||||||
peerRecordValidator: checkWakuPeerRecord,
|
peerRecordValidator: checkWakuPeerRecord,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
metrics,
|
metrics,
|
||||||
bearssl/rand
|
libp2p/crypto/crypto
|
||||||
import
|
import
|
||||||
../node/peer_manager, ../utils/requests, ./protocol_metrics, ./common, ./rpc_codec
|
../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
|
type WakuStoreClient* = ref object
|
||||||
peerManager: PeerManager
|
peerManager: PeerManager
|
||||||
rng: ref rand.HmacDrbgContext
|
rng: Rng
|
||||||
storeMsgMetricsPerShard*: Table[string, float64]
|
storeMsgMetricsPerShard*: Table[string, float64]
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuStoreClient, peerManager: PeerManager, rng: ref rand.HmacDrbgContext
|
T: type WakuStoreClient, peerManager: PeerManager, rng: crypto.Rng
|
||||||
): T {.gcsafe.} =
|
): T {.gcsafe.} =
|
||||||
WakuStoreClient(peerManager: peerManager, rng: rng)
|
WakuStoreClient(peerManager: peerManager, rng: rng)
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import
|
|||||||
results,
|
results,
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
bearssl/rand,
|
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/protocol,
|
libp2p/protocols/protocol,
|
||||||
libp2p/protobuf/minprotobuf,
|
libp2p/protobuf/minprotobuf,
|
||||||
@ -30,7 +29,7 @@ type StoreQueryRequestHandler* =
|
|||||||
|
|
||||||
type WakuStore* = ref object of LPProtocol
|
type WakuStore* = ref object of LPProtocol
|
||||||
peerManager: PeerManager
|
peerManager: PeerManager
|
||||||
rng: ref rand.HmacDrbgContext
|
rng: Rng
|
||||||
requestHandler*: StoreQueryRequestHandler
|
requestHandler*: StoreQueryRequestHandler
|
||||||
requestRateLimiter*: RequestRateLimiter
|
requestRateLimiter*: RequestRateLimiter
|
||||||
|
|
||||||
@ -154,7 +153,7 @@ proc initProtocolHandler(self: WakuStore) =
|
|||||||
proc new*(
|
proc new*(
|
||||||
T: type WakuStore,
|
T: type WakuStore,
|
||||||
peerManager: PeerManager,
|
peerManager: PeerManager,
|
||||||
rng: ref rand.HmacDrbgContext,
|
rng: crypto.Rng,
|
||||||
requestHandler: StoreQueryRequestHandler,
|
requestHandler: StoreQueryRequestHandler,
|
||||||
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
|
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
|
||||||
): T =
|
): T =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user