'use strict';

class TextEncoder {
    constructor() {
        this.encoding = "utf-8";
    }
    encode(data) {
        return Uint8Array.from(unescape(encodeURIComponent(data)).split(""), c => c.charCodeAt(0));
    }
}

const tables = {
    standard: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
    url: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
};
function encode$1(value, standard = "standard", padding = "") {
    if (typeof value == "string")
        value = new TextEncoder().encode(value);
    const table = tables[standard];
    const result = [];
    for (let c = 0; c < value.length; c += 3) {
        const c0 = value[c];
        const c1 = c + 1 < value.length ? value[c + 1] : 0;
        const c2 = c + 2 < value.length ? value[c + 2] : 0;
        result.push(table[c0 >>> 2]);
        result.push(table[((c0 & 3) << 4) | (c1 >>> 4)]);
        result.push(table[((c1 & 15) << 2) | (c2 >>> 6)]);
        result.push(table[c2 & 63]);
    }
    const length = Math.ceil((value.length / 3) * 4);
    return result.join("").substr(0, length) + padding.repeat(result.length - length);
}
function decode(value, standard = "standard") {
    while (value.endsWith("=") && value.length > 0)
        value = value.substr(0, value.length - 1);
    const table = tables[standard];
    const data = value.split("").map(c => table.indexOf(c));
    const result = new Uint8Array(Math.floor((data.length / 4) * 3));
    for (let c = 0; c < result.length; c += 3) {
        const d0 = data.shift() || 0;
        const d1 = data.shift() || 0;
        const d2 = data.shift() || 0;
        const d3 = data.shift() || 0;
        result[c] = (d0 << 2) | (d1 >>> 4);
        result[c + 1] = ((d1 & 15) << 4) | (d2 >>> 2);
        result[c + 2] = ((d2 & 3) << 6) | d3;
    }
    return result;
}

const crypto = typeof window != "undefined"
    ? window.crypto || window.msCrypto
    : self.crypto || self.msCrypto;

function encode(value, length) {
    const data = typeof value == "string" ? new TextEncoder().encode(value) : value;
    let result = [];
    for (const d of data)
        result.push(Math.floor(d / 16).toString(16), (d % 16).toString(16));
    if (length)
        result = result.slice(0, length);
    return result.join("");
}

var __awaiter$8 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class Digest {
    constructor(algorithm) {
        this.algorithm = algorithm;
    }
    get length() {
        return Digest.lengths[this.algorithm];
    }
    digest(data, base = "standard") {
        return __awaiter$8(this, void 0, void 0, function* () {
            let result;
            if (typeof data == "string") {
                const digest = yield this.digest(new TextEncoder().encode(data));
                result = base == 16 ? encode(digest) : encode$1(digest, base);
            }
            else
                result = new Uint8Array(yield crypto.subtle.digest(this.algorithm, data));
            return result;
        });
    }
}
Digest.lengths = {
    "SHA-1": 128,
    "SHA-256": 256,
    "SHA-384": 384,
    "SHA-512": 512,
};

var Encrypted;
(function (Encrypted) {
    function is(value) {
        return (typeof value == "object" &&
            (value.key == undefined || typeof value.key == "string") &&
            typeof value.value == "string" &&
            typeof value.salt == "string");
    }
    Encrypted.is = is;
    function stringify(encrypted) {
        encrypted.key = encrypted.key && encrypted.key.length != 4 ? encrypted.key.slice(-2) : encrypted.key;
        return [encrypted.key, encrypted.salt, encrypted.value].join(".");
    }
    Encrypted.stringify = stringify;
    function parse(encryptedString) {
        const splitted = encryptedString.split(".");
        const encrypted = { key: splitted[0], salt: splitted[1], value: splitted[2] };
        return Encrypted.is(encrypted) ? encrypted : undefined;
    }
    Encrypted.parse = parse;
})(Encrypted || (Encrypted = {}));

