viem 2.46.2 → 2.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/_cjs/actions/index.js +5 -3
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/public/getDelegation.js +21 -0
- package/_cjs/actions/public/getDelegation.js.map +1 -0
- package/_cjs/actions/public/simulateCalls.js +1 -1
- package/_cjs/actions/public/simulateCalls.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +12 -4
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendRawTransactionSync.js +1 -2
- package/_cjs/actions/wallet/sendRawTransactionSync.js.map +1 -1
- package/_cjs/chains/definitions/krown.js +26 -0
- package/_cjs/chains/definitions/krown.js.map +1 -0
- package/_cjs/chains/definitions/polygon.js +1 -1
- package/_cjs/chains/definitions/polygon.js.map +1 -1
- package/_cjs/chains/definitions/saigon.js +3 -3
- package/_cjs/chains/definitions/saigon.js.map +1 -1
- package/_cjs/chains/definitions/sei.js +3 -3
- package/_cjs/chains/definitions/sei.js.map +1 -1
- package/_cjs/chains/definitions/seiTestnet.js +3 -2
- package/_cjs/chains/definitions/seiTestnet.js.map +1 -1
- package/_cjs/chains/index.js +7 -7
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/decorators/public.js +2 -0
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Account.js +28 -15
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Addresses.js +2 -1
- package/_cjs/tempo/Addresses.js.map +1 -1
- package/_cjs/tempo/Decorator.js +11 -0
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +251 -0
- package/_cjs/tempo/actions/accessKey.js.map +1 -0
- package/_cjs/tempo/actions/index.js +2 -1
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/index.js +2 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/utils/abi/parseEventLogs.js +8 -6
- package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/public/getDelegation.js +43 -0
- package/_esm/actions/public/getDelegation.js.map +1 -0
- package/_esm/actions/public/simulateCalls.js +1 -1
- package/_esm/actions/public/simulateCalls.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +12 -4
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendRawTransactionSync.js +1 -2
- package/_esm/actions/wallet/sendRawTransactionSync.js.map +1 -1
- package/_esm/chains/definitions/krown.js +23 -0
- package/_esm/chains/definitions/krown.js.map +1 -0
- package/_esm/chains/definitions/polygon.js +1 -1
- package/_esm/chains/definitions/polygon.js.map +1 -1
- package/_esm/chains/definitions/saigon.js +3 -3
- package/_esm/chains/definitions/saigon.js.map +1 -1
- package/_esm/chains/definitions/sei.js +3 -3
- package/_esm/chains/definitions/sei.js.map +1 -1
- package/_esm/chains/definitions/seiTestnet.js +3 -2
- package/_esm/chains/definitions/seiTestnet.js.map +1 -1
- package/_esm/chains/index.js +1 -1
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/decorators/public.js +2 -0
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/Account.js +28 -16
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Addresses.js +1 -0
- package/_esm/tempo/Addresses.js.map +1 -1
- package/_esm/tempo/Decorator.js +11 -0
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +562 -0
- package/_esm/tempo/actions/accessKey.js.map +1 -0
- package/_esm/tempo/actions/index.js +1 -0
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/index.js +1 -1
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/utils/abi/parseEventLogs.js +11 -6
- package/_esm/utils/abi/parseEventLogs.js.map +1 -1
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/public/getDelegation.d.ts +46 -0
- package/_types/actions/public/getDelegation.d.ts.map +1 -0
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendRawTransactionSync.d.ts +1 -1
- package/_types/actions/wallet/sendRawTransactionSync.d.ts.map +1 -1
- package/_types/chains/definitions/abstract.d.ts +1 -0
- package/_types/chains/definitions/abstract.d.ts.map +1 -1
- package/_types/chains/definitions/abstractTestnet.d.ts +1 -0
- package/_types/chains/definitions/abstractTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/ancient8.d.ts +1 -0
- package/_types/chains/definitions/ancient8.d.ts.map +1 -1
- package/_types/chains/definitions/ancient8Sepolia.d.ts +1 -0
- package/_types/chains/definitions/ancient8Sepolia.d.ts.map +1 -1
- package/_types/chains/definitions/base.d.ts +2 -0
- package/_types/chains/definitions/base.d.ts.map +1 -1
- package/_types/chains/definitions/baseGoerli.d.ts +1 -0
- package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/baseSepolia.d.ts +2 -0
- package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/blast.d.ts +1 -0
- package/_types/chains/definitions/blast.d.ts.map +1 -1
- package/_types/chains/definitions/bob.d.ts +1 -0
- package/_types/chains/definitions/bob.d.ts.map +1 -1
- package/_types/chains/definitions/bobSepolia.d.ts +1 -0
- package/_types/chains/definitions/bobSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/codex.d.ts +1 -0
- package/_types/chains/definitions/codex.d.ts.map +1 -1
- package/_types/chains/definitions/codexTestnet.d.ts +1 -0
- package/_types/chains/definitions/codexTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/dchain.d.ts +1 -0
- package/_types/chains/definitions/dchain.d.ts.map +1 -1
- package/_types/chains/definitions/dchainTestnet.d.ts +1 -0
- package/_types/chains/definitions/dchainTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/elysiumTestnet.d.ts +1 -0
- package/_types/chains/definitions/elysiumTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/fraxtal.d.ts +1 -0
- package/_types/chains/definitions/fraxtal.d.ts.map +1 -1
- package/_types/chains/definitions/fraxtalTestnet.d.ts +1 -0
- package/_types/chains/definitions/fraxtalTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/funkiMainnet.d.ts +1 -0
- package/_types/chains/definitions/funkiMainnet.d.ts.map +1 -1
- package/_types/chains/definitions/funkiSepolia.d.ts +1 -0
- package/_types/chains/definitions/funkiSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/garnet.d.ts +1 -0
- package/_types/chains/definitions/garnet.d.ts.map +1 -1
- package/_types/chains/definitions/giwaSepolia.d.ts +2 -0
- package/_types/chains/definitions/giwaSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/ink.d.ts +1 -0
- package/_types/chains/definitions/ink.d.ts.map +1 -1
- package/_types/chains/definitions/inkSepolia.d.ts +1 -0
- package/_types/chains/definitions/inkSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/{seiDevnet.d.ts → krown.d.ts} +10 -10
- package/_types/chains/definitions/krown.d.ts.map +1 -0
- package/_types/chains/definitions/lisk.d.ts +1 -0
- package/_types/chains/definitions/lisk.d.ts.map +1 -1
- package/_types/chains/definitions/liskSepolia.d.ts +1 -0
- package/_types/chains/definitions/liskSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/metalL2.d.ts +1 -0
- package/_types/chains/definitions/metalL2.d.ts.map +1 -1
- package/_types/chains/definitions/mode.d.ts +1 -0
- package/_types/chains/definitions/mode.d.ts.map +1 -1
- package/_types/chains/definitions/modeTestnet.d.ts +1 -0
- package/_types/chains/definitions/modeTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/optimism.d.ts +1 -0
- package/_types/chains/definitions/optimism.d.ts.map +1 -1
- package/_types/chains/definitions/optimismGoerli.d.ts +1 -0
- package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/optimismSepolia.d.ts +1 -0
- package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/pgn.d.ts +1 -0
- package/_types/chains/definitions/pgn.d.ts.map +1 -1
- package/_types/chains/definitions/pgnTestnet.d.ts +1 -0
- package/_types/chains/definitions/pgnTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/playfiAlbireo.d.ts +1 -0
- package/_types/chains/definitions/playfiAlbireo.d.ts.map +1 -1
- package/_types/chains/definitions/polygon.d.ts +1 -1
- package/_types/chains/definitions/pyrope.d.ts +1 -0
- package/_types/chains/definitions/pyrope.d.ts.map +1 -1
- package/_types/chains/definitions/redstone.d.ts +1 -0
- package/_types/chains/definitions/redstone.d.ts.map +1 -1
- package/_types/chains/definitions/rss3.d.ts +1 -0
- package/_types/chains/definitions/rss3.d.ts.map +1 -1
- package/_types/chains/definitions/rss3Sepolia.d.ts +1 -0
- package/_types/chains/definitions/rss3Sepolia.d.ts.map +1 -1
- package/_types/chains/definitions/saigon.d.ts +3 -3
- package/_types/chains/definitions/sei.d.ts +3 -3
- package/_types/chains/definitions/seiTestnet.d.ts +3 -2
- package/_types/chains/definitions/seiTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/shape.d.ts +1 -0
- package/_types/chains/definitions/shape.d.ts.map +1 -1
- package/_types/chains/definitions/shapeSepolia.d.ts +1 -0
- package/_types/chains/definitions/shapeSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/snax.d.ts +1 -0
- package/_types/chains/definitions/snax.d.ts.map +1 -1
- package/_types/chains/definitions/snaxTestnet.d.ts +1 -0
- package/_types/chains/definitions/snaxTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/soneium.d.ts +1 -0
- package/_types/chains/definitions/soneium.d.ts.map +1 -1
- package/_types/chains/definitions/soneiumMinato.d.ts +1 -0
- package/_types/chains/definitions/soneiumMinato.d.ts.map +1 -1
- package/_types/chains/definitions/sophon.d.ts +1 -0
- package/_types/chains/definitions/sophon.d.ts.map +1 -1
- package/_types/chains/definitions/sophonTestnet.d.ts +1 -0
- package/_types/chains/definitions/sophonTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/superseed.d.ts +1 -0
- package/_types/chains/definitions/superseed.d.ts.map +1 -1
- package/_types/chains/definitions/superseedSepolia.d.ts +1 -0
- package/_types/chains/definitions/superseedSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/swellchain.d.ts +1 -0
- package/_types/chains/definitions/swellchain.d.ts.map +1 -1
- package/_types/chains/definitions/swellchainTestnet.d.ts +1 -0
- package/_types/chains/definitions/swellchainTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempo.d.ts +2 -0
- package/_types/chains/definitions/tempo.d.ts.map +1 -1
- package/_types/chains/definitions/tempoAndantino.d.ts +2 -0
- package/_types/chains/definitions/tempoAndantino.d.ts.map +1 -1
- package/_types/chains/definitions/tempoDevnet.d.ts +2 -0
- package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoLocalnet.d.ts +2 -0
- package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoModerato.d.ts +2 -0
- package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
- package/_types/chains/definitions/treasure.d.ts +1 -0
- package/_types/chains/definitions/treasure.d.ts.map +1 -1
- package/_types/chains/definitions/treasureTopaz.d.ts +1 -0
- package/_types/chains/definitions/treasureTopaz.d.ts.map +1 -1
- package/_types/chains/definitions/unichain.d.ts +1 -0
- package/_types/chains/definitions/unichain.d.ts.map +1 -1
- package/_types/chains/definitions/unichainSepolia.d.ts +1 -0
- package/_types/chains/definitions/unichainSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/worldchain.d.ts +1 -0
- package/_types/chains/definitions/worldchain.d.ts.map +1 -1
- package/_types/chains/definitions/worldchainSepolia.d.ts +1 -0
- package/_types/chains/definitions/worldchainSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/zircuit.d.ts +1 -0
- package/_types/chains/definitions/zircuit.d.ts.map +1 -1
- package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts +1 -0
- package/_types/chains/definitions/zircuitGarfieldTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zircuitTestnet.d.ts +1 -0
- package/_types/chains/definitions/zircuitTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zksync.d.ts +1 -0
- package/_types/chains/definitions/zksync.d.ts.map +1 -1
- package/_types/chains/definitions/zksyncInMemoryNode.d.ts +1 -0
- package/_types/chains/definitions/zksyncInMemoryNode.d.ts.map +1 -1
- package/_types/chains/definitions/zksyncLocalCustomHyperchain.d.ts +1 -0
- package/_types/chains/definitions/zksyncLocalCustomHyperchain.d.ts.map +1 -1
- package/_types/chains/definitions/zksyncLocalHyperchain.d.ts +1 -0
- package/_types/chains/definitions/zksyncLocalHyperchain.d.ts.map +1 -1
- package/_types/chains/definitions/zksyncLocalNode.d.ts +1 -0
- package/_types/chains/definitions/zksyncLocalNode.d.ts.map +1 -1
- package/_types/chains/definitions/zksyncSepoliaTestnet.d.ts +1 -0
- package/_types/chains/definitions/zksyncSepoliaTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zora.d.ts +1 -0
- package/_types/chains/definitions/zora.d.ts.map +1 -1
- package/_types/chains/definitions/zoraSepolia.d.ts +1 -0
- package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/zoraTestnet.d.ts +1 -0
- package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
- package/_types/chains/index.d.ts +1 -1
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +22 -0
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/op-stack/chainConfig.d.ts +1 -0
- package/_types/op-stack/chainConfig.d.ts.map +1 -1
- package/_types/op-stack/formatters.d.ts +1 -0
- package/_types/op-stack/formatters.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +20 -17
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Addresses.d.ts +1 -0
- package/_types/tempo/Addresses.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +340 -122
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/WebAuthnP256.d.ts +2 -2
- package/_types/tempo/WebAuthnP256.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +1174 -0
- package/_types/tempo/actions/accessKey.d.ts.map +1 -0
- package/_types/tempo/actions/index.d.ts +1 -0
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts +1 -0
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +1 -1
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +2 -2
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/types/transaction.d.ts +2 -0
- package/_types/types/transaction.d.ts.map +1 -1
- package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
- package/_types/zksync/chainConfig.d.ts +1 -0
- package/_types/zksync/chainConfig.d.ts.map +1 -1
- package/_types/zksync/formatters.d.ts +1 -0
- package/_types/zksync/formatters.d.ts.map +1 -1
- package/actions/index.ts +6 -0
- package/actions/public/getDelegation.ts +80 -0
- package/actions/public/simulateCalls.ts +1 -1
- package/actions/wallet/prepareTransactionRequest.ts +12 -4
- package/actions/wallet/sendRawTransactionSync.ts +2 -5
- package/chains/definitions/krown.ts +23 -0
- package/chains/definitions/polygon.ts +1 -1
- package/chains/definitions/saigon.ts +3 -3
- package/chains/definitions/sei.ts +3 -3
- package/chains/definitions/seiTestnet.ts +3 -2
- package/chains/index.ts +1 -1
- package/clients/decorators/public.ts +29 -0
- package/errors/version.ts +1 -1
- package/index.ts +5 -0
- package/package.json +2 -2
- package/tempo/Account.ts +58 -39
- package/tempo/Addresses.ts +1 -0
- package/tempo/Decorator.ts +373 -122
- package/tempo/WebAuthnP256.ts +5 -2
- package/tempo/actions/accessKey.ts +857 -0
- package/tempo/actions/index.ts +1 -0
- package/tempo/index.ts +1 -1
- package/types/eip1193.ts +2 -2
- package/types/transaction.ts +2 -0
- package/utils/abi/parseEventLogs.ts +13 -6
- package/_cjs/chains/definitions/seiDevnet.js +0 -22
- package/_cjs/chains/definitions/seiDevnet.js.map +0 -1
- package/_esm/chains/definitions/seiDevnet.js +0 -19
- package/_esm/chains/definitions/seiDevnet.js.map +0 -1
- package/_types/chains/definitions/seiDevnet.d.ts.map +0 -1
- package/chains/definitions/seiDevnet.ts +0 -19
|
@@ -0,0 +1,857 @@
|
|
|
1
|
+
import type { Address } from 'abitype'
|
|
2
|
+
import type { Account } from '../../accounts/types.js'
|
|
3
|
+
import { parseAccount } from '../../accounts/utils/parseAccount.js'
|
|
4
|
+
import type { ReadContractReturnType } from '../../actions/public/readContract.js'
|
|
5
|
+
import { readContract } from '../../actions/public/readContract.js'
|
|
6
|
+
import { sendTransaction } from '../../actions/wallet/sendTransaction.js'
|
|
7
|
+
import { sendTransactionSync } from '../../actions/wallet/sendTransactionSync.js'
|
|
8
|
+
import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js'
|
|
9
|
+
import { writeContract } from '../../actions/wallet/writeContract.js'
|
|
10
|
+
import { writeContractSync } from '../../actions/wallet/writeContractSync.js'
|
|
11
|
+
import type { Client } from '../../clients/createClient.js'
|
|
12
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
13
|
+
import type { BaseErrorType } from '../../errors/base.js'
|
|
14
|
+
import type { Chain } from '../../types/chain.js'
|
|
15
|
+
import type { GetEventArgs } from '../../types/contract.js'
|
|
16
|
+
import type { Log } from '../../types/log.js'
|
|
17
|
+
import type { Compute } from '../../types/utils.js'
|
|
18
|
+
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
|
|
19
|
+
import * as Abis from '../Abis.js'
|
|
20
|
+
import type { AccessKeyAccount } from '../Account.js'
|
|
21
|
+
import { signKeyAuthorization } from '../Account.js'
|
|
22
|
+
import * as Addresses from '../Addresses.js'
|
|
23
|
+
import type {
|
|
24
|
+
GetAccountParameter,
|
|
25
|
+
ReadParameters,
|
|
26
|
+
WriteParameters,
|
|
27
|
+
} from '../internal/types.js'
|
|
28
|
+
import { defineCall } from '../internal/utils.js'
|
|
29
|
+
import type { TransactionReceipt } from '../Transaction.js'
|
|
30
|
+
|
|
31
|
+
/** @internal */
|
|
32
|
+
const signatureTypes = {
|
|
33
|
+
0: 'secp256k1',
|
|
34
|
+
1: 'p256',
|
|
35
|
+
2: 'webAuthn',
|
|
36
|
+
} as const satisfies Record<number, string>
|
|
37
|
+
|
|
38
|
+
/** @internal */
|
|
39
|
+
const spendPolicies = {
|
|
40
|
+
true: 'limited',
|
|
41
|
+
false: 'unlimited',
|
|
42
|
+
} as const
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Authorizes an access key by signing a key authorization and sending a transaction.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { createClient, http } from 'viem'
|
|
50
|
+
* import { tempo } from 'viem/chains'
|
|
51
|
+
* import { Actions, Account } from 'viem/tempo'
|
|
52
|
+
* import { generatePrivateKey } from 'viem/accounts'
|
|
53
|
+
*
|
|
54
|
+
* const account = Account.from({ privateKey: '0x...' })
|
|
55
|
+
* const client = createClient({
|
|
56
|
+
* account,
|
|
57
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
58
|
+
* transport: http(),
|
|
59
|
+
* })
|
|
60
|
+
*
|
|
61
|
+
* const accessKey = Account.fromP256(generatePrivateKey(), {
|
|
62
|
+
* access: account,
|
|
63
|
+
* })
|
|
64
|
+
*
|
|
65
|
+
* const hash = await Actions.accessKey.authorize(client, {
|
|
66
|
+
* accessKey,
|
|
67
|
+
* expiry: Math.floor((Date.now() + 30_000) / 1000),
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @param client - Client.
|
|
72
|
+
* @param parameters - Parameters.
|
|
73
|
+
* @returns The transaction hash.
|
|
74
|
+
*/
|
|
75
|
+
export async function authorize<
|
|
76
|
+
chain extends Chain | undefined,
|
|
77
|
+
account extends Account | undefined,
|
|
78
|
+
>(
|
|
79
|
+
client: Client<Transport, chain, account>,
|
|
80
|
+
parameters: authorize.Parameters<chain, account>,
|
|
81
|
+
): Promise<authorize.ReturnValue> {
|
|
82
|
+
return authorize.inner(sendTransaction, client, parameters)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export namespace authorize {
|
|
86
|
+
export type Parameters<
|
|
87
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
88
|
+
account extends Account | undefined = Account | undefined,
|
|
89
|
+
> = WriteParameters<chain, account> & Args
|
|
90
|
+
|
|
91
|
+
export type Args = {
|
|
92
|
+
/** The access key to authorize. */
|
|
93
|
+
accessKey: Pick<AccessKeyAccount, 'accessKeyAddress' | 'keyType'>
|
|
94
|
+
/** The chain ID. */
|
|
95
|
+
chainId?: number | undefined
|
|
96
|
+
/** Unix timestamp when the key expires. */
|
|
97
|
+
expiry?: number | undefined
|
|
98
|
+
/** Spending limits per token. */
|
|
99
|
+
limits?: { token: Address; limit: bigint }[] | undefined
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type ReturnValue = WriteContractReturnType
|
|
103
|
+
|
|
104
|
+
// TODO: exhaustive error type
|
|
105
|
+
export type ErrorType = BaseErrorType
|
|
106
|
+
|
|
107
|
+
/** @internal */
|
|
108
|
+
export async function inner<
|
|
109
|
+
action extends typeof sendTransaction | typeof sendTransactionSync,
|
|
110
|
+
chain extends Chain | undefined,
|
|
111
|
+
account extends Account | undefined,
|
|
112
|
+
>(
|
|
113
|
+
action: action,
|
|
114
|
+
client: Client<Transport, chain, account>,
|
|
115
|
+
parameters: authorize.Parameters<chain, account>,
|
|
116
|
+
): Promise<ReturnType<action>> {
|
|
117
|
+
const {
|
|
118
|
+
accessKey,
|
|
119
|
+
chainId = client.chain?.id,
|
|
120
|
+
expiry,
|
|
121
|
+
limits,
|
|
122
|
+
...rest
|
|
123
|
+
} = parameters
|
|
124
|
+
const account_ = rest.account ?? client.account
|
|
125
|
+
if (!account_) throw new Error('account is required.')
|
|
126
|
+
if (!chainId) throw new Error('chainId is required.')
|
|
127
|
+
const parsed = parseAccount(account_)
|
|
128
|
+
const keyAuthorization = await signKeyAuthorization(parsed as never, {
|
|
129
|
+
chainId: BigInt(chainId),
|
|
130
|
+
key: accessKey,
|
|
131
|
+
expiry,
|
|
132
|
+
limits,
|
|
133
|
+
})
|
|
134
|
+
return (await action(client, {
|
|
135
|
+
...rest,
|
|
136
|
+
keyAuthorization,
|
|
137
|
+
} as never)) as never
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function extractEvent(logs: Log[]) {
|
|
141
|
+
const [log] = parseEventLogs({
|
|
142
|
+
abi: Abis.accountKeychain,
|
|
143
|
+
logs,
|
|
144
|
+
eventName: 'KeyAuthorized',
|
|
145
|
+
strict: true,
|
|
146
|
+
})
|
|
147
|
+
if (!log) throw new Error('`KeyAuthorized` event not found.')
|
|
148
|
+
return log
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Authorizes an access key and waits for the transaction receipt.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* import { createClient, http } from 'viem'
|
|
158
|
+
* import { tempo } from 'viem/chains'
|
|
159
|
+
* import { Actions, Account } from 'viem/tempo'
|
|
160
|
+
* import { generatePrivateKey } from 'viem/accounts'
|
|
161
|
+
*
|
|
162
|
+
* const account = Account.from({ privateKey: '0x...' })
|
|
163
|
+
* const client = createClient({
|
|
164
|
+
* account,
|
|
165
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
166
|
+
* transport: http(),
|
|
167
|
+
* })
|
|
168
|
+
*
|
|
169
|
+
* const accessKey = Account.fromP256(generatePrivateKey(), {
|
|
170
|
+
* access: account,
|
|
171
|
+
* })
|
|
172
|
+
*
|
|
173
|
+
* const { receipt, ...result } = await Actions.accessKey.authorizeSync(client, {
|
|
174
|
+
* accessKey,
|
|
175
|
+
* expiry: Math.floor((Date.now() + 30_000) / 1000),
|
|
176
|
+
* })
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @param client - Client.
|
|
180
|
+
* @param parameters - Parameters.
|
|
181
|
+
* @returns The transaction receipt and event data.
|
|
182
|
+
*/
|
|
183
|
+
export async function authorizeSync<
|
|
184
|
+
chain extends Chain | undefined,
|
|
185
|
+
account extends Account | undefined,
|
|
186
|
+
>(
|
|
187
|
+
client: Client<Transport, chain, account>,
|
|
188
|
+
parameters: authorizeSync.Parameters<chain, account>,
|
|
189
|
+
): Promise<authorizeSync.ReturnValue> {
|
|
190
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
191
|
+
const receipt = await authorize.inner(sendTransactionSync, client, {
|
|
192
|
+
...rest,
|
|
193
|
+
throwOnReceiptRevert,
|
|
194
|
+
} as never)
|
|
195
|
+
const { args } = authorize.extractEvent(receipt.logs)
|
|
196
|
+
return {
|
|
197
|
+
...args,
|
|
198
|
+
receipt,
|
|
199
|
+
} as never
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export namespace authorizeSync {
|
|
203
|
+
export type Parameters<
|
|
204
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
205
|
+
account extends Account | undefined = Account | undefined,
|
|
206
|
+
> = authorize.Parameters<chain, account>
|
|
207
|
+
|
|
208
|
+
export type Args = authorize.Args
|
|
209
|
+
|
|
210
|
+
export type ReturnValue = Compute<
|
|
211
|
+
GetEventArgs<
|
|
212
|
+
typeof Abis.accountKeychain,
|
|
213
|
+
'KeyAuthorized',
|
|
214
|
+
{ IndexedOnly: false; Required: true }
|
|
215
|
+
> & {
|
|
216
|
+
receipt: TransactionReceipt
|
|
217
|
+
}
|
|
218
|
+
>
|
|
219
|
+
|
|
220
|
+
// TODO: exhaustive error type
|
|
221
|
+
export type ErrorType = BaseErrorType
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Revokes an authorized access key.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* import { createClient, http } from 'viem'
|
|
230
|
+
* import { tempo } from 'viem/chains'
|
|
231
|
+
* import { Actions } from 'viem/tempo'
|
|
232
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
233
|
+
*
|
|
234
|
+
* const client = createClient({
|
|
235
|
+
* account: privateKeyToAccount('0x...'),
|
|
236
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
237
|
+
* transport: http(),
|
|
238
|
+
* })
|
|
239
|
+
*
|
|
240
|
+
* const hash = await Actions.accessKey.revoke(client, {
|
|
241
|
+
* accessKey: '0x...',
|
|
242
|
+
* })
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @param client - Client.
|
|
246
|
+
* @param parameters - Parameters.
|
|
247
|
+
* @returns The transaction hash.
|
|
248
|
+
*/
|
|
249
|
+
export async function revoke<
|
|
250
|
+
chain extends Chain | undefined,
|
|
251
|
+
account extends Account | undefined,
|
|
252
|
+
>(
|
|
253
|
+
client: Client<Transport, chain, account>,
|
|
254
|
+
parameters: revoke.Parameters<chain, account>,
|
|
255
|
+
): Promise<revoke.ReturnValue> {
|
|
256
|
+
return revoke.inner(writeContract, client, parameters)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export namespace revoke {
|
|
260
|
+
export type Parameters<
|
|
261
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
262
|
+
account extends Account | undefined = Account | undefined,
|
|
263
|
+
> = WriteParameters<chain, account> & Args
|
|
264
|
+
|
|
265
|
+
export type Args = {
|
|
266
|
+
/** The access key to revoke. */
|
|
267
|
+
accessKey: Address | AccessKeyAccount
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export type ReturnValue = WriteContractReturnType
|
|
271
|
+
|
|
272
|
+
// TODO: exhaustive error type
|
|
273
|
+
export type ErrorType = BaseErrorType
|
|
274
|
+
|
|
275
|
+
/** @internal */
|
|
276
|
+
export async function inner<
|
|
277
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
278
|
+
chain extends Chain | undefined,
|
|
279
|
+
account extends Account | undefined,
|
|
280
|
+
>(
|
|
281
|
+
action: action,
|
|
282
|
+
client: Client<Transport, chain, account>,
|
|
283
|
+
parameters: revoke.Parameters<chain, account>,
|
|
284
|
+
): Promise<ReturnType<action>> {
|
|
285
|
+
const { accessKey, ...rest } = parameters
|
|
286
|
+
const call = revoke.call({ accessKey })
|
|
287
|
+
return (await action(client, {
|
|
288
|
+
...rest,
|
|
289
|
+
...call,
|
|
290
|
+
} as never)) as never
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Defines a call to the `revokeKey` function.
|
|
295
|
+
*
|
|
296
|
+
* Can be passed as a parameter to:
|
|
297
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
298
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
299
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
304
|
+
* import { tempo } from 'viem/chains'
|
|
305
|
+
* import { Actions } from 'viem/tempo'
|
|
306
|
+
*
|
|
307
|
+
* const client = createClient({
|
|
308
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
309
|
+
* transport: http(),
|
|
310
|
+
* }).extend(walletActions)
|
|
311
|
+
*
|
|
312
|
+
* const hash = await client.sendTransaction({
|
|
313
|
+
* calls: [
|
|
314
|
+
* Actions.accessKey.revoke.call({ accessKey: '0x...' }),
|
|
315
|
+
* ],
|
|
316
|
+
* })
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* @param args - Arguments.
|
|
320
|
+
* @returns The call.
|
|
321
|
+
*/
|
|
322
|
+
export function call(args: Args) {
|
|
323
|
+
const { accessKey } = args
|
|
324
|
+
return defineCall({
|
|
325
|
+
address: Addresses.accountKeychain,
|
|
326
|
+
abi: Abis.accountKeychain,
|
|
327
|
+
functionName: 'revokeKey',
|
|
328
|
+
args: [resolveAccessKey(accessKey)],
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export function extractEvent(logs: Log[]) {
|
|
333
|
+
const [log] = parseEventLogs({
|
|
334
|
+
abi: Abis.accountKeychain,
|
|
335
|
+
logs,
|
|
336
|
+
eventName: 'KeyRevoked',
|
|
337
|
+
strict: true,
|
|
338
|
+
})
|
|
339
|
+
if (!log) throw new Error('`KeyRevoked` event not found.')
|
|
340
|
+
return log
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Revokes an authorized access key and waits for the transaction receipt.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* import { createClient, http } from 'viem'
|
|
350
|
+
* import { tempo } from 'viem/chains'
|
|
351
|
+
* import { Actions } from 'viem/tempo'
|
|
352
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
353
|
+
*
|
|
354
|
+
* const client = createClient({
|
|
355
|
+
* account: privateKeyToAccount('0x...'),
|
|
356
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
357
|
+
* transport: http(),
|
|
358
|
+
* })
|
|
359
|
+
*
|
|
360
|
+
* const result = await Actions.accessKey.revokeSync(client, {
|
|
361
|
+
* accessKey: '0x...',
|
|
362
|
+
* })
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* @param client - Client.
|
|
366
|
+
* @param parameters - Parameters.
|
|
367
|
+
* @returns The transaction receipt and event data.
|
|
368
|
+
*/
|
|
369
|
+
export async function revokeSync<
|
|
370
|
+
chain extends Chain | undefined,
|
|
371
|
+
account extends Account | undefined,
|
|
372
|
+
>(
|
|
373
|
+
client: Client<Transport, chain, account>,
|
|
374
|
+
parameters: revokeSync.Parameters<chain, account>,
|
|
375
|
+
): Promise<revokeSync.ReturnValue> {
|
|
376
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
377
|
+
const receipt = await revoke.inner(writeContractSync, client, {
|
|
378
|
+
...rest,
|
|
379
|
+
throwOnReceiptRevert,
|
|
380
|
+
} as never)
|
|
381
|
+
const { args } = revoke.extractEvent(receipt.logs)
|
|
382
|
+
return {
|
|
383
|
+
...args,
|
|
384
|
+
receipt,
|
|
385
|
+
} as never
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export namespace revokeSync {
|
|
389
|
+
export type Parameters<
|
|
390
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
391
|
+
account extends Account | undefined = Account | undefined,
|
|
392
|
+
> = revoke.Parameters<chain, account>
|
|
393
|
+
|
|
394
|
+
export type Args = revoke.Args
|
|
395
|
+
|
|
396
|
+
export type ReturnValue = Compute<
|
|
397
|
+
GetEventArgs<
|
|
398
|
+
typeof Abis.accountKeychain,
|
|
399
|
+
'KeyRevoked',
|
|
400
|
+
{ IndexedOnly: false; Required: true }
|
|
401
|
+
> & {
|
|
402
|
+
receipt: TransactionReceipt
|
|
403
|
+
}
|
|
404
|
+
>
|
|
405
|
+
|
|
406
|
+
// TODO: exhaustive error type
|
|
407
|
+
export type ErrorType = BaseErrorType
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Updates the spending limit for a specific token on an authorized access key.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* import { createClient, http } from 'viem'
|
|
416
|
+
* import { tempo } from 'viem/chains'
|
|
417
|
+
* import { Actions } from 'viem/tempo'
|
|
418
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
419
|
+
*
|
|
420
|
+
* const client = createClient({
|
|
421
|
+
* account: privateKeyToAccount('0x...'),
|
|
422
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
423
|
+
* transport: http(),
|
|
424
|
+
* })
|
|
425
|
+
*
|
|
426
|
+
* const hash = await Actions.accessKey.updateLimit(client, {
|
|
427
|
+
* accessKey: '0x...',
|
|
428
|
+
* token: '0x...',
|
|
429
|
+
* limit: 1000000000000000000n,
|
|
430
|
+
* })
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* @param client - Client.
|
|
434
|
+
* @param parameters - Parameters.
|
|
435
|
+
* @returns The transaction hash.
|
|
436
|
+
*/
|
|
437
|
+
export async function updateLimit<
|
|
438
|
+
chain extends Chain | undefined,
|
|
439
|
+
account extends Account | undefined,
|
|
440
|
+
>(
|
|
441
|
+
client: Client<Transport, chain, account>,
|
|
442
|
+
parameters: updateLimit.Parameters<chain, account>,
|
|
443
|
+
): Promise<updateLimit.ReturnValue> {
|
|
444
|
+
return updateLimit.inner(writeContract, client, parameters)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export namespace updateLimit {
|
|
448
|
+
export type Parameters<
|
|
449
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
450
|
+
account extends Account | undefined = Account | undefined,
|
|
451
|
+
> = WriteParameters<chain, account> & Args
|
|
452
|
+
|
|
453
|
+
export type Args = {
|
|
454
|
+
/** The access key to update. */
|
|
455
|
+
accessKey: Address | AccessKeyAccount
|
|
456
|
+
/** The token address. */
|
|
457
|
+
token: Address
|
|
458
|
+
/** The new spending limit. */
|
|
459
|
+
limit: bigint
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export type ReturnValue = WriteContractReturnType
|
|
463
|
+
|
|
464
|
+
// TODO: exhaustive error type
|
|
465
|
+
export type ErrorType = BaseErrorType
|
|
466
|
+
|
|
467
|
+
/** @internal */
|
|
468
|
+
export async function inner<
|
|
469
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
470
|
+
chain extends Chain | undefined,
|
|
471
|
+
account extends Account | undefined,
|
|
472
|
+
>(
|
|
473
|
+
action: action,
|
|
474
|
+
client: Client<Transport, chain, account>,
|
|
475
|
+
parameters: updateLimit.Parameters<chain, account>,
|
|
476
|
+
): Promise<ReturnType<action>> {
|
|
477
|
+
const { accessKey, token, limit, ...rest } = parameters
|
|
478
|
+
const call = updateLimit.call({ accessKey, token, limit })
|
|
479
|
+
return (await action(client, {
|
|
480
|
+
...rest,
|
|
481
|
+
...call,
|
|
482
|
+
} as never)) as never
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Defines a call to the `updateSpendingLimit` function.
|
|
487
|
+
*
|
|
488
|
+
* Can be passed as a parameter to:
|
|
489
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
490
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
491
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```ts
|
|
495
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
496
|
+
* import { tempo } from 'viem/chains'
|
|
497
|
+
* import { Actions } from 'viem/tempo'
|
|
498
|
+
*
|
|
499
|
+
* const client = createClient({
|
|
500
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
501
|
+
* transport: http(),
|
|
502
|
+
* }).extend(walletActions)
|
|
503
|
+
*
|
|
504
|
+
* const hash = await client.sendTransaction({
|
|
505
|
+
* calls: [
|
|
506
|
+
* Actions.accessKey.updateLimit.call({
|
|
507
|
+
* accessKey: '0x...',
|
|
508
|
+
* token: '0x...',
|
|
509
|
+
* limit: 1000000000000000000n,
|
|
510
|
+
* }),
|
|
511
|
+
* ],
|
|
512
|
+
* })
|
|
513
|
+
* ```
|
|
514
|
+
*
|
|
515
|
+
* @param args - Arguments.
|
|
516
|
+
* @returns The call.
|
|
517
|
+
*/
|
|
518
|
+
export function call(args: Args) {
|
|
519
|
+
const { accessKey, token, limit } = args
|
|
520
|
+
return defineCall({
|
|
521
|
+
address: Addresses.accountKeychain,
|
|
522
|
+
abi: Abis.accountKeychain,
|
|
523
|
+
functionName: 'updateSpendingLimit',
|
|
524
|
+
args: [resolveAccessKey(accessKey), token, limit],
|
|
525
|
+
})
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export function extractEvent(logs: Log[]) {
|
|
529
|
+
const [log] = parseEventLogs({
|
|
530
|
+
abi: Abis.accountKeychain,
|
|
531
|
+
logs,
|
|
532
|
+
eventName: 'SpendingLimitUpdated',
|
|
533
|
+
strict: true,
|
|
534
|
+
})
|
|
535
|
+
if (!log) throw new Error('`SpendingLimitUpdated` event not found.')
|
|
536
|
+
return log
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Updates the spending limit and waits for the transaction receipt.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```ts
|
|
545
|
+
* import { createClient, http } from 'viem'
|
|
546
|
+
* import { tempo } from 'viem/chains'
|
|
547
|
+
* import { Actions } from 'viem/tempo'
|
|
548
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
549
|
+
*
|
|
550
|
+
* const client = createClient({
|
|
551
|
+
* account: privateKeyToAccount('0x...'),
|
|
552
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
553
|
+
* transport: http(),
|
|
554
|
+
* })
|
|
555
|
+
*
|
|
556
|
+
* const result = await Actions.accessKey.updateLimitSync(client, {
|
|
557
|
+
* accessKey: '0x...',
|
|
558
|
+
* token: '0x...',
|
|
559
|
+
* limit: 1000000000000000000n,
|
|
560
|
+
* })
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @param client - Client.
|
|
564
|
+
* @param parameters - Parameters.
|
|
565
|
+
* @returns The transaction receipt and event data.
|
|
566
|
+
*/
|
|
567
|
+
export async function updateLimitSync<
|
|
568
|
+
chain extends Chain | undefined,
|
|
569
|
+
account extends Account | undefined,
|
|
570
|
+
>(
|
|
571
|
+
client: Client<Transport, chain, account>,
|
|
572
|
+
parameters: updateLimitSync.Parameters<chain, account>,
|
|
573
|
+
): Promise<updateLimitSync.ReturnValue> {
|
|
574
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
575
|
+
const receipt = await updateLimit.inner(writeContractSync, client, {
|
|
576
|
+
...rest,
|
|
577
|
+
throwOnReceiptRevert,
|
|
578
|
+
} as never)
|
|
579
|
+
const { args } = updateLimit.extractEvent(receipt.logs)
|
|
580
|
+
return {
|
|
581
|
+
account: args.account,
|
|
582
|
+
publicKey: args.publicKey,
|
|
583
|
+
token: args.token,
|
|
584
|
+
limit: args.newLimit,
|
|
585
|
+
receipt,
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
export namespace updateLimitSync {
|
|
590
|
+
export type Parameters<
|
|
591
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
592
|
+
account extends Account | undefined = Account | undefined,
|
|
593
|
+
> = updateLimit.Parameters<chain, account>
|
|
594
|
+
|
|
595
|
+
export type Args = updateLimit.Args
|
|
596
|
+
|
|
597
|
+
export type ReturnValue = {
|
|
598
|
+
/** The account that owns the key. */
|
|
599
|
+
account: Address
|
|
600
|
+
/** The access key address. */
|
|
601
|
+
publicKey: Address
|
|
602
|
+
/** The token address. */
|
|
603
|
+
token: Address
|
|
604
|
+
/** The new spending limit. */
|
|
605
|
+
limit: bigint
|
|
606
|
+
/** The transaction receipt. */
|
|
607
|
+
receipt: TransactionReceipt
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// TODO: exhaustive error type
|
|
611
|
+
export type ErrorType = BaseErrorType
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Gets access key information.
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```ts
|
|
619
|
+
* import { createClient, http } from 'viem'
|
|
620
|
+
* import { tempo } from 'viem/chains'
|
|
621
|
+
* import { Actions } from 'viem/tempo'
|
|
622
|
+
*
|
|
623
|
+
* const client = createClient({
|
|
624
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
625
|
+
* transport: http(),
|
|
626
|
+
* })
|
|
627
|
+
*
|
|
628
|
+
* const key = await Actions.accessKey.getMetadata(client, {
|
|
629
|
+
* account: '0x...',
|
|
630
|
+
* accessKey: '0x...',
|
|
631
|
+
* })
|
|
632
|
+
* ```
|
|
633
|
+
*
|
|
634
|
+
* @param client - Client.
|
|
635
|
+
* @param parameters - Parameters.
|
|
636
|
+
* @returns The key information.
|
|
637
|
+
*/
|
|
638
|
+
export async function getMetadata<
|
|
639
|
+
chain extends Chain | undefined,
|
|
640
|
+
account extends Account | undefined,
|
|
641
|
+
>(
|
|
642
|
+
client: Client<Transport, chain, account>,
|
|
643
|
+
parameters: getMetadata.Parameters<account>,
|
|
644
|
+
): Promise<getMetadata.ReturnValue> {
|
|
645
|
+
const { account: account_ = client.account, accessKey, ...rest } = parameters
|
|
646
|
+
if (!account_) throw new Error('account is required.')
|
|
647
|
+
const account = parseAccount(account_)
|
|
648
|
+
const result = await readContract(client, {
|
|
649
|
+
...rest,
|
|
650
|
+
...getMetadata.call({ account: account.address, accessKey }),
|
|
651
|
+
})
|
|
652
|
+
return {
|
|
653
|
+
address: result.keyId,
|
|
654
|
+
keyType:
|
|
655
|
+
signatureTypes[result.signatureType as keyof typeof signatureTypes] ??
|
|
656
|
+
'secp256k1',
|
|
657
|
+
expiry: result.expiry,
|
|
658
|
+
spendPolicy: spendPolicies[`${result.enforceLimits}`],
|
|
659
|
+
isRevoked: result.isRevoked,
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export namespace getMetadata {
|
|
664
|
+
export type Parameters<
|
|
665
|
+
account extends Account | undefined = Account | undefined,
|
|
666
|
+
> = ReadParameters & GetAccountParameter<account> & Pick<Args, 'accessKey'>
|
|
667
|
+
|
|
668
|
+
export type Args = {
|
|
669
|
+
/** Account address. */
|
|
670
|
+
account: Address
|
|
671
|
+
/** The access key. */
|
|
672
|
+
accessKey: Address | AccessKeyAccount
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export type ReturnValue = {
|
|
676
|
+
/** The access key address. */
|
|
677
|
+
address: Address
|
|
678
|
+
/** The key type. */
|
|
679
|
+
keyType: 'secp256k1' | 'p256' | 'webAuthn'
|
|
680
|
+
/** The expiry timestamp. */
|
|
681
|
+
expiry: bigint
|
|
682
|
+
/** The spending policy. */
|
|
683
|
+
spendPolicy: 'limited' | 'unlimited'
|
|
684
|
+
/** Whether the key is revoked. */
|
|
685
|
+
isRevoked: boolean
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Defines a call to the `getKey` function.
|
|
690
|
+
*
|
|
691
|
+
* @param args - Arguments.
|
|
692
|
+
* @returns The call.
|
|
693
|
+
*/
|
|
694
|
+
export function call(args: Args) {
|
|
695
|
+
const { account, accessKey } = args
|
|
696
|
+
return defineCall({
|
|
697
|
+
address: Addresses.accountKeychain,
|
|
698
|
+
abi: Abis.accountKeychain,
|
|
699
|
+
functionName: 'getKey',
|
|
700
|
+
args: [account, resolveAccessKey(accessKey)],
|
|
701
|
+
})
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Gets the remaining spending limit for a key-token pair.
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* ```ts
|
|
710
|
+
* import { createClient, http } from 'viem'
|
|
711
|
+
* import { tempo } from 'viem/chains'
|
|
712
|
+
* import { Actions } from 'viem/tempo'
|
|
713
|
+
*
|
|
714
|
+
* const client = createClient({
|
|
715
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
716
|
+
* transport: http(),
|
|
717
|
+
* })
|
|
718
|
+
*
|
|
719
|
+
* const remaining = await Actions.accessKey.getRemainingLimit(client, {
|
|
720
|
+
* account: '0x...',
|
|
721
|
+
* accessKey: '0x...',
|
|
722
|
+
* token: '0x...',
|
|
723
|
+
* })
|
|
724
|
+
* ```
|
|
725
|
+
*
|
|
726
|
+
* @param client - Client.
|
|
727
|
+
* @param parameters - Parameters.
|
|
728
|
+
* @returns The remaining spending amount.
|
|
729
|
+
*/
|
|
730
|
+
export async function getRemainingLimit<
|
|
731
|
+
chain extends Chain | undefined,
|
|
732
|
+
account extends Account | undefined,
|
|
733
|
+
>(
|
|
734
|
+
client: Client<Transport, chain, account>,
|
|
735
|
+
parameters: getRemainingLimit.Parameters<account>,
|
|
736
|
+
): Promise<getRemainingLimit.ReturnValue> {
|
|
737
|
+
const {
|
|
738
|
+
account: account_ = client.account,
|
|
739
|
+
accessKey,
|
|
740
|
+
token,
|
|
741
|
+
...rest
|
|
742
|
+
} = parameters
|
|
743
|
+
if (!account_) throw new Error('account is required.')
|
|
744
|
+
const account = parseAccount(account_)
|
|
745
|
+
return readContract(client, {
|
|
746
|
+
...rest,
|
|
747
|
+
...getRemainingLimit.call({ account: account.address, accessKey, token }),
|
|
748
|
+
})
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
export namespace getRemainingLimit {
|
|
752
|
+
export type Parameters<
|
|
753
|
+
account extends Account | undefined = Account | undefined,
|
|
754
|
+
> = ReadParameters &
|
|
755
|
+
GetAccountParameter<account> &
|
|
756
|
+
Pick<Args, 'accessKey' | 'token'>
|
|
757
|
+
|
|
758
|
+
export type Args = {
|
|
759
|
+
/** Account address. */
|
|
760
|
+
account: Address
|
|
761
|
+
/** The access key. */
|
|
762
|
+
accessKey: Address | AccessKeyAccount
|
|
763
|
+
/** The token address. */
|
|
764
|
+
token: Address
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export type ReturnValue = ReadContractReturnType<
|
|
768
|
+
typeof Abis.accountKeychain,
|
|
769
|
+
'getRemainingLimit',
|
|
770
|
+
never
|
|
771
|
+
>
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Defines a call to the `getRemainingLimit` function.
|
|
775
|
+
*
|
|
776
|
+
* @param args - Arguments.
|
|
777
|
+
* @returns The call.
|
|
778
|
+
*/
|
|
779
|
+
export function call(args: Args) {
|
|
780
|
+
const { account, accessKey, token } = args
|
|
781
|
+
return defineCall({
|
|
782
|
+
address: Addresses.accountKeychain,
|
|
783
|
+
abi: Abis.accountKeychain,
|
|
784
|
+
functionName: 'getRemainingLimit',
|
|
785
|
+
args: [account, resolveAccessKey(accessKey), token],
|
|
786
|
+
})
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Signs a key authorization for an access key.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* ```ts
|
|
795
|
+
* import { generatePrivateKey } from 'viem/accounts'
|
|
796
|
+
* import { Account, Actions } from 'viem/tempo'
|
|
797
|
+
*
|
|
798
|
+
* const account = Account.from({ privateKey: '0x...' })
|
|
799
|
+
* const accessKey = Account.fromP256(generatePrivateKey(), {
|
|
800
|
+
* access: account,
|
|
801
|
+
* })
|
|
802
|
+
*
|
|
803
|
+
* const keyAuthorization = await Actions.accessKey.signAuthorization(
|
|
804
|
+
* client,
|
|
805
|
+
* {
|
|
806
|
+
* account,
|
|
807
|
+
* accessKey,
|
|
808
|
+
* expiry: Math.floor((Date.now() + 30_000) / 1000),
|
|
809
|
+
* },
|
|
810
|
+
* )
|
|
811
|
+
* ```
|
|
812
|
+
*
|
|
813
|
+
* @param client - Client.
|
|
814
|
+
* @param parameters - Parameters.
|
|
815
|
+
* @returns The signed key authorization.
|
|
816
|
+
*/
|
|
817
|
+
export async function signAuthorization<
|
|
818
|
+
chain extends Chain | undefined,
|
|
819
|
+
account extends Account | undefined,
|
|
820
|
+
>(
|
|
821
|
+
client: Client<Transport, chain, account>,
|
|
822
|
+
parameters: signAuthorization.Parameters<account>,
|
|
823
|
+
): Promise<signAuthorization.ReturnValue> {
|
|
824
|
+
const { accessKey, chainId = client.chain?.id, ...rest } = parameters
|
|
825
|
+
const account_ = rest.account ?? client.account
|
|
826
|
+
if (!account_) throw new Error('account is required.')
|
|
827
|
+
if (!chainId) throw new Error('chainId is required.')
|
|
828
|
+
const parsed = parseAccount(account_)
|
|
829
|
+
return signKeyAuthorization(parsed as never, {
|
|
830
|
+
chainId: BigInt(chainId),
|
|
831
|
+
key: accessKey,
|
|
832
|
+
...rest,
|
|
833
|
+
})
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
export namespace signAuthorization {
|
|
837
|
+
export type Parameters<
|
|
838
|
+
account extends Account | undefined = Account | undefined,
|
|
839
|
+
> = GetAccountParameter<account> & {
|
|
840
|
+
/** The access key to authorize. */
|
|
841
|
+
accessKey: Pick<AccessKeyAccount, 'accessKeyAddress' | 'keyType'>
|
|
842
|
+
/** The chain ID. */
|
|
843
|
+
chainId?: number | undefined
|
|
844
|
+
/** Unix timestamp when the key expires. */
|
|
845
|
+
expiry?: number | undefined
|
|
846
|
+
/** Spending limits per token. */
|
|
847
|
+
limits?: { token: Address; limit: bigint }[] | undefined
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
export type ReturnValue = Awaited<ReturnType<typeof signKeyAuthorization>>
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/** @internal */
|
|
854
|
+
function resolveAccessKey(accessKey: Address | AccessKeyAccount): Address {
|
|
855
|
+
if (typeof accessKey === 'string') return accessKey
|
|
856
|
+
return accessKey.accessKeyAddress
|
|
857
|
+
}
|