@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.
@@ -0,0 +1,224 @@
1
+ import { type Address, type Hex, type TransactionReceipt } from 'viem';
2
+ import type { Signer } from '@agenticprimitives/connect-auth';
3
+ import { type PackedUserOperation } from './bundler-client';
4
+ export interface AgentAccountClientOpts {
5
+ rpcUrl: string;
6
+ chainId: number;
7
+ entryPoint: Address;
8
+ factory: Address;
9
+ }
10
+ /**
11
+ * Wave R0 — unified AgentAccount specification. Mirrors the factory's
12
+ * `AgentAccountInitParams` struct + the salt + the optional T4
13
+ * safetyDelay override.
14
+ *
15
+ * - `mode = 0` → simple (no CustodyPolicy installed; trustees ignored)
16
+ * - `mode = 1` → hybrid (CustodyPolicy installed; ≥1 trustee required)
17
+ * - `mode = 2` → threshold (CustodyPolicy installed; ≥2 trustees required)
18
+ * - `mode = 3` → org (CustodyPolicy installed; ≥3 trustees required)
19
+ *
20
+ * At least one signer (non-empty `custodians` OR non-zero `passkey`) is
21
+ * required. Defaults: mode=0, custodians=[], trustees=[],
22
+ * timelockOverrides=[] (factory uses spec defaults T4=1h / T5=24h / T6=48h).
23
+ */
24
+ export interface AgentAccountSpec {
25
+ mode?: number;
26
+ custodians?: readonly Address[];
27
+ trustees?: readonly Address[];
28
+ passkey?: {
29
+ credentialIdDigest: Hex;
30
+ x: bigint;
31
+ y: bigint;
32
+ };
33
+ salt: bigint;
34
+ /**
35
+ * Per-tier timelock override array (index 0 unused; tier t uses index
36
+ * t for t in 1..6). Where the override is 0 the factory falls back to
37
+ * the spec default per tier (T4=1h / T5=24h / T6=48h). Omit entirely
38
+ * for production deploys; demos can shorten any tier independently.
39
+ */
40
+ timelockOverrides?: readonly number[];
41
+ }
42
+ export declare class AgentAccountClient {
43
+ private readonly publicClient;
44
+ private readonly opts;
45
+ constructor(opts: AgentAccountClientOpts);
46
+ /**
47
+ * Deterministic CREATE2 address for any AgentAccount (any mode). Delegates
48
+ * to the factory's view so TS + Solidity stay in lock-step.
49
+ */
50
+ getAddressForAgentAccount(spec: AgentAccountSpec): Promise<Address>;
51
+ /**
52
+ * Deploy an AgentAccount via the factory using a raw bootstrap private key.
53
+ * Idempotent — skips the tx if the predicted address already has code.
54
+ * Prefer `createAgentAccountFromAccount` with a KMS-backed viem account
55
+ * in production (no private-key material in process memory).
56
+ */
57
+ createAgentAccountFromPrivateKey(spec: AgentAccountSpec, bootstrapPrivateKey: Hex): Promise<Address>;
58
+ /**
59
+ * Deploy an AgentAccount via the factory using any viem-compatible account.
60
+ * The signer pays gas; the deployed account is custodian-of-spec, not
61
+ * custodian-of-relayer. Idempotent.
62
+ */
63
+ createAgentAccountFromAccount(spec: AgentAccountSpec, account: any): Promise<Address>;
64
+ /**
65
+ * On-chain `isCustodian(addr)` query against a deployed AgentAccount.
66
+ * Returns the unified view (external custodians + passkey PIAs). Returns
67
+ * false if the account isn't deployed yet.
68
+ */
69
+ isCustodian(account: Address, address: Address): Promise<boolean>;
70
+ /**
71
+ * On-chain `hasPasskey(credentialIdDigest)` — is this passkey CURRENTLY a
72
+ * registered credential of the account? (Passkeys are tracked by digest, not as
73
+ * an EOA custodian.) Returns false if the account isn't deployed yet.
74
+ */
75
+ hasPasskey(account: Address, credentialIdDigest: Hex): Promise<boolean>;
76
+ /** On-chain count of EOA custodians (0 if not deployed). Lets a caller tell whether
77
+ * an account has wallet/EOA custody. */
78
+ custodianCount(account: Address): Promise<bigint>;
79
+ /** On-chain count of registered passkeys (0 if not deployed). Lets a caller tell
80
+ * whether an account has passkey custody. */
81
+ passkeyCount(account: Address): Promise<bigint>;
82
+ isDeployed(account: Address): Promise<boolean>;
83
+ /**
84
+ * Produce an ERC-1271-compatible signature: signer.signMessage of `hash`
85
+ * (as raw bytes). The deployed account's isValidSignature then validates
86
+ * by re-deriving EIP-191 digest and checking ownership.
87
+ */
88
+ signWithErc1271(account: Address, hash: Hex, signer: Signer): Promise<Hex>;
89
+ /**
90
+ * Verify a signature against a deployed account via on-chain ERC-1271 call.
91
+ * Returns true iff `isValidSignature` returns the magic value 0x1626ba7e.
92
+ */
93
+ isValidSignature(account: Address, hash: Hex, signature: Hex): Promise<boolean>;
94
+ /**
95
+ * Build an unsigned UserOp targeting an ALREADY-DEPLOYED AgentAccount.
96
+ * Counterpart to `buildDeployUserOpForAgentAccount` (which deploys the
97
+ * account); this is for calls AFTER deploy: addCustodian, addPasskey,
98
+ * validator.proposeAdmin, arbitrary execute(target, value, data), etc.
99
+ *
100
+ * @param opts.sender Existing AgentAccount address.
101
+ * @param opts.callData Calldata for the account's execute path. Typically
102
+ * built via viem's encodeFunctionData against
103
+ * agentAccountAbi.execute or the account's own
104
+ * per-action selectors.
105
+ * @param opts.paymaster Paymaster address (sponsors gas).
106
+ * @param opts.verifyingPaymaster When set, appends the EIP-191 paymaster
107
+ * signature to paymasterAndData (audit C2 mode).
108
+ *
109
+ * Returns { userOp, userOpHash, sender } — same shape as buildDeployUserOp.
110
+ * The caller signs userOpHash with their owner authority (EOA, passkey,
111
+ * or ERC-1271 contract sig) + drops the sig into userOp.signature, then
112
+ * passes the result to submitCallUserOp.
113
+ */
114
+ buildCallUserOp(opts: {
115
+ sender: Address;
116
+ callData: Hex;
117
+ paymaster: Address;
118
+ verificationGasLimit?: bigint;
119
+ callGasLimit?: bigint;
120
+ preVerificationGas?: bigint;
121
+ paymasterVerificationGasLimit?: bigint;
122
+ verifyingPaymaster?: {
123
+ signFn: (hash: Hex) => Promise<Hex>;
124
+ validUntilSeconds?: number;
125
+ validAfterSeconds?: number;
126
+ };
127
+ }): Promise<{
128
+ userOp: PackedUserOperation;
129
+ userOpHash: Hex;
130
+ sender: Address;
131
+ }>;
132
+ /**
133
+ * Backwards-compatible alias preserving the spec 201 `buildUserOp` shape.
134
+ * Wraps `buildCallUserOp` for single-call userOps. Multi-call (`account.executeBatch`)
135
+ * is the consumer's responsibility — encode the batch as callData and pass it in.
136
+ */
137
+ buildUserOp(params: {
138
+ account: Address;
139
+ calls: Array<{
140
+ to: Address;
141
+ data: Hex;
142
+ value: bigint;
143
+ }>;
144
+ paymaster: Address;
145
+ verifyingPaymaster?: {
146
+ signFn: (hash: Hex) => Promise<Hex>;
147
+ validUntilSeconds?: number;
148
+ validAfterSeconds?: number;
149
+ };
150
+ }): Promise<{
151
+ userOp: PackedUserOperation;
152
+ userOpHash: Hex;
153
+ sender: Address;
154
+ }>;
155
+ /**
156
+ * Compute the canonical hash a verifying-paymaster signer must sign
157
+ * (audit C2). Matches `SmartAgentPaymaster.getHash(...)` on-chain.
158
+ * Returns the raw keccak256 — callers wrap with EIP-191 ("\\x19Ethereum
159
+ * Signed Message:\\n32" prefix) before signing, which is what
160
+ * `signMessage({ raw })` does by convention on the viem side.
161
+ */
162
+ static computeVerifyingPaymasterHash(args: {
163
+ userOp: Pick<PackedUserOperation, 'sender' | 'nonce' | 'initCode' | 'callData' | 'accountGasLimits' | 'preVerificationGas' | 'gasFees'>;
164
+ paymaster: Address;
165
+ chainId: number;
166
+ validUntil: number;
167
+ validAfter: number;
168
+ }): Hex;
169
+ /**
170
+ * Build an UNSIGNED ERC-4337 v0.9 UserOperation that deploys an
171
+ * AgentAccount via `factory.createAgentAccount(...)`. Works for any
172
+ * mode and signer shape — the signature on `userOpHash` uses whatever
173
+ * owner authority the resulting account will accept.
174
+ *
175
+ * Paymaster sponsorship: `paymasterAndData` is set to the configured
176
+ * paymaster. Pass `verifyingPaymaster.signFn` to opt into audit C2's
177
+ * verifying-paymaster signed-attestation mode.
178
+ *
179
+ * Gas defaults are sized for the worst-case validateUserOp path: a
180
+ * WebAuthn passkey-init account verified by Daimo's pure-Solidity P-256
181
+ * fallback (~350-400k) plus ERC1967Proxy deploy + storage writes
182
+ * (~300k) + (for mode>0) the CustodyPolicy install (~250k). Override via
183
+ * `verificationGasLimit` for cheaper paths.
184
+ */
185
+ buildDeployUserOpForAgentAccount(opts: {
186
+ spec: AgentAccountSpec;
187
+ paymaster: Address;
188
+ /** Optional calldata the freshly-deployed account executes in the SAME userOp (deploy +
189
+ * execute atomically). Defaults to '0x' (deploy only). When set, `callGasLimit` covers it. */
190
+ callData?: Hex;
191
+ verificationGasLimit?: bigint;
192
+ callGasLimit?: bigint;
193
+ preVerificationGas?: bigint;
194
+ paymasterVerificationGasLimit?: bigint;
195
+ verifyingPaymaster?: {
196
+ signFn: (hash: Hex) => Promise<Hex>;
197
+ validUntilSeconds?: number;
198
+ validAfterSeconds?: number;
199
+ };
200
+ }): Promise<{
201
+ userOp: PackedUserOperation;
202
+ userOpHash: Hex;
203
+ sender: Address;
204
+ }>;
205
+ /**
206
+ * Submit a (now-signed) deploy UserOp via EntryPoint.handleOps. The
207
+ * `bundlerAccount` pays gas (will be reimbursed by the paymaster) and
208
+ * broadcasts the tx. In production this is `createKmsViemAccount(kms)`
209
+ * — no private key held locally.
210
+ */
211
+ submitDeployUserOp(userOp: PackedUserOperation, bundlerAccount: any): Promise<{
212
+ deployedAddress: Address;
213
+ receipt: TransactionReceipt;
214
+ }>;
215
+ /**
216
+ * Submit a (signed) post-deploy UserOp via EntryPoint.handleOps. Counterpart
217
+ * to `submitDeployUserOp`. The relayer (bundlerAccount) pays gas; the
218
+ * paymaster reimburses the bundler from its EntryPoint deposit.
219
+ */
220
+ submitCallUserOp(userOp: PackedUserOperation, bundlerAccount: any): Promise<{
221
+ receipt: TransactionReceipt;
222
+ }>;
223
+ }
224
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,EAQL,KAAK,OAAO,EACZ,KAAK,GAAG,EAER,KAAK,kBAAkB,EACxB,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAgC,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AA8D1F,MAAM,WAAW,sBAA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