UNPKG

@aviarytech/didcomm-core

Version:

Core methods and interfaces for DIDComm

52 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getKeyPairForType = void 0; const ed25519_key_pair_1 = require("@transmute/ed25519-key-pair"); const jsonld_signatures_bbs_1 = require("@mattrglobal/jsonld-signatures-bbs"); const secp256k1_key_pair_1 = require("@transmute/secp256k1-key-pair"); const web_crypto_key_pair_1 = require("@transmute/web-crypto-key-pair"); const x25519_key_pair_1 = require("@transmute/x25519-key-pair"); const getKeyPairForKtyAndCrv = (kty, crv) => { if (kty === "OKP") { if (crv === "Ed25519") { return ed25519_key_pair_1.Ed25519KeyPair; } if (crv == "X25519") { return x25519_key_pair_1.X25519KeyPair; } } if (kty === "EC") { if (crv === "secp256k1") { return secp256k1_key_pair_1.Secp256k1KeyPair; } if (crv === "BLS12381_G2") { return jsonld_signatures_bbs_1.Bls12381G2KeyPair; } if (["P-256", "P-384", "P-521"].includes(crv)) { return web_crypto_key_pair_1.WebCryptoKey; } } throw new Error(`getKeyPairForKtyAndCrv does not support: ${kty} and ${crv}`); }; exports.getKeyPairForType = (k) => { if (k.type === "JsonWebKey2020") { return getKeyPairForKtyAndCrv(k.publicKeyJwk.kty, k.publicKeyJwk.crv); } if (k.type === "Ed25519VerificationKey2018") { return ed25519_key_pair_1.Ed25519KeyPair; } if (k.type === "X25519KeyAgreementKey2019") { return x25519_key_pair_1.X25519KeyPair; } if (k.type === "EcdsaSecp256k1VerificationKey2019") { return secp256k1_key_pair_1.Secp256k1KeyPair; } if (k.type === "Bls12381G2Key2020") { return jsonld_signatures_bbs_1.Bls12381G2KeyPair; } if (["P256Key2021", "P384Key2021", "P521Key2021"].includes(k.type)) { return web_crypto_key_pair_1.WebCryptoKey; } throw new Error("getKeyPairForType does not support type: " + k.type); }; //# sourceMappingURL=keypair-utils.js.map