Encrypt Public Key Messages using symmetric encryption

This commit is contained in:
Franck Royer 2021-08-26 15:24:57 +10:00
parent 2f2eada322
commit 5af6d84852
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
5 changed files with 22 additions and 3 deletions

View File

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Examples (eth-pm): Encrypt Public Key Messages using symmetric encryption.
### Changed
- **Breaking**: Moved `startTime` and `endTime` for history queries to a `timeFilter` property as both or neither must be passed; passing only one parameter is not supported.

View File

@ -7,6 +7,7 @@
- Waku Light Push
- Signature with Web3
- Asymmetric Encryption
- Symmetric Encryption
A PoC implementation of [20/ETH-DM](https://rfc.vac.dev/spec/20/).

View File

@ -3,7 +3,7 @@ import '@ethersproject/shims';
import React, { useEffect, useState } from 'react';
import './App.css';
import { Waku } from 'js-waku';
import { KeyPair } from './crypto';
import { KeyPair, PublicKeyMessageEncryptionKey } from './crypto';
import { Message } from './messaging/Messages';
import 'fontsource-roboto';
import { AppBar, IconButton, Toolbar, Typography } from '@material-ui/core';
@ -108,10 +108,13 @@ function App() {
setPublicKeys
);
waku.relay.addDecryptionKey(PublicKeyMessageEncryptionKey);
waku.relay.addObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
return function cleanUp() {
if (!waku) return;
waku.relay.deleteDecryptionKey(PublicKeyMessageEncryptionKey);
waku.relay.deleteObserver(observerPublicKeyMessage, [
PublicKeyContentTopic,
]);

View File

@ -1,6 +1,10 @@
import { Button } from '@material-ui/core';
import React, { useState } from 'react';
import { createPublicKeyMessage, KeyPair } from './crypto';
import {
createPublicKeyMessage,
KeyPair,
PublicKeyMessageEncryptionKey,
} from './crypto';
import { PublicKeyMessage } from './messaging/wire';
import { WakuMessage, Waku } from 'js-waku';
import { PublicKeyContentTopic } from './waku';
@ -84,5 +88,7 @@ async function encodePublicKeyWakuMessage(
publicKeyMessage: PublicKeyMessage
): Promise<WakuMessage> {
const payload = publicKeyMessage.encode();
return await WakuMessage.fromBytes(payload, PublicKeyContentTopic);
return await WakuMessage.fromBytes(payload, PublicKeyContentTopic, {
symKey: PublicKeyMessageEncryptionKey,
});
}

View File

@ -4,6 +4,12 @@ import { PublicKeyMessage } from './messaging/wire';
import { hexToBuf, equalByteArrays, bufToHex } from 'js-waku/lib/utils';
import { generatePrivateKey, getPublicKey } from 'js-waku';
import * as sigUtil from 'eth-sig-util';
import { PublicKeyContentTopic } from './waku';
import { keccak256 } from 'ethers/lib/utils';
export const PublicKeyMessageEncryptionKey = hexToBuf(
keccak256(Buffer.from(PublicKeyContentTopic, 'utf-8'))
);
export interface KeyPair {
privateKey: Uint8Array;