# Prove control. Then sign in.

Source: https://docs.privatar.app/authentication

A public address is an identifier. A verified, fresh signature proves control for one specific sign-in request.

## The seven-line challenge

Create the challenge on your server, bind it to your configured origin, and store the exact message with a fresh cryptographic nonce. Its lifetime must not exceed five minutes.

Challenge format

```
Sign in to My application
Origin: https://my-application.example
Network: preprod
Address: <connected unshielded address>
Nonce: <32–128 hexadecimal characters>
Issued At: <canonical ISO timestamp>
Expires At: <canonical ISO timestamp>
```

The wallet checks all seven lines, the connected origin, network, address, and validity window before showing the request. The user must explicitly approve signing.

## The signed bytes

The wallet returns the original message, a 128-character hexadecimal signature, a 64-character hexadecimal verifying key, and `scheme: 'schnorr_bip340'`.

Server verification

```
const bytes = Buffer.from(proof.data, 'utf8');
const payload = Buffer.concat([
  Buffer.from('midnight_signed_message:' + bytes.length + ':'),
  bytes,
]);

const valid = verifySignature(
  proof.verifyingKey,
  payload,
  proof.signature,
);
```

The prefix uses the UTF-8 byte length, not the JavaScript string length. This is an authentication signature; it is not a zero-knowledge credential presentation.

## Verification checklist

- Find the server-owned challenge associated with this browser session.
- Reject expired, unknown, previously used, or changed messages.
- Require the supported signature scheme and bounded hexadecimal fields.
- Derive the unshielded address from the verifying key and encode it for the challenge network.
- Require an exact address match and verify the signature over the prefixed bytes.
- Consume the nonce once and create the application session only after all checks succeed.

## Application sessions

Use HttpOnly cookies and an explicit session lifetime. Connection state and application authentication are separate. Handle wallet disconnects and provide your own sign-out action.

**Never trust client-reported success.** Only your backend can decide that a nonce was issued, is unused, matches this session, and has a valid signature.
