From 4a35a785a7789670338aece364fd66cab514c829 Mon Sep 17 00:00:00 2001 From: zmeyer44 Date: Wed, 18 Oct 2023 18:51:17 -0400 Subject: [PATCH] got it --- app/(app)/list/[naddr]/_components/Header.tsx | 6 +++--- components/Modals/CreateList.tsx | 1 + lib/actions/ephemeral.ts | 15 ++++++++------- lib/actions/zap.ts | 15 +++++++-------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/(app)/list/[naddr]/_components/Header.tsx b/app/(app)/list/[naddr]/_components/Header.tsx index 6fa5eab..662794e 100644 --- a/app/(app)/list/[naddr]/_components/Header.tsx +++ b/app/(app)/list/[naddr]/_components/Header.tsx @@ -33,7 +33,7 @@ const ConfirmModal = dynamic(() => import("@/components/Modals/Confirm"), { export default function Header({ event }: { event: NDKEvent }) { const { currentUser } = useCurrentUser(); const modal = useModal(); - const { ndk, signer } = useNDK(); + const { ndk } = useNDK(); const [checkingPayment, setCheckingPayment] = useState(false); const [hasValidPayment, setHasValidPayment] = useState(false); const [syncingUsers, setSyncingUsers] = useState(false); @@ -88,11 +88,11 @@ export default function Header({ event }: { event: NDKEvent }) { } } async function handleSyncUsers() { - if (!event || !ndk || !signer) return; + if (!event || !ndk) return; setSyncingUsers(true); try { console.log("handleSyncUsers"); - await updateListUsersFromZaps(ndk, event.tagId(), rawEvent, signer); + await updateListUsersFromZaps(ndk, event.tagId(), rawEvent); toast.success("Users Synced!"); } catch (err) { console.log("error syncing users", err); diff --git a/components/Modals/CreateList.tsx b/components/Modals/CreateList.tsx index 657fcec..febd7a7 100644 --- a/components/Modals/CreateList.tsx +++ b/components/Modals/CreateList.tsx @@ -60,6 +60,7 @@ export default function CreateList() { kind: 30001, tags: tags, }); + console.log("EVENT Created", event); if (event && getTagValues("subscriptions", event.tags)) { await getSigner(new NDKList(ndk, event.rawEvent())) .then((delegateSigner) => diff --git a/lib/actions/ephemeral.ts b/lib/actions/ephemeral.ts index 6269c16..d6970e1 100644 --- a/lib/actions/ephemeral.ts +++ b/lib/actions/ephemeral.ts @@ -101,15 +101,16 @@ function generateContent( async function generateTags(mainSigner: NDKSigner, opts: ISaveOpts = {}) { const mainUser = await mainSigner.user(); const tags = [ - ["p", mainUser.hexpubkey], + ["p", mainUser.pubkey], ["client", "flockstr"], ]; if (opts.associatedEvent) { - // TODO: This is trivially reversable; better to encrypt it or hash it with the hexpubkey - const hashedEventReference = await getHashedKeyName( - opts.associatedEvent.encode(), - ); + const encodedEvent = opts.associatedEvent.encode(); + console.log("encodedEvent", encodedEvent); + // TODO: This is trivially reversable; better to encrypt it or hash it with the pubkey + const hashedEventReference = await getHashedKeyName(encodedEvent); + console.log("hashedEventReference", hashedEventReference); tags.push(["e", hashedEventReference]); } @@ -139,7 +140,7 @@ export async function saveEphemeralSigner( content: generateContent(targetSigner, opts), tags: await generateTags(mainSigner, opts), } as NostrEvent); - event.pubkey = mainUser.hexpubkey; + event.pubkey = mainUser.pubkey; await event.encrypt(mainUser, mainSigner); await event.publish(); @@ -152,7 +153,7 @@ export async function saveEphemeralSigner( content: JSON.stringify(opts.keyProfile), tags: [] as NDKTag[], } as NostrEvent); - event.pubkey = user.hexpubkey; + event.pubkey = user.pubkey; await event.sign(targetSigner); await event.publish(); } diff --git a/lib/actions/zap.ts b/lib/actions/zap.ts index 4ed92a3..314d154 100644 --- a/lib/actions/zap.ts +++ b/lib/actions/zap.ts @@ -104,7 +104,6 @@ export async function updateListUsersFromZaps( ndk: NDK, tagId: string, event: NostrEvent, - signer: NDKSigner, ) { const SECONDS_IN_MONTH = 2_628_000; const SECONDS_IN_YEAR = SECONDS_IN_MONTH * 365; @@ -122,7 +121,7 @@ export async function updateListUsersFromZaps( ([pubkey, relay, petname, expiryUnix]) => parseInt(expiryUnix ?? "0") > unixTimeNowInSeconds(), ); - const newUsers: string[] = []; + const newUsers: string[] = currentUsers.map(([pub]) => pub as string); for (const paymentInvoice of paymentInvoices) { if ( @@ -149,7 +148,7 @@ export async function updateListUsersFromZaps( // Send old codes to user } } - await sendCodesToNewUsers(ndk, newUsers, tagId, signer); + await sendCodesToNewUsers(ndk, newUsers, tagId, event); // Add self console.log("Adding self"); @@ -172,11 +171,10 @@ async function sendCodesToNewUsers( ndk: NDK, users: string[], tagId: string, - signer_: NDKSigner, + event: NostrEvent, ) { - console.log("sendCodesToNewUsers", users, signer_); - const signer = await findEphemeralSigner(ndk, signer_, { - associatedEventNip19: tagId, + const signer = await findEphemeralSigner(ndk, ndk.signer!, { + associatedEventNip19: new NDKEvent(ndk, event).encode(), }); console.log("Signer", signer); if (!signer) return; @@ -188,9 +186,10 @@ async function sendCodesToNewUsers( }); const codes: [string, string][] = []; for (const message of Array.from(messages)) { - await message.decrypt(delegate, signer); + await message.decrypt(); codes.push([getTagValues("e", message.tags) ?? "", message.content]); } + console.log("codes", codes); for (const user of users) { for (const [event, code] of codes) {