/** * Pick which wallet account signs. We must sign with the account the user * actually connected — never guess. A wrong signer produces a useless signature * for a payment, so we throw instead of silently falling back. */ export function resolveSigningAccount( accounts: ReadonlyArray, connectedAddress: string | null | undefined ): T { if (connectedAddress) { const match = accounts.find(a => a.address === connectedAddress) if (!match) { throw new Error( 'Connected Solana account not found in the wallet — refusing to sign with a different account' ) } return match } // No explicit selection is only safe when the wallet has exactly one account. if (accounts.length === 1) return accounts[0]! throw new Error( 'Cannot determine which Solana account to sign with — multiple accounts and none selected' ) }