\r
import { ALPHABET } from './constants'\r
\r
-const encoder = new TextEncoder()\r
-const decoder = new TextDecoder()\r
-\r
export class base32 {\r
/**\r
* Converts a base32 string to a Uint8Array of bytes.\r
* @returns {string} UTF-8 encoded text string\r
*/\r
static toUtf8 (bytes: Uint8Array): string {\r
- return decoder.decode(bytes)\r
+ return new TextDecoder().decode(bytes)\r
}\r
}\r
\r
}\r
}\r
\r
+export class obj {\r
+ /**\r
+ * Convert a numerically-indexed object of 8-bit values to a Uint8Array of bytes.\r
+ *\r
+ * @param {object} obj - Object to convert\r
+ * @returns {Uint8Array} Byte array representation of the input object\r
+ */\r
+ static toBytes (obj: { [key: number]: number }): Uint8Array {\r
+ const values = Object.keys(obj)\r
+ .map(key => +key)\r
+ .sort((a, b) => a - b)\r
+ .map(i => obj[i])\r
+ return new Uint8Array(values)\r
+ }\r
+}\r
+\r
export class utf8 {\r
/**\r
* Convert a UTF-8 text string to a Uint8Array of bytes.\r
* @returns {Uint8Array} Byte array representation of the input string\r
*/\r
static toBytes (utf8: string): Uint8Array {\r
- return encoder.encode(utf8)\r
+ return new TextEncoder().encode(utf8)\r
}\r
\r
/**\r
}\r
}\r
\r
-export class obj {\r
- /**\r
- * Convert a numerically-indexed object of 8-bit values to a Uint8Array of bytes.\r
- *\r
- * @param {object} obj - Object to convert\r
- * @returns {Uint8Array} Byte array representation of the input object\r
- */\r
- static toBytes (obj: { [key: number]: number }): Uint8Array {\r
- const values = Object.keys(obj)\r
- .map(key => +key)\r
- .sort((a, b) => a - b)\r
- .map(i => obj[i])\r
- return new Uint8Array(values)\r
- }\r
-}\r
-\r
export default `\r
const base32 = ${base32}\r
const bin = ${bin}\r
+ const buffer = ${buffer}\r
const bytes = ${bytes}\r
const dec = ${dec}\r
const hex = ${hex}\r