Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: renaming to seedPhrase when phrase is used #477

Merged
merged 5 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ build/
.gradle
local.properties
*.iml
gen/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what is generating this?

Copy link
Contributor Author

@hanwencheng hanwencheng Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know either, after build android with gradle assemble, it created three files under gen: buildConfig.java, Manifest.java and R.java. On each of them there is a head comment said:

/*___Generated_by_IDEA___*/

So I just add them there.


# node.js
#
Expand Down
4 changes: 2 additions & 2 deletions specs/util/identitiesUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
13 changes: 8 additions & 5 deletions src/screens/AccountNetworkChooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/screens/IdentityBackup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/screens/IdentityManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
14 changes: 10 additions & 4 deletions src/screens/MessageDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/screens/PathDerivation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/screens/PathDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions src/screens/TxDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/stores/AccountsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we only encrypt seedPhrase in encryptedSeed, but will include password in the future

const newIdentities = this.state.identities.concat(updatedIdentity);
this.setState({
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 10 additions & 9 deletions src/stores/ScannerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,16 @@ 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 =
NETWORK_LIST[sender.networkKey].protocol === NetworkProtocols.ETHEREUM;

let signedData;
if (isEthereum) {
signedData = await brainWalletSign(suri, dataToSign);
signedData = await brainWalletSign(seed, dataToSign);
} else {
let signable;

Expand All @@ -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));
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/stores/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type AccountMeta = {
};

export type Identity = {
encryptedSeedPhrase: string,
// encrypted seed include seedPhrase and password
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently only seedPhrase

encryptedSeed: string,
derivationPassword: string,
meta: Map<string, AccountMeta>,
accountIds: Map<string, string>,
Expand Down
2 changes: 1 addition & 1 deletion src/util/identitiesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function emptyIdentity() {
return {
accountIds: new Map(),
derivationPassword: '',
encryptedSeedPhrase: '',
encryptedSeed: '',
meta: new Map(),
name: ''
};
Expand Down
2 changes: 1 addition & 1 deletion src/util/navigationHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand Down