# sign-in-with-solana (siws-allowlist)

Sign in with Solana for the Kognai LAX tender (seat SEAT9, job 6417a35b): let a Solana wallet sign in, checked against an allowlist.

The message format (domain, address, nonce, issued at, expiry), ed25519 verification, a replay guard and an allowlist check. Pure TypeScript with no runtime dependencies: ed25519 comes from node:crypto, base58 is built in. No network; the clock and the nonce store are passed in.

## Interface

```ts
import { createMessage, verify } from 'siws-allowlist';

const message = createMessage({
  domain: 'app.kognai.ai', address, nonce, issuedAt: new Date(now).toISOString(),
  expirationTime: new Date(now + 10 * 60_000).toISOString(),
  statement: 'Sign in to the Kognai citizen app.',   // optional, one line
  // uri (default https://<domain>), chainId (default mainnet)
});
// the wallet signs the UTF 8 bytes of message (signMessage), base58 or raw bytes
const v = verify({ message, signature, address, allowlist, now: Date.now(), seen, domain: 'app.kognai.ai' });
// { ok: true, reason: 'signed in', fields } or { ok: false, reason }
```

`seen` is the replay guard (a Set, or any store with `has` and `add`); a nonce is recorded only after a successful sign in, so a failed attempt cannot burn it. `domain` is the domain this server expects. `allowlist` is any iterable of base58 addresses (array or Set); matching is exact.

Message format, lines joined by a newline, no trailing newline (the statement block is optional):

```
<domain> wants you to sign in with your Solana account:
<address>

<statement>

URI: <uri>
Version: 1
Chain ID: <chainId>
Nonce: <nonce>
Issued At: <ISO 8601 UTC>
Expiration Time: <ISO 8601 UTC>
```

## What is refused

`verify` never throws; every refusal has a plain reason.

| Case | Reason |
|---|---|
| wrong domain | the message is for X, not Y (wrong domain) |
| expired (now at or after the expiry) | the message expired |
| not yet valid | the message is not valid yet |
| replayed nonce | the nonce was already used (replay) |
| address not on the allowlist | the address is not on the allowlist |
| malformed signature (not 64 bytes as base58, base64 or bytes) | the signature is malformed |
| signed by another key, or message changed | the signature does not match the address |
| address differs from the message | the address does not match the message |
| not this message format | the message is not a Sign in with Solana message |

## Tests

```
npm install
npm test           # node:test, acceptance cases A1 to A10
npm run coverage   # c8, fails under 100 percent
npm run mutants    # 7 planted bugs, each must fail the suite
```

Acceptance from the spec: valid (A1), wrong domain (A2), expired (A3), replayed nonce (A4), address not on the allowlist (A5), malformed signature (A6). Coverage of src: 100 percent statements, branches, functions and lines. Test keys come from fixed throwaway seeds and hold nothing.

## Licence

MIT. Built by AgentGate Builder (Crypto Money Maker swarm), an AI agent listed on LAX as lax-ext-d898c749478a.
