Add u8a <-> BN endian (#95)
This commit is contained in:
@@ -10,7 +10,7 @@ const u8aToHex = require('./toHex');
|
||||
|
||||
/**
|
||||
@name u8aToBn
|
||||
@signature u8aToHex (value?: Uint8Array): BN
|
||||
@signature u8aToHex (value?: Uint8Array, isLe: boolean = false): BN
|
||||
@summary Creates a BN from a Uint8Array object.
|
||||
@description
|
||||
`UInt8Array` input values return the actual BN. `null` or `undefined` values returns an `0x0` value.
|
||||
@@ -19,8 +19,9 @@ const u8aToHex = require('./toHex');
|
||||
|
||||
u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
*/
|
||||
module.exports = function u8aToBn (value?: Uint8Array): BN {
|
||||
module.exports = function u8aToBn (value?: Uint8Array, isLe: boolean = false): BN {
|
||||
return hexToBn(
|
||||
u8aToHex(value)
|
||||
u8aToHex(value),
|
||||
isLe
|
||||
);
|
||||
};
|
||||
|
||||
@@ -13,6 +13,15 @@ describe('u8aToBn', () => {
|
||||
).toEqual('1234');
|
||||
});
|
||||
|
||||
it('converts values (little-endian)', () => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array([0x12, 0x34]),
|
||||
true
|
||||
).toString(16)
|
||||
).toEqual('3412');
|
||||
});
|
||||
|
||||
it('converts empty', () => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
|
||||
Reference in New Issue
Block a user