@libp2p/interface-compliance-tests 1.0.2 → 1.0.6
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/dist/src/connection/connection.d.ts.map +1 -1
- package/dist/src/connection/connection.js +0 -2
- package/dist/src/connection/connection.js.map +1 -1
- package/dist/src/crypto/index.d.ts.map +1 -1
- package/dist/src/crypto/index.js +7 -8
- package/dist/src/crypto/index.js.map +1 -1
- package/dist/src/crypto/utils/index.d.ts +3 -0
- package/dist/src/crypto/utils/index.d.ts.map +1 -0
- package/dist/src/crypto/utils/index.js +18 -0
- package/dist/src/crypto/utils/index.js.map +1 -0
- package/dist/src/stream-muxer/base-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/base-test.js +26 -23
- package/dist/src/stream-muxer/base-test.js.map +1 -1
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/close-test.js +16 -18
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/stream-muxer/spawner.d.ts.map +1 -1
- package/dist/src/stream-muxer/spawner.js +13 -12
- package/dist/src/stream-muxer/spawner.js.map +1 -1
- package/dist/src/transport/dial-test.d.ts.map +1 -1
- package/dist/src/transport/dial-test.js +5 -6
- package/dist/src/transport/dial-test.js.map +1 -1
- package/dist/src/transport/listen-test.d.ts.map +1 -1
- package/dist/src/transport/listen-test.js +13 -9
- package/dist/src/transport/listen-test.js.map +1 -1
- package/dist/src/transport/utils/index.d.ts.map +1 -1
- package/dist/src/transport/utils/index.js +3 -13
- package/dist/src/transport/utils/index.js.map +1 -1
- package/package.json +80 -65
- package/src/connection/connection.ts +0 -2
- package/src/crypto/index.ts +9 -9
- package/src/crypto/utils/index.ts +23 -0
- package/src/stream-muxer/base-test.ts +28 -24
- package/src/stream-muxer/close-test.ts +16 -18
- package/src/stream-muxer/spawner.ts +14 -13
- package/src/transport/dial-test.ts +5 -6
- package/src/transport/listen-test.ts +14 -10
- package/src/transport/utils/index.ts +5 -17
- package/dist/test/connection/index.spec.d.ts +0 -2
- package/dist/test/connection/index.spec.d.ts.map +0 -1
- package/dist/test/connection/index.spec.js +0 -71
- package/dist/test/connection/index.spec.js.map +0 -1
- package/dist/test/crypto/index.spec.d.ts +0 -2
- package/dist/test/crypto/index.spec.d.ts.map +0 -1
- package/dist/test/crypto/index.spec.js +0 -11
- package/dist/test/crypto/index.spec.js.map +0 -1
- package/dist/test/crypto/mock-crypto.d.ts +0 -4
- package/dist/test/crypto/mock-crypto.d.ts.map +0 -1
- package/dist/test/crypto/mock-crypto.js +0 -93
- package/dist/test/crypto/mock-crypto.js.map +0 -1
- package/dist/test/peer-discovery/index.spec.d.ts +0 -2
- package/dist/test/peer-discovery/index.spec.d.ts.map +0 -1
- package/dist/test/peer-discovery/index.spec.js +0 -18
- package/dist/test/peer-discovery/index.spec.js.map +0 -1
- package/dist/test/peer-discovery/mock-discovery.d.ts +0 -20
- package/dist/test/peer-discovery/mock-discovery.d.ts.map +0 -1
- package/dist/test/peer-discovery/mock-discovery.js +0 -39
- package/dist/test/peer-discovery/mock-discovery.js.map +0 -1
- package/dist/test/topology/mock-peer-store.d.ts +0 -12
- package/dist/test/topology/mock-peer-store.d.ts.map +0 -1
- package/dist/test/topology/mock-peer-store.js +0 -18
- package/dist/test/topology/mock-peer-store.js.map +0 -1
- package/dist/test/topology/multicodec-topology.spec.d.ts +0 -2
- package/dist/test/topology/multicodec-topology.spec.d.ts.map +0 -1
- package/dist/test/topology/multicodec-topology.spec.js +0 -45
- package/dist/test/topology/multicodec-topology.spec.js.map +0 -1
- package/dist/test/topology/topology.spec.d.ts +0 -2
- package/dist/test/topology/topology.spec.d.ts.map +0 -1
- package/dist/test/topology/topology.spec.js +0 -21
- package/dist/test/topology/topology.spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/* eslint max-nested-callbacks: ["error", 8] */
|
|
2
|
-
// @ts-expect-error no types
|
|
3
|
-
import pair from 'it-pair/duplex.js'
|
|
4
2
|
import { pipe } from 'it-pipe'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import AbortController from 'abort-controller'
|
|
3
|
+
import { duplexPair } from 'it-pair/duplex'
|
|
4
|
+
import { abortableSource, abortableDuplex } from 'abortable-iterator'
|
|
8
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
+
import drain from 'it-drain'
|
|
9
7
|
import type { TestSetup } from '../index.js'
|
|
10
8
|
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
|
|
11
9
|
import type { Connection } from '@libp2p/interfaces/connection'
|
|
@@ -47,16 +45,16 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
47
45
|
const mockUpgrade = async (maConn: any) => {
|
|
48
46
|
const muxer = await common.setup({
|
|
49
47
|
onStream: (stream) => {
|
|
50
|
-
pipe(stream, stream)
|
|
48
|
+
void pipe(stream, stream)
|
|
51
49
|
}
|
|
52
50
|
})
|
|
53
|
-
pipe(maConn, muxer, maConn)
|
|
51
|
+
pipe(maConn, muxer.newStream('/test/stream'), maConn)
|
|
54
52
|
return mockConn(muxer)
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
const [local, remote] =
|
|
55
|
+
const [local, remote] = duplexPair<Uint8Array>()
|
|
58
56
|
const controller = new AbortController()
|
|
59
|
-
const abortableRemote =
|
|
57
|
+
const abortableRemote = abortableDuplex(remote, controller.signal, {
|
|
60
58
|
returnOnAbort: true
|
|
61
59
|
})
|
|
62
60
|
|
|
@@ -69,8 +67,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
69
67
|
// close the remote in a bit
|
|
70
68
|
setTimeout(() => controller.abort(), 50)
|
|
71
69
|
|
|
72
|
-
const s1Result = pipe(infiniteRandom, s1,
|
|
73
|
-
const s2Result = pipe(infiniteRandom, s2,
|
|
70
|
+
const s1Result = pipe(infiniteRandom, s1.stream, drain)
|
|
71
|
+
const s2Result = pipe(infiniteRandom, s2.stream, drain)
|
|
74
72
|
|
|
75
73
|
// test is complete when all muxed streams have closed
|
|
76
74
|
await s1Result
|
|
@@ -78,16 +76,16 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
78
76
|
})
|
|
79
77
|
|
|
80
78
|
it('closing one of the muxed streams doesn\'t close others', async () => {
|
|
81
|
-
const p =
|
|
79
|
+
const p = duplexPair<Uint8Array>()
|
|
82
80
|
const dialer = await common.setup()
|
|
83
81
|
|
|
84
82
|
// Listener is echo server :)
|
|
85
83
|
const listener = await common.setup({
|
|
86
|
-
onStream: (stream) => pipe(stream, stream)
|
|
84
|
+
onStream: async (stream) => await pipe(stream, stream)
|
|
87
85
|
})
|
|
88
86
|
|
|
89
|
-
pipe(p[0], dialer, p[0])
|
|
90
|
-
pipe(p[1], listener, p[1])
|
|
87
|
+
void pipe(p[0], dialer.newStream('/test/stream'), p[0])
|
|
88
|
+
void pipe(p[1], listener.newStream('/test/stream'), p[1])
|
|
91
89
|
|
|
92
90
|
const stream = dialer.newStream()
|
|
93
91
|
const streams = Array.from(Array(5), () => dialer.newStream())
|
|
@@ -99,8 +97,8 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
99
97
|
controllers.push(controller)
|
|
100
98
|
|
|
101
99
|
try {
|
|
102
|
-
const abortableRand =
|
|
103
|
-
await pipe(abortableRand, stream,
|
|
100
|
+
const abortableRand = abortableSource(infiniteRandom, controller.signal, { abortCode: 'ERR_TEST_ABORT' })
|
|
101
|
+
await pipe(abortableRand, stream, drain)
|
|
104
102
|
} catch (err: any) {
|
|
105
103
|
if (err.code !== 'ERR_TEST_ABORT') throw err
|
|
106
104
|
}
|
|
@@ -110,7 +108,7 @@ export default (common: TestSetup<Muxer, MuxerOptions>) => {
|
|
|
110
108
|
|
|
111
109
|
// Pause, and then send some data and close the first stream
|
|
112
110
|
await pause(50)
|
|
113
|
-
await pipe([randomBuffer()], stream,
|
|
111
|
+
await pipe([randomBuffer()], stream, drain)
|
|
114
112
|
closed = true
|
|
115
113
|
|
|
116
114
|
// Abort all the other streams later
|
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
|
-
|
|
3
|
-
import pair from 'it-pair/duplex.js'
|
|
2
|
+
import { duplexPair } from 'it-pair/duplex'
|
|
4
3
|
import { pipe } from 'it-pipe'
|
|
5
4
|
import pLimit from 'p-limit'
|
|
6
|
-
import {
|
|
5
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
+
import drain from 'it-drain'
|
|
7
|
+
import all from 'it-all'
|
|
7
8
|
import type { Muxer, MuxerOptions } from '@libp2p/interfaces/stream-muxer'
|
|
8
9
|
|
|
9
10
|
export default async (createMuxer: (options?: MuxerOptions) => Promise<Muxer>, nStreams: number, nMsg: number, limit?: number) => {
|
|
10
|
-
const [dialerSocket, listenerSocket] =
|
|
11
|
+
const [dialerSocket, listenerSocket] = duplexPair<Uint8Array>()
|
|
11
12
|
|
|
12
|
-
const msg = 'simple msg'
|
|
13
|
+
const msg = uint8ArrayFromString('simple msg')
|
|
13
14
|
|
|
14
15
|
const listener = await createMuxer({
|
|
15
16
|
onStream: async (stream) => {
|
|
16
17
|
await pipe(
|
|
17
18
|
stream,
|
|
18
|
-
|
|
19
|
+
drain
|
|
19
20
|
)
|
|
20
21
|
|
|
21
|
-
pipe([], stream)
|
|
22
|
+
void pipe([], stream)
|
|
22
23
|
}
|
|
23
24
|
})
|
|
24
25
|
|
|
25
26
|
const dialer = await createMuxer()
|
|
26
27
|
|
|
27
|
-
pipe(listenerSocket, listener, listenerSocket)
|
|
28
|
-
pipe(dialerSocket, dialer, dialerSocket)
|
|
28
|
+
void pipe(listenerSocket, listener.newStream('/test/stream'), listenerSocket)
|
|
29
|
+
void pipe(dialerSocket, dialer.newStream('/test/stream'), dialerSocket)
|
|
29
30
|
|
|
30
31
|
const spawnStream = async () => {
|
|
31
32
|
const stream = dialer.newStream()
|
|
32
33
|
expect(stream).to.exist // eslint-disable-line
|
|
33
34
|
|
|
34
35
|
const res = await pipe(
|
|
35
|
-
(function * () {
|
|
36
|
+
(async function * () {
|
|
36
37
|
for (let i = 0; i < nMsg; i++) {
|
|
37
|
-
yield
|
|
38
|
+
yield msg
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
}()),
|
|
40
41
|
stream,
|
|
41
|
-
|
|
42
|
+
async (source) => await all(source)
|
|
42
43
|
)
|
|
43
44
|
|
|
44
45
|
expect(res).to.be.eql([])
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { expect } from 'aegir/utils/chai.js'
|
|
2
2
|
import { isValidTick, mockUpgrader } from './utils/index.js'
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import { collect } from 'streaming-iterables'
|
|
3
|
+
import { goodbye } from 'it-goodbye'
|
|
4
|
+
import all from 'it-all'
|
|
6
5
|
import { pipe } from 'it-pipe'
|
|
7
|
-
import AbortController from 'abort-controller'
|
|
8
6
|
import { AbortError } from '@libp2p/interfaces/errors'
|
|
9
7
|
import sinon from 'sinon'
|
|
8
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
9
|
import type { TestSetup } from '../index.js'
|
|
11
10
|
import type { Transport, Listener } from '@libp2p/interfaces/transport'
|
|
12
11
|
import type { TransportTestFixtures, SetupArgs, Connector } from './index.js'
|
|
@@ -43,14 +42,14 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
43
42
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeOutbound')
|
|
44
43
|
const conn = await transport.dial(addrs[0])
|
|
45
44
|
const { stream } = await conn.newStream(['/hello'])
|
|
46
|
-
const s = goodbye({ source: ['hey'], sink:
|
|
45
|
+
const s = goodbye({ source: [uint8ArrayFromString('hey')], sink: async (source) => await all(source) })
|
|
47
46
|
|
|
48
47
|
const result = await pipe(s, stream, s)
|
|
49
48
|
|
|
50
49
|
expect(upgradeSpy.callCount).to.equal(1)
|
|
51
50
|
await expect(upgradeSpy.getCall(0).returnValue).to.eventually.equal(conn)
|
|
52
51
|
expect(result.length).to.equal(1)
|
|
53
|
-
expect(result[0]
|
|
52
|
+
expect(result[0]).to.equalBytes(uint8ArrayFromString('hey'))
|
|
54
53
|
await conn.close()
|
|
55
54
|
})
|
|
56
55
|
|
|
@@ -16,7 +16,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
16
16
|
describe('listen', () => {
|
|
17
17
|
const upgrader = mockUpgrader()
|
|
18
18
|
let addrs: Multiaddr[]
|
|
19
|
-
let transport: Transport
|
|
19
|
+
let transport: Transport
|
|
20
20
|
|
|
21
21
|
before(async () => {
|
|
22
22
|
({ transport, addrs } = await common.setup({ upgrader }))
|
|
@@ -31,7 +31,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
it('simple', async () => {
|
|
34
|
-
const listener = transport.createListener(
|
|
34
|
+
const listener = transport.createListener()
|
|
35
35
|
await listener.listen(addrs[0])
|
|
36
36
|
await listener.close()
|
|
37
37
|
})
|
|
@@ -40,8 +40,10 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
40
40
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
|
41
41
|
const listenerConns: Connection[] = []
|
|
42
42
|
|
|
43
|
-
const listener = transport.createListener({
|
|
44
|
-
|
|
43
|
+
const listener = transport.createListener({
|
|
44
|
+
handler: (conn) => {
|
|
45
|
+
listenerConns.push(conn)
|
|
46
|
+
}
|
|
45
47
|
})
|
|
46
48
|
|
|
47
49
|
// Listen
|
|
@@ -83,8 +85,10 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
83
85
|
it('should not handle connection if upgradeInbound throws', async () => {
|
|
84
86
|
sinon.stub(upgrader, 'upgradeInbound').throws()
|
|
85
87
|
|
|
86
|
-
const listener = transport.createListener(
|
|
87
|
-
|
|
88
|
+
const listener = transport.createListener({
|
|
89
|
+
handler: () => {
|
|
90
|
+
throw new Error('should not handle the connection if upgradeInbound throws')
|
|
91
|
+
}
|
|
88
92
|
})
|
|
89
93
|
|
|
90
94
|
// Listen
|
|
@@ -100,7 +104,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
100
104
|
describe('events', () => {
|
|
101
105
|
it('connection', async () => {
|
|
102
106
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
|
103
|
-
const listener = transport.createListener(
|
|
107
|
+
const listener = transport.createListener()
|
|
104
108
|
const deferred = defer()
|
|
105
109
|
let conn
|
|
106
110
|
|
|
@@ -122,7 +126,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
122
126
|
})
|
|
123
127
|
|
|
124
128
|
it('listening', (done) => {
|
|
125
|
-
const listener = transport.createListener(
|
|
129
|
+
const listener = transport.createListener()
|
|
126
130
|
listener.on('listening', () => {
|
|
127
131
|
listener.close().then(done, done)
|
|
128
132
|
})
|
|
@@ -130,7 +134,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
130
134
|
})
|
|
131
135
|
|
|
132
136
|
it('error', (done) => {
|
|
133
|
-
const listener = transport.createListener(
|
|
137
|
+
const listener = transport.createListener()
|
|
134
138
|
listener.on('error', (err) => {
|
|
135
139
|
expect(err).to.exist()
|
|
136
140
|
listener.close().then(done, done)
|
|
@@ -139,7 +143,7 @@ export default (common: TestSetup<TransportTestFixtures, SetupArgs>) => {
|
|
|
139
143
|
})
|
|
140
144
|
|
|
141
145
|
it('close', (done) => {
|
|
142
|
-
const listener = transport.createListener(
|
|
146
|
+
const listener = transport.createListener()
|
|
143
147
|
listener.on('close', done)
|
|
144
148
|
|
|
145
149
|
void (async () => {
|
|
@@ -2,8 +2,7 @@ import { expect } from 'aegir/utils/chai.js'
|
|
|
2
2
|
import type { Upgrader, MultiaddrConnection } from '@libp2p/interfaces/transport'
|
|
3
3
|
import type { Connection, StreamData } from '@libp2p/interfaces/connection'
|
|
4
4
|
import type { MuxedStream } from '@libp2p/interfaces/stream-muxer'
|
|
5
|
-
|
|
6
|
-
import pair from 'it-pair'
|
|
5
|
+
import { pair } from 'it-pair'
|
|
7
6
|
import { PeerId } from '@libp2p/peer-id'
|
|
8
7
|
import * as PeerIdFactory from '@libp2p/peer-id-factory'
|
|
9
8
|
/**
|
|
@@ -26,7 +25,7 @@ export function isValidTick (date?: number, ms: number = 5000) {
|
|
|
26
25
|
|
|
27
26
|
export function mockUpgrader () {
|
|
28
27
|
const ensureProps = (multiaddrConnection: MultiaddrConnection) => {
|
|
29
|
-
['sink', 'source', 'remoteAddr', '
|
|
28
|
+
['sink', 'source', 'remoteAddr', 'timeline', 'close'].forEach(prop => {
|
|
30
29
|
expect(multiaddrConnection).to.have.property(prop)
|
|
31
30
|
})
|
|
32
31
|
expect(isValidTick(multiaddrConnection.timeline.open)).to.equal(true)
|
|
@@ -47,28 +46,18 @@ export function mockUpgrader () {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
async function createConnection (maConn: MultiaddrConnection, direction: 'inbound' | 'outbound'): Promise<Connection> {
|
|
50
|
-
const localAddr = maConn.localAddr
|
|
51
49
|
const remoteAddr = maConn.remoteAddr
|
|
52
|
-
|
|
53
|
-
if (localAddr == null) {
|
|
54
|
-
throw new Error('No localAddr found on MultiaddrConnection')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const localPeerIdStr = localAddr.getPeerId()
|
|
58
50
|
const remotePeerIdStr = remoteAddr.getPeerId()
|
|
59
|
-
const localPeer = localPeerIdStr != null ? PeerId.fromString(localPeerIdStr) : await PeerIdFactory.createEd25519PeerId()
|
|
60
51
|
const remotePeer = remotePeerIdStr != null ? PeerId.fromString(remotePeerIdStr) : await PeerIdFactory.createEd25519PeerId()
|
|
61
52
|
|
|
62
|
-
const streams:
|
|
53
|
+
const streams: MuxedStream[] = []
|
|
63
54
|
let streamId = 0
|
|
64
55
|
|
|
65
56
|
const registry = new Map()
|
|
66
57
|
|
|
67
58
|
return {
|
|
68
59
|
id: 'mock-connection',
|
|
69
|
-
localAddr,
|
|
70
60
|
remoteAddr,
|
|
71
|
-
localPeer,
|
|
72
61
|
remotePeer,
|
|
73
62
|
stat: {
|
|
74
63
|
status: 'OPEN',
|
|
@@ -85,7 +74,7 @@ async function createConnection (maConn: MultiaddrConnection, direction: 'inboun
|
|
|
85
74
|
throw new Error('protocols must have a length')
|
|
86
75
|
}
|
|
87
76
|
|
|
88
|
-
const echo = pair()
|
|
77
|
+
const echo = pair<Uint8Array>()
|
|
89
78
|
|
|
90
79
|
const id = `${streamId++}`
|
|
91
80
|
const stream: MuxedStream = {
|
|
@@ -97,8 +86,7 @@ async function createConnection (maConn: MultiaddrConnection, direction: 'inboun
|
|
|
97
86
|
reset: () => {},
|
|
98
87
|
timeline: {
|
|
99
88
|
open: 0
|
|
100
|
-
}
|
|
101
|
-
[Symbol.asyncIterator]: echo.source
|
|
89
|
+
}
|
|
102
90
|
}
|
|
103
91
|
|
|
104
92
|
const streamData = {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../../test/connection/index.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import tests from '../../src/connection/index.js';
|
|
2
|
-
import { Connection } from '@libp2p/connection';
|
|
3
|
-
import peers from '../../src/utils/peers.js';
|
|
4
|
-
import * as PeerIdFactory from '@libp2p/peer-id-factory';
|
|
5
|
-
import { Multiaddr } from '@multiformats/multiaddr';
|
|
6
|
-
// @ts-expect-error no types
|
|
7
|
-
import pair from 'it-pair';
|
|
8
|
-
describe('compliance tests', () => {
|
|
9
|
-
tests({
|
|
10
|
-
/**
|
|
11
|
-
* Test setup. `properties` allows the compliance test to override
|
|
12
|
-
* certain values for testing.
|
|
13
|
-
*/
|
|
14
|
-
async setup(properties) {
|
|
15
|
-
const localAddr = new Multiaddr('/ip4/127.0.0.1/tcp/8080');
|
|
16
|
-
const remoteAddr = new Multiaddr('/ip4/127.0.0.1/tcp/8081');
|
|
17
|
-
const [localPeer, remotePeer] = await Promise.all([
|
|
18
|
-
PeerIdFactory.createFromJSON(peers[0]),
|
|
19
|
-
PeerIdFactory.createFromJSON(peers[1])
|
|
20
|
-
]);
|
|
21
|
-
const openStreams = [];
|
|
22
|
-
let streamId = 0;
|
|
23
|
-
const connection = new Connection({
|
|
24
|
-
localPeer,
|
|
25
|
-
remotePeer,
|
|
26
|
-
localAddr,
|
|
27
|
-
remoteAddr,
|
|
28
|
-
stat: {
|
|
29
|
-
timeline: {
|
|
30
|
-
open: Date.now() - 10,
|
|
31
|
-
upgraded: Date.now()
|
|
32
|
-
},
|
|
33
|
-
direction: 'outbound',
|
|
34
|
-
encryption: '/secio/1.0.0',
|
|
35
|
-
multiplexer: '/mplex/6.7.0',
|
|
36
|
-
status: 'OPEN'
|
|
37
|
-
},
|
|
38
|
-
newStream: async (protocols) => {
|
|
39
|
-
const id = `${streamId++}`;
|
|
40
|
-
const stream = {
|
|
41
|
-
...pair(),
|
|
42
|
-
close: async () => {
|
|
43
|
-
await stream.sink(async function* () { }());
|
|
44
|
-
connection.removeStream(stream.id);
|
|
45
|
-
},
|
|
46
|
-
id,
|
|
47
|
-
abort: () => { },
|
|
48
|
-
reset: () => { },
|
|
49
|
-
timeline: {
|
|
50
|
-
open: 0
|
|
51
|
-
},
|
|
52
|
-
[Symbol.asyncIterator]: () => stream.source
|
|
53
|
-
};
|
|
54
|
-
openStreams.push(stream);
|
|
55
|
-
return {
|
|
56
|
-
stream,
|
|
57
|
-
protocol: protocols[0]
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
close: async () => { },
|
|
61
|
-
getStreams: () => openStreams,
|
|
62
|
-
...properties
|
|
63
|
-
});
|
|
64
|
-
return connection;
|
|
65
|
-
},
|
|
66
|
-
async teardown() {
|
|
67
|
-
// cleanup resources created by setup()
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../test/connection/index.spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,+BAA+B,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,MAAM,0BAA0B,CAAA;AAC5C,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,4BAA4B;AAC5B,OAAO,IAAI,MAAM,SAAS,CAAA;AAG1B,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,KAAK,CAAC;QACJ;;;WAGG;QACH,KAAK,CAAC,KAAK,CAAE,UAAU;YACrB,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAA;YAC1D,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAA;YAC3D,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBAChD,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACtC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACvC,CAAC,CAAA;YACF,MAAM,WAAW,GAAkB,EAAE,CAAA;YACrC,IAAI,QAAQ,GAAG,CAAC,CAAA;YAEhB,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;gBAChC,SAAS;gBACT,UAAU;gBACV,SAAS;gBACT,UAAU;gBACV,IAAI,EAAE;oBACJ,QAAQ,EAAE;wBACR,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE;wBAC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/crypto/index.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import tests from '../../src/crypto/index.js';
|
|
2
|
-
import mockCrypto from './mock-crypto.js';
|
|
3
|
-
describe('compliance tests', () => {
|
|
4
|
-
tests({
|
|
5
|
-
async setup() {
|
|
6
|
-
return mockCrypto;
|
|
7
|
-
},
|
|
8
|
-
async teardown() { }
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../test/crypto/index.spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,2BAA2B,CAAA;AAC7C,OAAO,UAAU,MAAM,kBAAkB,CAAA;AAEzC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,KAAK,CAAC;QACJ,KAAK,CAAC,KAAK;YACT,OAAO,UAAU,CAAA;QACnB,CAAC;QACD,KAAK,CAAC,QAAQ,KAAK,CAAC;KACrB,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-crypto.d.ts","sourceRoot":"","sources":["../../../test/crypto/mock-crypto.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAYvD,QAAA,MAAM,MAAM,EAAE,MAuFb,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { PeerId } from '@libp2p/peer-id';
|
|
2
|
-
// @ts-expect-error no types
|
|
3
|
-
import handshake from 'it-handshake';
|
|
4
|
-
// @ts-expect-error no types
|
|
5
|
-
import duplexPair from 'it-pair/duplex.js';
|
|
6
|
-
import pipe from 'it-pipe';
|
|
7
|
-
import { UnexpectedPeerError } from '@libp2p/interfaces/crypto/errors';
|
|
8
|
-
import { Multiaddr } from '@multiformats/multiaddr';
|
|
9
|
-
// A basic transform that does nothing to the data
|
|
10
|
-
const transform = () => {
|
|
11
|
-
return (source) => (async function* () {
|
|
12
|
-
for await (const chunk of source) {
|
|
13
|
-
yield chunk;
|
|
14
|
-
}
|
|
15
|
-
})();
|
|
16
|
-
};
|
|
17
|
-
const crypto = {
|
|
18
|
-
protocol: 'insecure',
|
|
19
|
-
secureInbound: async (localPeer, duplex, expectedPeer) => {
|
|
20
|
-
// 1. Perform a basic handshake.
|
|
21
|
-
const shake = handshake(duplex);
|
|
22
|
-
shake.write(localPeer.toBytes());
|
|
23
|
-
const remoteId = await shake.read();
|
|
24
|
-
if (remoteId == null) {
|
|
25
|
-
throw new Error('Could not read remote ID');
|
|
26
|
-
}
|
|
27
|
-
const remotePeer = PeerId.fromBytes(remoteId.slice());
|
|
28
|
-
shake.rest();
|
|
29
|
-
if (expectedPeer != null && !expectedPeer.equals(remotePeer)) {
|
|
30
|
-
throw new UnexpectedPeerError();
|
|
31
|
-
}
|
|
32
|
-
// 2. Create your encryption box/unbox wrapper
|
|
33
|
-
const wrapper = duplexPair();
|
|
34
|
-
const encrypt = transform(); // Use transform iterables to modify data
|
|
35
|
-
const decrypt = transform();
|
|
36
|
-
pipe(wrapper[0], // We write to wrapper
|
|
37
|
-
encrypt, // The data is encrypted
|
|
38
|
-
shake.stream, // It goes to the remote peer
|
|
39
|
-
decrypt, // Decrypt the incoming data
|
|
40
|
-
wrapper[0] // Pipe to the wrapper
|
|
41
|
-
);
|
|
42
|
-
return {
|
|
43
|
-
conn: {
|
|
44
|
-
...wrapper[1],
|
|
45
|
-
close: async () => { },
|
|
46
|
-
localAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
47
|
-
remoteAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4002'),
|
|
48
|
-
timeline: {
|
|
49
|
-
open: Date.now()
|
|
50
|
-
},
|
|
51
|
-
conn: true
|
|
52
|
-
},
|
|
53
|
-
remotePeer,
|
|
54
|
-
remoteEarlyData: new Uint8Array(0)
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
secureOutbound: async (localPeer, duplex, remotePeer) => {
|
|
58
|
-
// 1. Perform a basic handshake.
|
|
59
|
-
const shake = handshake(duplex);
|
|
60
|
-
shake.write(localPeer.toBytes());
|
|
61
|
-
const remoteId = await shake.read();
|
|
62
|
-
if (remoteId == null) {
|
|
63
|
-
throw new Error('Could not read remote ID');
|
|
64
|
-
}
|
|
65
|
-
shake.rest();
|
|
66
|
-
// 2. Create your encryption box/unbox wrapper
|
|
67
|
-
const wrapper = duplexPair();
|
|
68
|
-
const encrypt = transform();
|
|
69
|
-
const decrypt = transform();
|
|
70
|
-
pipe(wrapper[0], // We write to wrapper
|
|
71
|
-
encrypt, // The data is encrypted
|
|
72
|
-
shake.stream, // It goes to the remote peer
|
|
73
|
-
decrypt, // Decrypt the incoming data
|
|
74
|
-
wrapper[0] // Pipe to the wrapper
|
|
75
|
-
);
|
|
76
|
-
return {
|
|
77
|
-
conn: {
|
|
78
|
-
...wrapper[1],
|
|
79
|
-
close: async () => { },
|
|
80
|
-
localAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4001'),
|
|
81
|
-
remoteAddr: new Multiaddr('/ip4/127.0.0.1/tcp/4002'),
|
|
82
|
-
timeline: {
|
|
83
|
-
open: Date.now()
|
|
84
|
-
},
|
|
85
|
-
conn: true
|
|
86
|
-
},
|
|
87
|
-
remotePeer: PeerId.fromBytes(remoteId.slice()),
|
|
88
|
-
remoteEarlyData: new Uint8Array(0)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
export default crypto;
|
|
93
|
-
//# sourceMappingURL=mock-crypto.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-crypto.js","sourceRoot":"","sources":["../../../test/crypto/mock-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC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AE3B,IAAI,CACF,OAAO,CAAC,CAAC,CAAC,EAAE,sBAAsB;QAClC,OAAO,EAAE,wBAAwB;QACjC,KAAK,CAAC,MAAM,EAAE,6BAA6B;QAC3C,OAAO,EAAE,4BAA4B;QACrC,OAAO,CAAC,CAAC,CAAC,CAAC,sBAAsB;SAClC,CAAA;QAED,OAAO;YACL,IAAI,EAAE;gBACJ,GAAG,OAAO,CAAC,CAAC,CAAC;gBACb,KAAK,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;gBACrB,SAAS,EAAE,IAAI,SAAS,CAAC,yBAAyB,CAAC;gBACnD,UAAU,EAAE,IAAI,SAAS,CAAC,yBAAyB,CAAC;gBACpD,QAAQ,EAAE;oBACR,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;iBACjB;gBACD,IAAI,EAAE,IAAI;aACX;YACD,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC9C,eAAe,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC;SACnC,CAAA;IACH,CAAC;CACF,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../../test/peer-discovery/index.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import tests from '../../src/peer-discovery/index.js';
|
|
2
|
-
import { MockDiscovery } from './mock-discovery.js';
|
|
3
|
-
describe('compliance tests', () => {
|
|
4
|
-
let intervalId;
|
|
5
|
-
tests({
|
|
6
|
-
async setup() {
|
|
7
|
-
const mockDiscovery = new MockDiscovery({
|
|
8
|
-
discoveryDelay: 1
|
|
9
|
-
});
|
|
10
|
-
intervalId = setInterval(mockDiscovery._discoverPeer, 1000);
|
|
11
|
-
return mockDiscovery;
|
|
12
|
-
},
|
|
13
|
-
async teardown() {
|
|
14
|
-
clearInterval(intervalId);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
//# sourceMappingURL=index.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../test/peer-discovery/index.spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,mCAAmC,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,UAAe,CAAA;IAEnB,KAAK,CAAC;QACJ,KAAK,CAAC,KAAK;YACT,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;gBACtC,cAAc,EAAE,CAAC;aAClB,CAAC,CAAA;YAEF,UAAU,GAAG,WAAW,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;YAE3D,OAAO,aAAa,CAAA;QACtB,CAAC;QACD,KAAK,CAAC,QAAQ;YACZ,aAAa,CAAC,UAAU,CAAC,CAAA;QAC3B,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
interface MockDiscoveryOptions {
|
|
4
|
-
discoveryDelay?: number;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Emits 'peer' events on discovery.
|
|
8
|
-
*/
|
|
9
|
-
export declare class MockDiscovery extends EventEmitter {
|
|
10
|
-
readonly options: MockDiscoveryOptions;
|
|
11
|
-
private _isRunning;
|
|
12
|
-
private _timer;
|
|
13
|
-
constructor(options?: {});
|
|
14
|
-
start(): void;
|
|
15
|
-
stop(): void;
|
|
16
|
-
isStarted(): boolean;
|
|
17
|
-
_discoverPeer(): void;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
20
|
-
//# sourceMappingURL=mock-discovery.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-discovery.d.ts","sourceRoot":"","sources":["../../../test/peer-discovery/mock-discovery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAIrC,UAAU,oBAAoB;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAC7C,SAAgB,OAAO,EAAE,oBAAoB,CAAA;IAC7C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAK;gBAEN,OAAO,KAAK;IAOzB,KAAK;IAKL,IAAI;IAKJ,SAAS;IAIT,aAAa;CAcd"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
-
import * as PeerIdFactory from '@libp2p/peer-id-factory';
|
|
4
|
-
/**
|
|
5
|
-
* Emits 'peer' events on discovery.
|
|
6
|
-
*/
|
|
7
|
-
export class MockDiscovery extends EventEmitter {
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
super();
|
|
10
|
-
this.options = options;
|
|
11
|
-
this._isRunning = false;
|
|
12
|
-
}
|
|
13
|
-
start() {
|
|
14
|
-
this._isRunning = true;
|
|
15
|
-
this._discoverPeer();
|
|
16
|
-
}
|
|
17
|
-
stop() {
|
|
18
|
-
clearTimeout(this._timer);
|
|
19
|
-
this._isRunning = false;
|
|
20
|
-
}
|
|
21
|
-
isStarted() {
|
|
22
|
-
return this._isRunning;
|
|
23
|
-
}
|
|
24
|
-
_discoverPeer() {
|
|
25
|
-
if (!this._isRunning)
|
|
26
|
-
return;
|
|
27
|
-
PeerIdFactory.createEd25519PeerId()
|
|
28
|
-
.then(peerId => {
|
|
29
|
-
this._timer = setTimeout(() => {
|
|
30
|
-
this.emit('peer', {
|
|
31
|
-
id: peerId,
|
|
32
|
-
multiaddrs: [new Multiaddr('/ip4/127.0.0.1/tcp/8000')]
|
|
33
|
-
});
|
|
34
|
-
}, this.options.discoveryDelay ?? 1000);
|
|
35
|
-
})
|
|
36
|
-
.catch(() => { });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=mock-discovery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-discovery.js","sourceRoot":"","sources":["../../../test/peer-discovery/mock-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AAMxD;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAK7C,YAAa,OAAO,GAAG,EAAE;QACvB,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAA;IACzB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACtB,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC;IAED,IAAI;QACF,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAA;IACzB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED,aAAa;QACX,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAM;QAE5B,aAAa,CAAC,mBAAmB,EAAE;aAChC,IAAI,CAAC,MAAM,CAAC,EAAE;YACb,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;oBAChB,EAAE,EAAE,MAAM;oBACV,UAAU,EAAE,CAAC,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;iBACvD,CAAC,CAAA;YACJ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC,CAAA;QACzC,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACpB,CAAC;CACF"}
|