Allow hex or number[] -> u8a conversion for 'bytes' (#155)
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user