@aparajita/capacitor-biometric-auth 7.0.2 → 7.1.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/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
 
@@ -94,13 +94,14 @@ public class BiometricAuthNative extends Plugin {
94
94
  private ArrayList<BiometryType> biometryTypes;
95
95
 
96
96
  private int getAuthenticatorFromCall(PluginCall call) {
97
+ int authenticator = BiometricManager.Authenticators.BIOMETRIC_WEAK;
98
+
97
99
  Integer value = call.getInt(
98
100
  "androidBiometryStrength",
99
101
  BiometryStrength.WEAK.ordinal()
100
102
  );
101
- int authenticator = BiometricManager.Authenticators.BIOMETRIC_WEAK;
102
103
 
103
- if (value == BiometryStrength.STRONG.ordinal()) {
104
+ if (value != null && value == BiometryStrength.STRONG.ordinal()) {
104
105
  authenticator = BiometricManager.Authenticators.BIOMETRIC_STRONG;
105
106
  }
106
107
 
@@ -112,25 +113,31 @@ public class BiometricAuthNative extends Plugin {
112
113
  */
113
114
  @PluginMethod
114
115
  public void checkBiometry(PluginCall call) {
116
+ JSObject result = new JSObject();
115
117
  BiometricManager manager = BiometricManager.from(getContext());
116
118
 
117
119
  // First check for weak biometry or better.
118
- int biometryResult = manager.canAuthenticate(
120
+ int weakBiometryResult = manager.canAuthenticate(
119
121
  BiometricManager.Authenticators.BIOMETRIC_WEAK
120
122
  );
121
123
 
122
- JSObject result = new JSObject();
124
+ setReasonAndCode(weakBiometryResult, false, result);
125
+
123
126
  result.put(
124
127
  "isAvailable",
125
- biometryResult == BiometricManager.BIOMETRIC_SUCCESS
128
+ weakBiometryResult == BiometricManager.BIOMETRIC_SUCCESS
126
129
  );
127
130
 
128
131
  // Now check for strong biometry.
129
- biometryResult =
130
- manager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG);
132
+ int strongBiometryResult = manager.canAuthenticate(
133
+ BiometricManager.Authenticators.BIOMETRIC_STRONG
134
+ );
135
+
136
+ setReasonAndCode(strongBiometryResult, true, result);
137
+
131
138
  result.put(
132
139
  "strongBiometryIsAvailable",
133
- biometryResult == BiometricManager.BIOMETRIC_SUCCESS
140
+ strongBiometryResult == BiometricManager.BIOMETRIC_SUCCESS
134
141
  );
135
142
 
136
143
  biometryTypes = getDeviceBiometryTypes();
@@ -155,9 +162,17 @@ public class BiometricAuthNative extends Plugin {
155
162
  result.put("deviceIsSecure", false);
156
163
  }
157
164
 
165
+ call.resolve(result);
166
+ }
167
+
168
+ private static void setReasonAndCode(
169
+ int canAuthenticateResult,
170
+ boolean strong,
171
+ JSObject result
172
+ ) {
158
173
  String reason = "";
159
174
 
160
- switch (biometryResult) {
175
+ switch (canAuthenticateResult) {
161
176
  case BiometricManager.BIOMETRIC_SUCCESS:
162
177
  break;
163
178
  case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
@@ -182,15 +197,14 @@ public class BiometricAuthNative extends Plugin {
182
197
  break;
183
198
  }
184
199
 
185
- String errorCode = biometryErrorCodeMap.get(biometryResult);
200
+ String errorCode = biometryErrorCodeMap.get(canAuthenticateResult);
186
201
 
187
202
  if (errorCode == null) {
188
203
  errorCode = "biometryNotAvailable";
189
204
  }
190
205
 
191
- result.put("reason", reason);
192
- result.put("code", errorCode);
193
- call.resolve(result);
206
+ result.put(strong ? "strongReason" : "reason", reason);
207
+ result.put(strong ? "strongCode" : "code", errorCode);
194
208
  }
195
209
 
196
210
  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.1",
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.5.0",
62
+ "@commitlint/config-conventional": "^18.5.0",
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.11.6",
66
+ "@typescript-eslint/eslint-plugin": "^6.19.1",
67
+ "@typescript-eslint/parser": "^6.19.1",
68
+ "commit-and-tag-version": "^12.2.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
- "nodemon": "^3.0.2",
77
- "prettier": "^3.1.1",
76
+ "nodemon": "^3.0.3",
77
+ "prettier": "^3.2.4",
78
78
  "prettier-plugin-java": "^2.5.0",
79
79
  "rimraf": "^5.0.5",
80
- "rollup": "^4.9.2",
80
+ "rollup": "^4.9.6",
81
81
  "simple-git-hooks": "^2.9.0",
82
82
  "swiftlint": "^1.0.2",
83
83
  "typescript": "~5.3.3"