@brainai/satp-client 0.1.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.d.ts ADDED
@@ -0,0 +1,420 @@
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 type RuntimePolicyDecision =
93
+ | 'allow'
94
+ | 'deny'
95
+ | 'degrade'
96
+ | 'needs_approval';
97
+
98
+ export interface RuntimePolicyIdentityPayload {
99
+ active?: boolean;
100
+ satpVerified?: boolean;
101
+ verified?: boolean;
102
+ agentFolioTrustScore?: number;
103
+ trustScore?: number;
104
+ capabilities?: string[];
105
+ evidenceUpdatedAt?: string | number | Date | null;
106
+ }
107
+
108
+ export interface RuntimePolicyActionDescriptor {
109
+ type?: string;
110
+ resource?: string;
111
+ operation?: string;
112
+ requiresCapability?: string;
113
+ minimumTrustScore?: number;
114
+ allowDegraded?: boolean;
115
+ requiresFreshEvidence?: boolean;
116
+ costUsd?: number;
117
+ protectedTool?: boolean;
118
+ operatorApprovalRequired?: boolean;
119
+ evidenceLookup?: {
120
+ type?: string;
121
+ endpoint?: string;
122
+ maxCostUsd?: number;
123
+ };
124
+ }
125
+
126
+ export interface RuntimePolicyConfig {
127
+ minimumTrustScore?: number;
128
+ denyTrustScoreBelow?: number;
129
+ maxAutoSpendUsd?: number;
130
+ requireVerifiedIdentity?: boolean;
131
+ staleEvidenceAfterMs?: number;
132
+ }
133
+
134
+ export interface RuntimePolicyOptions {
135
+ now?: string | number | Date;
136
+ actionPaymentPreapproved?: boolean;
137
+ evidenceLookupPaymentPreapproved?: boolean;
138
+ operatorApproved?: boolean;
139
+ policy?: RuntimePolicyConfig;
140
+ }
141
+
142
+ export interface RuntimePolicyResult {
143
+ decision: RuntimePolicyDecision;
144
+ reasonCodes: string[];
145
+ message: string;
146
+ checks: Record<string, unknown>;
147
+ }
148
+
149
+ export const DECISIONS: Readonly<{
150
+ ALLOW: 'allow';
151
+ DENY: 'deny';
152
+ DEGRADE: 'degrade';
153
+ NEEDS_APPROVAL: 'needs_approval';
154
+ }>;
155
+
156
+ export const REASON_CODES: Readonly<Record<string, string>>;
157
+ export const DEFAULT_POLICY: Readonly<Required<RuntimePolicyConfig>>;
158
+
159
+ export function evaluateRuntimePolicy(
160
+ identityPayload: RuntimePolicyIdentityPayload,
161
+ actionDescriptor: RuntimePolicyActionDescriptor,
162
+ options?: RuntimePolicyOptions
163
+ ): RuntimePolicyResult;
164
+
165
+ export interface WalletControlChallengeOptions {
166
+ agentId: string;
167
+ wallet: PublicKey | string;
168
+ network?: Network;
169
+ domain?: string;
170
+ audience?: string;
171
+ nonce?: string;
172
+ issuedAt?: number;
173
+ expiresAt?: number;
174
+ }
175
+
176
+ export interface WalletControlChallenge {
177
+ schemaVersion: 'satp.walletControlChallenge.v1';
178
+ challengeType: 'wallet-control';
179
+ domain: string;
180
+ audience: string;
181
+ network: Network;
182
+ agentId: string;
183
+ wallet: string;
184
+ nonce: string;
185
+ issuedAt: number;
186
+ expiresAt: number;
187
+ agentIdHash: string;
188
+ genesisPda: string;
189
+ genesisBump: number;
190
+ linkedWalletPda: string;
191
+ linkedWalletBump: number;
192
+ }
193
+
194
+ export interface WalletControlChallengePdas {
195
+ agentIdHash: string;
196
+ genesisPda: string;
197
+ genesisBump: number;
198
+ linkedWalletPda: string;
199
+ linkedWalletBump: number;
200
+ }
201
+
202
+ export interface VerifyWalletControlChallengeSignatureOptions {
203
+ challenge: WalletControlChallenge | Record<string, unknown>;
204
+ signature: string | Buffer | Uint8Array | number[];
205
+ expectedWallet?: PublicKey | string;
206
+ expectedAgentId?: string;
207
+ expectedDomain?: string;
208
+ expectedAudience?: string;
209
+ now?: number;
210
+ usedNonces?: Set<string> | string[] | Record<string, boolean>;
211
+ replayCache?: { has(nonce: string): boolean } | string[] | Record<string, boolean>;
212
+ isNonceUsed?: (nonce: string, challenge: WalletControlChallenge) => boolean;
213
+ }
214
+
215
+ export interface WalletControlChallengeVerification {
216
+ ok: boolean;
217
+ errors: string[];
218
+ challengeHash: string;
219
+ }
220
+
221
+ // ─── V2 SDK ──────────────────────────────────────────────
222
+
223
+ export interface V2ProgramIds {
224
+ IDENTITY: PublicKey;
225
+ REPUTATION: PublicKey;
226
+ VALIDATION: PublicKey;
227
+ REVIEWS: PublicKey;
228
+ ESCROW: PublicKey | null;
229
+ }
230
+
231
+ export interface SATSDKOptions {
232
+ network?: Network;
233
+ rpcUrl?: string;
234
+ commitment?: 'processed' | 'confirmed' | 'finalized';
235
+ }
236
+
237
+ export interface V2Identity {
238
+ owner: string;
239
+ agentName: string;
240
+ metadata: string;
241
+ createdAt: number;
242
+ updatedAt: number;
243
+ pda: string;
244
+ reputationScore?: number;
245
+ verificationLevel?: number;
246
+ }
247
+
248
+ export interface V2EscrowState {
249
+ client: string;
250
+ agent: string;
251
+ amount: number;
252
+ descriptionHash: string;
253
+ deadline: number;
254
+ status: string;
255
+ createdAt: number;
256
+ bump: number;
257
+ workHash: string | null;
258
+ pda: string;
259
+ }
260
+
261
+ export interface V2ReviewState {
262
+ reviewer: string;
263
+ reviewed: string;
264
+ jobId: number;
265
+ jobRef: string;
266
+ rating: number;
267
+ categoryQuality: number;
268
+ categoryReliability: number;
269
+ categoryCommunication: number;
270
+ commentUri: string;
271
+ commentHash: string;
272
+ timestamp: number;
273
+ hasResponse: boolean;
274
+ responseUri: string | null;
275
+ responseHash: string | null;
276
+ responseTimestamp: number | null;
277
+ bump: number;
278
+ pda: string;
279
+ }
280
+
281
+ export class SATPSDK {
282
+ network: Network;
283
+ rpcUrl: string;
284
+ commitment: string;
285
+ connection: Connection;
286
+ programIds: V2ProgramIds;
287
+
288
+ constructor(opts?: SATSDKOptions);
289
+
290
+ // Identity
291
+ buildCreateIdentity(wallet: PublicKey | string, agentName: string, metadata: string | object): Promise<{ transaction: Transaction; identityPDA: PublicKey }>;
292
+ createIdentity(signer: any, agentName: string, metadata: string | object): Promise<string>;
293
+ getIdentity(wallet: PublicKey | string): Promise<V2Identity | null>;
294
+
295
+ // Reputation
296
+ buildRecomputeReputation(agentWallet: PublicKey | string, payer: PublicKey | string): Promise<{ transaction: Transaction }>;
297
+ recomputeReputation(signerKeypair: any, agentWallet: PublicKey | string): Promise<string>;
298
+ getReputation(wallet: PublicKey | string): Promise<{ owner: string; agentName: string; reputationScore: number; verificationLevel: number; pda: string } | null>;
299
+
300
+ // Validation
301
+ buildRecomputeLevel(agentWallet: PublicKey | string, payer: PublicKey | string): Promise<{ transaction: Transaction }>;
302
+ recomputeLevel(signerKeypair: any, agentWallet: PublicKey | string): Promise<string>;
303
+
304
+ // MintTracker
305
+ buildInitMintTracker(wallet: PublicKey | string): Promise<{ transaction: Transaction; mintTrackerPDA: PublicKey }>;
306
+
307
+ // Escrow
308
+ buildCreateEscrow(clientWallet: PublicKey | string, agentWallet: PublicKey | string, amountLamports: number, description: string, deadlineUnix: number): Promise<{ transaction: Transaction; escrowPDA: PublicKey; descriptionHash: Buffer }>;
309
+ buildRelease(clientWallet: PublicKey | string, agentWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
310
+ buildSubmitWork(agentWallet: PublicKey | string, escrowPDA: PublicKey | string, workProof: string): Promise<{ transaction: Transaction; workHash: Buffer }>;
311
+ buildCancel(clientWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
312
+ buildRaiseDispute(signerWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
313
+ buildCloseEscrow(clientWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
314
+ buildResolveDispute(clientWallet: PublicKey | string, agentWallet: PublicKey | string, escrowPDA: PublicKey | string, releaseToAgent: boolean): Promise<{ transaction: Transaction }>;
315
+ getEscrow(escrowPDA: PublicKey | string): Promise<V2EscrowState | null>;
316
+
317
+ // Reviews V3 (job-scoped)
318
+ 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 }>;
319
+ buildRespondToReview(responderWallet: PublicKey | string, reviewPDA: PublicKey | string, responseUri: string, responseHash: Buffer | string): Promise<{ transaction: Transaction }>;
320
+ getReview(reviewPDA: PublicKey | string): Promise<V2ReviewState | null>;
321
+ getReviewV3PDA(jobPDA: PublicKey | string, reviewer: PublicKey | string): [PublicKey, number];
322
+
323
+ // Verification
324
+ verifyAgent(wallet: PublicKey | string): Promise<boolean>;
325
+
326
+ // Utility
327
+ getPDAs(wallet: PublicKey | string): { identity: string; reviewCounter: string; mintTracker: string; reputationAuthority: string; validationAuthority: string };
328
+ }
329
+
330
+ // ─── V3 SDK ──────────────────────────────────────────────
331
+
332
+ export { SATPV3SDK } from './v3-sdk';
333
+
334
+ // ─── V2 PDA Helpers ─────────────────────────────────────
335
+
336
+ export function getProgramIds(network?: Network): V2ProgramIds;
337
+ export function getIdentityPDA(wallet: PublicKey, network?: Network): [PublicKey, number];
338
+ export function getReputationAuthorityPDA(network?: Network): [PublicKey, number];
339
+ export function getValidationAuthorityPDA(network?: Network): [PublicKey, number];
340
+ export function getReviewCounterPDA(wallet: PublicKey, network?: Network): [PublicKey, number];
341
+ export function getMintTrackerPDA(identityPDA: PublicKey, network?: Network): [PublicKey, number];
342
+ export function getReviewsAuthorityPDA(network?: Network): [PublicKey, number];
343
+ export function getReviewPDA(reviewCounter: PublicKey, network?: Network): [PublicKey, number];
344
+ export function getReviewAttestationPDA(reviewPDA: PublicKey, attester: PublicKey, network?: Network): [PublicKey, number];
345
+ export function getEscrowPDA(client: PublicKey, descriptionHash: Buffer, network?: Network): [PublicKey, number];
346
+ export function getReviewV3PDA(jobPDA: PublicKey | string, reviewer: PublicKey | string, network?: Network): [PublicKey, number];
347
+ export function anchorDiscriminator(ixName: string): Buffer;
348
+
349
+ // ─── V3 PDA Helpers ─────────────────────────────────────
350
+
351
+ export { getV3ProgramIds, hashAgentId, hashName, getGenesisPDA, getV3ReputationAuthorityPDA, getV3ValidationAuthorityPDA, getV3MintTrackerPDA, getNameRegistryPDA, getLinkedWalletPDA, getV3ReviewPDA, getV3ReviewCounterPDA, getV3AttestationPDA, getV3EscrowPDA } from './v3-pda';
352
+
353
+ export function prepareIdentityAttestationRequest(
354
+ opts: IdentityAttestationRequestOptions
355
+ ): IdentityAttestationRequest;
356
+
357
+ export const TRUST_PACKET_SCHEMA_VERSION: 'satp.trustPacket.v1';
358
+
359
+ export function buildSatpTrustPacket(
360
+ opts: IdentityAttestationRequestOptions
361
+ ): SatpTrustPacket;
362
+
363
+ export function validateSatpTrustPacket(
364
+ packet: SatpTrustPacket | Record<string, unknown> | null | undefined
365
+ ): SatpTrustPacketValidation;
366
+
367
+ export const WALLET_CONTROL_CHALLENGE_SCHEMA_VERSION: 'satp.walletControlChallenge.v1';
368
+ export const WALLET_CONTROL_CHALLENGE_TYPE: 'wallet-control';
369
+ export const DEFAULT_WALLET_CONTROL_DOMAIN: string;
370
+ export const DEFAULT_WALLET_CONTROL_AUDIENCE: string;
371
+
372
+ export function buildWalletControlChallenge(
373
+ opts: WalletControlChallengeOptions
374
+ ): WalletControlChallenge;
375
+
376
+ export function canonicalWalletControlChallenge(
377
+ challenge: WalletControlChallenge | Record<string, unknown>
378
+ ): string;
379
+
380
+ export function hashWalletControlChallenge(
381
+ challenge: WalletControlChallenge | Record<string, unknown>
382
+ ): string;
383
+
384
+ export function deriveWalletControlChallengePdas(
385
+ opts: Pick<WalletControlChallengeOptions, 'agentId' | 'wallet' | 'network'>
386
+ ): WalletControlChallengePdas;
387
+
388
+ export function verifyWalletControlChallengeSignature(
389
+ opts: VerifyWalletControlChallengeSignatureOptions
390
+ ): WalletControlChallengeVerification;
391
+
392
+ // ─── Borsh Deserialization Helpers ──────────────────────
393
+
394
+ export {
395
+ BorshReader,
396
+ deserializeGenesisRecord,
397
+ deserializeLinkedWallet,
398
+ deserializeMintTracker,
399
+ deserializeNameRegistry,
400
+ deserializeReview,
401
+ deserializeReviewCounter,
402
+ deserializeAttestation,
403
+ deserializeEscrowV3,
404
+ deserializeAccount,
405
+ deserializeBatch,
406
+ getAccountDiscriminator,
407
+ accountDiscriminator,
408
+ isAccountType,
409
+ DISCRIMINATORS,
410
+ ParsedGenesisRecord,
411
+ ParsedLinkedWallet,
412
+ ParsedMintTracker,
413
+ ParsedNameRegistry,
414
+ ParsedReview,
415
+ ParsedReviewCounter,
416
+ ParsedAttestation,
417
+ ParsedEscrowV3,
418
+ AccountTypeName,
419
+ ParsedAccountData,
420
+ } from './borsh-reader';