mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0396db5ed6 | ||
|
|
0c8e7a74f5 | ||
|
|
c66a2acda1 |
10
nip04.js
10
nip04.js
@@ -5,7 +5,7 @@ import * as secp256k1 from '@noble/secp256k1'
|
||||
|
||||
export function encrypt(privkey, pubkey, text) {
|
||||
const key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
|
||||
const normalizedKey = getOnlyXFromFullSharedSecret(key)
|
||||
const normalizedKey = getNormalizedX(key)
|
||||
|
||||
let iv = Uint8Array.from(randomBytes(16))
|
||||
var cipher = aes.createCipheriv(
|
||||
@@ -22,7 +22,7 @@ export function encrypt(privkey, pubkey, text) {
|
||||
export function decrypt(privkey, pubkey, ciphertext) {
|
||||
let [cip, iv] = ciphertext.split('?iv=')
|
||||
let key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
|
||||
let normalizedKey = getOnlyXFromFullSharedSecret(key)
|
||||
let normalizedKey = getNormalizedX(key)
|
||||
|
||||
var decipher = aes.createDecipheriv(
|
||||
'aes-256-cbc',
|
||||
@@ -35,6 +35,8 @@ export function decrypt(privkey, pubkey, ciphertext) {
|
||||
return decryptedMessage
|
||||
}
|
||||
|
||||
function getOnlyXFromFullSharedSecret(fullSharedSecretCoordinates) {
|
||||
return fullSharedSecretCoordinates.substr(2, 64)
|
||||
function getNormalizedX(key) {
|
||||
return typeof key === 'string'
|
||||
? key.substr(2, 64)
|
||||
: Buffer.from(key.slice(1)).toString('hex')
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nostr-tools",
|
||||
"version": "0.21.0",
|
||||
"version": "0.21.3",
|
||||
"description": "Tools for making a Nostr client.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user