@azeth/sdk 0.2.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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +139 -0
  3. package/dist/account/balance.d.ts +41 -0
  4. package/dist/account/balance.d.ts.map +1 -0
  5. package/dist/account/balance.js +264 -0
  6. package/dist/account/balance.js.map +1 -0
  7. package/dist/account/create.d.ts +27 -0
  8. package/dist/account/create.d.ts.map +1 -0
  9. package/dist/account/create.js +116 -0
  10. package/dist/account/create.js.map +1 -0
  11. package/dist/account/deposit.d.ts +34 -0
  12. package/dist/account/deposit.d.ts.map +1 -0
  13. package/dist/account/deposit.js +88 -0
  14. package/dist/account/deposit.js.map +1 -0
  15. package/dist/account/guardian-approval.d.ts +111 -0
  16. package/dist/account/guardian-approval.d.ts.map +1 -0
  17. package/dist/account/guardian-approval.js +223 -0
  18. package/dist/account/guardian-approval.js.map +1 -0
  19. package/dist/account/guardian.d.ts +27 -0
  20. package/dist/account/guardian.d.ts.map +1 -0
  21. package/dist/account/guardian.js +67 -0
  22. package/dist/account/guardian.js.map +1 -0
  23. package/dist/account/history.d.ts +22 -0
  24. package/dist/account/history.d.ts.map +1 -0
  25. package/dist/account/history.js +144 -0
  26. package/dist/account/history.js.map +1 -0
  27. package/dist/account/transfer.d.ts +28 -0
  28. package/dist/account/transfer.d.ts.map +1 -0
  29. package/dist/account/transfer.js +137 -0
  30. package/dist/account/transfer.js.map +1 -0
  31. package/dist/auth/erc8128.d.ts +14 -0
  32. package/dist/auth/erc8128.d.ts.map +1 -0
  33. package/dist/auth/erc8128.js +92 -0
  34. package/dist/auth/erc8128.js.map +1 -0
  35. package/dist/client.d.ts +394 -0
  36. package/dist/client.d.ts.map +1 -0
  37. package/dist/client.js +970 -0
  38. package/dist/client.js.map +1 -0
  39. package/dist/events/emitter.d.ts +96 -0
  40. package/dist/events/emitter.d.ts.map +1 -0
  41. package/dist/events/emitter.js +90 -0
  42. package/dist/events/emitter.js.map +1 -0
  43. package/dist/index.d.ts +29 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +33 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/messaging/message-router.d.ts +69 -0
  48. package/dist/messaging/message-router.d.ts.map +1 -0
  49. package/dist/messaging/message-router.js +307 -0
  50. package/dist/messaging/message-router.js.map +1 -0
  51. package/dist/messaging/rate-limiter.d.ts +31 -0
  52. package/dist/messaging/rate-limiter.d.ts.map +1 -0
  53. package/dist/messaging/rate-limiter.js +74 -0
  54. package/dist/messaging/rate-limiter.js.map +1 -0
  55. package/dist/messaging/xmtp.d.ts +144 -0
  56. package/dist/messaging/xmtp.d.ts.map +1 -0
  57. package/dist/messaging/xmtp.js +473 -0
  58. package/dist/messaging/xmtp.js.map +1 -0
  59. package/dist/payments/agreements.d.ts +87 -0
  60. package/dist/payments/agreements.d.ts.map +1 -0
  61. package/dist/payments/agreements.js +337 -0
  62. package/dist/payments/agreements.js.map +1 -0
  63. package/dist/payments/budget.d.ts +118 -0
  64. package/dist/payments/budget.d.ts.map +1 -0
  65. package/dist/payments/budget.js +176 -0
  66. package/dist/payments/budget.js.map +1 -0
  67. package/dist/payments/smart-fetch.d.ts +65 -0
  68. package/dist/payments/smart-fetch.d.ts.map +1 -0
  69. package/dist/payments/smart-fetch.js +115 -0
  70. package/dist/payments/smart-fetch.js.map +1 -0
  71. package/dist/payments/x402.d.ts +89 -0
  72. package/dist/payments/x402.d.ts.map +1 -0
  73. package/dist/payments/x402.js +620 -0
  74. package/dist/payments/x402.js.map +1 -0
  75. package/dist/registry/discover.d.ts +43 -0
  76. package/dist/registry/discover.d.ts.map +1 -0
  77. package/dist/registry/discover.js +272 -0
  78. package/dist/registry/discover.js.map +1 -0
  79. package/dist/registry/register.d.ts +44 -0
  80. package/dist/registry/register.d.ts.map +1 -0
  81. package/dist/registry/register.js +126 -0
  82. package/dist/registry/register.js.map +1 -0
  83. package/dist/reputation/opinion.d.ts +52 -0
  84. package/dist/reputation/opinion.d.ts.map +1 -0
  85. package/dist/reputation/opinion.js +198 -0
  86. package/dist/reputation/opinion.js.map +1 -0
  87. package/dist/utils/addresses.d.ts +6 -0
  88. package/dist/utils/addresses.d.ts.map +1 -0
  89. package/dist/utils/addresses.js +53 -0
  90. package/dist/utils/addresses.js.map +1 -0
  91. package/dist/utils/errors.d.ts +23 -0
  92. package/dist/utils/errors.d.ts.map +1 -0
  93. package/dist/utils/errors.js +188 -0
  94. package/dist/utils/errors.js.map +1 -0
  95. package/dist/utils/execution.d.ts +20 -0
  96. package/dist/utils/execution.d.ts.map +1 -0
  97. package/dist/utils/execution.js +28 -0
  98. package/dist/utils/execution.js.map +1 -0
  99. package/dist/utils/paymaster.d.ts +35 -0
  100. package/dist/utils/paymaster.d.ts.map +1 -0
  101. package/dist/utils/paymaster.js +115 -0
  102. package/dist/utils/paymaster.js.map +1 -0
  103. package/dist/utils/retry.d.ts +19 -0
  104. package/dist/utils/retry.d.ts.map +1 -0
  105. package/dist/utils/retry.js +68 -0
  106. package/dist/utils/retry.js.map +1 -0
  107. package/dist/utils/userop.d.ts +55 -0
  108. package/dist/utils/userop.d.ts.map +1 -0
  109. package/dist/utils/userop.js +201 -0
  110. package/dist/utils/userop.js.map +1 -0
  111. package/dist/utils/validation.d.ts +8 -0
  112. package/dist/utils/validation.d.ts.map +1 -0
  113. package/dist/utils/validation.js +35 -0
  114. package/dist/utils/validation.js.map +1 -0
  115. package/package.json +63 -0
