fix nsecbunker
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { NDKNip46Signer, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk';
|
import NDK, { NDKNip46Signer, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk';
|
||||||
import { readText } from '@tauri-apps/plugin-clipboard-manager';
|
import { readText } from '@tauri-apps/plugin-clipboard-manager';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
@@ -49,8 +49,13 @@ export function ImportAccountScreen() {
|
|||||||
await db.createSetting('nsecbunker', '1');
|
await db.createSetting('nsecbunker', '1');
|
||||||
await db.secureSave(`${pubkey}-nsecbunker`, localSigner.privateKey);
|
await db.secureSave(`${pubkey}-nsecbunker`, localSigner.privateKey);
|
||||||
|
|
||||||
const remoteSigner = new NDKNip46Signer(ndk, npub, localSigner);
|
const bunker = new NDK({
|
||||||
// await remoteSigner.blockUntilReady();
|
explicitRelayUrls: ['wss://relay.nsecbunker.com', 'wss://nostr.vulpem.com'],
|
||||||
|
});
|
||||||
|
bunker.connect();
|
||||||
|
|
||||||
|
const remoteSigner = new NDKNip46Signer(bunker, npub, localSigner);
|
||||||
|
await remoteSigner.blockUntilReady();
|
||||||
|
|
||||||
ndk.signer = remoteSigner;
|
ndk.signer = remoteSigner;
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export function NewPrivkeyScreen() {
|
|||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
autoCorrect="off"
|
autoCorrect="off"
|
||||||
autoCapitalize="off"
|
autoCapitalize="off"
|
||||||
className="h-11 w-full rounded-lg bg-neutral-100 px-3 py-2 placeholder:text-neutral-500 dark:bg-neutral-900 dark:placeholder:text-neutral-400"
|
className="h-11 rounded-lg border-transparent bg-neutral-100 px-3 placeholder:text-neutral-500 focus:border-blue-500 focus:ring focus:ring-blue-200 dark:bg-neutral-900 dark:placeholder:text-neutral-400 dark:focus:ring-blue-800"
|
||||||
/>
|
/>
|
||||||
<div className="mt-2 flex flex-col gap-2">
|
<div className="mt-2 flex flex-col gap-2">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -29,14 +29,22 @@ export const NDKInstance = () => {
|
|||||||
|
|
||||||
// NIP-46 Signer
|
// NIP-46 Signer
|
||||||
if (nsecbunker) {
|
if (nsecbunker) {
|
||||||
const localSignerPrivkey = await db.secureLoad(db.account.pubkey + '-nsecbunker');
|
const localSignerPrivkey = await db.secureLoad(`${db.account.pubkey}-nsecbunker`);
|
||||||
if (!localSignerPrivkey) return null;
|
if (!localSignerPrivkey) return null;
|
||||||
|
|
||||||
const localSigner = new NDKPrivateKeySigner(localSignerPrivkey);
|
const localSigner = new NDKPrivateKeySigner(localSignerPrivkey);
|
||||||
// await remoteSigner.blockUntilReady();
|
const bunker = new NDK({
|
||||||
return new NDKNip46Signer(ndk, db.account.id, localSigner);
|
explicitRelayUrls: ['wss://relay.nsecbunker.com', 'wss://nostr.vulpem.com'],
|
||||||
|
});
|
||||||
|
bunker.connect();
|
||||||
|
|
||||||
|
const remoteSigner = new NDKNip46Signer(bunker, db.account.id, localSigner);
|
||||||
|
await remoteSigner.blockUntilReady();
|
||||||
|
|
||||||
|
return remoteSigner;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Key Signer
|
// Privkey Signer
|
||||||
const userPrivkey = await db.secureLoad(db.account.pubkey);
|
const userPrivkey = await db.secureLoad(db.account.pubkey);
|
||||||
if (!userPrivkey) return null;
|
if (!userPrivkey) return null;
|
||||||
return new NDKPrivateKeySigner(userPrivkey);
|
return new NDKPrivateKeySigner(userPrivkey);
|
||||||
@@ -46,11 +54,6 @@ export const NDKInstance = () => {
|
|||||||
try {
|
try {
|
||||||
const outboxSetting = await db.getSettingValue('outbox');
|
const outboxSetting = await db.getSettingValue('outbox');
|
||||||
const bunkerSetting = await db.getSettingValue('nsecbunker');
|
const bunkerSetting = await db.getSettingValue('nsecbunker');
|
||||||
|
|
||||||
const bunker = !!parseInt(bunkerSetting);
|
|
||||||
const outbox = !!parseInt(outboxSetting);
|
|
||||||
|
|
||||||
const signer = await getSigner(bunker);
|
|
||||||
const explicitRelayUrls = normalizeRelayUrlSet([
|
const explicitRelayUrls = normalizeRelayUrlSet([
|
||||||
'wss://relay.damus.io',
|
'wss://relay.damus.io',
|
||||||
'wss://relay.nostr.band',
|
'wss://relay.nostr.band',
|
||||||
@@ -58,6 +61,9 @@ export const NDKInstance = () => {
|
|||||||
'wss://nostr.mutinywallet.com',
|
'wss://nostr.mutinywallet.com',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const bunker = !!parseInt(bunkerSetting);
|
||||||
|
const outbox = !!parseInt(outboxSetting);
|
||||||
|
|
||||||
const tauriAdapter = new NDKCacheAdapterTauri(db);
|
const tauriAdapter = new NDKCacheAdapterTauri(db);
|
||||||
const instance = new NDK({
|
const instance = new NDK({
|
||||||
explicitRelayUrls,
|
explicitRelayUrls,
|
||||||
@@ -67,10 +73,11 @@ export const NDKInstance = () => {
|
|||||||
autoConnectUserRelays: true,
|
autoConnectUserRelays: true,
|
||||||
autoFetchUserMutelist: true,
|
autoFetchUserMutelist: true,
|
||||||
clientName: 'Lume',
|
clientName: 'Lume',
|
||||||
clientNip89: 'Lume',
|
// clientNip89: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
// add signer if exist
|
// add signer if exist
|
||||||
|
const signer = await getSigner(bunker);
|
||||||
if (signer) instance.signer = signer;
|
if (signer) instance.signer = signer;
|
||||||
|
|
||||||
// connect
|
// connect
|
||||||
@@ -85,7 +92,7 @@ export const NDKInstance = () => {
|
|||||||
(user) => user.pubkey
|
(user) => user.pubkey
|
||||||
);
|
);
|
||||||
|
|
||||||
// prefetch data
|
// prefetch newsfeed
|
||||||
await queryClient.prefetchInfiniteQuery({
|
await queryClient.prefetchInfiniteQuery({
|
||||||
queryKey: ['newsfeed'],
|
queryKey: ['newsfeed'],
|
||||||
initialPageParam: 0,
|
initialPageParam: 0,
|
||||||
@@ -128,6 +135,7 @@ export const NDKInstance = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// prefetch notification
|
||||||
await queryClient.prefetchInfiniteQuery({
|
await queryClient.prefetchInfiniteQuery({
|
||||||
queryKey: ['notification'],
|
queryKey: ['notification'],
|
||||||
initialPageParam: 0,
|
initialPageParam: 0,
|
||||||
@@ -161,14 +169,12 @@ export const NDKInstance = () => {
|
|||||||
setFetcher(_fetcher);
|
setFetcher(_fetcher);
|
||||||
setRelayUrls(explicitRelayUrls);
|
setRelayUrls(explicitRelayUrls);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const yes = await ask(
|
console.error(e);
|
||||||
`Something wrong, Lume is not working as expected, do you want to relaunch app?`,
|
const yes = await ask(e, {
|
||||||
{
|
title: 'Lume',
|
||||||
title: 'Lume',
|
type: 'error',
|
||||||
type: 'error',
|
okLabel: 'Yes',
|
||||||
okLabel: 'Yes',
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
if (yes) relaunch();
|
if (yes) relaunch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function Logout() {
|
|||||||
|
|
||||||
// remove private key
|
// remove private key
|
||||||
await db.secureRemove(db.account.pubkey);
|
await db.secureRemove(db.account.pubkey);
|
||||||
await db.secureRemove(db.account.pubkey + '-bunker');
|
await db.secureRemove(db.account.pubkey + '-nsecbunker');
|
||||||
|
|
||||||
// logout
|
// logout
|
||||||
await db.accountLogout();
|
await db.accountLogout();
|
||||||
|
|||||||
@@ -124,10 +124,10 @@ export function NotifyNote({ event }: { event: NDKEvent }) {
|
|||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<div className="w-full px-3">
|
<div className="w-full px-3">
|
||||||
<div className="flex h-min w-full flex-col gap-3 rounded-lg bg-neutral-100 p-3 dark:bg-neutral-900">
|
<div className="flex h-min w-full flex-col gap-3 rounded-lg bg-neutral-100 p-3 dark:bg-neutral-900">
|
||||||
{thread.replyEventId ? (
|
{thread?.replyEventId ? (
|
||||||
<ChildNote id={thread.replyEventId} />
|
<ChildNote id={thread?.replyEventId} />
|
||||||
) : thread.rootEventId ? (
|
) : thread?.rootEventId ? (
|
||||||
<ChildNote id={thread.rootEventId} isRoot />
|
<ChildNote id={thread?.rootEventId} isRoot />
|
||||||
) : null}
|
) : null}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
Reference in New Issue
Block a user