Skip to content

Commit 5b80ddd

Browse files
nugaonbosi95
authored andcommitted
fix: 8 bytes span
1 parent 0cfd540 commit 5b80ddd

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/modules/pubsub.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import type { BeeRequestOptions } from '../types'
66
import { GsocEphemeralParams, PubsubMode, PubsubTopicListResponse } from '../types'
77
import { Bytes } from '../utils/bytes'
88
import { http } from '../utils/http'
9-
import { EthAddress, Identifier, PrivateKey, Signature } from '../utils/typed-bytes'
9+
import { EthAddress, Identifier, PrivateKey, Signature, Span } from '../utils/typed-bytes'
1010
import { NULL_IDENTIFIER } from '../utils/constants'
1111

1212
const endpoint = 'pubsub'
1313
const ENCODER = new TextEncoder()
1414

1515
const SIG_SIZE = Signature.LENGTH
16-
const SPAN_WS_SIZE = 4
16+
const SPAN_WS_SIZE = Span.LENGTH
1717

1818
export interface IPubsubMode {
1919
readonly topicAddress: string
@@ -99,9 +99,7 @@ export class GsocEphemeralMode implements IPubsubMode {
9999
throw new Error('Cannot encode messages in subscriber-only mode (no signer available)')
100100
}
101101

102-
const span4 = cac.span.toUint8Array().slice(0, SPAN_WS_SIZE)
103-
104-
return Binary.concatBytes(sigBytes, span4, cac.payload.toUint8Array())
102+
return Binary.concatBytes(sigBytes, cac.span.toUint8Array(), cac.payload.toUint8Array())
105103
}
106104

107105
decodeMessage(frame: Uint8Array): Bytes {

test/unit/pubsub.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const PAYLOAD_TEXT = 'hello there!'
66
const PAYLOAD_BYTES = new TextEncoder().encode(PAYLOAD_TEXT)
77

88
const SIG_SIZE = 65
9-
const SPAN_WS_SIZE = 4
9+
const SPAN_WS_SIZE = 8
1010

1111
test('GsocEphemeralMode - encodeMessage / decodeMessage round-trip (string payload)', async () => {
1212
const mode = new GsocEphemeralMode({ topic: TOPIC })
@@ -22,14 +22,15 @@ test('GsocEphemeralMode - encodeMessage / decodeMessage round-trip (Uint8Array p
2222
expect(decoded.toUint8Array()).toEqual(PAYLOAD_BYTES)
2323
})
2424

25-
test('GsocEphemeralMode - frame structure: [sig:65B][span:4B][payload]', async () => {
25+
test('GsocEphemeralMode - frame structure: [sig:65B][span:8B][payload]', async () => {
2626
const mode = new GsocEphemeralMode({ topic: TOPIC })
2727
const frame = await mode.encodeMessage(PAYLOAD_TEXT)
2828

2929
expect(frame.length).toBe(SIG_SIZE + SPAN_WS_SIZE + PAYLOAD_BYTES.length)
3030

31-
const span4 = new DataView(frame.buffer, frame.byteOffset + SIG_SIZE, SPAN_WS_SIZE).getUint32(0, true)
32-
expect(span4).toBe(PAYLOAD_BYTES.length)
31+
const spanView = new DataView(frame.buffer, frame.byteOffset + SIG_SIZE, SPAN_WS_SIZE)
32+
const span = spanView.getBigUint64(0, true)
33+
expect(span).toBe(BigInt(PAYLOAD_BYTES.length))
3334
})
3435

3536
test('GsocEphemeralMode - deterministic headers for same topic', () => {

0 commit comments

Comments
 (0)