react-native-trustdevice 1.1.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +35 -0
- package/README.md +94 -3
- package/android/build.gradle +0 -1
- package/android/src/main/java/com/trustdevice/TrustdeviceModule.java +110 -2
- package/android/src/main/java/com/trustdevice/TrustdeviceSeModule.java +32 -9
- package/android/src/main/java/com/trustdevice/TrustdeviceUiBridge.java +125 -0
- package/index.d.ts +65 -2
- package/index.js +11 -4
- package/ios/TrustDevice.h +2 -2
- package/ios/TrustDevice.m +186 -27
- package/ios/TrustDeviceSe.h +2 -2
- package/ios/TrustDeviceSe.m +111 -62
- package/package.json +9 -3
- package/react-native-trustdevice.podspec +0 -2
- package/react-native.config.js +10 -0
- package/src/TrustDevice.android.js +2 -1
- package/src/TrustDevice.ios.js +3 -4
- package/android/build/.transforms/34a3c3baa7ee620e604d2c62960577c0/results.bin +0 -1
- package/android/build/.transforms/34a3c3baa7ee620e604d2c62960577c0/transformed/classes/classes.dex +0 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +0 -7
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +0 -18
- package/android/build/intermediates/aar_metadata/debug/aar-metadata.properties +0 -5
- package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +0 -1
- package/android/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
- package/android/build/intermediates/compile_symbol_list/debug/R.txt +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +0 -1
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +0 -2
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
- package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
- package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
- package/android/build/intermediates/javac/debug/classes/com/trustdevice/TrustdeviceModule$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/trustdevice/TrustdeviceModule.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/trustdevice/TrustdevicePackage.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/trustdevice/TrustdeviceSeModule$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/trustdevice/TrustdeviceSeModule$2.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/trustdevice/TrustdeviceSeModule.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/trustdevice/utils/TDUniRiskUtils.class +0 -0
- package/android/build/intermediates/local_only_symbol_list/debug/R-def.txt +0 -2
- package/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +0 -7
- package/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml +0 -7
- package/android/build/intermediates/navigation_json/debug/navigation.json +0 -1
- package/android/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +0 -1
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +0 -16
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
package/Package.swift
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// swift-tools-version: 6.0
|
|
2
|
+
|
|
3
|
+
import PackageDescription
|
|
4
|
+
|
|
5
|
+
// React Native 0.88 links this package from
|
|
6
|
+
// ios/build/generated/autolinking/libs/ReactNativeTrustDevice. These relative
|
|
7
|
+
// paths point to the React Native packages generated by `react-native spm`.
|
|
8
|
+
let package = Package(
|
|
9
|
+
name: "ReactNativeTrustDevice",
|
|
10
|
+
platforms: [.iOS("15.1")],
|
|
11
|
+
products: [
|
|
12
|
+
.library(name: "ReactNativeTrustDevice", targets: ["ReactNativeTrustDevice"]),
|
|
13
|
+
],
|
|
14
|
+
dependencies: [
|
|
15
|
+
.package(name: "ReactNative", path: "../../../../xcframeworks"),
|
|
16
|
+
.package(name: "React-GeneratedCode", path: "../../../ios"),
|
|
17
|
+
.package(url: "https://github.com/trustdecision/trustdevice-pro-ios.git", from: "5.3.3"),
|
|
18
|
+
],
|
|
19
|
+
targets: [
|
|
20
|
+
.target(
|
|
21
|
+
name: "ReactNativeTrustDevice",
|
|
22
|
+
dependencies: [
|
|
23
|
+
.product(name: "ReactHeaders", package: "ReactNative"),
|
|
24
|
+
.product(name: "ReactNativeHeaders", package: "ReactNative"),
|
|
25
|
+
.product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
|
|
26
|
+
.product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
|
|
27
|
+
.product(name: "TrustDecisionPro", package: "trustdevice-pro-ios"),
|
|
28
|
+
],
|
|
29
|
+
path: "ios",
|
|
30
|
+
sources: ["TrustDevice.m", "TrustDeviceSe.m"],
|
|
31
|
+
publicHeadersPath: ".",
|
|
32
|
+
linkerSettings: [.unsafeFlags(["-Xlinker", "-ObjC"]) ]
|
|
33
|
+
),
|
|
34
|
+
]
|
|
35
|
+
)
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Please note that when integrating SDK products provided by the TrustDecision in
|
|
|
20
20
|
|
|
21
21
|
| | Android | iOS |
|
|
22
22
|
| ------------------------- | ------------------------------------ | :----------------- |
|
|
23
|
-
| Supported System Versions | Android 5.0 and above | iOS
|
|
23
|
+
| Supported System Versions | Android 5.0 and above | iOS 17.6 and above with the RN 0.88 SPM example (check the native SDK minimum for your own app) |
|
|
24
24
|
| Supported Architectures | armeabi-v7a, arm64-v8a, x86 | armv7,arm64,x86_64 |
|
|
25
25
|
|
|
26
26
|
# Integrate
|
|
@@ -32,7 +32,80 @@ Please note that when integrating SDK products provided by the TrustDecision in
|
|
|
32
32
|
Please execute in your react native project root directory
|
|
33
33
|
|
|
34
34
|
```shell
|
|
35
|
-
npm install --save
|
|
35
|
+
npm install --save react-native-trustdevice
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### iOS (React Native 0.88.1, Swift Package Manager)
|
|
39
|
+
|
|
40
|
+
The plugin contains a `Package.swift` that links the React Native bridge to
|
|
41
|
+
`TrustDecisionPro` (5.3.3 or later). `TDBehavior` is not included by default.
|
|
42
|
+
In an RN 0.88.1
|
|
43
|
+
SPM app, install the npm package, then run the RN SPM migration in the host app:
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
npx react-native spm add --deintegrate
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Open the generated Xcode project and build the app. The RN SPM autolinker
|
|
50
|
+
discovers this plugin's `Package.swift`; customers do not need to add a second
|
|
51
|
+
Swift package for the bridge manually. The fingerprint SDK is declared
|
|
52
|
+
in the bridge manifest. Run `npx react-native spm update` after changing native
|
|
53
|
+
dependencies. RN 0.88's SPM integration is experimental; use Xcode and Node
|
|
54
|
+
versions supported by RN 0.88.1 (Node 22.13+).
|
|
55
|
+
|
|
56
|
+
The example app keeps a comment-only `ios/Podfile` solely because CLI 20.2
|
|
57
|
+
uses that filename to detect an iOS project. It is not a CocoaPods integration.
|
|
58
|
+
|
|
59
|
+
The legacy `react-native-trustdevice.podspec` remains for existing CocoaPods
|
|
60
|
+
hosts. Do not link the SDK through both CocoaPods and SPM in the same target.
|
|
61
|
+
The native CocoaPods distribution is no longer maintained, so new iOS projects
|
|
62
|
+
should use the SPM path above.
|
|
63
|
+
|
|
64
|
+
### iOS behavior collection (optional)
|
|
65
|
+
|
|
66
|
+
Only if your app calls `start`, `stop`, or `collect`, add
|
|
67
|
+
`https://github.com/trustdecision/TDBehavior_spm` in Xcode via **File > Add
|
|
68
|
+
Package Dependencies...**. Select **Exact Version** `1.5.2` and add the
|
|
69
|
+
`TDBehavior` product to the host App target. Do not add it to the plugin's
|
|
70
|
+
`Package.swift` or link it a second time through CocoaPods. Fingerprint APIs
|
|
71
|
+
such as `getBlackBoxAsync` and `getDeviceInfoAsync` do not require this package.
|
|
72
|
+
|
|
73
|
+
### Android behavior collection dependency
|
|
74
|
+
|
|
75
|
+
The plugin does not bundle the Android behavior collection SDK. If behavior
|
|
76
|
+
collection is required, add the following dependency to the host application's
|
|
77
|
+
`android/app/build.gradle`:
|
|
78
|
+
|
|
79
|
+
```gradle
|
|
80
|
+
dependencies {
|
|
81
|
+
implementation 'com.trustdecision.android:behavior:1.5.1'
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Then rebuild the native application. Adding or removing this dependency cannot
|
|
86
|
+
be applied through Metro hot reload.
|
|
87
|
+
|
|
88
|
+
### Device information and verification UI
|
|
89
|
+
|
|
90
|
+
`TrustDevice` is the enterprise module (the package's default export), and
|
|
91
|
+
`TrustDeviceSe` is the standard module (named export). Both expose
|
|
92
|
+
`getDeviceInfo()` and `getDeviceInfoAsync()` as Promise methods returning
|
|
93
|
+
`blackBox`, `fpVersion`, `anonymousId`, `deviceRiskScore`, `sealedResult`, and
|
|
94
|
+
`apiStatus: {code, message}`. The standard iOS SDK has only a callback API, so
|
|
95
|
+
both methods use that asynchronous native call. Call them after initialization.
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
import TrustDevice, {TrustDeviceSe} from 'react-native-trustdevice';
|
|
99
|
+
|
|
100
|
+
const info = await TrustDevice.getDeviceInfoAsync();
|
|
101
|
+
// For a standard-edition integration:
|
|
102
|
+
// const info = await TrustDeviceSe.getDeviceInfoAsync();
|
|
103
|
+
|
|
104
|
+
const captcha = await TrustDevice.showCaptcha();
|
|
105
|
+
// captcha.function is onSuccess or onFailed; onReady is emitted as
|
|
106
|
+
// a TrustDeviceCaptcha event (TrustDeviceSeCaptcha for the standard module).
|
|
107
|
+
const liveness = await TrustDevice.showLiveness({license: 'YOUR_LICENSE'});
|
|
108
|
+
// liveness.function is onSuccess or onFailed.
|
|
36
109
|
```
|
|
37
110
|
|
|
38
111
|
### AndroidManifest.xml
|
|
@@ -99,6 +172,24 @@ Declare the following permissions in the AndroidManifest.xml file under the appl
|
|
|
99
172
|
async function getBlackBoxAsync();
|
|
100
173
|
```
|
|
101
174
|
|
|
175
|
+
## Behavior collection
|
|
176
|
+
|
|
177
|
+
Initialize the SDK before starting collection. There must be a real user
|
|
178
|
+
interaction such as typing, tapping, or scrolling between `start` and
|
|
179
|
+
`collect`; otherwise `collect` may return code `104`.
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
await TrustDevice.start();
|
|
183
|
+
|
|
184
|
+
const result = await TrustDevice.collect();
|
|
185
|
+
// result: {code: number, payload: string, msg: string}
|
|
186
|
+
|
|
187
|
+
await TrustDevice.stop();
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`collect` returns and clears the currently buffered behavior data. `stop`
|
|
191
|
+
stops collection and clears any uncollected data.
|
|
192
|
+
|
|
102
193
|
## Best Practices
|
|
103
194
|
|
|
104
195
|
1. Get TrustDevice Module
|
|
@@ -176,4 +267,4 @@ Declare the following permissions in the AndroidManifest.xml file under the appl
|
|
|
176
267
|
| runningTasks | Whether collecting running tasks, default allowed | Android | options["runningTasks"] = true |
|
|
177
268
|
| sensor | Whether collecting sensor information, default allowed | Android | options["sensor"] = true |
|
|
178
269
|
| readPhone | Whether collecting READ _PHONE_ STATE permission-related information, default allowed | Android | options["readPhone"] = true |
|
|
179
|
-
| installPackageList | Whether collecting application list information, default allowed | Android | options["installPackageList"] = true |
|
|
270
|
+
| installPackageList | Whether collecting application list information, default allowed | Android | options["installPackageList"] = true |
|
package/android/build.gradle
CHANGED
|
@@ -17,6 +17,10 @@ import java.util.HashMap;
|
|
|
17
17
|
import com.trustdecision.mobrisk.TDRisk;
|
|
18
18
|
import com.trustdecision.mobrisk.TDRiskCallback;
|
|
19
19
|
import com.trustdecision.mobrisk.TDAPISignResult;
|
|
20
|
+
import com.trustdecision.mobrisk.TDBehaviorResult;
|
|
21
|
+
import com.trustdecision.mobrisk.TDDeviceInfo;
|
|
22
|
+
import com.trustdecision.mobrisk.TDDeviceInfoCallbackAdapter;
|
|
23
|
+
import com.trustdecision.mobrisk.TDDeviceAPIStatus;
|
|
20
24
|
|
|
21
25
|
public class TrustdeviceModule extends ReactContextBaseJavaModule {
|
|
22
26
|
private final ReactApplicationContext reactContext;
|
|
@@ -34,11 +38,18 @@ public class TrustdeviceModule extends ReactContextBaseJavaModule {
|
|
|
34
38
|
|
|
35
39
|
@ReactMethod
|
|
36
40
|
public void initWithOptions(ReadableMap readableMap, Promise promise) {
|
|
37
|
-
if (readableMap
|
|
41
|
+
if (readableMap == null) {
|
|
42
|
+
promise.reject("initWithOptions Error", "options must not be null");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
38
47
|
HashMap<String, Object> options = readableMap.toHashMap();
|
|
39
48
|
TDRisk.Builder builder = TDUniRiskUtils.mapToBuilder(options);
|
|
40
49
|
TDRisk.initWithOptions(this.reactContext.getApplicationContext(), builder);
|
|
41
50
|
promise.resolve(null);
|
|
51
|
+
} catch (Exception e) {
|
|
52
|
+
promise.reject("initWithOptions Error", e);
|
|
42
53
|
}
|
|
43
54
|
}
|
|
44
55
|
|
|
@@ -66,6 +77,69 @@ public class TrustdeviceModule extends ReactContextBaseJavaModule {
|
|
|
66
77
|
}
|
|
67
78
|
}
|
|
68
79
|
|
|
80
|
+
private WritableMap deviceInfoResult(TDDeviceInfo info) {
|
|
81
|
+
WritableMap result = Arguments.createMap();
|
|
82
|
+
TDDeviceAPIStatus status = info.getApiStatus();
|
|
83
|
+
int code = status == null ? -1 : status.getCode();
|
|
84
|
+
String message = status == null ? "SDK returned no API status" : status.getMessage();
|
|
85
|
+
WritableMap apiStatus = Arguments.createMap();
|
|
86
|
+
apiStatus.putInt("code", code);
|
|
87
|
+
apiStatus.putString("message", message);
|
|
88
|
+
result.putString("blackBox", info.getBlackBox());
|
|
89
|
+
result.putString("fpVersion", info.getFpVersion());
|
|
90
|
+
result.putString("anonymousId", info.getAnonymousId());
|
|
91
|
+
result.putInt("deviceRiskScore", info.getDeviceRiskScore());
|
|
92
|
+
result.putString("sealedResult", info.getSealedResult());
|
|
93
|
+
result.putMap("apiStatus", apiStatus);
|
|
94
|
+
result.putInt("code", code);
|
|
95
|
+
result.putString("msg", message);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@ReactMethod
|
|
100
|
+
public void getDeviceInfo(Promise promise) {
|
|
101
|
+
new Thread(() -> {
|
|
102
|
+
try {
|
|
103
|
+
TDDeviceInfo info = TDRisk.getDeviceInfo();
|
|
104
|
+
if (info == null) {
|
|
105
|
+
promise.reject("device_info_unavailable", "SDK returned null device info");
|
|
106
|
+
} else {
|
|
107
|
+
promise.resolve(deviceInfoResult(info));
|
|
108
|
+
}
|
|
109
|
+
} catch (Exception e) {
|
|
110
|
+
promise.reject("getDeviceInfo Error", e);
|
|
111
|
+
}
|
|
112
|
+
}, "TrustDevice-getDeviceInfo").start();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@ReactMethod
|
|
116
|
+
public void getDeviceInfoAsync(Promise promise) {
|
|
117
|
+
try {
|
|
118
|
+
TDRisk.getDeviceInfo(new TDDeviceInfoCallbackAdapter() {
|
|
119
|
+
@Override
|
|
120
|
+
public void onResult(TDDeviceInfo info) {
|
|
121
|
+
if (info == null) {
|
|
122
|
+
promise.reject("device_info_unavailable", "SDK returned null device info");
|
|
123
|
+
} else {
|
|
124
|
+
promise.resolve(deviceInfoResult(info));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} catch (Exception e) {
|
|
129
|
+
promise.reject("getDeviceInfoAsync Error", e);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@ReactMethod
|
|
134
|
+
public void showCaptcha(Promise promise) {
|
|
135
|
+
TrustdeviceUiBridge.showCaptcha(reactContext, "TrustDeviceCaptcha", promise);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@ReactMethod
|
|
139
|
+
public void showLiveness(ReadableMap options, Promise promise) {
|
|
140
|
+
TrustdeviceUiBridge.showLiveness(reactContext, options, promise);
|
|
141
|
+
}
|
|
142
|
+
|
|
69
143
|
@ReactMethod
|
|
70
144
|
public void sign(String path, Promise promise) {
|
|
71
145
|
try {
|
|
@@ -83,9 +157,43 @@ public class TrustdeviceModule extends ReactContextBaseJavaModule {
|
|
|
83
157
|
}
|
|
84
158
|
}
|
|
85
159
|
|
|
160
|
+
@ReactMethod
|
|
161
|
+
public void start(Promise promise) {
|
|
162
|
+
try {
|
|
163
|
+
TDRisk.start();
|
|
164
|
+
promise.resolve(null);
|
|
165
|
+
} catch (Exception e) {
|
|
166
|
+
promise.reject("behaviorStart Error", e);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@ReactMethod
|
|
171
|
+
public void stop(Promise promise) {
|
|
172
|
+
try {
|
|
173
|
+
TDRisk.stop();
|
|
174
|
+
promise.resolve(null);
|
|
175
|
+
} catch (Exception e) {
|
|
176
|
+
promise.reject("behaviorStop Error", e);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@ReactMethod
|
|
181
|
+
public void collect(Promise promise) {
|
|
182
|
+
try {
|
|
183
|
+
TDBehaviorResult behaviorResult = TDRisk.collect();
|
|
184
|
+
WritableMap resultMap = Arguments.createMap();
|
|
185
|
+
resultMap.putInt("code", behaviorResult.code());
|
|
186
|
+
resultMap.putString("payload", behaviorResult.payload());
|
|
187
|
+
resultMap.putString("msg", behaviorResult.msg());
|
|
188
|
+
promise.resolve(resultMap);
|
|
189
|
+
} catch (Exception e) {
|
|
190
|
+
promise.reject("behaviorCollect Error", e);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
86
194
|
@ReactMethod
|
|
87
195
|
public void getSDKVersion(Promise promise) {
|
|
88
196
|
String sdkVersion = TDRisk.getSDKVersion();
|
|
89
197
|
promise.resolve(sdkVersion);
|
|
90
198
|
}
|
|
91
|
-
}
|
|
199
|
+
}
|
|
@@ -38,11 +38,17 @@ public class TrustdeviceSeModule extends ReactContextBaseJavaModule {
|
|
|
38
38
|
|
|
39
39
|
@ReactMethod
|
|
40
40
|
public void initWithOptions(ReadableMap readableMap, Promise promise) {
|
|
41
|
-
if (readableMap
|
|
41
|
+
if (readableMap == null) {
|
|
42
|
+
promise.reject("initWithOptions Error", "options must not be null");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
42
46
|
HashMap<String, Object> options = readableMap.toHashMap();
|
|
43
47
|
TDDeviceManager.Builder builder = TDUniRiskUtils.mapToBuilderSe(options);
|
|
44
48
|
TDDeviceManager.initWithOptions(this.reactContext.getApplicationContext(), builder);
|
|
45
49
|
promise.resolve(null);
|
|
50
|
+
} catch (Exception e) {
|
|
51
|
+
promise.reject("initWithOptions Error", e);
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
|
|
@@ -79,18 +85,20 @@ public class TrustdeviceSeModule extends ReactContextBaseJavaModule {
|
|
|
79
85
|
// deviceRiskScore: 设备风险分数
|
|
80
86
|
// apiStatus: API状态信息
|
|
81
87
|
// sealedResult: 密封结果
|
|
82
|
-
int code = apiStatus.getCode();
|
|
83
|
-
|
|
84
|
-
// 创建 WritableMap 来返回结构化数据
|
|
85
88
|
WritableMap resultMap = Arguments.createMap();
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
int code = apiStatus == null ? -1 : apiStatus.getCode();
|
|
90
|
+
String message = apiStatus == null ? "SDK returned no API status" : apiStatus.getMessage();
|
|
91
|
+
WritableMap statusMap = Arguments.createMap();
|
|
92
|
+
statusMap.putInt("code", code);
|
|
93
|
+
statusMap.putString("message", message);
|
|
94
|
+
resultMap.putInt("code", code);
|
|
88
95
|
resultMap.putString("fpVersion", fpVersion);
|
|
89
96
|
resultMap.putString("blackBox", blackBox);
|
|
90
97
|
resultMap.putString("anonymousId", anonymousId);
|
|
91
98
|
resultMap.putInt("deviceRiskScore", deviceRiskScore);
|
|
92
99
|
resultMap.putString("sealedResult", sealedResult);
|
|
93
|
-
resultMap.
|
|
100
|
+
resultMap.putMap("apiStatus", statusMap);
|
|
101
|
+
resultMap.putString("msg", message);
|
|
94
102
|
|
|
95
103
|
promise.resolve(resultMap);
|
|
96
104
|
}
|
|
@@ -101,6 +109,21 @@ public class TrustdeviceSeModule extends ReactContextBaseJavaModule {
|
|
|
101
109
|
}
|
|
102
110
|
}
|
|
103
111
|
|
|
112
|
+
@ReactMethod
|
|
113
|
+
public void getDeviceInfoAsync(Promise promise) {
|
|
114
|
+
getDeviceInfo(promise);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@ReactMethod
|
|
118
|
+
public void showCaptcha(Promise promise) {
|
|
119
|
+
TrustdeviceUiBridge.showCaptcha(reactContext, "TrustDeviceSeCaptcha", promise);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@ReactMethod
|
|
123
|
+
public void showLiveness(ReadableMap options, Promise promise) {
|
|
124
|
+
TrustdeviceUiBridge.showLiveness(reactContext, options, promise);
|
|
125
|
+
}
|
|
126
|
+
|
|
104
127
|
@ReactMethod
|
|
105
128
|
public void sign(String path, Promise promise) {
|
|
106
129
|
try {
|
|
@@ -120,7 +143,7 @@ public class TrustdeviceSeModule extends ReactContextBaseJavaModule {
|
|
|
120
143
|
|
|
121
144
|
@ReactMethod
|
|
122
145
|
public void getSDKVersion(Promise promise) {
|
|
123
|
-
String sdkVersion =
|
|
146
|
+
String sdkVersion = TDDeviceManager.getSDKVersion();
|
|
124
147
|
promise.resolve(sdkVersion);
|
|
125
148
|
}
|
|
126
|
-
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
package com.trustdevice;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Arguments;
|
|
6
|
+
import com.facebook.react.bridge.Promise;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
9
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
10
|
+
import com.facebook.react.bridge.WritableMap;
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
12
|
+
import com.trustdecision.mobrisk.TDRisk;
|
|
13
|
+
import com.trustdecision.mobrisk.TDRiskCaptchaCallback;
|
|
14
|
+
import com.trustdecision.mobrisk.TDRiskLivenessCallback;
|
|
15
|
+
|
|
16
|
+
import org.json.JSONObject;
|
|
17
|
+
|
|
18
|
+
import java.util.Iterator;
|
|
19
|
+
|
|
20
|
+
final class TrustdeviceUiBridge {
|
|
21
|
+
private TrustdeviceUiBridge() {}
|
|
22
|
+
|
|
23
|
+
static void showCaptcha(ReactApplicationContext context, String eventName, Promise promise) {
|
|
24
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
25
|
+
Activity activity = context.getCurrentActivity();
|
|
26
|
+
if (activity == null) {
|
|
27
|
+
promise.reject("captcha_no_activity", "No active Activity");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
TDRisk.showCaptcha(activity, new TDRiskCaptchaCallback() {
|
|
32
|
+
@Override
|
|
33
|
+
public void onReady() {
|
|
34
|
+
WritableMap ready = Arguments.createMap();
|
|
35
|
+
ready.putString("function", "onReady");
|
|
36
|
+
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
37
|
+
.emit(eventName, ready);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Override
|
|
41
|
+
public void onSuccess(String token) {
|
|
42
|
+
WritableMap result = Arguments.createMap();
|
|
43
|
+
result.putString("function", "onSuccess");
|
|
44
|
+
result.putString("token", token);
|
|
45
|
+
promise.resolve(result);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Override
|
|
49
|
+
public void onFailed(int code, String message) {
|
|
50
|
+
WritableMap result = Arguments.createMap();
|
|
51
|
+
result.putString("function", "onFailed");
|
|
52
|
+
result.putInt("errorCode", code);
|
|
53
|
+
result.putString("errorMsg", message);
|
|
54
|
+
promise.resolve(result);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
} catch (Exception e) {
|
|
58
|
+
promise.reject("showCaptcha Error", e);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static void showLiveness(ReactApplicationContext context, ReadableMap options, Promise promise) {
|
|
64
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
65
|
+
Activity activity = context.getCurrentActivity();
|
|
66
|
+
if (activity == null) {
|
|
67
|
+
promise.reject("liveness_no_activity", "No active Activity");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
String license = options != null && options.hasKey("license") && !options.isNull("license")
|
|
71
|
+
? options.getString("license") : null;
|
|
72
|
+
try {
|
|
73
|
+
TDRisk.showLiveness(activity, license, new TDRiskLivenessCallback() {
|
|
74
|
+
@Override
|
|
75
|
+
public void onSuccess(String json) {
|
|
76
|
+
WritableMap result = jsonResult(json);
|
|
77
|
+
result.putString("function", "onSuccess");
|
|
78
|
+
promise.resolve(result);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Override
|
|
82
|
+
public void onError(String errorCode, String errorMsg, String sequenceId) {
|
|
83
|
+
WritableMap result = Arguments.createMap();
|
|
84
|
+
result.putString("function", "onFailed");
|
|
85
|
+
try {
|
|
86
|
+
result.putInt("code", Integer.parseInt(errorCode));
|
|
87
|
+
} catch (NumberFormatException ignored) {
|
|
88
|
+
result.putString("code", errorCode);
|
|
89
|
+
}
|
|
90
|
+
result.putString("message", errorMsg);
|
|
91
|
+
result.putString("sequence_id", sequenceId);
|
|
92
|
+
result.putString("liveness_id", "");
|
|
93
|
+
promise.resolve(result);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
} catch (Exception e) {
|
|
97
|
+
promise.reject("showLiveness Error", e);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private static WritableMap jsonResult(String json) {
|
|
103
|
+
WritableMap result = Arguments.createMap();
|
|
104
|
+
try {
|
|
105
|
+
JSONObject object = new JSONObject(json);
|
|
106
|
+
Iterator<String> keys = object.keys();
|
|
107
|
+
while (keys.hasNext()) {
|
|
108
|
+
String key = keys.next();
|
|
109
|
+
Object value = object.opt(key);
|
|
110
|
+
if (value instanceof Boolean) {
|
|
111
|
+
result.putBoolean(key, (Boolean) value);
|
|
112
|
+
} else if (value instanceof Number) {
|
|
113
|
+
result.putDouble(key, ((Number) value).doubleValue());
|
|
114
|
+
} else if (value == JSONObject.NULL) {
|
|
115
|
+
result.putNull(key);
|
|
116
|
+
} else if (value != null) {
|
|
117
|
+
result.putString(key, String.valueOf(value));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch (Exception ignored) {
|
|
121
|
+
result.putString("raw", json);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,67 @@
|
|
|
1
|
+
export interface TDSignResult {
|
|
2
|
+
code: number;
|
|
3
|
+
sign: string;
|
|
4
|
+
msg: string;
|
|
5
|
+
}
|
|
1
6
|
|
|
2
|
-
|
|
7
|
+
export interface TDBehaviorResult {
|
|
8
|
+
code: number;
|
|
9
|
+
payload: string;
|
|
10
|
+
msg: string;
|
|
11
|
+
}
|
|
3
12
|
|
|
4
|
-
|
|
13
|
+
export interface TDDeviceInfoResult {
|
|
14
|
+
blackBox: string;
|
|
15
|
+
fpVersion: string;
|
|
16
|
+
anonymousId: string;
|
|
17
|
+
deviceRiskScore: number;
|
|
18
|
+
sealedResult: string;
|
|
19
|
+
apiStatus: {code: number; message: string};
|
|
20
|
+
code: number;
|
|
21
|
+
msg: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type TDCaptchaResult =
|
|
25
|
+
| {function: 'onSuccess'; token: string}
|
|
26
|
+
| {function: 'onFailed'; errorCode: number; errorMsg: string};
|
|
27
|
+
|
|
28
|
+
export interface TDLivenessResult {
|
|
29
|
+
function: 'onSuccess' | 'onFailed';
|
|
30
|
+
code?: number | string;
|
|
31
|
+
message?: string;
|
|
32
|
+
sequence_id?: string;
|
|
33
|
+
liveness_id?: string;
|
|
34
|
+
image?: string;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface TrustDeviceModule {
|
|
39
|
+
initWithOptions(options: Record<string, unknown>): Promise<void> | void;
|
|
40
|
+
getSDKVersion(): Promise<string>;
|
|
41
|
+
getBlackBox(): Promise<string>;
|
|
42
|
+
getBlackBoxAsync(): Promise<string>;
|
|
43
|
+
getDeviceInfo(): Promise<TDDeviceInfoResult>;
|
|
44
|
+
getDeviceInfoAsync(): Promise<TDDeviceInfoResult>;
|
|
45
|
+
sign(path: string): Promise<TDSignResult>;
|
|
46
|
+
showCaptcha(): Promise<TDCaptchaResult>;
|
|
47
|
+
showLiveness(options: {license?: string; showStyle?: 'present' | 'push'}): Promise<TDLivenessResult>;
|
|
48
|
+
start(): Promise<void>;
|
|
49
|
+
stop(): Promise<void>;
|
|
50
|
+
collect(): Promise<TDBehaviorResult>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface TrustDeviceSeModule {
|
|
54
|
+
initWithOptions(options: Record<string, unknown>): Promise<void> | void;
|
|
55
|
+
getSDKVersion(): Promise<string>;
|
|
56
|
+
getDeviceInfo(): Promise<TDDeviceInfoResult>;
|
|
57
|
+
getDeviceInfoAsync(): Promise<TDDeviceInfoResult>;
|
|
58
|
+
sign(path: string): Promise<TDSignResult>;
|
|
59
|
+
showCaptcha(): Promise<TDCaptchaResult>;
|
|
60
|
+
showLiveness(options: {license?: string; showStyle?: 'present' | 'push'}): Promise<TDLivenessResult>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare const TrustDevice: TrustDeviceModule;
|
|
64
|
+
|
|
65
|
+
export {TrustDevice};
|
|
66
|
+
export const TrustDeviceSe: TrustDeviceSeModule;
|
|
67
|
+
export default TrustDevice;
|
package/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
// Platform files are transpiled as ES modules by Metro, while older published
|
|
2
|
+
// versions of this package were consumed as CommonJS. Normalize the platform
|
|
3
|
+
// export once and preserve all existing public import styles.
|
|
4
|
+
const platformModule = require('./src/TrustDevice');
|
|
5
|
+
const TrustDevice = platformModule.default || platformModule;
|
|
6
|
+
const TrustDeviceSe = platformModule.TrustDeviceSe;
|
|
7
|
+
|
|
8
|
+
module.exports = TrustDevice;
|
|
9
|
+
module.exports.default = TrustDevice;
|
|
10
|
+
module.exports.TrustDevice = TrustDevice;
|
|
11
|
+
module.exports.TrustDeviceSe = TrustDeviceSe;
|
package/ios/TrustDevice.h
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
#import <Foundation/Foundation.h>
|
|
9
|
-
#import <React/
|
|
9
|
+
#import <React/RCTEventEmitter.h>
|
|
10
10
|
|
|
11
11
|
NS_ASSUME_NONNULL_BEGIN
|
|
12
12
|
|
|
13
|
-
@interface TrustDevice :
|
|
13
|
+
@interface TrustDevice : RCTEventEmitter <RCTBridgeModule>
|
|
14
14
|
|
|
15
15
|
@end
|
|
16
16
|
|