Skip to content

Commit 1fc3045

Browse files
authored
v1.1.4 (#15)
* Refacto signing (#13) * fix: sendBatchTransactions * feat: verifyMessage * clean: package.json * update: refacto isSupportedNetwork * fix: readMe verify message
1 parent e4a56f3 commit 1fc3045

18 files changed

+193
-84
lines changed

.eslintrc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66
"no-loops",
77
"prettier",
88
"import",
9-
"simple-import-sort",
10-
"jest"
9+
"simple-import-sort"
1110
],
1211
"extends": [
1312
"eslint:recommended",
1413
"plugin:@typescript-eslint/eslint-recommended",
1514
"plugin:@typescript-eslint/recommended",
1615
"prettier",
1716
"plugin:import/recommended",
18-
"plugin:import/typescript",
19-
"plugin:jest/recommended"
17+
"plugin:import/typescript"
2018
],
2119
"rules": {
2220
"no-console": 1,
2321
"no-loops/no-loops": 0,
24-
"jest/expect-expect": 0,
2522
"import/no-named-as-default-member": 0,
2623
"prettier/prettier": 1,
2724
"simple-import-sort/imports": "error",

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const txBatch = [
105105
{ to: DESTINATION, value: VALUE, data: txCallData },
106106
{ to: DESTINATION, value: VALUE, data: txCallData }
107107
]
108-
const txHash = await connectViemClient.sendTransaction(tx)
108+
const txHash = await connectViemClient.sendBatchTransactions(tx)
109109
```
110110

111111
This function relays a batch of transaction data to the targeted addresses. The transaction fees can be sponsored as well.
@@ -146,6 +146,18 @@ const signature = await connectViemAccount.signMessage({ message: 'hello' })
146146

147147
Sign the given message using the EOA, owner of the smart wallet.
148148

149+
### Verify Message
150+
151+
```javascript
152+
const signature = await connectViemAccount.verifyMessage({
153+
message: 'hello',
154+
address,
155+
signature
156+
})
157+
```
158+
159+
Verify the given signature and message signed by the the smart wallet.
160+
149161
### Sign Transaction
150162

151163
```javascript

jest.config.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cometh/connect-sdk-viem",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Viem SDK Cometh Connect",
@@ -19,7 +19,6 @@
1919
"build": "rimraf dist && yarn build:ts",
2020
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
2121
"lint": "eslint . --ext .ts",
22-
"test": "jest",
2322
"prepare": "husky install"
2423
},
2524
"repository": {
@@ -35,33 +34,28 @@
3534
"devDependencies": {
3635
"@rollup/plugin-typescript": "^11.1.0",
3736
"@tsconfig/recommended": "^1.0.2",
38-
"@types/jest": "^29.4.0",
3937
"@typescript-eslint/eslint-plugin": "^5.53.0",
4038
"@typescript-eslint/parser": "^5.53.0",
4139
"eslint": "^8.34.0",
4240
"eslint-config-prettier": "^8.0.0",
4341
"eslint-config-standard": "^17.0.0",
4442
"eslint-import-resolver-typescript": "^3.5.2",
4543
"eslint-plugin-import": "^2.26.0",
46-
"eslint-plugin-jest": "^27.1.6",
47-
"eslint-plugin-mocha": "^10.1.0",
4844
"eslint-plugin-no-loops": "^0.3.0",
4945
"eslint-plugin-prettier": "^4.2.1",
5046
"eslint-plugin-promise": "^6.1.1",
5147
"eslint-plugin-simple-import-sort": "^10.0.0",
5248
"husky": "^8.0.3",
53-
"jest": "^29.2.2",
5449
"prettier": "2.8.4",
5550
"rollup": "^3.21.3",
56-
"ts-jest": "^29.0.3",
5751
"ts-loader": "^9.4.2",
5852
"typescript": "^5.1.3",
5953
"webpack": "^5.81.0",
6054
"webpack-cli": "^5.0.2"
6155
},
6256
"dependencies": {
6357
"@babel/traverse": "^7.23.4",
64-
"@cometh/connect-sdk": "^1.2.8",
58+
"@cometh/connect-sdk": "^1.2.10",
6559
"@rainbow-me/rainbowkit": "^1.3.0",
6660
"@types/babel__core": "^7.20.0",
6761
"viem": "^1.16.2",

src/account/getConnectViemAccount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const getConnectViemAccount = (
2121
message: SignableMessage
2222
}): Promise<Hash> {
2323
const signedMessage = await wallet.signMessage(message.toString())
24-
return `0x${signedMessage}`
24+
return signedMessage as `0x${string}`
2525
},
2626
/* eslint-disable */
2727
/* @ts-ignore */

src/client/getConnectViemClient.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import {
1919
polygonZkEvmTestnet
2020
} from 'viem/chains'
2121

22-
import { connectWalletActions } from '../customActions'
23-
import { ComethAccountActions } from '../customActions/connectWalletActions'
24-
import { musterTestnet, redstoneHolesky } from '../customChains'
22+
import { ComethAccountActions, connectWalletActions } from '../customActions'
23+
import { muster, musterTestnet, redstoneHolesky } from '../customChains'
2524

2625
const supportedChains = [
2726
polygon,
@@ -33,6 +32,7 @@ const supportedChains = [
3332
polygonZkEvm,
3433
polygonZkEvmTestnet,
3534
musterTestnet,
35+
muster,
3636
redstoneHolesky
3737
]
3838

@@ -52,11 +52,13 @@ export type ConnectClient<
5252

5353
export type ConnectClientParams = {
5454
wallet: ComethWallet
55+
apiKey: string
5556
rpc?: string
5657
}
5758

5859
export const getConnectViemClient = ({
5960
wallet,
61+
apiKey,
6062
rpc
6163
}: ConnectClientParams): ConnectClient => {
6264
const chain = supportedChains.find(
@@ -66,5 +68,5 @@ export const getConnectViemClient = ({
6668
return createPublicClient({
6769
chain,
6870
transport: http(rpc)
69-
}).extend(connectWalletActions(wallet))
71+
}).extend(connectWalletActions(wallet, apiKey))
7072
}

src/customActions/connectWalletActions.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import {
1111
} from 'viem'
1212

1313
import { getTransaction } from './getTransaction'
14+
import { sendBatchTransactions, sendBatchTransactionsWithConnectParameters } from './sendBatchTransactions'
1415
import {
1516
sendTransaction,
1617
SendTransactionWithConnectParameters
1718
} from './sendTransaction'
18-
import { sendTransactions, SendTransactionsWithConnectParameters } from './sendTransactions'
19-
import { signMessage, SignMessageReturnType, SignMessageWithConnectParameters } from './signMessage'
19+
import { signMessage, SignMessageWithConnectParameters } from './signMessage'
2020
import { simulateContract, SimulateContractWithConnectParameters } from './simulateContract'
21+
import { verifyMessage, VerifyMessageWithConnectParameters } from './verifyMessage'
2122
import {
2223
writeContract,
2324
WriteContractWithConnectParameters
@@ -193,14 +194,18 @@ export type ComethAccountActions<
193194
* value: 10000000000000000n
194195
* }])
195196
*/
196-
sendTransactions: (
197-
args: SendTransactionsWithConnectParameters<TSmartAccount>
198-
) => ReturnType<typeof sendTransactions<TChain, TSmartAccount>>,
197+
sendBatchTransactions: (
198+
args: sendBatchTransactionsWithConnectParameters
199+
) => ReturnType<typeof sendBatchTransactions<TChain, TSmartAccount>>,
199200

200201
signMessage: (
201202
args: SignMessageWithConnectParameters<TSmartAccount>
202203
) => ReturnType<typeof signMessage>,
203204

205+
verifyMessage: (
206+
args: VerifyMessageWithConnectParameters
207+
) => ReturnType<typeof verifyMessage>,
208+
204209
simulateContract: <
205210
TChain extends Chain | undefined,
206211
const TAbi extends Abi | readonly unknown[],
@@ -221,7 +226,7 @@ export type ComethAccountActions<
221226

222227

223228
export const connectWalletActions =
224-
(wallet: ComethWallet) =>
229+
(wallet: ComethWallet, apiKey: string) =>
225230
<
226231
TTransport extends Transport,
227232
TChain extends Chain | undefined = Chain | undefined,
@@ -234,11 +239,11 @@ export const connectWalletActions =
234239
...args,
235240
wallet
236241
} as SendTransactionWithConnectParameters),
237-
sendTransactions: (args) =>
238-
sendTransactions(client, {
242+
sendBatchTransactions: (args) =>
243+
sendBatchTransactions(client, {
239244
...args,
240245
wallet
241-
} as SendTransactionsWithConnectParameters),
246+
} as sendBatchTransactionsWithConnectParameters),
242247
writeContract: (args) =>
243248
writeContract(client, {
244249
...args,
@@ -249,11 +254,16 @@ export const connectWalletActions =
249254
...args,
250255
wallet
251256
} as SignMessageWithConnectParameters),
257+
verifyMessage: (args) =>
258+
verifyMessage(client, {
259+
...args,
260+
apiKey
261+
} as VerifyMessageWithConnectParameters),
252262
simulateContract: (args) =>
253263
simulateContract(client, {
254264
...args,
255265
wallet
256266
} as SimulateContractWithConnectParameters)
257267
})
258268

