ox 0.4.3 → 0.5.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/core/Siwe.js +1 -1
  3. package/_cjs/core/Siwe.js.map +1 -1
  4. package/_cjs/erc4337/EntryPoint.js +1320 -0
  5. package/_cjs/erc4337/EntryPoint.js.map +1 -0
  6. package/_cjs/erc4337/RpcSchema.js +3 -0
  7. package/_cjs/erc4337/RpcSchema.js.map +1 -0
  8. package/_cjs/erc4337/UserOperation.js +152 -0
  9. package/_cjs/erc4337/UserOperation.js.map +1 -0
  10. package/_cjs/erc4337/UserOperationGas.js +31 -0
  11. package/_cjs/erc4337/UserOperationGas.js.map +1 -0
  12. package/_cjs/erc4337/UserOperationReceipt.js +35 -0
  13. package/_cjs/erc4337/UserOperationReceipt.js.map +1 -0
  14. package/_cjs/erc4337/index.js +9 -0
  15. package/_cjs/erc4337/index.js.map +1 -0
  16. package/_cjs/index.docs.js +1 -0
  17. package/_cjs/index.docs.js.map +1 -1
  18. package/_cjs/version.js +1 -1
  19. package/_esm/core/Siwe.js +1 -1
  20. package/_esm/core/Siwe.js.map +1 -1
  21. package/_esm/erc4337/EntryPoint.js +1321 -0
  22. package/_esm/erc4337/EntryPoint.js.map +1 -0
  23. package/_esm/erc4337/RpcSchema.js +2 -0
  24. package/_esm/erc4337/RpcSchema.js.map +1 -0
  25. package/_esm/erc4337/UserOperation.js +324 -0
  26. package/_esm/erc4337/UserOperation.js.map +1 -0
  27. package/_esm/erc4337/UserOperationGas.js +61 -0
  28. package/_esm/erc4337/UserOperationGas.js.map +1 -0
  29. package/_esm/erc4337/UserOperationReceipt.js +79 -0
  30. package/_esm/erc4337/UserOperationReceipt.js.map +1 -0
  31. package/_esm/erc4337/index.js +31 -0
  32. package/_esm/erc4337/index.js.map +1 -0
  33. package/_esm/index.docs.js +1 -0
  34. package/_esm/index.docs.js.map +1 -1
  35. package/_esm/version.js +1 -1
  36. package/_types/erc4337/EntryPoint.d.ts +1480 -0
  37. package/_types/erc4337/EntryPoint.d.ts.map +1 -0
  38. package/_types/erc4337/RpcSchema.d.ts +159 -0
  39. package/_types/erc4337/RpcSchema.d.ts.map +1 -0
  40. package/_types/erc4337/UserOperation.d.ts +330 -0
  41. package/_types/erc4337/UserOperation.d.ts.map +1 -0
  42. package/_types/erc4337/UserOperationGas.d.ts +62 -0
  43. package/_types/erc4337/UserOperationGas.d.ts.map +1 -0
  44. package/_types/erc4337/UserOperationReceipt.d.ts +87 -0
  45. package/_types/erc4337/UserOperationReceipt.d.ts.map +1 -0
  46. package/_types/erc4337/index.d.ts +33 -0
  47. package/_types/erc4337/index.d.ts.map +1 -0
  48. package/_types/index.docs.d.ts +1 -0
  49. package/_types/index.docs.d.ts.map +1 -1
  50. package/_types/version.d.ts +1 -1
  51. package/core/Siwe.ts +1 -1
  52. package/erc4337/EntryPoint/package.json +6 -0
  53. package/erc4337/EntryPoint.ts +1419 -0
  54. package/erc4337/RpcSchema/package.json +6 -0
  55. package/erc4337/RpcSchema.ts +179 -0
  56. package/erc4337/UserOperation/package.json +6 -0
  57. package/erc4337/UserOperation.ts +617 -0
  58. package/erc4337/UserOperationGas/package.json +6 -0
  59. package/erc4337/UserOperationGas.ts +109 -0
  60. package/erc4337/UserOperationReceipt/package.json +6 -0
  61. package/erc4337/UserOperationReceipt.ts +139 -0
  62. package/erc4337/index.ts +38 -0
  63. package/erc4337/package.json +6 -0
  64. package/index.docs.ts +1 -0
  65. package/package.json +31 -1
  66. package/version.ts +1 -1
