@tgrospic/rnode-http-js
Version:
HTTP client support for RNode
74 lines • 2.46 kB
JavaScript
;
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeAscii = exports.decodeBase58safe = exports.encodeBase58 = exports.decodeBase16 = exports.encodeBase16 = void 0;
var bs58_1 = __importDefault(require("bs58"));
/**
* Encode bytes to base 16 string.
*/
var encodeBase16 = function (bytes) {
return Array.from(bytes).map(function (x) { return (x & 0xff).toString(16).padStart(2, '0'); }).join('');
};
exports.encodeBase16 = encodeBase16;
/**
* Decode base 16 string to bytes.
*/
var decodeBase16 = function (hexStr) {
var removed0x = hexStr.replace(/^0x/, '');
var byte2hex = function (_a, x) {
var _b = __read(_a, 2), arr = _b[0], bhi = _b[1];
return (bhi ? [__spread(arr, [parseInt("" + bhi + x, 16)]), ''] : [arr, x]);
};
var _a = __read(Array.from(removed0x).reduce(byte2hex, [[], '']), 1), resArr = _a[0];
return Uint8Array.from(resArr);
};
exports.decodeBase16 = decodeBase16;
/**
* Encode base 16 string to base 58.
*/
var encodeBase58 = function (hexStr) {
var bytes = exports.decodeBase16(hexStr);
return bs58_1.default.encode(bytes);
};
exports.encodeBase58 = encodeBase58;
/**
* Decode base 58 string (handle errors).
*/
var decodeBase58safe = function (str) { try {
return bs58_1.default.decode(str);
}
catch (_a) {
return void 666;
} };
exports.decodeBase58safe = decodeBase58safe;
/**
* Decode ASCII string to bytes.
*/
var decodeAscii = function (str) {
if (str === void 0) { str = ''; }
return Array.from(str).map(function (x) { return ("" + x).charCodeAt(0); });
};
exports.decodeAscii = decodeAscii;
//# sourceMappingURL=codecs.js.map