Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: useSignAuthorization experimental hook #4377

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-oranges-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wagmi": minor
---

Added `useSignAuthorization` hook.
5 changes: 5 additions & 0 deletions .changeset/long-impalas-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/core": minor
---

Added `signAuthorization` action.
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
strategy:
matrix:
typescript-version: ['5.0.4', '5.1.6', '5.2.2', '5.3.3', '5.4.5', '5.5.2']
viem-version: ['2.21.28', 'latest']
viem-version: ['2.21.40', 'latest']

steps:
- name: Clone repository
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"sherif": "^1.0.0",
"simple-git-hooks": "^2.11.1",
"typescript": "5.5.4",
"viem": "2.21.28",
"viem": "2.21.40",
"vitest": "^2.1.1"
},
"packageManager": "[email protected]",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/actions/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test('insufficient funds', async () => {
value: 100000 ETH

Details: Insufficient funds for gas * price + value
Version: 2.21.28]
Version: 2.21.40]
`)
})

Expand All @@ -104,7 +104,7 @@ test('maxFeePerGas less than maxPriorityFeePerGas', async () => {
maxFeePerGas: 20 gwei
maxPriorityFeePerGas: 22 gwei

Version: 2.21.28]
Version: 2.21.40]
`)
})

Expand All @@ -124,7 +124,7 @@ test('contract revert (contract error)', async () => {
data: 0xa0712d6800000000000000000000000000000000000000000000000000000000000001a4

Details: execution reverted: revert: Token ID is taken
Version: 2.21.28]
Version: 2.21.40]
`)
})

Expand All @@ -144,6 +144,6 @@ test('contract revert (insufficient params)', async () => {
data: 0xa0712d68

Details: execution reverted
Version: 2.21.28]
Version: 2.21.40]
`)
})
2 changes: 1 addition & 1 deletion packages/core/src/actions/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('behavior: user rejected request', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to connect.
Version: 2.21.28]
Version: 2.21.40]
`)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/deployContract.test.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/src/actions/getToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ test('behavior: bogus token', async () => {
function: decimals()

Docs: https://viem.sh/docs/contract/multicall
Version: 2.21.28]
Version: 2.21.40]
`)
})
16 changes: 8 additions & 8 deletions packages/core/src/actions/readContracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
contracts,
chainId: mainnet.id,
})
expect(results).toMatchInlineSnapshot(`

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: Snapshot `default 1` mismatched - Expected + Received [ { - "result": 2n, - "status": "success", + "error": [ContractFunctionExecutionError: HTTP request failed. + + Status: 400 + URL: http://127.0.0.1:8545/3 + Request body: {"method":"eth_call","params":[{"data":"0x82ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a600000000000000000000000027a69ffba1e939ddcfecc8c7e0f967b872bac65c00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a6000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000426581d60000000000000000000000000000000000000000000000000000000000000000000000000000000001dfe7ca09e99d10835bf73044a23b73fc20623df0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000442f745c59000000000000000000000000a0cf798816d4b9b9866b5330eea46a18382f251e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to":"0xca11bde05977b3631167028862be2a173976ca11"},"latest"]} + + Raw Call Arguments: + to: 0xca11bde05977b3631167028862be2a173976ca11 + data: 0x82ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a600000000000000000000000027a69ffba1e939ddcfecc8c7e0f967b872bac65c00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a6000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000426581d60000000000000000000000000000000000000000000000000000000000000000000000000000000001dfe7ca09e99d10835bf73044a23b73fc20623df00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: toMatchInlineSnapshot cannot be called multiple times at the same location. ❯ packages/core/src/actions/readContracts.test.ts:65:19

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: toMatchInlineSnapshot cannot be called multiple times at the same location. ❯ packages/core/src/actions/readContracts.test.ts:65:19

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: toMatchInlineSnapshot cannot be called multiple times at the same location. ❯ packages/core/src/actions/readContracts.test.ts:65:19

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: Snapshot `default 1` mismatched - Expected + Received [ { - "result": 2n, - "status": "success", + "error": [ContractFunctionExecutionError: HTTP request failed. + + Status: 400 + URL: http://127.0.0.1:8545/3 + Request body: {"method":"eth_call","params":[{"data":"0x82ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a600000000000000000000000027a69ffba1e939ddcfecc8c7e0f967b872bac65c00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a6000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000426581d60000000000000000000000000000000000000000000000000000000000000000000000000000000001dfe7ca09e99d10835bf73044a23b73fc20623df0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000442f745c59000000000000000000000000a0cf798816d4b9b9866b5330eea46a18382f251e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to":"0xca11bde05977b3631167028862be2a173976ca11"},"latest"]} + + Raw Call Arguments: + to: 0xca11bde05977b3631167028862be2a173976ca11 + data: 0x82ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a600000000000000000000000027a69ffba1e939ddcfecc8c7e0f967b872bac65c00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a6000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000426581d60000000000000000000000000000000000000000000000000000000000000000000000000000000001dfe7ca09e99d10835bf73044a23b73fc20623df00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: toMatchInlineSnapshot cannot be called multiple times at the same location. ❯ packages/core/src/actions/readContracts.test.ts:65:19

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: toMatchInlineSnapshot cannot be called multiple times at the same location. ❯ packages/core/src/actions/readContracts.test.ts:65:19

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: toMatchInlineSnapshot cannot be called multiple times at the same location. ❯ packages/core/src/actions/readContracts.test.ts:65:19

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: Snapshot `default 1` mismatched - Expected + Received [ { - "result": 2n, - "status": "success", + "error": [ContractFunctionExecutionError: HTTP request failed. + + Status: 400 + URL: http://127.0.0.1:8545/3 + Request body: {"method":"eth_call","params":[{"data":"0x82ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a600000000000000000000000027a69ffba1e939ddcfecc8c7e0f967b872bac65c00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a6000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000426581d60000000000000000000000000000000000000000000000000000000000000000000000000000000001dfe7ca09e99d10835bf73044a23b73fc20623df0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000442f745c59000000000000000000000000a0cf798816d4b9b9866b5330eea46a18382f251e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to":"0xca11bde05977b3631167028862be2a173976ca11"},"latest"]} + + Raw Call Arguments: + to: 0xca11bde05977b3631167028862be2a173976ca11 + data: 0x82ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a600000000000000000000000027a69ffba1e939ddcfecc8c7e0f967b872bac65c00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000243684b4a6000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac00000000000000000000000000000000000000000000000000000000000000000000000000000000ecb504d39723b0be0e3a9aa33d646642d1051ee100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000426581d60000000000000000000000000000000000000000000000000000000000000000000000000000000001dfe7ca09e99d10835bf73044a23b73fc20623df00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000

Check failure on line 65 in packages/core/src/actions/readContracts.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test (1, 3)

packages/core/src/actions/readContracts.test.ts > default

Error: toMatchInlineSnapshot cannot be called multiple times at the same location. ❯ packages/core/src/actions/readContracts.test.ts:65:19
[
{
"result": 2n,
Expand Down Expand Up @@ -397,7 +397,7 @@
args: (0xA0Cf798816D4b9b9866b5330EEa46a18382f251e, 69420)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28]
Version: 2.21.40]
`,
)
})
Expand Down Expand Up @@ -450,7 +450,7 @@
args: (0xA0Cf798816D4b9b9866b5330EEa46a18382f251e, 69420)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28],
Version: 2.21.40],
"result": undefined,
"status": "failure",
},
Expand All @@ -464,7 +464,7 @@
args: (0xA0Cf798816D4b9b9866b5330EEa46a18382f251e, 69421)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28],
Version: 2.21.40],
"result": undefined,
"status": "failure",
},
Expand Down Expand Up @@ -502,7 +502,7 @@
args: (1e+31)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28]
Version: 2.21.40]
`,
)
})
Expand Down Expand Up @@ -561,7 +561,7 @@
args: (1e+31)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28],
Version: 2.21.40],
"result": undefined,
"status": "failure",
},
Expand All @@ -579,7 +579,7 @@
args: (1e+31)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28],
Version: 2.21.40],
"result": undefined,
"status": "failure",
},
Expand Down Expand Up @@ -617,7 +617,7 @@
args: (0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28]
Version: 2.21.40]
`,
)
})
Expand Down Expand Up @@ -669,7 +669,7 @@
args: (0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC)

