@ghostspeak/sdk 2.0.7 → 2.0.8

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.
Files changed (54) hide show
  1. package/README.md +145 -2
  2. package/dist/{GhostSpeakClient-CWmGaM9Q.d.ts → GhostSpeakClient-bnXwUPHI.d.ts} +10 -6
  3. package/dist/{StakingModule-C5rzuOWb.d.ts → StakingModule-DunDShLq.d.ts} +263 -343
  4. package/dist/{agent-5YLZ7DAC.js → agent-S42FIMR7.js} +3 -3
  5. package/dist/{agent-5YLZ7DAC.js.map → agent-S42FIMR7.js.map} +1 -1
  6. package/dist/browser-CI5_6Gzk.d.ts +234 -0
  7. package/dist/browser.d.ts +3 -64
  8. package/dist/browser.js +9 -9
  9. package/dist/{chunk-SFTSZ3LC.js → chunk-46QWY3MG.js} +3 -3
  10. package/dist/{chunk-SFTSZ3LC.js.map → chunk-46QWY3MG.js.map} +1 -1
  11. package/dist/{chunk-G7S6B6WB.js → chunk-5QBSC4T4.js} +7 -7
  12. package/dist/{chunk-G7S6B6WB.js.map → chunk-5QBSC4T4.js.map} +1 -1
  13. package/dist/{chunk-IHVDQ4YI.js → chunk-5QZVFUXB.js} +201 -256
  14. package/dist/chunk-5QZVFUXB.js.map +1 -0
  15. package/dist/{chunk-E3FD2CNY.js → chunk-6XCCMJ6M.js} +19 -23
  16. package/dist/chunk-6XCCMJ6M.js.map +1 -0
  17. package/dist/{chunk-JV2SWONF.js → chunk-A7ALCVUI.js} +3 -3
  18. package/dist/{chunk-JV2SWONF.js.map → chunk-A7ALCVUI.js.map} +1 -1
  19. package/dist/{chunk-AL3HQN73.js → chunk-AWMGX3OX.js} +172 -112
  20. package/dist/chunk-AWMGX3OX.js.map +1 -0
  21. package/dist/{chunk-S74EH3KD.js → chunk-IQM5RASO.js} +637 -25
  22. package/dist/chunk-IQM5RASO.js.map +1 -0
  23. package/dist/{chunk-SZGFSCNU.js → chunk-JYXSOXCP.js} +467 -299
  24. package/dist/chunk-JYXSOXCP.js.map +1 -0
  25. package/dist/{chunk-C5CDA3WX.js → chunk-OXA7MECJ.js} +476 -3
  26. package/dist/chunk-OXA7MECJ.js.map +1 -0
  27. package/dist/{chunk-KB6CKIUK.js → chunk-QLRWUHN2.js} +3 -3
  28. package/dist/{chunk-KB6CKIUK.js.map → chunk-QLRWUHN2.js.map} +1 -1
  29. package/dist/client.d.ts +2 -3
  30. package/dist/client.js +9 -9
  31. package/dist/{createAgentAuthorization-ULG47ZJI.js → createAgentAuthorization-KGZNXZBT.js} +4 -4
  32. package/dist/{createAgentAuthorization-ULG47ZJI.js.map → createAgentAuthorization-KGZNXZBT.js.map} +1 -1
  33. package/dist/generated-QJREJQ2C.js +9 -0
  34. package/dist/{generated-EG5USUFG.js.map → generated-QJREJQ2C.js.map} +1 -1
  35. package/dist/index.d.ts +209 -231
  36. package/dist/index.js +231 -521
  37. package/dist/index.js.map +1 -1
  38. package/dist/metafile-esm.json +1 -1
  39. package/dist/minimal/core-minimal.d.ts +266 -184
  40. package/dist/minimal/core-minimal.js +6 -6
  41. package/dist/minimal/core-minimal.js.map +1 -1
  42. package/dist/{revokeAuthorization-OK7E7OK3.js → revokeAuthorization-2ZRO6GUZ.js} +4 -4
  43. package/dist/{revokeAuthorization-OK7E7OK3.js.map → revokeAuthorization-2ZRO6GUZ.js.map} +1 -1
  44. package/dist/{updateReputationWithAuth-Y4ONEVSP.js → updateReputationWithAuth-PCEUOCFV.js} +4 -4
  45. package/dist/{updateReputationWithAuth-Y4ONEVSP.js.map → updateReputationWithAuth-PCEUOCFV.js.map} +1 -1
  46. package/dist/utils.js +9 -9
  47. package/package.json +4 -4
  48. package/dist/chunk-AL3HQN73.js.map +0 -1
  49. package/dist/chunk-C5CDA3WX.js.map +0 -1
  50. package/dist/chunk-E3FD2CNY.js.map +0 -1
  51. package/dist/chunk-IHVDQ4YI.js.map +0 -1
  52. package/dist/chunk-S74EH3KD.js.map +0 -1
  53. package/dist/chunk-SZGFSCNU.js.map +0 -1
  54. package/dist/generated-EG5USUFG.js +0 -9
package/dist/index.js CHANGED
@@ -1,29 +1,28 @@
1
1
  export { batchGetAccounts, batchGetAccountsWithRetry, batchGetAndMap, batchGetExistingAccounts, createBatchFetcher } from './chunk-SKMJJ3Q6.js';
2
2
  export { BaseReputationAdapter, GHOSTSPEAK_PROGRAM_ID, ReputationSource } from './chunk-TTB4OS2D.js';
