@ghostspeak/sdk 2.0.8 → 2.0.10

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 (33) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/{GhostSpeakClient-bnXwUPHI.d.ts → GhostSpeakClient-qdLGyuDp.d.ts} +2 -2
  3. package/dist/{StakingModule-DunDShLq.d.ts → StakingModule-CPhp_ZY0.d.ts} +1 -1
  4. package/dist/{browser-CI5_6Gzk.d.ts → browser-D1TpjbjZ.d.ts} +3 -3
  5. package/dist/browser.d.ts +3 -2
  6. package/dist/browser.js +3 -3
  7. package/dist/{chunk-6XCCMJ6M.js → chunk-5SS3OL4B.js} +5 -5
  8. package/dist/{chunk-6XCCMJ6M.js.map → chunk-5SS3OL4B.js.map} +1 -1
  9. package/dist/{chunk-JYXSOXCP.js → chunk-63A7F2YP.js} +42 -32
  10. package/dist/chunk-63A7F2YP.js.map +1 -0
  11. package/dist/{chunk-5QBSC4T4.js → chunk-EU6PHSM5.js} +3 -3
  12. package/dist/{chunk-5QBSC4T4.js.map → chunk-EU6PHSM5.js.map} +1 -1
  13. package/dist/{chunk-OXA7MECJ.js → chunk-HIDBANFS.js} +56 -4
  14. package/dist/chunk-HIDBANFS.js.map +1 -0
  15. package/dist/{chunk-BQDGRTVP.js → chunk-QWQTPTZ4.js} +39 -51
  16. package/dist/chunk-QWQTPTZ4.js.map +1 -0
  17. package/dist/client.d.ts +3 -3
  18. package/dist/client.js +4 -4
  19. package/dist/index.d.ts +142 -11
  20. package/dist/index.js +149 -24
  21. package/dist/index.js.map +1 -1
  22. package/dist/metafile-esm.json +1 -1
  23. package/dist/minimal/core-minimal.d.ts +0 -5
  24. package/dist/minimal/core-minimal.js +6 -6
  25. package/dist/minimal/core-minimal.js.map +1 -1
  26. package/dist/{signature-verification-DGxR4aYQ.d.ts → signature-verification-BDzoR1MG.d.ts} +0 -5
  27. package/dist/utils.d.ts +143 -2
  28. package/dist/utils.js +4 -4
  29. package/dist/utils.js.map +1 -1
  30. package/package.json +5 -3
  31. package/dist/chunk-BQDGRTVP.js.map +0 -1
  32. package/dist/chunk-JYXSOXCP.js.map +0 -1
  33. package/dist/chunk-OXA7MECJ.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,16 +1,17 @@
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-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';
3
+ export { AuthorizationModule, DidModule, GhostSpeakClient, PrivacyModule, UnifiedCredentialService, calculateVisibleScore, canViewerAccess, GhostSpeakClient_default as default, filterMetricsByVisibility, getDefaultMetricVisibility, getRangeDisplayString, getReputationTier, getScoreRange, getTierDisplayName, lamportsToSol, sol, validatePrivacySettings } from './chunk-5SS3OL4B.js';
4
+ import { init_MultiSourceAggregator, BaseModule } from './chunk-63A7F2YP.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, StakingModule, VerificationMethodType, VerificationRelationship, canPerformAction, createEd25519VerificationMethod, createIPFSUtils, createMetadataUri, createServiceEndpoint, deriveDidDocumentPda, determineStorageMethod, didDocumentToJson, exportAsW3CDidDocument, generateDidString, getIdentifierFromDid, getMethodsForRelationship, getNetworkFromDid, isDidActive, parseDidString, validateDidString } from './chunk-63A7F2YP.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-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';
8
+ import { getFeatureFlags, ClientEncryptionService } from './chunk-EU6PHSM5.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-EU6PHSM5.js';
10
10
  export { deriveAgentPda, deriveAgentVerificationPda, deriveUserRegistryPda, findProgramDerivedAddress } from './chunk-BF3IQ35I.js';
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, 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';
11
+ export { createAuthorizationMessage, createSignedAuthorization, deserializeAuthorization, generateNonce, getAuthorizationId, isAuthorizationExhausted, isAuthorizationExpired, serializeAuthorization, signAuthorizationMessage, validateAuthorizationNetwork, verifyAuthorizationSignature } from './chunk-QWQTPTZ4.js';
12
+ import { init_reputation_tag_engine, init_reputation_tags, ExternalIdNotFoundError, GhostSpeakError, GhostNotFoundError } from './chunk-HIDBANFS.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-HIDBANFS.js';
14
+ import { getCreateEscrowInstructionAsync, getSubmitDeliveryInstruction, getApproveDeliveryInstruction, getFileDisputeInstruction, getArbitrateDisputeInstruction } from './chunk-IQM5RASO.js';
14
15
  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
