viem 2.28.4 → 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 +18 -0
- package/_cjs/actions/public/watchBlocks.js +4 -4
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/wallet/getCapabilities.js +8 -2
- package/_cjs/actions/wallet/getCapabilities.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/_esm/actions/public/watchBlocks.js +4 -4
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/wallet/getCapabilities.js +8 -2
- package/_esm/actions/wallet/getCapabilities.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/_types/actions/wallet/getCapabilities.d.ts.map +1 -1
- 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 +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/types/capabilities.d.ts +24 -2
- package/_types/types/capabilities.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +66 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/actions/public/watchBlocks.ts +4 -4
- package/actions/wallet/getCapabilities.ts +7 -2
- 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 +1 -1
- package/package.json +9 -1
- package/types/capabilities.ts +40 -2
- package/types/eip1193.ts +70 -0
@@ -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
@@ -1185,7 +1185,7 @@ export type {
|
|
1185
1185
|
SignedAuthorization,
|
1186
1186
|
SignedAuthorizationList,
|
1187
1187
|
} from './types/authorization.js'
|
1188
|
-
export type { ResolvedRegister } from './types/register.js'
|
1188
|
+
export type { Register, ResolvedRegister } from './types/register.js'
|
1189
1189
|
export type {
|
1190
1190
|
Index,
|
1191
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
|
],
|
package/types/capabilities.ts
CHANGED
@@ -1,10 +1,36 @@
|
|
1
|
+
import type {
|
2
|
+
AddSubAccountParameters,
|
3
|
+
AddSubAccountReturnType,
|
4
|
+
} from '../experimental/erc7895/actions/addSubAccount.js'
|
5
|
+
import type { SiweMessage } from '../utils/siwe/types.js'
|
1
6
|
import type { Hex } from './misc.js'
|
2
7
|
import type { ResolvedRegister } from './register.js'
|
3
|
-
import type { Prettify } from './utils.js'
|
8
|
+
import type { Prettify, RequiredBy } from './utils.js'
|
4
9
|
|
5
10
|
export type CapabilitiesSchema = ResolvedRegister['CapabilitiesSchema']
|
6
11
|
|
7
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
|
+
}
|
8
34
|
getCapabilities: {
|
9
35
|
ReturnType: {
|
10
36
|
atomic?:
|
@@ -12,6 +38,17 @@ export type DefaultCapabilitiesSchema = {
|
|
12
38
|
status: 'supported' | 'ready' | 'unsupported'
|
13
39
|
}
|
14
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
|
15
52
|
paymasterService?:
|
16
53
|
| {
|
17
54
|
supported: boolean
|
@@ -24,8 +61,9 @@ export type DefaultCapabilitiesSchema = {
|
|
24
61
|
paymasterService?:
|
25
62
|
| {
|
26
63
|
[chainId: number]: {
|
27
|
-
url: string
|
28
64
|
context?: Record<string, any> | undefined
|
65
|
+
optional?: boolean | undefined
|
66
|
+
url: string
|
29
67
|
}
|
30
68
|
}
|
31
69
|
| undefined
|
package/types/eip1193.ts
CHANGED
@@ -1764,6 +1764,76 @@ export type WalletRpcSchema = [
|
|
1764
1764
|
Parameters: [chain: AddEthereumChainParameter]
|
1765
1765
|
ReturnType: null
|
1766
1766
|
},
|
1767
|
+
/**
|
1768
|
+
*
|
1769
|
+
*/
|
1770
|
+
{
|
1771
|
+
Method: 'wallet_addSubAccount'
|
1772
|
+
Parameters: [
|
1773
|
+
{
|
1774
|
+
account: OneOf<
|
1775
|
+
| {
|
1776
|
+
keys: readonly {
|
1777
|
+
publicKey: Hex
|
1778
|
+
type: 'address' | 'p256' | 'webcrypto-p256' | 'webauthn-p256'
|
1779
|
+
}[]
|
1780
|
+
type: 'create'
|
1781
|
+
}
|
1782
|
+
| {
|
1783
|
+
address: Address
|
1784
|
+
chainId?: number | undefined
|
1785
|
+
type: 'deployed'
|
1786
|
+
}
|
1787
|
+
| {
|
1788
|
+
address: Address
|
1789
|
+
chainId?: number | undefined
|
1790
|
+
factory: Address
|
1791
|
+
factoryData: Hex
|
1792
|
+
type: 'undeployed'
|
1793
|
+
}
|
1794
|
+
>
|
1795
|
+
version: string
|
1796
|
+
},
|
1797
|
+
]
|
1798
|
+
ReturnType: {
|
1799
|
+
address: Address
|
1800
|
+
factory?: Address | undefined
|
1801
|
+
factoryData?: Hex | undefined
|
1802
|
+
}
|
1803
|
+
},
|
1804
|
+
/**
|
1805
|
+
* @description Requests to connect account(s).
|
1806
|
+
* @link https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7846.md
|
1807
|
+
* @example
|
1808
|
+
* provider.request({ method: 'wallet_connect' })
|
1809
|
+
* // => { ... }
|
1810
|
+
*/
|
1811
|
+
{
|
1812
|
+
Method: 'wallet_connect'
|
1813
|
+
Parameters: [
|
1814
|
+
{
|
1815
|
+
capabilities?: Capabilities | undefined
|
1816
|
+
version: string
|
1817
|
+
},
|
1818
|
+
]
|
1819
|
+
ReturnType: {
|
1820
|
+
accounts: readonly {
|
1821
|
+
address: Address
|
1822
|
+
capabilities?: Capabilities | undefined
|
1823
|
+
}[]
|
1824
|
+
}
|
1825
|
+
},
|
1826
|
+
/**
|
1827
|
+
* @description Disconnects connected account(s).
|
1828
|
+
* @link https://github.com/ethereum/ERCs/blob/abd1c9f4eda2d6ad06ade0e3af314637a27d1ee7/ERCS/erc-7846.md
|
1829
|
+
* @example
|
1830
|
+
* provider.request({ method: 'wallet_disconnect' })
|
1831
|
+
*/
|
1832
|
+
{
|
1833
|
+
Method: 'wallet_disconnect'
|
1834
|
+
Parameters?: undefined
|
1835
|
+
ReturnType: void
|
1836
|
+
},
|
1767
1837
|
/**
|
1768
1838
|
* @description Returns the status of a call batch that was sent via `wallet_sendCalls`.
|
1769
1839
|
* @link https://eips.ethereum.org/EIPS/eip-5792
|