@account-kit/wallet-client 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +18 -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/overrides.js +8 -8
- package/dist/esm/capabilities/overrides.js.map +1 -1
- package/dist/esm/capabilities/permissions/index.d.ts +2 -2
- package/dist/esm/capabilities/permissions/index.js +6 -3
- package/dist/esm/capabilities/permissions/index.js.map +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 +10 -65
- package/dist/esm/client/actions/grantPermissions.js +63 -4
- 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/sendPreparedCalls.d.ts +6 -14
- package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
- package/dist/esm/client/actions/sendPreparedCalls.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/signPreparedCalls.d.ts +14 -0
- package/dist/esm/client/actions/signPreparedCalls.js +53 -0
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
- package/dist/esm/client/actions/signSignatureRequest.d.ts +9 -8
- package/dist/esm/client/actions/signSignatureRequest.js +69 -31
- 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 +47 -44
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +7 -5
- package/dist/esm/client/decorator.js +3 -1
- 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/exports/index.d.ts +2 -1
- package/dist/esm/exports/index.js +2 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/isomorphic/actions/createSession.js +15 -18
- 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 +39 -26
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +77 -37
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +139 -13
- package/dist/esm/isomorphic/utils/7702.d.ts +13 -6
- package/dist/esm/isomorphic/utils/7702.js +48 -13
- 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/decodeSignature.d.ts +3 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
- 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 +2 -3
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.d.ts +8 -2
- package/dist/esm/remote/client.js +3 -13
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/rpc/examples.d.ts +3 -3
- package/dist/esm/rpc/examples.js +3 -3
- package/dist/esm/rpc/examples.js.map +1 -1
- package/dist/esm/rpc/request.d.ts +362 -44
- package/dist/esm/rpc/request.js +26 -56
- package/dist/esm/rpc/request.js.map +1 -1
- package/dist/esm/rpc/schema.d.ts +325 -49
- package/dist/esm/rpc/schema.js.map +1 -1
- package/dist/esm/schemas.d.ts +454 -14
- package/dist/esm/schemas.js +168 -53
- package/dist/esm/schemas.js.map +1 -1
- package/dist/esm/types.d.ts +10 -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 +2 -2
- package/dist/types/capabilities/permissions/index.d.ts.map +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 +10 -65
- 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/sendPreparedCalls.d.ts +6 -14
- package/dist/types/client/actions/sendPreparedCalls.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/signPreparedCalls.d.ts +15 -0
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
- package/dist/types/client/actions/signSignatureRequest.d.ts +9 -8
- 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 +7 -5
- 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/exports/index.d.ts +2 -1
- package/dist/types/exports/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/actions/sendPreparedCalls.d.ts +3 -3
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +139 -13
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +13 -6
- 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/decodeSignature.d.ts +4 -0
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
- 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/examples.d.ts +3 -3
- package/dist/types/rpc/examples.d.ts.map +1 -1
- package/dist/types/rpc/request.d.ts +362 -44
- package/dist/types/rpc/request.d.ts.map +1 -1
- package/dist/types/rpc/schema.d.ts +325 -49
- package/dist/types/rpc/schema.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +454 -14
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/types/types.d.ts +10 -10
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/capabilities/eip7702Auth.ts +26 -0
- package/src/capabilities/index.ts +2 -0
- package/src/capabilities/overrides.ts +8 -8
- package/src/capabilities/permissions/index.ts +8 -3
- package/src/capabilities/permissions/mav2.ts +1 -0
- package/src/client/actions/getCallsStatus.ts +0 -10
- package/src/client/actions/grantPermissions.ts +16 -84
- package/src/client/actions/prepareCalls.ts +18 -23
- package/src/client/actions/requestAccount.ts +9 -26
- package/src/client/actions/sendPreparedCalls.ts +17 -17
- package/src/client/actions/signMessage.ts +2 -17
- package/src/client/actions/signPreparedCalls.ts +71 -0
- package/src/client/actions/signSignatureRequest.ts +51 -47
- package/src/client/actions/signTypedData.ts +1 -16
- package/src/client/client.e2e-test.ts +54 -57
- package/src/client/decorator.ts +19 -15
- package/src/client/index.ts +16 -39
- package/src/exports/index.ts +2 -1
- package/src/isomorphic/actions/createSession.ts +17 -20
- package/src/isomorphic/actions/getCallsStatus.ts +82 -10
- package/src/isomorphic/actions/prepareCalls.ts +43 -27
- package/src/isomorphic/actions/sendPreparedCalls.ts +105 -55
- package/src/isomorphic/utils/7702.ts +79 -21
- package/src/isomorphic/utils/createAccount.ts +5 -5
- package/src/isomorphic/utils/decodeSignature.ts +18 -0
- package/src/isomorphic/utils/parsePermissionsContext.ts +9 -9
- package/src/local/client.ts +5 -11
- package/src/remote/client.ts +7 -22
- package/src/rpc/examples.ts +3 -4
- package/src/rpc/request.ts +41 -64
- package/src/rpc/schema.ts +2 -2
- package/src/schemas.ts +232 -54
- package/src/types.ts +9 -21
|
@@ -6,7 +6,6 @@ import { TypePermission } from "../../capabilities/permissions/index.js";
|
|
|
6
6
|
import { isGlobalValidation } from "../../capabilities/permissions/mav2.js";
|
|
7
7
|
import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
|
|
8
8
|
import { createDummySigner } from "../utils/createDummySigner.js";
|
|
9
|
-
import { createAuthorization } from "../utils/7702.js";
|
|
10
9
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
11
10
|
export async function createSession(client, params) {
|
|
12
11
|
if (!client.chain) {
|
|
@@ -21,9 +20,14 @@ export async function createSession(client, params) {
|
|
|
21
20
|
},
|
|
22
21
|
],
|
|
23
22
|
});
|
|
24
|
-
if (
|
|
23
|
+
if (delegation) {
|
|
25
24
|
throw new InvalidRequestError({
|
|
26
|
-
message: "
|
|
25
|
+
message: "'wallet_createSession' does not currently support 7702 accounts.",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (!counterfactualInfo) {
|
|
29
|
+
throw new InvalidRequestError({
|
|
30
|
+
message: "No counterfactual info found.",
|
|
27
31
|
});
|
|
28
32
|
}
|
|
29
33
|
const account = await createAccount({
|
|
@@ -50,32 +54,25 @@ export async function createSession(client, params) {
|
|
|
50
54
|
});
|
|
51
55
|
const { typedData, fullPreSignatureDeferredActionDigest } = await new PermissionBuilder({
|
|
52
56
|
client: _client,
|
|
53
|
-
key:
|
|
57
|
+
key: {
|
|
58
|
+
...params.key,
|
|
59
|
+
// Alias 'ecdsa' to 'secp256k1'
|
|
60
|
+
type: params.key.type === "ecdsa" ? "secp256k1" : params.key.type,
|
|
61
|
+
},
|
|
54
62
|
entityId,
|
|
55
63
|
nonce,
|
|
56
|
-
deadline: params.
|
|
64
|
+
deadline: params.expirySec,
|
|
57
65
|
})
|
|
58
66
|
.addPermissions({
|
|
59
67
|
permissions: params.permissions.map((permission) => Value.Encode(TypePermission, permission)),
|
|
60
68
|
})
|
|
61
69
|
.compileDeferred();
|
|
62
|
-
// If using 7702, we need an Authorization (unless it's already authorized).
|
|
63
|
-
const authorizationRequest = delegation
|
|
64
|
-
? await createAuthorization(client, {
|
|
65
|
-
address: account.address,
|
|
66
|
-
delegation,
|
|
67
|
-
})
|
|
68
|
-
: undefined;
|
|
69
|
-
const signatureRequest = {
|
|
70
|
-
type: "eth_signTypedData_v4",
|
|
71
|
-
data: typedData,
|
|
72
|
-
};
|
|
73
70
|
return {
|
|
74
71
|
sessionId: null, // In remote mode, the server will set this later.
|
|
75
72
|
entityId: toHex(entityId),
|
|
76
73
|
signatureRequest: {
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
type: "eth_signTypedData_v4",
|
|
75
|
+
data: typedData,
|
|
79
76
|
},
|
|
80
77
|
fullPreSignatureDeferredActionDigest,
|
|
81
78
|
};
|
|
@@ -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,
|
|
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,gBAAgB,CAAC;AAoBrD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAMC,EACD,MAA2B;IAE3B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9D,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE;YACN;gBACE,cAAc,EAAE,MAAM,CAAC,OAAO;gBAC9B,yBAAyB,EAAE,IAAI;aAChC;SACF;KACF,CAAC,CAAC;IAEH,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EACL,kEAAkE;SACrE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE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ACL,QAAQ,EAAE,MAAM,CAAC,SAAS;KAC3B,CAAC;SACC,cAAc,CAAC;QACd,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACjD,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CACzC;KACF,CAAC;SACD,eAAe,EAAE,CAAC;IAEvB,OAAO;QACL,SAAS,EAAE,IAAI,EAAE,kDAAkD;QACnE,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;QACzB,gBAAgB,EAAE;YAChB,IAAI,EAAE,sBAA+B;YACrC,IAAI,EAAE,SAAS;SAChB;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 { InvalidRequestError } from \"ox/RpcResponse\";\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 const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.account,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (delegation) {\n throw new InvalidRequestError({\n message:\n \"'wallet_createSession' does not currently support 7702 accounts.\",\n });\n }\n\n if (!counterfactualInfo) {\n throw new InvalidRequestError({\n message: \"No counterfactual info 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.expirySec,\n })\n .addPermissions({\n permissions: params.permissions.map((permission) =>\n Value.Encode(TypePermission, permission),\n ),\n })\n .compileDeferred();\n\n return {\n sessionId: null, // In remote mode, the server will set this later.\n entityId: toHex(entityId),\n signatureRequest: {\n type: \"eth_signTypedData_v4\" as const,\n data: typedData,\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,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;A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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,30 @@ 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 {
|
|
5
|
+
import { createAuthorizationRequest, parseDelegation } from "../utils/7702.js";
|
|
6
6
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
7
|
+
import { assertNever } from "../../utils.js";
|
|
8
|
+
import { assertValid7702AccountAddress } from "../utils/7702.js";
|
|
7
9
|
export async function prepareCalls(client, params) {
|
|
8
10
|
if (!client.chain) {
|
|
9
11
|
throw new ChainNotFoundError();
|
|
10
12
|
}
|
|
13
|
+
assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
|
|
11
14
|
// in local mode, we probably want some kind of caching for this
|
|
12
|
-
const { counterfactualInfo, delegation } =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth
|
|
16
|
+
? {
|
|
17
|
+
counterfactualInfo: undefined,
|
|
18
|
+
delegation: parseDelegation(params.capabilities.eip7702Auth),
|
|
19
|
+
}
|
|
20
|
+
: await client.request({
|
|
21
|
+
method: "wallet_requestAccount",
|
|
22
|
+
params: [
|
|
23
|
+
{
|
|
24
|
+
accountAddress: params.from,
|
|
25
|
+
includeCounterfactualInfo: true,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
21
29
|
if (!counterfactualInfo && !delegation) {
|
|
22
30
|
throw new InvalidRequestError({
|
|
23
31
|
message: "No counterfactual info or delegated implementation address found.",
|
|
@@ -29,12 +37,12 @@ export async function prepareCalls(client, params) {
|
|
|
29
37
|
signer: createDummySigner(params.from),
|
|
30
38
|
accountAddress: params.from,
|
|
31
39
|
counterfactualInfo,
|
|
32
|
-
|
|
40
|
+
permissions: params.capabilities?.permissions,
|
|
33
41
|
delegation,
|
|
34
42
|
});
|
|
35
43
|
// If using 7702, we need an Authorization (unless it's already authorized).
|
|
36
44
|
const authorizationRequest = delegation
|
|
37
|
-
? await
|
|
45
|
+
? await createAuthorizationRequest(client, {
|
|
38
46
|
address: account.address,
|
|
39
47
|
delegation,
|
|
40
48
|
})
|
|
@@ -55,27 +63,32 @@ export async function prepareCalls(client, params) {
|
|
|
55
63
|
overrides: params.capabilities?.gasParamsOverride,
|
|
56
64
|
});
|
|
57
65
|
// The eip7702Auth field should never be included in the UO sig
|
|
58
|
-
// request. It's handled by
|
|
66
|
+
// request. It's handled by a separate authorization request.
|
|
59
67
|
if ("eip7702Auth" in builtUo) {
|
|
60
68
|
builtUo.eip7702Auth = undefined;
|
|
61
69
|
}
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
raw: account.getEntryPoint().getUserOperationHash(uoRequest),
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
type: account.getEntryPoint().version === "0.7.0"
|
|
70
|
+
const hexlifiedUo = deepHexlify(builtUo);
|
|
71
|
+
const ep = account.getEntryPoint();
|
|
72
|
+
const uoRequest = {
|
|
73
|
+
type: ep.version === "0.7.0"
|
|
71
74
|
? "user-operation-v070"
|
|
72
|
-
: "
|
|
73
|
-
|
|
75
|
+
: ep.version === "0.6.0"
|
|
76
|
+
? "user-operation-v060"
|
|
77
|
+
: assertNever(ep.version, "Unexpected entry point version"),
|
|
78
|
+
data: hexlifiedUo,
|
|
74
79
|
chainId: toHex(client.chain.id),
|
|
75
80
|
signatureRequest: {
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
type: "personal_sign",
|
|
82
|
+
data: {
|
|
83
|
+
raw: ep.getUserOperationHash(hexlifiedUo),
|
|
84
|
+
},
|
|
78
85
|
},
|
|
79
86
|
};
|
|
87
|
+
return authorizationRequest
|
|
88
|
+
? {
|
|
89
|
+
type: "array",
|
|
90
|
+
data: [authorizationRequest, uoRequest],
|
|
91
|
+
}
|
|
92
|
+
: uoRequest;
|
|
80
93
|
}
|
|
81
94
|
//# sourceMappingURL=prepareCalls.js.map
|
|
@@ -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,OA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AQ,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,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,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,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC;aAC1C;SACF;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 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, parseDelegation } 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 } = 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 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 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: ep.getUserOperationHash(hexlifiedUo),\n },\n },\n };\n\n return authorizationRequest\n ? {\n type: \"array\" as const,\n data: [authorizationRequest, uoRequest],\n }\n : uoRequest;\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
-
import type { Static, StaticDecode } from "@sinclair/typebox";
|
|
3
2
|
import { type Chain, type Transport } from "viem";
|
|
4
|
-
import type
|
|
3
|
+
import { type wallet_sendPreparedCalls } from "../../rpc/request.js";
|
|
5
4
|
import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
|
|
6
|
-
|
|
5
|
+
import type { Static } from "@sinclair/typebox";
|
|
6
|
+
export type SendPreparedCallsParams = Static<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0];
|
|
7
7
|
export type SendPreparedCallsResult = Static<(typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]>;
|
|
8
8
|
export declare function sendPreparedCalls(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: SendPreparedCallsParams): Promise<SendPreparedCallsResult>;
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { getEntryPoint, } from "@aa-sdk/core";
|
|
2
2
|
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { BaseError, ChainNotFoundError, concat, concatHex, toHex, } from "viem";
|
|
3
|
+
import { BaseError, ChainNotFoundError, concat, concatHex, numberToHex, parseSignature, toHex, } from "viem";
|
|
4
4
|
import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
|
|
5
|
+
import {} from "../../rpc/request.js";
|
|
5
6
|
import { TypeCallId } from "../../schemas.js";
|
|
6
|
-
import {
|
|
7
|
+
import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
|
|
7
8
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
9
|
+
import { assertNever } from "../../utils.js";
|
|
10
|
+
import { decodeSignature } from "../utils/decodeSignature.js";
|
|
8
11
|
// TODO: this only supports MAv2 right now, we need to fix this
|
|
9
12
|
export async function sendPreparedCalls(client, params) {
|
|
10
13
|
if (!client.chain) {
|
|
11
14
|
throw new ChainNotFoundError();
|
|
12
15
|
}
|
|
13
|
-
// One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
|
|
14
|
-
if (params.signedAuthorization &&
|
|
15
|
-
!isSupportedImplementationAddress7702(params.signedAuthorization.address)) {
|
|
16
|
-
throw new InvalidRequestError({
|
|
17
|
-
message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
16
|
const deferredAction = (() => {
|
|
21
17
|
if (!params.capabilities?.permissions) {
|
|
22
18
|
return;
|
|
@@ -29,35 +25,79 @@ export async function sendPreparedCalls(client, params) {
|
|
|
29
25
|
}
|
|
30
26
|
return decodedContext.deferredAction;
|
|
31
27
|
})();
|
|
32
|
-
const
|
|
33
|
-
?
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
return client
|
|
67
|
+
.sendRawUserOperation({
|
|
68
|
+
...userOp.data,
|
|
69
|
+
signature: deferredAction != null
|
|
70
|
+
? concatHex([
|
|
71
|
+
`0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc. that we had previously).
|
|
72
|
+
"0xff",
|
|
73
|
+
"0x00",
|
|
74
|
+
uoSigHex,
|
|
75
|
+
])
|
|
76
|
+
: concat(["0xFF", "0x00", uoSigHex]),
|
|
77
|
+
eip7702Auth: idx === 0 && authorization && authSig
|
|
78
|
+
? {
|
|
79
|
+
...authorization.data,
|
|
80
|
+
chainId: authorization.chainId,
|
|
81
|
+
...{
|
|
82
|
+
...authSig,
|
|
83
|
+
yParity: numberToHex(authSig.yParity),
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
: undefined,
|
|
87
|
+
}, ep.address)
|
|
88
|
+
.catch((err) => {
|
|
89
|
+
if (err instanceof BaseError &&
|
|
90
|
+
err.details.endsWith("is not a contract and initCode is empty")) {
|
|
91
|
+
throw new BaseError(`${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`);
|
|
92
|
+
}
|
|
93
|
+
throw err;
|
|
94
|
+
});
|
|
95
|
+
}));
|
|
59
96
|
return {
|
|
60
|
-
preparedCallIds:
|
|
97
|
+
preparedCallIds: hashes.map((hash) => Value.Encode(TypeCallId, {
|
|
98
|
+
chainId: toHex(client.chain.id),
|
|
99
|
+
hash,
|
|
100
|
+
})),
|
|
61
101
|
};
|
|
62
102
|
}
|
|
63
103
|
//# sourceMappingURL=sendPreparedCalls.js.map
|
|
@@ -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;
|
|
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,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAU9D,+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,MAAM,cAAc,GAAoB,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;YACtC,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,wBAAwB,CAC7C,MAAM,CAAC,YAAY,CAAC,WAAW,CAChC,CAAC;QAEF,IAAI,cAAc,CAAC,cAAc,K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BACrB,OAAO,EAAE,aAAa,CAAC,OAAO;oBAC9B,GAAG;wBACD,GAAG,OAAO;wBACV,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC;qBACtC;iBACF;gBACH,CAAC,CAAC,SAAS;SAChB,EACD,EAAE,CAAC,OAAO,CACX;aACA,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,IACE,GAAG,YAAY,SAAS;gBACxB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,yCAAyC,CAAC,EAC/D,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,GAAG,GAAG,CAAC,OAAO,0FAA0F,CACzG,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,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 return client\n .sendRawUserOperation(\n {\n ...userOp.data,\n signature:\n deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc. that we had previously).\n \"0xff\",\n \"0x00\",\n uoSigHex,\n ])\n : concat([\"0xFF\", \"0x00\", uoSigHex]),\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"]}
|