Skip to content

Commit 497588b

Browse files
committed
chore: make topics arbitrary data
1 parent dbaf898 commit 497588b

File tree

3 files changed

+80
-77
lines changed

3 files changed

+80
-77
lines changed

packages/core/src/lib/message/version_0.spec.ts

+42-35
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,58 @@ import fc from "fast-check";
33

44
import { createDecoder, createEncoder, DecodedMessage } from "./version_0.js";
55

6-
const TestContentTopic = "/test/1/waku-message/utf8";
7-
const TestPubSubTopic = "/test/pubsub/topic";
8-
96
describe("Waku Message version 0", function () {
107
it("Round trip binary serialization", async function () {
118
await fc.assert(
12-
fc.asyncProperty(fc.uint8Array({ minLength: 1 }), async (payload) => {
13-
const encoder = createEncoder({
14-
contentTopic: TestContentTopic,
15-
});
16-
const bytes = await encoder.toWire({ payload });
17-
const decoder = createDecoder(TestContentTopic);
18-
const protoResult = await decoder.fromWireToProtoObj(bytes);
19-
const result = (await decoder.fromProtoObj(
20-
TestPubSubTopic,
21-
protoResult!
22-
)) as DecodedMessage;
9+
fc.asyncProperty(
10+
fc.string(),
11+
fc.string(),
12+
fc.uint8Array({ minLength: 1 }),
13+
async (contentTopic, pubSubTopic, payload) => {
14+
const encoder = createEncoder({
15+
contentTopic,
16+
});
17+
const bytes = await encoder.toWire({ payload });
18+
const decoder = createDecoder(contentTopic);
19+
const protoResult = await decoder.fromWireToProtoObj(bytes);
20+
const result = (await decoder.fromProtoObj(
21+
pubSubTopic,
22+
protoResult!
23+
)) as DecodedMessage;
2324

24-
expect(result.contentTopic).to.eq(TestContentTopic);
25-
expect(result.pubSubTopic).to.eq(TestPubSubTopic);
26-
expect(result.version).to.eq(0);
27-
expect(result.ephemeral).to.be.false;
28-
expect(result.payload).to.deep.eq(payload);
29-
expect(result.timestamp).to.not.be.undefined;
30-
})
25+
expect(result.contentTopic).to.eq(contentTopic);
26+
expect(result.pubSubTopic).to.eq(pubSubTopic);
27+
expect(result.version).to.eq(0);
28+
expect(result.ephemeral).to.be.false;
29+
expect(result.payload).to.deep.eq(payload);
30+
expect(result.timestamp).to.not.be.undefined;
31+
}
32+
)
3133
);
3234
});
3335

3436
it("Ephemeral field set to true", async function () {
3537
await fc.assert(
36-
fc.asyncProperty(fc.uint8Array({ minLength: 1 }), async (payload) => {
37-
const encoder = createEncoder({
38-
contentTopic: TestContentTopic,
39-
ephemeral: true,
40-
});
41-
const bytes = await encoder.toWire({ payload });
42-
const decoder = createDecoder(TestContentTopic);
43-
const protoResult = await decoder.fromWireToProtoObj(bytes);
44-
const result = (await decoder.fromProtoObj(
45-
TestPubSubTopic,
46-
protoResult!
47-
)) as DecodedMessage;
38+
fc.asyncProperty(
39+
fc.string(),
40+
fc.string(),
41+
fc.uint8Array({ minLength: 1 }),
42+
async (contentTopic, pubSubTopic, payload) => {
43+
const encoder = createEncoder({
44+
contentTopic,
45+
ephemeral: true,
46+
});
47+
const bytes = await encoder.toWire({ payload });
48+
const decoder = createDecoder(contentTopic);
49+
const protoResult = await decoder.fromWireToProtoObj(bytes);
50+
const result = (await decoder.fromProtoObj(
51+
pubSubTopic,
52+
protoResult!
53+
)) as DecodedMessage;
4854

49-
expect(result.ephemeral).to.be.true;
50-
})
55+
expect(result.ephemeral).to.be.true;
56+
}
57+
)
5158
);
5259
});
5360
});

