Skip to content

Commit 8aae2cf

Browse files
committed
add u8a to hex
1 parent 6ad314f commit 8aae2cf

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ <h4>Sub-Account Generator</h4>
144144
<div type="text" class="form-control" id="subid-subid">Sub-Account
145145
</div>
146146
</div>
147+
<h4>u8 Array to Hex</h4>
148+
<div class="input-group">
149+
<input type="text" class="form-control" id="u8a-u82h"
150+
placeholder="Comma Separated u8a Array">
151+
<div class="input-group-prepend">
152+
<span class="input-group-text" id="addon-wrapping">&#8644;</span>
153+
</div>
154+
<input type="text" class="form-control" id="hex-u82h" placeholder="Hex">
155+
</div>
147156
</div>
148157
</div>
149158
</div>

utilities.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,34 @@ function subAccountId() {
273273
console.error(e);
274274
}
275275
}
276+
277+
/* u8a to Hex */
278+
let u82h = {
279+
"u8a": document.getElementById("u8a-u82h"),
280+
"hex": document.getElementById("hex-u82h")
281+
};
282+
283+
u82h.u8a.addEventListener("input", u8a2hex);
284+
u82h.hex.addEventListener("input", hex2u8a);
285+
286+
function u8a2hex() {
287+
try {
288+
let array = u82h.u8a.value.replace(/ /g, "").split(",").filter(e => e);
289+
let u8array = new Uint8Array(array);
290+
u82h.hex.value = u8aToHex(u8array);
291+
} catch (e) {
292+
u82h.hex.value = "Error";
293+
console.error(e);
294+
}
295+
}
296+
297+
function hex2u8a() {
298+
try {
299+
let array = u82h.hex.value.match(/.{1,2}/g).map(byte => parseInt(byte, 16));
300+
let u8a = new Uint8Array(array);
301+
u82h.u8a.value = u8a;
302+
} catch (e) {
303+
u82h.hex.value = "Error";
304+
console.error(e);
305+
}
306+
}

0 commit comments

Comments
 (0)