forked from cerc-io/laconic-wallet
Modify signMessage function
This commit is contained in:
parent
35d51f1c01
commit
63edfdd990
@ -23,6 +23,7 @@ const Accounts: React.FC<AccountsProps> = ({
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [isAccountCreating, setIsAccountCreating] = useState(false);
|
||||
const [hdDialog, setHdDialog] = useState(false);
|
||||
|
||||
const handlePress = () => setExpanded(!expanded);
|
||||
|
||||
const addAccountHandler = async () => {
|
||||
|
@ -21,6 +21,7 @@ const HDPath = ({
|
||||
setIsAccountCreating(true);
|
||||
const newAccount = await addAccountFromHDPath(path);
|
||||
setIsAccountCreating(false);
|
||||
|
||||
if (newAccount) {
|
||||
updateAccounts(newAccount);
|
||||
updateIndex(newAccount.counterId);
|
||||
|
15
utils.ts
15
utils.ts
@ -143,7 +143,7 @@ const addAccount = async (network: string): Promise<Account | undefined> => {
|
||||
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<string | undefined> => {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user