Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(result: void);
});
// $FlowExpectedError - First two arguments are required
setGenericPassword();
setGenericPassword('username', 'password').then(result => {
(result: boolean);
});
setGenericPassword('username', 'password', 'service');
setGenericPassword('username', 'password', simpleOptions);
getGenericPassword().then(result => {
(result: boolean | SharedWebCredentials);
});
getGenericPassword('service');
getGenericPassword(simpleOptions);
resetGenericPassword().then(result => {
(result: boolean);
});
resetGenericPassword('service');
resetGenericPassword(simpleOptions);
requestSharedWebCredentials().then(result => {
if (result) {
(result.server: string);
(result.username: string);
(result.password: string);
}
});
setSharedWebCredentials('server', 'username', 'password').then(result => {
async fetchStoredCreds () {
try {
const storedValues = await AsyncStorage.multiGet([
SERVER_URL_KEY,
CLIENT_CERT_PATH_KEY,
CA_CERT_PATH_KEY,
])
let caCertPath // Android only
if (storedValues.length) {
const serverUrl = storedValues[0][1]
const clientCertPath = storedValues[1][1]
if (Platform.OS === 'android') {
caCertPath = storedValues[2][1]
}
if (serverUrl && clientCertPath){
const credentials = await Keychain.getGenericPassword()
this.onSelectNode(
serverUrl,
clientCertPath,
credentials.password,
caCertPath
)
return
}
}
} catch (error) {
console.warn(error)
}
this.setDisconnected()
}
function fxaGetCredential() {
// Retrieve the credentials
return Keychain.getGenericPassword().then((credentials) => {
if (credentials && credentials.password) {
// TODO: might need to refactor this to exit out if empty
const creds = JSON.parse(credentials.password);
return creds;
} else {
return {};
}
}).catch((error) => {
// TODO: What on earth do we do here?
console.log('Keychain cannot be accessed!', error);
return {};
});
}
async function getPassword(): Promise {
// At the time of writing this file, the encryption password is stored in
// react-native-keychain and accessesed through src/lib/keychain.ts, but code
// is reproduced here in case things change in the future
if (typeof navigator !== 'undefined' && navigator.product == 'ReactNative') {
// We load react-native-keychain here conditionally because it is not
// transpiled and cannot be loaded into ts-node (if running migrations locally
// on dev machine)
const Keychain = require('react-native-keychain')
const keyChainData = await Keychain.getGenericPassword()
if (keyChainData && keyChainData.password) {
return keyChainData.password
} else {
throw new Error(
"Can't load password from react-native-keychain"
)
}
} else {
const password = process.env.SMARTWALLET_PASSWORD
if (!password) {
throw new Error(
"Node envrionment detected. " +
"Please set a password in the environment variable SMARTWALLET_PASSWORD"
)
}
return password
return new Promise(async (resolve) => {
try {
const result = await Keychain.getGenericPassword(key);
resolve({ error: false, data: result });
} catch (e) {
resolve({ error: true, data: e });
console.log(e);
}
});
};
async retrieveCredientials() {
let credentials = await Keychain.getGenericPassword()
console.log('username', credentials.username)
console.log('password', credentials.password)
console.log('Credentials successfully created')
}
retrieveUserCreds() {
return Keychain
.getGenericPassword()
.then(credentials => (credentials))
.catch(error => (error))
},
export function getRefreshToken() {
return Keychain.getGenericPassword()
.then(creds => {
if (creds) {
const data = JSON.parse(creds.password);
return data.refreshToken;
}
return null;
});
}
async componentWillMount() {
if (!this.props.storedPin) {
this.keyChainResult = await Keychain.getGenericPassword();
}
}