2019-05-15 01:25:46 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { arrayify, BytesLike } from "@ethersproject/bytes";
|
|
|
|
|
|
|
|
export function decode(textData: string): Uint8Array {
|
|
|
|
textData = atob(textData);
|
2019-11-01 17:33:51 +03:00
|
|
|
const data = [];
|
2019-05-15 01:25:46 +03:00
|
|
|
for (let i = 0; i < textData.length; i++) {
|
|
|
|
data.push(textData.charCodeAt(i));
|
|
|
|
}
|
|
|
|
return arrayify(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function encode(data: BytesLike): string {
|
|
|
|
data = arrayify(data);
|
|
|
|
let textData = "";
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
textData += String.fromCharCode(data[i]);
|
|
|
|
}
|
|
|
|
return btoa(textData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|