mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2025-08-27 04:59:22 +00:00
CONTEXT: encryption and decryption
This commit is contained in:
parent
b24578f0db
commit
856d333c30
24
CONTEXT.md
24
CONTEXT.md
@ -304,7 +304,8 @@ function MyComponent() {
|
|||||||
|
|
||||||
const handleUpload = async (file: File) => {
|
const handleUpload = async (file: File) => {
|
||||||
try {
|
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);
|
const [[_, url]] = await uploadFile(file);
|
||||||
// ...use the url
|
// ...use the url
|
||||||
} catch (error) {
|
} 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
|
## Development Practices
|
||||||
|
|
||||||
- Uses React Query for data fetching and caching
|
- Uses React Query for data fetching and caching
|
||||||
|
Loading…
x
Reference in New Issue
Block a user