UNPKG

@hashgraphonline/standards-sdk

Version:

The Hashgraph Online Standards SDK provides a complete implementation of the Hashgraph Consensus Standards (HCS), giving developers all the tools needed to build applications on Hedera.

73 lines (72 loc) 2.24 kB
import { Logger } from "./standards-sdk.es22.js"; import { HederaMirrorNode } from "./standards-sdk.es29.js"; import { HCS20_CONSTANTS, HCS20MessageSchema } from "./standards-sdk.es16.js"; import { InvalidAccountFormatError } from "./standards-sdk.es17.js"; class HCS20BaseClient { constructor(config) { this.logger = config.logger || new Logger({ module: "HCS20Client" }); this.network = config.network === "mainnet" ? "mainnet" : "testnet"; this.mirrorNode = new HederaMirrorNode( this.network, this.logger, config.mirrorNodeUrl ? { customUrl: config.mirrorNodeUrl } : void 0 ); this.registryTopicId = config.registryTopicId || HCS20_CONSTANTS.REGISTRY_TOPIC_ID; this.publicTopicId = config.publicTopicId || HCS20_CONSTANTS.PUBLIC_TOPIC_ID; } /** * Validate HCS-20 message using Zod schema */ validateMessage(message) { try { HCS20MessageSchema.parse(message); return { valid: true }; } catch (error) { if (error.errors) { const errors = error.errors.map( (e) => `${e.path.join(".")}: ${e.message}` ); return { valid: false, errors }; } return { valid: false, errors: [error.message] }; } } /** * Normalize tick to lowercase and trimmed */ normalizeTick(tick) { return tick.toLowerCase().trim(); } /** * Convert account to string format */ accountToString(account) { if (typeof account === "string") { if (!HCS20_CONSTANTS.HEDERA_ACCOUNT_REGEX.test(account)) { throw new InvalidAccountFormatError(account); } return account; } return account.toString(); } /** * Convert topic to string format */ topicToString(topic) { if (typeof topic === "string") { if (!HCS20_CONSTANTS.HEDERA_ACCOUNT_REGEX.test(topic)) { throw new InvalidAccountFormatError(topic); } return topic; } return topic.toString(); } /** * NOTE: State queries (getPointsInfo, getBalance, etc.) require an external indexing service. * The HCS-20 clients only handle message submission. Use HCS20PointsIndexer for state management. */ } export { HCS20BaseClient }; //# sourceMappingURL=standards-sdk.es18.js.map