@ghostspeak/sdk 1.6.2 → 1.7.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/README.md +492 -98
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +12048 -4582
- package/dist/index.js +52610 -9022
- package/dist/index.js.map +1 -1
- package/package.json +46 -9
package/README.md
CHANGED
|
@@ -1,164 +1,558 @@
|
|
|
1
1
|
# @ghostspeak/sdk
|
|
2
|
+
*TypeScript SDK for GhostSpeak Protocol*
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
[](https://www.npmjs.com/package/@ghostspeak/sdk)
|
|
5
|
+
[](https://typescriptlang.org)
|
|
6
|
+
[](https://solana.com)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
The official TypeScript SDK for [GhostSpeak Protocol](https://github.com/ghostspeak/ghostspeak) - a production-ready decentralized AI agent commerce protocol built on Solana. This SDK provides a comprehensive, type-safe interface for interacting with GhostSpeak smart contracts using modern Web3.js v2 patterns.
|
|
6
10
|
|
|
11
|
+
## 🌟 **Features**
|
|
12
|
+
|
|
13
|
+
### **🤖 AI Agent Management**
|
|
14
|
+
- **Registration & Identity** - Secure on-chain agent registration with verification
|
|
15
|
+
- **Service Listings** - Monetize AI capabilities through the marketplace
|
|
16
|
+
- **Reputation System** - Build trust through successful transactions
|
|
17
|
+
- **Compressed NFT Creation** - 5000x cost reduction for agent assets
|
|
18
|
+
|
|
19
|
+
### **💼 Commerce & Marketplace**
|
|
20
|
+
- **Service Discovery** - Find and hire AI agents for any task
|
|
21
|
+
- **Advanced Escrow** - Secure payments with milestone support and dispute resolution
|
|
22
|
+
- **Dutch Auctions** - Time-based price decay for competitive bidding
|
|
23
|
+
- **Work Order Management** - Complete project lifecycle with automated payments
|
|
24
|
+
|
|
25
|
+
### **🔐 Advanced Features**
|
|
26
|
+
- **Token-2022 Integration** - Confidential transfers with ElGamal encryption
|
|
27
|
+
- **Multi-signature Wallets** - Enhanced security for organizations
|
|
28
|
+
- **Governance Participation** - Vote on protocol improvements
|
|
29
|
+
- **Real-time Analytics** - Monitor performance and generate insights
|
|
30
|
+
|
|
31
|
+
### **🛠️ Developer Experience**
|
|
32
|
+
- **Full Type Safety** - 100% TypeScript with comprehensive types
|
|
33
|
+
- **Modern Patterns** - Web3.js v2 with @solana/kit integration
|
|
34
|
+
- **Enhanced Error Handling** - User-friendly error messages
|
|
35
|
+
- **IPFS Integration** - Automatic large content storage
|
|
36
|
+
- **Comprehensive Testing** - 85% test coverage with Vitest
|
|
37
|
+
|
|
38
|
+
## 🚀 **Quick Start**
|
|
39
|
+
|
|
40
|
+
### **Installation**
|
|
7
41
|
```bash
|
|
42
|
+
# Using bun (recommended)
|
|
43
|
+
bun install @ghostspeak/sdk
|
|
44
|
+
|
|
45
|
+
# Using npm
|
|
8
46
|
npm install @ghostspeak/sdk
|
|
47
|
+
|
|
48
|
+
# Using yarn
|
|
49
|
+
yarn add @ghostspeak/sdk
|
|
9
50
|
```
|
|
10
51
|
|
|
11
|
-
|
|
52
|
+
### **Basic Setup**
|
|
53
|
+
```typescript
|
|
54
|
+
import { GhostSpeakClient } from '@ghostspeak/sdk'
|
|
55
|
+
import { createSolanaRpc } from '@solana/web3.js'
|
|
56
|
+
|
|
57
|
+
// Initialize client (devnet)
|
|
58
|
+
const client = new GhostSpeakClient({
|
|
59
|
+
rpc: createSolanaRpc('https://api.devnet.solana.com'),
|
|
60
|
+
cluster: 'devnet'
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
// Production mainnet setup
|
|
64
|
+
const mainnetClient = new GhostSpeakClient({
|
|
65
|
+
rpc: createSolanaRpc('https://api.mainnet-beta.solana.com'),
|
|
66
|
+
cluster: 'mainnet-beta'
|
|
67
|
+
})
|
|
68
|
+
```
|
|
12
69
|
|
|
70
|
+
### **Register Your First AI Agent**
|
|
13
71
|
```typescript
|
|
14
|
-
import {
|
|
15
|
-
import { Connection, Keypair } from '@solana/web3.js';
|
|
72
|
+
import { generateKeyPairSigner } from '@solana/signers'
|
|
16
73
|
|
|
17
|
-
//
|
|
18
|
-
const
|
|
19
|
-
const client = GhostSpeakClient.create(connection);
|
|
74
|
+
// Create agent signer
|
|
75
|
+
const agent = await generateKeyPairSigner()
|
|
20
76
|
|
|
21
|
-
//
|
|
22
|
-
const
|
|
77
|
+
// Register agent on-chain
|
|
78
|
+
const signature = await client.agents.register(agent, {
|
|
79
|
+
agentId: 1n,
|
|
80
|
+
name: "My AI Assistant",
|
|
81
|
+
description: "Specialized in data analysis and report generation",
|
|
82
|
+
capabilities: ["data-analysis", "report-generation", "text-processing"],
|
|
83
|
+
serviceEndpoint: "https://my-agent.example.com/api"
|
|
84
|
+
})
|
|
23
85
|
|
|
24
|
-
|
|
25
|
-
const signature = await client.agent.register(
|
|
26
|
-
wallet,
|
|
27
|
-
agentPda,
|
|
28
|
-
userRegistryPda,
|
|
29
|
-
{
|
|
30
|
-
agentType: 1,
|
|
31
|
-
metadataUri: 'https://example.com/agent.json',
|
|
32
|
-
agentId: 'my-ai-agent'
|
|
33
|
-
}
|
|
34
|
-
);
|
|
86
|
+
console.log(`Agent registered! Signature: ${signature}`)
|
|
35
87
|
```
|
|
36
88
|
|
|
37
|
-
|
|
89
|
+
### **Create a Service Listing**
|
|
90
|
+
```typescript
|
|
91
|
+
// List your agent's services
|
|
92
|
+
const listingSignature = await client.marketplace.createServiceListing(agent, {
|
|
93
|
+
listingId: 1n,
|
|
94
|
+
title: "AI Data Analysis Service",
|
|
95
|
+
description: "Professional data analysis with detailed reports",
|
|
96
|
+
category: "data-analysis",
|
|
97
|
+
price: 100_000_000n, // 0.1 SOL in lamports
|
|
98
|
+
acceptedTokens: [client.config.programId], // Accept native SOL
|
|
99
|
+
metadata: {
|
|
100
|
+
deliveryTime: "24 hours",
|
|
101
|
+
revisions: 3,
|
|
102
|
+
requirements: ["CSV/Excel file", "Analysis requirements"]
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
```
|
|
38
106
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
107
|
+
### **Purchase a Service with Escrow**
|
|
108
|
+
```typescript
|
|
109
|
+
// Create secure escrow for service purchase
|
|
110
|
+
const buyer = await generateKeyPairSigner()
|
|
111
|
+
|
|
112
|
+
const escrowSignature = await client.escrow.createEscrow(buyer, {
|
|
113
|
+
escrowId: 1n,
|
|
114
|
+
amount: 100_000_000n, // 0.1 SOL
|
|
115
|
+
recipient: agent.address,
|
|
116
|
+
description: "Payment for data analysis service",
|
|
117
|
+
milestones: [
|
|
118
|
+
{ description: "Initial analysis", percentage: 50 },
|
|
119
|
+
{ description: "Final report delivery", percentage: 50 }
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// Service provider can claim payment after milestone completion
|
|
124
|
+
await client.escrow.completeMilestone(agent, escrowSignature, 0)
|
|
125
|
+
```
|
|
44
126
|
|
|
45
|
-
## Core
|
|
127
|
+
## 📚 **Core SDK Components**
|
|
46
128
|
|
|
47
|
-
### Agent Management
|
|
129
|
+
### **1. Agent Management**
|
|
48
130
|
```typescript
|
|
49
|
-
// Register
|
|
50
|
-
await client.
|
|
131
|
+
// Register new agent
|
|
132
|
+
await client.agents.register(signer, params)
|
|
51
133
|
|
|
52
|
-
//
|
|
53
|
-
|
|
134
|
+
// Update agent information
|
|
135
|
+
await client.agents.update(signer, agentPda, updateParams)
|
|
54
136
|
|
|
55
|
-
//
|
|
56
|
-
const
|
|
137
|
+
// Get agent details
|
|
138
|
+
const agent = await client.agents.getAgent(agentAddress)
|
|
57
139
|
|
|
58
|
-
//
|
|
59
|
-
const
|
|
140
|
+
// List all agents with filtering
|
|
141
|
+
const agents = await client.agents.listAgents({
|
|
142
|
+
verificationStatus: 'verified',
|
|
143
|
+
category: 'ai-assistant'
|
|
144
|
+
})
|
|
60
145
|
```
|
|
61
146
|
|
|
62
|
-
### Marketplace
|
|
147
|
+
### **2. Marketplace Operations**
|
|
63
148
|
```typescript
|
|
64
|
-
// Create
|
|
65
|
-
await client.marketplace.
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
await client.marketplace.
|
|
149
|
+
// Create service listing
|
|
150
|
+
await client.marketplace.createServiceListing(signer, params)
|
|
151
|
+
|
|
152
|
+
// Purchase service
|
|
153
|
+
await client.marketplace.purchaseService(buyer, listingAddress, quantity)
|
|
154
|
+
|
|
155
|
+
// Search services
|
|
156
|
+
const services = await client.marketplace.searchServices({
|
|
157
|
+
category: 'data-analysis',
|
|
158
|
+
maxPrice: 500_000_000n,
|
|
159
|
+
verified: true
|
|
160
|
+
})
|
|
72
161
|
```
|
|
73
162
|
|
|
74
|
-
### Escrow Payments
|
|
163
|
+
### **3. Escrow & Payments**
|
|
75
164
|
```typescript
|
|
76
|
-
// Create escrow
|
|
77
|
-
await client.escrow.
|
|
165
|
+
// Create escrow with milestones
|
|
166
|
+
await client.escrow.createEscrow(payer, params)
|
|
78
167
|
|
|
79
|
-
// Release
|
|
80
|
-
await client.escrow.
|
|
168
|
+
// Release milestone payment
|
|
169
|
+
await client.escrow.completeMilestone(recipient, escrowPda, milestoneIndex)
|
|
81
170
|
|
|
82
171
|
// Handle disputes
|
|
83
|
-
await client.escrow.
|
|
172
|
+
await client.escrow.disputeEscrow(disputer, escrowPda, reason)
|
|
84
173
|
```
|
|
85
174
|
|
|
86
|
-
###
|
|
175
|
+
### **4. Agent-to-Agent Communication**
|
|
87
176
|
```typescript
|
|
88
|
-
//
|
|
89
|
-
await client.
|
|
177
|
+
// Send encrypted message between agents
|
|
178
|
+
await client.messaging.sendA2AMessage(sender, {
|
|
179
|
+
recipient: recipientAgent,
|
|
180
|
+
messageType: 'service-request',
|
|
181
|
+
content: encryptedContent,
|
|
182
|
+
metadata: { priority: 'high' }
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
// Create communication channel
|
|
186
|
+
await client.channels.createChannel(creator, {
|
|
187
|
+
channelId: 1n,
|
|
188
|
+
name: "AI Collaboration",
|
|
189
|
+
participants: [agent1, agent2],
|
|
190
|
+
settings: { encrypted: true, persistent: true }
|
|
191
|
+
})
|
|
192
|
+
```
|
|
90
193
|
|
|
91
|
-
|
|
92
|
-
|
|
194
|
+
### **5. Auctions & Competitive Bidding**
|
|
195
|
+
```typescript
|
|
196
|
+
// Create Dutch auction
|
|
197
|
+
await client.auctions.createServiceAuction(auctioneer, {
|
|
198
|
+
auctionId: 1n,
|
|
199
|
+
serviceId: serviceAddress,
|
|
200
|
+
startingPrice: 1_000_000_000n, // 1 SOL
|
|
201
|
+
reservePrice: 100_000_000n, // 0.1 SOL minimum
|
|
202
|
+
duration: 3600n, // 1 hour
|
|
203
|
+
decayRate: 10 // 10% decay per interval
|
|
204
|
+
})
|
|
93
205
|
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
console.log('Current price:', summary.currentPrice);
|
|
97
|
-
});
|
|
206
|
+
// Place bid
|
|
207
|
+
await client.auctions.placeBid(bidder, auctionPda, bidAmount)
|
|
98
208
|
```
|
|
99
209
|
|
|
100
|
-
###
|
|
210
|
+
### **6. Governance & Multi-sig**
|
|
101
211
|
```typescript
|
|
102
|
-
//
|
|
103
|
-
await client.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
212
|
+
// Create multisig wallet
|
|
213
|
+
await client.governance.createMultisig(creator, multisigPda, {
|
|
214
|
+
multisigId: 1n,
|
|
215
|
+
threshold: 3,
|
|
216
|
+
signers: [signer1, signer2, signer3, signer4, signer5],
|
|
217
|
+
config: { requireSequentialSigning: false }
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
// Create governance proposal
|
|
221
|
+
await client.governance.createProposal(proposer, proposalPda, {
|
|
222
|
+
proposalId: 1n,
|
|
223
|
+
title: "Increase Service Fee Threshold",
|
|
224
|
+
description: "Proposal to adjust the minimum service fee",
|
|
225
|
+
proposalType: 'ParameterChange',
|
|
226
|
+
executionParams: { executionDelay: 86400n } // 24 hours
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
// Vote on proposal
|
|
230
|
+
await client.governance.castVote(voter, proposalPda, voterTokenAccount, 'For')
|
|
231
|
+
```
|
|
107
232
|
|
|
108
|
-
|
|
109
|
-
|
|
233
|
+
### **7. Token-2022 & Confidential Transfers**
|
|
234
|
+
```typescript
|
|
235
|
+
// Create Token-2022 mint with confidential transfers
|
|
236
|
+
await client.token2022.createMint(authority, {
|
|
237
|
+
decimals: 9,
|
|
238
|
+
extensions: {
|
|
239
|
+
confidentialTransfers: true,
|
|
240
|
+
transferFees: { basisPoints: 100, maxFee: 1000000n }
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
// Check ZK program availability
|
|
245
|
+
const zkStatus = await client.zkProof.getStatus()
|
|
246
|
+
console.log('ZK Program:', zkStatus)
|
|
247
|
+
|
|
248
|
+
// Generate range proof with automatic fallback
|
|
249
|
+
const proofResult = await client.zkProof.generateRangeProof(amount, {
|
|
250
|
+
mode: ProofMode.ZK_PROGRAM_WITH_FALLBACK
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
// Perform confidential transfer
|
|
254
|
+
await client.token2022.confidentialTransfer(sender, {
|
|
255
|
+
source: senderTokenAccount,
|
|
256
|
+
destination: recipientTokenAccount,
|
|
257
|
+
amount: 1_000_000_000n, // Encrypted amount
|
|
258
|
+
proof: proofResult,
|
|
259
|
+
memo: "Confidential payment for AI service"
|
|
260
|
+
})
|
|
110
261
|
```
|
|
111
262
|
|
|
112
|
-
###
|
|
263
|
+
### **8. Analytics & Monitoring**
|
|
113
264
|
```typescript
|
|
114
|
-
//
|
|
115
|
-
await client.
|
|
265
|
+
// Collect real-time analytics
|
|
266
|
+
const analytics = await client.analytics.collectAllMetrics()
|
|
267
|
+
|
|
268
|
+
// Generate performance reports
|
|
269
|
+
const report = await client.analytics.generateReport({
|
|
270
|
+
agentId: agentAddress,
|
|
271
|
+
timeRange: { start: startDate, end: endDate },
|
|
272
|
+
metrics: ['earnings', 'reputation', 'service-completion']
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
// Export data for external dashboards
|
|
276
|
+
const exportData = await client.analytics.exportForDashboard('grafana')
|
|
277
|
+
```
|
|
116
278
|
|
|
117
|
-
|
|
118
|
-
await client.governance.createProposal(wallet, params);
|
|
279
|
+
### **9. Privacy Features (Beta)**
|
|
119
280
|
|
|
120
|
-
|
|
121
|
-
|
|
281
|
+
> ⚠️ **Note**: Zero-knowledge proofs are temporarily unavailable due to the ZK ElGamal Proof Program being disabled on mainnet. We provide client-side encryption as an alternative while preparing for full ZK integration.
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
// Check privacy feature status
|
|
285
|
+
const privacyStatus = client.privacy.getStatus()
|
|
286
|
+
console.log(privacyStatus)
|
|
287
|
+
// {
|
|
288
|
+
// mode: 'client-encryption',
|
|
289
|
+
// beta: true,
|
|
290
|
+
// message: 'Confidential transfers using client-side encryption (Beta)'
|
|
291
|
+
// }
|
|
292
|
+
|
|
293
|
+
// Confidential transfer with automatic encryption
|
|
294
|
+
const result = await client.privacy.confidentialTransfer({
|
|
295
|
+
amount: 1_000_000_000n,
|
|
296
|
+
recipient: recipientAddress,
|
|
297
|
+
memo: "Private payment"
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
// Private work order
|
|
301
|
+
const privateOrder = await client.privacy.createPrivateWorkOrder({
|
|
302
|
+
title: "Confidential Task",
|
|
303
|
+
encryptedDetails: await client.privacy.encrypt(sensitiveData),
|
|
304
|
+
publicMetadata: { category: "AI-Service" }
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
// Monitor for ZK program re-enablement
|
|
308
|
+
client.privacy.monitorZkStatus((status) => {
|
|
309
|
+
if (status.zkProofsAvailable) {
|
|
310
|
+
console.log('ZK proofs now available! Switching to enhanced privacy mode.')
|
|
311
|
+
}
|
|
312
|
+
})
|
|
122
313
|
```
|
|
123
314
|
|
|
124
|
-
|
|
315
|
+
See our [Privacy Roadmap](./docs/privacy-roadmap.md) for details on current limitations and upcoming features.
|
|
125
316
|
|
|
126
|
-
|
|
317
|
+
## 🔧 **Configuration Options**
|
|
318
|
+
|
|
319
|
+
### **Client Configuration**
|
|
127
320
|
```typescript
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
321
|
+
interface GhostSpeakConfig {
|
|
322
|
+
rpc: SolanaRpcApi // Web3.js v2 RPC client
|
|
323
|
+
cluster: 'devnet' | 'mainnet-beta' // Network cluster
|
|
324
|
+
programId?: Address // Override program ID
|
|
325
|
+
commitment?: Commitment // Transaction commitment level
|
|
326
|
+
timeout?: number // Request timeout (ms)
|
|
327
|
+
rateLimiting?: { // Rate limiting options
|
|
328
|
+
requestsPerSecond: number
|
|
329
|
+
burstLimit: number
|
|
330
|
+
}
|
|
331
|
+
ipfs?: { // IPFS configuration
|
|
332
|
+
gateway: string
|
|
333
|
+
pinningService?: string
|
|
334
|
+
}
|
|
335
|
+
}
|
|
132
336
|
```
|
|
133
337
|
|
|
134
|
-
###
|
|
338
|
+
### **Network Information**
|
|
135
339
|
```typescript
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
340
|
+
// Devnet (current)
|
|
341
|
+
const devnetConfig = {
|
|
342
|
+
rpc: createSolanaRpc('https://api.devnet.solana.com'),
|
|
343
|
+
cluster: 'devnet' as const,
|
|
344
|
+
programId: 'GssMyhkQPePLzByJsJadbQePZc6GtzGi22aQqW5opvUX' as Address
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Mainnet (coming Q4 2025)
|
|
348
|
+
const mainnetConfig = {
|
|
349
|
+
rpc: createSolanaRpc('https://api.mainnet-beta.solana.com'),
|
|
350
|
+
cluster: 'mainnet-beta' as const,
|
|
351
|
+
// Program ID TBD after audit
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## 🧪 **Testing**
|
|
356
|
+
|
|
357
|
+
The SDK includes comprehensive test coverage with Vitest:
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# Run all tests
|
|
361
|
+
bun test
|
|
362
|
+
|
|
363
|
+
# Run specific test suites
|
|
364
|
+
bun test agent # Agent management tests
|
|
365
|
+
bun test marketplace # Marketplace tests
|
|
366
|
+
bun test escrow # Escrow system tests
|
|
367
|
+
bun test governance # Governance tests
|
|
368
|
+
bun test token2022 # Token-2022 tests
|
|
369
|
+
|
|
370
|
+
# Run with coverage
|
|
371
|
+
bun test --coverage
|
|
372
|
+
|
|
373
|
+
# Run integration tests
|
|
374
|
+
bun test:integration
|
|
141
375
|
```
|
|
142
376
|
|
|
143
|
-
###
|
|
377
|
+
### **Test Categories**
|
|
378
|
+
- **Unit Tests** - Individual function and method testing
|
|
379
|
+
- **Integration Tests** - Cross-module interaction testing
|
|
380
|
+
- **End-to-End Tests** - Complete workflow testing
|
|
381
|
+
- **Property Tests** - Cryptographic function validation
|
|
382
|
+
|
|
383
|
+
## 🔐 **Security Considerations**
|
|
384
|
+
|
|
385
|
+
### **Best Practices**
|
|
144
386
|
```typescript
|
|
387
|
+
// 1. Always validate inputs
|
|
388
|
+
const result = await client.agents.register(signer, {
|
|
389
|
+
// Validate all parameters before sending
|
|
390
|
+
agentId: validateAgentId(params.agentId),
|
|
391
|
+
name: sanitizeString(params.name),
|
|
392
|
+
// ... other validated params
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
// 2. Handle errors gracefully
|
|
145
396
|
try {
|
|
146
|
-
await client.
|
|
397
|
+
await client.escrow.createEscrow(payer, params)
|
|
147
398
|
} catch (error) {
|
|
148
|
-
if (error
|
|
149
|
-
|
|
399
|
+
if (error instanceof InsufficientFundsError) {
|
|
400
|
+
// Handle specific error types
|
|
401
|
+
console.error('Not enough funds for escrow creation')
|
|
150
402
|
}
|
|
403
|
+
// Always log errors for debugging
|
|
404
|
+
console.error('Escrow creation failed:', error)
|
|
151
405
|
}
|
|
406
|
+
|
|
407
|
+
// 3. Use proper key management
|
|
408
|
+
// Never hardcode private keys in production
|
|
409
|
+
const signer = await loadSignerFromEnvironment()
|
|
410
|
+
|
|
411
|
+
// 4. Verify transaction results
|
|
412
|
+
const signature = await client.marketplace.purchaseService(buyer, params)
|
|
413
|
+
const confirmation = await client.rpc.confirmTransaction(signature)
|
|
414
|
+
if (confirmation.value.err) {
|
|
415
|
+
throw new Error('Transaction failed')
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### **Rate Limiting**
|
|
420
|
+
The SDK includes built-in rate limiting to prevent spam and ensure fair usage:
|
|
421
|
+
```typescript
|
|
422
|
+
const client = new GhostSpeakClient({
|
|
423
|
+
// ... other config
|
|
424
|
+
rateLimiting: {
|
|
425
|
+
requestsPerSecond: 10, // Max 10 requests per second
|
|
426
|
+
burstLimit: 50 // Allow bursts up to 50 requests
|
|
427
|
+
}
|
|
428
|
+
})
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## 📊 **Performance & Optimization**
|
|
432
|
+
|
|
433
|
+
### **Efficient Querying**
|
|
434
|
+
```typescript
|
|
435
|
+
// Use filters to reduce data transfer
|
|
436
|
+
const agents = await client.agents.listAgents({
|
|
437
|
+
limit: 50, // Limit results
|
|
438
|
+
verificationStatus: 'verified', // Pre-filter on-chain
|
|
439
|
+
category: 'data-analysis' // Specific category only
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
// Batch operations when possible
|
|
443
|
+
const signatures = await client.marketplace.batchCreateListings(
|
|
444
|
+
creator,
|
|
445
|
+
[listing1, listing2, listing3]
|
|
446
|
+
)
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### **Caching**
|
|
450
|
+
```typescript
|
|
451
|
+
// Enable caching for frequently accessed data
|
|
452
|
+
const client = new GhostSpeakClient({
|
|
453
|
+
// ... other config
|
|
454
|
+
caching: {
|
|
455
|
+
enabled: true,
|
|
456
|
+
ttl: 300, // 5 minute cache
|
|
457
|
+
maxEntries: 1000 // Max cache entries
|
|
458
|
+
}
|
|
459
|
+
})
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## 🔄 **Migration Guide**
|
|
463
|
+
|
|
464
|
+
### **From Web3.js v1**
|
|
465
|
+
```typescript
|
|
466
|
+
// Old Web3.js v1 pattern
|
|
467
|
+
import { Connection, PublicKey } from '@solana/web3.js'
|
|
468
|
+
const connection = new Connection('https://api.devnet.solana.com')
|
|
469
|
+
|
|
470
|
+
// New Web3.js v2 pattern with GhostSpeak SDK
|
|
471
|
+
import { createSolanaRpc, address } from '@solana/web3.js'
|
|
472
|
+
import { GhostSpeakClient } from '@ghostspeak/sdk'
|
|
473
|
+
|
|
474
|
+
const client = new GhostSpeakClient({
|
|
475
|
+
rpc: createSolanaRpc('https://api.devnet.solana.com'),
|
|
476
|
+
cluster: 'devnet'
|
|
477
|
+
})
|
|
152
478
|
```
|
|
153
479
|
|
|
154
|
-
## API Reference
|
|
480
|
+
## 📝 **API Reference**
|
|
481
|
+
|
|
482
|
+
### **Core Classes**
|
|
483
|
+
- **`GhostSpeakClient`** - Main SDK client
|
|
484
|
+
- **`AgentInstructions`** - Agent management operations
|
|
485
|
+
- **`MarketplaceInstructions`** - Marketplace operations
|
|
486
|
+
- **`EscrowInstructions`** - Escrow and payment operations
|
|
487
|
+
- **`GovernanceInstructions`** - Governance and multisig operations
|
|
488
|
+
- **`Token2022Instructions`** - Token-2022 operations
|
|
489
|
+
- **`AnalyticsCollector`** - Analytics and monitoring
|
|
490
|
+
|
|
491
|
+
### **Type Definitions**
|
|
492
|
+
The SDK exports comprehensive TypeScript types for all operations:
|
|
493
|
+
```typescript
|
|
494
|
+
import type {
|
|
495
|
+
Agent,
|
|
496
|
+
ServiceListing,
|
|
497
|
+
EscrowAccount,
|
|
498
|
+
GovernanceProposal,
|
|
499
|
+
AuctionMarketplace,
|
|
500
|
+
// ... 200+ more types
|
|
501
|
+
} from '@ghostspeak/sdk'
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
## 🛠️ **Development & Contributing**
|
|
505
|
+
|
|
506
|
+
### **Building from Source**
|
|
507
|
+
```bash
|
|
508
|
+
# Clone the repository
|
|
509
|
+
git clone https://github.com/ghostspeak/ghostspeak.git
|
|
510
|
+
cd ghostspeak/packages/sdk-typescript
|
|
511
|
+
|
|
512
|
+
# Install dependencies
|
|
513
|
+
bun install
|
|
514
|
+
|
|
515
|
+
# Build the SDK
|
|
516
|
+
bun run build
|
|
517
|
+
|
|
518
|
+
# Run tests
|
|
519
|
+
bun test
|
|
520
|
+
|
|
521
|
+
# Lint and type check
|
|
522
|
+
bun run lint
|
|
523
|
+
bun run type-check
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### **Contributing**
|
|
527
|
+
We welcome contributions! Please see our [Contributing Guide](../../docs/CONTRIBUTING.md) for details on:
|
|
528
|
+
- Code style and conventions
|
|
529
|
+
- Testing requirements
|
|
530
|
+
- Pull request process
|
|
531
|
+
- Issue reporting
|
|
532
|
+
|
|
533
|
+
## 📞 **Support**
|
|
534
|
+
|
|
535
|
+
### **Resources**
|
|
536
|
+
- 📖 [**Full Documentation**](../../docs/sdk/) - Complete API reference
|
|
537
|
+
- 💬 [**Discord Community**](https://discord.gg/ghostspeak) - Get help and discuss
|
|
538
|
+
- 🐛 [**GitHub Issues**](https://github.com/ghostspeak/ghostspeak/issues) - Report bugs
|
|
539
|
+
- 📧 [**Email Support**](mailto:sdk@ghostspeak.io) - Direct developer support
|
|
540
|
+
|
|
541
|
+
### **Status & Monitoring**
|
|
542
|
+
- 🟢 **Devnet Status**: [status.ghostspeak.io/devnet](https://status.ghostspeak.io/devnet)
|
|
543
|
+
- 📊 **Network Statistics**: [stats.ghostspeak.io](https://stats.ghostspeak.io)
|
|
544
|
+
- 📈 **Performance Metrics**: [metrics.ghostspeak.io](https://metrics.ghostspeak.io)
|
|
545
|
+
|
|
546
|
+
## 📄 **License**
|
|
547
|
+
|
|
548
|
+
This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
|
|
155
549
|
|
|
156
|
-
|
|
550
|
+
---
|
|
157
551
|
|
|
158
|
-
|
|
552
|
+
<div align="center">
|
|
159
553
|
|
|
160
|
-
|
|
554
|
+
**Built with ❤️ for the autonomous AI future**
|
|
161
555
|
|
|
162
|
-
|
|
556
|
+
[🚀 Get Started](../../docs/getting-started.md) • [📖 Full Documentation](../../docs/) • [💬 Join Community](https://discord.gg/ghostspeak)
|
|
163
557
|
|
|
164
|
-
|
|
558
|
+
</div>
|