@brainai/satp-client 2.0.0 → 2.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/README.md +435 -51
- package/package.json +24 -4
- package/src/attestation-request.js +149 -0
- package/src/borsh-reader.d.ts +213 -0
- package/src/borsh-reader.js +587 -0
- package/src/constants.js +10 -0
- package/src/index.d.ts +266 -0
- package/src/index.js +642 -0
- package/src/pda.js +43 -0
- package/src/trust-packet.js +148 -0
- package/src/v3-pda.d.ts +72 -0
- package/src/v3-pda.js +281 -0
- package/src/v3-sdk.d.ts +508 -0
- package/src/v3-sdk.js +1800 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
// ─── V2 SDK ──────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
export interface V2ProgramIds {
|
|
95
|
+
IDENTITY: PublicKey;
|
|
96
|
+
REPUTATION: PublicKey;
|
|
97
|
+
VALIDATION: PublicKey;
|
|
98
|
+
REVIEWS: PublicKey;
|
|
99
|
+
ESCROW: PublicKey | null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface SATSDKOptions {
|
|
103
|
+
network?: Network;
|
|
104
|
+
rpcUrl?: string;
|
|
105
|
+
commitment?: 'processed' | 'confirmed' | 'finalized';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface V2Identity {
|
|
109
|
+
owner: string;
|
|
110
|
+
agentName: string;
|
|
111
|
+
metadata: string;
|
|
112
|
+
createdAt: number;
|
|
113
|
+
updatedAt: number;
|
|
114
|
+
pda: string;
|
|
115
|
+
reputationScore?: number;
|
|
116
|
+
verificationLevel?: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface V2EscrowState {
|
|
120
|
+
client: string;
|
|
121
|
+
agent: string;
|
|
122
|
+
amount: number;
|
|
123
|
+
descriptionHash: string;
|
|
124
|
+
deadline: number;
|
|
125
|
+
status: string;
|
|
126
|
+
createdAt: number;
|
|
127
|
+
bump: number;
|
|
128
|
+
workHash: string | null;
|
|
129
|
+
pda: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface V2ReviewState {
|
|
133
|
+
reviewer: string;
|
|
134
|
+
reviewed: string;
|
|
135
|
+
jobId: number;
|
|
136
|
+
jobRef: string;
|
|
137
|
+
rating: number;
|
|
138
|
+
categoryQuality: number;
|
|
139
|
+
categoryReliability: number;
|
|
140
|
+
categoryCommunication: number;
|
|
141
|
+
commentUri: string;
|
|
142
|
+
commentHash: string;
|
|
143
|
+
timestamp: number;
|
|
144
|
+
hasResponse: boolean;
|
|
145
|
+
responseUri: string | null;
|
|
146
|
+
responseHash: string | null;
|
|
147
|
+
responseTimestamp: number | null;
|
|
148
|
+
bump: number;
|
|
149
|
+
pda: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export class SATPSDK {
|
|
153
|
+
network: Network;
|
|
154
|
+
rpcUrl: string;
|
|
155
|
+
commitment: string;
|
|
156
|
+
connection: Connection;
|
|
157
|
+
programIds: V2ProgramIds;
|
|
158
|
+
|
|
159
|
+
constructor(opts?: SATSDKOptions);
|
|
160
|
+
|
|
161
|
+
// Identity
|
|
162
|
+
buildCreateIdentity(wallet: PublicKey | string, agentName: string, metadata: string | object): Promise<{ transaction: Transaction; identityPDA: PublicKey }>;
|
|
163
|
+
createIdentity(signer: any, agentName: string, metadata: string | object): Promise<string>;
|
|
164
|
+
getIdentity(wallet: PublicKey | string): Promise<V2Identity | null>;
|
|
165
|
+
|
|
166
|
+
// Reputation
|
|
167
|
+
buildRecomputeReputation(agentWallet: PublicKey | string, payer: PublicKey | string): Promise<{ transaction: Transaction }>;
|
|
168
|
+
recomputeReputation(signerKeypair: any, agentWallet: PublicKey | string): Promise<string>;
|
|
169
|
+
getReputation(wallet: PublicKey | string): Promise<{ owner: string; agentName: string; reputationScore: number; verificationLevel: number; pda: string } | null>;
|
|
170
|
+
|
|
171
|
+
// Validation
|
|
172
|
+
buildRecomputeLevel(agentWallet: PublicKey | string, payer: PublicKey | string): Promise<{ transaction: Transaction }>;
|
|
173
|
+
recomputeLevel(signerKeypair: any, agentWallet: PublicKey | string): Promise<string>;
|
|
174
|
+
|
|
175
|
+
// MintTracker
|
|
176
|
+
buildInitMintTracker(wallet: PublicKey | string): Promise<{ transaction: Transaction; mintTrackerPDA: PublicKey }>;
|
|
177
|
+
|
|
178
|
+
// Escrow
|
|
179
|
+
buildCreateEscrow(clientWallet: PublicKey | string, agentWallet: PublicKey | string, amountLamports: number, description: string, deadlineUnix: number): Promise<{ transaction: Transaction; escrowPDA: PublicKey; descriptionHash: Buffer }>;
|
|
180
|
+
buildRelease(clientWallet: PublicKey | string, agentWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
|
|
181
|
+
buildSubmitWork(agentWallet: PublicKey | string, escrowPDA: PublicKey | string, workProof: string): Promise<{ transaction: Transaction; workHash: Buffer }>;
|
|
182
|
+
buildCancel(clientWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
|
|
183
|
+
buildRaiseDispute(signerWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
|
|
184
|
+
buildCloseEscrow(clientWallet: PublicKey | string, escrowPDA: PublicKey | string): Promise<{ transaction: Transaction }>;
|
|
185
|
+
buildResolveDispute(clientWallet: PublicKey | string, agentWallet: PublicKey | string, escrowPDA: PublicKey | string, releaseToAgent: boolean): Promise<{ transaction: Transaction }>;
|
|
186
|
+
getEscrow(escrowPDA: PublicKey | string): Promise<V2EscrowState | null>;
|
|
187
|
+
|
|
188
|
+
// Reviews V3 (job-scoped)
|
|
189
|
+
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 }>;
|
|
190
|
+
buildRespondToReview(responderWallet: PublicKey | string, reviewPDA: PublicKey | string, responseUri: string, responseHash: Buffer | string): Promise<{ transaction: Transaction }>;
|
|
191
|
+
getReview(reviewPDA: PublicKey | string): Promise<V2ReviewState | null>;
|
|
192
|
+
getReviewV3PDA(jobPDA: PublicKey | string, reviewer: PublicKey | string): [PublicKey, number];
|
|
193
|
+
|
|
194
|
+
// Verification
|
|
195
|
+
verifyAgent(wallet: PublicKey | string): Promise<boolean>;
|
|
196
|
+
|
|
197
|
+
// Utility
|
|
198
|
+
getPDAs(wallet: PublicKey | string): { identity: string; reviewCounter: string; mintTracker: string; reputationAuthority: string; validationAuthority: string };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ─── V3 SDK ──────────────────────────────────────────────
|
|
202
|
+
|
|
203
|
+
export { SATPV3SDK } from './v3-sdk';
|
|
204
|
+
|
|
205
|
+
// ─── V2 PDA Helpers ─────────────────────────────────────
|
|
206
|
+
|
|
207
|
+
export function getProgramIds(network?: Network): V2ProgramIds;
|
|
208
|
+
export function getIdentityPDA(wallet: PublicKey, network?: Network): [PublicKey, number];
|
|
209
|
+
export function getReputationAuthorityPDA(network?: Network): [PublicKey, number];
|
|
210
|
+
export function getValidationAuthorityPDA(network?: Network): [PublicKey, number];
|
|
211
|
+
export function getReviewCounterPDA(wallet: PublicKey, network?: Network): [PublicKey, number];
|
|
212
|
+
export function getMintTrackerPDA(identityPDA: PublicKey, network?: Network): [PublicKey, number];
|
|
213
|
+
export function getReviewsAuthorityPDA(network?: Network): [PublicKey, number];
|
|
214
|
+
export function getReviewPDA(reviewCounter: PublicKey, network?: Network): [PublicKey, number];
|
|
215
|
+
export function getReviewAttestationPDA(reviewPDA: PublicKey, attester: PublicKey, network?: Network): [PublicKey, number];
|
|
216
|
+
export function getEscrowPDA(client: PublicKey, descriptionHash: Buffer, network?: Network): [PublicKey, number];
|
|
217
|
+
export function getReviewV3PDA(jobPDA: PublicKey | string, reviewer: PublicKey | string, network?: Network): [PublicKey, number];
|
|
218
|
+
export function anchorDiscriminator(ixName: string): Buffer;
|
|
219
|
+
|
|
220
|
+
// ─── V3 PDA Helpers ─────────────────────────────────────
|
|
221
|
+
|
|
222
|
+
export { getV3ProgramIds, hashAgentId, hashName, getGenesisPDA, getV3ReputationAuthorityPDA, getV3ValidationAuthorityPDA, getV3MintTrackerPDA, getNameRegistryPDA, getLinkedWalletPDA, getV3ReviewPDA, getV3ReviewCounterPDA, getV3AttestationPDA, getV3EscrowPDA } from './v3-pda';
|
|
223
|
+
|
|
224
|
+
export function prepareIdentityAttestationRequest(
|
|
225
|
+
opts: IdentityAttestationRequestOptions
|
|
226
|
+
): IdentityAttestationRequest;
|
|
227
|
+
|
|
228
|
+
export const TRUST_PACKET_SCHEMA_VERSION: 'satp.trustPacket.v1';
|
|
229
|
+
|
|
230
|
+
export function buildSatpTrustPacket(
|
|
231
|
+
opts: IdentityAttestationRequestOptions
|
|
232
|
+
): SatpTrustPacket;
|
|
233
|
+
|
|
234
|
+
export function validateSatpTrustPacket(
|
|
235
|
+
packet: SatpTrustPacket | Record<string, unknown> | null | undefined
|
|
236
|
+
): SatpTrustPacketValidation;
|
|
237
|
+
|
|
238
|
+
// ─── Borsh Deserialization Helpers ──────────────────────
|
|
239
|
+
|
|
240
|
+
export {
|
|
241
|
+
BorshReader,
|
|
242
|
+
deserializeGenesisRecord,
|
|
243
|
+
deserializeLinkedWallet,
|
|
244
|
+
deserializeMintTracker,
|
|
245
|
+
deserializeNameRegistry,
|
|
246
|
+
deserializeReview,
|
|
247
|
+
deserializeReviewCounter,
|
|
248
|
+
deserializeAttestation,
|
|
249
|
+
deserializeEscrowV3,
|
|
250
|
+
deserializeAccount,
|
|
251
|
+
deserializeBatch,
|
|
252
|
+
getAccountDiscriminator,
|
|
253
|
+
accountDiscriminator,
|
|
254
|
+
isAccountType,
|
|
255
|
+
DISCRIMINATORS,
|
|
256
|
+
ParsedGenesisRecord,
|
|
257
|
+
ParsedLinkedWallet,
|
|
258
|
+
ParsedMintTracker,
|
|
259
|
+
ParsedNameRegistry,
|
|
260
|
+
ParsedReview,
|
|
261
|
+
ParsedReviewCounter,
|
|
262
|
+
ParsedAttestation,
|
|
263
|
+
ParsedEscrowV3,
|
|
264
|
+
AccountTypeName,
|
|
265
|
+
ParsedAccountData,
|
|
266
|
+
} from './borsh-reader';
|