exports.Identifier = void 0;
(function (Identifier) {
    function is(value, length) {
        return (typeof value == "string" &&
            (length == undefined || value.length == length) &&
            Array.from(value).every(c => (c >= "0" && c <= "9") || (c >= "A" && c <= "Z") || (c >= "a" && c <= "z") || c == "-" || c == "_"));
    }
    Identifier.is = is;
    function fromBinary(identifier) {
        return encode$1(identifier, "url");
    }
    Identifier.fromBinary = fromBinary;
    function toBinary(identifier) {
        return decode(identifier, "url");
    }
    Identifier.toBinary = toBinary;
    function generate(length) {
        return fromBinary(crypto.getRandomValues(new Uint8Array((length / 4) * 3)));
    }
    Identifier.generate = generate;
    function fromHexadecimal(identifier) {
        if (identifier.length % 2 == 1)
            identifier += "0";
        const result = new Uint8Array(identifier.length / 2);
        for (let index = 0; index < result.length; index++)
            result[index] = Number.parseInt(identifier[index * 2], 16) * 16 + Number.parseInt(identifier[index * 2 + 1], 16);
        return fromBinary(result);
    }
    Identifier.fromHexadecimal = fromHexadecimal;
    function toHexadecimal(identifier, length) {
        const data = decode(identifier, "url");
        let result = [];
        for (const d of data)
            result.push(Math.floor(d / 16).toString(16), (d % 16).toString(16));
        if (length)
            result = result.slice(0, length);
        return result.join("");
    }
    Identifier.toHexadecimal = toHexadecimal;
    Identifier.length = [
        4,
        8,
        12,
        16,
        20,
        24,
        28,
        32,
        36,
        40,
        44,
        48,
        52,
        56,
        60,
        64,
        68,
        72,
        76,
        80,
        84,
        88,
        92,
        96,
        100,
        104,
        108,
        112,
        116,
        120,
        124,
        128,
    ];
    (function (Length) {
        function is(value) {
            return typeof value == "number" && value >= 4 && value <= 128 && (value & 252) == value;
        }
        Length.is = is;
    })(Identifier.Length || (Identifier.Length = {}));
})(exports.Identifier || (exports.Identifier = {}));

var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var Password;
(function (Password) {
    function is(value) {
        return (typeof value == "string" ||
            (typeof value == "object" && typeof value.hash == "string" && typeof value.salt == "string"));
    }
    Password.is = is;
    function hash(algorithm, password, salt) {
        return __awaiter$7(this, void 0, void 0, function* () {
            if (!salt)
                salt = encode$1(crypto.getRandomValues(new Uint8Array(64)));
            return {
                hash: yield algorithm.sign(salt + password),
                salt,
            };
        });
    }
    Password.hash = hash;
    function verify(algorithm, hash, password) {
        return __awaiter$7(this, void 0, void 0, function* () {
            return (yield Password.hash(algorithm, password, hash.salt)).hash == hash.hash;
        });
    }
    Password.verify = verify;
    (function (Hashed) {
        function is(value) {
            return typeof value == "object" && typeof value.hash == "string" && typeof value.salt == "string";
        }
        Hashed.is = is;
    })(Password.Hashed || (Password.Hashed = {}));
})(Password || (Password = {}));

var RandomValue;
(function (RandomValue) {
    function generate(array) {
        return crypto.getRandomValues(array);
    }
    RandomValue.generate = generate;
})(RandomValue || (RandomValue = {}));

var Algorithm$1;
(function (Algorithm) {
    function is(value) {
        return value == "HMAC" || value == "RSA" || value == "ECDSA" || value == "RSA-PSS";
    }
    Algorithm.is = is;
})(Algorithm$1 || (Algorithm$1 = {}));

var __awaiter$6 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class Base {
    sign(data) {
        return __awaiter$6(this, void 0, void 0, function* () {
            return typeof data == "string"
                ? encode$1(yield this.signBinary(new TextEncoder().encode(data)), "url")
                : this.signBinary(data);
        });
    }
    verify(data, signature) {
        if (typeof signature == "string")
            signature = decode(signature, "url");
        return typeof data == "string"
            ? this.verifyBinary(new TextEncoder().encode(data), signature)
            : this.verifyBinary(data, signature);
    }
}

