UNPKG

parse-cosekey

Version:

Parse COSE(CBOR Object Signing and Encryption) to JWK(JSON Web Key) or PEM.

357 lines 18.6 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EllipticCurveMapping = exports.KeyOperationMapping = exports.KeyParameterMapping = exports.KeyAlgorithmMapping = exports.KeyTypeMapping = void 0; const CoseKey = __importStar(require("./coseKey")); const JoseKey = __importStar(require("./joseKey")); class KeyTypeMapping { constructor(_coseKeyType, _jsonWebKeyType) { this._coseKeyType = _coseKeyType; this._jsonWebKeyType = _jsonWebKeyType; KeyTypeMapping._values.push(this); } get coseKeyType() { return this._coseKeyType; } get jsonWebKeyType() { return this._jsonWebKeyType; } static values() { return KeyTypeMapping._values; } static fromCOSEKeyType(coseKeyType) { const found = KeyTypeMapping.values().find((m) => { return m.coseKeyType === coseKeyType; }); if (found == null) { return null; } return found.jsonWebKeyType; } static fromCOSEKeyTypeValue(coseKeyTypeValue) { const found = KeyTypeMapping.values().find((m) => { return m.coseKeyType.value === coseKeyTypeValue; }); if (found == null) { return null; } return found.jsonWebKeyType; } static fromJSONWebKeyType(jsonWebKeyType) { const found = KeyTypeMapping.values().find((m) => { return m.jsonWebKeyType === jsonWebKeyType; }); if (found == null) { return null; } return found.coseKeyType; } static fromJSONWebKeyTypeValue(jsonWebKeyTypeValue) { const found = KeyTypeMapping.values().find((m) => { return m.jsonWebKeyType.value === jsonWebKeyTypeValue; }); if (found == null) { return null; } return found.coseKeyType; } } exports.KeyTypeMapping = KeyTypeMapping; KeyTypeMapping._values = []; KeyTypeMapping.OKP = new KeyTypeMapping(CoseKey.COSEKeyType.OKP, JoseKey.JSONWebKeyType.OKP); KeyTypeMapping.EC2 = new KeyTypeMapping(CoseKey.COSEKeyType.EC2, JoseKey.JSONWebKeyType.EC); KeyTypeMapping.RSA = new KeyTypeMapping(CoseKey.COSEKeyType.RSA, JoseKey.JSONWebKeyType.RSA); class KeyAlgorithmMapping { constructor(_coseAlgorithm, _joseAlgorithm) { this._coseAlgorithm = _coseAlgorithm; this._joseAlgorithm = _joseAlgorithm; KeyAlgorithmMapping._values.push(this); } get coseAlgorithm() { return this._coseAlgorithm; } get joseAlgorithm() { return this._joseAlgorithm; } static values() { return KeyAlgorithmMapping._values; } static fromCOSEAlgorithm(coseAlgorithm) { const found = KeyAlgorithmMapping.values().find((m) => { return m.coseAlgorithm === coseAlgorithm; }); if (found == null) { return null; } return found.joseAlgorithm; } static fromCOSEAlgorithmValue(coseAlgorithmValue) { const found = KeyAlgorithmMapping.values().find((m) => { return m.coseAlgorithm.value === coseAlgorithmValue; }); if (found == null) { return null; } return found.joseAlgorithm; } static fromJoseAlgorithm(joseAlgorithm) { const found = KeyAlgorithmMapping.values().find((m) => { return m.joseAlgorithm === joseAlgorithm; }); if (found == null) { return null; } return found.coseAlgorithm; } static fromJoseAlgorithmName(joseAlgorithmName) { const found = KeyAlgorithmMapping.values().find((m) => { return m.joseAlgorithm.name === joseAlgorithmName; }); if (found == null) { return null; } return found.coseAlgorithm; } } exports.KeyAlgorithmMapping = KeyAlgorithmMapping; KeyAlgorithmMapping._values = []; KeyAlgorithmMapping.RS1 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.RS1, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.RS1); KeyAlgorithmMapping.RS512 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.RS512, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.RS512); KeyAlgorithmMapping.RS384 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.RS384, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.RS384); KeyAlgorithmMapping.RS256 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.RS256, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.RS256); KeyAlgorithmMapping.ES256K = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.ES256K, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.ES256K); KeyAlgorithmMapping.RSAES_OAEP_SHA512 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.RSAES_OAEP_w_SHA_512, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.RSA_OAEP_512); KeyAlgorithmMapping.RSAES_OAEP_SHA256 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.RSAES_OAEP_w_SHA_256, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.RSA_OAEP_256); KeyAlgorithmMapping.PS512 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.PS512, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.PS512); KeyAlgorithmMapping.PS384 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.PS384, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.PS384); KeyAlgorithmMapping.PS256 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.PS256, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.PS256); KeyAlgorithmMapping.ES512 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.ES512, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.ES512); KeyAlgorithmMapping.ES384 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.ES384, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.ES384); KeyAlgorithmMapping.ECDH_ES_A256KW = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.ECDH_ES_A256KW, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.ECDH_ES_A256KW); KeyAlgorithmMapping.ECDH_ES_A192KW = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.ECDH_ES_A192KW, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.ECDH_ES_A192KW); KeyAlgorithmMapping.ECDH_ES_A128KW = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.ECDH_ES_A128KW, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.ECDH_ES_A128KW); KeyAlgorithmMapping.EdDSA = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.EdDSA, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.EdDSA); KeyAlgorithmMapping.ES256 = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.ES256, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.ES256); KeyAlgorithmMapping.DIRECT = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.DIRECT, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.DIR); KeyAlgorithmMapping.A256KW = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.A256KW, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.A256KW); KeyAlgorithmMapping.A192KW = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.A192KW, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.A192KW); KeyAlgorithmMapping.A128KW = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.A128KW, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.A128KW); KeyAlgorithmMapping.A128GCM = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.A128GCM, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.A128GCM); KeyAlgorithmMapping.A192GCM = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.A192GCM, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.A192GCM); KeyAlgorithmMapping.A256GCM = new KeyAlgorithmMapping(CoseKey.COSEAlgorithm.A256GCM, JoseKey.JSONWebSignatureAndEncryptionAlgorithm.A256GCM); class KeyParameterMapping { constructor(_coseKeyParameter, _jsonWebKeyParameter) { this._coseKeyParameter = _coseKeyParameter; this._jsonWebKeyParameter = _jsonWebKeyParameter; KeyParameterMapping._values.push(this); } get coseKeyParameter() { return this._coseKeyParameter; } get jsonWebKeyParameter() { return this._jsonWebKeyParameter; } static values() { return KeyParameterMapping._values; } static fromCOSEKeyParameter(coseKeyParameter) { const found = KeyParameterMapping.values().find((m) => { return m.coseKeyParameter === coseKeyParameter; }); if (found == null) { return null; } return found.jsonWebKeyParameter; } static fromCOSEKeyParameterLabel(coseKeyParameterLabel) { const found = KeyParameterMapping.values().find((m) => { return m.coseKeyParameter.label === coseKeyParameterLabel; }); if (found == null) { return null; } return found.jsonWebKeyParameter; } static fromJSONWebKeyParameter(jsonWebKeyParameter) { const found = KeyParameterMapping.values().find((m) => { return m.jsonWebKeyParameter === jsonWebKeyParameter; }); if (found == null) { return null; } return found.coseKeyParameter; } static fromJSONWebKeyParameterName(jsonWebKeyParameterName) { const found = KeyParameterMapping.values().find((m) => { return m.jsonWebKeyParameter.name === jsonWebKeyParameterName; }); if (found == null) { return null; } return found.coseKeyParameter; } } exports.KeyParameterMapping = KeyParameterMapping; KeyParameterMapping._values = []; KeyParameterMapping.KTY = new KeyParameterMapping(CoseKey.COSEKeyCommonParameter.KTY, JoseKey.JSONWebKeyParameter.KTY); KeyParameterMapping.KID = new KeyParameterMapping(CoseKey.COSEKeyCommonParameter.KID, JoseKey.JSONWebKeyParameter.KID); KeyParameterMapping.ALG = new KeyParameterMapping(CoseKey.COSEKeyCommonParameter.ALG, JoseKey.JSONWebKeyParameter.ALG); KeyParameterMapping.KEY_OPS = new KeyParameterMapping(CoseKey.COSEKeyCommonParameter.KEY_OPS, JoseKey.JSONWebKeyParameter.KEY_OPS); KeyParameterMapping.OKP_CRV = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.OKP_CRV, JoseKey.JSONWebKeyParameter.OKP_CRV); KeyParameterMapping.OKP_X = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.OKP_X, JoseKey.JSONWebKeyParameter.OKP_X); KeyParameterMapping.OKP_D = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.OKP_D, JoseKey.JSONWebKeyParameter.OKP_D); KeyParameterMapping.EC2_CRV = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.EC2_CRV, JoseKey.JSONWebKeyParameter.EC_CRV); KeyParameterMapping.EC2_X = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.EC2_X, JoseKey.JSONWebKeyParameter.EC_X); KeyParameterMapping.EC2_Y = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.EC2_Y, JoseKey.JSONWebKeyParameter.EC_Y); KeyParameterMapping.EC2_D = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.EC2_D, JoseKey.JSONWebKeyParameter.EC_D); KeyParameterMapping.RSA_N = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.RSA_N, JoseKey.JSONWebKeyParameter.N); KeyParameterMapping.RSA_E = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.RSA_E, JoseKey.JSONWebKeyParameter.E); KeyParameterMapping.RSA_D = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.RSA_D, JoseKey.JSONWebKeyParameter.RSA_D); KeyParameterMapping.RSA_P = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.RSA_P, JoseKey.JSONWebKeyParameter.P); KeyParameterMapping.RSA_Q = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.RSA_Q, JoseKey.JSONWebKeyParameter.Q); KeyParameterMapping.RSA_DP = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.RSA_DP, JoseKey.JSONWebKeyParameter.DP); KeyParameterMapping.RSA_DQ = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.RSA_DQ, JoseKey.JSONWebKeyParameter.DQ); KeyParameterMapping.OTHER = new KeyParameterMapping(CoseKey.COSEKeyTypeParameter.OTHER, JoseKey.JSONWebKeyParameter.OTH); class KeyOperationMapping { constructor(_coseKeyOperation, _jsonWebKeyOperation) { this._coseKeyOperation = _coseKeyOperation; this._jsonWebKeyOperation = _jsonWebKeyOperation; KeyOperationMapping._values.push(this); } get coseKeyOperation() { return this._coseKeyOperation; } get jsonWebKeyOperation() { return this._jsonWebKeyOperation; } static values() { return KeyOperationMapping._values; } static fromCOSEKeyOperation(coseKeyOperation) { const found = KeyOperationMapping.values().find((m) => { return m.coseKeyOperation === coseKeyOperation; }); if (found == null) { return null; } return found.jsonWebKeyOperation; } static fromCOSEKeyOperationValue(coseKeyOperationValue) { const found = KeyOperationMapping.values().find((m) => { return m.coseKeyOperation.value === coseKeyOperationValue; }); if (found == null) { return null; } return found.jsonWebKeyOperation; } static fromJSONWebKeyOperation(jsonWebKeyOperation) { const found = KeyOperationMapping.values().find((m) => { return m.jsonWebKeyOperation === jsonWebKeyOperation; }); if (found == null) { return null; } return found.coseKeyOperation; } static fromJSONWebKeyOperationValue(jsonWebKeyOperationValue) { const found = KeyOperationMapping.values().find((m) => { return m.jsonWebKeyOperation.value === jsonWebKeyOperationValue; }); if (found == null) { return null; } return found.coseKeyOperation; } } exports.KeyOperationMapping = KeyOperationMapping; KeyOperationMapping._values = []; KeyOperationMapping.SIGN = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.SIGN, JoseKey.JSONWebKeyOperation.SIGN); KeyOperationMapping.VERIFY = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.VERIFY, JoseKey.JSONWebKeyOperation.VERIFY); KeyOperationMapping.ENCRYPT = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.ENCRYPT, JoseKey.JSONWebKeyOperation.ENCRYPT); KeyOperationMapping.DECRYPT = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.DECRYPT, JoseKey.JSONWebKeyOperation.DECRYPT); KeyOperationMapping.WRAP_KEY = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.WRAP_KEY, JoseKey.JSONWebKeyOperation.WRAP_KEY); KeyOperationMapping.UNWRAP_KEY = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.UNWRAP_KEY, JoseKey.JSONWebKeyOperation.UNWRAP_KEY); KeyOperationMapping.DERIVE_KEY = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.DERIVE_KEY, JoseKey.JSONWebKeyOperation.DERIVE_KEY); KeyOperationMapping.DERIVE_BITS = new KeyOperationMapping(CoseKey.COSEKeyOperationValue.DERIVE_BITS, JoseKey.JSONWebKeyOperation.DERIVE_BITS); class EllipticCurveMapping { constructor(_coseEllipticCurve, _jsonWebKeyEllipticCurve) { this._coseEllipticCurve = _coseEllipticCurve; this._jsonWebKeyEllipticCurve = _jsonWebKeyEllipticCurve; EllipticCurveMapping._values.push(this); } get coseEllipticCurve() { return this._coseEllipticCurve; } get jsonWebKeyEllipticCurve() { return this._jsonWebKeyEllipticCurve; } static values() { return EllipticCurveMapping._values; } static fromCOSEEllipticCurve(coseEllipticCurve) { const found = EllipticCurveMapping.values().find((m) => { return m.coseEllipticCurve === coseEllipticCurve; }); if (found == null) { return null; } return found.jsonWebKeyEllipticCurve; } static fromCOSEEllipticCurveValue(coseEllipticCurveValue) { const found = EllipticCurveMapping.values().find((m) => { return m.coseEllipticCurve.value === coseEllipticCurveValue; }); if (found == null) { return null; } return found.jsonWebKeyEllipticCurve; } static fromJSONWebKeyEllipticCurve(jsonWebKeyEllipticCurve) { const found = EllipticCurveMapping.values().find((m) => { return m.jsonWebKeyEllipticCurve === jsonWebKeyEllipticCurve; }); if (found == null) { return null; } return found.coseEllipticCurve; } static fromJSONWebKeyEllipticCurveName(jsonWebKeyEllipticCurveValue) { const found = EllipticCurveMapping.values().find((m) => { return m.jsonWebKeyEllipticCurve.name === jsonWebKeyEllipticCurveValue; }); if (found == null) { return null; } return found.coseEllipticCurve; } } exports.EllipticCurveMapping = EllipticCurveMapping; EllipticCurveMapping._values = []; EllipticCurveMapping.P_256 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.P_256, JoseKey.JSONWebKeyEllipticCurve.P_256); EllipticCurveMapping.P_384 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.P_384, JoseKey.JSONWebKeyEllipticCurve.P_384); EllipticCurveMapping.P_512 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.P_512, JoseKey.JSONWebKeyEllipticCurve.P_521); EllipticCurveMapping.X25519 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.X25519, JoseKey.JSONWebKeyEllipticCurve.X25519); EllipticCurveMapping.X448 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.X448, JoseKey.JSONWebKeyEllipticCurve.X448); EllipticCurveMapping.ED25519 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.ED25519, JoseKey.JSONWebKeyEllipticCurve.ED25519); EllipticCurveMapping.ED448 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.ED448, JoseKey.JSONWebKeyEllipticCurve.ED448); EllipticCurveMapping.SECP256K1 = new EllipticCurveMapping(CoseKey.COSEEllipticCurve.SECP256K1, JoseKey.JSONWebKeyEllipticCurve.SECP256K1); //# sourceMappingURL=coseJoseMapping.js.map