@crossmint/client-sdk-smart-wallet 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SmartWalletSDK.cjs +1 -34
- package/dist/SmartWalletSDK.js +1 -34
- package/dist/api/CrossmintWalletService.cjs +1 -13
- package/dist/api/CrossmintWalletService.js +1 -13
- package/dist/blockchain/chains.cjs +1 -23
- package/dist/blockchain/chains.js +1 -23
- package/dist/blockchain/rpc.cjs +1 -11
- package/dist/blockchain/rpc.js +1 -11
- package/dist/blockchain/transfer.cjs +1 -7
- package/dist/blockchain/transfer.js +1 -7
- package/dist/blockchain/wallets/EVMSmartWallet.cjs +1 -10
- package/dist/blockchain/wallets/EVMSmartWallet.js +1 -10
- package/dist/blockchain/wallets/SendTransactionService.cjs +1 -11
- package/dist/blockchain/wallets/SendTransactionService.js +1 -11
- package/dist/blockchain/wallets/account/cache.cjs +1 -9
- package/dist/blockchain/wallets/account/cache.js +1 -9
- package/dist/blockchain/wallets/account/config.cjs +1 -9
- package/dist/blockchain/wallets/account/config.js +1 -9
- package/dist/blockchain/wallets/account/creator.cjs +1 -10
- package/dist/blockchain/wallets/account/creator.js +1 -10
- package/dist/blockchain/wallets/account/eoa.cjs +1 -11
- package/dist/blockchain/wallets/account/eoa.js +1 -11
- package/dist/blockchain/wallets/account/passkey.cjs +1 -9
- package/dist/blockchain/wallets/account/passkey.js +1 -9
- package/dist/blockchain/wallets/account/signer.cjs +1 -9
- package/dist/blockchain/wallets/account/signer.js +1 -9
- package/dist/blockchain/wallets/account/strategy.cjs +1 -1
- package/dist/blockchain/wallets/account/strategy.js +0 -1
- package/dist/blockchain/wallets/clientDecorator.cjs +1 -12
- package/dist/blockchain/wallets/clientDecorator.js +1 -12
- package/dist/blockchain/wallets/index.cjs +1 -10
- package/dist/blockchain/wallets/index.js +1 -10
- package/dist/blockchain/wallets/paymaster.cjs +1 -10
- package/dist/blockchain/wallets/paymaster.js +1 -10
- package/dist/blockchain/wallets/service.cjs +1 -16
- package/dist/blockchain/wallets/service.js +1 -16
- package/dist/chunk-265KNPZR.js +1 -0
- package/dist/chunk-2GS5TXEY.cjs +1 -0
- package/dist/chunk-2R6HK64N.cjs +1 -0
- package/dist/chunk-3F6P4HUZ.js +1 -0
- package/dist/chunk-4SPA557P.js +0 -0
- package/dist/chunk-7AVDZZGD.cjs +1 -0
- package/dist/chunk-7FXFOOQU.cjs +1 -0
- package/dist/chunk-7KTCGFU5.js +1 -0
- package/dist/chunk-AK6IIUTM.js +1 -0
- package/dist/chunk-ATQ4WGCW.js +1 -0
- package/dist/chunk-BIJAOWPS.js +1 -0
- package/dist/chunk-BJZQA5VC.js +1 -0
- package/dist/chunk-C3VZY7VJ.js +1 -0
- package/dist/chunk-CUTQYF3F.js +1 -0
- package/dist/chunk-D4NDUT36.js +1 -0
- package/dist/chunk-DIDKPOO2.cjs +1 -0
- package/dist/chunk-DQNKQDE2.cjs +1 -0
- package/dist/chunk-E3NG3YWO.js +1 -0
- package/dist/chunk-ETVJGLNY.js +1 -0
- package/dist/chunk-FHNNZVNU.js +1 -0
- package/dist/chunk-GB35YMN4.cjs +1 -0
- package/dist/chunk-H4CMXNVK.js +1 -0
- package/dist/chunk-HGA3WK6L.cjs +1 -0
- package/dist/chunk-II4HKF7X.cjs +1 -0
- package/dist/chunk-IQTGPM2U.cjs +1 -0
- package/dist/chunk-KYPTGHC6.cjs +1 -0
- package/dist/chunk-LDNU6SJL.cjs +3 -0
- package/dist/chunk-M4K3IZTT.cjs +1 -0
- package/dist/chunk-MJ62KCTK.cjs +1 -0
- package/dist/chunk-NAX6LRUY.cjs +1 -0
- package/dist/chunk-NLGILHJS.js +1 -0
- package/dist/chunk-O2ACORII.cjs +1 -0
- package/dist/chunk-ODAUWGUU.cjs +1 -0
- package/dist/chunk-PZ6Q22YJ.js +1 -0
- package/dist/chunk-QD2JKGX6.cjs +1 -0
- package/dist/chunk-S2XBSAGM.js +1 -0
- package/dist/chunk-SBW2PS63.cjs +1 -0
- package/dist/chunk-SCXFZMLR.cjs +1 -0
- package/dist/chunk-STH2LE35.cjs +1 -0
- package/dist/chunk-SWWOVT47.cjs +1 -0
- package/dist/chunk-TBTRV56U.cjs +2 -0
- package/dist/chunk-TWADESPF.cjs +1 -0
- package/dist/chunk-TXLAUKCK.cjs +1 -0
- package/dist/chunk-TZG6MROQ.js +1 -0
- package/dist/chunk-UG47CBKR.js +1 -0
- package/dist/chunk-UPURFW46.js +1 -0
- package/dist/chunk-UXNWF66Q.js +1 -0
- package/dist/chunk-VMOQWOZV.js +3 -0
- package/dist/chunk-VXGNAQOW.js +1 -0
- package/dist/chunk-WJ6XJMRD.cjs +1 -0
- package/dist/{chunk-5MG5CIEX.cjs → chunk-XJGFG3RT.cjs} +1 -13
- package/dist/chunk-XQ2K2K23.cjs +1 -0
- package/dist/chunk-YBHSEZMB.js +1 -0
- package/dist/chunk-YJUD5MVS.js +1 -0
- package/dist/chunk-YUWCRSYD.js +1 -0
- package/dist/chunk-Z7MMOBIC.js +2 -0
- package/dist/error/index.cjs +1 -25
- package/dist/error/index.js +1 -25
- package/dist/error/processor.cjs +1 -9
- package/dist/error/processor.js +1 -9
- package/dist/index.cjs +1 -86
- package/dist/index.js +1 -86
- package/dist/services/index.cjs +1 -11
- package/dist/services/index.js +1 -11
- package/dist/services/logger.cjs +1 -10
- package/dist/services/logger.js +1 -10
- package/dist/types/internal.cjs +1 -18
- package/dist/types/internal.js +1 -18
- package/dist/types/params.cjs +1 -1
- package/dist/types/params.js +0 -1
- package/dist/types/schema.cjs +1 -16
- package/dist/types/schema.js +1 -16
- package/dist/types/service.cjs +1 -1
- package/dist/types/service.js +0 -1
- package/dist/types/token.cjs +1 -1
- package/dist/types/token.js +0 -1
- package/dist/utils/api.cjs +1 -9
- package/dist/utils/api.js +1 -9
- package/dist/utils/blockchain.cjs +1 -7
- package/dist/utils/blockchain.js +1 -7
- package/dist/utils/constants.cjs +1 -19
- package/dist/utils/constants.js +1 -19
- package/dist/utils/environment.cjs +1 -7
- package/dist/utils/environment.js +1 -7
- package/dist/utils/helpers.cjs +1 -9
- package/dist/utils/helpers.js +1 -9
- package/dist/utils/signer.cjs +1 -10
- package/dist/utils/signer.js +1 -10
- package/dist/utils/test.cjs +1 -27
- package/dist/utils/test.js +1 -27
- package/package.json +3 -4
- package/dist/SmartWalletSDK.cjs.map +0 -1
- package/dist/SmartWalletSDK.js.map +0 -1
- package/dist/api/CrossmintWalletService.cjs.map +0 -1
- package/dist/api/CrossmintWalletService.js.map +0 -1
- package/dist/blockchain/chains.cjs.map +0 -1
- package/dist/blockchain/chains.js.map +0 -1
- package/dist/blockchain/rpc.cjs.map +0 -1
- package/dist/blockchain/rpc.js.map +0 -1
- package/dist/blockchain/transfer.cjs.map +0 -1
- package/dist/blockchain/transfer.js.map +0 -1
- package/dist/blockchain/wallets/EVMSmartWallet.cjs.map +0 -1
- package/dist/blockchain/wallets/EVMSmartWallet.js.map +0 -1
- package/dist/blockchain/wallets/SendTransactionService.cjs.map +0 -1
- package/dist/blockchain/wallets/SendTransactionService.js.map +0 -1
- package/dist/blockchain/wallets/account/cache.cjs.map +0 -1
- package/dist/blockchain/wallets/account/cache.js.map +0 -1
- package/dist/blockchain/wallets/account/config.cjs.map +0 -1
- package/dist/blockchain/wallets/account/config.js.map +0 -1
- package/dist/blockchain/wallets/account/creator.cjs.map +0 -1
- package/dist/blockchain/wallets/account/creator.js.map +0 -1
- package/dist/blockchain/wallets/account/eoa.cjs.map +0 -1
- package/dist/blockchain/wallets/account/eoa.js.map +0 -1
- package/dist/blockchain/wallets/account/passkey.cjs.map +0 -1
- package/dist/blockchain/wallets/account/passkey.js.map +0 -1
- package/dist/blockchain/wallets/account/signer.cjs.map +0 -1
- package/dist/blockchain/wallets/account/signer.js.map +0 -1
- package/dist/blockchain/wallets/account/strategy.cjs.map +0 -1
- package/dist/blockchain/wallets/account/strategy.js.map +0 -1
- package/dist/blockchain/wallets/clientDecorator.cjs.map +0 -1
- package/dist/blockchain/wallets/clientDecorator.js.map +0 -1
- package/dist/blockchain/wallets/index.cjs.map +0 -1
- package/dist/blockchain/wallets/index.js.map +0 -1
- package/dist/blockchain/wallets/paymaster.cjs.map +0 -1
- package/dist/blockchain/wallets/paymaster.js.map +0 -1
- package/dist/blockchain/wallets/service.cjs.map +0 -1
- package/dist/blockchain/wallets/service.js.map +0 -1
- package/dist/chunk-22PW4SGD.cjs +0 -36
- package/dist/chunk-22PW4SGD.cjs.map +0 -1
- package/dist/chunk-2HB65Y7D.js +0 -79
- package/dist/chunk-2HB65Y7D.js.map +0 -1
- package/dist/chunk-3EQHAQXO.js +0 -112
- package/dist/chunk-3EQHAQXO.js.map +0 -1
- package/dist/chunk-3PVQ4P74.cjs +0 -66
- package/dist/chunk-3PVQ4P74.cjs.map +0 -1
- package/dist/chunk-3R6PW6HY.js +0 -30
- package/dist/chunk-3R6PW6HY.js.map +0 -1
- package/dist/chunk-5EJ2YW7L.cjs +0 -93
- package/dist/chunk-5EJ2YW7L.cjs.map +0 -1
- package/dist/chunk-5IZ57G5A.js +0 -123
- package/dist/chunk-5IZ57G5A.js.map +0 -1
- package/dist/chunk-5MG5CIEX.cjs.map +0 -1
- package/dist/chunk-5URMCCO6.js +0 -9
- package/dist/chunk-5URMCCO6.js.map +0 -1
- package/dist/chunk-5WVQ7J3E.cjs +0 -369
- package/dist/chunk-5WVQ7J3E.cjs.map +0 -1
- package/dist/chunk-6IJLWHUN.cjs +0 -44
- package/dist/chunk-6IJLWHUN.cjs.map +0 -1
- package/dist/chunk-6NJVFL2X.js +0 -60
- package/dist/chunk-6NJVFL2X.js.map +0 -1
- package/dist/chunk-6O7DYITB.js +0 -99
- package/dist/chunk-6O7DYITB.js.map +0 -1
- package/dist/chunk-6OFQWFH6.cjs +0 -22
- package/dist/chunk-6OFQWFH6.cjs.map +0 -1
- package/dist/chunk-77GT6B5L.cjs +0 -79
- package/dist/chunk-77GT6B5L.cjs.map +0 -1
- package/dist/chunk-7KAFEHUT.js +0 -36
- package/dist/chunk-7KAFEHUT.js.map +0 -1
- package/dist/chunk-7KTQNIAZ.cjs +0 -112
- package/dist/chunk-7KTQNIAZ.cjs.map +0 -1
- package/dist/chunk-ASIPMVRQ.js +0 -90
- package/dist/chunk-ASIPMVRQ.js.map +0 -1
- package/dist/chunk-BARW756O.js +0 -27
- package/dist/chunk-BARW756O.js.map +0 -1
- package/dist/chunk-BXSAJOIV.cjs +0 -90
- package/dist/chunk-BXSAJOIV.cjs.map +0 -1
- package/dist/chunk-DMTDBTI6.js +0 -39
- package/dist/chunk-DMTDBTI6.js.map +0 -1
- package/dist/chunk-DTEA33DF.cjs +0 -59
- package/dist/chunk-DTEA33DF.cjs.map +0 -1
- package/dist/chunk-DYO4HODM.cjs +0 -36
- package/dist/chunk-DYO4HODM.cjs.map +0 -1
- package/dist/chunk-E44QR6BR.js +0 -41
- package/dist/chunk-E44QR6BR.js.map +0 -1
- package/dist/chunk-EP2KTXWN.cjs +0 -39
- package/dist/chunk-EP2KTXWN.cjs.map +0 -1
- package/dist/chunk-EPEGJY6N.cjs +0 -9
- package/dist/chunk-EPEGJY6N.cjs.map +0 -1
- package/dist/chunk-EQSMHR77.js +0 -30
- package/dist/chunk-EQSMHR77.js.map +0 -1
- package/dist/chunk-FSIMJYXR.js +0 -36
- package/dist/chunk-FSIMJYXR.js.map +0 -1
- package/dist/chunk-FVEUQ5LF.js +0 -14
- package/dist/chunk-FVEUQ5LF.js.map +0 -1
- package/dist/chunk-FXGOVLZW.cjs +0 -9
- package/dist/chunk-FXGOVLZW.cjs.map +0 -1
- package/dist/chunk-IHXCFM4Q.js +0 -22
- package/dist/chunk-IHXCFM4Q.js.map +0 -1
- package/dist/chunk-JOB7STIS.js +0 -9
- package/dist/chunk-JOB7STIS.js.map +0 -1
- package/dist/chunk-KHROQTVY.js +0 -1
- package/dist/chunk-KHROQTVY.js.map +0 -1
- package/dist/chunk-L5OEF7W3.cjs +0 -14
- package/dist/chunk-L5OEF7W3.cjs.map +0 -1
- package/dist/chunk-LGDLTGAS.js +0 -66
- package/dist/chunk-LGDLTGAS.js.map +0 -1
- package/dist/chunk-MGDAIRKC.cjs +0 -82
- package/dist/chunk-MGDAIRKC.cjs.map +0 -1
- package/dist/chunk-MPF4K2EV.cjs +0 -123
- package/dist/chunk-MPF4K2EV.cjs.map +0 -1
- package/dist/chunk-N6DG5EZG.cjs +0 -156
- package/dist/chunk-N6DG5EZG.cjs.map +0 -1
- package/dist/chunk-O6IFYHDP.cjs +0 -36
- package/dist/chunk-O6IFYHDP.cjs.map +0 -1
- package/dist/chunk-OGA3YDWS.cjs +0 -112
- package/dist/chunk-OGA3YDWS.cjs.map +0 -1
- package/dist/chunk-ON4DOYVD.js +0 -369
- package/dist/chunk-ON4DOYVD.js.map +0 -1
- package/dist/chunk-PVFA6PBX.cjs +0 -60
- package/dist/chunk-PVFA6PBX.cjs.map +0 -1
- package/dist/chunk-QHCELEYE.cjs +0 -99
- package/dist/chunk-QHCELEYE.cjs.map +0 -1
- package/dist/chunk-QIXYNYYS.js +0 -82
- package/dist/chunk-QIXYNYYS.js.map +0 -1
- package/dist/chunk-QJ3BSVGV.js +0 -36
- package/dist/chunk-QJ3BSVGV.js.map +0 -1
- package/dist/chunk-QZRRIK7N.cjs +0 -41
- package/dist/chunk-QZRRIK7N.cjs.map +0 -1
- package/dist/chunk-S5RL5PJD.js +0 -44
- package/dist/chunk-S5RL5PJD.js.map +0 -1
- package/dist/chunk-SLF7WWDT.js +0 -93
- package/dist/chunk-SLF7WWDT.js.map +0 -1
- package/dist/chunk-SMDX2MXU.js +0 -13
- package/dist/chunk-SMDX2MXU.js.map +0 -1
- package/dist/chunk-TDJDKTRS.js +0 -156
- package/dist/chunk-TDJDKTRS.js.map +0 -1
- package/dist/chunk-U4OBHCIP.js +0 -59
- package/dist/chunk-U4OBHCIP.js.map +0 -1
- package/dist/chunk-UQKE6R5W.cjs +0 -27
- package/dist/chunk-UQKE6R5W.cjs.map +0 -1
- package/dist/chunk-UZGHOTKZ.js +0 -112
- package/dist/chunk-UZGHOTKZ.js.map +0 -1
- package/dist/chunk-YWCXHOSD.cjs +0 -30
- package/dist/chunk-YWCXHOSD.cjs.map +0 -1
- package/dist/chunk-ZN42AA2G.cjs +0 -1
- package/dist/chunk-ZN42AA2G.cjs.map +0 -1
- package/dist/chunk-ZOXKITU4.cjs +0 -30
- package/dist/chunk-ZOXKITU4.cjs.map +0 -1
- package/dist/error/index.cjs.map +0 -1
- package/dist/error/index.js.map +0 -1
- package/dist/error/processor.cjs.map +0 -1
- package/dist/error/processor.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.js.map +0 -1
- package/dist/services/logger.cjs.map +0 -1
- package/dist/services/logger.js.map +0 -1
- package/dist/types/internal.cjs.map +0 -1
- package/dist/types/internal.js.map +0 -1
- package/dist/types/params.cjs.map +0 -1
- package/dist/types/params.js.map +0 -1
- package/dist/types/schema.cjs.map +0 -1
- package/dist/types/schema.js.map +0 -1
- package/dist/types/service.cjs.map +0 -1
- package/dist/types/service.js.map +0 -1
- package/dist/types/token.cjs.map +0 -1
- package/dist/types/token.js.map +0 -1
- package/dist/utils/api.cjs.map +0 -1
- package/dist/utils/api.js.map +0 -1
- package/dist/utils/blockchain.cjs.map +0 -1
- package/dist/utils/blockchain.js.map +0 -1
- package/dist/utils/constants.cjs.map +0 -1
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/environment.cjs.map +0 -1
- package/dist/utils/environment.js.map +0 -1
- package/dist/utils/helpers.cjs.map +0 -1
- package/dist/utils/helpers.js.map +0 -1
- package/dist/utils/signer.cjs.map +0 -1
- package/dist/utils/signer.js.map +0 -1
- package/dist/utils/test.cjs.map +0 -1
- package/dist/utils/test.js.map +0 -1
- package/src/ABI/ERC1155.json +0 -325
- package/src/ABI/ERC20.json +0 -222
- package/src/ABI/ERC721.json +0 -320
- package/src/SmartWalletSDK.test.ts +0 -31
- package/src/SmartWalletSDK.ts +0 -104
- package/src/api/CrossmintWalletService.test.ts +0 -43
- package/src/api/CrossmintWalletService.ts +0 -84
- package/src/blockchain/chains.ts +0 -57
- package/src/blockchain/rpc.ts +0 -25
- package/src/blockchain/transfer.ts +0 -54
- package/src/blockchain/wallets/EVMSmartWallet.ts +0 -157
- package/src/blockchain/wallets/SendTransactionService.test.ts +0 -159
- package/src/blockchain/wallets/SendTransactionService.ts +0 -188
- package/src/blockchain/wallets/account/cache.test.ts +0 -67
- package/src/blockchain/wallets/account/cache.ts +0 -43
- package/src/blockchain/wallets/account/config.test.ts +0 -103
- package/src/blockchain/wallets/account/config.ts +0 -116
- package/src/blockchain/wallets/account/creator.ts +0 -40
- package/src/blockchain/wallets/account/eoa.ts +0 -51
- package/src/blockchain/wallets/account/passkey.ts +0 -198
- package/src/blockchain/wallets/account/signer.ts +0 -44
- package/src/blockchain/wallets/account/strategy.ts +0 -5
- package/src/blockchain/wallets/clientDecorator.ts +0 -128
- package/src/blockchain/wallets/index.ts +0 -1
- package/src/blockchain/wallets/paymaster.ts +0 -41
- package/src/blockchain/wallets/service.ts +0 -107
- package/src/error/index.ts +0 -100
- package/src/error/processor.ts +0 -36
- package/src/index.ts +0 -47
- package/src/services/index.ts +0 -1
- package/src/services/logger.ts +0 -6
- package/src/types/internal.ts +0 -76
- package/src/types/params.ts +0 -34
- package/src/types/schema.ts +0 -63
- package/src/types/service.ts +0 -31
- package/src/types/token.ts +0 -29
- package/src/utils/api.ts +0 -39
- package/src/utils/blockchain.ts +0 -5
- package/src/utils/constants.ts +0 -9
- package/src/utils/environment.ts +0 -3
- package/src/utils/helpers.ts +0 -7
- package/src/utils/signer.ts +0 -33
- package/src/utils/test.ts +0 -24
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import { mock } from "vitest-mock-extended";
|
|
3
|
-
|
|
4
|
-
import type { CrossmintWalletService } from "../../../api/CrossmintWalletService";
|
|
5
|
-
import type { SmartWalletConfig } from "../../../types/service";
|
|
6
|
-
import { mockConfig } from "../../../utils/test";
|
|
7
|
-
import { SmartWalletChain } from "../../chains";
|
|
8
|
-
import type { AccountConfigCache } from "./cache";
|
|
9
|
-
import { AccountConfigService } from "./config";
|
|
10
|
-
import { PasskeySignerConfig } from "./signer";
|
|
11
|
-
|
|
12
|
-
describe("AccountConfigService", () => {
|
|
13
|
-
let service: AccountConfigService;
|
|
14
|
-
const mockCrossmintService = mock<CrossmintWalletService>();
|
|
15
|
-
const mockCache = mock<AccountConfigCache>();
|
|
16
|
-
|
|
17
|
-
const mockUser = { jwt: "test_jwt" };
|
|
18
|
-
const mockChain = SmartWalletChain.POLYGON_AMOY;
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
service = new AccountConfigService(mockCrossmintService, mockCache);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("get", () => {
|
|
25
|
-
it("should return config from cache if available", async () => {
|
|
26
|
-
mockCache.get.mockReturnValue(mockConfig);
|
|
27
|
-
const result = await service.get(mockUser, mockChain);
|
|
28
|
-
|
|
29
|
-
expect(result).toEqual({
|
|
30
|
-
config: {
|
|
31
|
-
entryPointVersion: mockConfig.entryPointVersion,
|
|
32
|
-
kernelVersion: mockConfig.kernelVersion,
|
|
33
|
-
userWithId: { ...mockUser, id: mockConfig.userId },
|
|
34
|
-
existing: {
|
|
35
|
-
signerConfig: expect.any(PasskeySignerConfig),
|
|
36
|
-
address: mockConfig.smartContractWalletAddress,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
cached: true,
|
|
40
|
-
});
|
|
41
|
-
expect(mockCache.get).toHaveBeenCalledWith(mockUser);
|
|
42
|
-
expect(mockCrossmintService.getSmartWalletConfig).not.toHaveBeenCalled();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should fetch config from service if not in cache", async () => {
|
|
46
|
-
mockCache.get.mockReturnValue(null);
|
|
47
|
-
mockCrossmintService.getSmartWalletConfig.mockResolvedValue(mockConfig);
|
|
48
|
-
|
|
49
|
-
const result = await service.get(mockUser, mockChain);
|
|
50
|
-
|
|
51
|
-
expect(result).toEqual({
|
|
52
|
-
config: {
|
|
53
|
-
entryPointVersion: mockConfig.entryPointVersion,
|
|
54
|
-
kernelVersion: mockConfig.kernelVersion,
|
|
55
|
-
userWithId: { ...mockUser, id: mockConfig.userId },
|
|
56
|
-
existing: {
|
|
57
|
-
signerConfig: expect.any(PasskeySignerConfig),
|
|
58
|
-
address: mockConfig.smartContractWalletAddress,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
cached: false,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
expect(mockCache.get).toHaveBeenCalledWith(mockUser);
|
|
65
|
-
expect(mockCrossmintService.getSmartWalletConfig).toHaveBeenCalledWith(mockUser, mockChain);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("should throw error for unsupported entryPoint and kernel version combination", async () => {
|
|
69
|
-
const unsupportedConfig: SmartWalletConfig = {
|
|
70
|
-
...mockConfig,
|
|
71
|
-
entryPointVersion: "v0.7" as const,
|
|
72
|
-
kernelVersion: "0.2.4" as const,
|
|
73
|
-
};
|
|
74
|
-
mockCache.get.mockReturnValue(unsupportedConfig);
|
|
75
|
-
|
|
76
|
-
await expect(service.get(mockUser, mockChain)).rejects.toThrow(
|
|
77
|
-
"Unsupported combination: entryPoint v0.7 and kernel version 0.2.4. Please contact support"
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("incomplete configurations", () => {
|
|
82
|
-
const testCases = [
|
|
83
|
-
{
|
|
84
|
-
name: "only signer is present",
|
|
85
|
-
config: { ...mockConfig, smartContractWalletAddress: undefined },
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: "only address is present",
|
|
89
|
-
config: { ...mockConfig, signers: [] },
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
testCases.forEach(({ name, config }) => {
|
|
94
|
-
it(`should throw error when ${name}`, async () => {
|
|
95
|
-
mockCache.get.mockReturnValue(config);
|
|
96
|
-
await expect(service.get(mockUser, mockChain)).rejects.toThrow(
|
|
97
|
-
"Either both signer and address must be present, or both must be null"
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type { CrossmintWalletService } from "../../../api/CrossmintWalletService";
|
|
2
|
-
import type { SmartWalletChain } from "../../../blockchain/chains";
|
|
3
|
-
import { SmartWalletError } from "../../../error";
|
|
4
|
-
import type {
|
|
5
|
-
PreExistingWalletProperties,
|
|
6
|
-
SupportedEntryPointVersion,
|
|
7
|
-
SupportedKernelVersion,
|
|
8
|
-
} from "../../../types/internal";
|
|
9
|
-
import type { UserParams } from "../../../types/params";
|
|
10
|
-
import type { SignerData, SmartWalletConfig } from "../../../types/service";
|
|
11
|
-
import type { AccountConfigCache } from "./cache";
|
|
12
|
-
import { EOASignerConfig, PasskeySignerConfig, type SignerConfig } from "./signer";
|
|
13
|
-
|
|
14
|
-
interface AccountConfig {
|
|
15
|
-
entryPointVersion: SupportedEntryPointVersion;
|
|
16
|
-
kernelVersion: SupportedKernelVersion;
|
|
17
|
-
userWithId: UserParams & { id: string };
|
|
18
|
-
existing?: PreExistingWalletProperties;
|
|
19
|
-
}
|
|
20
|
-
export class AccountConfigService {
|
|
21
|
-
constructor(
|
|
22
|
-
private readonly crossmintService: CrossmintWalletService,
|
|
23
|
-
private readonly configCache: AccountConfigCache
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
public async get(
|
|
27
|
-
user: UserParams,
|
|
28
|
-
chain: SmartWalletChain
|
|
29
|
-
): Promise<{
|
|
30
|
-
config: AccountConfig;
|
|
31
|
-
cached: boolean;
|
|
32
|
-
}> {
|
|
33
|
-
const cached = this.configCache.get(user);
|
|
34
|
-
if (cached != null) {
|
|
35
|
-
return {
|
|
36
|
-
config: this.validateAndFormat(user, cached),
|
|
37
|
-
cached: true,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const config = await this.crossmintService.getSmartWalletConfig(user, chain);
|
|
42
|
-
return { config: this.validateAndFormat(user, config), cached: false };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public cache({
|
|
46
|
-
entryPointVersion,
|
|
47
|
-
kernelVersion,
|
|
48
|
-
user,
|
|
49
|
-
existing,
|
|
50
|
-
}: {
|
|
51
|
-
entryPointVersion: SupportedEntryPointVersion;
|
|
52
|
-
kernelVersion: SupportedKernelVersion;
|
|
53
|
-
user: UserParams & { id: string };
|
|
54
|
-
existing: PreExistingWalletProperties;
|
|
55
|
-
}) {
|
|
56
|
-
this.configCache.clear();
|
|
57
|
-
this.configCache.set(user, {
|
|
58
|
-
entryPointVersion,
|
|
59
|
-
kernelVersion,
|
|
60
|
-
userId: user.id,
|
|
61
|
-
signers: [{ signerData: existing.signerConfig.data }],
|
|
62
|
-
smartContractWalletAddress: existing.address,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private validateAndFormat(
|
|
67
|
-
user: UserParams,
|
|
68
|
-
{ entryPointVersion, kernelVersion, signers, smartContractWalletAddress, userId }: SmartWalletConfig
|
|
69
|
-
): AccountConfig {
|
|
70
|
-
if (
|
|
71
|
-
(entryPointVersion === "v0.7" && kernelVersion.startsWith("0.2")) ||
|
|
72
|
-
(entryPointVersion === "v0.6" && kernelVersion.startsWith("0.3"))
|
|
73
|
-
) {
|
|
74
|
-
throw new SmartWalletError(
|
|
75
|
-
`Unsupported combination: entryPoint ${entryPointVersion} and kernel version ${kernelVersion}. Please contact support`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const signerData = signers.map((x) => x.signerData);
|
|
80
|
-
const signer = this.getSigner(signerData);
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
(smartContractWalletAddress != null && signer == null) ||
|
|
84
|
-
(signer != null && smartContractWalletAddress == null)
|
|
85
|
-
) {
|
|
86
|
-
throw new SmartWalletError("Either both signer and address must be present, or both must be null");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (signer == null || smartContractWalletAddress == null) {
|
|
90
|
-
return { entryPointVersion, kernelVersion, userWithId: { ...user, id: userId } };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
entryPointVersion,
|
|
95
|
-
kernelVersion,
|
|
96
|
-
userWithId: { ...user, id: userId },
|
|
97
|
-
existing: { signerConfig: signer, address: smartContractWalletAddress },
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private getSigner(signers: SignerData[]): SignerConfig | undefined {
|
|
102
|
-
if (signers.length === 0) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const data = signers[0];
|
|
107
|
-
|
|
108
|
-
if (data.type === "eoa") {
|
|
109
|
-
return new EOASignerConfig(data);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (data.type === "passkeys") {
|
|
113
|
-
return new PasskeySignerConfig(data);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { AdminMismatchError, ConfigError } from "../../../error";
|
|
2
|
-
import {
|
|
3
|
-
type AccountAndSigner,
|
|
4
|
-
type WalletCreationContext,
|
|
5
|
-
isEOACreationContext,
|
|
6
|
-
isPasskeyCreationContext,
|
|
7
|
-
isPasskeyWalletParams,
|
|
8
|
-
} from "../../../types/internal";
|
|
9
|
-
import type { EOACreationStrategy } from "./eoa";
|
|
10
|
-
import type { PasskeyCreationStrategy } from "./passkey";
|
|
11
|
-
|
|
12
|
-
export class AccountCreator {
|
|
13
|
-
constructor(
|
|
14
|
-
private readonly eoaStrategy: EOACreationStrategy,
|
|
15
|
-
private readonly passkeyStrategy: PasskeyCreationStrategy
|
|
16
|
-
) {}
|
|
17
|
-
|
|
18
|
-
public get(context: WalletCreationContext): Promise<AccountAndSigner> {
|
|
19
|
-
if (isPasskeyCreationContext(context)) {
|
|
20
|
-
return this.passkeyStrategy.create(context);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (isEOACreationContext(context)) {
|
|
24
|
-
return this.eoaStrategy.create(context);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (context.existing == null) {
|
|
28
|
-
throw new ConfigError(`Unsupported wallet params:\n${context.walletParams}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const display = context.existing.signerConfig.display();
|
|
32
|
-
const inputSignerType = isPasskeyWalletParams(context.walletParams) ? "passkey" : "eoa";
|
|
33
|
-
throw new AdminMismatchError(
|
|
34
|
-
`Cannot create wallet with ${inputSignerType} signer for user ${
|
|
35
|
-
context.user.id
|
|
36
|
-
}', they already have a wallet with signer:\n'${JSON.stringify(display, null, 2)}'`,
|
|
37
|
-
display
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator";
|
|
2
|
-
import { createKernelAccount } from "@zerodev/sdk";
|
|
3
|
-
|
|
4
|
-
import { AdminMismatchError } from "../../../error";
|
|
5
|
-
import type { AccountAndSigner, EOACreationContext } from "../../../types/internal";
|
|
6
|
-
import { equalsIgnoreCase } from "../../../utils/helpers";
|
|
7
|
-
import { createOwnerSigner } from "../../../utils/signer";
|
|
8
|
-
import { EOASignerConfig } from "./signer";
|
|
9
|
-
import type { AccountCreationStrategy } from "./strategy";
|
|
10
|
-
|
|
11
|
-
export class EOACreationStrategy implements AccountCreationStrategy {
|
|
12
|
-
public async create({
|
|
13
|
-
chain,
|
|
14
|
-
publicClient,
|
|
15
|
-
entryPoint,
|
|
16
|
-
walletParams,
|
|
17
|
-
kernelVersion,
|
|
18
|
-
user,
|
|
19
|
-
existing,
|
|
20
|
-
}: EOACreationContext): Promise<AccountAndSigner> {
|
|
21
|
-
const eoa = await createOwnerSigner({
|
|
22
|
-
chain,
|
|
23
|
-
walletParams,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (existing != null && !equalsIgnoreCase(eoa.address, existing.signerConfig.data.eoaAddress)) {
|
|
27
|
-
throw new AdminMismatchError(
|
|
28
|
-
`User '${user.id}' has an existing wallet with an eoa signer '${existing.signerConfig.data.eoaAddress}', this does not match input eoa signer '${eoa.address}'.`,
|
|
29
|
-
existing.signerConfig.display(),
|
|
30
|
-
{ type: "eoa", eoaAddress: existing.signerConfig.data.eoaAddress }
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
|
|
35
|
-
signer: eoa,
|
|
36
|
-
entryPoint,
|
|
37
|
-
kernelVersion,
|
|
38
|
-
});
|
|
39
|
-
const account = await createKernelAccount(publicClient, {
|
|
40
|
-
plugins: {
|
|
41
|
-
sudo: ecdsaValidator,
|
|
42
|
-
},
|
|
43
|
-
index: 0n,
|
|
44
|
-
entryPoint,
|
|
45
|
-
kernelVersion,
|
|
46
|
-
deployedAccountAddress: existing?.address,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return { account, signerConfig: new EOASignerConfig({ eoaAddress: eoa.address, type: "eoa" }) };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { PasskeyValidatorContractVersion, WebAuthnMode, toPasskeyValidator } from "@zerodev/passkey-validator";
|
|
2
|
-
import { type KernelSmartAccount, type KernelValidator, createKernelAccount } from "@zerodev/sdk";
|
|
3
|
-
import { type WebAuthnKey, toWebAuthnKey } from "@zerodev/webauthn-key";
|
|
4
|
-
import type { SmartAccount } from "permissionless/accounts";
|
|
5
|
-
import type { EntryPoint } from "permissionless/types/entrypoint";
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
PasskeyIncompatibleAuthenticatorError,
|
|
9
|
-
PasskeyMismatchError,
|
|
10
|
-
PasskeyPromptError,
|
|
11
|
-
PasskeyRegistrationError,
|
|
12
|
-
} from "../../../error";
|
|
13
|
-
import type { AccountAndSigner, PasskeyCreationContext } from "../../../types/internal";
|
|
14
|
-
import type { PasskeySigner, UserParams, WalletParams } from "../../../types/params";
|
|
15
|
-
import type { PasskeySignerData, PasskeyValidatorSerializedData } from "../../../types/service";
|
|
16
|
-
import { PasskeySignerConfig } from "./signer";
|
|
17
|
-
import type { AccountCreationStrategy } from "./strategy";
|
|
18
|
-
|
|
19
|
-
type PasskeyValidator = KernelValidator<EntryPoint, "WebAuthnValidator"> & {
|
|
20
|
-
getSerializedData: () => string;
|
|
21
|
-
};
|
|
22
|
-
export class PasskeyCreationStrategy implements AccountCreationStrategy {
|
|
23
|
-
constructor(
|
|
24
|
-
private readonly passkeyServerUrl: string,
|
|
25
|
-
private readonly apiKey: string
|
|
26
|
-
) {}
|
|
27
|
-
|
|
28
|
-
public async create({
|
|
29
|
-
user,
|
|
30
|
-
publicClient,
|
|
31
|
-
walletParams,
|
|
32
|
-
entryPoint,
|
|
33
|
-
kernelVersion,
|
|
34
|
-
existing,
|
|
35
|
-
}: PasskeyCreationContext): Promise<AccountAndSigner> {
|
|
36
|
-
const inputPasskeyName = walletParams.signer.passkeyName ?? user.id;
|
|
37
|
-
if (existing != null && existing.signerConfig.data.passkeyName !== inputPasskeyName) {
|
|
38
|
-
throw new PasskeyMismatchError(
|
|
39
|
-
`User '${user.id}' has an existing wallet created with a passkey named '${existing.signerConfig.data.passkeyName}', this does match input passkey name '${inputPasskeyName}'.`,
|
|
40
|
-
existing.signerConfig.display()
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
if (existing == null && walletParams.signer.onPrePasskeyRegistration != null) {
|
|
46
|
-
await walletParams.signer.onPrePasskeyRegistration();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const passkey = await this.getPasskey(user, inputPasskeyName, existing?.signerConfig.data);
|
|
50
|
-
|
|
51
|
-
const latestValidatorVersion = PasskeyValidatorContractVersion.V0_0_2;
|
|
52
|
-
const validatorContractVersion =
|
|
53
|
-
existing == null ? latestValidatorVersion : existing.signerConfig.data.validatorContractVersion;
|
|
54
|
-
|
|
55
|
-
const validator = await toPasskeyValidator(publicClient, {
|
|
56
|
-
webAuthnKey: passkey,
|
|
57
|
-
entryPoint,
|
|
58
|
-
validatorContractVersion,
|
|
59
|
-
kernelVersion,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const kernelAccount = await createKernelAccount(publicClient, {
|
|
63
|
-
plugins: { sudo: validator },
|
|
64
|
-
entryPoint,
|
|
65
|
-
kernelVersion,
|
|
66
|
-
deployedAccountAddress: existing?.address,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
signerConfig: this.getSignerConfig(validator, validatorContractVersion, inputPasskeyName),
|
|
71
|
-
account: this.decorate(kernelAccount, inputPasskeyName, walletParams),
|
|
72
|
-
};
|
|
73
|
-
} catch (error) {
|
|
74
|
-
if (walletParams.signer.onPasskeyRegistrationError != null) {
|
|
75
|
-
walletParams.signer.onPasskeyRegistrationError(error);
|
|
76
|
-
}
|
|
77
|
-
throw this.mapError(error, inputPasskeyName);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private async getPasskey(
|
|
82
|
-
user: UserParams,
|
|
83
|
-
passkeyName: string,
|
|
84
|
-
existing?: PasskeySignerData
|
|
85
|
-
): Promise<WebAuthnKey> {
|
|
86
|
-
if (existing != null) {
|
|
87
|
-
return {
|
|
88
|
-
pubX: BigInt(existing.pubKeyX),
|
|
89
|
-
pubY: BigInt(existing.pubKeyY),
|
|
90
|
-
authenticatorId: existing.authenticatorId,
|
|
91
|
-
authenticatorIdHash: existing.authenticatorIdHash,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return toWebAuthnKey({
|
|
96
|
-
passkeyName,
|
|
97
|
-
passkeyServerUrl: this.passkeyServerUrl,
|
|
98
|
-
mode: WebAuthnMode.Register,
|
|
99
|
-
passkeyServerHeaders: this.createPasskeysServerHeaders(user),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private getSignerConfig(
|
|
104
|
-
validator: PasskeyValidator,
|
|
105
|
-
validatorContractVersion: PasskeyValidatorContractVersion,
|
|
106
|
-
passkeyName: string
|
|
107
|
-
): PasskeySignerConfig {
|
|
108
|
-
return new PasskeySignerConfig({
|
|
109
|
-
...deserializePasskeyValidatorData(validator.getSerializedData()),
|
|
110
|
-
passkeyName,
|
|
111
|
-
validatorContractVersion,
|
|
112
|
-
domain: window.location.hostname,
|
|
113
|
-
type: "passkeys",
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private createPasskeysServerHeaders(user: UserParams) {
|
|
118
|
-
return {
|
|
119
|
-
"x-api-key": this.apiKey,
|
|
120
|
-
Authorization: `Bearer ${user.jwt}`,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private mapError(error: any, passkeyName: string) {
|
|
125
|
-
if (error.code === 0 && error.name === "DataError") {
|
|
126
|
-
return new PasskeyIncompatibleAuthenticatorError(passkeyName);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (error.message === "Registration not verified") {
|
|
130
|
-
return new PasskeyRegistrationError(passkeyName);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (error.code === "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY" && error.name === "NotAllowedError") {
|
|
134
|
-
return new PasskeyPromptError(passkeyName);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return error;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private decorate<Account extends KernelSmartAccount<EntryPoint>>(
|
|
141
|
-
account: Account,
|
|
142
|
-
passkeyName: string,
|
|
143
|
-
walletParams: WalletParams
|
|
144
|
-
): Account {
|
|
145
|
-
return new Proxy(account, {
|
|
146
|
-
get: (target, prop, receiver) => {
|
|
147
|
-
const original = Reflect.get(target, prop, receiver);
|
|
148
|
-
if (typeof original !== "function" || typeof prop !== "string" || !isAccountSigningMethod(prop)) {
|
|
149
|
-
return original;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const signer = walletParams.signer as PasskeySigner;
|
|
153
|
-
return async (...args: any[]) => {
|
|
154
|
-
const isFirstTransaction = args?.[0]?.factoryData != null;
|
|
155
|
-
if (
|
|
156
|
-
isFirstTransaction &&
|
|
157
|
-
prop === "signUserOperation" &&
|
|
158
|
-
signer.type === "PASSKEY" &&
|
|
159
|
-
signer.onFirstTimePasskeySigning != null
|
|
160
|
-
) {
|
|
161
|
-
await signer.onFirstTimePasskeySigning();
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
return await original.call(target, ...args);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
if (signer.onFirstTimePasskeySigningError != null) {
|
|
167
|
-
await signer.onFirstTimePasskeySigningError(error);
|
|
168
|
-
}
|
|
169
|
-
throw this.mapError(error, passkeyName);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const accountSigningMethods = [
|
|
178
|
-
"signMessage",
|
|
179
|
-
"signTypedData",
|
|
180
|
-
"signUserOperation",
|
|
181
|
-
"signTransaction",
|
|
182
|
-
] as const satisfies readonly (keyof SmartAccount<EntryPoint>)[];
|
|
183
|
-
|
|
184
|
-
function isAccountSigningMethod(method: string): method is (typeof accountSigningMethods)[number] {
|
|
185
|
-
return accountSigningMethods.includes(method as any);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const deserializePasskeyValidatorData = (params: string) => {
|
|
189
|
-
const uint8Array = base64ToBytes(params);
|
|
190
|
-
const jsonString = new TextDecoder().decode(uint8Array);
|
|
191
|
-
|
|
192
|
-
return JSON.parse(jsonString) as PasskeyValidatorSerializedData;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
function base64ToBytes(base64: string) {
|
|
196
|
-
const binString = atob(base64);
|
|
197
|
-
return Uint8Array.from(binString, (m) => m.codePointAt(0) as number);
|
|
198
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
EOASignerData,
|
|
3
|
-
PasskeyDisplay,
|
|
4
|
-
PasskeySignerData,
|
|
5
|
-
SignerData,
|
|
6
|
-
SignerDisplay,
|
|
7
|
-
} from "../../../types/service";
|
|
8
|
-
|
|
9
|
-
export interface SignerConfig {
|
|
10
|
-
readonly type: "passkeys" | "eoa";
|
|
11
|
-
display(): SignerDisplay;
|
|
12
|
-
readonly data: SignerData;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class PasskeySignerConfig implements SignerConfig {
|
|
16
|
-
public readonly data: PasskeySignerData;
|
|
17
|
-
public readonly type = "passkeys";
|
|
18
|
-
|
|
19
|
-
constructor(data: PasskeySignerData) {
|
|
20
|
-
this.data = data;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public display(): PasskeyDisplay {
|
|
24
|
-
return {
|
|
25
|
-
pubKeyX: this.data.pubKeyX,
|
|
26
|
-
pubKeyY: this.data.pubKeyY,
|
|
27
|
-
passkeyName: this.data.passkeyName,
|
|
28
|
-
type: this.type,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class EOASignerConfig implements SignerConfig {
|
|
34
|
-
public readonly data: EOASignerData;
|
|
35
|
-
public readonly type = "eoa";
|
|
36
|
-
|
|
37
|
-
constructor(data: EOASignerData) {
|
|
38
|
-
this.data = data;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public display() {
|
|
42
|
-
return this.data;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { SmartAccountClient } from "permissionless";
|
|
2
|
-
import type { EntryPoint } from "permissionless/types/entrypoint";
|
|
3
|
-
import { stringify } from "viem";
|
|
4
|
-
|
|
5
|
-
import { SmartWalletError } from "../../error";
|
|
6
|
-
import type { ErrorProcessor } from "../../error/processor";
|
|
7
|
-
import { scwLogger } from "../../services";
|
|
8
|
-
import { usesGelatoBundler } from "../../utils/blockchain";
|
|
9
|
-
import type { SmartWalletChain } from "../chains";
|
|
10
|
-
|
|
11
|
-
const transactionMethods = [
|
|
12
|
-
"sendTransaction",
|
|
13
|
-
"writeContract",
|
|
14
|
-
"sendUserOperation",
|
|
15
|
-
] as const satisfies readonly (keyof SmartAccountClient<EntryPoint>)[];
|
|
16
|
-
|
|
17
|
-
const signingMethods = [
|
|
18
|
-
"signMessage",
|
|
19
|
-
"signTypedData",
|
|
20
|
-
] as const satisfies readonly (keyof SmartAccountClient<EntryPoint>)[];
|
|
21
|
-
|
|
22
|
-
type TxnMethod = (typeof transactionMethods)[number];
|
|
23
|
-
type SignMethod = (typeof signingMethods)[number];
|
|
24
|
-
|
|
25
|
-
function isTxnMethod(method: string): method is TxnMethod {
|
|
26
|
-
return transactionMethods.includes(method as any);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isSignMethod(method: string): method is SignMethod {
|
|
30
|
-
return signingMethods.includes(method as any);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A decorator class for SmartAccountClient instances. It enhances the client with:
|
|
35
|
-
* - Error handling & logging.
|
|
36
|
-
* - Performance metrics.
|
|
37
|
-
* - Automatic formatting of transactions for Gelato bundler compatibility.
|
|
38
|
-
* */
|
|
39
|
-
export class ClientDecorator {
|
|
40
|
-
constructor(
|
|
41
|
-
private readonly errorProcessor: ErrorProcessor,
|
|
42
|
-
protected logger = scwLogger
|
|
43
|
-
) {}
|
|
44
|
-
|
|
45
|
-
public decorate<Client extends SmartAccountClient<EntryPoint>>({
|
|
46
|
-
crossmintChain,
|
|
47
|
-
smartAccountClient,
|
|
48
|
-
}: {
|
|
49
|
-
crossmintChain: SmartWalletChain;
|
|
50
|
-
smartAccountClient: Client;
|
|
51
|
-
}): Client {
|
|
52
|
-
return new Proxy(smartAccountClient, {
|
|
53
|
-
get: (target, prop, receiver) => {
|
|
54
|
-
const originalMethod = Reflect.get(target, prop, receiver);
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
typeof originalMethod !== "function" ||
|
|
58
|
-
typeof prop !== "string" ||
|
|
59
|
-
!(isSignMethod(prop) || isTxnMethod(prop))
|
|
60
|
-
) {
|
|
61
|
-
return originalMethod;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return (...args: any[]) =>
|
|
65
|
-
this.logger.logPerformance(`CrossmintSmartWallet.${prop}`, () =>
|
|
66
|
-
this.execute(target, prop, originalMethod, args, crossmintChain)
|
|
67
|
-
);
|
|
68
|
-
},
|
|
69
|
-
}) as Client;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private async execute<M extends TxnMethod | SignMethod>(
|
|
73
|
-
target: SmartAccountClient<EntryPoint>,
|
|
74
|
-
prop: M,
|
|
75
|
-
originalMethod: Function,
|
|
76
|
-
args: any[],
|
|
77
|
-
crossmintChain: SmartWalletChain
|
|
78
|
-
) {
|
|
79
|
-
try {
|
|
80
|
-
this.logger.log(`[CrossmintSmartWallet.${prop}] - params: ${stringify(args)}`);
|
|
81
|
-
const processed = isTxnMethod(prop) ? this.processTxnArgs(prop, crossmintChain, args) : args;
|
|
82
|
-
return await originalMethod.call(target, ...processed);
|
|
83
|
-
} catch (error: any) {
|
|
84
|
-
const description = isTxnMethod(prop) ? "signing" : "sending transaction";
|
|
85
|
-
throw this.errorProcessor.map(
|
|
86
|
-
error,
|
|
87
|
-
new SmartWalletError(`Error ${description}: ${error.message}`, stringify(error))
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private processTxnArgs(prop: TxnMethod, crossmintChain: SmartWalletChain, args: any[]): any[] {
|
|
93
|
-
if (prop === "sendUserOperation") {
|
|
94
|
-
const [{ userOperation, middleware, account }] = args as Parameters<
|
|
95
|
-
SmartAccountClient<EntryPoint>["sendUserOperation"]
|
|
96
|
-
>;
|
|
97
|
-
return [
|
|
98
|
-
{
|
|
99
|
-
middleware,
|
|
100
|
-
account,
|
|
101
|
-
userOperation: this.addGelatoBundlerProperties(crossmintChain, userOperation),
|
|
102
|
-
},
|
|
103
|
-
...args.slice(1),
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const [txn] = args as
|
|
108
|
-
| Parameters<SmartAccountClient<EntryPoint>["sendTransaction"]>
|
|
109
|
-
| Parameters<SmartAccountClient<EntryPoint>["writeContract"]>;
|
|
110
|
-
|
|
111
|
-
return [this.addGelatoBundlerProperties(crossmintChain, txn), ...args.slice(1)];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/*
|
|
115
|
-
* Chain that ZD uses Gelato as for bundler require special parameters:
|
|
116
|
-
* https://docs.zerodev.app/sdk/faqs/use-with-gelato#transaction-configuration
|
|
117
|
-
*/
|
|
118
|
-
private addGelatoBundlerProperties(
|
|
119
|
-
crossmintChain: SmartWalletChain,
|
|
120
|
-
txnParams: { maxFeePerGas?: bigint; maxPriorityFeePerGas?: bigint }
|
|
121
|
-
) {
|
|
122
|
-
if (usesGelatoBundler(crossmintChain)) {
|
|
123
|
-
return { ...txnParams, maxFeePerGas: "0x0" as any, maxPriorityFeePerGas: "0x0" as any };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return txnParams;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./EVMSmartWallet";
|