From 6121aa78d73c0c35e7604ec47ac50a37bb330e26 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Fri, 2 Dec 2022 16:51:11 +1100 Subject: [PATCH] doc: add readme for @waku/message-encryption --- packages/message-encryption/README.md | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 packages/message-encryption/README.md diff --git a/packages/message-encryption/README.md b/packages/message-encryption/README.md new file mode 100644 index 0000000000..68d3adb900 --- /dev/null +++ b/packages/message-encryption/README.md @@ -0,0 +1,65 @@ +# `@waku/message-encryption` + +Provide Waku Message Version 1 payload encryption as defined in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/). + +## Symmetric Encryption + +Symmetric encryption uses a unique key to encrypt and decrypt messages. + +```typescript +import { + createDecoder, + createEncoder, + generateSymmetricKey, +} from "@waku/message-encryption/symmetric"; + +// Generate a random key +const key = generateSymmetricKey(); + +// To send messages, create an encoder +const encoder = createEncoder(contentTopic, key); + +// For example +waku.lightPush.push(encoder, { payload }); + +// To receive messages, create a decoder +const decoder = createDecoder(contentTopic, key); + +// For example +await waku.store.queryOrderedCallback([decoder], (msg) => { + // ... +}); +``` + +## ECIES Encryption + +ECIES encryption enables encryption for a public key and decryption using a private key. + +```typescript +import { + createDecoder, + createEncoder, + generatePrivateKey, + getPublicKey, +} from "@waku/message-encryption/ecies"; + +// Generate a random private key +const privateKey = generatePrivateKey(); + +// Keep the private key secure, provide the public key to the sender +const publicKey = getPublicKey(privateKey); + +// To send messages, create an encoder +const encoder = createEncoder(contentTopic, publicKey); + +// For example +waku.lightPush.push(encoder, { payload }); + +// To receive messages, create a decoder +const decoder = createDecoder(contentTopic, privateKey); + +// For example +await waku.store.queryOrderedCallback([decoder], (msg) => { + // ... +}); +```