var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class ECDSA extends Base {
    constructor(hash, publicKey, privateKey) {
        super();
        this.hash = hash;
        if (publicKey) {
            if (typeof publicKey == "string")
                publicKey = decode(publicKey);
            this.publicKey = crypto.subtle.importKey("spki", publicKey, { name: "ECDSA", namedCurve: hash.replace("SHA", "P") == "P-512" ? "P-521" : hash.replace("SHA", "P") }, false, ["verify"]);
        }
        if (privateKey) {
            if (typeof privateKey == "string")
                privateKey = decode(privateKey);
            this.privateKey = crypto.subtle.importKey("pkcs8", privateKey, { name: "ECDSA", namedCurve: hash.replace("SHA", "P") == "P-512" ? "P-521" : hash.replace("SHA", "P") }, true, ["sign", "verify"]);
        }
    }
    signBinary(data) {
        return __awaiter$5(this, void 0, void 0, function* () {
            return new Uint8Array(yield crypto.subtle.sign({ name: "ECDSA", hash: { name: this.hash } }, yield this.privateKey, data));
        });
    }
    verifyBinary(data, signature) {
        return __awaiter$5(this, void 0, void 0, function* () {
            return crypto.subtle.verify({ name: "ECDSA", hash: { name: this.hash } }, yield this.publicKey, signature, data);
        });
    }
}

var Hash;
(function (Hash) {
    function is(value) {
        return value == "SHA-1" || value == "SHA-256" || value == "SHA-384" || value == "SHA-512";
    }
    Hash.is = is;
})(Hash || (Hash = {}));

var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class Symmetric$1 extends Base {
    verifyBinary(data, signature) {
        return __awaiter$4(this, void 0, void 0, function* () {
            return encode$1(yield this.signBinary(data), "url") == encode$1(signature, "url");
        });
    }
}

var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class HMAC extends Symmetric$1 {
    constructor(hash, key) {
        super();
        this.hash = hash;
        if (typeof key == "string")
            key = decode(key, "url");
        this.key = crypto.subtle.importKey("raw", key, { name: "HMAC", hash: { name: hash } }, false, ["sign", "verify"]);
    }
    signBinary(data) {
        return __awaiter$3(this, void 0, void 0, function* () {
            return new Uint8Array(yield crypto.subtle.sign("HMAC", yield this.key, data));
        });
    }
}

class None extends Symmetric$1 {
    signBinary(_) {
        return Promise.resolve(new Uint8Array(0));
    }
}

var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class RSA extends Base {
    constructor(hash, publicKey, privateKey) {
        super();
        this.hash = hash;
        if (publicKey) {
            if (typeof publicKey == "string")
                publicKey = decode(publicKey);
            this.publicKey = crypto.subtle.importKey("spki", publicKey, { name: "RSASSA-PKCS1-v1_5", hash: { name: hash } }, false, ["verify"]);
        }
        if (privateKey) {
            if (typeof privateKey == "string")
                privateKey = decode(privateKey);
            this.privateKey = crypto.subtle.importKey("pkcs8", privateKey, { name: "RSASSA-PKCS1-v1_5", hash: { name: hash } }, true, ["sign"]);
        }
    }
    signBinary(data) {
        return __awaiter$2(this, void 0, void 0, function* () {
            return new Uint8Array(yield crypto.subtle.sign("RSASSA-PKCS1-v1_5", yield this.privateKey, data));
        });
    }
    verifyBinary(data, signature) {
        return __awaiter$2(this, void 0, void 0, function* () {
            return crypto.subtle.verify("RSASSA-PKCS1-v1_5", yield this.publicKey, signature, data);
        });
    }
}

var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class RSAPSS extends Base {
    constructor(hash, publicKey, privateKey) {
        super();
        this.hash = hash;
        if (publicKey) {
            if (typeof publicKey == "string")
                publicKey = decode(publicKey);
            this.publicKey = crypto.subtle.importKey("spki", publicKey, { name: "RSA-PSS", hash: { name: hash } }, false, [
                "verify",
            ]);
        }
        if (privateKey) {
            if (typeof privateKey == "string")
                privateKey = decode(privateKey);
            this.privateKey = crypto.subtle.importKey("pkcs8", privateKey, { name: "RSA-PSS", hash: { name: hash } }, true, [
                "sign",
                "verify",
            ]);
        }
    }
    signBinary(data) {
        return __awaiter$1(this, void 0, void 0, function* () {
            return new Uint8Array(yield crypto.subtle.sign({ name: "RSA-PSS", saltLength: 128 }, yield this.privateKey, data));
        });
    }
    verifyBinary(data, signature) {
        return __awaiter$1(this, void 0, void 0, function* () {
            return crypto.subtle.verify({ name: "RSA-PSS", saltLength: 128 }, yield this.publicKey, signature, data);
        });
    }
}

