mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
@@ -1,6 +1,7 @@
|
||||
import crypto from 'node:crypto'
|
||||
import {hexToBytes} from '@noble/hashes/utils'
|
||||
|
||||
import {encrypt, decrypt} from './nip44.ts'
|
||||
import {encrypt, decrypt, getSharedSecret} from './nip44.ts'
|
||||
import {getPublicKey, generatePrivateKey} from './keys.ts'
|
||||
|
||||
// @ts-ignore
|
||||
@@ -12,8 +13,9 @@ test('encrypt and decrypt message', async () => {
|
||||
let sk2 = generatePrivateKey()
|
||||
let pk1 = getPublicKey(sk1)
|
||||
let pk2 = getPublicKey(sk2)
|
||||
let sharedKey1 = getSharedSecret(sk1, pk2)
|
||||
let sharedKey2 = getSharedSecret(sk2, pk1)
|
||||
|
||||
expect(await decrypt(sk2, pk1, await encrypt(sk1, pk2, 'hello'))).toEqual(
|
||||
'hello'
|
||||
)
|
||||
expect(decrypt(hexToBytes(sk1), encrypt(hexToBytes(sk1), 'hello'))).toEqual('hello')
|
||||
expect(decrypt(sharedKey2, encrypt(sharedKey1, 'hello'))).toEqual('hello')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user