nip44 updates (#278)

Co-authored-by: Jonathan Staab <shtaab@gmail.com>
This commit is contained in:
Jon Staab
2023-08-16 09:53:37 -07:00
committed by GitHub
parent 2431896921
commit b92407b156
2 changed files with 20 additions and 29 deletions

View File

@@ -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')
})