Skip to content

Commit 222792a

Browse files
committed
add mix pubkey in enr and fix lightpush rebase issues
1 parent 2b36dc7 commit 222792a

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

waku/factory/internal_config.nim

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import
1111
../common/utils/nat,
1212
../node/config,
1313
../waku_enr/capabilities,
14+
../waku_enr/mix,
1415
../waku_enr,
1516
../waku_core
1617

@@ -33,6 +34,9 @@ proc enrConfiguration*(
3334
).isOkOr:
3435
return err("could not initialize ENR with shards")
3536

37+
if conf.mix and conf.mixKey.isSome():
38+
enrBuilder.withMixKey(conf.mixKey.get())
39+
3640
let recordRes = enrBuilder.build()
3741
let record =
3842
if recordRes.isErr():

waku/waku_enr/mix.nim

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{.push raises: [].}
2+
3+
import
4+
std/[options],
5+
results,
6+
libp2p/crypto/curve25519,
7+
nimcrypto/utils as ncrutils
8+
9+
import ../common/enr
10+
11+
const MixKeyEnrField* = "mix-key"
12+
13+
func withMixKey*(builder: var EnrBuilder, mixPrivKey:string) =
14+
let mixKey = intoCurve25519Key(ncrutils.fromHex(mixPrivKey))
15+
let mixPubKey = public(mixKey)
16+
builder.addFieldPair(MixKeyEnrField, getBytes(mixPubKey))
17+
18+
func mixKey*(record: TypedRecord): Option[seq[byte]] =
19+
let field = record.tryGet(MixKeyEnrField, seq[byte])
20+
if field.isNone():
21+
return none(seq[byte])
22+
return field

waku/waku_lightpush/client.nim

+8-4
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,19 @@ proc publishToAny*(
114114

115115
proc publishWithConn*(
116116
wl: WakuLightPushClient, pubSubTopic: PubsubTopic, message: WakuMessage, conn: Connection
117-
): Future[WakuLightPushResult[void]] {.async, gcsafe.} =
117+
): Future[WakuLightPushResult] {.async, gcsafe.} =
118118
## This proc is similar to the publish one but in this case
119119
## we use existing connection to publish.
120120

121121
info "publishWithConn", msg_hash = computeMessageHash(pubsubTopic, message).to0xHex
122122

123-
let pushRequest = PushRequest(pubSubTopic: pubSubTopic, message: message)
124-
let rpc = PushRPC(requestId: generateRequestId(wl.rng), request: some(pushRequest))
125-
await conn.writeLP(rpc.encode().buffer)
123+
let pushRequest = LightpushRequest(
124+
requestId: generateRequestId(wl.rng),
125+
pubSubTopic: some(pubSubTopic),
126+
message: message,
127+
)
128+
129+
await conn.writeLP(pushRequest.encode().buffer)
126130

127131
for obs in wl.publishObservers:
128132
obs.onMessagePublished(pubSubTopic, message)

0 commit comments

Comments
 (0)