/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@keeex/crypto@3.7.8/lib/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{setGlobalValue,getGlobalValue}from"@keeex/utils/global.js";import{makeProfilePredicate}from"@keeex/utils/types/record.js";import{isCipherProvider}from"./ciphertypes.js";import{isDigestProvider}from"./digesttypes.js";import{isHmacProvider}from"./hmactypes.js";import{isKeysProvider}from"./keystypes.js";import{isRandomProvider}from"./randomtypes.js";const MAJOR_VERSION_EXPECTED=3,isCryptoProvider=makeProfilePredicate({cipherProvider:isCipherProvider,digestProvider:isDigestProvider,hmacProvider:isHmacProvider,keysProvider:isKeysProvider,majorVersion:"number",randomProvider:isRandomProvider}),isProviderOptions=makeProfilePredicate({noImmediateFallback:"boolean"}),defaultProviderOptions={noImmediateFallback:!1};let activeProvider;const globalProviderKey="kx_crypto3_provider",globalProviderOptionsKey="kx_crypto3_provider_options",loadGlobalOptions=()=>{const r=getGlobalValue(globalProviderOptionsKey);isProviderOptions(r)||setGlobalValue(globalProviderOptionsKey,defaultProviderOptions)};loadGlobalOptions();export const setProviderOptions=r=>{const e=getGlobalValue(globalProviderOptionsKey);if(!isProviderOptions(e))throw new Error("Unexpected state, global options invalid");Object.assign(e,r),setGlobalValue(globalProviderOptionsKey,e)};const validateProvider=r=>{if(!r)throw new Error("No cryptographic provider provided");if(!isCryptoProvider(r))throw new Error("Provided cryptographic provider does not match expected interface");if(3!==r.majorVersion)throw new Error(`Cryptographic provider version mismatch (expected 3, got ${r.majorVersion})`);return r};export const registerProvider=r=>{const e=getGlobalValue(globalProviderKey);try{validateProvider(e),console.warn("Multiple cryptographic provider tried to register. This indicate dependencies issues.")}catch{validateProvider(r),setGlobalValue(globalProviderKey,r),activeProvider=r}};export const setProvider=(r,e)=>{r&&registerProvider(r),e&&setProviderOptions(e)};export const getProvider=()=>{if(!activeProvider){const r=validateProvider(getGlobalValue(globalProviderKey));activeProvider=r}return activeProvider};export const getProviderOptions=()=>{const r=getGlobalValue(globalProviderOptionsKey);if(!isProviderOptions(r))throw new Error("Unexpected state, global options invalid");return{...r}};
//# sourceMappingURL=/sm/2dc14a4d55d9f3ef2fbe20f34a2cb657e954de9c4cf66afae5a9eb867469bc5e.map