NIP-04: fix bug in code sample

The code sample assumed that a `Uint8Array` was actually a hex string.
This commit is contained in:
fcked 2023-03-13 16:59:29 +01:00 committed by fiatjaf_
parent 8b70e83b37
commit b2c21ab10c

4
04.md
View File

@ -23,12 +23,12 @@ import crypto from 'crypto'
import * as secp from 'noble-secp256k1' import * as secp from 'noble-secp256k1'
let sharedPoint = secp.getSharedSecret(ourPrivateKey, '02' + theirPublicKey) let sharedPoint = secp.getSharedSecret(ourPrivateKey, '02' + theirPublicKey)
let sharedX = sharedPoint.slice(2, 67) let sharedX = sharedPoint.slice(1, 33)
let iv = crypto.randomFillSync(new Uint8Array(16)) let iv = crypto.randomFillSync(new Uint8Array(16))
var cipher = crypto.createCipheriv( var cipher = crypto.createCipheriv(
'aes-256-cbc', 'aes-256-cbc',
Buffer.from(sharedX, 'hex'), Buffer.from(sharedX),
iv iv
) )
let encryptedMessage = cipher.update(text, 'utf8', 'base64') let encryptedMessage = cipher.update(text, 'utf8', 'base64')