forked from cerc-io/laconic-wallet
Resolve errors due to rebasing
This commit is contained in:
parent
68eec9cc1a
commit
f2727315bd
@ -29,7 +29,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
setIsAccountCreating(false);
|
||||
if (newAccount) {
|
||||
updateAccounts(newAccount);
|
||||
updateId(newAccount.id);
|
||||
updateId(newAccount.counterId);
|
||||
}
|
||||
};
|
||||
|
||||
@ -47,10 +47,10 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
const renderAccountItems = () =>
|
||||
selectedAccounts.map(account => (
|
||||
<List.Item
|
||||
key={account.id}
|
||||
title={`Account ${account.id + 1}`}
|
||||
key={account.counterId}
|
||||
title={`Account ${account.counterId + 1}`}
|
||||
onPress={() => {
|
||||
updateId(account.id);
|
||||
updateId(account.counterId);
|
||||
setExpanded(false);
|
||||
}}
|
||||
/>
|
||||
|
@ -5,7 +5,7 @@ import { Button, Text, TextInput } from 'react-native-paper';
|
||||
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
||||
|
||||
import { StackParamsList } from '../types';
|
||||
import { accountFromHDPath } from '../utils';
|
||||
import { addAccountFromHDPath } from '../utils';
|
||||
|
||||
type HDPathProps = NativeStackScreenProps<StackParamsList, 'HDPath'>;
|
||||
|
||||
@ -16,7 +16,7 @@ const HDPath: React.FC<HDPathProps> = ({}) => {
|
||||
|
||||
const createFromHDPathHandler = async () => {
|
||||
setIsAccountCreating(true);
|
||||
const newAccount = await accountFromHDPath(path);
|
||||
const newAccount = await addAccountFromHDPath(path);
|
||||
setIsAccountCreating(false);
|
||||
setAccount(newAccount);
|
||||
Alert.alert('Account Created');
|
||||
|
@ -24,7 +24,7 @@ const SignMessage = ({ route }: SignProps) => {
|
||||
const signedMessage = await signMessage({
|
||||
message,
|
||||
network,
|
||||
accountId: account.id,
|
||||
accountId: account.counterId,
|
||||
});
|
||||
Alert.alert('Signature', signedMessage);
|
||||
}
|
||||
@ -35,7 +35,7 @@ const SignMessage = ({ route }: SignProps) => {
|
||||
<View style={styles.accountInfo}>
|
||||
<View>
|
||||
<Text variant="headlineSmall">
|
||||
{account && `Account ${account.id + 1}`}
|
||||
{account && `Account ${account.counterId + 1}`}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={styles.accountContainer}>
|
||||
|
4
types.ts
4
types.ts
@ -5,7 +5,7 @@ export type StackParamsList = {
|
||||
};
|
||||
|
||||
export type Account = {
|
||||
id: number;
|
||||
counterId: number;
|
||||
pubKey: string;
|
||||
address: string;
|
||||
hdPath: string;
|
||||
@ -41,7 +41,7 @@ export type AccountsState = {
|
||||
export type SignMessageParams = {
|
||||
message: string;
|
||||
network: string;
|
||||
accountId: string;
|
||||
accountId: number;
|
||||
};
|
||||
|
||||
export type CreateWalletProps = {
|
||||
|
62
utils.ts
62
utils.ts
@ -26,7 +26,7 @@ const createWallet = async (): Promise<WalletDetails> => {
|
||||
const cosmosNode = hdNode.derivePath("m/44'/118'/0'/0/0");
|
||||
|
||||
const ethAddress = ethNode.address;
|
||||
const cosmosAddress = (await getCosmosAccounts(mnemonic, `/0'/0/0`)).data
|
||||
const cosmosAddress = (await getCosmosAccounts(mnemonic, `0'/0/0`)).data
|
||||
.address;
|
||||
|
||||
const ethAccountInfo = `${0},${ethNode.privateKey}`;
|
||||
@ -34,30 +34,30 @@ const createWallet = async (): Promise<WalletDetails> => {
|
||||
|
||||
await setInternetCredentials(
|
||||
'eth:keyServer:0',
|
||||
'eth:keyPath:0',
|
||||
'eth:pathKey:0',
|
||||
ethAccountInfo,
|
||||
);
|
||||
await setInternetCredentials(
|
||||
'cosmos:keyServer:0',
|
||||
'cosmos:keyPath:0',
|
||||
'cosmos:pathKey:0',
|
||||
cosmosAccountInfo,
|
||||
);
|
||||
|
||||
await setInternetCredentials('eth:accountIndices', 'ethAccount', '0');
|
||||
await setInternetCredentials('cosmos:accountIndices', 'cosmosAccount', '0');
|
||||
await setInternetCredentials('eth:accountIndices', 'ethCounter', '0');
|
||||
await setInternetCredentials('cosmos:accountIndices', 'cosmosCounter', '0');
|
||||
|
||||
await setInternetCredentials('eth:globalCounter', 'ethCounter', '0');
|
||||
await setInternetCredentials('cosmos:globalCounter', 'cosmosCounter', '0');
|
||||
await setInternetCredentials('eth:globalCounter', 'ethGlobal', '0');
|
||||
await setInternetCredentials('cosmos:globalCounter', 'cosmosGlobal', '0');
|
||||
|
||||
const ethAccounts = {
|
||||
id: 0,
|
||||
counterId: 0,
|
||||
pubKey: ethNode.publicKey,
|
||||
address: ethAddress,
|
||||
hdPath: "m/44'/60'/0'/0/0",
|
||||
};
|
||||
|
||||
const cosmosAccounts = {
|
||||
id: 0,
|
||||
counterId: 0,
|
||||
pubKey: cosmosNode.publicKey,
|
||||
address: cosmosAddress,
|
||||
hdPath: "m/44'/118'/0'/0/0",
|
||||
@ -116,7 +116,7 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
|
||||
await resetInternetCredentials(`${network}:accountIndices`);
|
||||
await setInternetCredentials(
|
||||
`${network}:accountIndices`,
|
||||
`${network}Account`,
|
||||
`${network}Counter`,
|
||||
indices,
|
||||
);
|
||||
|
||||
@ -136,14 +136,14 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
|
||||
|
||||
await setInternetCredentials(
|
||||
`${network}:globalCounter`,
|
||||
`${network}Counter`,
|
||||
`${network}Global`,
|
||||
accountCounter,
|
||||
);
|
||||
|
||||
await setInternetCredentials(
|
||||
`${network}:keyServer:${counterId}`,
|
||||
`${network}:key:${counterId}`,
|
||||
`${id}${privKey}`,
|
||||
`${network}:pathKey:${counterId}`,
|
||||
`0'/0/${id}${privKey}`,
|
||||
);
|
||||
|
||||
return { counterId, pubKey, address, hdPath };
|
||||
@ -184,7 +184,7 @@ const addAccountFromHDPath = async (
|
||||
|
||||
await setInternetCredentials(
|
||||
`${network}:globalCounter`,
|
||||
`${network}Counter`,
|
||||
`${network}Global`,
|
||||
accountCounter,
|
||||
);
|
||||
|
||||
@ -194,19 +194,21 @@ const addAccountFromHDPath = async (
|
||||
case "60'":
|
||||
await setInternetCredentials(
|
||||
`eth:keyServer:${counterId}`,
|
||||
`eth:key:${counterId}`,
|
||||
`eth:pathKey:${counterId}`,
|
||||
accountInfo,
|
||||
);
|
||||
break;
|
||||
case "118'":
|
||||
await setInternetCredentials(
|
||||
`cosmos:keyServer${counterId}`,
|
||||
`cosmos:key:${counterId}`,
|
||||
`cosmos:pathKey:${counterId}`,
|
||||
accountInfo,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(pubKey, address);
|
||||
|
||||
return { pubKey, address };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -259,11 +261,23 @@ const signMessage = async ({
|
||||
network,
|
||||
accountId,
|
||||
}: SignMessageParams): Promise<string | undefined> => {
|
||||
const pathKeyStore = await getInternetCredentials(
|
||||
`${network}:keyServer:${accountId}`,
|
||||
);
|
||||
|
||||
if (!pathKeyStore) {
|
||||
throw new Error('Error while fetching counter');
|
||||
}
|
||||
|
||||
const pathKeyVal = pathKeyStore.password;
|
||||
const pathkey = pathKeyVal.split(',');
|
||||
const hdPath = pathkey[pathkey.length - 1];
|
||||
|
||||
switch (network) {
|
||||
case 'eth':
|
||||
return await signEthMessage(message, accountId);
|
||||
return await signEthMessage(message, hdPath);
|
||||
case 'cosmos':
|
||||
return await signCosmosMessage(message, accountId);
|
||||
return await signCosmosMessage(message, hdPath);
|
||||
default:
|
||||
throw new Error('Invalid wallet type');
|
||||
}
|
||||
@ -271,10 +285,10 @@ const signMessage = async ({
|
||||
|
||||
const signEthMessage = async (
|
||||
message: string,
|
||||
id: string,
|
||||
hdPath: string,
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
const keyCred = await getInternetCredentials(`eth:keyServer:${id}`);
|
||||
const keyCred = await getInternetCredentials(`eth:keyServer:${hdPath}`);
|
||||
|
||||
if (!keyCred) {
|
||||
throw new Error('Failed to retrieve internet credentials');
|
||||
@ -292,7 +306,7 @@ const signEthMessage = async (
|
||||
|
||||
const signCosmosMessage = async (
|
||||
message: string,
|
||||
id: string,
|
||||
hdPath: string,
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
const mnemonicStore = await getInternetCredentials('mnemonicServer');
|
||||
@ -302,7 +316,7 @@ const signCosmosMessage = async (
|
||||
}
|
||||
|
||||
const mnemonic = mnemonicStore.password;
|
||||
const cosmosAccount = await getCosmosAccounts(mnemonic, id);
|
||||
const cosmosAccount = await getCosmosAccounts(mnemonic, hdPath);
|
||||
const cosmosSignature = await cosmosAccount.cosmosWallet.signAmino(
|
||||
cosmosAccount.data.address,
|
||||
{
|
||||
@ -335,10 +349,10 @@ const signCosmosMessage = async (
|
||||
|
||||
const getCosmosAccounts = async (
|
||||
mnemonic: string,
|
||||
id: string,
|
||||
hdPath: string,
|
||||
): Promise<{ cosmosWallet: Secp256k1HdWallet; data: AccountData }> => {
|
||||
const cosmosWallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, {
|
||||
hdPaths: [stringToPath(`m/44'/118'/${id}`)],
|
||||
hdPaths: [stringToPath(`m/44'/118'/${hdPath}`)],
|
||||
});
|
||||
|
||||
const accountsData = await cosmosWallet.getAccounts();
|
||||
|
Loading…
Reference in New Issue
Block a user