mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-06 14:10:02 +00:00
nimble.lock: Stale lockfile (inherited from master at rebase time) pinned libp2p to ff8d51857, jwt to 18f8378de, json_rpc to status-im 43bbf499, etc. — all incompatible with this PR's waku.nimble pin set, and nimble's vnext SAT solver was falling back to the global packages.json registry (which still maps `jwt` → yglukhov/nim-jwt) when the lockfile/active-pin conflict couldn't be reconciled. That registry lookup tried to clone yglukhov/nim-jwt at SHA 057ec95… which only exists on the vacp2p fork, so the build aborted. Regenerated via `nimble lock`. Resulting pins now reflect what waku.nimble + libp2p v2.0.0 actually require: libp2p c43199378, jwt 057ec95, websock 387a8eb7, json_rpc f05fad25 (chaitanyaprem fork), lsquic 3813b849, libp2p_mix 50c4ab4f, mix_rln_spam_protection 23b278b4. Hand-fixed one nimble vnext bug: mix_rln_spam_protection's `vcsRevision` was generated as the local logos-delivery HEAD SHA instead of the plugin's HEAD; replaced with 23b278b4… (matches `version` field's URL+SHA spec and the cached package). tests/testlib/wakucore.nim: libp2p v2.0.0 also exports a `rng` symbol (the new `Rng` wrapper type), making the unqualified `rng[]` calls here ambiguous against the local `common.rng` template (returns `ref HmacDrbgContext`). Qualify the three call sites as `common.rng()[]` so we keep the `ref HmacDrbgContext` value that `libp2p_keys.PrivateKey.random` / `KeyPair.random` expect.
81 lines
2.1 KiB
Nim
81 lines
2.1 KiB
Nim
import
|
|
std/[options, times],
|
|
results,
|
|
stew/byteutils,
|
|
chronos,
|
|
libp2p/switch,
|
|
libp2p/builders,
|
|
libp2p/crypto/crypto as libp2p_keys,
|
|
eth/keys as eth_keys
|
|
import waku/waku_core, ./common
|
|
|
|
export switch
|
|
|
|
# Time
|
|
|
|
proc now*(): Timestamp =
|
|
getNanosecondTime(getTime().toUnixFloat())
|
|
|
|
proc ts*(offset = 0, origin = now()): Timestamp =
|
|
origin + getNanosecondTime(int64(offset))
|
|
|
|
# Switch
|
|
|
|
proc generateEcdsaKey*(): libp2p_keys.PrivateKey =
|
|
# libp2p v2.0.0 also exports a `rng` symbol (returns the new `Rng` wrapper),
|
|
# so the unqualified `rng[]` here is ambiguous against our local
|
|
# `common.rng` template. Qualify explicitly to keep using the
|
|
# `ref HmacDrbgContext` that `PrivateKey.random` expects.
|
|
libp2p_keys.PrivateKey.random(ECDSA, common.rng()[]).get()
|
|
|
|
proc generateEcdsaKeyPair*(): libp2p_keys.KeyPair =
|
|
libp2p_keys.KeyPair.random(ECDSA, common.rng()[]).get()
|
|
|
|
proc generateSecp256k1Key*(): libp2p_keys.PrivateKey =
|
|
libp2p_keys.PrivateKey.random(Secp256k1, common.rng()[]).get()
|
|
|
|
proc ethSecp256k1Key*(hex: string): eth_keys.PrivateKey =
|
|
eth_keys.PrivateKey.fromHex(hex).get()
|
|
|
|
proc newTestSwitch*(
|
|
key = none(libp2p_keys.PrivateKey), address = none(MultiAddress)
|
|
): Switch =
|
|
let peerKey = key.get(generateSecp256k1Key())
|
|
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
|
|
return newStandardSwitch(privKey = Opt.some(peerKey), addrs = peerAddr)
|
|
|
|
# Waku message
|
|
|
|
export waku_core.DefaultPubsubTopic, waku_core.DefaultContentTopic
|
|
|
|
proc fakeWakuMessage*(
|
|
payload: string | seq[byte] = "TEST-PAYLOAD",
|
|
contentTopic = DefaultContentTopic,
|
|
meta: string | seq[byte] = newSeq[byte](),
|
|
ts = now(),
|
|
ephemeral = false,
|
|
proof = newSeq[byte](),
|
|
): WakuMessage =
|
|
var payloadBytes: seq[byte]
|
|
var metaBytes: seq[byte]
|
|
|
|
when payload is string:
|
|
payloadBytes = toBytes(payload)
|
|
else:
|
|
payloadBytes = payload
|
|
|
|
when meta is string:
|
|
metaBytes = toBytes(meta)
|
|
else:
|
|
metaBytes = meta
|
|
|
|
WakuMessage(
|
|
payload: payloadBytes,
|
|
contentTopic: contentTopic,
|
|
meta: metaBytes,
|
|
version: 2,
|
|
timestamp: ts,
|
|
ephemeral: ephemeral,
|
|
proof: proof,
|
|
)
|