@hashgraphonline/standards-agent-kit
Version:
A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.
96 lines (95 loc) • 2.86 kB
JavaScript
import { BaseServiceBuilder } from "hedera-agent-kit";
import { HCS2Client } from "@hashgraphonline/standards-sdk";
class HCS2Builder extends BaseServiceBuilder {
constructor(hederaKit) {
super(hederaKit);
}
/**
* Get or create HCS-2 client
*/
async getHCS2Client() {
if (!this.hcs2Client) {
const operatorId = this.hederaKit.signer.getAccountId().toString();
const operatorPrivateKey = this.hederaKit.signer?.getOperatorPrivateKey() ? this.hederaKit.signer.getOperatorPrivateKey().toStringRaw() : "";
const network = this.hederaKit.client.network;
const networkType = network.toString().includes("mainnet") ? "mainnet" : "testnet";
const config = {
network: networkType,
operatorId,
operatorKey: operatorPrivateKey
};
this.hcs2Client = new HCS2Client(config);
}
return this.hcs2Client;
}
/**
* Create a new HCS-2 registry
* Note: This executes the transaction directly via HCS2Client
*/
async createRegistry(options = {}) {
const client = await this.getHCS2Client();
return await client.createRegistry(options);
}
/**
* Register a new entry in an HCS-2 registry
*/
async registerEntry(registryTopicId, options) {
const client = await this.getHCS2Client();
return await client.registerEntry(registryTopicId, options);
}
/**
* Update an existing entry in an HCS-2 registry
*/
async updateEntry(registryTopicId, options) {
const client = await this.getHCS2Client();
return await client.updateEntry(registryTopicId, options);
}
/**
* Delete an entry from an HCS-2 registry
*/
async deleteEntry(registryTopicId, options) {
const client = await this.getHCS2Client();
return await client.deleteEntry(registryTopicId, options);
}
/**
* Migrate an HCS-2 registry to a new topic
*/
async migrateRegistry(registryTopicId, options) {
const client = await this.getHCS2Client();
return await client.migrateRegistry(registryTopicId, options);
}
/**
* Query entries from an HCS-2 registry
*/
async getRegistry(topicId, options = {}) {
const client = await this.getHCS2Client();
return await client.getRegistry(topicId, options);
}
/**
* Submit a raw message to an HCS-2 topic
*/
async submitMessage(topicId, payload) {
const client = await this.getHCS2Client();
return await client.submitMessage(topicId, payload);
}
/**
* Get topic info from mirror node
*/
async getTopicInfo(topicId) {
const client = await this.getHCS2Client();
return await client.getTopicInfo(topicId);
}
/**
* Close the HCS-2 client
*/
async close() {
if (this.hcs2Client) {
this.hcs2Client.close();
this.hcs2Client = void 0;
}
}
}
export {
HCS2Builder
};
//# sourceMappingURL=standards-agent-kit.es3.js.map