nip49: nfkc normalization.

This commit is contained in:
fiatjaf
2024-02-16 00:13:54 -03:00
parent 37b046c047
commit 058d0276e2
2 changed files with 11 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ import { bech32 } from '@scure/base'
export function encrypt(sec: Uint8Array, password: string, logn: number = 16, ksb: 0x00 | 0x01 | 0x02 = 0x02): string {
let salt = randomBytes(16)
let n = 2 ** logn
let key = scrypt(password, salt, { N: n, r: 8, p: 1, dkLen: 32 })
let key = scrypt(password.normalize('NFKC'), salt, { N: n, r: 8, p: 1, dkLen: 32 })
let nonce = randomBytes(24)
let aad = Uint8Array.from([ksb])
let xc2p1 = xchacha20poly1305(key, nonce, aad)
@@ -37,7 +37,7 @@ export function decrypt(ncryptsec: string, password: string): Uint8Array {
let aad = Uint8Array.from([ksb])
let ciphertext = b.slice(2 + 16 + 24 + 1)
let key = scrypt(password, salt, { N: n, r: 8, p: 1, dkLen: 32 })
let key = scrypt(password.normalize('NFKC'), salt, { N: n, r: 8, p: 1, dkLen: 32 })
let xc2p1 = xchacha20poly1305(key, nonce, aad)
let sec = xc2p1.decrypt(ciphertext)