//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
//! SPDX-License-Identifier: GPL-3.0-or-later
-import { ACCOUNT_KEY_HEX_LENGTH, ALPHABET, PREFIX, PREFIX_LEGACY } from "../constants"
-import { base32, bytes, hex } from "../convert"
-import { Blake2b } from "../crypto"
+import { ACCOUNT_KEY_HEX_LENGTH, PREFIX, PREFIX_LEGACY } from '../constants'
+import { base32, bytes, hex } from '../convert'
+import { Blake2b } from '../crypto'
+import { _validate } from './validate'
export class Address {
#address: string
throw new TypeError('Invalid address input', { cause: value })
}
if (typeof value === 'string') {
- if (RegExp(`^[A-F0-9]{${ACCOUNT_KEY_HEX_LENGTH}}$`, 'i').test(value)) {
+ if (hex.is(value) && value.length === ACCOUNT_KEY_HEX_LENGTH) {
this.#address = (this.constructor as typeof Address).fromPublicKey(hex.toBuffer(value))
- } else if (RegExp(`^(${PREFIX}|${PREFIX_LEGACY})[13][${ALPHABET}]{59}$`).test(value)) {
- this.#address = value
} else {
- throw new TypeError('Invalid address input', { cause: value })
+ _validate(value)
+ this.#address = value
}
} else if (value instanceof ArrayBuffer || value instanceof Uint8Array) {
const v = new Uint8Array(value)