Allow hex or number[] -> u8a conversion for 'bytes' (#155)

This commit is contained in:
Jaco Greeff
2018-06-28 17:15:09 +02:00
committed by GitHub
parent d5f4f1dea1
commit 544034bf2e
5 changed files with 14 additions and 6 deletions
@@ -10,4 +10,10 @@ describe('bytesDecode', () => {
bytesDecode('0x0012345600')
).toEqual(new Uint8Array([0x00, 0x12, 0x34, 0x56, 0x00]));
});
it('decodes byte array (number', () => {
expect(
bytesDecode([0x00, 0x12, 0x34, 0x56, 0x00])
).toEqual(new Uint8Array([0x00, 0x12, 0x34, 0x56, 0x00]));
});
});
@@ -8,5 +8,7 @@ import { JsonBytes } from '../types';
import hexToU8a from '@polkadot/util/hex/toU8a';
export default function bytesDecode (value: JsonBytes): Bytes {
return hexToU8a(value);
return Array.isArray(value)
? new Uint8Array(value)
: hexToU8a(value);
}
+1 -1
View File
@@ -5,7 +5,7 @@
export type JsonBnType = string;
export type JsonHash = string;
export type JsonBytes = string;
export type JsonBytes = string | Array<number>;
export type JsonH160 = JsonHash;
export type JsonH256 = JsonHash;
export type JsonH512 = JsonHash;