remote = Remote();
+ if (remote == nullptr) {
+ return false;
+ }
+
+ int32_t result = remote->SendRequest(code, data, reply, option);
+ if (result != OHOS::UserIAM::UserAuth::SUCCESS) {
+ USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthProxy SendRequest fail");
+ return false;
+ }
+ return true;
+}
+} // namespace UserAuth
+} // namespace UserIam
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/innerkits/js/ohos.UserIAM.userAuth.d.ts b/interfaces/innerkits/js/ohos.UserIAM.userAuth.d.ts
new file mode 100644
index 0000000..dafdc1f
--- /dev/null
+++ b/interfaces/innerkits/js/ohos.UserIAM.userAuth.d.ts
@@ -0,0 +1,379 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import{AsyncCallback} from './basic';
+
+declare namespace userIAM
+{
+ class UserAuth
+ {
+ /**
+ * constructor.
+ *
+ * @return Constructor to get the userauth class instance
+ */
+ constructor();
+
+ /**
+ * getVersion.
+ *
+ * @return Get version information
+ */
+ getVersion() : number;
+
+ /**
+ * getAvailabeStatus.
+ *
+ * Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
+ *
+ * @param authType Credential type for authentication.
+ * @param authTrustLevel Credibility level of certification results.
+ * @return number.
+ */
+ getAvailabeStatus(authType : AuthType, authTrustLevel : AuthTurstLevel) : number;
+ /**
+ * getProperty.
+ *
+ *
Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
+ *
+ * @param request the attribute field list, authentication credential type, and credential subclass.
+ * @return ExecutorProperty: Get the attribute, pass in the credential type and the key to get, and return the value
+ * corresponding to the key (support to query subclasses / remaining authentication times / freezing time)
+ */
+ getProperty(request : GetPropertyRequest) : Promise;
+ getProperty(request: GetPropertyRequest, callback: AsyncCallback): void
+
+ /**
+ * getProperty.
+ *
+ * Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
+ *
+ * @param request pass in the credential type and the key value to be set.
+ * @return number.
+ */
+ setProperty(request: SetPropertyRequest): Promise;
+ setProperty(request: SetPropertyRequest, callback: AsyncCallback): void
+
+ /**
+ * auth
+ *
+ * Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
+ *
+ * @param challenge pass in challenge value.
+ * @param authMethod authentication method.
+ * @param authTrustLevel Credibility level of certification results.
+ * @param callback Return results and acquireinfo through callback.
+ * @return BigInt.
+ */
+ auth(challenge: BigInt, authMethod: number, authTrustLevel: AuthTurstLevel, callback: IUserAuthCallback): BigInt;
+
+ /**
+ * authUser
+ *
+ *
Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
+ *
+ * @param userId Incoming user ID.
+ * @param challenge pass in challenge value.
+ * @param authMethod authentication method.
+ * @param authTrustLevel Credibility level of certification results.
+ * @param callback Return results and acquireinfo through callback.
+ * @return BigInt.
+ */
+ authUser(userId: number, challenge: BigInt, authMethod: number, authTrustLevel: AuthTurstLevel, callback : IUserAuthCallback): BigInt;
+
+ /**
+ * getProperty.
+ *
+ *
Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
+ *
+ * @param contextID Cancel authentication and pass in ContextID.
+ * @return number.
+ */
+ cancelAuth(contextID : BigInt) : number;
+ }
+
+ /**
+ * Credential type for authentication
+ */
+ enum AuthType {
+ /**
+ * Authentication type pin.
+ */
+ PIN = 1,
+ /**
+ * Authentication type face.
+ */
+ FACE = 2
+ }
+
+ /**
+ * Credential subtype: 6-digit digital password, user-defined digital password,
+ * user-defined mixed password, 2D face, 3D face
+ */
+ enum AuthSubType{
+ /**
+ * Authentication sub type six number pin.
+ */
+ PIN_SIX = 10000,
+ /**
+ * Authentication sub type self defined number pin.
+ */
+ PIN_NUMBER = 10001,
+ /**
+ * Authentication sub type 2D face.
+ */
+ PIN_MIXED = 10002,
+ /**
+ * Authentication sub type 2D face.
+ */
+ FACE_2D = 20000,
+ /**
+ * Authentication sub type 3D face.
+ */
+ FACE_3D = 20001
+ }
+
+ /**
+ * Credibility level of certification results
+ */
+ enum AuthTurstLevel {
+ /**
+ * Authentication result trusted level 1.
+ */
+ ATL1 = 10000,
+ /**
+ * Authentication result trusted level 2.
+ */
+ ATL2 = 20000,
+ /**
+ * Authentication result trusted level 3.
+ */
+ ATL3 = 30000,
+ /**
+ * Authentication result trusted level 4.
+ */
+ ATL4 = 40000
+ }
+
+ /**
+ * Actuator attribute list
+ */
+ enum GetPropertyType {
+ /**
+ * Authentication remain times.
+ */
+ AUTH_SUB_TYPE = 1,
+ /**
+ * Authentication remain times.
+ */
+ REMAIN_TIMES = 2,
+ /**
+ * Authentication freezing time.
+ */
+ FREEZING_TIME = 3
+ }
+
+ /**
+ * Get attribute request: the attribute field list, authentication credential type, and credential subclass
+ * requested to be obtained
+ */
+ interface GetPropertyRequest {
+ authType : AuthType;
+ keys : Array;
+ }
+
+ /**
+ * Actuator attribute: subclass, remaining authentication times, freezing time
+ */
+ interface ExecutorProperty {
+ result: number;
+ authSubType : AuthSubType;
+ remainTimes ?: number;
+ freezingTime ?: number;
+ }
+
+ /**
+ * Actuator attribute list
+ */
+ enum SetPropertyType {
+ /**
+ * init algorithm.
+ */
+ INIT_ALGORITHM = 1,
+ }
+
+ /**
+ * Set attribute request: pass in the credential type and the key value to be set
+ */
+ interface SetPropertyRequest {
+ authType : AuthType;
+ key : SetPropertyType;
+ setInfo : Uint8Array;
+ }
+ /**
+ * Actuator attribute: subclass, remaining authentication times, freezing time
+ */
+ interface ExecutorProperty {
+ result : number;
+ authSubType : AuthSubType;
+ remainTimes ?: number;
+ freezingTime ?: number;
+ }
+ /**
+ * Authentication method and priority: currently only faces are supported
+ */
+ enum AuthMethod {
+ /**
+ * Authentication method PIN.
+ */
+ PIN_ONLY = 0xF,
+ /**
+ * Authentication method face.
+ */
+ FACE_ONLY = 0xF0
+ }
+
+ /**
+ * The authentication result code is returned through the callback, the authentication is passed, the authentication
+ * token is returned in extrainfo, the authentication fails, the remaining authentication times are returned in
+ * extrainfo, the authentication actuator is locked, and the freezing time / acquireinfo is returned in extrainfo
+ */
+ interface IUserAuthCallback {
+ onResult: (result : number, extraInfo : AuthResult) => void;
+ onAcquireInfo ?: (module : number, acquire : number, extraInfo : any) => void
+ }
+
+ /**
+ * Returns the module of acquireinfo
+ */
+ enum Module {
+ /**
+ * Acquire information from FaceAuth.
+ */
+ FACE_AUTH = 1
+ }
+
+ /**
+ * Authentication result: authentication token, remaining authentication times, freezing time
+ */
+ interface AuthResult {
+ token ?: Uint8Array;
+ remainTimes ?: number;
+ freezingTime ?: number;
+ }
+
+ /**
+ * Result code
+ */
+ enum ResultCode {
+ /**
+ * Indicates that authentication is success or ability is supported.
+ */
+ SUCCESS = 0,
+ /**
+ * Indicates the authenticator fails to identify user.
+ */
+ FAIL = 1,
+ /**
+ * Indicates other errors.
+ */
+ GENERAL_ERROR = 2,
+ /**
+ * Indicates that authentication has been canceled.
+ */
+ CANCELED = 3,
+ /**
+ * Indicates that authentication has timed out.
+ */
+ TIMEOUT = 4,
+ /**
+ * Indicates that this authentication type is not supported.
+ */
+ TYPE_NOT_SUPPORT = 5,
+ /**
+ * Indicates that the authentication trust level is not supported.
+ */
+ TRUST_LEVEL_NOT_SUPPORT = 6,
+ /**
+ * Indicates that the authentication task is busy. Wait for a few seconds and try again.
+ */
+ BUSY = 7,
+ /**
+ * Indicates incorrect parameters.
+ */
+ INVALID_PARAMETERS = 8,
+ /**
+ * Indicates that the authenticator is locked.
+ */
+ LOCKED = 9,
+ /**
+ * Indicates that the user has not enrolled the authenticator.
+ */
+ NOT_ENROLLED = 10
+ }
+
+ /**
+ * Enumeration of prompt codes during authentication
+ */
+ enum FaceTipsCode {
+ /**
+ * Indicates that the obtained facial image is too bright due to high illumination.
+ */
+ FACE_AUTH_TIP_TOO_BRIGHT = 1,
+ /**
+ * Indicates that the obtained facial image is too dark due to low illumination.
+ */
+ FACE_AUTH_TIP_TOO_DARK = 2,
+ /**
+ * Indicates that the face is too close to the device.
+ */
+ FACE_AUTH_TIP_TOO_CLOSE = 3,
+ /**
+ * Indicates that the face is too far away from the device.
+ */
+ FACE_AUTH_TIP_TOO_FAR = 4,
+ /**
+ * Indicates that the device is too high, and that only the upper part of the face is captured.
+ */
+ FACE_AUTH_TIP_TOO_HIGH = 5,
+ /**
+ * Indicates that the device is too low, and that only the lower part of the face is captured.
+ */
+ FACE_AUTH_TIP_TOO_LOW = 6,
+ /**
+ * Indicates that the device is deviated to the right, and that only the right part of the face is captured.
+ */
+ FACE_AUTH_TIP_TOO_RIGHT = 7,
+ /**
+ * Indicates that the device is deviated to the left, and that only the left part of the face is captured.
+ */
+ FACE_AUTH_TIP_TOO_LEFT = 8,
+ /**
+ * Indicates that the face moves too fast during facial information collection.
+ */
+ FACE_AUTH_TIP_TOO_MUCH_MOTION = 9,
+ /**
+ * Indicates that the face is not facing the device.
+ */
+ FACE_AUTH_TIP_POOR_GAZE = 10,
+ /**
+ * Indicates that no face is detected.
+ */
+ FACE_AUTH_TIP_NOT_DETECTED = 11,
+ }
+
+}
+
+export default userIAM;
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/BUILD.gn b/interfaces/innerkits/napi/BUILD.gn
new file mode 100644
index 0000000..962003f
--- /dev/null
+++ b/interfaces/innerkits/napi/BUILD.gn
@@ -0,0 +1,69 @@
+# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//base/useriam/userauth/userauth.gni")
+
+config("userauth_public_config") {
+ include_dirs = [
+ "include"
+ ]
+}
+
+ohos_shared_library("userauth") {
+ include_dirs = [
+ # "common/include",
+ # "//third_party/node/src",
+ # "//foundation/ace/napi/interfaces/kits",
+ # "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
+ ]
+
+
+ cflags = [
+ "-fPIC",
+ "-g3",
+ ]
+
+ sources = [
+ "src/auth_native_module.cpp",
+ "src/user_auth_impl.cpp",
+ "src/auth_build.cpp",
+ "src/result_convert.cpp",
+ "src/user_auth_helper.cpp",
+ "src/authapi_callback.cpp",
+ ]
+
+ deps = [
+ "//utils/native/base:utils",
+ "${userauth_innerkits_path}/native:userauth_framework",
+ "//foundation/ace/napi:ace_napi"
+ ]
+
+ configs = [
+ "${userauth_utils_path}:utils_config",
+ ]
+
+ public_configs = [ ":userauth_public_config" ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ relative_install_dir = "module"
+
+ part_name = "userauth"
+ subsystem_name = "userauth"
+}
diff --git a/interfaces/innerkits/napi/include/auth_build.h b/interfaces/innerkits/napi/include/auth_build.h
new file mode 100644
index 0000000..34050e5
--- /dev/null
+++ b/interfaces/innerkits/napi/include/auth_build.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FACERECOGNITION_AUTH_BUILD_H
+#define FACERECOGNITION_AUTH_BUILD_H
+
+#include "napi/native_common.h"
+#include "napi/native_node_api.h"
+
+#include "userauth_info.h"
+
+#include "auth_common.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class AuthBuild {
+public:
+ AuthBuild();
+ ~AuthBuild();
+ Napi_SetPropertyRequest SetPropertyRequestBuild(napi_env env, napi_value object);
+ Napi_GetPropertyRequest GetPropertyRequestBuild(napi_env env, napi_value object);
+ napi_value GetNapiExecutorProperty(napi_env env, Napi_ExecutorProperty property);
+ napi_value BuildAuthResult(napi_env env, Napi_AuthResult authResult);
+ bool NapiTypeObject(napi_env env, napi_value value);
+ bool NapiTypeBitInt(napi_env env, napi_value value);
+ bool NapiTypeNumber(napi_env env, napi_value value);
+
+ void AuthUserCallBackResult(napi_env env, AuthUserInfo *userInfo);
+ void AuthUserCallBackAcquireInfo(napi_env env, AuthUserInfo *userInfo);
+ void AuthCallBackAcquireInfo(napi_env env, AuthInfo *authInfo);
+ void AuthCallBackResult(napi_env env, AuthInfo *authInfo);
+ uint64_t GetUint8ArrayTo64(napi_env env, napi_value value);
+ int NapiGetValueInt(napi_env env, napi_value value);
+ napi_value Uint64ToUint8Array(napi_env env, uint64_t value);
+};
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+#endif // FACERECOGNITION_AUTH_BUILD_H
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/include/auth_common.h b/interfaces/innerkits/napi/include/auth_common.h
new file mode 100644
index 0000000..d45e2eb
--- /dev/null
+++ b/interfaces/innerkits/napi/include/auth_common.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OHOS_USERAUTH_COMMON_H
+#define OHOS_USERAUTH_COMMON_H
+
+#include "napi/native_common.h"
+#include "napi/native_node_api.h"
+
+#include
+#include
+#include
+#include
+#include
+
+#include "auth_object.h"
+#include "userauth_info.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+#define ARGS_MAX_COUNT 10
+#define ARGS_ASYNC_COUNT 1
+#define GET_VALUE_ERROR (-1)
+#define NAPI_GET_STRING_SIZE 128
+
+#define ARGS_ONE 1
+#define ARGS_TWO 2
+#define ARGS_THREE 3
+#define ARGS_FOUR 4
+#define ARGS_FIVE 5
+#define ARGS_SIX 6
+#define ARGS_SEVEN 7
+#define ARGS_EIGHT 8
+#define ARGS_NINE 9
+#define ARGS_TEN 10
+
+#define PARAM0 0
+#define PARAM1 1
+#define PARAM2 2
+#define PARAM3 3
+#define PARAM4 4
+#define PARAM5 5
+#define PARAM6 6
+#define PARAM7 7
+#define PARAM8 8
+#define PARAM9 9
+#define PARAM10 10
+
+struct CallBackInfo {
+ napi_env env;
+ napi_ref callBack = 0;
+ napi_deferred deferred;
+};
+
+struct GetVersionInfo {
+ GetVersionInfo() : asyncWork(nullptr) {};
+ CallBackInfo callBackInfo;
+ napi_async_work asyncWork;
+};
+
+struct GetPropertyInfo {
+ GetPropertyInfo() : asyncWork(nullptr), result(nullptr) {};
+ CallBackInfo callBackInfo;
+ napi_async_work asyncWork;
+ napi_value result;
+ int32_t authType;
+ UserIAM::UserAuth::ExecutorProperty property;
+ std::vector keys;
+};
+
+struct SetPropertyInfo {
+ SetPropertyInfo() : asyncWork(nullptr), result(nullptr) {};
+ CallBackInfo callBackInfo;
+ napi_async_work asyncWork;
+ napi_value result;
+ int authType;
+ int32_t key;
+ std::vector setInfo;
+};
+
+struct AuthInfo {
+ AuthInfo() : asyncWork(nullptr) {};
+ CallBackInfo callBackInfo;
+ napi_callback_info info;
+ napi_async_work asyncWork;
+ napi_value jsFunction;
+ napi_ref onResultCallBack;
+ napi_ref onAcquireInfoCallBack;
+ napi_value onResultData[ARGS_TWO];
+ napi_value onAcquireInfoData[ARGS_THREE];
+ uint64_t challenge;
+ int32_t authType;
+ int32_t authTrustLevel;
+
+ int32_t module;
+ uint32_t acquireInfo;
+ bool extraInfoIsNull;
+ int32_t result;
+ Napi_AuthResult authResult;
+};
+
+struct AuthUserInfo {
+ AuthUserInfo() : asyncWork(nullptr) {};
+ CallBackInfo callBackInfo;
+ napi_callback_info info;
+ napi_async_work asyncWork;
+ napi_value jsFunction;
+ napi_value onResultCallBack;
+ napi_value onAcquireInfoCallBack;
+ napi_value onResultData[ARGS_TWO];
+ napi_value onAcquireInfoData[ARGS_THREE];
+ int32_t userId;
+ uint64_t challenge;
+ int32_t authType;
+ int32_t authTrustLevel;
+
+ int32_t module;
+ uint32_t acquireInfo;
+ bool extraInfoIsNull;
+ int32_t result;
+ Napi_AuthResult authResult;
+};
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+#endif /* OHOS_USERAUTH_COMMON_H */
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/include/auth_hilog_wrapper.h b/interfaces/innerkits/napi/include/auth_hilog_wrapper.h
new file mode 100644
index 0000000..f8e944e
--- /dev/null
+++ b/interfaces/innerkits/napi/include/auth_hilog_wrapper.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HILOG_WRAPPER_H
+#define HILOG_WRAPPER_H
+
+#define CONFIG_HILOG
+#ifdef CONFIG_HILOG
+
+#include "hilog/log.h"
+
+#ifdef HILOG_FATAL
+#undef HILOG_FATAL
+#endif
+
+#ifdef HILOG_ERROR
+#undef HILOG_ERROR
+#endif
+
+#ifdef HILOG_WARN
+#undef HILOG_WARN
+#endif
+
+#ifdef HILOG_INFO
+#undef HILOG_INFO
+#endif
+
+#ifdef HILOG_DEBUG
+#undef HILOG_DEBUG
+#endif
+
+static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0, "UserAuthNapi===>"};
+
+#define HILOG_FATAL(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LOG_LABEL, __VA_ARGS__)
+#define HILOG_ERROR(...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, __VA_ARGS__)
+#define HILOG_WARN(...) (void)OHOS::HiviewDFX::HiLog::Warn(LOG_LABEL, __VA_ARGS__)
+#define HILOG_INFO(...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, __VA_ARGS__)
+#define HILOG_DEBUG(...) (void)OHOS::HiviewDFX::HiLog::Debug(LOG_LABEL, __VA_ARGS__)
+#else
+
+#define HILOG_FATAL(...)
+#define HILOG_ERROR(...)
+#define HILOG_WARN(...)
+#define HILOG_INFO(...)
+#define HILOG_DEBUG(...)
+
+#endif // CONFIG_HILOG
+
+#endif // HILOG_WRAPPER_H
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/include/auth_object.h b/interfaces/innerkits/napi/include/auth_object.h
new file mode 100644
index 0000000..7842eb9
--- /dev/null
+++ b/interfaces/innerkits/napi/include/auth_object.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AUTH_OBJECT_H
+#define AUTH_OBJECT_H
+
+#include
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class Napi_ExecutorProperty {
+public:
+ int32_t result_ = 0;
+ int32_t authSubType_ = 0;
+ uint32_t remainTimes_ = 0;
+ uint32_t freezingTime_ = 0;
+};
+
+class Napi_SetPropertyRequest {
+public:
+ int32_t authType_ = 0;
+ int32_t key_ = 0;
+ std::vector setInfo_;
+};
+
+class Napi_GetPropertyRequest {
+public:
+ int32_t authType_ = 0;
+ std::vector keys_;
+};
+
+class Napi_AuthResult {
+public:
+ std::vector token_;
+ uint32_t remainTimes_;
+ uint32_t freezingTime_;
+};
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+#endif // AUTH_OBJECT_H
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/include/authapi_callback.h b/interfaces/innerkits/napi/include/authapi_callback.h
new file mode 100644
index 0000000..a081b25
--- /dev/null
+++ b/interfaces/innerkits/napi/include/authapi_callback.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AUTHAPI_CALLBACK_H
+#define AUTHAPI_CALLBACK_H
+
+#include "napi/native_common.h"
+#include "napi/native_node_api.h"
+
+#include "userauth_callback.h"
+#include "userauth_info.h"
+
+#include "auth_common.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class AuthApiCallback : public UserAuthCallback {
+public:
+ AuthApiCallback();
+ virtual ~AuthApiCallback();
+ Napi_ExecutorProperty peoperty_;
+ GetPropertyInfo *getPropertyInfo_;
+ SetPropertyInfo *setPropertyInfo_;
+ AuthInfo *authInfo_;
+ AuthUserInfo *userInfo_;
+ void onExecutorPropertyInfo(const ExecutorProperty result) override;
+ void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override;
+ void onResult(const int32_t result, const AuthResult extraInfo) override;
+ void onSetExecutorProperty(const int32_t result) override;
+};
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+#endif // AUTHAPI_CALLBACK_H
diff --git a/interfaces/innerkits/napi/include/result_convert.h b/interfaces/innerkits/napi/include/result_convert.h
new file mode 100644
index 0000000..28a5946
--- /dev/null
+++ b/interfaces/innerkits/napi/include/result_convert.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RESULT_CONVERT_H
+#define RESULT_CONVERT_H
+
+#include
+#include
+
+#include "napi/native_common.h"
+#include "napi/native_node_api.h"
+
+#include "auth_common.h"
+#include "auth_object.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class ResultConvert {
+public:
+ ResultConvert();
+ ~ResultConvert();
+ std::vector NapiGetValueUint8Array(napi_env env, napi_value jsObject, std::string key);
+ napi_value BuildArrayExecutorProperty(napi_env env, Napi_ExecutorProperty property);
+ napi_valuetype GetType(napi_env env, napi_value value);
+ std::string GetStringValueByKey(napi_env env, napi_value jsObject, std::string key);
+ int32_t NapiGetValueInt32(napi_env env, napi_value value);
+ std::vector GetInt32ArrayValueByKey(napi_env env, napi_value jsObject, std::string key);
+ int32_t GetInt32ValueByKey(napi_env env, napi_value jsObject, std::string key);
+ int NapiGetValueInt(napi_env env, napi_value value);
+ void SetPropertyUint8Array(napi_env env, napi_value &jsObject, uint64_t value, std::string key);
+ napi_value GetAuthInfoRet(napi_env env, uint64_t Ret);
+ void SetPropertyUint8ArrayTest(napi_env env, napi_value &jsObject, std::vector value, std::string key);
+ std::vector ConvertUint8(uint64_t value);
+ napi_value BuildNapiUint8Array(napi_env env, std::vector value);
+
+private:
+ void SetPropertyInt(napi_env env, napi_value &jsObject, int32_t value, std::string key);
+ void SetPropertyUint(napi_env env, napi_value &jsObject, uint32_t value, std::string key);
+ void SetPropertyBigint(napi_env env, napi_value &jsObject, uint64_t value, std::string key);
+ std::string NapiGetValueString(napi_env env, napi_value value);
+ napi_value GetNapiValue(napi_env env, const std::string keyChar, napi_value object);
+};
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+#endif // RESULT_CONVERT_H
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/include/user_auth_helper.h b/interfaces/innerkits/napi/include/user_auth_helper.h
new file mode 100644
index 0000000..e791d02
--- /dev/null
+++ b/interfaces/innerkits/napi/include/user_auth_helper.h
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef FACERECOGNITION_PIN_AUTH_HELPER_H
+#define FACERECOGNITION_PIN_AUTH_HELPER_H
+
+#include "napi/native_common.h"
+#include "napi/native_node_api.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+/**
+ * @brief Napi initialization
+ *
+ * @param env
+ * @param exports
+ */
+void Init(napi_env env, napi_value exports);
+
+/**
+ * @brief Get the Ctor object
+ *
+ * @param env
+ * @return napi_value UserAuth Instance
+ */
+napi_value GetCtor(napi_env env);
+/**
+ * @brief Construction method
+ *
+ * @param env
+ * @param info
+ * @return napi_value UserAuth Instance
+ */
+napi_value Constructor(napi_env env, napi_callback_info info);
+
+/**
+ * @brief Instance passed to context
+ *
+ * @param env
+ * @param info
+ * @return napi_value Instance
+ */
+napi_value UserAuthServiceConstructor(napi_env env, napi_callback_info info);
+
+/**
+ * @brief Get the Version object
+ *
+ * @param env
+ * @param info
+ * @return napi_value Specific version number results
+ */
+napi_value GetVersion(napi_env env, napi_callback_info info);
+
+/**
+ * @brief Get the Availabe Status object
+ *
+ * @param env
+ * @param info
+ * @return napi_value Verify that the certification capability is available
+ */
+napi_value GetAvailabeStatus(napi_env env, napi_callback_info info);
+
+/**
+ * @brief Get the Property object
+ *
+ * @param env
+ * @param info
+ * @return napi_value It supports querying subclasses / remaining authentication times / freezing time
+ */
+napi_value GetProperty(napi_env env, napi_callback_info info);
+
+/**
+ * @brief Set the Property object
+ *
+ * @param env
+ * @param info
+ * @return napi_value Set properties: can be used to initialize algorithms
+ */
+napi_value SetProperty(napi_env env, napi_callback_info info);
+
+/**
+ * @brief user authentication
+ *
+ * @param env
+ * @param info
+ * @return napi_value Enter the challenge value, authentication method, trust level and callback, and return the result
+ * and acquireinfo through the callback
+ */
+napi_value Auth(napi_env env, napi_callback_info info);
+
+/**
+ * @brief user authentication
+ *
+ * @param env
+ * @param info
+ * @return napi_value Pass in the user ID, challenge value, authentication method, trust level and callback, and return
+ * the result acquireinfo through the callback
+ */
+napi_value AuthUser(napi_env env, napi_callback_info info);
+
+/**
+ * @brief Cancel authentication
+ *
+ * @param env
+ * @param info
+ * @return napi_value success or fail
+ */
+napi_value CancelAuth(napi_env env, napi_callback_info info);
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+#endif // FACERECOGNITION_PIN_AUTH_HELPER_H
diff --git a/interfaces/innerkits/napi/include/user_auth_impl.h b/interfaces/innerkits/napi/include/user_auth_impl.h
new file mode 100644
index 0000000..4162757
--- /dev/null
+++ b/interfaces/innerkits/napi/include/user_auth_impl.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef FACERECOGNITION_USER_AUTH_H
+#define FACERECOGNITION_USER_AUTH_H
+
+#include "auth_common.h"
+#include "napi/native_common.h"
+#include "napi/native_node_api.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class UserAuthImpl {
+public:
+ UserAuthImpl();
+ ~UserAuthImpl();
+
+ napi_value GetVersion(napi_env env, napi_callback_info info);
+ napi_value GetVersion(napi_env env, GetVersionInfo *getVersionInfo);
+ napi_value GetAvailabeStatus(napi_env env, napi_callback_info info);
+ napi_value GetProperty(napi_env env, napi_callback_info info);
+ napi_value SetProperty(napi_env env, napi_callback_info info);
+ napi_value Auth(napi_env env, napi_callback_info info);
+ napi_value AuthUser(napi_env env, napi_callback_info info);
+ napi_value CancelAuth(napi_env env, napi_callback_info info);
+
+private:
+ napi_value GetPropertyWrap(napi_env env, napi_callback_info info, GetPropertyInfo *getPropertyInfo);
+ napi_value GetPropertyAsync(napi_env env, GetPropertyInfo *getPropertyInfo);
+ napi_value GetPropertyPromise(napi_env env, GetPropertyInfo *getPropertyInfo);
+
+ napi_value SetPropertyWrap(napi_env env, napi_callback_info info, SetPropertyInfo *setPropertyInfo);
+ napi_value SetPropertyAsync(napi_env env, SetPropertyInfo *setPropertyInfo);
+ napi_value SetPropertyPromise(napi_env env, SetPropertyInfo *setPropertyInfo);
+
+ napi_value AuthWrap(napi_env env, AuthInfo *authInfo);
+ static void AuthExecute(napi_env env, void *data);
+ static void AuthExecuteDone(napi_env env, napi_status status, void *data);
+ napi_value AuthUserWrap(napi_env env, AuthUserInfo *userInfo);
+ static void AuthUserExecute(napi_env env, void *data);
+ static void AuthUserExecuteDone(napi_env env, napi_status status, void *data);
+ static void AuthCallBack(napi_env env, AuthInfo *authInfo);
+ static void AuthUserCallBack(napi_env env, AuthUserInfo *userInfo);
+
+ static void SetPropertyExecute(napi_env env, void *data);
+ static void SetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data);
+ static void SetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data);
+ static void GetPropertyExecute(napi_env env, void *data);
+ static void GetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data);
+ static void GetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data);
+};
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+#endif // FACERECOGNITION_USER_AUTH_H
diff --git a/interfaces/innerkits/napi/src/auth_build.cpp b/interfaces/innerkits/napi/src/auth_build.cpp
new file mode 100644
index 0000000..5cd3ad2
--- /dev/null
+++ b/interfaces/innerkits/napi/src/auth_build.cpp
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "auth_build.h"
+
+#include "auth_common.h"
+#include "auth_hilog_wrapper.h"
+#include "auth_object.h"
+#include "result_convert.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+AuthBuild::AuthBuild(void)
+{
+}
+AuthBuild::~AuthBuild()
+{
+}
+
+Napi_SetPropertyRequest AuthBuild::SetPropertyRequestBuild(napi_env env, napi_value object)
+{
+ Napi_SetPropertyRequest request;
+ if (object == nullptr) {
+ HILOG_ERROR("SetPropertyRequestBuild object is null ");
+ return request;
+ }
+ UserAuth::ResultConvert convert;
+ request.authType_ = convert.GetInt32ValueByKey(env, object, "authType");
+ request.key_ = convert.GetInt32ValueByKey(env, object, "key");
+ request.setInfo_ = convert.NapiGetValueUint8Array(env, object, "setInfo");
+ HILOG_INFO(" AuthBuild::SetPropertyRequestBuild authType = %{public}d", request.authType_);
+ HILOG_INFO(" AuthBuild::SetPropertyRequestBuild key = %{public}d", request.key_);
+ return request;
+}
+
+Napi_GetPropertyRequest AuthBuild::GetPropertyRequestBuild(napi_env env, napi_value object)
+{
+ Napi_GetPropertyRequest request;
+ if (object == nullptr) {
+ HILOG_ERROR("GetPropertyRequestBuild object is null ");
+ return request;
+ }
+ UserAuth::ResultConvert convert;
+ request.authType_ = convert.GetInt32ValueByKey(env, object, "authType");
+ request.keys_ = convert.GetInt32ArrayValueByKey(env, object, "keys");
+ HILOG_INFO(" AuthBuild::GetPropertyRequestBuild authType = %{public}d", request.authType_);
+ return request;
+}
+
+napi_value AuthBuild::GetNapiExecutorProperty(napi_env env, Napi_ExecutorProperty property)
+{
+ ResultConvert convert;
+ return convert.BuildArrayExecutorProperty(env, property);
+}
+
+bool AuthBuild::NapiTypeObject(napi_env env, napi_value value)
+{
+ if (value == nullptr) {
+ return false;
+ }
+ ResultConvert convert;
+ napi_valuetype isObject = convert.GetType(env, value);
+ if (isObject == napi_object) {
+ return true;
+ }
+ return false;
+}
+
+bool AuthBuild::NapiTypeBitInt(napi_env env, napi_value value)
+{
+ if (value == nullptr) {
+ return false;
+ }
+ ResultConvert convert;
+ napi_valuetype isBigInt = convert.GetType(env, value);
+ if (isBigInt == napi_bigint) {
+ return true;
+ }
+ return false;
+}
+
+bool AuthBuild::NapiTypeNumber(napi_env env, napi_value value)
+{
+ if (value == nullptr) {
+ return false;
+ }
+ ResultConvert convert;
+ napi_valuetype isNumber = convert.GetType(env, value);
+ if (isNumber == napi_number) {
+ return true;
+ }
+ return false;
+}
+
+napi_value AuthBuild::BuildAuthResult(napi_env env, Napi_AuthResult authResult)
+{
+ HILOG_INFO("BuildAuthResult start");
+ napi_value object = nullptr;
+ NAPI_CALL(env, napi_create_object(env, &object));
+
+ napi_value keyToken = nullptr;
+ NAPI_CALL(env, napi_create_string_utf8(env, "token", NAPI_AUTO_LENGTH, &keyToken));
+
+ ResultConvert convert;
+ napi_value token = convert.BuildNapiUint8Array(env, authResult.token_);
+ NAPI_CALL(env, napi_set_property(env, object, keyToken, token));
+
+ napi_value keyRemainTimes = nullptr;
+ NAPI_CALL(env, napi_create_string_utf8(env, "remainTimes", NAPI_AUTO_LENGTH, &keyRemainTimes));
+ uint32_t remainTimes = authResult.remainTimes_;
+ napi_value remainTimesValue = nullptr;
+ NAPI_CALL(env, napi_create_uint32(env, remainTimes, &remainTimesValue));
+ NAPI_CALL(env, napi_set_property(env, object, keyRemainTimes, remainTimesValue));
+
+ napi_value keyFreezingTime = nullptr;
+ NAPI_CALL(env, napi_create_string_utf8(env, "freezingTime", NAPI_AUTO_LENGTH, &keyFreezingTime));
+ uint32_t freezingTime = authResult.freezingTime_;
+ napi_value freezingTimeValue = nullptr;
+ NAPI_CALL(env, napi_create_uint32(env, freezingTime, &freezingTimeValue));
+ NAPI_CALL(env, napi_set_property(env, object, keyFreezingTime, freezingTimeValue));
+ HILOG_INFO("BuildAuthResult end");
+ return object;
+}
+
+void AuthBuild::AuthUserCallBackResult(napi_env env, AuthUserInfo *userInfo)
+{
+ HILOG_INFO("%{public}s, start ", __func__);
+ napi_status status;
+ int32_t result = userInfo->result;
+ napi_value dataResult = 0;
+ status = napi_create_int32(env, result, &dataResult);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_int32 faild");
+ }
+ userInfo->onResultData[0] = dataResult;
+
+ napi_value resultExtraInfo = BuildAuthResult(env, userInfo->authResult);
+ userInfo->onResultData[1] = resultExtraInfo;
+ HILOG_INFO("%{public}s, end", __func__);
+}
+
+void AuthBuild::AuthUserCallBackAcquireInfo(napi_env env, AuthUserInfo *userInfo)
+{
+ HILOG_INFO("%{public}s, start ", __func__);
+ napi_value jsModule = 0;
+ napi_status status;
+ int32_t jsModeValue = userInfo->module;
+ status = napi_create_int32(env, jsModeValue, &jsModule);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_int32 faild");
+ }
+ userInfo->onAcquireInfoData[0] = jsModule;
+ napi_value acquire = 0;
+ uint32_t acquireValue = userInfo->acquireInfo;
+ status = napi_create_uint32(env, acquireValue, &acquire);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_uint32 faild");
+ }
+ userInfo->onAcquireInfoData[1] = acquire;
+
+ if (userInfo->extraInfoIsNull) {
+ napi_value result = 0;
+ status = napi_get_null(env, &result);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_null faild");
+ }
+ userInfo->onAcquireInfoData[ARGS_TWO] = result;
+ } else {
+ HILOG_INFO("%{public}s, extraInfo Is not Null ", __func__);
+ napi_value result = 0;
+ status = napi_get_null(env, &result);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_null faild");
+ }
+ userInfo->onAcquireInfoData[ARGS_TWO] = result;
+ }
+}
+
+void AuthBuild::AuthCallBackAcquireInfo(napi_env env, AuthInfo *authInfo)
+{
+ HILOG_INFO("%{public}s, start ", __func__);
+ napi_status status;
+ napi_value jsModule = 0;
+ int32_t jsModeValue = authInfo->module;
+ status = napi_create_int32(env, jsModeValue, &jsModule);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_int32 faild");
+ }
+ authInfo->onAcquireInfoData[0] = jsModule;
+ napi_value acquire = 0;
+ uint32_t acquireValue = authInfo->acquireInfo;
+ status = napi_create_uint32(env, acquireValue, &acquire);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_uint32 faild");
+ }
+ authInfo->onAcquireInfoData[1] = acquire;
+
+ if (authInfo->extraInfoIsNull) {
+ napi_value result = 0;
+ status = napi_get_null(env, &result);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_null faild");
+ }
+ authInfo->onAcquireInfoData[ARGS_TWO] = result;
+ } else {
+ HILOG_INFO("%{public}s, extraInfo Is not Null ", __func__);
+ napi_value result = 0;
+ status = napi_get_null(env, &result);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_null faild");
+ }
+ authInfo->onAcquireInfoData[ARGS_TWO] = result;
+ }
+ HILOG_INFO("%{public}s, end", __func__);
+}
+
+void AuthBuild::AuthCallBackResult(napi_env env, AuthInfo *authInfo)
+{
+ HILOG_INFO("%{public}s, start ", __func__);
+ napi_status status;
+ int32_t result = authInfo->result;
+ napi_value dataResult = 0;
+ status = napi_create_int32(env, result, &dataResult);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_null faild");
+ }
+ authInfo->onResultData[0] = dataResult;
+
+ napi_value resultExtraInfo = BuildAuthResult(env, authInfo->authResult);
+ authInfo->onResultData[1] = resultExtraInfo;
+ HILOG_INFO("%{public}s, end", __func__);
+}
+
+uint64_t AuthBuild::GetUint8ArrayTo64(napi_env env, napi_value value)
+{
+ napi_typedarray_type arraytype;
+ std::string challenge;
+ size_t length = 0;
+ napi_value buffer = nullptr;
+ size_t offset = 0;
+ uint8_t *data = nullptr;
+ bool isTypedArray = false;
+ napi_is_typedarray(env, value, &isTypedArray);
+ if (isTypedArray) {
+ HILOG_INFO("args[PIN_PARAMS_ONE] is a array");
+ } else {
+ HILOG_INFO("args[PIN_PARAMS_ONE] is not a uint8array");
+ }
+ napi_get_typedarray_info(env, value, &arraytype, &length, reinterpret_cast(&data), &buffer, &offset);
+ if (arraytype == napi_uint8_array) {
+ HILOG_INFO("InputerImpl, OnSetData get uint8 array ");
+ } else {
+ HILOG_ERROR("InputerImpl, OnSetData get uint8 array error");
+ return 0;
+ }
+ if (offset != 0) {
+ HILOG_INFO(" offset is =============>%{public}d", offset);
+ return 0;
+ }
+ std::vector result(data, data+length);
+ challenge.assign(result.begin(), result.end());
+ uint64_t resultUint64 = atol(challenge.c_str());
+ return resultUint64;
+}
+
+int AuthBuild::NapiGetValueInt(napi_env env, napi_value value)
+{
+ ResultConvert convert;
+ return convert.NapiGetValueInt(env, value);
+}
+napi_value AuthBuild::Uint64ToUint8Array(napi_env env, uint64_t value)
+{
+ ResultConvert convert;
+ return convert.BuildNapiUint8Array(env, convert.ConvertUint8(value));
+}
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/src/auth_native_module.cpp b/interfaces/innerkits/napi/src/auth_native_module.cpp
new file mode 100644
index 0000000..35a5d77
--- /dev/null
+++ b/interfaces/innerkits/napi/src/auth_native_module.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include "user_auth_helper.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+static napi_value ModuleInit(napi_env env, napi_value exports)
+{
+ OHOS::UserIAM::UserAuth::Init(env, exports);
+ return exports;
+}
+extern "C" __attribute__((constructor)) void RegisterModule(void)
+{
+ napi_module module = {.nm_version = 1, // NAPI v1
+ .nm_flags = 0, // normal
+ .nm_filename = nullptr,
+ .nm_register_func = ModuleInit,
+ .nm_modname = "UserAuth",
+ .nm_priv = nullptr,
+ .reserved = {}};
+ napi_module_register(&module);
+}
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/src/authapi_callback.cpp b/interfaces/innerkits/napi/src/authapi_callback.cpp
new file mode 100644
index 0000000..09aa6ed
--- /dev/null
+++ b/interfaces/innerkits/napi/src/authapi_callback.cpp
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "authapi_callback.h"
+
+#include "auth_build.h"
+#include "auth_hilog_wrapper.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+AuthApiCallback::AuthApiCallback()
+{
+}
+
+AuthApiCallback::~AuthApiCallback()
+{
+}
+
+void AuthApiCallback::onExecutorPropertyInfo(const ExecutorProperty result)
+{
+ napi_status status;
+ HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 1 = %{public}d", result.result);
+ peoperty_.result_ = result.result;
+ HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 2 = %{public}d", result.authSubType);
+ peoperty_.authSubType_ = result.authSubType;
+ HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 3 = %{public}u", result.remainTimes);
+ peoperty_.remainTimes_ = result.remainTimes;
+ HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 4 = %{public}u", result.freezingTime);
+ peoperty_.freezingTime_ = result.freezingTime;
+ if (getPropertyInfo_ != nullptr) {
+ AuthBuild authBuild;
+ HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 5 ");
+ getPropertyInfo_->result = authBuild.GetNapiExecutorProperty(getPropertyInfo_->callBackInfo.env, peoperty_);
+ if (getPropertyInfo_->callBackInfo.callBack != nullptr) {
+ HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 6 ");
+ napi_value global = nullptr;
+ status = napi_get_global(getPropertyInfo_->callBackInfo.env, &global);
+ if (status != napi_ok) {
+ HILOG_INFO("napi_get_global faild ");
+ }
+ napi_value resultData[1];
+ resultData[0] = getPropertyInfo_->result;
+ getPropertyInfo_->result = nullptr;
+ napi_value result = nullptr;
+ napi_value callBack = nullptr;
+ status = napi_get_reference_value(
+ getPropertyInfo_->callBackInfo.env, getPropertyInfo_->callBackInfo.callBack, &callBack);
+ if (status != napi_ok) {
+ HILOG_INFO("napi_get_reference_value faild ");
+ }
+ status = napi_call_function(getPropertyInfo_->callBackInfo.env, global, callBack, 1, resultData, &result);
+ if (status != napi_ok) {
+ HILOG_INFO("napi_call_function faild ");
+ }
+ } else {
+ napi_value result = getPropertyInfo_->result;
+ napi_deferred deferred = getPropertyInfo_->callBackInfo.deferred;
+ status = napi_resolve_deferred(getPropertyInfo_->callBackInfo.env, deferred, result);
+ if (status != napi_ok) {
+ HILOG_INFO("napi_resolve_deferred faild ");
+ }
+ }
+ delete getPropertyInfo_;
+ getPropertyInfo_ = nullptr;
+ } else {
+ HILOG_INFO("AuthApiCallback onExecutorPropertyInfo getPropertyInfo_ is nullptr");
+ }
+}
+
+void AuthApiCallback::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo)
+{
+ napi_status status;
+ if (userInfo_ != nullptr) {
+ HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 1");
+ userInfo_->module = module;
+ userInfo_->acquireInfo = acquireInfo;
+ HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 2");
+ if (extraInfo == 0) {
+ userInfo_->extraInfoIsNull = true;
+ } else {
+ userInfo_->extraInfoIsNull = false;
+ }
+ HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 3");
+ AuthBuild authBuild;
+ authBuild.AuthUserCallBackAcquireInfo(userInfo_->callBackInfo.env, userInfo_);
+ napi_value returnOnAcquire = nullptr;
+ status = napi_call_function(userInfo_->callBackInfo.env, userInfo_->jsFunction, userInfo_->onAcquireInfoCallBack,
+ ARGS_THREE, userInfo_->onAcquireInfoData, &returnOnAcquire);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_call_function faild");
+ }
+ HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 4");
+ } else {
+ HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ is nullptr ");
+ }
+
+ if (authInfo_ != nullptr) {
+ HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 1");
+ authInfo_->module = module;
+ authInfo_->acquireInfo = acquireInfo;
+ HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 2");
+ if (extraInfo == 0) {
+ authInfo_->extraInfoIsNull = true;
+ } else {
+ authInfo_->extraInfoIsNull = false;
+ }
+ HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 3");
+ AuthBuild authBuild;
+ authBuild.AuthCallBackAcquireInfo(authInfo_->callBackInfo.env, authInfo_);
+ napi_value callbackRef;
+ status = napi_get_reference_value(authInfo_->callBackInfo.env, authInfo_->onAcquireInfoCallBack, &callbackRef);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_reference_value faild %{public}d", status);
+ }
+ napi_value returnOnAcquire = nullptr;
+ status = napi_call_function(authInfo_->callBackInfo.env, authInfo_->jsFunction,
+ callbackRef, ARGS_THREE, authInfo_->onAcquireInfoData, &returnOnAcquire);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_call_function faild");
+ }
+ HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 4");
+ } else {
+ HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ is nullptr ");
+ }
+ HILOG_INFO("AuthApiCallback onAcquireInfo end");
+}
+
+void AuthApiCallback::onResult(const int32_t result, const AuthResult extraInfo)
+{
+ napi_status status;
+ if (userInfo_ != nullptr) {
+ HILOG_INFO("AuthApiCallback onResult userInfo_");
+ userInfo_->result = result;
+ userInfo_->authResult.token_ = extraInfo.token;
+ userInfo_->authResult.remainTimes_ = extraInfo.remainTimes;
+ userInfo_->authResult.freezingTime_ = extraInfo.freezingTime;
+ AuthBuild authBuild;
+ authBuild.AuthUserCallBackResult(userInfo_->callBackInfo.env, userInfo_);
+ napi_value return_val = nullptr;
+ status = napi_call_function(userInfo_->callBackInfo.env, userInfo_->jsFunction,
+ userInfo_->onResultCallBack, ARGS_TWO, userInfo_->onResultData, &return_val);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_call_function faild");
+ }
+ } else {
+ HILOG_INFO("AuthApiCallback onResult userInfo_ is nullptr ");
+ }
+ if (authInfo_ != nullptr) {
+ HILOG_INFO("AuthApiCallback onResult authInfo_");
+ authInfo_->result = result;
+ authInfo_->authResult.token_ = extraInfo.token;
+ authInfo_->authResult.remainTimes_ = extraInfo.remainTimes;
+ authInfo_->authResult.freezingTime_ = extraInfo.freezingTime;
+ AuthBuild authBuild;
+ authBuild.AuthCallBackResult(authInfo_->callBackInfo.env, authInfo_);
+ napi_value return_val = nullptr;
+ napi_value callbackRef;
+ status = napi_get_reference_value(authInfo_->callBackInfo.env, authInfo_->onResultCallBack, &callbackRef);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_reference_value faild %{public}d", status);
+ }
+ status = napi_call_function(authInfo_->callBackInfo.env, authInfo_->jsFunction, callbackRef,
+ ARGS_TWO, authInfo_->onResultData, &return_val);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_call_function faild %{public}d", status);
+ }
+ delete authInfo_;
+ authInfo_ = nullptr;
+ } else {
+ HILOG_INFO("AuthApiCallback onResult authInfo_ is nullptr ");
+ }
+ HILOG_INFO("AuthApiCallback onResult end");
+}
+
+void AuthApiCallback::onSetExecutorProperty(const int32_t result)
+{
+ HILOG_INFO("onSetExecutorProperty 1 = %{public}d", result);
+ napi_status status;
+ if (setPropertyInfo_ != nullptr) {
+ status = napi_create_int32(setPropertyInfo_->callBackInfo.env, result, &setPropertyInfo_->result);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_int32 faild");
+ }
+ if (setPropertyInfo_->callBackInfo.callBack != nullptr) {
+ napi_value global = nullptr;
+ status = napi_get_global(setPropertyInfo_->callBackInfo.env, &global);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_global faild");
+ }
+ napi_value resultData[1];
+ resultData[0] = setPropertyInfo_->result;
+ setPropertyInfo_->result = nullptr;
+ napi_value result = nullptr;
+ napi_value callBack = nullptr;
+ status = napi_get_reference_value(
+ setPropertyInfo_->callBackInfo.env, setPropertyInfo_->callBackInfo.callBack, &callBack);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_reference_value faild");
+ }
+ status = napi_call_function(setPropertyInfo_->callBackInfo.env, global, callBack, 1, resultData, &result);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_call_function faild");
+ }
+ } else {
+ napi_value result = setPropertyInfo_->result;
+ napi_deferred deferred = setPropertyInfo_->callBackInfo.deferred;
+ status = napi_resolve_deferred(setPropertyInfo_->callBackInfo.env, deferred, result);
+ }
+ }
+}
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/src/result_convert.cpp b/interfaces/innerkits/napi/src/result_convert.cpp
new file mode 100644
index 0000000..8f17ff8
--- /dev/null
+++ b/interfaces/innerkits/napi/src/result_convert.cpp
@@ -0,0 +1,361 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "securec.h"
+#include "auth_hilog_wrapper.h"
+#include "result_convert.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+ResultConvert::ResultConvert(void)
+{
+}
+
+ResultConvert::~ResultConvert()
+{
+}
+
+napi_value ResultConvert::BuildArrayExecutorProperty(napi_env env, Napi_ExecutorProperty property)
+{
+ napi_value jsObject = nullptr;
+ napi_create_object(env, &jsObject);
+ SetPropertyInt(env, jsObject, property.result_, "result");
+ SetPropertyInt(env, jsObject, property.authSubType_, "authSubType");
+ SetPropertyUint(env, jsObject, property.remainTimes_, "remainTimes");
+ SetPropertyUint(env, jsObject, property.freezingTime_, "freezingTime");
+ return jsObject;
+}
+
+std::vector ResultConvert::ConvertUint8(uint64_t value)
+{
+ std::string number = std::to_string(value); // trimmed to fit
+ int length = number.length();
+ HILOG_INFO("ResultConvert ConvertUint8 strat result %{public}d", length);
+ std::vector uint8Array;
+ for (int i = 0; i < length; i++) {
+ char charVlaue = number.at(i);
+ uint8_t result = (uint8_t)atoi(&charVlaue);
+ HILOG_INFO("ResultConvert ConvertUint8 strat result %{public}u", result);
+ uint8Array.push_back(result);
+ }
+ return uint8Array;
+}
+
+napi_value ResultConvert::BuildNapiUint8Array(napi_env env, std::vector value)
+{
+ HILOG_INFO("ResultConvert SetPropertyUint8ArrayTest strat ");
+ void *data = nullptr;
+ napi_value buffer = nullptr;
+ NAPI_CALL(env, napi_create_arraybuffer(env, value.size(), &data, &buffer));
+ if (memcpy_s(data, value.size(), value.data(), value.size()) != 0) {
+ HILOG_INFO("ResultConvert SetPropertyUint8ArrayTest error");
+ return nullptr;
+ }
+ napi_value keyValue = nullptr;
+ NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, value.size(), buffer, 0, &keyValue));
+ return keyValue;
+}
+
+void ResultConvert::SetPropertyUint8ArrayTest(
+ napi_env env, napi_value &jsObject, std::vector value, std::string key)
+{
+ napi_status status;
+ napi_value keyValue = BuildNapiUint8Array(env, value);
+ if (keyValue == nullptr) {
+ status = napi_create_int64(env, -1, &keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_int64 faild");
+ }
+ }
+ napi_value resultKey = nullptr;
+ status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_string_utf8 faild");
+ }
+ status = napi_set_property(env, jsObject, resultKey, keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_set_property faild");
+ }
+ HILOG_INFO("ResultConvert SetPropertyUint8ArrayTest end");
+}
+
+void ResultConvert::SetPropertyUint8Array(napi_env env, napi_value &jsObject, uint64_t value, std::string key)
+{
+ HILOG_INFO("BuildArrayExecutorProperty SetPropertyUint8Array strat");
+ napi_status status;
+ napi_value keyValue = GetAuthInfoRet(env, value);
+ napi_value resultKey = nullptr;
+ status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_string_utf8 faild");
+ }
+ status = napi_set_property(env, jsObject, resultKey, keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_set_property faild");
+ }
+ HILOG_INFO("BuildArrayExecutorProperty SetPropertyUint8Array end");
+}
+
+napi_value ResultConvert::GetAuthInfoRet(napi_env env, uint64_t Ret)
+{
+ HILOG_INFO("GetAuthInfoRet strat");
+ std::string RetCode = std::to_string(Ret);
+ size_t bufefersize;
+ void *cdata = nullptr;
+ napi_value arrayBuffer = nullptr;
+ const char *CCrets = RetCode.c_str();
+ bufefersize = RetCode.size();
+ napi_value result = nullptr;
+ NAPI_CALL(env, napi_create_arraybuffer(env, bufefersize, &cdata, &arrayBuffer));
+ if (memcpy_s(cdata, bufefersize, reinterpret_cast(CCrets), bufefersize) != EOK) {
+ HILOG_INFO("memcpy_s failed");
+ }
+ NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, bufefersize, arrayBuffer, 0, &result));
+ HILOG_INFO("GetAuthInfoRet end");
+ return result;
+}
+
+void ResultConvert::SetPropertyInt(napi_env env, napi_value &jsObject, int32_t value, std::string key)
+{
+ napi_status status;
+ napi_value keyValue = 0;
+ status = napi_create_int32(env, value, &keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_int32 faild");
+ }
+ napi_value resultKey = nullptr;
+ status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_string_utf8 faild");
+ }
+ status = napi_set_property(env, jsObject, resultKey, keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_set_property faild");
+ }
+}
+
+void ResultConvert::SetPropertyUint(napi_env env, napi_value &jsObject, uint32_t value, std::string key)
+{
+ napi_status status;
+ napi_value keyValue = 0;
+ status = napi_create_uint32(env, value, &keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_uint32 faild");
+ }
+ napi_value resultKey = nullptr;
+ status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_string_utf8 faild");
+ }
+ status = napi_set_property(env, jsObject, resultKey, keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_set_property faild");
+ }
+}
+
+void ResultConvert::SetPropertyBigint(napi_env env, napi_value &jsObject, uint64_t value, std::string key)
+{
+ napi_status status;
+ napi_value keyValue = 0;
+ status = napi_create_bigint_uint64(env, value, &keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_bigint_uint64 faild");
+ }
+ napi_value resultKey = nullptr;
+ status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_create_string_utf8 faild");
+ }
+ status = napi_set_property(env, jsObject, resultKey, keyValue);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_set_property faild");
+ }
+}
+
+std::vector ResultConvert::NapiGetValueUint8Array(napi_env env, napi_value jsObject, std::string key)
+{
+ napi_value jsValue = GetNapiValue(env, key.c_str(), jsObject);
+ std::vector RetNull;
+ if (jsValue == nullptr) {
+ return RetNull;
+ }
+ napi_typedarray_type arraytype;
+ size_t length = 0;
+ napi_value buffer = nullptr;
+ size_t offset = 0;
+ uint8_t *data = nullptr;
+ bool isTypedArray = false;
+ napi_is_typedarray(env, jsValue, &isTypedArray);
+ if (isTypedArray) {
+ HILOG_INFO("args[PIN_PARAMS_ONE] is a array");
+ } else {
+ HILOG_INFO("args[PIN_PARAMS_ONE] is not a uint8array");
+ }
+ napi_get_typedarray_info(env, jsValue, &arraytype, &length, reinterpret_cast(&data), &buffer, &offset);
+ if (arraytype == napi_uint8_array) {
+ HILOG_INFO("InputerImpl, OnSetData get uint8 array ");
+ } else {
+ HILOG_ERROR("InputerImpl, OnSetData get uint8 array error");
+ return RetNull;
+ }
+ if (offset != 0) {
+ HILOG_INFO(" offset is =============>%{public}d", offset);
+ return RetNull;
+ }
+ std::vector result(data, data+length);
+ return result;
+}
+
+napi_valuetype ResultConvert::GetType(napi_env env, napi_value value)
+{
+ napi_status status;
+ if (value == nullptr) {
+ return napi_null;
+ }
+ napi_valuetype type;
+ status = napi_typeof(env, value, &type);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_typeof faild");
+ }
+ return type;
+}
+
+std::string ResultConvert::GetStringValueByKey(napi_env env, napi_value jsObject, std::string key)
+{
+ napi_value value = GetNapiValue(env, key.c_str(), jsObject);
+ std::string result = NapiGetValueString(env, value);
+ return result;
+}
+
+int32_t ResultConvert::GetInt32ValueByKey(napi_env env, napi_value jsObject, std::string key)
+{
+ napi_value value = GetNapiValue(env, key.c_str(), jsObject);
+ return NapiGetValueInt32(env, value);
+}
+
+std::vector ResultConvert::GetInt32ArrayValueByKey(napi_env env, napi_value jsObject, std::string key)
+{
+ napi_status status;
+ napi_value array = GetNapiValue(env, key.c_str(), jsObject);
+ std::vector values;
+ if (array == nullptr) {
+ return values;
+ }
+ std::vectorRetNull = {0};
+ napi_typedarray_type arraytype;
+ size_t length = 0;
+ napi_value buffer = nullptr;
+ size_t offset = 0;
+ uint8_t *data = nullptr;
+ bool isTypedArray = false;
+ status = napi_is_typedarray(env, array, &isTypedArray);
+ if (status != napi_ok) {
+ HILOG_INFO("napi_is_typedarray is failed");
+ }
+ if (isTypedArray) {
+ HILOG_INFO("args[PIN_PARAMS_ONE] is a array");
+ } else {
+ HILOG_INFO("args[PIN_PARAMS_ONE] is not a uint8array");
+ return RetNull;
+ }
+ status = napi_get_typedarray_info(env, array, &arraytype, &length, reinterpret_cast(&data), &buffer, &offset);
+ if (status != napi_ok) {
+ HILOG_INFO("napi_get_typedarray_info is failed");
+ }
+ if (arraytype == napi_uint32_array) {
+ HILOG_INFO("InputerImpl, OnSetData get uint8 array ");
+ } else {
+ HILOG_ERROR("InputerImpl, OnSetData get uint8 array error");
+ return RetNull;
+ }
+ if (offset != 0) {
+ HILOG_INFO(" offset is =============>%{public}d",offset);
+ return RetNull;
+ }
+ std::vectorresult(data, data + length);
+ return result;
+}
+
+std::string ResultConvert::NapiGetValueString(napi_env env, napi_value value)
+{
+ napi_status status;
+ if (value == nullptr) {
+ HILOG_ERROR("AuthBuild NapiGetValueString value is nullptr");
+ return "";
+ }
+ std::string resultValue = "";
+ char valueString[NAPI_GET_STRING_SIZE];
+ size_t valueSize = NAPI_GET_STRING_SIZE;
+ size_t resultSize = 0;
+ status =napi_get_value_string_utf8(env, value, valueString, valueSize, &resultSize);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_get_value_string_utf8 faild");
+ }
+ resultValue = valueString;
+ if (resultValue == "") {
+ HILOG_ERROR("ContactsBuild NapiGetValueString Data error");
+ return "";
+ }
+ return resultValue;
+}
+
+int32_t ResultConvert::NapiGetValueInt32(napi_env env, napi_value value)
+{
+ if (value == nullptr) {
+ return GET_VALUE_ERROR;
+ }
+ int32_t result;
+ napi_status status = napi_get_value_int32(env, value, &result);
+ if (status != napi_ok) {
+ return GET_VALUE_ERROR;
+ }
+ return result;
+}
+
+int ResultConvert::NapiGetValueInt(napi_env env, napi_value value)
+{
+ if (value == nullptr) {
+ return GET_VALUE_ERROR;
+ }
+ int32_t result;
+ napi_status status = napi_get_value_int32(env, value, &result);
+ if (status != napi_ok) {
+ return GET_VALUE_ERROR;
+ }
+ int ret = result;
+ return ret;
+}
+
+napi_value ResultConvert::GetNapiValue(napi_env env, const std::string keyChar, napi_value object)
+{
+ if (object == nullptr) {
+ HILOG_ERROR("ResultConvert::GetNapiValue object is nullptr");
+ return nullptr;
+ }
+ napi_value key = nullptr;
+ NAPI_CALL(env, napi_create_string_utf8(env, keyChar.c_str(), NAPI_AUTO_LENGTH, &key));
+ bool result = false;
+ NAPI_CALL(env, napi_has_property(env, object, key, &result));
+ if (result) {
+ napi_value value = nullptr;
+ NAPI_CALL(env, napi_get_property(env, object, key, &value));
+ return value;
+ }
+ return nullptr;
+}
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/src/user_auth_helper.cpp b/interfaces/innerkits/napi/src/user_auth_helper.cpp
new file mode 100644
index 0000000..a28ec55
--- /dev/null
+++ b/interfaces/innerkits/napi/src/user_auth_helper.cpp
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "user_auth_helper.h"
+
+#include "auth_hilog_wrapper.h"
+#include "user_auth_impl.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+/**
+ * @brief Instance passed to context
+ *
+ * @param env
+ * @param info
+ * @return napi_value Instance
+ */
+napi_value UserAuthServiceConstructor(napi_env env, napi_callback_info info)
+{
+ std::shared_ptr userAuthImpl;
+ userAuthImpl.reset(new UserAuthImpl());
+ napi_value thisVar = nullptr;
+ size_t argc = 1;
+ napi_value argv[1] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
+ NAPI_CALL(env, napi_wrap(
+ env, thisVar, userAuthImpl.get(),
+ [](napi_env env, void *data, void *hint) {
+ UserAuthImpl *userAuthImpl = static_cast(data);
+ if (userAuthImpl != nullptr) {
+ delete userAuthImpl;
+ }
+ },
+ nullptr, nullptr));
+ // Pull up the face service process
+ return thisVar;
+}
+
+/**
+ * @brief Get the Version object
+ *
+ * @param env
+ * @param info
+ * @return napi_value Specific version number results
+ */
+napi_value GetVersion(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ size_t argcAsync = 0;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
+ UserAuthImpl *userAuthImpl = nullptr;
+ NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
+ HILOG_INFO("UserAuthHelper, GetVersion");
+ return userAuthImpl->GetVersion(env, info);
+}
+
+/**
+ * @brief Get the Availabe Status object
+ *
+ * @param env
+ * @param info
+ * @return napi_value Verify that the certification capability is available
+ */
+napi_value GetAvailabeStatus(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ size_t argcAsync = 0;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
+ UserAuthImpl *userAuthImpl = nullptr;
+ NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
+ HILOG_INFO("UserAuthHelper, getAvailabeStatus");
+ return userAuthImpl->GetAvailabeStatus(env, info);
+}
+
+/**
+ * @brief Get the Property object
+ *
+ * @param env
+ * @param info
+ * @return napi_value It supports querying subclasses / remaining authentication times / freezing time
+ */
+napi_value GetProperty(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ size_t argcAsync = 0;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
+ UserAuthImpl *userAuthImpl = nullptr;
+ NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
+ HILOG_INFO("UserAuthHelper, GetProperty");
+ return userAuthImpl->GetProperty(env, info);
+}
+
+/**
+ * @brief Set the Property object
+ *
+ * @param env
+ * @param info
+ * @return napi_value Set properties: can be used to initialize algorithms
+ */
+napi_value SetProperty(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ size_t argcAsync = 0;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
+ UserAuthImpl *userAuthImpl = nullptr;
+ NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
+ HILOG_INFO("UserAuthHelper, SetProperty");
+ return userAuthImpl->SetProperty(env, info);
+}
+
+/**
+ * @brief user authentication
+ *
+ * @param env
+ * @param info
+ * @return napi_value Enter the challenge value, authentication method, trust level and callback, and return the result
+ * and acquireinfo through the callback
+ */
+napi_value Auth(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ size_t argcAsync = 0;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
+ UserAuthImpl *userAuthImpl = nullptr;
+ NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
+ HILOG_INFO("UserAuthHelper, Auth");
+ return userAuthImpl->Auth(env, info);
+}
+
+/**
+ * @brief user authentication
+ *
+ * @param env
+ * @param info
+ * @return napi_value Pass in the user ID, challenge value, authentication method, trust level and callback, and return
+ * the result acquireinfo through the callback
+ */
+napi_value AuthUser(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ size_t argcAsync = 0;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
+ UserAuthImpl *userAuthImpl = nullptr;
+ NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
+ HILOG_INFO("UserAuthHelper, AuthUser");
+ return userAuthImpl->AuthUser(env, info);
+}
+
+/**
+ * @brief Cancel authentication
+ *
+ * @param env
+ * @param info
+ * @return napi_value success or fail
+ */
+napi_value CancelAuth(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ size_t argcAsync = 0;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
+ UserAuthImpl *userAuthImpl = nullptr;
+ NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
+ HILOG_INFO("UserAuthHelper, CancelAuth");
+ return userAuthImpl->CancelAuth(env, info);
+}
+
+/**
+ * @brief Napi initialization
+ *
+ * @param env
+ * @param exports
+ */
+void Init(napi_env env, napi_value exports)
+{
+ napi_status status;
+ napi_property_descriptor exportFuncs[] = {
+ DECLARE_NAPI_FUNCTION("constructor", UserAuth::Constructor),
+ };
+ status = napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_define_properties faild");
+ }
+}
+
+napi_value Constructor(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ napi_value userAuth = nullptr;
+ NAPI_CALL(env, napi_new_instance(env, GetCtor(env), 0, nullptr, &userAuth));
+ NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
+ return userAuth;
+}
+
+napi_value GetCtor(napi_env env)
+{
+ napi_value cons = nullptr;
+ napi_property_descriptor clzDes[] = {
+ DECLARE_NAPI_FUNCTION("getVersion", UserAuth::GetVersion),
+ DECLARE_NAPI_FUNCTION("getAvailabeStatus", UserAuth::GetAvailabeStatus),
+ DECLARE_NAPI_FUNCTION("getProperty", UserAuth::GetProperty),
+ DECLARE_NAPI_FUNCTION("setProperty", UserAuth::SetProperty),
+ DECLARE_NAPI_FUNCTION("auth", UserAuth::Auth),
+ DECLARE_NAPI_FUNCTION("authUser", UserAuth::AuthUser),
+ DECLARE_NAPI_FUNCTION("cancelAuth", UserAuth::CancelAuth),
+ };
+ NAPI_CALL(env, napi_define_class(env, "UserAuth", NAPI_AUTO_LENGTH, UserAuthServiceConstructor, nullptr,
+ sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
+ return cons;
+}
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/innerkits/napi/src/user_auth_impl.cpp b/interfaces/innerkits/napi/src/user_auth_impl.cpp
new file mode 100644
index 0000000..cc44846
--- /dev/null
+++ b/interfaces/innerkits/napi/src/user_auth_impl.cpp
@@ -0,0 +1,490 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "user_auth_impl.h"
+
+#include "user_auth.h"
+#include "userauth_callback.h"
+#include "userauth_info.h"
+
+#include "auth_build.h"
+#include "auth_hilog_wrapper.h"
+#include "authapi_callback.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+UserAuthImpl::UserAuthImpl()
+{
+}
+
+UserAuthImpl::~UserAuthImpl()
+{
+}
+
+napi_value UserAuthImpl::GetVersion(napi_env env, napi_callback_info info)
+{
+ HILOG_INFO("GetVersion start");
+ int32_t result = UserAuth::GetInstance().GetVersion();
+ HILOG_INFO("GetVersion result = %{public}d ", result);
+ napi_value version = 0;
+ NAPI_CALL(env, napi_create_int32(env, result, &version));
+ return version;
+}
+
+napi_value UserAuthImpl::GetAvailabeStatus(napi_env env, napi_callback_info info)
+{
+ HILOG_INFO("%{public}s, start", __func__);
+ napi_value argv[ARGS_MAX_COUNT] = {nullptr};
+ size_t argc = ARGS_MAX_COUNT;
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+ if (argc != ARGS_TWO) {
+ HILOG_ERROR("%{public}s, parms error.", __func__);
+ return nullptr;
+ }
+ AuthBuild authBuild;
+ AuthType authType = AuthType(authBuild.NapiGetValueInt(env, argv[0]));
+ HILOG_INFO("GetAvailabeStatus authType");
+ AuthTurstLevel authTurstLevel = AuthTurstLevel(authBuild.NapiGetValueInt(env, argv[1]));
+ HILOG_INFO("GetAvailabeStatus authTrustLevel");
+ int32_t result = UserAuth::GetInstance().GetAvailableStatus(authType, authTurstLevel);
+ napi_value ret = 0;
+ NAPI_CALL(env, napi_create_int32(env, result, &ret));
+ return ret;
+}
+
+napi_value UserAuthImpl::GetProperty(napi_env env, napi_callback_info info)
+{
+ GetPropertyInfo *getPropertyInfo = new (std::nothrow) GetPropertyInfo();
+ getPropertyInfo->callBackInfo.env = env;
+ return GetPropertyWrap(env, info, getPropertyInfo);
+}
+
+napi_value UserAuthImpl::GetPropertyWrap(napi_env env, napi_callback_info info, GetPropertyInfo *getPropertyInfo)
+{
+ HILOG_INFO("%{public}s, called", __func__);
+ size_t argcAsync = ARGS_TWO;
+ const size_t argcPromise = ARGS_ONE;
+ const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr));
+ if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) {
+ HILOG_ERROR("%{public}s, Wrong argument count.", __func__);
+ return nullptr;
+ }
+ if (argcAsync > PARAM1) {
+ napi_valuetype valuetype = napi_undefined;
+ napi_typeof(env, args[PARAM1], &valuetype);
+ if (valuetype == napi_function) {
+ NAPI_CALL(env, napi_create_reference(env, args[PARAM1], 1, &(getPropertyInfo->callBackInfo.callBack)));
+ }
+ }
+
+ // C++ need js parms get
+ AuthBuild authBuild;
+ if (authBuild.NapiTypeObject(env, args[0])) {
+ Napi_GetPropertyRequest request = authBuild.GetPropertyRequestBuild(env, args[0]);
+ getPropertyInfo->authType = request.authType_;
+ getPropertyInfo->keys = request.keys_;
+ }
+
+ napi_value ret = 0;
+ if (argcAsync > argcPromise) {
+ ret = GetPropertyAsync(env, getPropertyInfo);
+ } else {
+ ret = GetPropertyPromise(env, getPropertyInfo);
+ }
+ HILOG_INFO("%{public}s,end.", __func__);
+ return ret;
+}
+
+void UserAuthImpl::GetPropertyExecute(napi_env env, void *data)
+{
+ HILOG_INFO("GetPropertyExecute, worker pool thread execute.");
+ GetPropertyInfo *getPropertyInfo = static_cast(data);
+ if (getPropertyInfo != nullptr) {
+ // do something C++
+ AuthBuild authBuild;
+ AuthType authTypeGet = AuthType(getPropertyInfo->authType);
+
+ GetPropertyRequest request;
+ request.authType = authTypeGet;
+ request.keys = getPropertyInfo->keys;
+ HILOG_INFO("GetPropertyExecute start 1");
+ AuthApiCallback *object = new AuthApiCallback();
+ object->getPropertyInfo_ = getPropertyInfo;
+ std::shared_ptr callback;
+ callback.reset(object);
+ UserAuth::GetInstance().GetProperty(request, callback);
+ } else {
+ HILOG_ERROR("GetPropertyExecute, asynccallBackInfo == nullptr");
+ }
+ HILOG_INFO("GetPropertyExecute, worker pool thread execute end.");
+}
+
+void UserAuthImpl::GetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data)
+{
+ HILOG_INFO("GetPropertyPromiseExecuteDone, start");
+ if (status != napi_ok) {
+ HILOG_ERROR("GetPropertyPromiseExecuteDone status is not ok===>");
+ return;
+ }
+ GetPropertyInfo *getPropertyInfo = static_cast(data);
+ napi_delete_async_work(env, getPropertyInfo->asyncWork);
+ HILOG_INFO("GetPropertyPromiseExecuteDone, end");
+}
+
+void UserAuthImpl::GetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data)
+{
+ if (status != napi_ok) {
+ HILOG_ERROR("SetPropertyAsyncExecuteDone status is not ok===>");
+ return;
+ }
+ GetPropertyInfo *getPropertyInfo = static_cast(data);
+ napi_delete_async_work(env, getPropertyInfo->asyncWork);
+ HILOG_INFO("GetPropertyPromiseExecuteDone, end");
+}
+
+napi_value UserAuthImpl::GetPropertyAsync(napi_env env, GetPropertyInfo *getPropertyInfo)
+{
+ HILOG_INFO("%{public}s, asyncCallback.", __func__);
+ if (getPropertyInfo == nullptr) {
+ HILOG_ERROR("%{public}s, param == nullptr.", __func__);
+ return nullptr;
+ }
+ napi_value resourceName = 0;
+ NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, GetPropertyExecute, GetPropertyAsyncExecuteDone,
+ (void *)getPropertyInfo, &getPropertyInfo->asyncWork));
+ NAPI_CALL(env, napi_queue_async_work(env, getPropertyInfo->asyncWork));
+ napi_value result = 0;
+ NAPI_CALL(env, napi_get_null(env, &result));
+ HILOG_INFO("%{public}s, asyncCallback end.", __func__);
+ return result;
+}
+
+napi_value UserAuthImpl::GetPropertyPromise(napi_env env, GetPropertyInfo *getPropertyInfo)
+{
+ HILOG_INFO("%{public}s, promise.", __func__);
+ if (getPropertyInfo == nullptr) {
+ HILOG_ERROR("%{public}s, param == nullptr.", __func__);
+ return nullptr;
+ }
+ napi_value resourceName = 0;
+ NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
+ napi_deferred deferred;
+ napi_value promise = 0;
+ NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
+ getPropertyInfo->callBackInfo.callBack = nullptr;
+ getPropertyInfo->callBackInfo.deferred = deferred;
+
+ NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, GetPropertyExecute, GetPropertyPromiseExecuteDone,
+ (void *)getPropertyInfo, &getPropertyInfo->asyncWork));
+ NAPI_CALL(env, napi_queue_async_work(env, getPropertyInfo->asyncWork));
+ HILOG_INFO("%{public}s, promise end.", __func__);
+ return promise;
+}
+
+napi_value UserAuthImpl::SetProperty(napi_env env, napi_callback_info info)
+{
+ SetPropertyInfo *setPropertyInfo = new (std::nothrow) SetPropertyInfo();
+ setPropertyInfo->callBackInfo.env = env;
+ return SetPropertyWrap(env, info, setPropertyInfo);
+}
+
+napi_value UserAuthImpl::SetPropertyWrap(napi_env env, napi_callback_info info, SetPropertyInfo *setPropertyInfo)
+{
+ HILOG_INFO("%{public}s, called", __func__);
+ size_t argcAsync = ARGS_TWO;
+ const size_t argcPromise = ARGS_ONE;
+ const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT;
+ napi_value args[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr));
+ if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) {
+ HILOG_ERROR("%{public}s, Wrong argument count.", __func__);
+ return nullptr;
+ }
+ if (argcAsync > PARAM1) {
+ napi_valuetype valuetype = napi_undefined;
+ napi_typeof(env, args[PARAM1], &valuetype);
+ if (valuetype == napi_function) {
+ NAPI_CALL(env, napi_create_reference(env, args[PARAM1], 1, &(setPropertyInfo->callBackInfo.callBack)));
+ }
+ }
+
+ // C++ need js parms get
+ AuthBuild authBuild;
+ if (authBuild.NapiTypeObject(env, args[0])) {
+ Napi_SetPropertyRequest request = authBuild.SetPropertyRequestBuild(env, args[0]);
+ setPropertyInfo->authType = request.authType_;
+ setPropertyInfo->key = request.key_;
+ setPropertyInfo->setInfo = request.setInfo_;
+ }
+
+ napi_value ret = 0;
+ if (argcAsync > argcPromise) {
+ ret = SetPropertyAsync(env, setPropertyInfo);
+ } else {
+ ret = SetPropertyPromise(env, setPropertyInfo);
+ }
+ HILOG_INFO("%{public}s,end.", __func__);
+ return ret;
+}
+
+void UserAuthImpl::SetPropertyExecute(napi_env env, void *data)
+{
+ HILOG_INFO("setPropertyExecute, worker pool thread execute.");
+ SetPropertyInfo *setPropertyInfo = static_cast(data);
+ if (setPropertyInfo != nullptr) {
+ // do something C++
+ AuthBuild authBuild;
+ AuthType authTypeGet = AuthType(setPropertyInfo->authType);
+
+ SetPropertyRequest request;
+ request.authType = authTypeGet;
+ request.key = SetPropertyType(setPropertyInfo->key);
+ request.setInfo = setPropertyInfo->setInfo;
+ HILOG_INFO("SetPropertyExecute start 1");
+ AuthApiCallback *object = new AuthApiCallback();
+ object->setPropertyInfo_ = setPropertyInfo;
+ std::shared_ptr callback;
+ callback.reset(object);
+ callback->setPropertyInfo_ = setPropertyInfo;
+ UserAuth::GetInstance().SetProperty(request, callback);
+ } else {
+ HILOG_ERROR("setPropertyExecute, asynccallBackInfo == nullptr");
+ }
+ HILOG_INFO("setPropertyExecute, worker pool thread execute end.");
+}
+
+void UserAuthImpl::SetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data)
+{
+ HILOG_INFO("SetPropertyPromiseExecuteDone, start");
+ if (status != napi_ok) {
+ HILOG_ERROR("SetPropertyPromiseExecuteDone status is not ok===>");
+ return;
+ }
+ SetPropertyInfo *setPropertyInfo = static_cast(data);
+ napi_delete_async_work(env, setPropertyInfo->asyncWork);
+ delete setPropertyInfo;
+ setPropertyInfo = nullptr;
+ HILOG_INFO("SetPropertyPromiseExecuteDone, start");
+}
+
+void UserAuthImpl::SetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data)
+{
+ if (status != napi_ok) {
+ HILOG_ERROR("setPropertyAsyncExecuteDone status is not ok===>");
+ return;
+ }
+ if (data != nullptr) {
+ SetPropertyInfo *setPropertyInfo = static_cast(data);
+ if (setPropertyInfo->asyncWork != nullptr) {
+ napi_delete_async_work(env, setPropertyInfo->asyncWork);
+ }
+ delete setPropertyInfo;
+ }
+}
+
+napi_value UserAuthImpl::SetPropertyAsync(napi_env env, SetPropertyInfo *setPropertyInfo)
+{
+ HILOG_INFO("%{public}s, asyncCallback.", __func__);
+ if (setPropertyInfo == nullptr) {
+ HILOG_ERROR("%{public}s, param == nullptr.", __func__);
+ return nullptr;
+ }
+ napi_value resourceName = 0;
+ NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
+ NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, SetPropertyExecute, SetPropertyAsyncExecuteDone,
+ (void *)setPropertyInfo, &setPropertyInfo->asyncWork));
+ NAPI_CALL(env, napi_queue_async_work(env, setPropertyInfo->asyncWork));
+ napi_value result = 0;
+ NAPI_CALL(env, napi_get_null(env, &result));
+ HILOG_INFO("%{public}s, asyncCallback end.", __func__);
+ return result;
+}
+
+napi_value UserAuthImpl::SetPropertyPromise(napi_env env, SetPropertyInfo *setPropertyInfo)
+{
+ HILOG_INFO("%{public}s, promise.", __func__);
+ if (setPropertyInfo == nullptr) {
+ HILOG_ERROR("%{public}s, param == nullptr.", __func__);
+ return nullptr;
+ }
+ napi_value resourceName = 0;
+ NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
+ napi_deferred deferred;
+ napi_value promise = 0;
+ NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
+ setPropertyInfo->callBackInfo.callBack = nullptr;
+ setPropertyInfo->callBackInfo.deferred = deferred;
+
+ NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, SetPropertyExecute, SetPropertyPromiseExecuteDone,
+ (void *)setPropertyInfo, &setPropertyInfo->asyncWork));
+ NAPI_CALL(env, napi_queue_async_work(env, setPropertyInfo->asyncWork));
+ HILOG_INFO("%{public}s, promise end.", __func__);
+ return promise;
+}
+
+napi_value UserAuthImpl::Auth(napi_env env, napi_callback_info info)
+{
+ HILOG_INFO("%{public}s, start", __func__);
+ AuthInfo *authInfo = new (std::nothrow) AuthInfo();
+ authInfo->info = info;
+ authInfo->callBackInfo.env = env;
+ size_t argc = ARGS_MAX_COUNT;
+ napi_value argv[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, authInfo->info, &argc, argv, nullptr, nullptr));
+ if (argc != ARGS_FOUR) {
+ HILOG_ERROR("%{public}s, parms error.", __func__);
+ return nullptr;
+ }
+ AuthBuild authBuild;
+ authInfo->challenge = authBuild.GetUint8ArrayTo64(env, argv[0]);
+
+ if (authBuild.NapiTypeNumber(env, argv[1])) {
+ int64_t type;
+ NAPI_CALL(env, napi_get_value_int64(env, argv[1], &type));
+ authInfo->authType = type;
+ }
+
+ if (authBuild.NapiTypeNumber(env, argv[ARGS_TWO])) {
+ int64_t level;
+ NAPI_CALL(env, napi_get_value_int64(env, argv[ARGS_TWO], &level));
+ authInfo->authTrustLevel = level;
+ }
+
+ if (authBuild.NapiTypeObject(env, argv[ARGS_THREE])) {
+ HILOG_INFO("%{public}s, get callback function start.", __func__);
+ authInfo->jsFunction = argv[ARGS_THREE];
+ napi_value value;
+ NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_THREE], "onResult", &value));
+ NAPI_CALL(env, napi_create_reference(env, value, 1, &authInfo->onResultCallBack));
+ NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_THREE], "onAcquireInfo", &value));
+ NAPI_CALL(env, napi_create_reference(env, value, 1, &authInfo->onAcquireInfoCallBack));
+ }
+ return AuthWrap(env, authInfo);
+}
+
+napi_value UserAuthImpl::AuthWrap(napi_env env, AuthInfo *authInfo)
+{
+ HILOG_INFO("%{public}s, start.", __func__);
+ if (authInfo == nullptr) {
+ HILOG_ERROR("%{public}s, param == nullptr.", __func__);
+ return nullptr;
+ }
+ AuthBuild authBuild;
+ AuthApiCallback *object = new AuthApiCallback();
+ object->authInfo_ = authInfo;
+ object->userInfo_ = nullptr;
+ std::shared_ptr callback;
+ callback.reset(object);
+ uint64_t result = UserAuth::GetInstance().Auth(
+ authInfo->challenge, AuthType(authInfo->authType), AuthTurstLevel(authInfo->authTrustLevel), callback);
+ HILOG_INFO("UserAuth::GetInstance().Auth.result = %{public}llu", result);
+
+ // auth BigInt
+ napi_value key = authBuild.Uint64ToUint8Array(env, result);
+ HILOG_INFO("%{public}s, end.", __func__);
+// callback->authInfo_ = nullptr;
+// delete authInfo;
+ return key;
+}
+
+napi_value UserAuthImpl::AuthUser(napi_env env, napi_callback_info info)
+{
+ HILOG_INFO("%{public}s, start.", __func__);
+ AuthUserInfo *userInfo = new (std::nothrow) AuthUserInfo();
+ userInfo->callBackInfo.env = env;
+ userInfo->info = info;
+ size_t argc = ARGS_MAX_COUNT;
+ napi_value argv[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, userInfo->info, &argc, argv, nullptr, nullptr));
+ if (argc != ARGS_FIVE) {
+ HILOG_ERROR("%{public}s, parms error.", __func__);
+ return nullptr;
+ }
+ AuthBuild authBuild;
+ if (authBuild.NapiTypeNumber(env, argv[0])) {
+ int32_t id = 0;
+ NAPI_CALL(env, napi_get_value_int32(env, argv[0], &id));
+ userInfo->userId = id;
+ }
+
+ userInfo->challenge = authBuild.GetUint8ArrayTo64(env, argv[1]);
+
+ if (authBuild.NapiTypeNumber(env, argv[ARGS_TWO])) {
+ int32_t type = 0;
+ napi_get_value_int32(env, argv[ARGS_TWO], &type);
+ userInfo->authType = type;
+ }
+
+ if (authBuild.NapiTypeNumber(env, argv[ARGS_THREE])) {
+ int32_t level = 0;
+ NAPI_CALL(env, napi_get_value_int32(env, argv[ARGS_THREE], &level));
+ userInfo->authTrustLevel = level;
+ }
+
+ if (authBuild.NapiTypeObject(env, argv[ARGS_FOUR])) {
+ userInfo->jsFunction = argv[ARGS_FOUR];
+ NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_FOUR], "onResult", &userInfo->onResultCallBack));
+ NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_FOUR], "onAcquireInfo",
+ &userInfo->onAcquireInfoCallBack));
+ }
+ return AuthUserWrap(env, userInfo);
+}
+
+napi_value UserAuthImpl::AuthUserWrap(napi_env env, AuthUserInfo *userInfo)
+{
+ HILOG_INFO("%{public}s, start.", __func__);
+ if (userInfo == nullptr) {
+ HILOG_ERROR("%{public}s, param == nullptr.", __func__);
+ return nullptr;
+ }
+ AuthApiCallback *object = new AuthApiCallback();
+ object->authInfo_ = nullptr;
+ object->userInfo_ = userInfo;
+ std::shared_ptr callback;
+ callback.reset(object);
+ uint64_t result = UserAuth::GetInstance().AuthUser(userInfo->userId, userInfo->challenge,
+ AuthType(userInfo->authType), AuthTurstLevel(userInfo->authTrustLevel), callback);
+ HILOG_INFO("UserAuth::GetInstance().AuthUser. result = %{public}llu", result);
+ AuthBuild authBuild;
+ napi_value key = authBuild.Uint64ToUint8Array(env, result);
+ HILOG_INFO("%{public}s, end.", __func__);
+ callback->userInfo_ = nullptr;
+ delete userInfo;
+ return key;
+}
+
+napi_value UserAuthImpl::CancelAuth(napi_env env, napi_callback_info info)
+{
+ size_t argc = ARGS_MAX_COUNT;
+ napi_value argv[ARGS_MAX_COUNT] = {nullptr};
+ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
+
+ AuthBuild authBuild;
+ uint64_t contextId = authBuild.GetUint8ArrayTo64(env, argv[0]);
+ HILOG_INFO("CancelAuth contextId = %{public}llu", contextId);
+
+ int32_t result = UserAuth::GetInstance().CancelAuth(contextId);
+ HILOG_INFO("CancelAuth result = %{public}d", result);
+ napi_value key = 0;
+ NAPI_CALL(env, napi_create_int32(env, result, &key));
+ return key;
+}
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
diff --git a/interfaces/innerkits/native/BUILD.gn b/interfaces/innerkits/native/BUILD.gn
new file mode 100644
index 0000000..39b9b47
--- /dev/null
+++ b/interfaces/innerkits/native/BUILD.gn
@@ -0,0 +1,55 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//base/useriam/userauth/userauth.gni")
+
+config("userauth_private_config") {
+ include_dirs = [
+ "//utils/system/safwk/napi/include",
+ #"${userauth_frameworks_path}/kitsimpl/include",
+ "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
+ ]
+}
+
+config("userauth_public_config") {
+ include_dirs = [ "include" ]
+}
+
+ohos_shared_library("userauth_framework") {
+ sources = [
+ "../../../frameworks/kitsimpl/src/userauth_proxy.cpp",
+ "../../../frameworks/kitsimpl/src/userauth.cpp",
+ "../../../frameworks/kitsimpl/src/userauth_async_stub.cpp",
+ ]
+
+ configs = [
+ "${userauth_utils_path}:utils_config",
+ ":userauth_private_config"
+ ]
+
+ public_configs = [ ":userauth_public_config" ]
+
+ deps = [
+ "//utils/native/base:utils",
+ "//base/useriam/coauth/interfaces/innerkits:coauth_framework",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ part_name = "${userauth_native_part_name}"
+}
diff --git a/interfaces/innerkits/native/include/iuser_auth.h b/interfaces/innerkits/native/include/iuser_auth.h
new file mode 100644
index 0000000..fcd759a
--- /dev/null
+++ b/interfaces/innerkits/native/include/iuser_auth.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IUSERAUTH_H
+#define IUSERAUTH_H
+
+#include
+
+#include "iuserauth_callback.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class IUserAuth : public IRemoteBroker {
+public:
+ enum {
+ USER_AUTH_GET_AVAILABLE_STATUS = 0,
+ USER_AUTH_GET_PROPERTY,
+ USER_AUTH_SET_PROPERTY,
+ USER_AUTH_AUTH,
+ USER_AUTH_AUTH_USER,
+ USER_AUTH_CANCEL_AUTH,
+ USER_AUTH_GET_VERSION,
+ USER_AUTH_ONRESULT,
+ USER_AUTH_GETEXPORP,
+ USER_AUTH_SETEXPORP,
+ USER_AUTH_ACQUIRENFO
+ };
+
+ virtual int32_t GetAvailableStatus(const AuthType authType, AuthTurstLevel authTurstLevel) = 0;
+ virtual void GetProperty(const GetPropertyRequest request, sptr &callback) = 0;
+ virtual void SetProperty(const SetPropertyRequest request, sptr &callback) = 0;
+ virtual uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
+ sptr &callback) = 0;
+ virtual uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
+ const AuthTurstLevel authTurstLevel, sptr &callback) = 0;
+ virtual int32_t CancelAuth(const uint64_t contextId) = 0;
+ virtual int32_t GetVersion() = 0;
+
+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.UserAuth.IUserAuth");
+};
+} // namespace UserAuth
+} // namespace UserIam
+} // namespace OHOS
+#endif // IUSERAUTH_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/include/iuserauth_callback.h b/interfaces/innerkits/native/include/iuserauth_callback.h
new file mode 100644
index 0000000..c88a288
--- /dev/null
+++ b/interfaces/innerkits/native/include/iuserauth_callback.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IUSERAUTH_CALLBACK_H
+#define IUSERAUTH_CALLBACK_H
+
+#include
+#include
+
+#include "userauth_info.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class IUserAuthCallback : public IRemoteBroker {
+public:
+
+ virtual void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) = 0;
+ virtual void onResult(const int32_t result, const AuthResult extraInfo) = 0;
+ virtual void onExecutorPropertyInfo(const ExecutorProperty result) = 0;
+ virtual void onSetExecutorProperty(const int32_t result) = 0;
+
+ DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.UserAuth.IUserAuthCallback");
+};
+} // namespace UserAuth
+} // namespace UserIam
+} // namespace OHOS
+#endif // IUSERAUTH_CALLBACK_H
diff --git a/interfaces/innerkits/native/include/user_auth.h b/interfaces/innerkits/native/include/user_auth.h
new file mode 100644
index 0000000..be71984
--- /dev/null
+++ b/interfaces/innerkits/native/include/user_auth.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USERAUTH_CLIENT_H
+#define USERAUTH_CLIENT_H
+
+#include
+#include
+#include
+
+#include "iuser_auth.h"
+#include "userauth_async_stub.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class UserAuth : public DelayedRefSingleton {
+ DECLARE_DELAYED_REF_SINGLETON(UserAuth);
+public:
+ DISALLOW_COPY_AND_MOVE(UserAuth);
+
+ int32_t GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel);
+ void GetProperty(const GetPropertyRequest request, std::shared_ptr callback);
+ void SetProperty(const SetPropertyRequest request, std::shared_ptr callback);
+ uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
+ std::shared_ptr callback);
+ uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
+ const AuthTurstLevel authTurstLevel, std::shared_ptr callback);
+ int32_t CancelAuth(const uint64_t contextId);
+ int32_t GetVersion();
+
+private:
+ class UserAuthDeathRecipient : public IRemoteObject::DeathRecipient {
+ public:
+ UserAuthDeathRecipient() = default;
+ ~UserAuthDeathRecipient() = default;
+ void OnRemoteDied(const wptr& remote) override;
+
+ private:
+ DISALLOW_COPY_AND_MOVE(UserAuthDeathRecipient);
+ };
+ void ResetProxy(const wptr& remote);
+ sptr GetProxy();
+
+ std::mutex mutex_;
+ sptr proxy_ {nullptr};
+ sptr deathRecipient_ {nullptr};
+};
+} // namespace UserAuth
+} // namespace UserIam
+} // namespace OHOS
+#endif // USERAUTH_CLIENT_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/include/userauth_async_stub.h b/interfaces/innerkits/native/include/userauth_async_stub.h
new file mode 100644
index 0000000..27ea1b6
--- /dev/null
+++ b/interfaces/innerkits/native/include/userauth_async_stub.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USERAUTH_ASYNC_STUB_H
+#define USERAUTH_ASYNC_STUB_H
+
+#include
+#include "iuserauth_callback.h"
+#include "userauth_callback.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class UserAuthAsyncStub : public IRemoteStub {
+public:
+ explicit UserAuthAsyncStub(std::shared_ptr& impl);
+ ~UserAuthAsyncStub() = default;
+
+ int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
+ void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override;
+ void onResult(const int32_t result, const AuthResult extraInfo) override;
+ void onExecutorPropertyInfo(const ExecutorProperty result) override;
+ void onSetExecutorProperty(const int32_t result) override;
+
+private:
+ int32_t onAcquireInfoStub(MessageParcel& data, MessageParcel& reply);
+ int32_t onResultStub(MessageParcel& data, MessageParcel& reply);
+ int32_t onExecutorPropertyInfoStub(MessageParcel& data, MessageParcel& reply);
+ int32_t onSetExecutorPropertyStub(MessageParcel& data, MessageParcel& reply);
+ std::shared_ptr callback_ {nullptr};
+};
+} // namespace UserAuth
+} // namespace UserIAM
+} // namespace OHOS
+
+#endif // USERAUTH_ASYNC_STUB_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/include/userauth_callback.h b/interfaces/innerkits/native/include/userauth_callback.h
new file mode 100644
index 0000000..9982c24
--- /dev/null
+++ b/interfaces/innerkits/native/include/userauth_callback.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USERAUTH_CALLBACK_H
+#define USERAUTH_CALLBACK_H
+
+#include "userauth_info.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class UserAuthCallback {
+public:
+
+ virtual void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) = 0;
+ virtual void onResult(const int32_t result, const AuthResult extraInfo) = 0;
+ virtual void onExecutorPropertyInfo(const ExecutorProperty result) = 0;
+ virtual void onSetExecutorProperty(const int32_t result) = 0;
+};
+} // namespace UserAuth
+} // namespace UserIam
+} // namespace OHOS
+#endif // IUSERAUTH_CALLBACK_H
\ No newline at end of file
diff --git a/interfaces/innerkits/native/include/userauth_info.h b/interfaces/innerkits/native/include/userauth_info.h
new file mode 100644
index 0000000..c293b8a
--- /dev/null
+++ b/interfaces/innerkits/native/include/userauth_info.h
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USERAUTH_INFO_H
+#define USERAUTH_INFO_H
+
+#include "parcel.h"
+
+#define SIGN_LEN 32
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+// 认证的类型(口令,人脸)
+enum AuthType: uint32_t {
+ PIN = 1,
+ FACE = 2,
+};
+// 认证子类型(2D人脸,3D人脸...)
+enum AuthSubType: uint32_t {
+ /**
+ * Authentication sub type six number pin.
+ */
+ PIN_SIX = 10000,
+ /**
+ * Authentication sub type self defined number pin.
+ */
+ PIN_NUMBER = 10001,
+ /**
+ * Authentication sub type 2D face.
+ */
+ PIN_MIXED = 10002,
+ /**
+ * Authentication sub type 2D face.
+ */
+ FACE_2D = 20000,
+ /**
+ * Authentication sub type 3D face.
+ */
+ FACE_3D = 20001
+};
+// 认证结果可信等级
+enum AuthTurstLevel: uint32_t {
+ // level 1-4
+ ATL1 = 10000,
+ ATL2 = 20000,
+ ATL3 = 30000,
+ ATL4 = 40000
+};
+// 执行器属性列表
+enum GetPropertyType: uint32_t {
+ // 认证子类型(此时认证类型已确认)
+ AUTH_SUB_TYPE = 1,
+ // 剩余认证次数
+ REMAIN_TIMES = 2,
+ // 冻结时间
+ FREEZING_TIME = 3,
+};
+// 获得属性请求
+struct GetPropertyRequest {
+ AuthType authType;
+ // GetPropertyType
+ std::vector keys;
+};
+// 执行器属性
+struct ExecutorProperty {
+ int32_t result;
+ AuthSubType authSubType;
+ uint32_t remainTimes;
+ uint32_t freezingTime;
+};
+// 执行器属性列表
+enum AuthPropertyMode: uint32_t {
+ PROPERMODE_DELETE = 0,
+ PROPERMODE_GET = 1,
+ PROPERMODE_SET = 2,
+ PROPERMODE_FREEZE = 3,
+ PROPERMODE_UNFREEZE = 4,
+};
+// 执行器属性列表
+enum SetPropertyType: uint32_t {
+ INIT_ALGORITHM = 1,
+ FREEZE_TEMPLATE = 2,
+ THAW_TEMPLATE = 3,
+};
+struct SetPropertyRequest {
+ AuthType authType;
+ SetPropertyType key;
+ std::vector setInfo;
+};
+// 认证结果
+struct AuthResult {
+ std::vector token;
+ uint32_t remainTimes;
+ uint32_t freezingTime;
+};
+struct CoAuthInfo {
+ AuthType authType;
+ uint64_t callerID;
+ uint64_t contextID;
+ std::string pkgName;
+ std::vector sessionIds;
+};
+
+struct FreezInfo {
+ uint64_t callerID;
+ std::string pkgName;
+ int32_t resultCode;
+ AuthType authType;
+};
+
+// 结果码
+enum ResultCode: int32_t {
+ /**
+ * Indicates that authentication is success or ability is supported.
+ */
+ SUCCESS = 0,
+ /**
+ * Indicates the authenticator fails to identify user.
+ */
+ FAIL = 1,
+ /**
+ * Indicates other errors.
+ */
+ GENERAL_ERROR = 2,
+ /**
+ * Indicates that authentication has been canceled.
+ */
+ CANCELED = 3,
+ /**
+ * Indicates that authentication has timed out.
+ */
+ TIMEOUT = 4,
+ /**
+ * Indicates that this authentication type is not supported.
+ */
+ TYPE_NOT_SUPPORT = 5,
+ /**
+ * Indicates that the authentication trust level is not supported.
+ */
+ TRUST_LEVEL_NOT_SUPPORT = 6,
+ /**
+ * Indicates that the authentication task is busy. Wait for a few seconds and try again.
+ */
+ BUSY = 7,
+ /**
+ * Indicates incorrect parameters.
+ */
+ INVALID_PARAMETERS = 8,
+ /**
+ * Indicates that the authenticator is locked.
+ */
+ LOCKED = 9,
+ /**
+ * Indicates that the user has not enrolled the authenticator.
+ */
+ NOT_ENROLLED = 10,
+ /**
+ * Indicates that IPC communication error.
+ */
+ IPC_ERROR = 11,
+ /**
+ * Indicates that invalid contextId.
+ */
+ INVALID_CONTEXTID = 12,
+ /**
+ * Indicates that WRITE PARCEL ERROR.
+ */
+ E_WRITE_PARCEL_ERROR = 13,
+ /**
+ * Indicates that READ PARCEL ERROR
+ */
+ E_READ_PARCEL_ERROR = 14,
+ /**
+ * Indicates that POWER SERVICE FAILED
+ */
+ E_GET_POWER_SERVICE_FAILED = 15,
+ /**
+ * Indicates that executor schudle undone
+ */
+ E_RET_UNDONE = 16,
+ /**
+ * Indicates that executor schudle undone
+ */
+ E_RET_NOSERVER = 17,
+ /**
+ * ERRORCODE_MAX.
+ */
+ ERRORCODE_MAX = 18
+};
+} // namespace UserAuth
+} // namespace UserIam
+} // namespace OHOS
+#endif // USERAUTH_INFO_H
diff --git a/interfaces/innerkits/native/include/userauth_proxy.h b/interfaces/innerkits/native/include/userauth_proxy.h
new file mode 100644
index 0000000..d4c1f4d
--- /dev/null
+++ b/interfaces/innerkits/native/include/userauth_proxy.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USERAUTH_PROXY_H
+#define USERAUTH_PROXY_H
+
+#include
+#include "iuser_auth.h"
+
+namespace OHOS {
+namespace UserIAM {
+namespace UserAuth {
+class UserAuthProxy : public IRemoteProxy {
+public:
+ explicit UserAuthProxy(const sptr &impl);
+ ~UserAuthProxy() = default;
+
+ int32_t GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel) override;
+ void GetProperty(const GetPropertyRequest request, sptr& callback) override;
+ void SetProperty(const SetPropertyRequest request, sptr& callback) override;
+ uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
+ sptr& callback) override;
+ uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
+ const AuthTurstLevel authTurstLevel, sptr& callback) override;
+ int32_t CancelAuth(const uint64_t contextId) override;
+ int32_t GetVersion() override;
+
+private:
+ bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption option);
+ static inline BrokerDelegator delegator_;
+};
+} // namespace UserAuth
+} // namespace UserIam
+} // namespace OHOS
+#endif // USERAUTH_PROXY_H
\ No newline at end of file
diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn
new file mode 100644
index 0000000..1c027f2
--- /dev/null
+++ b/interfaces/kits/napi/BUILD.gn
@@ -0,0 +1,59 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//base/useriam/userauth/userauth.gni")
+import("//build/lite/config/component/lite_component.gni")
+
+## Build userauth.so {{{
+config("userauth_public_config") {
+ visibility = [ ":*" ]
+ include_dirs = [
+ "include"
+ ]
+ cflags = [ ]
+}
+
+ohos_shared_library("userauthnorth") {
+ sources = [
+ "src/auth_native_module.cpp",
+ "src/user_auth_helper_north.cpp",
+ ]
+
+ include_dirs=[
+ "third_party/node/src"
+ ]
+
+ deps = [
+ "//foundation/ace/napi:ace_napi",
+ "//base/useriam/userauth/interfaces/innerkits/napi:userauth",
+ "${userauth_innerkits_path}/native:userauth_framework"
+ ]
+
+ public_configs = [ ":userauth_public_config" ]
+
+ external_deps = [
+ "ipc:ipc_core",
+ ]
+ if (is_standard_system) {
+ external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
+ } else {
+ external_deps += [ "hilog:libhilog" ]
+ }
+
+ public_deps = []
+ relative_install_dir = "module"
+ part_name = "userauth"
+ subsystem_name = "userauth"
+}
+## Build userauth.so }}}
diff --git a/interfaces/kits/napi/include/user_auth_helper_north.h b/interfaces/kits/napi/include/user_auth_helper_north.h
new file mode 100644
index 0000000..7fbac52
--- /dev/null
+++ b/interfaces/kits/napi/include/user_auth_helper_north.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef FACERECOGNITION_PIN_AUTH_HELPER_NORTH_H
+#define FACERECOGNITION_PIN_AUTH_HELPER_NORTH_H
+
+#include "napi/native_common.h"
+#include "napi/native_node_api.h"
+
+namespace OHOS {
+namespace UserAuthNorth {
+void Init(napi_env env, napi_value exports);
+napi_value Constructor(napi_env env, napi_callback_info info);
+napi_value GetCtor(napi_env env);
+} // namespace PinAuth
+} // namespace OHOS
+#endif // FACERECOGNITION_PIN_AUTH_HELPER_NORTH_H
diff --git a/interfaces/kits/napi/src/auth_native_module.cpp b/interfaces/kits/napi/src/auth_native_module.cpp
new file mode 100644
index 0000000..b826a2a
--- /dev/null
+++ b/interfaces/kits/napi/src/auth_native_module.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+
+#include "user_auth_helper_north.h"
+
+namespace OHOS {
+namespace UserAuthNorth {
+static napi_value ModuleInit(napi_env env, napi_value exports)
+{
+ OHOS::UserAuthNorth::Init(env, exports);
+ return exports;
+}
+extern "C" __attribute__((constructor)) void RegisterModule(void)
+{
+ napi_module module = {
+ .nm_version = 1, // NAPI v1
+ .nm_flags = 0, // normal
+ .nm_filename = nullptr,
+ .nm_register_func = ModuleInit,
+ .nm_modname = "UserAuthNorth",
+ .nm_priv = nullptr,
+ .reserved = {}
+ };
+ napi_module_register(&module);
+}
+} // namespace UserAuthNorth
+} // namespace OHOS
diff --git a/interfaces/kits/napi/src/user_auth_helper_north.cpp b/interfaces/kits/napi/src/user_auth_helper_north.cpp
new file mode 100644
index 0000000..2b4f842
--- /dev/null
+++ b/interfaces/kits/napi/src/user_auth_helper_north.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "user_auth_helper_north.h"
+
+#include "auth_hilog_wrapper.h"
+#include "user_auth_impl.h"
+#include "user_auth_helper.h"
+
+namespace OHOS {
+namespace UserAuthNorth {
+napi_value Constructor(napi_env env, napi_callback_info info)
+{
+ napi_value thisVar = nullptr;
+ napi_value userAuth = nullptr;
+ NAPI_CALL(env, napi_new_instance(env, GetCtor(env), 0, nullptr, &userAuth));
+ NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
+ HILOG_INFO("UserAuthNorth, Constructor start");
+ return userAuth;
+}
+
+napi_value GetCtor(napi_env env)
+{
+ napi_value cons = nullptr;
+ napi_property_descriptor clzDes[] = {
+ DECLARE_NAPI_FUNCTION("getVersion", UserIAM::UserAuth::GetVersion),
+ DECLARE_NAPI_FUNCTION("getAvailabeStatus", UserIAM::UserAuth::GetAvailabeStatus),
+ DECLARE_NAPI_FUNCTION("auth", UserIAM::UserAuth::Auth),
+ };
+ NAPI_CALL(env, napi_define_class(env, "UserAuthNorth", NAPI_AUTO_LENGTH,
+ UserIAM::UserAuth::UserAuthServiceConstructor, nullptr,
+ sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
+ return cons;
+}
+
+void Init(napi_env env, napi_value exports)
+{
+ napi_status status;
+ napi_property_descriptor exportFuncs[] = {
+ DECLARE_NAPI_FUNCTION("constructor", Constructor),
+ };
+ status = napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
+ if (status != napi_ok) {
+ HILOG_ERROR("napi_define_properties faild");
+ }
+}
+} // namespace UserAuthNorth
+} // namespace OHOS
\ No newline at end of file
diff --git a/ohos.build b/ohos.build
new file mode 100755
index 0000000..85389d3
--- /dev/null
+++ b/ohos.build
@@ -0,0 +1,24 @@
+{
+ "subsystem": "useriam",
+ "parts": {
+ "userauth": {
+ "variants": [
+ "wearable",
+ "phone"
+ ],
+ "module_list": [
+ "//base/useriam/userauth/sa_profile:userauth_sa_profile",
+ "//base/useriam/userauth/services:userauthservice",
+ "//base/useriam/userauth/interfaces/innerkits/native:userauth_framework",
+ "//base/useriam/userauth/interfaces/kits/napi:userauthnorth",
+ "//base/useriam/userauth/interfaces/innerkits/napi:userauth"
+ ],
+ "inner_kits": [
+
+ ],
+ "test_list": [
+ "//base/useriam/userauth/test:userauth_native_test"
+ ]
+ }
+ }
+}
diff --git a/sa_profile/5201.xml b/sa_profile/5201.xml
new file mode 100644
index 0000000..e4c74ff
--- /dev/null
+++ b/sa_profile/5201.xml
@@ -0,0 +1,24 @@
+
+
+
+ useriam
+
+ 5201
+ libuserauthservice.z.so
+ true
+ false
+ 1
+
+
diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn
new file mode 100644
index 0000000..5408fc9
--- /dev/null
+++ b/sa_profile/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//base/useriam/userauth/userauth.gni")
+import("//build/ohos/sa_profile/sa_profile.gni")
+import("//build/ohos.gni")
+
+ohos_sa_profile("userauth_sa_profile") {
+ sources = [ "5201.xml" ]
+ part_name = "${userauth_native_part_name}"
+}
diff --git a/services/BUILD.gn b/services/BUILD.gn
new file mode 100755
index 0000000..af1e0c0
--- /dev/null
+++ b/services/BUILD.gn
@@ -0,0 +1,62 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//base/useriam/userauth/userauth.gni")
+
+config("userauth_private_config") {
+ include_dirs = [
+ "include",
+ "//base/useriam/coauth/common/interface",
+ # "//utils/system/safwk/native/include",
+ # "//third_party/openssl/include/openssl",
+ # "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
+ ]
+}
+
+ohos_shared_library("userauthservice") {
+ sources = [
+ "src/userauth_service.cpp",
+ "src/userauth_adapter.cpp",
+ "src/userauth_controller.cpp",
+ "src/userauth_stub.cpp",
+ "src/userauth_excallback_impl.cpp",
+ "src/userauth_async_proxy.cpp",
+ "src/userauth_datamgr.cpp",
+ "src/context_thread_pool.cpp",
+ ]
+
+ configs = [
+ "${userauth_utils_path}:utils_config",
+ ":userauth_private_config",
+ ]
+
+ deps = [
+ "//base/useriam/coauth/interfaces/innerkits:coauth_framework",
+ "//base/useriam/useridm/interfaces/innerkits:useridm_framework",
+ "//third_party/openssl:libcrypto_static",
+ "${userauth_innerkits_path}/native:userauth_framework",
+ "//drivers/peripheral/display/hal:hdi_display_device",
+ "//utils/native/base:utils",
+ "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
+ "//base/useriam/coauth/common:useriam_common_lib",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ ]
+
+ part_name = "${userauth_native_part_name}"
+}
diff --git a/services/include/context_thread_pool.h b/services/include/context_thread_pool.h
new file mode 100644
index 0000000..6693293
--- /dev/null
+++ b/services/include/context_thread_pool.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USERAUTH_THREADPOOL_H
+#define USERAUTH_THREADPOOL_H
+#include
+#include