From 2ac9b42b2d11d0da739164ecc7e1062d128a0832 Mon Sep 17 00:00:00 2001 From: Dadepo Aderemi Date: Sun, 6 Mar 2022 12:51:36 +0100 Subject: [PATCH] Removing 0x prefix in hexToBytes --- src/utils.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 0583236..67d81a0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,16 +1,23 @@ // buf.toString('hex') -> toHex(buf) -import { assertBytes } from "@noble/hashes/utils"; +import { assertBytes, hexToBytes as _hexToBytes } from "@noble/hashes/utils"; export { assertBool, assertBytes, bytesToHex, bytesToHex as toHex, concatBytes, - hexToBytes, createView, utf8ToBytes } from "@noble/hashes/utils"; +export function hexToBytes(data: string): Uint8Array { + if (data.startsWith("0x")) { + return _hexToBytes(data.substring(2)); + } else { + return _hexToBytes(data); + } +} + // buf.toString('utf8') -> bytesToUtf8(buf) export function bytesToUtf8(data: Uint8Array): string { if (!(data instanceof Uint8Array)) {