mirror of
https://github.com/status-im/js-waku.git
synced 2025-02-22 18:08:14 +00:00
Store encryption public key as byte array
This commit is contained in:
parent
0bbe52ebb1
commit
278439df82
@ -71,7 +71,9 @@ function App() {
|
||||
const [EncryptionKeyPair, setEncryptionKeyPair] = useState<
|
||||
KeyPair | undefined
|
||||
>();
|
||||
const [publicKeys, setPublicKeys] = useState<Map<string, string>>(new Map());
|
||||
const [publicKeys, setPublicKeys] = useState<Map<string, Uint8Array>>(
|
||||
new Map()
|
||||
);
|
||||
const [messages, setMessages] = useState<Message[]>([]);
|
||||
const [address, setAddress] = useState<string>();
|
||||
|
||||
|
@ -14,7 +14,7 @@ const useStyles = makeStyles({
|
||||
|
||||
interface Props {
|
||||
waku: Waku | undefined;
|
||||
recipients: Map<string, string>;
|
||||
recipients: Map<string, Uint8Array>;
|
||||
messages: Message[];
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
export interface Props {
|
||||
waku: Waku | undefined;
|
||||
// address, public key
|
||||
recipients: Map<string, string>;
|
||||
recipients: Map<string, Uint8Array>;
|
||||
}
|
||||
|
||||
export default function SendMessage({ waku, recipients }: Props) {
|
||||
@ -106,7 +106,7 @@ export default function SendMessage({ waku, recipients }: Props) {
|
||||
|
||||
async function encodeEncryptedWakuMessage(
|
||||
message: string,
|
||||
publicKey: string,
|
||||
publicKey: Uint8Array,
|
||||
address: string
|
||||
): Promise<WakuMessage> {
|
||||
const directMsg = new DirectMessage({
|
||||
@ -123,7 +123,7 @@ async function encodeEncryptedWakuMessage(
|
||||
function sendMessage(
|
||||
waku: Waku,
|
||||
recipientAddress: string,
|
||||
recipientPublicKey: string,
|
||||
recipientPublicKey: Uint8Array,
|
||||
message: string,
|
||||
callback: (res: boolean) => void
|
||||
) {
|
||||
|
@ -34,23 +34,24 @@ export async function initWaku(): Promise<Waku> {
|
||||
|
||||
export function handlePublicKeyMessage(
|
||||
myAddress: string,
|
||||
setter: Dispatch<SetStateAction<Map<string, string>>>,
|
||||
setter: Dispatch<SetStateAction<Map<string, Uint8Array>>>,
|
||||
msg: WakuMessage
|
||||
) {
|
||||
console.log('Public Key Message received:', msg);
|
||||
if (!msg.payload) return;
|
||||
const publicKeyMsg = PublicKeyMessage.decode(msg.payload);
|
||||
if (!publicKeyMsg) return;
|
||||
const encryptionPublicKey = bufToHex(publicKeyMsg.encryptionPublicKey);
|
||||
console.log(encryptionPublicKey, myAddress);
|
||||
if (myAddress && equalByteArrays(publicKeyMsg.ethAddress, myAddress)) return;
|
||||
|
||||
const res = validatePublicKeyMessage(publicKeyMsg);
|
||||
console.log('Is Public Key Message valid?', res);
|
||||
|
||||
if (res) {
|
||||
setter((prevPks: Map<string, string>) => {
|
||||
prevPks.set(bufToHex(publicKeyMsg.ethAddress), encryptionPublicKey);
|
||||
setter((prevPks: Map<string, Uint8Array>) => {
|
||||
prevPks.set(
|
||||
bufToHex(publicKeyMsg.ethAddress),
|
||||
publicKeyMsg.encryptionPublicKey
|
||||
);
|
||||
return new Map(prevPks);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user