var Signer;
(function (Signer) {
    (function (Algorithm) {
        Algorithm.is = Algorithm$1.is;
    })(Signer.Algorithm || (Signer.Algorithm = {}));
    (function (Hash$1) {
        Hash$1.is = Hash.is;
    })(Signer.Hash || (Signer.Hash = {}));
    function create(algorithm, hash, ...keys) {
        let result;
        switch (algorithm) {
            case "HMAC":
                if (hash != undefined)
                    result = new HMAC(hash, keys[0]);
                break;
            case "RSA":
                if (hash != undefined)
                    result = new RSA(hash, keys[0], keys[1]);
                break;
            case "RSA-PSS":
                if (hash != undefined)
                    result = new RSAPSS(hash, keys[0], keys[1]);
                break;
            case "ECDSA":
                if (hash != undefined)
                    result = new ECDSA(hash, keys[0], keys[1]);
                break;
            case "None":
                result = new None();
        }
        return result;
    }
    Signer.create = create;
})(Signer || (Signer = {}));

if (!Uint8Array.__proto__.from) {
    (() => {
        Uint8Array.__proto__.from = function (object, theFunction, thisObject) {
            const typedArrayClass = Uint8Array.__proto__;
            if (typeof this !== "function") {
                throw new TypeError("# is not a constructor");
            }
            if (this.__proto__ !== typedArrayClass) {
                throw new TypeError("this is not a typed array.");
            }
            theFunction = theFunction || (element => element);
            if (typeof theFunction !== "function") {
                throw new TypeError("specified argument is not a function");
            }
            object = Object(object);
            if (!object.length) {
                return new this(0);
            }
            let copyData = [];
            for (const data of copyData) {
                copyData.push(data);
            }
            copyData = copyData.map(theFunction, thisObject);
            const typedArray = new this(copyData.length);
            for (let i = 0; i < typedArray.length; i++) {
                typedArray[i] = copyData[i];
            }
            return typedArray;
        };
    })();
}

var Converter;
(function (Converter) {
    function is(value) {
        return typeof value == "object" && Object.entries(value).every(v => typeof v == "function");
    }
    Converter.is = is;
})(Converter || (Converter = {}));

var Crypto;
(function (Crypto) {
    function is(value) {
        return Array.isArray(value) && value.every(v => typeof v == "string");
    }
    Crypto.is = is;
})(Crypto || (Crypto = {}));

var Renamer;
(function (Renamer) {
    function is(value) {
        return typeof value == "object" && Object.entries(value).every(thing => typeof thing[1] == "string");
    }
    Renamer.is = is;
})(Renamer || (Renamer = {}));

exports.Creatable = void 0;
(function (Creatable) {
    function is(value) {
        return Crypto.is(value) || Converter.is(value) || Renamer.is(value);
    }
    Creatable.is = is;
    (function (Converter$1) {
        Converter$1.is = Converter.is;
    })(Creatable.Converter || (Creatable.Converter = {}));
    (function (Crypto$1) {
        Crypto$1.is = Crypto.is;
    })(Creatable.Crypto || (Creatable.Crypto = {}));
    (function (Renamer$1) {
        Renamer$1.is = Renamer.is;
    })(Creatable.Renamer || (Creatable.Renamer = {}));
})(exports.Creatable || (exports.Creatable = {}));

exports.Transformer = void 0;
(function (Transformer) {
    function is(value) {
        return typeof value == "object" && typeof value.apply == "function" && typeof value.reverse == "function";
    }
    Transformer.is = is;
    function create(transformer) {
        return {
            apply: transformer.apply ? transformer.apply : (v) => v,
            reverse: transformer.reverse ? transformer.reverse : (v) => v,
        };
    }
    Transformer.create = create;
})(exports.Transformer || (exports.Transformer = {}));

var Asymmetric;
(function (Asymmetric) {
    function is(value) {
        return (value == "RS256" ||
            value == "RS384" ||
            value == "RS512" ||
            value == "ES256" ||
            value == "ES384" ||
            value == "ES512" ||
            value == "PS256" ||
            value == "PS384" ||
            value == "PS512");
    }
    Asymmetric.is = is;
})(Asymmetric || (Asymmetric = {}));

var Symmetric;
(function (Symmetric) {
    function is(value) {
        return value == "HS256" || value == "HS384" || value == "HS512";
    }
    Symmetric.is = is;
})(Symmetric || (Symmetric = {}));

