UNPKG

@hiero-ledger/sdk

Version:
83 lines (73 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _Key = _interopRequireDefault(require("./Key.cjs")); var hex = _interopRequireWildcard(require("./encoding/hex.cjs")); var _util = require("./util.cjs"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } // SPDX-License-Identifier: Apache-2.0 /** * @namespace proto * @typedef {import("@hashgraph/proto").proto.IKey} HieroProto.proto.IKey */ /** * @typedef {import("./client/Client.js").default<*, *>} Client */ /** * Represents an Ethereum Virtual Machine (EVM) address. * This class extends the Key class and provides functionality for handling EVM addresses. */ class EvmAddress extends _Key.default { /** * @internal * @param {Uint8Array} bytes */ constructor(bytes) { super(); this._bytes = bytes; } /** * Creates an EvmAddress from a hex string representation. * @param {string} evmAddress - The hex string representing the EVM address * @returns {EvmAddress} * @throws {Error} If the input string is not the correct size */ static fromString(evmAddress) { evmAddress = evmAddress.startsWith("0x") ? evmAddress.slice(2) : evmAddress; // Standard EVM address is 20 bytes which is 40 hex characters if (evmAddress.length !== 40) { throw new Error("Input EVM address string is not the correct size"); } return new EvmAddress(hex.decode(evmAddress)); } /** * @param {Uint8Array} bytes * @returns {EvmAddress} */ static fromBytes(bytes) { return new EvmAddress(bytes); } /** * @returns {Uint8Array} */ toBytes() { return this._bytes; } /** * @returns {string} */ toString() { return hex.encode(this._bytes); } /** * @param {EvmAddress} other * @returns {boolean} */ equals(other) { return (0, _util.arrayEqual)(this._bytes, other._bytes); } } exports.default = EvmAddress;