@@ -0,0 +1,394 @@
1
+ import { type PublicClient, type Chain, type Transport } from 'viem';
2
+ import { type SupportedChainName, type AzethContractAddresses, type RegistryEntry, type DiscoveryParams, type PaymentAgreement, type MessageHandler, type OnChainOpinion, type WeightedReputation, type ActiveOpinion, type OpinionEntry, type XMTPConfig, type XMTPConversation, type XMTPMessage } from '@azeth/common';
3
+ import { type CreateAccountParams, type CreateAccountResult } from './account/create.js';
4
+ import { type BalanceResult } from './account/balance.js';
5
+ import type { AggregatedBalanceResult } from '@azeth/common';
6
+ import { type TransferParams, type TransferResult } from './account/transfer.js';
7
+ import { type HistoryParams, type TransactionRecord } from './account/history.js';
8
+ import { type DepositParams, type DepositResult } from './account/deposit.js';
9
+ import { type RegisterParams, type RegisterResult, type MetadataUpdate } from './registry/register.js';
10
+ import { type Fetch402Options, type Fetch402Result } from './payments/x402.js';
11
+ import { type SmartFetch402Options, type SmartFetch402Result } from './payments/smart-fetch.js';
12
+ import { type CreateAgreementParams, type AgreementResult } from './payments/agreements.js';
13
+ import { type SendMessageParams } from './messaging/xmtp.js';
14
+ import { AzethEventEmitter, type AzethEventName, type AzethEventListener, type AzethEventMap } from './events/emitter.js';
15
+ import { BudgetManager, type BudgetConfig } from './payments/budget.js';
16
+ import type { PaymasterPolicy } from './utils/paymaster.js';
17
+ export interface AzethKitConfig {
18
+ /** The account owner's private key */
19
+ privateKey: `0x${string}`;
20
+ /** Chain to connect to */
21
+ chain: SupportedChainName;
22
+ /** Custom RPC URL (optional) */
23
+ rpcUrl?: string;
24
+ /** Azeth server URL for indexed data and message relay */
25
+ serverUrl?: string;
26
+ /** ERC-4337 bundler URL for UserOperation submission.
27
+ * Required for state-changing smart account operations (transfers, payments, reputation).
28
+ * Resolution: explicit value > AZETH_BUNDLER_URL env > SUPPORTED_CHAINS default > error.
29
+ * Get a free key at https://dashboard.pimlico.io or https://portal.cdp.coinbase.com. */
30
+ bundlerUrl?: string;
31
+ /** ERC-4337 paymaster URL for gas sponsorship (optional).
32
+ * When provided, the paymaster will sponsor gas for UserOperations.
33
+ * Resolution: explicit value > AZETH_PAYMASTER_URL env > SUPPORTED_CHAINS default.
34
+ * When not configured, UserOps use self-paid gas (no single point of failure). */
35
+ paymasterUrl?: string;
36
+ /** Client-side sponsorship policy for paymaster gas sponsorship (optional).
37
+ * Defense-in-depth layer on top of the paymaster's server-side policies.
38
+ * Only applies when a paymaster is configured. */
39
+ paymasterPolicy?: PaymasterPolicy;
40
+ /** Override contract addresses (merged with chain defaults) */
41
+ contractAddresses?: Partial<AzethContractAddresses>;
42
+ /** XMTP messaging configuration (optional — messaging lazy-initializes on first use) */
43
+ xmtp?: XMTPConfig;
44
+ /** Budget configuration for x402 payments.
45
+ * When provided, enables reputation-aware spending limits. */
46
+ budget?: BudgetConfig;
47
+ /** Optional guardian co-signing key.
48
+ * Used to derive the guardian address for account creation and for interactive XMTP approval.
49
+ * Only auto-signs UserOperations when `guardianAutoSign` is also set to `true`.
50
+ * The address derived from this key must match the guardian set in the account's guardrails. */
51
+ guardianKey?: `0x${string}`;
52
+ /** When true AND guardianKey is set, the SDK auto-appends a guardian co-signature
53
+ * to every UserOperation, enabling operations that exceed standard spending limits.
54
+ * Must be explicitly set to `true` — defaults to `false` (guardian must confirm via XMTP). */
55
+ guardianAutoSign?: boolean;
56
+ }
57
+ /** AzethKit -- Trust Infrastructure SDK for the Machine Economy
58
+ *
59
+ * Provides Phase 0 methods for machine participants:
60
+ * - create: Deploy a smart account + trust registry entry
61
+ * - transfer: Send ETH or tokens to another participant
62
+ * - getBalance: Check account balances
63
+ * - getHistory: Get transaction history
64
+ * - fetch402: Pay for x402-gated services (with budget enforcement)
65
+ * - publishService: Register on the trust registry
66
+ * - discoverServices: Find services by capability + reputation
67
+ * - createPaymentAgreement: Set up recurring payments
68
+ * - submitOpinion: Submit reputation opinion for a service
69
+ * - getWeightedReputation: Get payment-weighted reputation for an agent
70
+ * - getNetPaid: Get net payment delta with a counterparty
71
+ * - getActiveOpinion: Check active opinion for an agent
72
+ * - sendMessage: Send XMTP encrypted messages
73
+ * - onMessage: Listen for incoming messages
74
+ * - canReach: Check if an address is reachable on XMTP
75
+ *
76
+ * Events: on('beforePayment'), on('afterPayment'), on('paymentError'),
77
+ * on('beforeTransfer'), on('afterTransfer'), on('transferError')
78
+ */
79
+ export declare class AzethKit {
80
+ readonly address: `0x${string}`;
81
+ readonly chainName: SupportedChainName;
82
+ readonly addresses: AzethContractAddresses;
83
+ readonly publicClient: PublicClient<Transport, Chain>;
84
+ private readonly walletClient;
85
+ readonly serverUrl: string;
86
+ /** All smart account addresses owned by this EOA, resolved from factory.
87
+ * null until createAccount() is called or resolveSmartAccount() resolves them. */
88
+ private _smartAccounts;
89
+ /** H-2 fix: Private key stored as Uint8Array for proper zeroing in destroy() */
90
+ private _privateKeyBytes;
91
+ /** MEDIUM-7 fix: Track destroyed state to prevent use-after-destroy.
92
+ * H-6 fix (Audit #8): All state-changing methods now check this flag. */
93
+ private _destroyed;
94
+ private readonly _xmtpConfig;
95
+ private _messaging;
96
+ private _messagingInitPromise;
97
+ /** Event emitter for lifecycle hooks */
98
+ readonly events: AzethEventEmitter;
99
+ /** Budget manager for x402 spending limits */
100
+ readonly budget: BudgetManager;
101
+ /** ERC-4337 bundler URL for UserOperation submission */
102
+ private readonly _bundlerUrl;
103
+ /** ERC-4337 paymaster URL for gas sponsorship */
104
+ private readonly _paymasterUrl;
105
+ /** Client-side paymaster sponsorship policy */
106
+ private readonly _paymasterPolicy;
107
+ /** Guardian co-signing key — used for address derivation and optional auto-signing */
108
+ private readonly _guardianKey;
109
+ /** When true, auto-append guardian co-signature to every UserOp */
110
+ private readonly _guardianAutoSign;
111
+ /** Cached SmartAccountClient instances keyed by smart account address */
112
+ private readonly _smartAccountClients;
113
+ private constructor();
114
+ /** Create an AzethKit instance from a private key
115
+ *
116
+ * This connects to the chain and sets up clients for the owner's address.
117
+ * Call publishService() to register on the trust registry if not already registered.
118
+ */
119
+ static create(config: AzethKitConfig): Promise<AzethKit>;
120
+ /** Subscribe to a lifecycle event. Returns an unsubscribe function. */
121
+ on<K extends AzethEventName>(event: K, listener: AzethEventListener<AzethEventMap[K]>): () => void;
122
+ /** Subscribe to a lifecycle event for a single firing. */
123
+ once<K extends AzethEventName>(event: K, listener: AzethEventListener<AzethEventMap[K]>): () => void;
124
+ /** H-6 fix (Audit #8): Guard all state-changing methods against use-after-destroy.
125
+ * After destroy(), the walletClient may still hold a working key copy in memory.
126
+ * This prevents accidental operations on a "destroyed" instance. */
127
+ private _requireNotDestroyed;
128
+ /** The first (default) smart account address owned by this EOA, or null if not yet resolved */
129
+ get smartAccount(): `0x${string}` | null;
130
+ /** All smart account addresses owned by this EOA, or null if not yet resolved */
131
+ get smartAccounts(): readonly `0x${string}`[] | null;
132
+ /** Resolve all smart account addresses from the on-chain factory.
133
+ * Queries factory.getAccountsByOwner(ownerAddress).
134
+ * Caches the result for subsequent calls.
135
+ *
136
+ * @returns Array of smart account addresses owned by this EOA
137
+ */
138
+ getSmartAccounts(): Promise<readonly `0x${string}`[]>;
139
+ /** Resolve the default (first) smart account address from the on-chain factory.
140
+ * Caches the result for subsequent calls.
141
+ *
142
+ * @throws AzethError if no account is found for this owner
143
+ */
144
+ resolveSmartAccount(): Promise<`0x${string}`>;
145
+ /** Deploy a new Azeth smart account via the AzethFactory v11 (one-call setup).
146
+ *
147
+ * Single atomic transaction: deploys ERC-1967 proxy, installs all 4 modules,
148
+ * registers on ERC-8004 trust registry (optional), and permanently revokes factory access.
149
+ */
150
+ createAccount(params: CreateAccountParams): Promise<CreateAccountResult>;
151
+ /** Compute the deterministic address for an account without deploying */
152
+ getAccountAddress(salt: `0x${string}`): Promise<`0x${string}`>;
153
+ /** Transfer ETH or ERC-20 tokens from a smart account to another address.
154
+ *
155
+ * Executes via AzethAccount.execute() so transfers go through the smart account,
156
+ * not the EOA directly. Defaults to the first smart account if none specified.
157
+ *
158
+ * @param params - Transfer parameters (to, amount, token)
159
+ * @param fromAccount - Optional: specific smart account to transfer from (defaults to first)
160
+ */
161
+ transfer(params: TransferParams, fromAccount?: `0x${string}`): Promise<TransferResult>;
162
+ /** Get ETH and token balances for the smart account (primary) and EOA (gas).
163
+ *
164
+ * @param forAccount - Optional: specific smart account to check (defaults to first)
165
+ */
166
+ getBalance(forAccount?: `0x${string}`): Promise<BalanceResult>;
167
+ /** Get balances for ALL accounts (EOA + all smart accounts) with USD values.
168
+ * Single RPC call via AzethFactory.getOwnerBalancesAndUSD().
169
+ *
170
+ * Returns: EOA at index 0, smart accounts at index 1+.
171
+ * Each account has per-token balances with USD values and a total.
172
+ * Grand total USD sums across all accounts.
173
+ */
174
+ getAllBalances(): Promise<AggregatedBalanceResult>;
175
+ /** Get transaction history for a smart account.
176
+ *
177
+ * @param params - History params (limit, offset)
178
+ * @param forAccount - Optional: specific smart account (defaults to first)
179
+ */
180
+ getHistory(params?: HistoryParams, forAccount?: `0x${string}`): Promise<TransactionRecord[]>;
181
+ /** Deposit ETH or ERC-20 tokens from the owner EOA to a self-owned smart account.
182
+ *
183
+ * SECURITY: On-chain validation ensures the target is:
184
+ * 1. A real Azeth smart account (factory.isAzethAccount)
185
+ * 2. Owned by this EOA (factory.getOwnerOf)
186
+ */
187
+ deposit(params: DepositParams): Promise<DepositResult>;
188
+ /** Deposit ETH or ERC-20 tokens to this account's smart account.
189
+ * Convenience wrapper that auto-resolves the smart account address. */
190
+ depositToSelf(params: Omit<DepositParams, 'to'>): Promise<DepositResult>;
191
+ /** Update the token whitelist on the GuardianModule.
192
+ * Tokens must be whitelisted for executor-module operations (e.g., PaymentAgreementModule).
193
+ *
194
+ * @param token - Token address (use 0x0...0 for native ETH)
195
+ * @param allowed - true to whitelist, false to remove
196
+ * @param account - Optional: specific smart account (defaults to first)
197
+ */
198
+ setTokenWhitelist(token: `0x${string}`, allowed: boolean, account?: `0x${string}`): Promise<`0x${string}`>;
199
+ /** Update the protocol whitelist on the GuardianModule.
200
+ * Protocols must be whitelisted for executor-module operations.
201
+ *
202
+ * @param protocol - Protocol/contract address
203
+ * @param allowed - true to whitelist, false to remove
204
+ * @param account - Optional: specific smart account (defaults to first)
205
+ */
206
+ setProtocolWhitelist(protocol: `0x${string}`, allowed: boolean, account?: `0x${string}`): Promise<`0x${string}`>;
207
+ /** Fetch a URL, automatically paying x402 requirements.
208
+ *
209
+ * If the service returns 402, the SDK signs an ERC-3009 payment authorization,
210
+ * retries the request with the payment proof.
211
+ *
212
+ * Budget checking: If a BudgetManager is configured (default), the payment amount is
213
+ * checked against reputation-aware spending tiers before signing.
214
+ *
215
+ * @param url - Service URL to fetch
216
+ * @param options - Fetch options including budget overrides
217
+ * @param serviceReputation - Optional reputation score (0-100) for budget tier lookup
218
+ */
219
+ fetch402(url: string, options?: Fetch402Options, serviceReputation?: number): Promise<Fetch402Result>;
220
+ /** Discover, pay, and rate a service in one call.
221
+ *
222
+ * Given a capability (e.g., "price-feed"), discovers the best-reputation service,
223
+ * pays for it via x402, falls back to alternatives on failure, and submits
224
+ * reputation feedback automatically.
225
+ *
226
+ * Budget lock: Held for the entire retry sequence to prevent concurrent calls
227
+ * from exhausting budget between retries.
228
+ *
229
+ * Feedback lifecycle: Feedback is awaited (not fire-and-forget) so that callers
230
+ * like the MCP tool can safely call destroy() after this method returns without
231
+ * killing in-flight UserOps. Feedback errors are caught and never propagate.
232
+ *
233
+ * @param capability - Service capability to discover (e.g., 'price-feed', 'market-data')
234
+ * @param options - Smart fetch options (minReputation, maxRetries, autoFeedback, etc.)
235
+ */
236
+ smartFetch402(capability: string, options?: SmartFetch402Options): Promise<SmartFetch402Result>;
237
+ /** Submit reputation feedback for smartFetch402 routing.
238
+ * Errors are swallowed — this must never fail the payment flow.
239
+ *
240
+ * opinionURI: empty string (auto-generated opinions have no external URI)
241
+ * opinionHash: zero bytes32 (no off-chain content to hash)
242
+ */
243
+ private _submitSmartFeedback;
244
+ /** Register this account on the ERC-8004 trust registry */
245
+ publishService(params: RegisterParams): Promise<RegisterResult>;
246
+ /** Discover services by capability and reputation */
247
+ discoverServices(params: DiscoveryParams): Promise<RegistryEntry[]>;
248
+ /** Update metadata for this account's trust registry entry.
249
+ *
250
+ * @param key - Metadata key (e.g., 'endpoint', 'description', 'capabilities')
251
+ * @param value - Metadata value as string (will be hex-encoded internally)
252
+ * @returns Transaction hash
253
+ */
254
+ updateServiceMetadata(key: string, value: string): Promise<`0x${string}`>;
255
+ /** Update multiple metadata fields in a single batch transaction.
256
+ *
257
+ * @param updates - Array of { key, value } pairs to update
258
+ * @returns Transaction hash of the batch UserOp
259
+ */
260
+ updateServiceMetadataBatch(updates: MetadataUpdate[]): Promise<`0x${string}`>;
261
+ /** Create a recurring payment agreement */
262
+ createPaymentAgreement(params: CreateAgreementParams): Promise<AgreementResult>;
263
+ /** Find an active payment agreement with a specific payee.
264
+ * Searches from newest to oldest, returning the first match.
265
+ *
266
+ * @param payee - The payee address to search for
267
+ * @param token - Optional token address to filter by
268
+ * @returns The first matching active agreement, or null
269
+ */
270
+ findAgreementWithPayee(payee: `0x${string}`, token?: `0x${string}`): Promise<PaymentAgreement | null>;
271
+ /** Get details of a specific payment agreement */
272
+ getAgreement(agreementId: bigint, account?: `0x${string}`): Promise<PaymentAgreement>;
273
+ /** Execute a due payment agreement.
274
+ *
275
+ * Auto-detects own vs foreign account:
276
+ * - Own account: executes via UserOp from the payer's smart account (self-execution)
277
+ * - Foreign account: executes as keeper — routes via the caller's own smart account
278
+ * or falls back to direct EOA call if the caller has no smart account
279
+ */
280
+ executeAgreement(agreementId: bigint, account?: `0x${string}`): Promise<`0x${string}`>;
281
+ /** Cancel an active payment agreement. Only the payer can cancel.
282
+ * @param account - Optional: specific smart account that owns the agreement (defaults to first)
283
+ */
284
+ cancelAgreement(agreementId: bigint, account?: `0x${string}`): Promise<`0x${string}`>;
285
+ /** Get the total number of agreements for an account */
286
+ getAgreementCount(account?: `0x${string}`): Promise<bigint>;
287
+ /** Check if a payment agreement can be executed right now */
288
+ canExecutePayment(agreementId: bigint, account?: `0x${string}`): Promise<{
289
+ executable: boolean;
290
+ reason: string;
291
+ }>;
292
+ /** Get the next execution timestamp for a payment agreement */
293
+ getNextExecutionTime(agreementId: bigint, account?: `0x${string}`): Promise<bigint>;
294
+ /** Get comprehensive agreement data in a single RPC call.
295
+ * Combines agreement details + executability + isDue + nextExecutionTime + count. */
296
+ getAgreementData(agreementId: bigint, account?: `0x${string}`): Promise<{
297
+ agreement: PaymentAgreement;
298
+ executable: boolean;
299
+ reason: string;
300
+ isDue: boolean;
301
+ nextExecutionTime: bigint;
302
+ count: bigint;
303
+ }>;
304
+ /** Submit a reputation opinion for an agent via the ReputationModule.
305
+ *
306
+ * Requires a positive net USD payment from this account to the target agent
307
+ * (aggregated on-chain via Chainlink). Value is int128 with configurable decimal precision.
308
+ */
309
+ submitOpinion(opinion: OnChainOpinion): Promise<`0x${string}`>;
310
+ /** Get payment-weighted reputation for an agent.
311
+ *
312
+ * @param agentId - Target agent's ERC-8004 token ID
313
+ * @param raters - Optional list of rater addresses. If omitted, defaults to empty array.
314
+ */
315
+ getWeightedReputation(agentId: bigint, raters?: `0x${string}`[]): Promise<WeightedReputation>;
316
+ /** Get the net payment between this account and a counterparty.
317
+ *
318
+ * - **No token** (default): Returns total net paid in 18-decimal USD, aggregated across
319
+ * all tokens via the on-chain oracle. Always >= 0. This is what the contract uses
320
+ * to gate reputation opinions.
321
+ * - **With token**: Returns the signed per-token delta. Positive means this account
322
+ * has paid more; negative means the counterparty has paid more.
323
+ *
324
+ * @param counterparty - The other account address
325
+ * @param token - Optional token address. Omit for total USD. Use 0x0 for native ETH.
326
+ */
327
+ getNetPaid(counterparty: `0x${string}`, token?: `0x${string}`): Promise<bigint>;
328
+ /** Get active opinion state for this account's opinion on an agent.
329
+ *
330
+ * @param agentId - Target agent's ERC-8004 token ID
331
+ * @param account - Smart account address to query. Defaults to first smart account.
332
+ * @returns Active opinion index and existence flag
333
+ */
334
+ getActiveOpinion(agentId: bigint, account?: `0x${string}`): Promise<ActiveOpinion>;
335
+ /** Read a single opinion entry from the on-chain registry */
336
+ readOpinion(agentId: bigint, clientAddress: `0x${string}`, opinionIndex: bigint): Promise<OpinionEntry>;
337
+ /** Send an encrypted message via XMTP.
338
+ *
339
+ * Lazy-initializes the XMTP client on first call.
340
+ *
341
+ * @param params - Message parameters (to, content)
342
+ * @returns The conversation ID
343
+ */
344
+ sendMessage(params: SendMessageParams): Promise<string>;
345
+ /** Listen for incoming XMTP messages.
346
+ *
347
+ * The handler is registered immediately. If the XMTP client has not been
348
+ * initialized yet, it will be initialized asynchronously when the first
349
+ * handler is registered.
350
+ *
351
+ * @param handler - Async function called for each incoming message
352
+ * @returns Unsubscribe function
353
+ */
354
+ onMessage(handler: MessageHandler): () => void;
355
+ /** Check if an address is reachable on the XMTP network.
356
+ *
357
+ * @param address - Ethereum address to check
358
+ * @returns Whether the address can receive XMTP messages
359
+ */
360
+ canReach(address: `0x${string}`): Promise<boolean>;
361
+ /** List active XMTP conversations.
362
+ *
363
+ * Lazy-initializes the XMTP client on first call.
364
+ *
365
+ * @returns Array of conversation summaries with peer address and creation time
366
+ */
367
+ getConversations(): Promise<XMTPConversation[]>;
368
+ /** Read recent messages from a conversation with a peer.
369
+ *
370
+ * @param peerAddress - Ethereum address of the conversation peer
371
+ * @param limit - Max messages to return (default 20, max 100)
372
+ * @returns Array of messages sorted by timestamp
373
+ */
374
+ getMessages(peerAddress: `0x${string}`, limit?: number): Promise<XMTPMessage[]>;
375
+ /** Get a fetch function that automatically adds ERC-8128 auth headers */
376
+ getSignedFetch(): typeof fetch;
377
+ /** Clean up resources (XMTP agent, timers, etc.) and zero sensitive material.
378
+ * IMPORTANT: Call this when done with the AzethKit instance to zero private key
379
+ * bytes from memory. Use in a try/finally block for safety. */
380
+ destroy(): Promise<void>;
381
+ /** Get or create a SmartAccountClient for a specific smart account address.
382
+ *
383
+ * Uses permissionless's createSmartAccountClient with a custom viem SmartAccount
384
+ * implementation that routes all state-changing calls through ERC-4337 UserOperations.
385
+ *
386
+ * Lazily created and cached per smart account address.
387
+ */
388
+ private _getSmartAccountClient;
389
+ /** Get or create the XMTPClient instance (without initialization) */
390
+ private _getOrCreateMessaging;
391
+ /** Ensure the XMTP client is initialized. Returns the ready client. */
392
+ private _ensureMessaging;
393
+ }
394
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,YAAY,EAEjB,KAAK,KAAK,E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