]> git.codecow.com Git - libnemo.git/commitdiff
Extend Hex type to accomodate string expectations.
authorChris Duncan <chris@codecow.com>
Fri, 7 Aug 2026 04:31:00 +0000 (21:31 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 7 Aug 2026 04:31:00 +0000 (21:31 -0700)
src/index.ts
src/lib/account/address.ts

index 244c464c7be7a7470109f880ba324a459f51ff3b..65b53e9ba7b4646d56410887d70ad5a85aa6435c 100644 (file)
@@ -3,7 +3,7 @@
 
 declare global {
        type Bytes = Uint8Array<ArrayBuffer> | Buffer<ArrayBuffer>
-       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'
 }
index e531d38ce3aff391706a98ae1462b7f31fd3da2f..b1de2d8fcb94a9545e392b765c9c489288f56790 100644 (file)
@@ -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)