diff --git a/app/(app)/(profile)/[npub]/_components/Subscriptions.tsx b/app/(app)/(profile)/[npub]/_components/Subscriptions.tsx new file mode 100644 index 0000000..f47af5b --- /dev/null +++ b/app/(app)/(profile)/[npub]/_components/Subscriptions.tsx @@ -0,0 +1,23 @@ +import Subscriptions from "@/containers/Subscriptions"; +import Spinner from "@/components/spinner"; +import Link from "next/link"; +import { NDKEvent } from "@nostr-dev-kit/ndk"; +import { ReactElement } from "react"; +export default function ProfileSubscriptions({ pubkey }: { pubkey: string }) { + return ( +
+ ( +
+ +

+ Fetching Subscriptions... +

+
+ )} + /> +
+ ); +} diff --git a/app/(app)/(profile)/[npub]/page.tsx b/app/(app)/(profile)/[npub]/page.tsx index f1288fc..2ac0670 100644 --- a/app/(app)/(profile)/[npub]/page.tsx +++ b/app/(app)/(profile)/[npub]/page.tsx @@ -8,6 +8,7 @@ import Tabs from "@/components/Tabs"; import useProfile from "@/lib/hooks/useProfile"; import { getTwoLetters, truncateText } from "@/lib/utils"; import ProfileFeed from "./_components/Feed"; +import Subscriptions from "./_components/Subscriptions"; import { nip19 } from "nostr-tools"; export default function ProfilePage({ @@ -114,7 +115,7 @@ export default function ProfilePage({
-
+
{demo.map((e) => ( ))} @@ -126,10 +127,6 @@ export default function ProfilePage({ name: "feed", label: "Feed", }, - { - name: "media", - label: "Media", - }, { name: "subscriptions", label: "Subscriptions", @@ -140,6 +137,7 @@ export default function ProfilePage({ />
{activeTab === "feed" ? : ""} + {activeTab === "subscriptions" ? : ""}
); diff --git a/app/(app)/list/[naddr]/page.tsx b/app/(app)/list/[naddr]/page.tsx index 43d6259..9c7d99b 100644 --- a/app/(app)/list/[naddr]/page.tsx +++ b/app/(app)/list/[naddr]/page.tsx @@ -46,7 +46,8 @@ export default function ListPage({ ); } const noteIds = getTagsValues("e", event.tags).filter(Boolean); - console.log("notes", event.tags); + console.log("notes", noteIds); + console.log("tags", event.tags); return (
diff --git a/bun.lockb b/bun.lockb index bf5558d..0ba45c6 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/KindCard/3745.tsx b/components/KindCard/3745.tsx index bfe572a..45ac7bf 100644 --- a/components/KindCard/3745.tsx +++ b/components/KindCard/3745.tsx @@ -1,18 +1,119 @@ +"use client"; +import { useState, useEffect } from "react"; +import Link from "next/link"; import Container from "./components/Container"; import { CardTitle, CardDescription } from "@/components/ui/card"; import { type Event } from "nostr-tools"; +import { cn } from "@/lib/utils"; +import { useNDK } from "@/app/_providers/ndk"; +import { RiArrowRightLine, RiLockLine } from "react-icons/ri"; +import { decryptMessage } from "@/lib/nostr"; +import { NDKUser } from "@nostr-dev-kit/ndk"; -export default function Kind3745({ pubkey }: Event) { +import { EventSchema } from "@/types"; +import KindCard from "@/components/KindCard"; +import Spinner from "../spinner"; + +export default function Kind3745(props: Event) { + const { pubkey, content, id } = props; + const [error, setError] = useState(""); + const [fetchingEvent, setFetchingEvent] = useState(false); + const [decryptedEvent, setDecryptedEvent] = useState(); + const { ndk } = useNDK(); + useEffect(() => { + if (ndk && !fetchingEvent && !decryptedEvent) { + void handleFetchEvent(); + } + }, [ndk]); + + async function handleFetchEvent() { + setFetchingEvent(true); + try { + const directMessageEvent = await ndk!.fetchEvent({ + kinds: [4], + authors: [pubkey], + ["#e"]: [id], + }); + if (directMessageEvent) { + await directMessageEvent.decrypt( + new NDKUser({ hexpubkey: pubkey }), + ndk?.signer, + ); + const passphrase = directMessageEvent.content; + if (!passphrase) { + setError("Unable to parse event"); + return; + } + const decrypedData = await decryptMessage(content, passphrase); + console.log("Decrypted", decrypedData); + const hiddenEvent = EventSchema.safeParse( + JSON.parse(decrypedData ?? ""), + ); + if (hiddenEvent.success) { + setDecryptedEvent(hiddenEvent.data); + } else { + setError("Unable to parse event"); + } + } + } catch (err) { + setError("Unable to parse event"); + } finally { + setFetchingEvent(false); + } + } + if (decryptedEvent) { + return ; + } return ( - - The start of the Nostr revolution - - - This is the summary of this artilce. Let's hope that it is a good - article and that it will end up being worth reading. I don't want to - waste my time on some random other stuff. - +
+
+ + The start of the Nostr revolution + + + Here is some secret text. If you are reading this, that means you've + tried some sneaky css tricks to reveal what was hidden 🫣. + Unfourtunatly, CSS won't be able to help you here. In fact, I can't + even reveal this if I wanted to. Only the correct private key can + reveal it. + +
+
+ {fetchingEvent ? ( +
+ +
+ ) : ( + +
+
+
+
+ + Content locked + +

Subscribe to reveal

+
+
+ +
+
+ + )} +
+
); } diff --git a/components/KindCard/components/Container.tsx b/components/KindCard/components/Container.tsx index 7d9ad1b..713896a 100644 --- a/components/KindCard/components/Container.tsx +++ b/components/KindCard/components/Container.tsx @@ -60,10 +60,12 @@ export default function Container({ {children}
- {!!contentTags?.length && ( + {!!contentTags?.length ? (
+ ) : ( +
)}
diff --git a/components/Modals/ShortTextNote.tsx b/components/Modals/ShortTextNote.tsx index 04e75ad..d225588 100644 --- a/components/Modals/ShortTextNote.tsx +++ b/components/Modals/ShortTextNote.tsx @@ -77,7 +77,7 @@ export default function ShortTextNoteModal() { }); } } - + console.log("about to create private event with ", listSigner); const result = await createEventHandler( ndk, { diff --git a/containers/Subscriptions/index.tsx b/containers/Subscriptions/index.tsx new file mode 100644 index 0000000..555ea88 --- /dev/null +++ b/containers/Subscriptions/index.tsx @@ -0,0 +1,61 @@ +"use client"; +import KindCard from "@/components/KindCard"; +import { cn } from "@/lib/utils"; +import Link from "next/link"; +import Spinner from "@/components/spinner"; +import { Event } from "nostr-tools"; +import useEvents from "@/lib/hooks/useEvents"; +import NDK, { NDKEvent, type NDKFilter } from "@nostr-dev-kit/ndk"; +import ListCard from "@/components/ListCard"; + +type SubscriptionsProps = { + pubkey: string; + link?: boolean; + className?: string; + loader?: () => JSX.Element; + empty?: () => JSX.Element; +}; + +export default function Subscriptions({ + pubkey, + link = false, + className, + loader: Loader, + empty: Empty, +}: SubscriptionsProps) { + const { events, isLoading } = useEvents({ + filter: { + kinds: [30001], + ["#p"]: [pubkey], + }, + }); + if (isLoading) { + if (Loader) { + return ; + } + return ; + } + if (Empty && events.length === 0) { + return ; + } + if (link) { + return ( + <> + {events.map((e) => { + return ( + + ; + + ); + })} + + ); + } + return ( + <> + {events.map((e) => { + return ; + })} + + ); +} diff --git a/lib/actions/create.ts b/lib/actions/create.ts index 4e0bcfd..83f6dec 100644 --- a/lib/actions/create.ts +++ b/lib/actions/create.ts @@ -58,7 +58,7 @@ export async function createEventHandler( } const eventToPublish = new NDKEvent(ndk, { ...event, - tags: [...event.tags, ["client", "ordstr"]], + tags: [...event.tags, ["client", "flockstr"]], pubkey, created_at: unixTimeNowInSeconds(), } as NostrEvent); @@ -68,20 +68,27 @@ export async function createEventHandler( let publishedEvent: NDKEvent | null = null; // Check if is private event if (isPrivate) { + console.log("isPrivate"); const rawEventString = JSON.stringify(eventToPublish.rawEvent()); + console.log("rawEventString", rawEventString); const passphrase = generateRandomString(); + console.log("passphrase", passphrase); const encryptedRawEventString = await encryptMessage( rawEventString, passphrase, ); + console.log("encryptedRawEventString", encryptedRawEventString); + console.log("delegateSigner", delegateSigner); const signer = delegateSigner ?? ndk.signer!; const user = await signer.user(); + console.log("signer user", user); + const newEvent = new NDKEvent(ndk, { content: encryptedRawEventString, kind: 3745, tags: [ ["kind", event.kind.toString()], - ["client", "ordstr"], + ["client", "flockstr"], ], pubkey: user.pubkey, } as NostrEvent); @@ -98,7 +105,7 @@ export async function createEventHandler( tags: [ ["p", subscriber], ["e", newEvent.id], - ["client", "ordstr"], + ["client", "flockstr"], ], pubkey: user.pubkey, } as NostrEvent); @@ -141,7 +148,7 @@ export async function createEncryptedEventOnPrivateList( } const eventToPublish = new NDKEvent(ndk, { ...event, - tags: [...event.tags, ["client", "ordstr"]], + tags: [...event.tags, ["client", "flockstr"]], pubkey, created_at: unixTimeNowInSeconds(), } as NostrEvent); @@ -160,7 +167,7 @@ export async function createEncryptedEventOnPrivateList( kind: 3745, tags: [ ["kind", event.kind.toString()], - ["client", "ordstr"], + ["client", "flockstr"], ], pubkey: user.pubkey, } as NostrEvent); @@ -186,7 +193,7 @@ export async function createEncryptedEventOnPrivateList( tags: [ ["p", subscriber], ["e", newEvent.id], - ["client", "ordstr"], + ["client", "flockstr"], ], pubkey: user.hexpubkey, } as NostrEvent); diff --git a/lib/actions/ephemeral.ts b/lib/actions/ephemeral.ts index e3797a1..70d8719 100644 --- a/lib/actions/ephemeral.ts +++ b/lib/actions/ephemeral.ts @@ -103,7 +103,7 @@ async function generateTags(mainSigner: NDKSigner, opts: ISaveOpts = {}) { const mainUser = await mainSigner.user(); const tags = [ ["p", mainUser.hexpubkey], - ["client", "ordstr"], + ["client", "flockstr"], ]; if (opts.associatedEvent) { diff --git a/lib/nostr/index.ts b/lib/nostr/index.ts index 451dccf..e94792a 100644 --- a/lib/nostr/index.ts +++ b/lib/nostr/index.ts @@ -119,6 +119,7 @@ export function encryptMessage(message: string, password: string) { } // Function to decrypt a hashed message using a passphrase export function decryptMessage(encryptedMessage: string, password: string) { + console.log("Attemping decrypto", encryptedMessage, "with", password); try { const buffer = create32ByteBuffer(password); // Extract IV from the received message @@ -130,11 +131,15 @@ export function decryptMessage(encryptedMessage: string, password: string) { const iv = Buffer.from(ivBase64, "base64"); const encryptedText = Buffer.from(encryptedMessage, "base64"); - + console.log("at bugger"); const decipher = crypto.createDecipheriv("aes-256-cbc", buffer, iv); + console.log("at decipher"); const decrypted = decipher.update(encryptedText); - return Buffer.concat([decrypted, decipher.final()]).toString(); + + const toReturn = Buffer.concat([decrypted, decipher.final()]).toString(); + console.log("toReturn", toReturn); + return toReturn; } catch (e) { console.error(e); } diff --git a/package.json b/package.json index 5165ca3..9564a95 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.0.0", "cmdk": "^0.2.0", + "crypto": "^1.0.1", "crypto-js": "^4.1.1", "dayjs": "^1.11.10", "focus-trap-react": "^10.2.3",