mirror of https://github.com/waku-org/js-waku.git
Merge pull request #282 from status-im/encrypt-eth-pm
This commit is contained in:
commit
6dd54d2458
|
@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Examples (eth-pm): Encrypt Public Key Messages using symmetric encryption.
|
||||||
|
|
||||||
### Changed
|
### 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.
|
- **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.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Buffer concat error when using symmetric encryption in the browser.
|
||||||
|
|
||||||
## [0.11.0] - 2021-08-20
|
## [0.11.0] - 2021-08-20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
- Waku Light Push
|
- Waku Light Push
|
||||||
- Signature with Web3
|
- Signature with Web3
|
||||||
- Asymmetric Encryption
|
- Asymmetric Encryption
|
||||||
|
- Symmetric Encryption
|
||||||
|
|
||||||
A PoC implementation of [20/ETH-DM](https://rfc.vac.dev/spec/20/).
|
A PoC implementation of [20/ETH-DM](https://rfc.vac.dev/spec/20/).
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import '@ethersproject/shims';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import { Waku } from 'js-waku';
|
import { Waku } from 'js-waku';
|
||||||
import { KeyPair } from './crypto';
|
import { KeyPair, PublicKeyMessageEncryptionKey } from './crypto';
|
||||||
import { Message } from './messaging/Messages';
|
import { Message } from './messaging/Messages';
|
||||||
import 'fontsource-roboto';
|
import 'fontsource-roboto';
|
||||||
import { AppBar, IconButton, Toolbar, Typography } from '@material-ui/core';
|
import { AppBar, IconButton, Toolbar, Typography } from '@material-ui/core';
|
||||||
|
@ -108,10 +108,13 @@ function App() {
|
||||||
setPublicKeys
|
setPublicKeys
|
||||||
);
|
);
|
||||||
|
|
||||||
|
waku.relay.addDecryptionKey(PublicKeyMessageEncryptionKey);
|
||||||
waku.relay.addObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
|
waku.relay.addObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
|
||||||
|
|
||||||
return function cleanUp() {
|
return function cleanUp() {
|
||||||
if (!waku) return;
|
if (!waku) return;
|
||||||
|
|
||||||
|
waku.relay.deleteDecryptionKey(PublicKeyMessageEncryptionKey);
|
||||||
waku.relay.deleteObserver(observerPublicKeyMessage, [
|
waku.relay.deleteObserver(observerPublicKeyMessage, [
|
||||||
PublicKeyContentTopic,
|
PublicKeyContentTopic,
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { Button } from '@material-ui/core';
|
import { Button } from '@material-ui/core';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { createPublicKeyMessage, KeyPair } from './crypto';
|
import {
|
||||||
|
createPublicKeyMessage,
|
||||||
|
KeyPair,
|
||||||
|
PublicKeyMessageEncryptionKey,
|
||||||
|
} from './crypto';
|
||||||
import { PublicKeyMessage } from './messaging/wire';
|
import { PublicKeyMessage } from './messaging/wire';
|
||||||
import { WakuMessage, Waku } from 'js-waku';
|
import { WakuMessage, Waku } from 'js-waku';
|
||||||
import { PublicKeyContentTopic } from './waku';
|
import { PublicKeyContentTopic } from './waku';
|
||||||
|
@ -35,8 +39,8 @@ export default function BroadcastPublicKey({
|
||||||
console.error('Failed to send Public Key Message', e);
|
console.error('Failed to send Public Key Message', e);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((e) => {
|
||||||
console.log('Failed to encode Public Key Message in Waku Message');
|
console.log('Failed to encode Public Key Message in Waku Message', e);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
createPublicKeyMessage(
|
createPublicKeyMessage(
|
||||||
|
@ -55,9 +59,10 @@ export default function BroadcastPublicKey({
|
||||||
console.error('Failed to send Public Key Message', e);
|
console.error('Failed to send Public Key Message', e);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((e) => {
|
||||||
console.log(
|
console.log(
|
||||||
'Failed to encode Public Key Message in Waku Message'
|
'Failed to encode Public Key Message in Waku Message',
|
||||||
|
e
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -83,5 +88,7 @@ async function encodePublicKeyWakuMessage(
|
||||||
publicKeyMessage: PublicKeyMessage
|
publicKeyMessage: PublicKeyMessage
|
||||||
): Promise<WakuMessage> {
|
): Promise<WakuMessage> {
|
||||||
const payload = publicKeyMessage.encode();
|
const payload = publicKeyMessage.encode();
|
||||||
return await WakuMessage.fromBytes(payload, PublicKeyContentTopic);
|
return await WakuMessage.fromBytes(payload, PublicKeyContentTopic, {
|
||||||
|
symKey: PublicKeyMessageEncryptionKey,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,12 @@ import { PublicKeyMessage } from './messaging/wire';
|
||||||
import { hexToBuf, equalByteArrays, bufToHex } from 'js-waku/lib/utils';
|
import { hexToBuf, equalByteArrays, bufToHex } from 'js-waku/lib/utils';
|
||||||
import { generatePrivateKey, getPublicKey } from 'js-waku';
|
import { generatePrivateKey, getPublicKey } from 'js-waku';
|
||||||
import * as sigUtil from 'eth-sig-util';
|
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 {
|
export interface KeyPair {
|
||||||
privateKey: Uint8Array;
|
privateKey: Uint8Array;
|
||||||
|
|
|
@ -147,7 +147,7 @@ export async function encryptSymmetric(
|
||||||
|
|
||||||
// Returns `cipher | tag`
|
// Returns `cipher | tag`
|
||||||
const cipher = await symmetric.encrypt(iv, hexToBuf(key), Buffer.from(data));
|
const cipher = await symmetric.encrypt(iv, hexToBuf(key), Buffer.from(data));
|
||||||
return Buffer.concat([cipher, iv]);
|
return Buffer.concat([cipher, Buffer.from(iv)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue