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.

113 lines (112 loc) 3.75 kB
import { Long, AccountId } from "@hashgraph/sdk"; import { parseKey } from "./standards-sdk.es44.js"; import { Buffer } from "buffer"; class HCSParser { static parseConsensusCreateTopic(body) { if (!body) return void 0; const data = {}; if (body.memo) { data.memo = body.memo; } data.adminKey = parseKey(body.adminKey); data.submitKey = parseKey(body.submitKey); if (body.autoRenewPeriod?.seconds) { data.autoRenewPeriod = Long.fromValue( body.autoRenewPeriod.seconds ).toString(); } if (body.autoRenewAccount) { data.autoRenewAccountId = new AccountId( body.autoRenewAccount.shardNum ?? 0, body.autoRenewAccount.realmNum ?? 0, body.autoRenewAccount.accountNum ?? 0 ).toString(); } return data; } static parseConsensusSubmitMessage(body) { if (!body) return void 0; const data = {}; if (body.topicID) { data.topicId = `${body.topicID.shardNum ?? 0}.${body.topicID.realmNum ?? 0}.${body.topicID.topicNum ?? 0}`; } if (body.message?.length > 0) { const messageBuffer = Buffer.from(body.message); const utf8String = messageBuffer.toString("utf8"); if (/[\x00-\x08\x0B\x0E-\x1F\x7F]/.test(utf8String) || utf8String.includes("�")) { data.message = messageBuffer.toString("base64"); data.messageEncoding = "base64"; } else { data.message = utf8String; data.messageEncoding = "utf8"; } } if (body.chunkInfo) { if (body.chunkInfo.initialTransactionID) { const txId = body.chunkInfo.initialTransactionID.accountID; const taValidStart = body.chunkInfo.initialTransactionID.transactionValidStart; if (txId && taValidStart) { data.chunkInfoInitialTransactionID = `${txId.shardNum ?? 0}.${txId.realmNum ?? 0}.${txId.accountNum ?? 0}@${taValidStart.seconds ?? 0}.${taValidStart.nanos ?? 0}`; } } if (body.chunkInfo.number !== void 0 && body.chunkInfo.number !== null) { data.chunkInfoNumber = body.chunkInfo.number; } if (body.chunkInfo.total !== void 0 && body.chunkInfo.total !== null) { data.chunkInfoTotal = body.chunkInfo.total; } } return data; } static parseConsensusUpdateTopic(body) { if (!body) return void 0; const data = {}; if (body.topicID) { data.topicId = `${body.topicID.shardNum}.${body.topicID.realmNum}.${body.topicID.topicNum}`; } if (body.memo?.value !== void 0) { data.memo = body.memo.value; } if (body.adminKey === null) { data.clearAdminKey = true; data.adminKey = void 0; } else if (body.adminKey) { data.adminKey = parseKey(body.adminKey); } else { data.adminKey = void 0; } if (body.submitKey === null) { data.clearSubmitKey = true; data.submitKey = void 0; } else if (body.submitKey) { data.submitKey = parseKey(body.submitKey); } else { data.submitKey = void 0; } if (body.autoRenewPeriod?.seconds) { data.autoRenewPeriod = Long.fromValue( body.autoRenewPeriod.seconds ).toString(); } if (body.autoRenewAccount) { data.autoRenewAccountId = new AccountId( body.autoRenewAccount.shardNum ?? 0, body.autoRenewAccount.realmNum ?? 0, body.autoRenewAccount.accountNum ?? 0 ).toString(); } return data; } static parseConsensusDeleteTopic(body) { if (!body) return void 0; const data = {}; if (body.topicID) { data.topicId = `${body.topicID.shardNum}.${body.topicID.realmNum ?? 0}.${body.topicID.topicNum ?? 0}`; } return data; } } export { HCSParser }; //# sourceMappingURL=standards-sdk.es35.js.map