mirror of https://github.com/status-im/js-waku.git
Generate fresh new keypair, do not use signature as entropy
This commit is contained in:
parent
bd0ad81d17
commit
93665feac8
|
@ -67,7 +67,7 @@ function App() {
|
||||||
if (ethDmKeyPair) return;
|
if (ethDmKeyPair) return;
|
||||||
if (!provider) return;
|
if (!provider) return;
|
||||||
|
|
||||||
generateEthDmKeyPair(provider.getSigner())
|
generateEthDmKeyPair()
|
||||||
.then((keyPair) => {
|
.then((keyPair) => {
|
||||||
setEthDmKeyPair(keyPair);
|
setEthDmKeyPair(keyPair);
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,9 +5,6 @@ import { ethers } from 'ethers';
|
||||||
import { Signer } from '@ethersproject/abstract-signer';
|
import { Signer } from '@ethersproject/abstract-signer';
|
||||||
import { PublicKeyMessage } from './messages';
|
import { PublicKeyMessage } from './messages';
|
||||||
|
|
||||||
const Salt =
|
|
||||||
'Salt for Eth-Dm, do not share a signature of this message or others could decrypt your messages';
|
|
||||||
|
|
||||||
export interface KeyPair {
|
export interface KeyPair {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
publicKey: string;
|
publicKey: string;
|
||||||
|
@ -19,15 +16,8 @@ export interface KeyPair {
|
||||||
* the entropy for the EthCrypto keypair. Note that the entropy is hashed with keccak256
|
* the entropy for the EthCrypto keypair. Note that the entropy is hashed with keccak256
|
||||||
* to make the private key.
|
* to make the private key.
|
||||||
*/
|
*/
|
||||||
export async function generateEthDmKeyPair(
|
export async function generateEthDmKeyPair(): Promise<KeyPair> {
|
||||||
web3Signer: Signer
|
return EthCrypto.createIdentity();
|
||||||
): Promise<KeyPair> {
|
|
||||||
const signature = await web3Signer.signMessage(Salt);
|
|
||||||
// Need to remove '0x' prefix to allow buffer to decode the hex string.
|
|
||||||
const sigBuf = Buffer.from(signature.slice(2), 'hex');
|
|
||||||
const entropy = Buffer.concat([sigBuf, sigBuf]);
|
|
||||||
const keys = EthCrypto.createIdentity(entropy);
|
|
||||||
return keys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue