Skip to content

Commit

Permalink
Improve type checks for bigints
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Nov 22, 2024
1 parent 9d3943f commit cee168d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ const Point = secp.ProjectivePoint;
const base58check = createBase58check(sha256);

function bytesToNumber(bytes: Uint8Array): bigint {
return BigInt(`0x${bytesToHex(bytes)}`);
abytes(bytes);
const h = bytes.length === 0 ? '0' : bytesToHex(bytes);
return BigInt('0x' + h);
}

function numberToBytes(num: bigint): Uint8Array {
if (typeof num !== 'bigint') throw new Error('bigint expected');
return hexToBytes(num.toString(16).padStart(64, '0'));
}

Expand Down

0 comments on commit cee168d

Please sign in to comment.