@aparajita/capacitor-biometric-auth 7.0.2 → 7.1.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/README.md CHANGED
@@ -252,8 +252,10 @@ Register a function that will be called when the app resumes. The function will
252
252
  | biometryType | <a href="#biometrytype">BiometryType</a> | The primary (most secure) type of biometry supported by the device. Note that _supported_ is not the same as _available_, which requires the biometry to be enrolled. |
253
253
  | biometryTypes | BiometryType[] | All of the biometry types supported by the hardware on the device (currently only Android devices support multiple biometry types). If no biometry is supported, i.e. `biometryType === <a href="#biometrytype">BiometryType.none`</a>, this will be an empty array.<br><br>Note that _supported_ is not the same as _available_, which requires the biometry to be enrolled. |
254
254
  | deviceIsSecure | boolean | Returns true if the device is secure. On iOS, this means that the device has a passcode set. On Android, this means that the device has a PIN, pattern, or password set. |
255
- | reason | string | If biometry is not available and the system gives a reason why, it will be returned here. Otherwise it's an empty string. |
256
- | code | <a href="#biometryerrortype">BiometryErrorType</a> | If biometry is not available, the error code will be returned here. Otherwise it's an empty string. The error code will be one of the <a href="#biometryerrortype">`BiometryErrorType`</a> enum values, and is consistent across platforms. |
255
+ | reason | string | If weak or better biometry is not available and the system gives a reason why, it will be returned here. Otherwise it's an empty string. |
256
+ | code | <a href="#biometryerrortype">BiometryErrorType</a> | If weak or better biometry is not available, the error code will be returned here. Otherwise it's an empty string. The error code will be one of the <a href="#biometryerrortype">`BiometryErrorType`</a> enum values, and is consistent across platforms. |
257
+ | strongReason | string | If strong biometry is not available and the system gives a reason why, it will be returned here. Otherwise it's an empty string.<br><br>On iOS, this will always be the same as `reason`, since all biometry on iOS is strong. |
258
+ | strongCode | <a href="#biometryerrortype">BiometryErrorType</a> | If strong biometry is not available, the error code will be returned here. Otherwise it's an empty string. The error code will be one of the <a href="#biometryerrortype">`BiometryErrorType`</a> enum values, and is consistent across platforms.<br><br>On iOS, this will always be the same as `code`, since all biometry on iOS is strong. |
257
259
 
258
260
  #### Array
259
261
 
