UNPKG

@roochnetwork/rooch-sdk

Version:
35 lines (34 loc) 910 B
import { bech32m } from "@scure/base"; import { fromHEX, isHex, toHEX } from "../utils/index.js"; import { normalizeRoochAddress } from "./util.js"; import { Address, ROOCH_BECH32_PREFIX } from "./address.js"; class RoochAddress extends Address { constructor(input) { let bytes; if (typeof input === "string") { if (isHex(input)) { const normalizeAddress = normalizeRoochAddress(input); bytes = fromHEX(normalizeAddress); } else { bytes = bech32m.decodeToBytes(input).bytes; } } else { bytes = input; } super(bech32m.encode(ROOCH_BECH32_PREFIX, bech32m.toWords(bytes), false)); this.bytes = bytes; } toBytes() { return this.bytes; } toHexAddress() { return normalizeRoochAddress(toHEX(this.bytes)); } toBech32Address() { return this.rawAddress; } } export { RoochAddress }; //# sourceMappingURL=rooch.js.map