ox 0.9.7 → 0.9.9
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 +12 -0
- package/_cjs/erc7821/Calls.js +39 -0
- package/_cjs/erc7821/Calls.js.map +1 -0
- package/_cjs/erc7821/Execute.js +75 -0
- package/_cjs/erc7821/Execute.js.map +1 -0
- package/_cjs/erc7821/index.js +6 -0
- package/_cjs/erc7821/index.js.map +1 -0
- package/_cjs/index.docs.js +1 -0
- package/_cjs/index.docs.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/erc7821/Calls.js +101 -0
- package/_esm/erc7821/Calls.js.map +1 -0
- package/_esm/erc7821/Execute.js +151 -0
- package/_esm/erc7821/Execute.js.map +1 -0
- package/_esm/erc7821/index.js +69 -0
- package/_esm/erc7821/index.js.map +1 -0
- package/_esm/index.docs.js +1 -0
- package/_esm/index.docs.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/core/internal/rpcSchemas/eth.d.ts +16 -0
- package/_types/core/internal/rpcSchemas/eth.d.ts.map +1 -1
- package/_types/core/internal/rpcSchemas/wallet.d.ts +17 -0
- package/_types/core/internal/rpcSchemas/wallet.d.ts.map +1 -1
- package/_types/erc7821/Calls.d.ts +102 -0
- package/_types/erc7821/Calls.d.ts.map +1 -0
- package/_types/erc7821/Execute.d.ts +126 -0
- package/_types/erc7821/Execute.d.ts.map +1 -0
- package/_types/erc7821/index.d.ts +71 -0
- package/_types/erc7821/index.d.ts.map +1 -0
- package/_types/index.docs.d.ts +1 -0
- package/_types/index.docs.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/core/internal/rpcSchemas/eth.ts +18 -0
- package/core/internal/rpcSchemas/wallet.ts +19 -0
- package/erc7821/Calls/package.json +6 -0
- package/erc7821/Calls.ts +148 -0
- package/erc7821/Execute/package.json +6 -0
- package/erc7821/Execute.ts +197 -0
- package/erc7821/index.ts +73 -0
- package/erc7821/package.json +6 -0
- package/index.docs.ts +1 -0
- package/package.json +16 -1
- package/version.ts +1 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as AbiFunction from '../core/AbiFunction.js'
|
|
2
|
+
import type * as Hex from '../core/Hex.js'
|
|
3
|
+
import { AbiParameters } from '../index.js'
|
|
4
|
+
import * as Calls from './Calls.js'
|
|
5
|
+
|
|
6
|
+
export type Batch = {
|
|
7
|
+
calls: readonly Call[]
|
|
8
|
+
opData?: Hex.Hex | undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type Call = Calls.Call
|
|
12
|
+
|
|
13
|
+
export const abiFunction = {
|
|
14
|
+
type: 'function',
|
|
15
|
+
name: 'execute',
|
|
16
|
+
inputs: [
|
|
17
|
+
{
|
|
18
|
+
name: 'mode',
|
|
19
|
+
type: 'bytes32',
|
|
20
|
+
internalType: 'bytes32',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'executionData',
|
|
24
|
+
type: 'bytes',
|
|
25
|
+
internalType: 'bytes',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
outputs: [],
|
|
29
|
+
stateMutability: 'payable',
|
|
30
|
+
} satisfies AbiFunction.AbiFunction
|
|
31
|
+
|
|
32
|
+
export const mode = {
|
|
33
|
+
default: '0x0100000000000000000000000000000000000000000000000000000000000000',
|
|
34
|
+
opData: '0x0100000000007821000100000000000000000000000000000000000000000000',
|
|
35
|
+
batchOfBatches:
|
|
36
|
+
'0x0100000000007821000200000000000000000000000000000000000000000000',
|
|
37
|
+
} as const
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Decodes calls from ERC-7821 `execute` function data.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts twoslash
|
|
44
|
+
* import { Execute } from 'ox/erc7821'
|
|
45
|
+
*
|
|
46
|
+
* const { calls } = Execute.decodeData('0x...')
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param data - The encoded data.
|
|
50
|
+
* @returns The decoded calls and optional opData.
|
|
51
|
+
*/
|
|
52
|
+
export function decodeData(data: Hex.Hex): decodeData.ReturnType {
|
|
53
|
+
const [m, executionData] = AbiFunction.decodeData(abiFunction, data) as [
|
|
54
|
+
Hex.Hex,
|
|
55
|
+
Hex.Hex,
|
|
56
|
+
]
|
|
57
|
+
return Calls.decode(executionData, { opData: m !== mode.default })
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export declare namespace decodeData {
|
|
61
|
+
type ReturnType = {
|
|
62
|
+
calls: Call[]
|
|
63
|
+
opData?: Hex.Hex | undefined
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Decodes batches from ERC-7821 `execute` function data in "batch of batches" mode.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts twoslash
|
|
72
|
+
* import { Execute } from 'ox/erc7821'
|
|
73
|
+
*
|
|
74
|
+
* const batches = Execute.decodeBatchOfBatchesData('0x...')
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @param data - The encoded data.
|
|
78
|
+
* @returns The decoded batches.
|
|
79
|
+
*/
|
|
80
|
+
export function decodeBatchOfBatchesData(
|
|
81
|
+
data: Hex.Hex,
|
|
82
|
+
): decodeBatchOfBatchesData.ReturnType {
|
|
83
|
+
const [, executionData] = AbiFunction.decodeData(abiFunction, data) as [
|
|
84
|
+
Hex.Hex,
|
|
85
|
+
Hex.Hex,
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
const [encodedBatches] = AbiParameters.decode(
|
|
89
|
+
AbiParameters.from('bytes[]'),
|
|
90
|
+
executionData,
|
|
91
|
+
) as readonly [Hex.Hex[]]
|
|
92
|
+
|
|
93
|
+
return encodedBatches.map((encodedBatch) => {
|
|
94
|
+
// Try decoding with opData first
|
|
95
|
+
try {
|
|
96
|
+
const decoded = Calls.decode(encodedBatch, { opData: true })
|
|
97
|
+
if (decoded.opData) {
|
|
98
|
+
return {
|
|
99
|
+
calls: decoded.calls,
|
|
100
|
+
opData: decoded.opData,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// If opData is undefined, return without it
|
|
104
|
+
return { calls: decoded.calls }
|
|
105
|
+
} catch {
|
|
106
|
+
// If decoding with opData fails, decode without it
|
|
107
|
+
const decoded = Calls.decode(encodedBatch, { opData: false })
|
|
108
|
+
return { calls: decoded.calls }
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export declare namespace decodeBatchOfBatchesData {
|
|
114
|
+
type ReturnType = Batch[]
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Encodes calls for the ERC-7821 `execute` function with "batch of batches" mode.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts twoslash
|
|
122
|
+
* import { Execute } from 'ox/erc7821'
|
|
123
|
+
*
|
|
124
|
+
* const data = Execute.encodeBatchOfBatchesData([
|
|
125
|
+
* {
|
|
126
|
+
* calls: [
|
|
127
|
+
* {
|
|
128
|
+
* data: '0xcafebabe',
|
|
129
|
+
* to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
130
|
+
* value: 1n,
|
|
131
|
+
* }
|
|
132
|
+
* ]
|
|
133
|
+
* },
|
|
134
|
+
* {
|
|
135
|
+
* calls: [
|
|
136
|
+
* {
|
|
137
|
+
* data: '0xdeadbeef',
|
|
138
|
+
* to: '0xcafebabecafebabecafebabecafebabecafebabe',
|
|
139
|
+
* value: 2n,
|
|
140
|
+
* }
|
|
141
|
+
* ],
|
|
142
|
+
* opData: '0xcafebabe',
|
|
143
|
+
* }
|
|
144
|
+
* ])
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @param calls - The calls to encode.
|
|
148
|
+
* @param options - The options.
|
|
149
|
+
* @returns The encoded data.
|
|
150
|
+
*/
|
|
151
|
+
export function encodeBatchOfBatchesData(batches: readonly Batch[]) {
|
|
152
|
+
const b = AbiParameters.encode(AbiParameters.from('bytes[]'), [
|
|
153
|
+
batches.map((b) => {
|
|
154
|
+
const batch = b as Batch
|
|
155
|
+
return Calls.encode(batch.calls, {
|
|
156
|
+
opData: batch.opData,
|
|
157
|
+
})
|
|
158
|
+
}),
|
|
159
|
+
])
|
|
160
|
+
return AbiFunction.encodeData(abiFunction, [mode.batchOfBatches, b])
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Encodes calls for the ERC-7821 `execute` function.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts twoslash
|
|
168
|
+
* import { Execute } from 'ox/erc7821'
|
|
169
|
+
*
|
|
170
|
+
* const data = Execute.encodeData([
|
|
171
|
+
* {
|
|
172
|
+
* data: '0xcafebabe',
|
|
173
|
+
* to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
174
|
+
* value: 1n,
|
|
175
|
+
* }
|
|
176
|
+
* ])
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @param calls - The calls to encode.
|
|
180
|
+
* @param options - The options.
|
|
181
|
+
* @returns The encoded data.
|
|
182
|
+
*/
|
|
183
|
+
export function encodeData(
|
|
184
|
+
calls: readonly Call[],
|
|
185
|
+
options: encodeData.Options = {},
|
|
186
|
+
) {
|
|
187
|
+
const { opData } = options
|
|
188
|
+
const c = Calls.encode(calls, { opData })
|
|
189
|
+
const m = opData ? mode.opData : mode.default
|
|
190
|
+
return AbiFunction.encodeData(abiFunction, [m, c])
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export declare namespace encodeData {
|
|
194
|
+
type Options = {
|
|
195
|
+
opData?: Hex.Hex | undefined
|
|
196
|
+
}
|
|
197
|
+
}
|
package/erc7821/index.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** @entrypointCategory ERCs */
|
|
2
|
+
// biome-ignore lint/complexity/noUselessEmptyExport: tsdoc
|
|
3
|
+
export type {}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Utility functions for encoding and decoding [ERC-7821](https://eips.ethereum.org/EIPS/eip-7821) calls.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ### Encoding calls
|
|
10
|
+
*
|
|
11
|
+
* Calls can be encoded using `Calls.encode`.
|
|
12
|
+
*
|
|
13
|
+
* ```ts twoslash
|
|
14
|
+
* import { Calls } from 'ox/erc7821'
|
|
15
|
+
*
|
|
16
|
+
* const calls = Calls.encode([
|
|
17
|
+
* {
|
|
18
|
+
* data: '0xcafebabe',
|
|
19
|
+
* to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
20
|
+
* value: 1n,
|
|
21
|
+
* }
|
|
22
|
+
* ])
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ### Decoding calls
|
|
27
|
+
*
|
|
28
|
+
* Calls can be decoded using `Calls.decode`.
|
|
29
|
+
*
|
|
30
|
+
* ```ts twoslash
|
|
31
|
+
* import { Calls } from 'ox/erc7821'
|
|
32
|
+
*
|
|
33
|
+
* const { calls } = Calls.decode('0x...')
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @category ERC-7821
|
|
37
|
+
*/
|
|
38
|
+
export * as Calls from './Calls.js'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Utility functions for encoding and decoding [ERC-7821](https://eips.ethereum.org/EIPS/eip-7821) `execute` function data.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ### Encoding `execute` Function Data
|
|
45
|
+
*
|
|
46
|
+
* The `execute` function data can be encoded using `Execute.encodeData`.
|
|
47
|
+
*
|
|
48
|
+
* ```ts twoslash
|
|
49
|
+
* import { Execute } from 'ox/erc7821'
|
|
50
|
+
*
|
|
51
|
+
* const data = Execute.encodeData([
|
|
52
|
+
* {
|
|
53
|
+
* data: '0xcafebabe',
|
|
54
|
+
* to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
55
|
+
* value: 1n,
|
|
56
|
+
* }
|
|
57
|
+
* ])
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ### Decoding `execute` Function Data
|
|
62
|
+
*
|
|
63
|
+
* The `execute` function data can be decoded using `Execute.decodeData`.
|
|
64
|
+
*
|
|
65
|
+
* ```ts twoslash
|
|
66
|
+
* import { Execute } from 'ox/erc7821'
|
|
67
|
+
*
|
|
68
|
+
* const { calls } = Execute.decodeData('0xe9ae5c53...')
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @category ERC-7821
|
|
72
|
+
*/
|
|
73
|
+
export * as Execute from './Execute.js'
|
package/index.docs.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ox",
|
|
3
3
|
"description": "Ethereum Standard Library",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.9",
|
|
5
5
|
"main": "./_cjs/index.js",
|
|
6
6
|
"module": "./_esm/index.js",
|
|
7
7
|
"types": "./_types/index.d.ts",
|
|
@@ -428,6 +428,21 @@
|
|
|
428
428
|
"import": "./_esm/erc6492/index.js",
|
|
429
429
|
"default": "./_cjs/erc6492/index.js"
|
|
430
430
|
},
|
|
431
|
+
"./erc7821/Calls": {
|
|
432
|
+
"types": "./_types/erc7821/Calls.d.ts",
|
|
433
|
+
"import": "./_esm/erc7821/Calls.js",
|
|
434
|
+
"default": "./_cjs/erc7821/Calls.js"
|
|
435
|
+
},
|
|
436
|
+
"./erc7821/Execute": {
|
|
437
|
+
"types": "./_types/erc7821/Execute.d.ts",
|
|
438
|
+
"import": "./_esm/erc7821/Execute.js",
|
|
439
|
+
"default": "./_cjs/erc7821/Execute.js"
|
|
440
|
+
},
|
|
441
|
+
"./erc7821": {
|
|
442
|
+
"types": "./_types/erc7821/index.d.ts",
|
|
443
|
+
"import": "./_esm/erc7821/index.js",
|
|
444
|
+
"default": "./_cjs/erc7821/index.js"
|
|
445
|
+
},
|
|
431
446
|
"./erc8010/SignatureErc8010": {
|
|
432
447
|
"types": "./_types/erc8010/SignatureErc8010.d.ts",
|
|
433
448
|
"import": "./_esm/erc8010/SignatureErc8010.js",
|
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.9.
|
|
2
|
+
export const version = '0.9.9'
|