From 856d333c309f7786fae08ab7bc390015f7b17114 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 16 May 2025 13:43:59 -0500 Subject: [PATCH] CONTEXT: encryption and decryption --- CONTEXT.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/CONTEXT.md b/CONTEXT.md index 67cfb47..27cc069 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -304,7 +304,8 @@ function MyComponent() { const handleUpload = async (file: File) => { try { - // The first tuple in the array contains the URL + // Provides an array of NIP-94 compatible tags + // The first tag in the array contains the URL const [[_, url]] = await uploadFile(file); // ...use the url } catch (error) { @@ -316,6 +317,27 @@ function MyComponent() { } ``` +To attach files to kind 1 events, each file's URL should be appended to the event's `content`, and an `imeta` tag should be added for each file. For kind 0 events, the URL by itself can be used in relevant fields of the JSON content. + +## Encryption and Decryption + +The logged-in user has a `signer` object (matching the NIP-07 signer interface) that can be used for encryption and decryption. + +```ts +// Get the current user +const { user } = useCurrentUser(); + +// Optional guard to check that nip44 is available +if (!user.signer.nip44) { + throw new Error("Please upgrade your signer extension to a version that supports NIP-44 encryption"); +} + +// Encrypt message to self +const encrypted = await user.signer.nip44.encrypt(user.pubkey, "hello world"); +// Decrypt message to self +const decrypted = await user.signer.nip44.decrypt(user.pubkey, encrypted) // "hello world" +``` + ## Development Practices - Uses React Query for data fetching and caching