From 753e7a3cd9dcc89d80f6b1685fa7477eca486ec1 Mon Sep 17 00:00:00 2001 From: Raul Duarte Pereira Date: Thu, 13 Jun 2024 23:05:59 -0300 Subject: [PATCH] CU-86dtu1h0f - Add new function to AbstractWalletConnectEIP155Adapter to get a custom signer --- .../main_2024-06-14-02-03.json | 10 ++++++++++ common/config/rush/pnpm-lock.yaml | 3 +++ .../package.json | 3 ++- .../AbstractWalletConnectEIP155Adapter.ts | 20 ++++++++++++++++--- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 common/changes/@cityofzion/wallet-connect-sdk-wallet-core/main_2024-06-14-02-03.json diff --git a/common/changes/@cityofzion/wallet-connect-sdk-wallet-core/main_2024-06-14-02-03.json b/common/changes/@cityofzion/wallet-connect-sdk-wallet-core/main_2024-06-14-02-03.json new file mode 100644 index 0000000..f3304b0 --- /dev/null +++ b/common/changes/@cityofzion/wallet-connect-sdk-wallet-core/main_2024-06-14-02-03.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/wallet-connect-sdk-wallet-core", + "comment": "Add getCustomSigner function to AbstractWalletConnectEIP155Adapter ", + "type": "minor" + } + ], + "packageName": "@cityofzion/wallet-connect-sdk-wallet-core" +} \ No newline at end of file diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 36c99fc..b7f1fb0 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -163,6 +163,9 @@ importers: '@cityofzion/wallet-connect-sdk-core': specifier: workspace:* version: link:../wallet-connect-sdk-core + '@ethersproject/abstract-signer': + specifier: ~5.7.0 + version: 5.7.0 '@walletconnect/core': specifier: ^2.13.1 version: 2.13.1 diff --git a/packages/wallet-connect-sdk-wallet-core/package.json b/packages/wallet-connect-sdk-wallet-core/package.json index 02f8333..c4fda27 100644 --- a/packages/wallet-connect-sdk-wallet-core/package.json +++ b/packages/wallet-connect-sdk-wallet-core/package.json @@ -40,7 +40,8 @@ "@walletconnect/web3wallet": "^1.12.1", "moment": "^2.29.4", "@cityofzion/neon-dappkit": "0.4.2", - "ethers": "5.7.2" + "ethers": "5.7.2", + "@ethersproject/abstract-signer": "~5.7.0" }, "devDependencies": { "@types/node": "^20.1.3", diff --git a/packages/wallet-connect-sdk-wallet-core/src/adapters/AbstractWalletConnectEIP155Adapter.ts b/packages/wallet-connect-sdk-wallet-core/src/adapters/AbstractWalletConnectEIP155Adapter.ts index 5934303..25718c9 100644 --- a/packages/wallet-connect-sdk-wallet-core/src/adapters/AbstractWalletConnectEIP155Adapter.ts +++ b/packages/wallet-connect-sdk-wallet-core/src/adapters/AbstractWalletConnectEIP155Adapter.ts @@ -1,14 +1,24 @@ +import { TypedDataSigner } from '@ethersproject/abstract-signer' import { TAdapterMethodParam } from '../types' import { ethers } from 'ethers' +export type TCustomSigner = ethers.Signer & TypedDataSigner + /* Some methods are named in snakecase, as Ethereum methods are in snakecase and the SDK does not make any transformer for the method called by the dapp. */ export abstract class AbstractWalletConnectEIP155Adapter { protected async getServices(args: TAdapterMethodParam) { const rpcAddress = await this.getRPCUrl(args) - const accountString = await this.getAccountString(args) - const provider = new ethers.providers.JsonRpcProvider(rpcAddress) - const wallet = new ethers.Wallet(accountString) + let wallet: TCustomSigner + + const customSigner = await this.getCustomSigner() + if (customSigner) { + wallet = customSigner + } else { + const accountString = await this.getAccountString(args) + wallet = new ethers.Wallet(accountString) + } + return { wallet, provider, @@ -88,6 +98,10 @@ export abstract class AbstractWalletConnectEIP155Adapter { return hash } + async getCustomSigner(): Promise { + return undefined + } + abstract getAccountString(args: TAdapterMethodParam): Promise abstract getRPCUrl(args: TAdapterMethodParam): Promise