viem 2.28.3 → 2.29.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 +24 -0
- package/_cjs/actions/public/watchBlocks.js +4 -4
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/wallet/getCallsStatus.js.map +1 -1
- package/_cjs/actions/wallet/getCapabilities.js +8 -2
- package/_cjs/actions/wallet/getCapabilities.js.map +1 -1
- package/_cjs/actions/wallet/sendCalls.js +18 -2
- package/_cjs/actions/wallet/sendCalls.js.map +1 -1
- package/_cjs/chains/definitions/plumeMainnet.js +4 -4
- package/_cjs/chains/definitions/plumeMainnet.js.map +1 -1
- package/_cjs/chains/definitions/plumeSepolia.js +4 -4
- package/_cjs/chains/definitions/plumeSepolia.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/erc7846/actions/connect.js +108 -0
- package/_cjs/experimental/erc7846/actions/connect.js.map +1 -0
- package/_cjs/experimental/erc7846/actions/disconnect.js +7 -0
- package/_cjs/experimental/erc7846/actions/disconnect.js.map +1 -0
- package/_cjs/experimental/erc7846/decorators/erc7846.js +14 -0
- package/_cjs/experimental/erc7846/decorators/erc7846.js.map +1 -0
- package/_cjs/experimental/erc7846/index.js +10 -0
- package/_cjs/experimental/erc7846/index.js.map +1 -0
- package/_cjs/experimental/erc7895/actions/addSubAccount.js +21 -0
- package/_cjs/experimental/erc7895/actions/addSubAccount.js.map +1 -0
- package/_cjs/experimental/erc7895/decorators/erc7895.js +12 -0
- package/_cjs/experimental/erc7895/decorators/erc7895.js.map +1 -0
- package/_cjs/experimental/erc7895/index.js +8 -0
- package/_cjs/experimental/erc7895/index.js.map +1 -0
- package/_cjs/experimental/index.js +5 -1
- package/_cjs/experimental/index.js.map +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/types/capabilities.js +3 -0
- package/_cjs/types/capabilities.js.map +1 -0
- package/_cjs/types/eip1193.js.map +1 -1
- package/_cjs/types/register.js +3 -0
- package/_cjs/types/register.js.map +1 -0
- package/_esm/actions/public/watchBlocks.js +4 -4
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/wallet/getCallsStatus.js.map +1 -1
- package/_esm/actions/wallet/getCapabilities.js +8 -2
- package/_esm/actions/wallet/getCapabilities.js.map +1 -1
- package/_esm/actions/wallet/sendCalls.js +18 -2
- package/_esm/actions/wallet/sendCalls.js.map +1 -1
- package/_esm/chains/definitions/plumeMainnet.js +4 -4
- package/_esm/chains/definitions/plumeMainnet.js.map +1 -1
- package/_esm/chains/definitions/plumeSepolia.js +4 -4
- package/_esm/chains/definitions/plumeSepolia.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/erc7846/actions/connect.js +128 -0
- package/_esm/experimental/erc7846/actions/connect.js.map +1 -0
- package/_esm/experimental/erc7846/actions/disconnect.js +25 -0
- package/_esm/experimental/erc7846/actions/disconnect.js.map +1 -0
- package/_esm/experimental/erc7846/decorators/erc7846.js +26 -0
- package/_esm/experimental/erc7846/decorators/erc7846.js.map +1 -0
- package/_esm/experimental/erc7846/index.js +5 -0
- package/_esm/experimental/erc7846/index.js.map +1 -0
- package/_esm/experimental/erc7895/actions/addSubAccount.js +42 -0
- package/_esm/experimental/erc7895/actions/addSubAccount.js.map +1 -0
- package/_esm/experimental/erc7895/decorators/erc7895.js +27 -0
- package/_esm/experimental/erc7895/decorators/erc7895.js.map +1 -0
- package/_esm/experimental/erc7895/index.js +4 -0
- package/_esm/experimental/erc7895/index.js.map +1 -0
- package/_esm/experimental/index.js +2 -0
- package/_esm/experimental/index.js.map +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/types/capabilities.js +2 -0
- package/_esm/types/capabilities.js.map +1 -0
- package/_esm/types/eip1193.js.map +1 -1
- package/_esm/types/register.js +2 -0
- package/_esm/types/register.js.map +1 -0
- package/_types/actions/wallet/getCallsStatus.d.ts +3 -2
- package/_types/actions/wallet/getCallsStatus.d.ts.map +1 -1
- package/_types/actions/wallet/getCapabilities.d.ts +2 -2
- package/_types/actions/wallet/getCapabilities.d.ts.map +1 -1
- package/_types/actions/wallet/sendCalls.d.ts +7 -5
- package/_types/actions/wallet/sendCalls.d.ts.map +1 -1
- package/_types/chains/definitions/plumeMainnet.d.ts +4 -4
- package/_types/chains/definitions/plumeSepolia.d.ts +4 -4
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/erc7846/actions/connect.d.ts +41 -0
- package/_types/experimental/erc7846/actions/connect.d.ts.map +1 -0
- package/_types/experimental/erc7846/actions/disconnect.d.ts +28 -0
- package/_types/experimental/erc7846/actions/disconnect.d.ts.map +1 -0
- package/_types/experimental/erc7846/decorators/erc7846.d.ts +68 -0
- package/_types/experimental/erc7846/decorators/erc7846.d.ts.map +1 -0
- package/_types/experimental/erc7846/index.d.ts +4 -0
- package/_types/experimental/erc7846/index.d.ts.map +1 -0
- package/_types/experimental/erc7895/actions/addSubAccount.d.ts +56 -0
- package/_types/experimental/erc7895/actions/addSubAccount.d.ts.map +1 -0
- package/_types/experimental/erc7895/decorators/erc7895.d.ts +52 -0
- package/_types/experimental/erc7895/decorators/erc7895.d.ts.map +1 -0
- package/_types/experimental/erc7895/index.d.ts +3 -0
- package/_types/experimental/erc7895/index.d.ts.map +1 -0
- package/_types/experimental/index.d.ts +2 -0
- package/_types/experimental/index.d.ts.map +1 -1
- package/_types/index.d.ts +8 -2
- package/_types/index.d.ts.map +1 -1
- package/_types/types/capabilities.d.ts +58 -0
- package/_types/types/capabilities.d.ts.map +1 -0
- package/_types/types/eip1193.d.ts +74 -13
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/types/register.d.ts +14 -0
- package/_types/types/register.d.ts.map +1 -0
- package/actions/public/watchBlocks.ts +4 -4
- package/actions/wallet/getCallsStatus.ts +3 -5
- package/actions/wallet/getCapabilities.ts +18 -9
- package/actions/wallet/sendCalls.ts +32 -11
- package/chains/definitions/plumeMainnet.ts +4 -4
- package/chains/definitions/plumeSepolia.ts +4 -4
- package/errors/version.ts +1 -1
- package/experimental/erc7846/actions/connect.ts +179 -0
- package/experimental/erc7846/actions/disconnect.ts +36 -0
- package/experimental/erc7846/decorators/erc7846.ts +88 -0
- package/experimental/erc7846/index.ts +13 -0
- package/experimental/erc7846/package.json +6 -0
- package/experimental/erc7895/actions/addSubAccount.ts +84 -0
- package/experimental/erc7895/decorators/erc7895.ts +70 -0
- package/experimental/erc7895/index.ts +9 -0
- package/experimental/erc7895/package.json +6 -0
- package/experimental/index.ts +10 -0
- package/index.ts +11 -3
- package/package.json +9 -1
- package/types/capabilities.ts +96 -0
- package/types/eip1193.ts +78 -18
- package/types/register.ts +15 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import {
|
3
|
+
type RequestAddressesErrorType,
|
4
|
+
requestAddresses,
|
5
|
+
} from '../../../actions/wallet/requestAddresses.js'
|
6
|
+
import type { Client } from '../../../clients/createClient.js'
|
7
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
8
|
+
import type { BaseError } from '../../../errors/base.js'
|
9
|
+
import type { ExtractCapabilities } from '../../../types/capabilities.js'
|
10
|
+
import type { Chain } from '../../../types/chain.js'
|
11
|
+
import type { Prettify } from '../../../types/utils.js'
|
12
|
+
import type { RequestErrorType } from '../../../utils/buildRequest.js'
|
13
|
+
import { numberToHex } from '../../../utils/encoding/toHex.js'
|
14
|
+
|
15
|
+
export type ConnectParameters = Prettify<{
|
16
|
+
capabilities?: ExtractCapabilities<'connect', 'Request'> | undefined
|
17
|
+
}>
|
18
|
+
|
19
|
+
export type ConnectReturnType = Prettify<{
|
20
|
+
accounts: readonly {
|
21
|
+
address: Address
|
22
|
+
capabilities?: ExtractCapabilities<'connect', 'ReturnType'> | undefined
|
23
|
+
}[]
|
24
|
+
}>
|
25
|
+
|
26
|
+
export type ConnectErrorType = RequestErrorType | RequestAddressesErrorType
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Requests to connect account(s) with optional capabilities.
|
30
|
+
*
|
31
|
+
* - Docs: https://viem.sh/experimental/erc7846/connect
|
32
|
+
* - JSON-RPC Methods: [`wallet_connect`](https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7846.md)
|
33
|
+
*
|
34
|
+
* @param client - Client to use
|
35
|
+
* @param parameters - {@link ConnectParameters}
|
36
|
+
* @returns List of accounts managed by a wallet {@link ConnectReturnType}
|
37
|
+
*
|
38
|
+
* @example
|
39
|
+
* import { createWalletClient, custom } from 'viem'
|
40
|
+
* import { mainnet } from 'viem/chains'
|
41
|
+
* import { connect } from 'viem/experimental/erc7846'
|
42
|
+
*
|
43
|
+
* const client = createWalletClient({
|
44
|
+
* chain: mainnet,
|
45
|
+
* transport: custom(window.ethereum),
|
46
|
+
* })
|
47
|
+
* const response = await connect(client)
|
48
|
+
*/
|
49
|
+
export async function connect<chain extends Chain | undefined>(
|
50
|
+
client: Client<Transport, chain>,
|
51
|
+
parameters: ConnectParameters = {},
|
52
|
+
): Promise<ConnectReturnType> {
|
53
|
+
const capabilities = formatRequestCapabilities(parameters.capabilities)
|
54
|
+
|
55
|
+
const response = await (async () => {
|
56
|
+
try {
|
57
|
+
return await client.request(
|
58
|
+
{ method: 'wallet_connect', params: [{ capabilities, version: '1' }] },
|
59
|
+
{ dedupe: true, retryCount: 0 },
|
60
|
+
)
|
61
|
+
} catch (e) {
|
62
|
+
const error = e as BaseError
|
63
|
+
|
64
|
+
// If the wallet does not support `wallet_connect`, and has no
|
65
|
+
// capabilities, attempt to use `eth_requestAccounts` instead.
|
66
|
+
if (
|
67
|
+
!parameters.capabilities &&
|
68
|
+
(error.name === 'InvalidInputRpcError' ||
|
69
|
+
error.name === 'InvalidParamsRpcError' ||
|
70
|
+
error.name === 'MethodNotFoundRpcError' ||
|
71
|
+
error.name === 'MethodNotSupportedRpcError' ||
|
72
|
+
error.name === 'UnsupportedProviderMethodError')
|
73
|
+
) {
|
74
|
+
const addresses = await requestAddresses(client)
|
75
|
+
return {
|
76
|
+
accounts: addresses.map((address) => ({
|
77
|
+
address,
|
78
|
+
capabilities: {},
|
79
|
+
})),
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
throw error
|
84
|
+
}
|
85
|
+
})()
|
86
|
+
|
87
|
+
return {
|
88
|
+
...response,
|
89
|
+
accounts: (response.accounts ?? []).map((account) => ({
|
90
|
+
...account,
|
91
|
+
capabilities: formatResponseCapabilities(account.capabilities),
|
92
|
+
})),
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
function formatRequestCapabilities(
|
97
|
+
capabilities: ExtractCapabilities<'connect', 'Request'> | undefined,
|
98
|
+
) {
|
99
|
+
const {
|
100
|
+
unstable_addSubAccount,
|
101
|
+
unstable_getSubAccounts: getSubAccounts,
|
102
|
+
unstable_signInWithEthereum,
|
103
|
+
...rest
|
104
|
+
} = capabilities ?? {}
|
105
|
+
|
106
|
+
const addSubAccount = unstable_addSubAccount
|
107
|
+
? {
|
108
|
+
...unstable_addSubAccount,
|
109
|
+
account: {
|
110
|
+
...unstable_addSubAccount.account,
|
111
|
+
...(unstable_addSubAccount.account.chainId
|
112
|
+
? {
|
113
|
+
chainId: numberToHex(unstable_addSubAccount.account.chainId),
|
114
|
+
}
|
115
|
+
: {}),
|
116
|
+
},
|
117
|
+
}
|
118
|
+
: undefined
|
119
|
+
|
120
|
+
const { chainId, expirationTime, issuedAt, notBefore } =
|
121
|
+
unstable_signInWithEthereum ?? {}
|
122
|
+
const signInWithEthereum = unstable_signInWithEthereum
|
123
|
+
? {
|
124
|
+
...unstable_signInWithEthereum,
|
125
|
+
chainId: numberToHex(chainId!),
|
126
|
+
...(expirationTime
|
127
|
+
? {
|
128
|
+
expirationTime: expirationTime.toISOString(),
|
129
|
+
}
|
130
|
+
: {}),
|
131
|
+
...(issuedAt
|
132
|
+
? {
|
133
|
+
issuedAt: issuedAt.toISOString(),
|
134
|
+
}
|
135
|
+
: {}),
|
136
|
+
...(notBefore
|
137
|
+
? {
|
138
|
+
notBefore: notBefore.toISOString(),
|
139
|
+
}
|
140
|
+
: {}),
|
141
|
+
}
|
142
|
+
: undefined
|
143
|
+
|
144
|
+
return {
|
145
|
+
...rest,
|
146
|
+
...(addSubAccount
|
147
|
+
? {
|
148
|
+
addSubAccount,
|
149
|
+
}
|
150
|
+
: {}),
|
151
|
+
...(getSubAccounts
|
152
|
+
? {
|
153
|
+
getSubAccounts,
|
154
|
+
}
|
155
|
+
: {}),
|
156
|
+
...(signInWithEthereum
|
157
|
+
? {
|
158
|
+
signInWithEthereum,
|
159
|
+
}
|
160
|
+
: {}),
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
function formatResponseCapabilities(
|
165
|
+
capabilities: ExtractCapabilities<'connect', 'ReturnType'> | undefined,
|
166
|
+
) {
|
167
|
+
return Object.entries(capabilities ?? {}).reduce(
|
168
|
+
(capabilities, [key, value]) => {
|
169
|
+
const k = (() => {
|
170
|
+
if (key === 'signInWithEthereum') return 'unstable_signInWithEthereum'
|
171
|
+
if (key === 'subAccounts') return 'unstable_subAccounts'
|
172
|
+
return key
|
173
|
+
})()
|
174
|
+
capabilities[k] = value
|
175
|
+
return capabilities
|
176
|
+
},
|
177
|
+
{} as Record<string, unknown>,
|
178
|
+
)
|
179
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import type { Client } from '../../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
|
+
import type { Chain } from '../../../types/chain.js'
|
4
|
+
import type { RequestErrorType } from '../../../utils/buildRequest.js'
|
5
|
+
|
6
|
+
export type DisconnectErrorType = RequestErrorType
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Requests to disconnect connected accounts.
|
10
|
+
*
|
11
|
+
* - Docs: https://viem.sh/experimental/erc7846/disconnect
|
12
|
+
* - JSON-RPC Methods: [`wallet_disconnect`](https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7846.md)
|
13
|
+
*
|
14
|
+
* @param client - Client to use
|
15
|
+
* @returns void
|
16
|
+
*
|
17
|
+
* @example
|
18
|
+
* import { createWalletClient, custom } from 'viem'
|
19
|
+
* import { mainnet } from 'viem/chains'
|
20
|
+
* import { disconnect } from 'viem/experimental/erc7846'
|
21
|
+
*
|
22
|
+
* const client = createWalletClient({
|
23
|
+
* chain: mainnet,
|
24
|
+
* transport: custom(window.ethereum),
|
25
|
+
* })
|
26
|
+
*
|
27
|
+
* await disconnect(client)
|
28
|
+
*/
|
29
|
+
export async function disconnect<chain extends Chain | undefined>(
|
30
|
+
client: Client<Transport, chain>,
|
31
|
+
) {
|
32
|
+
return await client.request(
|
33
|
+
{ method: 'wallet_disconnect' },
|
34
|
+
{ dedupe: true, retryCount: 0 },
|
35
|
+
)
|
36
|
+
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import type { Client } from '../../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
|
+
import type { Chain } from '../../../types/chain.js'
|
4
|
+
import {
|
5
|
+
type ConnectParameters,
|
6
|
+
type ConnectReturnType,
|
7
|
+
connect,
|
8
|
+
} from '../actions/connect.js'
|
9
|
+
import { disconnect } from '../actions/disconnect.js'
|
10
|
+
|
11
|
+
export type Erc7846Actions = {
|
12
|
+
/**
|
13
|
+
* Requests to connect to a wallet.
|
14
|
+
*
|
15
|
+
* - Docs: https://viem.sh/experimental/erc7846/connect
|
16
|
+
* - JSON-RPC Methods: [`wallet_connect`](https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7846.md)
|
17
|
+
*
|
18
|
+
* @param client - Client to use
|
19
|
+
* @param parameters - {@link ConnectParameters}
|
20
|
+
* @returns List of accounts managed by a wallet {@link ConnectReturnType}
|
21
|
+
*
|
22
|
+
* @example
|
23
|
+
* import { createWalletClient, custom } from 'viem'
|
24
|
+
* import { mainnet } from 'viem/chains'
|
25
|
+
* import { erc7846Actions } from 'viem/experimental/erc7846'
|
26
|
+
*
|
27
|
+
* const client = createWalletClient({
|
28
|
+
* chain: mainnet,
|
29
|
+
* transport: custom(window.ethereum),
|
30
|
+
* }).extend(erc7846Actions())
|
31
|
+
*
|
32
|
+
* const response = await client.connect()
|
33
|
+
*/
|
34
|
+
connect: (
|
35
|
+
parameters?: ConnectParameters | undefined,
|
36
|
+
) => Promise<ConnectReturnType>
|
37
|
+
/**
|
38
|
+
* Requests to disconnect connected accounts.
|
39
|
+
*
|
40
|
+
* - Docs: https://viem.sh/experimental/erc7846/disconnect
|
41
|
+
* - JSON-RPC Methods: [`wallet_disconnect`](https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7846.md)
|
42
|
+
*
|
43
|
+
* @param client - Client to use
|
44
|
+
* @returns void
|
45
|
+
*
|
46
|
+
* @example
|
47
|
+
* import { createWalletClient, custom } from 'viem'
|
48
|
+
* import { mainnet } from 'viem/chains'
|
49
|
+
* import { erc7846Actions } from 'viem/experimental/erc7846'
|
50
|
+
*
|
51
|
+
* const client = createWalletClient({
|
52
|
+
* chain: mainnet,
|
53
|
+
* transport: custom(window.ethereum),
|
54
|
+
* }).extend(erc7846Actions())
|
55
|
+
*
|
56
|
+
* await client.disconnect()
|
57
|
+
*/
|
58
|
+
disconnect: () => Promise<void>
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* A suite of ERC-7846 Wallet Actions.
|
63
|
+
*
|
64
|
+
* @example
|
65
|
+
* import { createPublicClient, createWalletClient, http } from 'viem'
|
66
|
+
* import { mainnet } from 'viem/chains'
|
67
|
+
* import { erc7846Actions } from 'viem/experimental/erc7846'
|
68
|
+
*
|
69
|
+
* const client = createWalletClient({
|
70
|
+
* chain: mainnet,
|
71
|
+
* transport: http(),
|
72
|
+
* }).extend(erc7846Actions())
|
73
|
+
*
|
74
|
+
* const response = await client.connect()
|
75
|
+
*/
|
76
|
+
export function erc7846Actions() {
|
77
|
+
return <
|
78
|
+
transport extends Transport,
|
79
|
+
chain extends Chain | undefined = Chain | undefined,
|
80
|
+
>(
|
81
|
+
client: Client<transport, chain>,
|
82
|
+
): Erc7846Actions => {
|
83
|
+
return {
|
84
|
+
connect: (parameters) => connect(client, parameters),
|
85
|
+
disconnect: () => disconnect(client),
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: entrypoint
|
2
|
+
export {
|
3
|
+
type ConnectErrorType,
|
4
|
+
type ConnectParameters,
|
5
|
+
type ConnectReturnType,
|
6
|
+
connect,
|
7
|
+
} from './actions/connect.js'
|
8
|
+
export {
|
9
|
+
type DisconnectErrorType,
|
10
|
+
disconnect,
|
11
|
+
} from './actions/disconnect.js'
|
12
|
+
|
13
|
+
export { type Erc7846Actions, erc7846Actions } from './decorators/erc7846.js'
|
@@ -0,0 +1,84 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import type { Client } from '../../../clients/createClient.js'
|
3
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
4
|
+
import type { Chain } from '../../../types/chain.js'
|
5
|
+
import type { Hex } from '../../../types/misc.js'
|
6
|
+
import type { OneOf, Prettify } from '../../../types/utils.js'
|
7
|
+
import type { RequestErrorType } from '../../../utils/buildRequest.js'
|
8
|
+
import { numberToHex } from '../../../utils/index.js'
|
9
|
+
|
10
|
+
export type AddSubAccountParameters = Prettify<
|
11
|
+
OneOf<
|
12
|
+
| {
|
13
|
+
keys: readonly {
|
14
|
+
publicKey: Hex
|
15
|
+
type: 'address' | 'p256' | 'webcrypto-p256' | 'webauthn-p256'
|
16
|
+
}[]
|
17
|
+
type: 'create'
|
18
|
+
}
|
19
|
+
| {
|
20
|
+
address: Address
|
21
|
+
chainId?: number | undefined
|
22
|
+
type: 'deployed'
|
23
|
+
}
|
24
|
+
| {
|
25
|
+
address: Address
|
26
|
+
chainId?: number | undefined
|
27
|
+
factory: Address
|
28
|
+
factoryData: Hex
|
29
|
+
type: 'undeployed'
|
30
|
+
}
|
31
|
+
>
|
32
|
+
>
|
33
|
+
|
34
|
+
export type AddSubAccountReturnType = Prettify<{
|
35
|
+
address: Address
|
36
|
+
factory?: Address | undefined
|
37
|
+
factoryData?: Hex | undefined
|
38
|
+
}>
|
39
|
+
|
40
|
+
export type AddSubAccountErrorType = RequestErrorType
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Requests to add a Sub Account.
|
44
|
+
*
|
45
|
+
* - Docs: https://viem.sh/experimental/erc7895/addSubAccount
|
46
|
+
* - JSON-RPC Methods: [`wallet_addSubAccount`](https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7895.md)
|
47
|
+
*
|
48
|
+
* @param client - Client to use
|
49
|
+
* @param parameters - {@link AddSubAccountParameters}
|
50
|
+
* @returns Sub Account. {@link AddSubAccountReturnType}
|
51
|
+
*
|
52
|
+
* @example
|
53
|
+
* import { createWalletClient, custom } from 'viem'
|
54
|
+
* import { mainnet } from 'viem/chains'
|
55
|
+
* import { addSubAccount } from 'viem/experimental/erc7895'
|
56
|
+
*
|
57
|
+
* const client = createWalletClient({
|
58
|
+
* chain: mainnet,
|
59
|
+
* transport: custom(window.ethereum),
|
60
|
+
* })
|
61
|
+
* const response = await addSubAccount(client, {
|
62
|
+
* keys: [{ key: '0x0000000000000000000000000000000000000000', type: 'address' }],
|
63
|
+
* type: 'create',
|
64
|
+
* })
|
65
|
+
*/
|
66
|
+
export async function addSubAccount<chain extends Chain | undefined>(
|
67
|
+
client: Client<Transport, chain>,
|
68
|
+
parameters: AddSubAccountParameters,
|
69
|
+
): Promise<AddSubAccountReturnType> {
|
70
|
+
return client.request({
|
71
|
+
method: 'wallet_addSubAccount',
|
72
|
+
params: [
|
73
|
+
{
|
74
|
+
account: {
|
75
|
+
...parameters,
|
76
|
+
...(parameters.chainId
|
77
|
+
? { chainId: numberToHex(parameters.chainId) }
|
78
|
+
: {}),
|
79
|
+
} as never,
|
80
|
+
version: '1',
|
81
|
+
},
|
82
|
+
],
|
83
|
+
})
|
84
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import type { Client } from '../../../clients/createClient.js'
|
2
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
|
+
import type { Chain } from '../../../types/chain.js'
|
4
|
+
import {
|
5
|
+
type AddSubAccountParameters,
|
6
|
+
type AddSubAccountReturnType,
|
7
|
+
addSubAccount,
|
8
|
+
} from '../actions/addSubAccount.js'
|
9
|
+
|
10
|
+
export type Erc7895Actions = {
|
11
|
+
/**
|
12
|
+
* Requests to add a Sub Account.
|
13
|
+
*
|
14
|
+
* - Docs: https://viem.sh/experimental/erc7895/addSubAccount
|
15
|
+
* - JSON-RPC Methods: [`wallet_addSubAccount`](https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7895.md)
|
16
|
+
*
|
17
|
+
* @param client - Client to use
|
18
|
+
* @param parameters - {@link AddSubAccountParameters}
|
19
|
+
* @returns Sub Account. {@link AddSubAccountReturnType}
|
20
|
+
*
|
21
|
+
* @example
|
22
|
+
* import { createWalletClient, custom } from 'viem'
|
23
|
+
* import { mainnet } from 'viem/chains'
|
24
|
+
* import { erc7895Actions } from 'viem/experimental'
|
25
|
+
*
|
26
|
+
* const client = createWalletClient({
|
27
|
+
* chain: mainnet,
|
28
|
+
* transport: custom(window.ethereum),
|
29
|
+
* }).extend(erc7895Actions())
|
30
|
+
*
|
31
|
+
* const response = await client.addSubAccount({
|
32
|
+
* keys: [{ key: '0x0000000000000000000000000000000000000000', type: 'address' }],
|
33
|
+
* type: 'create',
|
34
|
+
* })
|
35
|
+
*/
|
36
|
+
addSubAccount: (
|
37
|
+
parameters: AddSubAccountParameters,
|
38
|
+
) => Promise<AddSubAccountReturnType>
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* A suite of ERC-7895 Wallet Actions.
|
43
|
+
*
|
44
|
+
* @example
|
45
|
+
* import { createPublicClient, createWalletClient, http } from 'viem'
|
46
|
+
* import { mainnet } from 'viem/chains'
|
47
|
+
* import { erc7895Actions } from 'viem/experimental'
|
48
|
+
*
|
49
|
+
* const client = createWalletClient({
|
50
|
+
* chain: mainnet,
|
51
|
+
* transport: http(),
|
52
|
+
* }).extend(erc7895Actions())
|
53
|
+
*
|
54
|
+
* const response = await client.addSubAccount({
|
55
|
+
* keys: [{ key: '0x0000000000000000000000000000000000000000', type: 'address' }],
|
56
|
+
* type: 'create',
|
57
|
+
* })
|
58
|
+
*/
|
59
|
+
export function erc7895Actions() {
|
60
|
+
return <
|
61
|
+
transport extends Transport,
|
62
|
+
chain extends Chain | undefined = Chain | undefined,
|
63
|
+
>(
|
64
|
+
client: Client<transport, chain>,
|
65
|
+
): Erc7895Actions => {
|
66
|
+
return {
|
67
|
+
addSubAccount: (parameters) => addSubAccount(client, parameters),
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: entrypoint
|
2
|
+
export {
|
3
|
+
type AddSubAccountErrorType,
|
4
|
+
type AddSubAccountParameters,
|
5
|
+
type AddSubAccountReturnType,
|
6
|
+
addSubAccount,
|
7
|
+
} from './actions/addSubAccount.js'
|
8
|
+
|
9
|
+
export { type Erc7895Actions, erc7895Actions } from './decorators/erc7895.js'
|
package/experimental/index.ts
CHANGED
@@ -175,3 +175,13 @@ export {
|
|
175
175
|
type Erc7821Actions,
|
176
176
|
erc7821Actions,
|
177
177
|
} from './erc7821/decorators/erc7821.js'
|
178
|
+
|
179
|
+
export {
|
180
|
+
type Erc7846Actions,
|
181
|
+
erc7846Actions,
|
182
|
+
} from './erc7846/decorators/erc7846.js'
|
183
|
+
|
184
|
+
export {
|
185
|
+
type Erc7895Actions,
|
186
|
+
erc7895Actions,
|
187
|
+
} from './erc7895/decorators/erc7895.js'
|
package/index.ts
CHANGED
@@ -13,7 +13,6 @@ export {
|
|
13
13
|
type ParseAbiItem,
|
14
14
|
type ParseAbiParameter,
|
15
15
|
type ParseAbiParameters,
|
16
|
-
type ResolvedRegister,
|
17
16
|
type TypedData,
|
18
17
|
type TypedDataDomain,
|
19
18
|
type TypedDataParameter,
|
@@ -1105,6 +1104,16 @@ export type {
|
|
1105
1104
|
BlockTag,
|
1106
1105
|
Uncle,
|
1107
1106
|
} from './types/block.js'
|
1107
|
+
export type {
|
1108
|
+
Capabilities,
|
1109
|
+
/** @deprecated Use `Capabilities` instead. */
|
1110
|
+
Capabilities as WalletCapabilities,
|
1111
|
+
CapabilitiesSchema,
|
1112
|
+
/** @deprecated Use `ChainIdToCapabilities` instead. */
|
1113
|
+
ChainIdToCapabilities as WalletCapabilitiesRecord,
|
1114
|
+
ChainIdToCapabilities,
|
1115
|
+
ExtractCapabilities,
|
1116
|
+
} from './types/capabilities.js'
|
1108
1117
|
export type {
|
1109
1118
|
ByteArray,
|
1110
1119
|
Hash,
|
@@ -1133,8 +1142,6 @@ export type {
|
|
1133
1142
|
RpcSchema,
|
1134
1143
|
RpcSchemaOverride,
|
1135
1144
|
TestRpcSchema,
|
1136
|
-
WalletCapabilities,
|
1137
|
-
WalletCapabilitiesRecord,
|
1138
1145
|
WalletCallReceipt,
|
1139
1146
|
WalletGetCallsStatusReturnType,
|
1140
1147
|
WalletGrantPermissionsParameters,
|
@@ -1178,6 +1185,7 @@ export type {
|
|
1178
1185
|
SignedAuthorization,
|
1179
1186
|
SignedAuthorizationList,
|
1180
1187
|
} from './types/authorization.js'
|
1188
|
+
export type { Register, ResolvedRegister } from './types/register.js'
|
1181
1189
|
export type {
|
1182
1190
|
Index,
|
1183
1191
|
Quantity,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "viem",
|
3
3
|
"description": "TypeScript Interface for Ethereum",
|
4
|
-
"version": "2.
|
4
|
+
"version": "2.29.0",
|
5
5
|
"main": "./_cjs/index.js",
|
6
6
|
"module": "./_esm/index.js",
|
7
7
|
"types": "./_types/index.d.ts",
|
@@ -74,6 +74,11 @@
|
|
74
74
|
"import": "./_esm/experimental/erc7821/index.js",
|
75
75
|
"default": "./_cjs/experimental/erc7821/index.js"
|
76
76
|
},
|
77
|
+
"./experimental/erc7846": {
|
78
|
+
"types": "./_types/experimental/erc7846/index.d.ts",
|
79
|
+
"import": "./_esm/experimental/erc7846/index.js",
|
80
|
+
"default": "./_cjs/experimental/erc7846/index.js"
|
81
|
+
},
|
77
82
|
"./linea": {
|
78
83
|
"types": "./_types/linea/index.d.ts",
|
79
84
|
"import": "./_esm/linea/index.js",
|
@@ -145,6 +150,9 @@
|
|
145
150
|
"experimental/erc7821": [
|
146
151
|
"./_types/experimental/erc7821/index.d.ts"
|
147
152
|
],
|
153
|
+
"experimental/erc7846": [
|
154
|
+
"./_types/experimental/erc7846/index.d.ts"
|
155
|
+
],
|
148
156
|
"node": [
|
149
157
|
"./_types/node/index.d.ts"
|
150
158
|
],
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import type {
|
2
|
+
AddSubAccountParameters,
|
3
|
+
AddSubAccountReturnType,
|
4
|
+
} from '../experimental/erc7895/actions/addSubAccount.js'
|
5
|
+
import type { SiweMessage } from '../utils/siwe/types.js'
|
6
|
+
import type { Hex } from './misc.js'
|
7
|
+
import type { ResolvedRegister } from './register.js'
|
8
|
+
import type { Prettify, RequiredBy } from './utils.js'
|
9
|
+
|
10
|
+
export type CapabilitiesSchema = ResolvedRegister['CapabilitiesSchema']
|
11
|
+
|
12
|
+
export type DefaultCapabilitiesSchema = {
|
13
|
+
connect: {
|
14
|
+
Request: {
|
15
|
+
unstable_addSubAccount?:
|
16
|
+
| {
|
17
|
+
account: AddSubAccountParameters
|
18
|
+
}
|
19
|
+
| undefined
|
20
|
+
unstable_signInWithEthereum?:
|
21
|
+
| RequiredBy<Partial<SiweMessage>, 'chainId' | 'nonce'>
|
22
|
+
| undefined
|
23
|
+
}
|
24
|
+
ReturnType: {
|
25
|
+
unstable_signInWithEthereum?:
|
26
|
+
| {
|
27
|
+
message: string
|
28
|
+
signature: Hex
|
29
|
+
}
|
30
|
+
| undefined
|
31
|
+
unstable_subAccounts?: readonly AddSubAccountReturnType[] | undefined
|
32
|
+
}
|
33
|
+
}
|
34
|
+
getCapabilities: {
|
35
|
+
ReturnType: {
|
36
|
+
atomic?:
|
37
|
+
| {
|
38
|
+
status: 'supported' | 'ready' | 'unsupported'
|
39
|
+
}
|
40
|
+
| undefined
|
41
|
+
unstable_addSubAccount?:
|
42
|
+
| {
|
43
|
+
keyTypes: (
|
44
|
+
| 'address'
|
45
|
+
| 'p256'
|
46
|
+
| 'webcrypto-p256'
|
47
|
+
| 'webauthn-p256'
|
48
|
+
)[]
|
49
|
+
supported: boolean
|
50
|
+
}
|
51
|
+
| undefined
|
52
|
+
paymasterService?:
|
53
|
+
| {
|
54
|
+
supported: boolean
|
55
|
+
}
|
56
|
+
| undefined
|
57
|
+
}
|
58
|
+
}
|
59
|
+
sendCalls: {
|
60
|
+
Request: {
|
61
|
+
paymasterService?:
|
62
|
+
| {
|
63
|
+
[chainId: number]: {
|
64
|
+
context?: Record<string, any> | undefined
|
65
|
+
optional?: boolean | undefined
|
66
|
+
url: string
|
67
|
+
}
|
68
|
+
}
|
69
|
+
| undefined
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
export type Capabilities<capabilities extends Record<string, any> = {}> = {
|
75
|
+
[key: string]: any
|
76
|
+
} & capabilities
|
77
|
+
|
78
|
+
export type ChainIdToCapabilities<
|
79
|
+
capabilities extends Capabilities = Capabilities,
|
80
|
+
id extends string | number = Hex,
|
81
|
+
> = {
|
82
|
+
[chainId in id]: capabilities
|
83
|
+
}
|
84
|
+
|
85
|
+
export type ExtractCapabilities<
|
86
|
+
method extends string,
|
87
|
+
key extends 'Request' | 'ReturnType',
|
88
|
+
> = Prettify<
|
89
|
+
method extends keyof CapabilitiesSchema
|
90
|
+
? CapabilitiesSchema[method] extends {
|
91
|
+
[k in key]: infer value extends Record<string, any>
|
92
|
+
}
|
93
|
+
? Capabilities<value>
|
94
|
+
: Capabilities
|
95
|
+
: Capabilities
|
96
|
+
>
|