3
- export { AuthorizationModule, DidModule, GhostSpeakClient, PrivacyModule, UnifiedCredentialService, calculateVisibleScore, canViewerAccess, GhostSpeakClient_default as default, filterMetricsByVisibility, getDefaultMetricVisibility, getRangeDisplayString, getReputationTier, getScoreRange, getTierDisplayName, lamportsToSol, sol, validatePrivacySettings } from './chunk-E3FD2CNY.js';
4
- import { init_MultiSourceAggregator } from './chunk-SZGFSCNU.js';
5
- export { AgentModule, BaseModule, CacheManager, CredentialKind, CredentialModule, CredentialStatus, DEFAULT_IPFS_CONFIG, DidError, DidErrorClass, GovernanceModule, IPFSUtils, InstructionBuilder, MultiSourceAggregator, MultisigModule, PayAIClient, ReputationModule, RpcClient, ServiceEndpointType, VerificationMethodType, VerificationRelationship, canPerformAction, createEd25519VerificationMethod, createIPFSUtils, createMetadataUri, createPayAIClient, createServiceEndpoint, deriveDidDocumentPda, determineStorageMethod, didDocumentToJson, exportAsW3CDidDocument, extractPaymentRequirements, generateDidString, getIdentifierFromDid, getMethodsForRelationship, getNetworkFromDid, isDidActive, isPaymentRequired, parseDidString, payAIFetch, validateDidString } from './chunk-SZGFSCNU.js';
3
+ export { AuthorizationModule, DidModule, GhostSpeakClient, PrivacyModule, UnifiedCredentialService, calculateVisibleScore, canViewerAccess, GhostSpeakClient_default as default, filterMetricsByVisibility, getDefaultMetricVisibility, getRangeDisplayString, getReputationTier, getScoreRange, getTierDisplayName, lamportsToSol, sol, validatePrivacySettings } from './chunk-6XCCMJ6M.js';
4
+ import { init_MultiSourceAggregator } from './chunk-JYXSOXCP.js';
5
+ export { ATTESTATION_SEED, AgentModule, BaseModule, CREDENTIAL_SEED, CacheManager, CredentialKind, CredentialModule, CredentialStatus, DEFAULT_IPFS_CONFIG, DidError, DidErrorClass, GhostModule, GovernanceModule, IPFSUtils, InstructionBuilder, MultiSourceAggregator, MultisigModule, ReputationModule, RpcClient, SASAttestationHelper, SAS_PROGRAM_ID, SCHEMA_SEED, ServiceEndpointType, VerificationMethodType, VerificationRelationship, canPerformAction, createEd25519VerificationMethod, createIPFSUtils, createMetadataUri, createServiceEndpoint, deriveDidDocumentPda, determineStorageMethod, didDocumentToJson, exportAsW3CDidDocument, generateDidString, getIdentifierFromDid, getMethodsForRelationship, getNetworkFromDid, isDidActive, parseDidString, validateDidString } from './chunk-JYXSOXCP.js';
6
6
  export { AccountNotFoundError, ErrorFactory, ErrorHandler, GhostSpeakError, InsufficientBalanceError, InvalidInputError, NetworkError, SimulationFailedError, TimeoutError, TransactionFailedError, ValidationError } from './chunk-5DMB3UAV.js';
7
7
  export { decrypt, elgamal_exports as elgamal, encrypt, generateKeypair, generateTransferProof, generateWithdrawProof, isWasmAvailable, loadWasmModule, wasm_bridge_exports as wasmBridge } from './chunk-VQZQCHUT.js';
8
- import { getFeatureFlags, ClientEncryptionService } from './chunk-G7S6B6WB.js';
9
- export { ClientEncryptionService, FeatureFlagManager, TokenExtension, TokenProgram, createDiscriminatorErrorMessage, createMigrationPlan, createMigrationReport, deriveAssociatedTokenAddress, deriveMultisigPda, deriveProposalPda, deriveSplTokenAssociatedTokenAddress, deriveToken2022AssociatedTokenAddress, detectTokenProgram, diagnoseAccountFromChain, diagnoseBatchFromChain, exportDiagnosticReport, extractLegacyData, formatTokenAmount, generateLocalPrivacyProof, getAllAssociatedTokenAddresses, getAssociatedTokenAccount, getConfidentialTransferConfig, getFeatureFlags, getInterestBearingConfig, getMigrationInstructions, getTokenProgramAddress, getTokenProgramFromAddress, getTokenProgramType, getTransferFeeConfig, hasConfidentialTransferExtension, hasInterestBearingExtension, hasTransferFeeExtension, inspectAccountData, isFeatureEnabled, isToken2022Mint, parseTokenAmount, runAccountDiagnostics, runBatchDiagnostics, safeDecodeAgent, simulateMigration, validateAccountDiscriminator, validateAssociatedTokenAddress, verifyLocalPrivacyProof } from './chunk-G7S6B6WB.js';
8
+ import { getFeatureFlags, ClientEncryptionService } from './chunk-5QBSC4T4.js';
9
+ export { ClientEncryptionService, FeatureFlagManager, TokenExtension, TokenProgram, createDiscriminatorErrorMessage, createMigrationPlan, createMigrationReport, deriveAssociatedTokenAddress, deriveMultisigPda, deriveProposalPda, deriveSplTokenAssociatedTokenAddress, deriveToken2022AssociatedTokenAddress, detectTokenProgram, diagnoseAccountFromChain, diagnoseBatchFromChain, exportDiagnosticReport, extractLegacyData, formatTokenAmount, generateLocalPrivacyProof, getAllAssociatedTokenAddresses, getAssociatedTokenAccount, getConfidentialTransferConfig, getFeatureFlags, getInterestBearingConfig, getMigrationInstructions, getTokenProgramAddress, getTokenProgramFromAddress, getTokenProgramType, getTransferFeeConfig, hasConfidentialTransferExtension, hasInterestBearingExtension, hasTransferFeeExtension, inspectAccountData, isFeatureEnabled, isToken2022Mint, parseTokenAmount, runAccountDiagnostics, runBatchDiagnostics, safeDecodeAgent, simulateMigration, validateAccountDiscriminator, validateAssociatedTokenAddress, verifyLocalPrivacyProof } from './chunk-5QBSC4T4.js';
10
10
  export { deriveAgentPda, deriveAgentVerificationPda, deriveUserRegistryPda, findProgramDerivedAddress } from './chunk-BF3IQ35I.js';
