Fix Amber login: store as 'amber' type (NIP-55) not 'bunker' (NIP-46)
The nostrconnect flow was incorrectly creating a bunker login and trying to do NIP-46 key exchange. Amber signs as the user's own key directly, so the pubkey from the connect response IS the user pubkey. Now stores a proper amber login which uses AmberSigner via useCurrentUser. Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
parent
03ea569a2a
commit
e3dd66d078
1 changed files with 10 additions and 29 deletions
|
|
@ -12,7 +12,7 @@ import { useToast } from '@/hooks/useToast';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { NLogin } from '@nostrify/react/login';
|
import { NLogin } from '@nostrify/react/login';
|
||||||
import { useNostrLogin } from '@nostrify/react/login';
|
import { useNostrLogin } from '@nostrify/react/login';
|
||||||
import { NConnectSigner, NSecSigner, NRelay1 } from '@nostrify/nostrify';
|
|
||||||
import { SimplePool, generateSecretKey, getPublicKey, nip19, nip04 } from 'nostr-tools';
|
import { SimplePool, generateSecretKey, getPublicKey, nip19, nip04 } from 'nostr-tools';
|
||||||
|
|
||||||
interface LoginDialogProps {
|
interface LoginDialogProps {
|
||||||
|
|
@ -119,33 +119,14 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
|
||||||
if (elapsedIntervalRef.current) { clearInterval(elapsedIntervalRef.current); elapsedIntervalRef.current = null; }
|
if (elapsedIntervalRef.current) { clearInterval(elapsedIntervalRef.current); elapsedIntervalRef.current = null; }
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Complete login once we have signerPubkey from any source
|
// Complete login — store as 'amber' type (NIP-55), not bunker.
|
||||||
const completeLogin = useCallback(async (signerPubkey: string, clientSk: Uint8Array, clientNsec: string, relays: string[]) => {
|
// Amber signs as the user's own key, so signerPubkey IS the user's pubkey.
|
||||||
setAmberStatus('Getting your pubkey...');
|
const completeLogin = useCallback(async (signerPubkey: string) => {
|
||||||
let userPubkey = signerPubkey;
|
setAmberStatus('Logging in...');
|
||||||
|
console.log('[Amber] Completing login for pubkey:', signerPubkey);
|
||||||
|
|
||||||
// Try to get the real user pubkey via NConnectSigner
|
// Store as amber login type — picked up by useCurrentUser → AmberSigner
|
||||||
try {
|
const nlogin = new NLogin('amber' as Parameters<typeof NLogin>[0], signerPubkey);
|
||||||
const clientSigner = new NSecSigner(clientSk);
|
|
||||||
const relay = new NRelay1(relays[0]);
|
|
||||||
const signer = new NConnectSigner({
|
|
||||||
pubkey: signerPubkey,
|
|
||||||
signer: clientSigner,
|
|
||||||
relay,
|
|
||||||
timeout: 15000,
|
|
||||||
});
|
|
||||||
userPubkey = await signer.getPublicKey();
|
|
||||||
try { relay.close(); } catch { /* ignore */ }
|
|
||||||
} catch {
|
|
||||||
// Amber signs as the user's key directly, so signerPubkey IS the userPubkey
|
|
||||||
userPubkey = signerPubkey;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nlogin = new NLogin('bunker', userPubkey, {
|
|
||||||
bunkerPubkey: signerPubkey,
|
|
||||||
clientNsec,
|
|
||||||
relays,
|
|
||||||
});
|
|
||||||
addLogin(nlogin);
|
addLogin(nlogin);
|
||||||
setLogin(nlogin.id);
|
setLogin(nlogin.id);
|
||||||
clearPendingNC();
|
clearPendingNC();
|
||||||
|
|
@ -193,7 +174,7 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
|
||||||
freshPool.close(NOSTRCONNECT_RELAYS);
|
freshPool.close(NOSTRCONNECT_RELAYS);
|
||||||
pendingRef.current = null;
|
pendingRef.current = null;
|
||||||
abortRef.current?.abort();
|
abortRef.current?.abort();
|
||||||
await completeLogin(event.pubkey, clientSk, pending.clientNsec, pending.relays);
|
await completeLogin(event.pubkey);
|
||||||
resolve();
|
resolve();
|
||||||
} catch { /* wrong encryption key or malformed event */ }
|
} catch { /* wrong encryption key or malformed event */ }
|
||||||
},
|
},
|
||||||
|
|
@ -343,7 +324,7 @@ export const LoginDialog: React.FC<LoginDialogProps> = ({ isOpen, onClose, onLog
|
||||||
console.log('[Amber] Valid response — completing login');
|
console.log('[Amber] Valid response — completing login');
|
||||||
controller.abort();
|
controller.abort();
|
||||||
pendingRef.current = null;
|
pendingRef.current = null;
|
||||||
await completeLogin(event.pubkey, clientSk, clientNsec, NOSTRCONNECT_RELAYS);
|
await completeLogin(event.pubkey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Amber] Failed to decrypt event:', e);
|
console.warn('[Amber] Failed to decrypt event:', e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue