From dc567fa7f3c78ca7e271716125bf0510cfac099f Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 7 Mar 2017 17:30:32 +0100 Subject: [PATCH] signing keys are stored in hex so encode and decode them --- www/common/encode.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 www/common/encode.js diff --git a/www/common/encode.js b/www/common/encode.js new file mode 100644 index 000000000..44b2071ba --- /dev/null +++ b/www/common/encode.js @@ -0,0 +1,19 @@ +define([], function () { + var exports = {}; + + var hexToUint8Array = exports.hexToUint8Array = function (s) { + // if not hex or odd number of characters + if (!/[a-fA-F0-9]+/.test(s) || s.length % 2) { throw new Error("string is not hex"); } + return s.split(/([0-9a-fA-F]{2})/) + .filter(function (x) { return x; }) + .map(function (x) { return Number('0x' + x); }); + }; + + var uint8ArrayToHex = exports.uint8ArrayToHex = function (a) { + return a.reduce(function(memo, i) { + return memo + ((i < 16) ? '0' : '') + i.toString(16); + }, ''); + }; + + return exports; +});