Docs: https://viem.sh/docs/contract/readContract
Version: 2.21.28],
Version: 2.21.40],
"result": undefined,
"status": "failure",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test('behavior: value exceeds balance', async () => {
value: 99999 ETH

Details: Insufficient funds for gas * price + value
Version: 2.21.28]
Version: 2.21.40]
`)
await disconnect(config, { connector })
})
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/signMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('behavior: user rejected request', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to sign message.
Version: 2.21.28]
Version: 2.21.40]
`)
await disconnect(config, { connector: connector_ })
})
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/signTypedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('behavior: user rejected request', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to sign typed data.
Version: 2.21.28]
Version: 2.21.40]
`)
await disconnect(config, { connector: connector_ })
})
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/switchChain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('behavior: user rejected request', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to switch chain.
Version: 2.21.28]
Version: 2.21.40]
`)
await disconnect(config, { connector: connector_ })
})
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/connectors/mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('behavior: features.connectError', () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to connect.
Version: 2.21.28]
Version: 2.21.40]
`)
})

Expand Down Expand Up @@ -44,7 +44,7 @@ test('behavior: connector.getProvider request errors', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to sign typed data.
Version: 2.21.28]
Version: 2.21.40]
`)

expect(
Expand All @@ -56,7 +56,7 @@ test('behavior: connector.getProvider request errors', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to switch chain.
Version: 2.21.28]
Version: 2.21.40]
`)

expect(
Expand All @@ -68,7 +68,7 @@ test('behavior: connector.getProvider request errors', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to switch chain.
Version: 2.21.28]
Version: 2.21.40]
`)

