Skip to content

Commit 7c3ea2b

Browse files
authored
Merge pull request #54 from etherspot/Signature_WC_fix
2 parents 766709a + fb88a90 commit 7c3ea2b

6 files changed

Lines changed: 95 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## [4.0.1] - 2024-12-16
3+
### fix
4+
-`signMessage` on walletconnect now verifies as valid on react walletConnect testing app
25

36
## [4.0.0] - 2024-12-12
47
### Breaking Changes
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import * as dotenv from 'dotenv';
2+
import { generateModularSDKInstance } from '../helpers/sdk-helper';
3+
import { Address, createPublicClient, Hex, http } from 'viem';
4+
import { sepolia } from 'viem/chains';
5+
6+
dotenv.config();
7+
8+
// tsx examples/basics/get-address.ts
9+
async function main() {
10+
const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9';
11+
12+
// initializating sdk...
13+
const modularSdk = generateModularSDKInstance(
14+
process.env.WALLET_PRIVATE_KEY as string,
15+
Number(process.env.CHAIN_ID), bundlerApiKey);
16+
17+
// get EtherspotWallet address...
18+
const address: string = await modularSdk.getCounterFactualAddress();
19+
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);
20+
21+
const typedData = {
22+
domain: {
23+
name: 'EtherspotModular',
24+
version: '1.0.0',
25+
chainId: 11155111,
26+
verifyingContract: `0x${address.slice(2)}` as Address,
27+
},
28+
types: {
29+
Person: [
30+
{ name: 'name', type: 'string' },
31+
{ name: 'wallet', type: 'address' },
32+
],
33+
Mail: [
34+
{ name: 'from', type: 'Person' },
35+
{ name: 'to', type: 'Person' },
36+
{ name: 'contents', type: 'string' },
37+
],
38+
},
39+
primaryType: 'Mail',
40+
message: {
41+
from: {
42+
name: 'Cow',
43+
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
44+
},
45+
to: {
46+
name: 'Bob',
47+
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
48+
},
49+
contents: 'Hello, Bob!',
50+
},
51+
}
52+
53+
const signTypedData = await modularSdk.signTypedData(typedData);
54+
const sign = await modularSdk.signMessage({message: 'Hello'})
55+
56+
console.log('signature: ', sign, signTypedData);
57+
58+
const publicClient = createPublicClient({
59+
chain: sepolia,
60+
transport: http(`https://testnet-rpc.etherspot.io/v2/11155111?api-key=${bundlerApiKey}`),
61+
})
62+
63+
console.log(await publicClient.verifyMessage({
64+
address: address as Address,
65+
signature: sign as Hex,
66+
message: 'Hello'
67+
}))
68+
69+
console.log(await publicClient.verifyTypedData({
70+
address: address as Address,
71+
domain: typedData.domain,
72+
types: typedData.types,
73+
primaryType: 'Mail',
74+
message: typedData.message,
75+
signature: signTypedData as Hex,
76+
}))
77+
78+
}
79+
80+
main()
81+
.catch(console.error)
82+
.finally(() => process.exit());

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@etherspot/modular-sdk",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "Etherspot Modular SDK - build with ERC-7579 smart accounts modules",
55
"keywords": [
66
"ether",

src/sdk/common/OperationUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { resolveProperties } from './utils';
22
import { BaseAccountUserOperationStruct } from '../types/user-operation-types';
33
import { toHex } from 'viem';
4+
import { BigNumber } from '../types/bignumber';
45

56
export function toJSON(op: Partial<BaseAccountUserOperationStruct>): Promise<any> {
67
return resolveProperties(op).then((userOp) =>
78
Object.keys(userOp)
89
.map((key) => {
910
let val = (userOp as any)[key];
10-
if (typeof val !== 'string' || !val.startsWith('0x')) {
11+
if (typeof val === 'object' && BigNumber.isBigNumber(val)) {
12+
val = val.toHexString()
13+
}
14+
else if (typeof val !== 'string' || !val.startsWith('0x')) {
1115
val = toHex(val);
1216
}
1317
return [key, val];

src/sdk/wallet/providers/key.wallet-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Hash, Hex, TransactionRequest, WalletClient, createWalletClient, http, concat, Address, encodeAbiParameters, parseAbiParameters } from 'viem';
1+
import { Hash, Hex, TransactionRequest, WalletClient, createWalletClient, http, concat, Address, encodeAbiParameters, parseAbiParameters, hashMessage, toBytes } from 'viem';
22
import { MessagePayload, WalletProvider } from './interfaces';
33
import { privateKeyToAccount } from 'viem/accounts';
44
import { Networks } from '../../network/constants';
@@ -24,7 +24,7 @@ export class KeyWalletProvider implements WalletProvider {
2424

2525
async signMessage(message: string, validatorAddress?: Address, factoryAddress?: Address, initCode?: Hex): Promise<string> {
2626
const signature = await this.wallet.signMessage({
27-
message: message,
27+
message: {raw: toBytes(hashMessage({raw : toBytes(message)}))},
2828
account: this.wallet.account
2929
})
3030
if (initCode !== '0x') {

0 commit comments

Comments
 (0)