259-
export { getTransaction, sendTransaction, sendTransactions, simulateContract, writeContract }
269+
export { getTransaction, sendBatchTransactions, sendTransaction, simulateContract, verifyMessage, writeContract }

src/customActions/getTransaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const getTransaction = async ({
7070
let txFailureEvent
7171

7272
while (!txSuccessEvent && !txFailureEvent) {
73-
sleep(2000)
73+
sleep(3000)
7474
txSuccessEvent = await _catchSuccessEvent(
7575
client,
7676
from,
@@ -116,6 +116,6 @@ export const getTransaction = async ({
116116
return txResponse
117117
}
118118

119-
sleep(2000)
119+
sleep(3000)
120120
return getTransaction({ client, wallet, safeTxHash })
121121
}

src/customActions/sendTransactions.ts renamed to src/customActions/sendBatchTransactions.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@ import {
99
SendTransactionReturnType,
1010
Transport
1111
} from 'viem'
12-
import { GetAccountParameter } from 'viem/_types/types/account'
1312

1413
import { deepHexlify } from '../utils/utils'
14+
import { getTransaction } from './getTransaction'
1515

16-
export type SendTransactionsWithConnectParameters<
17-
TAccount extends Account | undefined = Account | undefined
18-
> = {
16+
export type sendBatchTransactionsWithConnectParameters = {
1917
transactions: { to: Address; value: bigint; data: Hex }[]
20-
} & GetAccountParameter<TAccount> & {
21-
wallet: ComethWallet
22-
}
18+
} & {
19+
wallet: ComethWallet
20+
}
2321

24-
export async function sendTransactions<
22+
export async function sendBatchTransactions<
2523
TChain extends Chain | undefined,
2624
TAccount extends Account | undefined
2725
>(
2826
client: Client<Transport, TChain, TAccount>,
29-
args: SendTransactionsWithConnectParameters<TAccount>
27+
args: sendBatchTransactionsWithConnectParameters
3028
): Promise<SendTransactionReturnType> {
3129
const { transactions, wallet } = args
3230

3331
const result = await wallet.sendBatchTransactions(deepHexlify(transactions))
34-
return result.safeTxHash as Hash
32+
33+
const txReceipt = await getTransaction({
34+
client,
35+
wallet,
36+
safeTxHash: result.safeTxHash as Hash
37+
})
38+
39+
return txReceipt.transactionHash as Hash
3540
}

src/customActions/signMessage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
ToHexErrorType
99
} from 'viem/utils'
1010

11+
import { getConnectViemAccount } from '../account'
12+
1113
export type SignMessageWithConnectParameters<
1214
TAccount extends Account | undefined = Account | undefined
1315
> = GetAccountParameter<TAccount> & {
@@ -31,9 +33,7 @@ export async function signMessage<
3133
): Promise<SignMessageReturnType> {
3234
const { message, wallet } = args
3335

34-
const signature = (await wallet.signMessage(
35-
message as string
36-
)) as `0x${string}`
36+
const account = getConnectViemAccount(wallet)
3737

38-
return signature
38+
return await account.signMessage({ message })
3939
}

0 commit comments

Comments
 (0)