expect(
Expand All @@ -80,7 +80,7 @@ test('behavior: connector.getProvider request errors', async () => {
[UserRejectedRequestError: User rejected the request.

Details: Failed to sign message.
Version: 2.21.28]
Version: 2.21.40]
`)
})

Expand Down
68 changes: 68 additions & 0 deletions packages/core/src/experimental/actions/signAuthorization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { address, config, privateKey } from '@wagmi/test'
import { expect, test } from 'vitest'

import { privateKeyToAccount } from 'viem/accounts'
import { connect } from '../../actions/connect.js'
import { disconnect } from '../../actions/disconnect.js'
import { signAuthorization } from './signAuthorization.js'

const account = privateKeyToAccount(privateKey)
const connector = config.connectors[0]!

test('default', async () => {
await connect(config, { connector })
await expect(
signAuthorization(config, {
account,
contractAddress: address.wagmiMintExample,
chainId: config.chains[0].id,
nonce: 0,
}),
).resolves.toMatchInlineSnapshot(
`
{
"chainId": 1,
"contractAddress": "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
"nonce": 0,
"r": "0xff5d79daa56d5aae2657e8950af71377f8c2860255a9c915948c071ef9286def",
"s": "0x17318a10ff56f0000a350a210fdb312ba22260a64f38dddc135912a6c4795c1d",
"v": 27n,
"yParity": 0,
}`,
)
await disconnect(config, { connector })
})

test('behavior: not connected', async () => {
await expect(
signAuthorization(config, {
account,
contractAddress: address.wagmiMintExample,
chainId: config.chains[0].id,
nonce: 0,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[ConnectorNotConnectedError: Connector not connected.

Version: @wagmi/[email protected]]
`)
})

test('behavior: unsupported account type', async () => {
await connect(config, { connector })
await expect(
signAuthorization(config, {
contractAddress: address.wagmiMintExample,
chainId: config.chains[0].id,
nonce: 0,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[AccountTypeNotSupportedError: Account type "json-rpc" is not supported.

The \`signAuthorization\` Action does not support JSON-RPC Accounts.

Docs: https://viem.sh/experimental/eip7702/signAuthorization
Version: [email protected]]
`)
await disconnect(config, { connector })
})
51 changes: 51 additions & 0 deletions packages/core/src/experimental/actions/signAuthorization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { Account } from 'viem'
import {
type SignAuthorizationErrorType as viem_SignAuthorizationErrorType,
type SignAuthorizationParameters as viem_SignAuthorizationParameters,
type SignAuthorizationReturnType as viem_SignAuthorizationReturnType,
signAuthorization as viem_signAuthorization,
} from 'viem/experimental'

import {
type GetConnectorClientErrorType,
getConnectorClient,
} from '../../actions/getConnectorClient.js'
import type { Config } from '../../createConfig.js'
import type { BaseErrorType, ErrorType } from '../../errors/base.js'
import type { ConnectorParameter } from '../../types/properties.js'
import type { Compute } from '../../types/utils.js'

export type SignAuthorizationParameters = Compute<
viem_SignAuthorizationParameters<Account> & ConnectorParameter
>

export type SignAuthorizationReturnType = viem_SignAuthorizationReturnType

export type SignAuthorizationErrorType =
// getConnectorClient()
| GetConnectorClientErrorType
// base
| BaseErrorType
| ErrorType
// viem
| viem_SignAuthorizationErrorType

/** https://wagmi.sh/core/api/actions/signAuthorization */
export async function signAuthorization<config extends Config>(
config: config,
parameters: SignAuthorizationParameters,
) {
const { account, chainId, connector, ...rest } = parameters

const client = await getConnectorClient(config, {
account,
chainId,
connector,
})

return viem_signAuthorization(client, {
...rest,
account,
chainId,
})
}
15 changes: 15 additions & 0 deletions packages/core/src/experimental/query/signAuthorization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { config } from '@wagmi/test'
import { expect, test } from 'vitest'

import { signAuthorizationMutationOptions } from './signAuthorization.js'

test('default', () => {
expect(signAuthorizationMutationOptions(config)).toMatchInlineSnapshot(`
{
"mutationFn": [Function],
"mutationKey": [
"signAuthorization",
],
}
`)
})
Loading
Loading