INNER CODE UNIT · JavaScript
hexEncode
dfinity/examples · motoko/vetkeys/basic_vetkd/frontend/src/main.js:45
function hexEncode(bytes) {
return Array.from(bytes)
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
}
function hexDecode(str) {
const matches = str.match(/.{1,2}/g);
if (!matches) throw new Error("Invalid hex string");
return new Uint8Array(matches.map((b) => parseInt(b, 16)));
}
async function handleFetchVetKey() {
if (!myPrincipal) {
setStatus("sym-status", "Please log in first.");
return;
}
setStatus("sym-status", "Fetching VetKey…");