@account-kit/wallet-client 0.1.0-alpha.4 → 0.1.0-alpha.5
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/esm/capabilities/eip7702Auth.d.ts +4 -0
- package/dist/esm/capabilities/eip7702Auth.js +16 -0
- package/dist/esm/capabilities/eip7702Auth.js.map +1 -0
- package/dist/esm/capabilities/index.d.ts +4 -0
- package/dist/esm/capabilities/index.js +2 -0
- package/dist/esm/capabilities/index.js.map +1 -1
- package/dist/esm/capabilities/permissions/index.d.ts +1 -1
- package/dist/esm/capabilities/permissions/mav2.js +1 -0
- package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
- package/dist/esm/client/actions/getCallsStatus.d.ts +1 -2
- package/dist/esm/client/actions/getCallsStatus.js +19 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +6 -6
- package/dist/esm/client/actions/grantPermissions.js +115 -3
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +4 -4
- package/dist/esm/client/actions/prepareCalls.js +38 -5
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.d.ts +3 -4
- package/dist/esm/client/actions/requestAccount.js +18 -1
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +3 -3
- package/dist/esm/client/actions/signMessage.js +18 -0
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/esm/client/actions/signSignatureRequest.js +2 -2
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +2 -2
- package/dist/esm/client/actions/signTypedData.js +31 -0
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +19 -19
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +4 -4
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +35 -10
- package/dist/esm/client/index.js +0 -29
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/isomorphic/actions/createSession.js +21 -10
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/getCallsStatus.js +62 -9
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.js +18 -11
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +2 -2
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +1 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +9 -3
- package/dist/esm/isomorphic/utils/7702.js +35 -8
- package/dist/esm/isomorphic/utils/7702.js.map +1 -1
- package/dist/esm/isomorphic/utils/createAccount.d.ts +2 -2
- package/dist/esm/isomorphic/utils/createAccount.js +4 -3
- package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +2 -2
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +8 -7
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
- package/dist/esm/local/client.d.ts +2 -2
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.d.ts +8 -2
- package/dist/esm/remote/client.js +1 -7
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/rpc/request.d.ts +12 -2
- package/dist/esm/rpc/request.js +6 -9
- package/dist/esm/rpc/request.js.map +1 -1
- package/dist/esm/rpc/schema.d.ts +23 -13
- package/dist/esm/schemas.d.ts +3 -1
- package/dist/esm/schemas.js +6 -4
- package/dist/esm/schemas.js.map +1 -1
- package/dist/esm/types.d.ts +7 -10
- package/dist/esm/types.js.map +1 -1
- package/dist/types/capabilities/eip7702Auth.d.ts +5 -0
- package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -0
- package/dist/types/capabilities/index.d.ts +4 -0
- package/dist/types/capabilities/index.d.ts.map +1 -1
- package/dist/types/capabilities/permissions/index.d.ts +1 -1
- package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
- package/dist/types/client/actions/getCallsStatus.d.ts +1 -2
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +6 -6
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +4 -4
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts +3 -4
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +3 -3
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +2 -2
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +4 -4
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +35 -10
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +9 -3
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts +2 -2
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +2 -2
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
- package/dist/types/local/client.d.ts +2 -2
- package/dist/types/local/client.d.ts.map +1 -1
- package/dist/types/remote/client.d.ts +8 -2
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/rpc/request.d.ts +12 -2
- package/dist/types/rpc/request.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +23 -13
- package/dist/types/rpc/schema.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +3 -1
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/types.d.ts +7 -10
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/capabilities/eip7702Auth.ts +19 -0
- package/src/capabilities/index.ts +2 -0
- package/src/capabilities/permissions/mav2.ts +1 -0
- package/src/client/actions/getCallsStatus.ts +0 -10
- package/src/client/actions/grantPermissions.ts +12 -25
- package/src/client/actions/prepareCalls.ts +18 -23
- package/src/client/actions/requestAccount.ts +9 -26
- package/src/client/actions/signMessage.ts +2 -17
- package/src/client/actions/signSignatureRequest.ts +5 -5
- package/src/client/actions/signTypedData.ts +1 -16
- package/src/client/client.e2e-test.ts +22 -22
- package/src/client/decorator.ts +5 -10
- package/src/client/index.ts +16 -39
- package/src/isomorphic/actions/createSession.ts +29 -10
- package/src/isomorphic/actions/getCallsStatus.ts +82 -10
- package/src/isomorphic/actions/prepareCalls.ts +19 -11
- package/src/isomorphic/actions/sendPreparedCalls.ts +2 -2
- package/src/isomorphic/utils/7702.ts +61 -13
- package/src/isomorphic/utils/createAccount.ts +5 -5
- package/src/isomorphic/utils/parsePermissionsContext.ts +9 -9
- package/src/local/client.ts +3 -5
- package/src/remote/client.ts +5 -13
- package/src/rpc/request.ts +8 -9
- package/src/schemas.ts +8 -4
- package/src/types.ts +5 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSession.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/createSession.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAGzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,iBAAiB,GAClB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,WAAW,EACX,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"createSession.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/createSession.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAGzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,iBAAiB,GAClB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,WAAW,EACX,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,e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B,GAAG;QACvB,IAAI,EAAE,sBAA+B;QACrC,IAAI,EAAE,SAAS;KAChB,CAAC;IAEF,OAAO;QACL,SAAS,EAAE,IAAI,EAAE,kDAAkD;QACnE,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;QACzB,gBAAgB,EAAE;YAChB,GAAG,gBAAgB;YACnB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D;QACD,oCAAoC;KACrC,CAAC;AACJ,CAAC","sourcesContent":["import {\n createSmartAccountClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport {\n deferralActions,\n PermissionBuilder,\n} from \"@account-kit/smart-contracts/experimental\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n ChainNotFoundError,\n custom,\n hexToNumber,\n toHex,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { TypePermission } from \"../../capabilities/permissions/index.js\";\nimport { isGlobalValidation } from \"../../capabilities/permissions/mav2.js\";\nimport type { wallet_createSession } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { createAccount, isModularAccountV2 } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorization } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport {\n parseDelegation,\n assertValid7702AccountAddress,\n} from \"../utils/7702.js\";\n\nexport type CreateSessionParams = Omit<\n Static<\n (typeof wallet_createSession)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n> & {\n entityId?: Hex;\n};\n\nexport type CreateSessionResult = Omit<\n Static<(typeof wallet_createSession)[\"properties\"][\"ReturnType\"]>,\n \"sessionId\"\n> & {\n sessionId: Hex | null;\n entityId: Hex;\n fullPreSignatureDeferredActionDigest: Hex;\n};\n\nexport async function createSession(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: CreateSessionParams,\n): Promise<CreateSessionResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n assertValid7702AccountAddress(\n params.account,\n params.capabilities?.eip7702Auth,\n );\n\n const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth\n ? {\n counterfactualInfo: undefined,\n delegation: parseDelegation(params.capabilities.eip7702Auth),\n }\n : await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.account,\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.account),\n accountAddress: params.account,\n counterfactualInfo,\n delegation,\n });\n\n if (!isModularAccountV2(account)) {\n throw new InvalidRequestError({\n message: \"Sessions are currently only supported by MAv2 accounts.\",\n });\n }\n\n const _client = createSmartAccountClient({\n chain: client.chain,\n transport: custom(client.transport),\n account,\n }).extend(deferralActions);\n\n const { entityId, nonce } = await _client.getEntityIdAndNonce({\n entityId: params.entityId ? hexToNumber(params.entityId) : undefined,\n isGlobalValidation: isGlobalValidation(params),\n });\n\n const { typedData, fullPreSignatureDeferredActionDigest } =\n await new PermissionBuilder({\n client: _client,\n key: {\n ...params.key,\n // Alias 'ecdsa' to 'secp256k1'\n type: params.key.type === \"ecdsa\" ? \"secp256k1\" : params.key.type,\n },\n entityId,\n nonce,\n deadline: params.expiry,\n })\n .addPermissions({\n permissions: params.permissions.map((permission) =>\n Value.Encode(TypePermission, permission),\n ),\n })\n .compileDeferred();\n\n // If using 7702, we need an Authorization (unless it's already authorized).\n const authorizationRequest = delegation\n ? await createAuthorization(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n const signatureRequest = {\n type: \"eth_signTypedData_v4\" as const,\n data: typedData,\n };\n\n return {\n sessionId: null, // In remote mode, the server will set this later.\n entityId: toHex(entityId),\n signatureRequest: {\n ...signatureRequest,\n ...(authorizationRequest ? { authorizationRequest } : {}),\n },\n fullPreSignatureDeferredActionDigest,\n };\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {} from "@aa-sdk/core";
|
|
2
2
|
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { ChainNotFoundError, isHex, } from "viem";
|
|
3
|
+
import { ChainNotFoundError, hexToNumber, isHex, } from "viem";
|
|
4
4
|
import { TypeCallId } from "../../schemas.js";
|
|
5
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";
|
|
6
8
|
const ReceiptStatus = {
|
|
7
9
|
reverted: "0x0",
|
|
8
10
|
success: "0x1",
|
|
@@ -20,22 +22,73 @@ export const CallStatusCode = {
|
|
|
20
22
|
/** Batch reverted *partially* and some changes related to batch calls may have been included onchain */
|
|
21
23
|
PARTIAL_CHAIN_RULES_FAILURE: 600,
|
|
22
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
|
+
];
|
|
23
46
|
export async function getCallsStatus(client, callId) {
|
|
24
47
|
if (!client.chain) {
|
|
25
48
|
throw new ChainNotFoundError();
|
|
26
49
|
}
|
|
27
50
|
const { chainId, hash } = Value.Decode(TypeCallId, callId);
|
|
28
|
-
const
|
|
29
|
-
return {
|
|
51
|
+
const baseResp = {
|
|
30
52
|
id: callId,
|
|
31
53
|
chainId,
|
|
32
54
|
atomic: true,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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)],
|
|
39
92
|
};
|
|
40
93
|
}
|
|
41
94
|
function transformReceipt(receipt) {
|
|
@@ -1 +1 @@
|
|
|
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,KAAK,GAKN,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
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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IAE3B,OAAO;QACL,wGAAwG;QACxG,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAC3B,CAAC,CAAC,OAAO,CAAC,MAAM;YAChB,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;QACjC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,+FAA+F;QAC/F,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC;QAC3C,2FAA2F;QAC3F,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;QACnC,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC/B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,MAAM,EAAE,GAAG,CAAC,MAAM;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"]}
|
|
@@ -2,22 +2,29 @@ import { deepHexlify, default7702GasEstimator, } from "@aa-sdk/core";
|
|
|
2
2
|
import { ChainNotFoundError, custom, fromHex, toHex, } from "viem";
|
|
3
3
|
import { createAccount } from "../utils/createAccount.js";
|
|
4
4
|
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
5
|
-
import { createAuthorization } from "../utils/7702.js";
|
|
5
|
+
import { createAuthorization, parseDelegation } from "../utils/7702.js";
|
|
6
6
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
7
|
+
import { assertValid7702AccountAddress } from "../utils/7702.js";
|
|
7
8
|
export async function prepareCalls(client, params) {
|
|
8
9
|
if (!client.chain) {
|
|
9
10
|
throw new ChainNotFoundError();
|
|
10
11
|
}
|
|
12
|
+
assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
|
|
11
13
|
// in local mode, we probably want some kind of caching for this
|
|
12
|
-
const { counterfactualInfo, delegation } =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth
|
|
15
|
+
? {
|
|
16
|
+
counterfactualInfo: undefined,
|
|
17
|
+
delegation: parseDelegation(params.capabilities.eip7702Auth),
|
|
18
|
+
}
|
|
19
|
+
: await client.request({
|
|
20
|
+
method: "wallet_requestAccount",
|
|
21
|
+
params: [
|
|
22
|
+
{
|
|
23
|
+
accountAddress: params.from,
|
|
24
|
+
includeCounterfactualInfo: true,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
});
|
|
21
28
|
if (!counterfactualInfo && !delegation) {
|
|
22
29
|
throw new InvalidRequestError({
|
|
23
30
|
message: "No counterfactual info or delegated implementation address found.",
|
|
@@ -29,7 +36,7 @@ export async function prepareCalls(client, params) {
|
|
|
29
36
|
signer: createDummySigner(params.from),
|
|
30
37
|
accountAddress: params.from,
|
|
31
38
|
counterfactualInfo,
|
|
32
|
-
|
|
39
|
+
permissions: params.capabilities?.permissions,
|
|
33
40
|
delegation,
|
|
34
41
|
});
|
|
35
42
|
// If using 7702, we need an Authorization (unless it's already authorized).
|
|
@@ -1 +1 @@
|
|
|
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,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,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;
|
|
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,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,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,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,CAAC,YAAY,EAAE,WAAW;QACzE,CAAC,CAAC;YACE,kBAAkB,EAAE,SAAS;YAC7B,U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,CAAC,EAAE;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI;YACpB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;SACxD,CAAC,CAAC;QACH,OAAO;QACP,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE,iBAAiB;KAClD,CAAC,CAAC;IAEH,+DAA+D;IAC/D,+DAA+D;IAC/D,IAAI,aAAa,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAClC,CAAC;IACD,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEvC,MAAM,gBAAgB,GAAG;QACvB,IAAI,EAAE,eAAwB;QAC9B,IAAI,EAAE;YACJ,GAAG,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,oBAAoB,CAAC,SAAS,CAAC;SAC7D;KACF,CAAC;IAEF,OAAO;QACL,IAAI,EACF,OAAO,CAAC,aAAa,EAAE,CAAC,OAAO,KAAK,OAAO;YACzC,CAAC,CAAC,qBAAqB;YACvB,CAAC,CAAC,qBAAqB;QAC3B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,GAAG,gBAAgB;YACnB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D;KACF,CAAC;AACJ,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 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 { createAuthorization, parseDelegation } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\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 } = params.capabilities?.eip7702Auth\n ? {\n counterfactualInfo: undefined,\n delegation: parseDelegation(params.capabilities.eip7702Auth),\n }\n : await client.request({\n method: \"wallet_requestAccount\",\n params: [\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 createAuthorization(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 the separate authorization request.\n if (\"eip7702Auth\" in builtUo) {\n builtUo.eip7702Auth = undefined;\n }\n const uoRequest = deepHexlify(builtUo);\n\n const signatureRequest = {\n type: \"personal_sign\" as const,\n data: {\n raw: account.getEntryPoint().getUserOperationHash(uoRequest),\n },\n };\n\n return {\n type:\n account.getEntryPoint().version === \"0.7.0\"\n ? \"user-operation-v070\"\n : \"user-operation-v060\",\n data: uoRequest,\n chainId: toHex(client.chain.id),\n signatureRequest: {\n ...signatureRequest,\n ...(authorizationRequest ? { authorizationRequest } : {}),\n },\n };\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { Value } from "@sinclair/typebox/value";
|
|
|
3
3
|
import { BaseError, ChainNotFoundError, concat, concatHex, toHex, } from "viem";
|
|
4
4
|
import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
|
|
5
5
|
import { TypeCallId } from "../../schemas.js";
|
|
6
|
-
import {
|
|
6
|
+
import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
|
|
7
7
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
8
8
|
// TODO: this only supports MAv2 right now, we need to fix this
|
|
9
9
|
export async function sendPreparedCalls(client, params) {
|
|
@@ -12,7 +12,7 @@ export async function sendPreparedCalls(client, params) {
|
|
|
12
12
|
}
|
|
13
13
|
// One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
|
|
14
14
|
if (params.signedAuthorization &&
|
|
15
|
-
!
|
|
15
|
+
!isSupportedDelegationAddress7702(params.signedAuthorization.address)) {
|
|
16
16
|
throw new InvalidRequestError({
|
|
17
17
|
message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,
|
|
18
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAarD,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAMC,EACD,MAA+B;IAE/B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,6GAA6G;IAC7G,IACE,MAAM,CAAC,mBAAmB;QAC1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AC,SAAS,CAAC,CAAC;QAC1D,WAAW,EAAE,MAAM,CAAC,mBAAmB;KACxC,EACD,UAAU,CAAC,OAAO,CACnB;SACA,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IACE,GAAG,YAAY,SAAS;YACxB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,yCAAyC,CAAC,EAC/D,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,GAAG,GAAG,CAAC,OAAO,iGAAiG,CAChH,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;IAEL,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;QACtC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,IAAI;KACL,CAAC,CAAC;IAEH,OAAO;QACL,eAAe,EAAE,CAAC,MAAM,CAAC;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import {\n getEntryPoint,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static, StaticDecode } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n BaseError,\n ChainNotFoundError,\n concat,\n concatHex,\n toHex,\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\";\n\nexport type SendPreparedCallsParams = Omit<\n StaticDecode<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\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 // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.\n if (\n params.signedAuthorization &&\n !isSupportedDelegationAddress7702(params.signedAuthorization.address)\n ) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,\n });\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 entryPoint =\n params.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : getEntryPoint(client.chain, { version: \"0.7.0\" });\n\n const hash = await client\n .sendRawUserOperation(\n {\n ...params.data,\n signature:\n deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).\n \"0xff\",\n \"0x00\",\n params.signature.signature,\n ])\n : concat([\"0xFF\", \"0x00\", params.signature.signature]),\n eip7702Auth: params.signedAuthorization,\n },\n entryPoint.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 'signedAuthorization' field in the request parameters)`,\n );\n }\n throw err;\n });\n\n const callId = Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n });\n\n return {\n preparedCallIds: [callId],\n };\n}\n"]}
|
|
@@ -13,7 +13,7 @@ type ClientParams = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare function isomorphicClientActions(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>): {
|
|
15
15
|
prepareCalls: (params: PrepareCallsParams) => Promise<{
|
|
16
|
-
type: "user-operation-
|
|
16
|
+
type: "user-operation-v060" | "user-operation-v070";
|
|
17
17
|
chainId: `0x${string}`;
|
|
18
18
|
data: {
|
|
19
19
|
sender: `0x${string}`;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import { type Authorization, type Address, type Chain, type Transport } from "viem";
|
|
3
3
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
4
|
+
import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
|
|
5
|
+
import type { Static } from "@sinclair/typebox";
|
|
4
6
|
export declare const createAuthorization: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
|
|
5
7
|
address: Address;
|
|
6
8
|
delegation: Address;
|
|
7
9
|
}) => Promise<Authorization<number, false> | undefined>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const EIP_7702_ACCOUNT_TYPE: readonly ["ModularAccountV2"];
|
|
11
|
+
type Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];
|
|
12
|
+
export declare const SUPPORTED_DELEGATION_ADDRESSES: "0x69007702764179f14F51cdce752f4f775d74E139"[];
|
|
13
|
+
export declare const isSupportedDelegationAddress7702: (address: Address) => boolean;
|
|
14
|
+
export declare const getAccountTypeForDelegationAddress7702: (address: Address) => Supported7702AccountType | undefined;
|
|
15
|
+
export declare const parseDelegation: (eip7702AuthCapability: Static<typeof Eip7702AuthCapability>) => "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
16
|
+
export declare const assertValid7702AccountAddress: (fromAddress: Address, eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined) => void;
|
|
11
17
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { concatHex, } from "viem";
|
|
1
|
+
import { concatHex, isAddress, } from "viem";
|
|
2
|
+
import { InvalidRequestError } from "ox/RpcResponse";
|
|
2
3
|
export const createAuthorization = async (client, params) => {
|
|
3
4
|
const expectedCode = concatHex(["0xef0100", params.delegation]);
|
|
4
5
|
const code = (await client.getCode({ address: params.address })) ?? "0x";
|
|
@@ -13,14 +14,40 @@ export const createAuthorization = async (client, params) => {
|
|
|
13
14
|
}),
|
|
14
15
|
};
|
|
15
16
|
};
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
export const EIP_7702_ACCOUNT_TYPE = ["ModularAccountV2"];
|
|
18
|
+
const Eip7702AccountTypeToDelegationAddress = {
|
|
19
|
+
ModularAccountV2: "0x69007702764179f14F51cdce752f4f775d74E139",
|
|
18
20
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
const DelegationAddressToAccountType = Object.fromEntries(Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
|
|
22
|
+
value,
|
|
23
|
+
key,
|
|
24
|
+
]));
|
|
25
|
+
export const SUPPORTED_DELEGATION_ADDRESSES = Object.values(Eip7702AccountTypeToDelegationAddress);
|
|
26
|
+
export const isSupportedDelegationAddress7702 = (address) => {
|
|
27
|
+
return SUPPORTED_DELEGATION_ADDRESSES.includes(address);
|
|
21
28
|
};
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
export const getAccountTypeForDelegationAddress7702 = (address) => {
|
|
30
|
+
return DelegationAddressToAccountType[address];
|
|
31
|
+
};
|
|
32
|
+
const getDelegationAddressForAccountType7702 = (accountType) => {
|
|
33
|
+
return Eip7702AccountTypeToDelegationAddress[accountType];
|
|
34
|
+
};
|
|
35
|
+
const DEFAULT_7702_DELEGATION_ADDR = Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
|
|
36
|
+
export const parseDelegation = (eip7702AuthCapability) => {
|
|
37
|
+
return eip7702AuthCapability === true
|
|
38
|
+
? DEFAULT_7702_DELEGATION_ADDR
|
|
39
|
+
: isAddress(eip7702AuthCapability.delegation)
|
|
40
|
+
? eip7702AuthCapability.delegation
|
|
41
|
+
: getDelegationAddressForAccountType7702(eip7702AuthCapability.delegation);
|
|
42
|
+
};
|
|
43
|
+
export const assertValid7702AccountAddress = (fromAddress, eip7702AuthCapability) => {
|
|
44
|
+
if (eip7702AuthCapability &&
|
|
45
|
+
typeof eip7702AuthCapability === "object" &&
|
|
46
|
+
"account" in eip7702AuthCapability &&
|
|
47
|
+
eip7702AuthCapability?.account !== fromAddress) {
|
|
48
|
+
throw new InvalidRequestError({
|
|
49
|
+
message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
25
52
|
};
|
|
26
53
|
//# sourceMappingURL=7702.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,
|
|
1
|
+
{"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAKT,SAAS,GACV,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAMC,EACD,MAAiD,EACE,EAAE;IACrD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO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,MAAM,4BAA4B,GAChC,qCAAqC,CAAC,kBAAkB,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,qBAA2D,EAC3D,EAAE;IACF,OAAO,qBAAqB,KAAK,IAAI;QACnC,CAAC,CAAC,4BAA4B;QAC9B,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,UAAU,CAAC;YAC3C,CAAC,CAAC,qBAAqB,CAAC,UAAU;YAClC,CAAC,CAAC,sCAAsC,CACpC,qBAAqB,CAAC,UAAU,CACjC,CAAC;AACV,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,WAAoB,EACpB,qBAAuE,EACvE,EAAE;IACF,IACE,qBAAqB;QACrB,OAAO,qBAAqB,KAAK,QAAQ;QACzC,SAAS,IAAI,qBAAqB;QAClC,qBAAqB,EAAE,OAAO,KAAK,WAAW,EAC9C,CAAC;QACD,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,+BAA+B,qBAAqB,CAAC,OAAO,8BAA8B,WAAW,GAAG;SAClH,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n concatHex,\n type Authorization,\n type Address,\n type Chain,\n type Transport,\n isAddress,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport type { Eip7702AuthCapability } from \"../../capabilities/eip7702Auth.ts\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\n\nexport const createAuthorization = async (\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: { address: Address; delegation: Address },\n): Promise<Authorization<number, false> | undefined> => {\n const expectedCode = concatHex([\"0xef0100\", params.delegation]);\n const code = (await client.getCode({ address: params.address })) ?? \"0x\";\n if (code.toLowerCase() === expectedCode.toLowerCase()) {\n return undefined; // Already authorized.\n }\n return {\n chainId: client.chain.id,\n address: params.delegation,\n nonce: await client.getTransactionCount({\n address: params.address,\n }),\n };\n};\n\nexport const EIP_7702_ACCOUNT_TYPE = [\"ModularAccountV2\"] as const;\n\ntype Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];\n\nconst Eip7702AccountTypeToDelegationAddress = {\n ModularAccountV2: \"0x69007702764179f14F51cdce752f4f775d74E139\",\n} as const satisfies Record<Supported7702AccountType, Address>;\n\nconst DelegationAddressToAccountType: Record<\n Address,\n Supported7702AccountType\n> = Object.fromEntries(\n Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [\n value,\n key,\n ]),\n) as Record<Address, Supported7702AccountType>;\n\nexport const SUPPORTED_DELEGATION_ADDRESSES = Object.values(\n Eip7702AccountTypeToDelegationAddress,\n);\n\nexport const isSupportedDelegationAddress7702 = (address: Address): boolean => {\n return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);\n};\n\nexport const getAccountTypeForDelegationAddress7702 = (\n address: Address,\n): Supported7702AccountType | undefined => {\n return DelegationAddressToAccountType[address];\n};\n\nconst getDelegationAddressForAccountType7702 = (\n accountType: Supported7702AccountType,\n): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {\n return Eip7702AccountTypeToDelegationAddress[accountType];\n};\n\nconst DEFAULT_7702_DELEGATION_ADDR =\n Eip7702AccountTypeToDelegationAddress[\"ModularAccountV2\"];\n\nexport const parseDelegation = (\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability>,\n) => {\n return eip7702AuthCapability === true\n ? DEFAULT_7702_DELEGATION_ADDR\n : isAddress(eip7702AuthCapability.delegation)\n ? eip7702AuthCapability.delegation\n : getDelegationAddressForAccountType7702(\n eip7702AuthCapability.delegation,\n );\n};\n\nexport const assertValid7702AccountAddress = (\n fromAddress: Address,\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined,\n) => {\n if (\n eip7702AuthCapability &&\n typeof eip7702AuthCapability === \"object\" &&\n \"account\" in eip7702AuthCapability &&\n eip7702AuthCapability?.account !== fromAddress\n ) {\n throw new InvalidRequestError({\n message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,\n });\n }\n};\n"]}
|
|
@@ -2,16 +2,16 @@ import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
|
|
|
2
2
|
import { type ModularAccountV2 } from "@account-kit/smart-contracts";
|
|
3
3
|
import type { StaticDecode } from "@sinclair/typebox";
|
|
4
4
|
import type { Address, Chain, Transport } from "viem";
|
|
5
|
-
import type { Capabilities } from "../../capabilities/index.js";
|
|
6
5
|
import type { TypeSerializedInitcode } from "../../schemas.js";
|
|
6
|
+
import { PermissionsCapability } from "../../capabilities/permissions/index.js";
|
|
7
7
|
type CreateAccountParams = {
|
|
8
8
|
chain: Chain;
|
|
9
9
|
transport: Transport;
|
|
10
10
|
signer: SmartAccountSigner;
|
|
11
11
|
accountAddress: Address;
|
|
12
12
|
counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>;
|
|
13
|
+
permissions?: StaticDecode<typeof PermissionsCapability>;
|
|
13
14
|
delegation?: Address;
|
|
14
|
-
capabilities?: StaticDecode<typeof Capabilities>;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Creates a smart account instance from the given parameters.
|
|
@@ -2,8 +2,9 @@ import { createModularAccountV2, } from "@account-kit/smart-contracts";
|
|
|
2
2
|
import { concatHex, hexToNumber } from "viem";
|
|
3
3
|
import { parsePermissionsContext } from "./parsePermissionsContext.js";
|
|
4
4
|
import { assertNever } from "../../utils.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
|
|
6
6
|
import { InternalError } from "ox/RpcResponse";
|
|
7
|
+
import { PermissionsCapability } from "../../capabilities/permissions/index.js";
|
|
7
8
|
/**
|
|
8
9
|
* Creates a smart account instance from the given parameters.
|
|
9
10
|
* @param params - The parameters for creating a smart account.
|
|
@@ -25,7 +26,7 @@ export async function createAccount(params) {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
else if (mode === "7702") {
|
|
28
|
-
const accountType =
|
|
29
|
+
const accountType = getAccountTypeForDelegationAddress7702(params.delegation);
|
|
29
30
|
if (accountType !== "ModularAccountV2") {
|
|
30
31
|
throw new InternalError({
|
|
31
32
|
message: "7702 mode currently only supports ModularAccountV2",
|
|
@@ -35,7 +36,7 @@ export async function createAccount(params) {
|
|
|
35
36
|
else {
|
|
36
37
|
assertNever(mode, "Unexpected mode in createAccount");
|
|
37
38
|
}
|
|
38
|
-
const parsedContext = parsePermissionsContext(params.
|
|
39
|
+
const parsedContext = parsePermissionsContext(params.permissions, ci, params.delegation);
|
|
39
40
|
const signerEntity = parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
|
|
40
41
|
? {
|
|
41
42
|
entityId: hexToNumber(parsedContext.entityId),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAccount.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createAccount.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,GAEvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"createAccount.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createAccount.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,GAEvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,sCAAsC,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CA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a,CAAC,kBAAkB;SACrD;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,0DAA0D;IAC1D,OAAO,sBAAsB,CAAC;QAC5B,GAAG,aAAa;QAChB,YAAY;QACZ,cAAc,EAAE,aAAa,EAAE,cAAc;QAC7C,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QACzE,IAAI;KACL,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAA6B;IAE7B,OAAO,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC/C,CAAC","sourcesContent":["import type { SmartAccountSigner, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n createModularAccountV2,\n type ModularAccountV2,\n} from \"@account-kit/smart-contracts\";\nimport type { StaticDecode } from \"@sinclair/typebox\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport { concatHex, hexToNumber } from \"viem\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport { parsePermissionsContext } from \"./parsePermissionsContext.js\";\nimport { assertNever } from \"../../utils.js\";\nimport { getAccountTypeForDelegationAddress7702 } from \"./7702.js\";\nimport { InternalError } from \"ox/RpcResponse\";\nimport { PermissionsCapability } from \"../../capabilities/permissions/index.js\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartAccountSigner;\n accountAddress: Address;\n counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts\n permissions?: StaticDecode<typeof PermissionsCapability>;\n delegation?: Address;\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n * @param params - The parameters for creating a smart account.\n * @returns A promise that resolves to the created smart account.\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, ...accountParams } = params;\n\n const mode = params.delegation ? \"7702\" : \"default\";\n\n if (mode === \"default\") {\n if (!ci) {\n throw new InternalError({\n message: \"Counterfactual info not found\",\n });\n }\n if (ci.factoryType !== \"MAv2.0.0-sma-b\") {\n throw new InternalError({\n message: `Factory type ${ci.factoryType} is not currently supported.`,\n });\n }\n } else if (mode === \"7702\") {\n const accountType = getAccountTypeForDelegationAddress7702(\n params.delegation!,\n );\n if (accountType !== \"ModularAccountV2\") {\n throw new InternalError({\n message: \"7702 mode currently only supports ModularAccountV2\",\n });\n }\n } else {\n assertNever(mode, \"Unexpected mode in createAccount\");\n }\n\n const parsedContext = parsePermissionsContext(\n params.permissions,\n ci,\n params.delegation,\n );\n\n const signerEntity =\n parsedContext?.contextVersion === \"NON_DEFERRED_ACTION\"\n ? {\n entityId: hexToNumber(parsedContext.entityId),\n isGlobalValidation: parsedContext.isGlobalValidation,\n }\n : undefined;\n\n // TODO: clean this up to support different account types.\n return createModularAccountV2({\n ...accountParams,\n signerEntity,\n deferredAction: parsedContext?.deferredAction,\n initCode: ci ? concatHex([ci.factoryAddress, ci.factoryData]) : undefined,\n mode,\n });\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { StaticDecode } from "@sinclair/typebox";
|
|
2
2
|
import type { TypeSerializedInitcode } from "../../schemas.js";
|
|
3
|
-
import type { PrepareCallsParams } from "../actions/prepareCalls.js";
|
|
4
3
|
import type { Address } from "viem";
|
|
5
|
-
|
|
4
|
+
import { PermissionsCapability } from "../../capabilities/permissions/index.js";
|
|
5
|
+
export declare function parsePermissionsContext(permissions?: StaticDecode<typeof PermissionsCapability>, parsedCi?: StaticDecode<typeof TypeSerializedInitcode> | undefined, delegation7702?: Address): ({
|
|
6
6
|
contextVersion: keyof typeof import("../../exports/internal.js").PermissionsContextVersion;
|
|
7
7
|
} & {
|
|
8
8
|
contextVersion: "LOCAL_MODE_DEFERRED_ACTION";
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
2
2
|
import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
|
|
4
|
+
import { PermissionsCapability } from "../../capabilities/permissions/index.js";
|
|
5
|
+
export function parsePermissionsContext(permissions, parsedCi, delegation7702) {
|
|
6
|
+
if (!permissions) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
if ("sessionId" in
|
|
9
|
+
if ("sessionId" in permissions) {
|
|
9
10
|
throw new InvalidRequestError({
|
|
10
11
|
message: "Remote permissions are not supported in isomorphic client",
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
|
-
if (!("context" in
|
|
14
|
+
if (!("context" in permissions)) {
|
|
14
15
|
return undefined;
|
|
15
16
|
}
|
|
16
17
|
const isMAV2 = (parsedCi && parsedCi.factoryType === "MAv2.0.0-sma-b") ||
|
|
17
18
|
(delegation7702 &&
|
|
18
|
-
|
|
19
|
+
getAccountTypeForDelegationAddress7702(delegation7702) ===
|
|
19
20
|
"ModularAccountV2");
|
|
20
21
|
if (!isMAV2) {
|
|
21
22
|
throw new InvalidRequestError({
|
|
22
23
|
message: "Permissions are currently only supported by MAv2 accounts",
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
|
-
const context = decodePermissionsContext(
|
|
26
|
+
const context = decodePermissionsContext(permissions);
|
|
26
27
|
if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
|
|
27
28
|
throw new InvalidRequestError({
|
|
28
29
|
message: "Remote mode deferred action not supported in isomorphic client",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePermissionsContext.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/parsePermissionsContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"parsePermissionsContext.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/parsePermissionsContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,sCAAsC,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAEhF,MAAM,UAAU,uBAAuB,CACrC,WAAwD,EACxD,QAAkE,EAClE,cAAwB;IAExB,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,CAAC,SAAS,IAAI,WAAW,CAAC,EAAE,CAAC;QAChC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GACV,CAAC,QAAQ,IAAI,QAAQ,CAAC,WAAW,KAAK,gBAAgB,CAAC;QACvD,CAAC,cAAc;YACb,sCAAsC,CAAC,cAAc,CAAC;gBACpD,kBAAkB,CAAC,CAAC;IAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IAEtD,IAAI,OAAO,EAAE,cAAc,KAAK,6BAA6B,EAAE,CAAC;QAC9D,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,gEAAgE;SAC1E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { StaticDecode } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport type { Address } from \"viem\";\nimport { getAccountTypeForDelegationAddress7702 } from \"./7702.js\";\nimport { PermissionsCapability } from \"../../capabilities/permissions/index.js\";\n\nexport function parsePermissionsContext(\n permissions?: StaticDecode<typeof PermissionsCapability>,\n parsedCi?: StaticDecode<typeof TypeSerializedInitcode> | undefined,\n delegation7702?: Address,\n) {\n if (!permissions) {\n return undefined;\n }\n\n if (\"sessionId\" in permissions) {\n throw new InvalidRequestError({\n message: \"Remote permissions are not supported in isomorphic client\",\n });\n }\n\n if (!(\"context\" in permissions)) {\n return undefined;\n }\n\n const isMAV2 =\n (parsedCi && parsedCi.factoryType === \"MAv2.0.0-sma-b\") ||\n (delegation7702 &&\n getAccountTypeForDelegationAddress7702(delegation7702) ===\n \"ModularAccountV2\");\n\n if (!isMAV2) {\n throw new InvalidRequestError({\n message: \"Permissions are currently only supported by MAv2 accounts\",\n });\n }\n\n const context = decodePermissionsContext(permissions);\n\n if (context?.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message: \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return context;\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type Address
|
|
1
|
+
import { type Address } from "viem";
|
|
2
2
|
import type { CreateInnerClientParams, InnerWalletApiClient } from "../types.ts";
|
|
3
|
-
export declare function createLocalClient<TAccount extends
|
|
3
|
+
export declare function createLocalClient<TAccount extends Address | undefined = Address | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
|