mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-05 15:23:12 +00:00
Add API to generate keys
This commit is contained in:
parent
f123cd7e62
commit
22c716e0e6
@ -13,7 +13,7 @@ import { delay } from '../delay';
|
||||
import { hexToBuf } from '../utils';
|
||||
import { Waku } from '../waku';
|
||||
|
||||
import { getPublicKey } from './version_1';
|
||||
import { generatePrivateKey, getPublicKey } from './version_1';
|
||||
|
||||
import { DefaultContentTopic, WakuMessage } from './index';
|
||||
|
||||
@ -129,9 +129,7 @@ describe('Interop: Nim', function () {
|
||||
payload: Buffer.from(messageText, 'utf-8').toString('hex'),
|
||||
};
|
||||
|
||||
const keyPair = await nimWaku.getAsymmetricKeyPair();
|
||||
const privateKey = hexToBuf(keyPair.privateKey);
|
||||
const publicKey = hexToBuf(keyPair.publicKey);
|
||||
const privateKey = generatePrivateKey();
|
||||
|
||||
waku.relay.addDecryptionPrivateKey(privateKey);
|
||||
|
||||
@ -139,6 +137,7 @@ describe('Interop: Nim', function () {
|
||||
waku.relay.addObserver(resolve);
|
||||
});
|
||||
|
||||
const publicKey = getPublicKey(privateKey);
|
||||
dbg('Post message');
|
||||
await nimWaku.postAsymmetricMessage(message, publicKey);
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Buffer } from 'buffer';
|
||||
import { randomBytes } from 'crypto';
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
import ecies from 'ecies-parity';
|
||||
import { keccak256 } from 'js-sha3';
|
||||
@ -122,6 +123,13 @@ export async function decryptAsymmetric(
|
||||
return ecies.decrypt(Buffer.from(privKey), Buffer.from(payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new private key
|
||||
*/
|
||||
export function generatePrivateKey(): Uint8Array {
|
||||
return crypto.randomBytes(32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the public key for the given private key
|
||||
*/
|
||||
|
||||
3
src/types/ecies-parity.d.ts
vendored
3
src/types/ecies-parity.d.ts
vendored
@ -1,9 +1,6 @@
|
||||
// TypeScript Version: 2.1
|
||||
/// <reference types="node" />
|
||||
declare module 'ecies-parity' {
|
||||
// Generate a new valid private key. Will use crypto.randomBytes as source.
|
||||
export function generatePrivate(): Buffer;
|
||||
|
||||
// Compute the public key for a given private key.
|
||||
export function getPublic(privateKey: Buffer): Buffer;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user