Add support for nip44

This commit is contained in:
Jonathan Staab
2023-08-11 17:18:00 -07:00
committed by fiatjaf_
parent df6f887d7e
commit d13eecad4a
5 changed files with 105 additions and 17 deletions

19
nip44.test.ts Normal file
View File

@@ -0,0 +1,19 @@
import crypto from 'node:crypto'
import {encrypt, decrypt} from './nip44.ts'
import {getPublicKey, generatePrivateKey} from './keys.ts'
// @ts-ignore
// eslint-disable-next-line no-undef
globalThis.crypto = crypto
test('encrypt and decrypt message', async () => {
let sk1 = generatePrivateKey()
let sk2 = generatePrivateKey()
let pk1 = getPublicKey(sk1)
let pk2 = getPublicKey(sk2)
expect(await decrypt(sk2, pk1, await encrypt(sk1, pk2, 'hello'))).toEqual(
'hello'
)
})