16
  export { ProposalStatus, decodeAgent, fetchAgent, fetchMaybeAgent, getAgentDecoder } from './chunk-5QZVFUXB.js';
16
17
  import './chunk-46QWY3MG.js';
@@ -247,6 +248,106 @@ var ExternalIdResolver = class {
247
248
  }
248
249
  };
249
250
 
251
+ // src/modules/escrow/EscrowModule.ts
252
+ var EscrowModule = class extends BaseModule {
253
+ /**
254
+ * Create a new escrow for a service agreement
255
+ *
256
+ * @param params - Escrow creation parameters
257
+ * @returns Transaction signature
258
+ */
259
+ async createEscrow(params) {
260
+ const instruction = await getCreateEscrowInstructionAsync({
261
+ agent: params.agent,
262
+ clientTokenAccount: params.clientTokenAccount,
263
+ escrowVault: params.escrowVault,
264
+ tokenMint: params.tokenMint,
265
+ client: params.client,
266
+ escrowId: params.escrowId,
267
+ amount: params.amount,
268
+ jobDescription: params.jobDescription,
269
+ deadline: params.deadline
270
+ }, { programAddress: this.programId });
271
+ return this.execute("createEscrow", () => instruction, [params.client]);
272
+ }
273
+ /**
274
+ * Submit proof of delivery for an escrow
275
+ *
276
+ * @param params - Delivery submission parameters
277
+ * @returns Transaction signature
278
+ */
279
+ async submitDelivery(params) {
280
+ const instruction = getSubmitDeliveryInstruction({
281
+ escrow: params.escrow,
282
+ agent: params.agent,
283
+ agentOwner: params.agentOwner,
284
+ deliveryProof: params.deliveryProof
285
+ }, { programAddress: this.programId });
286
+ return this.execute("submitDelivery", () => instruction, [params.agentOwner]);
287
+ }
288
+ /**
289
+ * Approve delivery and release funds to agent
290
+ *
291
+ * @param params - Approval parameters
292
+ * @returns Transaction signature
293
+ */
294
+ async approveDelivery(params) {
295
+ const instruction = getApproveDeliveryInstruction({
296
+ escrow: params.escrow,
297
+ escrowVault: params.escrowVault,
298
+ agentTokenAccount: params.agentTokenAccount,
299
+ client: params.client
300
+ }, { programAddress: this.programId });
301
+ return this.execute("approveDelivery", () => instruction, [params.client]);
302
+ }
303
+ /**
304
+ * File a dispute for an escrow
305
+ *
306
+ * @param params - Dispute filing parameters
307
+ * @returns Transaction signature
308
+ */
309
+ async fileDispute(params) {
310
+ const instruction = getFileDisputeInstruction({
311
+ escrow: params.escrow,
312
+ client: params.client,
313
+ reason: params.reason
314
+ }, { programAddress: this.programId });
315
+ return this.execute("fileDispute", () => instruction, [params.client]);
316
+ }
317
+ /**
318
+ * Arbitrate a disputed escrow
319
+ *
320
+ * @param params - Arbitration parameters
321
+ * @returns Transaction signature
322
+ */
323
+ async arbitrateDispute(params) {
324
+ const instruction = getArbitrateDisputeInstruction({
325
+ escrow: params.escrow,
326
+ escrowVault: params.escrowVault,
327
+ agentTokenAccount: params.agentTokenAccount,
328
+ clientTokenAccount: params.clientTokenAccount,
329
+ agentStaking: params.agentStaking,
330
+ arbitrator: params.arbitrator,
331
+ decision: params.decision
332
+ }, { programAddress: this.programId });
333
+ return this.execute("arbitrateDispute", () => instruction, [params.arbitrator]);
334
+ }
335
+ /**
336
+ * Get escrow account data
337
+ *
338
+ * @param escrowAddress - The escrow account address
339
+ * @returns Escrow data or null if not found
340
+ */
341
+ async getEscrow(escrowAddress) {
342
+ try {
343
+ return await this.getAccount(escrowAddress, "getGhostProtectEscrowDecoder");
344
+ } catch (error) {
345
+ console.error("Error fetching escrow:", error);
346
+ return null;
347
+ }
348
+ }
349
+ };
350
+
250
351
  // src/index.ts
251
352
  init_reputation_tag_engine();
252
353
 
