viem 2.16.1 → 2.16.2
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 +8 -0
- package/_cjs/chains/definitions/dchain.js +27 -0
- package/_cjs/chains/definitions/dchain.js.map +1 -0
- package/_cjs/chains/definitions/dchainTestnet.js +29 -0
- package/_cjs/chains/definitions/dchainTestnet.js.map +1 -0
- package/_cjs/chains/index.js +9 -5
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/erc7715/actions/grantPermissions.js +94 -0
- package/_cjs/experimental/erc7715/actions/grantPermissions.js.map +1 -0
- package/_cjs/experimental/erc7715/decorators/erc7715.js +2 -2
- package/_cjs/experimental/erc7715/types/policy.js +3 -0
- package/_cjs/experimental/erc7715/types/policy.js.map +1 -0
- package/_cjs/experimental/index.js +3 -3
- package/_esm/chains/definitions/dchain.js +24 -0
- package/_esm/chains/definitions/dchain.js.map +1 -0
- package/_esm/chains/definitions/dchainTestnet.js +26 -0
- package/_esm/chains/definitions/dchainTestnet.js.map +1 -0
- package/_esm/chains/index.js +2 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/erc7715/actions/grantPermissions.js +130 -0
- package/_esm/experimental/erc7715/actions/grantPermissions.js.map +1 -0
- package/_esm/experimental/erc7715/decorators/erc7715.js +3 -3
- package/_esm/experimental/erc7715/types/policy.js +2 -0
- package/_esm/experimental/erc7715/types/policy.js.map +1 -0
- package/_esm/experimental/index.js +1 -1
- package/_types/chains/definitions/dchain.d.ts +1049 -0
- package/_types/chains/definitions/dchain.d.ts.map +1 -0
- package/_types/chains/definitions/dchainTestnet.d.ts +1049 -0
- package/_types/chains/definitions/dchainTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +2 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/erc7715/actions/{issuePermissions.d.ts → grantPermissions.d.ts} +18 -16
- package/_types/experimental/erc7715/actions/{issuePermissions.d.ts.map → grantPermissions.d.ts.map} +1 -1
- package/_types/experimental/erc7715/decorators/erc7715.d.ts +5 -5
- package/_types/experimental/erc7715/types/permission.d.ts +24 -20
- package/_types/experimental/erc7715/types/permission.d.ts.map +1 -1
- package/_types/experimental/erc7715/types/policy.d.ts +36 -0
- package/_types/experimental/erc7715/types/policy.d.ts.map +1 -0
- package/_types/experimental/erc7715/types/signer.d.ts +5 -1
- package/_types/experimental/erc7715/types/signer.d.ts.map +1 -1
- package/_types/experimental/index.d.ts +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/types/eip1193.d.ts +19 -10
- package/_types/types/eip1193.d.ts.map +1 -1
- package/chains/definitions/dchain.ts +24 -0
- package/chains/definitions/dchainTestnet.ts +27 -0
- package/chains/index.ts +2 -0
- package/errors/version.ts +1 -1
- package/experimental/erc7715/actions/{issuePermissions.ts → grantPermissions.ts} +82 -54
- package/experimental/erc7715/decorators/erc7715.ts +11 -11
- package/experimental/erc7715/types/permission.ts +28 -26
- package/experimental/erc7715/types/policy.ts +43 -0
- package/experimental/erc7715/types/signer.ts +8 -1
- package/experimental/index.ts +4 -4
- package/index.ts +2 -2
- package/package.json +1 -1
- package/types/eip1193.ts +19 -10
- package/_cjs/experimental/erc7715/actions/issuePermissions.js +0 -73
- package/_cjs/experimental/erc7715/actions/issuePermissions.js.map +0 -1
- package/_esm/experimental/erc7715/actions/issuePermissions.js +0 -107
- package/_esm/experimental/erc7715/actions/issuePermissions.js.map +0 -1
@@ -2,14 +2,14 @@ import type { Address } from 'abitype'
|
|
2
2
|
import type { Client } from '../../../clients/createClient.js'
|
3
3
|
import type { Transport } from '../../../clients/transports/createTransport.js'
|
4
4
|
import type { Account } from '../../../types/account.js'
|
5
|
-
import type {
|
5
|
+
import type { WalletGrantPermissionsReturnType } from '../../../types/eip1193.js'
|
6
6
|
import type { Hex } from '../../../types/misc.js'
|
7
7
|
import type { OneOf } from '../../../types/utils.js'
|
8
|
-
import { numberToHex } from '../../../utils/
|
8
|
+
import { numberToHex, parseAccount } from '../../../utils/index.js'
|
9
9
|
import type { Permission } from '../types/permission.js'
|
10
10
|
import type { Signer } from '../types/signer.js'
|
11
11
|
|
12
|
-
export type
|
12
|
+
export type GrantPermissionsParameters = {
|
13
13
|
/** Timestamp (in seconds) that specifies the time by which this session MUST expire. */
|
14
14
|
expiry: number
|
15
15
|
/** Set of permissions to grant to the user. */
|
@@ -25,7 +25,7 @@ export type IssuePermissionsParameters = {
|
|
25
25
|
}
|
26
26
|
>
|
27
27
|
|
28
|
-
export type
|
28
|
+
export type GrantPermissionsReturnType = {
|
29
29
|
/** Timestamp (in seconds) that specifies the time by which this session MUST expire. */
|
30
30
|
expiry: number
|
31
31
|
/** ERC-4337 Factory to deploy smart contract account. */
|
@@ -33,7 +33,7 @@ export type IssuePermissionsReturnType = {
|
|
33
33
|
/** Calldata to use when calling the ERC-4337 Factory. */
|
34
34
|
factoryData?: string | undefined
|
35
35
|
/** Set of granted permissions. */
|
36
|
-
grantedPermissions:
|
36
|
+
grantedPermissions: readonly Permission[]
|
37
37
|
/** Permissions identifier. */
|
38
38
|
permissionsContext: string
|
39
39
|
/** Signer attached to the permissions. */
|
@@ -48,76 +48,80 @@ export type IssuePermissionsReturnType = {
|
|
48
48
|
/**
|
49
49
|
* Request permissions from a wallet to perform actions on behalf of a user.
|
50
50
|
*
|
51
|
-
* - Docs: https://viem.sh/experimental/erc7715/
|
51
|
+
* - Docs: https://viem.sh/experimental/erc7715/grantPermissions
|
52
52
|
*
|
53
53
|
* @example
|
54
54
|
* import { createWalletClient, custom } from 'viem'
|
55
55
|
* import { mainnet } from 'viem/chains'
|
56
|
-
* import {
|
56
|
+
* import { grantPermissions } from 'viem/experimental'
|
57
57
|
*
|
58
58
|
* const client = createWalletClient({
|
59
59
|
* chain: mainnet,
|
60
60
|
* transport: custom(window.ethereum),
|
61
61
|
* })
|
62
62
|
*
|
63
|
-
* const result = await
|
63
|
+
* const result = await grantPermissions(client, {
|
64
64
|
* expiry: 1716846083638,
|
65
65
|
* permissions: [
|
66
66
|
* {
|
67
|
-
* type: '
|
67
|
+
* type: 'native-token-transfer',
|
68
68
|
* data: {
|
69
|
-
*
|
70
|
-
* },
|
71
|
-
* },
|
72
|
-
* {
|
73
|
-
* type: 'native-token-limit',
|
74
|
-
* data: {
|
75
|
-
* amount: 69420n,
|
69
|
+
* ticker: 'ETH',
|
76
70
|
* },
|
71
|
+
* policies: [
|
72
|
+
* {
|
73
|
+
* type: 'token-allowance',
|
74
|
+
* data: {
|
75
|
+
* allowance: parseEther('1'),
|
76
|
+
* },
|
77
|
+
* }
|
78
|
+
* ],
|
77
79
|
* required: true,
|
78
80
|
* },
|
79
81
|
* ],
|
80
82
|
* })
|
81
83
|
*/
|
82
|
-
export async function
|
84
|
+
export async function grantPermissions(
|
83
85
|
client: Client<Transport>,
|
84
|
-
parameters:
|
85
|
-
): Promise<
|
86
|
-
const { expiry, permissions, signer } = parameters
|
86
|
+
parameters: GrantPermissionsParameters,
|
87
|
+
): Promise<GrantPermissionsReturnType> {
|
88
|
+
const { account, expiry, permissions, signer } = parameters
|
87
89
|
const result = await client.request(
|
88
90
|
{
|
89
|
-
method: '
|
90
|
-
params: [
|
91
|
+
method: 'wallet_grantPermissions',
|
92
|
+
params: [
|
93
|
+
formatParameters({ account, expiry, permissions, signer } as any),
|
94
|
+
],
|
91
95
|
},
|
92
96
|
{ retryCount: 0 },
|
93
97
|
)
|
94
|
-
return
|
98
|
+
return formatRequest(result) as GrantPermissionsReturnType
|
95
99
|
}
|
96
100
|
|
97
|
-
function
|
98
|
-
const {
|
101
|
+
function formatParameters(parameters: GrantPermissionsParameters) {
|
102
|
+
const { expiry, permissions, signer: signer_ } = parameters
|
103
|
+
|
104
|
+
const account = parameters.account
|
105
|
+
? parseAccount(parameters.account)
|
106
|
+
: undefined
|
99
107
|
|
100
108
|
const signer = (() => {
|
101
109
|
if (!account && !signer_) return undefined
|
102
110
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
data: {
|
109
|
-
id: account,
|
110
|
-
},
|
111
|
-
}
|
111
|
+
// JSON-RPC Account as signer.
|
112
|
+
if (account?.type === 'json-rpc')
|
113
|
+
return {
|
114
|
+
type: 'wallet',
|
115
|
+
}
|
112
116
|
|
113
|
-
|
117
|
+
// Local Account as signer.
|
118
|
+
if (account?.type === 'local')
|
114
119
|
return {
|
115
120
|
type: 'account',
|
116
121
|
data: {
|
117
122
|
id: account.address,
|
118
123
|
},
|
119
124
|
}
|
120
|
-
}
|
121
125
|
|
122
126
|
// ERC-7715 Signer as signer.
|
123
127
|
return signer_
|
@@ -127,36 +131,60 @@ function parseParameters(parameters: IssuePermissionsParameters) {
|
|
127
131
|
expiry,
|
128
132
|
permissions: permissions.map((permission) => ({
|
129
133
|
...permission,
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
134
|
+
policies: permission.policies.map((policy) => {
|
135
|
+
const data = (() => {
|
136
|
+
if (policy.type === 'token-allowance')
|
137
|
+
return {
|
138
|
+
allowance: numberToHex(policy.data.allowance),
|
139
|
+
}
|
140
|
+
if (policy.type === 'gas-limit')
|
141
|
+
return {
|
142
|
+
limit: numberToHex(policy.data.limit),
|
143
|
+
}
|
144
|
+
return policy.data
|
145
|
+
})()
|
146
|
+
|
147
|
+
return {
|
148
|
+
data,
|
149
|
+
type:
|
150
|
+
typeof policy.type === 'string' ? policy.type : policy.type.custom,
|
151
|
+
}
|
152
|
+
}),
|
141
153
|
required: permission.required ?? false,
|
154
|
+
type:
|
155
|
+
typeof permission.type === 'string'
|
156
|
+
? permission.type
|
157
|
+
: permission.type.custom,
|
142
158
|
})),
|
143
159
|
...(signer ? { signer } : {}),
|
144
160
|
}
|
145
161
|
}
|
146
162
|
|
147
|
-
function
|
163
|
+
function formatRequest(result: WalletGrantPermissionsReturnType) {
|
148
164
|
return {
|
149
165
|
expiry: result.expiry,
|
150
166
|
...(result.factory ? { factory: result.factory } : {}),
|
151
167
|
...(result.factoryData ? { factoryData: result.factoryData } : {}),
|
152
168
|
grantedPermissions: result.grantedPermissions.map((permission) => ({
|
153
169
|
...permission,
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
170
|
+
policies: permission.policies.map((policy) => {
|
171
|
+
const data = (() => {
|
172
|
+
if (policy.type === 'token-allowance')
|
173
|
+
return {
|
174
|
+
allowance: BigInt((policy.data as any).allowance),
|
175
|
+
}
|
176
|
+
if (policy.type === 'gas-limit')
|
177
|
+
return {
|
178
|
+
limit: BigInt((policy.data as any).limit),
|
179
|
+
}
|
180
|
+
return policy.data
|
181
|
+
})()
|
182
|
+
|
183
|
+
return {
|
184
|
+
data,
|
185
|
+
type: policy.type,
|
186
|
+
}
|
187
|
+
}),
|
160
188
|
})),
|
161
189
|
permissionsContext: result.permissionsContext,
|
162
190
|
...(result.signerData ? { signerData: result.signerData } : {}),
|
@@ -3,16 +3,16 @@ 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
5
|
import {
|
6
|
-
type
|
7
|
-
type
|
8
|
-
|
9
|
-
} from '../actions/
|
6
|
+
type GrantPermissionsParameters,
|
7
|
+
type GrantPermissionsReturnType,
|
8
|
+
grantPermissions,
|
9
|
+
} from '../actions/grantPermissions.js'
|
10
10
|
|
11
11
|
export type WalletActionsErc7715 = {
|
12
12
|
/**
|
13
13
|
* Request permissions from a wallet to perform actions on behalf of a user.
|
14
14
|
*
|
15
|
-
* - Docs: https://viem.sh/experimental/erc7715/
|
15
|
+
* - Docs: https://viem.sh/experimental/erc7715/grantPermissions
|
16
16
|
*
|
17
17
|
* @example
|
18
18
|
* import { createWalletClient, custom } from 'viem'
|
@@ -24,7 +24,7 @@ export type WalletActionsErc7715 = {
|
|
24
24
|
* transport: custom(window.ethereum),
|
25
25
|
* }).extend(walletActionsErc7715())
|
26
26
|
*
|
27
|
-
* const result = await client.
|
27
|
+
* const result = await client.grantPermissions({
|
28
28
|
* expiry: 1716846083638,
|
29
29
|
* permissions: [
|
30
30
|
* {
|
@@ -43,9 +43,9 @@ export type WalletActionsErc7715 = {
|
|
43
43
|
* ],
|
44
44
|
* })
|
45
45
|
*/
|
46
|
-
|
47
|
-
parameters:
|
48
|
-
) => Promise<
|
46
|
+
grantPermissions: (
|
47
|
+
parameters: GrantPermissionsParameters,
|
48
|
+
) => Promise<GrantPermissionsReturnType>
|
49
49
|
}
|
50
50
|
|
51
51
|
/**
|
@@ -63,7 +63,7 @@ export type WalletActionsErc7715 = {
|
|
63
63
|
* transport: http(),
|
64
64
|
* }).extend(walletActionsErc7715())
|
65
65
|
*
|
66
|
-
* const result = await walletClient.
|
66
|
+
* const result = await walletClient.grantPermissions({...})
|
67
67
|
*/
|
68
68
|
export function walletActionsErc7715() {
|
69
69
|
return <
|
@@ -74,7 +74,7 @@ export function walletActionsErc7715() {
|
|
74
74
|
client: Client<transport, chain, account>,
|
75
75
|
): WalletActionsErc7715 => {
|
76
76
|
return {
|
77
|
-
|
77
|
+
grantPermissions: (parameters) => grantPermissions(client, parameters),
|
78
78
|
}
|
79
79
|
}
|
80
80
|
}
|
@@ -1,51 +1,53 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
3
|
import type { OneOf } from '../../../types/utils.js'
|
4
|
+
import type { Policy } from './policy.js'
|
4
5
|
|
5
6
|
/** @internal */
|
6
|
-
export type
|
7
|
-
|
8
|
-
|
9
|
-
amount: amount
|
10
|
-
}
|
7
|
+
export type CustomPermission<data = unknown, type = { custom: string }> = {
|
8
|
+
data: data
|
9
|
+
type: type
|
11
10
|
}
|
12
11
|
|
13
12
|
/** @internal */
|
14
|
-
export type
|
15
|
-
type: '
|
13
|
+
export type NativeTokenTransferPermission = {
|
14
|
+
type: 'native-token-transfer'
|
16
15
|
data: {
|
17
|
-
|
18
|
-
|
16
|
+
/** Native token ticker (e.g. ETH). */
|
17
|
+
ticker: string
|
19
18
|
}
|
20
19
|
}
|
21
20
|
|
22
21
|
/** @internal */
|
23
|
-
export type
|
24
|
-
type: '
|
22
|
+
export type Erc20TokenTransferPermission = {
|
23
|
+
type: 'erc20-token-transfer'
|
25
24
|
data: {
|
26
|
-
|
25
|
+
/** ERC20 address. */
|
26
|
+
address: Address
|
27
|
+
/** Native token ticker (e.g. ETH). */
|
28
|
+
ticker: string
|
27
29
|
}
|
28
30
|
}
|
29
31
|
|
30
32
|
/** @internal */
|
31
33
|
export type ContractCallPermission = {
|
32
34
|
type: 'contract-call'
|
33
|
-
data: unknown
|
34
|
-
}
|
35
|
-
|
36
|
-
/** @internal */
|
37
|
-
export type RateLimitPermission = {
|
38
|
-
type: 'rate-limit'
|
39
35
|
data: {
|
40
|
-
|
41
|
-
|
36
|
+
/** Contract address. */
|
37
|
+
address: Address
|
38
|
+
/** Set of contract signatures to permit. */
|
39
|
+
calls: string[]
|
42
40
|
}
|
43
41
|
}
|
44
42
|
|
45
|
-
export type Permission<
|
46
|
-
|
|
47
|
-
|
|
48
|
-
| GasLimitPermission<amount>
|
43
|
+
export type Permission<uint256 = bigint> = OneOf<
|
44
|
+
| NativeTokenTransferPermission
|
45
|
+
| Erc20TokenTransferPermission
|
49
46
|
| ContractCallPermission
|
50
|
-
|
|
51
|
-
> & {
|
47
|
+
| CustomPermission
|
48
|
+
> & {
|
49
|
+
/** Set of policies for the permission. */
|
50
|
+
policies: readonly Policy<uint256>[]
|
51
|
+
/** Whether or not the wallet must grant the permission. */
|
52
|
+
required?: boolean | undefined
|
53
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import type { OneOf } from '../../../types/utils.js'
|
2
|
+
|
3
|
+
/** @internal */
|
4
|
+
export type CustomPolicy<data = unknown> = {
|
5
|
+
data: data
|
6
|
+
type: { custom: string }
|
7
|
+
}
|
8
|
+
|
9
|
+
/** @internal */
|
10
|
+
export type TokenAllowancePolicy<uint256 = bigint> = {
|
11
|
+
type: 'token-allowance'
|
12
|
+
data: {
|
13
|
+
/** Token allowance (in wei). */
|
14
|
+
allowance: uint256
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
/** @internal */
|
19
|
+
export type GasLimitPolicy<uint256 = bigint> = {
|
20
|
+
type: 'gas-limit'
|
21
|
+
data: {
|
22
|
+
/** Gas limit (in wei). */
|
23
|
+
limit: uint256
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
/** @internal */
|
28
|
+
export type RateLimitPolicy = {
|
29
|
+
type: 'rate-limit'
|
30
|
+
data: {
|
31
|
+
/** Number of times during each interval. */
|
32
|
+
count: number
|
33
|
+
/** Interval (in seconds). */
|
34
|
+
interval: number
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
export type Policy<amount = bigint> = OneOf<
|
39
|
+
| TokenAllowancePolicy<amount>
|
40
|
+
| GasLimitPolicy<amount>
|
41
|
+
| RateLimitPolicy
|
42
|
+
| CustomPolicy
|
43
|
+
>
|
@@ -25,4 +25,11 @@ export type MultiKeySigner = {
|
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
-
|
28
|
+
/** @internal */
|
29
|
+
export type WalletSigner = {
|
30
|
+
type: 'wallet'
|
31
|
+
}
|
32
|
+
|
33
|
+
export type Signer = OneOf<
|
34
|
+
AccountSigner | KeySigner | MultiKeySigner | WalletSigner
|
35
|
+
>
|
package/experimental/index.ts
CHANGED
@@ -67,10 +67,10 @@ export {
|
|
67
67
|
} from '../utils/signature/serializeErc6492Signature.js'
|
68
68
|
|
69
69
|
export {
|
70
|
-
type
|
71
|
-
type
|
72
|
-
|
73
|
-
} from './erc7715/actions/
|
70
|
+
type GrantPermissionsParameters,
|
71
|
+
type GrantPermissionsReturnType,
|
72
|
+
grantPermissions,
|
73
|
+
} from './erc7715/actions/grantPermissions.js'
|
74
74
|
export {
|
75
75
|
type WalletActionsErc7715,
|
76
76
|
walletActionsErc7715,
|
package/index.ts
CHANGED
@@ -1021,8 +1021,8 @@ export type {
|
|
1021
1021
|
WalletCapabilitiesRecord,
|
1022
1022
|
WalletCallReceipt,
|
1023
1023
|
WalletGetCallsStatusReturnType,
|
1024
|
-
|
1025
|
-
|
1024
|
+
WalletGrantPermissionsParameters,
|
1025
|
+
WalletGrantPermissionsReturnType,
|
1026
1026
|
WalletSendCallsParameters,
|
1027
1027
|
WalletPermissionCaveat,
|
1028
1028
|
WalletPermission,
|
package/package.json
CHANGED
package/types/eip1193.ts
CHANGED
@@ -131,28 +131,37 @@ export type WalletCallReceipt<quantity = Hex, status = Hex> = {
|
|
131
131
|
transactionHash: Hex
|
132
132
|
}
|
133
133
|
|
134
|
-
export type
|
134
|
+
export type WalletGrantPermissionsParameters = {
|
135
135
|
signer?:
|
136
136
|
| {
|
137
137
|
type: string
|
138
|
-
data
|
138
|
+
data?: unknown | undefined
|
139
139
|
}
|
140
140
|
| undefined
|
141
141
|
permissions: readonly {
|
142
|
-
type: string
|
143
142
|
data: unknown
|
144
|
-
|
143
|
+
policies: readonly {
|
144
|
+
data: unknown
|
145
|
+
type: string
|
146
|
+
}[]
|
147
|
+
required?: boolean | undefined
|
148
|
+
type: string
|
145
149
|
}[]
|
146
150
|
expiry: number
|
147
151
|
}
|
148
152
|
|
149
|
-
export type
|
153
|
+
export type WalletGrantPermissionsReturnType = {
|
150
154
|
expiry: number
|
151
155
|
factory?: `0x${string}` | undefined
|
152
156
|
factoryData?: string | undefined
|
153
157
|
grantedPermissions: readonly {
|
158
|
+
data: unknown
|
159
|
+
policies: readonly {
|
160
|
+
data: unknown
|
161
|
+
type: string
|
162
|
+
}[]
|
163
|
+
required?: boolean | undefined
|
154
164
|
type: string
|
155
|
-
data: any
|
156
165
|
}[]
|
157
166
|
permissionsContext: string
|
158
167
|
signerData?:
|
@@ -1404,13 +1413,13 @@ export type WalletRpcSchema = [
|
|
1404
1413
|
* @description Requests permissions from a wallet
|
1405
1414
|
* @link https://eips.ethereum.org/EIPS/eip-7715
|
1406
1415
|
* @example
|
1407
|
-
* provider.request({ method: '
|
1416
|
+
* provider.request({ method: 'wallet_grantPermissions', params: [{ ... }] })
|
1408
1417
|
* // => { ... }
|
1409
1418
|
*/
|
1410
1419
|
{
|
1411
|
-
Method: '
|
1412
|
-
Parameters?: [
|
1413
|
-
ReturnType: Prettify<
|
1420
|
+
Method: 'wallet_grantPermissions'
|
1421
|
+
Parameters?: [WalletGrantPermissionsParameters]
|
1422
|
+
ReturnType: Prettify<WalletGrantPermissionsReturnType>
|
1414
1423
|
},
|
1415
1424
|
/**
|
1416
1425
|
* @description Requests the given permissions from the user.
|
@@ -1,73 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.issuePermissions = issuePermissions;
|
4
|
-
const toHex_js_1 = require("../../../utils/encoding/toHex.js");
|
5
|
-
async function issuePermissions(client, parameters) {
|
6
|
-
const { expiry, permissions, signer } = parameters;
|
7
|
-
const result = await client.request({
|
8
|
-
method: 'wallet_issuePermissions',
|
9
|
-
params: [parseParameters({ expiry, permissions, signer })],
|
10
|
-
}, { retryCount: 0 });
|
11
|
-
return parseResult(result);
|
12
|
-
}
|
13
|
-
function parseParameters(parameters) {
|
14
|
-
const { account, expiry, permissions, signer: signer_ } = parameters;
|
15
|
-
const signer = (() => {
|
16
|
-
if (!account && !signer_)
|
17
|
-
return undefined;
|
18
|
-
if (account) {
|
19
|
-
if (typeof account === 'string')
|
20
|
-
return {
|
21
|
-
type: 'account',
|
22
|
-
data: {
|
23
|
-
id: account,
|
24
|
-
},
|
25
|
-
};
|
26
|
-
return {
|
27
|
-
type: 'account',
|
28
|
-
data: {
|
29
|
-
id: account.address,
|
30
|
-
},
|
31
|
-
};
|
32
|
-
}
|
33
|
-
return signer_;
|
34
|
-
})();
|
35
|
-
return {
|
36
|
-
expiry,
|
37
|
-
permissions: permissions.map((permission) => ({
|
38
|
-
...permission,
|
39
|
-
...(permission.data && typeof permission.data === 'object'
|
40
|
-
? {
|
41
|
-
data: {
|
42
|
-
...permission.data,
|
43
|
-
...('amount' in permission.data &&
|
44
|
-
typeof permission.data.amount === 'bigint'
|
45
|
-
? { amount: (0, toHex_js_1.numberToHex)(permission.data.amount) }
|
46
|
-
: {}),
|
47
|
-
},
|
48
|
-
}
|
49
|
-
: {}),
|
50
|
-
required: permission.required ?? false,
|
51
|
-
})),
|
52
|
-
...(signer ? { signer } : {}),
|
53
|
-
};
|
54
|
-
}
|
55
|
-
function parseResult(result) {
|
56
|
-
return {
|
57
|
-
expiry: result.expiry,
|
58
|
-
...(result.factory ? { factory: result.factory } : {}),
|
59
|
-
...(result.factoryData ? { factoryData: result.factoryData } : {}),
|
60
|
-
grantedPermissions: result.grantedPermissions.map((permission) => ({
|
61
|
-
...permission,
|
62
|
-
data: {
|
63
|
-
...permission.data,
|
64
|
-
...('amount' in permission.data
|
65
|
-
? { amount: BigInt(permission.data.amount) }
|
66
|
-
: {}),
|
67
|
-
},
|
68
|
-
})),
|
69
|
-
permissionsContext: result.permissionsContext,
|
70
|
-
...(result.signerData ? { signerData: result.signerData } : {}),
|
71
|
-
};
|
72
|
-
}
|
73
|
-
//# sourceMappingURL=issuePermissions.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"issuePermissions.js","sourceRoot":"","sources":["../../../../experimental/erc7715/actions/issuePermissions.ts"],"names":[],"mappings":";;AAiFA,4CAaC;AAvFD,+DAA8D;AA0EvD,KAAK,UAAU,gBAAgB,CACpC,MAAyB,EACzB,UAAsC;IAEtC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,UAAU,CAAA;IAClD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CACjC;QACE,MAAM,EAAE,yBAAyB;QACjC,MAAM,EAAE,CAAC,eAAe,CAA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