@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.
package/src/index.d.ts ADDED
@@ -0,0 +1,507 @@
1
+ import { PublicKey, Transaction, Connection } from '@solana/web3.js';
2
+
3
+ export type Network = 'mainnet' | 'devnet';
4
+
5
+ export type IdentityAttestationTypeOption =
6
+ | { claimType: string; attestationType?: string }
7
+ | { claimType?: string; attestationType: string };
8
+
9
+ export type IdentityAttestationRequestOptions = {
10
+ subjectWallet: PublicKey | string;
11
+ agentId?: string;
12
+ metadataHash: string;
13
+ attester?: PublicKey | string;
14
+ issuer?: PublicKey | string;
15
+ network?: Network;
16
+ expiresAt?: number | null;
17
+ } & IdentityAttestationTypeOption;
18
+
19
+ export interface IdentityAttestationRequest {
20
+ schemaVersion: 'satp.identityAttestationRequest.v1';
21
+ requestType: 'identity-attestation';
22
+ mode: 'unsigned-readonly-request';
23
+ network: Network;
24
+ signingRequired: false;
25
+ unsigned: true;
26
+ subjectWallet: string;
27
+ agentId: string;
28
+ attester: string;
29
+ claimType: string;
30
+ attestationType: string;
31
+ metadataHash: string;
32
+ proofData: string;
33
+ expiresAt: number | null;
34
+ agentIdHash: string;
35
+ genesisPda: string;
36
+ genesisBump: number;
37
+ attestationPda: string;
38
+ attestationBump: number;
39
+ programs: {
40
+ identity: string;
41
+ attestations: string;
42
+ };
43
+ instructions: [];
44
+ signers: [];
45
+ transaction: null;
46
+ requestHash: string;
47
+ }
48
+
49
+ export interface SatpTrustPacket {
50
+ schemaVersion: 'satp.trustPacket.v1';
51
+ packetType: 'satp-trust-packet';
52
+ mode: 'offline-readonly-trust-packet';
53
+ network: Network;
54
+ subjectWallet: string;
55
+ agentId: string;
56
+ claimType: string;
57
+ attestationType: string;
58
+ metadataHash: string;
59
+ attester: string;
60
+ expiresAt: number | null;
61
+ programs: {
62
+ identity: string;
63
+ attestations: string;
64
+ };
65
+ pda: {
66
+ genesis: string;
67
+ genesisBump: number;
68
+ attestation: string;
69
+ attestationBump: number;
70
+ };
71
+ requestHash: string;
72
+ flags: {
73
+ signingRequired: false;
74
+ transactionRequired: false;
75
+ writesRequired: false;
76
+ livePaymentRequired: false;
77
+ unsigned: true;
78
+ noSign: true;
79
+ noTransaction: true;
80
+ };
81
+ instructions: [];
82
+ signers: [];
83
+ transaction: null;
84
+ request: IdentityAttestationRequest;
85
+ }
86
+
87
+ export interface SatpTrustPacketValidation {
88
+ ok: boolean;
89
+ errors: string[];
90
+ }
91
+
92
+ export interface X402PaymentRequirement {
93
+ scheme?: string;
94
+ network?: string;
95
+ asset?: string;
96
+ payTo?: string;
97
+ maxAmountRequired?: string | number;
98
+ amountRequired?: string | number;
99
+ resource?: string;
100
+ description?: string;
101
+ mimeType?: string;
102
+ maxTimeoutSeconds?: number;
103
+ extra?: unknown;
104
+ }
105
+
106
+ export interface X402DiscoveryMetadata {
107
+ schemaVersion: 'satp.x402DiscoveryMetadata.v1';
108
+ protocol: 'x402';
109
+ resource: string | null;
110
+ endpoint: string | null;
111
+ action: string | null;
112
+ paymentRequired: boolean;
113
+ paymentRequirements: X402PaymentRequirement[];
114
+ guardrail: 'X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION';
115
+ }
116
+
117
+ export interface X402EvidenceLookup {
118
+ type: 'x402';
119
+ endpoint: string | null;
120
+ maxCostUsd: number | null;
121
+ protocol: 'x402';
122
+ source: {
123
+ kind: string;
124
+ url: string | null;
125
+ };
126
+ resource: string | null;
127
+ paymentRequired: boolean;
128
+ paymentRequirements: X402PaymentRequirement[];
129
+ discovery: X402DiscoveryMetadata;
130
+ guardrail: 'X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION';
131
+ paymentAuthorization: false;
132
+ actionAuthorization: false;
133
+ spendAuthorized: false;
134
+ livePaymentRequired: false;
135
+ }
136
+
137
+ export type RuntimePolicyDecision =
138
+ | 'allow'
139
+ | 'deny'
140
+ | 'degrade'
141
+ | 'needs_approval';
142
+
143
+ export interface RuntimePolicyIdentityPayload {
144
+ active?: boolean;
145
+ satpVerified?: boolean;
146
+ verified?: boolean;
147
+ agentFolioTrustScore?: number;
148
+ trustScore?: number;
149
+ capabilities?: string[];
150
+ evidenceUpdatedAt?: string | number | Date | null;
151
+ }
152
+
153
+ export interface RuntimePolicyActionDescriptor {
154
+ type?: string;
155
+ resource?: string;
156
+ operation?: string;
157
+ requiresCapability?: string;
158
+ minimumTrustScore?: number;
159
+ allowDegraded?: boolean;
160
+ requiresFreshEvidence?: boolean;
161
+ costUsd?: number;
162
+ protectedTool?: boolean;
163
+ operatorApprovalRequired?: boolean;
164
+ evidenceLookup?: {
165
+ type?: string;
166
+ endpoint?: string;
167
+ maxCostUsd?: number;
168
+ } | X402EvidenceLookup;
169
+ }
170
+
171
+ export interface RuntimePolicyConfig {
172
+ minimumTrustScore?: number;
173
+ denyTrustScoreBelow?: number;
174
+ maxAutoSpendUsd?: number;
175
+ requireVerifiedIdentity?: boolean;
176
+ staleEvidenceAfterMs?: number;
177
+ }
178
+
179
+ export interface RuntimePolicyOptions {
180
+ now?: string | number | Date;
181
+ actionPaymentPreapproved?: boolean;
182
+ evidenceLookupPaymentPreapproved?: boolean;
183
+ operatorApproved?: boolean;
184
+ policy?: RuntimePolicyConfig;
185
+ }
186
+
187
+ export interface RuntimePolicyResult {
188
+ decision: RuntimePolicyDecision;
189
+ reasonCodes: string[];
190
+ message: string;
191
+ checks: Record<string, unknown>;
192
+ }
193
+
194
+ export const DECISIONS: Readonly<{
195
+ ALLOW: 'allow';
196
+ DENY: 'deny';
197
+ DEGRADE: 'degrade';
198
+ NEEDS_APPROVAL: 'needs_approval';
199
+ }>;
200
+
201
+ export const REASON_CODES: Readonly<Record<string, string>>;
202
+ export const DEFAULT_POLICY: Readonly<Required<RuntimePolicyConfig>>;
203
+
204
+ export function evaluateRuntimePolicy(
205
+ identityPayload: RuntimePolicyIdentityPayload,
206
+ actionDescriptor: RuntimePolicyActionDescriptor,
207
+ options?: RuntimePolicyOptions
208
+ ): RuntimePolicyResult;
209
+
210
+ export interface WalletControlChallengeOptions {
211
+ agentId: string;
212
+ wallet: PublicKey | string;
213
+ network?: Network;
214
+ domain?: string;
215
+ audience?: string;
216
+ nonce?: string;
217
+ issuedAt?: number;
218
+ expiresAt?: number;
219
+ }
220
+
221
+ export interface WalletControlChallenge {
222
+ schemaVersion: 'satp.walletControlChallenge.v1';
223
+ challengeType: 'wallet-control';
224
+ domain: string;
225
+ audience: string;
226
+ network: Network;
227
+ agentId: string;
228
+ wallet: string;
229
+ nonce: string;
230
+ issuedAt: number;
231
+ expiresAt: number;
232
+ agentIdHash: string;
233
+ genesisPda: string;
234
+ genesisBump: number;
235
+ linkedWalletPda: string;
236
+ linkedWalletBump: number;
237
+ }
238
+
239
+ export interface WalletControlChallengePdas {
240
+ agentIdHash: string;
241
+ genesisPda: string;
242
+ genesisBump: number;
243
+ linkedWalletPda: string;
244
+ linkedWalletBump: number;
245
+ }
246
+
247
+ export interface VerifyWalletControlChallengeSignatureOptions {
248
+ challenge: WalletControlChallenge | Record<string, unknown>;
249
+ signature: string | Buffer | Uint8Array | number[];
250
+ expectedWallet?: PublicKey | string;
251
+ expectedAgentId?: string;
252
+ expectedDomain?: string;
253
+ expectedAudience?: string;
254
+ now?: number;
255
+ usedNonces?: Set<string> | string[] | Record<string, boolean>;
256
+ replayCache?: { has(nonce: string): boolean } | string[] | Record<string, boolean>;
257
+ isNonceUsed?: (nonce: string, challenge: WalletControlChallenge) => boolean;
258
+ }
259
+
260
+ export interface WalletControlChallengeVerification {
261
+ ok: boolean;
262
+ errors: string[];
263
+ challengeHash: string;
264
+ }
265
+
266
+ // ─── V2 SDK ──────────────────────────────────────────────
267
+
268
+ export interface V2ProgramIds {
269
+ IDENTITY: PublicKey;
270
+ REPUTATION: PublicKey;
271
+ VALIDATION: PublicKey;
272
+ REVIEWS: PublicKey;
273
+ ESCROW: PublicKey | null;
274
+ }
275
+
276
+ export interface SATSDKOptions {
277
+ network?: Network;
278
+ rpcUrl?: string;
279
+ commitment?: 'processed' | 'confirmed' | 'finalized';
280
+ }
281
+
282
+ export interface V2Identity {
283
+ owner: string;
284
+ agentName: string;
285
+ metadata: string;
286
+ createdAt: number;
287
+ updatedAt: number;
288
+ pda: string;
289
+ reputationScore?: number;
290
+ verificationLevel?: number;
291
+ }
292
+
293
+ export interface V2EscrowState {
294
+ client: string;
295
+ agent: string;
296
+ amount: number;
297
+ descriptionHash: string;
298
+ deadline: number;
299
+ status: string;
300
+ createdAt: number;
301
+ bump: number;
302
+ workHash: string | null;
303
+ pda: string;
304
+ }
305
+
306
+ export interface V2ReviewState {
307
+ reviewer: string;
308
+ reviewed: string;
309
+ jobId: number;
310
+ jobRef: string;
311
+ rating: number;
312
+ categoryQuality: number;
313
+ categoryReliability: number;
314
+ categoryCommunication: number;
315
+ commentUri: string;
316
+ commentHash: string;
317
+ timestamp: number;
318
+ hasResponse: boolean;
319
+ responseUri: string | null;
320
+ responseHash: string | null;
321
+ responseTimestamp: number | null;
322
+ bump: number;
323
+ pda: string;
324
+ }
325
+
326
+ export class SATPSDK {
327
+ network: Network;
328
+ rpcUrl: string;
329
+ commitment: string;
330
+ connection: Connection;
331
+ programIds: V2ProgramIds;
332
+
333
+ constructor(opts?: SATSDKOptions);
334
+
335
+ // Identity
336
+ buildCreateIdentity(wallet: PublicKey | string, agentName: string, metadata: string | object): Promise<{ transaction: Transaction; identityPDA: PublicKey }>;
337
+ createIdentity(signer: any, agentName: string, metadata: string | object): Promise<string>;
338
+ getIdentity(wallet: PublicKey | string): Promise<V2Identity | null>;
339
+
340
+ // Reputation
341
+ buildRecomputeReputation(agentWallet: PublicKey | string, payer: PublicKey | string): Promise<{ transaction: Transaction }>;
342
+ recomputeReputation(signerKeypair: any, agentWallet: PublicKey | string): Promise<string>;
343
+ getReputation(wallet: PublicKey | string): Promise<{ owner: string; agentName: string; reputationScore: number; verificationLevel: number; pda: string } | null>;
344
+
345
+ // Validation
346
+ buildRecomputeLevel(agentWallet: PublicKey | string, payer: PublicKey | string): Promise<{ transaction: Transaction }>;
347
+ recomputeLevel(signerKeypair: any, agentWallet: PublicKey | string): Promise<string>;
348
+
349
+ // MintTracker
350
+ buildInitMintTracker(wallet: PublicKey | string): Promise<{ transaction: Transaction; mintTrackerPDA: PublicKey }>;
351
+
352
+ // Escrow
353
+ buildCreateEscrow(clientWallet: PublicKey | string, agentWallet: PublicKey | string, amountLamports: number, description: string, deadlineUnix: number): Promise<{ transaction: Transaction; escrowPDA: PublicKey; descriptionHash: Buffer }>;
354
+ buildRelease(clientWallet: PublicKey | string, agentWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
355
+ buildSubmitWork(agentWallet: PublicKey | string, escrowPDA: PublicKey | string, workProof: string): Promise<{ transaction: Transaction; workHash: Buffer }>;
356
+ buildCancel(clientWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
357
+ buildRaiseDispute(signerWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
358
+ buildCloseEscrow(clientWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
359
+ buildResolveDispute(clientWallet: PublicKey | string, agentWallet: PublicKey | string, escrowPDA: PublicKey | string, releaseToAgent: boolean): Promise<{ transaction: Transaction }>;
360
+ getEscrow(escrowPDA: PublicKey | string): Promise<V2EscrowState | null>;
361
+
362
+ // Reviews V3 (job-scoped)
363
+ buildSubmitReview(reviewerWallet: PublicKey | string, reviewerIdentityPDA: PublicKey | string, jobPDA: PublicKey | string, ratings: { rating: number; quality: number; reliability: number; communication: number }, commentUri: string, commentHash: Buffer | string): Promise<{ transaction: Transaction; reviewPDA: PublicKey }>;
364
+ buildRespondToReview(responderWallet: PublicKey | string, reviewPDA: PublicKey | string, responseUri: string, responseHash: Buffer | string): Promise<{ transaction: Transaction }>;
365
+ getReview(reviewPDA: PublicKey | string): Promise<V2ReviewState | null>;
366
+ getReviewV3PDA(jobPDA: PublicKey | string, reviewer: PublicKey | string): [PublicKey, number];
367
+
368
+ // Verification
369
+ verifyAgent(wallet: PublicKey | string): Promise<boolean>;
370
+
371
+ // Utility
372
+ getPDAs(wallet: PublicKey | string): { identity: string; reviewCounter: string; mintTracker: string; reputationAuthority: string; validationAuthority: string };
373
+ }
374
+
375
+ // ─── V3 SDK ──────────────────────────────────────────────
376
+
377
+ export { SATPV3SDK } from './v3-sdk';
378
+
379
+ // ─── V2 PDA Helpers ─────────────────────────────────────
380
+
381
+ export function getProgramIds(network?: Network): V2ProgramIds;
382
+ export function getIdentityPDA(wallet: PublicKey, network?: Network): [PublicKey, number];
383
+ export function getReputationAuthorityPDA(network?: Network): [PublicKey, number];
384
+ export function getValidationAuthorityPDA(network?: Network): [PublicKey, number];
385
+ export function getReviewCounterPDA(wallet: PublicKey, network?: Network): [PublicKey, number];
386
+ export function getMintTrackerPDA(identityPDA: PublicKey, network?: Network): [PublicKey, number];
387
+ export function getReviewsAuthorityPDA(network?: Network): [PublicKey, number];
388
+ export function getReviewPDA(reviewCounter: PublicKey, network?: Network): [PublicKey, number];
389
+ export function getReviewAttestationPDA(reviewPDA: PublicKey, attester: PublicKey, network?: Network): [PublicKey, number];
390
+ export function getEscrowPDA(client: PublicKey, descriptionHash: Buffer, network?: Network): [PublicKey, number];
391
+ export function getReviewV3PDA(jobPDA: PublicKey | string, reviewer: PublicKey | string, network?: Network): [PublicKey, number];
392
+ export function anchorDiscriminator(ixName: string): Buffer;
393
+
394
+ // ─── V3 PDA Helpers ─────────────────────────────────────
395
+
396
+ export { getV3ProgramIds, hashAgentId, hashName, getGenesisPDA, getV3ReputationAuthorityPDA, getV3ValidationAuthorityPDA, getV3MintTrackerPDA, getNameRegistryPDA, getLinkedWalletPDA, getV3ReviewPDA, getV3ReviewCounterPDA, getV3AttestationPDA, getV3EscrowPDA } from './v3-pda';
397
+
398
+ export function prepareIdentityAttestationRequest(
399
+ opts: IdentityAttestationRequestOptions
400
+ ): IdentityAttestationRequest;
401
+
402
+ export const TRUST_PACKET_SCHEMA_VERSION: 'satp.trustPacket.v1';
403
+
404
+ export function buildSatpTrustPacket(
405
+ opts: IdentityAttestationRequestOptions
406
+ ): SatpTrustPacket;
407
+
408
+ export function validateSatpTrustPacket(
409
+ packet: SatpTrustPacket | Record<string, unknown> | null | undefined
410
+ ): SatpTrustPacketValidation;
411
+
412
+ export const X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION: 'X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION';
413
+ export const X402_DISCOVERY_SCHEMA_VERSION: 'satp.x402DiscoveryMetadata.v1';
414
+ export const RUNTIME_POLICY_ACTION_DESCRIPTOR_SCHEMA_VERSION: 'satp.runtimePolicyActionDescriptor.v1';
415
+
416
+ export function parseX402DiscoveryMetadata(
417
+ input: Record<string, unknown> | string
418
+ ): X402DiscoveryMetadata;
419
+
420
+ export function buildX402EvidenceLookup(
421
+ input: Record<string, unknown> | string,
422
+ opts?: {
423
+ endpoint?: string;
424
+ maxCostUsd?: number;
425
+ sourceKind?: string;
426
+ sourceUrl?: string;
427
+ }
428
+ ): X402EvidenceLookup;
429
+
430
+ export function buildRuntimePolicyActionDescriptorFromX402Discovery(
431
+ input: Record<string, unknown> | string,
432
+ opts?: {
433
+ type?: string;
434
+ resource?: string;
435
+ operation?: string;
436
+ requiresFreshEvidence?: boolean;
437
+ endpoint?: string;
438
+ maxCostUsd?: number;
439
+ sourceKind?: string;
440
+ sourceUrl?: string;
441
+ }
442
+ ): RuntimePolicyActionDescriptor & {
443
+ schemaVersion: 'satp.runtimePolicyActionDescriptor.v1';
444
+ evidenceLookup: X402EvidenceLookup;
445
+ paymentAuthorization: false;
446
+ actionAuthorization: false;
447
+ spendAuthorized: false;
448
+ livePaymentRequired: false;
449
+ guardrail: 'X402_PAYMENT_IS_NOT_ACTION_AUTHORIZATION';
450
+ };
451
+
452
+ export const buildRuntimePolicyActionDescriptorFromX402: typeof buildRuntimePolicyActionDescriptorFromX402Discovery;
453
+
454
+ export const WALLET_CONTROL_CHALLENGE_SCHEMA_VERSION: 'satp.walletControlChallenge.v1';
455
+ export const WALLET_CONTROL_CHALLENGE_TYPE: 'wallet-control';
456
+ export const DEFAULT_WALLET_CONTROL_DOMAIN: string;
457
+ export const DEFAULT_WALLET_CONTROL_AUDIENCE: string;
458
+
459
+ export function buildWalletControlChallenge(
460
+ opts: WalletControlChallengeOptions
461
+ ): WalletControlChallenge;
462
+
463
+ export function canonicalWalletControlChallenge(
464
+ challenge: WalletControlChallenge | Record<string, unknown>
465
+ ): string;
466
+
467
+ export function hashWalletControlChallenge(
468
+ challenge: WalletControlChallenge | Record<string, unknown>
469
+ ): string;
470
+
471
+ export function deriveWalletControlChallengePdas(
472
+ opts: Pick<WalletControlChallengeOptions, 'agentId' | 'wallet' | 'network'>
473
+ ): WalletControlChallengePdas;
474
+
475
+ export function verifyWalletControlChallengeSignature(
476
+ opts: VerifyWalletControlChallengeSignatureOptions
477
+ ): WalletControlChallengeVerification;
478
+
479
+ // ─── Borsh Deserialization Helpers ──────────────────────
480
+
481
+ export {
482
+ BorshReader,
483
+ deserializeGenesisRecord,
484
+ deserializeLinkedWallet,
485
+ deserializeMintTracker,
486
+ deserializeNameRegistry,
487
+ deserializeReview,
488
+ deserializeReviewCounter,
489
+ deserializeAttestation,
490
+ deserializeEscrowV3,
491
+ deserializeAccount,
492
+ deserializeBatch,
493
+ getAccountDiscriminator,
494
+ accountDiscriminator,
495
+ isAccountType,
496
+ DISCRIMINATORS,
497
+ ParsedGenesisRecord,
498
+ ParsedLinkedWallet,
499
+ ParsedMintTracker,
500
+ ParsedNameRegistry,
501
+ ParsedReview,
502
+ ParsedReviewCounter,
503
+ ParsedAttestation,
504
+ ParsedEscrowV3,
505
+ AccountTypeName,
506
+ ParsedAccountData,
507
+ } from './borsh-reader';