@@ -353,26 +454,37 @@ var X402TransactionIndexer = class {
353
454
  * Check if transaction is an x402 payment
354
455
  *
355
456
  * x402 payments are characterized by:
356
- * - SPL token transfer (TokenProgram or Token2022Program)
457
+ * - SPL token transfer (TokenProgram or Token2022Program) for USDC
458
+ * - Native SOL transfer (System Program)
357
459
  * - Transfer TO the facilitator address
358
460
  * - Optional memo instruction with payment metadata
461
+ *
462
+ * Supports both devnet and mainnet for all payment types
359
463
  */
360
464
  isX402Payment(transaction) {
361
465
  try {
362
466
  const instructions = transaction.transaction?.message?.instructions || [];
363
- const hasTokenTransfer = instructions.some((ix) => {
467
+ const hasPaymentTransfer = instructions.some((ix) => {
364
468
  const programId = ix.programId?.toString();
365
469
  const isTokenProgram = programId === "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" || // SPL Token
366
470
  programId === "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
367
- if (!isTokenProgram) return false;
368
- const parsed = ix.parsed;
369
- if (parsed?.type === "transfer" || parsed?.type === "transferChecked") {
370
- const destination = parsed.info?.destination;
371
- return destination === this.facilitatorAddress.toString();
471
+ if (isTokenProgram) {
472
+ const parsed = ix.parsed;
473
+ if (parsed?.type === "transfer" || parsed?.type === "transferChecked") {
474
+ const destination = parsed.info?.destination;
475
+ return destination === this.facilitatorAddress.toString();
476
+ }
477
+ }
478
+ if (programId === "11111111111111111111111111111111") {
479
+ const parsed = ix.parsed;
480
+ if (parsed?.type === "transfer") {
481
+ const destination = parsed.info?.destination;
482
+ return destination === this.facilitatorAddress.toString();
483
+ }
372
484
  }
373
485
  return false;
374
486
  });
375
- return hasTokenTransfer;
487
+ return hasPaymentTransfer;
376
488
  } catch (error) {
377
489
  console.error("[X402 Indexer] Error checking if x402 payment:", error);
378
490
  return false;
@@ -386,7 +498,11 @@ var X402TransactionIndexer = class {
386
498
  const instructions = transaction.transaction?.message?.instructions || [];
387
499
  const transferIx = instructions.find((ix) => {
388
500
  const parsed = ix.parsed;
389
- return parsed?.type === "transfer" || parsed?.type === "transferChecked";
501
+ const programId = ix.programId?.toString();
502
+ if (parsed?.type === "transfer" || parsed?.type === "transferChecked") {
503
+ return true;
504
+ }
505
+ return false;
390
506
  });
391
507
  if (!transferIx) {
392
508
  return null;
@@ -394,7 +510,7 @@ var X402TransactionIndexer = class {
394
510
  const transferInfo = transferIx.parsed.info;
395
511
  const merchant = transferInfo.destination;
396
512
  const payer = transferInfo.source;
397
- const amount = transferInfo.amount || transferInfo.tokenAmount?.amount || "0";
513
+ const amount = transferInfo.amount || transferInfo.tokenAmount?.amount || transferInfo.lamports || "0";
398
514
  const success = transaction.meta?.err === null;
399
515
  const blockTime = transaction.blockTime;
400
516
  const timestamp = blockTime ? new Date(blockTime * 1e3) : /* @__PURE__ */ new Date();
@@ -403,12 +519,21 @@ var X402TransactionIndexer = class {
403
519
  );
404
520
  let responseTimeMs;
405
521
  let metadata;
406
- if (memoIx && memoIx.data) {
522
+ if (memoIx) {
407
523
  try {
408
- const memoText = Buffer.from(memoIx.data, "base64").toString("utf-8");
409
- const memoData = JSON.parse(memoText);
410
- responseTimeMs = memoData.responseTimeMs;
411
- metadata = memoData;
524
+ let memoText;
525
+ if (memoIx.parsed) {
526
+ memoText = memoIx.parsed;
527
+ } else if (memoIx.data) {
528
+ memoText = Buffer.from(memoIx.data, "base64").toString("utf-8");
529
+ } else {
530
+ memoText = "";
531
+ }
532
+ if (memoText) {
533
+ const memoData = JSON.parse(memoText);
534
+ responseTimeMs = memoData.responseTimeMs;
535
+ metadata = memoData;
536
+ }
412
537
  } catch {
413
538
  }
414
539
  }
@@ -2056,6 +2181,6 @@ function clearFeatureGateCache() {
2056
2181
  featureCache.clear();
2057
2182
  }
2058
2183
 
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 };
2184
+ export { CircuitBreaker, DEFAULT_RETRY_CONFIG, EscrowModule, 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 };
2060
2185
  //# sourceMappingURL=index.js.map
2061
2186
  //# sourceMappingURL=index.js.map