Modify signMessage function

This commit is contained in:
IshaVenikar 2024-02-20 18:55:00 +05:30
parent 35d51f1c01
commit 63edfdd990
3 changed files with 11 additions and 6 deletions

View File

@ -23,6 +23,7 @@ const Accounts: React.FC<AccountsProps> = ({
const [expanded, setExpanded] = useState(false); const [expanded, setExpanded] = useState(false);
const [isAccountCreating, setIsAccountCreating] = useState(false); const [isAccountCreating, setIsAccountCreating] = useState(false);
const [hdDialog, setHdDialog] = useState(false); const [hdDialog, setHdDialog] = useState(false);
const handlePress = () => setExpanded(!expanded); const handlePress = () => setExpanded(!expanded);
const addAccountHandler = async () => { const addAccountHandler = async () => {

View File

@ -21,6 +21,7 @@ const HDPath = ({
setIsAccountCreating(true); setIsAccountCreating(true);
const newAccount = await addAccountFromHDPath(path); const newAccount = await addAccountFromHDPath(path);
setIsAccountCreating(false); setIsAccountCreating(false);
if (newAccount) { if (newAccount) {
updateAccounts(newAccount); updateAccounts(newAccount);
updateIndex(newAccount.counterId); updateIndex(newAccount.counterId);

View File

@ -143,7 +143,7 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
await setInternetCredentials( await setInternetCredentials(
`${network}:keyServer:${counterId}`, `${network}:keyServer:${counterId}`,
`${network}:pathKey:${counterId}`, `${network}:pathKey:${counterId}`,
`0'/0/${id}${privKey}`, `0'/0/${id},${privKey}`,
); );
return { counterId, pubKey, address, hdPath }; return { counterId, pubKey, address, hdPath };
@ -271,11 +271,11 @@ const signMessage = async ({
const pathKeyVal = pathKeyStore.password; const pathKeyVal = pathKeyStore.password;
const pathkey = pathKeyVal.split(','); const pathkey = pathKeyVal.split(',');
const hdPath = pathkey[pathkey.length - 1]; const hdPath = pathkey[0];
switch (network) { switch (network) {
case 'eth': case 'eth':
return await signEthMessage(message, hdPath); return await signEthMessage(message, accountId);
case 'cosmos': case 'cosmos':
return await signCosmosMessage(message, hdPath); return await signCosmosMessage(message, hdPath);
default: default:
@ -285,16 +285,19 @@ const signMessage = async ({
const signEthMessage = async ( const signEthMessage = async (
message: string, message: string,
hdPath: string, accountId: number,
): Promise<string | undefined> => { ): Promise<string | undefined> => {
try { try {
const keyCred = await getInternetCredentials(`eth:keyServer:${hdPath}`); const keyCred = await getInternetCredentials(`eth:keyServer:${accountId}`);
if (!keyCred) { if (!keyCred) {
throw new Error('Failed to retrieve internet credentials'); throw new Error('Failed to retrieve internet credentials');
} }
const wallet = new Wallet(keyCred.password); const pathKey = keyCred.password;
const privKeyVal = pathKey.split(',');
const privKey = privKeyVal[privKeyVal.length - 1];
const wallet = new Wallet(privKey);
const signature = await wallet.signMessage(message); const signature = await wallet.signMessage(message);
return signature; return signature;