Allow Moment with BE/LE hex encoding (#933)

* Allow Moment with BE/LE hex encoding

* description clarification
This commit is contained in:
Jaco Greeff
2019-05-17 17:13:11 +02:00
committed by GitHub
parent 37911b6684
commit 9f258ff4c7
2 changed files with 18 additions and 2 deletions
@@ -41,6 +41,18 @@ describe('Moment', () => {
.startsWith('Thu Jan 01 1970') // The time depends on the timezone this test is run in
).toBe(true);
});
it('encodes default BE hex', () => {
expect(
new Moment(3).toHex()
).toEqual('0x0000000000000003');
});
it('encodes options LE hex', () => {
expect(
new Moment(3).toHex(true)
).toEqual('0x0300000000000000');
});
});
describe('utils', () => {
+6 -2
View File
@@ -83,8 +83,12 @@ export default class Moment extends Date implements Codec {
/**
* @description Returns a hex string representation of the value
*/
toHex (): string {
return bnToHex(this.toBn(), BITLENGTH);
toHex (isLe: boolean = false): string {
return bnToHex(this.toBn(), {
bitLength: BITLENGTH,
isLe,
isNegative: false
});
}
/**