UNPKG

cose-kit

Version:

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

103 lines (102 loc) 3.92 kB
import { TypedMap } from "@jfromaniello/typedmap"; import { encoder } from "./cbor.js"; export 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 || (Headers = {})); export 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 || (Algorithms = {})); export var MacAlgorithms; (function (MacAlgorithms) { MacAlgorithms[MacAlgorithms["HS256"] = 5] = "HS256"; MacAlgorithms[MacAlgorithms["HS384"] = 6] = "HS384"; MacAlgorithms[MacAlgorithms["HS512"] = 7] = "HS512"; })(MacAlgorithms || (MacAlgorithms = {})); export 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 || (EncryptionAlgorithms = {})); export const EncryptionAlgorithmNames = new Map([ [EncryptionAlgorithms.A128GCM, 'A128GCM'], [EncryptionAlgorithms.A192GCM, 'A192GCM'], [EncryptionAlgorithms.A256GCM, 'A256GCM'] ]); export const MacAlgorithmNames = new Map([ [MacAlgorithms.HS256, 'HS256'], [MacAlgorithms.HS384, 'HS384'], [MacAlgorithms.HS512, 'HS512'] ]); export const 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'] ]); export class ProtectedHeaders extends TypedMap { static from(headers) { if (headers instanceof ProtectedHeaders) { return headers; } return new ProtectedHeaders(headers); } encode() { return encoder.encode(this.esMap); } } export class EncryptProtectedHeaders extends TypedMap { static from(headers) { if (headers instanceof EncryptProtectedHeaders) { return headers; } return new MacProtectedHeaders(headers); } } export class MacProtectedHeaders extends TypedMap { static from(headers) { if (headers instanceof MacProtectedHeaders) { return headers; } return new MacProtectedHeaders(headers); } } export class UnprotectedHeaders extends TypedMap { static from(headers) { if (headers instanceof UnprotectedHeaders) { return headers; } return new UnprotectedHeaders(headers); } }