@agenticprimitives/agent-account 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/abis.d.ts +543 -0
- package/dist/abis.d.ts.map +1 -0
- package/dist/abis.js +261 -0
- package/dist/abis.js.map +1 -0
- package/dist/bundler-client.d.ts +62 -0
- package/dist/bundler-client.d.ts.map +1 -0
- package/dist/bundler-client.js +95 -0
- package/dist/bundler-client.js.map +1 -0
- package/dist/client.d.ts +224 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +473 -0
- package/dist/client.js.map +1 -0
- package/dist/execute.d.ts +39 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +72 -0
- package/dist/execute.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/quorum.d.ts +62 -0
- package/dist/quorum.d.ts.map +1 -0
- package/dist/quorum.js +103 -0
- package/dist/quorum.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/webauthn-signature.d.ts +34 -0
- package/dist/webauthn-signature.d.ts.map +1 -0
- package/dist/webauthn-signature.js +51 -0
- package/dist/webauthn-signature.js.map +1 -0
- package/package.json +57 -0
- package/spec.md +6 -0
package/dist/abis.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// Minimal ABI fragments for the on-chain calls AgentAccountClient makes.
|
|
2
|
+
// Source of truth: packages/contracts/src/AgentAccountFactory.sol + AgentAccount.sol.
|
|
3
|
+
// Wave R0 — unified factory surface: a single `createAgentAccount` entry
|
|
4
|
+
// replaces the legacy `createPersonAgent` + `createMultiSigSmartAgent` pair.
|
|
5
|
+
// `mode` on the init params picks the shape (0=simple, 1-3=CustodyPolicy
|
|
6
|
+
// installed; mode>0 requires ≥1 trustee).
|
|
7
|
+
const initParamsTuple = {
|
|
8
|
+
name: 'params',
|
|
9
|
+
type: 'tuple',
|
|
10
|
+
components: [
|
|
11
|
+
{ name: 'mode', type: 'uint8' },
|
|
12
|
+
{ name: 'custodians', type: 'address[]' },
|
|
13
|
+
{ name: 'trustees', type: 'address[]' },
|
|
14
|
+
{ name: 'initialPasskeyCredentialIdDigest', type: 'bytes32' },
|
|
15
|
+
{ name: 'initialPasskeyX', type: 'uint256' },
|
|
16
|
+
{ name: 'initialPasskeyY', type: 'uint256' },
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
export const agentAccountFactoryAbi = [
|
|
20
|
+
// ─── Unified factory entry ────────────────────────────────────────────
|
|
21
|
+
{
|
|
22
|
+
type: 'function',
|
|
23
|
+
name: 'createAgentAccount',
|
|
24
|
+
stateMutability: 'nonpayable',
|
|
25
|
+
inputs: [
|
|
26
|
+
initParamsTuple,
|
|
27
|
+
{ name: 'timelockOverrides', type: 'uint32[7]' },
|
|
28
|
+
{ name: 'salt', type: 'uint256' },
|
|
29
|
+
],
|
|
30
|
+
outputs: [{ name: 'account', type: 'address' }],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'function',
|
|
34
|
+
name: 'getAddressForAgentAccount',
|
|
35
|
+
stateMutability: 'view',
|
|
36
|
+
inputs: [
|
|
37
|
+
initParamsTuple,
|
|
38
|
+
{ name: 'salt', type: 'uint256' },
|
|
39
|
+
],
|
|
40
|
+
outputs: [{ name: '', type: 'address' }],
|
|
41
|
+
},
|
|
42
|
+
// ─── Factory-level capability roles ──────────────────────────────────
|
|
43
|
+
{
|
|
44
|
+
type: 'function',
|
|
45
|
+
name: 'accountImplementation',
|
|
46
|
+
stateMutability: 'view',
|
|
47
|
+
inputs: [],
|
|
48
|
+
outputs: [{ name: '', type: 'address' }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'function',
|
|
52
|
+
name: 'bundlerSigner',
|
|
53
|
+
stateMutability: 'view',
|
|
54
|
+
inputs: [],
|
|
55
|
+
outputs: [{ name: '', type: 'address' }],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: 'function',
|
|
59
|
+
name: 'sessionIssuer',
|
|
60
|
+
stateMutability: 'view',
|
|
61
|
+
inputs: [],
|
|
62
|
+
outputs: [{ name: '', type: 'address' }],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'function',
|
|
66
|
+
name: 'delegationManager',
|
|
67
|
+
stateMutability: 'view',
|
|
68
|
+
inputs: [],
|
|
69
|
+
outputs: [{ name: '', type: 'address' }],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'function',
|
|
73
|
+
name: 'custodyPolicy',
|
|
74
|
+
stateMutability: 'view',
|
|
75
|
+
inputs: [],
|
|
76
|
+
outputs: [{ name: '', type: 'address' }],
|
|
77
|
+
},
|
|
78
|
+
// ─── Events ──────────────────────────────────────────────────────────
|
|
79
|
+
{
|
|
80
|
+
type: 'event',
|
|
81
|
+
name: 'AgentAccountCreated',
|
|
82
|
+
inputs: [
|
|
83
|
+
{ name: 'account', type: 'address', indexed: true },
|
|
84
|
+
{ name: 'mode', type: 'uint8', indexed: false },
|
|
85
|
+
{ name: 'nExternalCustodians', type: 'uint256', indexed: false },
|
|
86
|
+
{ name: 'withPasskey', type: 'bool', indexed: false },
|
|
87
|
+
{ name: 'salt', type: 'uint256', indexed: false },
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
export const agentAccountAbi = [
|
|
92
|
+
{
|
|
93
|
+
type: 'function',
|
|
94
|
+
name: 'isValidSignature',
|
|
95
|
+
stateMutability: 'view',
|
|
96
|
+
inputs: [
|
|
97
|
+
{ name: 'hash', type: 'bytes32' },
|
|
98
|
+
{ name: 'signature', type: 'bytes' },
|
|
99
|
+
],
|
|
100
|
+
outputs: [{ name: '', type: 'bytes4' }],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: 'function',
|
|
104
|
+
name: 'acceptSessionDelegation',
|
|
105
|
+
stateMutability: 'nonpayable',
|
|
106
|
+
inputs: [{ name: 'sessionDelegationHash', type: 'bytes32' }],
|
|
107
|
+
outputs: [],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: 'function',
|
|
111
|
+
name: 'hasAcceptedSessionDelegation',
|
|
112
|
+
stateMutability: 'view',
|
|
113
|
+
inputs: [{ name: 'sessionDelegationHash', type: 'bytes32' }],
|
|
114
|
+
outputs: [{ type: 'bool' }],
|
|
115
|
+
},
|
|
116
|
+
{ type: 'function', name: 'isCustodian', stateMutability: 'view', inputs: [{ name: 'account', type: 'address' }], outputs: [{ type: 'bool' }] },
|
|
117
|
+
{ type: 'function', name: 'custodianCount', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
118
|
+
{ type: 'function', name: 'factory', stateMutability: 'view', inputs: [], outputs: [{ type: 'address' }] },
|
|
119
|
+
{ type: 'function', name: 'delegationManager', stateMutability: 'view', inputs: [], outputs: [{ type: 'address' }] },
|
|
120
|
+
// Phase 6f.4 — passkey-direct custody surface.
|
|
121
|
+
{ type: 'function', name: 'passkeyIdentity', stateMutability: 'pure', inputs: [{ name: 'x', type: 'uint256' }, { name: 'y', type: 'uint256' }], outputs: [{ type: 'address' }] },
|
|
122
|
+
{ type: 'function', name: 'hasPasskey', stateMutability: 'view', inputs: [{ name: 'credentialIdDigest', type: 'bytes32' }], outputs: [{ type: 'bool' }] },
|
|
123
|
+
{ type: 'function', name: 'getPasskey', stateMutability: 'view', inputs: [{ name: 'credentialIdDigest', type: 'bytes32' }], outputs: [{ name: 'x', type: 'uint256' }, { name: 'y', type: 'uint256' }] },
|
|
124
|
+
{ type: 'function', name: 'passkeyCount', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
125
|
+
{ type: 'function', name: 'addPasskey', stateMutability: 'nonpayable', inputs: [{ name: 'credentialIdDigest', type: 'bytes32' }, { name: 'x', type: 'uint256' }, { name: 'y', type: 'uint256' }], outputs: [] },
|
|
126
|
+
{ type: 'function', name: 'removePasskey', stateMutability: 'nonpayable', inputs: [{ name: 'credentialIdDigest', type: 'bytes32' }], outputs: [] },
|
|
127
|
+
{ type: 'function', name: 'addCustodian', stateMutability: 'nonpayable', inputs: [{ name: 'owner', type: 'address' }], outputs: [] },
|
|
128
|
+
{ type: 'function', name: 'removeCustodian', stateMutability: 'nonpayable', inputs: [{ name: 'owner', type: 'address' }], outputs: [] },
|
|
129
|
+
// execute(target, value, data) — used to wrap arbitrary calls from the account.
|
|
130
|
+
{ type: 'function', name: 'execute', stateMutability: 'nonpayable', inputs: [{ name: 'target', type: 'address' }, { name: 'value', type: 'uint256' }, { name: 'data', type: 'bytes' }], outputs: [] },
|
|
131
|
+
// ERC-165 surface for the IAgenticPrimitivesAgentAccount marker.
|
|
132
|
+
{ type: 'function', name: 'supportsInterface', stateMutability: 'pure', inputs: [{ name: 'interfaceId', type: 'bytes4' }], outputs: [{ type: 'bool' }] },
|
|
133
|
+
{ type: 'function', name: 'isAgenticPrimitivesAgentAccount', stateMutability: 'pure', inputs: [], outputs: [{ type: 'bool' }] },
|
|
134
|
+
// Events.
|
|
135
|
+
{ type: 'event', name: 'CustodianAdded', inputs: [{ name: 'owner', type: 'address', indexed: true }] },
|
|
136
|
+
{ type: 'event', name: 'CustodianRemoved', inputs: [{ name: 'owner', type: 'address', indexed: true }] },
|
|
137
|
+
{ type: 'event', name: 'PasskeyAdded', inputs: [{ name: 'credentialIdDigest', type: 'bytes32', indexed: true }, { name: 'x', type: 'uint256', indexed: false }, { name: 'y', type: 'uint256', indexed: false }] },
|
|
138
|
+
{ type: 'event', name: 'PasskeyRemoved', inputs: [{ name: 'credentialIdDigest', type: 'bytes32', indexed: true }] },
|
|
139
|
+
];
|
|
140
|
+
// custodyPolicyAbi was relocated to `@agenticprimitives/account-custody` per
|
|
141
|
+
// spec 213 § 2.6 (phase 6g.3). Source of truth lives there now.
|
|
142
|
+
/**
|
|
143
|
+
* ApprovedHashRegistry (packages/contracts/src/ApprovedHashRegistry.sol).
|
|
144
|
+
* The v=1 path companion — passkey-only or hardware-wallet signers
|
|
145
|
+
* pre-approve a hash with one tx instead of producing an off-chain
|
|
146
|
+
* ECDSA sig. `QuorumEnforcer.beforeHook` (and the
|
|
147
|
+
* `_verifyQuorum(..., guardianMode=true)` path in AgentAccount) check
|
|
148
|
+
* `isApproved(signer, hash)` for v=1 slots in the packed blob.
|
|
149
|
+
*/
|
|
150
|
+
export const approvedHashRegistryAbi = [
|
|
151
|
+
{
|
|
152
|
+
type: 'function',
|
|
153
|
+
name: 'approveHash',
|
|
154
|
+
stateMutability: 'nonpayable',
|
|
155
|
+
inputs: [{ name: 'hash', type: 'bytes32' }],
|
|
156
|
+
outputs: [],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: 'function',
|
|
160
|
+
name: 'revokeHash',
|
|
161
|
+
stateMutability: 'nonpayable',
|
|
162
|
+
inputs: [{ name: 'hash', type: 'bytes32' }],
|
|
163
|
+
outputs: [],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
type: 'function',
|
|
167
|
+
name: 'isApproved',
|
|
168
|
+
stateMutability: 'view',
|
|
169
|
+
inputs: [
|
|
170
|
+
{ name: 'signer', type: 'address' },
|
|
171
|
+
{ name: 'hash', type: 'bytes32' },
|
|
172
|
+
],
|
|
173
|
+
outputs: [{ type: 'bool' }],
|
|
174
|
+
},
|
|
175
|
+
];
|
|
176
|
+
/** ERC-1271 magic value returned by isValidSignature on success. */
|
|
177
|
+
export const ERC1271_MAGIC_VALUE = '0x1626ba7e';
|
|
178
|
+
/**
|
|
179
|
+
* Minimal EntryPoint ABI for our bundler client + UserOp hashing.
|
|
180
|
+
* Source: account-abstraction/contracts/core/EntryPoint.sol (v0.9).
|
|
181
|
+
*/
|
|
182
|
+
export const entryPointAbi = [
|
|
183
|
+
{
|
|
184
|
+
type: 'function',
|
|
185
|
+
name: 'getUserOpHash',
|
|
186
|
+
stateMutability: 'view',
|
|
187
|
+
inputs: [
|
|
188
|
+
{
|
|
189
|
+
name: 'userOp',
|
|
190
|
+
type: 'tuple',
|
|
191
|
+
components: [
|
|
192
|
+
{ name: 'sender', type: 'address' },
|
|
193
|
+
{ name: 'nonce', type: 'uint256' },
|
|
194
|
+
{ name: 'initCode', type: 'bytes' },
|
|
195
|
+
{ name: 'callData', type: 'bytes' },
|
|
196
|
+
{ name: 'accountGasLimits', type: 'bytes32' },
|
|
197
|
+
{ name: 'preVerificationGas', type: 'uint256' },
|
|
198
|
+
{ name: 'gasFees', type: 'bytes32' },
|
|
199
|
+
{ name: 'paymasterAndData', type: 'bytes' },
|
|
200
|
+
{ name: 'signature', type: 'bytes' },
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
outputs: [{ name: '', type: 'bytes32' }],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
type: 'function',
|
|
208
|
+
name: 'handleOps',
|
|
209
|
+
stateMutability: 'nonpayable',
|
|
210
|
+
inputs: [
|
|
211
|
+
{
|
|
212
|
+
name: 'ops',
|
|
213
|
+
type: 'tuple[]',
|
|
214
|
+
components: [
|
|
215
|
+
{ name: 'sender', type: 'address' },
|
|
216
|
+
{ name: 'nonce', type: 'uint256' },
|
|
217
|
+
{ name: 'initCode', type: 'bytes' },
|
|
218
|
+
{ name: 'callData', type: 'bytes' },
|
|
219
|
+
{ name: 'accountGasLimits', type: 'bytes32' },
|
|
220
|
+
{ name: 'preVerificationGas', type: 'uint256' },
|
|
221
|
+
{ name: 'gasFees', type: 'bytes32' },
|
|
222
|
+
{ name: 'paymasterAndData', type: 'bytes' },
|
|
223
|
+
{ name: 'signature', type: 'bytes' },
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
{ name: 'beneficiary', type: 'address' },
|
|
227
|
+
],
|
|
228
|
+
outputs: [],
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
type: 'function',
|
|
232
|
+
name: 'getNonce',
|
|
233
|
+
stateMutability: 'view',
|
|
234
|
+
inputs: [
|
|
235
|
+
{ name: 'sender', type: 'address' },
|
|
236
|
+
{ name: 'key', type: 'uint192' },
|
|
237
|
+
],
|
|
238
|
+
outputs: [{ name: 'nonce', type: 'uint256' }],
|
|
239
|
+
},
|
|
240
|
+
// EntryPoint custom errors — declaring them lets viem decode the
|
|
241
|
+
// revert (e.g. "AA24 signature error", "AA13 initCode failed or OOG")
|
|
242
|
+
// when handleOps reverts during simulation or execution.
|
|
243
|
+
{
|
|
244
|
+
type: 'error',
|
|
245
|
+
name: 'FailedOp',
|
|
246
|
+
inputs: [
|
|
247
|
+
{ name: 'opIndex', type: 'uint256' },
|
|
248
|
+
{ name: 'reason', type: 'string' },
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
type: 'error',
|
|
253
|
+
name: 'FailedOpWithRevert',
|
|
254
|
+
inputs: [
|
|
255
|
+
{ name: 'opIndex', type: 'uint256' },
|
|
256
|
+
{ name: 'reason', type: 'string' },
|
|
257
|
+
{ name: 'inner', type: 'bytes' },
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
];
|
|
261
|
+
//# sourceMappingURL=abis.js.map
|
package/dist/abis.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abis.js","sourceRoot":"","sources":["../src/abis.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,sFAAsF;AACtF,yEAAyE;AACzE,6EAA6E;AAC7E,yEAAyE;AACzE,0CAA0C;AAE1C,MAAM,eAAe,GAAG;IACtB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,OAAO;IACb,UAAU,EAAE;QACV,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE;QAC/B,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE;QACzC,EAAE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AE;oBAC3C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE;iBACrC;aACF;YACD,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE;SACzC;QACD,OAAO,EAAE,EAAE;KACZ;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;YACnC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE;SACjC;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KAC9C;IACD,iEAAiE;IACjE,sEAAsE;IACtE,yDAAyD;IACzD;QACE,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACpC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;SACnC;KACF;IACD;QACE,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,oBAAoB;QAC1B,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACpC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;YAClC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;SACjC;KACF;CACO,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type Address, type Hex, type TransactionReceipt } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* PackedUserOperation (ERC-4337 v0.7+). Each "packed" field is two
|
|
4
|
+
* uint128s packed into a bytes32:
|
|
5
|
+
* accountGasLimits = (verificationGasLimit << 128) | callGasLimit
|
|
6
|
+
* gasFees = (maxPriorityFeePerGas << 128) | maxFeePerGas
|
|
7
|
+
*/
|
|
8
|
+
export interface PackedUserOperation {
|
|
9
|
+
sender: Address;
|
|
10
|
+
nonce: bigint;
|
|
11
|
+
initCode: Hex;
|
|
12
|
+
callData: Hex;
|
|
13
|
+
accountGasLimits: Hex;
|
|
14
|
+
preVerificationGas: bigint;
|
|
15
|
+
gasFees: Hex;
|
|
16
|
+
paymasterAndData: Hex;
|
|
17
|
+
signature: Hex;
|
|
18
|
+
}
|
|
19
|
+
export interface BundlerClientOpts {
|
|
20
|
+
rpcUrl: string;
|
|
21
|
+
entryPoint: Address;
|
|
22
|
+
}
|
|
23
|
+
/** Pack two uint128s into a single bytes32. high << 128 | low. */
|
|
24
|
+
export declare function packGasLimits(high: bigint, low: bigint): Hex;
|
|
25
|
+
/** Unpack a bytes32 (high << 128 | low) into [high, low]. */
|
|
26
|
+
export declare function unpackGasLimits(packed: Hex): {
|
|
27
|
+
high: bigint;
|
|
28
|
+
low: bigint;
|
|
29
|
+
};
|
|
30
|
+
export declare class BundlerClient {
|
|
31
|
+
private readonly publicClient;
|
|
32
|
+
private readonly opts;
|
|
33
|
+
constructor(opts: BundlerClientOpts);
|
|
34
|
+
/**
|
|
35
|
+
* Ask the EntryPoint for the canonical hash of a (still-unsigned)
|
|
36
|
+
* UserOp. The smart account validates against THIS hash in its
|
|
37
|
+
* validateUserOp. Use this to get the hash for the user to sign.
|
|
38
|
+
*/
|
|
39
|
+
getUserOpHash(userOp: PackedUserOperation): Promise<Hex>;
|
|
40
|
+
/**
|
|
41
|
+
* EntryPoint.getNonce(sender, key). Returns the next-valid nonce for
|
|
42
|
+
* (sender, key). For first deploys, sender doesn't exist yet so the
|
|
43
|
+
* EntryPoint's internal counter starts at 0 — we can hardcode nonce=0
|
|
44
|
+
* for deploy UserOps and skip the RPC call. But for subsequent ops,
|
|
45
|
+
* call this.
|
|
46
|
+
*/
|
|
47
|
+
getNonce(sender: Address, key?: bigint): Promise<bigint>;
|
|
48
|
+
/**
|
|
49
|
+
* Submit a batch of UserOps via EntryPoint.handleOps. The `viemAccount`
|
|
50
|
+
* pays gas (will be reimbursed by the paymaster if one is set in
|
|
51
|
+
* paymasterAndData) and broadcasts the tx.
|
|
52
|
+
*
|
|
53
|
+
* @param userOps The signed UserOps to bundle.
|
|
54
|
+
* @param beneficiary Address receiving the bundler reward (typically
|
|
55
|
+
* the same as the viem account's address).
|
|
56
|
+
* @param viemAccount Any viem-compatible account — in production this
|
|
57
|
+
* is `createKmsViemAccount(kmsBackend)` so signing
|
|
58
|
+
* is HSM-backed and no private key is held locally.
|
|
59
|
+
*/
|
|
60
|
+
sendUserOps(userOps: PackedUserOperation[], beneficiary: Address, viemAccount: any): Promise<TransactionReceipt>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=bundler-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler-client.d.ts","sourceRoot":"","sources":["../src/bundler-client.ts"],"names":[],"mappings":"AAcA,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,GAAG,EAER,KAAK,kBAAkB,EACxB,MAAM,MAAM,CAAC;AAGd;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;IACd,gBAAgB,EAAE,GAAG,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,GAAG,CAAC;IACb,gBAAgB,EAAE,GAAG,CAAC;IACtB,SAAS,EAAE,GAAG,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAK5D;AAED,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAG1E;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;gBAE7B,IAAI,EAAE,iBAAiB;IAKnC;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC;IAS9D;;;;;;OAMG;IACG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IASlE;;;;;;;;;;;OAWG;IACG,WAAW,CACf,OAAO,EAAE,mBAAmB,EAAE,EAC9B,WAAW,EAAE,OAAO,EAEpB,WAAW,EAAE,GAAG,GACf,OAAO,CAAC,kBAAkB,CAAC;CAe/B"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// bundler-client — submit ERC-4337 v0.9 UserOps directly to our own
|
|
2
|
+
// deployed EntryPoint via handleOps. We are the bundler.
|
|
3
|
+
//
|
|
4
|
+
// Why this exists: public bundlers (Pimlico, Stackup, Alchemy AA) only
|
|
5
|
+
// support canonical EntryPoint addresses. We deployed our OWN EntryPoint
|
|
6
|
+
// (v0.9 from eth-infinitism's lib) so we can stay on the latest spec
|
|
7
|
+
// without waiting for SaaS support. The trade-off: we operate the
|
|
8
|
+
// bundler ourselves — a single transaction calling handleOps([userOp])
|
|
9
|
+
// per submission. KMS-signs the handleOps tx (via createKmsViemAccount).
|
|
10
|
+
//
|
|
11
|
+
// The paymaster contract (SmartAgentPaymaster) sponsors gas at the
|
|
12
|
+
// EntryPoint layer, so users never need ETH and our bundler EOA only
|
|
13
|
+
// pays gas it gets reimbursed for (paymaster.deposit → EntryPoint → us).
|
|
14
|
+
import { createPublicClient, createWalletClient, http, } from 'viem';
|
|
15
|
+
import { entryPointAbi } from './abis';
|
|
16
|
+
/** Pack two uint128s into a single bytes32. high << 128 | low. */
|
|
17
|
+
export function packGasLimits(high, low) {
|
|
18
|
+
if (high < 0n || high >= 1n << 128n)
|
|
19
|
+
throw new Error(`packGasLimits: high out of uint128 range`);
|
|
20
|
+
if (low < 0n || low >= 1n << 128n)
|
|
21
|
+
throw new Error(`packGasLimits: low out of uint128 range`);
|
|
22
|
+
const combined = (high << 128n) | low;
|
|
23
|
+
return ('0x' + combined.toString(16).padStart(64, '0'));
|
|
24
|
+
}
|
|
25
|
+
/** Unpack a bytes32 (high << 128 | low) into [high, low]. */
|
|
26
|
+
export function unpackGasLimits(packed) {
|
|
27
|
+
const v = BigInt(packed);
|
|
28
|
+
return { high: v >> 128n, low: v & ((1n << 128n) - 1n) };
|
|
29
|
+
}
|
|
30
|
+
export class BundlerClient {
|
|
31
|
+
publicClient;
|
|
32
|
+
opts;
|
|
33
|
+
constructor(opts) {
|
|
34
|
+
this.opts = opts;
|
|
35
|
+
this.publicClient = createPublicClient({ transport: http(opts.rpcUrl) });
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Ask the EntryPoint for the canonical hash of a (still-unsigned)
|
|
39
|
+
* UserOp. The smart account validates against THIS hash in its
|
|
40
|
+
* validateUserOp. Use this to get the hash for the user to sign.
|
|
41
|
+
*/
|
|
42
|
+
async getUserOpHash(userOp) {
|
|
43
|
+
return (await this.publicClient.readContract({
|
|
44
|
+
address: this.opts.entryPoint,
|
|
45
|
+
abi: entryPointAbi,
|
|
46
|
+
functionName: 'getUserOpHash',
|
|
47
|
+
args: [userOp],
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* EntryPoint.getNonce(sender, key). Returns the next-valid nonce for
|
|
52
|
+
* (sender, key). For first deploys, sender doesn't exist yet so the
|
|
53
|
+
* EntryPoint's internal counter starts at 0 — we can hardcode nonce=0
|
|
54
|
+
* for deploy UserOps and skip the RPC call. But for subsequent ops,
|
|
55
|
+
* call this.
|
|
56
|
+
*/
|
|
57
|
+
async getNonce(sender, key = 0n) {
|
|
58
|
+
return (await this.publicClient.readContract({
|
|
59
|
+
address: this.opts.entryPoint,
|
|
60
|
+
abi: entryPointAbi,
|
|
61
|
+
functionName: 'getNonce',
|
|
62
|
+
args: [sender, key],
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Submit a batch of UserOps via EntryPoint.handleOps. The `viemAccount`
|
|
67
|
+
* pays gas (will be reimbursed by the paymaster if one is set in
|
|
68
|
+
* paymasterAndData) and broadcasts the tx.
|
|
69
|
+
*
|
|
70
|
+
* @param userOps The signed UserOps to bundle.
|
|
71
|
+
* @param beneficiary Address receiving the bundler reward (typically
|
|
72
|
+
* the same as the viem account's address).
|
|
73
|
+
* @param viemAccount Any viem-compatible account — in production this
|
|
74
|
+
* is `createKmsViemAccount(kmsBackend)` so signing
|
|
75
|
+
* is HSM-backed and no private key is held locally.
|
|
76
|
+
*/
|
|
77
|
+
async sendUserOps(userOps, beneficiary,
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
viemAccount) {
|
|
80
|
+
const wallet = createWalletClient({
|
|
81
|
+
account: viemAccount,
|
|
82
|
+
transport: http(this.opts.rpcUrl),
|
|
83
|
+
});
|
|
84
|
+
const hash = await wallet.writeContract({
|
|
85
|
+
address: this.opts.entryPoint,
|
|
86
|
+
abi: entryPointAbi,
|
|
87
|
+
functionName: 'handleOps',
|
|
88
|
+
args: [userOps, beneficiary],
|
|
89
|
+
account: viemAccount,
|
|
90
|
+
chain: null,
|
|
91
|
+
});
|
|
92
|
+
return this.publicClient.waitForTransactionReceipt({ hash });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=bundler-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler-client.js","sourceRoot":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