diff --git a/CHANGELOG.md b/CHANGELOG.md index 68ebb2a..0158389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/basics/verify-signatures.ts b/examples/basics/verify-signatures.ts new file mode 100644 index 0000000..15c7507 --- /dev/null +++ b/examples/basics/verify-signatures.ts @@ -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()); diff --git a/package-lock.json b/package-lock.json index 1a0b787..9f8a08c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/modular-sdk", - "version": "4.0.0", + "version": "4.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/modular-sdk", - "version": "4.0.0", + "version": "4.0.1", "license": "MIT", "dependencies": { "@lifi/sdk": "2.5.0", diff --git a/package.json b/package.json index 5f78a34..aaa0195 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/sdk/common/OperationUtils.ts b/src/sdk/common/OperationUtils.ts index 3d66364..e6b87a1 100644 --- a/src/sdk/common/OperationUtils.ts +++ b/src/sdk/common/OperationUtils.ts @@ -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): Promise { 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]; diff --git a/src/sdk/wallet/providers/key.wallet-provider.ts b/src/sdk/wallet/providers/key.wallet-provider.ts index 351b5aa..3f14cbc 100644 --- a/src/sdk/wallet/providers/key.wallet-provider.ts +++ b/src/sdk/wallet/providers/key.wallet-provider.ts @@ -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'; @@ -24,7 +24,7 @@ export class KeyWalletProvider implements WalletProvider { async signMessage(message: string, validatorAddress?: Address, factoryAddress?: Address, initCode?: Hex): Promise { const signature = await this.wallet.signMessage({ - message: message, + message: {raw: toBytes(hashMessage({raw : toBytes(message)}))}, account: this.wallet.account }) if (initCode !== '0x') {