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