feat(signin): use the wallet's one-approval signIn when available

This commit is contained in:
2026-10-07 11:06:21 -04:00
parent 3b8f03eb9c
commit 84893bad58
2 changed files with 30 additions and 4 deletions
+19 -3
View File
@@ -89,8 +89,12 @@ export default function Home() {
try {
setError(null);
// Connect to extension (get public keys)
// A wallet with signIn connects and signs in one approval once a coin is
// chosen, so skip the separate connect prompt (and its unlock).
if (typeof window.smirk.signIn !== 'function') {
// Older wallets: connect first (get public keys), sign afterwards.
await window.smirk.connect();
}
setStep('choose-coin');
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to connect');
@@ -108,8 +112,20 @@ export default function Home() {
// Get challenge from backend
const challenge = await getChallenge(window.location.origin);
// Sign with the selected coin
const result = await window.smirk.signMessage(challenge.challenge);
// Sign with the selected coin: one approval on wallets with signIn, the
// older connect-then-sign path otherwise.
let result: SmirkSignResult | null = null;
if (typeof window.smirk.signIn === 'function') {
try {
result = await window.smirk.signIn(challenge.challenge, [coin]);
} catch (e) {
if ((e as { code?: string } | null)?.code !== 'UNSUPPORTED') throw e;
}
}
if (!result) {
if (!(await window.smirk.isConnected())) await window.smirk.connect();
result = await window.smirk.signMessage(challenge.challenge);
}
const sig = result.signatures.find((s) => s.asset === coin);
if (!sig) {
throw new Error(`No signature found for ${coin}`);
+10
View File
@@ -37,6 +37,10 @@ interface SmirkSignResult {
signatures: SmirkSignature[];
}
interface SmirkSignInResult extends SmirkSignResult {
publicKeys: SmirkPublicKeys;
}
interface SmirkClaimResult {
success: boolean;
txid?: string;
@@ -72,6 +76,12 @@ interface SmirkAPI {
getPublicKeys(): Promise<SmirkPublicKeys | null>;
getAddresses(): Promise<SmirkAddresses | null>;
signMessage(message: string): Promise<SmirkSignResult>;
/**
* Connect (when needed) and sign a login challenge in one approval, so a
* wallet that locks every time asks for the password once. Newer wallets
* only: feature-detect with `typeof window.smirk.signIn === 'function'`.
*/
signIn?(message: string, assets?: SmirkAsset[]): Promise<SmirkSignInResult>;
/**
* Request a payment from the user. Surfaces the Smirk send flow
* pre-filled with the asset/amount/address; user must approve.