11
11
  export { createAuthorizationMessage, createSignedAuthorization, deserializeAuthorization, generateNonce, getAuthorizationId, isAuthorizationExhausted, isAuthorizationExpired, serializeAuthorization, signAuthorizationMessage, validateAuthorizationNetwork, verifyAuthorizationSignature } from './chunk-BQDGRTVP.js';
12
- import { init_reputation_tag_engine, init_reputation_tags } from './chunk-C5CDA3WX.js';
13
- export { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, BadgeType, BehaviorTag, ComplianceTag, DEFAULT_TAG_DECAY, GhostSpeakSDKError, INSTRUCTION_MAPPINGS, IPFSClient, InstructionValidationError, NATIVE_MINT_ADDRESS, PRIVACY_CONSTANTS, PrivacyMode, PrivacyPresets, REPUTATION_CONSTANTS, ReputationTagEngine, ReputationTier, ScoreRange, SkillTag, TAG_CONSTANTS, TOKEN_2022_PROGRAM_ADDRESS, TOKEN_PROGRAM_ADDRESS, TagCategory, TagConfidenceLevel, VisibilityLevel, createAccountMismatchError, createErrorContext, debugInstructionCall, enhanceErrorMessage, enhanceTransactionError, extractInstructionName, generateAccountValidationError, getAccountRequirements, getInstructionMapping, getPDAAccounts, getRequiredSigners, getWritableAccounts, isKnownInstruction, logEnhancedError, validateInstructionAccounts, validatePreconditions, withEnhancedErrors, withEnhancedErrorsSync } from './chunk-C5CDA3WX.js';
14
- export { getApproveDeliveryInstruction, getArbitrateDisputeInstruction, getCreateDidDocumentInstructionAsync, getCreateEscrowInstructionAsync, getDeactivateDidDocumentInstructionAsync, getFileDisputeInstruction, getGhostProtectEscrowDecoder, getInitializeStakingConfigInstructionAsync, getRegisterAgentInstructionAsync, getResolveDidDocumentInstructionAsync, getSlashStakeInstructionAsync, getStakeGhostInstructionAsync, getStakingAccountDecoder, getStakingConfigDecoder, getSubmitDeliveryInstruction, getUnstakeGhostInstructionAsync, getUpdateDidDocumentInstructionAsync, getUpdateReputationTagsInstructionAsync } from './chunk-S74EH3KD.js';
15
- export { ProposalStatus, getAgentDecoder } from './chunk-IHVDQ4YI.js';
16
- import './chunk-SFTSZ3LC.js';
17
- import './chunk-JV2SWONF.js';
18
- import './chunk-KB6CKIUK.js';
19
- export { GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS } from './chunk-AL3HQN73.js';
12
+ import { init_reputation_tag_engine, init_reputation_tags, ExternalIdNotFoundError, GhostSpeakError, GhostNotFoundError } from './chunk-OXA7MECJ.js';
13
+ export { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, BadgeType, BehaviorTag, ComplianceTag, DEFAULT_TAG_DECAY, GhostSpeakSDKError, INSTRUCTION_MAPPINGS, IPFSClient, InstructionValidationError, NATIVE_MINT_ADDRESS, PRIVACY_CONSTANTS, PrivacyMode, PrivacyPresets, REPUTATION_CONSTANTS, ReputationTagEngine, ReputationTier, ScoreRange, SkillTag, TAG_CONSTANTS, TOKEN_2022_PROGRAM_ADDRESS, TOKEN_PROGRAM_ADDRESS, TagCategory, TagConfidenceLevel, VisibilityLevel, createAccountMismatchError, createErrorContext, debugInstructionCall, enhanceErrorMessage, enhanceTransactionError, extractInstructionName, generateAccountValidationError, getAccountRequirements, getInstructionMapping, getPDAAccounts, getRequiredSigners, getWritableAccounts, isKnownInstruction, logEnhancedError, validateInstructionAccounts, validatePreconditions, withEnhancedErrors, withEnhancedErrorsSync } from './chunk-OXA7MECJ.js';
14
+ export { getApproveDeliveryInstruction, getArbitrateDisputeInstruction, getClaimGhostInstruction, getCreateDidDocumentInstructionAsync, getCreateEscrowInstructionAsync, getDeactivateDidDocumentInstructionAsync, getFileDisputeInstruction, getGhostProtectEscrowDecoder, getInitializeStakingConfigInstructionAsync, getRegisterAgentInstructionAsync, getResolveDidDocumentInstructionAsync, getSlashStakeInstructionAsync, getStakeGhostInstructionAsync, getStakingAccountDecoder, getStakingConfigDecoder, getSubmitDeliveryInstruction, getUnstakeGhostInstructionAsync, getUpdateDidDocumentInstructionAsync, getUpdateReputationTagsInstructionAsync } from './chunk-IQM5RASO.js';
15
+ export { ProposalStatus, decodeAgent, fetchAgent, fetchMaybeAgent, getAgentDecoder } from './chunk-5QZVFUXB.js';
16
+ import './chunk-46QWY3MG.js';
17
+ import './chunk-A7ALCVUI.js';
18
+ import './chunk-QLRWUHN2.js';
19
+ export { GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS } from './chunk-AWMGX3OX.js';
20
20
  export { AgentType, ChannelType, ErrorCode, EscrowStatus, MessageType, ParticipantType, isError, isSuccess, unwrap } from './chunk-SRS2SKFS.js';
