From 63edfdd9900cc9990d6bc8f0d093e6ec632992fb Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Tue, 20 Feb 2024 18:55:00 +0530 Subject: [PATCH] Modify signMessage function --- components/Accounts.tsx | 1 + components/HDPath.tsx | 1 + utils.ts | 15 +++++++++------ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/components/Accounts.tsx b/components/Accounts.tsx index 6850299..4d05944 100644 --- a/components/Accounts.tsx +++ b/components/Accounts.tsx @@ -23,6 +23,7 @@ const Accounts: React.FC = ({ const [expanded, setExpanded] = useState(false); const [isAccountCreating, setIsAccountCreating] = useState(false); const [hdDialog, setHdDialog] = useState(false); + const handlePress = () => setExpanded(!expanded); const addAccountHandler = async () => { diff --git a/components/HDPath.tsx b/components/HDPath.tsx index a5d86cc..f3cb123 100644 --- a/components/HDPath.tsx +++ b/components/HDPath.tsx @@ -21,6 +21,7 @@ const HDPath = ({ setIsAccountCreating(true); const newAccount = await addAccountFromHDPath(path); setIsAccountCreating(false); + if (newAccount) { updateAccounts(newAccount); updateIndex(newAccount.counterId); diff --git a/utils.ts b/utils.ts index 4a28585..516cb01 100644 --- a/utils.ts +++ b/utils.ts @@ -143,7 +143,7 @@ const addAccount = async (network: string): Promise => { await setInternetCredentials( `${network}:keyServer:${counterId}`, `${network}:pathKey:${counterId}`, - `0'/0/${id}${privKey}`, + `0'/0/${id},${privKey}`, ); return { counterId, pubKey, address, hdPath }; @@ -271,11 +271,11 @@ const signMessage = async ({ const pathKeyVal = pathKeyStore.password; const pathkey = pathKeyVal.split(','); - const hdPath = pathkey[pathkey.length - 1]; + const hdPath = pathkey[0]; switch (network) { case 'eth': - return await signEthMessage(message, hdPath); + return await signEthMessage(message, accountId); case 'cosmos': return await signCosmosMessage(message, hdPath); default: @@ -285,16 +285,19 @@ const signMessage = async ({ const signEthMessage = async ( message: string, - hdPath: string, + accountId: number, ): Promise => { try { - const keyCred = await getInternetCredentials(`eth:keyServer:${hdPath}`); + const keyCred = await getInternetCredentials(`eth:keyServer:${accountId}`); if (!keyCred) { 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); return signature;