Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const decrypted = await instance.decryptPassword(encryptedPassword);
keychainObject.password = decrypted.password;
instance.isAuthenticating = false;
return keychainObject;
}
instance.isAuthenticating = false;
}
return null;
},
async setGenericPassword(key, password, authOptions) {
const encryptedPassword = await instance.encryptPassword(password);
return Keychain.setGenericPassword(key, encryptedPassword, { ...defaultOptions, ...authOptions });
},
ACCESS_CONTROL: Keychain.ACCESS_CONTROL,
ACCESSIBLE: Keychain.ACCESSIBLE,
AUTHENTICATION_TYPE: Keychain.AUTHENTICATION_TYPE
};
export const setKeychainDataObject = (data: KeyChainData) => Keychain
.setGenericPassword(KEYCHAIN_DATA_KEY, JSON.stringify(data), {
accessControl: Platform.select({
ios: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
android: Keychain.ACCESS_CONTROL.BIOMETRY_ANY,
}),
accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED,
service: KEYCHAIN_SERVICE,
})
.catch(() => null);
if (Platform.OS === 'android') {
await KeyStoreBridge.initFingerprintKeys(dataKey)
const fingerprintEncryptedMasterKey = await KeyStoreBridge.encryptData(
masterKey,
dataKey,
)
return fingerprintEncryptedMasterKey
}
if (Platform.OS === 'ios') {
await Keychain.setGenericPassword('', masterKey, {
service: dataKey,
accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
})
return ''
}
throw new Error('Unsupported platform')
}
export function setCredentials ({ username, password }: KeychainCredentials, service?: string): Promise {
return Keychain.setGenericPassword(
username,
password,
{ service, accessible: Keychain.ACCESSIBLE.AFTER_FIRST_UNLOCK }
);
}