Skip to content

Commit

Permalink
Fix hash string representation in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Jun 15, 2024
1 parent 9fd0388 commit c86c330
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/cli/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ export function hasParameter(p: string[], n: number): boolean {
export function userInput(t: string): string {
return prompt(t) || "";
}
export function toHexString(bytes: Uint8Array): string {
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(
"",
);
export function toHexString(bytes: number): string {
// Ensure the input is a valid number
if (typeof bytes !== "number" || isNaN(bytes)) {
throw new Error("Input must be a valid number");
}

// Convert the number to an unsigned 32-bit integer
const unsignedNumber = bytes >>> 0;

// Use toString(16) for hexadecimal conversion
const hexString = unsignedNumber.toString(16);

// Pad with zeros if needed
return hexString.padStart(2, "0");
}
export function printTransaction(
transaction: KVTransactionResult<unknown>,
Expand Down

0 comments on commit c86c330

Please sign in to comment.