var Name;
(function (Name) {
    function is(value) {
        return value == "none" || Symmetric.is(value) || Asymmetric.is(value);
    }
    Name.is = is;
    (function (Symmetric$1) {
        Symmetric$1.is = Symmetric.is;
    })(Name.Symmetric || (Name.Symmetric = {}));
    (function (Asymmetric$1) {
        Asymmetric$1.is = Asymmetric.is;
    })(Name.Asymmetric || (Name.Asymmetric = {}));
})(Name || (Name = {}));

var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class Algorithm {
    constructor(name, signer) {
        this.name = name;
        this.signer = signer;
    }
    sign(data) {
        return __awaiter(this, void 0, void 0, function* () {
            return typeof data == "string" ? this.signer.sign(data) : this.signer.sign(data);
        });
    }
    verify(data, signature) {
        return this.signer.verify(data, signature);
    }
    static create(name, ...keys) {
        let result;
        switch (name) {
            case "ES256":
                result = Signer.create("ECDSA", "SHA-256", keys[0], keys[1]);
                break;
            case "ES384":
                result = Signer.create("ECDSA", "SHA-384", keys[0], keys[1]);
                break;
            case "ES512":
                result = Signer.create("ECDSA", "SHA-512", keys[0], keys[1]);
                break;
            case "PS256":
                result = Signer.create("RSA-PSS", "SHA-256", keys[0], keys[1]);
                break;
            case "PS384":
                result = Signer.create("RSA-PSS", "SHA-384", keys[0], keys[1]);
                break;
            case "PS512":
                result = Signer.create("RSA-PSS", "SHA-512", keys[0], keys[1]);
                break;
            case "HS256":
                result = Signer.create("HMAC", "SHA-256", keys[0]);
                break;
            case "HS384":
                result = Signer.create("HMAC", "SHA-384", keys[0]);
                break;
            case "HS512":
                result = Signer.create("HMAC", "SHA-512", keys[0]);
                break;
            case "RS256":
                result = Signer.create("RSA", "SHA-256", keys[0], keys[1]);
                break;
            case "RS384":
                result = Signer.create("RSA", "SHA-384", keys[0], keys[1]);
                break;
            case "RS512":
                result = Signer.create("RSA", "SHA-512", keys[0], keys[1]);
                break;
            case "none":
                result = Signer.create("None");
                break;
        }
        return result && new Algorithm(name, result);
    }
    static none() {
        return Algorithm.create("none");
    }
    static HS256(key) {
        return Algorithm.create("HS256", key);
    }
    static HS384(key) {
        return Algorithm.create("HS384", key);
    }
    static HS512(key) {
        return Algorithm.create("HS512", key);
    }
    static RS256(publicKey, privateKey) {
        return Algorithm.create("RS256", publicKey, privateKey);
    }
    static RS384(publicKey, privateKey) {
        return Algorithm.create("RS384", publicKey, privateKey);
    }
    static RS512(publicKey, privateKey) {
        return Algorithm.create("RS512", publicKey, privateKey);
    }
    static ES256(publicKey, privateKey) {
        return Algorithm.create("ES256", publicKey, privateKey);
    }
    static ES384(publicKey, privateKey) {
        return Algorithm.create("ES384", publicKey, privateKey);
    }
    static ES512(publicKey, privateKey) {
        return Algorithm.create("ES512", publicKey, privateKey);
    }
    static PS256(publicKey, privateKey) {
        return Algorithm.create("PS256", publicKey, privateKey);
    }
    static PS384(publicKey, privateKey) {
        return Algorithm.create("PS384", publicKey, privateKey);
    }
    static PS512(publicKey, privateKey) {
        return Algorithm.create("PS512", publicKey, privateKey);
    }
}
(function (Algorithm) {
    (function (Name$1) {
        Name$1.is = Name.is;
        (function (Symmetric) {
            Symmetric.is = Name.Symmetric.is;
        })(Name$1.Symmetric || (Name$1.Symmetric = {}));
        (function (Asymmetric) {
            Asymmetric.is = Name.Asymmetric.is;
        })(Name$1.Asymmetric || (Name$1.Asymmetric = {}));
    })(Algorithm.Name || (Algorithm.Name = {}));
})(Algorithm || (Algorithm = {}));

exports.Token = void 0;
(function (Token) {
    function is(value) {
        return typeof value == "string" && /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/.test(value);
    }
    Token.is = is;
})(exports.Token || (exports.Token = {}));

exports.Algorithm = Algorithm;
exports.Digest = Digest;
exports.TextEncoder = TextEncoder;
exports.decode = decode;
exports.encode = encode$1;
