Skip to content

Commit

Permalink
CU-86dtu1h0f - Add new function to AbstractWalletConnectEIP155Adapter…
Browse files Browse the repository at this point in the history
… to get a custom signer
  • Loading branch information
raulduartep committed Jun 14, 2024
1 parent 3604461 commit 753e7a3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/wallet-connect-sdk-wallet-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -88,6 +98,10 @@ export abstract class AbstractWalletConnectEIP155Adapter {
return hash
}

async getCustomSigner(): Promise<TCustomSigner | undefined> {
return undefined
}

abstract getAccountString(args: TAdapterMethodParam): Promise<string>

abstract getRPCUrl(args: TAdapterMethodParam): Promise<string>
Expand Down

0 comments on commit 753e7a3

Please sign in to comment.