# `Identity`

A class in `fastatp.identity` ([source](https://github.com/jacoblapenna/fastatp/blob/main/fastatp/identity.py#L133)).

```python
Identity(
    did: str,
    signer: Signer,
    storage: Storage,
    repo: Repo,
    signing_key: PrivateKey | None = None,
    domain: str | None = None,
    chain: ContinuityChain | None = None,
    state_dir: Path | None = None,
    curve: str = 'k256',
    rotation_private_key: PrivateKey | None = None,
)
```

A bootstrapped identity: its DID, signing key, durable repo, and (for a
`did:web` identity) its self-certifying continuity chain.

## Attributes

- `did: str`
- `signer: Signer`
- `storage: Storage`
- `repo: Repo`
- `signing_key: PrivateKey | None`
- `domain: str | None`
- `chain: ContinuityChain | None`
- `state_dir: Path | None`
- `curve: str`
- `rotation_private_key: PrivateKey | None`
- `store: BlockStore`: The repo's block store (`storage.blocks`).

## Methods

### `peer`

```python
peer(*, resolver: Any = None, authorize: Any = None) -> Peer
```

### `create_server`

```python
create_server(*, resolver: Any = None, **kwargs: Any) -> PeerServer
```

A PeerServer hosting this identity's durable repo.

### `pretty_document`

```python
pretty_document() -> DIDDocument
```

### `twin_document`

```python
twin_document() -> DIDDocument
```

### `rotate`

```python
async rotate(
    new_signing_key: PrivateKey | Signer,
    rotation_private_key: PrivateKey,
) -> None
```

Turn the page: sign a new document (with the new signing key) using
the supplied rotation pen, append it to the chain, switch the serving
key, and re-sign the repo head under the new key. The pen is checked
against the current head's `rotationKeys` before anything changes.
`new_signing_key` may be a [`Signer`](https://fastatp.com/api/signer.md): an identity can rotate
onto a hardware pen, or off one.

### `import_repo_car`

```python
async import_repo_car(data: bytes, *, verify: bool = True) -> None
```

Bring an existing repo's full CAR into this identity (checkpoint load).

With `verify=True` (default) the CAR's head commit must verify
against THIS identity's signing key — the adopt-your-did:web story:
same key, so the existing commit chain is already valid and nothing
needs re-signing. Persists the new head so a reload resumes from it.

### `adopt_web`

```python
async adopt_web(
    domain: str,
    signing_key: PrivateKey | Signer,
    state_dir: str | Path,
    *,
    rotation_public_keys: list[str] | None = None,
    persist_rotation_key: bool = False,
    storage: Storage | None = None,
) -> Identity
```

Adopt an EXISTING did:web into FastATP: same DID, same signing key.

The one difference from a fresh mint: the signing key is imported,
not generated (a [`Signer`](https://fastatp.com/api/signer.md) for a pen already in hardware; it is
then needed again on every load). Everything else is identical — a fresh continuity
chain genesis binds the domain to the *current* key, a fresh rotation
pen is returned once (or `rotation_public_keys` supplied off-box),
and an empty-genesis repo is created (see `import_repo_car` to
bring an existing repo across).

Because the key is unchanged, vanilla did:web resolvers observe
nothing: old records keep verifying, the served document merely gains
the twin alias. Be honest about the boundary: the chain certifies
custody FROM ADOPTION FORWARD — it cannot retroactively attest
pre-adoption history, and whoever holds this key at adoption time is
who the chain binds. Adopt with a key you still exclusively control.

The curve is inferred from the supplied key. Refuses to clobber a
`state_dir` that already holds an identity — adoption is a one-time
migration; use `bootstrap()` to load thereafter.

### `bootstrap`

```python
async bootstrap(
    *,
    domain: str | None = None,
    state_dir: str | Path | None = None,
    ephemeral_ok: bool = False,
    rotation_public_keys: list[str] | None = None,
    persist_rotation_key: bool = False,
    curve: str = 'k256',
    signer: Signer | None = None,
    storage: Storage | None = None,
) -> Identity
```

Stand up a durable peer: mint on the first call, load on every
later one. `signer` puts the pen in hardware: it is used in place of
a minted key, nothing secret is written, and it must be passed again
on every load (its public key is checked against the recorded one).
`storage` puts the repo in the builder's own database and must be
passed again on every load too; without it the repo lives in the
`state_dir`'s sqlite.
