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