viem 2.21.50 → 2.21.52
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +26 -0
- package/_cjs/chains/definitions/boolBetaMainnet.js +24 -0
- package/_cjs/chains/definitions/boolBetaMainnet.js.map +1 -0
- package/_cjs/chains/definitions/corn.js +32 -0
- package/_cjs/chains/definitions/corn.js.map +1 -0
- package/_cjs/chains/definitions/cornTestnet.js +33 -0
- package/_cjs/chains/definitions/cornTestnet.js.map +1 -0
- package/_cjs/chains/definitions/redbellyMainnet.js +27 -0
- package/_cjs/chains/definitions/redbellyMainnet.js.map +1 -0
- package/_cjs/chains/definitions/redbellyTestnet.js +3 -3
- package/_cjs/chains/definitions/redbellyTestnet.js.map +1 -1
- package/_cjs/chains/definitions/sonicTestnet.js +24 -0
- package/_cjs/chains/definitions/sonicTestnet.js.map +1 -0
- package/_cjs/chains/definitions/swissdlt.js +26 -0
- package/_cjs/chains/definitions/swissdlt.js.map +1 -0
- package/_cjs/chains/definitions/worldLand.js +26 -0
- package/_cjs/chains/definitions/worldLand.js.map +1 -0
- package/_cjs/chains/index.js +23 -9
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/eip7702/actions/prepareAuthorization.js +44 -0
- package/_cjs/experimental/eip7702/actions/prepareAuthorization.js.map +1 -0
- package/_cjs/experimental/eip7702/actions/signAuthorization.js +3 -30
- package/_cjs/experimental/eip7702/actions/signAuthorization.js.map +1 -1
- package/_cjs/experimental/eip7702/decorators/eip7702.js +2 -0
- package/_cjs/experimental/eip7702/decorators/eip7702.js.map +1 -1
- package/_cjs/experimental/index.js +3 -1
- package/_cjs/experimental/index.js.map +1 -1
- package/_cjs/utils/observe.js +4 -1
- package/_cjs/utils/observe.js.map +1 -1
- package/_esm/chains/definitions/boolBetaMainnet.js +21 -0
- package/_esm/chains/definitions/boolBetaMainnet.js.map +1 -0
- package/_esm/chains/definitions/corn.js +29 -0
- package/_esm/chains/definitions/corn.js.map +1 -0
- package/_esm/chains/definitions/cornTestnet.js +30 -0
- package/_esm/chains/definitions/cornTestnet.js.map +1 -0
- package/_esm/chains/definitions/redbellyMainnet.js +24 -0
- package/_esm/chains/definitions/redbellyMainnet.js.map +1 -0
- package/_esm/chains/definitions/redbellyTestnet.js +3 -3
- package/_esm/chains/definitions/redbellyTestnet.js.map +1 -1
- package/_esm/chains/definitions/sonicTestnet.js +21 -0
- package/_esm/chains/definitions/sonicTestnet.js.map +1 -0
- package/_esm/chains/definitions/swissdlt.js +23 -0
- package/_esm/chains/definitions/swissdlt.js.map +1 -0
- package/_esm/chains/definitions/worldLand.js +23 -0
- package/_esm/chains/definitions/worldLand.js.map +1 -0
- package/_esm/chains/index.js +8 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/eip7702/actions/prepareAuthorization.js +82 -0
- package/_esm/experimental/eip7702/actions/prepareAuthorization.js.map +1 -0
- package/_esm/experimental/eip7702/actions/signAuthorization.js +3 -30
- package/_esm/experimental/eip7702/actions/signAuthorization.js.map +1 -1
- package/_esm/experimental/eip7702/decorators/eip7702.js +2 -0
- package/_esm/experimental/eip7702/decorators/eip7702.js.map +1 -1
- package/_esm/experimental/index.js +1 -0
- package/_esm/experimental/index.js.map +1 -1
- package/_esm/utils/observe.js +4 -1
- package/_esm/utils/observe.js.map +1 -1
- package/_types/chains/definitions/boolBetaMainnet.d.ts +37 -0
- package/_types/chains/definitions/boolBetaMainnet.d.ts.map +1 -0
- package/_types/chains/definitions/corn.d.ts +34 -0
- package/_types/chains/definitions/corn.d.ts.map +1 -0
- package/_types/chains/definitions/cornTestnet.d.ts +34 -0
- package/_types/chains/definitions/cornTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/redbellyMainnet.d.ts +38 -0
- package/_types/chains/definitions/redbellyMainnet.d.ts.map +1 -0
- package/_types/chains/definitions/redbellyTestnet.d.ts +3 -3
- package/_types/chains/definitions/redbellyTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/sonicTestnet.d.ts +37 -0
- package/_types/chains/definitions/sonicTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/swissdlt.d.ts +37 -0
- package/_types/chains/definitions/swissdlt.d.ts.map +1 -0
- package/_types/chains/definitions/worldLand.d.ts +37 -0
- package/_types/chains/definitions/worldLand.d.ts.map +1 -0
- package/_types/chains/index.d.ts +8 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/eip7702/actions/prepareAuthorization.d.ts +66 -0
- package/_types/experimental/eip7702/actions/prepareAuthorization.d.ts.map +1 -0
- package/_types/experimental/eip7702/actions/signAuthorization.d.ts +3 -15
- package/_types/experimental/eip7702/actions/signAuthorization.d.ts.map +1 -1
- package/_types/experimental/eip7702/decorators/eip7702.d.ts +45 -0
- package/_types/experimental/eip7702/decorators/eip7702.d.ts.map +1 -1
- package/_types/experimental/index.d.ts +1 -0
- package/_types/experimental/index.d.ts.map +1 -1
- package/_types/utils/observe.d.ts.map +1 -1
- package/chains/definitions/boolBetaMainnet.ts +21 -0
- package/chains/definitions/corn.ts +31 -0
- package/chains/definitions/cornTestnet.ts +32 -0
- package/chains/definitions/redbellyMainnet.ts +25 -0
- package/chains/definitions/redbellyTestnet.ts +4 -3
- package/chains/definitions/sonicTestnet.ts +21 -0
- package/chains/definitions/swissdlt.ts +23 -0
- package/chains/definitions/worldLand.ts +23 -0
- package/chains/index.ts +8 -0
- package/errors/version.ts +1 -1
- package/experimental/eip7702/actions/prepareAuthorization.ts +141 -0
- package/experimental/eip7702/actions/signAuthorization.ts +9 -60
- package/experimental/eip7702/decorators/eip7702.ts +53 -0
- package/experimental/index.ts +6 -0
- package/package.json +1 -1
- package/utils/observe.ts +3 -1
@@ -2,6 +2,11 @@ import type { Client } from '../../../clients/createClient.js'
|
|
2
2
|
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
3
|
import type { Account } from '../../../types/account.js'
|
4
4
|
import type { Chain } from '../../../types/chain.js'
|
5
|
+
import {
|
6
|
+
type PrepareAuthorizationParameters,
|
7
|
+
type PrepareAuthorizationReturnType,
|
8
|
+
prepareAuthorization,
|
9
|
+
} from '../actions/prepareAuthorization.js'
|
5
10
|
import {
|
6
11
|
type SignAuthorizationParameters,
|
7
12
|
type SignAuthorizationReturnType,
|
@@ -11,6 +16,52 @@ import {
|
|
11
16
|
export type Eip7702Actions<
|
12
17
|
account extends Account | undefined = Account | undefined,
|
13
18
|
> = {
|
19
|
+
/**
|
20
|
+
* Prepares an [EIP-7702 Authorization](https://eips.ethereum.org/EIPS/eip-7702) object for signing.
|
21
|
+
* This Action will fill the required fields of the Authorization object if they are not provided (e.g. `nonce` and `chainId`).
|
22
|
+
*
|
23
|
+
* With the prepared Authorization object, you can use [`signAuthorization`](https://viem.sh/experimental/eip7702/signAuthorization) to sign over the Authorization object.
|
24
|
+
*
|
25
|
+
* @param client - Client to use
|
26
|
+
* @param parameters - {@link PrepareAuthorizationParameters}
|
27
|
+
* @returns The prepared Authorization object. {@link PrepareAuthorizationReturnType}
|
28
|
+
*
|
29
|
+
* @example
|
30
|
+
* import { createClient, http } from 'viem'
|
31
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
32
|
+
* import { mainnet } from 'viem/chains'
|
33
|
+
* import { eip7702Actions } from 'viem/experimental'
|
34
|
+
*
|
35
|
+
* const client = createClient({
|
36
|
+
* chain: mainnet,
|
37
|
+
* transport: http(),
|
38
|
+
* }).extend(eip7702Actions())
|
39
|
+
*
|
40
|
+
* const authorization = await client.prepareAuthorization({
|
41
|
+
* account: privateKeyToAccount('0x..'),
|
42
|
+
* contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
43
|
+
* })
|
44
|
+
*
|
45
|
+
* @example
|
46
|
+
* // Account Hoisting
|
47
|
+
* import { createClient, http } from 'viem'
|
48
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
49
|
+
* import { mainnet } from 'viem/chains'
|
50
|
+
* import { eip7702Actions } from 'viem/experimental'
|
51
|
+
*
|
52
|
+
* const client = createClient({
|
53
|
+
* account: privateKeyToAccount('0x…'),
|
54
|
+
* chain: mainnet,
|
55
|
+
* transport: http(),
|
56
|
+
* }).extend(eip7702Actions())
|
57
|
+
*
|
58
|
+
* const authorization = await client.prepareAuthorization({
|
59
|
+
* contractAddress: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
60
|
+
* })
|
61
|
+
*/
|
62
|
+
prepareAuthorization: (
|
63
|
+
parameters: PrepareAuthorizationParameters<account>,
|
64
|
+
) => Promise<PrepareAuthorizationReturnType>
|
14
65
|
/**
|
15
66
|
* Signs an [EIP-7702 Authorization](https://eips.ethereum.org/EIPS/eip-7702) object.
|
16
67
|
*
|
@@ -80,6 +131,8 @@ export function eip7702Actions() {
|
|
80
131
|
client: Client<Transport, Chain | undefined, account>,
|
81
132
|
): Eip7702Actions<account> => {
|
82
133
|
return {
|
134
|
+
prepareAuthorization: (parameters) =>
|
135
|
+
prepareAuthorization(client, parameters),
|
83
136
|
signAuthorization: (parameters) => signAuthorization(client, parameters),
|
84
137
|
}
|
85
138
|
}
|
package/experimental/index.ts
CHANGED
@@ -43,6 +43,12 @@ export {
|
|
43
43
|
type Eip7702Actions,
|
44
44
|
eip7702Actions,
|
45
45
|
} from './eip7702/decorators/eip7702.js'
|
46
|
+
export {
|
47
|
+
type PrepareAuthorizationParameters,
|
48
|
+
type PrepareAuthorizationReturnType,
|
49
|
+
type PrepareAuthorizationErrorType,
|
50
|
+
prepareAuthorization,
|
51
|
+
} from './eip7702/actions/prepareAuthorization.js'
|
46
52
|
export {
|
47
53
|
type SignAuthorizationParameters,
|
48
54
|
type SignAuthorizationReturnType,
|
package/package.json
CHANGED
package/utils/observe.ts
CHANGED
@@ -43,8 +43,10 @@ export function observe<callbacks extends Callbacks>(
|
|
43
43
|
}
|
44
44
|
|
45
45
|
const unwatch = () => {
|
46
|
+
const listeners = getListeners()
|
47
|
+
if (!listeners.some((cb: any) => cb.id === callbackId)) return
|
46
48
|
const cleanup = cleanupCache.get(observerId)
|
47
|
-
if (
|
49
|
+
if (listeners.length === 1 && cleanup) cleanup()
|
48
50
|
unsubscribe()
|
49
51
|
}
|
50
52
|
|