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