mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-07 16:23:09 +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 { hexToBuf } from '../utils';
|
||||||
import { Waku } from '../waku';
|
import { Waku } from '../waku';
|
||||||
|
|
||||||
import { getPublicKey } from './version_1';
|
import { generatePrivateKey, getPublicKey } from './version_1';
|
||||||
|
|
||||||
import { DefaultContentTopic, WakuMessage } from './index';
|
import { DefaultContentTopic, WakuMessage } from './index';
|
||||||
|
|
||||||
@ -129,9 +129,7 @@ describe('Interop: Nim', function () {
|
|||||||
payload: Buffer.from(messageText, 'utf-8').toString('hex'),
|
payload: Buffer.from(messageText, 'utf-8').toString('hex'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const keyPair = await nimWaku.getAsymmetricKeyPair();
|
const privateKey = generatePrivateKey();
|
||||||
const privateKey = hexToBuf(keyPair.privateKey);
|
|
||||||
const publicKey = hexToBuf(keyPair.publicKey);
|
|
||||||
|
|
||||||
waku.relay.addDecryptionPrivateKey(privateKey);
|
waku.relay.addDecryptionPrivateKey(privateKey);
|
||||||
|
|
||||||
@ -139,6 +137,7 @@ describe('Interop: Nim', function () {
|
|||||||
waku.relay.addObserver(resolve);
|
waku.relay.addObserver(resolve);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const publicKey = getPublicKey(privateKey);
|
||||||
dbg('Post message');
|
dbg('Post message');
|
||||||
await nimWaku.postAsymmetricMessage(message, publicKey);
|
await nimWaku.postAsymmetricMessage(message, publicKey);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
|
import * as crypto from 'crypto';
|
||||||
|
|
||||||
import ecies from 'ecies-parity';
|
import ecies from 'ecies-parity';
|
||||||
import { keccak256 } from 'js-sha3';
|
import { keccak256 } from 'js-sha3';
|
||||||
@ -122,6 +123,13 @@ export async function decryptAsymmetric(
|
|||||||
return ecies.decrypt(Buffer.from(privKey), Buffer.from(payload));
|
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
|
* 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
|
// TypeScript Version: 2.1
|
||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
declare module 'ecies-parity' {
|
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.
|
// Compute the public key for a given private key.
|
||||||
export function getPublic(privateKey: Buffer): Buffer;
|
export function getPublic(privateKey: Buffer): Buffer;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user