import {encodeHex, decodeHex, isHex} from "./tools/binary/hex.js" export class Id { static fromBinary(binary: ArrayBuffer) { return new Id(binary) } static fromString(text: string) { const binary = decodeHex(text) return new Id(binary) } static isId(text: string) { return text.length === 64 && isHex(text) } #binary: ArrayBuffer #string: string constructor(binary: ArrayBuffer) { this.#binary = binary this.#string = encodeHex(binary) } get binary() { return this.#binary } get string() { return this.#string } toBinary() { return this.#binary } toString() { return this.#string } equals(id: Id | string) { return typeof id === "string" ? this.#string === id : this.#string === id.toString() } }