@account-kit/wallet-client 0.1.0-alpha.8 → 4.50.0
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/LICENSE +21 -0
- package/dist/esm/client/actions/formatSign.d.ts +30 -0
- package/dist/esm/client/actions/formatSign.js +32 -0
- package/dist/esm/client/actions/formatSign.js.map +1 -0
- package/dist/esm/client/actions/getCallsStatus.d.ts +6 -3
- package/dist/esm/client/actions/getCallsStatus.js +3 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +10 -11
- package/dist/esm/client/actions/grantPermissions.js +26 -12
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +10 -3
- package/dist/esm/client/actions/listAccounts.js +14 -2
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +6 -3
- package/dist/esm/client/actions/prepareCalls.js +12 -8
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +28 -0
- package/dist/esm/client/actions/prepareSign.js +31 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -0
- package/dist/esm/client/actions/requestAccount.d.ts +3 -1
- package/dist/esm/client/actions/requestAccount.js +5 -3
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/esm/client/actions/sendPreparedCalls.js +2 -0
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +5 -2
- package/dist/esm/client/actions/signMessage.js +5 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +2 -2
- package/dist/esm/client/actions/signPreparedCalls.js +28 -39
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +6 -10
- package/dist/esm/client/actions/signSignatureRequest.js +4 -7
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +2 -0
- package/dist/esm/client/actions/signTypedData.js +2 -0
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +0 -2
- package/dist/esm/client/decorator.js +1 -3
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +10 -6
- package/dist/esm/client/index.js +18 -21
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +1 -5
- package/dist/esm/exports/index.js +1 -6
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/internal/account.d.ts +33 -0
- package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +33 -35
- package/dist/esm/internal/account.js.map +1 -0
- package/dist/esm/types.d.ts +5 -11
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +14 -1
- package/dist/esm/utils.js +13 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +4 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/client/actions/formatSign.d.ts +31 -0
- package/dist/types/client/actions/formatSign.d.ts.map +1 -0
- package/dist/types/client/actions/getCallsStatus.d.ts +6 -3
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +10 -11
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +10 -3
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +6 -3
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +29 -0
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/client/actions/requestAccount.d.ts +3 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +3 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +5 -2
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts +2 -2
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +6 -10
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +2 -0
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +0 -2
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +10 -6
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +1 -5
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/internal/account.d.ts +34 -0
- package/dist/types/internal/account.d.ts.map +1 -0
- package/dist/types/types.d.ts +5 -11
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +14 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +33 -28
- package/src/client/actions/formatSign.ts +55 -0
- package/src/client/actions/getCallsStatus.ts +10 -6
- package/src/client/actions/grantPermissions.ts +46 -18
- package/src/client/actions/listAccounts.ts +22 -5
- package/src/client/actions/prepareCalls.ts +22 -16
- package/src/client/actions/prepareSign.ts +51 -0
- package/src/client/actions/requestAccount.ts +6 -4
- package/src/client/actions/sendPreparedCalls.ts +3 -1
- package/src/client/actions/signMessage.ts +5 -2
- package/src/client/actions/signPreparedCalls.ts +40 -45
- package/src/client/actions/signSignatureRequest.ts +12 -15
- package/src/client/actions/signTypedData.ts +2 -0
- package/src/client/decorator.ts +1 -8
- package/src/client/index.ts +41 -33
- package/src/exports/index.ts +1 -13
- package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +37 -54
- package/src/types.ts +7 -18
- package/src/utils.ts +15 -1
- package/src/version.ts +3 -0
- package/dist/esm/capabilities/eip7702Auth.d.ts +0 -4
- package/dist/esm/capabilities/eip7702Auth.js +0 -18
- package/dist/esm/capabilities/eip7702Auth.js.map +0 -1
- package/dist/esm/capabilities/index.d.ts +0 -38
- package/dist/esm/capabilities/index.js +0 -12
- package/dist/esm/capabilities/index.js.map +0 -1
- package/dist/esm/capabilities/overrides.d.ts +0 -26
- package/dist/esm/capabilities/overrides.js +0 -14
- package/dist/esm/capabilities/overrides.js.map +0 -1
- package/dist/esm/capabilities/paymaster.d.ts +0 -3
- package/dist/esm/capabilities/paymaster.js +0 -5
- package/dist/esm/capabilities/paymaster.js.map +0 -1
- package/dist/esm/capabilities/permissions/index.d.ts +0 -145
- package/dist/esm/capabilities/permissions/index.js +0 -83
- package/dist/esm/capabilities/permissions/index.js.map +0 -1
- package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
- package/dist/esm/capabilities/permissions/mav2.js +0 -88
- package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
- package/dist/esm/client/actions/createAccount.d.ts +0 -35
- package/dist/esm/client/actions/createAccount.js +0 -32
- package/dist/esm/client/actions/createAccount.js.map +0 -1
- package/dist/esm/client/client.e2e-test.d.ts +0 -1
- package/dist/esm/client/client.e2e-test.js +0 -375
- package/dist/esm/client/client.e2e-test.js.map +0 -1
- package/dist/esm/exports/internal.d.ts +0 -13
- package/dist/esm/exports/internal.js +0 -15
- package/dist/esm/exports/internal.js.map +0 -1
- package/dist/esm/isomorphic/actions/createSession.d.ts +0 -14
- package/dist/esm/isomorphic/actions/createSession.js +0 -89
- package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -21
- package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -113
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -8
- package/dist/esm/isomorphic/actions/prepareCalls.js +0 -101
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -148
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
- package/dist/esm/isomorphic/client.d.ts +0 -239
- package/dist/esm/isomorphic/client.js +0 -37
- package/dist/esm/isomorphic/client.js.map +0 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +0 -18
- package/dist/esm/isomorphic/utils/7702.js +0 -74
- package/dist/esm/isomorphic/utils/7702.js.map +0 -1
- package/dist/esm/isomorphic/utils/createAccount.d.ts +0 -23
- package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
- package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
- package/dist/esm/isomorphic/utils/decodeSignature.js +0 -13
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
- package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
- package/dist/esm/local/client.d.ts +0 -3
- package/dist/esm/local/client.js +0 -97
- package/dist/esm/local/client.js.map +0 -1
- package/dist/esm/remote/client.d.ts +0 -9
- package/dist/esm/remote/client.js +0 -41
- package/dist/esm/remote/client.js.map +0 -1
- package/dist/esm/rpc/examples.d.ts +0 -230
- package/dist/esm/rpc/examples.js +0 -314
- package/dist/esm/rpc/examples.js.map +0 -1
- package/dist/esm/rpc/request.d.ts +0 -711
- package/dist/esm/rpc/request.js +0 -213
- package/dist/esm/rpc/request.js.map +0 -1
- package/dist/esm/rpc/schema.d.ts +0 -659
- package/dist/esm/rpc/schema.js +0 -5
- package/dist/esm/rpc/schema.js.map +0 -1
- package/dist/esm/schemas.d.ts +0 -693
- package/dist/esm/schemas.js +0 -419
- package/dist/esm/schemas.js.map +0 -1
- package/dist/types/capabilities/eip7702Auth.d.ts +0 -5
- package/dist/types/capabilities/eip7702Auth.d.ts.map +0 -1
- package/dist/types/capabilities/index.d.ts +0 -39
- package/dist/types/capabilities/index.d.ts.map +0 -1
- package/dist/types/capabilities/overrides.d.ts +0 -27
- package/dist/types/capabilities/overrides.d.ts.map +0 -1
- package/dist/types/capabilities/paymaster.d.ts +0 -4
- package/dist/types/capabilities/paymaster.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/index.d.ts +0 -146
- package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
- package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
- package/dist/types/client/actions/createAccount.d.ts +0 -36
- package/dist/types/client/actions/createAccount.d.ts.map +0 -1
- package/dist/types/client/client.e2e-test.d.ts +0 -2
- package/dist/types/client/client.e2e-test.d.ts.map +0 -1
- package/dist/types/exports/internal.d.ts +0 -14
- package/dist/types/exports/internal.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/createSession.d.ts +0 -15
- package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -22
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -9
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -9
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/client.d.ts +0 -240
- package/dist/types/isomorphic/client.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/7702.d.ts +0 -19
- package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts +0 -24
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
- package/dist/types/local/client.d.ts +0 -4
- package/dist/types/local/client.d.ts.map +0 -1
- package/dist/types/remote/client.d.ts +0 -10
- package/dist/types/remote/client.d.ts.map +0 -1
- package/dist/types/rpc/examples.d.ts +0 -231
- package/dist/types/rpc/examples.d.ts.map +0 -1
- package/dist/types/rpc/request.d.ts +0 -712
- package/dist/types/rpc/request.d.ts.map +0 -1
- package/dist/types/rpc/schema.d.ts +0 -660
- package/dist/types/rpc/schema.d.ts.map +0 -1
- package/dist/types/schemas.d.ts +0 -694
- package/dist/types/schemas.d.ts.map +0 -1
- package/src/capabilities/eip7702Auth.ts +0 -26
- package/src/capabilities/index.ts +0 -12
- package/src/capabilities/overrides.ts +0 -35
- package/src/capabilities/paymaster.ts +0 -5
- package/src/capabilities/permissions/index.ts +0 -163
- package/src/capabilities/permissions/mav2.ts +0 -138
- package/src/client/actions/createAccount.ts +0 -53
- package/src/client/client.e2e-test.ts +0 -463
- package/src/exports/internal.ts +0 -16
- package/src/isomorphic/actions/createSession.ts +0 -151
- package/src/isomorphic/actions/getCallsStatus.ts +0 -170
- package/src/isomorphic/actions/prepareCalls.ts +0 -152
- package/src/isomorphic/actions/sendPreparedCalls.ts +0 -222
- package/src/isomorphic/client.ts +0 -94
- package/src/isomorphic/utils/7702.ts +0 -132
- package/src/isomorphic/utils/createDummySigner.ts +0 -27
- package/src/isomorphic/utils/decodeSignature.ts +0 -18
- package/src/isomorphic/utils/parsePermissionsContext.ts +0 -49
- package/src/isomorphic/utils/supportsFeature.ts +0 -34
- package/src/local/client.ts +0 -136
- package/src/remote/client.ts +0 -67
- package/src/rpc/examples.ts +0 -342
- package/src/rpc/request.ts +0 -299
- package/src/rpc/schema.ts +0 -40
- package/src/schemas.ts +0 -585
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {} from "@aa-sdk/core";
|
|
2
|
-
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { ChainNotFoundError, hexToNumber, isHex, } from "viem";
|
|
4
|
-
import { TypeCallId } from "../../schemas.js";
|
|
5
|
-
import { castToHex } from "../../utils.js";
|
|
6
|
-
import { InternalError, BaseError } from "ox/RpcResponse";
|
|
7
|
-
import { polygon, mainnet, base, worldchain, optimism, arbitrum, sepolia, polygonAmoy, baseSepolia, optimismSepolia, worldchainSepolia, arbitrumSepolia, } from "viem/chains";
|
|
8
|
-
const ReceiptStatus = {
|
|
9
|
-
reverted: "0x0",
|
|
10
|
-
success: "0x1",
|
|
11
|
-
};
|
|
12
|
-
/** EIP-5792 call status codes */
|
|
13
|
-
export const CallStatusCode = {
|
|
14
|
-
/** Batch has been received by the wallet but has not completed execution onchain */
|
|
15
|
-
PENDING: 100,
|
|
16
|
-
/** Batch has been included onchain without reverts, receipts array contains info of all calls */
|
|
17
|
-
CONFIRMED: 200,
|
|
18
|
-
/** Batch has not been included onchain and wallet will not retry */
|
|
19
|
-
OFFCHAIN_FAILURE: 400,
|
|
20
|
-
/** Batch reverted *completely* and only changes related to gas charge may have been included onchain */
|
|
21
|
-
CHAIN_RULES_FAILURE: 500,
|
|
22
|
-
/** Batch reverted *partially* and some changes related to batch calls may have been included onchain */
|
|
23
|
-
PARTIAL_CHAIN_RULES_FAILURE: 600,
|
|
24
|
-
};
|
|
25
|
-
// https://eips.ethereum.org/EIPS/eip-5792#error-codes
|
|
26
|
-
const ErrorCode = {
|
|
27
|
-
UNKNOWN_BUNDLE_ID: 5730,
|
|
28
|
-
};
|
|
29
|
-
// "eth_getUserOperationByHash" is limited to the last 150 blocks
|
|
30
|
-
// for all networks except those in this list.
|
|
31
|
-
// https://www.alchemy.com/docs/node/bundler-api/bundler-api-endpoints/eth-get-user-operation-by-hash
|
|
32
|
-
const GET_USER_OP_BY_HASH_UNLIMITED_RANGE_NETWORKS = [
|
|
33
|
-
mainnet.id,
|
|
34
|
-
sepolia.id,
|
|
35
|
-
polygon.id,
|
|
36
|
-
polygonAmoy.id,
|
|
37
|
-
base.id,
|
|
38
|
-
baseSepolia.id,
|
|
39
|
-
optimism.id,
|
|
40
|
-
optimismSepolia.id,
|
|
41
|
-
worldchain.id,
|
|
42
|
-
worldchainSepolia.id,
|
|
43
|
-
arbitrum.id,
|
|
44
|
-
arbitrumSepolia.id,
|
|
45
|
-
];
|
|
46
|
-
export async function getCallsStatus(client, callId) {
|
|
47
|
-
if (!client.chain) {
|
|
48
|
-
throw new ChainNotFoundError();
|
|
49
|
-
}
|
|
50
|
-
const { chainId, hash } = Value.Decode(TypeCallId, callId);
|
|
51
|
-
const baseResp = {
|
|
52
|
-
id: callId,
|
|
53
|
-
chainId,
|
|
54
|
-
atomic: true,
|
|
55
|
-
};
|
|
56
|
-
const result = await client.getUserOperationByHash(hash);
|
|
57
|
-
if (!result &&
|
|
58
|
-
GET_USER_OP_BY_HASH_UNLIMITED_RANGE_NETWORKS.includes(hexToNumber(chainId))) {
|
|
59
|
-
// This network has unlimited range, so we should always have a result here if the callId is valid.
|
|
60
|
-
throw new BaseError({
|
|
61
|
-
message: `callId ${callId} not found`,
|
|
62
|
-
code: ErrorCode.UNKNOWN_BUNDLE_ID,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
if (result && !result.transactionHash) {
|
|
66
|
-
// A result but no txn hash means it's valid but pending.
|
|
67
|
-
return {
|
|
68
|
-
...baseResp,
|
|
69
|
-
status: CallStatusCode.PENDING,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const receipt = await client.getUserOperationReceipt(hash);
|
|
73
|
-
if (result?.transactionHash && !receipt) {
|
|
74
|
-
// This should never happen.
|
|
75
|
-
throw new InternalError({
|
|
76
|
-
message: `Failed to get receipt for callId ${callId}`,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
if (!receipt) {
|
|
80
|
-
// This covers txns older than 150 blocks which were not retrievable by "eth_getUserOperationByHash".
|
|
81
|
-
throw new BaseError({
|
|
82
|
-
message: `callId ${callId} not found`,
|
|
83
|
-
code: ErrorCode.UNKNOWN_BUNDLE_ID,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
...baseResp,
|
|
88
|
-
status: receipt.success
|
|
89
|
-
? CallStatusCode.CONFIRMED
|
|
90
|
-
: CallStatusCode.CHAIN_RULES_FAILURE,
|
|
91
|
-
receipts: [transformReceipt(receipt.receipt)],
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function transformReceipt(receipt) {
|
|
95
|
-
return {
|
|
96
|
-
// viem's type for status is "success" | "reverted", but the actual value seems to already be 0x0 or 0x1
|
|
97
|
-
status: isHex(receipt.status)
|
|
98
|
-
? receipt.status
|
|
99
|
-
: ReceiptStatus[receipt.status],
|
|
100
|
-
blockHash: receipt.blockHash,
|
|
101
|
-
// viem's type for blockNumber is bigint, but the actual value seems to already be a hex string
|
|
102
|
-
blockNumber: castToHex(receipt.blockNumber),
|
|
103
|
-
// viem's type for gasUsed is bigint, but the actual value seems to already be a hex string
|
|
104
|
-
gasUsed: castToHex(receipt.gasUsed),
|
|
105
|
-
transactionHash: receipt.transactionHash,
|
|
106
|
-
logs: receipt.logs.map((log) => ({
|
|
107
|
-
address: log.address,
|
|
108
|
-
data: log.data,
|
|
109
|
-
topics: log.topics,
|
|
110
|
-
})),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=getCallsStatus.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getCallsStatus.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/getCallsStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,KAAK,GAKN,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EACL,OAAO,EACP,OAAO,EACP,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,WAAW,EACX,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,aAAa,CAAC;AAUrB,MAAM,aAAa,GAA8C;IAC/D,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,KAAK;CACf,CAAC;AAEF,iCAAiC;AACjC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,oFAAoF;IACpF,OAAO,EAAE,GAAG;IACZ,iGAAiG;IACjG,SAAS,EAAE,GAAG;IACd,oEAAoE;IACpE,gBAAgB,EAAE,GAAG;IACrB,wGAAwG;IACxG,mBAAmB,EAAE,GAAG;IACxB,wGAAwG;IACxG,2BAA2B,EAAE,GAAG;CACxB,CAAC;AAEX,sDAAsD;AACtD,MAAM,SAAS,GAAG;IAChB,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF,iEAAiE;AACjE,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M;SACnB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["import {\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n ChainNotFoundError,\n hexToNumber,\n isHex,\n type Chain,\n type Hex,\n type TransactionReceipt,\n type Transport,\n} from \"viem\";\nimport type { wallet_getCallsStatus } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { TypeCallId } from \"../../schemas.js\";\nimport { castToHex } from \"../../utils.js\";\nimport { InternalError, BaseError } from \"ox/RpcResponse\";\nimport {\n polygon,\n mainnet,\n base,\n worldchain,\n optimism,\n arbitrum,\n sepolia,\n polygonAmoy,\n baseSepolia,\n optimismSepolia,\n worldchainSepolia,\n arbitrumSepolia,\n} from \"viem/chains\";\n\nexport type GetCallsStatusParams = Static<\n (typeof wallet_getCallsStatus)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type GetCallsStatusResponse = Static<\n (typeof wallet_getCallsStatus)[\"properties\"][\"ReturnType\"]\n>;\n\nconst ReceiptStatus: Record<TransactionReceipt[\"status\"], Hex> = {\n reverted: \"0x0\",\n success: \"0x1\",\n};\n\n/** EIP-5792 call status codes */\nexport const CallStatusCode = {\n /** Batch has been received by the wallet but has not completed execution onchain */\n PENDING: 100,\n /** Batch has been included onchain without reverts, receipts array contains info of all calls */\n CONFIRMED: 200,\n /** Batch has not been included onchain and wallet will not retry */\n OFFCHAIN_FAILURE: 400,\n /** Batch reverted *completely* and only changes related to gas charge may have been included onchain */\n CHAIN_RULES_FAILURE: 500,\n /** Batch reverted *partially* and some changes related to batch calls may have been included onchain */\n PARTIAL_CHAIN_RULES_FAILURE: 600,\n} as const;\n\n// https://eips.ethereum.org/EIPS/eip-5792#error-codes\nconst ErrorCode = {\n UNKNOWN_BUNDLE_ID: 5730,\n};\n\n// \"eth_getUserOperationByHash\" is limited to the last 150 blocks\n// for all networks except those in this list.\n// https://www.alchemy.com/docs/node/bundler-api/bundler-api-endpoints/eth-get-user-operation-by-hash\nconst GET_USER_OP_BY_HASH_UNLIMITED_RANGE_NETWORKS: number[] = [\n mainnet.id,\n sepolia.id,\n polygon.id,\n polygonAmoy.id,\n base.id,\n baseSepolia.id,\n optimism.id,\n optimismSepolia.id,\n worldchain.id,\n worldchainSepolia.id,\n arbitrum.id,\n arbitrumSepolia.id,\n];\n\nexport async function getCallsStatus(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n callId: GetCallsStatusParams,\n): Promise<GetCallsStatusResponse> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n const { chainId, hash } = Value.Decode(TypeCallId, callId);\n\n const baseResp = {\n id: callId,\n chainId,\n atomic: true,\n };\n\n const result = await client.getUserOperationByHash(hash);\n if (\n !result &&\n GET_USER_OP_BY_HASH_UNLIMITED_RANGE_NETWORKS.includes(hexToNumber(chainId))\n ) {\n // This network has unlimited range, so we should always have a result here if the callId is valid.\n throw new BaseError({\n message: `callId ${callId} not found`,\n code: ErrorCode.UNKNOWN_BUNDLE_ID,\n });\n }\n if (result && !result.transactionHash) {\n // A result but no txn hash means it's valid but pending.\n return {\n ...baseResp,\n status: CallStatusCode.PENDING,\n };\n }\n\n const receipt = await client.getUserOperationReceipt(hash);\n if (result?.transactionHash && !receipt) {\n // This should never happen.\n throw new InternalError({\n message: `Failed to get receipt for callId ${callId}`,\n });\n }\n if (!receipt) {\n // This covers txns older than 150 blocks which were not retrievable by \"eth_getUserOperationByHash\".\n throw new BaseError({\n message: `callId ${callId} not found`,\n code: ErrorCode.UNKNOWN_BUNDLE_ID,\n });\n }\n\n return {\n ...baseResp,\n status: receipt.success\n ? CallStatusCode.CONFIRMED\n : CallStatusCode.CHAIN_RULES_FAILURE,\n receipts: [transformReceipt(receipt.receipt)],\n };\n}\n\nfunction transformReceipt(\n receipt: TransactionReceipt,\n): NonNullable<GetCallsStatusResponse[\"receipts\"]>[number] {\n return {\n // viem's type for status is \"success\" | \"reverted\", but the actual value seems to already be 0x0 or 0x1\n status: isHex(receipt.status)\n ? receipt.status\n : ReceiptStatus[receipt.status],\n blockHash: receipt.blockHash,\n // viem's type for blockNumber is bigint, but the actual value seems to already be a hex string\n blockNumber: castToHex(receipt.blockNumber),\n // viem's type for gasUsed is bigint, but the actual value seems to already be a hex string\n gasUsed: castToHex(receipt.gasUsed),\n transactionHash: receipt.transactionHash,\n logs: receipt.logs.map((log) => ({\n address: log.address,\n data: log.data,\n topics: log.topics,\n })),\n };\n}\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import type { Static } from "@sinclair/typebox";
|
|
3
|
-
import { type Chain, type Transport } from "viem";
|
|
4
|
-
import type { wallet_prepareCalls } from "../../rpc/request.js";
|
|
5
|
-
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
6
|
-
export type PrepareCallsParams = Omit<Static<(typeof wallet_prepareCalls)["properties"]["Request"]["properties"]["params"]>[0], "chainId">;
|
|
7
|
-
export type PrepareCallsResult = Static<(typeof wallet_prepareCalls)["properties"]["ReturnType"]>;
|
|
8
|
-
export declare function prepareCalls(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: PrepareCallsParams): Promise<PrepareCallsResult>;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { deepHexlify, default7702GasEstimator, } from "@aa-sdk/core";
|
|
2
|
-
import { ChainNotFoundError, custom, fromHex, hashMessage, toHex, } from "viem";
|
|
3
|
-
import { createAccount } from "../utils/createAccount.js";
|
|
4
|
-
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
5
|
-
import { createAuthorizationRequest } from "../utils/7702.js";
|
|
6
|
-
import { InvalidRequestError } from "ox/RpcResponse";
|
|
7
|
-
import { assertNever } from "../../utils.js";
|
|
8
|
-
import { assertValid7702AccountAddress } from "../utils/7702.js";
|
|
9
|
-
export async function prepareCalls(client, params) {
|
|
10
|
-
if (!client.chain) {
|
|
11
|
-
throw new ChainNotFoundError();
|
|
12
|
-
}
|
|
13
|
-
assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
|
|
14
|
-
// in local mode, we probably want some kind of caching for this
|
|
15
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
16
|
-
method: "wallet_requestAccount",
|
|
17
|
-
params: [
|
|
18
|
-
params.capabilities?.eip7702Auth
|
|
19
|
-
? {
|
|
20
|
-
signerAddress: params.from,
|
|
21
|
-
creationHint: {
|
|
22
|
-
accountType: "7702",
|
|
23
|
-
},
|
|
24
|
-
includeCounterfactualInfo: true,
|
|
25
|
-
}
|
|
26
|
-
: {
|
|
27
|
-
accountAddress: params.from,
|
|
28
|
-
includeCounterfactualInfo: true,
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
});
|
|
32
|
-
if (!counterfactualInfo && !delegation) {
|
|
33
|
-
throw new InvalidRequestError({
|
|
34
|
-
message: "No counterfactual info or delegated implementation address found.",
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const account = await createAccount({
|
|
38
|
-
chain: client.chain,
|
|
39
|
-
transport: custom(client.transport),
|
|
40
|
-
signer: createDummySigner(params.from),
|
|
41
|
-
accountAddress: params.from,
|
|
42
|
-
counterfactualInfo,
|
|
43
|
-
permissions: params.capabilities?.permissions,
|
|
44
|
-
delegation,
|
|
45
|
-
});
|
|
46
|
-
// If using 7702, we need an Authorization (unless it's already authorized).
|
|
47
|
-
const authorizationRequest = delegation
|
|
48
|
-
? await createAuthorizationRequest(client, {
|
|
49
|
-
address: account.address,
|
|
50
|
-
delegation,
|
|
51
|
-
})
|
|
52
|
-
: undefined;
|
|
53
|
-
if (authorizationRequest) {
|
|
54
|
-
// @ts-expect-error - this is available but not typed as public
|
|
55
|
-
client.middleware.gasEstimator = default7702GasEstimator();
|
|
56
|
-
}
|
|
57
|
-
// TODO: oops we don't actually support setting the policyId as an override here
|
|
58
|
-
// if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
|
|
59
|
-
const builtUo = await client.buildUserOperation({
|
|
60
|
-
uo: params.calls.map((x) => ({
|
|
61
|
-
target: x.to,
|
|
62
|
-
data: x.data ?? "0x",
|
|
63
|
-
value: x.value ? fromHex(x.value, "bigint") : undefined,
|
|
64
|
-
})),
|
|
65
|
-
account,
|
|
66
|
-
overrides: params.capabilities?.gasParamsOverride,
|
|
67
|
-
});
|
|
68
|
-
// The eip7702Auth field should never be included in the UO sig
|
|
69
|
-
// request. It's handled by a separate authorization request.
|
|
70
|
-
if ("eip7702Auth" in builtUo) {
|
|
71
|
-
builtUo.eip7702Auth = undefined;
|
|
72
|
-
}
|
|
73
|
-
const hexlifiedUo = deepHexlify(builtUo);
|
|
74
|
-
const ep = account.getEntryPoint();
|
|
75
|
-
const uoHash = ep.getUserOperationHash(hexlifiedUo);
|
|
76
|
-
const uoRequest = {
|
|
77
|
-
type: ep.version === "0.7.0"
|
|
78
|
-
? "user-operation-v070"
|
|
79
|
-
: ep.version === "0.6.0"
|
|
80
|
-
? "user-operation-v060"
|
|
81
|
-
: assertNever(ep.version, "Unexpected entry point version"),
|
|
82
|
-
data: hexlifiedUo,
|
|
83
|
-
chainId: toHex(client.chain.id),
|
|
84
|
-
signatureRequest: {
|
|
85
|
-
type: "personal_sign",
|
|
86
|
-
data: {
|
|
87
|
-
raw: uoHash,
|
|
88
|
-
},
|
|
89
|
-
rawPayload: hashMessage({
|
|
90
|
-
raw: uoHash,
|
|
91
|
-
}),
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
return authorizationRequest
|
|
95
|
-
? {
|
|
96
|
-
type: "array",
|
|
97
|
-
data: [authorizationRequest, uoRequest],
|
|
98
|
-
}
|
|
99
|
-
: uoRequest;
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=prepareCalls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,WAAW,EACX,KAAK,GAGN,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAajE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAMC,EACD,MAA0B;IAE1B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAE7E,gEAAgE;IAChE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9D,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE;YACN,MAAM,CAAC,YAAY,EAAE,WAAW;gBAC9B,CAAC,CAAC;oBACE,aAAa,EAAE,MAAM,CAAC,IAAI;oBAC1B,YAAY,EAAE;wBACZ,WAAW,EAAE,MAAM;qBACpB;oBACD,yBAAyB,EAAE,IAAI;iBAChC;gBACH,CAAC,CAAC;oBACE,cAA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C,CAAC,SAAS;SACxD,CAAC,CAAC;QACH,OAAO;QACP,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE,iBAAiB;KAClD,CAAC,CAAC;IAEH,+DAA+D;IAC/D,6DAA6D;IAC7D,IAAI,aAAa,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAClC,CAAC;IAED,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEzC,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAEnC,MAAM,MAAM,GAAG,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAEpD,MAAM,SAAS,GAAG;QAChB,IAAI,EACF,EAAE,CAAC,OAAO,KAAK,OAAO;YACpB,CAAC,CAAE,qBAA+B;YAClC,CAAC,CAAC,EAAE,CAAC,OAAO,KAAK,OAAO;gBACtB,CAAC,CAAE,qBAA+B;gBAClC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,gCAAgC,CAAC;QACjE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAwB;YAC9B,IAAI,EAAE;gBACJ,GAAG,EAAE,MAAM;aACZ;YACD,UAAU,EAAE,WAAW,CAAC;gBACtB,GAAG,EAAE,MAAM;aACZ,CAAC;SACH;KACF,CAAC;IAEF,OAAO,oBAAoB;QACzB,CAAC,CAAC;YACE,IAAI,EAAE,OAAgB;YACtB,IAAI,EAAE,CAAC,oBAAoB,EAAE,SAAS,CAAC;SACxC;QACH,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC","sourcesContent":["import {\n deepHexlify,\n default7702GasEstimator,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport {\n ChainNotFoundError,\n custom,\n fromHex,\n hashMessage,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { wallet_prepareCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorizationRequest } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport { assertValid7702AccountAddress } from \"../utils/7702.js\";\n\nexport type PrepareCallsParams = Omit<\n Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type PrepareCallsResult = Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function prepareCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);\n\n // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n params.capabilities?.eip7702Auth\n ? {\n signerAddress: params.from,\n creationHint: {\n accountType: \"7702\",\n },\n includeCounterfactualInfo: true,\n }\n : {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.from),\n accountAddress: params.from,\n counterfactualInfo,\n permissions: params.capabilities?.permissions,\n delegation,\n });\n\n // If using 7702, we need an Authorization (unless it's already authorized).\n const authorizationRequest = delegation\n ? await createAuthorizationRequest(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n if (authorizationRequest) {\n // @ts-expect-error - this is available but not typed as public\n client.middleware.gasEstimator = default7702GasEstimator();\n }\n\n // TODO: oops we don't actually support setting the policyId as an override here\n // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly\n const builtUo = await client.buildUserOperation({\n uo: params.calls.map((x) => ({\n target: x.to,\n data: x.data ?? \"0x\",\n value: x.value ? fromHex(x.value, \"bigint\") : undefined,\n })),\n account,\n overrides: params.capabilities?.gasParamsOverride,\n });\n\n // The eip7702Auth field should never be included in the UO sig\n // request. It's handled by a separate authorization request.\n if (\"eip7702Auth\" in builtUo) {\n builtUo.eip7702Auth = undefined;\n }\n\n const hexlifiedUo = deepHexlify(builtUo);\n\n const ep = account.getEntryPoint();\n\n const uoHash = ep.getUserOperationHash(hexlifiedUo);\n\n const uoRequest = {\n type:\n ep.version === \"0.7.0\"\n ? (\"user-operation-v070\" as const)\n : ep.version === \"0.6.0\"\n ? (\"user-operation-v060\" as const)\n : assertNever(ep.version, \"Unexpected entry point version\"),\n data: hexlifiedUo,\n chainId: toHex(client.chain.id),\n signatureRequest: {\n type: \"personal_sign\" as const,\n data: {\n raw: uoHash,\n },\n rawPayload: hashMessage({\n raw: uoHash,\n }),\n },\n };\n\n return authorizationRequest\n ? {\n type: \"array\" as const,\n data: [authorizationRequest, uoRequest],\n }\n : uoRequest;\n}\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import { type Chain, type Transport } from "viem";
|
|
3
|
-
import { type wallet_sendPreparedCalls } from "../../rpc/request.js";
|
|
4
|
-
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
5
|
-
import type { Static } from "@sinclair/typebox";
|
|
6
|
-
export type SendPreparedCallsParams = Static<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0];
|
|
7
|
-
export type SendPreparedCallsResult = Static<(typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]>;
|
|
8
|
-
export declare function sendPreparedCalls(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: SendPreparedCallsParams): Promise<SendPreparedCallsResult>;
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { getEntryPoint, } from "@aa-sdk/core";
|
|
2
|
-
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { BaseError, ChainNotFoundError, concat, concatHex, numberToHex, parseSignature, toHex, } from "viem";
|
|
4
|
-
import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
|
|
5
|
-
import {} from "../../rpc/request.js";
|
|
6
|
-
import { TypeCallId } from "../../schemas.js";
|
|
7
|
-
import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
|
|
8
|
-
import { InvalidRequestError } from "ox/RpcResponse";
|
|
9
|
-
import { assertNever } from "../../utils.js";
|
|
10
|
-
import { decodeSignature } from "../utils/decodeSignature.js";
|
|
11
|
-
// TODO: this only supports MAv2 right now, we need to fix this
|
|
12
|
-
export async function sendPreparedCalls(client, params) {
|
|
13
|
-
if (!client.chain) {
|
|
14
|
-
throw new ChainNotFoundError();
|
|
15
|
-
}
|
|
16
|
-
const deferredAction = (() => {
|
|
17
|
-
if (!params.capabilities?.permissions) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const decodedContext = decodePermissionsContext(params.capabilities.permissions);
|
|
21
|
-
if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
|
|
22
|
-
throw new InvalidRequestError({
|
|
23
|
-
message: "Remote mode deferred action not supported in isomorphic client",
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return decodedContext.deferredAction;
|
|
27
|
-
})();
|
|
28
|
-
const userOps = params.type === "array"
|
|
29
|
-
? params.data.filter((it) => {
|
|
30
|
-
const isUserOp = it.type === "user-operation-v060" ||
|
|
31
|
-
it.type === "user-operation-v070";
|
|
32
|
-
if (isUserOp && it.chainId !== toHex(client.chain.id)) {
|
|
33
|
-
throw new InvalidRequestError({
|
|
34
|
-
message: "Multiple chain IDs in a single request are not currently supported.",
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return isUserOp;
|
|
38
|
-
})
|
|
39
|
-
: [params];
|
|
40
|
-
const authorizations = params.type === "array"
|
|
41
|
-
? params.data.filter((it) => it.type === "authorization")
|
|
42
|
-
: [];
|
|
43
|
-
if (authorizations.length > 1) {
|
|
44
|
-
throw new InvalidRequestError({
|
|
45
|
-
message: "Multiple authorizations in a single request are not currently supported",
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const [authorization] = authorizations;
|
|
49
|
-
// One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
|
|
50
|
-
if (authorization &&
|
|
51
|
-
!isSupportedDelegationAddress7702(authorization.data.address)) {
|
|
52
|
-
throw new InvalidRequestError({
|
|
53
|
-
message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
const hashes = await Promise.all(userOps.map(async (userOp, idx) => {
|
|
57
|
-
const ep = userOp.type === "user-operation-v060"
|
|
58
|
-
? getEntryPoint(client.chain, { version: "0.6.0" })
|
|
59
|
-
: userOp.type === "user-operation-v070"
|
|
60
|
-
? getEntryPoint(client.chain, { version: "0.7.0" })
|
|
61
|
-
: assertNever(userOp, "Unexpected user op type");
|
|
62
|
-
const authSig = authorization
|
|
63
|
-
? parseSignature(decodeSignature(authorization.signature).data)
|
|
64
|
-
: undefined;
|
|
65
|
-
const uoSigHex = decodeSignature(userOp.signature).data;
|
|
66
|
-
const { counterfactualInfo, delegation } = await client.request({
|
|
67
|
-
method: "wallet_requestAccount",
|
|
68
|
-
params: [
|
|
69
|
-
{
|
|
70
|
-
accountAddress: userOp.data.sender,
|
|
71
|
-
includeCounterfactualInfo: true,
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
});
|
|
75
|
-
if (!counterfactualInfo && !delegation) {
|
|
76
|
-
throw new InvalidRequestError({
|
|
77
|
-
message: "No counterfactual info or delegated implementation address found.",
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
const factoryType = counterfactualInfo?.factoryType;
|
|
81
|
-
// build signature based on account type
|
|
82
|
-
const signature = (() => {
|
|
83
|
-
switch (factoryType) {
|
|
84
|
-
// light accounts
|
|
85
|
-
case "LightAccountV1.0.1":
|
|
86
|
-
case "LightAccountV1.0.2":
|
|
87
|
-
case "LightAccountV1.1.0":
|
|
88
|
-
// For LAv1, we always just pass the signature.
|
|
89
|
-
return uoSigHex;
|
|
90
|
-
case "LightAccountV2.0.0":
|
|
91
|
-
// for LAv2, we need to prepend the "SignatureType.EOA" byte
|
|
92
|
-
return concat(["0x00", uoSigHex]);
|
|
93
|
-
case undefined: // undefined defaults to sma-b
|
|
94
|
-
case "MAv2.0.0-sma-b":
|
|
95
|
-
// For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
|
|
96
|
-
// Signature Segment" and "SignatureType.EOA" bytes
|
|
97
|
-
return deferredAction != null
|
|
98
|
-
? concatHex([
|
|
99
|
-
`0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
|
|
100
|
-
"0xFF",
|
|
101
|
-
"0x00",
|
|
102
|
-
uoSigHex,
|
|
103
|
-
])
|
|
104
|
-
: concat(["0xFF", "0x00", uoSigHex]);
|
|
105
|
-
case "MAv2.0.0-ma-ssv":
|
|
106
|
-
case "MAv2.0.0-ma-webauthn":
|
|
107
|
-
case "LightAccountV2.0.0-MultiOwner":
|
|
108
|
-
case "MAv1.0.0-MultiOwner":
|
|
109
|
-
case "MAv1.0.0-MultiSig":
|
|
110
|
-
case "unknown":
|
|
111
|
-
throw new InvalidRequestError({
|
|
112
|
-
message: `Unsupported factory type: ${factoryType}`,
|
|
113
|
-
});
|
|
114
|
-
default:
|
|
115
|
-
return assertNever(factoryType, "Unsupported factory type");
|
|
116
|
-
}
|
|
117
|
-
})();
|
|
118
|
-
return client
|
|
119
|
-
.sendRawUserOperation({
|
|
120
|
-
...userOp.data,
|
|
121
|
-
signature,
|
|
122
|
-
eip7702Auth: idx === 0 && authorization && authSig
|
|
123
|
-
? {
|
|
124
|
-
...authorization.data,
|
|
125
|
-
chainId: authorization.chainId,
|
|
126
|
-
...{
|
|
127
|
-
...authSig,
|
|
128
|
-
yParity: numberToHex(authSig.yParity),
|
|
129
|
-
},
|
|
130
|
-
}
|
|
131
|
-
: undefined,
|
|
132
|
-
}, ep.address)
|
|
133
|
-
.catch((err) => {
|
|
134
|
-
if (err instanceof BaseError &&
|
|
135
|
-
err.details.endsWith("is not a contract and initCode is empty")) {
|
|
136
|
-
throw new BaseError(`${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`);
|
|
137
|
-
}
|
|
138
|
-
throw err;
|
|
139
|
-
});
|
|
140
|
-
}));
|
|
141
|
-
return {
|
|
142
|
-
preparedCallIds: hashes.map((hash) => Value.Encode(TypeCallId, {
|
|
143
|
-
chainId: toHex(client.chain.id),
|
|
144
|
-
hash,
|
|
145
|
-
})),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
//# sourceMappingURL=sendPreparedCalls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,WAAW,EACX,cAAc,EACd,KAAK,GAKN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAiC,MAAM,sBAAsB,CAAC;AAErE,OAAO,EAAE,U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CACnC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;YACvB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,IAAI;SACL,CAAC,CACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n getEntryPoint,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n BaseError,\n ChainNotFoundError,\n concat,\n concatHex,\n numberToHex,\n parseSignature,\n toHex,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport { type wallet_sendPreparedCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { TypeCallId } from \"../../schemas.js\";\nimport { isSupportedDelegationAddress7702 } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { decodeSignature } from \"../utils/decodeSignature.js\";\n\nexport type SendPreparedCallsParams = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type SendPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"ReturnType\"]\n>;\n\n// TODO: this only supports MAv2 right now, we need to fix this\nexport async function sendPreparedCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message:\n \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return decodedContext.deferredAction;\n })();\n\n const userOps =\n params.type === \"array\"\n ? params.data.filter((it) => {\n const isUserOp =\n it.type === \"user-operation-v060\" ||\n it.type === \"user-operation-v070\";\n if (isUserOp && it.chainId !== toHex(client.chain.id)) {\n throw new InvalidRequestError({\n message:\n \"Multiple chain IDs in a single request are not currently supported.\",\n });\n }\n return isUserOp;\n })\n : [params];\n\n const authorizations =\n params.type === \"array\"\n ? params.data.filter((it) => it.type === \"authorization\")\n : [];\n\n if (authorizations.length > 1) {\n throw new InvalidRequestError({\n message:\n \"Multiple authorizations in a single request are not currently supported\",\n });\n }\n const [authorization] = authorizations;\n\n // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.\n if (\n authorization &&\n !isSupportedDelegationAddress7702(authorization.data.address)\n ) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${authorization.data.address}`,\n });\n }\n\n const hashes = await Promise.all(\n userOps.map(async (userOp, idx) => {\n const ep: { address: Address } =\n userOp.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : userOp.type === \"user-operation-v070\"\n ? getEntryPoint(client.chain, { version: \"0.7.0\" })\n : assertNever(userOp, \"Unexpected user op type\");\n const authSig = authorization\n ? parseSignature(decodeSignature(authorization.signature).data)\n : undefined;\n const uoSigHex = decodeSignature(userOp.signature).data;\n\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: userOp.data.sender,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const factoryType = counterfactualInfo?.factoryType;\n\n // build signature based on account type\n const signature = (() => {\n switch (factoryType) {\n // light accounts\n case \"LightAccountV1.0.1\":\n case \"LightAccountV1.0.2\":\n case \"LightAccountV1.1.0\":\n // For LAv1, we always just pass the signature.\n return uoSigHex;\n case \"LightAccountV2.0.0\":\n // for LAv2, we need to prepend the \"SignatureType.EOA\" byte\n return concat([\"0x00\", uoSigHex]);\n case undefined: // undefined defaults to sma-b\n case \"MAv2.0.0-sma-b\":\n // For sma-b, we need to handle deferred actions if needed and prepend the \"Reserved\n // Signature Segment\" and \"SignatureType.EOA\" bytes\n return deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).\n \"0xFF\",\n \"0x00\",\n uoSigHex,\n ])\n : concat([\"0xFF\", \"0x00\", uoSigHex]);\n case \"MAv2.0.0-ma-ssv\":\n case \"MAv2.0.0-ma-webauthn\":\n case \"LightAccountV2.0.0-MultiOwner\":\n case \"MAv1.0.0-MultiOwner\":\n case \"MAv1.0.0-MultiSig\":\n case \"unknown\":\n throw new InvalidRequestError({\n message: `Unsupported factory type: ${factoryType}`,\n });\n default:\n return assertNever(factoryType, \"Unsupported factory type\");\n }\n })();\n\n return client\n .sendRawUserOperation(\n {\n ...userOp.data,\n signature,\n eip7702Auth:\n idx === 0 && authorization && authSig\n ? {\n ...authorization.data,\n chainId: authorization.chainId,\n ...{\n ...authSig,\n yParity: numberToHex(authSig.yParity),\n },\n }\n : undefined,\n },\n ep.address,\n )\n .catch((err) => {\n if (\n err instanceof BaseError &&\n err.details.endsWith(\"is not a contract and initCode is empty\")\n ) {\n throw new BaseError(\n `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,\n );\n }\n throw err;\n });\n }),\n );\n\n return {\n preparedCallIds: hashes.map((hash) =>\n Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n }),\n ),\n };\n}\n"]}
|