fixed decryption issue
This commit is contained in:
parent
f84cc85148
commit
69d96cdefc
@ -1,23 +1,14 @@
|
||||
import Feed from "@/containers/Feed";
|
||||
import Spinner from "@/components/spinner";
|
||||
import { NDKKind } from "@nostr-dev-kit/ndk";
|
||||
|
||||
export default function ProfileFeed({
|
||||
pubkey,
|
||||
alt,
|
||||
}: {
|
||||
pubkey: string;
|
||||
alt?: string;
|
||||
}) {
|
||||
const authors = [pubkey];
|
||||
if (alt) {
|
||||
authors.push(alt);
|
||||
}
|
||||
export default function ProfileFeed({ pubkey }: { pubkey: string }) {
|
||||
return (
|
||||
<div className="center w-full flex-col items-stretch space-y-6 text-primary">
|
||||
<Feed
|
||||
filter={{
|
||||
authors: authors,
|
||||
kinds: [1],
|
||||
authors: [pubkey],
|
||||
kinds: [1, 3745 as NDKKind],
|
||||
}}
|
||||
loader={() => (
|
||||
<div className="center flex-col gap-y-4 pt-7 text-center">
|
||||
|
@ -42,22 +42,12 @@ export default function ProfilePage({
|
||||
const modal = useModal();
|
||||
const { currentUser, mySubscription, initSubscriptions } = useCurrentUser();
|
||||
const [activeTab, setActiveTab] = useState("feed");
|
||||
const [delegate, setDelegate] = useState<string>();
|
||||
const { type, data } = nip19.decode(npub);
|
||||
const pubkey = data.toString();
|
||||
|
||||
useEffect(() => {
|
||||
console.log("In affectr");
|
||||
if (mySubscription) {
|
||||
const _delegate = getTagValues("delegate", mySubscription.tags);
|
||||
console.log("Setting");
|
||||
setDelegate(_delegate);
|
||||
}
|
||||
}, [mySubscription]);
|
||||
useEffect(() => {
|
||||
initSubscriptions(pubkey);
|
||||
}, []);
|
||||
console.log("Delegate", delegate);
|
||||
// useEffect(() => {
|
||||
// initSubscriptions(pubkey);
|
||||
// }, []);
|
||||
if (type !== "npub") {
|
||||
throw new Error("Invalid list");
|
||||
}
|
||||
@ -171,11 +161,7 @@ export default function ProfilePage({
|
||||
setActiveTab={(t) => setActiveTab(t.name)}
|
||||
/>
|
||||
</div>
|
||||
{activeTab === "feed" ? (
|
||||
<ProfileFeed pubkey={pubkey} alt={delegate} />
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
{activeTab === "feed" ? <ProfileFeed pubkey={pubkey} /> : ""}
|
||||
{activeTab === "subscriptions" ? <Subscriptions pubkey={pubkey} /> : ""}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -31,9 +31,6 @@ import {
|
||||
} from "@/components/ui/tooltip";
|
||||
import { useKeyboardShortcut } from "@/lib/hooks/useKeyboardShortcut";
|
||||
|
||||
import { db } from "@nostr-dev-kit/ndk-cache-dexie";
|
||||
import { useLiveQuery } from "dexie-react-hooks";
|
||||
|
||||
const LoginModal = dynamic(() => import("@/components/Modals/Login"), {
|
||||
ssr: false,
|
||||
});
|
||||
@ -44,16 +41,6 @@ export default function AuthActions() {
|
||||
const { currentUser, logout, attemptLogin, initSubscriptions } =
|
||||
useCurrentUser();
|
||||
const { ndk } = useNDK();
|
||||
const friends = useLiveQuery(
|
||||
async () => {
|
||||
console.log("Calling", db);
|
||||
if (!db) return;
|
||||
const friends = await db.users.count();
|
||||
return friends;
|
||||
},
|
||||
// specify vars that affect query:
|
||||
[],
|
||||
);
|
||||
|
||||
useKeyboardShortcut(["shift", "ctrl", "u"], () => {
|
||||
if (currentUser) {
|
||||
@ -78,7 +65,6 @@ export default function AuthActions() {
|
||||
<Notifications user={currentUser} />
|
||||
<Relays />
|
||||
<UserMenu user={currentUser} logout={logout} />
|
||||
{friends}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import NDK, {
|
||||
import NDKInstance from "./instance";
|
||||
import { _loginWithNip07, _loginWithNip46, _loginWithSecret } from "./signers";
|
||||
import { Users } from "./Users";
|
||||
import { log } from "@/lib/utils";
|
||||
|
||||
interface NDKContext {
|
||||
ndk: NDK | undefined;
|
||||
@ -105,6 +106,7 @@ const NDKProvider = ({
|
||||
}
|
||||
|
||||
async function loginWithNip07() {
|
||||
log("func", "loginWithNip07");
|
||||
const res = await _loginWithNip07();
|
||||
if (res) {
|
||||
const { signer } = res;
|
||||
|
@ -68,7 +68,7 @@ export default function NDKInstance(explicitRelayUrls: string[]) {
|
||||
) {
|
||||
const explicitRelayUrls = await getExplicitRelays();
|
||||
const dexieAdapter = new NDKCacheAdapterDexie({
|
||||
dbName: "ndkcache",
|
||||
dbName: "flockstr-ndkcache",
|
||||
});
|
||||
const ndkInstance = new NDK({
|
||||
explicitRelayUrls,
|
||||
@ -81,6 +81,7 @@ export default function NDKInstance(explicitRelayUrls: string[]) {
|
||||
}
|
||||
|
||||
if (signer) {
|
||||
console.log("SIGNER", signer);
|
||||
_setSigner(signer);
|
||||
}
|
||||
|
||||
@ -96,6 +97,7 @@ export default function NDKInstance(explicitRelayUrls: string[]) {
|
||||
async function setSigner(
|
||||
signer: NDKPrivateKeySigner | NDKNip46Signer | NDKNip07Signer,
|
||||
) {
|
||||
console.log("SetSigner caled");
|
||||
loadNdk(signer);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ export default function Kind3745(props: KindCardProps) {
|
||||
const [passphrase, setPassphrase] = useState("");
|
||||
const [fetchingEvent, setFetchingEvent] = useState(false);
|
||||
const [decryptedEvent, setDecryptedEvent] = useState<Event>();
|
||||
const { ndk, fetchEvents } = useNDK();
|
||||
const { ndk, signer } = useNDK();
|
||||
useEffect(() => {
|
||||
if (ndk && !fetchingEvent && !decryptedEvent) {
|
||||
void handleFetchEvent();
|
||||
@ -40,22 +40,21 @@ export default function Kind3745(props: KindCardProps) {
|
||||
}, [ndk]);
|
||||
|
||||
async function handleFetchEvent() {
|
||||
if (!ndk) return;
|
||||
log("func", `handleFetchEvent(${pubkey})`);
|
||||
|
||||
if (!ndk || !currentUser) return;
|
||||
log("func", `handleFetchEvent()`);
|
||||
setFetchingEvent(true);
|
||||
try {
|
||||
const directMessageEvent = await ndk!.fetchEvent({
|
||||
const directMessageEvent = await ndk.fetchEvent({
|
||||
kinds: [4],
|
||||
authors: [pubkey],
|
||||
["#e"]: [id],
|
||||
["#p"]: [currentUser.pubkey],
|
||||
});
|
||||
if (directMessageEvent) {
|
||||
log("info", "direct msg decryption");
|
||||
console.log(directMessageEvent);
|
||||
if (!signer) return;
|
||||
await directMessageEvent.decrypt(
|
||||
new NDKUser({ hexpubkey: pubkey }),
|
||||
ndk!.signer,
|
||||
new NDKUser({ hexpubkey: directMessageEvent.pubkey }),
|
||||
signer,
|
||||
);
|
||||
const passphrase_ = directMessageEvent.content;
|
||||
if (!passphrase_) {
|
||||
@ -64,7 +63,6 @@ export default function Kind3745(props: KindCardProps) {
|
||||
}
|
||||
setPassphrase(passphrase_);
|
||||
const decrypedData = await decryptMessage(content, passphrase_);
|
||||
console.log("Decrypted", decrypedData);
|
||||
const hiddenEvent = EventSchema.safeParse(
|
||||
JSON.parse(decrypedData ?? ""),
|
||||
);
|
||||
|
@ -80,9 +80,6 @@ export async function createEventHandler(
|
||||
rawEventString,
|
||||
passphrase,
|
||||
);
|
||||
const signer = delegateSigner ?? ndk.signer!;
|
||||
const user = await signer.user();
|
||||
log("info", "Signer", user.toString());
|
||||
const newEvent = new NDKEvent(ndk, {
|
||||
content: encryptedRawEventString,
|
||||
kind: 3745,
|
||||
@ -90,11 +87,15 @@ export async function createEventHandler(
|
||||
["kind", event.kind.toString()],
|
||||
["client", "flockstr"],
|
||||
],
|
||||
pubkey: user.pubkey,
|
||||
pubkey,
|
||||
} as NostrEvent);
|
||||
await newEvent.sign(signer);
|
||||
await newEvent.sign();
|
||||
await newEvent.publish();
|
||||
|
||||
const messenger = delegateSigner ?? ndk.signer!;
|
||||
const user = await messenger.user();
|
||||
log("info", "Signer", user.toString());
|
||||
|
||||
if (list) {
|
||||
// Send DMs to subscribers
|
||||
const subscribers = getTagsValues("p", list.tags);
|
||||
@ -111,9 +112,9 @@ export async function createEventHandler(
|
||||
} as NostrEvent);
|
||||
await messageEvent.encrypt(
|
||||
new NDKUser({ hexpubkey: subscriber }),
|
||||
signer,
|
||||
messenger,
|
||||
);
|
||||
await messageEvent.sign(signer);
|
||||
await messageEvent.sign(messenger);
|
||||
await messageEvent.publish();
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ export default function useCurrentUser() {
|
||||
const shouldReconnect = localStorage.getItem("shouldReconnect");
|
||||
if (!shouldReconnect || typeof window.nostr === "undefined") return;
|
||||
const user = await loginWithNip07();
|
||||
console.log("Called loginWithNip07");
|
||||
if (!user) {
|
||||
throw new Error("NO auth");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user