Unverified Commit bdb2349c authored by Hanwen Cheng's avatar Hanwen Cheng Committed by GitHub
Browse files

chore: renaming to seedPhrase when phrase is used (#477)

* chore: ignore generated file

* fix: schema should use encryptedSeed

* chore: renaming for better understanding

* chore: rephrase comment
parent f67dcace
Pipeline #70224 failed with stages
in 4 minutes and 15 seconds
......@@ -45,6 +45,7 @@ build/
.gradle
local.properties
*.iml
gen/
# node.js
#
......
......@@ -109,14 +109,14 @@ const testIdentities = [
{
accountIds: accountIdsMap,
derivationPassword: '',
encryptedSeedPhrase: 'yyyy',
encryptedSeed: 'yyyy',
meta: metaMap,
name: 'identity1'
},
{
accountIds: accountIdsMap,
derivationPassword: '',
encryptedSeedPhrase: 'xxxx',
encryptedSeed: 'xxxx',
meta: metaMap,
name: 'identity2'
}
......
......@@ -29,7 +29,10 @@ import {
SubstrateNetworkKeys,
NetworkProtocols
} from '../constants';
import { navigateToPathsList, unlockSeed } from '../util/navigationHelpers';
import {
navigateToPathsList,
unlockSeedPhrase
} from '../util/navigationHelpers';
import { withAccountStore } from '../util/HOC';
import { alertPathDerivationError } from '../util/alertUtils';
import {
......@@ -123,10 +126,10 @@ function AccountNetworkChooser({ navigation, accounts }) {
const deriveSubstrateDefault = async (networkKey, networkParams) => {
const { prefix, pathId } = networkParams;
const seed = await unlockSeed(navigation);
const seedPhrase = await unlockSeedPhrase(navigation);
const derivationSucceed = await accounts.deriveNewPath(
`//${pathId}//default`,
seed,
seedPhrase,
prefix,
networkKey,
'Default'
......@@ -135,9 +138,9 @@ function AccountNetworkChooser({ navigation, accounts }) {
};
const deriveEthereumAccount = async networkKey => {
const seed = await unlockSeed(navigation);
const seedPhrase = await unlockSeedPhrase(navigation);
const derivationSucceed = await accounts.deriveEthereumAccount(
seed,
seedPhrase,
networkKey
);
onDerivationFinished(derivationSucceed, networkKey);
......
......@@ -28,7 +28,7 @@ import { withNavigation } from 'react-navigation';
import {
navigateToNewIdentityNetwork,
setPin,
unlockSeed
unlockSeedPhrase
} from '../util/navigationHelpers';
import { withAccountStore } from '../util/HOC';
import testIDs from '../../e2e/testIDs';
......@@ -50,7 +50,7 @@ function IdentityBackup({ navigation, accounts }) {
if (isNew) {
setSeedPhrase(await words());
} else {
const backupSeedPhrase = await unlockSeed(navigation);
const backupSeedPhrase = await unlockSeedPhrase(navigation);
navigation.pop();
setSeedPhrase(backupSeedPhrase);
}
......
......@@ -22,7 +22,10 @@ import { ScrollView, StyleSheet, View } from 'react-native';
import { withAccountStore } from '../util/HOC';
import TextInput from '../components/TextInput';
import { navigateToLandingPage, unlockSeed } from '../util/navigationHelpers';
import {
navigateToLandingPage,
unlockSeedPhrase
} from '../util/navigationHelpers';
import {
alertDeleteIdentity,
alertIdentityDeletionError
......@@ -39,7 +42,7 @@ function IdentityManagement({ accounts, navigation }) {
const onOptionSelect = value => {
if (value === 'PathDelete') {
alertDeleteIdentity(async () => {
await unlockSeed(navigation);
await unlockSeedPhrase(navigation);
const deleteSucceed = await accounts.deleteCurrentIdentity();
if (deleteSucceed) {
navigateToLandingPage(navigation, true);
......
......@@ -33,7 +33,10 @@ import Button from '../components/Button';
import PayloadDetailsCard from '../components/PayloadDetailsCard';
import ScannerStore from '../stores/ScannerStore';
import AccountsStore from '../stores/AccountsStore';
import { navigateToSignedMessage, unlockSeed } from '../util/navigationHelpers';
import {
navigateToSignedMessage,
unlockSeedPhrase
} from '../util/navigationHelpers';
import fontStyles from '../fontStyles';
import MessageDetailsCard from '../components/MessageDetailsCard';
import { alertMultipart } from '../util/alertUtils';
......@@ -52,9 +55,12 @@ export default class MessageDetails extends React.PureComponent {
sender,
accountsStore.state.identities
);
const seed = await unlockSeed(this.props.navigation, senderIdentity);
await scannerStore.signDataWithSeed(
seed,
const seedPhrase = await unlockSeedPhrase(
this.props.navigation,
senderIdentity
);
await scannerStore.signDataWithSeedPhrase(
seedPhrase,
NETWORK_LIST[sender.networkKey].protocol
);
return navigateToSignedMessage(this.props.navigation);
......
......@@ -23,7 +23,10 @@ import { StyleSheet, Text, View } from 'react-native';
import TextInput from '../components/TextInput';
import ButtonMainAction from '../components/ButtonMainAction';
import { validateDerivedPath } from '../util/identitiesUtils';
import { navigateToPathsList, unlockSeed } from '../util/navigationHelpers';
import {
navigateToPathsList,
unlockSeedPhrase
} from '../util/navigationHelpers';
import { NETWORK_LIST, UnknownNetworkKeys } from '../constants';
import { alertPathDerivationError } from '../util/alertUtils';
import testIDs from '../../e2e/testIDs';
......@@ -49,10 +52,10 @@ function PathDerivation({ accounts, navigation }) {
if (!validateDerivedPath(derivationPath)) {
return setIsPathValid(false);
}
const seed = await unlockSeed(navigation);
const seedPhrase = await unlockSeedPhrase(navigation);
const derivationSucceed = await accounts.deriveNewPath(
completePath,
seed,
seedPhrase,
NETWORK_LIST[networkKey].prefix,
networkKey,
keyPairsName
......
......@@ -32,7 +32,10 @@ import {
} from '../util/identitiesUtils';
import { UnknownNetworkKeys } from '../constants';
import { alertDeleteAccount, alertPathDeletionError } from '../util/alertUtils';
import { navigateToPathsList, unlockSeed } from '../util/navigationHelpers';
import {
navigateToPathsList,
unlockSeedPhrase
} from '../util/navigationHelpers';
import testIDs from '../../e2e/testIDs';
export function PathDetailsView({ accounts, navigation, path, networkKey }) {
......@@ -42,7 +45,7 @@ export function PathDetailsView({ accounts, navigation, path, networkKey }) {
const onOptionSelect = value => {
if (value === 'PathDelete') {
alertDeleteAccount('this key pairs', async () => {
await unlockSeed(navigation);
await unlockSeedPhrase(navigation);
const deleteSucceed = await accounts.deletePath(path);
if (deleteSucceed) {
isSubstratePath(path)
......
......@@ -34,7 +34,10 @@ import TxDetailsCard from '../components/TxDetailsCard';
import AccountsStore from '../stores/AccountsStore';
import ScannerStore from '../stores/ScannerStore';
import PayloadDetailsCard from '../components/PayloadDetailsCard';
import { navigateToSignedTx, unlockSeed } from '../util/navigationHelpers';
import {
navigateToSignedTx,
unlockSeedPhrase
} from '../util/navigationHelpers';
import { GenericExtrinsicPayload } from '@polkadot/types';
import testIDs from '../../e2e/testIDs';
import fontStyles from '../fontStyles';
......@@ -53,9 +56,12 @@ export default class TxDetails extends React.PureComponent {
sender,
accountsStore.state.identities
);
const seed = await unlockSeed(this.props.navigation, senderIdentity);
await scannerStore.signDataWithSeed(
seed,
const seedPhrase = await unlockSeedPhrase(
this.props.navigation,
senderIdentity
);
await scannerStore.signDataWithSeedPhrase(
seedPhrase,
NETWORK_LIST[sender.networkKey].protocol
);
return navigateToSignedTx(this.props.navigation);
......
......@@ -89,9 +89,9 @@ export default class AccountsStore extends Container<AccountsStoreState> {
});
}
async deriveEthereumAccount(seed, networkKey) {
async deriveEthereumAccount(seedPhrase, networkKey) {
const networkParams = NETWORK_LIST[networkKey];
const ethereumAddress = await brainWalletAddress(seed);
const ethereumAddress = await brainWalletAddress(seedPhrase);
if (ethereumAddress === '') return false;
const { ethereumChainId } = networkParams;
const accountId = generateAccountId({
......@@ -296,6 +296,8 @@ export default class AccountsStore extends Container<AccountsStoreState> {
async saveNewIdentity(seedPhrase, pin) {
const updatedIdentity = deepCopyIdentity(this.state.newIdentity);
//TODO encrypt seedPhrase with password in the future version,
// current encryption with only seedPhrase is compatible.
updatedIdentity.encryptedSeed = await encryptData(seedPhrase, pin);
const newIdentities = this.state.identities.concat(updatedIdentity);
this.setState({
......@@ -367,12 +369,12 @@ export default class AccountsStore extends Container<AccountsStoreState> {
}
}
async deriveNewPath(newPath, seed, prefix, networkKey, name) {
async deriveNewPath(newPath, seedPhrase, prefix, networkKey, name) {
const updatedCurrentIdentity = deepCopyIdentity(this.state.currentIdentity);
const suri = constructSURI({
derivePath: newPath,
password: '',
phrase: seed
phrase: seedPhrase
});
let address = '';
try {
......
......@@ -406,7 +406,8 @@ export default class ScannerStore extends Container<ScannerState> {
return true;
}
async signDataWithSuri(suri) {
//seed is SURI on substrate and is seedPhrase on Ethereum
async signData(seed) {
const { dataToSign, isHash, sender } = this.state;
const isEthereum =
......@@ -414,7 +415,7 @@ export default class ScannerStore extends Container<ScannerState> {
let signedData;
if (isEthereum) {
signedData = await brainWalletSign(suri, dataToSign);
signedData = await brainWalletSign(seed, dataToSign);
} else {
let signable;
......@@ -427,7 +428,7 @@ export default class ScannerStore extends Container<ScannerState> {
} else if (isAscii(dataToSign)) {
signable = hexStripPrefix(asciiToHex(dataToSign));
}
let signed = await substrateSign(suri, signable);
let signed = await substrateSign(seed, signable);
signed = '0x' + signed;
// TODO: tweak the first byte if and when sig type is not sr25519
const sig = u8aConcat(SIG_TYPE_SR25519, hexToU8a(signed));
......@@ -436,23 +437,23 @@ export default class ScannerStore extends Container<ScannerState> {
this.setState({ signedData });
}
async signDataWithSeed(seed, protocol) {
async signDataWithSeedPhrase(seedPhrase, protocol) {
if (protocol === NetworkProtocols.SUBSTRATE) {
const suri = constructSURI({
derivePath: this.state.sender.path,
password: '',
phrase: seed
phrase: seedPhrase
});
await this.signDataWithSuri(suri);
await this.signData(suri);
} else {
await this.signDataWithSuri(seed);
await this.signData(seedPhrase);
}
}
async signDataLegacy(pin = '1') {
const { sender } = this.state;
const suri = await decryptData(sender.encryptedSeed, pin);
await this.signDataWithSuri(suri);
const seed = await decryptData(sender.encryptedSeed, pin);
await this.signData(seed);
}
cleanup() {
......
......@@ -38,7 +38,8 @@ type AccountMeta = {
};
export type Identity = {
encryptedSeedPhrase: string,
// encrypted seed include seedPhrase and password
encryptedSeed: string,
derivationPassword: string,
meta: Map<string, AccountMeta>,
accountIds: Map<string, string>,
......
......@@ -46,7 +46,7 @@ export function emptyIdentity() {
return {
accountIds: new Map(),
derivationPassword: '',
encryptedSeedPhrase: '',
encryptedSeed: '',
meta: new Map(),
name: ''
};
......
......@@ -23,7 +23,7 @@ export const setPin = async navigation =>
navigation.navigate('IdentityPin', { isNew: true, resolve });
});
export const unlockSeed = async (navigation, identity) =>
export const unlockSeedPhrase = async (navigation, identity) =>
new Promise(resolve => {
navigation.navigate('IdentityPin', { identity, isUnlock: true, resolve });
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment