@libp2p/pubsub 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +86 -70
- package/dist/test/emit-self.spec.d.ts +0 -2
- package/dist/test/emit-self.spec.d.ts.map +0 -1
- package/dist/test/emit-self.spec.js +0 -63
- package/dist/test/emit-self.spec.js.map +0 -1
- package/dist/test/instance.spec.d.ts +0 -2
- package/dist/test/instance.spec.d.ts.map +0 -1
- package/dist/test/instance.spec.js +0 -50
- package/dist/test/instance.spec.js.map +0 -1
- package/dist/test/lifesycle.spec.d.ts +0 -2
- package/dist/test/lifesycle.spec.d.ts.map +0 -1
- package/dist/test/lifesycle.spec.js +0 -192
- package/dist/test/lifesycle.spec.js.map +0 -1
- package/dist/test/message.spec.d.ts +0 -2
- package/dist/test/message.spec.d.ts.map +0 -1
- package/dist/test/message.spec.js +0 -83
- package/dist/test/message.spec.js.map +0 -1
- package/dist/test/pubsub.spec.d.ts +0 -2
- package/dist/test/pubsub.spec.d.ts.map +0 -1
- package/dist/test/pubsub.spec.js +0 -310
- package/dist/test/pubsub.spec.js.map +0 -1
- package/dist/test/sign.spec.d.ts +0 -2
- package/dist/test/sign.spec.d.ts.map +0 -1
- package/dist/test/sign.spec.js +0 -93
- package/dist/test/sign.spec.js.map +0 -1
- package/dist/test/topic-validators.spec.d.ts +0 -2
- package/dist/test/topic-validators.spec.d.ts.map +0 -1
- package/dist/test/topic-validators.spec.js +0 -86
- package/dist/test/topic-validators.spec.js.map +0 -1
- package/dist/test/utils/index.d.ts +0 -23
- package/dist/test/utils/index.d.ts.map +0 -1
- package/dist/test/utils/index.js +0 -85
- package/dist/test/utils/index.js.map +0 -1
- package/dist/test/utils.spec.d.ts +0 -2
- package/dist/test/utils.spec.d.ts.map +0 -1
- package/dist/test/utils.spec.js +0 -53
- package/dist/test/utils.spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/test/pubsub.spec.js
DELETED
@@ -1,310 +0,0 @@
|
|
1
|
-
/* eslint max-nested-callbacks: ["error", 6] */
|
2
|
-
import { expect } from 'aegir/utils/chai.js';
|
3
|
-
import sinon from 'sinon';
|
4
|
-
import pWaitFor from 'p-wait-for';
|
5
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
6
|
-
import { PeerStreams } from '../src/peer-streams.js';
|
7
|
-
import { createPeerId, createMockRegistrar, ConnectionPair, mockRegistrar, PubsubImplementation } from './utils/index.js';
|
8
|
-
const protocol = '/pubsub/1.0.0';
|
9
|
-
const topic = 'test-topic';
|
10
|
-
const message = uint8ArrayFromString('hello');
|
11
|
-
describe('pubsub base implementation', () => {
|
12
|
-
describe('publish', () => {
|
13
|
-
let pubsub;
|
14
|
-
beforeEach(async () => {
|
15
|
-
const peerId = await createPeerId();
|
16
|
-
pubsub = new PubsubImplementation({
|
17
|
-
libp2p: {
|
18
|
-
peerId: peerId,
|
19
|
-
registrar: mockRegistrar
|
20
|
-
},
|
21
|
-
multicodecs: [protocol]
|
22
|
-
});
|
23
|
-
});
|
24
|
-
afterEach(() => pubsub.stop());
|
25
|
-
it('calls _publish for router to forward messages', async () => {
|
26
|
-
sinon.spy(pubsub, '_publish');
|
27
|
-
await pubsub.start();
|
28
|
-
await pubsub.publish(topic, message);
|
29
|
-
// @ts-expect-error .callCount is a added by sinon
|
30
|
-
expect(pubsub._publish.callCount).to.eql(1);
|
31
|
-
});
|
32
|
-
it('should sign messages on publish', async () => {
|
33
|
-
sinon.spy(pubsub, '_publish');
|
34
|
-
await pubsub.start();
|
35
|
-
await pubsub.publish(topic, message);
|
36
|
-
// Get the first message sent to _publish, and validate it
|
37
|
-
// @ts-expect-error .getCall is a added by sinon
|
38
|
-
const signedMessage = pubsub._publish.getCall(0).lastArg;
|
39
|
-
await expect(pubsub.validate(signedMessage)).to.eventually.be.undefined();
|
40
|
-
});
|
41
|
-
});
|
42
|
-
describe('subscribe', () => {
|
43
|
-
describe('basics', () => {
|
44
|
-
let pubsub;
|
45
|
-
beforeEach(async () => {
|
46
|
-
const peerId = await createPeerId();
|
47
|
-
pubsub = new PubsubImplementation({
|
48
|
-
multicodecs: [protocol],
|
49
|
-
libp2p: {
|
50
|
-
peerId: peerId,
|
51
|
-
registrar: mockRegistrar
|
52
|
-
}
|
53
|
-
});
|
54
|
-
await pubsub.start();
|
55
|
-
});
|
56
|
-
afterEach(() => pubsub.stop());
|
57
|
-
it('should add subscription', () => {
|
58
|
-
pubsub.subscribe(topic);
|
59
|
-
expect(pubsub.subscriptions.size).to.eql(1);
|
60
|
-
expect(pubsub.subscriptions.has(topic)).to.be.true();
|
61
|
-
});
|
62
|
-
});
|
63
|
-
describe('two nodes', () => {
|
64
|
-
let pubsubA, pubsubB;
|
65
|
-
let peerIdA, peerIdB;
|
66
|
-
const registrarRecordA = new Map();
|
67
|
-
const registrarRecordB = new Map();
|
68
|
-
beforeEach(async () => {
|
69
|
-
peerIdA = await createPeerId();
|
70
|
-
peerIdB = await createPeerId();
|
71
|
-
pubsubA = new PubsubImplementation({
|
72
|
-
multicodecs: [protocol],
|
73
|
-
libp2p: {
|
74
|
-
peerId: peerIdA,
|
75
|
-
registrar: createMockRegistrar(registrarRecordA)
|
76
|
-
}
|
77
|
-
});
|
78
|
-
pubsubB = new PubsubImplementation({
|
79
|
-
multicodecs: [protocol],
|
80
|
-
libp2p: {
|
81
|
-
peerId: peerIdB,
|
82
|
-
registrar: createMockRegistrar(registrarRecordB)
|
83
|
-
}
|
84
|
-
});
|
85
|
-
});
|
86
|
-
// start pubsub and connect nodes
|
87
|
-
beforeEach(async () => {
|
88
|
-
pubsubA.start();
|
89
|
-
pubsubB.start();
|
90
|
-
const onConnectA = registrarRecordA.get(protocol).onConnect;
|
91
|
-
const handlerB = registrarRecordB.get(protocol).handler;
|
92
|
-
// Notice peers of connection
|
93
|
-
const [c0, c1] = ConnectionPair();
|
94
|
-
await onConnectA(peerIdB, c0);
|
95
|
-
await handlerB({
|
96
|
-
protocol,
|
97
|
-
stream: c1.stream,
|
98
|
-
connection: {
|
99
|
-
remotePeer: peerIdA
|
100
|
-
}
|
101
|
-
});
|
102
|
-
});
|
103
|
-
afterEach(() => {
|
104
|
-
pubsubA.stop();
|
105
|
-
pubsubB.stop();
|
106
|
-
});
|
107
|
-
it('should send subscribe message to connected peers', async () => {
|
108
|
-
sinon.spy(pubsubA, '_sendSubscriptions');
|
109
|
-
sinon.spy(pubsubB, '_processRpcSubOpt');
|
110
|
-
pubsubA.subscribe(topic);
|
111
|
-
// Should send subscriptions to a peer
|
112
|
-
// @ts-expect-error .callCount is a added by sinon
|
113
|
-
expect(pubsubA._sendSubscriptions.callCount).to.eql(1);
|
114
|
-
// Other peer should receive subscription message
|
115
|
-
await pWaitFor(() => {
|
116
|
-
const subscribers = pubsubB.getSubscribers(topic);
|
117
|
-
return subscribers.length === 1;
|
118
|
-
});
|
119
|
-
// @ts-expect-error .callCount is a added by sinon
|
120
|
-
expect(pubsubB._processRpcSubOpt.callCount).to.eql(1);
|
121
|
-
});
|
122
|
-
});
|
123
|
-
});
|
124
|
-
describe('unsubscribe', () => {
|
125
|
-
describe('basics', () => {
|
126
|
-
let pubsub;
|
127
|
-
beforeEach(async () => {
|
128
|
-
const peerId = await createPeerId();
|
129
|
-
pubsub = new PubsubImplementation({
|
130
|
-
multicodecs: [protocol],
|
131
|
-
libp2p: {
|
132
|
-
peerId: peerId,
|
133
|
-
registrar: mockRegistrar
|
134
|
-
}
|
135
|
-
});
|
136
|
-
await pubsub.start();
|
137
|
-
});
|
138
|
-
afterEach(() => pubsub.stop());
|
139
|
-
it('should remove all subscriptions for a topic', () => {
|
140
|
-
pubsub.subscribe(topic);
|
141
|
-
pubsub.subscribe(topic);
|
142
|
-
expect(pubsub.subscriptions.size).to.eql(1);
|
143
|
-
pubsub.unsubscribe(topic);
|
144
|
-
expect(pubsub.subscriptions.size).to.eql(0);
|
145
|
-
});
|
146
|
-
});
|
147
|
-
describe('two nodes', () => {
|
148
|
-
let pubsubA, pubsubB;
|
149
|
-
let peerIdA, peerIdB;
|
150
|
-
const registrarRecordA = new Map();
|
151
|
-
const registrarRecordB = new Map();
|
152
|
-
beforeEach(async () => {
|
153
|
-
peerIdA = await createPeerId();
|
154
|
-
peerIdB = await createPeerId();
|
155
|
-
pubsubA = new PubsubImplementation({
|
156
|
-
multicodecs: [protocol],
|
157
|
-
libp2p: {
|
158
|
-
peerId: peerIdA,
|
159
|
-
registrar: createMockRegistrar(registrarRecordA)
|
160
|
-
}
|
161
|
-
});
|
162
|
-
pubsubB = new PubsubImplementation({
|
163
|
-
multicodecs: [protocol],
|
164
|
-
libp2p: {
|
165
|
-
peerId: peerIdB,
|
166
|
-
registrar: createMockRegistrar(registrarRecordB)
|
167
|
-
}
|
168
|
-
});
|
169
|
-
});
|
170
|
-
// start pubsub and connect nodes
|
171
|
-
beforeEach(async () => {
|
172
|
-
pubsubA.start();
|
173
|
-
pubsubB.start();
|
174
|
-
const onConnectA = registrarRecordA.get(protocol).onConnect;
|
175
|
-
const handlerB = registrarRecordB.get(protocol).handler;
|
176
|
-
// Notice peers of connection
|
177
|
-
const [c0, c1] = ConnectionPair();
|
178
|
-
await onConnectA(peerIdB, c0);
|
179
|
-
await handlerB({
|
180
|
-
protocol,
|
181
|
-
stream: c1.stream,
|
182
|
-
connection: {
|
183
|
-
remotePeer: peerIdA
|
184
|
-
}
|
185
|
-
});
|
186
|
-
});
|
187
|
-
afterEach(() => {
|
188
|
-
pubsubA.stop();
|
189
|
-
pubsubB.stop();
|
190
|
-
});
|
191
|
-
it('should send unsubscribe message to connected peers', async () => {
|
192
|
-
sinon.spy(pubsubA, '_sendSubscriptions');
|
193
|
-
sinon.spy(pubsubB, '_processRpcSubOpt');
|
194
|
-
pubsubA.subscribe(topic);
|
195
|
-
// Should send subscriptions to a peer
|
196
|
-
// @ts-expect-error .callCount is a property added by sinon
|
197
|
-
expect(pubsubA._sendSubscriptions.callCount).to.eql(1);
|
198
|
-
// Other peer should receive subscription message
|
199
|
-
await pWaitFor(() => {
|
200
|
-
const subscribers = pubsubB.getSubscribers(topic);
|
201
|
-
return subscribers.length === 1;
|
202
|
-
});
|
203
|
-
// @ts-expect-error .callCount is a property added by sinon
|
204
|
-
expect(pubsubB._processRpcSubOpt.callCount).to.eql(1);
|
205
|
-
// Unsubscribe
|
206
|
-
pubsubA.unsubscribe(topic);
|
207
|
-
// Should send subscriptions to a peer
|
208
|
-
// @ts-expect-error .callCount is a property added by sinon
|
209
|
-
expect(pubsubA._sendSubscriptions.callCount).to.eql(2);
|
210
|
-
// Other peer should receive subscription message
|
211
|
-
await pWaitFor(() => {
|
212
|
-
const subscribers = pubsubB.getSubscribers(topic);
|
213
|
-
return subscribers.length === 0;
|
214
|
-
});
|
215
|
-
// @ts-expect-error .callCount is a property added by sinon
|
216
|
-
expect(pubsubB._processRpcSubOpt.callCount).to.eql(2);
|
217
|
-
});
|
218
|
-
it('should not send unsubscribe message to connected peers if not subscribed', () => {
|
219
|
-
sinon.spy(pubsubA, '_sendSubscriptions');
|
220
|
-
sinon.spy(pubsubB, '_processRpcSubOpt');
|
221
|
-
// Unsubscribe
|
222
|
-
pubsubA.unsubscribe(topic);
|
223
|
-
// Should send subscriptions to a peer
|
224
|
-
// @ts-expect-error .callCount is a property added by sinon
|
225
|
-
expect(pubsubA._sendSubscriptions.callCount).to.eql(0);
|
226
|
-
});
|
227
|
-
});
|
228
|
-
});
|
229
|
-
describe('getTopics', () => {
|
230
|
-
let peerId;
|
231
|
-
let pubsub;
|
232
|
-
beforeEach(async () => {
|
233
|
-
peerId = await createPeerId();
|
234
|
-
pubsub = new PubsubImplementation({
|
235
|
-
multicodecs: [protocol],
|
236
|
-
libp2p: {
|
237
|
-
peerId: peerId,
|
238
|
-
registrar: mockRegistrar
|
239
|
-
}
|
240
|
-
});
|
241
|
-
await pubsub.start();
|
242
|
-
});
|
243
|
-
afterEach(() => pubsub.stop());
|
244
|
-
it('returns the subscribed topics', () => {
|
245
|
-
let subsTopics = pubsub.getTopics();
|
246
|
-
expect(subsTopics).to.have.lengthOf(0);
|
247
|
-
pubsub.subscribe(topic);
|
248
|
-
subsTopics = pubsub.getTopics();
|
249
|
-
expect(subsTopics).to.have.lengthOf(1);
|
250
|
-
expect(subsTopics[0]).to.eql(topic);
|
251
|
-
});
|
252
|
-
});
|
253
|
-
describe('getSubscribers', () => {
|
254
|
-
let peerId;
|
255
|
-
let pubsub;
|
256
|
-
beforeEach(async () => {
|
257
|
-
peerId = await createPeerId();
|
258
|
-
pubsub = new PubsubImplementation({
|
259
|
-
multicodecs: [protocol],
|
260
|
-
libp2p: {
|
261
|
-
peerId: peerId,
|
262
|
-
registrar: mockRegistrar
|
263
|
-
}
|
264
|
-
});
|
265
|
-
});
|
266
|
-
afterEach(() => pubsub.stop());
|
267
|
-
it('should fail if pubsub is not started', () => {
|
268
|
-
const topic = 'topic-test';
|
269
|
-
try {
|
270
|
-
pubsub.getSubscribers(topic);
|
271
|
-
}
|
272
|
-
catch (err) {
|
273
|
-
expect(err).to.exist();
|
274
|
-
expect(err.code).to.eql('ERR_NOT_STARTED_YET');
|
275
|
-
return;
|
276
|
-
}
|
277
|
-
throw new Error('should fail if pubsub is not started');
|
278
|
-
});
|
279
|
-
it('should fail if no topic is provided', async () => {
|
280
|
-
// start pubsub
|
281
|
-
await pubsub.start();
|
282
|
-
try {
|
283
|
-
// @ts-expect-error invalid params
|
284
|
-
pubsub.getSubscribers();
|
285
|
-
}
|
286
|
-
catch (err) {
|
287
|
-
expect(err).to.exist();
|
288
|
-
expect(err.code).to.eql('ERR_NOT_VALID_TOPIC');
|
289
|
-
return;
|
290
|
-
}
|
291
|
-
throw new Error('should fail if no topic is provided');
|
292
|
-
});
|
293
|
-
it('should get peer subscribed to one topic', async () => {
|
294
|
-
const topic = 'topic-test';
|
295
|
-
// start pubsub
|
296
|
-
await pubsub.start();
|
297
|
-
let peersSubscribed = pubsub.getSubscribers(topic);
|
298
|
-
expect(peersSubscribed).to.be.empty();
|
299
|
-
// Set mock peer subscribed
|
300
|
-
const peer = new PeerStreams({ id: peerId, protocol: 'a-protocol' });
|
301
|
-
const id = peer.id.toString();
|
302
|
-
pubsub.topics.set(topic, new Set([id]));
|
303
|
-
pubsub.peers.set(id, peer);
|
304
|
-
peersSubscribed = pubsub.getSubscribers(topic);
|
305
|
-
expect(peersSubscribed).to.not.be.empty();
|
306
|
-
expect(peersSubscribed[0]).to.eql(id);
|
307
|
-
});
|
308
|
-
});
|
309
|
-
});
|
310
|
-
//# sourceMappingURL=pubsub.spec.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"pubsub.spec.js","sourceRoot":"","sources":["../../test/pubsub.spec.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AAGzB,MAAM,QAAQ,GAAG,eAAe,CAAA;AAChC,MAAM,KAAK,GAAG,YAAY,CAAA;AAC1B,MAAM,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAA;AAE7C,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACvB,IAAI,MAA4B,CAAA;QAEhC,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAA;YACnC,MAAM,GAAG,IAAI,oBAAoB,CAAC;gBAChC,MAAM,EAAE;oBACN,MAAM,EAAE,MAAM;oBACd,SAAS,EAA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AE,CAAC,QAAQ,EAAE,CAAA;YAE7B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YACvC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;YAE1B,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;YAE9C,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;YACzC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACvC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/test/sign.spec.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"sign.spec.d.ts","sourceRoot":"","sources":["../../test/sign.spec.ts"],"names":[],"mappings":""}
|
package/dist/test/sign.spec.js
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
import { expect } from 'aegir/utils/chai.js';
|
2
|
-
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
3
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
4
|
-
import { RPC } from '../src/message/rpc.js';
|
5
|
-
import { signMessage, SignPrefix, verifySignature } from '../src/message/sign.js';
|
6
|
-
import * as PeerIdFactory from '@libp2p/peer-id-factory';
|
7
|
-
import { randomSeqno } from '../src/utils.js';
|
8
|
-
import { keys } from '@libp2p/crypto';
|
9
|
-
describe('message signing', () => {
|
10
|
-
let peerId;
|
11
|
-
before(async () => {
|
12
|
-
peerId = await PeerIdFactory.createRSAPeerId({
|
13
|
-
bits: 1024
|
14
|
-
});
|
15
|
-
});
|
16
|
-
it('should be able to sign and verify a message', async () => {
|
17
|
-
const message = {
|
18
|
-
from: peerId.toBytes(),
|
19
|
-
receivedFrom: peerId.toString(),
|
20
|
-
data: uint8ArrayFromString('hello'),
|
21
|
-
seqno: randomSeqno(),
|
22
|
-
topicIDs: ['test-topic']
|
23
|
-
};
|
24
|
-
const bytesToSign = uint8ArrayConcat([SignPrefix, RPC.Message.encode(message).finish()]);
|
25
|
-
if (peerId.privateKey == null) {
|
26
|
-
throw new Error('No private key found on PeerId');
|
27
|
-
}
|
28
|
-
const privateKey = await keys.unmarshalPrivateKey(peerId.privateKey);
|
29
|
-
const expectedSignature = await privateKey.sign(bytesToSign);
|
30
|
-
const signedMessage = await signMessage(peerId, message);
|
31
|
-
// Check the signature and public key
|
32
|
-
expect(signedMessage.signature).to.eql(expectedSignature);
|
33
|
-
expect(signedMessage.key).to.eql(peerId.publicKey);
|
34
|
-
// Verify the signature
|
35
|
-
const verified = await verifySignature({
|
36
|
-
...signedMessage,
|
37
|
-
from: peerId.toBytes()
|
38
|
-
});
|
39
|
-
expect(verified).to.eql(true);
|
40
|
-
});
|
41
|
-
it('should be able to extract the public key from an inlined key', async () => {
|
42
|
-
const secPeerId = await PeerIdFactory.createSecp256k1PeerId();
|
43
|
-
const message = {
|
44
|
-
from: secPeerId.toBytes(),
|
45
|
-
receivedFrom: secPeerId.toString(),
|
46
|
-
data: uint8ArrayFromString('hello'),
|
47
|
-
seqno: randomSeqno(),
|
48
|
-
topicIDs: ['test-topic']
|
49
|
-
};
|
50
|
-
const bytesToSign = uint8ArrayConcat([SignPrefix, RPC.Message.encode(message).finish()]);
|
51
|
-
if (secPeerId.privateKey == null) {
|
52
|
-
throw new Error('No private key found on PeerId');
|
53
|
-
}
|
54
|
-
const privateKey = await keys.unmarshalPrivateKey(secPeerId.privateKey);
|
55
|
-
const expectedSignature = await privateKey.sign(bytesToSign);
|
56
|
-
const signedMessage = await signMessage(secPeerId, message);
|
57
|
-
// Check the signature and public key
|
58
|
-
expect(signedMessage.signature).to.eql(expectedSignature);
|
59
|
-
signedMessage.key = undefined;
|
60
|
-
// Verify the signature
|
61
|
-
const verified = await verifySignature({
|
62
|
-
...signedMessage,
|
63
|
-
from: secPeerId.toBytes()
|
64
|
-
});
|
65
|
-
expect(verified).to.eql(true);
|
66
|
-
});
|
67
|
-
it('should be able to extract the public key from the message', async () => {
|
68
|
-
const message = {
|
69
|
-
from: peerId.toBytes(),
|
70
|
-
receivedFrom: peerId.toString(),
|
71
|
-
data: uint8ArrayFromString('hello'),
|
72
|
-
seqno: randomSeqno(),
|
73
|
-
topicIDs: ['test-topic']
|
74
|
-
};
|
75
|
-
const bytesToSign = uint8ArrayConcat([SignPrefix, RPC.Message.encode(message).finish()]);
|
76
|
-
if (peerId.privateKey == null) {
|
77
|
-
throw new Error('No private key found on PeerId');
|
78
|
-
}
|
79
|
-
const privateKey = await keys.unmarshalPrivateKey(peerId.privateKey);
|
80
|
-
const expectedSignature = await privateKey.sign(bytesToSign);
|
81
|
-
const signedMessage = await signMessage(peerId, message);
|
82
|
-
// Check the signature and public key
|
83
|
-
expect(signedMessage.signature).to.equalBytes(expectedSignature);
|
84
|
-
expect(signedMessage.key).to.equalBytes(peerId.publicKey);
|
85
|
-
// Verify the signature
|
86
|
-
const verified = await verifySignature({
|
87
|
-
...signedMessage,
|
88
|
-
from: peerId.toBytes()
|
89
|
-
});
|
90
|
-
expect(verified).to.eql(true);
|
91
|
-
});
|
92
|
-
});
|
93
|
-
//# sourceMappingURL=sign.spec.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"sign.spec.js","sourceRoot":"","sources":["../../test/sign.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAC3C,OAAO,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AAC,UAAU,CAAC,iBAAiB,CAAC,CAAA;QAChE,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAEzD,uBAAuB;QACvB,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC;YACrC,GAAG,aAAa;YAChB,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE;SACvB,CAAC,CAAA;QACF,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"topic-validators.spec.d.ts","sourceRoot":"","sources":["../../test/topic-validators.spec.ts"],"names":[],"mappings":""}
|
@@ -1,86 +0,0 @@
|
|
1
|
-
import { expect } from 'aegir/utils/chai.js';
|
2
|
-
import sinon from 'sinon';
|
3
|
-
import pWaitFor from 'p-wait-for';
|
4
|
-
import errCode from 'err-code';
|
5
|
-
import * as PeerIdFactory from '@libp2p/peer-id-factory';
|
6
|
-
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
7
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
8
|
-
import { PeerStreams } from '../src/peer-streams.js';
|
9
|
-
import { createPeerId, mockRegistrar, PubsubImplementation } from './utils/index.js';
|
10
|
-
const protocol = '/pubsub/1.0.0';
|
11
|
-
describe('topic validators', () => {
|
12
|
-
let pubsub;
|
13
|
-
beforeEach(async () => {
|
14
|
-
const peerId = await createPeerId();
|
15
|
-
pubsub = new PubsubImplementation({
|
16
|
-
libp2p: {
|
17
|
-
peerId: peerId,
|
18
|
-
registrar: mockRegistrar
|
19
|
-
},
|
20
|
-
multicodecs: [protocol],
|
21
|
-
globalSignaturePolicy: 'StrictNoSign'
|
22
|
-
});
|
23
|
-
await pubsub.start();
|
24
|
-
});
|
25
|
-
afterEach(() => {
|
26
|
-
sinon.restore();
|
27
|
-
});
|
28
|
-
it('should filter messages by topic validator', async () => {
|
29
|
-
// use _publish.callCount() to see if a message is valid or not
|
30
|
-
sinon.spy(pubsub, '_publish');
|
31
|
-
// @ts-expect-error not all fields are implemented in return value
|
32
|
-
sinon.stub(pubsub.peers, 'get').returns({});
|
33
|
-
const filteredTopic = 't';
|
34
|
-
const peer = new PeerStreams({ id: await PeerIdFactory.createEd25519PeerId(), protocol: 'a-protocol' });
|
35
|
-
// Set a trivial topic validator
|
36
|
-
pubsub.topicValidators.set(filteredTopic, async (topic, message) => {
|
37
|
-
if (!uint8ArrayEquals(message.data, uint8ArrayFromString('a message'))) {
|
38
|
-
throw errCode(new Error(), 'ERR_TOPIC_VALIDATOR_REJECT');
|
39
|
-
}
|
40
|
-
});
|
41
|
-
// valid case
|
42
|
-
const validRpc = {
|
43
|
-
subscriptions: [],
|
44
|
-
msgs: [{
|
45
|
-
data: uint8ArrayFromString('a message'),
|
46
|
-
topicIDs: [filteredTopic]
|
47
|
-
}],
|
48
|
-
toJSON: () => ({})
|
49
|
-
};
|
50
|
-
// process valid message
|
51
|
-
pubsub.subscribe(filteredTopic);
|
52
|
-
void pubsub._processRpc(peer.id.toString(), peer, validRpc);
|
53
|
-
// @ts-expect-error .callCount is a property added by sinon
|
54
|
-
await pWaitFor(() => pubsub._publish.callCount === 1);
|
55
|
-
// invalid case
|
56
|
-
const invalidRpc = {
|
57
|
-
subscriptions: [],
|
58
|
-
msgs: [{
|
59
|
-
data: uint8ArrayFromString('a different message'),
|
60
|
-
topicIDs: [filteredTopic]
|
61
|
-
}],
|
62
|
-
toJSON: () => ({})
|
63
|
-
};
|
64
|
-
// process invalid message
|
65
|
-
void pubsub._processRpc(peer.id.toString(), peer, invalidRpc);
|
66
|
-
// @ts-expect-error .callCount is a property added by sinon
|
67
|
-
expect(pubsub._publish.callCount).to.eql(1);
|
68
|
-
// remove topic validator
|
69
|
-
pubsub.topicValidators.delete(filteredTopic);
|
70
|
-
// another invalid case
|
71
|
-
const invalidRpc2 = {
|
72
|
-
subscriptions: [],
|
73
|
-
msgs: [{
|
74
|
-
data: uint8ArrayFromString('a different message'),
|
75
|
-
topicIDs: [filteredTopic]
|
76
|
-
}],
|
77
|
-
toJSON: () => ({})
|
78
|
-
};
|
79
|
-
// process previously invalid message, now is valid
|
80
|
-
void pubsub._processRpc(peer.id.toString(), peer, invalidRpc2);
|
81
|
-
pubsub.unsubscribe(filteredTopic);
|
82
|
-
// @ts-expect-error .callCount is a property added by sinon
|
83
|
-
await pWaitFor(() => pubsub._publish.callCount === 2);
|
84
|
-
});
|
85
|
-
});
|
86
|
-
//# sourceMappingURL=topic-validators.spec.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"topic-validators.spec.js","sourceRoot":"","sources":["../../test/topic-validators.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,QAAQ,GAAG,eAAe,CAAA;AAEhC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,MAA4B,CAAA;IAEhC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAA;QAEnC,MAAM,GAAG,IAAI,oBAAoB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C,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,CAAA;QAC9D,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAA;QAEjC,2DAA2D;QAC3D,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,KAAK,CAAC,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import { PubsubBaseProtocol } from '../../src/index.js';
|
2
|
-
import { RPC, IRPC } from '../../src/message/rpc.js';
|
3
|
-
import type { Registrar } from '@libp2p/interfaces/registrar';
|
4
|
-
import type { Ed25519PeerId } from '@libp2p/peer-id';
|
5
|
-
export declare const createPeerId: () => Promise<Ed25519PeerId>;
|
6
|
-
export declare class PubsubImplementation extends PubsubBaseProtocol {
|
7
|
-
_publish(): Promise<void>;
|
8
|
-
_decodeRpc(bytes: Uint8Array): RPC;
|
9
|
-
_encodeRpc(rpc: IRPC): Uint8Array;
|
10
|
-
}
|
11
|
-
export declare const mockRegistrar: {
|
12
|
-
handle: () => void;
|
13
|
-
register: () => void;
|
14
|
-
unregister: () => void;
|
15
|
-
};
|
16
|
-
export declare const createMockRegistrar: (registrarRecord: Map<string, Record<string, any>>) => Registrar;
|
17
|
-
export declare const ConnectionPair: () => {
|
18
|
-
stream: import("it-stream-types").Duplex<Uint8Array, Uint8Array, Promise<void>>;
|
19
|
-
newStream: () => Promise<{
|
20
|
-
stream: import("it-stream-types").Duplex<Uint8Array, Uint8Array, Promise<void>>;
|
21
|
-
}>;
|
22
|
-
}[];
|
23
|
-
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../test/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,eAAO,MAAM,YAAY,QAAa,QAAQ,aAAa,CAI1D,CAAA;AAED,qBAAa,oBAAqB,SAAQ,kBAAkB;IACpD,QAAQ;IAId,UAAU,CAAE,KAAK,EAAE,UAAU;IAI7B,UAAU,CAAE,GAAG,EAAE,IAAI;CAGtB;AAED,eAAO,MAAM,aAAa;;;;CAIzB,CAAA;AAED,eAAO,MAAM,mBAAmB,oBAAqB,IAAI,MAAM,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAC,cAqDpF,CAAA;AAED,eAAO,MAAM,cAAc;;;;;GAa1B,CAAA"}
|
package/dist/test/utils/index.js
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
import { duplexPair } from 'it-pair/duplex';
|
2
|
-
import * as PeerIdFactory from '@libp2p/peer-id-factory';
|
3
|
-
import { PubsubBaseProtocol } from '../../src/index.js';
|
4
|
-
import { RPC } from '../../src/message/rpc.js';
|
5
|
-
export const createPeerId = async () => {
|
6
|
-
const peerId = await PeerIdFactory.createEd25519PeerId();
|
7
|
-
return peerId;
|
8
|
-
};
|
9
|
-
export class PubsubImplementation extends PubsubBaseProtocol {
|
10
|
-
async _publish() {
|
11
|
-
// ...
|
12
|
-
}
|
13
|
-
_decodeRpc(bytes) {
|
14
|
-
return RPC.decode(bytes);
|
15
|
-
}
|
16
|
-
_encodeRpc(rpc) {
|
17
|
-
return RPC.encode(rpc).finish();
|
18
|
-
}
|
19
|
-
}
|
20
|
-
export const mockRegistrar = {
|
21
|
-
handle: () => { },
|
22
|
-
register: () => { },
|
23
|
-
unregister: () => { }
|
24
|
-
};
|
25
|
-
export const createMockRegistrar = (registrarRecord) => {
|
26
|
-
const registrar = {
|
27
|
-
handle: (multicodecs, handler) => {
|
28
|
-
const rec = registrarRecord.get(multicodecs[0]) ?? {};
|
29
|
-
registrarRecord.set(multicodecs[0], {
|
30
|
-
...rec,
|
31
|
-
handler
|
32
|
-
});
|
33
|
-
},
|
34
|
-
register: (topology) => {
|
35
|
-
const { multicodecs } = topology;
|
36
|
-
const rec = registrarRecord.get(multicodecs[0]) ?? {};
|
37
|
-
registrarRecord.set(multicodecs[0], {
|
38
|
-
...rec,
|
39
|
-
onConnect: topology._onConnect,
|
40
|
-
onDisconnect: topology._onDisconnect
|
41
|
-
});
|
42
|
-
return multicodecs[0];
|
43
|
-
},
|
44
|
-
unregister: (id) => {
|
45
|
-
registrarRecord.delete(id);
|
46
|
-
},
|
47
|
-
getConnection(peerId) {
|
48
|
-
throw new Error('Not implemented');
|
49
|
-
},
|
50
|
-
peerStore: {
|
51
|
-
on: () => {
|
52
|
-
throw new Error('Not implemented');
|
53
|
-
},
|
54
|
-
protoBook: {
|
55
|
-
get: () => {
|
56
|
-
throw new Error('Not implemented');
|
57
|
-
}
|
58
|
-
},
|
59
|
-
peers: new Map(),
|
60
|
-
get: (peerId) => {
|
61
|
-
throw new Error('Not implemented');
|
62
|
-
}
|
63
|
-
},
|
64
|
-
connectionManager: {
|
65
|
-
on: () => {
|
66
|
-
throw new Error('Not implemented');
|
67
|
-
}
|
68
|
-
}
|
69
|
-
};
|
70
|
-
return registrar;
|
71
|
-
};
|
72
|
-
export const ConnectionPair = () => {
|
73
|
-
const [d0, d1] = duplexPair();
|
74
|
-
return [
|
75
|
-
{
|
76
|
-
stream: d0,
|
77
|
-
newStream: async () => await Promise.resolve({ stream: d0 })
|
78
|
-
},
|
79
|
-
{
|
80
|
-
stream: d1,
|
81
|
-
newStream: async () => await Promise.resolve({ stream: d1 })
|
82
|
-
}
|
83
|
-
];
|
84
|
-
};
|
85
|
-
//# sourceMappingURL=index.js.map
|