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