From: Chris Duncan Date: Fri, 7 Aug 2026 04:31:00 +0000 (-0700) Subject: Extend Hex type to accomodate string expectations. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=63fc107dd0e216bd987304dc0a46668885ddfd3d;p=libnemo.git Extend Hex type to accomodate string expectations. --- diff --git a/src/index.ts b/src/index.ts index 244c464..65b53e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ declare global { type Bytes = Uint8Array | Buffer - type Hex = HexByte[] + type Hex = string & HexByte[] type HexByte = `${HexChar}${HexChar}` type HexChar = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' } diff --git a/src/lib/account/address.ts b/src/lib/account/address.ts index e531d38..b1de2d8 100644 --- a/src/lib/account/address.ts +++ b/src/lib/account/address.ts @@ -28,8 +28,8 @@ export class Address { if (typeof value !== 'string' && !(value instanceof ArrayBuffer) && !(value instanceof Uint8Array)) { throw new TypeError('Invalid address input', { cause: value }) } - if (typeof value === 'string') { - if (hex.is(value) && value.length === ACCOUNT_KEY_HEX_LENGTH) { + if (hex.is(value)) { + if (value.length === ACCOUNT_KEY_HEX_LENGTH) { this.#address = (this.constructor as typeof Address).fromPublicKey(hex.toBuffer(value)) } else { _validate(value)