js-waku/packages/message-encryption
fryorcraken 55431a52e0
chore: release master (#1558)
2023-09-11 13:27:24 +02:00
..
src chore: upgrade libp2p and related deps (#1482) 2023-08-16 20:18:13 +05:30
.eslintrc.cjs chore: upgrade libp2p and related deps (#1482) 2023-08-16 20:18:13 +05:30
.mocharc.json chore: remove usage of jsdom 2023-02-10 19:44:59 +11:00
CHANGELOG.md chore: release master (#1558) 2023-09-11 13:27:24 +02:00
README.md chore: upgrade libp2p and related deps (#1482) 2023-08-16 20:18:13 +05:30
karma.conf.cjs chore: upgrade libp2p and related deps (#1482) 2023-08-16 20:18:13 +05:30
package.json chore: release master (#1558) 2023-09-11 13:27:24 +02:00
rollup.config.js chore: upgrade libp2p and related deps (#1482) 2023-08-16 20:18:13 +05:30
tsconfig.dev.json chore: merge tsconfig 2022-12-02 15:54:30 +11:00
tsconfig.json chore: merge tsconfig 2022-12-02 15:54:30 +11:00

README.md

@waku/message-encryption

Provide Waku Message Version 1 payload encryption as defined in 26/WAKU2-PAYLOAD.

Symmetric Encryption

Symmetric encryption uses a unique key to encrypt and decrypt messages.

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.

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) => {
  // ...
});