@ghostspeak/sdk 2.0.5 → 2.0.7
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 +152 -30
- package/dist/GhostSpeakClient-CWmGaM9Q.d.ts +1007 -0
- package/dist/StakingModule-C5rzuOWb.d.ts +2526 -0
- package/dist/{agent-M74TCRON.js → agent-5YLZ7DAC.js} +4 -4
- package/dist/{agent-M74TCRON.js.map → agent-5YLZ7DAC.js.map} +1 -1
- package/dist/batch-operations-45CQFEID.js +4 -0
- package/dist/batch-operations-45CQFEID.js.map +1 -0
- package/dist/browser.d.ts +45 -554
- package/dist/browser.js +15 -842
- package/dist/browser.js.map +1 -1
- package/dist/chunk-AL3HQN73.js +754 -0
- package/dist/chunk-AL3HQN73.js.map +1 -0
- package/dist/chunk-BF3IQ35I.js +284 -0
- package/dist/chunk-BF3IQ35I.js.map +1 -0
- package/dist/chunk-BQDGRTVP.js +168 -0
- package/dist/chunk-BQDGRTVP.js.map +1 -0
- package/dist/chunk-C5CDA3WX.js +7314 -0
- package/dist/chunk-C5CDA3WX.js.map +1 -0
- package/dist/chunk-E3FD2CNY.js +1869 -0
- package/dist/chunk-E3FD2CNY.js.map +1 -0
- package/dist/{chunk-V3SOFUAZ.js → chunk-G7S6B6WB.js} +327 -493
- package/dist/chunk-G7S6B6WB.js.map +1 -0
- package/dist/chunk-IHVDQ4YI.js +4231 -0
- package/dist/chunk-IHVDQ4YI.js.map +1 -0
- package/dist/chunk-JV2SWONF.js +98 -0
- package/dist/chunk-JV2SWONF.js.map +1 -0
- package/dist/chunk-KB6CKIUK.js +231 -0
- package/dist/chunk-KB6CKIUK.js.map +1 -0
- package/dist/chunk-RIZZPLLB.js +343 -0
- package/dist/chunk-RIZZPLLB.js.map +1 -0
- package/dist/chunk-S74EH3KD.js +7890 -0
- package/dist/chunk-S74EH3KD.js.map +1 -0
- package/dist/chunk-SFTSZ3LC.js +156 -0
- package/dist/chunk-SFTSZ3LC.js.map +1 -0
- package/dist/chunk-SKMJJ3Q6.js +125 -0
- package/dist/chunk-SKMJJ3Q6.js.map +1 -0
- package/dist/chunk-SZGFSCNU.js +3682 -0
- package/dist/chunk-SZGFSCNU.js.map +1 -0
- package/dist/chunk-TTB4OS2D.js +69 -0
- package/dist/chunk-TTB4OS2D.js.map +1 -0
- package/dist/chunk-UP2VWCW5.js +33 -0
- package/dist/{chunk-NSBPE2FW.js.map → chunk-UP2VWCW5.js.map} +1 -1
- package/dist/{chunk-UJUGGLMT.js → chunk-VQZQCHUT.js} +5 -5
- package/dist/{chunk-UJUGGLMT.js.map → chunk-VQZQCHUT.js.map} +1 -1
- package/dist/client.d.ts +6 -4
- package/dist/client.js +12 -10
- package/dist/createAgentAuthorization-ULG47ZJI.js +5 -0
- package/dist/createAgentAuthorization-ULG47ZJI.js.map +1 -0
- package/dist/credentials.d.ts +155 -0
- package/dist/credentials.js +4 -0
- package/dist/credentials.js.map +1 -0
- package/dist/crypto.js +2 -2
- package/dist/errors.js +1 -1
- package/dist/feature-flags-B1g0DCPe.d.ts +1181 -0
- package/dist/generated-EG5USUFG.js +9 -0
- package/dist/{generated-VNLHMR6Y.js.map → generated-EG5USUFG.js.map} +1 -1
- package/dist/{ghostspeak_wasm-SB2RPJ3D.js → ghostspeak_wasm-F227HOSM.js} +3 -3
- package/dist/{ghostspeak_wasm-SB2RPJ3D.js.map → ghostspeak_wasm-F227HOSM.js.map} +1 -1
- package/dist/index.d.ts +1210 -1506
- package/dist/index.js +601 -3532
- package/dist/index.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/minimal/core-minimal.d.ts +2383 -1264
- package/dist/minimal/core-minimal.js +9 -9
- package/dist/minimal/core-minimal.js.map +1 -1
- package/dist/nacl-fast-W5BJ3KZ2.js +2229 -0
- package/dist/nacl-fast-W5BJ3KZ2.js.map +1 -0
- package/dist/pda-4KP7CURF.js +4 -0
- package/dist/pda-4KP7CURF.js.map +1 -0
- package/dist/pda-Ce7VYg4T.d.ts +25 -0
- package/dist/reputation-types-Yebf0Rm_.d.ts +1071 -0
- package/dist/revokeAuthorization-OK7E7OK3.js +5 -0
- package/dist/revokeAuthorization-OK7E7OK3.js.map +1 -0
- package/dist/signature-verification-DGxR4aYQ.d.ts +448 -0
- package/dist/types.js +1 -1
- package/dist/updateReputationWithAuth-Y4ONEVSP.js +5 -0
- package/dist/updateReputationWithAuth-Y4ONEVSP.js.map +1 -0
- package/dist/utils.d.ts +69 -203
- package/dist/utils.js +15 -153
- package/dist/utils.js.map +1 -1
- package/package.json +28 -31
- package/dist/.tsbuildinfo +0 -1
- package/dist/GhostSpeakClient-hsGuGg__.d.ts +0 -860
- package/dist/GovernanceModule-DQYYys-H.d.ts +0 -1766
- package/dist/chunk-ASQXX4IT.js +0 -572
- package/dist/chunk-ASQXX4IT.js.map +0 -1
- package/dist/chunk-COGZFWOT.js +0 -19657
- package/dist/chunk-COGZFWOT.js.map +0 -1
- package/dist/chunk-FKRN4PW5.js +0 -1667
- package/dist/chunk-FKRN4PW5.js.map +0 -1
- package/dist/chunk-GMHIUK2R.js +0 -7526
- package/dist/chunk-GMHIUK2R.js.map +0 -1
- package/dist/chunk-IAWBZYPE.js +0 -356
- package/dist/chunk-IAWBZYPE.js.map +0 -1
- package/dist/chunk-NSBPE2FW.js +0 -15
- package/dist/chunk-OWYHJG6H.js +0 -13311
- package/dist/chunk-OWYHJG6H.js.map +0 -1
- package/dist/chunk-RDDPOFR5.js +0 -3
- package/dist/chunk-RDDPOFR5.js.map +0 -1
- package/dist/chunk-RERCHKZP.js +0 -35
- package/dist/chunk-RERCHKZP.js.map +0 -1
- package/dist/chunk-TVVGXYCI.js +0 -2887
- package/dist/chunk-TVVGXYCI.js.map +0 -1
- package/dist/chunk-V3SOFUAZ.js.map +0 -1
- package/dist/chunk-ZGP5552B.js +0 -377
- package/dist/chunk-ZGP5552B.js.map +0 -1
- package/dist/chunk-ZWOYNHVK.js +0 -196
- package/dist/chunk-ZWOYNHVK.js.map +0 -1
- package/dist/dist/.tsbuildinfo +0 -1
- package/dist/elgamal-VZLWB3XK.js +0 -5
- package/dist/elgamal-VZLWB3XK.js.map +0 -1
- package/dist/feature-flags-V722ZuXO.d.ts +0 -3512
- package/dist/generated-VNLHMR6Y.js +0 -5
- package/dist/ipfs-types-BOt9ZNg4.d.ts +0 -592
- package/dist/multisigConfig-BzEhy6jy.d.ts +0 -58
- package/dist/pda-B_nS8SbD.d.ts +0 -114
- package/dist/pda-S4BFJVGE.js +0 -4
- package/dist/pda-S4BFJVGE.js.map +0 -1
- package/dist/system-addresses-BFNLEbFx.d.ts +0 -857
- package/dist/token-2022-rpc-RALH4RK7.js +0 -593
- package/dist/token-2022-rpc-RALH4RK7.js.map +0 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export { d as deriveAgentPda,
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
export { d as deriveAgentPda, f as findProgramDerivedAddress } from './pda-Ce7VYg4T.js';
|
|
2
|
+
export { E as ErrorContext, G as GhostSpeakSDKError, R as ReputationTagEngine, T as TokenProgram, j as accounts, c as createErrorContext, d as deriveAssociatedTokenAddress, a as detectTokenProgram, e as enhanceTransactionError, l as features, f as formatTokenAmount, g as getTokenProgramType, k as governance, b as ipfs, i as isToken2022Mint, p as parseTokenAmount, h as privacy, w as withEnhancedErrors } from './feature-flags-B1g0DCPe.js';
|
|
3
|
+
export { s as authSignatures, c as createAuthorizationMessage, b as createSignedAuthorization, e as deserializeAuthorization, g as generateNonce, f as getAuthorizationId, h as isAuthorizationExhausted, i as isAuthorizationExpired, d as serializeAuthorization, a as signAuthorizationMessage, j as validateAuthorizationNetwork, v as verifyAuthorizationSignature } from './signature-verification-DGxR4aYQ.js';
|
|
4
|
+
import { R as ReputationData, J as JobPerformance, a as ReputationCalculationResult, P as PerformanceSnapshot } from './reputation-types-Yebf0Rm_.js';
|
|
4
5
|
import '@solana/addresses';
|
|
5
6
|
import '@solana/kit';
|
|
6
|
-
import './ipfs-types-BOt9ZNg4.js';
|
|
7
|
-
import './multisigConfig-BzEhy6jy.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Common utility functions for GhostSpeak SDK
|
|
@@ -19,203 +18,70 @@ declare function sol(amount: number): bigint;
|
|
|
19
18
|
declare function lamportsToSol(lamports: bigint): number;
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
21
|
+
* Advanced reputation calculation engine
|
|
22
|
+
*/
|
|
23
|
+
declare class ReputationCalculator {
|
|
24
|
+
private fraudPatterns;
|
|
25
|
+
constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Initialize fraud detection patterns
|
|
28
|
+
*/
|
|
29
|
+
private initializeFraudPatterns;
|
|
30
|
+
/**
|
|
31
|
+
* Calculate reputation update based on job performance
|
|
32
|
+
*/
|
|
33
|
+
calculateReputation(currentData: ReputationData, jobPerformance: JobPerformance): ReputationCalculationResult;
|
|
34
|
+
/**
|
|
35
|
+
* Apply time-based reputation decay
|
|
36
|
+
*/
|
|
37
|
+
private applyTimeDecay;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate weighted score based on job performance
|
|
40
|
+
*/
|
|
41
|
+
private calculateWeightedScore;
|
|
42
|
+
/**
|
|
43
|
+
* Calculate timeliness score based on expected vs actual duration
|
|
44
|
+
*/
|
|
45
|
+
private calculateTimelinessScore;
|
|
46
|
+
/**
|
|
47
|
+
* Calculate dispute score
|
|
48
|
+
*/
|
|
49
|
+
private calculateDisputeScore;
|
|
50
|
+
/**
|
|
51
|
+
* Update category-specific reputation
|
|
52
|
+
*/
|
|
53
|
+
private updateCategoryReputation;
|
|
54
|
+
/**
|
|
55
|
+
* Calculate overall score from category reputations
|
|
56
|
+
*/
|
|
57
|
+
private calculateOverallScore;
|
|
58
|
+
/**
|
|
59
|
+
* Get reputation tier from score
|
|
60
|
+
*/
|
|
61
|
+
private getTierFromScore;
|
|
62
|
+
/**
|
|
63
|
+
* Check for badge achievements
|
|
64
|
+
*/
|
|
65
|
+
private checkBadgeAchievements;
|
|
66
|
+
/**
|
|
67
|
+
* Detect potential fraud patterns
|
|
68
|
+
*/
|
|
69
|
+
private detectFraud;
|
|
70
|
+
/**
|
|
71
|
+
* Create performance snapshot
|
|
72
|
+
*/
|
|
73
|
+
createPerformanceSnapshot(data: ReputationData, newScore: number): PerformanceSnapshot;
|
|
74
|
+
/**
|
|
75
|
+
* Calculate reputation slash amount
|
|
76
|
+
*/
|
|
77
|
+
calculateSlashAmount(currentScore: number, slashPercentage: number): {
|
|
78
|
+
newScore: number;
|
|
79
|
+
slashAmount: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Calculate staking bonus
|
|
83
|
+
*/
|
|
84
|
+
calculateStakingBonus(stakeAmount: number): number;
|
|
42
85
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Configuration options for agent status checks
|
|
45
|
-
*/
|
|
46
|
-
interface AgentStatusConfig {
|
|
47
|
-
/** Activity threshold in seconds (default: 30 days) */
|
|
48
|
-
activityThresholdSeconds?: number;
|
|
49
|
-
/** Current timestamp in seconds (default: Date.now() / 1000) */
|
|
50
|
-
currentTimestamp?: number;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Check if an agent is verified (has completed at least 1 paid x402 transaction)
|
|
54
|
-
*
|
|
55
|
-
* @param agent - Agent object with x402_total_calls field
|
|
56
|
-
* @returns true if agent has at least 1 x402 call
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const agent = await discoveryClient.getAgent(address)
|
|
61
|
-
* if (isAgentVerified(agent)) {
|
|
62
|
-
* console.log('Agent has completed paid work')
|
|
63
|
-
* }
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
declare function isAgentVerified(agent: Pick<Agent, 'x402_total_calls'>): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Check if an agent is active (received payment within threshold)
|
|
69
|
-
*
|
|
70
|
-
* @param agent - Agent object with x402_total_calls and last_payment_timestamp fields
|
|
71
|
-
* @param config - Optional configuration for thresholds
|
|
72
|
-
* @returns true if agent is verified AND has recent activity
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* const agent = await discoveryClient.getAgent(address)
|
|
77
|
-
* if (isAgentActive(agent)) {
|
|
78
|
-
* console.log('Agent is actively providing services')
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
declare function isAgentActive(agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>, config?: AgentStatusConfig): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Check if an agent is inactive (has payment history but no recent activity)
|
|
85
|
-
*
|
|
86
|
-
* @param agent - Agent object with x402_total_calls and last_payment_timestamp fields
|
|
87
|
-
* @param config - Optional configuration for thresholds
|
|
88
|
-
* @returns true if agent is verified but has not had recent activity
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const agent = await discoveryClient.getAgent(address)
|
|
93
|
-
* if (isAgentInactive(agent)) {
|
|
94
|
-
* console.log('Agent has gone dormant')
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
declare function isAgentInactive(agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>, config?: AgentStatusConfig): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Check if an agent is dead (alias for isAgentInactive for backwards compatibility)
|
|
101
|
-
*
|
|
102
|
-
* @deprecated Use isAgentInactive instead. "Dead" and "Inactive" are semantically identical.
|
|
103
|
-
*
|
|
104
|
-
* @param agent - Agent object with x402_total_calls and last_payment_timestamp fields
|
|
105
|
-
* @param config - Optional configuration for thresholds
|
|
106
|
-
* @returns true if agent is verified but has not had recent activity
|
|
107
|
-
*/
|
|
108
|
-
declare function isAgentDead(agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>, config?: AgentStatusConfig): boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Get the comprehensive status of an agent
|
|
111
|
-
*
|
|
112
|
-
* @param agent - Agent object with x402_total_calls and last_payment_timestamp fields
|
|
113
|
-
* @param config - Optional configuration for thresholds
|
|
114
|
-
* @returns AgentStatus enum value
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```typescript
|
|
118
|
-
* const agent = await discoveryClient.getAgent(address)
|
|
119
|
-
* const status = getAgentStatus(agent)
|
|
120
|
-
* switch (status) {
|
|
121
|
-
* case AgentStatus.Active:
|
|
122
|
-
* console.log('Agent is actively serving')
|
|
123
|
-
* break
|
|
124
|
-
* case AgentStatus.Inactive:
|
|
125
|
-
* console.log('Agent has gone dormant')
|
|
126
|
-
* break
|
|
127
|
-
* case AgentStatus.Unverified:
|
|
128
|
-
* console.log('Agent has not completed paid work')
|
|
129
|
-
* break
|
|
130
|
-
* }
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
declare function getAgentStatus(agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>, config?: AgentStatusConfig): AgentStatus;
|
|
134
|
-
/**
|
|
135
|
-
* Filter options for agent status filtering
|
|
136
|
-
*/
|
|
137
|
-
interface AgentStatusFilterOptions {
|
|
138
|
-
/** Exclude agents that have never completed an x402 transaction */
|
|
139
|
-
excludeUnverified?: boolean;
|
|
140
|
-
/** Exclude agents that have not been active within the threshold */
|
|
141
|
-
excludeInactive?: boolean;
|
|
142
|
-
/** Alias for excludeInactive for backwards compatibility */
|
|
143
|
-
excludeDead?: boolean;
|
|
144
|
-
/** Configuration for status checks */
|
|
145
|
-
config?: AgentStatusConfig;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Filter agents by their activity status
|
|
149
|
-
*
|
|
150
|
-
* @param agents - Array of agents to filter
|
|
151
|
-
* @param options - Filter options
|
|
152
|
-
* @returns Filtered array of agents
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* const allAgents = await discoveryClient.searchAgents()
|
|
157
|
-
* const activeAgents = filterAgentsByStatus(allAgents.agents, {
|
|
158
|
-
* excludeUnverified: true,
|
|
159
|
-
* excludeInactive: true
|
|
160
|
-
* })
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
declare function filterAgentsByStatus<T extends Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>>(agents: T[], options?: AgentStatusFilterOptions): T[];
|
|
164
|
-
/**
|
|
165
|
-
* Sort agents by their activity (most recently active first)
|
|
166
|
-
*
|
|
167
|
-
* @param agents - Array of agents to sort
|
|
168
|
-
* @returns Sorted array of agents (descending by last_payment_timestamp)
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* const agents = await discoveryClient.searchAgents()
|
|
173
|
-
* const sortedAgents = sortAgentsByActivity(agents.agents)
|
|
174
|
-
* // sortedAgents[0] is the agent with most recent last_payment_timestamp
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
declare function sortAgentsByActivity<T extends Pick<Agent, 'last_payment_timestamp'>>(agents: T[]): T[];
|
|
178
|
-
/**
|
|
179
|
-
* Get time since last payment in a human-readable format
|
|
180
|
-
*
|
|
181
|
-
* @param agent - Agent object with last_payment_timestamp field
|
|
182
|
-
* @param config - Optional configuration
|
|
183
|
-
* @returns Human-readable time string (e.g., "2 days ago", "1 month ago")
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```typescript
|
|
187
|
-
* const agent = await discoveryClient.getAgent(address)
|
|
188
|
-
* console.log(`Last active: ${getTimeSinceLastPayment(agent)}`)
|
|
189
|
-
* // Output: "Last active: 5 days ago"
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
declare function getTimeSinceLastPayment(agent: Pick<Agent, 'last_payment_timestamp'>, config?: AgentStatusConfig): string;
|
|
193
|
-
/**
|
|
194
|
-
* Summary statistics for a collection of agents
|
|
195
|
-
*/
|
|
196
|
-
interface AgentStatusSummary {
|
|
197
|
-
total: number;
|
|
198
|
-
verified: number;
|
|
199
|
-
active: number;
|
|
200
|
-
inactive: number;
|
|
201
|
-
unverified: number;
|
|
202
|
-
activePercentage: number;
|
|
203
|
-
verifiedPercentage: number;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get summary statistics for a collection of agents
|
|
207
|
-
*
|
|
208
|
-
* @param agents - Array of agents to summarize
|
|
209
|
-
* @param config - Optional configuration for status checks
|
|
210
|
-
* @returns Summary statistics object
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* ```typescript
|
|
214
|
-
* const allAgents = await discoveryClient.searchAgents()
|
|
215
|
-
* const summary = getAgentStatusSummary(allAgents.agents)
|
|
216
|
-
* console.log(`${summary.activePercentage}% of agents are active`)
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
declare function getAgentStatusSummary<T extends Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>>(agents: T[], config?: AgentStatusConfig): AgentStatusSummary;
|
|
220
86
|
|
|
221
|
-
export {
|
|
87
|
+
export { ReputationCalculator, lamportsToSol, sol };
|
package/dist/utils.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
export { account_diagnostics_exports as accounts, deriveAssociatedTokenAddress, detectTokenProgram, feature_flags_exports as features, formatTokenAmount, getTokenProgramType, isToken2022Mint, parseTokenAmount, client_encryption_exports as privacy
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import './chunk-
|
|
8
|
-
import './chunk-
|
|
1
|
+
export { account_diagnostics_exports as accounts, deriveAssociatedTokenAddress, detectTokenProgram, feature_flags_exports as features, formatTokenAmount, getTokenProgramType, governance_helpers_exports as governance, isToken2022Mint, parseTokenAmount, client_encryption_exports as privacy } from './chunk-G7S6B6WB.js';
|
|
2
|
+
export { deriveAgentPda, findProgramDerivedAddress } from './chunk-BF3IQ35I.js';
|
|
3
|
+
export { signature_verification_exports as authSignatures, createAuthorizationMessage, createSignedAuthorization, deserializeAuthorization, generateNonce, getAuthorizationId, isAuthorizationExhausted, isAuthorizationExpired, serializeAuthorization, signAuthorizationMessage, validateAuthorizationNetwork, verifyAuthorizationSignature } from './chunk-BQDGRTVP.js';
|
|
4
|
+
import { init_reputation_tag_engine } from './chunk-C5CDA3WX.js';
|
|
5
|
+
export { GhostSpeakSDKError, ReputationCalculator, ReputationTagEngine, createErrorContext, enhanceTransactionError, ipfs_client_exports as ipfs, withEnhancedErrors } from './chunk-C5CDA3WX.js';
|
|
6
|
+
import './chunk-S74EH3KD.js';
|
|
7
|
+
import './chunk-IHVDQ4YI.js';
|
|
8
|
+
import './chunk-SFTSZ3LC.js';
|
|
9
|
+
import './chunk-JV2SWONF.js';
|
|
10
|
+
import './chunk-KB6CKIUK.js';
|
|
11
|
+
import './chunk-AL3HQN73.js';
|
|
9
12
|
import './chunk-SRS2SKFS.js';
|
|
10
|
-
import './chunk-
|
|
11
|
-
import './chunk-NSBPE2FW.js';
|
|
13
|
+
import './chunk-UP2VWCW5.js';
|
|
12
14
|
|
|
13
15
|
// src/utils/common.ts
|
|
14
16
|
function sol(amount) {
|
|
@@ -18,149 +20,9 @@ function lamportsToSol(lamports) {
|
|
|
18
20
|
return Number(lamports) / 1e9;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
// src/utils/
|
|
22
|
-
|
|
23
|
-
AgentStatus2["Unverified"] = "unverified";
|
|
24
|
-
AgentStatus2["Active"] = "active";
|
|
25
|
-
AgentStatus2["Inactive"] = "inactive";
|
|
26
|
-
AgentStatus2["Dead"] = "dead";
|
|
27
|
-
return AgentStatus2;
|
|
28
|
-
})(AgentStatus || {});
|
|
29
|
-
var DEFAULT_ACTIVITY_THRESHOLD = 30 * 24 * 60 * 60;
|
|
30
|
-
function getCurrentTimestamp(config) {
|
|
31
|
-
return config.currentTimestamp ?? Math.floor(Date.now() / 1e3);
|
|
32
|
-
}
|
|
33
|
-
function getActivityThreshold(config) {
|
|
34
|
-
return config.activityThresholdSeconds ?? DEFAULT_ACTIVITY_THRESHOLD;
|
|
35
|
-
}
|
|
36
|
-
function isAgentVerified(agent) {
|
|
37
|
-
return agent.x402_total_calls > 0n;
|
|
38
|
-
}
|
|
39
|
-
function isAgentActive(agent, config = {}) {
|
|
40
|
-
if (!isAgentVerified(agent)) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const currentTimestamp = getCurrentTimestamp(config);
|
|
44
|
-
const threshold = getActivityThreshold(config);
|
|
45
|
-
const lastPayment = Number(agent.last_payment_timestamp);
|
|
46
|
-
const timeSinceLastPayment = currentTimestamp - lastPayment;
|
|
47
|
-
return timeSinceLastPayment <= threshold;
|
|
48
|
-
}
|
|
49
|
-
function isAgentInactive(agent, config = {}) {
|
|
50
|
-
if (!isAgentVerified(agent)) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
const currentTimestamp = getCurrentTimestamp(config);
|
|
54
|
-
const threshold = getActivityThreshold(config);
|
|
55
|
-
const lastPayment = Number(agent.last_payment_timestamp);
|
|
56
|
-
const timeSinceLastPayment = currentTimestamp - lastPayment;
|
|
57
|
-
return timeSinceLastPayment > threshold;
|
|
58
|
-
}
|
|
59
|
-
function isAgentDead(agent, config = {}) {
|
|
60
|
-
return isAgentInactive(agent, config);
|
|
61
|
-
}
|
|
62
|
-
function getAgentStatus(agent, config = {}) {
|
|
63
|
-
if (!isAgentVerified(agent)) {
|
|
64
|
-
return "unverified" /* Unverified */;
|
|
65
|
-
}
|
|
66
|
-
if (isAgentActive(agent, config)) {
|
|
67
|
-
return "active" /* Active */;
|
|
68
|
-
}
|
|
69
|
-
return "inactive" /* Inactive */;
|
|
70
|
-
}
|
|
71
|
-
function filterAgentsByStatus(agents, options = {}) {
|
|
72
|
-
const config = options.config ?? {};
|
|
73
|
-
const excludeInactive = options.excludeInactive ?? options.excludeDead ?? false;
|
|
74
|
-
return agents.filter((agent) => {
|
|
75
|
-
if (options.excludeUnverified && !isAgentVerified(agent)) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
if (excludeInactive && isAgentInactive(agent, config)) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return true;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function sortAgentsByActivity(agents) {
|
|
85
|
-
return [...agents].sort((a, b) => {
|
|
86
|
-
const timestampA = Number(a.last_payment_timestamp);
|
|
87
|
-
const timestampB = Number(b.last_payment_timestamp);
|
|
88
|
-
return timestampB - timestampA;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
function getTimeSinceLastPayment(agent, config = {}) {
|
|
92
|
-
const lastPayment = Number(agent.last_payment_timestamp);
|
|
93
|
-
if (lastPayment === 0) {
|
|
94
|
-
return "Never";
|
|
95
|
-
}
|
|
96
|
-
const currentTimestamp = getCurrentTimestamp(config);
|
|
97
|
-
const seconds = currentTimestamp - lastPayment;
|
|
98
|
-
if (seconds < 60) {
|
|
99
|
-
return "Just now";
|
|
100
|
-
}
|
|
101
|
-
const minutes = Math.floor(seconds / 60);
|
|
102
|
-
if (minutes < 60) {
|
|
103
|
-
return `${minutes} minute${minutes !== 1 ? "s" : ""} ago`;
|
|
104
|
-
}
|
|
105
|
-
const hours = Math.floor(minutes / 60);
|
|
106
|
-
if (hours < 24) {
|
|
107
|
-
return `${hours} hour${hours !== 1 ? "s" : ""} ago`;
|
|
108
|
-
}
|
|
109
|
-
const days = Math.floor(hours / 24);
|
|
110
|
-
if (days < 30) {
|
|
111
|
-
return `${days} day${days !== 1 ? "s" : ""} ago`;
|
|
112
|
-
}
|
|
113
|
-
const months = Math.floor(days / 30);
|
|
114
|
-
if (months < 12) {
|
|
115
|
-
return `${months} month${months !== 1 ? "s" : ""} ago`;
|
|
116
|
-
}
|
|
117
|
-
const years = Math.floor(months / 12);
|
|
118
|
-
return `${years} year${years !== 1 ? "s" : ""} ago`;
|
|
119
|
-
}
|
|
120
|
-
function getAgentStatusSummary(agents, config = {}) {
|
|
121
|
-
const total = agents.length;
|
|
122
|
-
if (total === 0) {
|
|
123
|
-
return {
|
|
124
|
-
total: 0,
|
|
125
|
-
verified: 0,
|
|
126
|
-
active: 0,
|
|
127
|
-
inactive: 0,
|
|
128
|
-
unverified: 0,
|
|
129
|
-
activePercentage: 0,
|
|
130
|
-
verifiedPercentage: 0
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
let verified = 0;
|
|
134
|
-
let active = 0;
|
|
135
|
-
let inactive = 0;
|
|
136
|
-
let unverified = 0;
|
|
137
|
-
for (const agent of agents) {
|
|
138
|
-
const status = getAgentStatus(agent, config);
|
|
139
|
-
switch (status) {
|
|
140
|
-
case "active" /* Active */:
|
|
141
|
-
verified++;
|
|
142
|
-
active++;
|
|
143
|
-
break;
|
|
144
|
-
case "inactive" /* Inactive */:
|
|
145
|
-
verified++;
|
|
146
|
-
inactive++;
|
|
147
|
-
break;
|
|
148
|
-
case "unverified" /* Unverified */:
|
|
149
|
-
unverified++;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
total,
|
|
155
|
-
verified,
|
|
156
|
-
active,
|
|
157
|
-
inactive,
|
|
158
|
-
unverified,
|
|
159
|
-
activePercentage: Math.round(active / total * 100),
|
|
160
|
-
verifiedPercentage: Math.round(verified / total * 100)
|
|
161
|
-
};
|
|
162
|
-
}
|
|
23
|
+
// src/utils/index.ts
|
|
24
|
+
init_reputation_tag_engine();
|
|
163
25
|
|
|
164
|
-
export {
|
|
26
|
+
export { lamportsToSol, sol };
|
|
165
27
|
//# sourceMappingURL=utils.js.map
|
|
166
28
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/common.ts","../src/utils/agent-status.ts"],"names":["AgentStatus"],"mappings":";;;;;;;;;;;;;AAOO,SAAS,IAAI,MAAA,EAAwB;AAC1C,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,MAAA,GAAS,GAAa,CAAC,CAAA;AAClD;AAKO,SAAS,cAAc,QAAA,EAA0B;AACtD,EAAA,OAAO,MAAA,CAAO,QAAQ,CAAA,GAAI,GAAA;AAC5B;;;ACFO,IAAK,WAAA,qBAAAA,YAAAA,KAAL;AAEL,EAAAA,aAAA,YAAA,CAAA,GAAa,YAAA;AAEb,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AAET,EAAAA,aAAA,UAAA,CAAA,GAAW,UAAA;AAEX,EAAAA,aAAA,MAAA,CAAA,GAAO,MAAA;AARG,EAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AAsBZ,IAAM,0BAAA,GAA6B,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA;AAKlD,SAAS,oBAAoB,MAAA,EAAmC;AAC9D,EAAA,OAAO,OAAO,gBAAA,IAAoB,IAAA,CAAK,MAAM,IAAA,CAAK,GAAA,KAAQ,GAAI,CAAA;AAChE;AAKA,SAAS,qBAAqB,MAAA,EAAmC;AAC/D,EAAA,OAAO,OAAO,wBAAA,IAA4B,0BAAA;AAC5C;AAgBO,SAAS,gBACd,KAAA,EACS;AACT,EAAA,OAAO,MAAM,gBAAA,GAAmB,EAAA;AAClC;AAiBO,SAAS,aAAA,CACd,KAAA,EACA,MAAA,GAA4B,EAAC,EACpB;AACT,EAAA,IAAI,CAAC,eAAA,CAAgB,KAAK,CAAA,EAAG;AAC3B,IA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;AAAA,MACR,QAAA,EAAU,CAAA;AAAA,MACV,UAAA,EAAY,CAAA;AAAA,MACZ,gBAAA,EAAkB,CAAA;AAAA,MAClB,kBAAA,EAAoB;AAAA,KACtB;AAAA,EACF;AAEA,EAAA,IAAI,QAAA,GAAW,CAAA;AACf,EAAA,IAAI,MAAA,GAAS,CAAA;AACb,EAAA,IAAI,QAAA,GAAW,CAAA;AACf,EAAA,IAAI,UAAA,GAAa,CAAA;AAEjB,EAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,IAAA,MAAM,MAAA,GAAS,cAAA,CAAe,KAAA,EAAO,MAAM,CAAA;AAC3C,IAAA,QAAQ,MAAA;AAAQ,MACd,KAAK,QAAA;AACH,QAAA,QAAA,EAAA;AACA,QAAA,MAAA,EAAA;AACA,QAAA;AAAA,MACF,KAAK,UAAA;AACH,QAAA,QAAA,EAAA;AACA,QAAA,QAAA,EAAA;AACA,QAAA;AAAA,MACF,KAAK,YAAA;AACH,QAAA,UAAA,EAAA;AACA,QAAA;AAAA;AACJ,EACF;AAEA,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAA;AAAA,IACA,UAAA;AAAA,IACA,gBAAA,EAAkB,IAAA,CAAK,KAAA,CAAO,MAAA,GAAS,QAAS,GAAG,CAAA;AAAA,IACnD,kBAAA,EAAoB,IAAA,CAAK,KAAA,CAAO,QAAA,GAAW,QAAS,GAAG;AAAA,GACzD;AACF","file":"utils.js","sourcesContent":["/**\n * Common utility functions for GhostSpeak SDK\n */\n\n/**\n * Convert SOL to lamports\n */\nexport function sol(amount: number): bigint {\n return BigInt(Math.round(amount * 1_000_000_000))\n}\n\n/**\n * Convert lamports to SOL\n */\nexport function lamportsToSol(lamports: bigint): number {\n return Number(lamports) / 1_000_000_000\n}","/**\n * Agent Status Utilities for Proof-of-Agent Verification\n *\n * Provides functions to determine agent activity status based on x402 payment history.\n * Uses snake_case field names to match the AgentDiscoveryClient.Agent interface.\n *\n * @module utils/agent-status\n */\n\nimport type { Agent } from '../x402/AgentDiscoveryClient.js'\n\n/**\n * Agent status enumeration\n */\nexport enum AgentStatus {\n /** Agent has never completed a paid x402 transaction */\n Unverified = 'unverified',\n /** Agent has received payment within the activity threshold */\n Active = 'active',\n /** Agent has payment history but no recent activity */\n Inactive = 'inactive',\n /** Agent is inactive beyond recovery threshold (deprecated - use Inactive) */\n Dead = 'dead'\n}\n\n/**\n * Configuration options for agent status checks\n */\nexport interface AgentStatusConfig {\n /** Activity threshold in seconds (default: 30 days) */\n activityThresholdSeconds?: number\n /** Current timestamp in seconds (default: Date.now() / 1000) */\n currentTimestamp?: number\n}\n\n/** Default activity threshold: 30 days in seconds */\nconst DEFAULT_ACTIVITY_THRESHOLD = 30 * 24 * 60 * 60\n\n/**\n * Get the current timestamp in seconds\n */\nfunction getCurrentTimestamp(config: AgentStatusConfig): number {\n return config.currentTimestamp ?? Math.floor(Date.now() / 1000)\n}\n\n/**\n * Get the activity threshold in seconds\n */\nfunction getActivityThreshold(config: AgentStatusConfig): number {\n return config.activityThresholdSeconds ?? DEFAULT_ACTIVITY_THRESHOLD\n}\n\n/**\n * Check if an agent is verified (has completed at least 1 paid x402 transaction)\n *\n * @param agent - Agent object with x402_total_calls field\n * @returns true if agent has at least 1 x402 call\n *\n * @example\n * ```typescript\n * const agent = await discoveryClient.getAgent(address)\n * if (isAgentVerified(agent)) {\n * console.log('Agent has completed paid work')\n * }\n * ```\n */\nexport function isAgentVerified(\n agent: Pick<Agent, 'x402_total_calls'>\n): boolean {\n return agent.x402_total_calls > 0n\n}\n\n/**\n * Check if an agent is active (received payment within threshold)\n *\n * @param agent - Agent object with x402_total_calls and last_payment_timestamp fields\n * @param config - Optional configuration for thresholds\n * @returns true if agent is verified AND has recent activity\n *\n * @example\n * ```typescript\n * const agent = await discoveryClient.getAgent(address)\n * if (isAgentActive(agent)) {\n * console.log('Agent is actively providing services')\n * }\n * ```\n */\nexport function isAgentActive(\n agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>,\n config: AgentStatusConfig = {}\n): boolean {\n if (!isAgentVerified(agent)) {\n return false\n }\n\n const currentTimestamp = getCurrentTimestamp(config)\n const threshold = getActivityThreshold(config)\n const lastPayment = Number(agent.last_payment_timestamp)\n const timeSinceLastPayment = currentTimestamp - lastPayment\n\n return timeSinceLastPayment <= threshold\n}\n\n/**\n * Check if an agent is inactive (has payment history but no recent activity)\n *\n * @param agent - Agent object with x402_total_calls and last_payment_timestamp fields\n * @param config - Optional configuration for thresholds\n * @returns true if agent is verified but has not had recent activity\n *\n * @example\n * ```typescript\n * const agent = await discoveryClient.getAgent(address)\n * if (isAgentInactive(agent)) {\n * console.log('Agent has gone dormant')\n * }\n * ```\n */\nexport function isAgentInactive(\n agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>,\n config: AgentStatusConfig = {}\n): boolean {\n if (!isAgentVerified(agent)) {\n return false // Unverified agents are not \"inactive\", just unverified\n }\n\n const currentTimestamp = getCurrentTimestamp(config)\n const threshold = getActivityThreshold(config)\n const lastPayment = Number(agent.last_payment_timestamp)\n const timeSinceLastPayment = currentTimestamp - lastPayment\n\n return timeSinceLastPayment > threshold\n}\n\n/**\n * Check if an agent is dead (alias for isAgentInactive for backwards compatibility)\n *\n * @deprecated Use isAgentInactive instead. \"Dead\" and \"Inactive\" are semantically identical.\n *\n * @param agent - Agent object with x402_total_calls and last_payment_timestamp fields\n * @param config - Optional configuration for thresholds\n * @returns true if agent is verified but has not had recent activity\n */\nexport function isAgentDead(\n agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>,\n config: AgentStatusConfig = {}\n): boolean {\n return isAgentInactive(agent, config)\n}\n\n/**\n * Get the comprehensive status of an agent\n *\n * @param agent - Agent object with x402_total_calls and last_payment_timestamp fields\n * @param config - Optional configuration for thresholds\n * @returns AgentStatus enum value\n *\n * @example\n * ```typescript\n * const agent = await discoveryClient.getAgent(address)\n * const status = getAgentStatus(agent)\n * switch (status) {\n * case AgentStatus.Active:\n * console.log('Agent is actively serving')\n * break\n * case AgentStatus.Inactive:\n * console.log('Agent has gone dormant')\n * break\n * case AgentStatus.Unverified:\n * console.log('Agent has not completed paid work')\n * break\n * }\n * ```\n */\nexport function getAgentStatus(\n agent: Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>,\n config: AgentStatusConfig = {}\n): AgentStatus {\n if (!isAgentVerified(agent)) {\n return AgentStatus.Unverified\n }\n\n if (isAgentActive(agent, config)) {\n return AgentStatus.Active\n }\n\n return AgentStatus.Inactive\n}\n\n/**\n * Filter options for agent status filtering\n */\nexport interface AgentStatusFilterOptions {\n /** Exclude agents that have never completed an x402 transaction */\n excludeUnverified?: boolean\n /** Exclude agents that have not been active within the threshold */\n excludeInactive?: boolean\n /** Alias for excludeInactive for backwards compatibility */\n excludeDead?: boolean\n /** Configuration for status checks */\n config?: AgentStatusConfig\n}\n\n/**\n * Filter agents by their activity status\n *\n * @param agents - Array of agents to filter\n * @param options - Filter options\n * @returns Filtered array of agents\n *\n * @example\n * ```typescript\n * const allAgents = await discoveryClient.searchAgents()\n * const activeAgents = filterAgentsByStatus(allAgents.agents, {\n * excludeUnverified: true,\n * excludeInactive: true\n * })\n * ```\n */\nexport function filterAgentsByStatus<\n T extends Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>\n>(agents: T[], options: AgentStatusFilterOptions = {}): T[] {\n const config = options.config ?? {}\n const excludeInactive = options.excludeInactive ?? options.excludeDead ?? false\n\n return agents.filter((agent) => {\n // Check unverified filter\n if (options.excludeUnverified && !isAgentVerified(agent)) {\n return false\n }\n\n // Check inactive filter\n if (excludeInactive && isAgentInactive(agent, config)) {\n return false\n }\n\n return true\n })\n}\n\n/**\n * Sort agents by their activity (most recently active first)\n *\n * @param agents - Array of agents to sort\n * @returns Sorted array of agents (descending by last_payment_timestamp)\n *\n * @example\n * ```typescript\n * const agents = await discoveryClient.searchAgents()\n * const sortedAgents = sortAgentsByActivity(agents.agents)\n * // sortedAgents[0] is the agent with most recent last_payment_timestamp\n * ```\n */\nexport function sortAgentsByActivity<\n T extends Pick<Agent, 'last_payment_timestamp'>\n>(agents: T[]): T[] {\n return [...agents].sort((a, b) => {\n const timestampA = Number(a.last_payment_timestamp)\n const timestampB = Number(b.last_payment_timestamp)\n return timestampB - timestampA // Descending order (most recent first)\n })\n}\n\n/**\n * Get time since last payment in a human-readable format\n *\n * @param agent - Agent object with last_payment_timestamp field\n * @param config - Optional configuration\n * @returns Human-readable time string (e.g., \"2 days ago\", \"1 month ago\")\n *\n * @example\n * ```typescript\n * const agent = await discoveryClient.getAgent(address)\n * console.log(`Last active: ${getTimeSinceLastPayment(agent)}`)\n * // Output: \"Last active: 5 days ago\"\n * ```\n */\nexport function getTimeSinceLastPayment(\n agent: Pick<Agent, 'last_payment_timestamp'>,\n config: AgentStatusConfig = {}\n): string {\n const lastPayment = Number(agent.last_payment_timestamp)\n\n if (lastPayment === 0) {\n return 'Never'\n }\n\n const currentTimestamp = getCurrentTimestamp(config)\n const seconds = currentTimestamp - lastPayment\n\n if (seconds < 60) {\n return 'Just now'\n }\n\n const minutes = Math.floor(seconds / 60)\n if (minutes < 60) {\n return `${minutes} minute${minutes !== 1 ? 's' : ''} ago`\n }\n\n const hours = Math.floor(minutes / 60)\n if (hours < 24) {\n return `${hours} hour${hours !== 1 ? 's' : ''} ago`\n }\n\n const days = Math.floor(hours / 24)\n if (days < 30) {\n return `${days} day${days !== 1 ? 's' : ''} ago`\n }\n\n const months = Math.floor(days / 30)\n if (months < 12) {\n return `${months} month${months !== 1 ? 's' : ''} ago`\n }\n\n const years = Math.floor(months / 12)\n return `${years} year${years !== 1 ? 's' : ''} ago`\n}\n\n/**\n * Summary statistics for a collection of agents\n */\nexport interface AgentStatusSummary {\n total: number\n verified: number\n active: number\n inactive: number\n unverified: number\n activePercentage: number\n verifiedPercentage: number\n}\n\n/**\n * Get summary statistics for a collection of agents\n *\n * @param agents - Array of agents to summarize\n * @param config - Optional configuration for status checks\n * @returns Summary statistics object\n *\n * @example\n * ```typescript\n * const allAgents = await discoveryClient.searchAgents()\n * const summary = getAgentStatusSummary(allAgents.agents)\n * console.log(`${summary.activePercentage}% of agents are active`)\n * ```\n */\nexport function getAgentStatusSummary<\n T extends Pick<Agent, 'x402_total_calls' | 'last_payment_timestamp'>\n>(agents: T[], config: AgentStatusConfig = {}): AgentStatusSummary {\n const total = agents.length\n\n if (total === 0) {\n return {\n total: 0,\n verified: 0,\n active: 0,\n inactive: 0,\n unverified: 0,\n activePercentage: 0,\n verifiedPercentage: 0\n }\n }\n\n let verified = 0\n let active = 0\n let inactive = 0\n let unverified = 0\n\n for (const agent of agents) {\n const status = getAgentStatus(agent, config)\n switch (status) {\n case AgentStatus.Active:\n verified++\n active++\n break\n case AgentStatus.Inactive:\n verified++\n inactive++\n break\n case AgentStatus.Unverified:\n unverified++\n break\n }\n }\n\n return {\n total,\n verified,\n active,\n inactive,\n unverified,\n activePercentage: Math.round((active / total) * 100),\n verifiedPercentage: Math.round((verified / total) * 100)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/common.ts","../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOO,SAAS,IAAI,MAAA,EAAwB;AAC1C,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,MAAA,GAAS,GAAa,CAAC,CAAA;AAClD;AAKO,SAAS,cAAc,QAAA,EAA0B;AACtD,EAAA,OAAO,MAAA,CAAO,QAAQ,CAAA,GAAI,GAAA;AAC5B;;;AC4DA,0BAAA,EAAA","file":"utils.js","sourcesContent":["/**\n * Common utility functions for GhostSpeak SDK\n */\n\n/**\n * Convert SOL to lamports\n */\nexport function sol(amount: number): bigint {\n return BigInt(Math.round(amount * 1_000_000_000))\n}\n\n/**\n * Convert lamports to SOL\n */\nexport function lamportsToSol(lamports: bigint): number {\n return Number(lamports) / 1_000_000_000\n}","/**\n * Utilities Index - Tree-shakeable Exports\n * \n * Import only the utilities you need for optimal bundle size.\n */\n\n// Most commonly used utilities\nexport { sol, lamportsToSol } from './common.js'\n\n// PDA derivation (frequently used)\nexport {\n deriveAgentPda,\n findProgramDerivedAddress\n} from './pda.js'\n\n// Token operations (moderate usage)\nexport {\n deriveAssociatedTokenAddress,\n detectTokenProgram,\n isToken2022Mint,\n getTokenProgramType,\n formatTokenAmount,\n parseTokenAmount,\n type TokenProgram\n} from './token-utils.js'\n\n// Error handling (essential for good UX)\nexport {\n GhostSpeakSDKError,\n withEnhancedErrors,\n enhanceTransactionError,\n createErrorContext,\n type ErrorContext\n} from './enhanced-client-errors.js'\n\n// Advanced utilities (tree-shakeable bulk exports)\n// Only import specific modules if needed to avoid bundle bloat\n\n// Token-2022 extensions removed - not aligned with pivot\n\n// IPFS operations (for large content)\nexport * as ipfs from './ipfs-client.js'\n\n// Privacy and encryption (specialized usage)\nexport * as privacy from './client-encryption.js'\n\n// Agent authorization signatures - GhostSpeak trustless delegation\nexport * as authSignatures from './signature-verification.js'\nexport {\n createAuthorizationMessage,\n signAuthorizationMessage,\n verifyAuthorizationSignature,\n createSignedAuthorization,\n generateNonce,\n serializeAuthorization,\n deserializeAuthorization,\n getAuthorizationId,\n isAuthorizationExpired,\n isAuthorizationExhausted,\n validateAuthorizationNetwork,\n} from './signature-verification.js'\n\n// Confidential transfers removed - x402 payment protocol focus\n// export * as confidential from './confidential-transfer-manager.js'\n\n// Account management (diagnostic and migration)\nexport * as accounts from './account-diagnostics.js'\n\n// Governance helpers (DAO functionality)\nexport * as governance from './governance-helpers.js'\n\n// Feature flags and gates (configuration)\nexport * as features from './feature-flags.js'\n\n// Reputation calculation and tagging (reputation layer)\nexport { ReputationCalculator } from './reputation-calculator.js'\nexport { ReputationTagEngine } from './reputation-tag-engine.js'\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghostspeak/sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "TypeScript SDK for GhostSpeak AI Agent Commerce Protocol - Production Ready Beta",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"import": "./dist/minimal/core-minimal.js",
|
|
40
40
|
"types": "./dist/minimal/core-minimal.d.ts"
|
|
41
41
|
},
|
|
42
|
+
"./credentials": {
|
|
43
|
+
"import": "./dist/credentials.js",
|
|
44
|
+
"types": "./dist/credentials.d.ts"
|
|
45
|
+
},
|
|
42
46
|
"./x402": {
|
|
43
47
|
"import": "./dist/index.js",
|
|
44
48
|
"types": "./dist/index.d.ts"
|
|
@@ -52,8 +56,9 @@
|
|
|
52
56
|
"dist"
|
|
53
57
|
],
|
|
54
58
|
"scripts": {
|
|
55
|
-
"generate": "codama run --config codama.config.js js && bun scripts/generate-mappings.ts
|
|
56
|
-
"build": "
|
|
59
|
+
"generate": "codama run --config codama.config.js js && bun scripts/generate-mappings.ts",
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"build:full": "bun run build:wasm && tsup",
|
|
57
62
|
"build:wasm": "bun run wasm:build",
|
|
58
63
|
"build:dev": "tsup --watch",
|
|
59
64
|
"dev": "tsup --watch",
|
|
@@ -71,10 +76,6 @@
|
|
|
71
76
|
"wasm:build": "cd src/wasm/crypto-wasm && wasm-pack build --target web --out-dir ../../../dist/wasm --scope ghostspeak",
|
|
72
77
|
"wasm:clean": "rm -rf dist/wasm src/wasm/crypto-wasm/pkg",
|
|
73
78
|
"wasm:install": "cargo install wasm-pack",
|
|
74
|
-
"db:generate": "drizzle-kit generate",
|
|
75
|
-
"db:migrate": "drizzle-kit migrate",
|
|
76
|
-
"db:push": "drizzle-kit push",
|
|
77
|
-
"db:studio": "drizzle-kit studio",
|
|
78
79
|
"lint": "eslint src --no-error-on-unmatched-pattern --ignore-pattern 'src/generated/**' && eslint src/generated --no-error-on-unmatched-pattern --config .eslintrc.generated.js",
|
|
79
80
|
"lint:fix": "eslint src --fix --ignore-pattern 'src/generated/**' && eslint src/generated --fix --config .eslintrc.generated.js",
|
|
80
81
|
"clean": "rm -rf dist coverage && bun run wasm:clean"
|
|
@@ -112,29 +113,28 @@
|
|
|
112
113
|
"@noble/curves": "^1.9.4",
|
|
113
114
|
"@noble/hashes": "^1.8.0",
|
|
114
115
|
"@solana-program/system": "^0.10.0",
|
|
115
|
-
"@solana-program/token
|
|
116
|
-
"@solana/
|
|
117
|
-
"@solana/
|
|
118
|
-
"@solana/
|
|
119
|
-
"@solana/codecs-
|
|
120
|
-
"@solana/codecs-
|
|
121
|
-
"@solana/codecs-
|
|
122
|
-
"@solana/
|
|
123
|
-
"@solana/
|
|
124
|
-
"@solana/
|
|
125
|
-
"@solana/
|
|
126
|
-
"@solana/
|
|
127
|
-
"@solana/
|
|
128
|
-
"@solana/rpc
|
|
129
|
-
"@solana/rpc-
|
|
130
|
-
"@solana/
|
|
116
|
+
"@solana-program/token": "^0.9.0",
|
|
117
|
+
"@solana-program/token-2022": "^0.6.1",
|
|
118
|
+
"@solana/accounts": "^5.1.0",
|
|
119
|
+
"@solana/addresses": "^5.1.0",
|
|
120
|
+
"@solana/codecs-core": "^5.1.0",
|
|
121
|
+
"@solana/codecs-data-structures": "^5.1.0",
|
|
122
|
+
"@solana/codecs-numbers": "^5.1.0",
|
|
123
|
+
"@solana/codecs-strings": "^5.1.0",
|
|
124
|
+
"@solana/errors": "^5.1.0",
|
|
125
|
+
"@solana/instructions": "^5.1.0",
|
|
126
|
+
"@solana/kit": "^5.1.0",
|
|
127
|
+
"@solana/options": "^5.1.0",
|
|
128
|
+
"@solana/programs": "^5.1.0",
|
|
129
|
+
"@solana/rpc": "^5.1.0",
|
|
130
|
+
"@solana/rpc-spec": "^5.1.0",
|
|
131
|
+
"@solana/rpc-types": "^5.1.0",
|
|
132
|
+
"@solana/signers": "^5.1.0",
|
|
131
133
|
"@solana/spl-account-compression": "^0.4.1",
|
|
132
|
-
"@solana/
|
|
133
|
-
"@solana/sysvars": "^5.0.0",
|
|
134
|
-
"@solana/transactions": "^5.0.0",
|
|
134
|
+
"@solana/sysvars": "^5.1.0",
|
|
135
135
|
"bs58": "^6.0.0",
|
|
136
|
-
"
|
|
137
|
-
"
|
|
136
|
+
"kubo-rpc-client": "^5.2.0",
|
|
137
|
+
"lru-cache": "^11.2.4"
|
|
138
138
|
},
|
|
139
139
|
"devDependencies": {
|
|
140
140
|
"@codama/cli": "^1.2.1",
|
|
@@ -143,11 +143,8 @@
|
|
|
143
143
|
"@codama/renderers-js": "^1.3.2",
|
|
144
144
|
"@codama/visitors": "^1.3.1",
|
|
145
145
|
"@types/node": "^24.0.15",
|
|
146
|
-
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
147
|
-
"@typescript-eslint/parser": "^8.37.0",
|
|
148
146
|
"@vitest/coverage-v8": "^3.2.4",
|
|
149
147
|
"@vitest/ui": "^3.2.4",
|
|
150
|
-
"drizzle-kit": "^0.28.0",
|
|
151
148
|
"eslint": "^9.31.0",
|
|
152
149
|
"glob": "^10.4.5",
|
|
153
150
|
"tsup": "^8.0.0",
|