-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
common.ts
27 lines (24 loc) · 959 Bytes
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// @dev The Fuel testing Merkle trees.
/// A set of useful helper methods for testing and deploying Merkle trees.
import { toHex } from '@fuel-ts/math';
export const EMPTY = '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
export const ZERO = '0x0000000000000000000000000000000000000000000000000000000000000000';
export const MAX_HEIGHT = 256;
/**
* Convert integer to 32 bytes hex string
*/
export function uintToBytes32(i: number): string {
const value = toHex(i);
let trimmedValue = value.slice(2);
trimmedValue = '0'.repeat(64 - trimmedValue.length).concat(trimmedValue);
return '0x'.concat(trimmedValue);
}
/**
* Pad an uint left side to be 32 bytes
*/
export function padUint(value: bigint): string {
// uint256 is encoded as 32 bytes, so pad that string.
let trimmedValue = toHex(value).slice(2);
trimmedValue = '0'.repeat(64 - trimmedValue.length).concat(trimmedValue);
return '0x'.concat(trimmedValue);
}