@ghostspeak/sdk 1.6.0 → 1.6.2

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/dist/index.js CHANGED
@@ -21031,11 +21031,13 @@ var SimpleRpcClient = class {
21031
21031
  rpc;
21032
21032
  rpcSubscriptions;
21033
21033
  commitment;
21034
+ endpoint;
21034
21035
  constructor(config) {
21035
- this.rpc = createSolanaRpc({ url: config.endpoint });
21036
+ this.endpoint = config.endpoint;
21037
+ this.rpc = createSolanaRpc(config.endpoint);
21036
21038
  this.commitment = config.commitment ?? "confirmed";
21037
21039
  if (config.wsEndpoint) {
21038
- this.rpcSubscriptions = createSolanaRpcSubscriptions({ url: config.wsEndpoint });
21040
+ this.rpcSubscriptions = createSolanaRpcSubscriptions(config.wsEndpoint);
21039
21041
  }
21040
21042
  }
21041
21043
  /**
@@ -21106,9 +21108,11 @@ var SimpleRpcClient = class {
21106
21108
  * Simulate transaction
21107
21109
  */
21108
21110
  async simulateTransaction(transaction, options) {
21109
- return await this.rpc.simulateTransaction(transaction, {
21111
+ return this.rpc.simulateTransaction(transaction, {
21110
21112
  commitment: options?.commitment ?? this.commitment,
21111
- replaceRecentBlockhash: options?.replaceRecentBlockhash ?? false
21113
+ replaceRecentBlockhash: options?.replaceRecentBlockhash ?? false,
21114
+ sigVerify: false,
21115
+ encoding: "base64"
21112
21116
  }).send();
21113
21117
  }
21114
21118
  /**
@@ -21119,17 +21123,53 @@ var SimpleRpcClient = class {
21119
21123
  return Number(result.value ?? 5e3);
21120
21124
  }
21121
21125
  /**
21122
- * Get program accounts (placeholder implementation)
21126
+ * Get program accounts
21123
21127
  */
21124
21128
  async getProgramAccounts(programId, options) {
21125
- console.warn("getProgramAccounts: Using simplified implementation");
21126
- return [];
21129
+ try {
21130
+ console.log(`Getting program accounts for program: ${programId}`);
21131
+ console.log(`Options: ${JSON.stringify(options)}`);
21132
+ const rpcOptions = {
21133
+ commitment: options?.commitment ?? this.commitment,
21134
+ ...options?.filters && { filters: options.filters }
21135
+ };
21136
+ const requestBody = {
21137
+ jsonrpc: "2.0",
21138
+ id: Math.floor(Math.random() * 1e5),
21139
+ method: "getProgramAccounts",
21140
+ params: [programId, rpcOptions]
21141
+ };
21142
+ const response = await globalThis.fetch(this.endpoint, {
21143
+ method: "POST",
21144
+ headers: { "Content-Type": "application/json" },
21145
+ body: JSON.stringify(requestBody)
21146
+ });
21147
+ if (!response.ok) {
21148
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
21149
+ }
21150
+ const data = await response.json();
21151
+ if (data.error) {
21152
+ throw new Error(`RPC Error: ${data.error.message}`);
21153
+ }
21154
+ const accounts = data.result ?? [];
21155
+ console.log(`Found ${accounts.length} program accounts`);
21156
+ return accounts.map((item) => {
21157
+ return {
21158
+ pubkey: item.pubkey,
21159
+ account: this.parseAccountInfo(item.account)
21160
+ };
21161
+ });
21162
+ } catch (error) {
21163
+ console.error(`Failed to get program accounts:`, error);
21164
+ throw new Error(`Failed to get program accounts: ${error instanceof Error ? error.message : "Unknown error"}`);
21165
+ }
21127
21166
  }
21128
21167
  parseAccountInfo(accountInfo) {
21129
21168
  const account = accountInfo;
21130
21169
  return {
21131
21170
  executable: account.executable,
21132
- lamports: account.lamports,
21171
+ lamports: BigInt(account.lamports),
21172
+ // Cast to Lamports branded type
21133
21173
  owner: account.owner,
21134
21174
  rentEpoch: account.rentEpoch,
21135
21175
  data: account.data,
@@ -21159,7 +21199,7 @@ var BaseInstructions = class {
21159
21199
  this._rpcClient ??= new SimpleRpcClient({
21160
21200
  endpoint: this.config.rpcEndpoint ?? "https://api.devnet.solana.com",
21161
21201
  wsEndpoint: this.config.rpcSubscriptions ? void 0 : void 0,
21162
- // TODO: get ws endpoint from config
21202
+ // WebSocket endpoint from config if available
21163
21203
  commitment: this.config.commitment ?? "confirmed"
21164
21204
  });
21165
21205
  return this._rpcClient;
@@ -21367,9 +21407,9 @@ var BaseInstructions = class {
21367
21407
  replaceRecentBlockhash: true
21368
21408
  });
21369
21409
  console.log(`\u2705 Real simulation completed:`);
21370
- console.log(` Success: ${!simulation.err}`);
21371
- console.log(` Compute units: ${simulation.unitsConsumed ?? "N/A"}`);
21372
- console.log(` Logs: ${simulation.logs?.length ?? 0} entries`);
21410
+ console.log(` Success: ${!simulation.value.err}`);
21411
+ console.log(` Compute units: ${simulation.value.unitsConsumed ?? "N/A"}`);
21412
+ console.log(` Logs: ${simulation.value.logs?.length ?? 0} entries`);
21373
21413
  return simulation;
21374
21414
  } catch (error) {
21375
21415
  console.error("\u274C Real simulation failed:", error);
@@ -21487,8 +21527,43 @@ var BaseInstructions = class {
21487
21527
  * NOTE: Temporarily simplified due to RPC client complexity
21488
21528
  */
21489
21529
  async getDecodedProgramAccounts(decoderImportName, filters = [], commitment = this.commitment) {
21490
- console.warn(`getDecodedProgramAccounts temporarily disabled - using placeholder`);
21491
- return [];
21530
+ try {
21531
+ console.log(`Getting program accounts with decoder: ${decoderImportName}`);
21532
+ console.log(`Filters: ${JSON.stringify(filters)}`);
21533
+ console.log(`Commitment: ${commitment}`);
21534
+ const accounts = await this._rpcClient.getProgramAccounts(this.config.programId, {
21535
+ commitment,
21536
+ filters
21537
+ });
21538
+ console.log(`Found ${Array.isArray(accounts) ? accounts.length : 0} program accounts`);
21539
+ try {
21540
+ const generated = await Promise.resolve().then(() => (init_generated(), generated_exports));
21541
+ const decoderGetter = generated[decoderImportName];
21542
+ if (!decoderGetter || typeof decoderGetter !== "function") {
21543
+ console.warn(`Decoder ${decoderImportName} not found in generated decoders`);
21544
+ return [];
21545
+ }
21546
+ const decoder = decoderGetter();
21547
+ const decodedAccounts = [];
21548
+ for (const { pubkey, account } of accounts) {
21549
+ try {
21550
+ const rawData = Buffer.isBuffer(account.data) || account.data instanceof Uint8Array ? account.data : Buffer.from(account.data.data ?? account.data, "base64");
21551
+ const decodedData = decoder.decode(rawData);
21552
+ decodedAccounts.push({ address: pubkey, data: decodedData });
21553
+ } catch (decodeError) {
21554
+ console.warn(`Failed to decode account ${pubkey}:`, decodeError);
21555
+ }
21556
+ }
21557
+ console.log(`Successfully decoded ${decodedAccounts.length}/${accounts.length} program accounts`);
21558
+ return decodedAccounts;
21559
+ } catch (decoderError) {
21560
+ console.warn(`Failed to load decoder ${decoderImportName}:`, decoderError);
21561
+ return [];
21562
+ }
21563
+ } catch (error) {
21564
+ console.error(`Failed to get program accounts:`, error);
21565
+ throw new Error(`Failed to get program accounts: ${error instanceof Error ? error.message : "Unknown error"}`);
21566
+ }
21492
21567
  }
21493
21568
  /**
21494
21569
  * Execute a single instruction with standard error handling
@@ -21627,17 +21702,19 @@ var AgentInstructions = class extends BaseInstructions {
21627
21702
  */
21628
21703
  async searchByCapabilities(capabilities) {
21629
21704
  const accounts = await this.getDecodedProgramAccounts("getAgentDecoder");
21630
- return accounts.map(({ data }) => data).filter(
21631
- (agent) => capabilities.some(
21632
- (capability) => agent.capabilities?.includes(capability)
21705
+ return accounts.filter(
21706
+ ({ data }) => capabilities.some(
21707
+ (capability) => data.capabilities?.includes(capability)
21633
21708
  )
21634
- );
21709
+ ).map(({ address: address2, data }) => ({ address: address2, data }));
21635
21710
  }
21636
21711
  /**
21637
21712
  * List agents (alias for getAllAgents for CLI compatibility)
21638
21713
  */
21639
21714
  async list(options = {}) {
21640
- return this.getAllAgents(options.limit ?? 100, options.offset ?? 0);
21715
+ const agents = await this.getAllAgents(options.limit ?? 100, options.offset ?? 0);
21716
+ const accounts = await this.getDecodedProgramAccounts("getAgentDecoder");
21717
+ return accounts.filter(({ data }) => agents.some((a) => JSON.stringify(a) === JSON.stringify(data))).map(({ address: address2, data }) => ({ address: address2, data }));
21641
21718
  }
21642
21719
  /**
21643
21720
  * Search agents (alias for searchByCapabilities for CLI compatibility)
@@ -21663,7 +21740,7 @@ var AgentInstructions = class extends BaseInstructions {
21663
21740
  */
21664
21741
  async listByOwner(options) {
21665
21742
  const accounts = await this.getDecodedProgramAccounts("getAgentDecoder");
21666
- return accounts.map(({ data }) => data).filter((agent) => agent.owner?.toString() === options.owner.toString());
21743
+ return accounts.filter(({ data }) => data.owner?.toString() === options.owner.toString()).map(({ address: address2, data }) => ({ address: address2, data }));
21667
21744
  }
21668
21745
  /**
21669
21746
  * Get agent status details
@@ -21919,7 +21996,7 @@ var MarketplaceInstructions = class extends BaseInstructions {
21919
21996
  */
21920
21997
  async getServiceListings() {
21921
21998
  const accounts = await this.getDecodedProgramAccounts("getServiceListingDecoder");
21922
- return accounts.map(({ data }) => data).filter((listing) => listing.isActive);
21999
+ return accounts.filter(({ data }) => data.isActive).map(({ address: address2, data }) => ({ address: address2, data }));
21923
22000
  }
21924
22001
  /**
21925
22002
  * Get all active job postings
@@ -21933,9 +22010,10 @@ var MarketplaceInstructions = class extends BaseInstructions {
21933
22010
  */
21934
22011
  async searchServicesByCategory(category) {
21935
22012
  const allListings = await this.getServiceListings();
21936
- return allListings.filter(
21937
- (listing) => listing.serviceType?.toLowerCase().includes(category.toLowerCase()) || listing.tags?.some((tag) => tag.toLowerCase().includes(category.toLowerCase()))
21938
- );
22013
+ return allListings.filter(({ data }) => {
22014
+ const service = data;
22015
+ return service.serviceType?.toLowerCase().includes(category.toLowerCase()) || service.tags?.some((tag) => tag.toLowerCase().includes(category.toLowerCase()));
22016
+ });
21939
22017
  }
21940
22018
  /**
21941
22019
  * Search job postings by budget range
@@ -22001,7 +22079,7 @@ var EscrowInstructions = class extends BaseInstructions {
22001
22079
  return {
22002
22080
  workOrderAddress: params.workOrderAddress,
22003
22081
  deliverables: params.deliverables ?? [],
22004
- ipfsHash: params.ipfsHash ?? `ipfs://${Date.now()}-placeholder`,
22082
+ ipfsHash: params.ipfsHash ?? "",
22005
22083
  metadataUri: params.metadataUri ?? `https://ghostspeak.io/delivery/${Date.now()}`,
22006
22084
  signer: params.signer
22007
22085
  };
@@ -22050,7 +22128,7 @@ var EscrowInstructions = class extends BaseInstructions {
22050
22128
  * Cancel escrow and refund to buyer
22051
22129
  */
22052
22130
  async cancel(signer, escrowAddress) {
22053
- console.warn("Work order cancellation requires dispute resolution. Use dispute() method instead.");
22131
+ console.log("Work order cancellation through dispute resolution...");
22054
22132
  return this.dispute({ signer, escrowAddress, reason: "Buyer requested cancellation" });
22055
22133
  }
22056
22134
  /**
@@ -22085,8 +22163,8 @@ var EscrowInstructions = class extends BaseInstructions {
22085
22163
  "dispute filing"
22086
22164
  );
22087
22165
  } catch (error) {
22088
- console.warn("Dispute filing failed. This may indicate the smart contract needs additional implementation:", error);
22089
- return `mock_dispute_${Date.now()}_${Math.random().toString(36).substring(7)}`;
22166
+ console.error("Dispute filing failed:", error);
22167
+ throw error;
22090
22168
  }
22091
22169
  }
22092
22170
  /**
@@ -23208,8 +23286,8 @@ var DisputeInstructions = class extends BaseInstructions {
23208
23286
  }
23209
23287
  }
23210
23288
  async deriveUserRegistry(user) {
23211
- console.log(`Deriving user registry for ${user}`);
23212
- return "11111111111111111111111111111111";
23289
+ const { deriveUserRegistryPda: deriveUserRegistryPda2 } = await Promise.resolve().then(() => (init_pda(), pda_exports));
23290
+ return deriveUserRegistryPda2(this.config.programId, user.address);
23213
23291
  }
23214
23292
  disputeToSummary(disputeAddress, dispute) {
23215
23293
  const now = BigInt(Math.floor(Date.now() / 1e3));
@@ -23858,8 +23936,8 @@ var BulkDealsInstructions = class extends BaseInstructions {
23858
23936
  return null;
23859
23937
  }
23860
23938
  async deriveUserRegistry(user) {
23861
- console.log(`Deriving user registry for ${user}`);
23862
- return "11111111111111111111111111111111";
23939
+ const { deriveUserRegistryPda: deriveUserRegistryPda2 } = await Promise.resolve().then(() => (init_pda(), pda_exports));
23940
+ return deriveUserRegistryPda2(this.config.programId, user.address);
23863
23941
  }
23864
23942
  };
23865
23943
 
@@ -24283,11 +24361,13 @@ var AnalyticsInstructions = class extends BaseInstructions {
24283
24361
  return 3 /* Unknown */;
24284
24362
  }
24285
24363
  async deriveUserRegistry(user) {
24286
- console.log(`Deriving user registry for ${user}`);
24287
- return "11111111111111111111111111111111";
24364
+ const { deriveUserRegistryPda: deriveUserRegistryPda2 } = await Promise.resolve().then(() => (init_pda(), pda_exports));
24365
+ return deriveUserRegistryPda2(this.config.programId, user.address);
24288
24366
  }
24289
24367
  async deriveMarketAnalyticsPda() {
24290
- return "MarketAnalytics11111111111111111";
24368
+ const { findProgramDerivedAddress: findProgramDerivedAddress2 } = await Promise.resolve().then(() => (init_pda(), pda_exports));
24369
+ const [address2] = await findProgramDerivedAddress2(["market_analytics"], this.config.programId);
24370
+ return address2;
24291
24371
  }
24292
24372
  };
24293
24373
 
@@ -24412,17 +24492,24 @@ var ComplianceInstructions = class extends BaseInstructions {
24412
24492
  console.log(` Verification Level: ${params.verificationLevel}`);
24413
24493
  console.log(` Jurisdiction: ${params.jurisdiction}`);
24414
24494
  this.validateKycParams(params);
24415
- const verificationResult = {
24416
- status: "Approved",
24417
- riskScore: Math.random() * 100,
24418
- documentVerified: true,
24419
- biometricMatched: params.verificationLevel !== "Basic"
24420
- };
24421
- console.log(`\u2705 KYC verification completed: ${verificationResult.status}`);
24422
- return {
24423
- signature: "simulated_kyc_signature",
24424
- verificationResult
24425
- };
24495
+ try {
24496
+ await this.deriveAuditTrailPda();
24497
+ const verificationResult = {
24498
+ status: "Pending",
24499
+ // Real KYC requires external verification
24500
+ riskScore: this.calculateKycRiskScore(params),
24501
+ documentVerified: false,
24502
+ // Requires external document verification service
24503
+ biometricMatched: false
24504
+ // Requires biometric verification service
24505
+ };
24506
+ console.log(`\u2705 KYC verification initiated: ${verificationResult.status}`);
24507
+ console.log("Note: External KYC provider integration required for completion");
24508
+ throw new Error("KYC verification requires integration with external compliance providers");
24509
+ } catch (error) {
24510
+ console.error("KYC verification failed:", error);
24511
+ throw error;
24512
+ }
24426
24513
  }
24427
24514
  /**
24428
24515
  * Perform AML screening for transaction
@@ -24491,7 +24578,8 @@ var ComplianceInstructions = class extends BaseInstructions {
24491
24578
  requestId,
24492
24579
  status: "received",
24493
24580
  estimatedCompletion,
24494
- dataPackage: requestType === "access" ? { placeholder: "User data package" } : void 0
24581
+ dataPackage: requestType === "access" ? void 0 : void 0
24582
+ // Data package would be generated by real data collection system
24495
24583
  };
24496
24584
  }
24497
24585
  // =====================================================
@@ -24602,8 +24690,39 @@ var ComplianceInstructions = class extends BaseInstructions {
24602
24690
  throw new Error("Transaction amount must be greater than 0");
24603
24691
  }
24604
24692
  }
24693
+ calculateKycRiskScore(params) {
24694
+ let riskScore = 0;
24695
+ switch (params.verificationLevel) {
24696
+ case "Basic":
24697
+ riskScore += 30;
24698
+ break;
24699
+ case "Enhanced":
24700
+ riskScore += 15;
24701
+ break;
24702
+ case "Premium":
24703
+ riskScore += 5;
24704
+ break;
24705
+ }
24706
+ switch (params.documentType) {
24707
+ case "passport":
24708
+ riskScore += 5;
24709
+ break;
24710
+ case "drivers_license":
24711
+ riskScore += 10;
24712
+ break;
24713
+ case "national_id":
24714
+ riskScore += 8;
24715
+ break;
24716
+ case "utility_bill":
24717
+ riskScore += 20;
24718
+ break;
24719
+ }
24720
+ return Math.min(riskScore, 100);
24721
+ }
24605
24722
  async deriveAuditTrailPda() {
24606
- return "AuditTrail11111111111111111111111";
24723
+ const { findProgramDerivedAddress: findProgramDerivedAddress2 } = await Promise.resolve().then(() => (init_pda(), pda_exports));
24724
+ const [address2] = await findProgramDerivedAddress2(["audit_trail"], this.config.programId);
24725
+ return address2;
24607
24726
  }
24608
24727
  };
24609
24728