forked from cerc-io/laconic-wallet
Display hdpaths for newly created accounts
This commit is contained in:
parent
1bde70b7d6
commit
dbaf43f98c
@ -27,8 +27,10 @@ const Accounts: React.FC<AccountsProps> = ({
|
|||||||
setIsAccountCreating(true);
|
setIsAccountCreating(true);
|
||||||
const newAccount = await addAccount(network);
|
const newAccount = await addAccount(network);
|
||||||
setIsAccountCreating(false);
|
setIsAccountCreating(false);
|
||||||
newAccount && updateAccounts(newAccount);
|
if (newAccount) {
|
||||||
updateIndex(selectedAccounts[selectedAccounts.length - 1].id + 1);
|
updateAccounts(newAccount);
|
||||||
|
updateIndex(newAccount.id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectedAccounts: Account[] = (() => {
|
const selectedAccounts: Account[] = (() => {
|
||||||
@ -82,6 +84,12 @@ const Accounts: React.FC<AccountsProps> = ({
|
|||||||
<Text style={styles.highlight}>Public Key: </Text>
|
<Text style={styles.highlight}>Public Key: </Text>
|
||||||
{selectedAccounts[currentIndex]?.pubKey}
|
{selectedAccounts[currentIndex]?.pubKey}
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text variant="bodyLarge">
|
||||||
|
<Text style={{ fontWeight: '700' }}>HD Path: </Text>
|
||||||
|
{selectedAccounts &&
|
||||||
|
selectedAccounts[currentIndex] &&
|
||||||
|
selectedAccounts[currentIndex].hdPath}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={styles.signLink}>
|
<View style={styles.signLink}>
|
||||||
|
@ -30,7 +30,6 @@ const HomeScreen = () => {
|
|||||||
|
|
||||||
const createWalletHandler = async () => {
|
const createWalletHandler = async () => {
|
||||||
setIsWalletCreating(true);
|
setIsWalletCreating(true);
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
||||||
const { mnemonic, ethAccounts, cosmosAccounts } = await createWallet();
|
const { mnemonic, ethAccounts, cosmosAccounts } = await createWallet();
|
||||||
ethAccounts &&
|
ethAccounts &&
|
||||||
cosmosAccounts &&
|
cosmosAccounts &&
|
||||||
|
1
types.ts
1
types.ts
@ -7,6 +7,7 @@ export type Account = {
|
|||||||
id: number;
|
id: number;
|
||||||
pubKey: string;
|
pubKey: string;
|
||||||
address: string;
|
address: string;
|
||||||
|
hdPath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WalletDetails = {
|
export type WalletDetails = {
|
||||||
|
16
utils.ts
16
utils.ts
@ -22,12 +22,8 @@ const createWallet = async (): Promise<WalletDetails> => {
|
|||||||
await setInternetCredentials('mnemonicServer', 'mnemonic', mnemonic);
|
await setInternetCredentials('mnemonicServer', 'mnemonic', mnemonic);
|
||||||
|
|
||||||
const hdNode = HDNode.fromMnemonic(mnemonic);
|
const hdNode = HDNode.fromMnemonic(mnemonic);
|
||||||
|
const ethNode = hdNode.derivePath("m/44'/60'/0'/0/0");
|
||||||
const ethDerivationPath = "m/44'/60'/0'/0/0";
|
const cosmosNode = hdNode.derivePath("m/44'/118'/0'/0/0");
|
||||||
const cosmosDerivationPath = "m/44'/118'/0'/0/0";
|
|
||||||
|
|
||||||
const ethNode = hdNode.derivePath(ethDerivationPath);
|
|
||||||
const cosmosNode = hdNode.derivePath(cosmosDerivationPath);
|
|
||||||
|
|
||||||
const ethAddress = ethNode.address;
|
const ethAddress = ethNode.address;
|
||||||
const cosmosAddress = (await getCosmosAccounts(mnemonic, 0)).data.address;
|
const cosmosAddress = (await getCosmosAccounts(mnemonic, 0)).data.address;
|
||||||
@ -50,12 +46,14 @@ const createWallet = async (): Promise<WalletDetails> => {
|
|||||||
id: 0,
|
id: 0,
|
||||||
pubKey: ethNode.publicKey,
|
pubKey: ethNode.publicKey,
|
||||||
address: ethAddress,
|
address: ethAddress,
|
||||||
|
hdPath: "m/44'/60'/0'/0/0",
|
||||||
};
|
};
|
||||||
|
|
||||||
const cosmosAccounts = {
|
const cosmosAccounts = {
|
||||||
id: 0,
|
id: 0,
|
||||||
pubKey: cosmosNode.publicKey,
|
pubKey: cosmosNode.publicKey,
|
||||||
address: cosmosAddress,
|
address: cosmosAddress,
|
||||||
|
hdPath: "m/44'/118'/0'/0/0",
|
||||||
};
|
};
|
||||||
|
|
||||||
return { mnemonic, ethAccounts, cosmosAccounts };
|
return { mnemonic, ethAccounts, cosmosAccounts };
|
||||||
@ -84,10 +82,10 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
|
|||||||
const ids = accountIds.split(',').map(Number);
|
const ids = accountIds.split(',').map(Number);
|
||||||
const id = ids[ids.length - 1] + 1;
|
const id = ids[ids.length - 1] + 1;
|
||||||
|
|
||||||
const derivationPath =
|
const hdPath =
|
||||||
network === 'eth' ? `m/44'/60'/0'/0/${id}` : `m/44'/118'/0'/0/${id}`;
|
network === 'eth' ? `m/44'/60'/0'/0/${id}` : `m/44'/118'/0'/0/${id}`;
|
||||||
|
|
||||||
const node = hdNode.derivePath(derivationPath);
|
const node = hdNode.derivePath(hdPath);
|
||||||
const privKey = node.privateKey;
|
const privKey = node.privateKey;
|
||||||
const pubKey = node.publicKey;
|
const pubKey = node.publicKey;
|
||||||
|
|
||||||
@ -126,7 +124,7 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
|
|||||||
indices,
|
indices,
|
||||||
);
|
);
|
||||||
|
|
||||||
return { id, pubKey, address };
|
return { pubKey, address, id, hdPath: hdPath };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating account:', error);
|
console.error('Error creating account:', error);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user