mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-08-01 01:12:04 +00:00
lint fixes
This commit is contained in:
10
test/fixtures/peer.ts
vendored
10
test/fixtures/peer.ts
vendored
@@ -19,16 +19,16 @@ const peers = [{
|
||||
pubKey: 'CAESIMbnikZaPciAMZhUXqDRVCs7VFOBtmlIk26g0GgOotDA'
|
||||
}]
|
||||
|
||||
export async function createPeerIdsFromFixtures (length) {
|
||||
return Promise.all(
|
||||
export async function createPeerIdsFromFixtures (length:number): Promise<PeerId[]> {
|
||||
return await Promise.all(
|
||||
Array.from({ length }).map((_, i) => PeerId.createFromJSON(peers[i]))
|
||||
)
|
||||
}
|
||||
|
||||
export async function createPeerIds (length) {
|
||||
const peerIds: any[] = []
|
||||
export async function createPeerIds (length: number): Promise<PeerId[]> {
|
||||
const peerIds: PeerId[] = []
|
||||
for (let i = 0; i < length; i++) {
|
||||
const id = await PeerId.create({ keyType: 'ed25519', bits: 256 })
|
||||
const id = await PeerId.create({ keyType: 'Ed25519', bits: 256 })
|
||||
peerIds.push(id)
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@ describe('IK handshake', () => {
|
||||
|
||||
// initiator creates payload
|
||||
const initSignedPayload = await libp2pInitKeys.sign(getHandshakePayload(kpInitiator.publicKey))
|
||||
const libp2pInitPrivKey = libp2pInitKeys.marshal().slice(0, 32)
|
||||
libp2pInitKeys.marshal().slice(0, 32)
|
||||
const libp2pInitPubKey = libp2pInitKeys.marshal().slice(32, 64)
|
||||
const payloadInitEnc = await createHandshakePayload(libp2pInitPubKey, initSignedPayload)
|
||||
|
||||
@@ -40,12 +40,12 @@ describe('IK handshake', () => {
|
||||
expect(messageBuffer.ne.length).not.equal(0)
|
||||
|
||||
// responder receives message
|
||||
const plaintext = ikR.recvMessage(responderSession, messageBuffer)
|
||||
ikR.recvMessage(responderSession, messageBuffer)
|
||||
|
||||
/* Stage 1 */
|
||||
|
||||
// responder creates payload
|
||||
const libp2pRespPrivKey = libp2pRespKeys.marshal().slice(0, 32)
|
||||
libp2pRespKeys.marshal().slice(0, 32)
|
||||
const libp2pRespPubKey = libp2pRespKeys.marshal().slice(32, 64)
|
||||
const respSignedPayload = await libp2pRespKeys.sign(getHandshakePayload(kpResponder.publicKey))
|
||||
const payloadRespEnc = await createHandshakePayload(libp2pRespPubKey, respSignedPayload)
|
||||
@@ -54,12 +54,11 @@ describe('IK handshake', () => {
|
||||
const messageBuffer2 = ikR.sendMessage(responderSession, message1)
|
||||
|
||||
// initiator receives message
|
||||
const plaintext2 = ikI.recvMessage(initiatorSession, messageBuffer2)
|
||||
ikI.recvMessage(initiatorSession, messageBuffer2)
|
||||
|
||||
assert(initiatorSession.cs1.k.equals(responderSession.cs1.k))
|
||||
assert(initiatorSession.cs2.k.equals(responderSession.cs2.k))
|
||||
assert(initiatorSession?.cs1?.k.equals(responderSession?.cs1?.k || new Uint8Array()))
|
||||
assert(initiatorSession?.cs2?.k.equals(responderSession?.cs2?.k || new Uint8Array()))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return assert(false, e.message)
|
||||
}
|
||||
})
|
||||
|
@@ -14,15 +14,15 @@ describe('XX Handshake', () => {
|
||||
const xx = new XX()
|
||||
|
||||
const kpInitiator: KeyPair = await generateKeypair()
|
||||
const kpResponder: KeyPair = await generateKeypair()
|
||||
await generateKeypair()
|
||||
|
||||
const session = await xx.initSession(true, prologue, kpInitiator)
|
||||
await xx.initSession(true, prologue, kpInitiator)
|
||||
} catch (e) {
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
|
||||
it('Test get HKDF', async () => {
|
||||
it('Test get HKDF', () => {
|
||||
const ckBytes = Buffer.from('4e6f6973655f58585f32353531395f58436861436861506f6c795f53484132353600000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||
const ikm = Buffer.from('a3eae50ea37a47e8a7aa0c7cd8e16528670536dcd538cebfd724fb68ce44f1910ad898860666227d4e8dd50d22a9a64d1c0a6f47ace092510161e9e442953da3', 'hex')
|
||||
const ck = Buffer.alloc(32)
|
||||
@@ -54,7 +54,7 @@ describe('XX Handshake', () => {
|
||||
/* STAGE 0 */
|
||||
|
||||
// initiator creates payload
|
||||
const libp2pInitPrivKey = libp2pInitKeys.marshal().slice(0, 32)
|
||||
libp2pInitKeys.marshal().slice(0, 32)
|
||||
const libp2pInitPubKey = libp2pInitKeys.marshal().slice(32, 64)
|
||||
|
||||
const payloadInitEnc = await createHandshakePayload(libp2pInitPubKey, initSignedPayload)
|
||||
@@ -71,7 +71,7 @@ describe('XX Handshake', () => {
|
||||
/* STAGE 1 */
|
||||
|
||||
// responder creates payload
|
||||
const libp2pRespPrivKey = libp2pRespKeys.marshal().slice(0, 32)
|
||||
libp2pRespKeys.marshal().slice(0, 32)
|
||||
const libp2pRespPubKey = libp2pRespKeys.marshal().slice(32, 64)
|
||||
const payloadRespEnc = await createHandshakePayload(libp2pRespPubKey, respSignedPayload)
|
||||
|
||||
|
@@ -8,10 +8,10 @@ import { generateKeypair, getPayload } from '../src/utils'
|
||||
import { IKHandshake } from '../src/handshake-ik'
|
||||
|
||||
describe('IK Handshake', () => {
|
||||
let peerA, peerB, fakePeer
|
||||
let peerA, peerB
|
||||
|
||||
before(async () => {
|
||||
[peerA, peerB, fakePeer] = await createPeerIdsFromFixtures(3)
|
||||
[peerA, peerB] = await createPeerIdsFromFixtures(3)
|
||||
})
|
||||
|
||||
it('should finish both stages as initiator and responder', async () => {
|
||||
@@ -49,7 +49,6 @@ describe('IK Handshake', () => {
|
||||
const { plaintext: decrypted } = handshakeResp.decrypt(encrypted, handshakeResp.session)
|
||||
assert(decrypted.equals(Buffer.from('encryptthis')))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { expect, assert } from 'chai'
|
||||
import { assert } from 'chai'
|
||||
import { KeyCache } from '../src/keycache'
|
||||
import { createPeerIds, createPeerIdsFromFixtures } from './fixtures/peer'
|
||||
|
||||
describe('KeyCache', () => {
|
||||
let peerA, peerB
|
||||
let peerA
|
||||
|
||||
before(async () => {
|
||||
[peerA, peerB] = await createPeerIdsFromFixtures(2)
|
||||
[peerA] = await createPeerIdsFromFixtures(2)
|
||||
})
|
||||
|
||||
it('should store and load same key successfully', async () => {
|
||||
@@ -14,9 +14,8 @@ describe('KeyCache', () => {
|
||||
const key = Buffer.from('this is id 007')
|
||||
await KeyCache.store(peerA, key)
|
||||
const result = await KeyCache.load(peerA)
|
||||
assert(result.equals(key), 'Stored and loaded key are not the same')
|
||||
assert(result?.equals(key), 'Stored and loaded key are not the same')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, `Test failed - ${e.message}`)
|
||||
}
|
||||
})
|
||||
@@ -27,7 +26,6 @@ describe('KeyCache', () => {
|
||||
const result = await KeyCache.load(newPeer)
|
||||
assert(!result)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, `Test failed - ${e.message}`)
|
||||
}
|
||||
})
|
||||
|
@@ -30,8 +30,8 @@ describe('Noise', () => {
|
||||
|
||||
it('should communicate through encrypted streams without noise pipes', async () => {
|
||||
try {
|
||||
const noiseInit = new Noise(undefined, undefined, false)
|
||||
const noiseResp = new Noise(undefined, undefined, false)
|
||||
const noiseInit = new Noise(undefined, undefined)
|
||||
const noiseResp = new Noise(undefined, undefined)
|
||||
|
||||
const [inboundConnection, outboundConnection] = DuplexPair()
|
||||
const [outbound, inbound] = await Promise.all([
|
||||
@@ -50,7 +50,7 @@ describe('Noise', () => {
|
||||
})
|
||||
|
||||
it('should test that secureOutbound is spec compliant', async () => {
|
||||
const noiseInit = new Noise(undefined, undefined, false)
|
||||
const noiseInit = new Noise(undefined, undefined)
|
||||
const [inboundConnection, outboundConnection] = DuplexPair()
|
||||
|
||||
const [outbound, { wrapped, handshake }] = await Promise.all([
|
||||
@@ -111,8 +111,8 @@ describe('Noise', () => {
|
||||
it('should test large payloads', async function () {
|
||||
this.timeout(10000)
|
||||
try {
|
||||
const noiseInit = new Noise(undefined, undefined, false)
|
||||
const noiseResp = new Noise(undefined, undefined, false)
|
||||
const noiseInit = new Noise(undefined, undefined)
|
||||
const noiseResp = new Noise(undefined, undefined)
|
||||
|
||||
const [inboundConnection, outboundConnection] = DuplexPair()
|
||||
const [outbound, inbound] = await Promise.all([
|
||||
@@ -128,7 +128,6 @@ describe('Noise', () => {
|
||||
|
||||
expect(response.length).equals(largePlaintext.length)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
@@ -162,7 +161,6 @@ describe('Noise', () => {
|
||||
assert(xxSpy.notCalled)
|
||||
assert(xxFallbackSpy.notCalled)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
@@ -194,7 +192,6 @@ describe('Noise', () => {
|
||||
|
||||
assert(xxSpy.calledOnce, 'XX Fallback method was never called.')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
@@ -228,7 +225,6 @@ describe('Noise', () => {
|
||||
|
||||
assert(xxSpy.calledOnce, 'XX Fallback method was never called.')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
@@ -263,7 +259,6 @@ describe('Noise', () => {
|
||||
assert(xxInitSpy.calledOnce, 'XX method was never called.')
|
||||
assert(xxRespSpy.calledOnce, 'XX Fallback method was never called.')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
@@ -301,7 +296,6 @@ describe('Noise', () => {
|
||||
assert(ikRespSpy.calledOnce, 'IK handshake was not called.')
|
||||
assert(xxFallbackInitSpy.notCalled, 'XX Fallback method was called.')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
@@ -332,7 +326,6 @@ describe('Noise', () => {
|
||||
assert(inbound.remotePeer.marshalPubKey().equals(localPeer.marshalPubKey()))
|
||||
assert(outbound.remotePeer.marshalPubKey().equals(remotePeer.marshalPubKey()))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
@@ -358,7 +351,6 @@ describe('Noise', () => {
|
||||
assert(inbound.remoteEarlyData.equals(localPeerEarlyData))
|
||||
assert(outbound.remoteEarlyData.equals(Buffer.alloc(0)))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { keys } from 'libp2p-crypto'
|
||||
import { keys, PrivateKey } from 'libp2p-crypto'
|
||||
import { KeyPair } from '../src/@types/libp2p'
|
||||
import PeerId from 'peer-id'
|
||||
|
||||
export async function generateEd25519Keys () {
|
||||
return await keys.generateKeyPair('ed25519')
|
||||
export async function generateEd25519Keys (): Promise<PrivateKey> {
|
||||
return await keys.generateKeyPair('Ed25519', 32)
|
||||
}
|
||||
|
||||
export function getKeyPairFromPeerId (peerId: PeerId): KeyPair {
|
||||
|
@@ -9,10 +9,10 @@ import {
|
||||
import { XXFallbackHandshake } from '../src/handshake-xx-fallback'
|
||||
import { createPeerIdsFromFixtures } from './fixtures/peer'
|
||||
import { assert } from 'chai'
|
||||
import { decode1, encode0, encode1 } from '../src/encoder'
|
||||
import { encode0 } from '../src/encoder'
|
||||
|
||||
describe('XX Fallback Handshake', () => {
|
||||
let peerA, peerB, fakePeer
|
||||
let peerA, peerB
|
||||
|
||||
before(async () => {
|
||||
[peerA, peerB] = await createPeerIdsFromFixtures(2)
|
||||
@@ -67,7 +67,6 @@ describe('XX Fallback Handshake', () => {
|
||||
assert(false)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
assert(false, e.message)
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user