utils: improve isBytes

This commit is contained in:
Paul Miller 2023-12-10 23:04:11 +00:00
parent ada1ea5a19
commit 30f68c9e54
No known key found for this signature in database
GPG Key ID: 697079DA6878B89B

@ -16,8 +16,11 @@ export type CHash = {
};
export type FHash = (message: Uint8Array | string) => Uint8Array;
export function isBytes(a: any): a is Uint8Array {
return a instanceof Uint8Array || a.constructor.name === 'Uint8Array';
export function isBytes(a: unknown): a is Uint8Array {
return (
a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
);
}
// Array where index 0xf0 (240) is mapped to string 'f0'