UNPKG

cose-kit

Version:

**DEPRECATED:** Use [@auth0/cose](https://www.npmjs.com/package/@auth0/cose).

110 lines (109 loc) 4.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnprotectedHeaders = exports.MacProtectedHeaders = exports.EncryptProtectedHeaders = exports.ProtectedHeaders = exports.AlgorithmNames = exports.MacAlgorithmNames = exports.EncryptionAlgorithmNames = exports.EncryptionAlgorithms = exports.MacAlgorithms = exports.Algorithms = exports.Headers = void 0; const typedmap_1 = require("@jfromaniello/typedmap"); const cbor_js_1 = require("./cbor.js"); var Headers; (function (Headers) { Headers[Headers["Algorithm"] = 1] = "Algorithm"; Headers[Headers["Critical"] = 2] = "Critical"; Headers[Headers["ContentType"] = 3] = "ContentType"; Headers[Headers["KeyID"] = 4] = "KeyID"; Headers[Headers["IV"] = 5] = "IV"; Headers[Headers["PartialIV"] = 6] = "PartialIV"; Headers[Headers["CounterSignature"] = 7] = "CounterSignature"; Headers[Headers["CounterSignature0"] = 9] = "CounterSignature0"; Headers[Headers["CounterSignatureV2"] = 11] = "CounterSignatureV2"; Headers[Headers["CounterSignature0V2"] = 12] = "CounterSignature0V2"; Headers[Headers["X5Bag"] = 32] = "X5Bag"; Headers[Headers["X5Chain"] = 33] = "X5Chain"; Headers[Headers["X5T"] = 34] = "X5T"; Headers[Headers["X5U"] = 35] = "X5U"; })(Headers || (exports.Headers = Headers = {})); var Algorithms; (function (Algorithms) { Algorithms[Algorithms["EdDSA"] = -8] = "EdDSA"; Algorithms[Algorithms["ES256"] = -7] = "ES256"; Algorithms[Algorithms["ES384"] = -35] = "ES384"; Algorithms[Algorithms["ES512"] = -36] = "ES512"; Algorithms[Algorithms["PS256"] = -37] = "PS256"; Algorithms[Algorithms["PS384"] = -38] = "PS384"; Algorithms[Algorithms["PS512"] = -39] = "PS512"; Algorithms[Algorithms["RS256"] = -257] = "RS256"; Algorithms[Algorithms["RS384"] = -258] = "RS384"; Algorithms[Algorithms["RS512"] = -259] = "RS512"; })(Algorithms || (exports.Algorithms = Algorithms = {})); var MacAlgorithms; (function (MacAlgorithms) { MacAlgorithms[MacAlgorithms["HS256"] = 5] = "HS256"; MacAlgorithms[MacAlgorithms["HS384"] = 6] = "HS384"; MacAlgorithms[MacAlgorithms["HS512"] = 7] = "HS512"; })(MacAlgorithms || (exports.MacAlgorithms = MacAlgorithms = {})); var EncryptionAlgorithms; (function (EncryptionAlgorithms) { EncryptionAlgorithms[EncryptionAlgorithms["A128GCM"] = 1] = "A128GCM"; EncryptionAlgorithms[EncryptionAlgorithms["A192GCM"] = 2] = "A192GCM"; EncryptionAlgorithms[EncryptionAlgorithms["A256GCM"] = 3] = "A256GCM"; EncryptionAlgorithms[EncryptionAlgorithms["Direct"] = -6] = "Direct"; })(EncryptionAlgorithms || (exports.EncryptionAlgorithms = EncryptionAlgorithms = {})); exports.EncryptionAlgorithmNames = new Map([ [EncryptionAlgorithms.A128GCM, 'A128GCM'], [EncryptionAlgorithms.A192GCM, 'A192GCM'], [EncryptionAlgorithms.A256GCM, 'A256GCM'] ]); exports.MacAlgorithmNames = new Map([ [MacAlgorithms.HS256, 'HS256'], [MacAlgorithms.HS384, 'HS384'], [MacAlgorithms.HS512, 'HS512'] ]); exports.AlgorithmNames = new Map([ [Algorithms.EdDSA, 'EdDSA'], [Algorithms.ES256, 'ES256'], [Algorithms.ES384, 'ES384'], [Algorithms.ES512, 'ES512'], [Algorithms.PS256, 'PS256'], [Algorithms.PS384, 'PS384'], [Algorithms.PS512, 'PS512'], [Algorithms.RS256, 'RS256'], [Algorithms.RS384, 'RS384'], [Algorithms.RS512, 'RS512'] ]); class ProtectedHeaders extends typedmap_1.TypedMap { static from(headers) { if (headers instanceof ProtectedHeaders) { return headers; } return new ProtectedHeaders(headers); } encode() { return cbor_js_1.encoder.encode(this.esMap); } } exports.ProtectedHeaders = ProtectedHeaders; class EncryptProtectedHeaders extends typedmap_1.TypedMap { static from(headers) { if (headers instanceof EncryptProtectedHeaders) { return headers; } return new MacProtectedHeaders(headers); } } exports.EncryptProtectedHeaders = EncryptProtectedHeaders; class MacProtectedHeaders extends typedmap_1.TypedMap { static from(headers) { if (headers instanceof MacProtectedHeaders) { return headers; } return new MacProtectedHeaders(headers); } } exports.MacProtectedHeaders = MacProtectedHeaders; class UnprotectedHeaders extends typedmap_1.TypedMap { static from(headers) { if (headers instanceof UnprotectedHeaders) { return headers; } return new UnprotectedHeaders(headers); } } exports.UnprotectedHeaders = UnprotectedHeaders;