js-waku/packages/message-encryption
dependabot[bot] 872c9cd0df
build(deps-dev): bump cspell from 5.21.2 to 6.17.0
Bumps [cspell](https://github.com/streetsidesoftware/cspell) from 5.21.2 to 6.17.0.
- [Release notes](https://github.com/streetsidesoftware/cspell/releases)
- [Changelog](https://github.com/streetsidesoftware/cspell/blob/main/CHANGELOG.md)
- [Commits](https://github.com/streetsidesoftware/cspell/compare/v5.21.2...v6.17.0)

---
updated-dependencies:
- dependency-name: cspell
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-13 13:46:02 +11:00
..
src refactor: remove `waku_` from module names 2022-12-12 22:36:13 +11:00
.eslintrc.cjs chore: init message-encryption package 2022-11-04 11:25:53 +11:00
.mocharc.json chore: init message-encryption package 2022-11-04 11:25:53 +11:00
.prettierignore chore: init message-encryption package 2022-11-04 11:25:53 +11:00
CHANGELOG.md doc: update changelogs 2022-12-05 16:05:20 +11:00
README.md doc: add readme for @waku/message-encryption 2022-12-05 15:14:51 +11:00
karma.conf.cjs chore: init message-encryption package 2022-11-04 11:25:53 +11:00
package.json build(deps-dev): bump cspell from 5.21.2 to 6.17.0 2022-12-13 13:46:02 +11:00
rollup.config.js feat: easy import by having an export map for each type of encryption 2022-12-05 15:14:17 +11:00
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) => {
  // ...
});