Skip to content

Commit

Permalink
Merge pull request #54 from etherspot/Signature_WC_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 authored Dec 19, 2024
2 parents 766709a + fb88a90 commit 7c3ea2b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## [4.0.1] - 2024-12-16
### fix
-`signMessage` on walletconnect now verifies as valid on react walletConnect testing app

## [4.0.0] - 2024-12-12
### Breaking Changes
Expand Down
82 changes: 82 additions & 0 deletions examples/basics/verify-signatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as dotenv from 'dotenv';
import { generateModularSDKInstance } from '../helpers/sdk-helper';
import { Address, createPublicClient, Hex, http } from 'viem';
import { sepolia } from 'viem/chains';

dotenv.config();

// tsx examples/basics/get-address.ts
async function main() {
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';

// initializating sdk...
const modularSdk = generateModularSDKInstance(
process.env.WALLET_PRIVATE_KEY as string,
Number(process.env.CHAIN_ID), bundlerApiKey);

// get EtherspotWallet address...
const address: string = await modularSdk.getCounterFactualAddress();
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);

const typedData = {
domain: {
name: 'EtherspotModular',
version: '1.0.0',
chainId: 11155111,
verifyingContract: `0x${address.slice(2)}` as Address,
},
types: {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person' },
{ name: 'contents', type: 'string' },
],
},
primaryType: 'Mail',
message: {
from: {
name: 'Cow',
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: 'Hello, Bob!',
},
}

const signTypedData = await modularSdk.signTypedData(typedData);
const sign = await modularSdk.signMessage({message: 'Hello'})

console.log('signature: ', sign, signTypedData);

const publicClient = createPublicClient({
chain: sepolia,
transport: http(`https://testnet-rpc.etherspot.io/v2/11155111?api-key=${bundlerApiKey}`),
})

console.log(await publicClient.verifyMessage({
address: address as Address,
signature: sign as Hex,
message: 'Hello'
}))

console.log(await publicClient.verifyTypedData({
address: address as Address,
domain: typedData.domain,
types: typedData.types,
primaryType: 'Mail',
message: typedData.message,
signature: signTypedData as Hex,
}))

}

main()
.catch(console.error)
.finally(() => process.exit());
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/modular-sdk",
"version": "4.0.0",
"version": "4.0.1",
"description": "Etherspot Modular SDK - build with ERC-7579 smart accounts modules",
"keywords": [
"ether",
Expand Down
6 changes: 5 additions & 1 deletion src/sdk/common/OperationUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { resolveProperties } from './utils';
import { BaseAccountUserOperationStruct } from '../types/user-operation-types';
import { toHex } from 'viem';
import { BigNumber } from '../types/bignumber';

export function toJSON(op: Partial<BaseAccountUserOperationStruct>): Promise<any> {
return resolveProperties(op).then((userOp) =>
Object.keys(userOp)
.map((key) => {
let val = (userOp as any)[key];
if (typeof val !== 'string' || !val.startsWith('0x')) {
if (typeof val === 'object' && BigNumber.isBigNumber(val)) {
val = val.toHexString()
}
else if (typeof val !== 'string' || !val.startsWith('0x')) {
val = toHex(val);
}
return [key, val];
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/wallet/providers/key.wallet-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hash, Hex, TransactionRequest, WalletClient, createWalletClient, http, concat, Address, encodeAbiParameters, parseAbiParameters } from 'viem';
import { Hash, Hex, TransactionRequest, WalletClient, createWalletClient, http, concat, Address, encodeAbiParameters, parseAbiParameters, hashMessage, toBytes } from 'viem';
import { MessagePayload, WalletProvider } from './interfaces';
import { privateKeyToAccount } from 'viem/accounts';
import { Networks } from '../../network/constants';
Expand All @@ -24,7 +24,7 @@ export class KeyWalletProvider implements WalletProvider {

async signMessage(message: string, validatorAddress?: Address, factoryAddress?: Address, initCode?: Hex): Promise<string> {
const signature = await this.wallet.signMessage({
message: message,
message: {raw: toBytes(hashMessage({raw : toBytes(message)}))},
account: this.wallet.account
})
if (initCode !== '0x') {
Expand Down

0 comments on commit 7c3ea2b

Please sign in to comment.