Skip to content

Commit

Permalink
Merge pull request #78 from ChainSafe/cayman/fix-ephem-pubkey
Browse files Browse the repository at this point in the history
Fix ephem pubkey
  • Loading branch information
wemeetagain committed Aug 3, 2020
2 parents 06331b9 + 2074049 commit a774fce
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/session/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
IAuthResponse,
Nonce,
} from "../packet";
import { generateKeypair, IKeypair, createKeypair } from "../keypair";
import { generateKeypair, IKeypair, createKeypair, KeypairType, secp256k1PublicKeyToRaw } from "../keypair";
import { fromHex } from "../util";

// Implementation for generating session keys in the Discv5 protocol.
Expand All @@ -36,12 +36,11 @@ export function generateSessionKeys(localId: NodeId, remoteEnr: ENR, idNonce: No
const remoteKeypair = remoteEnr.keypair;
const ephemKeypair = generateKeypair(remoteKeypair.type);
const secret = ephemKeypair.deriveSecret(remoteKeypair);
return [...deriveKey(secret, localId, remoteEnr.nodeId, idNonce), ephemKeypair.publicKey] as [
Buffer,
Buffer,
Buffer,
Buffer
];
const ephemPubkey =
remoteKeypair.type === KeypairType.secp256k1
? secp256k1PublicKeyToRaw(ephemKeypair.publicKey)
: ephemKeypair.publicKey;
return [...deriveKey(secret, localId, remoteEnr.nodeId, idNonce), ephemPubkey] as [Buffer, Buffer, Buffer, Buffer];
}

export function deriveKey(secret: Buffer, firstId: NodeId, secondId: NodeId, idNonce: Nonce): [Buffer, Buffer, Buffer] {
Expand Down

0 comments on commit a774fce

Please sign in to comment.