"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Encoder = void 0;
var base64_1 = require("multiformats/bases/base64");
var textEncoder = new TextEncoder();
var textDecoder = new TextDecoder();
/**
 * Utility class for encoding/converting data into various formats.
 */
var Encoder = /** @class */ (function () {
    function Encoder() {
    }
    Encoder.base64UrlToBytes = function (base64urlString) {
        var content = base64_1.base64url.baseDecode(base64urlString);
        return content;
    };
    Encoder.base64UrlToObject = function (base64urlString) {
        var payloadBytes = base64_1.base64url.baseDecode(base64urlString);
        var payloadString = Encoder.bytesToString(payloadBytes);
        var payloadObject = JSON.parse(payloadString);
        return payloadObject;
    };
    Encoder.bytesToBase64Url = function (bytes) {
        var base64UrlString = base64_1.base64url.baseEncode(bytes);
        return base64UrlString;
    };
    Encoder.bytesToString = function (content) {
        var bytes = textDecoder.decode(content);
        return bytes;
    };
    Encoder.bytesToObject = function (content) {
        var bytes = textDecoder.decode(content);
        var payloadObject = JSON.parse(bytes);
        return payloadObject;
    };
    Encoder.objectToBytes = function (obj) {
        var objectString = JSON.stringify(obj);
        var objectBytes = textEncoder.encode(objectString);
        return objectBytes;
    };
    Encoder.stringToBase64Url = function (content) {
        var bytes = textEncoder.encode(content);
        var base64UrlString = base64_1.base64url.baseEncode(bytes);
        return base64UrlString;
    };
    Encoder.stringToBytes = function (content) {
        var bytes = textEncoder.encode(content);
        return bytes;
    };
    return Encoder;
}());
exports.Encoder = Encoder;
//# sourceMappingURL=encoder.js.map