Merge pull request #168 from waku-org/chore/@waku-core-0.0.8

This commit is contained in:
fryorcraken.eth 2022-12-21 15:41:52 +11:00 committed by GitHub
commit 047715670d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7002 additions and 920 deletions

View File

@ -9,10 +9,10 @@
"@material-ui/core": "^4.12.4", "@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3", "@material-ui/icons": "^4.11.3",
"@waku/byte-utils": "0.0.2", "@waku/byte-utils": "0.0.2",
"@waku/core": "0.0.6", "@waku/core": "^0.0.8",
"@waku/create": "0.0.4", "@waku/create": "^0.0.6",
"@waku/interfaces": "0.0.5", "@waku/interfaces": "^0.0.6",
"@waku/message-encryption": "0.0.4", "@waku/message-encryption": "^0.0.7",
"ethers": "5.7.1", "ethers": "5.7.1",
"fontsource-roboto": "^4.0.0", "fontsource-roboto": "^4.0.0",
"protobufjs": "^7.1.2", "protobufjs": "^7.1.2",

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,9 @@ import "@ethersproject/shims";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import "./App.css"; import "./App.css";
import type { WakuPrivacy } from "@waku/interfaces"; import type { RelayNode, IDecoder } from "@waku/interfaces";
import { AsymDecoder, SymDecoder } from "@waku/message-encryption"; import { createDecoder as createSymmetricDecoder } from "@waku/message-encryption/symmetric";
import { createDecoder, DecodedMessage } from "@waku/message-encryption/ecies";
import { KeyPair, PublicKeyMessageEncryptionKey } from "./crypto"; import { KeyPair, PublicKeyMessageEncryptionKey } from "./crypto";
import { Message } from "./messaging/Messages"; import { Message } from "./messaging/Messages";
import "fontsource-roboto"; import "fontsource-roboto";
@ -67,13 +68,13 @@ const useStyles = makeStyles({
}); });
function App() { function App() {
const [waku, setWaku] = useState<WakuPrivacy>(); const [waku, setWaku] = useState<RelayNode>();
const [provider, setProvider] = useState<Web3Provider>(); const [provider, setProvider] = useState<Web3Provider>();
const [encryptionKeyPair, setEncryptionKeyPair] = useState< const [encryptionKeyPair, setEncryptionKeyPair] = useState<
KeyPair | undefined KeyPair | undefined
>(); >();
const [privateMessageDecoder, setPrivateMessageDecoder] = const [privateMessageDecoder, setPrivateMessageDecoder] =
useState<AsymDecoder>(); useState<IDecoder<DecodedMessage>>();
const [publicKeys, setPublicKeys] = useState<Map<string, Uint8Array>>( const [publicKeys, setPublicKeys] = useState<Map<string, Uint8Array>>(
new Map() new Map()
); );
@ -109,7 +110,7 @@ function App() {
setPublicKeys setPublicKeys
); );
const publicKeyMessageDecoder = new SymDecoder( const publicKeyMessageDecoder = createSymmetricDecoder(
PublicKeyContentTopic, PublicKeyContentTopic,
PublicKeyMessageEncryptionKey PublicKeyMessageEncryptionKey
); );
@ -134,7 +135,7 @@ function App() {
if (!encryptionKeyPair) return; if (!encryptionKeyPair) return;
setPrivateMessageDecoder( setPrivateMessageDecoder(
new AsymDecoder(PrivateMessageContentTopic, encryptionKeyPair.privateKey) createDecoder(PrivateMessageContentTopic, encryptionKeyPair.privateKey)
); );
}, [encryptionKeyPair]); }, [encryptionKeyPair]);

View File

@ -6,14 +6,14 @@ import {
PublicKeyMessageEncryptionKey, PublicKeyMessageEncryptionKey,
} from "./crypto"; } from "./crypto";
import { PublicKeyMessage } from "./messaging/wire"; import { PublicKeyMessage } from "./messaging/wire";
import type { WakuPrivacy } from "@waku/interfaces"; import type { RelayNode } from "@waku/interfaces";
import { SymEncoder } from "@waku/message-encryption"; import { createEncoder } from "@waku/message-encryption/symmetric";
import { PublicKeyContentTopic } from "./waku"; import { PublicKeyContentTopic } from "./waku";
import type { TypedDataSigner } from "@ethersproject/abstract-signer"; import type { TypedDataSigner } from "@ethersproject/abstract-signer";
interface Props { interface Props {
encryptionKeyPair: KeyPair | undefined; encryptionKeyPair: KeyPair | undefined;
waku: WakuPrivacy | undefined; waku: RelayNode | undefined;
address: string | undefined; address: string | undefined;
signer: TypedDataSigner | undefined; signer: TypedDataSigner | undefined;
} }
@ -47,7 +47,7 @@ export default function BroadcastPublicKey({
})(); })();
const payload = _publicKeyMessage.encode(); const payload = _publicKeyMessage.encode();
const publicKeyMessageEncoder = new SymEncoder( const publicKeyMessageEncoder = createEncoder(
PublicKeyContentTopic, PublicKeyContentTopic,
PublicKeyMessageEncryptionKey PublicKeyMessageEncryptionKey
); );

View File

