@microsoft/useragent-sdk
Version:
SDK for building decentralized identity wallets and enterprise agents.
98 lines • 3.76 kB
JavaScript
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Utility class to handle all CryptoSuite dependency injection
*/
class CryptoFactory {
/**
* Constructs a new CryptoRegistry
* @param keyStore used to store private keys
* @param crypto The default subtle crypto for the environment used for dependency injection
*/
constructor(keyStore, crypto) {
/**
* Label for default algorithm
*/
this.defaultAlgorithm = '*';
this.keyStore = keyStore;
this.keyEncrypters = { '*': crypto };
this.sharedKeyEncrypters = { '*': crypto };
this.symmetricEncrypter = { '*': crypto };
this.messageSigners = { '*': crypto };
this.messageAuthenticationCodeSigners = { '*': crypto };
this.messageDigests = { '*': crypto };
}
/**
* Gets the key encrypter object given the encryption algorithm's name
* @param name The name of the algorithm
* @returns The corresponding crypto API
*/
getKeyEncrypter(name) {
if (this.keyEncrypters[name]) {
return this.keyEncrypters[name];
}
return this.keyEncrypters[this.defaultAlgorithm];
}
/**
* Gets the shared key encrypter object given the encryption algorithm's name
* Used for DH algorithms
* @param name The name of the algorithm
* @returns The corresponding crypto API
*/
getSharedKeyEncrypter(name) {
if (this.sharedKeyEncrypters[name]) {
return this.sharedKeyEncrypters[name];
}
return this.sharedKeyEncrypters[this.defaultAlgorithm];
}
/**
* Gets the SymmetricEncrypter object given the symmetric encryption algorithm's name
* @param name The name of the algorithm
* @returns The corresponding crypto API
*/
getSymmetricEncrypter(name) {
if (this.symmetricEncrypter[name]) {
return this.symmetricEncrypter[name];
}
return this.symmetricEncrypter[this.defaultAlgorithm];
}
/**
* Gets the message signer object given the signing algorithm's name
* @param name The name of the algorithm
* @returns The corresponding crypto API
*/
getMessageSigner(name) {
if (this.messageSigners[name]) {
return this.messageSigners[name];
}
return this.messageSigners[this.defaultAlgorithm];
}
/**
* Gets the mac signer object given the signing algorithm's name
* @param name The name of the algorithm
* @returns The corresponding crypto API
*/
getMessageAuthenticationCodeSigners(name) {
if (this.messageAuthenticationCodeSigners[name]) {
return this.messageAuthenticationCodeSigners[name];
}
return this.messageAuthenticationCodeSigners[this.defaultAlgorithm];
}
/**
* Gets the message digest object given the digest algorithm's name
* @param name The name of the algorithm
* @returns The corresponding crypto API
*/
getMessageDigest(name) {
if (this.messageDigests[name]) {
return this.messageDigests[name];
}
return this.messageDigests[this.defaultAlgorithm];
}
}
exports.default = CryptoFactory;
//# sourceMappingURL=CryptoFactory.js.map