UNPKG

parse-cosekey

Version:

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

440 lines 24.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.COSEKeyParameterValueMapping = exports.COSEAlgorithm = exports.COSEEllipticCurve = exports.COSEKeyOperationValue = exports.COSEKeyTypeParameter = exports.COSEKeyType = exports.COSEKeyCommonParameter = void 0; class COSEKeyParameterValue { } /** * COSE Key Types. * {@link https://www.iana.org/assignments/cose/cose.xhtml#key-type} */ class COSEKeyType extends COSEKeyParameterValue { constructor(_name, _value, _description) { super(); this._name = _name; this._value = _value; this._description = _description; COSEKeyType._values.push(this); } get name() { return this._name; } get value() { return this._value; } get description() { return this._description; } static values() { return COSEKeyType._values; } static fromValue(value) { const found = COSEKeyType.values().find((c) => { return c.value === value; }); return found || null; } static fromName(name) { const found = COSEKeyType.values().find((c) => { return c.name === name; }); return found || null; } } exports.COSEKeyType = COSEKeyType; COSEKeyType._values = []; COSEKeyType.OKP = new COSEKeyType('OKP', 1, 'Octet Key Pair'); COSEKeyType.EC2 = new COSEKeyType('EC2', 2, 'Elliptic Curve Keys w/ x- and y-coordinate pair'); COSEKeyType.RSA = new COSEKeyType('RSA', 3, 'RSA Key'); COSEKeyType.SYMMETRIC = new COSEKeyType('Symmetric', 4, 'Symmetric Keys'); COSEKeyType.HSS_LMS = new COSEKeyType('HSS-LMS', 5, 'Public key for HSS/LMS hash-based digital signature'); COSEKeyType.WALNUT_DSA = new COSEKeyType('WalnutDSA', 6, 'WalnutDSA public key'); class COSEKeyParameter { } /** * COSE Key Common Parameters. * {@link https://www.iana.org/assignments/cose/cose.xhtml#key-common-parameters} */ class COSEKeyCommonParameter extends COSEKeyParameter { constructor(_name, _label, _description) { super(); this._name = _name; this._label = _label; this._description = _description; COSEKeyCommonParameter._values.push(this); } get name() { return this._name; } get label() { return this._label; } get description() { return this._description; } static values() { return COSEKeyCommonParameter._values; } static fromLabel(label) { const found = COSEKeyCommonParameter.values().find((c) => { return c.label === label; }); return found || null; } static fromName(name) { const found = COSEKeyCommonParameter.values().find((c) => { return c.name === name; }); return found || null; } } exports.COSEKeyCommonParameter = COSEKeyCommonParameter; COSEKeyCommonParameter._values = []; COSEKeyCommonParameter.KTY = new COSEKeyCommonParameter('kty', 1, 'Identification of the key type'); COSEKeyCommonParameter.KID = new COSEKeyCommonParameter('kid', 2, 'Key identification value -- match to kid in message'); COSEKeyCommonParameter.ALG = new COSEKeyCommonParameter('alg', 3, 'Key usage restriction to this algorithm'); COSEKeyCommonParameter.KEY_OPS = new COSEKeyCommonParameter('key_ops', 4, 'Restrict set of permissible operations'); COSEKeyCommonParameter.BASE_IV = new COSEKeyCommonParameter('Base IV', 5, 'Base IV to be xor-ed with Partial IVs'); /** * COSE Key Type Parameters. * {@link https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters} */ class COSEKeyTypeParameter extends COSEKeyParameter { constructor(_keyType, _name, _label, _description) { super(); this._keyType = _keyType; this._name = _name; this._label = _label; this._description = _description; COSEKeyTypeParameter._values.push(this); } get keyType() { return this._keyType; } get name() { return this._name; } get label() { return this._label; } get description() { return this._description; } static values() { return COSEKeyTypeParameter._values; } static fromLabel(keyType, label) { const found = COSEKeyTypeParameter.values().find((c) => { return c.keyType === keyType && c.label === label; }); return found || null; } static fromName(keyType, name) { const found = COSEKeyTypeParameter.values().find((c) => { return c.keyType === keyType && c.name === name; }); return found || null; } } exports.COSEKeyTypeParameter = COSEKeyTypeParameter; COSEKeyTypeParameter._values = []; COSEKeyTypeParameter.OKP_CRV = new COSEKeyTypeParameter(COSEKeyType.OKP, 'crv', -1, 'EC identifier - Taken from the "COSE Elliptic Curves" registry'); COSEKeyTypeParameter.OKP_X = new COSEKeyTypeParameter(COSEKeyType.OKP, 'x', -2, 'x-coordinate'); COSEKeyTypeParameter.OKP_D = new COSEKeyTypeParameter(COSEKeyType.OKP, 'd', -4, 'Private key'); COSEKeyTypeParameter.EC2_CRV = new COSEKeyTypeParameter(COSEKeyType.EC2, 'crv', -1, 'EC identifier - Taken from the "COSE Elliptic Curves" registry'); COSEKeyTypeParameter.EC2_X = new COSEKeyTypeParameter(COSEKeyType.EC2, 'x', -2, 'Public Key'); COSEKeyTypeParameter.EC2_Y = new COSEKeyTypeParameter(COSEKeyType.EC2, 'y', -3, 'y-coordinate'); COSEKeyTypeParameter.EC2_D = new COSEKeyTypeParameter(COSEKeyType.EC2, 'd', -4, 'Private key'); COSEKeyTypeParameter.RSA_N = new COSEKeyTypeParameter(COSEKeyType.RSA, 'n', -1, 'the RSA modulus n'); COSEKeyTypeParameter.RSA_E = new COSEKeyTypeParameter(COSEKeyType.RSA, 'e', -2, 'the RSA public exponent e'); COSEKeyTypeParameter.RSA_D = new COSEKeyTypeParameter(COSEKeyType.RSA, 'd', -3, 'the RSA private exponent d'); COSEKeyTypeParameter.RSA_P = new COSEKeyTypeParameter(COSEKeyType.RSA, 'p', -4, 'the prime factor p of n'); COSEKeyTypeParameter.RSA_Q = new COSEKeyTypeParameter(COSEKeyType.RSA, 'q', -5, 'the prime factor q of n'); COSEKeyTypeParameter.RSA_DP = new COSEKeyTypeParameter(COSEKeyType.RSA, 'dP', -6, 'dP is d mod (p - 1)'); COSEKeyTypeParameter.RSA_DQ = new COSEKeyTypeParameter(COSEKeyType.RSA, 'dQ', -7, 'dQ is d mod (q - 1)'); COSEKeyTypeParameter.RSA_QINV = new COSEKeyTypeParameter(COSEKeyType.RSA, 'qInv', -8, 'qInv is the CRT coefficient q^(-1) mod p'); COSEKeyTypeParameter.OTHER = new COSEKeyTypeParameter(COSEKeyType.RSA, 'other', -9, 'other prime infos, an array'); COSEKeyTypeParameter.R_I = new COSEKeyTypeParameter(COSEKeyType.RSA, 'r_i', -10, 'a prime factor r_i of n, where i >= 3'); COSEKeyTypeParameter.D_I = new COSEKeyTypeParameter(COSEKeyType.RSA, 'd_i', -11, 'd_i = d mod (r_i - 1)'); COSEKeyTypeParameter.T_I = new COSEKeyTypeParameter(COSEKeyType.RSA, 't_i', -12, 'the CRT coefficient t_i = (r_1 * r_2 * ... * r_(i-1))^(-1) mod r_i'); COSEKeyTypeParameter.SYMMETRIC_K = new COSEKeyTypeParameter(COSEKeyType.SYMMETRIC, 'k', -1, 'Key Value'); COSEKeyTypeParameter.PUB = new COSEKeyTypeParameter(COSEKeyType.HSS_LMS, 'pub', -1, 'Public key for HSS/LMS hash-based digital signature'); COSEKeyTypeParameter.WALNUTRSA_N = new COSEKeyTypeParameter(COSEKeyType.WALNUT_DSA, 'N', -1, 'Group and Matrix (NxN) size'); COSEKeyTypeParameter.WALNUTRSA_Q = new COSEKeyTypeParameter(COSEKeyType.WALNUT_DSA, 'q', -2, 'Finite field F_q'); COSEKeyTypeParameter.T_VALUES = new COSEKeyTypeParameter(COSEKeyType.WALNUT_DSA, 't-values', -3, 'List of T-values, entries in F_q'); COSEKeyTypeParameter.MATRIX_1 = new COSEKeyTypeParameter(COSEKeyType.WALNUT_DSA, 'matrix 1', -4, 'NxN Matrix of entries in F_q in column-major form'); COSEKeyTypeParameter.PERMUTATION_1 = new COSEKeyTypeParameter(COSEKeyType.WALNUT_DSA, 'permutation', -5, 'Permutation associated with matrix 1'); COSEKeyTypeParameter.MATRIX_2 = new COSEKeyTypeParameter(COSEKeyType.WALNUT_DSA, 'matrix 2', -6, 'NxN Matrix of entries in F_q in column-major form'); class COSEKeyOperationValue extends COSEKeyParameterValue { constructor(_name, _value, _description) { super(); this._name = _name; this._value = _value; this._description = _description; COSEKeyOperationValue._values.push(this); } get name() { return this._name; } get value() { return this._value; } get description() { return this._description; } static values() { return COSEKeyOperationValue._values; } static fromValue(value) { const found = COSEKeyOperationValue.values().find((c) => { return c.value === value; }); return found || null; } static fromName(name) { const found = COSEKeyOperationValue.values().find((c) => { return c.name === name; }); return found || null; } } exports.COSEKeyOperationValue = COSEKeyOperationValue; COSEKeyOperationValue._values = []; COSEKeyOperationValue.SIGN = new COSEKeyOperationValue('sign', 1, 'The key is used to create signatures. Requires private key fields.'); COSEKeyOperationValue.VERIFY = new COSEKeyOperationValue('verify', 2, 'The key is used for verification of signatures.'); COSEKeyOperationValue.ENCRYPT = new COSEKeyOperationValue('encrypt', 3, 'The key is used for key transport encryption.'); COSEKeyOperationValue.DECRYPT = new COSEKeyOperationValue('decrypt', 4, 'The key is used for key transport decryption. Requires private key fields.'); COSEKeyOperationValue.WRAP_KEY = new COSEKeyOperationValue('wrap key', 5, 'The key is used for key wrap encryption.'); COSEKeyOperationValue.UNWRAP_KEY = new COSEKeyOperationValue('unwrap key', 6, 'The key is used for key wrap decryption. Requires private key fields.'); COSEKeyOperationValue.DERIVE_KEY = new COSEKeyOperationValue('derive key', 7, 'The key is used for deriving keys. Requires private key fields.'); COSEKeyOperationValue.DERIVE_BITS = new COSEKeyOperationValue('derive bits', 8, 'The key is used for deriving bits not to be used as a key. Requires private key fields.'); COSEKeyOperationValue.MAC_CREATE = new COSEKeyOperationValue('MAC create', 9, 'The key is used for creating MACs.'); COSEKeyOperationValue.MAC_VERIFY = new COSEKeyOperationValue('MAC verify', 10, 'The key is used for validating MACs.'); class COSEEllipticCurve extends COSEKeyParameterValue { constructor(_name, _value, _keyType, _description) { super(); this._name = _name; this._value = _value; this._keyType = _keyType; this._description = _description; COSEEllipticCurve._values.push(this); } get name() { return this._name; } get value() { return this._value; } get keyType() { return this._keyType; } get description() { return this._description; } static values() { return COSEEllipticCurve._values; } static fromValue(keyType, value) { const found = COSEEllipticCurve.values().find((c) => { return c.keyType === keyType && c.value === value; }); return found || null; } static fromName(keyType, name) { const found = COSEEllipticCurve.values().find((c) => { return c.keyType === keyType && c.name === name; }); return found || null; } } exports.COSEEllipticCurve = COSEEllipticCurve; COSEEllipticCurve._values = []; COSEEllipticCurve.P_256 = new COSEEllipticCurve('P-256', 1, COSEKeyType.EC2, 'NIST P-256 also known as secp256r1'); COSEEllipticCurve.P_384 = new COSEEllipticCurve('P-384', 2, COSEKeyType.EC2, 'NIST P-384 also known as secp384r1'); COSEEllipticCurve.P_512 = new COSEEllipticCurve('P-512', 3, COSEKeyType.EC2, 'NIST P-512 also known as secp512r1'); COSEEllipticCurve.X25519 = new COSEEllipticCurve('X25519', 4, COSEKeyType.OKP, 'X25519 for use w/ ECDH only'); COSEEllipticCurve.X448 = new COSEEllipticCurve('X448', 5, COSEKeyType.OKP, 'X448 for use w/ ECDH only'); COSEEllipticCurve.ED25519 = new COSEEllipticCurve('Ed25519', 6, COSEKeyType.OKP, 'Ed25519 for use w/ EdDSA only'); COSEEllipticCurve.ED448 = new COSEEllipticCurve('Ed448', 7, COSEKeyType.OKP, 'Ed448 for use w/ EdDSA only'); COSEEllipticCurve.SECP256K1 = new COSEEllipticCurve('secp256k1', 8, COSEKeyType.EC2, 'SECG secp256k1 curve'); class COSEAlgorithm extends COSEKeyParameterValue { constructor(_name, _value, _description, _nodeCryptoHashAlg) { super(); this._name = _name; this._value = _value; this._description = _description; this._nodeCryptoHashAlg = _nodeCryptoHashAlg; COSEAlgorithm._values.push(this); } get name() { return this._name; } get value() { return this._value; } get description() { return this._description; } get nodeCryptoHashAlg() { return this._nodeCryptoHashAlg; } static values() { return COSEAlgorithm._values; } static fromValue(value) { const found = COSEAlgorithm.values().find((c) => { return c.value === value; }); return found || null; } static fromName(name) { const found = COSEAlgorithm.values().find((c) => { return c.name === name; }); return found || null; } } exports.COSEAlgorithm = COSEAlgorithm; COSEAlgorithm._values = []; COSEAlgorithm.RS1 = new COSEAlgorithm('RS1', -65535, 'RSASSA-PKCS1-v1_5 using SHA-1', 'sha1'); COSEAlgorithm.WALNUT_DSA = new COSEAlgorithm('WalnutDSA', -260, 'WalnutDSA signature', null); COSEAlgorithm.RS512 = new COSEAlgorithm('RS512', -259, 'RSASSA-PKCS1-v1_5 using SHA-512', 'sha512'); COSEAlgorithm.RS384 = new COSEAlgorithm('RS384', -258, 'RSASSA-PKCS1-v1_5 using SHA-384', 'sha384'); COSEAlgorithm.RS256 = new COSEAlgorithm('RS256', -257, 'RSASSA-PKCS1-v1_5 using SHA-256', 'sha256'); COSEAlgorithm.ES256K = new COSEAlgorithm('ES256K', -47, 'ECDSA using secp256k1 curve and SHA-256', 'sha256'); COSEAlgorithm.HSS_LMS = new COSEAlgorithm('HSS-LMS', -46, 'HSS/LMS hash-based digital signature', null); COSEAlgorithm.SHAKE256 = new COSEAlgorithm('SHAKE256', -45, 'SHAKE-256 512-bit Hash Value', null); COSEAlgorithm.SHA_512 = new COSEAlgorithm('SHA-512', -44, 'SHA-2 512-bit Hash', null); COSEAlgorithm.SHA_384 = new COSEAlgorithm('SHA-384', -43, 'SHA-2 384-bit Hash', null); COSEAlgorithm.RSAES_OAEP_w_SHA_512 = new COSEAlgorithm('RSAES-OAEP w/ SHA-512', -42, 'RSAES-OAEP w/ SHA-512', 'sha512'); COSEAlgorithm.RSAES_OAEP_w_SHA_256 = new COSEAlgorithm('RSAES-OAEP w/ SHA-256', -41, 'RSAES-OAEP w/ SHA-256', 'sha256'); COSEAlgorithm.RSAES_OAEP_w_RFC8017_DEFAULT_PARAMETERS = new COSEAlgorithm('RSAES-OAEP w/ RFC 8017 default parameters', -40, 'RSAES-OAEP w/ SHA-1', null); COSEAlgorithm.PS512 = new COSEAlgorithm('PS512', -39, 'RSASSA-PSS w/ SHA-512', 'sha512'); COSEAlgorithm.PS384 = new COSEAlgorithm('PS384', -38, 'RSASSA-PSS w/ SHA-384', 'sha384'); COSEAlgorithm.PS256 = new COSEAlgorithm('PS256', -37, 'RSASSA-PSS w/ SHA-256', 'sha256'); COSEAlgorithm.ES512 = new COSEAlgorithm('ES512', -36, 'ECDSA w/ SHA-512', 'sha512'); COSEAlgorithm.ES384 = new COSEAlgorithm('ES384', -35, 'ECDSA w/ SHA-384', 'sha384'); COSEAlgorithm.ECDH_SS_A256KW = new COSEAlgorithm('ECDH-SS + A256KW', -34, 'ECDH SS w/ Concat KDF and AES Key Wrap w/ 256-bit key', null); COSEAlgorithm.ECDH_SS_A192KW = new COSEAlgorithm('ECDH-SS + A256KW', -33, 'ECDH SS w/ Concat KDF and AES Key Wrap w/ 192-bit key', null); COSEAlgorithm.ECDH_SS_A128KW = new COSEAlgorithm('ECDH-SS + A128KW', -32, 'ECDH SS w/ Concat KDF and AES Key Wrap w/ 128-bit key', null); COSEAlgorithm.ECDH_ES_A256KW = new COSEAlgorithm('ECDH-ES + A256KW', -31, 'ECDH ES w/ Concat KDF and AES Key Wrap w/ 256-bit key', null); COSEAlgorithm.ECDH_ES_A192KW = new COSEAlgorithm('ECDH-ES + A192KW', -30, 'ECDH ES w/ Concat KDF and AES Key Wrap w/ 192-bit key', null); COSEAlgorithm.ECDH_ES_A128KW = new COSEAlgorithm('ECDH-ES + A128KW', -29, 'ECDH ES w/ Concat KDF and AES Key Wrap w/ 128-bit key', null); COSEAlgorithm.ECDH_SS_HKDF_512 = new COSEAlgorithm('ECDH-SS + HKDF-512', -28, 'ECDH SS w/ HKDF - generate key directly', null); COSEAlgorithm.ECDH_SS_HKDF_256 = new COSEAlgorithm('ECDH-SS + HKDF-256', -27, 'ECDH SS w/ HKDF - generate key directly', null); COSEAlgorithm.ECDH_ES_HKDF_512 = new COSEAlgorithm('ECDH-ES + HKDF-512', -26, 'ECDH ES w/ HKDF - generate key directly', null); COSEAlgorithm.ECDH_ES_HKDF_256 = new COSEAlgorithm('ECDH-ES + HKDF-256', -25, 'ECDH ES w/ HKDF - generate key directly', null); COSEAlgorithm.SHAKE128 = new COSEAlgorithm('SHAKE128', -18, 'SHAKE-128 512-bit Hash Value', null); COSEAlgorithm.SHA_512_256 = new COSEAlgorithm('SHA-512/256', -17, 'SHA-2 512-bit Hash truncated to 256-bits', null); COSEAlgorithm.SHA_256 = new COSEAlgorithm('SHA-256', -16, 'SHA-2 256-bit Hash', null); COSEAlgorithm.SHA_256_64 = new COSEAlgorithm('SHA-256/64', -15, 'SHA-2 256-bit Hash truncated to 64-bits', null); COSEAlgorithm.SHA_1 = new COSEAlgorithm('SHA-1', -14, 'SHA-1 Hash', null); COSEAlgorithm.DIRECT_HKDF_AES_256 = new COSEAlgorithm('direct+HKDF-AES-256', -13, 'Shared secret w/ AES-MAC 256-bit key', null); COSEAlgorithm.DIRECT_HKDF_AES_128 = new COSEAlgorithm('direct+HKDF-AES-128', -12, 'Shared secret w/ AES-MAC 128-bit key', null); COSEAlgorithm.DIRECT_HKDF_SHA_512 = new COSEAlgorithm('direct+HKDF-SHA-512', -11, 'Shared secret w/ HKDF and SHA-512', null); COSEAlgorithm.DIRECT_HKDF_SHA_256 = new COSEAlgorithm('direct+HKDF-SHA-256', -10, 'Shared secret w/ HKDF and SHA-256', null); COSEAlgorithm.EdDSA = new COSEAlgorithm('EdDSA', -8, 'EdDSA', 'sha512'); COSEAlgorithm.ES256 = new COSEAlgorithm('ES256', -7, 'ECDSA w/ SHA-256', 'sha256'); COSEAlgorithm.DIRECT = new COSEAlgorithm('direct', -6, 'Direct use of CEK', null); COSEAlgorithm.A256KW = new COSEAlgorithm('A256KW', -5, 'AES Key Wrap w/ 256-bit key', null); COSEAlgorithm.A192KW = new COSEAlgorithm('A192KW', -4, 'AES Key Wrap w/ 192-bit key', null); COSEAlgorithm.A128KW = new COSEAlgorithm('A128KW', -3, 'AES Key Wrap w/ 128-bit key', null); COSEAlgorithm.A128GCM = new COSEAlgorithm('A128GCM', 1, 'AES-GCM mode w/ 128-bit key, 128-bit tag', null); COSEAlgorithm.A192GCM = new COSEAlgorithm('A192GCM', 2, 'AES-GCM mode w/ 192-bit key, 128-bit tag', null); COSEAlgorithm.A256GCM = new COSEAlgorithm('A256GCM', 3, 'AES-GCM mode w/ 256-bit key, 128-bit tag', null); COSEAlgorithm.HMAC_256_64 = new COSEAlgorithm('HMAC 256/64', 4, 'HMAC w/ SHA-256 truncated to 64 bits', 'sha256'); COSEAlgorithm.HMAC_256_256 = new COSEAlgorithm('HMAC 256/256', 5, 'HMAC w/ SHA-256', 'sha256'); COSEAlgorithm.HMAC_384_384 = new COSEAlgorithm('HMAC 384/384', 6, 'HMAC w/ SHA-384', 'sha384'); COSEAlgorithm.HMAC_512_512 = new COSEAlgorithm('HMAC 512/512', 7, 'HMAC w/ SHA-512', 'sha512'); COSEAlgorithm.AES_CCM_16_64_128 = new COSEAlgorithm('AES-CCM-16-64-128', 10, 'AES-CCM mode 128-bit key, 64-bit tag, 13-byte nonce', null); COSEAlgorithm.AES_CCM_16_64_256 = new COSEAlgorithm('AES-CCM-16-64-256', 11, 'AES-CCM mode 256-bit key, 64-bit tag, 13-byte nonce', null); COSEAlgorithm.AES_CCM_64_64_128 = new COSEAlgorithm('AES-CCM-64-64-128', 12, 'AES-CCM mode 128-bit key, 64-bit tag, 7-byte nonce', null); COSEAlgorithm.AES_CCM_64_64_256 = new COSEAlgorithm('AES-CCM-64-64-256', 13, 'AES-CCM mode 256-bit key, 64-bit tag, 7-byte nonce', null); COSEAlgorithm.AES_MAC_128_64 = new COSEAlgorithm('AES-MAC 128/64', 14, 'AES-MAC 128-bit key, 64-bit tag', null); COSEAlgorithm.AES_MAC_256_64 = new COSEAlgorithm('AES-MAC 256/64', 15, 'AES-MAC 256-bit key, 64-bit tag', null); COSEAlgorithm.CHACHA20_POLY1305 = new COSEAlgorithm('ChaCha20/Poly1305', 24, 'ChaCha20/Poly1305 w/ 256-bit key, 128-bit tag', null); COSEAlgorithm.AES_MAC_128_128 = new COSEAlgorithm('AES-MAC 128/128', 25, 'AES-MAC 128-bit key, 128-bit tag', null); COSEAlgorithm.AES_MAC_256_128 = new COSEAlgorithm('AES-MAC 256/128', 26, 'AES-MAC 256-bit key, 128-bit tag', null); COSEAlgorithm.AES_CCM_16_128_128 = new COSEAlgorithm('AES-CCM-16-128-128', 30, 'AES-CCM mode 128-bit key, 128-bit tag, 13-byte nonce', null); COSEAlgorithm.AES_CCM_16_128_256 = new COSEAlgorithm('AES-CCM-16-128-256', 31, 'AES-CCM mode 256-bit key, 128-bit tag, 13-byte nonce', null); COSEAlgorithm.AES_CCM_64_128_128 = new COSEAlgorithm('AES-CCM-64-128-128', 32, 'AES-CCM mode 128-bit key, 128-bit tag, 7-byte nonce', null); COSEAlgorithm.AES_CCM_64_128_256 = new COSEAlgorithm('AES-CCM-64-128-256', 33, 'AES-CCM mode 256-bit key, 128-bit tag, 7-byte nonce', null); COSEAlgorithm.IV_GENERATION = new COSEAlgorithm('IV-GENERATION', 34, 'For doing IV generation for symmetric algorithms.', null); class COSEKeyParameterValueMapping { constructor(_parameter, _value) { this._parameter = _parameter; this._value = _value; COSEKeyParameterValueMapping._values.push(this); } get parameter() { return this._parameter; } get value() { return this._value; } static values() { return COSEKeyParameterValueMapping._values; } static fromParameter(parameter) { const found = COSEKeyParameterValueMapping.values().find((c) => { return c.parameter == parameter; }); return found || null; } fromParameterLabel(label, keyType) { const parameter = COSEKeyCommonParameter.fromLabel(label) || COSEKeyTypeParameter.fromLabel(keyType || COSEKeyType.OKP, label) || null; if (!parameter) { return null; } return COSEKeyParameterValueMapping.fromParameter(parameter); } fromValueLabel(label) { if (this._value === COSEKeyType) { return COSEKeyType.fromValue(label); } else if (this._value === COSEKeyOperationValue) { return COSEKeyOperationValue.fromValue(label); } else if (this._value === COSEEllipticCurve) { if (this === COSEKeyParameterValueMapping.OKP_CRV) { return COSEEllipticCurve.fromValue(COSEKeyType.OKP, label); } else if (this === COSEKeyParameterValueMapping.EC2_CRV) { return COSEEllipticCurve.fromValue(COSEKeyType.EC2, label); } } else if (this._value === COSEAlgorithm) { return COSEAlgorithm.fromValue(label); } return null; } fromValueName(name) { if (this._value === COSEKeyType) { return COSEKeyType.fromName(name); } else if (this._value === COSEKeyOperationValue) { return COSEKeyOperationValue.fromName(name); } else if (this._value === COSEEllipticCurve) { if (this === COSEKeyParameterValueMapping.OKP_CRV) { return COSEEllipticCurve.fromName(COSEKeyType.OKP, name); } else if (this === COSEKeyParameterValueMapping.EC2_CRV) { return COSEEllipticCurve.fromName(COSEKeyType.EC2, name); } } else if (this._value === COSEAlgorithm) { return COSEAlgorithm.fromName(name); } return null; } } exports.COSEKeyParameterValueMapping = COSEKeyParameterValueMapping; COSEKeyParameterValueMapping._values = []; COSEKeyParameterValueMapping.KTY = new COSEKeyParameterValueMapping(COSEKeyCommonParameter.KTY, COSEKeyType); COSEKeyParameterValueMapping.ALG = new COSEKeyParameterValueMapping(COSEKeyCommonParameter.ALG, COSEAlgorithm); COSEKeyParameterValueMapping.KEY_OPS = new COSEKeyParameterValueMapping(COSEKeyCommonParameter.KEY_OPS, COSEKeyOperationValue); COSEKeyParameterValueMapping.OKP_CRV = new COSEKeyParameterValueMapping(COSEKeyTypeParameter.OKP_CRV, COSEEllipticCurve); COSEKeyParameterValueMapping.EC2_CRV = new COSEKeyParameterValueMapping(COSEKeyTypeParameter.EC2_CRV, COSEEllipticCurve); //# sourceMappingURL=coseKey.js.map