@@ -0,0 +1,109 @@
1
+ import * as Hex from '../core/Hex.js'
2
+ import type { OneOf } from '../core/internal/types.js'
3
+ import type * as EntryPoint from './EntryPoint.js'
4
+
5
+ /** User Operation Gas type. */
6
+ export type UserOperationGas<
7
+ entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
8
+ bigintType = bigint,
9
+ > = OneOf<
10
+ | (entryPointVersion extends '0.6' ? V06<bigintType> : never)
11
+ | (entryPointVersion extends '0.7' ? V07<bigintType> : never)
12
+ >
13
+
14
+ /** RPC User Operation Gas on EntryPoint 0.6 */
15
+ export type Rpc<
16
+ entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
17
+ > = UserOperationGas<entryPointVersion, Hex.Hex>
18
+
19
+ /** Type for User Operation Gas on EntryPoint 0.6 */
20
+ export type V06<bigintType = bigint> = {
21
+ callGasLimit: bigintType
22
+ preVerificationGas: bigintType
23
+ verificationGasLimit: bigintType
24
+ }
25
+
26
+ /** RPC User Operation Gas on EntryPoint 0.6 */
27
+ export type RpcV06 = V06<Hex.Hex>
28
+
29
+ /** Type for User Operation Gas on EntryPoint 0.7 */
30
+ export type V07<bigintType = bigint> = {
31
+ callGasLimit: bigintType
32
+ paymasterVerificationGasLimit?: bigintType | undefined
33
+ paymasterPostOpGasLimit?: bigintType | undefined
34
+ preVerificationGas: bigintType
35
+ verificationGasLimit: bigintType
36
+ }
37
+
38
+ /** RPC User Operation Gas on EntryPoint 0.7 */
39
+ export type RpcV07 = V07<Hex.Hex>
40
+
41
+ /**
42
+ * Converts an {@link ox#UserOperationGas.Rpc} to an {@link ox#UserOperationGas.UserOperationGas}.
43
+ *
44
+ * @example
45
+ * ```ts twoslash
46
+ * import { UserOperationGas } from 'ox/erc4337'
47
+ *
48
+ * const userOperationGas = UserOperationGas.fromRpc({
49
+ * callGasLimit: '0x69420',
50
+ * preVerificationGas: '0x69420',
51
+ * verificationGasLimit: '0x69420',
52
+ * })
53
+ * ```
54
+ *
55
+ * @param rpc - The RPC user operation gas to convert.
56
+ * @returns An instantiated {@link ox#UserOperationGas.UserOperationGas}.
57
+ */
58
+ export function fromRpc(rpc: Rpc): UserOperationGas {
59
+ return {
60
+ ...rpc,
61
+ callGasLimit: BigInt(rpc.callGasLimit),
62
+ preVerificationGas: BigInt(rpc.preVerificationGas),
63
+ verificationGasLimit: BigInt(rpc.verificationGasLimit),
64
+ ...(rpc.paymasterVerificationGasLimit && {
65
+ paymasterVerificationGasLimit: BigInt(rpc.paymasterVerificationGasLimit),
66
+ }),
67
+ ...(rpc.paymasterPostOpGasLimit && {
68
+ paymasterPostOpGasLimit: BigInt(rpc.paymasterPostOpGasLimit),
69
+ }),
70
+ } as UserOperationGas
71
+ }
72
+
73
+ /**
74
+ * Converts a {@link ox#UserOperationGas.UserOperationGas} to a {@link ox#UserOperationGas.Rpc}.
75
+ *
76
+ * @example
77
+ * ```ts twoslash
78
+ * import { UserOperationGas } from 'ox/erc4337'
79
+ *
80
+ * const userOperationGas = UserOperationGas.toRpc({
81
+ * callGasLimit: 300_000n,
82
+ * preVerificationGas: 100_000n,
83
+ * verificationGasLimit: 100_000n,
84
+ * })
85
+ * ```
86
+ *
87
+ * @param userOperationGas - The user operation gas to convert.
88
+ * @returns An RPC-formatted user operation gas.
89
+ */
90
+ export function toRpc(userOperationGas: UserOperationGas): Rpc {
91
+ const rpc = {} as Rpc
92
+
93
+ rpc.callGasLimit = Hex.fromNumber(userOperationGas.callGasLimit)
94
+ rpc.preVerificationGas = Hex.fromNumber(userOperationGas.preVerificationGas)
95
+ rpc.verificationGasLimit = Hex.fromNumber(
96
+ userOperationGas.verificationGasLimit,
97
+ )
98
+
99
+ if (typeof userOperationGas.paymasterVerificationGasLimit === 'bigint')
100
+ rpc.paymasterVerificationGasLimit = Hex.fromNumber(
101
+ userOperationGas.paymasterVerificationGasLimit,
102
+ )
103
+ if (typeof userOperationGas.paymasterPostOpGasLimit === 'bigint')
104
+ rpc.paymasterPostOpGasLimit = Hex.fromNumber(
105
+ userOperationGas.paymasterPostOpGasLimit,
106
+ )
107
+
108
+ return rpc
109
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc4337/UserOperationReceipt.d.ts",
4
+ "main": "../../_cjs/erc4337/UserOperationReceipt.js",
5
+ "module": "../../_esm/erc4337/UserOperationReceipt.js"
6
+ }
@@ -0,0 +1,139 @@
1
+ import type * as Address from '../core/Address.js'
2
+ import * as Hex from '../core/Hex.js'
3
+ import * as Log from '../core/Log.js'
4
+ import * as TransactionReceipt from '../core/TransactionReceipt.js'
5
+ import type * as EntryPoint from './EntryPoint.js'
6
+
7
+ /**
8
+ * User Operation Receipt type.
9
+ *
10
+ * @see https://eips.ethereum.org/EIPS/eip-4337#-eth_getuseroperationreceipt
11
+ */
12
+ export type UserOperationReceipt<
13
+ _entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
14
+ bigIntType = bigint,
15
+ intType = number,
16
+ receipt = TransactionReceipt.TransactionReceipt<
17
+ TransactionReceipt.Status,
18
+ TransactionReceipt.Type,
19
+ bigIntType,
20
+ intType
21
+ >,
22
+ > = {
23
+ /** Actual gas cost. */
24
+ actualGasCost: bigIntType
25
+ /** Actual gas used. */
26
+ actualGasUsed: bigIntType
27
+ /** Entrypoint address. */
28
+ entryPoint: Address.Address
29
+ /** Logs emitted during execution. */
30
+ logs: Log.Log<false, bigIntType, intType>[]
31
+ /** Anti-replay parameter. */
32
+ nonce: bigIntType
33
+ /** Paymaster for the user operation. */
34
+ paymaster?: Address.Address | undefined
35
+ /** Revert reason, if unsuccessful. */
36
+ reason?: string | undefined
37
+ /** Transaction receipt of the user operation execution. */
38
+ receipt: receipt
39
+ /** The account sending the user operation. */
40
+ sender: Address.Address
41
+ /** If the user operation execution was successful. */
42
+ success: boolean
43
+ /** Hash of the user operation. */
44
+ userOpHash: Hex.Hex
45
+ }
46
+
47
+ /** RPC User Operation Receipt on EntryPoint 0.6 */
48
+ export type Rpc<
49
+ entryPointVersion extends EntryPoint.Version = EntryPoint.Version,
50
+ > = UserOperationReceipt<
51
+ entryPointVersion,
52
+ Hex.Hex,
53
+ Hex.Hex,
54
+ TransactionReceipt.TransactionReceipt<
55
+ TransactionReceipt.RpcStatus,
56
+ TransactionReceipt.RpcType,
57
+ Hex.Hex,
58
+ Hex.Hex
59
+ >
60
+ >
61
+
62
+ /**
63
+ * Converts an {@link ox#UserOperationReceipt.Rpc} to an {@link ox#UserOperationReceipt.UserOperationReceipt}.
64
+ *
65
+ * @example
66
+ * ```ts twoslash
67
+ * // @noErrors
68
+ * import { UserOperationReceipt } from 'ox/erc4337'
69
+ *
70
+ * const userOperationReceipt = UserOperationReceipt.fromRpc({
71
+ * actualGasCost: '0x1',
72
+ * actualGasUsed: '0x2',
73
+ * entryPoint: '0x0000000071727de22e5e9d8baf0edac6f37da032',
74
+ * logs: [],
75
+ * nonce: '0x1',
76
+ * receipt: { ... },
77
+ * sender: '0xE911628bF8428C23f179a07b081325cAe376DE1f',
78
+ * success: true,
79
+ * userOpHash: '0x5ab163e9b2f30549274c7c567ca0696edf9ef1aa476d9784d22974468fdb24d8',
80
+ * })
81
+ * ```
82
+ *
83
+ * @param rpc - The RPC user operation receipt to convert.
84
+ * @returns An instantiated {@link ox#UserOperationReceipt.UserOperationReceipt}.
85
+ */
86
+ export function fromRpc(rpc: Rpc): UserOperationReceipt {
87
+ return {
88
+ ...rpc,
89
+ actualGasCost: BigInt(rpc.actualGasCost),
90
+ actualGasUsed: BigInt(rpc.actualGasUsed),
91
+ logs: rpc.logs.map((log) => Log.fromRpc(log)),
92
+ nonce: BigInt(rpc.nonce),
93
+ receipt: TransactionReceipt.fromRpc(rpc.receipt),
94
+ } as UserOperationReceipt
95
+ }
96
+
97
+ /**
98
+ * Converts a {@link ox#UserOperationReceipt.UserOperationReceipt} to a {@link ox#UserOperationReceipt.Rpc}.
99
+ *
100
+ * @example
101
+ * ```ts twoslash
102
+ * // @noErrors
103
+ * import { UserOperationReceipt } from 'ox/erc4337'
104
+ *
105
+ * const userOperationReceipt = UserOperationReceipt.toRpc({
106
+ * actualGasCost: 1n,
107
+ * actualGasUsed: 2n,
108
+ * entryPoint: '0x0000000071727de22e5e9d8baf0edac6f37da032',
109
+ * logs: [],
110
+ * nonce: 1n,
111
+ * receipt: { ... },
112
+ * sender: '0xE911628bF8428C23f179a07b081325cAe376DE1f',
113
+ * success: true,
114
+ * userOpHash: '0x5ab163e9b2f30549274c7c567ca0696edf9ef1aa476d9784d22974468fdb24d8',
115
+ * })
116
+ * ```
117
+ *
118
+ * @param userOperationReceipt - The user operation receipt to convert.
119
+ * @returns An RPC-formatted user operation receipt.
120
+ */
121
+ export function toRpc(userOperationReceipt: UserOperationReceipt): Rpc {
122
+ const rpc = {} as Rpc
123
+
124
+ rpc.actualGasCost = Hex.fromNumber(userOperationReceipt.actualGasCost)
125
+ rpc.actualGasUsed = Hex.fromNumber(userOperationReceipt.actualGasUsed)
126
+ rpc.entryPoint = userOperationReceipt.entryPoint
127
+ rpc.logs = userOperationReceipt.logs.map((log) => Log.toRpc(log))
128
+ rpc.nonce = Hex.fromNumber(userOperationReceipt.nonce)
129
+ rpc.receipt = TransactionReceipt.toRpc(userOperationReceipt.receipt)
130
+ rpc.sender = userOperationReceipt.sender
131
+ rpc.success = userOperationReceipt.success
132
+ rpc.userOpHash = userOperationReceipt.userOpHash
133
+
134
+ if (userOperationReceipt.paymaster)
135
+ rpc.paymaster = userOperationReceipt.paymaster
136
+ if (userOperationReceipt.reason) rpc.reason = userOperationReceipt.reason
137
+
138
+ return rpc
139
+ }
@@ -0,0 +1,38 @@
1
+ /** @entrypointCategory ERCs */
2
+ // biome-ignore lint/complexity/noUselessEmptyExport: tsdoc
3
+ export type {}
4
+
5
+ /**
6
+ * Utility functions and types for working with [ERC-4337 EntryPoints](https://eips.ethereum.org/EIPS/eip-4337).
7
+ *
8
+ * @category ERC-4337
9
+ */
10
+ export * as EntryPoint from './EntryPoint.js'
11
+
12
+ /**
13
+ * Utility types for working with ERC-4337 JSON-RPC schemas.
14
+ *
15
+ * @category ERC-4337
16
+ */
17
+ export * as RpcSchema from './RpcSchema.js'
18
+
19
+ /**
20
+ * Utility functions and types for working with [ERC-4337 User Operations](https://eips.ethereum.org/EIPS/eip-4337).
21
+ *
22
+ * @category ERC-4337
23
+ */
24
+ export * as UserOperation from './UserOperation.js'
25
+
26
+ /**
27
+ * Utility functions and types for working with [ERC-4337 User Operation Gas](https://eips.ethereum.org/EIPS/eip-4337).
28
+ *
29
+ * @category ERC-4337
30
+ */
31
+ export * as UserOperationGas from './UserOperationGas.js'
32
+
33
+ /**
34
+ * Utility functions and types for working with [ERC-4337 User Operation Receipts](https://eips.ethereum.org/EIPS/eip-4337).
35
+ *
36
+ * @category ERC-4337
37
+ */
38
+ export * as UserOperationReceipt from './UserOperationReceipt.js'
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/erc4337/index.d.ts",
4
+ "main": "../_cjs/erc4337/index.js",
5
+ "module": "../_esm/erc4337/index.js"
6
+ }
package/index.docs.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  // @ts-nocheck
2
2
  /** Used by api-extractor for docgen. https://github.com/microsoft/rushstack/issues/3557 */
