# ZoneRpcAuthentication

Zone RPC authentication token utilities for private zone RPC access.

Zone RPC authentication tokens are short-lived, read-only credentials used in
the `X-Authorization-Token` header when talking to private zone RPC endpoints.
They reuse Tempo's multi-signature model, so secp256k1, P256, WebAuthn, and
keychain access-key signatures all share the same wire format as Tempo
transaction signatures.

[Zone RPC Specification](https://docs.tempo.xyz/protocol/privacy/rpc#authorization-tokens)

## Examples

```ts twoslash
import { Secp256k1 } from 'ox'
import { ZoneRpcAuthentication } from 'ox/tempo'

const authentication = ZoneRpcAuthentication.from({
  chainId: 4217000026,
  expiresAt: 1711235160,
  issuedAt: 1711234560,
  zoneId: 26,
  zonePortal: '0x0f1b0cedd7e8226e39ecb161f522c8b1ac45e9c8'
})

const signature = Secp256k1.sign({
  payload:
    ZoneRpcAuthentication.getSignPayload(authentication),
  privateKey: '0x...'
})

const token = ZoneRpcAuthentication.serialize(
  authentication,
  { signature }
)
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`ZoneRpcAuthentication.deserialize`](/tempo/reference/ZoneRpcAuthentication/deserialize) | Parses a serialized Zone RPC authentication token. |
| [`ZoneRpcAuthentication.from`](/tempo/reference/ZoneRpcAuthentication/from) | Instantiates a typed Zone RPC authentication token. |
| [`ZoneRpcAuthentication.getFields`](/tempo/reference/ZoneRpcAuthentication/getFields) | Returns the 29-byte fixed field suffix for a Zone RPC authentication token. |
| [`ZoneRpcAuthentication.getSignPayload`](/tempo/reference/ZoneRpcAuthentication/getSignPayload) | Computes the sign payload for a Zone RPC authentication token. |
| [`ZoneRpcAuthentication.hash`](/tempo/reference/ZoneRpcAuthentication/hash) | Computes the raw authorization hash for a Zone RPC authentication token. |
| [`ZoneRpcAuthentication.serialize`](/tempo/reference/ZoneRpcAuthentication/serialize) | Serializes a Zone RPC authentication token to hex. |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`ZoneRpcAuthentication.InvalidSerializedError`](/tempo/reference/ZoneRpcAuthentication/errors#zonerpcauthenticationinvalidserializederror) | Error thrown when a serialized authentication token cannot be deserialized. |
| [`ZoneRpcAuthentication.MissingSignatureError`](/tempo/reference/ZoneRpcAuthentication/errors#zonerpcauthenticationmissingsignatureerror) | Error thrown when serializing an authentication token without a signature. |

## Types

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`ZoneRpcAuthentication.Fields`](/tempo/reference/ZoneRpcAuthentication/types#zonerpcauthenticationfields) | 29-byte fixed Zone RPC authentication field suffix. |
| [`ZoneRpcAuthentication.Input`](/tempo/reference/ZoneRpcAuthentication/types#zonerpcauthenticationinput) | Input type for a Zone RPC authentication token. |
| [`ZoneRpcAuthentication.Serialized`](/tempo/reference/ZoneRpcAuthentication/types#zonerpcauthenticationserialized) | Hex-encoded serialized Zone RPC authentication token. |
| [`ZoneRpcAuthentication.Signed`](/tempo/reference/ZoneRpcAuthentication/types#zonerpcauthenticationsigned) | Signed Zone RPC authentication token. |
| [`ZoneRpcAuthentication.Version`](/tempo/reference/ZoneRpcAuthentication/types#zonerpcauthenticationversion) | Current Zone RPC authentication version. |
| [`ZoneRpcAuthentication.ZoneRpcAuthentication`](/tempo/reference/ZoneRpcAuthentication/types#zonerpcauthenticationzonerpcauthentication) | Root type for a Tempo Zone RPC authentication token. |
