mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 05:52:29 +00:00
Fix libp2p-crypto imports
This commit is contained in:
parent
17f8fb3140
commit
296c5dbe5b
@ -2,7 +2,7 @@ import hkdf from 'futoin-hkdf';
|
|||||||
import {box} from 'tweetnacl';
|
import {box} from 'tweetnacl';
|
||||||
import {Buffer} from "buffer";
|
import {Buffer} from "buffer";
|
||||||
import PeerId from "peer-id";
|
import PeerId from "peer-id";
|
||||||
import * as crypto from 'libp2p-crypto';
|
import {keys} from 'libp2p-crypto';
|
||||||
import {KeyPair} from "./@types/libp2p";
|
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";
|
||||||
@ -93,7 +93,7 @@ export async function verifySignedPayload(
|
|||||||
}
|
}
|
||||||
const generatedPayload = getHandshakePayload(noiseStaticKey);
|
const generatedPayload = getHandshakePayload(noiseStaticKey);
|
||||||
// Unmarshaling from PublicKey protobuf
|
// Unmarshaling from PublicKey protobuf
|
||||||
const publicKey = crypto.keys.unmarshalPublicKey(identityKey);
|
const publicKey = keys.unmarshalPublicKey(identityKey);
|
||||||
if (!publicKey.verify(generatedPayload, payload.identitySig)) {
|
if (!publicKey.verify(generatedPayload, payload.identitySig)) {
|
||||||
throw new Error("Static key doesn't match to peer that signed payload!");
|
throw new Error("Static key doesn't match to peer that signed payload!");
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import {Noise} from "../src";
|
|||||||
import {createPeerIdsFromFixtures} from "./fixtures/peer";
|
import {createPeerIdsFromFixtures} from "./fixtures/peer";
|
||||||
import Wrap from "it-pb-rpc";
|
import Wrap from "it-pb-rpc";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
import crypto from 'libp2p-crypto';
|
import {randomBytes} from 'libp2p-crypto';
|
||||||
import {XXHandshake} from "../src/handshake-xx";
|
import {XXHandshake} from "../src/handshake-xx";
|
||||||
import {createHandshakePayload, generateKeypair, getHandshakePayload, getPayload, signPayload} from "../src/utils";
|
import {createHandshakePayload, generateKeypair, getHandshakePayload, getPayload, signPayload} from "../src/utils";
|
||||||
import {decode0, decode2, encode1, uint16BEDecode, uint16BEEncode} from "../src/encoder";
|
import {decode0, decode2, encode1, uint16BEDecode, uint16BEEncode} from "../src/encoder";
|
||||||
@ -122,7 +122,7 @@ describe("Noise", () => {
|
|||||||
const wrappedInbound = Wrap(inbound.conn);
|
const wrappedInbound = Wrap(inbound.conn);
|
||||||
const wrappedOutbound = Wrap(outbound.conn);
|
const wrappedOutbound = Wrap(outbound.conn);
|
||||||
|
|
||||||
const largePlaintext = crypto.randomBytes(100000);
|
const largePlaintext = randomBytes(100000);
|
||||||
wrappedOutbound.writeLP(largePlaintext);
|
wrappedOutbound.writeLP(largePlaintext);
|
||||||
const response = await wrappedInbound.read(100000);
|
const response = await wrappedInbound.read(100000);
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as crypto from 'libp2p-crypto';
|
import {keys} from 'libp2p-crypto';
|
||||||
import {KeyPair, PeerId} from "../src/@types/libp2p";
|
import {KeyPair, PeerId} from "../src/@types/libp2p";
|
||||||
|
|
||||||
export async function generateEd25519Keys() {
|
export async function generateEd25519Keys() {
|
||||||
return await crypto.keys.generateKeyPair('ed25519');
|
return await keys.generateKeyPair('ed25519');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getKeyPairFromPeerId(peerId: PeerId): KeyPair {
|
export function getKeyPairFromPeerId(peerId: PeerId): KeyPair {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user