mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-03 20:07:11 +01:00
ADD: export individual private keys for addresses
This commit is contained in:
parent
5774e57115
commit
1f6a7722b7
2 changed files with 66 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { useRef } from 'react';
|
import React, { useContext, useRef } from 'react';
|
||||||
import { StyleSheet, Text, View } from 'react-native';
|
import { StyleSheet, Text, View } from 'react-native';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import { ListItem } from 'react-native-elements';
|
import { ListItem } from 'react-native-elements';
|
||||||
|
@ -9,8 +9,22 @@ import TooltipMenu from '../TooltipMenu';
|
||||||
import Clipboard from '@react-native-clipboard/clipboard';
|
import Clipboard from '@react-native-clipboard/clipboard';
|
||||||
import Share from 'react-native-share';
|
import Share from 'react-native-share';
|
||||||
import { useTheme } from '../themes';
|
import { useTheme } from '../themes';
|
||||||
|
import { BitcoinUnit } from '../../models/bitcoinUnits';
|
||||||
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||||
|
import { AbstractWallet } from '../../class';
|
||||||
|
import Biometric from '../../class/biometrics';
|
||||||
|
const confirm = require('../../helpers/confirm');
|
||||||
|
|
||||||
const AddressItem = ({ item, balanceUnit, walletID, allowSignVerifyMessage }) => {
|
interface AddressItemProps {
|
||||||
|
// todo: fix `any` after addresses.js is converted to the church of holy typescript
|
||||||
|
item: any;
|
||||||
|
balanceUnit: BitcoinUnit;
|
||||||
|
walletID: string;
|
||||||
|
allowSignVerifyMessage: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AddressItem = ({ item, balanceUnit, walletID, allowSignVerifyMessage }: AddressItemProps) => {
|
||||||
|
const { wallets } = useContext(BlueStorageContext);
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
|
|
||||||
const hasTransactions = item.transactions > 0;
|
const hasTransactions = item.transactions > 0;
|
||||||
|
@ -38,7 +52,9 @@ const AddressItem = ({ item, balanceUnit, walletID, allowSignVerifyMessage }) =>
|
||||||
|
|
||||||
const menuRef = useRef();
|
const menuRef = useRef();
|
||||||
const navigateToReceive = () => {
|
const navigateToReceive = () => {
|
||||||
|
// @ts-ignore wtf
|
||||||
menuRef.current?.dismissMenu();
|
menuRef.current?.dismissMenu();
|
||||||
|
// @ts-ignore wtf
|
||||||
navigate('ReceiveDetailsRoot', {
|
navigate('ReceiveDetailsRoot', {
|
||||||
screen: 'ReceiveDetails',
|
screen: 'ReceiveDetails',
|
||||||
params: {
|
params: {
|
||||||
|
@ -49,7 +65,9 @@ const AddressItem = ({ item, balanceUnit, walletID, allowSignVerifyMessage }) =>
|
||||||
};
|
};
|
||||||
|
|
||||||
const navigateToSignVerify = () => {
|
const navigateToSignVerify = () => {
|
||||||
|
// @ts-ignore wtf
|
||||||
menuRef.current?.dismissMenu();
|
menuRef.current?.dismissMenu();
|
||||||
|
// @ts-ignore wtf
|
||||||
navigate('SignVerifyRoot', {
|
navigate('SignVerifyRoot', {
|
||||||
screen: 'SignVerify',
|
screen: 'SignVerify',
|
||||||
params: {
|
params: {
|
||||||
|
@ -69,13 +87,42 @@ const AddressItem = ({ item, balanceUnit, walletID, allowSignVerifyMessage }) =>
|
||||||
Share.open({ message: item.address }).catch(error => console.log(error));
|
Share.open({ message: item.address }).catch(error => console.log(error));
|
||||||
};
|
};
|
||||||
|
|
||||||
const onToolTipPress = id => {
|
const handleCopyPrivkeyPress = () => {
|
||||||
|
const wallet = wallets.find((w: AbstractWallet) => w.getID() === walletID);
|
||||||
|
if (!wallet) {
|
||||||
|
alert('Internal error: cant find wallet');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const wif = wallet._getWIFbyAddress(item.address);
|
||||||
|
if (!wif) {
|
||||||
|
alert('Internal error: cant get WIF from the wallet');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Clipboard.setString(wif);
|
||||||
|
} catch (error: any) {
|
||||||
|
alert(error.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onToolTipPress = async (id: string) => {
|
||||||
if (id === AddressItem.actionKeys.CopyToClipboard) {
|
if (id === AddressItem.actionKeys.CopyToClipboard) {
|
||||||
handleCopyPress();
|
handleCopyPress();
|
||||||
} else if (id === AddressItem.actionKeys.Share) {
|
} else if (id === AddressItem.actionKeys.Share) {
|
||||||
handleSharePress();
|
handleSharePress();
|
||||||
} else if (id === AddressItem.actionKeys.SignVerify) {
|
} else if (id === AddressItem.actionKeys.SignVerify) {
|
||||||
navigateToSignVerify();
|
navigateToSignVerify();
|
||||||
|
} else if (id === AddressItem.actionKeys.ExportPrivateKey) {
|
||||||
|
if (await confirm(loc.addresses.sensitive_private_key)) {
|
||||||
|
if (await Biometric.isBiometricUseCapableAndEnabled()) {
|
||||||
|
if (!(await Biometric.unlockWithBiometrics())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCopyPrivkeyPress();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,6 +148,14 @@ const AddressItem = ({ item, balanceUnit, walletID, allowSignVerifyMessage }) =>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allowSignVerifyMessage) {
|
||||||
|
actions.push({
|
||||||
|
id: AddressItem.actionKeys.ExportPrivateKey,
|
||||||
|
text: loc.addresses.copy_private_key,
|
||||||
|
icon: AddressItem.actionIcons.ExportPrivateKey,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -125,7 +180,7 @@ const AddressItem = ({ item, balanceUnit, walletID, allowSignVerifyMessage }) =>
|
||||||
<Text style={[stylesHook.list, styles.balance, stylesHook.balance]}>{balance}</Text>
|
<Text style={[stylesHook.list, styles.balance, stylesHook.balance]}>{balance}</Text>
|
||||||
</View>
|
</View>
|
||||||
</ListItem.Content>
|
</ListItem.Content>
|
||||||
<View style={styles.labels}>
|
<View>
|
||||||
<AddressTypeBadge isInternal={item.isInternal} hasTransactions={hasTransactions} />
|
<AddressTypeBadge isInternal={item.isInternal} hasTransactions={hasTransactions} />
|
||||||
<Text style={[stylesHook.list, styles.balance, stylesHook.balance]}>
|
<Text style={[stylesHook.list, styles.balance, stylesHook.balance]}>
|
||||||
{loc.addresses.transactions}: {item.transactions}
|
{loc.addresses.transactions}: {item.transactions}
|
||||||
|
@ -143,6 +198,7 @@ AddressItem.actionKeys = {
|
||||||
Share: 'share',
|
Share: 'share',
|
||||||
CopyToClipboard: 'copyToClipboard',
|
CopyToClipboard: 'copyToClipboard',
|
||||||
SignVerify: 'signVerify',
|
SignVerify: 'signVerify',
|
||||||
|
ExportPrivateKey: 'exportPrivateKey',
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressItem.actionIcons = {
|
AddressItem.actionIcons = {
|
||||||
|
@ -158,6 +214,10 @@ AddressItem.actionIcons = {
|
||||||
iconType: 'SYSTEM',
|
iconType: 'SYSTEM',
|
||||||
iconValue: 'doc.on.doc',
|
iconValue: 'doc.on.doc',
|
||||||
},
|
},
|
||||||
|
ExportPrivateKey: {
|
||||||
|
iconType: 'SYSTEM',
|
||||||
|
iconValue: 'key',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
|
@ -571,6 +571,8 @@
|
||||||
"sats": "sats"
|
"sats": "sats"
|
||||||
},
|
},
|
||||||
"addresses": {
|
"addresses": {
|
||||||
|
"copy_private_key": "Copy private key",
|
||||||
|
"sensitive_private_key": "Warning: private keys are extremely sensitive. Continue?",
|
||||||
"sign_title": "Sign/Verify Message",
|
"sign_title": "Sign/Verify Message",
|
||||||
"sign_help": "Here you can create or verify a cryptographic signature based on a Bitcoin address.",
|
"sign_help": "Here you can create or verify a cryptographic signature based on a Bitcoin address.",
|
||||||
"sign_sign": "Sign",
|
"sign_sign": "Sign",
|
||||||
|
|
Loading…
Add table
Reference in a new issue