Skip to content

Commit

Permalink
ft adding implementation for wallet connect
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilkumar1612 committed Dec 22, 2024
1 parent 2046453 commit b6ccbf0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/sdk/wallet/providers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface WalletConnectConnector {
accounts: string[];
chainId: number;
signPersonalMessage(params: any[]): Promise<any>;
request<T = unknown>(args: RequestArguments): Promise<T>;
on(event: string, callback: (error: Error | null, payload: any | null) => void): void;
}

Expand Down
25 changes: 22 additions & 3 deletions src/sdk/wallet/providers/wallet-connect.wallet-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BytesLike } from 'ethers';
import { BytesLike, utils } from 'ethers';
import { toHex } from '../../common';
import { DynamicWalletProvider } from './dynamic.wallet-provider';
import { MessagePayload, WalletConnectConnector } from './interfaces';
Expand Down Expand Up @@ -42,9 +42,28 @@ export class WalletConnectWalletProvider extends DynamicWalletProvider {
return response || null;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async signTypedData(typedData: MessagePayload, message: any, factoryAddress?: string, initCode?: string): Promise<string> {
throw new Error('Not supported on this provider')
const signature: string = await this.connector.request({
method: 'eth_signTypedData_v4',
params: [
this.address,
{
domain: typedData.domain,
message,
primaryType: typedData.primaryType,
types: typedData.types,
}
]
});

if (initCode !== '0x') {
const abiCoderResult = utils.defaultAbiCoder.encode(
['address', 'bytes', 'bytes'],
[factoryAddress, initCode, signature]
);
return abiCoderResult + '6492649264926492649264926492649264926492649264926492649264926492'; //magicBytes
}
return signature;
}

protected updateSessionHandler(error: Error, payload: { params: { accounts: string[]; chainId: number } }): void {
Expand Down

0 comments on commit b6ccbf0

Please sign in to comment.