Skip to content

Commit

Permalink
Merge pull request #658 from liquality/fix/personal_sign
Browse files Browse the repository at this point in the history
fix: implemented sign message for personal sign
  • Loading branch information
bradleySuira authored Aug 25, 2023
2 parents cd30f4a + 7cc8d07 commit 1eed160
Show file tree
Hide file tree
Showing 3 changed files with 4,023 additions and 3,290 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-singers-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainify/evm': major
---

Fix for personal sign
11 changes: 9 additions & 2 deletions packages/evm/lib/wallet/EvmWalletProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Chain } from '@chainify/client';
import { Address, NamingProvider, Network, WalletOptions } from '@chainify/types';
import { Address, AddressType, NamingProvider, Network, WalletOptions } from '@chainify/types';
import { compare, remove0x } from '@chainify/utils';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { Wallet as EthersWallet } from '@ethersproject/wallet';
import { signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
import { SignTypedMessageType } from '../types';
import { EvmBaseWalletProvider } from './EvmBaseWalletProvider';

import { personalSign } from '@metamask/eth-sig-util';
export class EvmWalletProvider extends EvmBaseWalletProvider<StaticJsonRpcProvider, EthersWallet> {
private _wallet: EthersWallet;
private _walletOptions: WalletOptions;
Expand Down Expand Up @@ -34,6 +34,13 @@ export class EvmWalletProvider extends EvmBaseWalletProvider<StaticJsonRpcProvid
});
}

public async signMessage(message: string, _from: AddressType): Promise<string> {
const { privateKey } = this._wallet._signingKey();
const _pk = privateKey.startsWith('0x') ? privateKey.substring(2) : privateKey;
return personalSign({ privateKey: Buffer.from(_pk, 'hex',), data: message });
}


public async signTypedData({ data, from, version }: SignTypedMessageType): Promise<string> {
if (!data) {
throw new Error(`Undefined data - message required to sign typed data.`);
Expand Down
Loading

0 comments on commit 1eed160

Please sign in to comment.