wip: migrate to ark

This commit is contained in:
reya
2023-12-08 09:32:48 +07:00
parent 5f90bd0d22
commit 68886ad584
26 changed files with 441 additions and 349 deletions
+3 -13
View File
@@ -1,29 +1,19 @@
import { NDKEvent, NDKKind, NDKUser } from '@nostr-dev-kit/ndk';
import { useState } from 'react';
import { toast } from 'sonner';
import { MediaUploader } from '@app/chats/components/mediaUploader';
import { useNDK } from '@libs/ndk/provider';
import { useArk } from '@libs/ark';
import { EnterIcon } from '@shared/icons';
export function ChatForm({ receiverPubkey }: { receiverPubkey: string }) {
const { ndk } = useNDK();
const { ark } = useArk();
const [value, setValue] = useState('');
const submit = async () => {
try {
const recipient = new NDKUser({ pubkey: receiverPubkey });
const message = await ndk.signer.encrypt(recipient, value);
const event = new NDKEvent(ndk);
event.content = message;
event.kind = NDKKind.EncryptedDirectMessage;
event.tag(recipient);
const publish = await event.publish();
const publish = await ark.nip04Encrypt({ content: value, pubkey: receiverPubkey });
if (publish) setValue('');
} catch (e) {
toast.error(e);
+7 -16
View File
@@ -1,26 +1,17 @@
import { NDKEvent, NDKUser } from '@nostr-dev-kit/ndk';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { useEffect, useState } from 'react';
import { useNDK } from '@libs/ndk/provider';
import { useStorage } from '@libs/storage/provider';
import { useArk } from '@libs/ark';
export function useDecryptMessage(message: NDKEvent) {
const { db } = useStorage();
const { ndk } = useNDK();
const [content, setContent] = useState(message.content);
export function useDecryptMessage(event: NDKEvent) {
const { ark } = useArk();
const [content, setContent] = useState(event.content);
useEffect(() => {
async function decryptContent() {
try {
const sender = new NDKUser({
pubkey:
db.account.pubkey === message.pubkey
? message.tags.find((el) => el[0] === 'p')[1]
: message.pubkey,
});
const result = await ndk.signer.decrypt(sender, message.content);
setContent(result);
const message = await ark.nip04Decrypt({ event });
setContent(message);
} catch (e) {
console.error(e);
}