21
21
  export { CrossmintVCClient, GHOSTSPEAK_CREDENTIAL_TYPES } from './chunk-RIZZPLLB.js';
22
22
  import { __require } from './chunk-UP2VWCW5.js';
23
23
  import { createSolanaRpc, lamports, pipe, createTransactionMessage, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, signTransactionMessageWithSigners, getBase64EncodedWireTransaction, createKeyPairSignerFromBytes, generateKeyPairSigner } from '@solana/kit';
24
24
  export { address, createKeyPairSignerFromBytes, createSolanaRpc, generateKeyPairSigner } from '@solana/kit';
25
- import { EventEmitter } from 'events';
26
- import { timingSafeEqual, createHmac } from 'crypto';
25
+ import { address } from '@solana/addresses';
27
26
  import { getTransferSolInstruction } from '@solana-program/system';
28
27
  import { promises } from 'fs';
29
28
  import process2 from 'process';
@@ -32,8 +31,223 @@ import tty from 'tty';
32
31
  import bs58 from 'bs58';
33
32
  import { sha256 } from '@noble/hashes/sha256';
34
33
  import { bytesToHex, hexToBytes } from '@noble/curves/abstract/utils';
35
- import { address } from '@solana/addresses';
36
34
 
35
+ var DEFAULT_API_URL = "https://api.ghostspeak.ai";
36
+ var DEVNET_API_URL = "https://api-devnet.ghostspeak.ai";
37
+ var LOCALNET_API_URL = "http://localhost:3001";
38
+ var ExternalIdResolver = class {
39
+ apiUrl;
40
+ constructor(config) {
41
+ if (config?.apiUrl) {
42
+ this.apiUrl = config.apiUrl;
43
+ } else {
44
+ const cluster = config?.cluster || "devnet";
45
+ this.apiUrl = cluster === "mainnet-beta" ? DEFAULT_API_URL : cluster === "localnet" ? LOCALNET_API_URL : DEVNET_API_URL;
46
+ }
47
+ }
48
+ /**
49
+ * Resolve external ID to Ghost address
50
+ *
51
+ * @example
52
+ * const address = await resolver.resolve('payai', 'agent-123');
53
+ */
54
+ async resolve(platform, externalId) {
55
+ const result = await this.lookup(platform, externalId);
56
+ return address(result.mapping.ghostAddress);
57
+ }
58
+ /**
59
+ * Lookup external ID with full Ghost data
60
+ *
61
+ * @example
62
+ * const { mapping, ghost } = await resolver.lookup('payai', 'agent-123');
63
+ */
64
+ async lookup(platform, externalId) {
65
+ try {
66
+ const response = await fetch(
67
+ `${this.apiUrl}/ghosts/external/${encodeURIComponent(platform)}/${encodeURIComponent(externalId)}`
68
+ );
69
+ if (response.status === 404) {
70
+ throw new ExternalIdNotFoundError(platform, externalId);
71
+ }
72
+ if (!response.ok) {
73
+ const error = await response.json().catch(() => ({}));
74
+ throw new GhostSpeakError(
75
+ error.message || "Failed to lookup external ID",
76
+ error.code || "LOOKUP_FAILED"
77
+ );
78
+ }
79
+ const data = await response.json();
80
+ return data;
81
+ } catch (error) {
82
+ if (error instanceof GhostSpeakError || error instanceof ExternalIdNotFoundError) throw error;
83
+ throw new GhostSpeakError(
84
+ "Failed to lookup external ID",
85
+ "LOOKUP_FAILED"
86
+ );
87
+ }
88
+ }
89
+ /**
90
+ * Get Ghost by Solana address via API
91
+ *
92
+ * Faster than on-chain lookup for read operations
93
+ */
94
+ async getGhost(ghostAddress) {
95
+ try {
96
+ const addrString = typeof ghostAddress === "string" ? ghostAddress : ghostAddress;
97
+ const response = await fetch(
98
+ `${this.apiUrl}/ghosts/${encodeURIComponent(addrString)}`
99
+ );
100
+ if (response.status === 404) {
101
+ throw new GhostNotFoundError(addrString);
102
+ }
103
+ if (!response.ok) {
104
+ const error = await response.json().catch(() => ({}));
105
+ throw new GhostSpeakError(
106
+ error.message || "Failed to fetch Ghost",
107
+ error.code || "FETCH_FAILED"
108
+ );
109
+ }
110
+ const ghost = await response.json();
111
+ return ghost;
112
+ } catch (error) {
113
+ if (error instanceof GhostSpeakError || error instanceof GhostNotFoundError) throw error;
114
+ throw new GhostSpeakError(
115
+ "Failed to fetch Ghost",
116
+ "FETCH_FAILED"
117
+ );
118
+ }
119
+ }
120
+ /**
121
+ * Get Ghost Score via API
122
+ */
123
+ async getGhostScore(ghostAddress) {
124
+ try {
125
+ const addrString = typeof ghostAddress === "string" ? ghostAddress : ghostAddress;
126
+ const response = await fetch(
127
+ `${this.apiUrl}/ghosts/${encodeURIComponent(addrString)}/score`
128
+ );
129
+ if (response.status === 404) {
130
+ throw new GhostNotFoundError(addrString);
131
+ }
132
+ if (!response.ok) {
133
+ const error = await response.json().catch(() => ({}));
134
+ throw new GhostSpeakError(
135
+ error.message || "Failed to fetch Ghost Score",
136
+ error.code || "FETCH_FAILED"
137
+ );
138
+ }
139
+ const score = await response.json();
140
+ return score;
141
+ } catch (error) {
142
+ if (error instanceof GhostSpeakError || error instanceof GhostNotFoundError) throw error;
143
+ throw new GhostSpeakError(
144
+ "Failed to fetch Ghost Score",
145
+ "FETCH_FAILED"
146
+ );
147
+ }
148
+ }
149
+ /**
150
+ * Get detailed reputation breakdown via API
151
+ */
152
+ async getGhostReputation(ghostAddress) {
153
+ try {
154
+ const addrString = typeof ghostAddress === "string" ? ghostAddress : ghostAddress;
155
+ const response = await fetch(
156
+ `${this.apiUrl}/ghosts/${encodeURIComponent(addrString)}/reputation`
157
+ );
158
+ if (response.status === 404) {
159
+ throw new GhostNotFoundError(addrString);
160
+ }
161
+ if (!response.ok) {
162
+ const error = await response.json().catch(() => ({}));
163
+ throw new GhostSpeakError(
164
+ error.message || "Failed to fetch reputation",
165
+ error.code || "FETCH_FAILED"
166
+ );
167
+ }
168
+ return await response.json();
169
+ } catch (error) {
170
+ if (error instanceof GhostSpeakError || error instanceof GhostNotFoundError) throw error;
171
+ throw new GhostSpeakError(
172
+ "Failed to fetch reputation",
173
+ "FETCH_FAILED"
174
+ );
175
+ }
176
+ }
177
+ /**
178
+ * Batch resolve multiple external IDs
179
+ */
180
+ async resolveBatch(identifiers) {
181
+ const promises = identifiers.map(
182
+ ({ platform, externalId }) => this.resolve(platform, externalId).catch(() => null)
183
+ );
184
+ return Promise.all(promises);
185
+ }
186
+ /**
187
+ * Check if external ID exists
188
+ */
189
+ async exists(platform, externalId) {
190
+ try {
191
+ await this.resolve(platform, externalId);
192
+ return true;
193
+ } catch (error) {
194
+ if (error instanceof ExternalIdNotFoundError) return false;
195
+ throw error;
196
+ }
197
+ }
198
+ /**
199
+ * Get all external IDs for a Ghost
200
+ *
201
+ * Fetches Ghost data and returns external identifiers
202
+ */
203
+ async getExternalIds(ghostAddress) {
204
+ const ghost = await this.getGhost(ghostAddress);
205
+ return ghost.externalIdentifiers;
206
+ }
207
+ /**
208
+ * Search for Ghost by partial platform ID
209
+ *
210
+ * Note: This is a client-side filter, not server-side search
211
+ * For production, implement server-side search endpoint
212
+ */
213
+ async searchByExternalId(platform, partialId) {
214
+ throw new GhostSpeakError(
215
+ "Search not yet implemented",
216
+ "NOT_IMPLEMENTED"
217
+ );
218
+ }
219
+ /**
220
+ * Set custom API URL
221
+ */
222
+ setApiUrl(apiUrl) {
223
+ this.apiUrl = apiUrl;
224
+ }
225
+ /**
226
+ * Get current API URL
227
+ */
228
+ getApiUrl() {
229
+ return this.apiUrl;
230
+ }
231
+ /**
232
+ * Check API health
233
+ */
234
+ async checkHealth() {
235
+ try {
236
+ const response = await fetch(`${this.apiUrl}/health`);
237
+ if (!response.ok) {
238
+ throw new Error(`HTTP ${response.status}`);
239
+ }
240
+ return await response.json();
241
+ } catch (error) {
242
+ throw new GhostSpeakError(
243
+ "Failed to check API health",
244
+ "HEALTH_CHECK_FAILED"
245
+ );
246
+ }
247
+ }
248
+ };
249
+
250
+ // src/index.ts
37
251
  init_reputation_tag_engine();
