# AuthorizationTempo.from

Converts an EIP-7702 Authorization object into a typed [`AuthorizationTempo.AuthorizationTempo`](/tempo/reference/AuthorizationTempo/types#authorizationtempo).

Tempo extends EIP-7702 to support secp256k1, P256, and WebAuthn signature types.

[Tempo Authorization Specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#tempo-authorization-list)

## Imports

:::code-group
```ts [Named]
import { AuthorizationTempo } from 'ox/tempo'
```

```ts [Entrypoint]
import * as AuthorizationTempo from 'ox/tempo/AuthorizationTempo'
```
:::

## Examples

An Authorization can be instantiated from an EIP-7702 Authorization tuple in object format.

```ts twoslash
import { AuthorizationTempo } from 'ox/tempo'

const authorization = AuthorizationTempo.from({
  address: '0x1234567890abcdef1234567890abcdef12345678',
  chainId: 1,
  nonce: 69n
})
```

### Attaching Signatures (Secp256k1)

Standard Ethereum ECDSA signature using the secp256k1 curve.

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

const privateKey = Secp256k1.randomPrivateKey()

const authorization = AuthorizationTempo.from({
  address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
  chainId: 1,
  nonce: 40n
})

const signature = Secp256k1.sign({
  payload: AuthorizationTempo.getSignPayload(authorization),
  privateKey
})

const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature } // [!code focus]
)
```

### Attaching Signatures (P256)

ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the public key and a `prehash` flag indicating whether the payload was hashed before signing.

```ts twoslash
import { P256 } from 'ox'
import {
  AuthorizationTempo,
  SignatureEnvelope
} from 'ox/tempo'

const { privateKey, publicKey } = P256.createKeyPair()

const authorization = AuthorizationTempo.from({
  address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
  chainId: 1,
  nonce: 40n
})

const signature = P256.sign({
  payload: AuthorizationTempo.getSignPayload(authorization),
  privateKey
})
const signatureEnvelope = SignatureEnvelope.from({
  signature,
  publicKey,
  prehash: false
})

const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature: signatureEnvelope } // [!code focus]
)
```

### Attaching Signatures (P256 WebCrypto)

When using WebCrypto keys, `prehash` must be `true` since WebCrypto always hashes the payload internally before signing.

```ts twoslash
// @noErrors
import { WebCryptoP256 } from 'ox'
import {
  AuthorizationTempo,
  SignatureEnvelope
} from 'ox/tempo'

const { privateKey, publicKey } =
  await WebCryptoP256.createKeyPair()

const authorization = AuthorizationTempo.from({
  address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
  chainId: 1,
  nonce: 40n
})

const signature = await WebCryptoP256.sign({
  payload: AuthorizationTempo.getSignPayload(authorization),
  privateKey
})
const signatureEnvelope = SignatureEnvelope.from({
  signature,
  publicKey,
  prehash: true
})

const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature: signatureEnvelope } // [!code focus]
)
```

### Attaching Signatures (WebAuthn)

Passkey-based signature using WebAuthn. Includes authenticator metadata (authenticatorData and clientDataJSON) along with the P-256 signature and public key.

```ts twoslash
// @noErrors
import { WebAuthnP256 } from 'ox'
import {
  AuthorizationTempo,
  SignatureEnvelope
} from 'ox/tempo'

const credential = await WebAuthnP256.createCredential({
  name: 'Example'
})

const authorization = AuthorizationTempo.from({
  address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
  chainId: 1,
  nonce: 40n
})

const { metadata, signature } = await WebAuthnP256.sign({
  challenge:
    AuthorizationTempo.getSignPayload(authorization),
  credentialId: credential.id
})
const signatureEnvelope = SignatureEnvelope.from({
  signature,
  publicKey: credential.publicKey,
  metadata
})

const authorization_signed = AuthorizationTempo.from(
  authorization,
  { signature: signatureEnvelope } // [!code focus]
)
```

## Definition

```ts
function from<authorization, signature>(
  authorization: authorization | AuthorizationTempo,
  options?: from.Options<signature>,
): from.ReturnType<authorization, signature>
```

**Source:** [src/tempo/AuthorizationTempo.ts](https://github.com/wevm/ox/blob/main/src/tempo/AuthorizationTempo.ts#L954)

## Parameters

### authorization

* **Type:** `authorization | AuthorizationTempo`

An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple in object format.

### options

* **Type:** `from.Options<signature>`
* **Optional**

AA Authorization options.

#### options.signature

* **Type:** `signature | SignatureEnvelope`
* **Optional**

The [`SignatureEnvelope.SignatureEnvelope`](/tempo/reference/SignatureEnvelope/types#signatureenvelope) to attach to the AA Authorization.

## Return Type

The [`AuthorizationTempo.AuthorizationTempo`](/tempo/reference/AuthorizationTempo/types#authorizationtempo).

`from.ReturnType<authorization, signature>`
