UNPKG

@hashgraph/sdk

Version:
204 lines (203 loc) 7.15 kB
/** * This method is called by most entity ID constructors. It's purpose is to * deduplicate the constuctors. * * @param {number | Long | IEntityId} props * @param {(number | null | Long)=} realmOrNull * @param {(number | null | Long)=} numOrNull * @returns {IEntityIdResult} */ export function constructor(props: number | Long | IEntityId, realmOrNull?: (number | null | Long) | undefined, numOrNull?: (number | null | Long) | undefined): IEntityIdResult; /** * A simple comparison function for comparing entity IDs * * @param {[Long, Long, Long]} a * @param {[Long, Long, Long]} b * @returns {number} */ export function compare(a: [Long, Long, Long], b: [Long, Long, Long]): number; /** * This type is part of the entity ID checksums feature which * is responsible for checking if an entity ID was created on * the same ledger ID as the client is currently using. * * @typedef {object} ParseAddressResult * @property {number} status * @property {Long} [num1] * @property {Long} [num2] * @property {Long} [num3] * @property {string} [correctChecksum] * @property {string} [givenChecksum] * @property {string} [noChecksumFormat] * @property {string} [withChecksumFormat] */ /** * @param {string} text * @returns {IEntityIdParts} */ export function fromStringSplitter(text: string): IEntityIdParts; /** * @param {string} text * @returns {IEntityIdResultWithChecksum} */ export function fromString(text: string): IEntityIdResultWithChecksum; /** * Return the shard, realm, and num from a solidity address. * * Solidity addresses are 20 bytes long and hex encoded, where the first 4 * bytes represent the shard, the next 8 bytes represent the realm, and * the last 8 bytes represent the num. All in Big Endian format * * @param {string} address * @returns {[Long, Long, Long]} */ export function fromSolidityAddress(address: string): [Long, Long, Long]; /** * Parse an EVM address and return shard, realm, entity num, and optional EVM address. * * For long zero addresses (first 12 bytes are zeros): returns [shard, realm, entityNum, null] * For regular EVM addresses: returns [shard, realm, 0, EvmAddress] * * @param {Long | number} shard - The shard number to use * @param {Long | number} realm - The realm number to use * @param {string} address - The EVM address to parse (with or without 0x prefix) * @returns {[Long, Long, Long, EvmAddress | null]} - [shard, realm, entityNum, evmAddressOrNull] */ export function fromEvmAddress(shard: Long | number, realm: Long | number, address: string): [Long, Long, Long, EvmAddress | null]; /** * Convert shard, realm, and num into a solidity address. * * See `fromSolidityAddress()` for more documentation. * * @param {[Long,Long,Long] | [number,number,number]} address * @returns {string} */ export function toSolidityAddress(address: [Long, Long, Long] | [number, number, number]): string; /** * @overload * @param {Uint8Array} evmAddressBytes - EVM address bytes to convert to hex * @returns {string} */ export function toEvmAddress(evmAddressBytes: Uint8Array): string; /** * @overload * @param {Long} accountNum - Account number to convert to long-zero EVM address * @returns {string} */ export function toEvmAddress(accountNum: Long): string; /** * Parse the address string addr and return an object with the results (8 fields). * The first four fields are numbers, which could be implemented as signed 32 bit * integers, and the last four are strings. * * status; //the status of the parsed address * // 0 = syntax error * // 1 = an invalid with-checksum address (bad checksum) * // 2 = a valid no-checksum address * // 3 = a valid with-checksum address * num1; //the 3 numbers in the address, such as 1.2.3, with leading zeros removed * num2; * num3; * correctchecksum; //the correct checksum * givenChecksum; //the checksum in the address that was parsed * noChecksumFormat; //the address in no-checksum format * withChecksumFormat; //the address in with-checksum format * * @param {Uint8Array} ledgerId * @param {string} addr * @returns {ParseAddressResult} */ export function _parseAddress(ledgerId: Uint8Array, addr: string): ParseAddressResult; /** * Given an address like "0.0.123", return a checksum like "laujm" * * @param {Uint8Array} ledgerId * @param {string} addr * @returns {string} */ export function _checksum(ledgerId: Uint8Array, addr: string): string; /** * Validate an entity ID checksum against a client * * @param {Long} shard * @param {Long} realm * @param {Long} num * @param {string | null} checksum * @param {Client} client */ export function validateChecksum(shard: Long, realm: Long, num: Long, checksum: string | null, client: Client): void; /** * Stringify the entity ID with a checksum. * * @param {string} string * @param {Client} client * @returns {string} */ export function toStringWithChecksum(string: string, client: Client): string; /** * Deserialize the alias to public key. * Alias is created from ed25519 or ECDSASecp256k1 types of accounts. If hollow account is used, the alias is created from evm address. * For hollow accounts, please use aliasToEvmAddress. * * @param {string} alias * @returns {PublicKey | null} */ export function aliasToPublicKey(alias: string): PublicKey | null; /** * Deserialize the alias to evm address. * Alias is created from hollow account. * For ed25519 or ECDSASecp256k1 accounts, please use aliasToPublicKey. * * @param {string} alias * @returns {string | null} */ export function aliasToEvmAddress(alias: string): string | null; /** * Serialize the public key to alias. * Alias is created from ed25519 or ECDSASecp256k1 types of accounts. If hollow account is used, the alias is created from evm address. * * @param {string | PublicKey} publicKey * @returns {string | null} */ export function publicKeyToAlias(publicKey: string | PublicKey): string | null; /** * This type is part of the entity ID checksums feature which * is responsible for checking if an entity ID was created on * the same ledger ID as the client is currently using. */ export type ParseAddressResult = { status: number; num1?: Long | undefined; num2?: Long | undefined; num3?: Long | undefined; correctChecksum?: string | undefined; givenChecksum?: string | undefined; noChecksumFormat?: string | undefined; withChecksumFormat?: string | undefined; }; export type Client = import("./client/Client.js").default<any, any>; export type IEntityId = { num: number | Long; shard?: (number | Long) | undefined; realm?: (number | Long) | undefined; }; export type IEntityIdResult = { shard: Long; realm: Long; num: Long; }; export type IEntityIdParts = { shard: string | null; realm: string | null; numOrHex: string; checksum: string | null; }; export type IEntityIdResultWithChecksum = { shard: Long; realm: Long; num: Long; checksum: string | null; }; import Long from "long"; import EvmAddress from "./EvmAddress.js"; import PublicKey from "./PublicKey.js";