From b06bbb48e6c6c7f81a9592ab9562bb8e3042b2b6 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 27 Sep 2026 08:29:00 -0700 Subject: Amber (NIP-55) signs you in on Android: one intent per request, the answer read off the clipboard or pasted. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #7. A "Sign in with Amber" door on Android opens nostrsigner: intents for get_public_key, sign_event and nip44 encrypt/decrypt, with a waiting card that reads the clipboard when the tab returns (or takes a paste). Requests queue one at a time — a sign-in fires the backup, relay list and follows together — and each answer is checked for its type so a stale clipboard is never mistaken for one. An interactive signer is not asked to decrypt DMs or private lists that arrive on their own; each trip through Amber is a deliberate one. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01VhUKyXKtsJ67QAFfb7QR9D --- src/features/messages.js | 8 +++++--- src/features/nostrlogin.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'src/features') diff --git a/src/features/messages.js b/src/features/messages.js index 16bc052..06cb6dd 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -2141,7 +2141,7 @@ export function messagesFeature(ctx) { dec: async (ct) => nip44.decrypt(ct, wallet.nostr.ck), }); const login = hook('nostrLoginIdentity'); - if (login && login.signer && login.signer.encryptSelf) out.push({ + if (login && login.signer && login.signer.encryptSelf && !login.signer.interactive) out.push({ pk: login.pubkey, sign: (e) => login.signer.signEvent(e), enc: (txt) => login.signer.encryptSelf(txt), @@ -2506,7 +2506,9 @@ export function messagesFeature(ctx) { const out = []; if (wallet.nostr && wallet.nostr.sk) out.push(wallet.nostr.sk); const login = hook('nostrLoginIdentity'); - if (login && login.signer && login.signer.decryptFrom) out.push(login.signer); + // an interactive signer (Amber by intent) is a trip through another app + // per call: never for a wrap that arrives on its own + if (login && login.signer && login.signer.decryptFrom && !login.signer.interactive) out.push(login.signer); return out; } // A "full-strength" attempt has every key this wallet expects: retries @@ -2515,7 +2517,7 @@ export function messagesFeature(ctx) { // sealed to the login npub. function decryptorsComplete() { const login = hook('nostrLoginIdentity'); - return !login || !!(login.signer && login.signer.decryptFrom); + return !login || !login.signer || !!login.signer.interactive || !!login.signer.decryptFrom; } // Raw-key unwraps (seed-derived / pasted nsec — the common case) run in diff --git a/src/features/nostrlogin.js b/src/features/nostrlogin.js index fef054b..306a12f 100644 --- a/src/features/nostrlogin.js +++ b/src/features/nostrlogin.js @@ -15,7 +15,8 @@ import { t } from '../i18n.js'; import { qrSvg } from '../qr.js'; import { extensionSigner, bunkerSigner, keySigner, parseNostrSecret, - walletForSigner, publishWalletBackup, fetchWalletBackup, nostrConnect, nostrConnectPending, resumeBunker } from '../nostr-login.js'; + walletForSigner, publishWalletBackup, fetchWalletBackup, nostrConnect, nostrConnectPending, resumeBunker, + amberAvailable, amberSigner, amberPending, amberDeliver, amberCancel, onAmberChange } from '../nostr-login.js'; // The nostr ostrich, in the brand's monochrome. const OSTRICH = ''; @@ -126,6 +127,7 @@ export function nostrLoginFeature(ctx) { ? ui.nostrLoginVia : signer && signer.kind === 'bunker' ? 'bunker' : signer && signer.kind === 'extension' ? 'extension' + : signer && signer.kind === 'amber' ? 'amber' : 'key'; const busy = (v) => { ui.nostrLoginBusy = v; render(); }; @@ -382,6 +384,22 @@ export function nostrLoginFeature(ctx) { // is a lazy chunk, so the two strings live here too). const GOOGLE_CENTRAL = 'https://auth.njump.me'; // flip to auth.coinos.io with pomegranate.js DEFAULT_CENTRAL const GOOGLE_LEGACY = 'https://auth.njump.me'; + // While a request is out with the signer app: what to do, and a way in for + // the answer when the browser won't read the clipboard for us. + onAmberChange(() => render()); + function amberWaitCard() { + const p = amberPending(); + if (!p) return null; + const e = ui.amberPaste || (ui.amberPaste = { text: '' }); + return h('div', { class: 'card col amber-wait', style: 'gap:8px' }, + h('div', { class: 'row gap6', style: 'align-items:center' }, h('span', { class: 'spinner sm' }), h('span', { class: 'small' }, t('nlAmberWait'))), + h('div', { class: 'small muted' }, t('nlAmberPasteHint')), + h('div', { class: 'row gap6' }, + h('input', { type: 'text', class: 'grow amber-paste', placeholder: t('nlAmberPastePh'), value: e.text, autocapitalize: 'none', autocomplete: 'off', spellcheck: 'false', + onInput: (ev) => { e.text = ev.target.value; } }), + h('button', { class: 'btn-sm', type: 'button', onClick: () => { if (amberDeliver(e.text)) e.text = ''; else { ui.nostrLoginError = t('nlAmberBadPaste'); render(); } } }, t('nlAmberPasteBtn'))), + h('button', { class: 'btn-ghost btn-sm', type: 'button', onClick: () => amberCancel() }, t('cancel'))); + } function externalButtons(run, big = false) { const hasPasskey = typeof window !== 'undefined' && !!window.PublicKeyCredential && !!navigator.credentials; const pad = big ? 'padding:14px' : ''; @@ -423,6 +441,13 @@ export function nostrLoginFeature(ctx) { onClick: () => run(() => extensionSigner()) }, t('nlExtension')) : null, nostrConnectSection(run), + // On Android, the signer app straight through an intent (NIP-55): works + // with Amber offline, no bunker, no relay — one trip through the app + // per signature. + amberAvailable() + ? h('button', { class: 'btn-block', disabled: ui.nostrLoginBusy, onClick: () => run(() => amberSigner()) }, t('nlAmber')) + : null, + amberWaitCard(), // These are alternatives, not steps: without the divider the field under // the button reads as something you also have to fill in. h('div', { class: 'or-split' }, h('span', {}, t('or'))), @@ -585,6 +610,9 @@ export function nostrLoginFeature(ctx) { if (s.pubkey === st.pubkey) return (live = s); } catch {} } + // an Android signer app: the stored pubkey is the whole session, and + // coming back needs no round trip (the first signature will be one) + if (st.session && st.session.amber === st.pubkey) return (live = await amberSigner({ pubkey: st.pubkey })); if (st.session) { try { const s = await resumeBunker(st.session, { onAuth: (url) => { ui.nostrLoginAuthUrl = url; render(); } }); @@ -604,7 +632,7 @@ export function nostrLoginFeature(ctx) { // Which door this account came through, for the reconnect surfaces. State // saved before `via` existed: a stored session means a bunker; without one // it could be extension, key, or passkey — offer everything. - const reconnectViaOf = (st) => st.via || (st.session ? 'bunker' : 'legacy'); + const reconnectViaOf = (st) => st.via || (st.session && st.session.amber ? 'amber' : st.session ? 'bunker' : 'legacy'); // Fire-and-forget resume for render paths: heal the badge without anyone // tapping, repaint when it lands. resumeLogin's own gating keeps this from -- cgit v1.2.3