diff options
| author | fcked <enntheprogrammer@gmail.com> | 2023-03-13 16:59:29 +0100 |
|---|---|---|
| committer | fiatjaf_ <fiatjaf@gmail.com> | 2023-03-13 13:22:28 -0300 |
| commit | b2c21ab10c06be0976a08920c07f5421d17c0654 (patch) | |
| tree | 23895a4e6bfd4eadec37aef0d1f48fd24bd84325 /04.md | |
| parent | 8b70e83b377d835b5ae570c14b697da2881d40d9 (diff) | |
NIP-04: fix bug in code sample
The code sample assumed that a `Uint8Array` was actually a hex string.
Diffstat (limited to '04.md')
| -rw-r--r-- | 04.md | 4 |
1 files changed, 2 insertions, 2 deletions
| @@ -23,12 +23,12 @@ import crypto from 'crypto' | |||
| 23 | import * as secp from 'noble-secp256k1' | 23 | import * as secp from 'noble-secp256k1' |
| 24 | 24 | ||
| 25 | let sharedPoint = secp.getSharedSecret(ourPrivateKey, '02' + theirPublicKey) | 25 | let sharedPoint = secp.getSharedSecret(ourPrivateKey, '02' + theirPublicKey) |
| 26 | let sharedX = sharedPoint.slice(2, 67) | 26 | let sharedX = sharedPoint.slice(1, 33) |
| 27 | 27 | ||
| 28 | let iv = crypto.randomFillSync(new Uint8Array(16)) | 28 | let iv = crypto.randomFillSync(new Uint8Array(16)) |
| 29 | var cipher = crypto.createCipheriv( | 29 | var cipher = crypto.createCipheriv( |
| 30 | 'aes-256-cbc', | 30 | 'aes-256-cbc', |
| 31 | Buffer.from(sharedX, 'hex'), | 31 | Buffer.from(sharedX), |
| 32 | iv | 32 | iv |
| 33 | ) | 33 | ) |
| 34 | let encryptedMessage = cipher.update(text, 'utf8', 'base64') | 34 | let encryptedMessage = cipher.update(text, 'utf8', 'base64') |