This module provides capabilities to identify fraud risks on the current device and detect cheating behaviors such as automated clicks and device farming.
Since: 5.0.0(12)
Fraud detection request parameters.
System capability: SystemCapability.Security.BusinessRiskIntelligentDetection
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| nonce | Uint8Array | No | No | A randomly generated nonce value passed by your app, which is used to prevent replay attacks. The detection result contains this value. A nonce value must contain 24 to 80 bytes. |
| algorithm | SigningAlgorithm | No | No | Digital signature algorithm. |
| version | number | No | Yes | Version number of a detection result message format. The default value is 1. Currently, the value can only be 1, 2, and 3. If the value is 1, the tag in the detection result does not include the timestamp attribute or risk level. If the value is 2, the tag in the detection result includes the timestamp attribute and risk level. For each tag, the timestamp attribute indicates the last occurrence time of its associated clue, and the risk level indicates its risk severity. Since 26.0.0, the value 3 is added. If the value is 3, the tag in the detection result includes the timestamp attribute, risk level, and risk control factor. For each tag, the timestamp attribute indicates the last occurrence time of its associated clue, the risk level indicates its risk severity, and the risk control factor indicates its risk factor. Since: 5.1.0(18) |
Request parameters for simulated click detection.
System capability: SystemCapability.Security.BusinessRiskIntelligentDetection
Model restriction: This API can be used only in the stage model.
Since: 6.0.0(20)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| version | number | No | Yes | Version number of a detection result message format. The default value is 1. Currently, the value can only be 1. |
Request parameters for enhanced simulated click detection.
System capability: SystemCapability.Security.BusinessRiskIntelligentDetection
Model restriction: This API can be used only in the stage model.
Since: 6.0.2(22)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| nonce | Uint8Array | No | No | A randomly generated nonce value passed by your app, which is used to prevent replay attacks. The detection result contains this value. A nonce value must contain 24 to 80 bytes. |
| algorithm | SigningAlgorithm | No | No | Digital signature algorithm. |
| version | number | No | Yes | Version number of a detection result message format. The default value is 1. Currently, the value can only be 1. |
Digital signature algorithm.
System capability: SystemCapability.Security.BusinessRiskIntelligentDetection
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| ES256 | 0 | SHA256withECDSA algorithm. |
detectFraudRisk(params: FraudDetectionRequest): Promise<string>
Obtains the fraud risks of a device. This API uses a promise to return the result.
System capability: SystemCapability.Security.BusinessRiskIntelligentDetection
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| params | FraudDetectionRequest | Yes | Request parameter. |
Returns:
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the fraud detection result, which is a JWS string encoded using Base64URL. If an exception or error occurs, an error code will be returned. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 401 | Invalid parameters. |
| 1012500001 | Internal error. API call limit exceeded. Internal error. Internal interface invocation exception. |
| 1012500002 | The network is unreachable. |
| 1012500003 | Access cloud server fail. |
| 1012500004 | Verify capability fail. |
Example:
import { businessRiskIntelligentDetection } from '@kit.DeviceSecurityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
const TAG = '[BusinessRiskIntelligentDetectionModel]';
let rand = cryptoFramework.createRandom();
let len = 48;
let randData = rand.generateRandomSync(len);
let params = {
nonce: randData.data,
algorithm: businessRiskIntelligentDetection.SigningAlgorithm.ES256
} as businessRiskIntelligentDetection.FraudDetectionRequest;
try {
hilog.info(0x0000, TAG, 'Detect fraud risk begin.');
businessRiskIntelligentDetection.detectFraudRisk(params).then((result: string) => {
hilog.info(0x0000, TAG, 'Detect fraud risk success: %{public}s', result);
}).catch((error: Error) => {
let e: BusinessError = error as BusinessError;
hilog.error(0x0000, TAG, 'Detect fraud risk failed: %{public}d %{public}s', e.code, e.message);
});
} catch (error) {
let e: BusinessError = error as BusinessError;
hilog.error(0x0000, TAG, 'Detect fraud risk failed: %{public}d %{public}s', e.code, e.message);
} detectSimulatedClickRisk(params: SimulatedClickDetectionRequest): Promise<string>
Obtains the detection result for cheating behaviors such as automated clicks and device farming. This API uses a promise to return the result.
System capability: SystemCapability.Security.BusinessRiskIntelligentDetection
Model restriction: This API can be used only in the stage model.
Since: 6.0.0(20)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| params | SimulatedClickDetectionRequest | Yes | Request parameter. |
Returns:
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the simulated click detection result. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 1012500001 | Internal error. |
| 1012500002 | The network is unreachable. |
| 1012500003 | Access cloud server fail. |
| 1012500004 | Verify capability fail. |
| 1012500005 | The interface access frequency exceeds the limit. |
| 1012500006 | Internal timeout. |
| 1012500007 | Invalid parameters. |
Example:
import { businessRiskIntelligentDetection } from '@kit.DeviceSecurityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = 'BusinessRiskIntelligentDetectionJsTest';
let params = {
version: 1
} as businessRiskIntelligentDetection.SimulatedClickDetectionRequest;
try {
hilog.info(0x0000, TAG, 'Detect simulated click risk begin.');
businessRiskIntelligentDetection.detectSimulatedClickRisk(params).then((result: string) => {
hilog.info(0x0000, TAG, 'Detect simulated click risk success: %{public}s', result);
}).catch((error: Error) => {
let e: BusinessError = error as BusinessError;
hilog.error(0x0000, TAG, 'Detect simulated click risk failed: %{public}d %{public}s', e.code, e.message);
});
} catch (error) {
let e: BusinessError = error as BusinessError;
hilog.error(0x0000, TAG, 'Detect simulated click risk failed: %{public}d %{public}s', e.code, e.message);
} detectSimulatedClickRiskEnhanced(params: SimulatedClickDetectionEnhancedRequest): Promise<string>
Obtains the enhanced detection result for cheating behaviors such as automated clicks and device farming. This API uses a promise to return the result.
System capability: SystemCapability.Security.BusinessRiskIntelligentDetection
Model restriction: This API can be used only in the stage model.
Since: 6.0.2(22)
Parameters:
| Name | Type | Mandatory | Description |
|---|---|---|---|
| params | SimulatedClickDetectionEnhancedRequest | Yes | Request parameter. |
Returns:
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the enhanced simulated click detection result, which is a JWS string encoded using Base64URL. If an exception or error occurs, an error code will be returned. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| ID | Error Message |
|---|---|
| 1012500001 | Internal error. |
| 1012500002 | The network is unreachable. |
| 1012500003 | Access cloud server fail. |
| 1012500005 | The interface access frequency exceeds the limit. |
| 1012500006 | Internal timeout. |
| 1012500007 | Invalid parameters. |
Example:
import { businessRiskIntelligentDetection } from '@kit.DeviceSecurityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
const TAG = 'BusinessRiskIntelligentDetectionJsTest';
let nonceLength = 48;
let nonceBlob = cryptoFramework.createRandom().generateRandomSync(nonceLength);
let params = {
version: 1,
nonce: nonceBlob.data,
algorithm: businessRiskIntelligentDetection.SigningAlgorithm.ES256
} as businessRiskIntelligentDetection.SimulatedClickDetectionEnhancedRequest;
try {
hilog.info(0x0000, TAG, 'Detect simulated click risk enhanced begin.');
businessRiskIntelligentDetection.detectSimulatedClickRiskEnhanced(params).then((result: string) => {
hilog.info(0x0000, TAG, 'Detect simulated click risk enhanced success: %{public}s', result);
}).catch((error: Error) => {
let e: BusinessError = error as BusinessError;
hilog.error(0x0000, TAG, 'Detect simulated click risk enhanced failed: %{public}d %{public}s', e.code, e.message);
});
} catch (error) {
let e: BusinessError = error as BusinessError;
hilog.error(0x0000, TAG, 'Detect simulated click risk enhanced failed: %{public}d %{public}s', e.code, e.message);
}