From d5a40da503835e511e42e4a56f5b551a2a99628e Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 6 Nov 2024 10:05:49 -0800 Subject: use hex.decode --- src/lib/nostr.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/nostr.ts b/src/lib/nostr.ts index 8aea40d7..4392134d 100644 --- a/src/lib/nostr.ts +++ b/src/lib/nostr.ts @@ -10,14 +10,13 @@ import { nip19, } from "nostr-tools"; import { get } from "svelte/store"; -import { hexToUint8Array } from "uint8array-extras"; import { decrypt as nip49decrypt, encrypt as nip49encrypt, } from "nostr-tools/nip49"; -import { bech32m } from "@scure/base"; +import { bech32m, hex } from "@scure/base"; import { entropyToMnemonic, mnemonicToEntropy } from "@scure/bip39"; import { wordlist } from "@scure/bip39/wordlists/english"; @@ -51,7 +50,7 @@ export const generate = async (user: any) => { ), ); - user.pubkey = getPublicKey(hexToUint8Array(sk)); + user.pubkey = getPublicKey(hex.decode(sk)); user.cipher = encode("en", toWords(bytes), 180); user.salt = Buffer.from(salt).toString("hex"); }; @@ -96,7 +95,7 @@ export const getPrivateKey = async (user: User): Promise => { if (nsec) { k = nip49decrypt(nsec, await getPassword()); - } else k = hexToUint8Array(privateKeyFromSeedWords(await getMnemonic(user))); + } else k = hex.decode(privateKeyFromSeedWords(await getMnemonic(user))); localStorage.setItem("nsec", nip19.nsecEncode(k)); return k; @@ -161,14 +160,14 @@ export const reEncryptEntropy = async (user: User, newPassword: string) => { const entropy = await crypto.subtle.decrypt( { name: "AES-GCM", iv: new Uint8Array(16) }, - await stretch(await getPassword(), hexToUint8Array(salt)), + await stretch(await getPassword(), hex.decode(salt)), Uint8Array.from(fromWords(decode(cipher, 180).words)), ); const bytes = new Uint8Array( await crypto.subtle.encrypt( { name: "AES-GCM", iv: new Uint8Array(16) }, - await stretch(newPassword, hexToUint8Array(salt)), + await stretch(newPassword, hex.decode(salt)), entropy, ), ); -- cgit v1.2.3