@@ -9,13 +9,15 @@ import {
9
9
AutoSharding ,
10
10
DEFAULT_CLUSTER_ID ,
11
11
DEFAULT_NUM_SHARDS ,
12
+ IMessage ,
12
13
ShardId ,
13
14
StaticSharding ,
14
15
} from "@waku/interfaces" ;
15
16
import { bootstrap } from "@libp2p/bootstrap" ;
16
17
import { EnrDecoder , TransportProtocol } from "@waku/enr" ;
17
18
import type { ITestBrowser } from "../types/global.js" ;
18
19
import { StaticShardingRoutingInfo } from "@waku/utils" ;
20
+ import { messageHashStr } from "@waku/core" ;
19
21
20
22
export interface SerializableSDKProtocolResult {
21
23
successes : string [ ] ;
@@ -24,6 +26,7 @@ export interface SerializableSDKProtocolResult {
24
26
peerId ?: string ;
25
27
} > ;
26
28
myPeerId ?: string ;
29
+ messageHash ?: string ;
27
30
}
28
31
29
32
function makeSerializable ( result : any ) : SerializableSDKProtocolResult {
@@ -173,6 +176,11 @@ export class WakuHeadless {
173
176
processedPayload = new TextEncoder ( ) . encode ( payload ) ;
174
177
}
175
178
179
+ const message : IMessage = {
180
+ payload : processedPayload ,
181
+ timestamp : new Date ( ) ,
182
+ } ;
183
+
176
184
try {
177
185
const lightPush = this . waku . lightPush ;
178
186
if ( ! lightPush ) {
@@ -197,6 +205,11 @@ export class WakuHeadless {
197
205
console . log ( "Pubsub topic:" , pubsubTopic ) ;
198
206
console . log ( "Encoder pubsub topic:" , encoder . pubsubTopic ) ;
199
207
208
+ const protoObj = await encoder . toProtoObj ( message ) ;
209
+ if ( ! protoObj ) {
210
+ throw new Error ( "Failed to convert message to proto object" ) ;
211
+ }
212
+
200
213
if ( pubsubTopic && pubsubTopic !== encoder . pubsubTopic ) {
201
214
console . warn (
202
215
`Explicit pubsubTopic ${ pubsubTopic } provided, but auto-sharding determined ${ encoder . pubsubTopic } . Using auto-sharding.` ,
@@ -210,10 +223,7 @@ export class WakuHeadless {
210
223
this . lightpushNode ,
211
224
) ;
212
225
if ( preferredPeerId ) {
213
- result = await lightPush . send ( encoder , {
214
- payload : processedPayload ,
215
- timestamp : new Date ( ) ,
216
- } ) ;
226
+ result = await lightPush . send ( encoder , message ) ;
217
227
console . log ( "✅ Message sent via preferred lightpush node" ) ;
218
228
} else {
219
229
throw new Error (
@@ -225,20 +235,25 @@ export class WakuHeadless {
225
235
"Couldn't send message via preferred lightpush node:" ,
226
236
error ,
227
237
) ;
228
- result = await lightPush . send ( encoder , {
229
- payload : processedPayload ,
230
- timestamp : new Date ( ) ,
231
- } ) ;
238
+ result = await lightPush . send ( encoder , message ) ;
232
239
}
233
240
} else {
234
- result = await lightPush . send ( encoder , {
235
- payload : processedPayload ,
236
- timestamp : new Date ( ) ,
237
- } ) ;
241
+ result = await lightPush . send ( encoder , message ) ;
238
242
}
239
243
240
244
const serializableResult = makeSerializable ( result ) ;
241
245
246
+ serializableResult . myPeerId = this . waku . libp2p . peerId . toString ( ) ;
247
+
248
+ const messageHash = '0x' + messageHashStr (
249
+ encoder . pubsubTopic ,
250
+ protoObj ,
251
+ ) ;
252
+
253
+ console . log ( "Message hash:" , messageHash ) ;
254
+
255
+ serializableResult . messageHash = messageHash ;
256
+
242
257
return serializableResult ;
243
258
} catch ( error ) {
244
259
console . error ( "Error sending message via v3 lightpush:" , error ) ;
0 commit comments