@@ -112,25 +112,31 @@ public class BiometricAuthNative extends Plugin {
112
112
  */
113
113
  @PluginMethod
114
114
  public void checkBiometry(PluginCall call) {
115
+ JSObject result = new JSObject();
115
116
  BiometricManager manager = BiometricManager.from(getContext());
116
117
 
117
118
  // First check for weak biometry or better.
118
- int biometryResult = manager.canAuthenticate(
119
+ int weakBiometryResult = manager.canAuthenticate(
119
120
  BiometricManager.Authenticators.BIOMETRIC_WEAK
120
121
  );
121
122
 
122
- JSObject result = new JSObject();
123
+ setReasonAndCode(weakBiometryResult, false, result);
124
+
123
125
  result.put(
124
126
  "isAvailable",
125
- biometryResult == BiometricManager.BIOMETRIC_SUCCESS
127
+ weakBiometryResult == BiometricManager.BIOMETRIC_SUCCESS
126
128
  );
127
129
 
128
130
  // Now check for strong biometry.
129
- biometryResult =
130
- manager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG);
131
+ int strongBiometryResult = manager.canAuthenticate(
132
+ BiometricManager.Authenticators.BIOMETRIC_STRONG
133
+ );
134
+
135
+ setReasonAndCode(strongBiometryResult, true, result);
136
+
131
137
  result.put(
132
138
  "strongBiometryIsAvailable",
133
- biometryResult == BiometricManager.BIOMETRIC_SUCCESS
139
+ strongBiometryResult == BiometricManager.BIOMETRIC_SUCCESS
134
140
  );
135
141
 
136
142
  biometryTypes = getDeviceBiometryTypes();
@@ -155,9 +161,17 @@ public class BiometricAuthNative extends Plugin {
155
161
  result.put("deviceIsSecure", false);
156
162
  }
157
163
 
164
+ call.resolve(result);
165
+ }
166
+
167
+ private static void setReasonAndCode(
168
+ int canAuthenticateResult,
169
+ boolean strong,
170
+ JSObject result
171
+ ) {
158
172
  String reason = "";
159
173
 
160
- switch (biometryResult) {
174
+ switch (canAuthenticateResult) {
161
175
  case BiometricManager.BIOMETRIC_SUCCESS:
162
176
  break;
163
177
  case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
@@ -182,15 +196,14 @@ public class BiometricAuthNative extends Plugin {
182
196
  break;
183
197
  }
184
198
 
185
- String errorCode = biometryErrorCodeMap.get(biometryResult);
199
+ String errorCode = biometryErrorCodeMap.get(canAuthenticateResult);
186
200
 
187
201
  if (errorCode == null) {
188
202
  errorCode = "biometryNotAvailable";
189
203
  }
190
204
 
191
- result.put("reason", reason);
192
- result.put("code", errorCode);
193
- call.resolve(result);
205
+ result.put(strong ? "strongReason" : "reason", reason);
206
+ result.put(strong ? "strongCode" : "code", errorCode);
194
207
  }
195
208
 
196
209
  private ArrayList<BiometryType> getDeviceBiometryTypes() {
@@ -210,17 +210,35 @@ export interface CheckBiometryResult {
210
210
  */
211
211
  deviceIsSecure: boolean;
212
212
  /**
213
- * If biometry is not available and the system gives a reason why,
214
- * it will be returned here. Otherwise it's an empty string.
213
+ * If weak or better biometry is not available and the system gives
214
+ * a reason why, it will be returned here. Otherwise it's an empty string.
215
215
  */
216
216
  reason: string;
217
217
  /**
218
- * If biometry is not available, the error code will be returned here.
219
- * Otherwise it's an empty string. The error code will be one of the
220
- * `BiometryErrorType` enum values, and is consistent across
218
+ * If weak or better biometry is not available, the error code will be
219
+ * returned here. Otherwise it's an empty string. The error code will be
220
+ * one of the `BiometryErrorType` enum values, and is consistent across
221
221
  * platforms.
222
222
  */
223
223
  code: BiometryErrorType;
224
+ /**
225
+ * If strong biometry is not available and the system gives
226
+ * a reason why, it will be returned here. Otherwise it's an empty string.
227
+ *
228
+ * On iOS, this will always be the same as `reason`, since all biometry
229
+ * on iOS is strong.
230
+ */
231
+ strongReason?: string;
232
+ /**
233
+ * If strong biometry is not available, the error code will be
234
+ * returned here. Otherwise it's an empty string. The error code will be
235
+ * one of the `BiometryErrorType` enum values, and is consistent across
236
+ * platforms.
237
+ *
238
+ * On iOS, this will always be the same as `code`, since all biometry
239
+ * on iOS is strong.
240
+ */
241
+ strongCode?: BiometryErrorType;
224
242
  }
225
243
  /**
226
244
  * The signature of the callback passed to `addResumeListener()`.
@@ -30,6 +30,8 @@ export class BiometricAuthNative extends BiometricAuthBase {
30
30
  deviceIsSecure: false,
31
31
  reason: '',
32
32
  code: BiometryErrorType.none,
33
+ strongReason: '',
34
+ strongCode: BiometryErrorType.none,
33
35
  });
34
36
  }
35
37
  // @native
@@ -298,6 +298,8 @@ class BiometricAuthNative extends BiometricAuthBase {
298
298
  deviceIsSecure: false,
299
299
  reason: '',
300
300
  code: exports.BiometryErrorType.none,
301
+ strongReason: '',
302
+ strongCode: exports.BiometryErrorType.none,
301
303
  });
302
304
  }
303
305
  // @native
package/dist/plugin.js CHANGED
@@ -296,6 +296,8 @@ var capacitorBiometricAuth = (function (exports, core, app) {
296
296
  deviceIsSecure: false,
297
297
  reason: '',
298
298
  code: exports.BiometryErrorType.none,
299
+ strongReason: '',
300
+ strongCode: exports.BiometryErrorType.none,
299
301
  });
300
302
  }
301
303
  // @native
@@ -69,7 +69,9 @@ public class BiometricAuthNative: CAPPlugin {
69
69
  "biometryTypes": types,
70
70
  "deviceIsSecure": deviceIsSecure,
71
71
  "reason": reason,
72
- "code": errorCode
72
+ "code": errorCode,
73
+ "strongReason": reason,
74
+ "strongCode": errorCode
73
75
  ])
74
76
  }
75
77
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparajita/capacitor-biometric-auth",
3
- "version": "7.0.2",
3
+ "version": "7.1.0",
4
4
  "description": "Provides access to the native biometric auth & device security APIs for Capacitor apps",
5
5
  "author": "Aparajita Fishman",
6
6
  "license": "MIT",
@@ -58,26 +58,26 @@
58
58
  "@aparajita/prettier-config": "^2.0.0",
59
59
  "@aparajita/swiftly": "^1.0.4",
60
60
  "@capacitor/cli": "^5.6.0",
61
- "@commitlint/cli": "^18.4.3",
62
- "@commitlint/config-conventional": "^18.4.3",
61
+ "@commitlint/cli": "^18.4.4",
62
+ "@commitlint/config-conventional": "^18.4.4",
63
63
  "@ionic/swiftlint-config": "^1.1.2",
64
64
  "@rollup/plugin-json": "^6.1.0",
65
- "@types/node": "^20.10.6",
66
- "@typescript-eslint/eslint-plugin": "^6.17.0",
67
- "@typescript-eslint/parser": "^6.17.0",
68
- "commit-and-tag-version": "^12.0.0",
65
+ "@types/node": "^20.10.8",
66
+ "@typescript-eslint/eslint-plugin": "^6.18.1",
67
+ "@typescript-eslint/parser": "^6.18.1",
68
+ "commit-and-tag-version": "^12.1.0",
69
69
  "eslint": "^8.56.0",
70
70
  "eslint-config-prettier": "^9.1.0",
71
71
  "eslint-config-standard": "^17.1.0",
72
72
  "eslint-import-resolver-typescript": "^3.6.1",
73
73
  "eslint-plugin-import": "^2.29.1",
74
- "eslint-plugin-n": "^16.6.0",
74
+ "eslint-plugin-n": "^16.6.2",
75
75
  "eslint-plugin-promise": "^6.1.1",
76
76
  "nodemon": "^3.0.2",
77
77
  "prettier": "^3.1.1",
78
78
  "prettier-plugin-java": "^2.5.0",
79
79
  "rimraf": "^5.0.5",
80
- "rollup": "^4.9.2",
80
+ "rollup": "^4.9.4",
81
81
  "simple-git-hooks": "^2.9.0",
82
82
  "swiftlint": "^1.0.2",
83
83
  "typescript": "~5.3.3"