UNPKG

@signumjs/crypto

Version:

Cryptographic functions for building Signum Network apps.

40 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Crypto = void 0; const cryptoError_1 = require("../typings/cryptoError"); /** * Unified Low-Level Crypto Class for common crypto operations needed for Signum. * * IMPORTANT: Before using any of the crypto functions {@link init()} needs to be called once * * Usually, you want to use the comfort functions like * {@link encryptData}, {@link encryptMessage}, {@link decryptData}, {@link decryptData}, {@link getRandomBytes}, etc. * * Interacting with this class maybe necessary in cases where the underlying crypto implementations need to be * customized, i.e. React Native * */ class Crypto { static cryptoAdapter; /** * The adapter gives access to required crypto methods */ static get adapter() { if (!Crypto.cryptoAdapter) { throw new cryptoError_1.CryptoError('No Crypto Adapter provided - Use [Crypto.init()] first'); } return Crypto.cryptoAdapter; } /** * Initializes the crypto module with platform specific {@link CryptoAdapter} * * This must be called, before any of the crypto functions is being used * * @param cryptoAdapter The platform specific adapter, e.g. {@link NodeJSCryptoAdapter}, {@link WebCryptoAdapter}, or any other provider */ static init(cryptoAdapter) { Crypto.cryptoAdapter = cryptoAdapter; } } exports.Crypto = Crypto; //# sourceMappingURL=crypto.js.map