(password, type)
| 113 | }, |
| 114 | |
| 115 | async setGenericPassword(password, type) { |
| 116 | const authOptions = { |
| 117 | accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY, |
| 118 | }; |
| 119 | |
| 120 | const metrics = MetaMetrics.getInstance(); |
| 121 | if (type === this.TYPES.BIOMETRICS) { |
| 122 | authOptions.accessControl = Keychain.ACCESS_CONTROL.BIOMETRY_CURRENT_SET; |
| 123 | await metrics.addTraitsToUser({ |
| 124 | [UserProfileProperty.AUTHENTICATION_TYPE]: |
| 125 | AUTHENTICATION_TYPE.BIOMETRIC, |
| 126 | }); |
| 127 | } else if (type === this.TYPES.PASSCODE) { |
| 128 | authOptions.accessControl = Keychain.ACCESS_CONTROL.DEVICE_PASSCODE; |
| 129 | await metrics.addTraitsToUser({ |
| 130 | [UserProfileProperty.AUTHENTICATION_TYPE]: AUTHENTICATION_TYPE.PASSCODE, |
| 131 | }); |
| 132 | } else if (type === this.TYPES.REMEMBER_ME) { |
| 133 | await metrics.addTraitsToUser({ |
| 134 | [UserProfileProperty.AUTHENTICATION_TYPE]: |
| 135 | AUTHENTICATION_TYPE.REMEMBER_ME, |
| 136 | }); |
| 137 | //Don't need to add any parameter |
| 138 | } else { |
| 139 | // Setting a password without a type does not save it |
| 140 | return await this.resetGenericPassword(); |
| 141 | } |
| 142 | |
| 143 | const encryptedPassword = await instance.encryptPassword(password); |
| 144 | await Keychain.setGenericPassword('metamask-user', encryptedPassword, { |
| 145 | ...defaultOptions, |
| 146 | ...authOptions, |
| 147 | }); |
| 148 | |
| 149 | if (type === this.TYPES.BIOMETRICS) { |
| 150 | await AsyncStorage.setItem(BIOMETRY_CHOICE, TRUE); |
| 151 | await AsyncStorage.setItem(PASSCODE_DISABLED, TRUE); |
| 152 | await AsyncStorage.removeItem(PASSCODE_CHOICE); |
| 153 | await AsyncStorage.removeItem(BIOMETRY_CHOICE_DISABLED); |
| 154 | |
| 155 | // If the user enables biometrics, we're trying to read the password |
| 156 | // immediately so we get the permission prompt |
| 157 | if (Platform.OS === 'ios') { |
| 158 | await this.getGenericPassword(); |
| 159 | } |
| 160 | } else if (type === this.TYPES.PASSCODE) { |
| 161 | await AsyncStorage.removeItem(BIOMETRY_CHOICE); |
| 162 | await AsyncStorage.removeItem(PASSCODE_DISABLED); |
| 163 | await AsyncStorage.setItem(PASSCODE_CHOICE, TRUE); |
| 164 | await AsyncStorage.setItem(BIOMETRY_CHOICE_DISABLED, TRUE); |
| 165 | } else if (type === this.TYPES.REMEMBER_ME) { |
| 166 | await AsyncStorage.removeItem(BIOMETRY_CHOICE); |
| 167 | await AsyncStorage.setItem(PASSCODE_DISABLED, TRUE); |
| 168 | await AsyncStorage.removeItem(PASSCODE_CHOICE); |
| 169 | await AsyncStorage.setItem(BIOMETRY_CHOICE_DISABLED, TRUE); |
| 170 | //Don't need to add any parameter |
| 171 | } |
| 172 | }, |
nothing calls this directly
no test coverage detected