@brainai/satp-client 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,508 @@
1
+ import { Connection, PublicKey, Transaction } from '@solana/web3.js';
2
+
3
+ export type Network = 'mainnet' | 'devnet';
4
+ export type AgentIdOrHash = string | Buffer;
5
+
6
+ export interface SATPV3SDKOptions {
7
+ network?: Network;
8
+ rpcUrl?: string;
9
+ url?: string;
10
+ endpoint?: string;
11
+ commitment?: 'processed' | 'confirmed' | 'finalized';
12
+ }
13
+
14
+ export type SATPV3SDKConstructorOptions = SATPV3SDKOptions | Network | string;
15
+
16
+ export interface V3ProgramIds {
17
+ IDENTITY: PublicKey;
18
+ REVIEWS: PublicKey;
19
+ REPUTATION: PublicKey;
20
+ ATTESTATIONS: PublicKey;
21
+ VALIDATION: PublicKey;
22
+ ESCROW: PublicKey;
23
+ }
24
+
25
+ export interface CreateIdentityMeta {
26
+ name?: string;
27
+ description?: string;
28
+ category?: string;
29
+ capabilities?: string[];
30
+ metadataUri?: string;
31
+ }
32
+
33
+ export interface UpdateIdentityFields {
34
+ name?: string | null;
35
+ description?: string | null;
36
+ category?: string | null;
37
+ capabilities?: string[] | null;
38
+ metadataUri?: string | null;
39
+ }
40
+
41
+ export interface GenesisRecord {
42
+ agentId: string;
43
+ authority: string;
44
+ name: string;
45
+ description: string;
46
+ category: string;
47
+ capabilities: string[];
48
+ metadataUri: string;
49
+ reputationScore: number;
50
+ verificationLevel: number;
51
+ isActive: boolean;
52
+ createdAt: number;
53
+ updatedAt: number;
54
+ pendingAuthority: string | null;
55
+ faceImage: string;
56
+ faceMint: string | null;
57
+ faceBurnTx: string;
58
+ genesisRecord: boolean;
59
+ pda: string;
60
+ }
61
+
62
+ export interface TransactionResult {
63
+ transaction: Transaction;
64
+ }
65
+
66
+ export interface CreateIdentityResult extends TransactionResult {
67
+ genesisPDA: PublicKey;
68
+ }
69
+
70
+ export interface RegisterNameResult extends TransactionResult {
71
+ nameRegistryPDA: PublicKey;
72
+ }
73
+
74
+ export interface LinkWalletResult extends TransactionResult {
75
+ linkedWalletPDA: PublicKey;
76
+ }
77
+
78
+ export interface MintTrackerResult extends TransactionResult {
79
+ mintTrackerPDA: PublicKey;
80
+ }
81
+
82
+ export interface CreateAttestationResult extends TransactionResult {
83
+ attestationPDA: PublicKey;
84
+ }
85
+
86
+ export interface CreateReviewResult extends TransactionResult {
87
+ reviewPDA: PublicKey;
88
+ }
89
+
90
+ export interface InitReviewCounterResult extends TransactionResult {
91
+ counterPDA: PublicKey;
92
+ }
93
+
94
+ export interface CreateReviewOpts {
95
+ identityProgram?: PublicKey | string;
96
+ identityAccount?: PublicKey | string;
97
+ }
98
+
99
+ export interface V3Review {
100
+ pda: string;
101
+ agentId: string;
102
+ agentIdHash: string;
103
+ reviewer: string;
104
+ rating: number;
105
+ reviewText: string;
106
+ metadata: string;
107
+ createdAt: number;
108
+ updatedAt: number;
109
+ isActive: boolean;
110
+ bump: number;
111
+ }
112
+
113
+ export interface V3ReviewCounter {
114
+ pda: string;
115
+ agentId: string;
116
+ count: number;
117
+ bump: number;
118
+ }
119
+
120
+ export interface UpdateReviewFields {
121
+ rating?: number;
122
+ reviewText?: string;
123
+ metadata?: string;
124
+ }
125
+
126
+ export type EscrowStatus = 'Active' | 'WorkSubmitted' | 'Released' | 'Cancelled' | 'Disputed' | 'Resolved';
127
+
128
+ export interface CreateEscrowOpts {
129
+ minVerificationLevel?: number;
130
+ requireBorn?: boolean;
131
+ arbiter?: PublicKey | string;
132
+ }
133
+
134
+ export interface CreateEscrowResult extends TransactionResult {
135
+ escrowPDA: PublicKey;
136
+ descriptionHash: Buffer;
137
+ }
138
+
139
+ export interface SubmitWorkResult extends TransactionResult {
140
+ workHash: Buffer;
141
+ }
142
+
143
+ export interface RaiseDisputeResult extends TransactionResult {
144
+ reasonHash: Buffer;
145
+ }
146
+
147
+ export interface EscrowPDAResult {
148
+ escrowPDA: string;
149
+ bump: number;
150
+ descriptionHash: string;
151
+ }
152
+
153
+ export interface V3Escrow {
154
+ pda: string;
155
+ client: string;
156
+ agent: string;
157
+ agentIdHash: string;
158
+ amount: number;
159
+ releasedAmount: number;
160
+ remaining: number;
161
+ descriptionHash: string;
162
+ deadline: number;
163
+ nonce: number;
164
+ status: EscrowStatus;
165
+ statusCode: number;
166
+ minVerificationLevel: number;
167
+ requireBorn: boolean;
168
+ createdAt: number;
169
+ arbiter: string;
170
+ workHash: string | null;
171
+ workSubmittedAt: number | null;
172
+ disputeReasonHash: string | null;
173
+ disputedAt: number | null;
174
+ disputedBy: string | null;
175
+ bump: number;
176
+ }
177
+
178
+ export interface V3PDAs {
179
+ genesis: string;
180
+ reputationAuthority: string;
181
+ validationAuthority: string;
182
+ mintTracker: string;
183
+ }
184
+
185
+ export class SATPV3SDK {
186
+ network: Network;
187
+ rpcUrl: string;
188
+ commitment: string;
189
+ connection: Connection;
190
+ programIds: V3ProgramIds;
191
+
192
+ constructor(opts?: SATPV3SDKConstructorOptions);
193
+
194
+ // ─── Identity — Genesis Record CRUD ───────────────────
195
+
196
+ /** Build createIdentity transaction. */
197
+ buildCreateIdentity(
198
+ creator: PublicKey | string,
199
+ agentId: string,
200
+ meta: CreateIdentityMeta
201
+ ): Promise<CreateIdentityResult>;
202
+
203
+ /** Build burnToBecome transaction (set immutable face). */
204
+ buildBurnToBecome(
205
+ authority: PublicKey | string,
206
+ agentIdOrHash: AgentIdOrHash,
207
+ faceImage: string,
208
+ faceMint: PublicKey | string,
209
+ faceBurnTx: string
210
+ ): Promise<TransactionResult>;
211
+
212
+ /** Build updateIdentity transaction. */
213
+ buildUpdateIdentity(
214
+ authority: PublicKey | string,
215
+ agentIdOrHash: AgentIdOrHash,
216
+ updates: UpdateIdentityFields
217
+ ): Promise<TransactionResult>;
218
+
219
+ /** Build proposeAuthority transaction (step 1 of 2-step rotation). */
220
+ buildProposeAuthority(
221
+ authority: PublicKey | string,
222
+ agentIdOrHash: AgentIdOrHash,
223
+ newAuthority: PublicKey | string
224
+ ): Promise<TransactionResult>;
225
+
226
+ /** Build acceptAuthority transaction (step 2 of 2-step rotation). */
227
+ buildAcceptAuthority(
228
+ newAuthority: PublicKey | string,
229
+ agentIdOrHash: AgentIdOrHash
230
+ ): Promise<TransactionResult>;
231
+
232
+ /** Build cancelAuthorityTransfer transaction. */
233
+ buildCancelAuthorityTransfer(
234
+ authority: PublicKey | string,
235
+ agentIdOrHash: AgentIdOrHash
236
+ ): Promise<TransactionResult>;
237
+
238
+ /** Build deactivateIdentity transaction. */
239
+ buildDeactivateIdentity(
240
+ authority: PublicKey | string,
241
+ agentIdOrHash: AgentIdOrHash
242
+ ): Promise<TransactionResult>;
243
+
244
+ /** Build reactivateIdentity transaction. */
245
+ buildReactivateIdentity(
246
+ authority: PublicKey | string,
247
+ agentIdOrHash: AgentIdOrHash
248
+ ): Promise<TransactionResult>;
249
+
250
+ /** Build migrateV2ToV3 transaction. */
251
+ buildMigrateV2ToV3(
252
+ v2Authority: PublicKey | string,
253
+ agentId: string,
254
+ meta: CreateIdentityMeta
255
+ ): Promise<CreateIdentityResult>;
256
+
257
+ // ─── Name Registry ────────────────────────────────────
258
+
259
+ /** Build registerName transaction (case-insensitive uniqueness). */
260
+ buildRegisterName(
261
+ authority: PublicKey | string,
262
+ agentIdOrHash: AgentIdOrHash,
263
+ name: string
264
+ ): Promise<RegisterNameResult>;
265
+
266
+ /** Build releaseName transaction. */
267
+ buildReleaseName(
268
+ authority: PublicKey | string,
269
+ agentIdOrHash: AgentIdOrHash,
270
+ name: string
271
+ ): Promise<TransactionResult>;
272
+
273
+ // ─── Linked Wallets ───────────────────────────────────
274
+
275
+ /** Build linkWallet transaction. */
276
+ buildLinkWallet(
277
+ authority: PublicKey | string,
278
+ agentIdOrHash: AgentIdOrHash,
279
+ wallet: PublicKey | string,
280
+ chain: string,
281
+ label: string
282
+ ): Promise<LinkWalletResult>;
283
+
284
+ /** Build unlinkWallet transaction (soft-delete). */
285
+ buildUnlinkWallet(
286
+ authority: PublicKey | string,
287
+ agentIdOrHash: AgentIdOrHash,
288
+ wallet: PublicKey | string
289
+ ): Promise<TransactionResult>;
290
+
291
+ // ─── Mint Tracker ─────────────────────────────────────
292
+
293
+ /** Build initMintTracker transaction. */
294
+ buildInitMintTracker(
295
+ authority: PublicKey | string,
296
+ agentIdOrHash: AgentIdOrHash
297
+ ): Promise<MintTrackerResult>;
298
+
299
+ /** Build recordMint transaction (max 3 per identity). */
300
+ buildRecordMint(
301
+ authority: PublicKey | string,
302
+ agentIdOrHash: AgentIdOrHash
303
+ ): Promise<TransactionResult>;
304
+
305
+ // ─── Attestations ─────────────────────────────────────
306
+
307
+ /** Build createAttestation transaction. */
308
+ buildCreateAttestation(
309
+ issuer: PublicKey | string,
310
+ agentId: string,
311
+ attestationType: string,
312
+ proofData: string,
313
+ expiresAt?: number | null
314
+ ): Promise<CreateAttestationResult>;
315
+
316
+ /** Build verifyAttestation transaction. */
317
+ buildVerifyAttestation(
318
+ issuer: PublicKey | string,
319
+ attestationPDA: PublicKey | string
320
+ ): Promise<TransactionResult>;
321
+
322
+ /** Build revokeAttestation transaction. */
323
+ buildRevokeAttestation(
324
+ issuer: PublicKey | string,
325
+ attestationPDA: PublicKey | string
326
+ ): Promise<TransactionResult>;
327
+
328
+ // ─── Reviews ───────────────────────────────────────────
329
+
330
+ /** Build initReviewCounter transaction. Must be called once per agent before reviews. */
331
+ buildInitReviewCounter(
332
+ payer: PublicKey | string,
333
+ agentId: string
334
+ ): Promise<InitReviewCounterResult>;
335
+
336
+ /**
337
+ * Build createReview transaction (V3.1 with optional self-review prevention).
338
+ * Pass opts.identityProgram + opts.identityAccount to enable self-review check.
339
+ * Omit opts (or pass {}) to skip the check (backwards compatible).
340
+ */
341
+ buildCreateReview(
342
+ reviewer: PublicKey | string,
343
+ agentId: string,
344
+ rating: number,
345
+ reviewText: string,
346
+ metadata?: string,
347
+ opts?: CreateReviewOpts
348
+ ): Promise<CreateReviewResult>;
349
+
350
+ /**
351
+ * Build createReview with self-review prevention auto-enabled.
352
+ * Automatically resolves identity PDA from agentId.
353
+ */
354
+ buildCreateReviewWithSelfCheck(
355
+ reviewer: PublicKey | string,
356
+ agentId: string,
357
+ rating: number,
358
+ reviewText: string,
359
+ metadata?: string
360
+ ): Promise<CreateReviewResult>;
361
+
362
+ /** Build updateReview transaction (reviewer only). */
363
+ buildUpdateReview(
364
+ reviewer: PublicKey | string,
365
+ reviewPDA: PublicKey | string,
366
+ updates?: UpdateReviewFields
367
+ ): Promise<TransactionResult>;
368
+
369
+ /** Build deleteReview transaction (soft-delete, reviewer only). */
370
+ buildDeleteReview(
371
+ reviewer: PublicKey | string,
372
+ reviewPDA: PublicKey | string
373
+ ): Promise<TransactionResult>;
374
+
375
+ // ─── Reputation (CPI → Identity) ─────────────────────
376
+
377
+ /**
378
+ * Build recomputeReputation transaction (permissionless).
379
+ * Pass review account pubkeys as remaining_accounts for score computation.
380
+ */
381
+ buildRecomputeReputation(
382
+ caller: PublicKey | string,
383
+ agentIdOrHash: AgentIdOrHash,
384
+ reviewAccounts?: (PublicKey | string)[]
385
+ ): Promise<TransactionResult>;
386
+
387
+ // ─── Validation (CPI → Identity) ─────────────────────
388
+
389
+ /**
390
+ * Build recomputeLevel transaction (permissionless).
391
+ * Pass attestation account pubkeys as remaining_accounts for level computation.
392
+ */
393
+ buildRecomputeLevel(
394
+ caller: PublicKey | string,
395
+ agentIdOrHash: AgentIdOrHash,
396
+ attestationAccounts?: (PublicKey | string)[]
397
+ ): Promise<TransactionResult>;
398
+
399
+ // ─── Escrow V3 (Identity-Verified) ───────────────────
400
+
401
+ /**
402
+ * Build createEscrow transaction (V3 — identity-verified).
403
+ * Creates an escrow between a client and a verified SATP V3 agent.
404
+ */
405
+ buildCreateEscrow(
406
+ client: PublicKey | string,
407
+ agentWallet: PublicKey | string,
408
+ agentId: string,
409
+ amount: number,
410
+ descriptionOrHash: string | Buffer,
411
+ deadline: number,
412
+ nonce?: number,
413
+ opts?: CreateEscrowOpts
414
+ ): Promise<CreateEscrowResult>;
415
+
416
+ /** Build submitWork transaction (agent submits work proof). */
417
+ buildSubmitWork(
418
+ agent: PublicKey | string,
419
+ escrowPDA: PublicKey | string,
420
+ workProofOrHash: string | Buffer
421
+ ): Promise<SubmitWorkResult>;
422
+
423
+ /** Build release transaction (client releases full remaining funds). */
424
+ buildEscrowRelease(
425
+ client: PublicKey | string,
426
+ agent: PublicKey | string,
427
+ escrowPDA: PublicKey | string
428
+ ): Promise<TransactionResult>;
429
+
430
+ /** Build partialRelease transaction (milestone payment). */
431
+ buildPartialRelease(
432
+ client: PublicKey | string,
433
+ agent: PublicKey | string,
434
+ escrowPDA: PublicKey | string,
435
+ amount: number
436
+ ): Promise<TransactionResult>;
437
+
438
+ /** Build cancel transaction (client cancels after deadline). */
439
+ buildCancelEscrow(
440
+ client: PublicKey | string,
441
+ escrowPDA: PublicKey | string
442
+ ): Promise<TransactionResult>;
443
+
444
+ /** Build raiseDispute transaction (either client or agent). */
445
+ buildRaiseDispute(
446
+ signer: PublicKey | string,
447
+ escrowPDA: PublicKey | string,
448
+ reasonOrHash: string | Buffer
449
+ ): Promise<RaiseDisputeResult>;
450
+
451
+ /** Build resolveDispute transaction (arbiter splits funds). */
452
+ buildResolveDispute(
453
+ arbiter: PublicKey | string,
454
+ agent: PublicKey | string,
455
+ clientWallet: PublicKey | string,
456
+ escrowPDA: PublicKey | string,
457
+ agentAmount: number,
458
+ clientAmount: number
459
+ ): Promise<TransactionResult>;
460
+
461
+ /** Build extendDeadline transaction (client extends escrow deadline). */
462
+ buildExtendDeadline(
463
+ client: PublicKey | string,
464
+ escrowPDA: PublicKey | string,
465
+ newDeadline: number
466
+ ): Promise<TransactionResult>;
467
+
468
+ /** Build closeEscrow transaction (returns rent to client). */
469
+ buildCloseEscrow(
470
+ client: PublicKey | string,
471
+ escrowPDA: PublicKey | string
472
+ ): Promise<TransactionResult>;
473
+
474
+ /** Fetch and deserialize an Escrow V3 account. */
475
+ getEscrow(escrowPDA: PublicKey | string): Promise<V3Escrow | null>;
476
+
477
+ /** Derive Escrow V3 PDA without RPC calls. */
478
+ getEscrowPDA(
479
+ client: PublicKey | string,
480
+ descriptionOrHash: string | Buffer,
481
+ nonce?: number
482
+ ): EscrowPDAResult;
483
+
484
+ // ─── Read Methods ─────────────────────────────────────
485
+
486
+ /** Fetch and deserialize a Genesis Record from on-chain. */
487
+ getGenesisRecord(agentIdOrHash: AgentIdOrHash): Promise<GenesisRecord | null>;
488
+
489
+ /** Check if a name is available in the registry. */
490
+ isNameAvailable(name: string): Promise<boolean>;
491
+
492
+ /** Check if an agent has a registered identity. */
493
+ hasIdentity(agentId: string): Promise<boolean>;
494
+
495
+ /** Fetch and deserialize a Review account. */
496
+ getReview(agentId: string, reviewer: PublicKey | string): Promise<V3Review | null>;
497
+
498
+ /** Fetch review counter for an agent. */
499
+ getReviewCount(agentId: string): Promise<V3ReviewCounter | null>;
500
+
501
+ // ─── Utility ──────────────────────────────────────────
502
+
503
+ /**
504
+ * Derive all V3 PDAs for an agent without RPC calls.
505
+ * @param agentIdOrHash - Agent ID string or pre-computed SHA-256 hash buffer
506
+ */
507
+ getV3PDAs(agentIdOrHash: AgentIdOrHash): V3PDAs;
508
+ }