@react-native-ohos/react-native-sensitive-info 6.0.1-rc.1 → 6.1.0-rc.1
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/LICENSE +21 -21
- package/README.OpenSource +10 -10
- package/README.md +12 -12
- package/harmony/react_native_sensitive_info/BuildProfile.ets +16 -16
- package/harmony/react_native_sensitive_info/build-profile.json5 +27 -27
- package/harmony/react_native_sensitive_info/hvigorfile.ts +6 -6
- package/harmony/react_native_sensitive_info/index.ets +6 -6
- package/harmony/react_native_sensitive_info/obfuscation-rules.txt +17 -17
- package/harmony/react_native_sensitive_info/oh-package.json5 +13 -13
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/RNOH/generated/BaseReactNativeSensitiveInfoPackage.h +72 -72
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/RNOH/generated/turbo_modules/SensitiveInfoNativeModule.cpp +24 -24
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/RNOH/generated/turbo_modules/SensitiveInfoNativeModule.h +16 -16
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/ComponentDescriptors.h +24 -24
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/EventEmitters.cpp +16 -16
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/EventEmitters.h +17 -17
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/Props.cpp +19 -19
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/Props.h +18 -18
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/ShadowNodes.cpp +17 -17
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/ShadowNodes.h +23 -23
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/States.cpp +16 -16
- package/harmony/react_native_sensitive_info/src/main/cpp/generated/react/renderer/components/react_native_sensitive_info/States.h +18 -18
- package/harmony/react_native_sensitive_info/src/main/ets/Logger.ts +63 -63
- package/harmony/react_native_sensitive_info/src/main/ets/RNSensitiveInfoPackage.ts +45 -45
- package/harmony/react_native_sensitive_info/src/main/ets/RNSensitiveInfoTurboModule.ts +229 -229
- package/harmony/react_native_sensitive_info/src/main/ets/generated/components/ts.ts +5 -5
- package/harmony/react_native_sensitive_info/src/main/ets/generated/index.ets +5 -5
- package/harmony/react_native_sensitive_info/src/main/ets/generated/ts.ts +6 -6
- package/harmony/react_native_sensitive_info/src/main/ets/generated/turboModules/SensitiveInfoNativeModule.ts +34 -34
- package/harmony/react_native_sensitive_info/src/main/ets/generated/turboModules/ts.ts +5 -5
- package/harmony/react_native_sensitive_info/src/main/ets/pages/index.ets +25 -25
- package/harmony/react_native_sensitive_info/src/main/ets/tools.ts +59 -59
- package/harmony/react_native_sensitive_info/src/main/ets/utils/Calc.ets +8 -8
- package/harmony/react_native_sensitive_info/src/main/module.json5 +10 -10
- package/harmony/react_native_sensitive_info/src/main/resources/base/element/color.json +7 -7
- package/harmony/react_native_sensitive_info/src/main/resources/base/element/string.json +15 -15
- package/harmony/react_native_sensitive_info/src/main/resources/base/media/layered_image.json +6 -6
- package/harmony/react_native_sensitive_info/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/react_native_sensitive_info/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/react_native_sensitive_info/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/react_native_sensitive_info/src/mock/mock-config.json5 +1 -1
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/test/Ability.test.ets +40 -40
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/test/List.test.ets +10 -10
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/testability/TestAbility.ets +60 -60
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/testability/pages/Index.ets +22 -22
- package/harmony/react_native_sensitive_info/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets +97 -97
- package/harmony/react_native_sensitive_info/src/ohosTest/module.json5 +28 -28
- package/harmony/react_native_sensitive_info/src/ohosTest/resources/base/element/color.json +7 -7
- package/harmony/react_native_sensitive_info/src/ohosTest/resources/base/element/string.json +15 -15
- package/harmony/react_native_sensitive_info/src/ohosTest/resources/base/profile/test_pages.json +5 -5
- package/harmony/react_native_sensitive_info/src/test/List.test.ets +10 -10
- package/harmony/react_native_sensitive_info/src/test/LocalUnit.test.ets +38 -38
- package/harmony/react_native_sensitive_info/ts.ts +9 -9
- package/harmony/react_native_sensitive_info.har +0 -0
- package/index.d.ts +74 -74
- package/package.json +70 -70
- package/react-native-sensitive-info.podspec +19 -19
|
@@ -1,230 +1,230 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
import userAuth from '@ohos.userIAM.userAuth';
|
|
25
|
-
import dataPreferences from '@ohos.data.preferences';
|
|
26
|
-
import { BusinessError } from '@ohos.base';
|
|
27
|
-
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
|
|
28
|
-
import { TM } from './generated/ts';
|
|
29
|
-
import cryptoFramework from '@ohos.security.cryptoFramework';
|
|
30
|
-
import buffer from '@ohos.buffer';
|
|
31
|
-
|
|
32
|
-
import Logger from './Logger'
|
|
33
|
-
import { util } from '@kit.ArkTS';
|
|
34
|
-
import { tool } from './tools';
|
|
35
|
-
|
|
36
|
-
let preferences: dataPreferences.Preferences | null = null;
|
|
37
|
-
let tools = new tool()
|
|
38
|
-
const DEFAULT = 'default'
|
|
39
|
-
const UTF8 = 'utf-8'
|
|
40
|
-
let invalidateEnrollment = false;
|
|
41
|
-
|
|
42
|
-
const keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159])
|
|
43
|
-
|
|
44
|
-
export class RNSensitiveInfoTurboModule extends TurboModule implements TM.SensitiveInfoNativeModule.Spec {
|
|
45
|
-
constructor(ctx) {
|
|
46
|
-
super(ctx);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
stringToArray(str: string): Uint8Array {
|
|
50
|
-
let textEncoder = new util.TextEncoder();
|
|
51
|
-
return textEncoder.encodeInto(str);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
setItem(key: string, value: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<null> {
|
|
55
|
-
return new Promise(async () => {
|
|
56
|
-
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
57
|
-
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
58
|
-
let symKey = await tools.genSymKeyByData(keyData);
|
|
59
|
-
let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(value, UTF8).buffer) };
|
|
60
|
-
let encryptText = await tools.encryptMessagePromise(symKey, plainText);
|
|
61
|
-
preferences.put(key, encryptText.data, (err: BusinessError) => {
|
|
62
|
-
if (err) {
|
|
63
|
-
Logger.error("Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
Logger.info("Succeeded in putting value of 'startup'.");
|
|
67
|
-
})
|
|
68
|
-
preferences.flush((err: BusinessError) => {
|
|
69
|
-
if (err) {
|
|
70
|
-
Logger.error("Failed to flush. code =" + err.code + ", message =" + err.message);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
Logger.info("Succeeded in flushing.");
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<string> {
|
|
79
|
-
return new Promise((res) => {
|
|
80
|
-
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
81
|
-
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
82
|
-
let decryptResult: string
|
|
83
|
-
preferences.get(key, DEFAULT, async(err: BusinessError, val: Uint8Array) => {
|
|
84
|
-
if (err) {
|
|
85
|
-
Logger.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
let symKey = await tools.genSymKeyByData(keyData);
|
|
89
|
-
let plainText: cryptoFramework.DataBlob = { data: val };
|
|
90
|
-
let decryptText = await tools.decryptMessagePromise(symKey, plainText);
|
|
91
|
-
if (decryptText.data) {
|
|
92
|
-
decryptResult = buffer.from(decryptText.data).toString(UTF8)
|
|
93
|
-
res(decryptResult)
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async decrypt(value: Uint8Array) {
|
|
100
|
-
let symKey = await tools.genSymKeyByData(keyData);
|
|
101
|
-
let decryptResult: string
|
|
102
|
-
let plainText: cryptoFramework.DataBlob = { data: value };
|
|
103
|
-
let decryptText = await tools.decryptMessagePromise(symKey, plainText);
|
|
104
|
-
if (decryptText.data) {
|
|
105
|
-
decryptResult = buffer.from(decryptText.data).toString(UTF8)
|
|
106
|
-
return decryptResult
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
hasItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<boolean> {
|
|
111
|
-
return new Promise(res => {
|
|
112
|
-
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
113
|
-
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
114
|
-
preferences.has(key, (err: BusinessError, val: boolean) => {
|
|
115
|
-
if (err) {
|
|
116
|
-
Logger.error("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (val) { res(true) }
|
|
120
|
-
else { res(false) }
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getObjKeys(obj: Object): string[] {
|
|
126
|
-
let keys = Object.keys(obj);
|
|
127
|
-
return keys;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
getAllItems(options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<any> {
|
|
131
|
-
return new Promise((res) => {
|
|
132
|
-
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
133
|
-
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
134
|
-
preferences.getAll(async (err: BusinessError, value: Object) => {
|
|
135
|
-
if (err) {
|
|
136
|
-
Logger.error("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
let allKeys = this.getObjKeys(value);
|
|
140
|
-
let newValues: Object = Object.create(null);
|
|
141
|
-
for (const item of allKeys) {
|
|
142
|
-
newValues[item] = await this.decrypt(value[item]); // 等待异步方法完成
|
|
143
|
-
}
|
|
144
|
-
console.info('key-values:',JSON.stringify(newValues) )
|
|
145
|
-
res(newValues)
|
|
146
|
-
})
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
deleteItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<void> {
|
|
151
|
-
return new Promise(() => {
|
|
152
|
-
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
153
|
-
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
154
|
-
preferences.delete(key, (err: BusinessError) => {
|
|
155
|
-
if (err) {
|
|
156
|
-
Logger.error("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
isSensorAvailable(): Promise<Object> {
|
|
164
|
-
return new Promise((res) => {
|
|
165
|
-
try {
|
|
166
|
-
if (invalidateEnrollment){
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
let userAuthInstance = userAuth.getUserAuthInstance(tools.authParam, tools.widgetParam);
|
|
170
|
-
Logger.info('get userAuth instance success');
|
|
171
|
-
userAuthInstance.start()
|
|
172
|
-
Logger.info('auth start success');
|
|
173
|
-
userAuthInstance.on('result', {
|
|
174
|
-
onResult(result) {
|
|
175
|
-
Logger.info('userAuthInstance callback result = ' + JSON.stringify(result));
|
|
176
|
-
res(result)
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
} catch (error) {
|
|
180
|
-
res(error)
|
|
181
|
-
Logger.error('auth catch error: ' + JSON.stringify(error));
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
hasEnrolledFingerprints(): Promise<boolean> {
|
|
187
|
-
return new Promise((res) => {
|
|
188
|
-
try {
|
|
189
|
-
userAuth.getAvailableStatus(userAuth.UserAuthType.FINGERPRINT, userAuth.AuthTrustLevel.ATL1);
|
|
190
|
-
Logger.info('current auth trust level is supported');
|
|
191
|
-
res(true)
|
|
192
|
-
} catch (error) {
|
|
193
|
-
const err: BusinessError = error as BusinessError;
|
|
194
|
-
res(false)
|
|
195
|
-
Logger.info(`current auth trust level is not supported. Code is ${err?.code}, message is ${err?.message}`);
|
|
196
|
-
}
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
sharedPreferences(options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): string {
|
|
201
|
-
let obj = Object.keys(options)
|
|
202
|
-
let name: string =
|
|
203
|
-
obj.indexOf("sharedPreferencesName") !== -1 ? options.sharedPreferencesName : "shared_preferences";
|
|
204
|
-
if (name == null) {
|
|
205
|
-
name = "shared_preferences";
|
|
206
|
-
}
|
|
207
|
-
return name;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
cancelFingerprintAuth(): void {
|
|
211
|
-
if (invalidateEnrollment){
|
|
212
|
-
return
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
let userAuthInstance = userAuth.getUserAuthInstance(tools.authParam, tools.widgetParam);
|
|
216
|
-
userAuthInstance.off('result', {
|
|
217
|
-
onResult (result) {
|
|
218
|
-
Logger.info('auth off result: ' + JSON.stringify(result));
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
Logger.info('auth off success');
|
|
222
|
-
} catch (error) {
|
|
223
|
-
Logger.error('auth catch error: ' + JSON.stringify(error));
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
setInvalidatedByBiometricEnrollment(set: boolean): void {
|
|
228
|
-
invalidateEnrollment = set
|
|
229
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
import userAuth from '@ohos.userIAM.userAuth';
|
|
25
|
+
import dataPreferences from '@ohos.data.preferences';
|
|
26
|
+
import { BusinessError } from '@ohos.base';
|
|
27
|
+
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
|
|
28
|
+
import { TM } from './generated/ts';
|
|
29
|
+
import cryptoFramework from '@ohos.security.cryptoFramework';
|
|
30
|
+
import buffer from '@ohos.buffer';
|
|
31
|
+
|
|
32
|
+
import Logger from './Logger'
|
|
33
|
+
import { util } from '@kit.ArkTS';
|
|
34
|
+
import { tool } from './tools';
|
|
35
|
+
|
|
36
|
+
let preferences: dataPreferences.Preferences | null = null;
|
|
37
|
+
let tools = new tool()
|
|
38
|
+
const DEFAULT = 'default'
|
|
39
|
+
const UTF8 = 'utf-8'
|
|
40
|
+
let invalidateEnrollment = false;
|
|
41
|
+
|
|
42
|
+
const keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159])
|
|
43
|
+
|
|
44
|
+
export class RNSensitiveInfoTurboModule extends TurboModule implements TM.SensitiveInfoNativeModule.Spec {
|
|
45
|
+
constructor(ctx) {
|
|
46
|
+
super(ctx);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
stringToArray(str: string): Uint8Array {
|
|
50
|
+
let textEncoder = new util.TextEncoder();
|
|
51
|
+
return textEncoder.encodeInto(str);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setItem(key: string, value: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<null> {
|
|
55
|
+
return new Promise(async () => {
|
|
56
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
57
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
58
|
+
let symKey = await tools.genSymKeyByData(keyData);
|
|
59
|
+
let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(value, UTF8).buffer) };
|
|
60
|
+
let encryptText = await tools.encryptMessagePromise(symKey, plainText);
|
|
61
|
+
preferences.put(key, encryptText.data, (err: BusinessError) => {
|
|
62
|
+
if (err) {
|
|
63
|
+
Logger.error("Failed to put value of 'startup'. code =" + err.code + ", message =" + err.message);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
Logger.info("Succeeded in putting value of 'startup'.");
|
|
67
|
+
})
|
|
68
|
+
preferences.flush((err: BusinessError) => {
|
|
69
|
+
if (err) {
|
|
70
|
+
Logger.error("Failed to flush. code =" + err.code + ", message =" + err.message);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
Logger.info("Succeeded in flushing.");
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<string> {
|
|
79
|
+
return new Promise((res) => {
|
|
80
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
81
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
82
|
+
let decryptResult: string
|
|
83
|
+
preferences.get(key, DEFAULT, async(err: BusinessError, val: Uint8Array) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
Logger.error("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
let symKey = await tools.genSymKeyByData(keyData);
|
|
89
|
+
let plainText: cryptoFramework.DataBlob = { data: val };
|
|
90
|
+
let decryptText = await tools.decryptMessagePromise(symKey, plainText);
|
|
91
|
+
if (decryptText.data) {
|
|
92
|
+
decryptResult = buffer.from(decryptText.data).toString(UTF8)
|
|
93
|
+
res(decryptResult)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async decrypt(value: Uint8Array) {
|
|
100
|
+
let symKey = await tools.genSymKeyByData(keyData);
|
|
101
|
+
let decryptResult: string
|
|
102
|
+
let plainText: cryptoFramework.DataBlob = { data: value };
|
|
103
|
+
let decryptText = await tools.decryptMessagePromise(symKey, plainText);
|
|
104
|
+
if (decryptText.data) {
|
|
105
|
+
decryptResult = buffer.from(decryptText.data).toString(UTF8)
|
|
106
|
+
return decryptResult
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
hasItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<boolean> {
|
|
111
|
+
return new Promise(res => {
|
|
112
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
113
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
114
|
+
preferences.has(key, (err: BusinessError, val: boolean) => {
|
|
115
|
+
if (err) {
|
|
116
|
+
Logger.error("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (val) { res(true) }
|
|
120
|
+
else { res(false) }
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getObjKeys(obj: Object): string[] {
|
|
126
|
+
let keys = Object.keys(obj);
|
|
127
|
+
return keys;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
getAllItems(options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<any> {
|
|
131
|
+
return new Promise((res) => {
|
|
132
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
133
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
134
|
+
preferences.getAll(async (err: BusinessError, value: Object) => {
|
|
135
|
+
if (err) {
|
|
136
|
+
Logger.error("Failed to get all key-values. code =" + err.code + ", message =" + err.message);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
let allKeys = this.getObjKeys(value);
|
|
140
|
+
let newValues: Object = Object.create(null);
|
|
141
|
+
for (const item of allKeys) {
|
|
142
|
+
newValues[item] = await this.decrypt(value[item]); // 等待异步方法完成
|
|
143
|
+
}
|
|
144
|
+
console.info('key-values:',JSON.stringify(newValues) )
|
|
145
|
+
res(newValues)
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
deleteItem(key: string, options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): Promise<void> {
|
|
151
|
+
return new Promise(() => {
|
|
152
|
+
let preferencesName: dataPreferences.Options = { name: this.sharedPreferences(options) };
|
|
153
|
+
preferences = dataPreferences.getPreferencesSync(this.ctx.uiAbilityContext, preferencesName);
|
|
154
|
+
preferences.delete(key, (err: BusinessError) => {
|
|
155
|
+
if (err) {
|
|
156
|
+
Logger.error("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
isSensorAvailable(): Promise<Object> {
|
|
164
|
+
return new Promise((res) => {
|
|
165
|
+
try {
|
|
166
|
+
if (invalidateEnrollment){
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
let userAuthInstance = userAuth.getUserAuthInstance(tools.authParam, tools.widgetParam);
|
|
170
|
+
Logger.info('get userAuth instance success');
|
|
171
|
+
userAuthInstance.start()
|
|
172
|
+
Logger.info('auth start success');
|
|
173
|
+
userAuthInstance.on('result', {
|
|
174
|
+
onResult(result) {
|
|
175
|
+
Logger.info('userAuthInstance callback result = ' + JSON.stringify(result));
|
|
176
|
+
res(result)
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
} catch (error) {
|
|
180
|
+
res(error)
|
|
181
|
+
Logger.error('auth catch error: ' + JSON.stringify(error));
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
hasEnrolledFingerprints(): Promise<boolean> {
|
|
187
|
+
return new Promise((res) => {
|
|
188
|
+
try {
|
|
189
|
+
userAuth.getAvailableStatus(userAuth.UserAuthType.FINGERPRINT, userAuth.AuthTrustLevel.ATL1);
|
|
190
|
+
Logger.info('current auth trust level is supported');
|
|
191
|
+
res(true)
|
|
192
|
+
} catch (error) {
|
|
193
|
+
const err: BusinessError = error as BusinessError;
|
|
194
|
+
res(false)
|
|
195
|
+
Logger.info(`current auth trust level is not supported. Code is ${err?.code}, message is ${err?.message}`);
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
sharedPreferences(options: TM.SensitiveInfoNativeModule.RNSensitiveInfoOptions): string {
|
|
201
|
+
let obj = Object.keys(options)
|
|
202
|
+
let name: string =
|
|
203
|
+
obj.indexOf("sharedPreferencesName") !== -1 ? options.sharedPreferencesName : "shared_preferences";
|
|
204
|
+
if (name == null) {
|
|
205
|
+
name = "shared_preferences";
|
|
206
|
+
}
|
|
207
|
+
return name;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
cancelFingerprintAuth(): void {
|
|
211
|
+
if (invalidateEnrollment){
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
let userAuthInstance = userAuth.getUserAuthInstance(tools.authParam, tools.widgetParam);
|
|
216
|
+
userAuthInstance.off('result', {
|
|
217
|
+
onResult (result) {
|
|
218
|
+
Logger.info('auth off result: ' + JSON.stringify(result));
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
Logger.info('auth off success');
|
|
222
|
+
} catch (error) {
|
|
223
|
+
Logger.error('auth catch error: ' + JSON.stringify(error));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
setInvalidatedByBiometricEnrollment(set: boolean): void {
|
|
228
|
+
invalidateEnrollment = set
|
|
229
|
+
}
|
|
230
230
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from "./ts"
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from "./ts"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * as RNC from "./components/ts"
|
|
6
|
-
export * as TM from "./turboModules/ts"
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * as RNC from "./components/ts"
|
|
6
|
+
export * as TM from "./turboModules/ts"
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Tag } from "@rnoh/react-native-openharmony/ts"
|
|
6
|
-
|
|
7
|
-
export namespace SensitiveInfoNativeModule {
|
|
8
|
-
export const NAME = 'SensitiveInfoNativeModule' as const
|
|
9
|
-
|
|
10
|
-
export type RNSensitiveInfoAndroidDialogStrings = {header?: string, description?: string, hint?: string, success?: string, notRecognized?: string, cancel?: string, cancelled?: string}
|
|
11
|
-
|
|
12
|
-
export type RNSensitiveInfoOptions = {kSecAccessControl?: unknown, kSecAttrAccessible?: unknown, kSecAttrSynchronizable?: boolean, keychainService?: string, sharedPreferencesName?: string, touchID?: boolean, showModal?: boolean, kSecUseOperationPrompt?: string, kLocalizedFallbackTitle?: string, strings?: RNSensitiveInfoAndroidDialogStrings}
|
|
13
|
-
|
|
14
|
-
export interface Spec {
|
|
15
|
-
setItem(key: string, value: string, options: RNSensitiveInfoOptions): Promise<void>;
|
|
16
|
-
|
|
17
|
-
getItem(key: string, options: RNSensitiveInfoOptions): Promise<string>;
|
|
18
|
-
|
|
19
|
-
hasItem(key: string, options: RNSensitiveInfoOptions): Promise<boolean>;
|
|
20
|
-
|
|
21
|
-
getAllItems(options: RNSensitiveInfoOptions): Promise<void>;
|
|
22
|
-
|
|
23
|
-
deleteItem(key: string, options: RNSensitiveInfoOptions): Promise<void>;
|
|
24
|
-
|
|
25
|
-
isSensorAvailable(): Promise<Object>;
|
|
26
|
-
|
|
27
|
-
hasEnrolledFingerprints(): Promise<boolean>;
|
|
28
|
-
|
|
29
|
-
cancelFingerprintAuth(): void;
|
|
30
|
-
|
|
31
|
-
setInvalidatedByBiometricEnrollment(set: boolean): void;
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Tag } from "@rnoh/react-native-openharmony/ts"
|
|
6
|
+
|
|
7
|
+
export namespace SensitiveInfoNativeModule {
|
|
8
|
+
export const NAME = 'SensitiveInfoNativeModule' as const
|
|
9
|
+
|
|
10
|
+
export type RNSensitiveInfoAndroidDialogStrings = {header?: string, description?: string, hint?: string, success?: string, notRecognized?: string, cancel?: string, cancelled?: string}
|
|
11
|
+
|
|
12
|
+
export type RNSensitiveInfoOptions = {kSecAccessControl?: unknown, kSecAttrAccessible?: unknown, kSecAttrSynchronizable?: boolean, keychainService?: string, sharedPreferencesName?: string, touchID?: boolean, showModal?: boolean, kSecUseOperationPrompt?: string, kLocalizedFallbackTitle?: string, strings?: RNSensitiveInfoAndroidDialogStrings}
|
|
13
|
+
|
|
14
|
+
export interface Spec {
|
|
15
|
+
setItem(key: string, value: string, options: RNSensitiveInfoOptions): Promise<void>;
|
|
16
|
+
|
|
17
|
+
getItem(key: string, options: RNSensitiveInfoOptions): Promise<string>;
|
|
18
|
+
|
|
19
|
+
hasItem(key: string, options: RNSensitiveInfoOptions): Promise<boolean>;
|
|
20
|
+
|
|
21
|
+
getAllItems(options: RNSensitiveInfoOptions): Promise<void>;
|
|
22
|
+
|
|
23
|
+
deleteItem(key: string, options: RNSensitiveInfoOptions): Promise<void>;
|
|
24
|
+
|
|
25
|
+
isSensorAvailable(): Promise<Object>;
|
|
26
|
+
|
|
27
|
+
hasEnrolledFingerprints(): Promise<boolean>;
|
|
28
|
+
|
|
29
|
+
cancelFingerprintAuth(): void;
|
|
30
|
+
|
|
31
|
+
setInvalidatedByBiometricEnrollment(set: boolean): void;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from "./SensitiveInfoNativeModule"
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from "./SensitiveInfoNativeModule"
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
@Entry
|
|
8
|
-
@Component
|
|
9
|
-
struct Index {
|
|
10
|
-
@State message: string = 'Hello World';
|
|
11
|
-
|
|
12
|
-
build() {
|
|
13
|
-
RelativeContainer() {
|
|
14
|
-
Text(this.message)
|
|
15
|
-
.id('HelloWorld')
|
|
16
|
-
.fontSize(50)
|
|
17
|
-
.fontWeight(FontWeight.Bold)
|
|
18
|
-
.alignRules({
|
|
19
|
-
center: { anchor: '__container__', align: VerticalAlign.Center },
|
|
20
|
-
middle: { anchor: '__container__', align: HorizontalAlign.Center }
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
.height('100%')
|
|
24
|
-
.width('100%')
|
|
25
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
@Entry
|
|
8
|
+
@Component
|
|
9
|
+
struct Index {
|
|
10
|
+
@State message: string = 'Hello World';
|
|
11
|
+
|
|
12
|
+
build() {
|
|
13
|
+
RelativeContainer() {
|
|
14
|
+
Text(this.message)
|
|
15
|
+
.id('HelloWorld')
|
|
16
|
+
.fontSize(50)
|
|
17
|
+
.fontWeight(FontWeight.Bold)
|
|
18
|
+
.alignRules({
|
|
19
|
+
center: { anchor: '__container__', align: VerticalAlign.Center },
|
|
20
|
+
middle: { anchor: '__container__', align: HorizontalAlign.Center }
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
.height('100%')
|
|
24
|
+
.width('100%')
|
|
25
|
+
}
|
|
26
26
|
}
|