-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: encryption with signatures (#494)
- Loading branch information
Showing
9 changed files
with
392 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
createEncoder as createWakuSymmetricEncoder, | ||
createDecoder as createWakuSymmetricDecoder, | ||
} from '@waku/message-encryption/symmetric' | ||
import { getTopic, type ContentTopic } from './waku' | ||
import { bytesToHex, hexToBytes } from '@waku/utils/bytes' | ||
import { type Hex, fixHex } from './crypto' | ||
|
||
function toHex(value: Uint8Array | Hex): Hex { | ||
return typeof value === 'string' ? fixHex(value) : bytesToHex(value) | ||
} | ||
|
||
export function createSymmetricEncoder(options: { | ||
contentTopic: ContentTopic | ||
symKey: Uint8Array | Hex | ||
sigPrivKey?: Uint8Array | Hex | ||
}) { | ||
const contentTopic = getTopic(options.contentTopic, toHex(options.symKey)) | ||
return createWakuSymmetricEncoder({ | ||
...options, | ||
contentTopic, | ||
symKey: hexToBytes(options.symKey), | ||
sigPrivKey: options.sigPrivKey ? hexToBytes(options.sigPrivKey) : undefined, | ||
}) | ||
} | ||
|
||
export function createSymmetricDecoder(options: { | ||
contentTopic: ContentTopic | ||
symKey: Uint8Array | Hex | ||
}) { | ||
const contentTopic = getTopic(options.contentTopic, toHex(options.symKey)) | ||
return createWakuSymmetricDecoder(contentTopic, hexToBytes(options.symKey)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7108b07
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
waku-objects-playground – ./
waku-objects-playground-git-main-waku-objects.vercel.app
chat.wakuplay.im
waku-objects-playground.vercel.app
waku-objects-playground-waku-objects.vercel.app