packages/message-encryption/src/ecies.spec.ts

+22-21
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,31 @@ import fc from "fast-check";
44
import { getPublicKey } from "./crypto/index.js";
55
import { createDecoder, createEncoder } from "./ecies.js";
66

7-
const TestContentTopic = "/test/1/waku-message/utf8";
8-
const TestPubSubTopic = "/test/pubsub/topic";
9-
107
describe("Ecies Encryption", function () {
118
it("Round trip binary encryption [ecies, no signature]", async function () {
129
await fc.assert(
1310
fc.asyncProperty(
11+
fc.string(),
12+
fc.string(),
1413
fc.uint8Array({ minLength: 1 }),
1514
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
16-
async (payload, privateKey) => {
15+
async (pubSubTopic, contentTopic, payload, privateKey) => {
1716
const publicKey = getPublicKey(privateKey);
1817

1918
const encoder = createEncoder({
20-
contentTopic: TestContentTopic,
19+
contentTopic,
2120
publicKey,
2221
});
2322
const bytes = await encoder.toWire({ payload });
2423

25-
const decoder = createDecoder(TestContentTopic, privateKey);
24+
const decoder = createDecoder(contentTopic, privateKey);
2625
const protoResult = await decoder.fromWireToProtoObj(bytes!);
2726
if (!protoResult) throw "Failed to proto decode";
28-
const result = await decoder.fromProtoObj(
29-
TestPubSubTopic,
30-
protoResult
31-
);
27+
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
3228
if (!result) throw "Failed to decode";
3329

34-
expect(result.contentTopic).to.equal(TestContentTopic);
35-
expect(result.pubSubTopic).to.equal(TestPubSubTopic);
30+
expect(result.contentTopic).to.equal(contentTopic);
31+
expect(result.pubSubTopic).to.equal(pubSubTopic);
3632
expect(result.version).to.equal(1);
3733
expect(result?.payload).to.deep.equal(payload);
3834
expect(result.signature).to.be.undefined;
@@ -47,31 +43,36 @@ describe("Ecies Encryption", function () {
4743

4844
await fc.assert(
4945
fc.asyncProperty(
46+
fc.string(),
47+
fc.string(),
5048
fc.uint8Array({ minLength: 1 }),
5149
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
5250
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
53-
async (payload, alicePrivateKey, bobPrivateKey) => {
51+
async (
52+
pubSubTopic,
53+
contentTopic,
54+
payload,
55+
alicePrivateKey,
56+
bobPrivateKey
57+
) => {
5458
const alicePublicKey = getPublicKey(alicePrivateKey);
5559
const bobPublicKey = getPublicKey(bobPrivateKey);
5660

5761
const encoder = createEncoder({
58-
contentTopic: TestContentTopic,
62+
contentTopic,
5963
publicKey: bobPublicKey,
6064
sigPrivKey: alicePrivateKey,
6165
});
6266
const bytes = await encoder.toWire({ payload });
6367

64-
const decoder = createDecoder(TestContentTopic, bobPrivateKey);
68+
const decoder = createDecoder(contentTopic, bobPrivateKey);
6569
const protoResult = await decoder.fromWireToProtoObj(bytes!);
6670
if (!protoResult) throw "Failed to proto decode";
67-
const result = await decoder.fromProtoObj(
68-
TestPubSubTopic,
69-
protoResult
70-
);
71+
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
7172
if (!result) throw "Failed to decode";
7273

73-
expect(result.contentTopic).to.equal(TestContentTopic);
74-
expect(result.pubSubTopic).to.equal(TestPubSubTopic);
74+
expect(result.contentTopic).to.equal(contentTopic);
75+
expect(result.pubSubTopic).to.equal(pubSubTopic);
7576
expect(result.version).to.equal(1);
7677
expect(result?.payload).to.deep.equal(payload);
7778
expect(result.signature).to.not.be.undefined;

packages/message-encryption/src/symmetric.spec.ts

+16-21
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,29 @@ import fc from "fast-check";
44
import { getPublicKey } from "./crypto/index.js";
55
import { createDecoder, createEncoder } from "./symmetric.js";
66

7-
const TestContentTopic = "/test/1/waku-message/utf8";
8-
const TestPubSubTopic = "/test/pubsub/topic";
9-
107
describe("Symmetric Encryption", function () {
118
it("Round trip binary encryption [symmetric, no signature]", async function () {
129
await fc.assert(
1310
fc.asyncProperty(
11+
fc.string(),
12+
fc.string(),
1413
fc.uint8Array({ minLength: 1 }),
1514
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
16-
async (payload, symKey) => {
15+
async (pubSubTopic, contentTopic, payload, symKey) => {
1716
const encoder = createEncoder({
18-
contentTopic: TestContentTopic,
17+
contentTopic,
1918
symKey,
2019
});
2120
const bytes = await encoder.toWire({ payload });
2221

23-
const decoder = createDecoder(TestContentTopic, symKey);
22+
const decoder = createDecoder(contentTopic, symKey);
2423
const protoResult = await decoder.fromWireToProtoObj(bytes!);
2524
if (!protoResult) throw "Failed to proto decode";
26-
const result = await decoder.fromProtoObj(
27-
TestPubSubTopic,
28-
protoResult
29-
);
25+
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
3026
if (!result) throw "Failed to decode";
3127

32-
expect(result.contentTopic).to.equal(TestContentTopic);
33-
expect(result.pubSubTopic).to.equal(TestPubSubTopic);
28+
expect(result.contentTopic).to.equal(contentTopic);
29+
expect(result.pubSubTopic).to.equal(pubSubTopic);
3430
expect(result.version).to.equal(1);
3531
expect(result?.payload).to.deep.equal(payload);
3632
expect(result.signature).to.be.undefined;
@@ -43,30 +39,29 @@ describe("Symmetric Encryption", function () {
4339
it("Round trip binary encryption [symmetric, signature]", async function () {
4440
await fc.assert(
4541
fc.asyncProperty(
42+
fc.string(),
43+
fc.string(),
4644
fc.uint8Array({ minLength: 1 }),
4745
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
4846
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
49-
async (payload, sigPrivKey, symKey) => {
47+
async (pubSubTopic, contentTopic, payload, sigPrivKey, symKey) => {
5048
const sigPubKey = getPublicKey(sigPrivKey);
5149

5250
const encoder = createEncoder({
53-
contentTopic: TestContentTopic,
51+
contentTopic,
5452
symKey,
5553
sigPrivKey,
5654
});
5755
const bytes = await encoder.toWire({ payload });
5856

59-
const decoder = createDecoder(TestContentTopic, symKey);
57+
const decoder = createDecoder(contentTopic, symKey);
6058
const protoResult = await decoder.fromWireToProtoObj(bytes!);
6159
if (!protoResult) throw "Failed to proto decode";
62-
const result = await decoder.fromProtoObj(
63-
TestPubSubTopic,
64-
protoResult
65-
);
60+
const result = await decoder.fromProtoObj(pubSubTopic, protoResult);
6661
if (!result) throw "Failed to decode";
6762

68-
expect(result.contentTopic).to.equal(TestContentTopic);
69-
expect(result.pubSubTopic).to.equal(TestPubSubTopic);
63+
expect(result.contentTopic).to.equal(contentTopic);
64+
expect(result.pubSubTopic).to.equal(pubSubTopic);
7065
expect(result.version).to.equal(1);
7166
expect(result?.payload).to.deep.equal(payload);
7267
expect(result.signature).to.not.be.undefined;

0 commit comments

Comments
 (0)