@ -1,5 +1,5 @@
import Messages, { Message } from "./Messages"; import Messages, { Message } from "./Messages";
import type { WakuPrivacy } from "@waku/interfaces"; import type { RelayNode } from "@waku/interfaces";
import SendMessage from "./SendMessage"; import SendMessage from "./SendMessage";
import { makeStyles } from "@material-ui/core"; import { makeStyles } from "@material-ui/core";
@ -13,7 +13,7 @@ const useStyles = makeStyles({
}); });
interface Props { interface Props {
waku: WakuPrivacy | undefined; waku: RelayNode | undefined;
recipients: Map<string, Uint8Array>; recipients: Map<string, Uint8Array>;
messages: Message[]; messages: Message[];
} }

View File

@ -7,8 +7,8 @@ import {
TextField, TextField,
} from "@material-ui/core"; } from "@material-ui/core";
import React, { ChangeEvent, useState, KeyboardEvent } from "react"; import React, { ChangeEvent, useState, KeyboardEvent } from "react";
import type { WakuPrivacy } from "@waku/interfaces"; import type { RelayNode } from "@waku/interfaces";
import { AsymEncoder } from "@waku/message-encryption"; import { createEncoder } from "@waku/message-encryption/ecies";
import { PrivateMessage } from "./wire"; import { PrivateMessage } from "./wire";
import { PrivateMessageContentTopic } from "../waku"; import { PrivateMessageContentTopic } from "../waku";
import { hexToBytes } from "@waku/byte-utils"; import { hexToBytes } from "@waku/byte-utils";
@ -24,7 +24,7 @@ const useStyles = makeStyles((theme) => ({
})); }));
export interface Props { export interface Props {
waku: WakuPrivacy | undefined; waku: RelayNode | undefined;
// address, public key // address, public key
recipients: Map<string, Uint8Array>; recipients: Map<string, Uint8Array>;
} }
@ -106,7 +106,7 @@ export default function SendMessage({ waku, recipients }: Props) {
} }
async function sendMessage( async function sendMessage(
waku: WakuPrivacy, waku: RelayNode,
recipientAddress: string, recipientAddress: string,
recipientPublicKey: Uint8Array, recipientPublicKey: Uint8Array,
message: string, message: string,
@ -118,10 +118,7 @@ async function sendMessage(
}); });
const payload = privateMessage.encode(); const payload = privateMessage.encode();
const encoder = new AsymEncoder( const encoder = createEncoder(PrivateMessageContentTopic, recipientPublicKey);
PrivateMessageContentTopic,
recipientPublicKey
);
console.log("pushing"); console.log("pushing");
const res = await waku.relay.send(encoder, { payload }); const res = await waku.relay.send(encoder, { payload });

View File

@ -1,19 +1,20 @@
import { Dispatch, SetStateAction } from "react"; import { Dispatch, SetStateAction } from "react";
import type { Message as WakuMessage, WakuPrivacy } from "@waku/interfaces"; import type { RelayNode } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
import { PrivateMessage, PublicKeyMessage } from "./messaging/wire"; import { PrivateMessage, PublicKeyMessage } from "./messaging/wire";
import { validatePublicKeyMessage } from "./crypto"; import { validatePublicKeyMessage } from "./crypto";
import { Message } from "./messaging/Messages"; import { Message } from "./messaging/Messages";
import { equals } from "uint8arrays/equals"; import { equals } from "uint8arrays/equals";
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer"; import { waitForRemotePeer } from "@waku/core";
import { createPrivacyNode } from "@waku/create"; import { createRelayNode } from "@waku/create";
import { bytesToHex, hexToBytes } from "@waku/byte-utils"; import { bytesToHex, hexToBytes } from "@waku/byte-utils";
import type { DecodedMessage } from "@waku/message-encryption";
export const PublicKeyContentTopic = "/eth-pm/1/public-key/proto"; export const PublicKeyContentTopic = "/eth-pm/1/public-key/proto";
export const PrivateMessageContentTopic = "/eth-pm/1/private-message/proto"; export const PrivateMessageContentTopic = "/eth-pm/1/private-message/proto";
export async function initWaku(): Promise<WakuPrivacy> { export async function initWaku(): Promise<RelayNode> {
const waku = await createPrivacyNode({ defaultBootstrap: true }); const waku = await createRelayNode({ defaultBootstrap: true });
await waku.start(); await waku.start();
await waitForRemotePeer(waku, [Protocols.Relay]); await waitForRemotePeer(waku, [Protocols.Relay]);
@ -23,7 +24,7 @@ export async function initWaku(): Promise<WakuPrivacy> {
export function handlePublicKeyMessage( export function handlePublicKeyMessage(
myAddress: string | undefined, myAddress: string | undefined,
setter: Dispatch<SetStateAction<Map<string, Uint8Array>>>, setter: Dispatch<SetStateAction<Map<string, Uint8Array>>>,
msg: WakuMessage msg: DecodedMessage
) { ) {
console.log("Public Key Message received:", msg); console.log("Public Key Message received:", msg);
if (!msg.payload) return; if (!msg.payload) return;
@ -49,7 +50,7 @@ export function handlePublicKeyMessage(
export async function handlePrivateMessage( export async function handlePrivateMessage(
setter: Dispatch<SetStateAction<Message[]>>, setter: Dispatch<SetStateAction<Message[]>>,
address: string, address: string,
wakuMsg: WakuMessage wakuMsg: DecodedMessage
) { ) {
console.log("Private Message received:", wakuMsg); console.log("Private Message received:", wakuMsg);
if (!wakuMsg.payload) return; if (!wakuMsg.payload) return;