38
252
 
39
253
  // src/modules/indexer/X402TransactionIndexer.ts
@@ -219,510 +433,6 @@ var X402TransactionIndexer = class {
219
433
  // src/index.ts
220
434
  init_reputation_tags();
221
435
  init_MultiSourceAggregator();
222
- var TIMESTAMP_TOLERANCE_MS = 5 * 60 * 1e3;
223
- var SIGNATURE_HEADER = "x-payai-signature";
224
- var TIMESTAMP_HEADER = "x-payai-timestamp";
225
- var PayAIWebhookHandler = class extends EventEmitter {
226
- options;
227
- verifySignatures;
228
- authorizationModule;
229
- payAIFacilitatorAddress;
230
- constructor(options = {}, authorizationModule, payAIFacilitatorAddress) {
231
- super();
232
- this.options = options;
233
- this.verifySignatures = options.verifySignatures ?? process.env.NODE_ENV === "production";
234
- this.authorizationModule = authorizationModule;
235
- this.payAIFacilitatorAddress = payAIFacilitatorAddress;
236
- }
237
- // =====================================================
238
- // PUBLIC METHODS
239
- // =====================================================
240
- /**
241
- * Handle an incoming webhook request
242
- *
243
- * @param request - The incoming HTTP request (must have headers and body)
244
- * @returns Processing result
245
- */
246
- async handleWebhook(request) {
247
- try {
248
- const payload = typeof request.body === "string" ? JSON.parse(request.body) : request.body;
249
- if (this.verifySignatures && this.options.webhookSecret) {
250
- const bodyStr = typeof request.body === "string" ? request.body : JSON.stringify(request.body);
251
- const verification = await this.verifySignature(
252
- request.headers,
253
- bodyStr
254
- );
255
- if (!verification.valid) {
256
- return {
257
- success: false,
258
- error: verification.error ?? "Invalid signature"
259
- };
260
- }
261
- }
262
- return await this.processPayload(payload);
263
- } catch (error) {
264
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
265
- this.emit("error", new Error(`Webhook processing failed: ${errorMessage}`));
266
- return {
267
- success: false,
268
- error: errorMessage
269
- };
270
- }
271
- }
272
- /**
273
- * Verify webhook signature
274
- */
275
- async verifySignature(headers, body) {
276
- const getHeader = (name) => {
277
- if (headers instanceof Headers) {
278
- return headers.get(name) ?? void 0;
279
- }
280
- return headers[name];
281
- };
282
- const signature = getHeader(SIGNATURE_HEADER);
283
- const timestamp = getHeader(TIMESTAMP_HEADER);
284
- if (!signature) {
285
- return { valid: false, error: "Missing signature header" };
286
- }
287
- if (!timestamp) {
288
- return { valid: false, error: "Missing timestamp header" };
289
- }
290
- const timestampMs = parseInt(timestamp, 10);
291
- if (isNaN(timestampMs)) {
292
- return { valid: false, error: "Invalid timestamp format" };
293
- }
294
- const now = Date.now();
295
- if (Math.abs(now - timestampMs) > TIMESTAMP_TOLERANCE_MS) {
296
- return { valid: false, error: "Timestamp too old or too far in future" };
297
- }
298
- if (!this.options.webhookSecret) {
299
- return { valid: false, error: "Webhook secret not configured" };
300
- }
301
- const expectedSignature = this.computeSignature(
302
- timestamp,
303
- body,
304
- this.options.webhookSecret
305
- );
306
- const signatureBuffer = Buffer.from(signature, "hex");
307
- const expectedBuffer = Buffer.from(expectedSignature, "hex");
308
- if (signatureBuffer.length !== expectedBuffer.length) {
309
- return { valid: false, error: "Invalid signature" };
310
- }
311
- if (!timingSafeEqual(signatureBuffer, expectedBuffer)) {
312
- return { valid: false, error: "Invalid signature" };
313
- }
314
- return { valid: true };
315
- }
316
- /**
317
- * Convert a PayAI payment to a reputation record
318
- */
319
- paymentToReputationRecord(data) {
320
- return {
321
- agentAddress: data.merchant,
322
- paymentSignature: data.transactionSignature,
323
- amount: BigInt(data.amount),
324
- success: data.success ?? data.status === "settled",
325
- responseTimeMs: data.responseTimeMs ?? 0,
326
- payerAddress: data.payer,
327
- timestamp: new Date(data.settledAt ?? data.verifiedAt ?? Date.now()),
328
- network: data.network
329
- };
330
- }
331
- // =====================================================
332
- // PRIVATE METHODS
333
- // =====================================================
334
- /**
335
- * Process a verified webhook payload
336
- */
337
- async processPayload(payload) {
338
- const { type, data } = payload;
339
- switch (type) {
340
- case "payment.verified":
341
- this.emit("payment:verified", data);
342
- await this.options.onPaymentVerified?.(data);
343
- break;
344
- case "payment.settled":
345
- this.emit("payment:settled", data);
346
- await this.options.onPaymentSettled?.(data);
347
- if (this.options.onRecordReputation) {
348
- if (this.authorizationModule && this.payAIFacilitatorAddress) {
349
- const isAuthorized = await this.verifyOnChainAuthorization(data.merchant);
350
- if (!isAuthorized) {
351
- return {
352
- success: false,
353
- eventType: type,
354
- paymentId: data.paymentId,
355
- error: "Agent has not authorized PayAI facilitator to update reputation",
356
- reputationRecorded: false
357
- };
358
- }
359
- }
360
- const record = this.paymentToReputationRecord(data);
361
- await this.options.onRecordReputation(record);
362
- this.emit("reputation:recorded", record);
363
- return {
364
- success: true,
365
- eventType: type,
366
- paymentId: data.paymentId,
367
- reputationRecorded: true
368
- };
369
- }
370
- break;
371
- case "payment.failed":
372
- this.emit("payment:failed", data);
373
- await this.options.onPaymentFailed?.(data);
374
- if (this.options.onRecordReputation) {
375
- const record = this.paymentToReputationRecord(data);
376
- record.success = false;
377
- await this.options.onRecordReputation(record);
378
- this.emit("reputation:recorded", record);
379
- return {
380
- success: true,
381
- eventType: type,
382
- paymentId: data.paymentId,
383
- reputationRecorded: true
384
- };
385
- }
386
- break;
387
- case "payment.refunded":
388
- break;
389
- default:
390
- return {
391
- success: false,
392
- error: `Unknown event type: ${type}`
393
- };
394
- }
395
- return {
396
- success: true,
397
- eventType: type,
398
- paymentId: data.paymentId,
399
- reputationRecorded: false
400
- };
401
- }
402
- /**
403
- * Verify on-chain authorization for an agent
404
- *
405
- * Checks if the agent has pre-authorized the PayAI facilitator
406
- * to update their reputation on-chain.
407
- */
408
- async verifyOnChainAuthorization(agentAddress) {
409
- if (!this.authorizationModule || !this.payAIFacilitatorAddress) {
410
- return true;
411
- }
412
- try {
413
- const authorization = await this.authorizationModule.fetchAuthorization(
414
- agentAddress,
415
- this.payAIFacilitatorAddress
416
- );
417
- if (!authorization) {
418
- return false;
419
- }
420
- const status = this.authorizationModule.getAuthorizationStatus(
421
- authorization,
422
- authorization.currentIndex
423
- );
424
- return status.isValid;
425
- } catch (error) {
426
- console.error("Failed to verify on-chain authorization:", error);
427
- return false;
428
- }
429
- }
430
- /**
431
- * Compute HMAC-SHA256 signature for a webhook payload
432
- */
433
- computeSignature(timestamp, body, secret) {
434
- const signedPayload = `${timestamp}.${body}`;
435
- const hmac = createHmac("sha256", secret);
436
- hmac.update(signedPayload);
437
- return hmac.digest("hex");
438
- }
439
- };
440
- function createPayAIWebhookHandler(options = {}) {
441
- return new PayAIWebhookHandler(options);
442
- }
443
- function generateTestWebhookSignature(body, secret, timestamp) {
444
- const ts = (timestamp ?? Date.now()).toString();
445
- const signedPayload = `${ts}.${body}`;
446
- const hmac = createHmac("sha256", secret);
447
- hmac.update(signedPayload);
448
- return {
449
- signature: hmac.digest("hex"),
450
- timestamp: ts
451
- };
452
- }
453
- function createMockPayAIWebhook(overrides = {}) {
454
- return {
455
- id: `evt_${Date.now()}`,
456
- type: "payment.settled",
457
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
458
- data: {
459
- paymentId: `pay_${Date.now()}`,
460
- transactionSignature: `${Math.random().toString(36).slice(2)}${Math.random().toString(36).slice(2)}`,
461
- network: "solana",
462
- payer: "PayerWalletAddress111111111111111111111111",
463
- merchant: "MerchantAgentAddress11111111111111111111",
464
- amount: "1000000",
465
- // 1 USDC
466
- asset: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
467
- assetSymbol: "USDC",
468
- status: "settled",
469
- resource: "https://api.example.com/ai/generate",
470
- responseTimeMs: 250,
471
- httpStatusCode: 200,
472
- success: true,
473
- settledAt: (/* @__PURE__ */ new Date()).toISOString(),
474
- ...overrides
475
- }
476
- };
477
- }
478
- var DEFAULT_MARKETPLACE_URL = "https://marketplace.payai.network/api";
479
- var PayAIAgentSync = class extends EventEmitter {
480
- config;
481
- constructor(config = {}) {
482
- super();
483
- this.config = {
484
- marketplaceUrl: config.marketplaceUrl ?? DEFAULT_MARKETPLACE_URL,
485
- apiKey: config.apiKey,
486
- network: config.network ?? "solana",
487
- timeout: config.timeout ?? 3e4
488
- };
489
- }
490
- // =====================================================
491
- // PUBLIC METHODS
492
- // =====================================================
493
- /**
494
- * Register a GhostSpeak agent with PayAI marketplace
495
- *
496
- * @param agent - Agent data from GhostSpeak
497
- * @returns Registration result
498
- */
499
- async registerAgent(agent) {
500
- try {
501
- const registration = this.toPayAIRegistration(agent);
502
- const response = await this.makeRequest("/merchants/register", {
503
- method: "POST",
504
- body: JSON.stringify(registration)
505
- });
506
- if (!response.ok) {
507
- const error = await response.text();
508
- return {
509
- success: false,
510
- error: `Registration failed: ${error}`
511
- };
512
- }
513
- const data = await response.json();
514
- this.emit("agent:registered", {
515
- agentAddress: agent.address,
516
- agentId: data.agentId
517
- });
518
- return {
519
- success: true,
520
- agentId: data.agentId,
521
- marketplaceUrl: data.url
522
- };
523
- } catch (error) {
524
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
525
- return {
526
- success: false,
527
- error: errorMessage
528
- };
529
- }
530
- }
531
- /**
532
- * Update an agent's registration on PayAI marketplace
533
- *
534
- * @param agentId - PayAI agent ID
535
- * @param agent - Updated agent data
536
- * @returns Update result
537
- */
538
- async updateAgent(agentId, agent) {
539
- try {
540
- const response = await this.makeRequest(`/merchants/${agentId}`, {
541
- method: "PATCH",
542
- body: JSON.stringify(agent)
543
- });
544
- if (!response.ok) {
545
- const error = await response.text();
546
- return {
547
- success: false,
548
- error: `Update failed: ${error}`
549
- };
550
- }
551
- this.emit("agent:updated", { agentId });
552
- return {
553
- success: true,
554
- agentId
555
- };
556
- } catch (error) {
557
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
558
- return {
559
- success: false,
560
- error: errorMessage
561
- };
562
- }
563
- }
564
- /**
565
- * Remove an agent from PayAI marketplace
566
- *
567
- * @param agentId - PayAI agent ID
568
- * @returns Removal result
569
- */
570
- async removeAgent(agentId) {
571
- try {
572
- const response = await this.makeRequest(`/merchants/${agentId}`, {
573
- method: "DELETE"
574
- });
575
- if (!response.ok) {
576
- const error = await response.text();
577
- return {
578
- success: false,
579
- error: `Removal failed: ${error}`
580
- };
581
- }
582
- this.emit("agent:removed", { agentId });
583
- return {
584
- success: true,
585
- agentId
586
- };
587
- } catch (error) {
588
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
589
- return {
590
- success: false,
591
- error: errorMessage
592
- };
593
- }
594
- }
595
- /**
596
- * Check if an agent is registered on PayAI marketplace
597
- *
598
- * @param agentAddress - Agent's Solana address
599
- * @returns Whether agent is registered
600
- */
601
- async isAgentRegistered(agentAddress) {
602
- try {
603
- const response = await this.makeRequest(
604
- `/merchants/check?address=${agentAddress}&network=${this.config.network}`
605
- );
606
- if (!response.ok) {
607
- return false;
608
- }
609
- const data = await response.json();
610
- return data.registered;
611
- } catch {
612
- return false;
613
- }
614
- }
615
- /**
616
- * Get agent's PayAI marketplace listing
617
- *
618
- * @param agentAddress - Agent's Solana address
619
- * @returns Agent listing or null
620
- */
621
- async getAgentListing(agentAddress) {
622
- try {
623
- const response = await this.makeRequest(
624
- `/merchants/by-address?address=${agentAddress}&network=${this.config.network}`
625
- );
626
- if (!response.ok) {
627
- return null;
628
- }
629
- return response.json();
630
- } catch {
631
- return null;
632
- }
633
- }
634
- /**
635
- * Sync reputation score to PayAI marketplace
636
- *
637
- * Updates the agent's reputation score on PayAI based on
638
- * GhostSpeak reputation calculations.
639
- *
640
- * @param agentId - PayAI agent ID
641
- * @param reputationScore - New reputation score (0-10000)
642
- * @returns Update result
643
- */
644
- async syncReputationScore(agentId, reputationScore) {
645
- try {
646
- const response = await this.makeRequest(`/merchants/${agentId}/reputation`, {
647
- method: "POST",
648
- body: JSON.stringify({
649
- score: reputationScore,
650
- source: "ghostspeak",
651
- timestamp: Date.now()
652
- })
653
- });
654
- if (!response.ok) {
655
- const error = await response.text();
656
- return {
657
- success: false,
658
- error: `Reputation sync failed: ${error}`
659
- };
660
- }
661
- this.emit("reputation:synced", { agentId, reputationScore });
662
- return {
663
- success: true,
664
- agentId
665
- };
666
- } catch (error) {
667
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
668
- return {
669
- success: false,
670
- error: errorMessage
671
- };
672
- }
673
- }
674
- // =====================================================
675
- // PRIVATE METHODS
676
- // =====================================================
677
- /**
678
- * Convert GhostSpeak agent data to PayAI registration format
679
- */
680
- toPayAIRegistration(agent) {
681
- return {
682
- agentAddress: agent.address,
683
- serviceEndpoint: agent.serviceEndpoint,
684
- capabilities: agent.capabilities,
685
- acceptedTokens: agent.acceptedTokens,
686
- pricing: agent.pricing,
687
- metadata: {
688
- name: agent.name,
689
- description: agent.description,
690
- logo: agent.logo,
691
- website: agent.website
692
- }
693
- };
694
- }
695
- /**
696
- * Make an authenticated request to PayAI marketplace
697
- */
698
- async makeRequest(path, options = {}) {
699
- const controller = new AbortController();
700
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
701
- const headers = {
702
- "Content-Type": "application/json",
703
- "X-Ghostspeak-Integration": "1.0"
704
- };
705
- if (this.config.apiKey) {
706
- headers["Authorization"] = `Bearer ${this.config.apiKey}`;
707
- }
708
- try {
709
- const response = await fetch(`${this.config.marketplaceUrl}${path}`, {
710
- ...options,
711
- headers: {
712
- ...headers,
713
- ...options.headers
714
- },
715
- signal: controller.signal
716
- });
717
- return response;
718
- } finally {
719
- clearTimeout(timeoutId);
720
- }
721
- }
722
- };
723
- function createPayAIAgentSync(config = {}) {
724
- return new PayAIAgentSync(config);
725
- }
726
436
 
727
437
  // src/utils/test-ipfs-config.ts
728
438
  var TEST_IPFS_CONFIG = {
@@ -2346,6 +2056,6 @@ function clearFeatureGateCache() {
2346
2056
  featureCache.clear();
2347
2057
  }
2348
2058
 
2349
- export { CircuitBreaker, DEFAULT_RETRY_CONFIG, FEATURE_GATES, FallbackHandler, IPFSErrorHandler, IPFSOperationError, IPFSProvider, LocalStorageProvider, PayAIAgentSync, PayAIWebhookHandler, PrivateDataQuery, PrivateMetadataStorage, RetryHandler, TEST_IPFS_CONFIG, WalletFundingService, X402TransactionIndexer, checkFeatureGate, clearFeatureGateCache, createIPFSErrorHandler, createMockPayAIWebhook, createPayAIAgentSync, createPayAIWebhookHandler, createPrivacyManifest, createTestIPFSConfig, defaultFundingService, ensureMinimumBalance, estimateStorageCost, fundWallet, generateTestWebhookSignature, isIPFSError, withIPFSErrorHandling };
2059
+ export { CircuitBreaker, DEFAULT_RETRY_CONFIG, ExternalIdResolver, FEATURE_GATES, FallbackHandler, IPFSErrorHandler, IPFSOperationError, IPFSProvider, LocalStorageProvider, PrivateDataQuery, PrivateMetadataStorage, RetryHandler, TEST_IPFS_CONFIG, WalletFundingService, X402TransactionIndexer, checkFeatureGate, clearFeatureGateCache, createIPFSErrorHandler, createPrivacyManifest, createTestIPFSConfig, defaultFundingService, ensureMinimumBalance, estimateStorageCost, fundWallet, isIPFSError, withIPFSErrorHandling };
2350
2060
  //# sourceMappingURL=index.js.map
2351
2061
  //# sourceMappingURL=index.js.map