1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CREDMGR_NAPI_H 17 #define CREDMGR_NAPI_H 18 19 #include "device_auth.h" 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 23 namespace OHOS { 24 namespace CredMgrNapi { 25 26 enum AsyncType { 27 ASYNC_CALLBACK = 1, 28 ASYNC_PROMISE = 2, 29 }; 30 31 constexpr size_t ARGS_SIZE_TWO = 2; 32 constexpr size_t ARGS_SIZE_THREE = 3; 33 constexpr int32_t PARAM0 = 0; 34 constexpr int32_t PARAM1 = 1; 35 36 class NapiCredManager { 37 public: 38 explicit NapiCredManager(CredManager *manager); 39 ~NapiCredManager(); 40 41 CredManager *GetCurrentCredMgr(); 42 43 static napi_value NapiCredMgrConstructor(napi_env env, napi_callback_info info); 44 static napi_value NapiGetCredMgrInstance(napi_env env, napi_callback_info info); 45 static napi_value NapiBatchUpdateCreds(napi_env env, napi_callback_info info); 46 47 static void CredMgrNapiRegister(napi_env env, napi_value exports); 48 static thread_local napi_ref classRef_; 49 50 private: 51 CredManager *credManager_ = nullptr; 52 static std::mutex g_instanceLock; 53 }; 54 55 } // namespace CredMgrNapi 56 } // namespace OHOS 57 58 #endif