Bringing back js-sha3 to fix in-browser signing (#4063)

* Bring back Uint8Array sha3 support

* Added SHA3 test with HEX encoding

* Rename hex2Ascii => hexToAscii
Add tests or the api/util/format functions
Use js-sha3 for sha3 with hex encoding support

* Adding Uint8Array test

* Fixing Transaction import
This commit is contained in:
Tomasz Drwięga
2017-01-06 15:36:24 +01:00
committed by Jaco Greeff
parent 52d3633473
commit f6349187ef
9 changed files with 79 additions and 25 deletions

View File

@@ -20,15 +20,21 @@ export function bytesToHex (bytes) {
return '0x' + bytes.map((b) => ('0' + b.toString(16)).slice(-2)).join('');
}
export function hex2Ascii (_hex) {
const hex = /^(?:0x)?(.*)$/.exec(_hex.toString())[1];
export function hexToBytes (hex) {
const raw = toHex(hex).slice(2);
const bytes = [];
let str = '';
for (let i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
for (let i = 0; i < raw.length; i += 2) {
bytes.push(parseInt(raw.substr(i, 2), 16));
}
return bytes;
}
export function hexToAscii (hex) {
const bytes = hexToBytes(hex);
const str = bytes.map((byte) => String.fromCharCode(byte)).join('');
return str;
}