3
3
  export * from './index.js'
4
+ export * from './erc4337/index.js'
4
5
  export * from './erc6492/index.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.4.3",
4
+ "version": "0.5.0",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -357,6 +357,36 @@
357
357
  "import": "./_esm/core/Withdrawal.js",
358
358
  "default": "./_cjs/core/Withdrawal.js"
359
359
  },
360
+ "./erc4337/EntryPoint": {
361
+ "types": "./_types/erc4337/EntryPoint.d.ts",
362
+ "import": "./_esm/erc4337/EntryPoint.js",
363
+ "default": "./_cjs/erc4337/EntryPoint.js"
364
+ },
365
+ "./erc4337/RpcSchema": {
366
+ "types": "./_types/erc4337/RpcSchema.d.ts",
367
+ "import": "./_esm/erc4337/RpcSchema.js",
368
+ "default": "./_cjs/erc4337/RpcSchema.js"
369
+ },
370
+ "./erc4337/UserOperation": {
371
+ "types": "./_types/erc4337/UserOperation.d.ts",
372
+ "import": "./_esm/erc4337/UserOperation.js",
373
+ "default": "./_cjs/erc4337/UserOperation.js"
374
+ },
375
+ "./erc4337/UserOperationGas": {
376
+ "types": "./_types/erc4337/UserOperationGas.d.ts",
377
+ "import": "./_esm/erc4337/UserOperationGas.js",
378
+ "default": "./_cjs/erc4337/UserOperationGas.js"
379
+ },
380
+ "./erc4337/UserOperationReceipt": {
381
+ "types": "./_types/erc4337/UserOperationReceipt.d.ts",
382
+ "import": "./_esm/erc4337/UserOperationReceipt.js",
383
+ "default": "./_cjs/erc4337/UserOperationReceipt.js"
384
+ },
385
+ "./erc4337": {
386
+ "types": "./_types/erc4337/index.d.ts",
387
+ "import": "./_esm/erc4337/index.js",
388
+ "default": "./_cjs/erc4337/index.js"
389
+ },
360
390
  "./erc6492/WrappedSignature": {
361
391
  "types": "./_types/erc6492/WrappedSignature.d.ts",
362
392
  "import": "./_esm/erc6492/WrappedSignature.js",
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.4.3'
2
+ export const version = '0.5.0'