mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-05 21:49:31 +00:00
* bump libp2p pin to release/v2.0.0 (c43199378) * pin nimble.lock: lsquic/websock/boringssl/protobuf_serialization/npeg/jwt * add libp2p_mix dep and point libp2p/protocols/mix -> libp2p_mix * migrate rng to libp2p Rng type (prod, channels, noise, tests) * noise: take Rng, extract bearSslDrbg internally * waku_switch: TransportConfig factory; withMaxInOut; local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery) * tests: newStandardSwitch shim; PeerId.random(rng); common.rng()/crypto.newRng() * drop libp2p/utils/semaphore (use chronos AsyncSemaphore) * add waku/compat/option_valueor shim where needed * add std/options where transitive re-export dropped
38 lines
1.5 KiB
Nim
38 lines
1.5 KiB
Nim
import waku/compat/option_valueor
|
|
{.push raises: [].}
|
|
|
|
import results
|
|
import ../waku_core, ../waku_noise/noise_types, ../waku_noise/noise_utils
|
|
|
|
# Decodes a WakuMessage to a PayloadV2
|
|
# Currently, this is just a wrapper over deserializePayloadV2 and encryption/decryption is done on top (no KeyInfo)
|
|
proc decodePayloadV2*(
|
|
message: WakuMessage
|
|
): Result[PayloadV2, cstring] {.raises: [NoiseMalformedHandshake, NoisePublicKeyError].} =
|
|
# We check message version (only 2 is supported in this proc)
|
|
case message.version
|
|
of 2:
|
|
# We attempt to decode the WakuMessage payload
|
|
let deserializedPayload2 = deserializePayloadV2(message.payload).valueOr:
|
|
return err("Failed to decode WakuMessage")
|
|
return ok(deserializedPayload2)
|
|
else:
|
|
return err("Wrong message version while decoding payload")
|
|
|
|
# Encodes a PayloadV2 to a WakuMessage
|
|
# Currently, this is just a wrapper over serializePayloadV2 and encryption/decryption is done on top (no KeyInfo)
|
|
proc encodePayloadV2*(
|
|
payload2: PayloadV2, contentTopic: ContentTopic = default(ContentTopic)
|
|
): Result[WakuMessage, cstring] {.
|
|
raises: [NoiseMalformedHandshake, NoisePublicKeyError]
|
|
.} =
|
|
# We attempt to encode the PayloadV2
|
|
let serializedPayload2 = serializePayloadV2(payload2).valueOr:
|
|
return err("Failed to encode PayloadV2")
|
|
|
|
# If successful, we create and return a WakuMessage
|
|
let msg =
|
|
WakuMessage(payload: serializedPayload2, version: 2, contentTopic: contentTopic)
|
|
|
|
return ok(msg)
|