mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-09 13:51:30 +00:00
fix conflicts
This commit is contained in:
parent
8da430cdc5
commit
66e569cb65
@ -41,7 +41,7 @@
|
|||||||
"sinon": "^8.1.0"
|
"sinon": "^8.1.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypto": "5.1.0",
|
"bcrypto": "^5.2.0",
|
||||||
"buffer": "^5.4.3",
|
"buffer": "^5.4.3",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
"it-buffer": "^0.1.1",
|
"it-buffer": "^0.1.1",
|
||||||
@ -49,9 +49,10 @@
|
|||||||
"it-pair": "^1.0.0",
|
"it-pair": "^1.0.0",
|
||||||
"it-pb-rpc": "^0.1.8",
|
"it-pb-rpc": "^0.1.8",
|
||||||
"it-pipe": "^1.1.0",
|
"it-pipe": "^1.1.0",
|
||||||
"libp2p-crypto": "^0.17.6",
|
"libp2p-crypto": "^0.18.0",
|
||||||
"peer-id": "^0.13.5",
|
"peer-id": "^0.14.0",
|
||||||
"protobufjs": "6.8.8"
|
"protobufjs": "^6.10.1",
|
||||||
|
"uint8arrays": "^1.1.0"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"bn.js": "4.4.0"
|
"bn.js": "4.4.0"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { bytes, bytes32 } from './@types/basic'
|
import { bytes32 } from './@types/basic'
|
||||||
import PeerId from 'peer-id'
|
import PeerId from 'peer-id'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage for static keys of previously connected peers.
|
* Storage for static keys of previously connected peers.
|
||||||
*/
|
*/
|
||||||
class Keycache {
|
class Keycache {
|
||||||
private storage = new Map<bytes, bytes32>();
|
private storage = new Map<Uint8Array, bytes32>();
|
||||||
|
|
||||||
public store (peerId: PeerId, key: bytes32): void {
|
public store (peerId: PeerId, key: bytes32): void {
|
||||||
this.storage.set(peerId.id, key)
|
this.storage.set(peerId.id, key)
|
||||||
|
15
src/utils.ts
15
src/utils.ts
@ -8,6 +8,7 @@ import { KeyPair } from './@types/libp2p'
|
|||||||
import { bytes, bytes32 } from './@types/basic'
|
import { bytes, bytes32 } from './@types/basic'
|
||||||
import { Hkdf, INoisePayload } from './@types/handshake'
|
import { Hkdf, INoisePayload } from './@types/handshake'
|
||||||
import { pb } from './proto/payload'
|
import { pb } from './proto/payload'
|
||||||
|
import uint8ArrayEquals from 'uint8arrays/equals'
|
||||||
|
|
||||||
const NoiseHandshakePayloadProto = pb.NoiseHandshakePayload
|
const NoiseHandshakePayloadProto = pb.NoiseHandshakePayload
|
||||||
|
|
||||||
@ -37,12 +38,12 @@ export async function getPayload (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createHandshakePayload (
|
export function createHandshakePayload (
|
||||||
libp2pPublicKey: bytes,
|
libp2pPublicKey: Uint8Array,
|
||||||
signedPayload: bytes,
|
signedPayload: Uint8Array,
|
||||||
earlyData?: bytes
|
earlyData?: Uint8Array
|
||||||
): bytes {
|
): bytes {
|
||||||
const payloadInit = NoiseHandshakePayloadProto.create({
|
const payloadInit = NoiseHandshakePayloadProto.create({
|
||||||
identityKey: libp2pPublicKey,
|
identityKey: Buffer.from(libp2pPublicKey),
|
||||||
identitySig: signedPayload,
|
identitySig: signedPayload,
|
||||||
data: earlyData || null
|
data: earlyData || null
|
||||||
})
|
})
|
||||||
@ -51,7 +52,7 @@ export function createHandshakePayload (
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function signPayload (peerId: PeerId, payload: bytes): Promise<bytes> {
|
export async function signPayload (peerId: PeerId, payload: bytes): Promise<bytes> {
|
||||||
return await peerId.privKey.sign(payload)
|
return Buffer.from(await peerId.privKey.sign(payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPeerIdFromPayload (payload: pb.INoiseHandshakePayload): Promise<PeerId> {
|
export async function getPeerIdFromPayload (payload: pb.INoiseHandshakePayload): Promise<PeerId> {
|
||||||
@ -68,9 +69,9 @@ export function getHandshakePayload (publicKey: bytes): bytes {
|
|||||||
return Buffer.concat([Buffer.from('noise-libp2p-static-key:'), publicKey])
|
return Buffer.concat([Buffer.from('noise-libp2p-static-key:'), publicKey])
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isValidPeerId (peerId: bytes, publicKeyProtobuf: bytes) {
|
async function isValidPeerId (peerId: Uint8Array, publicKeyProtobuf: bytes) {
|
||||||
const generatedPeerId = await PeerId.createFromPubKey(publicKeyProtobuf)
|
const generatedPeerId = await PeerId.createFromPubKey(publicKeyProtobuf)
|
||||||
return generatedPeerId.id.equals(peerId)
|
return uint8ArrayEquals(generatedPeerId.id, peerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { KeyCache } from '../src/keycache'
|
import { KeyCache } from '../src/keycache'
|
||||||
import { createPeerIds, createPeerIdsFromFixtures } from './fixtures/peer'
|
import { createPeerIds, createPeerIdsFromFixtures } from './fixtures/peer'
|
||||||
|
import uint8ArrayEquals from 'uint8arrays/equals'
|
||||||
|
|
||||||
describe('KeyCache', () => {
|
describe('KeyCache', () => {
|
||||||
let peerA
|
let peerA
|
||||||
@ -14,7 +15,7 @@ describe('KeyCache', () => {
|
|||||||
const key = Buffer.from('this is id 007')
|
const key = Buffer.from('this is id 007')
|
||||||
await KeyCache.store(peerA, key)
|
await KeyCache.store(peerA, key)
|
||||||
const result = await KeyCache.load(peerA)
|
const result = await KeyCache.load(peerA)
|
||||||
assert(result?.equals(key), 'Stored and loaded key are not the same')
|
assert(uint8ArrayEquals(result, key), 'Stored and loaded key are not the same')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(false, `Test failed - ${e.message}`)
|
assert(false, `Test failed - ${e.message}`)
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import sinon from 'sinon'
|
|||||||
import BufferList from 'bl'
|
import BufferList from 'bl'
|
||||||
import { randomBytes } from 'libp2p-crypto'
|
import { randomBytes } from 'libp2p-crypto'
|
||||||
import { Buffer } from 'buffer'
|
import { Buffer } from 'buffer'
|
||||||
|
import uint8ArrayEquals from 'uint8arrays/equals'
|
||||||
|
|
||||||
import { Noise } from '../src'
|
import { Noise } from '../src'
|
||||||
import { XXHandshake } from '../src/handshake-xx'
|
import { XXHandshake } from '../src/handshake-xx'
|
||||||
@ -123,7 +124,7 @@ describe('Noise', () => {
|
|||||||
const wrappedOutbound = Wrap(outbound.conn)
|
const wrappedOutbound = Wrap(outbound.conn)
|
||||||
|
|
||||||
const largePlaintext = randomBytes(100000)
|
const largePlaintext = randomBytes(100000)
|
||||||
wrappedOutbound.writeLP(largePlaintext)
|
wrappedOutbound.writeLP(Buffer.from(largePlaintext))
|
||||||
const response = await wrappedInbound.read(100000)
|
const response = await wrappedInbound.read(100000)
|
||||||
|
|
||||||
expect(response.length).equals(largePlaintext.length)
|
expect(response.length).equals(largePlaintext.length)
|
||||||
@ -203,7 +204,7 @@ describe('Noise', () => {
|
|||||||
const noiseInit = new Noise(staticKeysInitiator.privateKey)
|
const noiseInit = new Noise(staticKeysInitiator.privateKey)
|
||||||
|
|
||||||
const staticKeysResponder = generateKeypair()
|
const staticKeysResponder = generateKeypair()
|
||||||
const noiseResp = new Noise(staticKeysResponder.privateKey, undefined, false)
|
const noiseResp = new Noise(staticKeysResponder.privateKey, undefined)
|
||||||
const xxSpy = sandbox.spy(noiseInit, 'performXXFallbackHandshake')
|
const xxSpy = sandbox.spy(noiseInit, 'performXXFallbackHandshake')
|
||||||
|
|
||||||
// Prepare key cache for noise pipes
|
// Prepare key cache for noise pipes
|
||||||
@ -232,7 +233,7 @@ describe('Noise', () => {
|
|||||||
it.skip('Initiator starts with XX (pipes disabled), responder has enabled noise pipes', async () => {
|
it.skip('Initiator starts with XX (pipes disabled), responder has enabled noise pipes', async () => {
|
||||||
try {
|
try {
|
||||||
const staticKeysInitiator = generateKeypair()
|
const staticKeysInitiator = generateKeypair()
|
||||||
const noiseInit = new Noise(staticKeysInitiator.privateKey, undefined, false)
|
const noiseInit = new Noise(staticKeysInitiator.privateKey, undefined)
|
||||||
const staticKeysResponder = generateKeypair()
|
const staticKeysResponder = generateKeypair()
|
||||||
|
|
||||||
const noiseResp = new Noise(staticKeysResponder.privateKey)
|
const noiseResp = new Noise(staticKeysResponder.privateKey)
|
||||||
@ -323,8 +324,8 @@ describe('Noise', () => {
|
|||||||
const response = await wrappedInbound.readLP()
|
const response = await wrappedInbound.readLP()
|
||||||
expect(response.toString()).equal('test v2')
|
expect(response.toString()).equal('test v2')
|
||||||
|
|
||||||
assert(inbound.remotePeer.marshalPubKey().equals(localPeer.marshalPubKey()))
|
assert(uint8ArrayEquals(inbound.remotePeer.marshalPubKey(), localPeer.marshalPubKey()))
|
||||||
assert(outbound.remotePeer.marshalPubKey().equals(remotePeer.marshalPubKey()))
|
assert(uint8ArrayEquals(outbound.remotePeer.marshalPubKey(), remotePeer.marshalPubKey()))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert(false, e.message)
|
assert(false, e.message)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user