@invariance/sdk 0.0.1
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 +274 -0
- package/dist/abis-F52VBHAX.js +30 -0
- package/dist/abis-F52VBHAX.js.map +1 -0
- package/dist/chunk-3ONNY6AX.js +849 -0
- package/dist/chunk-3ONNY6AX.js.map +1 -0
- package/dist/chunk-GHYGRZHM.js +7485 -0
- package/dist/chunk-GHYGRZHM.js.map +1 -0
- package/dist/chunk-VUNV25KB.js +16 -0
- package/dist/chunk-VUNV25KB.js.map +1 -0
- package/dist/contract-helpers-XI4NOQLS.js +73 -0
- package/dist/contract-helpers-XI4NOQLS.js.map +1 -0
- package/dist/index.cjs +19028 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4735 -0
- package/dist/index.d.ts +4735 -0
- package/dist/index.js +10135 -0
- package/dist/index.js.map +1 -0
- package/dist/main-I6AWLQD7.js +364 -0
- package/dist/main-I6AWLQD7.js.map +1 -0
- package/package.json +95 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4735 @@
|
|
|
1
|
+
import * as _invariance_common from '@invariance/common';
|
|
2
|
+
import { LedgerQueryFilters, LedgerEntry, ExportData, RegisterIdentityOptions, CreatePolicyOptions, Identity, SpecPolicy, HireOptions, IntentRequestOptions, LedgerEventInput, IntentResult, ActorType, ActorReference, SubmitReviewOptions, HireResult, CompletionResult, ReputationScore, PolicyRule, InvarianceConfig, ChainConfig, ContractAddresses, PauseResult, TxReceipt as TxReceipt$2, Attestation, PreparedIntent, ApprovalResult, IntentStatus, PolicyStatus, EvaluationResult, Unsubscribe, CreateEscrowOptions, EscrowContract, ResolveOptions, ApprovalStatus, EscrowStatus, VerificationResult, IdentityVerification, EscrowVerification, ReputationProfile, Review, ComparisonResult, Badge, ScoreHistory, GasEstimate, GasBalance, RegisterListingOptions, Listing, SearchQuery, SearchResults, AuditConfig, AuditLogMode, AuditVisibility, AuditLogInput, AuditLogRecord, AuditQueryFilters, CreateProposalOptions, VoteInput, Vote, SettlementData, MerkleProofBundle, Proposal, ErrorCode } from '@invariance/common';
|
|
3
|
+
export { ActorReference, ActorType, ApprovalMethod, ApprovalResult, ApprovalStatus, Attestation, AuditConfig, AuditLogInput, AuditLogMode, AuditLogRecord, AuditQueryFilters, AuditVisibility, Badge, ChainConfig, ComparisonResult, CompletionResult, ContractAddresses, CreateEscrowOptions, CreatePolicyOptions, EIP1193Provider, ErrorCode, EscrowConditions, EscrowContract, EscrowState, EscrowStatus, EscrowVerification, EvaluationResult, ExportData, GasBalance, GasEstimate, HireOptions, HireResult, Identity, IdentityVerification, IntentLifecycle, IntentRequestOptions, IntentResult, IntentStatus, InvarianceConfig, InvarianceSigner, LedgerEntry, LedgerEventInput, LedgerQueryFilters, Listing, ListingCategory, OnChainMetrics, PauseResult, PaymentGatedAuthorization, PaymentOptions, PolicyRule, PolicyRuleType, PolicyStatus, PreparedIntent, PricingModel, ProofBundle, RegisterIdentityOptions, RegisterListingOptions, ReputationProfile, ReputationScore, RequirePaymentConfig, ResolveOptions, Review, ReviewSummary, ScoreHistory, ScoreHistoryEntry, SearchQuery, SearchResults, SpecPolicy, SubmitReviewOptions, TxReceipt, Unsubscribe, VerificationResult } from '@invariance/common';
|
|
4
|
+
import { PublicClient, WalletClient, Chain } from 'viem';
|
|
5
|
+
export { generatePrivateKey, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* SDK-level event types that modules can emit.
|
|
9
|
+
*/
|
|
10
|
+
interface InvarianceEvents {
|
|
11
|
+
'identity.registered': {
|
|
12
|
+
identityId: string;
|
|
13
|
+
address: string;
|
|
14
|
+
};
|
|
15
|
+
'identity.paused': {
|
|
16
|
+
identityId: string;
|
|
17
|
+
};
|
|
18
|
+
'identity.resumed': {
|
|
19
|
+
identityId: string;
|
|
20
|
+
};
|
|
21
|
+
'intent.requested': {
|
|
22
|
+
intentId: string;
|
|
23
|
+
action: string;
|
|
24
|
+
requester?: string;
|
|
25
|
+
requesterIdentityId?: string;
|
|
26
|
+
target?: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
mode?: string;
|
|
29
|
+
};
|
|
30
|
+
'intent.approved': {
|
|
31
|
+
intentId: string;
|
|
32
|
+
approver: string;
|
|
33
|
+
approverIdentityId: string;
|
|
34
|
+
};
|
|
35
|
+
'intent.completed': {
|
|
36
|
+
intentId: string;
|
|
37
|
+
txHash: string;
|
|
38
|
+
requester?: string;
|
|
39
|
+
requesterIdentityId?: string;
|
|
40
|
+
action?: string;
|
|
41
|
+
value?: string;
|
|
42
|
+
};
|
|
43
|
+
'intent.rejected': {
|
|
44
|
+
intentId: string;
|
|
45
|
+
reason: string;
|
|
46
|
+
rejector?: string;
|
|
47
|
+
rejectorIdentityId?: string;
|
|
48
|
+
};
|
|
49
|
+
'policy.created': {
|
|
50
|
+
policyId: string;
|
|
51
|
+
name: string;
|
|
52
|
+
};
|
|
53
|
+
'policy.attached': {
|
|
54
|
+
policyId: string;
|
|
55
|
+
identityId: string;
|
|
56
|
+
};
|
|
57
|
+
'policy.detached': {
|
|
58
|
+
policyId: string;
|
|
59
|
+
identityId: string;
|
|
60
|
+
};
|
|
61
|
+
'policy.revoked': {
|
|
62
|
+
policyId: string;
|
|
63
|
+
};
|
|
64
|
+
'policy.composed': {
|
|
65
|
+
policyId: string;
|
|
66
|
+
name: string;
|
|
67
|
+
};
|
|
68
|
+
'policy.violation': {
|
|
69
|
+
policyId: string;
|
|
70
|
+
action: string;
|
|
71
|
+
detail: string;
|
|
72
|
+
};
|
|
73
|
+
'escrow.created': {
|
|
74
|
+
escrowId: string;
|
|
75
|
+
amount: string;
|
|
76
|
+
depositor?: string;
|
|
77
|
+
depositorIdentityId?: string;
|
|
78
|
+
beneficiary?: string;
|
|
79
|
+
beneficiaryIdentityId?: string;
|
|
80
|
+
conditionType?: string;
|
|
81
|
+
};
|
|
82
|
+
'escrow.funded': {
|
|
83
|
+
escrowId: string;
|
|
84
|
+
funder?: string;
|
|
85
|
+
depositor?: string;
|
|
86
|
+
depositorIdentityId?: string;
|
|
87
|
+
beneficiary?: string;
|
|
88
|
+
beneficiaryIdentityId?: string;
|
|
89
|
+
amount?: string;
|
|
90
|
+
};
|
|
91
|
+
'escrow.released': {
|
|
92
|
+
escrowId: string;
|
|
93
|
+
depositor?: string;
|
|
94
|
+
depositorIdentityId?: string;
|
|
95
|
+
beneficiary?: string;
|
|
96
|
+
beneficiaryIdentityId?: string;
|
|
97
|
+
amount?: string;
|
|
98
|
+
};
|
|
99
|
+
'escrow.refunded': {
|
|
100
|
+
escrowId: string;
|
|
101
|
+
depositor?: string;
|
|
102
|
+
depositorIdentityId?: string;
|
|
103
|
+
beneficiary?: string;
|
|
104
|
+
beneficiaryIdentityId?: string;
|
|
105
|
+
amount?: string;
|
|
106
|
+
};
|
|
107
|
+
'escrow.disputed': {
|
|
108
|
+
escrowId: string;
|
|
109
|
+
reason: string;
|
|
110
|
+
disputant?: string;
|
|
111
|
+
depositor?: string;
|
|
112
|
+
depositorIdentityId?: string;
|
|
113
|
+
beneficiary?: string;
|
|
114
|
+
beneficiaryIdentityId?: string;
|
|
115
|
+
amount?: string;
|
|
116
|
+
};
|
|
117
|
+
'escrow.resolved': {
|
|
118
|
+
escrowId: string;
|
|
119
|
+
depositor?: string;
|
|
120
|
+
depositorIdentityId?: string;
|
|
121
|
+
beneficiary?: string;
|
|
122
|
+
beneficiaryIdentityId?: string;
|
|
123
|
+
transferAmount?: string;
|
|
124
|
+
releasedToBeneficiary?: boolean;
|
|
125
|
+
};
|
|
126
|
+
'ledger.logged': {
|
|
127
|
+
entryId: string;
|
|
128
|
+
action: string;
|
|
129
|
+
};
|
|
130
|
+
'reputation.reviewed': {
|
|
131
|
+
reviewId: string;
|
|
132
|
+
target: string;
|
|
133
|
+
rating: number;
|
|
134
|
+
reviewer?: string;
|
|
135
|
+
reviewerIdentityId?: string;
|
|
136
|
+
targetIdentityId?: string;
|
|
137
|
+
escrowId?: string;
|
|
138
|
+
commentHash?: string;
|
|
139
|
+
categories?: Record<string, number>;
|
|
140
|
+
};
|
|
141
|
+
'marketplace.listed': {
|
|
142
|
+
listingId: string;
|
|
143
|
+
};
|
|
144
|
+
'marketplace.hired': {
|
|
145
|
+
hireId: string;
|
|
146
|
+
listingId: string;
|
|
147
|
+
hirer?: string;
|
|
148
|
+
provider?: string;
|
|
149
|
+
escrowId?: string;
|
|
150
|
+
policyId?: string;
|
|
151
|
+
};
|
|
152
|
+
'marketplace.hire.completed': {
|
|
153
|
+
hireId: string;
|
|
154
|
+
hirer: string;
|
|
155
|
+
provider: string;
|
|
156
|
+
listingId: string;
|
|
157
|
+
escrowId: string;
|
|
158
|
+
completedAt: number;
|
|
159
|
+
};
|
|
160
|
+
'marketplace.hire.cancelled': {
|
|
161
|
+
hireId: string;
|
|
162
|
+
hirer: string;
|
|
163
|
+
provider: string;
|
|
164
|
+
listingId: string;
|
|
165
|
+
escrowId: string;
|
|
166
|
+
};
|
|
167
|
+
'marketplace.hire.disputed': {
|
|
168
|
+
hireId: string;
|
|
169
|
+
disputant: string;
|
|
170
|
+
hirer: string;
|
|
171
|
+
provider: string;
|
|
172
|
+
listingId: string;
|
|
173
|
+
escrowId: string;
|
|
174
|
+
};
|
|
175
|
+
'webhook.delivered': {
|
|
176
|
+
webhookId: string;
|
|
177
|
+
event: string;
|
|
178
|
+
};
|
|
179
|
+
'payment.completed': {
|
|
180
|
+
paymentId: string;
|
|
181
|
+
action: string;
|
|
182
|
+
amount: string;
|
|
183
|
+
};
|
|
184
|
+
'payment.failed': {
|
|
185
|
+
action: string;
|
|
186
|
+
reason: string;
|
|
187
|
+
};
|
|
188
|
+
'erc8004.identity.linked': {
|
|
189
|
+
invarianceIdentityId: string;
|
|
190
|
+
erc8004AgentId: string;
|
|
191
|
+
};
|
|
192
|
+
'erc8004.identity.unlinked': {
|
|
193
|
+
invarianceIdentityId: string;
|
|
194
|
+
erc8004AgentId: string;
|
|
195
|
+
};
|
|
196
|
+
'erc8004.feedback.pushed': {
|
|
197
|
+
erc8004AgentId: string;
|
|
198
|
+
value: number;
|
|
199
|
+
};
|
|
200
|
+
'erc8004.validation.responded': {
|
|
201
|
+
requestHash: string;
|
|
202
|
+
response: number;
|
|
203
|
+
};
|
|
204
|
+
'action.before': {
|
|
205
|
+
action: string;
|
|
206
|
+
actor: {
|
|
207
|
+
type: string;
|
|
208
|
+
address: string;
|
|
209
|
+
};
|
|
210
|
+
timestamp: number;
|
|
211
|
+
};
|
|
212
|
+
'action.after': {
|
|
213
|
+
action: string;
|
|
214
|
+
actor: {
|
|
215
|
+
type: string;
|
|
216
|
+
address: string;
|
|
217
|
+
};
|
|
218
|
+
durationMs: number;
|
|
219
|
+
success: boolean;
|
|
220
|
+
timestamp: number;
|
|
221
|
+
};
|
|
222
|
+
'action.violation': {
|
|
223
|
+
action: string;
|
|
224
|
+
detail: string;
|
|
225
|
+
policyId?: string;
|
|
226
|
+
timestamp: number;
|
|
227
|
+
};
|
|
228
|
+
'action.error': {
|
|
229
|
+
action: string;
|
|
230
|
+
message: string;
|
|
231
|
+
code?: string;
|
|
232
|
+
timestamp: number;
|
|
233
|
+
};
|
|
234
|
+
'error': {
|
|
235
|
+
code: string;
|
|
236
|
+
message: string;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** Listener callback type */
|
|
240
|
+
type Listener<T> = (data: T) => void;
|
|
241
|
+
/**
|
|
242
|
+
* Typed event emitter for SDK-level events.
|
|
243
|
+
*
|
|
244
|
+
* Provides a simple pub/sub mechanism for all Invariance modules
|
|
245
|
+
* to emit events and for consumers to subscribe to them.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* const emitter = new InvarianceEventEmitter();
|
|
250
|
+
* emitter.on('intent.completed', (data) => {
|
|
251
|
+
* console.log(`Intent ${data.intentId} completed: ${data.txHash}`);
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare class InvarianceEventEmitter {
|
|
256
|
+
private listeners;
|
|
257
|
+
/**
|
|
258
|
+
* Subscribe to an event.
|
|
259
|
+
*
|
|
260
|
+
* @param event - The event name to listen for
|
|
261
|
+
* @param listener - Callback invoked when the event is emitted
|
|
262
|
+
* @returns A function to unsubscribe
|
|
263
|
+
*/
|
|
264
|
+
on<K extends keyof InvarianceEvents>(event: K, listener: Listener<InvarianceEvents[K]>): () => void;
|
|
265
|
+
/**
|
|
266
|
+
* Unsubscribe from an event.
|
|
267
|
+
*
|
|
268
|
+
* @param event - The event name
|
|
269
|
+
* @param listener - The callback to remove
|
|
270
|
+
*/
|
|
271
|
+
off<K extends keyof InvarianceEvents>(event: K, listener: Listener<InvarianceEvents[K]>): void;
|
|
272
|
+
/**
|
|
273
|
+
* Emit an event to all subscribers.
|
|
274
|
+
*
|
|
275
|
+
* @param event - The event name
|
|
276
|
+
* @param data - The event payload
|
|
277
|
+
*/
|
|
278
|
+
emit<K extends keyof InvarianceEvents>(event: K, data: InvarianceEvents[K]): void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Type definitions for Invariance SDK convenience methods.
|
|
283
|
+
*
|
|
284
|
+
* These types support higher-level workflow methods on the {@link Invariance} class
|
|
285
|
+
* that compose multiple module calls into single operations.
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
/** Options for {@link Invariance.quickSetup} */
|
|
289
|
+
interface QuickSetupOptions {
|
|
290
|
+
/** Identity registration options */
|
|
291
|
+
identity: RegisterIdentityOptions;
|
|
292
|
+
/** Policy to create and attach to the new identity (required unless policyTemplate is set) */
|
|
293
|
+
policy?: CreatePolicyOptions;
|
|
294
|
+
/** Use a built-in policy template instead of manual policy config */
|
|
295
|
+
policyTemplate?: string;
|
|
296
|
+
/** Auto-fund the wallet after setup */
|
|
297
|
+
fund?: {
|
|
298
|
+
amount: string;
|
|
299
|
+
token?: 'USDC';
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/** Result of {@link Invariance.quickSetup} */
|
|
303
|
+
interface QuickSetupResult {
|
|
304
|
+
identity: Identity;
|
|
305
|
+
policy: SpecPolicy;
|
|
306
|
+
/** Whether the wallet was funded during setup */
|
|
307
|
+
funded?: boolean;
|
|
308
|
+
}
|
|
309
|
+
/** Options for {@link Invariance.hireAndFund} */
|
|
310
|
+
interface HireAndFundOptions extends HireOptions {
|
|
311
|
+
/** Amount to fund the escrow with (defaults to hire payment amount) */
|
|
312
|
+
fundAmount?: string;
|
|
313
|
+
}
|
|
314
|
+
/** Options for a single agent in a batch registration */
|
|
315
|
+
interface BatchAgentOptions {
|
|
316
|
+
/** Identity registration options */
|
|
317
|
+
identity: RegisterIdentityOptions;
|
|
318
|
+
/** Optional per-agent policy override (otherwise shared policy is used) */
|
|
319
|
+
policyOverride?: CreatePolicyOptions;
|
|
320
|
+
}
|
|
321
|
+
/** Result of a single agent in a batch registration */
|
|
322
|
+
interface BatchRegisterEntry {
|
|
323
|
+
identity: Identity;
|
|
324
|
+
policy: SpecPolicy;
|
|
325
|
+
}
|
|
326
|
+
/** Options for {@link Invariance.batchRegister} */
|
|
327
|
+
interface BatchRegisterOptions {
|
|
328
|
+
/** Agents to register */
|
|
329
|
+
agents: BatchAgentOptions[];
|
|
330
|
+
/** Shared policy applied to all agents (unless overridden) */
|
|
331
|
+
sharedPolicy: CreatePolicyOptions;
|
|
332
|
+
}
|
|
333
|
+
/** Options for {@link Invariance.executeAndLog} */
|
|
334
|
+
interface ExecuteAndLogOptions {
|
|
335
|
+
/** Intent request options */
|
|
336
|
+
intent: IntentRequestOptions;
|
|
337
|
+
/** Additional ledger event to log alongside the intent */
|
|
338
|
+
log: LedgerEventInput;
|
|
339
|
+
}
|
|
340
|
+
/** Result of {@link Invariance.executeAndLog} */
|
|
341
|
+
interface ExecuteAndLogResult {
|
|
342
|
+
intent: IntentResult;
|
|
343
|
+
log: LedgerEntry;
|
|
344
|
+
}
|
|
345
|
+
/** Options for {@link Invariance.recurringPayment} */
|
|
346
|
+
interface RecurringPaymentOptions {
|
|
347
|
+
/** Human-readable name for the payment policy */
|
|
348
|
+
name: string;
|
|
349
|
+
/** Payment amount per interval */
|
|
350
|
+
amount: string;
|
|
351
|
+
/** Payment recipient address */
|
|
352
|
+
recipient: string;
|
|
353
|
+
/** Interval between payments (ISO 8601 duration, e.g. "P1M" for monthly) */
|
|
354
|
+
interval: string;
|
|
355
|
+
/** Maximum number of payments (optional, unlimited if omitted) */
|
|
356
|
+
maxPayments?: number;
|
|
357
|
+
/** Actor types this policy applies to */
|
|
358
|
+
actor?: ActorType | ActorType[];
|
|
359
|
+
/** Allowed actions during the payment window */
|
|
360
|
+
allowedActions?: string[];
|
|
361
|
+
/** Policy expiry (ISO 8601 datetime) */
|
|
362
|
+
expiry?: string;
|
|
363
|
+
}
|
|
364
|
+
/** Options for {@link Invariance.createMultiSig} */
|
|
365
|
+
interface CreateMultiSigOptions {
|
|
366
|
+
/** Escrow amount in USDC */
|
|
367
|
+
amount: string;
|
|
368
|
+
/** Recipient identity or address */
|
|
369
|
+
recipient: ActorReference;
|
|
370
|
+
/** Signer addresses for multi-sig approval */
|
|
371
|
+
signers: string[];
|
|
372
|
+
/** Number of signatures required to release */
|
|
373
|
+
threshold: number;
|
|
374
|
+
/** Timeout per signer (ISO 8601 duration) */
|
|
375
|
+
timeoutPerSigner?: string;
|
|
376
|
+
/** Overall escrow timeout (ISO 8601 duration) */
|
|
377
|
+
timeout?: string;
|
|
378
|
+
/** Whether to auto-fund on creation */
|
|
379
|
+
autoFund?: boolean;
|
|
380
|
+
}
|
|
381
|
+
/** Options for {@link Invariance.setupRateLimitedAgent} */
|
|
382
|
+
interface SetupRateLimitedAgentOptions {
|
|
383
|
+
/** Identity registration options */
|
|
384
|
+
identity: RegisterIdentityOptions;
|
|
385
|
+
/** Maximum actions per window */
|
|
386
|
+
maxActions: number;
|
|
387
|
+
/** Rate limit window (ISO 8601 duration, e.g. "PT1H" for 1 hour) */
|
|
388
|
+
window: string;
|
|
389
|
+
/** Cooldown between actions (ISO 8601 duration) */
|
|
390
|
+
cooldown?: string;
|
|
391
|
+
/** Allowed actions (whitelist) */
|
|
392
|
+
allowedActions?: string[];
|
|
393
|
+
/** Maximum spend per window */
|
|
394
|
+
maxSpend?: string;
|
|
395
|
+
}
|
|
396
|
+
/** Options for {@link Invariance.hireAndReview} */
|
|
397
|
+
interface HireAndReviewOptions {
|
|
398
|
+
/** Hire options */
|
|
399
|
+
hire: HireOptions;
|
|
400
|
+
/** Review to submit after completion */
|
|
401
|
+
review: Omit<SubmitReviewOptions, 'target' | 'escrowId'>;
|
|
402
|
+
/** Amount to fund escrow (defaults to hire payment amount) */
|
|
403
|
+
fundAmount?: string;
|
|
404
|
+
}
|
|
405
|
+
/** Result of {@link Invariance.hireAndReview} */
|
|
406
|
+
interface HireAndReviewResult {
|
|
407
|
+
hire: HireResult;
|
|
408
|
+
completion: CompletionResult;
|
|
409
|
+
review: {
|
|
410
|
+
reviewId: string;
|
|
411
|
+
updatedReputation: ReputationScore;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/** Options for {@link Invariance.audit} */
|
|
415
|
+
interface AuditOptions extends LedgerQueryFilters {
|
|
416
|
+
/** Whether to verify each ledger entry */
|
|
417
|
+
verify?: boolean;
|
|
418
|
+
/** Export format */
|
|
419
|
+
exportFormat?: 'json' | 'csv';
|
|
420
|
+
}
|
|
421
|
+
/** Result of {@link Invariance.audit} */
|
|
422
|
+
interface AuditReport {
|
|
423
|
+
entries: LedgerEntry[];
|
|
424
|
+
totalEntries: number;
|
|
425
|
+
verifiedCount: number;
|
|
426
|
+
failedVerifications: Array<{
|
|
427
|
+
entryId: string;
|
|
428
|
+
error: string;
|
|
429
|
+
}>;
|
|
430
|
+
exported?: ExportData;
|
|
431
|
+
generatedAt: number;
|
|
432
|
+
}
|
|
433
|
+
/** Options for {@link Invariance.delegate} */
|
|
434
|
+
interface DelegateOptions {
|
|
435
|
+
/** Identity ID of the delegating agent */
|
|
436
|
+
from: string;
|
|
437
|
+
/** Identity ID of the agent receiving delegation */
|
|
438
|
+
to: string;
|
|
439
|
+
/** Scope of allowed actions for the delegate */
|
|
440
|
+
scope: {
|
|
441
|
+
/** Allowed actions */
|
|
442
|
+
actions: string[];
|
|
443
|
+
/** Maximum spend limit */
|
|
444
|
+
maxSpend?: string;
|
|
445
|
+
/** Delegation expiry (ISO 8601 datetime) */
|
|
446
|
+
expiry?: string;
|
|
447
|
+
/** Additional policy rules */
|
|
448
|
+
additionalRules?: PolicyRule[];
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
/** Result of {@link Invariance.delegate} */
|
|
452
|
+
interface DelegateResult {
|
|
453
|
+
policy: SpecPolicy;
|
|
454
|
+
intent: IntentResult;
|
|
455
|
+
}
|
|
456
|
+
/** A deferred operation for batch execution */
|
|
457
|
+
interface DeferredOperation<T = unknown> {
|
|
458
|
+
/** The async function to execute */
|
|
459
|
+
execute: () => Promise<T>;
|
|
460
|
+
/** Human-readable description of the operation */
|
|
461
|
+
description: string;
|
|
462
|
+
}
|
|
463
|
+
/** Options for batch execution */
|
|
464
|
+
interface BatchOptions {
|
|
465
|
+
/** Continue executing remaining operations after a failure (default: false) */
|
|
466
|
+
continueOnError?: boolean;
|
|
467
|
+
/** Maximum number of concurrent operations (default: 5) */
|
|
468
|
+
maxConcurrency?: number;
|
|
469
|
+
}
|
|
470
|
+
/** Result of a batch execution */
|
|
471
|
+
interface BatchResult<T = unknown> {
|
|
472
|
+
results: Array<{
|
|
473
|
+
index: number;
|
|
474
|
+
description: string;
|
|
475
|
+
result: T;
|
|
476
|
+
}>;
|
|
477
|
+
failures: Array<{
|
|
478
|
+
index: number;
|
|
479
|
+
description: string;
|
|
480
|
+
error: string;
|
|
481
|
+
}>;
|
|
482
|
+
successCount: number;
|
|
483
|
+
failureCount: number;
|
|
484
|
+
totalCount: number;
|
|
485
|
+
}
|
|
486
|
+
/** Options for creating a session context */
|
|
487
|
+
interface SessionOptions {
|
|
488
|
+
/** The actor to bind to all session operations */
|
|
489
|
+
actor: ActorReference;
|
|
490
|
+
}
|
|
491
|
+
/** A single step result in a pipeline execution */
|
|
492
|
+
interface PipelineStep {
|
|
493
|
+
name: string;
|
|
494
|
+
success: boolean;
|
|
495
|
+
result?: unknown;
|
|
496
|
+
error?: string;
|
|
497
|
+
durationMs: number;
|
|
498
|
+
}
|
|
499
|
+
/** Result of a pipeline execution */
|
|
500
|
+
interface PipelineResult {
|
|
501
|
+
success: boolean;
|
|
502
|
+
steps: PipelineStep[];
|
|
503
|
+
context: Record<string, unknown>;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** Filters for querying intent history */
|
|
507
|
+
interface IntentHistoryFilters {
|
|
508
|
+
actor?: string;
|
|
509
|
+
action?: string | string[];
|
|
510
|
+
status?: 'completed' | 'rejected' | 'expired';
|
|
511
|
+
from?: string | number;
|
|
512
|
+
to?: string | number;
|
|
513
|
+
limit?: number;
|
|
514
|
+
offset?: number;
|
|
515
|
+
}
|
|
516
|
+
/** Configuration for intent retry behavior */
|
|
517
|
+
interface RetryConfig {
|
|
518
|
+
/** Maximum number of attempts (default: 3) */
|
|
519
|
+
maxAttempts?: number;
|
|
520
|
+
/** Initial delay in milliseconds (default: 1000) */
|
|
521
|
+
initialDelayMs?: number;
|
|
522
|
+
/** Backoff multiplier (default: 2) */
|
|
523
|
+
backoffMultiplier?: number;
|
|
524
|
+
/** Error codes that trigger a retry (default: NETWORK_ERROR, RPC_ERROR, TIMEOUT) */
|
|
525
|
+
retryableErrors?: string[];
|
|
526
|
+
}
|
|
527
|
+
/** Result of a retried intent request */
|
|
528
|
+
interface RetryResult {
|
|
529
|
+
/** The successful intent result (if any) */
|
|
530
|
+
result: _invariance_common.IntentResult | null;
|
|
531
|
+
/** Total number of attempts made */
|
|
532
|
+
attempts: number;
|
|
533
|
+
/** Errors from each failed attempt */
|
|
534
|
+
errors: Array<{
|
|
535
|
+
attempt: number;
|
|
536
|
+
error: string;
|
|
537
|
+
code?: string;
|
|
538
|
+
}>;
|
|
539
|
+
/** Whether the request ultimately succeeded */
|
|
540
|
+
success: boolean;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Callback for streamed ledger entries */
|
|
544
|
+
type LedgerStreamCallback = (entry: _invariance_common.LedgerEntry) => void;
|
|
545
|
+
/** Configuration for auto-batching compact ledger entries */
|
|
546
|
+
interface AutoBatchConfig {
|
|
547
|
+
/** Maximum entries per batch (default: 10) */
|
|
548
|
+
maxBatchSize?: number;
|
|
549
|
+
/** Maximum wait time in ms before flushing (default: 5000) */
|
|
550
|
+
maxWaitMs?: number;
|
|
551
|
+
/** Whether batching is enabled (default: true) */
|
|
552
|
+
enabled?: boolean;
|
|
553
|
+
}
|
|
554
|
+
/** Time range filter for analytics queries */
|
|
555
|
+
interface AnalyticsTimeframe {
|
|
556
|
+
from?: string | number;
|
|
557
|
+
to?: string | number;
|
|
558
|
+
}
|
|
559
|
+
/** Result of a success rate query */
|
|
560
|
+
interface SuccessRateResult {
|
|
561
|
+
total: number;
|
|
562
|
+
successful: number;
|
|
563
|
+
failed: number;
|
|
564
|
+
/** Success rate as a decimal (0-1) */
|
|
565
|
+
rate: number;
|
|
566
|
+
/** Success rate as a percentage (0-100) */
|
|
567
|
+
percentage: number;
|
|
568
|
+
}
|
|
569
|
+
/** Result of an action count query */
|
|
570
|
+
interface ActionCountResult {
|
|
571
|
+
action: string;
|
|
572
|
+
count: number;
|
|
573
|
+
byCategory: Record<string, number>;
|
|
574
|
+
}
|
|
575
|
+
/** Result of a cost summary query */
|
|
576
|
+
interface CostSummaryResult {
|
|
577
|
+
totalCost: string;
|
|
578
|
+
transactionCount: number;
|
|
579
|
+
byAction: Record<string, number>;
|
|
580
|
+
}
|
|
581
|
+
/** Result of a violations query */
|
|
582
|
+
interface ViolationResult {
|
|
583
|
+
total: number;
|
|
584
|
+
byAction: Record<string, number>;
|
|
585
|
+
details: Array<{
|
|
586
|
+
action: string;
|
|
587
|
+
timestamp: number;
|
|
588
|
+
detail: string;
|
|
589
|
+
policyId: string;
|
|
590
|
+
}>;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** Options for evaluating an action against a policy */
|
|
594
|
+
interface EvaluateOptions {
|
|
595
|
+
policyId: string;
|
|
596
|
+
actor: _invariance_common.ActorReference;
|
|
597
|
+
action: string;
|
|
598
|
+
amount?: string;
|
|
599
|
+
params?: Record<string, unknown>;
|
|
600
|
+
/** x402 payment receipt ID for require-payment rule verification */
|
|
601
|
+
paymentReceiptId?: string;
|
|
602
|
+
}
|
|
603
|
+
/** Filters for listing policies */
|
|
604
|
+
interface PolicyListFilters {
|
|
605
|
+
identityId?: string;
|
|
606
|
+
actor?: string;
|
|
607
|
+
state?: 'active' | 'revoked' | 'expired';
|
|
608
|
+
limit?: number;
|
|
609
|
+
offset?: number;
|
|
610
|
+
}
|
|
611
|
+
/** Callback for policy violation events */
|
|
612
|
+
type PolicyViolationCallback = (violation: {
|
|
613
|
+
policyId: string;
|
|
614
|
+
action: string;
|
|
615
|
+
detail: string;
|
|
616
|
+
timestamp: number;
|
|
617
|
+
}) => void;
|
|
618
|
+
/** Built-in template names */
|
|
619
|
+
type BuiltInTemplate = 'conservative-spending' | 'defi-trading' | 'content-agent' | 'research-agent' | 'full-autonomy' | 'mev-bot' | 'social-agent' | 'cross-chain-bridge' | 'payment-delegation' | 'iot-device' | 'government-benefits' | 'identity-verifier';
|
|
620
|
+
/** A policy template definition */
|
|
621
|
+
interface PolicyTemplate {
|
|
622
|
+
/** Template name */
|
|
623
|
+
name: string;
|
|
624
|
+
/** Human-readable description */
|
|
625
|
+
description: string;
|
|
626
|
+
/** Whether this is a built-in template */
|
|
627
|
+
builtin: boolean;
|
|
628
|
+
/** Policy rules included in the template */
|
|
629
|
+
rules: _invariance_common.PolicyRule[];
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Session context that binds an actor to all operations,
|
|
634
|
+
* eliminating repetitive actor passing.
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* const session = inv.session({ actor: { type: 'agent', address: '0xBot' } });
|
|
639
|
+
* await session.requestIntent({ action: 'swap', params: {...} });
|
|
640
|
+
* await session.myActions({ limit: 50 });
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* A session scoped to a specific actor.
|
|
646
|
+
*
|
|
647
|
+
* All operations automatically use the bound actor, removing the need
|
|
648
|
+
* to pass actor references repeatedly.
|
|
649
|
+
*/
|
|
650
|
+
declare class SessionContext {
|
|
651
|
+
private readonly inv;
|
|
652
|
+
/** The actor bound to this session */
|
|
653
|
+
readonly actor: ActorReference;
|
|
654
|
+
constructor(inv: Invariance, options: SessionOptions);
|
|
655
|
+
/**
|
|
656
|
+
* Request an intent with the session actor pre-filled.
|
|
657
|
+
*
|
|
658
|
+
* @param opts - Intent options (actor is auto-filled)
|
|
659
|
+
* @returns Intent result
|
|
660
|
+
*/
|
|
661
|
+
requestIntent(opts: Omit<IntentRequestOptions, 'actor'>): Promise<IntentResult>;
|
|
662
|
+
/**
|
|
663
|
+
* Query the session actor's action history.
|
|
664
|
+
*
|
|
665
|
+
* @param filters - Optional additional filters
|
|
666
|
+
* @returns Array of intent results
|
|
667
|
+
*/
|
|
668
|
+
myActions(filters?: Omit<IntentHistoryFilters, 'actor'>): Promise<IntentResult[]>;
|
|
669
|
+
/**
|
|
670
|
+
* Query ledger entries for the session actor.
|
|
671
|
+
*
|
|
672
|
+
* @param filters - Optional additional filters
|
|
673
|
+
* @returns Array of ledger entries
|
|
674
|
+
*/
|
|
675
|
+
myLedgerEntries(filters?: Omit<LedgerQueryFilters, 'actor'>): Promise<LedgerEntry[]>;
|
|
676
|
+
/**
|
|
677
|
+
* List policies attached to the session actor's identity.
|
|
678
|
+
*
|
|
679
|
+
* @param filters - Optional additional filters
|
|
680
|
+
* @returns Array of policies
|
|
681
|
+
*/
|
|
682
|
+
myPolicies(filters?: Omit<PolicyListFilters, 'identityId'>): Promise<SpecPolicy[]>;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Fluent pipeline builder for multi-step workflows with auto-linked context.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* const result = await inv.pipeline()
|
|
691
|
+
* .register({ type: 'agent', label: 'Bot', owner: '0x...' })
|
|
692
|
+
* .createPolicy({ template: 'defi-trading' })
|
|
693
|
+
* .attachPolicy()
|
|
694
|
+
* .fundWallet({ amount: '100' })
|
|
695
|
+
* .execute();
|
|
696
|
+
* ```
|
|
697
|
+
*/
|
|
698
|
+
|
|
699
|
+
/** Shared context passed between pipeline steps */
|
|
700
|
+
type PipelineContext = Map<string, unknown>;
|
|
701
|
+
/**
|
|
702
|
+
* Fluent builder for multi-step agent workflows.
|
|
703
|
+
*
|
|
704
|
+
* Steps store results in a shared context map. Later steps auto-read
|
|
705
|
+
* values (like identityId, policyId) from context.
|
|
706
|
+
*/
|
|
707
|
+
declare class PipelineBuilder {
|
|
708
|
+
private readonly inv;
|
|
709
|
+
private readonly steps;
|
|
710
|
+
constructor(inv: Invariance);
|
|
711
|
+
/**
|
|
712
|
+
* Register an identity. Stores `identityId` and `identity` in context.
|
|
713
|
+
*/
|
|
714
|
+
register(opts: RegisterIdentityOptions): this;
|
|
715
|
+
/**
|
|
716
|
+
* Create a policy. Accepts either a template name or full options.
|
|
717
|
+
* Stores `policyId` and `policy` in context.
|
|
718
|
+
*/
|
|
719
|
+
createPolicy(opts: {
|
|
720
|
+
template: string;
|
|
721
|
+
expiry?: string;
|
|
722
|
+
} | CreatePolicyOptions): this;
|
|
723
|
+
/**
|
|
724
|
+
* Attach the policy from context to the identity from context.
|
|
725
|
+
* Auto-reads `policyId` and `identityId` from previous steps.
|
|
726
|
+
*/
|
|
727
|
+
attachPolicy(policyId?: string, identityId?: string): this;
|
|
728
|
+
/**
|
|
729
|
+
* Fund the wallet with a specified amount.
|
|
730
|
+
*/
|
|
731
|
+
fundWallet(opts: {
|
|
732
|
+
amount: string;
|
|
733
|
+
token?: 'USDC';
|
|
734
|
+
}): this;
|
|
735
|
+
/**
|
|
736
|
+
* Add a custom step with access to the pipeline context.
|
|
737
|
+
*/
|
|
738
|
+
custom(name: string, fn: (ctx: PipelineContext) => Promise<unknown>): this;
|
|
739
|
+
/**
|
|
740
|
+
* Execute all pipeline steps sequentially.
|
|
741
|
+
* Stops on first error with full step-by-step reporting.
|
|
742
|
+
*
|
|
743
|
+
* @returns Pipeline result with success status, step results, and context
|
|
744
|
+
*/
|
|
745
|
+
execute(): Promise<PipelineResult>;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
type ContractName = 'identity' | 'policy' | 'ledger' | 'intent' | 'escrow' | 'review' | 'registry' | 'hire' | 'mockUsdc' | 'compactLedger' | 'atomicVerifier' | 'voting';
|
|
749
|
+
/**
|
|
750
|
+
* Manages contract instances and blockchain connectivity.
|
|
751
|
+
*
|
|
752
|
+
* ContractFactory is the central point for creating and caching
|
|
753
|
+
* viem PublicClient and WalletClient instances, as well as providing
|
|
754
|
+
* typed contract addresses for each Invariance module.
|
|
755
|
+
*
|
|
756
|
+
* @example
|
|
757
|
+
* ```typescript
|
|
758
|
+
* const factory = new ContractFactory(config);
|
|
759
|
+
* const identityAddr = factory.getAddress('identity');
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
762
|
+
declare class ContractFactory {
|
|
763
|
+
private readonly config;
|
|
764
|
+
private readonly chainConfig;
|
|
765
|
+
private readonly addresses;
|
|
766
|
+
private publicClient;
|
|
767
|
+
private wsPublicClient;
|
|
768
|
+
private walletClient;
|
|
769
|
+
constructor(config: InvarianceConfig);
|
|
770
|
+
/**
|
|
771
|
+
* Get the RPC URL for the current chain.
|
|
772
|
+
* Uses config override if provided, otherwise falls back to chain default.
|
|
773
|
+
*/
|
|
774
|
+
getRpcUrl(): string;
|
|
775
|
+
/**
|
|
776
|
+
* Get the chain configuration.
|
|
777
|
+
*/
|
|
778
|
+
getChainConfig(): ChainConfig;
|
|
779
|
+
/**
|
|
780
|
+
* Get the chain ID.
|
|
781
|
+
*/
|
|
782
|
+
getChainId(): number;
|
|
783
|
+
/**
|
|
784
|
+
* Get all contract addresses for the current chain.
|
|
785
|
+
*/
|
|
786
|
+
getAddresses(): ContractAddresses;
|
|
787
|
+
/**
|
|
788
|
+
* Get a specific contract address by module name.
|
|
789
|
+
*
|
|
790
|
+
* @param name - The contract module name
|
|
791
|
+
* @returns The contract address as a hex string
|
|
792
|
+
*/
|
|
793
|
+
getAddress(name: keyof ContractAddresses): string;
|
|
794
|
+
/**
|
|
795
|
+
* Get the signer/wallet from config.
|
|
796
|
+
* Returns undefined if no signer is configured.
|
|
797
|
+
*/
|
|
798
|
+
getSigner(): unknown;
|
|
799
|
+
/**
|
|
800
|
+
* Get the API key from config (for managed hosting).
|
|
801
|
+
*/
|
|
802
|
+
getApiKey(): string | undefined;
|
|
803
|
+
/**
|
|
804
|
+
* Get the gas strategy.
|
|
805
|
+
*/
|
|
806
|
+
getGasStrategy(): 'standard' | 'fast' | 'abstracted' | 'sponsored';
|
|
807
|
+
/**
|
|
808
|
+
* Get the explorer base URL.
|
|
809
|
+
*/
|
|
810
|
+
getExplorerBaseUrl(): string;
|
|
811
|
+
/**
|
|
812
|
+
* Check whether managed mode is active (API key provided).
|
|
813
|
+
*/
|
|
814
|
+
isManaged(): boolean;
|
|
815
|
+
/** Set the viem clients after wallet initialization */
|
|
816
|
+
setClients(publicClient: PublicClient, walletClient: WalletClient): void;
|
|
817
|
+
/**
|
|
818
|
+
* Get the best available client for receipt watching.
|
|
819
|
+
* Prefers WebSocket (instant block notifications) over HTTP polling.
|
|
820
|
+
*/
|
|
821
|
+
getReceiptClient(): PublicClient;
|
|
822
|
+
/** Get the confirmation strategy. */
|
|
823
|
+
getConfirmation(): 'optimistic' | 'receipt';
|
|
824
|
+
/** Get the public client for read operations */
|
|
825
|
+
getPublicClient(): PublicClient;
|
|
826
|
+
/** Get the wallet client for write operations */
|
|
827
|
+
getWalletClient(): WalletClient;
|
|
828
|
+
/** Check if clients are initialized */
|
|
829
|
+
hasClients(): boolean;
|
|
830
|
+
/**
|
|
831
|
+
* Get a viem contract instance for the given contract name.
|
|
832
|
+
*
|
|
833
|
+
* @param name - The contract name
|
|
834
|
+
* @returns A viem contract instance with read/write methods
|
|
835
|
+
*/
|
|
836
|
+
getContract(name: ContractName): {
|
|
837
|
+
address: `0x${string}`;
|
|
838
|
+
abi: readonly unknown[];
|
|
839
|
+
read: Record<string, (...args: unknown[]) => Promise<unknown>>;
|
|
840
|
+
write: Record<string, (...args: unknown[]) => Promise<`0x${string}`>>;
|
|
841
|
+
};
|
|
842
|
+
/** Get the API base URL for indexer calls */
|
|
843
|
+
getApiBaseUrl(): string;
|
|
844
|
+
/** Get the wallet address from the wallet client */
|
|
845
|
+
getWalletAddress(): string;
|
|
846
|
+
/**
|
|
847
|
+
* Get the EIP-712 domain for CompactLedger signatures.
|
|
848
|
+
*
|
|
849
|
+
* @returns EIP-712 domain with the CompactLedger contract address
|
|
850
|
+
*/
|
|
851
|
+
getCompactLedgerDomain(): {
|
|
852
|
+
name: string;
|
|
853
|
+
version: string;
|
|
854
|
+
chainId: number;
|
|
855
|
+
verifyingContract: `0x${string}`;
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Anonymized telemetry collector for SDK usage metrics.
|
|
861
|
+
*
|
|
862
|
+
* When enabled, collects non-identifying usage data such as method call counts,
|
|
863
|
+
* error rates, and latency distributions. All data is anonymized and contains
|
|
864
|
+
* no wallet addresses, transaction hashes, or personally identifiable information.
|
|
865
|
+
*
|
|
866
|
+
* Telemetry is opt-out: enabled by default but can be disabled via config.
|
|
867
|
+
*/
|
|
868
|
+
declare class Telemetry {
|
|
869
|
+
private readonly enabled;
|
|
870
|
+
private buffer;
|
|
871
|
+
private static readonly MAX_BUFFER_SIZE;
|
|
872
|
+
constructor(enabled: boolean);
|
|
873
|
+
/**
|
|
874
|
+
* Track an anonymized telemetry event.
|
|
875
|
+
*
|
|
876
|
+
* @param event - Event name (e.g., 'identity.register', 'intent.request')
|
|
877
|
+
* @param data - Anonymized event data (no PII, no addresses, no hashes)
|
|
878
|
+
*/
|
|
879
|
+
track(event: string, data?: Record<string, unknown>): void;
|
|
880
|
+
/**
|
|
881
|
+
* Flush buffered telemetry events.
|
|
882
|
+
*
|
|
883
|
+
* In V1 this is a no-op stub. Future versions will send to
|
|
884
|
+
* the Invariance telemetry endpoint.
|
|
885
|
+
*/
|
|
886
|
+
flush(): Promise<void>;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Re-exports and module-specific types for the Identity module.
|
|
891
|
+
*/
|
|
892
|
+
|
|
893
|
+
/** Filters for listing identities */
|
|
894
|
+
interface IdentityListFilters {
|
|
895
|
+
type?: 'agent' | 'human' | 'device' | 'service';
|
|
896
|
+
owner?: string;
|
|
897
|
+
status?: 'active' | 'suspended' | 'deactivated';
|
|
898
|
+
limit?: number;
|
|
899
|
+
offset?: number;
|
|
900
|
+
}
|
|
901
|
+
/** Attestation input (without auto-generated fields) */
|
|
902
|
+
interface AttestationInput {
|
|
903
|
+
claim: string;
|
|
904
|
+
attester: string;
|
|
905
|
+
evidence?: string;
|
|
906
|
+
expiresAt?: number;
|
|
907
|
+
}
|
|
908
|
+
/** Options for updating an identity */
|
|
909
|
+
interface UpdateIdentityOptions {
|
|
910
|
+
label?: string;
|
|
911
|
+
metadata?: Record<string, string>;
|
|
912
|
+
capabilities?: string[];
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Manages identity registration, resolution, and lifecycle.
|
|
917
|
+
*
|
|
918
|
+
* Everything in Invariance is an Identity. An identity is an on-chain entity
|
|
919
|
+
* that can perform actions, hold reputation, and be verified. The identity
|
|
920
|
+
* module replaces the concept of "wallet management" with a universal actor registry.
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* const agent = await inv.identity.register({
|
|
925
|
+
* type: 'agent',
|
|
926
|
+
* owner: '0xDeveloperWallet',
|
|
927
|
+
* label: 'AlphaTrader v2',
|
|
928
|
+
* capabilities: ['swap', 'rebalance'],
|
|
929
|
+
* wallet: { create: true },
|
|
930
|
+
* });
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
933
|
+
declare class IdentityManager {
|
|
934
|
+
private readonly contracts;
|
|
935
|
+
private readonly events;
|
|
936
|
+
private readonly telemetry;
|
|
937
|
+
private indexer;
|
|
938
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
939
|
+
/** Lazily initialize the indexer client */
|
|
940
|
+
private getIndexer;
|
|
941
|
+
/** Map an on-chain identity tuple to the SDK Identity type */
|
|
942
|
+
private mapOnChainIdentity;
|
|
943
|
+
/** Map an on-chain attestation tuple to the SDK Attestation type */
|
|
944
|
+
private mapOnChainAttestation;
|
|
945
|
+
/**
|
|
946
|
+
* Register a new identity (agent, human, device, or service).
|
|
947
|
+
*
|
|
948
|
+
* Creates an on-chain identity record and optionally provisions
|
|
949
|
+
* an embedded wallet via Privy.
|
|
950
|
+
*
|
|
951
|
+
* @param opts - Registration options including type, owner, and label
|
|
952
|
+
* @returns The newly created identity
|
|
953
|
+
*/
|
|
954
|
+
register(opts: RegisterIdentityOptions): Promise<Identity>;
|
|
955
|
+
/**
|
|
956
|
+
* Get identity details by address.
|
|
957
|
+
*
|
|
958
|
+
* @param address - The 0x wallet address of the identity
|
|
959
|
+
* @returns The identity record
|
|
960
|
+
* @throws {InvarianceError} If identity is not found
|
|
961
|
+
*/
|
|
962
|
+
get(address: string): Promise<Identity>;
|
|
963
|
+
/**
|
|
964
|
+
* Resolve an identity by ID, address, or ENS name.
|
|
965
|
+
*
|
|
966
|
+
* @param idOrAddress - Identity ID (bytes32 hex), 0x address, or string ID
|
|
967
|
+
* @returns The resolved identity
|
|
968
|
+
* @throws {InvarianceError} If identity cannot be resolved
|
|
969
|
+
*/
|
|
970
|
+
resolve(idOrAddress: string): Promise<Identity>;
|
|
971
|
+
/**
|
|
972
|
+
* Update identity metadata.
|
|
973
|
+
*
|
|
974
|
+
* @param id - The identity ID to update
|
|
975
|
+
* @param opts - Fields to update (label, metadata, capabilities)
|
|
976
|
+
* @returns The updated identity
|
|
977
|
+
*/
|
|
978
|
+
update(id: string, opts: UpdateIdentityOptions): Promise<Identity>;
|
|
979
|
+
/**
|
|
980
|
+
* EMERGENCY STOP: Freeze an identity.
|
|
981
|
+
*
|
|
982
|
+
* Pausing an identity is the kill switch. One call revokes all active
|
|
983
|
+
* policies, freezes all escrowed funds, and cancels all pending intents.
|
|
984
|
+
* Only the identity owner can call this.
|
|
985
|
+
*
|
|
986
|
+
* @param id - The identity ID to pause
|
|
987
|
+
* @returns Pause result with counts of affected resources
|
|
988
|
+
*/
|
|
989
|
+
pause(id: string): Promise<PauseResult>;
|
|
990
|
+
/**
|
|
991
|
+
* Resume a paused identity.
|
|
992
|
+
*
|
|
993
|
+
* Reactivates the identity. Policies must be re-attached manually
|
|
994
|
+
* as a safety measure. Escrows unfreeze but require fresh approval.
|
|
995
|
+
*
|
|
996
|
+
* @param id - The identity ID to resume
|
|
997
|
+
* @returns Transaction receipt
|
|
998
|
+
*/
|
|
999
|
+
resume(id: string): Promise<TxReceipt$2>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Permanently deactivate an identity.
|
|
1002
|
+
*
|
|
1003
|
+
* This is irreversible. All policies are revoked and escrows are refunded.
|
|
1004
|
+
*
|
|
1005
|
+
* @param id - The identity ID to deactivate
|
|
1006
|
+
* @returns Transaction receipt
|
|
1007
|
+
*/
|
|
1008
|
+
deactivate(id: string): Promise<TxReceipt$2>;
|
|
1009
|
+
/**
|
|
1010
|
+
* List identities by type, owner, or status.
|
|
1011
|
+
*
|
|
1012
|
+
* Attempts the indexer API first, falls back to on-chain reads.
|
|
1013
|
+
*
|
|
1014
|
+
* @param filters - Optional filters to narrow results
|
|
1015
|
+
* @returns Array of matching identities
|
|
1016
|
+
*/
|
|
1017
|
+
list(filters?: IdentityListFilters): Promise<Identity[]>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Add an attestation to an identity.
|
|
1020
|
+
*
|
|
1021
|
+
* Attestations are claims made by third parties about an identity,
|
|
1022
|
+
* stored on-chain with optional evidence hashes.
|
|
1023
|
+
*
|
|
1024
|
+
* @param id - The identity ID to attest
|
|
1025
|
+
* @param attestation - The attestation details
|
|
1026
|
+
* @returns The created attestation record
|
|
1027
|
+
*/
|
|
1028
|
+
attest(id: string, attestation: AttestationInput): Promise<Attestation>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Get all attestations for an identity.
|
|
1031
|
+
*
|
|
1032
|
+
* @param id - The identity ID
|
|
1033
|
+
* @returns Array of attestation records
|
|
1034
|
+
*/
|
|
1035
|
+
attestations(id: string): Promise<Attestation[]>;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
type WalletProvider = 'coinbase-wallet' | 'coinbase-smart-wallet' | 'metamask' | 'walletconnect' | 'privy' | 'dynamic' | 'turnkey' | 'safe' | 'ledger' | 'raw' | 'custom';
|
|
1039
|
+
interface WalletInfo {
|
|
1040
|
+
address: string;
|
|
1041
|
+
provider: WalletProvider;
|
|
1042
|
+
chainId: number;
|
|
1043
|
+
connected: boolean;
|
|
1044
|
+
isSmartAccount: boolean;
|
|
1045
|
+
identityId?: string | undefined;
|
|
1046
|
+
}
|
|
1047
|
+
interface BalanceInfo {
|
|
1048
|
+
usdc: string;
|
|
1049
|
+
eth: string;
|
|
1050
|
+
address: string;
|
|
1051
|
+
}
|
|
1052
|
+
interface FundOptions {
|
|
1053
|
+
amount: string;
|
|
1054
|
+
token?: 'USDC' | undefined;
|
|
1055
|
+
}
|
|
1056
|
+
interface CreateWalletOptions {
|
|
1057
|
+
provider?: WalletProvider | undefined;
|
|
1058
|
+
label?: string | undefined;
|
|
1059
|
+
chainType?: string | undefined;
|
|
1060
|
+
}
|
|
1061
|
+
interface ConnectOptions {
|
|
1062
|
+
provider?: WalletProvider | undefined;
|
|
1063
|
+
chainId?: number | undefined;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
/**
|
|
1067
|
+
* Handles wallet management for all identity types.
|
|
1068
|
+
*
|
|
1069
|
+
* Accepts any wallet type: viem Account, WalletClient, EIP-1193 provider,
|
|
1070
|
+
* or custom InvarianceSigner. Normalizes to viem WalletClient internally.
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```typescript
|
|
1074
|
+
* const inv = new Invariance({
|
|
1075
|
+
* chain: 'base',
|
|
1076
|
+
* signer: privateKeyToAccount('0x...'),
|
|
1077
|
+
* });
|
|
1078
|
+
* const balance = await inv.wallet.balance();
|
|
1079
|
+
* ```
|
|
1080
|
+
*/
|
|
1081
|
+
declare class WalletManager {
|
|
1082
|
+
private readonly contracts;
|
|
1083
|
+
private readonly telemetry;
|
|
1084
|
+
private readonly config;
|
|
1085
|
+
private walletClient;
|
|
1086
|
+
private publicClient;
|
|
1087
|
+
private address;
|
|
1088
|
+
private detectedProvider;
|
|
1089
|
+
constructor(contracts: ContractFactory, telemetry: Telemetry, config: InvarianceConfig);
|
|
1090
|
+
/**
|
|
1091
|
+
* Initialize from a signer provided in config.
|
|
1092
|
+
* Detects type and normalizes to viem WalletClient.
|
|
1093
|
+
*/
|
|
1094
|
+
initFromSigner(signer: unknown, rpcUrl: string, chain: Chain): Promise<void>;
|
|
1095
|
+
private isViemAccount;
|
|
1096
|
+
private isWalletClient;
|
|
1097
|
+
private isEIP1193Provider;
|
|
1098
|
+
private isInvarianceSigner;
|
|
1099
|
+
private isPrivyWallet;
|
|
1100
|
+
private requireWallet;
|
|
1101
|
+
private requirePublicClient;
|
|
1102
|
+
/** Get the wallet address */
|
|
1103
|
+
getAddress(): `0x${string}`;
|
|
1104
|
+
/** Get the underlying viem WalletClient */
|
|
1105
|
+
getWalletClient(): WalletClient;
|
|
1106
|
+
/** Get the public client for read operations */
|
|
1107
|
+
getPublicClient(): PublicClient;
|
|
1108
|
+
/** Check if a wallet is connected */
|
|
1109
|
+
isConnected(): boolean;
|
|
1110
|
+
/**
|
|
1111
|
+
* Create an embedded wallet using Privy.
|
|
1112
|
+
* Requires Privy configuration in InvarianceConfig: { privy: { appId, appSecret } }
|
|
1113
|
+
* @param _opts - Optional wallet creation options
|
|
1114
|
+
*/
|
|
1115
|
+
create(_opts?: CreateWalletOptions): Promise<WalletInfo>;
|
|
1116
|
+
/** Get the current wallet info */
|
|
1117
|
+
get(): Promise<WalletInfo>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Send USDC or ETH to a wallet address.
|
|
1120
|
+
* WARNING: This method executes transfers immediately without confirmation prompts.
|
|
1121
|
+
* The caller is responsible for implementing any necessary security checks.
|
|
1122
|
+
* @param address - The recipient address
|
|
1123
|
+
* @param opts - Fund options including amount and token type (defaults to USDC)
|
|
1124
|
+
*/
|
|
1125
|
+
fund(address: string, opts: FundOptions): Promise<TxReceipt$2>;
|
|
1126
|
+
/**
|
|
1127
|
+
* Get USDC and ETH balances for an address.
|
|
1128
|
+
* @param address - The address to check (defaults to current wallet)
|
|
1129
|
+
*/
|
|
1130
|
+
balance(address?: string | undefined): Promise<BalanceInfo>;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* The Intent Protocol is the heart of Invariance.
|
|
1135
|
+
*
|
|
1136
|
+
* Every verified action follows the same four-step handshake:
|
|
1137
|
+
* **Request -> Approve -> Execute -> Verify**.
|
|
1138
|
+
*
|
|
1139
|
+
* The proof generated at the end looks identical regardless of who
|
|
1140
|
+
* performed the action (agent, human, or device).
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```typescript
|
|
1144
|
+
* const trade = await inv.intent.request({
|
|
1145
|
+
* actor: { type: 'agent', address: '0xTradingBot' },
|
|
1146
|
+
* action: 'swap',
|
|
1147
|
+
* params: { from: 'USDC', to: 'ETH', amount: '100' },
|
|
1148
|
+
* approval: 'auto',
|
|
1149
|
+
* });
|
|
1150
|
+
* console.log(trade.explorerUrl);
|
|
1151
|
+
* ```
|
|
1152
|
+
*/
|
|
1153
|
+
declare class IntentProtocol {
|
|
1154
|
+
private readonly contracts;
|
|
1155
|
+
private readonly events;
|
|
1156
|
+
private readonly telemetry;
|
|
1157
|
+
private indexer;
|
|
1158
|
+
private x402;
|
|
1159
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
1160
|
+
/** Lazily initialize the X402 manager */
|
|
1161
|
+
private getX402Manager;
|
|
1162
|
+
/** Lazily initialize the indexer client */
|
|
1163
|
+
private getIndexer;
|
|
1164
|
+
/**
|
|
1165
|
+
* Full intent handshake: request, approve, execute, verify.
|
|
1166
|
+
*
|
|
1167
|
+
* This is the primary method for performing verified actions.
|
|
1168
|
+
* The approval method determines how the intent is approved:
|
|
1169
|
+
* - 'auto': Policy engine auto-approves (for agents)
|
|
1170
|
+
* - 'wallet-signature': Requires wallet signature (for humans)
|
|
1171
|
+
* - 'multi-sig': M-of-N approval required
|
|
1172
|
+
*
|
|
1173
|
+
* @param opts - Intent request options
|
|
1174
|
+
* @returns The completed intent result with proof bundle
|
|
1175
|
+
*/
|
|
1176
|
+
request(opts: IntentRequestOptions): Promise<IntentResult>;
|
|
1177
|
+
/**
|
|
1178
|
+
* Single-transaction atomic verification using CompactLedger + AtomicVerifier.
|
|
1179
|
+
*
|
|
1180
|
+
* Collapses identity check + policy evaluation + ledger log into one tx.
|
|
1181
|
+
* ~86% gas reduction compared to the full intent handshake.
|
|
1182
|
+
*
|
|
1183
|
+
* @param opts - Intent request options
|
|
1184
|
+
* @returns The completed intent result with proof bundle
|
|
1185
|
+
*/
|
|
1186
|
+
requestAtomic(opts: IntentRequestOptions): Promise<IntentResult>;
|
|
1187
|
+
/**
|
|
1188
|
+
* Prepare an intent without executing (dry-run).
|
|
1189
|
+
*
|
|
1190
|
+
* Useful for checking if an intent would succeed, estimating gas,
|
|
1191
|
+
* and previewing policy evaluations before committing.
|
|
1192
|
+
*
|
|
1193
|
+
* @param opts - Intent request options
|
|
1194
|
+
* @returns Prepared intent with policy checks and gas estimate
|
|
1195
|
+
*/
|
|
1196
|
+
prepare(opts: IntentRequestOptions): Promise<PreparedIntent>;
|
|
1197
|
+
/**
|
|
1198
|
+
* Manually approve a pending intent.
|
|
1199
|
+
*
|
|
1200
|
+
* Used when an intent requires wallet signature or multi-sig approval
|
|
1201
|
+
* and the signer wants to approve it explicitly.
|
|
1202
|
+
*
|
|
1203
|
+
* @param intentId - The intent to approve
|
|
1204
|
+
* @returns Approval result with threshold status
|
|
1205
|
+
*/
|
|
1206
|
+
approve(intentId: string): Promise<ApprovalResult>;
|
|
1207
|
+
/**
|
|
1208
|
+
* Reject a pending intent.
|
|
1209
|
+
*
|
|
1210
|
+
* @param intentId - The intent to reject
|
|
1211
|
+
* @param reason - Optional reason for rejection
|
|
1212
|
+
* @returns Transaction receipt
|
|
1213
|
+
*/
|
|
1214
|
+
reject(intentId: string, reason?: string): Promise<TxReceipt$2>;
|
|
1215
|
+
/**
|
|
1216
|
+
* Check the lifecycle status of an intent.
|
|
1217
|
+
*
|
|
1218
|
+
* @param intentId - The intent to check
|
|
1219
|
+
* @returns Current intent status with approval details
|
|
1220
|
+
*/
|
|
1221
|
+
status(intentId: string): Promise<IntentStatus>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Request an intent with automatic retry on transient failures.
|
|
1224
|
+
*
|
|
1225
|
+
* Retries on NETWORK_ERROR, RPC_ERROR, and TIMEOUT by default.
|
|
1226
|
+
* Uses exponential backoff between attempts.
|
|
1227
|
+
*
|
|
1228
|
+
* @param opts - Intent request options
|
|
1229
|
+
* @param retryConfig - Retry behavior configuration
|
|
1230
|
+
* @returns Result with attempt history
|
|
1231
|
+
*
|
|
1232
|
+
* @example
|
|
1233
|
+
* ```typescript
|
|
1234
|
+
* const result = await inv.intent.requestWithRetry(
|
|
1235
|
+
* { actor, action: 'swap', params, approval: 'auto' },
|
|
1236
|
+
* { maxAttempts: 3, initialDelayMs: 1000, backoffMultiplier: 2 }
|
|
1237
|
+
* );
|
|
1238
|
+
* ```
|
|
1239
|
+
*/
|
|
1240
|
+
requestWithRetry(opts: IntentRequestOptions, retryConfig?: RetryConfig): Promise<RetryResult>;
|
|
1241
|
+
/**
|
|
1242
|
+
* Query intent history with filters.
|
|
1243
|
+
*
|
|
1244
|
+
* @param filters - Optional filters for actor, action, status, time range
|
|
1245
|
+
* @returns Array of completed intent results
|
|
1246
|
+
*/
|
|
1247
|
+
history(filters?: IntentHistoryFilters): Promise<IntentResult[]>;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Composable, verifiable condition sets for action control.
|
|
1252
|
+
*
|
|
1253
|
+
* The Policy Engine replaces simple permissions with composable, verifiable
|
|
1254
|
+
* condition sets. A policy is a set of rules: can I do this, under these
|
|
1255
|
+
* conditions, with these constraints, verified by these parties?
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```typescript
|
|
1259
|
+
* const policy = await inv.policy.create({
|
|
1260
|
+
* name: 'Daily Trading Limits',
|
|
1261
|
+
* actor: 'agent',
|
|
1262
|
+
* rules: [
|
|
1263
|
+
* { type: 'max-spend', config: { limit: '1000', period: '24h' } },
|
|
1264
|
+
* { type: 'action-whitelist', config: { actions: ['swap'] } },
|
|
1265
|
+
* ],
|
|
1266
|
+
* });
|
|
1267
|
+
* await inv.policy.attach(policy.policyId, agent.identityId);
|
|
1268
|
+
* ```
|
|
1269
|
+
*/
|
|
1270
|
+
declare class PolicyEngine {
|
|
1271
|
+
private readonly contracts;
|
|
1272
|
+
private readonly events;
|
|
1273
|
+
private readonly telemetry;
|
|
1274
|
+
private indexer;
|
|
1275
|
+
private x402;
|
|
1276
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
1277
|
+
/** Lazily initialize the X402 manager */
|
|
1278
|
+
private getX402Manager;
|
|
1279
|
+
/** Lazily initialize the indexer client */
|
|
1280
|
+
private getIndexer;
|
|
1281
|
+
/** Map an on-chain policy tuple to the SDK SpecPolicy type */
|
|
1282
|
+
private mapOnChainPolicy;
|
|
1283
|
+
/** Get the contract address for the policy module */
|
|
1284
|
+
getContractAddress(): string;
|
|
1285
|
+
/**
|
|
1286
|
+
* Create a new policy.
|
|
1287
|
+
*
|
|
1288
|
+
* Policies are registered on-chain and can be attached to one or more
|
|
1289
|
+
* identities. They support composable rules including spending limits,
|
|
1290
|
+
* time windows, action whitelists, and custom evaluators.
|
|
1291
|
+
*
|
|
1292
|
+
* @param opts - Policy creation options
|
|
1293
|
+
* @returns The created policy
|
|
1294
|
+
*/
|
|
1295
|
+
create(opts: CreatePolicyOptions): Promise<SpecPolicy>;
|
|
1296
|
+
/**
|
|
1297
|
+
* Attach a policy to an identity.
|
|
1298
|
+
*
|
|
1299
|
+
* Once attached, all actions by this identity will be evaluated
|
|
1300
|
+
* against the policy rules.
|
|
1301
|
+
*
|
|
1302
|
+
* @param policyId - The policy to attach
|
|
1303
|
+
* @param identityId - The identity to attach it to
|
|
1304
|
+
* @returns Transaction receipt
|
|
1305
|
+
*/
|
|
1306
|
+
attach(policyId: string, identityId: string): Promise<TxReceipt$2>;
|
|
1307
|
+
/**
|
|
1308
|
+
* Remove a policy from an identity.
|
|
1309
|
+
*
|
|
1310
|
+
* @param policyId - The policy to detach
|
|
1311
|
+
* @param identityId - The identity to detach it from
|
|
1312
|
+
* @returns Transaction receipt
|
|
1313
|
+
*/
|
|
1314
|
+
detach(policyId: string, identityId: string): Promise<TxReceipt$2>;
|
|
1315
|
+
/**
|
|
1316
|
+
* Check policy state and usage statistics.
|
|
1317
|
+
*
|
|
1318
|
+
* @param policyId - The policy to check
|
|
1319
|
+
* @returns Extended policy status with usage metrics
|
|
1320
|
+
*/
|
|
1321
|
+
status(policyId: string): Promise<PolicyStatus>;
|
|
1322
|
+
/**
|
|
1323
|
+
* List policies by identity, type, or status.
|
|
1324
|
+
*
|
|
1325
|
+
* @param filters - Optional filters
|
|
1326
|
+
* @returns Array of matching policies
|
|
1327
|
+
*/
|
|
1328
|
+
list(filters?: PolicyListFilters): Promise<SpecPolicy[]>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Evaluate an action against a policy without executing.
|
|
1331
|
+
*
|
|
1332
|
+
* Returns detailed rule-by-rule evaluation results, remaining
|
|
1333
|
+
* budgets, and compliance proof if all rules pass.
|
|
1334
|
+
*
|
|
1335
|
+
* @param opts - Evaluation options (policy, actor, action)
|
|
1336
|
+
* @returns Detailed evaluation result per rule
|
|
1337
|
+
*/
|
|
1338
|
+
evaluate(opts: EvaluateOptions): Promise<EvaluationResult>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Revoke a policy entirely.
|
|
1341
|
+
*
|
|
1342
|
+
* Once revoked, the policy cannot be re-activated. All identities
|
|
1343
|
+
* with this policy attached will have it automatically detached.
|
|
1344
|
+
*
|
|
1345
|
+
* @param policyId - The policy to revoke
|
|
1346
|
+
* @returns Transaction receipt
|
|
1347
|
+
*/
|
|
1348
|
+
revoke(policyId: string): Promise<TxReceipt$2>;
|
|
1349
|
+
/**
|
|
1350
|
+
* Combine multiple policies into one composite policy.
|
|
1351
|
+
*
|
|
1352
|
+
* The composed policy evaluates all constituent rules. An action
|
|
1353
|
+
* must pass ALL rules from ALL composed policies to be allowed.
|
|
1354
|
+
*
|
|
1355
|
+
* @param policyIds - Array of policy IDs to compose
|
|
1356
|
+
* @returns The new composite policy
|
|
1357
|
+
*/
|
|
1358
|
+
compose(policyIds: string[]): Promise<SpecPolicy>;
|
|
1359
|
+
/**
|
|
1360
|
+
* Create a policy from a pre-built template.
|
|
1361
|
+
*
|
|
1362
|
+
* @param templateName - Name of the template (e.g. 'defi-trading')
|
|
1363
|
+
* @param overrides - Optional overrides for expiry, actor, or additional rules
|
|
1364
|
+
* @returns The created policy
|
|
1365
|
+
*
|
|
1366
|
+
* @example
|
|
1367
|
+
* ```typescript
|
|
1368
|
+
* const policy = await inv.policy.fromTemplate('defi-trading', { expiry: '2025-12-31' });
|
|
1369
|
+
* ```
|
|
1370
|
+
*/
|
|
1371
|
+
fromTemplate(templateName: string, overrides?: {
|
|
1372
|
+
expiry?: string;
|
|
1373
|
+
actor?: _invariance_common.ActorType | _invariance_common.ActorType[];
|
|
1374
|
+
additionalRules?: _invariance_common.PolicyRule[];
|
|
1375
|
+
}): Promise<SpecPolicy>;
|
|
1376
|
+
/**
|
|
1377
|
+
* Register a custom policy template.
|
|
1378
|
+
*
|
|
1379
|
+
* @param name - Template name
|
|
1380
|
+
* @param template - Template definition with description and rules
|
|
1381
|
+
*
|
|
1382
|
+
* @example
|
|
1383
|
+
* ```typescript
|
|
1384
|
+
* inv.policy.defineTemplate('my-custom', {
|
|
1385
|
+
* description: 'Custom policy for my use case',
|
|
1386
|
+
* rules: [{ type: 'max-spend', config: { amount: '500' } }],
|
|
1387
|
+
* });
|
|
1388
|
+
* ```
|
|
1389
|
+
*/
|
|
1390
|
+
defineTemplate(name: string, template: Omit<PolicyTemplate, 'name' | 'builtin'>): void;
|
|
1391
|
+
/**
|
|
1392
|
+
* List all available policy templates (built-in + custom).
|
|
1393
|
+
*
|
|
1394
|
+
* @returns Array of template metadata
|
|
1395
|
+
*/
|
|
1396
|
+
listTemplates(): Array<{
|
|
1397
|
+
name: string;
|
|
1398
|
+
description: string;
|
|
1399
|
+
builtin: boolean;
|
|
1400
|
+
}>;
|
|
1401
|
+
/**
|
|
1402
|
+
* Subscribe to policy violations in real-time.
|
|
1403
|
+
*
|
|
1404
|
+
* @param policyId - The policy to monitor
|
|
1405
|
+
* @param callback - Called when a violation occurs
|
|
1406
|
+
* @returns Unsubscribe function
|
|
1407
|
+
*/
|
|
1408
|
+
onViolation(policyId: string, callback: PolicyViolationCallback): Unsubscribe;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
/** Filters for listing escrows */
|
|
1412
|
+
interface EscrowListFilters {
|
|
1413
|
+
depositor?: string;
|
|
1414
|
+
recipient?: string;
|
|
1415
|
+
state?: _invariance_common.EscrowState;
|
|
1416
|
+
limit?: number;
|
|
1417
|
+
offset?: number;
|
|
1418
|
+
}
|
|
1419
|
+
/** Callback for escrow state change events */
|
|
1420
|
+
type EscrowStateChangeCallback = (change: {
|
|
1421
|
+
escrowId: string;
|
|
1422
|
+
previousState: _invariance_common.EscrowState;
|
|
1423
|
+
newState: _invariance_common.EscrowState;
|
|
1424
|
+
txHash: string;
|
|
1425
|
+
timestamp: number;
|
|
1426
|
+
}) => void;
|
|
1427
|
+
/** Options for releasing escrow funds */
|
|
1428
|
+
interface ReleaseOptions {
|
|
1429
|
+
/** Optional linked intent ID for automatic release verification */
|
|
1430
|
+
intentId?: string;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/**
|
|
1434
|
+
* USDC escrow with multi-sig, conditional release.
|
|
1435
|
+
*
|
|
1436
|
+
* Escrow is the payment primitive for any verified interaction.
|
|
1437
|
+
* Lock USDC, define release conditions, and funds only move when
|
|
1438
|
+
* conditions are cryptographically confirmed.
|
|
1439
|
+
*
|
|
1440
|
+
* @example
|
|
1441
|
+
* ```typescript
|
|
1442
|
+
* const escrow = await inv.escrow.create({
|
|
1443
|
+
* amount: '250.00',
|
|
1444
|
+
* recipient: { type: 'agent', address: '0xContentBot' },
|
|
1445
|
+
* conditions: { type: 'task-completion', timeout: '48h', arbiter: '0xPlatform' },
|
|
1446
|
+
* autoFund: true,
|
|
1447
|
+
* });
|
|
1448
|
+
* ```
|
|
1449
|
+
*/
|
|
1450
|
+
declare class EscrowManager {
|
|
1451
|
+
private readonly contracts;
|
|
1452
|
+
private readonly events;
|
|
1453
|
+
private readonly telemetry;
|
|
1454
|
+
private indexer;
|
|
1455
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
1456
|
+
/** Lazily initialize the indexer client */
|
|
1457
|
+
private getIndexer;
|
|
1458
|
+
/** Get the contract address for the escrow module */
|
|
1459
|
+
getContractAddress(): string;
|
|
1460
|
+
/**
|
|
1461
|
+
* Parse timeout string (e.g., '48h', '7d') to seconds.
|
|
1462
|
+
*
|
|
1463
|
+
* @param timeout - The timeout string
|
|
1464
|
+
* @returns Timeout in seconds
|
|
1465
|
+
*/
|
|
1466
|
+
private parseTimeout;
|
|
1467
|
+
/**
|
|
1468
|
+
* Resolve an identity ID to its actor type by querying the identity contract.
|
|
1469
|
+
*
|
|
1470
|
+
* @param identityId - The on-chain identity ID (bytes32)
|
|
1471
|
+
* @returns The actor type string
|
|
1472
|
+
*/
|
|
1473
|
+
private resolveActorType;
|
|
1474
|
+
/** Map an on-chain escrow tuple to the SDK EscrowContract type */
|
|
1475
|
+
private mapOnChainEscrow;
|
|
1476
|
+
/**
|
|
1477
|
+
* Deploy a new escrow contract on Base.
|
|
1478
|
+
*
|
|
1479
|
+
* Creates an escrow with specified conditions: single-arbiter,
|
|
1480
|
+
* multi-sig, intent-linked, or milestone-based release.
|
|
1481
|
+
*
|
|
1482
|
+
* @param opts - Escrow creation options
|
|
1483
|
+
* @returns The deployed escrow contract details
|
|
1484
|
+
*/
|
|
1485
|
+
create(opts: CreateEscrowOptions): Promise<EscrowContract>;
|
|
1486
|
+
/**
|
|
1487
|
+
* Fund an escrow with USDC.
|
|
1488
|
+
*
|
|
1489
|
+
* This uses a two-step ERC20 approval flow:
|
|
1490
|
+
* 1. Approve the escrow contract to spend USDC
|
|
1491
|
+
* 2. Call fund() to transfer USDC to the escrow
|
|
1492
|
+
*
|
|
1493
|
+
* @param escrowId - The escrow to fund
|
|
1494
|
+
* @returns Transaction receipt
|
|
1495
|
+
*/
|
|
1496
|
+
fund(escrowId: string): Promise<TxReceipt$2>;
|
|
1497
|
+
/**
|
|
1498
|
+
* Release escrow funds to recipient.
|
|
1499
|
+
*
|
|
1500
|
+
* @param escrowId - The escrow to release
|
|
1501
|
+
* @param opts - Optional release options
|
|
1502
|
+
* @returns Transaction receipt
|
|
1503
|
+
*/
|
|
1504
|
+
release(escrowId: string, _opts?: ReleaseOptions): Promise<TxReceipt$2>;
|
|
1505
|
+
/**
|
|
1506
|
+
* Refund escrow to depositor.
|
|
1507
|
+
*
|
|
1508
|
+
* @param escrowId - The escrow to refund
|
|
1509
|
+
* @returns Transaction receipt
|
|
1510
|
+
*/
|
|
1511
|
+
refund(escrowId: string): Promise<TxReceipt$2>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Open a dispute on an escrow.
|
|
1514
|
+
*
|
|
1515
|
+
* @param escrowId - The escrow to dispute
|
|
1516
|
+
* @param reason - Reason for the dispute
|
|
1517
|
+
* @returns Transaction receipt
|
|
1518
|
+
*/
|
|
1519
|
+
dispute(escrowId: string, reason: string): Promise<TxReceipt$2>;
|
|
1520
|
+
/**
|
|
1521
|
+
* Resolve a dispute (arbiter only).
|
|
1522
|
+
*
|
|
1523
|
+
* Transfers funds to either beneficiary or depositor based on resolution.
|
|
1524
|
+
*
|
|
1525
|
+
* @param escrowId - The disputed escrow
|
|
1526
|
+
* @param opts - Resolution options
|
|
1527
|
+
* @returns Transaction receipt
|
|
1528
|
+
*/
|
|
1529
|
+
resolve(escrowId: string, opts: ResolveOptions): Promise<TxReceipt$2>;
|
|
1530
|
+
/**
|
|
1531
|
+
* Approve escrow release (multi-sig signer).
|
|
1532
|
+
*
|
|
1533
|
+
* Each signer calls this independently. When the threshold is met,
|
|
1534
|
+
* funds can be released.
|
|
1535
|
+
*
|
|
1536
|
+
* @param escrowId - The escrow to approve
|
|
1537
|
+
* @returns Approval result with threshold status
|
|
1538
|
+
*/
|
|
1539
|
+
approve(escrowId: string): Promise<ApprovalResult>;
|
|
1540
|
+
/**
|
|
1541
|
+
* Check multi-sig approval status.
|
|
1542
|
+
*
|
|
1543
|
+
* @param escrowId - The escrow to check
|
|
1544
|
+
* @returns Approval status with signer details
|
|
1545
|
+
*/
|
|
1546
|
+
approvals(escrowId: string): Promise<ApprovalStatus>;
|
|
1547
|
+
/**
|
|
1548
|
+
* Get the current state of an escrow.
|
|
1549
|
+
*
|
|
1550
|
+
* @param escrowId - The escrow to check
|
|
1551
|
+
* @returns Extended escrow status with time remaining and approvals
|
|
1552
|
+
*/
|
|
1553
|
+
status(escrowId: string): Promise<EscrowStatus>;
|
|
1554
|
+
/**
|
|
1555
|
+
* List escrows by identity, state, or role.
|
|
1556
|
+
*
|
|
1557
|
+
* Attempts the indexer API first, falls back to on-chain reads.
|
|
1558
|
+
*
|
|
1559
|
+
* @param filters - Optional filters
|
|
1560
|
+
* @returns Array of matching escrow contracts
|
|
1561
|
+
*/
|
|
1562
|
+
list(filters?: EscrowListFilters): Promise<EscrowContract[]>;
|
|
1563
|
+
/**
|
|
1564
|
+
* Subscribe to escrow state changes in real-time.
|
|
1565
|
+
*
|
|
1566
|
+
* @param escrowId - The escrow to monitor
|
|
1567
|
+
* @param callback - Called when the escrow state changes
|
|
1568
|
+
* @returns Unsubscribe function
|
|
1569
|
+
*/
|
|
1570
|
+
onStateChange(escrowId: string, callback: EscrowStateChangeCallback): Unsubscribe;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
/**
|
|
1574
|
+
* Semantic analytics helpers for common ledger query patterns.
|
|
1575
|
+
*
|
|
1576
|
+
* @example
|
|
1577
|
+
* ```typescript
|
|
1578
|
+
* const rate = await inv.ledger.analytics.successRate('0xBot', { from: '2025-01-01' });
|
|
1579
|
+
* const costs = await inv.ledger.analytics.costSummary('0xBot', { from: '2025-01-01' });
|
|
1580
|
+
* ```
|
|
1581
|
+
*/
|
|
1582
|
+
|
|
1583
|
+
/**
|
|
1584
|
+
* Analytics layer on top of the Event Ledger.
|
|
1585
|
+
*/
|
|
1586
|
+
declare class LedgerAnalytics {
|
|
1587
|
+
private readonly ledger;
|
|
1588
|
+
constructor(ledger: EventLedger);
|
|
1589
|
+
/**
|
|
1590
|
+
* Calculate the success rate for an actor's actions.
|
|
1591
|
+
*
|
|
1592
|
+
* @param actor - Actor address
|
|
1593
|
+
* @param timeframe - Optional time range filter
|
|
1594
|
+
* @returns Success rate as a ratio and percentage
|
|
1595
|
+
*/
|
|
1596
|
+
successRate(actor: string, timeframe?: AnalyticsTimeframe): Promise<SuccessRateResult>;
|
|
1597
|
+
/**
|
|
1598
|
+
* Count occurrences of a specific action for an actor.
|
|
1599
|
+
*
|
|
1600
|
+
* @param actor - Actor address
|
|
1601
|
+
* @param action - Action name to count
|
|
1602
|
+
* @param timeframe - Optional time range filter
|
|
1603
|
+
* @returns Count and breakdown by category
|
|
1604
|
+
*/
|
|
1605
|
+
actionCount(actor: string, action: string, timeframe?: AnalyticsTimeframe): Promise<ActionCountResult>;
|
|
1606
|
+
/**
|
|
1607
|
+
* Summarize costs/spending for an actor.
|
|
1608
|
+
*
|
|
1609
|
+
* @param actor - Actor address
|
|
1610
|
+
* @param timeframe - Optional time range filter
|
|
1611
|
+
* @returns Cost breakdown by action
|
|
1612
|
+
*/
|
|
1613
|
+
costSummary(actor: string, timeframe?: AnalyticsTimeframe): Promise<CostSummaryResult>;
|
|
1614
|
+
/**
|
|
1615
|
+
* Query policy violations for an actor.
|
|
1616
|
+
*
|
|
1617
|
+
* @param actor - Actor address
|
|
1618
|
+
* @param timeframe - Optional time range filter
|
|
1619
|
+
* @returns List of violations with details
|
|
1620
|
+
*/
|
|
1621
|
+
violations(actor: string, timeframe?: AnalyticsTimeframe): Promise<ViolationResult>;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
/**
|
|
1625
|
+
* Immutable on-chain logging with dual signatures.
|
|
1626
|
+
*
|
|
1627
|
+
* The Event Ledger is the single source of truth for all Invariance actions.
|
|
1628
|
+
* Every intent, every escrow state change, every policy evaluation is logged
|
|
1629
|
+
* here with dual signatures. This is a Truth Ledger that produces identical
|
|
1630
|
+
* proof records regardless of actor type.
|
|
1631
|
+
*
|
|
1632
|
+
* @example
|
|
1633
|
+
* ```typescript
|
|
1634
|
+
* const entry = await inv.ledger.log({
|
|
1635
|
+
* action: 'model-inference',
|
|
1636
|
+
* actor: { type: 'agent', address: '0xMyAgent' },
|
|
1637
|
+
* metadata: { model: 'claude-sonnet', latencyMs: 230 },
|
|
1638
|
+
* });
|
|
1639
|
+
* console.log(entry.explorerUrl);
|
|
1640
|
+
* ```
|
|
1641
|
+
*/
|
|
1642
|
+
declare class EventLedger {
|
|
1643
|
+
private readonly contracts;
|
|
1644
|
+
private readonly events;
|
|
1645
|
+
private readonly telemetry;
|
|
1646
|
+
private indexer;
|
|
1647
|
+
private _analytics?;
|
|
1648
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
1649
|
+
/**
|
|
1650
|
+
* Analytics helpers for common ledger query patterns.
|
|
1651
|
+
*
|
|
1652
|
+
* @example
|
|
1653
|
+
* ```typescript
|
|
1654
|
+
* const rate = await inv.ledger.analytics.successRate('0xBot');
|
|
1655
|
+
* ```
|
|
1656
|
+
*/
|
|
1657
|
+
get analytics(): LedgerAnalytics;
|
|
1658
|
+
/** Lazily initialize the indexer client */
|
|
1659
|
+
private getIndexer;
|
|
1660
|
+
/** Get the contract address for the ledger module */
|
|
1661
|
+
getContractAddress(): string;
|
|
1662
|
+
/**
|
|
1663
|
+
* Log a custom event on-chain.
|
|
1664
|
+
*
|
|
1665
|
+
* Creates an immutable ledger entry with dual signatures (actor + platform),
|
|
1666
|
+
* metadata hash, and a public explorer URL.
|
|
1667
|
+
*
|
|
1668
|
+
* @param event - The event to log
|
|
1669
|
+
* @returns The created ledger entry with proof bundle
|
|
1670
|
+
*/
|
|
1671
|
+
log(event: LedgerEventInput): Promise<LedgerEntry>;
|
|
1672
|
+
/**
|
|
1673
|
+
* Log multiple events in a single transaction.
|
|
1674
|
+
*
|
|
1675
|
+
* More gas-efficient than individual log() calls when
|
|
1676
|
+
* logging multiple related events.
|
|
1677
|
+
*
|
|
1678
|
+
* @param events - Array of events to log
|
|
1679
|
+
* @returns Array of created ledger entries
|
|
1680
|
+
*/
|
|
1681
|
+
batch(events: LedgerEventInput[]): Promise<LedgerEntry[]>;
|
|
1682
|
+
/**
|
|
1683
|
+
* Query ledger entries by identity, action, or time range.
|
|
1684
|
+
*
|
|
1685
|
+
* @param filters - Query filters (actor, action, category, time range)
|
|
1686
|
+
* @returns Array of matching ledger entries
|
|
1687
|
+
*/
|
|
1688
|
+
query(filters: LedgerQueryFilters): Promise<LedgerEntry[]>;
|
|
1689
|
+
/**
|
|
1690
|
+
* Stream ledger entries in real-time.
|
|
1691
|
+
*
|
|
1692
|
+
* Subscribes to new ledger entries matching the given filters
|
|
1693
|
+
* and invokes the callback for each new entry.
|
|
1694
|
+
*
|
|
1695
|
+
* @param filters - Optional filters for the stream
|
|
1696
|
+
* @param callback - Called for each new matching entry
|
|
1697
|
+
* @returns Unsubscribe function
|
|
1698
|
+
*/
|
|
1699
|
+
stream(filters: LedgerQueryFilters, callback: LedgerStreamCallback): Unsubscribe;
|
|
1700
|
+
/**
|
|
1701
|
+
* Export ledger entries as JSON or CSV.
|
|
1702
|
+
*
|
|
1703
|
+
* @param filters - Query filters to select entries for export
|
|
1704
|
+
* @returns Exported data in the requested format
|
|
1705
|
+
*/
|
|
1706
|
+
export(filters: LedgerQueryFilters): Promise<ExportData>;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Fraud-proof on-chain logging via CompactLedger with EIP-712 dual signatures.
|
|
1711
|
+
*
|
|
1712
|
+
* Unlike the legacy {@link EventLedger}, this module calls `CompactLedger.log(input, actorSig, platformSig)`
|
|
1713
|
+
* where both signatures are verified on-chain via `ECDSA.recover`. This means:
|
|
1714
|
+
* - Actor signature uses EIP-712 `signTypedData` (not `signMessage`)
|
|
1715
|
+
* - Platform signature comes from `/v1/attest` API (API key required)
|
|
1716
|
+
* - The keccak256 fallback is NOT valid — it will revert on-chain
|
|
1717
|
+
*
|
|
1718
|
+
* @example
|
|
1719
|
+
* ```typescript
|
|
1720
|
+
* // Requires API key for platform attestation
|
|
1721
|
+
* const inv = new Invariance({
|
|
1722
|
+
* chain: 'base-sepolia',
|
|
1723
|
+
* signer: wallet,
|
|
1724
|
+
* apiKey: 'inv_live_xxx',
|
|
1725
|
+
* });
|
|
1726
|
+
*
|
|
1727
|
+
* const entry = await inv.ledgerCompact.log({
|
|
1728
|
+
* action: 'model-inference',
|
|
1729
|
+
* actor: { type: 'agent', address: '0xMyAgent' },
|
|
1730
|
+
* metadata: { model: 'claude-sonnet', latencyMs: 230 },
|
|
1731
|
+
* });
|
|
1732
|
+
* ```
|
|
1733
|
+
*/
|
|
1734
|
+
declare class EventLedgerCompact {
|
|
1735
|
+
private readonly contracts;
|
|
1736
|
+
private readonly events;
|
|
1737
|
+
private readonly telemetry;
|
|
1738
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
1739
|
+
/** Get the contract address for the compact ledger module */
|
|
1740
|
+
getContractAddress(): string;
|
|
1741
|
+
/**
|
|
1742
|
+
* Log a fraud-proof event on-chain via CompactLedger.
|
|
1743
|
+
*
|
|
1744
|
+
* Creates an immutable ledger entry with EIP-712 dual signatures (actor + platform)
|
|
1745
|
+
* that are verified on-chain. Requires an API key for platform attestation.
|
|
1746
|
+
*
|
|
1747
|
+
* @param event - The event to log
|
|
1748
|
+
* @returns The created ledger entry with proof bundle
|
|
1749
|
+
* @throws {InvarianceError} If no API key is configured
|
|
1750
|
+
*/
|
|
1751
|
+
log(event: LedgerEventInput): Promise<LedgerEntry>;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* Auto-batching wrapper around CompactLedger that buffers `log()` calls
|
|
1756
|
+
* and flushes them as a single `logBatch()` transaction.
|
|
1757
|
+
*
|
|
1758
|
+
* @example
|
|
1759
|
+
* ```typescript
|
|
1760
|
+
* const batched = inv.ledgerCompactBatched({ maxBatchSize: 10, maxWaitMs: 5000 });
|
|
1761
|
+
* // These 10 calls produce 1 on-chain transaction:
|
|
1762
|
+
* await Promise.all(Array.from({ length: 10 }, (_, i) =>
|
|
1763
|
+
* batched.log({ action: `action-${i}`, actor: { type: 'agent', address: '0x...' } })
|
|
1764
|
+
* ));
|
|
1765
|
+
* ```
|
|
1766
|
+
*/
|
|
1767
|
+
declare class AutoBatchedEventLedgerCompact {
|
|
1768
|
+
private readonly contracts;
|
|
1769
|
+
private readonly events;
|
|
1770
|
+
private readonly telemetry;
|
|
1771
|
+
private readonly maxBatchSize;
|
|
1772
|
+
private readonly maxWaitMs;
|
|
1773
|
+
private readonly enabled;
|
|
1774
|
+
private buffer;
|
|
1775
|
+
private timer;
|
|
1776
|
+
private destroyed;
|
|
1777
|
+
private flushing;
|
|
1778
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry, config?: AutoBatchConfig);
|
|
1779
|
+
/**
|
|
1780
|
+
* Log an event. If batching is enabled, the call is buffered and resolved
|
|
1781
|
+
* when the batch is flushed. If disabled, delegates directly to the single-entry path.
|
|
1782
|
+
*/
|
|
1783
|
+
log(event: LedgerEventInput): Promise<LedgerEntry>;
|
|
1784
|
+
/** Manually flush all buffered entries immediately */
|
|
1785
|
+
flush(): Promise<void>;
|
|
1786
|
+
/** Flush remaining buffer and prevent future calls */
|
|
1787
|
+
destroy(): Promise<void>;
|
|
1788
|
+
/** Get the current number of buffered entries */
|
|
1789
|
+
getBufferSize(): number;
|
|
1790
|
+
private _prepare;
|
|
1791
|
+
private _scheduleFlush;
|
|
1792
|
+
private _clearTimer;
|
|
1793
|
+
private _flush;
|
|
1794
|
+
/** Bypass batching — direct single-entry log */
|
|
1795
|
+
private _logSingle;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
/** Decoded proof data */
|
|
1799
|
+
interface ProofData {
|
|
1800
|
+
proofHash: string;
|
|
1801
|
+
actor: _invariance_common.ActorReference;
|
|
1802
|
+
action: string;
|
|
1803
|
+
timestamp: number;
|
|
1804
|
+
blockNumber: number;
|
|
1805
|
+
signatures: {
|
|
1806
|
+
actor: string;
|
|
1807
|
+
platform?: string;
|
|
1808
|
+
valid: boolean;
|
|
1809
|
+
};
|
|
1810
|
+
metadataHash: string;
|
|
1811
|
+
raw: string;
|
|
1812
|
+
verified: boolean;
|
|
1813
|
+
}
|
|
1814
|
+
/** Options for verifying by actor and action */
|
|
1815
|
+
interface VerifyActionOptions {
|
|
1816
|
+
actor: string;
|
|
1817
|
+
action?: string;
|
|
1818
|
+
from?: string | number;
|
|
1819
|
+
to?: string | number;
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
/**
|
|
1823
|
+
* Cryptographic verification and public explorer URLs.
|
|
1824
|
+
*
|
|
1825
|
+
* Verification is the public-facing proof layer. Any person, any system,
|
|
1826
|
+
* anywhere in the world can verify any Invariance action using a transaction
|
|
1827
|
+
* hash, an identity address, or a public explorer URL.
|
|
1828
|
+
*
|
|
1829
|
+
* The Verifier is special: it is both callable directly as `inv.verify(txHash)`
|
|
1830
|
+
* and has sub-methods like `inv.verify.action()`, `inv.verify.identity()`, etc.
|
|
1831
|
+
*
|
|
1832
|
+
* @example
|
|
1833
|
+
* ```typescript
|
|
1834
|
+
* // Direct call
|
|
1835
|
+
* const result = await inv.verify('0xtxhash...');
|
|
1836
|
+
*
|
|
1837
|
+
* // Sub-methods
|
|
1838
|
+
* const audit = await inv.verify.identity('0xTradingBot');
|
|
1839
|
+
* const url = inv.verify.url('inv_int_abc123');
|
|
1840
|
+
* ```
|
|
1841
|
+
*/
|
|
1842
|
+
declare class Verifier {
|
|
1843
|
+
private readonly contracts;
|
|
1844
|
+
private readonly telemetry;
|
|
1845
|
+
private indexer;
|
|
1846
|
+
constructor(contracts: ContractFactory, _events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
1847
|
+
/** Lazily initialize the indexer client */
|
|
1848
|
+
private getIndexer;
|
|
1849
|
+
/**
|
|
1850
|
+
* Verify a single transaction by hash.
|
|
1851
|
+
*
|
|
1852
|
+
* Retrieves the on-chain proof, validates signatures, and returns
|
|
1853
|
+
* the full verification result with an explorer URL.
|
|
1854
|
+
*
|
|
1855
|
+
* @param txHash - The transaction hash to verify
|
|
1856
|
+
* @returns Verification result with proof and explorer URL
|
|
1857
|
+
*/
|
|
1858
|
+
verify(txHash: string): Promise<VerificationResult>;
|
|
1859
|
+
/**
|
|
1860
|
+
* Verify by actor address and optionally action type and timeframe.
|
|
1861
|
+
*
|
|
1862
|
+
* @param opts - Verification options (actor, action, time range)
|
|
1863
|
+
* @returns Verification result for the matching action
|
|
1864
|
+
*/
|
|
1865
|
+
action(opts: VerifyActionOptions): Promise<VerificationResult>;
|
|
1866
|
+
/**
|
|
1867
|
+
* Full audit of an identity.
|
|
1868
|
+
*
|
|
1869
|
+
* Returns comprehensive verification data including total actions,
|
|
1870
|
+
* verified count, policy history, attestations, and volume.
|
|
1871
|
+
*
|
|
1872
|
+
* @param address - The identity address to audit
|
|
1873
|
+
* @returns Full identity verification audit
|
|
1874
|
+
*/
|
|
1875
|
+
identity(address: string): Promise<IdentityVerification>;
|
|
1876
|
+
/**
|
|
1877
|
+
* Escrow audit trail.
|
|
1878
|
+
*
|
|
1879
|
+
* Returns the complete timeline of an escrow from creation to
|
|
1880
|
+
* final state, with proof bundles for each state transition.
|
|
1881
|
+
*
|
|
1882
|
+
* @param escrowId - The escrow to audit
|
|
1883
|
+
* @returns Escrow verification with full timeline
|
|
1884
|
+
*/
|
|
1885
|
+
escrow(escrowId: string): Promise<EscrowVerification>;
|
|
1886
|
+
/**
|
|
1887
|
+
* Decode and validate a proof by its hash.
|
|
1888
|
+
*
|
|
1889
|
+
* @param proofHash - The proof hash to decode
|
|
1890
|
+
* @returns Decoded proof data with validation status
|
|
1891
|
+
*/
|
|
1892
|
+
proof(proofHash: string): Promise<ProofData>;
|
|
1893
|
+
/**
|
|
1894
|
+
* Batch verify multiple transactions.
|
|
1895
|
+
*
|
|
1896
|
+
* More efficient than calling verify() in a loop when verifying
|
|
1897
|
+
* multiple transactions simultaneously.
|
|
1898
|
+
*
|
|
1899
|
+
* @param txHashes - Array of transaction hashes to verify
|
|
1900
|
+
* @returns Array of verification results (one per hash)
|
|
1901
|
+
*/
|
|
1902
|
+
bulk(txHashes: string[]): Promise<VerificationResult[]>;
|
|
1903
|
+
/**
|
|
1904
|
+
* Verify a CompactLedger commitment hash on-chain.
|
|
1905
|
+
*
|
|
1906
|
+
* Reads the stored commitment from the CompactLedger contract and
|
|
1907
|
+
* optionally reconstructs the expected commitment to compare.
|
|
1908
|
+
*
|
|
1909
|
+
* @param entryId - The entry ID to verify
|
|
1910
|
+
* @param expected - Optional expected values to reconstruct and compare commitment
|
|
1911
|
+
* @returns Whether the commitment exists and matches
|
|
1912
|
+
*/
|
|
1913
|
+
verifyCommitment(entryId: string, expected?: {
|
|
1914
|
+
actorAddress: string;
|
|
1915
|
+
action: string;
|
|
1916
|
+
metadataHash: string;
|
|
1917
|
+
proofHash: string;
|
|
1918
|
+
timestamp: number;
|
|
1919
|
+
}): Promise<{
|
|
1920
|
+
exists: boolean;
|
|
1921
|
+
matches: boolean;
|
|
1922
|
+
commitmentHash: string;
|
|
1923
|
+
}>;
|
|
1924
|
+
/**
|
|
1925
|
+
* Generate a public explorer URL for an intent.
|
|
1926
|
+
*
|
|
1927
|
+
* This URL can be shared publicly. Anyone can open it to
|
|
1928
|
+
* independently verify the action without needing the SDK.
|
|
1929
|
+
*
|
|
1930
|
+
* @param intentId - The intent ID to generate a URL for
|
|
1931
|
+
* @returns The public explorer URL
|
|
1932
|
+
*/
|
|
1933
|
+
url(intentId: string): string;
|
|
1934
|
+
/**
|
|
1935
|
+
* Verify a vote's merkle inclusion in a settled proposal.
|
|
1936
|
+
*
|
|
1937
|
+
* @param proposalId - The proposal ID
|
|
1938
|
+
* @param voter - Voter address
|
|
1939
|
+
* @param support - Vote direction (true = for)
|
|
1940
|
+
* @param weight - Vote weight
|
|
1941
|
+
* @param proof - Merkle proof
|
|
1942
|
+
* @returns Whether the vote is included in the settled merkle root
|
|
1943
|
+
*/
|
|
1944
|
+
verifyVote(proposalId: string, voter: string, support: boolean, weight: bigint, proof: string[]): Promise<boolean>;
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* Single-transaction atomic verifier: identity check + policy eval + compact ledger log.
|
|
1949
|
+
*
|
|
1950
|
+
* Wraps `AtomicVerifier.verifyAndLog()` with the same EIP-712 signing flow
|
|
1951
|
+
* as {@link EventLedgerCompact}. Requires an API key for platform attestation.
|
|
1952
|
+
*
|
|
1953
|
+
* @example
|
|
1954
|
+
* ```typescript
|
|
1955
|
+
* const entry = await inv.atomic.verifyAndLog({
|
|
1956
|
+
* action: 'swap',
|
|
1957
|
+
* actor: { type: 'agent', address: '0xBot' },
|
|
1958
|
+
* metadata: { from: 'USDC', to: 'ETH', amount: '100' },
|
|
1959
|
+
* });
|
|
1960
|
+
* ```
|
|
1961
|
+
*/
|
|
1962
|
+
declare class AtomicVerifier {
|
|
1963
|
+
private readonly contracts;
|
|
1964
|
+
private readonly events;
|
|
1965
|
+
private readonly telemetry;
|
|
1966
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
1967
|
+
/** Get the contract address for the atomic verifier */
|
|
1968
|
+
getContractAddress(): string;
|
|
1969
|
+
/**
|
|
1970
|
+
* Verify identity + evaluate policy + log to CompactLedger in a single transaction.
|
|
1971
|
+
*
|
|
1972
|
+
* @param event - The event to verify and log
|
|
1973
|
+
* @returns The created ledger entry with proof bundle
|
|
1974
|
+
* @throws {InvarianceError} If no API key is configured
|
|
1975
|
+
*/
|
|
1976
|
+
verifyAndLog(event: LedgerEventInput): Promise<LedgerEntry>;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
/** Options for querying reviews */
|
|
1980
|
+
interface ReviewQueryOptions {
|
|
1981
|
+
limit?: number;
|
|
1982
|
+
offset?: number;
|
|
1983
|
+
sortBy?: 'newest' | 'highest' | 'lowest';
|
|
1984
|
+
}
|
|
1985
|
+
/** Paginated review list */
|
|
1986
|
+
interface ReviewList {
|
|
1987
|
+
reviews: _invariance_common.Review[];
|
|
1988
|
+
total: number;
|
|
1989
|
+
page: number;
|
|
1990
|
+
}
|
|
1991
|
+
/** Options for querying score history */
|
|
1992
|
+
interface ScoreHistoryOptions {
|
|
1993
|
+
from?: string | number;
|
|
1994
|
+
to?: string | number;
|
|
1995
|
+
limit?: number;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Auto-calculated reputation scores and 1-5 star reviews.
|
|
2000
|
+
*
|
|
2001
|
+
* Reputation applies to all identity types. The scoring model is identical.
|
|
2002
|
+
* Reviews are 1-5 stars, cryptographically linked to completed escrows.
|
|
2003
|
+
* No escrow = no review. Fake reviews are mathematically impossible.
|
|
2004
|
+
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* ```typescript
|
|
2007
|
+
* const rep = await inv.reputation.get('0xTradingBot');
|
|
2008
|
+
* console.log(rep.scores.overall, rep.scores.tier);
|
|
2009
|
+
*
|
|
2010
|
+
* const review = await inv.reputation.review({
|
|
2011
|
+
* target: '0xTradingBot',
|
|
2012
|
+
* escrowId: 'esc_abc',
|
|
2013
|
+
* rating: 5,
|
|
2014
|
+
* comment: 'Excellent execution',
|
|
2015
|
+
* });
|
|
2016
|
+
* ```
|
|
2017
|
+
*/
|
|
2018
|
+
declare class ReputationEngine {
|
|
2019
|
+
private readonly contracts;
|
|
2020
|
+
private readonly events;
|
|
2021
|
+
private readonly telemetry;
|
|
2022
|
+
private indexer;
|
|
2023
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
2024
|
+
/** Lazily initialize the indexer client */
|
|
2025
|
+
private getIndexer;
|
|
2026
|
+
/** Calculate on-chain metrics for an identity */
|
|
2027
|
+
private calculateOnChainMetrics;
|
|
2028
|
+
/** Calculate overall reputation score */
|
|
2029
|
+
private calculateOverallScore;
|
|
2030
|
+
/** Determine tier from overall score */
|
|
2031
|
+
private determineTier;
|
|
2032
|
+
/** Get the contract address for the review module */
|
|
2033
|
+
getContractAddress(): string;
|
|
2034
|
+
/**
|
|
2035
|
+
* Get full reputation profile for any identity.
|
|
2036
|
+
*
|
|
2037
|
+
* Includes scores, reviews, on-chain metrics, badges, and explorer URL.
|
|
2038
|
+
*
|
|
2039
|
+
* @param address - The identity address
|
|
2040
|
+
* @returns Full reputation profile
|
|
2041
|
+
*/
|
|
2042
|
+
get(address: string): Promise<ReputationProfile>;
|
|
2043
|
+
/**
|
|
2044
|
+
* Submit a 1-5 star review.
|
|
2045
|
+
*
|
|
2046
|
+
* Reviews MUST reference a completed escrow between the reviewer
|
|
2047
|
+
* and the target. This is enforced on-chain. No escrow = no review.
|
|
2048
|
+
*
|
|
2049
|
+
* @param opts - Review options (target, escrowId, rating)
|
|
2050
|
+
* @returns The submitted review
|
|
2051
|
+
* @throws {InvarianceError} With NO_ESCROW_FOR_REVIEW if no qualifying escrow
|
|
2052
|
+
* @throws {InvarianceError} With ALREADY_REVIEWED if already reviewed
|
|
2053
|
+
*/
|
|
2054
|
+
review(opts: SubmitReviewOptions): Promise<Review>;
|
|
2055
|
+
/**
|
|
2056
|
+
* Get all reviews for an identity.
|
|
2057
|
+
*
|
|
2058
|
+
* @param address - The identity address
|
|
2059
|
+
* @param opts - Optional query options (pagination, sorting)
|
|
2060
|
+
* @returns Paginated review list
|
|
2061
|
+
*/
|
|
2062
|
+
getReviews(address: string, opts?: ReviewQueryOptions): Promise<ReviewList>;
|
|
2063
|
+
/**
|
|
2064
|
+
* Get numeric reputation scores only (lighter than full profile).
|
|
2065
|
+
*
|
|
2066
|
+
* @param address - The identity address
|
|
2067
|
+
* @returns Reputation scores
|
|
2068
|
+
*/
|
|
2069
|
+
score(address: string): Promise<ReputationScore>;
|
|
2070
|
+
/**
|
|
2071
|
+
* Compare multiple identities side-by-side.
|
|
2072
|
+
*
|
|
2073
|
+
* Returns ranked comparison with key metrics for each identity.
|
|
2074
|
+
*
|
|
2075
|
+
* @param addresses - Array of identity addresses to compare
|
|
2076
|
+
* @returns Comparison result with rankings
|
|
2077
|
+
*/
|
|
2078
|
+
compare(addresses: string[]): Promise<ComparisonResult>;
|
|
2079
|
+
/**
|
|
2080
|
+
* Get earned badge for an identity.
|
|
2081
|
+
*
|
|
2082
|
+
* Badges are auto-calculated based on on-chain metrics:
|
|
2083
|
+
* - Verified: Has attestations
|
|
2084
|
+
* - Trusted: 50+ verified actions
|
|
2085
|
+
* - Elite: 95%+ policy compliance with 100+ actions
|
|
2086
|
+
*
|
|
2087
|
+
* @param address - The identity address
|
|
2088
|
+
* @returns Badge or null if none earned
|
|
2089
|
+
*/
|
|
2090
|
+
badge(address: string): Promise<Badge | null>;
|
|
2091
|
+
/**
|
|
2092
|
+
* Get score changes over time.
|
|
2093
|
+
*
|
|
2094
|
+
* @param address - The identity address
|
|
2095
|
+
* @param opts - Optional query options (time range, limit)
|
|
2096
|
+
* @returns Score history with entries
|
|
2097
|
+
*/
|
|
2098
|
+
history(address: string, opts?: ScoreHistoryOptions): Promise<ScoreHistory>;
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
/**
|
|
2102
|
+
* Re-exports and module-specific types for the Gas module.
|
|
2103
|
+
*/
|
|
2104
|
+
|
|
2105
|
+
/** Options for gas estimation */
|
|
2106
|
+
interface EstimateGasOptions {
|
|
2107
|
+
action: string;
|
|
2108
|
+
params?: Record<string, unknown>;
|
|
2109
|
+
target?: string;
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
/**
|
|
2113
|
+
* Gas abstraction for Invariance operations.
|
|
2114
|
+
*
|
|
2115
|
+
* Provides gas estimation and balance checking with support for
|
|
2116
|
+
* USDC-based gas abstraction (where users pay gas fees in USDC
|
|
2117
|
+
* instead of ETH).
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```typescript
|
|
2121
|
+
* const estimate = await inv.gas.estimate({ action: 'swap' });
|
|
2122
|
+
* console.log(estimate.usdcCost);
|
|
2123
|
+
*
|
|
2124
|
+
* const balance = await inv.gas.balance();
|
|
2125
|
+
* console.log(balance.canAbstract);
|
|
2126
|
+
* ```
|
|
2127
|
+
*/
|
|
2128
|
+
declare class GasManager {
|
|
2129
|
+
private readonly contracts;
|
|
2130
|
+
private readonly telemetry;
|
|
2131
|
+
constructor(contracts: ContractFactory, _events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
2132
|
+
/**
|
|
2133
|
+
* Estimate gas cost for an action.
|
|
2134
|
+
*
|
|
2135
|
+
* Returns both ETH and USDC costs based on the current gas strategy.
|
|
2136
|
+
*
|
|
2137
|
+
* @param opts - Action details for gas estimation
|
|
2138
|
+
* @returns Gas estimate with ETH and USDC costs
|
|
2139
|
+
*/
|
|
2140
|
+
estimate(opts: EstimateGasOptions): Promise<GasEstimate>;
|
|
2141
|
+
/**
|
|
2142
|
+
* Sponsor a user operation via Coinbase Paymaster on Base.
|
|
2143
|
+
*
|
|
2144
|
+
* Sends the user operation to the paymaster endpoint for gas sponsorship.
|
|
2145
|
+
* Requires `PAYMASTER_URL` and `PAYMASTER_API_KEY` environment variables.
|
|
2146
|
+
*
|
|
2147
|
+
* @param userOp - The user operation to sponsor
|
|
2148
|
+
* @returns The sponsored user operation with paymaster fields filled in
|
|
2149
|
+
*/
|
|
2150
|
+
sponsorUserOperation(userOp: {
|
|
2151
|
+
sender: string;
|
|
2152
|
+
nonce: string;
|
|
2153
|
+
callData: string;
|
|
2154
|
+
callGasLimit: string;
|
|
2155
|
+
verificationGasLimit: string;
|
|
2156
|
+
preVerificationGas: string;
|
|
2157
|
+
maxFeePerGas: string;
|
|
2158
|
+
maxPriorityFeePerGas: string;
|
|
2159
|
+
}): Promise<{
|
|
2160
|
+
paymasterAndData: string;
|
|
2161
|
+
callGasLimit: string;
|
|
2162
|
+
verificationGasLimit: string;
|
|
2163
|
+
preVerificationGas: string;
|
|
2164
|
+
}>;
|
|
2165
|
+
/**
|
|
2166
|
+
* Get gas-related balances for the current wallet.
|
|
2167
|
+
*
|
|
2168
|
+
* Returns ETH and USDC balances and whether gas abstraction
|
|
2169
|
+
* is available (requires sufficient USDC and abstracted strategy).
|
|
2170
|
+
*
|
|
2171
|
+
* @returns Gas balance information
|
|
2172
|
+
*/
|
|
2173
|
+
balance(): Promise<GasBalance>;
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
/**
|
|
2177
|
+
* Types for the x402 payment protocol module.
|
|
2178
|
+
*/
|
|
2179
|
+
/** Options for paying for an action via x402 */
|
|
2180
|
+
interface PayForActionOptions {
|
|
2181
|
+
/** The action being paid for */
|
|
2182
|
+
action: string;
|
|
2183
|
+
/** Payment amount in USDC (decimal string, e.g. '1.50') */
|
|
2184
|
+
amount: string;
|
|
2185
|
+
/** Payment recipient address */
|
|
2186
|
+
recipient: string;
|
|
2187
|
+
/** Identity ID of the payer */
|
|
2188
|
+
identityId?: string;
|
|
2189
|
+
/** x402 facilitator URL */
|
|
2190
|
+
facilitatorUrl?: string;
|
|
2191
|
+
/** Additional metadata to attach to the payment */
|
|
2192
|
+
metadata?: Record<string, unknown>;
|
|
2193
|
+
}
|
|
2194
|
+
/** Receipt returned after a successful payment */
|
|
2195
|
+
interface PaymentReceipt {
|
|
2196
|
+
/** Unique payment identifier */
|
|
2197
|
+
paymentId: string;
|
|
2198
|
+
/** Backwards-compatible alias for payloadHash (not an on-chain tx hash) */
|
|
2199
|
+
txHash?: string;
|
|
2200
|
+
/** Hash of the payment payload (not an on-chain tx hash) */
|
|
2201
|
+
payloadHash: string;
|
|
2202
|
+
/** Payment amount in USDC */
|
|
2203
|
+
amount: string;
|
|
2204
|
+
/** Recipient address */
|
|
2205
|
+
recipient: string;
|
|
2206
|
+
/** Payer address */
|
|
2207
|
+
payer: string;
|
|
2208
|
+
/** The action this payment is for */
|
|
2209
|
+
action: string;
|
|
2210
|
+
/** Unix timestamp of payment */
|
|
2211
|
+
timestamp: number;
|
|
2212
|
+
/** Cryptographic proof of payment */
|
|
2213
|
+
proof: string;
|
|
2214
|
+
}
|
|
2215
|
+
/** Result of verifying a payment */
|
|
2216
|
+
interface PaymentVerification {
|
|
2217
|
+
/** Whether the payment is valid */
|
|
2218
|
+
valid: boolean;
|
|
2219
|
+
/** The verified receipt */
|
|
2220
|
+
receipt?: PaymentReceipt;
|
|
2221
|
+
/** Reason for failure, if invalid */
|
|
2222
|
+
reason?: string;
|
|
2223
|
+
}
|
|
2224
|
+
/** Filters for querying payment history */
|
|
2225
|
+
interface PaymentHistoryFilters {
|
|
2226
|
+
/** Filter by action type */
|
|
2227
|
+
action?: string;
|
|
2228
|
+
/** Start of time range (unix timestamp or ISO string) */
|
|
2229
|
+
from?: string | number;
|
|
2230
|
+
/** End of time range (unix timestamp or ISO string) */
|
|
2231
|
+
to?: string | number;
|
|
2232
|
+
/** Maximum number of results */
|
|
2233
|
+
limit?: number;
|
|
2234
|
+
/** Offset for pagination */
|
|
2235
|
+
offset?: number;
|
|
2236
|
+
}
|
|
2237
|
+
/** Estimated cost for an action */
|
|
2238
|
+
interface PaymentEstimate {
|
|
2239
|
+
/** Estimated USDC cost */
|
|
2240
|
+
amount: string;
|
|
2241
|
+
/** The action being estimated */
|
|
2242
|
+
action: string;
|
|
2243
|
+
/** Whether a payment is required for this action */
|
|
2244
|
+
required: boolean;
|
|
2245
|
+
/** Breakdown of cost components */
|
|
2246
|
+
breakdown?: {
|
|
2247
|
+
baseCost: string;
|
|
2248
|
+
gasCost: string;
|
|
2249
|
+
facilitatorFee: string;
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
/** x402 module configuration */
|
|
2253
|
+
interface X402Settings {
|
|
2254
|
+
/** Default facilitator URL for x402 payments */
|
|
2255
|
+
facilitatorUrl?: string;
|
|
2256
|
+
/** Default payment recipient address */
|
|
2257
|
+
defaultRecipient?: string;
|
|
2258
|
+
/** Maximum auto-approve amount in USDC (payments above this require explicit approval) */
|
|
2259
|
+
maxAutoApprove?: string;
|
|
2260
|
+
/** USDC token address override (defaults to chain-specific address) */
|
|
2261
|
+
usdcAddress?: string;
|
|
2262
|
+
/** Whether to use Permit2 transfer method (default: false, uses EIP-3009) */
|
|
2263
|
+
usePermit2?: boolean;
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
/**
|
|
2267
|
+
* Manages x402 payment protocol operations.
|
|
2268
|
+
*
|
|
2269
|
+
* Provides pay-per-action execution, payment verification, and
|
|
2270
|
+
* agent-to-agent payments using the x402 HTTP payment standard.
|
|
2271
|
+
* Payments are made in USDC on Base.
|
|
2272
|
+
*
|
|
2273
|
+
* @example
|
|
2274
|
+
* ```typescript
|
|
2275
|
+
* // Pay for an action
|
|
2276
|
+
* const receipt = await inv.x402.payForAction({
|
|
2277
|
+
* action: 'swap',
|
|
2278
|
+
* amount: '1.00',
|
|
2279
|
+
* recipient: '0xServiceProvider',
|
|
2280
|
+
* });
|
|
2281
|
+
*
|
|
2282
|
+
* // Verify a payment
|
|
2283
|
+
* const verification = await inv.x402.verifyPayment(receipt.paymentId);
|
|
2284
|
+
*
|
|
2285
|
+
* // Query payment history
|
|
2286
|
+
* const history = await inv.x402.history('agent-identity-id');
|
|
2287
|
+
* ```
|
|
2288
|
+
*/
|
|
2289
|
+
declare class X402Manager {
|
|
2290
|
+
private readonly contracts;
|
|
2291
|
+
private readonly events;
|
|
2292
|
+
private readonly telemetry;
|
|
2293
|
+
private paymentClient;
|
|
2294
|
+
private indexer;
|
|
2295
|
+
private receipts;
|
|
2296
|
+
private static readonly MAX_RECEIPTS;
|
|
2297
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
2298
|
+
/** Lazily initialize the payment client */
|
|
2299
|
+
private getPaymentClient;
|
|
2300
|
+
/** Lazily initialize the indexer client */
|
|
2301
|
+
private getIndexer;
|
|
2302
|
+
/**
|
|
2303
|
+
* Pay for an action via the x402 protocol.
|
|
2304
|
+
*
|
|
2305
|
+
* Creates a USDC payment authorization and returns a receipt
|
|
2306
|
+
* that can be attached to intent requests for policy verification.
|
|
2307
|
+
*
|
|
2308
|
+
* @param opts - Payment options including action, amount, and recipient
|
|
2309
|
+
* @returns Payment receipt with proof
|
|
2310
|
+
*/
|
|
2311
|
+
payForAction(opts: PayForActionOptions): Promise<PaymentReceipt>;
|
|
2312
|
+
/**
|
|
2313
|
+
* Verify a payment by receipt ID.
|
|
2314
|
+
*
|
|
2315
|
+
* Checks that the payment proof is valid and the amount
|
|
2316
|
+
* meets requirements.
|
|
2317
|
+
*
|
|
2318
|
+
* @param receiptId - The payment receipt ID to verify
|
|
2319
|
+
* @returns Verification result
|
|
2320
|
+
*/
|
|
2321
|
+
verifyPayment(receiptId: string): Promise<PaymentVerification>;
|
|
2322
|
+
/**
|
|
2323
|
+
* Query payment history for an identity.
|
|
2324
|
+
*
|
|
2325
|
+
* @param identityId - The identity to query payments for
|
|
2326
|
+
* @param filters - Optional filters for action, time range, pagination
|
|
2327
|
+
* @returns Array of payment receipts
|
|
2328
|
+
*/
|
|
2329
|
+
history(identityId: string, filters?: PaymentHistoryFilters): Promise<PaymentReceipt[]>;
|
|
2330
|
+
/**
|
|
2331
|
+
* Estimate the cost for an action.
|
|
2332
|
+
*
|
|
2333
|
+
* @param opts - Estimation options
|
|
2334
|
+
* @returns Cost estimate
|
|
2335
|
+
*/
|
|
2336
|
+
estimateCost(opts: {
|
|
2337
|
+
action: string;
|
|
2338
|
+
recipient?: string;
|
|
2339
|
+
}): Promise<PaymentEstimate>;
|
|
2340
|
+
/**
|
|
2341
|
+
* Configure x402 module settings.
|
|
2342
|
+
*
|
|
2343
|
+
* @param settings - Configuration options
|
|
2344
|
+
*/
|
|
2345
|
+
configure(settings: X402Settings): Promise<void>;
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
/**
|
|
2349
|
+
* ERC-8004 (Trustless Agents) types.
|
|
2350
|
+
*
|
|
2351
|
+
* Self-contained type definitions for the ERC-8004 module.
|
|
2352
|
+
* Standalone types have NO imports from Invariance common types.
|
|
2353
|
+
* Bridge types (at the bottom) import from Invariance where needed.
|
|
2354
|
+
*/
|
|
2355
|
+
/** Registry contract addresses for an ERC-8004 deployment */
|
|
2356
|
+
interface ERC8004RegistryAddresses {
|
|
2357
|
+
identity: `0x${string}`;
|
|
2358
|
+
reputation: `0x${string}`;
|
|
2359
|
+
validation: `0x${string}`;
|
|
2360
|
+
}
|
|
2361
|
+
/** Configuration for an ERC8004Manager instance */
|
|
2362
|
+
interface ERC8004Config {
|
|
2363
|
+
/** Chain ID of the target network */
|
|
2364
|
+
chainId: number;
|
|
2365
|
+
/** viem PublicClient for read operations */
|
|
2366
|
+
publicClient: unknown;
|
|
2367
|
+
/** Optional viem WalletClient for write operations */
|
|
2368
|
+
walletClient?: unknown;
|
|
2369
|
+
/** Override default registry addresses (for custom deployments) */
|
|
2370
|
+
registryAddresses?: ERC8004RegistryAddresses;
|
|
2371
|
+
}
|
|
2372
|
+
/** A single metadata key-value pair stored on an agent identity */
|
|
2373
|
+
interface ERC8004Metadata {
|
|
2374
|
+
key: string;
|
|
2375
|
+
value: string;
|
|
2376
|
+
}
|
|
2377
|
+
/** An agent identity registered in the ERC-8004 Identity Registry */
|
|
2378
|
+
interface ERC8004AgentIdentity {
|
|
2379
|
+
/** On-chain agent ID (token ID) */
|
|
2380
|
+
agentId: bigint;
|
|
2381
|
+
/** Agent URI (off-chain metadata pointer) */
|
|
2382
|
+
agentURI: string;
|
|
2383
|
+
/** Wallet address authorized to act on behalf of the agent */
|
|
2384
|
+
wallet: `0x${string}`;
|
|
2385
|
+
/** Cross-chain global identifier: eip155:{chainId}:{registryAddress} */
|
|
2386
|
+
globalId: string;
|
|
2387
|
+
/** Metadata entries associated with the agent */
|
|
2388
|
+
metadata: ERC8004Metadata[];
|
|
2389
|
+
}
|
|
2390
|
+
/** Options for the giveFeedback() call */
|
|
2391
|
+
interface GiveFeedbackOptions {
|
|
2392
|
+
/** Agent ID to give feedback on */
|
|
2393
|
+
agentId: bigint;
|
|
2394
|
+
/** Feedback value (contract-specific scale) */
|
|
2395
|
+
value: number;
|
|
2396
|
+
/** First feedback tag */
|
|
2397
|
+
tag1: string;
|
|
2398
|
+
/** Optional second feedback tag */
|
|
2399
|
+
tag2?: string;
|
|
2400
|
+
/** Optional feedback URI (off-chain details) */
|
|
2401
|
+
feedbackURI?: string;
|
|
2402
|
+
}
|
|
2403
|
+
/** A single feedback entry from the ERC-8004 Reputation Registry */
|
|
2404
|
+
interface ERC8004Feedback {
|
|
2405
|
+
/** Address of the client who gave the feedback */
|
|
2406
|
+
client: `0x${string}`;
|
|
2407
|
+
/** Feedback value */
|
|
2408
|
+
value: number;
|
|
2409
|
+
/** First feedback tag */
|
|
2410
|
+
tag1: string;
|
|
2411
|
+
/** Second feedback tag */
|
|
2412
|
+
tag2: string;
|
|
2413
|
+
/** Feedback URI */
|
|
2414
|
+
feedbackURI: string;
|
|
2415
|
+
/** Block timestamp */
|
|
2416
|
+
timestamp: number;
|
|
2417
|
+
}
|
|
2418
|
+
/** Aggregated reputation summary for an agent */
|
|
2419
|
+
interface ERC8004ReputationSummary {
|
|
2420
|
+
/** Total number of feedback entries */
|
|
2421
|
+
count: number;
|
|
2422
|
+
/** Summary value from the contract */
|
|
2423
|
+
summaryValue: number;
|
|
2424
|
+
/** Decimal precision of the summary value */
|
|
2425
|
+
decimals: number;
|
|
2426
|
+
}
|
|
2427
|
+
/** Filter options for reputation summary queries */
|
|
2428
|
+
interface ReputationSummaryFilterOptions {
|
|
2429
|
+
/** Filter by tag */
|
|
2430
|
+
tag?: string;
|
|
2431
|
+
/** Lookback period in milliseconds from now */
|
|
2432
|
+
lookbackMs?: number;
|
|
2433
|
+
}
|
|
2434
|
+
/** Options for requesting a validation */
|
|
2435
|
+
interface ValidationRequestOptions {
|
|
2436
|
+
/** Agent ID to validate */
|
|
2437
|
+
agentId: bigint;
|
|
2438
|
+
/** Validator address */
|
|
2439
|
+
validator: `0x${string}`;
|
|
2440
|
+
/** Validation request URI (details about what to validate) */
|
|
2441
|
+
requestURI: string;
|
|
2442
|
+
}
|
|
2443
|
+
/** Options for responding to a validation request */
|
|
2444
|
+
interface ValidationResponseOptions {
|
|
2445
|
+
/** Hash of the validation request */
|
|
2446
|
+
requestHash: `0x${string}`;
|
|
2447
|
+
/** Response value (0 = invalid, 1 = valid, etc.) */
|
|
2448
|
+
response: number;
|
|
2449
|
+
/** Optional response URI (off-chain proof) */
|
|
2450
|
+
responseURI?: string;
|
|
2451
|
+
}
|
|
2452
|
+
/** Full validation status for a request */
|
|
2453
|
+
interface ERC8004ValidationStatus {
|
|
2454
|
+
/** The request hash */
|
|
2455
|
+
requestHash: `0x${string}`;
|
|
2456
|
+
/** Agent ID being validated */
|
|
2457
|
+
agentId: bigint;
|
|
2458
|
+
/** Validator address */
|
|
2459
|
+
validator: `0x${string}`;
|
|
2460
|
+
/** Request URI */
|
|
2461
|
+
requestURI: string;
|
|
2462
|
+
/** Response value (0 if not yet responded) */
|
|
2463
|
+
response: number;
|
|
2464
|
+
/** Response URI */
|
|
2465
|
+
responseURI: string;
|
|
2466
|
+
/** Whether the validation is complete */
|
|
2467
|
+
completed: boolean;
|
|
2468
|
+
}
|
|
2469
|
+
/** Aggregated validation summary for an agent */
|
|
2470
|
+
interface ERC8004ValidationSummary {
|
|
2471
|
+
/** Total number of validation requests */
|
|
2472
|
+
count: number;
|
|
2473
|
+
/** Average response value */
|
|
2474
|
+
avgResponse: number;
|
|
2475
|
+
}
|
|
2476
|
+
/** Filter options for validation summary queries */
|
|
2477
|
+
interface ValidationSummaryFilterOptions {
|
|
2478
|
+
/** Filter by validator address */
|
|
2479
|
+
validator?: `0x${string}`;
|
|
2480
|
+
/** Lookback period in milliseconds from now */
|
|
2481
|
+
lookbackMs?: number;
|
|
2482
|
+
}
|
|
2483
|
+
/** A linked identity pairing between Invariance and ERC-8004 */
|
|
2484
|
+
interface LinkedIdentity {
|
|
2485
|
+
/** Invariance identity ID */
|
|
2486
|
+
invarianceIdentityId: string;
|
|
2487
|
+
/** ERC-8004 agent ID */
|
|
2488
|
+
erc8004AgentId: string;
|
|
2489
|
+
/** ERC-8004 global ID */
|
|
2490
|
+
erc8004GlobalId: string;
|
|
2491
|
+
/** Timestamp when linked */
|
|
2492
|
+
linkedAt: number;
|
|
2493
|
+
/** Transaction hash of the linking operation */
|
|
2494
|
+
txHash: string;
|
|
2495
|
+
}
|
|
2496
|
+
/** External reputation signal pulled from ERC-8004 */
|
|
2497
|
+
interface ExternalReputationSignal {
|
|
2498
|
+
/** Source protocol */
|
|
2499
|
+
source: 'erc8004';
|
|
2500
|
+
/** Total feedback count */
|
|
2501
|
+
feedbackCount: number;
|
|
2502
|
+
/** Average feedback value */
|
|
2503
|
+
averageValue: number;
|
|
2504
|
+
/** Normalized score (0-100) */
|
|
2505
|
+
normalizedScore: number;
|
|
2506
|
+
}
|
|
2507
|
+
/** Options for pushing Invariance ledger data as ERC-8004 feedback */
|
|
2508
|
+
interface PushFeedbackOptions {
|
|
2509
|
+
/** First feedback tag */
|
|
2510
|
+
tag1: string;
|
|
2511
|
+
/** Optional second feedback tag */
|
|
2512
|
+
tag2?: string;
|
|
2513
|
+
/** Lookback period in milliseconds to query ledger entries */
|
|
2514
|
+
lookbackMs?: number;
|
|
2515
|
+
/** Optional feedback URI */
|
|
2516
|
+
feedbackURI?: string;
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
/**
|
|
2520
|
+
* Standalone ERC-8004 (Trustless Agents) manager.
|
|
2521
|
+
*
|
|
2522
|
+
* NO dependency on ContractFactory, EventEmitter, or Telemetry.
|
|
2523
|
+
* Takes raw viem PublicClient + optional WalletClient directly.
|
|
2524
|
+
* Can be used without any Invariance infrastructure.
|
|
2525
|
+
*
|
|
2526
|
+
* @example
|
|
2527
|
+
* ```typescript
|
|
2528
|
+
* import { createPublicClient, http } from 'viem';
|
|
2529
|
+
* import { base } from 'viem/chains';
|
|
2530
|
+
* import { ERC8004Manager } from '@invariance/sdk';
|
|
2531
|
+
*
|
|
2532
|
+
* const publicClient = createPublicClient({ chain: base, transport: http() });
|
|
2533
|
+
* const manager = new ERC8004Manager({ chainId: 8453, publicClient });
|
|
2534
|
+
*
|
|
2535
|
+
* const agent = await manager.getAgent(1n);
|
|
2536
|
+
* const summary = await manager.getSummary(1n);
|
|
2537
|
+
* ```
|
|
2538
|
+
*/
|
|
2539
|
+
|
|
2540
|
+
/** Transaction receipt returned by write methods */
|
|
2541
|
+
interface TxReceipt$1 {
|
|
2542
|
+
txHash: string;
|
|
2543
|
+
blockNumber: number;
|
|
2544
|
+
status: 'success' | 'reverted';
|
|
2545
|
+
}
|
|
2546
|
+
declare class ERC8004Manager {
|
|
2547
|
+
private readonly chainId;
|
|
2548
|
+
private readonly publicClient;
|
|
2549
|
+
private readonly walletClient;
|
|
2550
|
+
private readonly registryAddresses;
|
|
2551
|
+
private readonly identityContract;
|
|
2552
|
+
private readonly reputationContract;
|
|
2553
|
+
private readonly validationContract;
|
|
2554
|
+
constructor(config: ERC8004Config);
|
|
2555
|
+
/**
|
|
2556
|
+
* Register a new agent identity in the ERC-8004 Identity Registry.
|
|
2557
|
+
*
|
|
2558
|
+
* @param agentURI - Off-chain metadata URI for the agent
|
|
2559
|
+
* @param metadata - Optional initial metadata key-value pairs
|
|
2560
|
+
* @returns The registered agent identity
|
|
2561
|
+
*/
|
|
2562
|
+
register(agentURI: string, metadata?: ERC8004Metadata[]): Promise<ERC8004AgentIdentity>;
|
|
2563
|
+
/**
|
|
2564
|
+
* Get an agent identity by ID.
|
|
2565
|
+
*
|
|
2566
|
+
* @param agentId - The on-chain agent ID
|
|
2567
|
+
* @returns The agent identity
|
|
2568
|
+
*/
|
|
2569
|
+
getAgent(agentId: bigint): Promise<ERC8004AgentIdentity>;
|
|
2570
|
+
/**
|
|
2571
|
+
* Set a metadata value on an agent identity.
|
|
2572
|
+
*
|
|
2573
|
+
* @param agentId - The agent ID
|
|
2574
|
+
* @param key - Metadata key
|
|
2575
|
+
* @param value - Metadata value
|
|
2576
|
+
* @returns Transaction receipt
|
|
2577
|
+
*/
|
|
2578
|
+
setMetadata(agentId: bigint, key: string, value: string): Promise<TxReceipt$1>;
|
|
2579
|
+
/**
|
|
2580
|
+
* Get a metadata value from an agent identity.
|
|
2581
|
+
*
|
|
2582
|
+
* @param agentId - The agent ID
|
|
2583
|
+
* @param key - Metadata key
|
|
2584
|
+
* @returns The metadata value
|
|
2585
|
+
*/
|
|
2586
|
+
getMetadata(agentId: bigint, key: string): Promise<string>;
|
|
2587
|
+
/**
|
|
2588
|
+
* Set the wallet address for an agent (with signature authorization).
|
|
2589
|
+
*
|
|
2590
|
+
* @param agentId - The agent ID
|
|
2591
|
+
* @param newWallet - New wallet address
|
|
2592
|
+
* @param deadline - Signature deadline timestamp
|
|
2593
|
+
* @param signature - Authorization signature
|
|
2594
|
+
* @returns Transaction receipt
|
|
2595
|
+
*/
|
|
2596
|
+
setAgentWallet(agentId: bigint, newWallet: `0x${string}`, deadline: bigint, signature: `0x${string}`): Promise<TxReceipt$1>;
|
|
2597
|
+
/**
|
|
2598
|
+
* Set the agent URI.
|
|
2599
|
+
*
|
|
2600
|
+
* @param agentId - The agent ID
|
|
2601
|
+
* @param newURI - New agent URI
|
|
2602
|
+
* @returns Transaction receipt
|
|
2603
|
+
*/
|
|
2604
|
+
setAgentURI(agentId: bigint, newURI: string): Promise<TxReceipt$1>;
|
|
2605
|
+
/**
|
|
2606
|
+
* Compute the cross-chain global ID for an agent.
|
|
2607
|
+
*
|
|
2608
|
+
* @param agentId - The on-chain agent ID
|
|
2609
|
+
* @returns The global ID string: eip155:{chainId}:{registryAddress}:{agentId}
|
|
2610
|
+
*/
|
|
2611
|
+
getGlobalId(agentId: bigint): string;
|
|
2612
|
+
/**
|
|
2613
|
+
* Give feedback on an agent.
|
|
2614
|
+
*
|
|
2615
|
+
* @param opts - Feedback options
|
|
2616
|
+
* @returns Transaction receipt
|
|
2617
|
+
*/
|
|
2618
|
+
giveFeedback(opts: GiveFeedbackOptions): Promise<TxReceipt$1>;
|
|
2619
|
+
/**
|
|
2620
|
+
* Revoke previously given feedback.
|
|
2621
|
+
*
|
|
2622
|
+
* @param agentId - The agent ID
|
|
2623
|
+
* @param feedbackIndex - Index of the feedback to revoke
|
|
2624
|
+
* @returns Transaction receipt
|
|
2625
|
+
*/
|
|
2626
|
+
revokeFeedback(agentId: bigint, feedbackIndex: bigint): Promise<TxReceipt$1>;
|
|
2627
|
+
/**
|
|
2628
|
+
* Get reputation summary for an agent.
|
|
2629
|
+
*
|
|
2630
|
+
* @param agentId - The agent ID
|
|
2631
|
+
* @param _opts - Optional filter options (reserved for future use)
|
|
2632
|
+
* @returns Reputation summary
|
|
2633
|
+
*/
|
|
2634
|
+
getSummary(agentId: bigint, _opts?: ReputationSummaryFilterOptions): Promise<ERC8004ReputationSummary>;
|
|
2635
|
+
/**
|
|
2636
|
+
* Read a single feedback entry.
|
|
2637
|
+
*
|
|
2638
|
+
* @param agentId - The agent ID
|
|
2639
|
+
* @param client - The client address who gave the feedback
|
|
2640
|
+
* @param index - Feedback index for this client
|
|
2641
|
+
* @returns The feedback entry
|
|
2642
|
+
*/
|
|
2643
|
+
readFeedback(agentId: bigint, client: `0x${string}`, index: bigint): Promise<ERC8004Feedback>;
|
|
2644
|
+
/**
|
|
2645
|
+
* Read all feedback entries for an agent.
|
|
2646
|
+
*
|
|
2647
|
+
* @param agentId - The agent ID
|
|
2648
|
+
* @returns All feedback entries
|
|
2649
|
+
*/
|
|
2650
|
+
readAllFeedback(agentId: bigint): Promise<ERC8004Feedback[]>;
|
|
2651
|
+
/**
|
|
2652
|
+
* Submit a validation request for an agent.
|
|
2653
|
+
*
|
|
2654
|
+
* @param opts - Validation request options
|
|
2655
|
+
* @returns Transaction receipt
|
|
2656
|
+
*/
|
|
2657
|
+
requestValidation(opts: ValidationRequestOptions): Promise<TxReceipt$1>;
|
|
2658
|
+
/**
|
|
2659
|
+
* Respond to a validation request.
|
|
2660
|
+
*
|
|
2661
|
+
* @param opts - Validation response options
|
|
2662
|
+
* @returns Transaction receipt
|
|
2663
|
+
*/
|
|
2664
|
+
respondToValidation(opts: ValidationResponseOptions): Promise<TxReceipt$1>;
|
|
2665
|
+
/**
|
|
2666
|
+
* Get the status of a validation request.
|
|
2667
|
+
*
|
|
2668
|
+
* @param requestHash - The validation request hash
|
|
2669
|
+
* @returns Validation status
|
|
2670
|
+
*/
|
|
2671
|
+
getValidationStatus(requestHash: `0x${string}`): Promise<ERC8004ValidationStatus>;
|
|
2672
|
+
/**
|
|
2673
|
+
* Get validation summary for an agent.
|
|
2674
|
+
*
|
|
2675
|
+
* @param agentId - The agent ID
|
|
2676
|
+
* @param _opts - Optional filter options (reserved for future use)
|
|
2677
|
+
* @returns Validation summary
|
|
2678
|
+
*/
|
|
2679
|
+
getValidationSummary(agentId: bigint, _opts?: ValidationSummaryFilterOptions): Promise<ERC8004ValidationSummary>;
|
|
2680
|
+
/** Get a read function from a contract, throwing if not found */
|
|
2681
|
+
private getReadFn;
|
|
2682
|
+
/** Get a write function from a contract, throwing if not found */
|
|
2683
|
+
private getWriteFn;
|
|
2684
|
+
/** Ensure walletClient is available for write operations */
|
|
2685
|
+
private requireWalletClient;
|
|
2686
|
+
/** Compute the global ID for an agent */
|
|
2687
|
+
private computeGlobalId;
|
|
2688
|
+
/** Wait for a transaction receipt and return a simplified result */
|
|
2689
|
+
private waitForTxReceipt;
|
|
2690
|
+
/** Parse agent ID from registration event logs */
|
|
2691
|
+
private parseAgentIdFromLogs;
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* Error class for ERC-8004 operations.
|
|
2695
|
+
* Standalone — does not extend InvarianceError.
|
|
2696
|
+
*/
|
|
2697
|
+
declare class ERC8004Error extends Error {
|
|
2698
|
+
readonly code: string;
|
|
2699
|
+
constructor(code: string, message: string);
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
/**
|
|
2703
|
+
* Optional bridge between ERC-8004 and Invariance modules.
|
|
2704
|
+
*
|
|
2705
|
+
* Takes an ERC8004Manager instance + Invariance module references.
|
|
2706
|
+
* Explicitly constructed — never automatic.
|
|
2707
|
+
*
|
|
2708
|
+
* @example
|
|
2709
|
+
* ```typescript
|
|
2710
|
+
* const inv = new Invariance({ chain: 'base', signer: wallet });
|
|
2711
|
+
* const bridge = inv.erc8004Bridge;
|
|
2712
|
+
*
|
|
2713
|
+
* // Link identities
|
|
2714
|
+
* const linked = await bridge.linkIdentity('inv-id-123', 42n);
|
|
2715
|
+
*
|
|
2716
|
+
* // Pull external reputation
|
|
2717
|
+
* const signal = await bridge.pullERC8004Reputation(42n);
|
|
2718
|
+
* ```
|
|
2719
|
+
*/
|
|
2720
|
+
|
|
2721
|
+
/** Transaction receipt returned by bridge write methods */
|
|
2722
|
+
interface TxReceipt {
|
|
2723
|
+
txHash: string;
|
|
2724
|
+
blockNumber: number;
|
|
2725
|
+
status: 'success' | 'reverted';
|
|
2726
|
+
}
|
|
2727
|
+
declare class InvarianceBridge {
|
|
2728
|
+
private readonly erc8004;
|
|
2729
|
+
private readonly identity;
|
|
2730
|
+
private readonly ledger;
|
|
2731
|
+
private readonly contracts;
|
|
2732
|
+
private readonly events;
|
|
2733
|
+
private readonly telemetry;
|
|
2734
|
+
/** In-memory cache of linked identities */
|
|
2735
|
+
private linkedIdentities;
|
|
2736
|
+
private static readonly MAX_LINKED_IDENTITIES;
|
|
2737
|
+
constructor(erc8004: ERC8004Manager, identity: IdentityManager, ledger: EventLedger, contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
2738
|
+
/**
|
|
2739
|
+
* Link an Invariance identity to an ERC-8004 agent identity.
|
|
2740
|
+
*
|
|
2741
|
+
* Sets `invariance-identity-id` as ERC-8004 metadata AND creates
|
|
2742
|
+
* an Invariance attestation with `erc8004-agent-id` claim.
|
|
2743
|
+
*
|
|
2744
|
+
* @param invarianceIdentityId - Invariance identity ID
|
|
2745
|
+
* @param erc8004AgentId - ERC-8004 agent ID
|
|
2746
|
+
* @returns The linked identity pairing
|
|
2747
|
+
*/
|
|
2748
|
+
linkIdentity(invarianceIdentityId: string, erc8004AgentId: bigint): Promise<LinkedIdentity>;
|
|
2749
|
+
/**
|
|
2750
|
+
* Get a linked identity pairing.
|
|
2751
|
+
*
|
|
2752
|
+
* Checks local cache first, then queries ERC-8004 metadata.
|
|
2753
|
+
*
|
|
2754
|
+
* @param invarianceIdentityId - Invariance identity ID
|
|
2755
|
+
* @returns The linked identity or null if not linked
|
|
2756
|
+
*/
|
|
2757
|
+
getLinkedIdentity(invarianceIdentityId: string): Promise<LinkedIdentity | null>;
|
|
2758
|
+
/**
|
|
2759
|
+
* Unlink an Invariance identity from its ERC-8004 agent.
|
|
2760
|
+
*
|
|
2761
|
+
* Removes the ERC-8004 metadata and clears the local cache.
|
|
2762
|
+
*
|
|
2763
|
+
* @param invarianceIdentityId - Invariance identity ID
|
|
2764
|
+
*/
|
|
2765
|
+
unlinkIdentity(invarianceIdentityId: string): Promise<void>;
|
|
2766
|
+
/**
|
|
2767
|
+
* Pull ERC-8004 reputation data and normalize to a 0-100 score.
|
|
2768
|
+
*
|
|
2769
|
+
* Does NOT modify Invariance scoring — caller decides how to use the signal.
|
|
2770
|
+
*
|
|
2771
|
+
* @param erc8004AgentId - ERC-8004 agent ID
|
|
2772
|
+
* @returns External reputation signal with normalized score
|
|
2773
|
+
*/
|
|
2774
|
+
pullERC8004Reputation(erc8004AgentId: bigint): Promise<ExternalReputationSignal>;
|
|
2775
|
+
/**
|
|
2776
|
+
* Push Invariance ledger data as ERC-8004 feedback.
|
|
2777
|
+
*
|
|
2778
|
+
* Queries Invariance ledger entries for the identity, derives a
|
|
2779
|
+
* feedback value (based on success rate), and calls giveFeedback()
|
|
2780
|
+
* on the ERC-8004 Reputation Registry.
|
|
2781
|
+
*
|
|
2782
|
+
* @param invarianceIdentityId - Invariance identity ID
|
|
2783
|
+
* @param erc8004AgentId - ERC-8004 agent ID to give feedback on
|
|
2784
|
+
* @param opts - Feedback options (tags, lookback, URI)
|
|
2785
|
+
* @returns Transaction receipt
|
|
2786
|
+
*/
|
|
2787
|
+
pushFeedbackFromLedger(invarianceIdentityId: string, erc8004AgentId: bigint, opts: PushFeedbackOptions): Promise<TxReceipt>;
|
|
2788
|
+
/**
|
|
2789
|
+
* Act as a validator for an ERC-8004 agent.
|
|
2790
|
+
*
|
|
2791
|
+
* Reads Invariance execution logs, evaluates integrity,
|
|
2792
|
+
* and submits a validation response.
|
|
2793
|
+
*
|
|
2794
|
+
* @param erc8004AgentId - ERC-8004 agent ID being validated
|
|
2795
|
+
* @param requestHash - Hash of the validation request to respond to
|
|
2796
|
+
* @returns Transaction receipt
|
|
2797
|
+
*/
|
|
2798
|
+
actAsValidator(erc8004AgentId: bigint, requestHash: `0x${string}`): Promise<TxReceipt>;
|
|
2799
|
+
/**
|
|
2800
|
+
* Submit a validation request targeting Invariance as validator.
|
|
2801
|
+
*
|
|
2802
|
+
* @param erc8004AgentId - ERC-8004 agent ID to validate
|
|
2803
|
+
* @param requestURI - URI describing what to validate
|
|
2804
|
+
* @returns Transaction receipt
|
|
2805
|
+
*/
|
|
2806
|
+
requestInvarianceValidation(erc8004AgentId: bigint, requestURI: string): Promise<TxReceipt>;
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
/** Options for updating a marketplace listing */
|
|
2810
|
+
interface UpdateListingOptions {
|
|
2811
|
+
name?: string;
|
|
2812
|
+
description?: string;
|
|
2813
|
+
category?: _invariance_common.ListingCategory;
|
|
2814
|
+
pricing?: _invariance_common.PricingModel;
|
|
2815
|
+
capabilities?: string[];
|
|
2816
|
+
tags?: string[];
|
|
2817
|
+
avatar?: string;
|
|
2818
|
+
apiEndpoint?: string;
|
|
2819
|
+
sla?: {
|
|
2820
|
+
maxResponseTime: string;
|
|
2821
|
+
uptime: number;
|
|
2822
|
+
refundPolicy: string;
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
/** Options for querying featured listings */
|
|
2826
|
+
interface FeaturedOptions {
|
|
2827
|
+
category?: _invariance_common.ListingCategory;
|
|
2828
|
+
limit?: number;
|
|
2829
|
+
}
|
|
2830
|
+
/** Options for completing a hire */
|
|
2831
|
+
interface CompleteHireOptions {
|
|
2832
|
+
review?: Omit<_invariance_common.SubmitReviewOptions, 'target' | 'escrowId'>;
|
|
2833
|
+
deliverables?: string[];
|
|
2834
|
+
notes?: string;
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
/**
|
|
2838
|
+
* Pre-built primitives for building verified marketplaces.
|
|
2839
|
+
*
|
|
2840
|
+
* The Marketplace Kit provides everything needed to build a marketplace
|
|
2841
|
+
* where any identity type can list services, be discovered, hired, and
|
|
2842
|
+
* reviewed. V1 focuses on AI agent marketplaces.
|
|
2843
|
+
*
|
|
2844
|
+
* The full flow: Register -> Search -> Hire -> Complete
|
|
2845
|
+
* Hiring automatically creates an escrow + policy in one call.
|
|
2846
|
+
*
|
|
2847
|
+
* @example
|
|
2848
|
+
* ```typescript
|
|
2849
|
+
* const listing = await inv.marketplace.register({
|
|
2850
|
+
* identity: agent.identityId,
|
|
2851
|
+
* name: 'ContentGenius Pro',
|
|
2852
|
+
* description: 'AI content writer',
|
|
2853
|
+
* category: 'content',
|
|
2854
|
+
* pricing: { type: 'per-task', amount: '25.00', currency: 'USDC' },
|
|
2855
|
+
* capabilities: ['blog-posts', 'seo-optimization'],
|
|
2856
|
+
* });
|
|
2857
|
+
* ```
|
|
2858
|
+
*/
|
|
2859
|
+
declare class MarketplaceKit {
|
|
2860
|
+
private readonly contracts;
|
|
2861
|
+
private readonly events;
|
|
2862
|
+
private readonly telemetry;
|
|
2863
|
+
private indexer;
|
|
2864
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
2865
|
+
/** Get the contract address for the registry module */
|
|
2866
|
+
getContractAddress(): string;
|
|
2867
|
+
/** Lazily initialize the indexer client */
|
|
2868
|
+
private getIndexer;
|
|
2869
|
+
/**
|
|
2870
|
+
* Map an on-chain listing tuple to the SDK Listing type.
|
|
2871
|
+
* Uses sensible defaults for reputation/reviews since the indexer provides enriched data.
|
|
2872
|
+
*/
|
|
2873
|
+
private mapOnChainListing;
|
|
2874
|
+
/**
|
|
2875
|
+
* Build a metadata URI JSON string from registration/update options.
|
|
2876
|
+
*/
|
|
2877
|
+
private buildMetadataUri;
|
|
2878
|
+
/**
|
|
2879
|
+
* Register an identity on the marketplace.
|
|
2880
|
+
*
|
|
2881
|
+
* Creates a public listing with pricing, capabilities, and SLA details.
|
|
2882
|
+
* The listing is linked to the identity's on-chain reputation.
|
|
2883
|
+
*
|
|
2884
|
+
* @param opts - Listing registration options
|
|
2885
|
+
* @returns The created listing
|
|
2886
|
+
*/
|
|
2887
|
+
register(opts: RegisterListingOptions): Promise<Listing>;
|
|
2888
|
+
/**
|
|
2889
|
+
* Update listing details.
|
|
2890
|
+
*
|
|
2891
|
+
* @param listingId - The listing to update
|
|
2892
|
+
* @param opts - Fields to update
|
|
2893
|
+
* @returns The updated listing
|
|
2894
|
+
*/
|
|
2895
|
+
update(listingId: string, opts: UpdateListingOptions): Promise<Listing>;
|
|
2896
|
+
/**
|
|
2897
|
+
* Deactivate a listing.
|
|
2898
|
+
*
|
|
2899
|
+
* The listing will no longer appear in search results but
|
|
2900
|
+
* existing hires remain active until completed.
|
|
2901
|
+
*
|
|
2902
|
+
* @param listingId - The listing to deactivate
|
|
2903
|
+
* @returns Transaction receipt
|
|
2904
|
+
*/
|
|
2905
|
+
deactivate(listingId: string): Promise<TxReceipt$2>;
|
|
2906
|
+
/**
|
|
2907
|
+
* Search and filter marketplace listings.
|
|
2908
|
+
*
|
|
2909
|
+
* Supports text search, category filtering, rating thresholds,
|
|
2910
|
+
* price ranges, and capability matching.
|
|
2911
|
+
*
|
|
2912
|
+
* @param query - Search query with filters
|
|
2913
|
+
* @returns Paginated search results with facets
|
|
2914
|
+
*/
|
|
2915
|
+
search(query: SearchQuery): Promise<SearchResults>;
|
|
2916
|
+
/**
|
|
2917
|
+
* Get a single listing with full details.
|
|
2918
|
+
*
|
|
2919
|
+
* @param listingId - The listing ID
|
|
2920
|
+
* @returns The listing with reputation and reviews
|
|
2921
|
+
*/
|
|
2922
|
+
get(listingId: string): Promise<Listing>;
|
|
2923
|
+
/**
|
|
2924
|
+
* Get top-rated listings by category.
|
|
2925
|
+
*
|
|
2926
|
+
* @param opts - Optional category and limit
|
|
2927
|
+
* @returns Array of featured listings
|
|
2928
|
+
*/
|
|
2929
|
+
featured(opts?: FeaturedOptions): Promise<Listing[]>;
|
|
2930
|
+
/**
|
|
2931
|
+
* Hire from a listing.
|
|
2932
|
+
*
|
|
2933
|
+
* This is a compound operation that creates an escrow, policy, and
|
|
2934
|
+
* on-chain hire record in a single call. The escrow holds the payment,
|
|
2935
|
+
* the policy constrains what the hired identity can do, and the hire
|
|
2936
|
+
* contract records the agreement on-chain.
|
|
2937
|
+
*
|
|
2938
|
+
* @param opts - Hire options (listing, task, payment, policy)
|
|
2939
|
+
* @returns Hire result with escrow and policy IDs
|
|
2940
|
+
*/
|
|
2941
|
+
hire(opts: HireOptions): Promise<HireResult>;
|
|
2942
|
+
/**
|
|
2943
|
+
* Complete a job and optionally leave a review.
|
|
2944
|
+
*
|
|
2945
|
+
* Marks the hire as completed on-chain, releases the escrow,
|
|
2946
|
+
* submits a review (if provided), and updates the identity's reputation.
|
|
2947
|
+
*
|
|
2948
|
+
* @param hireId - The hire to complete
|
|
2949
|
+
* @param opts - Completion options (optional review)
|
|
2950
|
+
* @returns Completion result with escrow and reputation updates
|
|
2951
|
+
*/
|
|
2952
|
+
complete(hireId: string, opts?: CompleteHireOptions): Promise<CompletionResult>;
|
|
2953
|
+
/**
|
|
2954
|
+
* Get a hire agreement from the on-chain contract.
|
|
2955
|
+
*
|
|
2956
|
+
* @param hireId - The hire ID
|
|
2957
|
+
* @returns The on-chain hire data
|
|
2958
|
+
*/
|
|
2959
|
+
getHire(hireId: string): Promise<{
|
|
2960
|
+
hireId: string;
|
|
2961
|
+
listingId: string;
|
|
2962
|
+
escrowId: string;
|
|
2963
|
+
policyId: string;
|
|
2964
|
+
hirer: string;
|
|
2965
|
+
provider: string;
|
|
2966
|
+
taskDescription: string;
|
|
2967
|
+
status: number;
|
|
2968
|
+
createdAt: number;
|
|
2969
|
+
completedAt: number;
|
|
2970
|
+
}>;
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
/** Options for a gated action execution. */
|
|
2974
|
+
interface GateActionOptions {
|
|
2975
|
+
action: string;
|
|
2976
|
+
actor: ActorReference;
|
|
2977
|
+
category?: string;
|
|
2978
|
+
metadata?: Record<string, unknown>;
|
|
2979
|
+
mode?: AuditLogMode;
|
|
2980
|
+
visibility?: AuditVisibility;
|
|
2981
|
+
requestId?: string;
|
|
2982
|
+
}
|
|
2983
|
+
/** Result envelope for a gated action. */
|
|
2984
|
+
interface GateActionResult<T> {
|
|
2985
|
+
result: T;
|
|
2986
|
+
mode: AuditLogMode;
|
|
2987
|
+
offchain?: {
|
|
2988
|
+
attemptId?: string;
|
|
2989
|
+
successId?: string;
|
|
2990
|
+
};
|
|
2991
|
+
onchainEntryId?: string;
|
|
2992
|
+
}
|
|
2993
|
+
/** Fully-resolved audit settings. */
|
|
2994
|
+
interface ResolvedAuditConfig extends Required<Pick<AuditConfig, 'enabled' | 'mode' | 'visibility' | 'failOpen'>> {
|
|
2995
|
+
route: string;
|
|
2996
|
+
}
|
|
2997
|
+
|
|
2998
|
+
declare class AuditTrail {
|
|
2999
|
+
private readonly contracts;
|
|
3000
|
+
private readonly events;
|
|
3001
|
+
private readonly telemetry;
|
|
3002
|
+
private readonly ledger;
|
|
3003
|
+
private readonly config;
|
|
3004
|
+
private indexer;
|
|
3005
|
+
constructor(contracts: ContractFactory, events: InvarianceEventEmitter, telemetry: Telemetry, ledger: EventLedger, config?: InvarianceConfig['audit']);
|
|
3006
|
+
/** Resolved audit configuration currently used by this module. */
|
|
3007
|
+
getSettings(): ResolvedAuditConfig;
|
|
3008
|
+
/** Log a single off-chain audit record. */
|
|
3009
|
+
log(input: AuditLogInput): Promise<AuditLogRecord>;
|
|
3010
|
+
/** Query off-chain audit logs. */
|
|
3011
|
+
query(filters: AuditQueryFilters): Promise<{
|
|
3012
|
+
data: AuditLogRecord[];
|
|
3013
|
+
total: number;
|
|
3014
|
+
}>;
|
|
3015
|
+
/**
|
|
3016
|
+
* Execute any action through a consistent SDK gate:
|
|
3017
|
+
* - emits action lifecycle events
|
|
3018
|
+
* - writes off-chain audit logs (default)
|
|
3019
|
+
* - optionally anchors to on-chain ledger
|
|
3020
|
+
*/
|
|
3021
|
+
gate<T>(opts: GateActionOptions, executor: () => Promise<T>): Promise<GateActionResult<T>>;
|
|
3022
|
+
private getIndexer;
|
|
3023
|
+
private tryOffchainLog;
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
/**
|
|
3027
|
+
* Off-chain batch voting with merkle root settlement.
|
|
3028
|
+
*
|
|
3029
|
+
* Proposals are created on-chain for immutability. Votes are collected
|
|
3030
|
+
* off-chain as EIP-712 signed messages. A single merkle root posted
|
|
3031
|
+
* on-chain proves all votes (95%+ gas savings vs individual storage).
|
|
3032
|
+
*
|
|
3033
|
+
* @example
|
|
3034
|
+
* ```typescript
|
|
3035
|
+
* // Create a proposal
|
|
3036
|
+
* await inv.voting.createProposal({
|
|
3037
|
+
* proposalId: 'prop-1',
|
|
3038
|
+
* identityId: 'id-1',
|
|
3039
|
+
* title: 'Upgrade to v2',
|
|
3040
|
+
* descriptionHash: '0x...',
|
|
3041
|
+
* votingPeriod: 7 * 24 * 3600,
|
|
3042
|
+
* quorum: 100n,
|
|
3043
|
+
* threshold: 5000,
|
|
3044
|
+
* });
|
|
3045
|
+
*
|
|
3046
|
+
* // Cast votes off-chain
|
|
3047
|
+
* const vote = await inv.voting.castVote({ proposalId: 'prop-1', support: true, weight: 50n });
|
|
3048
|
+
*
|
|
3049
|
+
* // Settle with merkle root
|
|
3050
|
+
* await inv.voting.settleVotes('prop-1');
|
|
3051
|
+
*
|
|
3052
|
+
* // Verify any vote
|
|
3053
|
+
* const proof = inv.voting.generateProof('prop-1', vote.voter);
|
|
3054
|
+
* const valid = await inv.voting.verifyVote('prop-1', proof);
|
|
3055
|
+
* ```
|
|
3056
|
+
*/
|
|
3057
|
+
declare class VotingManager {
|
|
3058
|
+
private readonly contracts;
|
|
3059
|
+
private readonly telemetry;
|
|
3060
|
+
/** In-memory vote storage per proposal */
|
|
3061
|
+
private readonly voteStore;
|
|
3062
|
+
/** Cached merkle trees per proposal */
|
|
3063
|
+
private readonly treeCache;
|
|
3064
|
+
constructor(contracts: ContractFactory, _events: InvarianceEventEmitter, telemetry: Telemetry);
|
|
3065
|
+
/**
|
|
3066
|
+
* Create a proposal on-chain.
|
|
3067
|
+
*
|
|
3068
|
+
* @param opts - Proposal creation options
|
|
3069
|
+
* @returns Transaction hash
|
|
3070
|
+
*/
|
|
3071
|
+
createProposal(opts: CreateProposalOptions): Promise<string>;
|
|
3072
|
+
/**
|
|
3073
|
+
* Cast a vote off-chain with EIP-712 signature.
|
|
3074
|
+
*
|
|
3075
|
+
* The vote is signed and stored in memory. No on-chain transaction
|
|
3076
|
+
* occurs until settleVotes() is called.
|
|
3077
|
+
*
|
|
3078
|
+
* @param input - Vote input (proposalId, support, weight)
|
|
3079
|
+
* @returns The signed vote
|
|
3080
|
+
*/
|
|
3081
|
+
castVote(input: VoteInput): Promise<Vote>;
|
|
3082
|
+
/**
|
|
3083
|
+
* Build the merkle tree for a proposal's votes.
|
|
3084
|
+
*
|
|
3085
|
+
* @param proposalId - The proposal ID
|
|
3086
|
+
* @returns The merkle root
|
|
3087
|
+
*/
|
|
3088
|
+
buildMerkleTree(proposalId: string): string;
|
|
3089
|
+
/**
|
|
3090
|
+
* Settle votes on-chain by posting the merkle root.
|
|
3091
|
+
*
|
|
3092
|
+
* Builds the merkle tree, computes totals, and submits a single
|
|
3093
|
+
* transaction to the contract.
|
|
3094
|
+
*
|
|
3095
|
+
* @param proposalId - The proposal to settle
|
|
3096
|
+
* @returns Settlement data including tx hash
|
|
3097
|
+
*/
|
|
3098
|
+
settleVotes(proposalId: string): Promise<SettlementData & {
|
|
3099
|
+
txHash: string;
|
|
3100
|
+
}>;
|
|
3101
|
+
/**
|
|
3102
|
+
* Generate a merkle proof for a specific voter.
|
|
3103
|
+
*
|
|
3104
|
+
* @param proposalId - The proposal ID
|
|
3105
|
+
* @param voter - Voter address
|
|
3106
|
+
* @returns Merkle proof bundle
|
|
3107
|
+
*/
|
|
3108
|
+
generateProof(proposalId: string, voter: string): MerkleProofBundle;
|
|
3109
|
+
/**
|
|
3110
|
+
* Verify a vote on-chain using a merkle proof.
|
|
3111
|
+
*
|
|
3112
|
+
* @param proposalId - The proposal ID
|
|
3113
|
+
* @param bundle - Merkle proof bundle
|
|
3114
|
+
* @returns Whether the vote is valid
|
|
3115
|
+
*/
|
|
3116
|
+
verifyVote(proposalId: string, bundle: MerkleProofBundle): Promise<boolean>;
|
|
3117
|
+
/**
|
|
3118
|
+
* Verify a vote off-chain using the merkle proof.
|
|
3119
|
+
*
|
|
3120
|
+
* @param root - Expected merkle root
|
|
3121
|
+
* @param vote - The vote to verify
|
|
3122
|
+
* @param proof - Merkle proof
|
|
3123
|
+
* @returns Whether the proof is valid
|
|
3124
|
+
*/
|
|
3125
|
+
verifyVoteOffChain(root: string, vote: Vote, proof: string[]): boolean;
|
|
3126
|
+
/**
|
|
3127
|
+
* Get a proposal from the contract.
|
|
3128
|
+
*
|
|
3129
|
+
* @param proposalId - The proposal ID
|
|
3130
|
+
* @returns Proposal data
|
|
3131
|
+
*/
|
|
3132
|
+
getProposal(proposalId: string): Promise<Proposal>;
|
|
3133
|
+
/**
|
|
3134
|
+
* Get all in-memory votes for a proposal.
|
|
3135
|
+
*
|
|
3136
|
+
* @param proposalId - The proposal ID
|
|
3137
|
+
* @returns Array of votes
|
|
3138
|
+
*/
|
|
3139
|
+
getVotes(proposalId: string): Vote[];
|
|
3140
|
+
/**
|
|
3141
|
+
* Check if a settled proposal passed (on-chain).
|
|
3142
|
+
*
|
|
3143
|
+
* @param proposalId - The proposal ID
|
|
3144
|
+
* @returns Whether the proposal passed
|
|
3145
|
+
*/
|
|
3146
|
+
didPass(proposalId: string): Promise<boolean>;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
/**
|
|
3150
|
+
* Current SDK version, injected at build time via tsup define.
|
|
3151
|
+
*/
|
|
3152
|
+
declare const SDK_VERSION: string;
|
|
3153
|
+
/**
|
|
3154
|
+
* The callable verify interface.
|
|
3155
|
+
*
|
|
3156
|
+
* Supports both `inv.verify(txHash)` direct call syntax
|
|
3157
|
+
* and sub-methods like `inv.verify.action()`.
|
|
3158
|
+
*/
|
|
3159
|
+
interface VerifyProxy extends Verifier {
|
|
3160
|
+
(txHash: string): Promise<VerificationResult>;
|
|
3161
|
+
}
|
|
3162
|
+
/**
|
|
3163
|
+
* The main entry point for the Invariance SDK.
|
|
3164
|
+
*
|
|
3165
|
+
* Lazily initializes all 12 module managers and exposes them as properties.
|
|
3166
|
+
* The constructor validates chain configuration and contract availability.
|
|
3167
|
+
*
|
|
3168
|
+
* @example
|
|
3169
|
+
* ```typescript
|
|
3170
|
+
* import { Invariance } from '@invariance/sdk';
|
|
3171
|
+
*
|
|
3172
|
+
* // Self-hosted
|
|
3173
|
+
* const inv = new Invariance({
|
|
3174
|
+
* chain: 'base',
|
|
3175
|
+
* rpcUrl: 'https://mainnet.base.org',
|
|
3176
|
+
* signer: wallet,
|
|
3177
|
+
* });
|
|
3178
|
+
*
|
|
3179
|
+
* // Managed hosting
|
|
3180
|
+
* const inv = new Invariance({
|
|
3181
|
+
* apiKey: 'inv_live_xxx',
|
|
3182
|
+
* chain: 'base',
|
|
3183
|
+
* });
|
|
3184
|
+
*
|
|
3185
|
+
* // Register an identity
|
|
3186
|
+
* const agent = await inv.identity.register({
|
|
3187
|
+
* type: 'agent',
|
|
3188
|
+
* owner: '0xDev',
|
|
3189
|
+
* label: 'TraderBot',
|
|
3190
|
+
* });
|
|
3191
|
+
*
|
|
3192
|
+
* // Execute a verified intent
|
|
3193
|
+
* const result = await inv.intent.request({
|
|
3194
|
+
* actor: { type: 'agent', address: agent.address },
|
|
3195
|
+
* action: 'swap',
|
|
3196
|
+
* params: { from: 'USDC', to: 'ETH', amount: '100' },
|
|
3197
|
+
* approval: 'auto',
|
|
3198
|
+
* });
|
|
3199
|
+
*
|
|
3200
|
+
* // Verify any transaction
|
|
3201
|
+
* const verification = await inv.verify('0xtxhash...');
|
|
3202
|
+
* ```
|
|
3203
|
+
*/
|
|
3204
|
+
declare class Invariance {
|
|
3205
|
+
private readonly config;
|
|
3206
|
+
private readonly contracts;
|
|
3207
|
+
private readonly events;
|
|
3208
|
+
private readonly telemetry;
|
|
3209
|
+
private _identity?;
|
|
3210
|
+
private _wallet?;
|
|
3211
|
+
private _walletInitPromise?;
|
|
3212
|
+
private _intent?;
|
|
3213
|
+
private _policy?;
|
|
3214
|
+
private _escrow?;
|
|
3215
|
+
private _ledger?;
|
|
3216
|
+
private _ledgerCompact?;
|
|
3217
|
+
private _verify?;
|
|
3218
|
+
private _atomic?;
|
|
3219
|
+
private _reputation?;
|
|
3220
|
+
private _gas?;
|
|
3221
|
+
private _x402?;
|
|
3222
|
+
private _erc8004?;
|
|
3223
|
+
private _erc8004Bridge?;
|
|
3224
|
+
private _marketplace?;
|
|
3225
|
+
private _auditTrail?;
|
|
3226
|
+
private _voting?;
|
|
3227
|
+
/**
|
|
3228
|
+
* Generate a fresh random wallet and return an Invariance client.
|
|
3229
|
+
*
|
|
3230
|
+
* @example
|
|
3231
|
+
* ```typescript
|
|
3232
|
+
* const inv = Invariance.createRandom({ chain: 'base-sepolia' });
|
|
3233
|
+
* console.log(inv.wallet.getAddress());
|
|
3234
|
+
* ```
|
|
3235
|
+
*/
|
|
3236
|
+
static createRandom(config?: Partial<InvarianceConfig>): Invariance;
|
|
3237
|
+
/**
|
|
3238
|
+
* Create a client from a hex private key string.
|
|
3239
|
+
*
|
|
3240
|
+
* @param key - Hex private key (with or without 0x prefix)
|
|
3241
|
+
* @param config - Optional SDK configuration overrides
|
|
3242
|
+
*
|
|
3243
|
+
* @example
|
|
3244
|
+
* ```typescript
|
|
3245
|
+
* const inv = Invariance.fromPrivateKey('0xabc...', { chain: 'base-sepolia' });
|
|
3246
|
+
* ```
|
|
3247
|
+
*/
|
|
3248
|
+
static fromPrivateKey(key: string, config?: Partial<InvarianceConfig>): Invariance;
|
|
3249
|
+
/**
|
|
3250
|
+
* Create a client from a BIP-39 mnemonic phrase.
|
|
3251
|
+
*
|
|
3252
|
+
* @param phrase - 12 or 24 word mnemonic
|
|
3253
|
+
* @param config - Optional SDK configuration overrides
|
|
3254
|
+
*
|
|
3255
|
+
* @example
|
|
3256
|
+
* ```typescript
|
|
3257
|
+
* const inv = Invariance.fromMnemonic('abandon abandon ... about', { chain: 'base' });
|
|
3258
|
+
* ```
|
|
3259
|
+
*/
|
|
3260
|
+
static fromMnemonic(phrase: string, config?: Partial<InvarianceConfig>): Invariance;
|
|
3261
|
+
constructor(config?: Partial<InvarianceConfig>);
|
|
3262
|
+
/**
|
|
3263
|
+
* Ensure wallet initialization is complete.
|
|
3264
|
+
* Call this before using any contract methods.
|
|
3265
|
+
*
|
|
3266
|
+
* @remarks
|
|
3267
|
+
* This is called automatically when accessing module getters,
|
|
3268
|
+
* so manual calls are rarely needed.
|
|
3269
|
+
*/
|
|
3270
|
+
ensureWalletInit(): Promise<void>;
|
|
3271
|
+
/**
|
|
3272
|
+
* Internal: ensure wallet init is complete.
|
|
3273
|
+
* Called automatically by module getters.
|
|
3274
|
+
* @internal
|
|
3275
|
+
*/
|
|
3276
|
+
private _autoInit;
|
|
3277
|
+
/**
|
|
3278
|
+
* Identity management module.
|
|
3279
|
+
*
|
|
3280
|
+
* Register agents, humans, devices as verified identities.
|
|
3281
|
+
* 10 methods: register, get, resolve, update, pause, resume, deactivate, list, attest, attestations
|
|
3282
|
+
*/
|
|
3283
|
+
get identity(): IdentityManager;
|
|
3284
|
+
/**
|
|
3285
|
+
* Ensure wallet is initialized before performing contract operations.
|
|
3286
|
+
* Automatically called internally; rarely needed by consumers.
|
|
3287
|
+
* @internal
|
|
3288
|
+
*/
|
|
3289
|
+
ready(): Promise<this>;
|
|
3290
|
+
/**
|
|
3291
|
+
* Wallet management module.
|
|
3292
|
+
*
|
|
3293
|
+
* Key management, embedded wallets via Privy.
|
|
3294
|
+
* 9 methods: create, connect, get, fund, balance, export, exportPrivateKey, signMessage, disconnect
|
|
3295
|
+
*/
|
|
3296
|
+
get wallet(): WalletManager;
|
|
3297
|
+
/**
|
|
3298
|
+
* Intent Protocol module.
|
|
3299
|
+
*
|
|
3300
|
+
* Request -> Approve -> Execute -> Verify handshake.
|
|
3301
|
+
* 6 methods: request, prepare, approve, reject, status, history
|
|
3302
|
+
*/
|
|
3303
|
+
get intent(): IntentProtocol;
|
|
3304
|
+
/**
|
|
3305
|
+
* Policy Engine module.
|
|
3306
|
+
*
|
|
3307
|
+
* Composable, verifiable condition sets.
|
|
3308
|
+
* 9 methods: create, attach, detach, evaluate, revoke, status, list, compose, onViolation
|
|
3309
|
+
*/
|
|
3310
|
+
get policy(): PolicyEngine;
|
|
3311
|
+
/**
|
|
3312
|
+
* Escrow module.
|
|
3313
|
+
*
|
|
3314
|
+
* USDC escrow with multi-sig, conditional release.
|
|
3315
|
+
* 11 methods: create, fund, release, refund, dispute, resolve, approve, approvals, status, list, onStateChange
|
|
3316
|
+
*/
|
|
3317
|
+
get escrow(): EscrowManager;
|
|
3318
|
+
/**
|
|
3319
|
+
* Event Ledger module.
|
|
3320
|
+
*
|
|
3321
|
+
* Immutable on-chain logging with dual signatures.
|
|
3322
|
+
* 5 methods: log, batch, query, stream, export
|
|
3323
|
+
*/
|
|
3324
|
+
get ledger(): EventLedger;
|
|
3325
|
+
/**
|
|
3326
|
+
* Compact Event Ledger module (fraud-proof).
|
|
3327
|
+
*
|
|
3328
|
+
* Uses CompactLedger with EIP-712 dual signatures verified on-chain.
|
|
3329
|
+
* Requires an API key for platform attestation.
|
|
3330
|
+
*
|
|
3331
|
+
* @example
|
|
3332
|
+
* ```typescript
|
|
3333
|
+
* const entry = await inv.ledgerCompact.log({
|
|
3334
|
+
* action: 'model-inference',
|
|
3335
|
+
* actor: { type: 'agent', address: '0xBot' },
|
|
3336
|
+
* });
|
|
3337
|
+
* ```
|
|
3338
|
+
*/
|
|
3339
|
+
get ledgerCompact(): EventLedgerCompact;
|
|
3340
|
+
/**
|
|
3341
|
+
* Atomic Verifier module.
|
|
3342
|
+
*
|
|
3343
|
+
* Identity check + policy eval + CompactLedger log in a single transaction.
|
|
3344
|
+
* Requires an API key for platform attestation.
|
|
3345
|
+
*
|
|
3346
|
+
* @example
|
|
3347
|
+
* ```typescript
|
|
3348
|
+
* const entry = await inv.atomic.verifyAndLog({
|
|
3349
|
+
* action: 'swap',
|
|
3350
|
+
* actor: { type: 'agent', address: '0xBot' },
|
|
3351
|
+
* });
|
|
3352
|
+
* ```
|
|
3353
|
+
*/
|
|
3354
|
+
get atomic(): AtomicVerifier;
|
|
3355
|
+
/**
|
|
3356
|
+
* Verify module.
|
|
3357
|
+
*
|
|
3358
|
+
* Cryptographic verification + public explorer URLs.
|
|
3359
|
+
* Supports both direct call `inv.verify(txHash)` and sub-methods.
|
|
3360
|
+
* 7 methods: verify (callable), action, identity, escrow, proof, bulk, url
|
|
3361
|
+
*/
|
|
3362
|
+
get verify(): VerifyProxy;
|
|
3363
|
+
/**
|
|
3364
|
+
* Reputation Engine module.
|
|
3365
|
+
*
|
|
3366
|
+
* Auto-calculated scores + 1-5 star reviews.
|
|
3367
|
+
* 7 methods: get, review, getReviews, score, compare, badge, history
|
|
3368
|
+
*/
|
|
3369
|
+
get reputation(): ReputationEngine;
|
|
3370
|
+
/**
|
|
3371
|
+
* Gas management module.
|
|
3372
|
+
*
|
|
3373
|
+
* Gas abstraction (USDC-based).
|
|
3374
|
+
* 2 methods: estimate, balance
|
|
3375
|
+
*/
|
|
3376
|
+
get gas(): GasManager;
|
|
3377
|
+
/**
|
|
3378
|
+
* X402 Payment Protocol module.
|
|
3379
|
+
*
|
|
3380
|
+
* Pay-per-action execution and agent-to-agent payments via x402.
|
|
3381
|
+
* 5 methods: payForAction, verifyPayment, history, estimateCost, configure
|
|
3382
|
+
*/
|
|
3383
|
+
get x402(): X402Manager;
|
|
3384
|
+
/**
|
|
3385
|
+
* ERC-8004 (Trustless Agents) module.
|
|
3386
|
+
*
|
|
3387
|
+
* Standalone manager for on-chain agent identity, reputation, and validation.
|
|
3388
|
+
* Works without any Invariance contracts — just ERC-8004 registries.
|
|
3389
|
+
* 14 methods: register, getAgent, setMetadata, getMetadata, setAgentWallet,
|
|
3390
|
+
* setAgentURI, getGlobalId, giveFeedback, revokeFeedback, getSummary,
|
|
3391
|
+
* readFeedback, readAllFeedback, requestValidation, respondToValidation,
|
|
3392
|
+
* getValidationStatus, getValidationSummary
|
|
3393
|
+
*/
|
|
3394
|
+
get erc8004(): ERC8004Manager;
|
|
3395
|
+
/**
|
|
3396
|
+
* ERC-8004 Bridge module.
|
|
3397
|
+
*
|
|
3398
|
+
* Optional bridge between ERC-8004 and Invariance modules.
|
|
3399
|
+
* Links identities, bridges reputation, enables cross-protocol validation.
|
|
3400
|
+
* 6 methods: linkIdentity, getLinkedIdentity, unlinkIdentity,
|
|
3401
|
+
* pullERC8004Reputation, pushFeedbackFromLedger, actAsValidator,
|
|
3402
|
+
* requestInvarianceValidation
|
|
3403
|
+
*/
|
|
3404
|
+
get erc8004Bridge(): InvarianceBridge;
|
|
3405
|
+
/**
|
|
3406
|
+
* Marketplace Kit module.
|
|
3407
|
+
*
|
|
3408
|
+
* Pre-built primitives for verified marketplaces: list, search, hire, complete.
|
|
3409
|
+
* 8 methods: register, update, deactivate, search, get, featured, hire, complete
|
|
3410
|
+
*/
|
|
3411
|
+
get marketplace(): MarketplaceKit;
|
|
3412
|
+
/**
|
|
3413
|
+
* Off-chain-first audit module with optional on-chain anchoring.
|
|
3414
|
+
*
|
|
3415
|
+
* Wallet account integrations remain unchanged: actor identity and signer
|
|
3416
|
+
* flow still use the configured wallet/account providers.
|
|
3417
|
+
*/
|
|
3418
|
+
get auditTrail(): AuditTrail;
|
|
3419
|
+
/**
|
|
3420
|
+
* Off-chain batch voting with merkle root settlement.
|
|
3421
|
+
*
|
|
3422
|
+
* Create proposals on-chain, collect EIP-712 signed votes off-chain,
|
|
3423
|
+
* then settle with a single merkle root transaction.
|
|
3424
|
+
* 10 methods: createProposal, castVote, buildMerkleTree, settleVotes,
|
|
3425
|
+
* generateProof, verifyVote, verifyVoteOffChain, getProposal, getVotes, didPass
|
|
3426
|
+
*/
|
|
3427
|
+
get voting(): VotingManager;
|
|
3428
|
+
/**
|
|
3429
|
+
* Create an auto-batching compact ledger that buffers `log()` calls
|
|
3430
|
+
* and flushes them as a single `logBatch()` transaction for ~85% gas savings.
|
|
3431
|
+
*
|
|
3432
|
+
* @param config - Batch configuration (maxBatchSize, maxWaitMs, enabled)
|
|
3433
|
+
* @returns Auto-batching compact ledger wrapper
|
|
3434
|
+
*
|
|
3435
|
+
* @example
|
|
3436
|
+
* ```typescript
|
|
3437
|
+
* const batched = inv.ledgerCompactBatched({ maxBatchSize: 10, maxWaitMs: 5000 });
|
|
3438
|
+
* await Promise.all(events.map(e => batched.log(e))); // 1 tx instead of N
|
|
3439
|
+
* await batched.destroy(); // flush remaining + cleanup
|
|
3440
|
+
* ```
|
|
3441
|
+
*/
|
|
3442
|
+
ledgerCompactBatched(config?: AutoBatchConfig): AutoBatchedEventLedgerCompact;
|
|
3443
|
+
/**
|
|
3444
|
+
* Register an identity, create a policy, and attach it in one call.
|
|
3445
|
+
*
|
|
3446
|
+
* @param opts - Identity and policy options
|
|
3447
|
+
* @returns The created identity and attached policy
|
|
3448
|
+
*
|
|
3449
|
+
* @example
|
|
3450
|
+
* ```typescript
|
|
3451
|
+
* const { identity, policy } = await inv.quickSetup({
|
|
3452
|
+
* identity: { type: 'agent', owner: '0xDev', label: 'TraderBot' },
|
|
3453
|
+
* policy: { name: 'trading-limits', rules: [{ type: 'max-spend', config: { amount: '1000' } }] },
|
|
3454
|
+
* });
|
|
3455
|
+
* ```
|
|
3456
|
+
*/
|
|
3457
|
+
quickSetup(opts: QuickSetupOptions): Promise<QuickSetupResult>;
|
|
3458
|
+
/**
|
|
3459
|
+
* Hire from a marketplace listing and auto-fund the escrow.
|
|
3460
|
+
*
|
|
3461
|
+
* @param opts - Hire options with optional fund amount override
|
|
3462
|
+
* @returns Hire result with funded escrow
|
|
3463
|
+
*
|
|
3464
|
+
* @example
|
|
3465
|
+
* ```typescript
|
|
3466
|
+
* const result = await inv.hireAndFund({
|
|
3467
|
+
* listingId: 'listing-123',
|
|
3468
|
+
* task: { description: 'Label 1000 images', deadline: '2025-06-01' },
|
|
3469
|
+
* payment: { amount: '500', type: 'escrow' },
|
|
3470
|
+
* });
|
|
3471
|
+
* ```
|
|
3472
|
+
*/
|
|
3473
|
+
hireAndFund(opts: HireAndFundOptions): Promise<_invariance_common.HireResult>;
|
|
3474
|
+
/**
|
|
3475
|
+
* Register multiple agents with a shared policy in one call.
|
|
3476
|
+
*
|
|
3477
|
+
* @param opts - Batch of agents and a shared policy
|
|
3478
|
+
* @returns Array of registered identities with attached policies
|
|
3479
|
+
*
|
|
3480
|
+
* @example
|
|
3481
|
+
* ```typescript
|
|
3482
|
+
* const agents = await inv.batchRegister({
|
|
3483
|
+
* agents: [
|
|
3484
|
+
* { identity: { type: 'agent', owner: '0xDev', label: 'Worker-1' } },
|
|
3485
|
+
* { identity: { type: 'agent', owner: '0xDev', label: 'Worker-2' } },
|
|
3486
|
+
* ],
|
|
3487
|
+
* sharedPolicy: { name: 'worker-policy', rules: [{ type: 'rate-limit', config: { max: 100, window: 'PT1H' } }] },
|
|
3488
|
+
* });
|
|
3489
|
+
* ```
|
|
3490
|
+
*/
|
|
3491
|
+
batchRegister(opts: BatchRegisterOptions): Promise<BatchRegisterEntry[]>;
|
|
3492
|
+
/**
|
|
3493
|
+
* Execute an intent and log a custom ledger event in one call.
|
|
3494
|
+
*
|
|
3495
|
+
* @param opts - Intent request options and ledger event input
|
|
3496
|
+
* @returns The intent result and logged ledger entry
|
|
3497
|
+
*
|
|
3498
|
+
* @example
|
|
3499
|
+
* ```typescript
|
|
3500
|
+
* const { intent, log } = await inv.executeAndLog({
|
|
3501
|
+
* intent: {
|
|
3502
|
+
* actor: { type: 'agent', address: '0xAgent' },
|
|
3503
|
+
* action: 'moderate',
|
|
3504
|
+
* params: { contentId: 'post-456' },
|
|
3505
|
+
* approval: 'auto',
|
|
3506
|
+
* },
|
|
3507
|
+
* log: {
|
|
3508
|
+
* action: 'content-moderated',
|
|
3509
|
+
* actor: { type: 'agent', address: '0xAgent' },
|
|
3510
|
+
* category: 'custom',
|
|
3511
|
+
* metadata: { contentId: 'post-456', verdict: 'approved' },
|
|
3512
|
+
* },
|
|
3513
|
+
* });
|
|
3514
|
+
* ```
|
|
3515
|
+
*/
|
|
3516
|
+
executeAndLog(opts: ExecuteAndLogOptions): Promise<ExecuteAndLogResult>;
|
|
3517
|
+
/**
|
|
3518
|
+
* Gate any async action through SDK lifecycle + audit logging.
|
|
3519
|
+
*
|
|
3520
|
+
* Defaults to off-chain logging via infrastructure APIs. Per-action mode can
|
|
3521
|
+
* be overridden with `opts.mode` (`offchain`, `onchain`, or `dual`).
|
|
3522
|
+
*/
|
|
3523
|
+
gateAction<T>(opts: GateActionOptions, executor: () => Promise<T>): Promise<GateActionResult<T>>;
|
|
3524
|
+
/**
|
|
3525
|
+
* Create a policy configured for recurring payments with time-window rules.
|
|
3526
|
+
*
|
|
3527
|
+
* @param opts - Recurring payment configuration
|
|
3528
|
+
* @returns The created policy
|
|
3529
|
+
*
|
|
3530
|
+
* @example
|
|
3531
|
+
* ```typescript
|
|
3532
|
+
* const policy = await inv.recurringPayment({
|
|
3533
|
+
* name: 'monthly-subscription',
|
|
3534
|
+
* amount: '50',
|
|
3535
|
+
* recipient: '0xService',
|
|
3536
|
+
* interval: 'P1M',
|
|
3537
|
+
* maxPayments: 12,
|
|
3538
|
+
* });
|
|
3539
|
+
* ```
|
|
3540
|
+
*/
|
|
3541
|
+
recurringPayment(opts: RecurringPaymentOptions): Promise<SpecPolicy>;
|
|
3542
|
+
/**
|
|
3543
|
+
* Create a multi-sig escrow with simplified options.
|
|
3544
|
+
*
|
|
3545
|
+
* @param opts - Multi-sig escrow configuration
|
|
3546
|
+
* @returns The created escrow contract
|
|
3547
|
+
*
|
|
3548
|
+
* @example
|
|
3549
|
+
* ```typescript
|
|
3550
|
+
* const escrow = await inv.createMultiSig({
|
|
3551
|
+
* amount: '10000',
|
|
3552
|
+
* recipient: { type: 'agent', address: '0xAgent' },
|
|
3553
|
+
* signers: ['0xSigner1', '0xSigner2', '0xSigner3'],
|
|
3554
|
+
* threshold: 2,
|
|
3555
|
+
* });
|
|
3556
|
+
* ```
|
|
3557
|
+
*/
|
|
3558
|
+
createMultiSig(opts: CreateMultiSigOptions): Promise<EscrowContract>;
|
|
3559
|
+
/**
|
|
3560
|
+
* Register an agent with rate-limit and cooldown policies pre-configured.
|
|
3561
|
+
*
|
|
3562
|
+
* @param opts - Agent identity and rate limit configuration
|
|
3563
|
+
* @returns The created identity and rate-limit policy
|
|
3564
|
+
*
|
|
3565
|
+
* @example
|
|
3566
|
+
* ```typescript
|
|
3567
|
+
* const { identity, policy } = await inv.setupRateLimitedAgent({
|
|
3568
|
+
* identity: { type: 'agent', owner: '0xDev', label: 'SupportBot' },
|
|
3569
|
+
* maxActions: 100,
|
|
3570
|
+
* window: 'PT1H',
|
|
3571
|
+
* cooldown: 'PT5S',
|
|
3572
|
+
* allowedActions: ['reply', 'escalate', 'close'],
|
|
3573
|
+
* });
|
|
3574
|
+
* ```
|
|
3575
|
+
*/
|
|
3576
|
+
setupRateLimitedAgent(opts: SetupRateLimitedAgentOptions): Promise<QuickSetupResult>;
|
|
3577
|
+
/**
|
|
3578
|
+
* Complete the full hire → complete → review flow in one call.
|
|
3579
|
+
*
|
|
3580
|
+
* @param opts - Hire, completion, and review options
|
|
3581
|
+
* @returns Combined result with hire, completion, and review data
|
|
3582
|
+
*
|
|
3583
|
+
* @example
|
|
3584
|
+
* ```typescript
|
|
3585
|
+
* const result = await inv.hireAndReview({
|
|
3586
|
+
* hire: {
|
|
3587
|
+
* listingId: 'listing-123',
|
|
3588
|
+
* task: { description: 'Analyze dataset', deadline: '2025-06-01' },
|
|
3589
|
+
* payment: { amount: '200', type: 'escrow' },
|
|
3590
|
+
* },
|
|
3591
|
+
* review: { rating: 5, comment: 'Excellent work' },
|
|
3592
|
+
* });
|
|
3593
|
+
* ```
|
|
3594
|
+
*/
|
|
3595
|
+
hireAndReview(opts: HireAndReviewOptions): Promise<HireAndReviewResult>;
|
|
3596
|
+
/**
|
|
3597
|
+
* Query ledger entries, optionally verify each one, and export a report.
|
|
3598
|
+
*
|
|
3599
|
+
* @param opts - Audit query filters and options
|
|
3600
|
+
* @returns Audit report with entries, verification results, and optional export
|
|
3601
|
+
*
|
|
3602
|
+
* @example
|
|
3603
|
+
* ```typescript
|
|
3604
|
+
* const report = await inv.audit({
|
|
3605
|
+
* actor: '0xAgent',
|
|
3606
|
+
* from: '2025-01-01',
|
|
3607
|
+
* to: '2025-06-01',
|
|
3608
|
+
* verify: true,
|
|
3609
|
+
* exportFormat: 'json',
|
|
3610
|
+
* });
|
|
3611
|
+
* console.log(`${report.verifiedCount}/${report.totalEntries} entries verified`);
|
|
3612
|
+
* ```
|
|
3613
|
+
*/
|
|
3614
|
+
audit(opts: AuditOptions): Promise<AuditReport>;
|
|
3615
|
+
/**
|
|
3616
|
+
* Create a scoped child policy for agent-to-agent delegation.
|
|
3617
|
+
*
|
|
3618
|
+
* @param opts - Delegation scope and agent identifiers
|
|
3619
|
+
* @returns The delegation policy and intent recording the delegation
|
|
3620
|
+
*
|
|
3621
|
+
* @example
|
|
3622
|
+
* ```typescript
|
|
3623
|
+
* const { policy, intent } = await inv.delegate({
|
|
3624
|
+
* from: 'identity-orchestrator',
|
|
3625
|
+
* to: 'identity-worker',
|
|
3626
|
+
* scope: {
|
|
3627
|
+
* actions: ['fetch-data', 'transform'],
|
|
3628
|
+
* maxSpend: '50',
|
|
3629
|
+
* expiry: '2025-06-01T00:00:00Z',
|
|
3630
|
+
* },
|
|
3631
|
+
* });
|
|
3632
|
+
* ```
|
|
3633
|
+
*/
|
|
3634
|
+
delegate(opts: DelegateOptions): Promise<DelegateResult>;
|
|
3635
|
+
/**
|
|
3636
|
+
* Execute multiple operations with concurrency control and error handling.
|
|
3637
|
+
*
|
|
3638
|
+
* @param operations - Operations to execute
|
|
3639
|
+
* @param options - Batch execution options
|
|
3640
|
+
* @returns Aggregated results with success/failure counts
|
|
3641
|
+
*
|
|
3642
|
+
* @example
|
|
3643
|
+
* ```typescript
|
|
3644
|
+
* const results = await inv.batch([
|
|
3645
|
+
* { execute: () => inv.identity.register({...}), description: 'Register Bot1' },
|
|
3646
|
+
* { execute: () => inv.identity.register({...}), description: 'Register Bot2' },
|
|
3647
|
+
* ], { continueOnError: true, maxConcurrency: 3 });
|
|
3648
|
+
* ```
|
|
3649
|
+
*/
|
|
3650
|
+
batch<T = unknown>(operations: DeferredOperation<T>[], options?: BatchOptions): Promise<BatchResult<T>>;
|
|
3651
|
+
/**
|
|
3652
|
+
* Create a session context bound to a specific actor.
|
|
3653
|
+
*
|
|
3654
|
+
* All operations on the returned session automatically use the bound actor.
|
|
3655
|
+
*
|
|
3656
|
+
* @param options - Session options with actor reference
|
|
3657
|
+
* @returns Session context with actor-scoped methods
|
|
3658
|
+
*
|
|
3659
|
+
* @example
|
|
3660
|
+
* ```typescript
|
|
3661
|
+
* const session = inv.session({ actor: { type: 'agent', address: '0xBot' } });
|
|
3662
|
+
* await session.requestIntent({ action: 'swap', params: {...} });
|
|
3663
|
+
* ```
|
|
3664
|
+
*/
|
|
3665
|
+
session(options: SessionOptions): SessionContext;
|
|
3666
|
+
/**
|
|
3667
|
+
* Create a fluent pipeline builder for multi-step workflows.
|
|
3668
|
+
*
|
|
3669
|
+
* @returns Pipeline builder with chainable methods
|
|
3670
|
+
*
|
|
3671
|
+
* @example
|
|
3672
|
+
* ```typescript
|
|
3673
|
+
* const result = await inv.pipeline()
|
|
3674
|
+
* .register({ type: 'agent', label: 'Bot', owner: '0x...' })
|
|
3675
|
+
* .createPolicy({ template: 'defi-trading' })
|
|
3676
|
+
* .attachPolicy()
|
|
3677
|
+
* .execute();
|
|
3678
|
+
* ```
|
|
3679
|
+
*/
|
|
3680
|
+
pipeline(): PipelineBuilder;
|
|
3681
|
+
/**
|
|
3682
|
+
* Register a callback to run before every intent action.
|
|
3683
|
+
*
|
|
3684
|
+
* @param callback - Called before each action with action details
|
|
3685
|
+
* @returns Unsubscribe function
|
|
3686
|
+
*/
|
|
3687
|
+
beforeAction(callback: (data: InvarianceEvents['action.before']) => void): () => void;
|
|
3688
|
+
/**
|
|
3689
|
+
* Register a callback to run after every intent action.
|
|
3690
|
+
*
|
|
3691
|
+
* @param callback - Called after each action with result details
|
|
3692
|
+
* @returns Unsubscribe function
|
|
3693
|
+
*/
|
|
3694
|
+
afterAction(callback: (data: InvarianceEvents['action.after']) => void): () => void;
|
|
3695
|
+
/**
|
|
3696
|
+
* Register a callback for policy violation events.
|
|
3697
|
+
*
|
|
3698
|
+
* @param callback - Called when a violation occurs
|
|
3699
|
+
* @returns Unsubscribe function
|
|
3700
|
+
*/
|
|
3701
|
+
onViolation(callback: (data: InvarianceEvents['action.violation']) => void): () => void;
|
|
3702
|
+
/**
|
|
3703
|
+
* Register a callback for error events.
|
|
3704
|
+
*
|
|
3705
|
+
* @param callback - Called when an error occurs
|
|
3706
|
+
* @returns Unsubscribe function
|
|
3707
|
+
*/
|
|
3708
|
+
onError(callback: (data: InvarianceEvents['action.error']) => void): () => void;
|
|
3709
|
+
/**
|
|
3710
|
+
* Get the raw configuration object.
|
|
3711
|
+
*/
|
|
3712
|
+
getConfig(): InvarianceConfig;
|
|
3713
|
+
/**
|
|
3714
|
+
* Get the current SDK version.
|
|
3715
|
+
*/
|
|
3716
|
+
get version(): string;
|
|
3717
|
+
/**
|
|
3718
|
+
* Get the chain configuration.
|
|
3719
|
+
*/
|
|
3720
|
+
getChainConfig(): _invariance_common.ChainConfig;
|
|
3721
|
+
/**
|
|
3722
|
+
* Get all contract addresses for the current chain.
|
|
3723
|
+
*/
|
|
3724
|
+
getContractAddresses(): _invariance_common.ContractAddresses;
|
|
3725
|
+
/**
|
|
3726
|
+
* Get the explorer base URL.
|
|
3727
|
+
*/
|
|
3728
|
+
getExplorerBaseUrl(): string;
|
|
3729
|
+
/**
|
|
3730
|
+
* Subscribe to SDK-level events.
|
|
3731
|
+
*
|
|
3732
|
+
* @param event - Event name
|
|
3733
|
+
* @param listener - Callback
|
|
3734
|
+
* @returns Unsubscribe function
|
|
3735
|
+
*/
|
|
3736
|
+
on<K extends keyof InvarianceEvents>(event: K, listener: (data: InvarianceEvents[K]) => void): () => void;
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
/**
|
|
3740
|
+
* Batch executor for running multiple operations with concurrency control.
|
|
3741
|
+
*
|
|
3742
|
+
* @example
|
|
3743
|
+
* ```typescript
|
|
3744
|
+
* const results = await inv.batch([
|
|
3745
|
+
* { execute: () => inv.identity.register({...}), description: 'Register Bot1' },
|
|
3746
|
+
* { execute: () => inv.identity.register({...}), description: 'Register Bot2' },
|
|
3747
|
+
* ], { continueOnError: true, maxConcurrency: 3 });
|
|
3748
|
+
* ```
|
|
3749
|
+
*/
|
|
3750
|
+
|
|
3751
|
+
/**
|
|
3752
|
+
* Execute a batch of operations with concurrency control and error handling.
|
|
3753
|
+
*/
|
|
3754
|
+
declare class BatchExecutor {
|
|
3755
|
+
/**
|
|
3756
|
+
* Execute operations with configurable concurrency and error handling.
|
|
3757
|
+
*
|
|
3758
|
+
* @param operations - Operations to execute
|
|
3759
|
+
* @param options - Batch execution options
|
|
3760
|
+
* @returns Aggregated results with success/failure counts
|
|
3761
|
+
*/
|
|
3762
|
+
execute<T = unknown>(operations: DeferredOperation<T>[], options?: BatchOptions): Promise<BatchResult<T>>;
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
/**
|
|
3766
|
+
* Base error class for all Invariance SDK errors.
|
|
3767
|
+
*
|
|
3768
|
+
* Every SDK error carries a structured {@link ErrorCode} for programmatic handling,
|
|
3769
|
+
* along with optional explorer URL and transaction hash for on-chain debugging.
|
|
3770
|
+
*
|
|
3771
|
+
* @example
|
|
3772
|
+
* ```typescript
|
|
3773
|
+
* try {
|
|
3774
|
+
* await inv.intent.request(opts);
|
|
3775
|
+
* } catch (err) {
|
|
3776
|
+
* if (err instanceof InvarianceError) {
|
|
3777
|
+
* console.error(err.code, err.message, err.explorerUrl);
|
|
3778
|
+
* }
|
|
3779
|
+
* }
|
|
3780
|
+
* ```
|
|
3781
|
+
*/
|
|
3782
|
+
declare class InvarianceError extends Error {
|
|
3783
|
+
/** Structured error code for programmatic handling */
|
|
3784
|
+
readonly code: ErrorCode;
|
|
3785
|
+
/** Public explorer URL relevant to the error context */
|
|
3786
|
+
readonly explorerUrl?: string | undefined;
|
|
3787
|
+
/** On-chain transaction hash related to the error */
|
|
3788
|
+
readonly txHash?: string | undefined;
|
|
3789
|
+
constructor(code: ErrorCode, message: string, opts?: {
|
|
3790
|
+
explorerUrl?: string;
|
|
3791
|
+
txHash?: string;
|
|
3792
|
+
});
|
|
3793
|
+
}
|
|
3794
|
+
|
|
3795
|
+
/**
|
|
3796
|
+
* Canonical ERC-8004 registry addresses per chain.
|
|
3797
|
+
*
|
|
3798
|
+
* **IMPORTANT — Testnet placeholders only.**
|
|
3799
|
+
* The addresses below are synthetic pre-deployment values (sequential hex pattern).
|
|
3800
|
+
* They do NOT correspond to deployed contracts. Before using ERC-8004 features in
|
|
3801
|
+
* production, you **must** override these with real deployed addresses via
|
|
3802
|
+
* `Invariance({ erc8004: { addresses: { identity, reputation, validation } } })`.
|
|
3803
|
+
*
|
|
3804
|
+
* @todo Replace with actual deployed contract addresses after ERC-8004 registry deployment.
|
|
3805
|
+
*/
|
|
3806
|
+
|
|
3807
|
+
/**
|
|
3808
|
+
* Get ERC-8004 registry addresses for a given chain.
|
|
3809
|
+
*
|
|
3810
|
+
* @param chainId - The chain ID
|
|
3811
|
+
* @returns Registry addresses or undefined if not supported
|
|
3812
|
+
*/
|
|
3813
|
+
declare function getERC8004Addresses(chainId: number): ERC8004RegistryAddresses | undefined;
|
|
3814
|
+
/**
|
|
3815
|
+
* Check if ERC-8004 is supported on a given chain.
|
|
3816
|
+
*
|
|
3817
|
+
* @param chainId - The chain ID
|
|
3818
|
+
* @returns Whether ERC-8004 registries are deployed on this chain
|
|
3819
|
+
*/
|
|
3820
|
+
declare function isERC8004Supported(chainId: number): boolean;
|
|
3821
|
+
|
|
3822
|
+
/**
|
|
3823
|
+
* Verify an Invariance webhook HMAC-SHA256 signature.
|
|
3824
|
+
*
|
|
3825
|
+
* Use this in your webhook endpoint to verify that incoming
|
|
3826
|
+
* payloads are genuinely from Invariance and have not been tampered with.
|
|
3827
|
+
*
|
|
3828
|
+
* @param body - The raw request body (string or object)
|
|
3829
|
+
* @param signature - The signature from the `X-Invariance-Signature` header
|
|
3830
|
+
* @param secret - Your webhook secret (from webhook registration)
|
|
3831
|
+
* @returns True if the signature is valid
|
|
3832
|
+
*
|
|
3833
|
+
* @example
|
|
3834
|
+
* ```typescript
|
|
3835
|
+
* import { verifyWebhookSignature } from '@invariance/sdk';
|
|
3836
|
+
*
|
|
3837
|
+
* app.post('/webhooks/invariance', (req, res) => {
|
|
3838
|
+
* const sig = req.headers['x-invariance-signature'];
|
|
3839
|
+
* if (!verifyWebhookSignature(req.body, sig, WEBHOOK_SECRET)) {
|
|
3840
|
+
* return res.status(401).send('Invalid signature');
|
|
3841
|
+
* }
|
|
3842
|
+
* // Process webhook...
|
|
3843
|
+
* });
|
|
3844
|
+
* ```
|
|
3845
|
+
*/
|
|
3846
|
+
declare function verifyWebhookSignature(body: unknown, signature: string, secret: string): boolean;
|
|
3847
|
+
|
|
3848
|
+
/**
|
|
3849
|
+
* Generic pre/post action hooks for ANY agent runtime.
|
|
3850
|
+
* 3-line integration for any framework.
|
|
3851
|
+
*
|
|
3852
|
+
* @example
|
|
3853
|
+
* ```typescript
|
|
3854
|
+
* const hooks = new RuntimeHookAdapter(inv);
|
|
3855
|
+
* const { allowed } = await hooks.beforeAction({ action: 'swap', actor, params: {} });
|
|
3856
|
+
* await hooks.afterAction(ctx, { success: true, txHash: '0x...' });
|
|
3857
|
+
* ```
|
|
3858
|
+
*/
|
|
3859
|
+
|
|
3860
|
+
/** Action context passed through hooks */
|
|
3861
|
+
interface ActionContext {
|
|
3862
|
+
/** Action identifier (e.g., 'swap', 'transfer') */
|
|
3863
|
+
action: string;
|
|
3864
|
+
/** Actor performing the action */
|
|
3865
|
+
actor: ActorReference;
|
|
3866
|
+
/** Action parameters */
|
|
3867
|
+
params: Record<string, unknown>;
|
|
3868
|
+
/** Optional policy to evaluate against */
|
|
3869
|
+
policyId?: string;
|
|
3870
|
+
/** Timestamp of action initiation */
|
|
3871
|
+
timestamp: number;
|
|
3872
|
+
}
|
|
3873
|
+
/** Result from beforeAction hook */
|
|
3874
|
+
interface BeforeActionResult {
|
|
3875
|
+
/** Whether the action is permitted */
|
|
3876
|
+
allowed: boolean;
|
|
3877
|
+
/** Reason if denied */
|
|
3878
|
+
reason?: string;
|
|
3879
|
+
/** Policy evaluation details */
|
|
3880
|
+
policyId?: string;
|
|
3881
|
+
}
|
|
3882
|
+
/** Result from afterAction hook */
|
|
3883
|
+
interface AfterActionResult {
|
|
3884
|
+
/** Ledger entry ID */
|
|
3885
|
+
entryId: string;
|
|
3886
|
+
/** Transaction hash */
|
|
3887
|
+
txHash: string;
|
|
3888
|
+
/** Duration in milliseconds */
|
|
3889
|
+
durationMs: number;
|
|
3890
|
+
}
|
|
3891
|
+
/** Hook callbacks for custom logic */
|
|
3892
|
+
interface RuntimeHooks {
|
|
3893
|
+
/** Called before policy evaluation */
|
|
3894
|
+
onBeforeEvaluate?: (ctx: ActionContext) => Promise<void> | void;
|
|
3895
|
+
/** Called after policy evaluation, before execution */
|
|
3896
|
+
onAfterEvaluate?: (ctx: ActionContext, result: BeforeActionResult) => Promise<void> | void;
|
|
3897
|
+
/** Called after logging */
|
|
3898
|
+
onAfterLog?: (ctx: ActionContext, result: AfterActionResult) => Promise<void> | void;
|
|
3899
|
+
/** Called on any error */
|
|
3900
|
+
onError?: (ctx: ActionContext, error: Error) => Promise<void> | void;
|
|
3901
|
+
}
|
|
3902
|
+
/**
|
|
3903
|
+
* RuntimeHookAdapter — drop-in verification for any agent runtime.
|
|
3904
|
+
*
|
|
3905
|
+
* @example
|
|
3906
|
+
* ```typescript
|
|
3907
|
+
* const hooks = new RuntimeHookAdapter(inv);
|
|
3908
|
+
* // Wrap any agent action:
|
|
3909
|
+
* const { result, log } = await hooks.wrap(
|
|
3910
|
+
* { action: 'swap', actor: { type: 'agent', address: '0x...' }, params: {} },
|
|
3911
|
+
* () => executeSwap(),
|
|
3912
|
+
* );
|
|
3913
|
+
* ```
|
|
3914
|
+
*/
|
|
3915
|
+
declare class RuntimeHookAdapter {
|
|
3916
|
+
private readonly client;
|
|
3917
|
+
private readonly hooks;
|
|
3918
|
+
constructor(client: Invariance, hooks?: RuntimeHooks);
|
|
3919
|
+
/**
|
|
3920
|
+
* Evaluate policy and request intent before action execution.
|
|
3921
|
+
*/
|
|
3922
|
+
beforeAction(ctx: Omit<ActionContext, 'timestamp'>): Promise<BeforeActionResult>;
|
|
3923
|
+
/**
|
|
3924
|
+
* Log action result to immutable ledger after execution.
|
|
3925
|
+
*/
|
|
3926
|
+
afterAction(ctx: Omit<ActionContext, 'timestamp'>, outcome: {
|
|
3927
|
+
success: boolean;
|
|
3928
|
+
txHash?: string;
|
|
3929
|
+
error?: string;
|
|
3930
|
+
metadata?: Record<string, unknown>;
|
|
3931
|
+
}): Promise<AfterActionResult>;
|
|
3932
|
+
/**
|
|
3933
|
+
* Wrap an async function with before/after hooks.
|
|
3934
|
+
*/
|
|
3935
|
+
wrap<T>(ctx: Omit<ActionContext, 'timestamp'>, fn: () => Promise<T>): Promise<{
|
|
3936
|
+
result: T;
|
|
3937
|
+
log: AfterActionResult;
|
|
3938
|
+
}>;
|
|
3939
|
+
}
|
|
3940
|
+
|
|
3941
|
+
/**
|
|
3942
|
+
* Setup crews with shared budgets and per-role policies.
|
|
3943
|
+
*
|
|
3944
|
+
* @example
|
|
3945
|
+
* ```typescript
|
|
3946
|
+
* const composer = new MultiAgentComposer(inv);
|
|
3947
|
+
* const crew = await composer.setupCrew({
|
|
3948
|
+
* name: 'research-crew',
|
|
3949
|
+
* budget: '5000',
|
|
3950
|
+
* roles: [
|
|
3951
|
+
* { name: 'researcher', rules: [], allowedActions: ['query', 'analyze'] },
|
|
3952
|
+
* { name: 'executor', rules: [], allowedActions: ['swap', 'transfer'], maxSpend: '1000' },
|
|
3953
|
+
* ],
|
|
3954
|
+
* members: [
|
|
3955
|
+
* { identity: { type: 'agent', owner: '0xDev', label: 'R-1' }, role: 'researcher' },
|
|
3956
|
+
* ],
|
|
3957
|
+
* signers: ['0xSigner1', '0xSigner2'],
|
|
3958
|
+
* threshold: 2,
|
|
3959
|
+
* });
|
|
3960
|
+
* ```
|
|
3961
|
+
*/
|
|
3962
|
+
|
|
3963
|
+
/** Role definition for a crew member */
|
|
3964
|
+
interface CrewRole {
|
|
3965
|
+
/** Role identifier (e.g., 'researcher', 'executor', 'reviewer') */
|
|
3966
|
+
name: string;
|
|
3967
|
+
/** Policy rules specific to this role */
|
|
3968
|
+
rules: PolicyRule[];
|
|
3969
|
+
/** Optional spending limit override for this role */
|
|
3970
|
+
maxSpend?: string;
|
|
3971
|
+
/** Allowed actions for this role */
|
|
3972
|
+
allowedActions?: string[];
|
|
3973
|
+
}
|
|
3974
|
+
/** Agent to register as part of a crew */
|
|
3975
|
+
interface CrewMember {
|
|
3976
|
+
/** Identity registration options */
|
|
3977
|
+
identity: {
|
|
3978
|
+
type: 'agent' | 'human' | 'device' | 'service';
|
|
3979
|
+
owner: string;
|
|
3980
|
+
label: string;
|
|
3981
|
+
metadata?: Record<string, unknown>;
|
|
3982
|
+
};
|
|
3983
|
+
/** Role name from the crew's role definitions */
|
|
3984
|
+
role: string;
|
|
3985
|
+
}
|
|
3986
|
+
/** Options for setting up a crew */
|
|
3987
|
+
interface SetupCrewOptions {
|
|
3988
|
+
/** Crew name */
|
|
3989
|
+
name: string;
|
|
3990
|
+
/** Shared budget amount in USDC */
|
|
3991
|
+
budget: string;
|
|
3992
|
+
/** Role definitions */
|
|
3993
|
+
roles: CrewRole[];
|
|
3994
|
+
/** Members to register */
|
|
3995
|
+
members: CrewMember[];
|
|
3996
|
+
/** Multi-sig signers for budget release */
|
|
3997
|
+
signers: string[];
|
|
3998
|
+
/** Required signatures for budget release */
|
|
3999
|
+
threshold: number;
|
|
4000
|
+
/** Budget escrow timeout (ISO 8601 duration, default: P30D) */
|
|
4001
|
+
timeout?: string;
|
|
4002
|
+
/** Shared policy rules that apply to ALL members */
|
|
4003
|
+
sharedRules?: PolicyRule[];
|
|
4004
|
+
}
|
|
4005
|
+
/** Result of crew setup */
|
|
4006
|
+
interface CrewSetupResult {
|
|
4007
|
+
/** Crew identifier */
|
|
4008
|
+
crewId: string;
|
|
4009
|
+
/** Registered member identities */
|
|
4010
|
+
members: Array<{
|
|
4011
|
+
identity: Identity;
|
|
4012
|
+
role: string;
|
|
4013
|
+
policy: SpecPolicy;
|
|
4014
|
+
}>;
|
|
4015
|
+
/** Shared budget escrow */
|
|
4016
|
+
escrow: EscrowContract;
|
|
4017
|
+
/** Shared policy (applied to all members) */
|
|
4018
|
+
sharedPolicy: SpecPolicy;
|
|
4019
|
+
}
|
|
4020
|
+
/**
|
|
4021
|
+
* MultiAgentComposer — orchestrate agent crews with shared budgets and role-based policies.
|
|
4022
|
+
*/
|
|
4023
|
+
declare class MultiAgentComposer {
|
|
4024
|
+
private readonly client;
|
|
4025
|
+
constructor(client: Invariance);
|
|
4026
|
+
/**
|
|
4027
|
+
* Register a crew of agents with shared budget and role-based policies.
|
|
4028
|
+
*/
|
|
4029
|
+
setupCrew(opts: SetupCrewOptions): Promise<CrewSetupResult>;
|
|
4030
|
+
/**
|
|
4031
|
+
* Add a new member to an existing crew.
|
|
4032
|
+
*/
|
|
4033
|
+
addMember(crewSharedPolicyId: string, member: CrewMember, role: CrewRole, crewName: string): Promise<{
|
|
4034
|
+
identity: Identity;
|
|
4035
|
+
policy: SpecPolicy;
|
|
4036
|
+
}>;
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
/**
|
|
4040
|
+
* Publish agents to external stores with verified badges.
|
|
4041
|
+
*
|
|
4042
|
+
* @example
|
|
4043
|
+
* ```typescript
|
|
4044
|
+
* const plugin = new MarketplacePlugin(inv);
|
|
4045
|
+
* const { listing, badge } = await plugin.publishAgent({
|
|
4046
|
+
* identity: 'identity-123',
|
|
4047
|
+
* name: 'DataAnalyzer',
|
|
4048
|
+
* description: 'Analyzes datasets with ML',
|
|
4049
|
+
* category: 'analytics',
|
|
4050
|
+
* pricing: { model: 'per-task', amount: '50' },
|
|
4051
|
+
* generateBadge: true,
|
|
4052
|
+
* });
|
|
4053
|
+
* ```
|
|
4054
|
+
*/
|
|
4055
|
+
|
|
4056
|
+
/** Options for publishing an agent */
|
|
4057
|
+
interface PublishAgentOptions extends RegisterListingOptions {
|
|
4058
|
+
/** Auto-generate a reputation badge on publish */
|
|
4059
|
+
generateBadge?: boolean;
|
|
4060
|
+
/** Minimum reputation score required for badge */
|
|
4061
|
+
badgeThreshold?: number;
|
|
4062
|
+
}
|
|
4063
|
+
/** Result of publishing an agent */
|
|
4064
|
+
interface PublishResult {
|
|
4065
|
+
/** Created marketplace listing */
|
|
4066
|
+
listing: Listing;
|
|
4067
|
+
/** Generated badge (if requested) */
|
|
4068
|
+
badge?: Badge;
|
|
4069
|
+
}
|
|
4070
|
+
/** Options for hiring with escrow */
|
|
4071
|
+
interface HireWithEscrowOptions {
|
|
4072
|
+
/** Listing ID to hire from */
|
|
4073
|
+
listingId: string;
|
|
4074
|
+
/** Task description */
|
|
4075
|
+
task: {
|
|
4076
|
+
description: string;
|
|
4077
|
+
deadline?: string;
|
|
4078
|
+
};
|
|
4079
|
+
/** Payment configuration */
|
|
4080
|
+
payment: {
|
|
4081
|
+
amount: string;
|
|
4082
|
+
type: 'escrow';
|
|
4083
|
+
};
|
|
4084
|
+
/** Optional fund amount override */
|
|
4085
|
+
fundAmount?: string;
|
|
4086
|
+
}
|
|
4087
|
+
/**
|
|
4088
|
+
* MarketplacePlugin — simplified publish + hire flows with verified badges.
|
|
4089
|
+
*/
|
|
4090
|
+
declare class MarketplacePlugin {
|
|
4091
|
+
private readonly client;
|
|
4092
|
+
constructor(client: Invariance);
|
|
4093
|
+
/**
|
|
4094
|
+
* Publish an agent listing with optional reputation badge.
|
|
4095
|
+
*/
|
|
4096
|
+
publishAgent(opts: PublishAgentOptions): Promise<PublishResult>;
|
|
4097
|
+
/**
|
|
4098
|
+
* Hire an agent with automatic escrow funding.
|
|
4099
|
+
*/
|
|
4100
|
+
hireWithEscrow(opts: HireWithEscrowOptions): Promise<HireResult>;
|
|
4101
|
+
/**
|
|
4102
|
+
* Get verified listing with reputation data.
|
|
4103
|
+
*/
|
|
4104
|
+
getVerifiedListing(listingId: string): Promise<{
|
|
4105
|
+
listing: Listing;
|
|
4106
|
+
badge?: Badge;
|
|
4107
|
+
}>;
|
|
4108
|
+
}
|
|
4109
|
+
|
|
4110
|
+
/**
|
|
4111
|
+
* Import/aggregate scores from external platforms.
|
|
4112
|
+
*
|
|
4113
|
+
* @example
|
|
4114
|
+
* ```typescript
|
|
4115
|
+
* const bridge = new ReputationBridge(inv);
|
|
4116
|
+
* bridge.importExternalScore('identity-123', {
|
|
4117
|
+
* platform: 'gitcoin',
|
|
4118
|
+
* score: 85,
|
|
4119
|
+
* proofUrl: 'https://passport.gitcoin.co/...',
|
|
4120
|
+
* fetchedAt: Date.now(),
|
|
4121
|
+
* });
|
|
4122
|
+
* const agg = await bridge.getAggregatedScore('identity-123');
|
|
4123
|
+
* ```
|
|
4124
|
+
*/
|
|
4125
|
+
|
|
4126
|
+
/** External score source */
|
|
4127
|
+
interface ExternalScore {
|
|
4128
|
+
/** Platform name (e.g., 'gitcoin', 'lens', 'olas') */
|
|
4129
|
+
platform: string;
|
|
4130
|
+
/** Score value (0-100 normalized) */
|
|
4131
|
+
score: number;
|
|
4132
|
+
/** Source URL or proof */
|
|
4133
|
+
proofUrl?: string;
|
|
4134
|
+
/** When the score was fetched */
|
|
4135
|
+
fetchedAt: number;
|
|
4136
|
+
/** Raw score data from the platform */
|
|
4137
|
+
rawData?: Record<string, unknown>;
|
|
4138
|
+
}
|
|
4139
|
+
/** Aggregation weights configuration */
|
|
4140
|
+
interface AggregationWeights {
|
|
4141
|
+
/** Weight for Invariance on-chain score (default: 0.7) */
|
|
4142
|
+
invariance: number;
|
|
4143
|
+
/** Weight for external scores (default: 0.3) */
|
|
4144
|
+
external: number;
|
|
4145
|
+
}
|
|
4146
|
+
/** Aggregated reputation result */
|
|
4147
|
+
interface AggregatedReputation {
|
|
4148
|
+
/** Final weighted score (0-100) */
|
|
4149
|
+
score: number;
|
|
4150
|
+
/** Invariance on-chain score component */
|
|
4151
|
+
invarianceScore: number;
|
|
4152
|
+
/** Average external score component */
|
|
4153
|
+
externalAverage: number;
|
|
4154
|
+
/** Individual external scores */
|
|
4155
|
+
externalScores: ExternalScore[];
|
|
4156
|
+
/** Weights used */
|
|
4157
|
+
weights: AggregationWeights;
|
|
4158
|
+
/** Number of sources */
|
|
4159
|
+
sourceCount: number;
|
|
4160
|
+
}
|
|
4161
|
+
/**
|
|
4162
|
+
* ReputationBridge — import and aggregate reputation from external platforms.
|
|
4163
|
+
*/
|
|
4164
|
+
declare class ReputationBridge {
|
|
4165
|
+
private readonly client;
|
|
4166
|
+
private readonly externalScores;
|
|
4167
|
+
private weights;
|
|
4168
|
+
constructor(client: Invariance, weights?: Partial<AggregationWeights>);
|
|
4169
|
+
/**
|
|
4170
|
+
* Import an external reputation score for an identity.
|
|
4171
|
+
*/
|
|
4172
|
+
importExternalScore(identityId: string, score: ExternalScore): void;
|
|
4173
|
+
/**
|
|
4174
|
+
* Get external scores for an identity.
|
|
4175
|
+
*/
|
|
4176
|
+
getExternalScores(identityId: string): ExternalScore[];
|
|
4177
|
+
/**
|
|
4178
|
+
* Get aggregated reputation score combining Invariance + external sources.
|
|
4179
|
+
*/
|
|
4180
|
+
getAggregatedScore(identityId: string): Promise<AggregatedReputation>;
|
|
4181
|
+
/**
|
|
4182
|
+
* Update aggregation weights.
|
|
4183
|
+
*/
|
|
4184
|
+
setWeights(weights: Partial<AggregationWeights>): void;
|
|
4185
|
+
/**
|
|
4186
|
+
* Record external score as on-chain attestation.
|
|
4187
|
+
*/
|
|
4188
|
+
attestExternalScore(identityId: string, score: ExternalScore): Promise<string>;
|
|
4189
|
+
}
|
|
4190
|
+
|
|
4191
|
+
/**
|
|
4192
|
+
* Escrow with cross-chain policy enforcement.
|
|
4193
|
+
*
|
|
4194
|
+
* @example
|
|
4195
|
+
* ```typescript
|
|
4196
|
+
* const xEscrow = new CrossChainEscrow(inv);
|
|
4197
|
+
* const result = await xEscrow.create({
|
|
4198
|
+
* sourceChain: 'base',
|
|
4199
|
+
* destinationChain: 'optimism',
|
|
4200
|
+
* amount: '5000',
|
|
4201
|
+
* recipient: { type: 'agent', address: '0xAgent' },
|
|
4202
|
+
* perChainCap: '2500',
|
|
4203
|
+
* });
|
|
4204
|
+
* ```
|
|
4205
|
+
*/
|
|
4206
|
+
|
|
4207
|
+
/** Supported chain identifiers */
|
|
4208
|
+
type ChainId = 'base' | 'base-sepolia' | 'ethereum' | 'optimism' | 'arbitrum';
|
|
4209
|
+
/** Cross-chain escrow configuration */
|
|
4210
|
+
interface CrossChainEscrowOptions {
|
|
4211
|
+
/** Source chain where escrow is created */
|
|
4212
|
+
sourceChain: ChainId;
|
|
4213
|
+
/** Destination chain for the bridged action */
|
|
4214
|
+
destinationChain: ChainId;
|
|
4215
|
+
/** Escrow amount in USDC */
|
|
4216
|
+
amount: string;
|
|
4217
|
+
/** Recipient actor reference */
|
|
4218
|
+
recipient: {
|
|
4219
|
+
type: string;
|
|
4220
|
+
address: string;
|
|
4221
|
+
};
|
|
4222
|
+
/** Per-chain spending cap */
|
|
4223
|
+
perChainCap?: string;
|
|
4224
|
+
/** Allowed bridge actions */
|
|
4225
|
+
allowedActions?: string[];
|
|
4226
|
+
/** Additional policy rules */
|
|
4227
|
+
additionalRules?: PolicyRule[];
|
|
4228
|
+
/** Escrow timeout (ISO 8601 duration) */
|
|
4229
|
+
timeout?: string;
|
|
4230
|
+
}
|
|
4231
|
+
/** Result of cross-chain escrow creation */
|
|
4232
|
+
interface CrossChainEscrowResult {
|
|
4233
|
+
/** Created escrow on source chain */
|
|
4234
|
+
escrow: EscrowContract;
|
|
4235
|
+
/** Attached bridge policy */
|
|
4236
|
+
policy: SpecPolicy;
|
|
4237
|
+
/** Source chain */
|
|
4238
|
+
sourceChain: ChainId;
|
|
4239
|
+
/** Destination chain */
|
|
4240
|
+
destinationChain: ChainId;
|
|
4241
|
+
}
|
|
4242
|
+
/**
|
|
4243
|
+
* CrossChainEscrow — escrow with cross-chain policy enforcement.
|
|
4244
|
+
*/
|
|
4245
|
+
declare class CrossChainEscrow {
|
|
4246
|
+
private readonly client;
|
|
4247
|
+
constructor(client: Invariance);
|
|
4248
|
+
/**
|
|
4249
|
+
* Create an escrow on the source chain with bridge-specific policy enforcement.
|
|
4250
|
+
*/
|
|
4251
|
+
create(opts: CrossChainEscrowOptions): Promise<CrossChainEscrowResult>;
|
|
4252
|
+
/**
|
|
4253
|
+
* Verify that a cross-chain action complies with the attached policy.
|
|
4254
|
+
*/
|
|
4255
|
+
verifyAction(policyId: string, action: string, actor: {
|
|
4256
|
+
type: string;
|
|
4257
|
+
address: string;
|
|
4258
|
+
}, params?: Record<string, unknown>): Promise<{
|
|
4259
|
+
allowed: boolean;
|
|
4260
|
+
reason?: string;
|
|
4261
|
+
}>;
|
|
4262
|
+
}
|
|
4263
|
+
|
|
4264
|
+
/**
|
|
4265
|
+
* Time-expiring verification with sybil resistance.
|
|
4266
|
+
* Serves: Tinder+World ID, Hicky, Luna, Gitcoin Passport, Polygon ID, government ID programs.
|
|
4267
|
+
*
|
|
4268
|
+
* @example
|
|
4269
|
+
* ```typescript
|
|
4270
|
+
* const gatekeeper = new IdentityGatekeeper(inv);
|
|
4271
|
+
* const credential = await gatekeeper.verifyAndGate({
|
|
4272
|
+
* identityId: 'identity-123',
|
|
4273
|
+
* platform: 'world-id',
|
|
4274
|
+
* validityMs: 365 * 24 * 60 * 60 * 1000,
|
|
4275
|
+
* sybilResistant: true,
|
|
4276
|
+
* });
|
|
4277
|
+
* ```
|
|
4278
|
+
*/
|
|
4279
|
+
|
|
4280
|
+
/** Verification credential */
|
|
4281
|
+
interface VerificationCredential {
|
|
4282
|
+
/** Identity ID of the verified entity */
|
|
4283
|
+
identityId: string;
|
|
4284
|
+
/** Platform that issued the verification */
|
|
4285
|
+
platform: string;
|
|
4286
|
+
/** When the verification was issued (ms since epoch) */
|
|
4287
|
+
issuedAt: number;
|
|
4288
|
+
/** When the verification expires (ms since epoch) */
|
|
4289
|
+
expiresAt: number;
|
|
4290
|
+
/** Transaction hash of the attestation */
|
|
4291
|
+
txHash: string;
|
|
4292
|
+
/** Whether still valid */
|
|
4293
|
+
active: boolean;
|
|
4294
|
+
}
|
|
4295
|
+
/** Options for verifying and gating */
|
|
4296
|
+
interface VerifyAndGateOptions {
|
|
4297
|
+
/** Identity to verify */
|
|
4298
|
+
identityId: string;
|
|
4299
|
+
/** Platform name (e.g., 'world-id', 'polygon-id', 'civic') */
|
|
4300
|
+
platform: string;
|
|
4301
|
+
/** Verification validity duration in milliseconds (default: 365 days) */
|
|
4302
|
+
validityMs?: number;
|
|
4303
|
+
/** External proof (e.g., World ID proof, Polygon ID credential) */
|
|
4304
|
+
proof?: string;
|
|
4305
|
+
/** Enforce 1-identity-per-platform (default: true) */
|
|
4306
|
+
sybilResistant?: boolean;
|
|
4307
|
+
}
|
|
4308
|
+
/** Access log entry */
|
|
4309
|
+
interface AccessLogEntry {
|
|
4310
|
+
/** Who queried the identity data */
|
|
4311
|
+
queriedBy: string;
|
|
4312
|
+
/** Identity that was queried */
|
|
4313
|
+
identityId: string;
|
|
4314
|
+
/** What data was accessed */
|
|
4315
|
+
dataAccessed: string;
|
|
4316
|
+
/** Timestamp */
|
|
4317
|
+
timestamp: number;
|
|
4318
|
+
/** Ledger entry ID */
|
|
4319
|
+
entryId: string;
|
|
4320
|
+
}
|
|
4321
|
+
/**
|
|
4322
|
+
* IdentityGatekeeper — time-expiring verification with sybil resistance.
|
|
4323
|
+
*/
|
|
4324
|
+
declare class IdentityGatekeeper {
|
|
4325
|
+
private readonly client;
|
|
4326
|
+
private readonly platformRegistry;
|
|
4327
|
+
private readonly credentials;
|
|
4328
|
+
constructor(client: Invariance);
|
|
4329
|
+
/**
|
|
4330
|
+
* Verify an identity and issue a time-bounded credential.
|
|
4331
|
+
* Enforces 1-identity-per-platform when sybilResistant is true.
|
|
4332
|
+
*/
|
|
4333
|
+
verifyAndGate(opts: VerifyAndGateOptions): Promise<VerificationCredential>;
|
|
4334
|
+
/**
|
|
4335
|
+
* Check if an identity has valid (non-expired) verification.
|
|
4336
|
+
*/
|
|
4337
|
+
isVerified(identityId: string, platform: string): boolean;
|
|
4338
|
+
/**
|
|
4339
|
+
* Revoke expired verifications. Returns count of revoked credentials.
|
|
4340
|
+
*/
|
|
4341
|
+
revokeExpired(platform?: string): number;
|
|
4342
|
+
/**
|
|
4343
|
+
* Log an access event for GDPR compliance.
|
|
4344
|
+
*/
|
|
4345
|
+
accessLog(queriedBy: string, identityId: string, dataAccessed: string): Promise<AccessLogEntry>;
|
|
4346
|
+
/**
|
|
4347
|
+
* Get all active credentials for an identity.
|
|
4348
|
+
*/
|
|
4349
|
+
getCredentials(identityId: string): VerificationCredential[];
|
|
4350
|
+
}
|
|
4351
|
+
|
|
4352
|
+
/**
|
|
4353
|
+
* Dual-identity verification (device + human) with confidence thresholds.
|
|
4354
|
+
* Serves: Neuralink, Merge Labs, and future BCI platforms.
|
|
4355
|
+
*
|
|
4356
|
+
* @example
|
|
4357
|
+
* ```typescript
|
|
4358
|
+
* const bci = new BCIIntentVerifier(inv, { autoApprove: 0.95, humanReview: 0.7, deny: 0.3 });
|
|
4359
|
+
* const result = await bci.verifyIntent({
|
|
4360
|
+
* deviceId: 'device-neuralink-001',
|
|
4361
|
+
* humanId: 'identity-user-123',
|
|
4362
|
+
* confidence: 0.92,
|
|
4363
|
+
* action: 'transfer',
|
|
4364
|
+
* params: { to: '0xRecipient', amount: '100' },
|
|
4365
|
+
* });
|
|
4366
|
+
* ```
|
|
4367
|
+
*/
|
|
4368
|
+
|
|
4369
|
+
/** BCI signal with confidence score */
|
|
4370
|
+
interface BCISignal {
|
|
4371
|
+
/** Device identity ID */
|
|
4372
|
+
deviceId: string;
|
|
4373
|
+
/** Human identity ID */
|
|
4374
|
+
humanId: string;
|
|
4375
|
+
/** Neural confidence score (0.0 - 1.0) */
|
|
4376
|
+
confidence: number;
|
|
4377
|
+
/** Intended action */
|
|
4378
|
+
action: string;
|
|
4379
|
+
/** Action parameters */
|
|
4380
|
+
params: Record<string, unknown>;
|
|
4381
|
+
/** Raw signal metadata */
|
|
4382
|
+
signalMetadata?: Record<string, unknown>;
|
|
4383
|
+
}
|
|
4384
|
+
/** Confidence threshold configuration */
|
|
4385
|
+
interface ConfidenceThresholds {
|
|
4386
|
+
/** Minimum confidence for auto-approval (default: 0.95) */
|
|
4387
|
+
autoApprove: number;
|
|
4388
|
+
/** Minimum confidence for human-in-the-loop approval (default: 0.7) */
|
|
4389
|
+
humanReview: number;
|
|
4390
|
+
/** Below this, action is denied (default: 0.3) */
|
|
4391
|
+
deny: number;
|
|
4392
|
+
}
|
|
4393
|
+
/** BCI verification result */
|
|
4394
|
+
interface BCIVerificationResult {
|
|
4395
|
+
/** Whether the action is approved */
|
|
4396
|
+
approved: boolean;
|
|
4397
|
+
/** Approval method used */
|
|
4398
|
+
method: 'auto' | 'human-review' | 'denied';
|
|
4399
|
+
/** Confidence score */
|
|
4400
|
+
confidence: number;
|
|
4401
|
+
/** Reason for decision */
|
|
4402
|
+
reason: string;
|
|
4403
|
+
/** Ledger entry for audit trail */
|
|
4404
|
+
auditEntryId?: string;
|
|
4405
|
+
/** Transaction hash */
|
|
4406
|
+
txHash?: string;
|
|
4407
|
+
}
|
|
4408
|
+
/**
|
|
4409
|
+
* BCIIntentVerifier — dual-identity verification for brain-computer interfaces.
|
|
4410
|
+
*/
|
|
4411
|
+
declare class BCIIntentVerifier {
|
|
4412
|
+
private readonly client;
|
|
4413
|
+
private readonly thresholds;
|
|
4414
|
+
private readonly highStakesActions;
|
|
4415
|
+
constructor(client: Invariance, thresholds?: Partial<ConfidenceThresholds>, highStakesActions?: string[]);
|
|
4416
|
+
/**
|
|
4417
|
+
* Verify a BCI intent signal with dual-identity check and confidence gating.
|
|
4418
|
+
*/
|
|
4419
|
+
verifyIntent(signal: BCISignal): Promise<BCIVerificationResult>;
|
|
4420
|
+
/**
|
|
4421
|
+
* Update confidence thresholds.
|
|
4422
|
+
*/
|
|
4423
|
+
setThresholds(thresholds: Partial<ConfidenceThresholds>): void;
|
|
4424
|
+
/**
|
|
4425
|
+
* Add actions to the high-stakes list.
|
|
4426
|
+
*/
|
|
4427
|
+
addHighStakesActions(actions: string[]): void;
|
|
4428
|
+
/**
|
|
4429
|
+
* Get current threshold configuration.
|
|
4430
|
+
*/
|
|
4431
|
+
getThresholds(): ConfidenceThresholds;
|
|
4432
|
+
}
|
|
4433
|
+
|
|
4434
|
+
/**
|
|
4435
|
+
* Beneficiary-gated bot registration + extraction logging.
|
|
4436
|
+
* Serves: MEV bots, DeFi arbitrage, liquidation systems.
|
|
4437
|
+
*
|
|
4438
|
+
* @example
|
|
4439
|
+
* ```typescript
|
|
4440
|
+
* const mev = new MEVComplianceKit(inv);
|
|
4441
|
+
* const bot = await mev.registerBot({
|
|
4442
|
+
* identity: { type: 'agent', owner: '0xDev', label: 'ArbBot-1' },
|
|
4443
|
+
* beneficiaries: ['0xTreasury', '0xDAO'],
|
|
4444
|
+
* maxExtractionPerTx: '1000',
|
|
4445
|
+
* maxDailyExtraction: '50000',
|
|
4446
|
+
* allowedStrategies: ['arbitrage', 'liquidation'],
|
|
4447
|
+
* });
|
|
4448
|
+
* ```
|
|
4449
|
+
*/
|
|
4450
|
+
|
|
4451
|
+
/** MEV bot registration options */
|
|
4452
|
+
interface RegisterBotOptions {
|
|
4453
|
+
/** Bot identity details */
|
|
4454
|
+
identity: {
|
|
4455
|
+
type: 'agent';
|
|
4456
|
+
owner: string;
|
|
4457
|
+
label: string;
|
|
4458
|
+
metadata?: Record<string, unknown>;
|
|
4459
|
+
};
|
|
4460
|
+
/** Allowed beneficiary addresses */
|
|
4461
|
+
beneficiaries: string[];
|
|
4462
|
+
/** Maximum extraction per transaction */
|
|
4463
|
+
maxExtractionPerTx?: string;
|
|
4464
|
+
/** Maximum daily extraction */
|
|
4465
|
+
maxDailyExtraction?: string;
|
|
4466
|
+
/** Allowed MEV strategies */
|
|
4467
|
+
allowedStrategies?: string[];
|
|
4468
|
+
}
|
|
4469
|
+
/** Registered bot result */
|
|
4470
|
+
interface RegisteredBot {
|
|
4471
|
+
/** Bot identity */
|
|
4472
|
+
identity: Identity;
|
|
4473
|
+
/** Attached compliance policy */
|
|
4474
|
+
policy: SpecPolicy;
|
|
4475
|
+
/** Registered beneficiaries */
|
|
4476
|
+
beneficiaries: string[];
|
|
4477
|
+
}
|
|
4478
|
+
/** MEV extraction log entry */
|
|
4479
|
+
interface ExtractionLog {
|
|
4480
|
+
/** Ledger entry ID */
|
|
4481
|
+
entryId: string;
|
|
4482
|
+
/** Transaction hash */
|
|
4483
|
+
txHash: string;
|
|
4484
|
+
/** Strategy used */
|
|
4485
|
+
strategy: string;
|
|
4486
|
+
/** Amount extracted (USDC) */
|
|
4487
|
+
amount: string;
|
|
4488
|
+
/** Beneficiary address */
|
|
4489
|
+
beneficiary: string;
|
|
4490
|
+
/** Timestamp */
|
|
4491
|
+
timestamp: number;
|
|
4492
|
+
}
|
|
4493
|
+
/**
|
|
4494
|
+
* MEVComplianceKit — beneficiary-gated bot registration + extraction logging.
|
|
4495
|
+
*/
|
|
4496
|
+
declare class MEVComplianceKit {
|
|
4497
|
+
private readonly client;
|
|
4498
|
+
private readonly beneficiaryRegistry;
|
|
4499
|
+
constructor(client: Invariance);
|
|
4500
|
+
/**
|
|
4501
|
+
* Register a MEV bot with beneficiary gates and extraction limits.
|
|
4502
|
+
*/
|
|
4503
|
+
registerBot(opts: RegisterBotOptions): Promise<RegisteredBot>;
|
|
4504
|
+
/**
|
|
4505
|
+
* Verify that an extraction targets an approved beneficiary.
|
|
4506
|
+
*/
|
|
4507
|
+
isBeneficiaryApproved(botIdentityId: string, beneficiary: string): boolean;
|
|
4508
|
+
/**
|
|
4509
|
+
* Log an MEV extraction event to the immutable ledger.
|
|
4510
|
+
*/
|
|
4511
|
+
logExtraction(botIdentityId: string, extraction: {
|
|
4512
|
+
strategy: string;
|
|
4513
|
+
amount: string;
|
|
4514
|
+
beneficiary: string;
|
|
4515
|
+
metadata?: Record<string, unknown>;
|
|
4516
|
+
}): Promise<ExtractionLog>;
|
|
4517
|
+
/**
|
|
4518
|
+
* Add a beneficiary to an existing bot.
|
|
4519
|
+
*/
|
|
4520
|
+
addBeneficiary(botIdentityId: string, beneficiary: string): void;
|
|
4521
|
+
/**
|
|
4522
|
+
* Remove a beneficiary from an existing bot.
|
|
4523
|
+
*/
|
|
4524
|
+
removeBeneficiary(botIdentityId: string, beneficiary: string): boolean;
|
|
4525
|
+
/**
|
|
4526
|
+
* Get all approved beneficiaries for a bot.
|
|
4527
|
+
*/
|
|
4528
|
+
getBeneficiaries(botIdentityId: string): string[];
|
|
4529
|
+
}
|
|
4530
|
+
|
|
4531
|
+
/**
|
|
4532
|
+
* Role-based procurement + benefits distribution.
|
|
4533
|
+
* Serves: DOGE, government procurement, benefits distribution programs.
|
|
4534
|
+
*
|
|
4535
|
+
* @example
|
|
4536
|
+
* ```typescript
|
|
4537
|
+
* const gov = new GovernmentComplianceKit(inv);
|
|
4538
|
+
* const agency = await gov.setupAgency({
|
|
4539
|
+
* name: 'DOT',
|
|
4540
|
+
* identity: { type: 'service', owner: '0xGov', label: 'Dept-of-Transportation' },
|
|
4541
|
+
* roles: [
|
|
4542
|
+
* { name: 'officer', maxSpend: '100000', allowedActions: ['approve', 'procure', 'audit'] },
|
|
4543
|
+
* { name: 'vendor', maxSpend: '0', allowedActions: ['bid', 'deliver', 'invoice'] },
|
|
4544
|
+
* ],
|
|
4545
|
+
* agencyCap: '10000000',
|
|
4546
|
+
* });
|
|
4547
|
+
* ```
|
|
4548
|
+
*/
|
|
4549
|
+
|
|
4550
|
+
/** Agency role with permission matrix */
|
|
4551
|
+
interface AgencyRole {
|
|
4552
|
+
/** Role name (e.g., 'procurement-officer', 'auditor', 'vendor') */
|
|
4553
|
+
name: string;
|
|
4554
|
+
/** Maximum spending authority */
|
|
4555
|
+
maxSpend: string;
|
|
4556
|
+
/** Allowed actions */
|
|
4557
|
+
allowedActions: string[];
|
|
4558
|
+
/** Approval required above this amount */
|
|
4559
|
+
approvalThreshold?: string;
|
|
4560
|
+
}
|
|
4561
|
+
/** Options for setting up an agency */
|
|
4562
|
+
interface SetupAgencyOptions {
|
|
4563
|
+
/** Agency name */
|
|
4564
|
+
name: string;
|
|
4565
|
+
/** Agency identity details */
|
|
4566
|
+
identity: {
|
|
4567
|
+
type: 'service';
|
|
4568
|
+
owner: string;
|
|
4569
|
+
label: string;
|
|
4570
|
+
metadata?: Record<string, unknown>;
|
|
4571
|
+
};
|
|
4572
|
+
/** Role definitions */
|
|
4573
|
+
roles: AgencyRole[];
|
|
4574
|
+
/** Agency-wide spending cap */
|
|
4575
|
+
agencyCap: string;
|
|
4576
|
+
}
|
|
4577
|
+
/** Agency setup result */
|
|
4578
|
+
interface AgencySetupResult {
|
|
4579
|
+
/** Agency identity */
|
|
4580
|
+
identity: Identity;
|
|
4581
|
+
/** Agency-wide policy */
|
|
4582
|
+
policy: SpecPolicy;
|
|
4583
|
+
/** Role policies */
|
|
4584
|
+
rolePolicies: Map<string, SpecPolicy>;
|
|
4585
|
+
}
|
|
4586
|
+
/** Milestone for escrow release */
|
|
4587
|
+
interface Milestone {
|
|
4588
|
+
/** Milestone description */
|
|
4589
|
+
description: string;
|
|
4590
|
+
/** Amount to release on completion */
|
|
4591
|
+
amount: string;
|
|
4592
|
+
/** Verifier identity ID */
|
|
4593
|
+
verifier: string;
|
|
4594
|
+
}
|
|
4595
|
+
/** Milestone escrow result */
|
|
4596
|
+
interface MilestoneEscrowResult {
|
|
4597
|
+
/** Created escrow */
|
|
4598
|
+
escrow: EscrowContract;
|
|
4599
|
+
/** Policy for milestone verification */
|
|
4600
|
+
policy: SpecPolicy;
|
|
4601
|
+
/** Milestones registered */
|
|
4602
|
+
milestones: Milestone[];
|
|
4603
|
+
}
|
|
4604
|
+
/** Benefits distribution options */
|
|
4605
|
+
interface DistributeBenefitsOptions {
|
|
4606
|
+
/** Program name */
|
|
4607
|
+
program: string;
|
|
4608
|
+
/** Recipient identity IDs */
|
|
4609
|
+
recipients: string[];
|
|
4610
|
+
/** Amount per recipient */
|
|
4611
|
+
amountPerRecipient: string;
|
|
4612
|
+
/** Maximum total distribution */
|
|
4613
|
+
maxTotal: string;
|
|
4614
|
+
/** Require eligibility verification */
|
|
4615
|
+
requireEligibility?: boolean;
|
|
4616
|
+
}
|
|
4617
|
+
/** Distribution result */
|
|
4618
|
+
interface DistributionResult {
|
|
4619
|
+
/** Number of successful distributions */
|
|
4620
|
+
successCount: number;
|
|
4621
|
+
/** Total amount distributed */
|
|
4622
|
+
totalDistributed: string;
|
|
4623
|
+
/** Ledger entries for audit trail */
|
|
4624
|
+
auditEntries: string[];
|
|
4625
|
+
/** Failed distributions */
|
|
4626
|
+
failures: Array<{
|
|
4627
|
+
recipientId: string;
|
|
4628
|
+
reason: string;
|
|
4629
|
+
}>;
|
|
4630
|
+
}
|
|
4631
|
+
/**
|
|
4632
|
+
* GovernmentComplianceKit — role-based procurement + benefits distribution.
|
|
4633
|
+
*/
|
|
4634
|
+
declare class GovernmentComplianceKit {
|
|
4635
|
+
private readonly client;
|
|
4636
|
+
constructor(client: Invariance);
|
|
4637
|
+
/**
|
|
4638
|
+
* Register an agency identity with role-based permission matrix.
|
|
4639
|
+
*/
|
|
4640
|
+
setupAgency(opts: SetupAgencyOptions): Promise<AgencySetupResult>;
|
|
4641
|
+
/**
|
|
4642
|
+
* Create milestone-based escrow for procurement contracts.
|
|
4643
|
+
*/
|
|
4644
|
+
milestoneEscrow(contractName: string, totalAmount: string, milestones: Milestone[], signers: string[], threshold: number): Promise<MilestoneEscrowResult>;
|
|
4645
|
+
/**
|
|
4646
|
+
* Distribute benefits with eligibility gates and per-citizen caps.
|
|
4647
|
+
*/
|
|
4648
|
+
distributeBenefits(opts: DistributeBenefitsOptions): Promise<DistributionResult>;
|
|
4649
|
+
/**
|
|
4650
|
+
* Create immutable compliance attestation.
|
|
4651
|
+
*/
|
|
4652
|
+
complianceAttestation(agencyIdentityId: string, regulation: string, details: Record<string, unknown>): Promise<{
|
|
4653
|
+
txHash: string;
|
|
4654
|
+
}>;
|
|
4655
|
+
}
|
|
4656
|
+
|
|
4657
|
+
/**
|
|
4658
|
+
* Agent/user relationship tracking via attestations.
|
|
4659
|
+
* BFS traversal of social connections for trust graphs.
|
|
4660
|
+
*
|
|
4661
|
+
* @example
|
|
4662
|
+
* ```typescript
|
|
4663
|
+
* const graph = new SocialGraphAdapter(inv);
|
|
4664
|
+
* await graph.linkAgents('identity-a', 'identity-b', 'trusts', 0.9);
|
|
4665
|
+
* const trust = graph.getTrustGraph('identity-a', 3);
|
|
4666
|
+
* ```
|
|
4667
|
+
*/
|
|
4668
|
+
|
|
4669
|
+
/** A link between two identities */
|
|
4670
|
+
interface SocialLink {
|
|
4671
|
+
/** Source identity ID */
|
|
4672
|
+
from: string;
|
|
4673
|
+
/** Target identity ID */
|
|
4674
|
+
to: string;
|
|
4675
|
+
/** Relationship type (e.g., 'trusts', 'delegates-to', 'collaborates-with') */
|
|
4676
|
+
relationship: string;
|
|
4677
|
+
/** Link strength (0.0 - 1.0) */
|
|
4678
|
+
strength: number;
|
|
4679
|
+
/** When the link was created */
|
|
4680
|
+
createdAt: number;
|
|
4681
|
+
/** Transaction hash of the attestation */
|
|
4682
|
+
txHash: string;
|
|
4683
|
+
}
|
|
4684
|
+
/** Trust graph node */
|
|
4685
|
+
interface TrustNode {
|
|
4686
|
+
/** Identity ID */
|
|
4687
|
+
identityId: string;
|
|
4688
|
+
/** Distance from the origin (in hops) */
|
|
4689
|
+
depth: number;
|
|
4690
|
+
/** Aggregated trust score at this depth */
|
|
4691
|
+
trustScore: number;
|
|
4692
|
+
/** Incoming links */
|
|
4693
|
+
incomingLinks: SocialLink[];
|
|
4694
|
+
}
|
|
4695
|
+
/** Trust graph result */
|
|
4696
|
+
interface TrustGraph {
|
|
4697
|
+
/** Origin identity */
|
|
4698
|
+
origin: string;
|
|
4699
|
+
/** All reachable nodes */
|
|
4700
|
+
nodes: TrustNode[];
|
|
4701
|
+
/** Total edges traversed */
|
|
4702
|
+
edgeCount: number;
|
|
4703
|
+
/** Maximum depth reached */
|
|
4704
|
+
maxDepth: number;
|
|
4705
|
+
}
|
|
4706
|
+
/**
|
|
4707
|
+
* SocialGraphAdapter — agent/user relationship tracking and trust graph traversal.
|
|
4708
|
+
*/
|
|
4709
|
+
declare class SocialGraphAdapter {
|
|
4710
|
+
private readonly client;
|
|
4711
|
+
private readonly adjacency;
|
|
4712
|
+
constructor(client: Invariance);
|
|
4713
|
+
/**
|
|
4714
|
+
* Create a link between two identities with on-chain attestation.
|
|
4715
|
+
*/
|
|
4716
|
+
linkAgents(fromId: string, toId: string, relationship: string, strength: number): Promise<SocialLink>;
|
|
4717
|
+
/**
|
|
4718
|
+
* Remove a link between two identities.
|
|
4719
|
+
*/
|
|
4720
|
+
unlinkAgents(fromId: string, toId: string, relationship: string): boolean;
|
|
4721
|
+
/**
|
|
4722
|
+
* Get direct links from an identity.
|
|
4723
|
+
*/
|
|
4724
|
+
getLinks(identityId: string): SocialLink[];
|
|
4725
|
+
/**
|
|
4726
|
+
* BFS traversal to build a trust graph from an origin identity.
|
|
4727
|
+
*/
|
|
4728
|
+
getTrustGraph(origin: string, maxDepth?: number, minStrength?: number): TrustGraph;
|
|
4729
|
+
/**
|
|
4730
|
+
* Get mutual connections between two identities.
|
|
4731
|
+
*/
|
|
4732
|
+
getMutualConnections(idA: string, idB: string): string[];
|
|
4733
|
+
}
|
|
4734
|
+
|
|
4735
|
+
export { type AccessLogEntry, type ActionContext, type ActionCountResult, type AfterActionResult, type AgencyRole, type AgencySetupResult, type AggregatedReputation, type AggregationWeights, type AnalyticsTimeframe, AtomicVerifier, type AttestationInput, type AuditOptions, type AuditReport, AuditTrail, type AutoBatchConfig, AutoBatchedEventLedgerCompact, BCIIntentVerifier, type BCISignal, type BCIVerificationResult, type BalanceInfo, type BatchAgentOptions, BatchExecutor, type BatchOptions, type BatchRegisterEntry, type BatchRegisterOptions, type BatchResult, type BeforeActionResult, type BuiltInTemplate, type ChainId, type CompleteHireOptions, type ConfidenceThresholds, type ConnectOptions, ContractFactory, type CostSummaryResult, type CreateMultiSigOptions, type CreateWalletOptions, type CrewMember, type CrewRole, type CrewSetupResult, CrossChainEscrow, type CrossChainEscrowOptions, type CrossChainEscrowResult, type DeferredOperation, type DelegateOptions, type DelegateResult, type DistributeBenefitsOptions, type DistributionResult, type ERC8004AgentIdentity, InvarianceBridge as ERC8004Bridge, type ERC8004Config, ERC8004Error, type ERC8004Feedback, ERC8004Manager, type ERC8004Metadata, type ERC8004RegistryAddresses, type ERC8004ReputationSummary, type ERC8004ValidationStatus, type ERC8004ValidationSummary, type EscrowListFilters, EscrowManager, type EscrowStateChangeCallback, type EstimateGasOptions, type EvaluateOptions, EventLedger, EventLedgerCompact, type ExecuteAndLogOptions, type ExecuteAndLogResult, type ExternalReputationSignal, type ExternalScore, type ExtractionLog, type FeaturedOptions, type FundOptions, GasManager, type GateActionOptions, type GateActionResult, type GiveFeedbackOptions, GovernmentComplianceKit, type HireAndFundOptions, type HireAndReviewOptions, type HireAndReviewResult, type HireWithEscrowOptions, IdentityGatekeeper, type IdentityListFilters, IdentityManager, type IntentHistoryFilters, IntentProtocol, Invariance, InvarianceError, InvarianceEventEmitter, type InvarianceEvents, LedgerAnalytics, type LedgerStreamCallback, type LinkedIdentity, MEVComplianceKit, MarketplaceKit, MarketplacePlugin, type Milestone, type MilestoneEscrowResult, MultiAgentComposer, type PayForActionOptions, type PaymentEstimate, type PaymentHistoryFilters, type PaymentReceipt, type PaymentVerification, PipelineBuilder, type PipelineResult, type PipelineStep, PolicyEngine, type PolicyListFilters, type PolicyTemplate, type PolicyViolationCallback, type ProofData, type PublishAgentOptions, type PublishResult, type PushFeedbackOptions, type QuickSetupOptions, type QuickSetupResult, type RecurringPaymentOptions, type RegisterBotOptions, type RegisteredBot, type ReleaseOptions, ReputationBridge, ReputationEngine, type ReputationSummaryFilterOptions, type RetryConfig, type RetryResult, type ReviewList, type ReviewQueryOptions, RuntimeHookAdapter, type RuntimeHooks, SDK_VERSION, type ScoreHistoryOptions, SessionContext, type SessionOptions, type SetupAgencyOptions, type SetupCrewOptions, type SetupRateLimitedAgentOptions, SocialGraphAdapter, type SocialLink, type SuccessRateResult, Telemetry, type TrustGraph, type TrustNode, type UpdateIdentityOptions, type UpdateListingOptions, type ValidationRequestOptions, type ValidationResponseOptions, type ValidationSummaryFilterOptions, type VerificationCredential, Verifier, type VerifyActionOptions, type VerifyAndGateOptions, type VerifyProxy, type ViolationResult, type WalletInfo, WalletManager, type WalletProvider, X402Manager, type X402Settings, getERC8004Addresses, isERC8004Supported, verifyWebhookSignature };
|