98 lines
2.2 KiB
Markdown
98 lines
2.2 KiB
Markdown
---
|
|
description: Recovers the original signing address from a signed Authorization object.
|
|
---
|
|
|
|
# recoverAuthorizationAddress
|
|
|
|
Recovers the original signing address from a signed Authorization object.
|
|
|
|
## Import
|
|
|
|
```ts twoslash
|
|
import { recoverAuthorizationAddress } from 'viem/utils'
|
|
```
|
|
|
|
## Usage
|
|
|
|
:::code-group
|
|
|
|
```ts twoslash [example.ts]
|
|
import { privateKeyToAccount } from 'viem/accounts'
|
|
import { recoverAuthorizationAddress } from 'viem/utils' // [!code focus]
|
|
import { walletClient } from './client'
|
|
|
|
const eoa = privateKeyToAccount('0x...')
|
|
|
|
const authorization = await walletClient.signAuthorization({
|
|
account: eoa,
|
|
authorization: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
|
|
})
|
|
|
|
const address = await recoverAuthorizationAddress({ // [!code focus]
|
|
authorization, // [!code focus]
|
|
}) // [!code focus]
|
|
```
|
|
|
|
```ts twoslash [client.ts] filename="client.ts"
|
|
import { createWalletClient, http } from 'viem'
|
|
import { mainnet } from 'viem/chains'
|
|
|
|
export const walletClient = createWalletClient({
|
|
chain: mainnet,
|
|
transport: http(),
|
|
})
|
|
```
|
|
|
|
:::
|
|
|
|
## Returns
|
|
|
|
`Address`
|
|
|
|
The address that signed the Authorization object.
|
|
|
|
## Parameters
|
|
|
|
### authorization
|
|
|
|
- **Type:** `Authorization | SignedAuthorization`
|
|
|
|
The Authorization object that was signed.
|
|
|
|
```ts twoslash
|
|
import { recoverAuthorizationAddress } from 'viem/utils'
|
|
import { walletClient } from './client'
|
|
// ---cut---
|
|
const authorization = await walletClient.signAuthorization({
|
|
authorization: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
|
|
})
|
|
const address = await recoverAuthorizationAddress({
|
|
authorization, // [!code focus]
|
|
})
|
|
```
|
|
|
|
### signature
|
|
|
|
- **Type:** `Hex | ByteArray | Signature | SignedAuthorization`
|
|
|
|
The signature that was generated by signing the Authorization object with the address's private key.
|
|
|
|
```ts twoslash
|
|
import { recoverAuthorizationAddress } from 'viem/utils'
|
|
import { walletClient } from './client'
|
|
// ---cut---
|
|
const signature = await walletClient.signAuthorization({
|
|
contractAddress: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
|
|
chainId: 1,
|
|
nonce: 0,
|
|
})
|
|
|
|
const address = await recoverAuthorizationAddress({
|
|
authorization: {
|
|
contractAddress: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
|
|
chainId: 1,
|
|
nonce: 0,
|
|
},
|
|
signature, // [!code focus]
|
|
})
|
|
``` |