From 296c5dbe5b261de04188e999c0ac3cd5bd0ecf80 Mon Sep 17 00:00:00 2001 From: Matija Petrunic Date: Thu, 9 Apr 2020 11:09:00 +0200 Subject: [PATCH] Fix libp2p-crypto imports --- src/utils.ts | 4 ++-- test/noise.test.ts | 4 ++-- test/utils.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 751a9a5..22fb423 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,7 @@ import hkdf from 'futoin-hkdf'; import {box} from 'tweetnacl'; import {Buffer} from "buffer"; import PeerId from "peer-id"; -import * as crypto from 'libp2p-crypto'; +import {keys} from 'libp2p-crypto'; import {KeyPair} from "./@types/libp2p"; import {bytes, bytes32} from "./@types/basic"; import {Hkdf, INoisePayload} from "./@types/handshake"; @@ -93,7 +93,7 @@ export async function verifySignedPayload( } const generatedPayload = getHandshakePayload(noiseStaticKey); // Unmarshaling from PublicKey protobuf - const publicKey = crypto.keys.unmarshalPublicKey(identityKey); + const publicKey = keys.unmarshalPublicKey(identityKey); if (!publicKey.verify(generatedPayload, payload.identitySig)) { throw new Error("Static key doesn't match to peer that signed payload!"); } diff --git a/test/noise.test.ts b/test/noise.test.ts index b363721..d8e7f84 100644 --- a/test/noise.test.ts +++ b/test/noise.test.ts @@ -4,7 +4,7 @@ import {Noise} from "../src"; import {createPeerIdsFromFixtures} from "./fixtures/peer"; import Wrap from "it-pb-rpc"; import sinon from "sinon"; -import crypto from 'libp2p-crypto'; +import {randomBytes} from 'libp2p-crypto'; import {XXHandshake} from "../src/handshake-xx"; import {createHandshakePayload, generateKeypair, getHandshakePayload, getPayload, signPayload} from "../src/utils"; import {decode0, decode2, encode1, uint16BEDecode, uint16BEEncode} from "../src/encoder"; @@ -122,7 +122,7 @@ describe("Noise", () => { const wrappedInbound = Wrap(inbound.conn); const wrappedOutbound = Wrap(outbound.conn); - const largePlaintext = crypto.randomBytes(100000); + const largePlaintext = randomBytes(100000); wrappedOutbound.writeLP(largePlaintext); const response = await wrappedInbound.read(100000); diff --git a/test/utils.ts b/test/utils.ts index 2ac5b7b..63206ef 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,8 +1,8 @@ -import * as crypto from 'libp2p-crypto'; +import {keys} from 'libp2p-crypto'; import {KeyPair, PeerId} from "../src/@types/libp2p"; export async function generateEd25519Keys() { - return await crypto.keys.generateKeyPair('ed25519'); + return await keys.generateKeyPair('ed25519'); } export function getKeyPairFromPeerId(peerId: PeerId): KeyPair {