/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/@keeex/crypto@3.7.9/web/provider.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
/**
 * @license
 * @preserve
 *
 * KeeeX SAS Public code
 * https://keeex.me
 * Copyright 2013-2023 KeeeX All Rights Reserved.
 * 
 * These computer program listings and specifications, herein,
 * are and remain the property of KeeeX SAS. The intellectual
 * and technical concepts herein are proprietary to KeeeX SAS
 * and may be covered by EU and foreign patents,
 * patents in process, trade secrets and copyright law.
 * 
 * These listings are published as a way to provide third party
 * with the ability to process KeeeX data.
 * As such, support for public inquiries is limited.
 * They are provided "as-is", without warrany of any kind.
 * 
 * They shall not be reproduced or copied or used in whole or
 * in part as the basis for manufacture or sale of items unless
 * prior written permission is obtained from KeeeX SAS.
 * 
 * For a license agreement, please contact:
 * <mailto: contact@keeex.net>
 * 
 */
import*as utilGlobal from"@keeex/utils/global.js";import{makeProfilePredicate}from"@keeex/utils/types/record.js";import*as cipherTypes from"./ciphertypes.js";import*as digestTypes from"./digesttypes.js";import*as hmacTypes from"./hmactypes.js";import*as keysTypes from"./keystypes.js";import*as randomTypes from"./randomtypes.js";const MAJOR_VERSION_EXPECTED=3,isCryptoProvider=makeProfilePredicate({cipherProvider:cipherTypes.isCipherProvider,digestProvider:digestTypes.isDigestProvider,hmacProvider:hmacTypes.isHmacProvider,keysProvider:keysTypes.isKeysProvider,majorVersion:"number",randomProvider:randomTypes.isRandomProvider}),isProviderOptions=makeProfilePredicate({noImmediateFallback:"boolean"}),defaultProviderOptions={noImmediateFallback:!1};let activeProvider;const globalProviderKey="kx_crypto3_provider",globalProviderOptionsKey="kx_crypto3_provider_options",loadGlobalOptions=()=>{const e=utilGlobal.getGlobalValue(globalProviderOptionsKey);isProviderOptions(e)||utilGlobal.setGlobalValue(globalProviderOptionsKey,defaultProviderOptions)};loadGlobalOptions();export const setProviderOptions=e=>{const r=utilGlobal.getGlobalValue(globalProviderOptionsKey);if(!isProviderOptions(r))throw new Error("Unexpected state, global options invalid");Object.assign(r,e),utilGlobal.setGlobalValue(globalProviderOptionsKey,r)};const validateProvider=e=>{if(!e)throw new Error("No cryptographic provider provided");if(!isCryptoProvider(e))throw new Error("Provided cryptographic provider does not match expected interface");if(3!==e.majorVersion)throw new Error(`Cryptographic provider version mismatch (expected 3, got ${e.majorVersion})`);return e};export const registerProvider=e=>{const r=utilGlobal.getGlobalValue(globalProviderKey);try{validateProvider(r),console.warn("Multiple cryptographic provider tried to register. This indicate dependencies issues.")}catch{validateProvider(e),utilGlobal.setGlobalValue(globalProviderKey,e),activeProvider=e}};export const setProvider=(e,r)=>{e&&registerProvider(e),r&&setProviderOptions(r)};export const getProvider=()=>{if(!activeProvider){const e=validateProvider(utilGlobal.getGlobalValue(globalProviderKey));activeProvider=e}return activeProvider};export const getProviderOptions=()=>{const e=utilGlobal.getGlobalValue(globalProviderOptionsKey);if(!isProviderOptions(e))throw new Error("Unexpected state, global options invalid");return{...e}};
//# sourceMappingURL=/sm/b0031f4189db0d515be16a83a4198422d75b593fc091887f9aa1942640f73d0c.map