* Pull api-* packages into lerna repo * Bootstrap with hoist * Update jest alias config * Add api-jsonrpc * Pull in jsonrpc * Update badges * Don't hoist, use workspaces * .eslintrc to root * Cleanups, build from root * Shorthand commands * Update to @polkadot/dev 0.9.1 * Update description
34 lines
829 B
JavaScript
34 lines
829 B
JavaScript
// ISC, Copyright 2017 Jaco Greeff
|
|
// @flow
|
|
|
|
const { hexAddPrefix, hexHasPrefix, hexStripPrefix } = require('@polkadot/util/hex');
|
|
|
|
const H64_ZERO: string = '00000000000000000000000000000000';
|
|
const H128_ZERO: string = `${H64_ZERO}${H64_ZERO}`;
|
|
const H256_ZERO: string = `${H128_ZERO}${H128_ZERO}`;
|
|
// const H512_ZERO: string = `${H256_ZERO}${H256_ZERO}`;
|
|
|
|
function leftHexPad (value: ?string, bitLength: number): string {
|
|
const length = 2 * bitLength / 8;
|
|
|
|
if (hexHasPrefix(value)) {
|
|
value = hexStripPrefix(value);
|
|
}
|
|
|
|
return hexAddPrefix(`${H256_ZERO}${value || ''}`.slice(-length));
|
|
}
|
|
|
|
function formatH160 (value: ?string): string {
|
|
return leftHexPad(value, 160);
|
|
}
|
|
|
|
function formatH256 (value: ?string): string {
|
|
return leftHexPad(value, 256);
|
|
}
|
|
|
|
module.exports = {
|
|
leftHexPad,
|
|
formatH160,
|
|
formatH256
|
|
};
|