Skip to content

Commit

Permalink
use uint8arrays/equals for signature verification
Browse files Browse the repository at this point in the history
  • Loading branch information
LordGhostX committed Dec 7, 2023
1 parent 69a15a1 commit 1b50902
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions docs/guides/js-waku/message-encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Waku uses libp2p noise encryption for node-to-node connections. However, no defa

## Installation

Install the `@waku/message-encryption` package using your preferred package manager:
Install the required packages for integrating `@waku/message-encryption` using your preferred package manager:

```mdx-code-block
import Tabs from '@theme/Tabs';
Expand All @@ -22,14 +22,14 @@ import TabItem from '@theme/TabItem';
<TabItem value="npm" label="NPM">

```shell
npm install @waku/message-encryption @waku/utils
npm install @waku/message-encryption @waku/utils uint8arrays
```

</TabItem>
<TabItem value="yarn" label="Yarn">

```shell
yarn add @waku/message-encryption @waku/utils
yarn add @waku/message-encryption @waku/utils uint8arrays
```

</TabItem>
Expand Down Expand Up @@ -174,6 +174,8 @@ await node.lightPush.send(ECIESEncoder, { payload });
You can extract the `signature` and its public key (`signaturePublicKey`) from the [DecodedMessage](https://js.waku.org/classes/_waku_message_encryption.DecodedMessage.html) and compare it with the expected public key to verify the message origin:

```js
import { equals } from "uint8arrays/equals";

// Generate a random private key for signing messages
const sigPrivKey = generatePrivateKey();

Expand All @@ -194,7 +196,7 @@ const callback = (wakuMessage) => {
const signaturePublicKey = wakuMessage.signaturePublicKey;

// Compare the public key of the message signature with the sender's own
if (JSON.stringify(signaturePublicKey) === JSON.stringify(sigPubKey)) {
if (equals(signaturePublicKey, sigPubKey)) {
console.log("This message was correctly signed");
} else {
console.log("This message has an incorrect signature");
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/js-waku/use-waku-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ yarn create vite [PROJECT DIRECTORY] --template react
</TabItem>
</Tabs>

Next, install the required libraries for integrating `@waku/sdk` using your preferred package manager:
Next, install the required packages for integrating `@waku/sdk` using your preferred package manager:

<Tabs groupId="package-manager">
<TabItem value="npm" label="NPM">
Expand Down

0 comments on commit 1b50902

Please sign in to comment.