Skip to content

Commit db89cf1

Browse files
committed
fix: 🐛 pubsub message encoding
1 parent 236955e commit db89cf1

File tree

3 files changed

+2613
-7209
lines changed

3 files changed

+2613
-7209
lines changed

packages/pubsub/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"dependencies": {
3131
"@chainsafe/libp2p-gossipsub": "^10.1.0",
3232
"@libp2p/interface": "^0.1.3",
33+
"@libp2p/peer-id": "^4.0.6",
3334
"@multiformats/multiaddr": "^12.1.3",
3435
"@windingtree/sdk-constants": "workspace:*",
3536
"@windingtree/sdk-logger": "workspace:*",

packages/pubsub/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { decodeText } from '@windingtree/sdk-utils';
1919
import { CashedMessageEntry, MessagesCache } from './cache.js';
2020
import { createLogger } from '@windingtree/sdk-logger';
2121
import { parse } from 'superjson';
22+
import { peerIdFromBytes } from '@libp2p/peer-id';
2223

2324
const logger = createLogger('CenterSub');
2425

@@ -179,13 +180,20 @@ export class CenterSub extends GossipSub {
179180
logger.trace('messageTransformer not defined');
180181
return;
181182
}
183+
184+
rpcMsg.from = new Uint8Array(rpcMsg.from as ArrayBufferLike);
185+
rpcMsg.signature = new Uint8Array(rpcMsg.signature as ArrayBufferLike);
186+
rpcMsg.key = new Uint8Array(rpcMsg.key as ArrayBufferLike);
187+
rpcMsg.data = new Uint8Array(rpcMsg.data as ArrayBufferLike);
188+
rpcMsg.seqno = new Uint8Array(rpcMsg.seqno as ArrayBufferLike);
189+
182190
const msgId = await sha256.encode(rpcMsg.data);
183191
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
184192
const msgIdStr = this['msgIdToStrFn'](msgId) as string;
185193
const transformed = this.messageTransformer(rpcMsg.data);
186194
await this.messages.set(
187195
msgIdStr,
188-
rpcMsg.from.toString(),
196+
peerIdFromBytes(rpcMsg.from).toString(),
189197
rpcMsg,
190198
Number(transformed.expire),
191199
Number(transformed.nonce),

0 commit comments

Comments
 (0)