@account-kit/wallet-client 0.1.0-alpha.5 → 0.1.0-alpha.7

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.
Files changed (121) hide show
  1. package/dist/esm/capabilities/eip7702Auth.js +3 -1
  2. package/dist/esm/capabilities/eip7702Auth.js.map +1 -1
  3. package/dist/esm/capabilities/overrides.js +8 -8
  4. package/dist/esm/capabilities/overrides.js.map +1 -1
  5. package/dist/esm/capabilities/permissions/index.d.ts +1 -1
  6. package/dist/esm/capabilities/permissions/index.js +6 -3
  7. package/dist/esm/capabilities/permissions/index.js.map +1 -1
  8. package/dist/esm/client/actions/grantPermissions.d.ts +5 -60
  9. package/dist/esm/client/actions/grantPermissions.js +5 -58
  10. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  11. package/dist/esm/client/actions/requestAccount.js +5 -2
  12. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  13. package/dist/esm/client/actions/sendPreparedCalls.d.ts +6 -14
  14. package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
  15. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  16. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  17. package/dist/esm/client/actions/signPreparedCalls.js +54 -0
  18. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  19. package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -7
  20. package/dist/esm/client/actions/signSignatureRequest.js +69 -31
  21. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  22. package/dist/esm/client/client.e2e-test.js +80 -24
  23. package/dist/esm/client/client.e2e-test.js.map +1 -1
  24. package/dist/esm/client/decorator.d.ts +3 -1
  25. package/dist/esm/client/decorator.js +3 -1
  26. package/dist/esm/client/decorator.js.map +1 -1
  27. package/dist/esm/exports/index.d.ts +2 -1
  28. package/dist/esm/exports/index.js +2 -1
  29. package/dist/esm/exports/index.js.map +1 -1
  30. package/dist/esm/isomorphic/actions/createSession.js +18 -32
  31. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  32. package/dist/esm/isomorphic/actions/prepareCalls.js +22 -16
  33. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  34. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  35. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +76 -36
  36. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  37. package/dist/esm/isomorphic/client.d.ts +139 -13
  38. package/dist/esm/isomorphic/utils/7702.d.ts +4 -3
  39. package/dist/esm/isomorphic/utils/7702.js +14 -6
  40. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  41. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  42. package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
  43. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  44. package/dist/esm/local/client.js +2 -3
  45. package/dist/esm/local/client.js.map +1 -1
  46. package/dist/esm/remote/client.js +3 -7
  47. package/dist/esm/remote/client.js.map +1 -1
  48. package/dist/esm/rpc/examples.d.ts +3 -3
  49. package/dist/esm/rpc/examples.js +3 -3
  50. package/dist/esm/rpc/examples.js.map +1 -1
  51. package/dist/esm/rpc/request.d.ts +357 -49
  52. package/dist/esm/rpc/request.js +26 -53
  53. package/dist/esm/rpc/request.js.map +1 -1
  54. package/dist/esm/rpc/schema.d.ts +323 -57
  55. package/dist/esm/rpc/schema.js.map +1 -1
  56. package/dist/esm/schemas.d.ts +451 -13
  57. package/dist/esm/schemas.js +165 -52
  58. package/dist/esm/schemas.js.map +1 -1
  59. package/dist/esm/types.d.ts +3 -0
  60. package/dist/esm/types.js.map +1 -1
  61. package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -1
  62. package/dist/types/capabilities/permissions/index.d.ts +1 -1
  63. package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
  64. package/dist/types/client/actions/grantPermissions.d.ts +5 -60
  65. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  66. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  67. package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
  68. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  69. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  70. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  71. package/dist/types/client/actions/signSignatureRequest.d.ts +8 -7
  72. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  73. package/dist/types/client/decorator.d.ts +3 -1
  74. package/dist/types/client/decorator.d.ts.map +1 -1
  75. package/dist/types/exports/index.d.ts +2 -1
  76. package/dist/types/exports/index.d.ts.map +1 -1
  77. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  78. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  79. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  80. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  81. package/dist/types/isomorphic/client.d.ts +139 -13
  82. package/dist/types/isomorphic/client.d.ts.map +1 -1
  83. package/dist/types/isomorphic/utils/7702.d.ts +4 -3
  84. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  85. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  86. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  87. package/dist/types/remote/client.d.ts.map +1 -1
  88. package/dist/types/rpc/examples.d.ts +3 -3
  89. package/dist/types/rpc/examples.d.ts.map +1 -1
  90. package/dist/types/rpc/request.d.ts +357 -49
  91. package/dist/types/rpc/request.d.ts.map +1 -1
  92. package/dist/types/rpc/schema.d.ts +323 -57
  93. package/dist/types/rpc/schema.d.ts.map +1 -1
  94. package/dist/types/schemas.d.ts +451 -13
  95. package/dist/types/schemas.d.ts.map +1 -1
  96. package/dist/types/types.d.ts +3 -0
  97. package/dist/types/types.d.ts.map +1 -1
  98. package/package.json +5 -5
  99. package/src/capabilities/eip7702Auth.ts +17 -10
  100. package/src/capabilities/overrides.ts +8 -8
  101. package/src/capabilities/permissions/index.ts +8 -3
  102. package/src/client/actions/grantPermissions.ts +5 -60
  103. package/src/client/actions/requestAccount.ts +10 -8
  104. package/src/client/actions/sendPreparedCalls.ts +17 -17
  105. package/src/client/actions/signPreparedCalls.ts +72 -0
  106. package/src/client/actions/signSignatureRequest.ts +50 -46
  107. package/src/client/client.e2e-test.ts +101 -33
  108. package/src/client/decorator.ts +14 -5
  109. package/src/exports/index.ts +2 -1
  110. package/src/isomorphic/actions/createSession.ts +20 -42
  111. package/src/isomorphic/actions/prepareCalls.ts +25 -17
  112. package/src/isomorphic/actions/sendPreparedCalls.ts +104 -54
  113. package/src/isomorphic/utils/7702.ts +18 -8
  114. package/src/isomorphic/utils/decodeSignature.ts +18 -0
  115. package/src/local/client.ts +2 -6
  116. package/src/remote/client.ts +3 -10
  117. package/src/rpc/examples.ts +3 -4
  118. package/src/rpc/request.ts +41 -63
  119. package/src/rpc/schema.ts +2 -2
  120. package/src/schemas.ts +227 -53
  121. package/src/types.ts +4 -0
@@ -6,31 +6,28 @@ 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
- import { parseDelegation, assertValid7702AccountAddress, } from "../utils/7702.js";
12
10
  export async function createSession(client, params) {
13
11
  if (!client.chain) {
14
12
  throw new ChainNotFoundError();
15
13
  }
16
- assertValid7702AccountAddress(params.account, params.capabilities?.eip7702Auth);
17
- const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth
18
- ? {
19
- counterfactualInfo: undefined,
20
- delegation: parseDelegation(params.capabilities.eip7702Auth),
21
- }
22
- : await client.request({
23
- method: "wallet_requestAccount",
24
- params: [
25
- {
26
- accountAddress: params.account,
27
- includeCounterfactualInfo: true,
28
- },
29
- ],
14
+ const { counterfactualInfo, delegation } = await client.request({
15
+ method: "wallet_requestAccount",
16
+ params: [
17
+ {
18
+ accountAddress: params.account,
19
+ includeCounterfactualInfo: true,
20
+ },
21
+ ],
22
+ });
23
+ if (delegation) {
24
+ throw new InvalidRequestError({
25
+ message: "'wallet_createSession' does not currently support 7702 accounts.",
30
26
  });
31
- if (!counterfactualInfo && !delegation) {
27
+ }
28
+ if (!counterfactualInfo) {
32
29
  throw new InvalidRequestError({
33
- message: "No counterfactual info or delegated implementation address found.",
30
+ message: "No counterfactual info found.",
34
31
  });
35
32
  }
36
33
  const account = await createAccount({
@@ -64,29 +61,18 @@ export async function createSession(client, params) {
64
61
  },
65
62
  entityId,
66
63
  nonce,
67
- deadline: params.expiry,
64
+ deadline: params.expirySec,
68
65
  })
69
66
  .addPermissions({
70
67
  permissions: params.permissions.map((permission) => Value.Encode(TypePermission, permission)),
71
68
  })
72
69
  .compileDeferred();
73
- // If using 7702, we need an Authorization (unless it's already authorized).
74
- const authorizationRequest = delegation
75
- ? await createAuthorization(client, {
76
- address: account.address,
77
- delegation,
78
- })
79
- : undefined;
80
- const signatureRequest = {
81
- type: "eth_signTypedData_v4",
82
- data: typedData,
83
- };
84
70
  return {
85
71
  sessionId: null, // In remote mode, the server will set this later.
86
72
  entityId: toHex(entityId),
87
73
  signatureRequest: {
88
- ...signatureRequest,
89
- ...(authorizationRequest ? { authorizationRequest } : {}),
74
+ type: "eth_signTypedData_v4",
75
+ data: typedData,
90
76
  },
91
77
  fullPreSignatureDeferredActionDigest,
92
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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AAG,CAAC,IAAI;SAClE;QACD,QAAQ;QACR,KAAK;QACL,QAAQ,EAAE,MAAM,CAAC,MAAM;KACxB,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,4EAA4E;IAC5E,MAAM,oBAAoB,GAAG,UAAU;QACrC,CAAC,CAAC,MAAM,mBAAmB,CAAC,MAAM,EAAE;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,UAAU;SACX,CAAC;QACJ,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,gBAAgB,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
+ {"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,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R,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAE3B,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,mBAAmB,CAAC;QAC5D,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;QACpE,kBAAkB,EAAE,kBAAkB,CAAC,MAAM,CAAC;KAC/C,CAAC,CAAC;IAEH,MAAM,EAAE,SAAS,EAAE,oCAAoC,EAAE,GACvD,MAAM,IAAI,iBAAiB,CAAC;QAC1B,MAAM,EAAE,OAAO;QACf,GAAG,EAAE;YACH,GAAG,MAAM,CAAC,GAAG;YACb,+BAA+B;YAC/B,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI;SAClE;QACD,QAAQ;QACR,KAAK;QACL,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"]}
@@ -2,8 +2,9 @@ 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, parseDelegation } from "../utils/7702.js";
5
+ import { createAuthorizationRequest, parseDelegation } from "../utils/7702.js";
6
6
  import { InvalidRequestError } from "ox/RpcResponse";
7
+ import { assertNever } from "../../utils.js";
7
8
  import { assertValid7702AccountAddress } from "../utils/7702.js";
8
9
  export async function prepareCalls(client, params) {
9
10
  if (!client.chain) {
@@ -41,7 +42,7 @@ export async function prepareCalls(client, params) {
41
42
  });
42
43
  // If using 7702, we need an Authorization (unless it's already authorized).
43
44
  const authorizationRequest = delegation
44
- ? await createAuthorization(client, {
45
+ ? await createAuthorizationRequest(client, {
45
46
  address: account.address,
46
47
  delegation,
47
48
  })
@@ -62,27 +63,32 @@ export async function prepareCalls(client, params) {
62
63
  overrides: params.capabilities?.gasParamsOverride,
63
64
  });
64
65
  // The eip7702Auth field should never be included in the UO sig
65
- // request. It's handled by the separate authorization request.
66
+ // request. It's handled by a separate authorization request.
66
67
  if ("eip7702Auth" in builtUo) {
67
68
  builtUo.eip7702Auth = undefined;
68
69
  }
69
- const uoRequest = deepHexlify(builtUo);
70
- const signatureRequest = {
71
- type: "personal_sign",
72
- data: {
73
- raw: account.getEntryPoint().getUserOperationHash(uoRequest),
74
- },
75
- };
76
- return {
77
- 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"
78
74
  ? "user-operation-v070"
79
- : "user-operation-v060",
80
- data: uoRequest,
75
+ : ep.version === "0.6.0"
76
+ ? "user-operation-v060"
77
+ : assertNever(ep.version, "Unexpected entry point version"),
78
+ data: hexlifiedUo,
81
79
  chainId: toHex(client.chain.id),
82
80
  signatureRequest: {
83
- ...signatureRequest,
84
- ...(authorizationRequest ? { authorizationRequest } : {}),
81
+ type: "personal_sign",
82
+ data: {
83
+ raw: ep.getUserOperationHash(hexlifiedUo),
84
+ },
85
85
  },
86
86
  };
87
+ return authorizationRequest
88
+ ? {
89
+ type: "array",
90
+ data: [authorizationRequest, uoRequest],
91
+ }
92
+ : uoRequest;
87
93
  }
88
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,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAA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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"]}
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCal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O,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 { wallet_sendPreparedCalls } from "../../rpc/request.js";
3
+ import { type wallet_sendPreparedCalls } from "../../rpc/request.js";
5
4
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
6
- export type SendPreparedCallsParams = Omit<StaticDecode<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0], "chainId">;
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
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
- !isSupportedDelegationAddress7702(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 entryPoint = params.type === "user-operation-v060"
33
- ? getEntryPoint(client.chain, { version: "0.6.0" })
34
- : getEntryPoint(client.chain, { version: "0.7.0" });
35
- const hash = await client
36
- .sendRawUserOperation({
37
- ...params.data,
38
- signature: deferredAction != null
39
- ? concatHex([
40
- `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).
41
- "0xff",
42
- "0x00",
43
- params.signature.signature,
44
- ])
45
- : concat(["0xFF", "0x00", params.signature.signature]),
46
- eip7702Auth: params.signedAuthorization,
47
- }, entryPoint.address)
48
- .catch((err) => {
49
- if (err instanceof BaseError &&
50
- err.details.endsWith("is not a contract and initCode is empty")) {
51
- throw new BaseError(`${err.details} (If using 7702, be sure you include the 'signedAuthorization' field in the request parameters)`);
52
- }
53
- throw err;
54
- });
55
- const callId = Value.Encode(TypeCallId, {
56
- chainId: toHex(client.chain.id),
57
- hash,
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: [callId],
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;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,6GA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AM,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,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"]}
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,KAAK,6BAA6B,EAAE,CAAC;YACpE,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EACL,gEAAgE;aACnE,CAAC,CA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AAO,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"]}
@@ -13,7 +13,108 @@ 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-v060" | "user-operation-v070";
16
+ type: "array";
17
+ data: ({
18
+ type: "user-operation-v060";
19
+ chainId: `0x${string}`;
20
+ data: {
21
+ sender: `0x${string}`;
22
+ nonce: `0x${string}`;
23
+ initCode: `0x${string}`;
24
+ callData: `0x${string}`;
25
+ callGasLimit: `0x${string}`;
26
+ verificationGasLimit: `0x${string}`;
27
+ preVerificationGas: `0x${string}`;
28
+ maxFeePerGas: `0x${string}`;
29
+ maxPriorityFeePerGas: `0x${string}`;
30
+ paymasterAndData: `0x${string}`;
31
+ };
32
+ signatureRequest: {
33
+ type: "eth_signTypedData_v4";
34
+ data: {
35
+ domain?: {
36
+ chainId?: number | undefined;
37
+ salt?: `0x${string}` | undefined;
38
+ name?: string | undefined;
39
+ verifyingContract?: `0x${string}` | undefined;
40
+ version?: string | undefined;
41
+ } | undefined;
42
+ types: {
43
+ [x: string]: {
44
+ type: string;
45
+ name: string;
46
+ }[];
47
+ };
48
+ primaryType: string;
49
+ message: {
50
+ [x: string]: unknown;
51
+ };
52
+ };
53
+ } | {
54
+ type: "personal_sign";
55
+ data: string | {
56
+ raw: `0x${string}`;
57
+ };
58
+ };
59
+ } | {
60
+ type: "user-operation-v070";
61
+ chainId: `0x${string}`;
62
+ data: {
63
+ factory?: `0x${string}` | undefined;
64
+ factoryData?: `0x${string}` | undefined;
65
+ paymaster?: `0x${string}` | undefined;
66
+ paymasterData?: `0x${string}` | undefined;
67
+ paymasterVerificationGasLimit?: `0x${string}` | undefined;
68
+ paymasterPostOpGasLimit?: `0x${string}` | undefined;
69
+ sender: `0x${string}`;
70
+ nonce: `0x${string}`;
71
+ callData: `0x${string}`;
72
+ callGasLimit: `0x${string}`;
73
+ verificationGasLimit: `0x${string}`;
74
+ preVerificationGas: `0x${string}`;
75
+ maxFeePerGas: `0x${string}`;
76
+ maxPriorityFeePerGas: `0x${string}`;
77
+ };
78
+ signatureRequest: {
79
+ type: "eth_signTypedData_v4";
80
+ data: {
81
+ domain?: {
82
+ chainId?: number | undefined;
83
+ salt?: `0x${string}` | undefined;
84
+ name?: string | undefined;
85
+ verifyingContract?: `0x${string}` | undefined;
86
+ version?: string | undefined;
87
+ } | undefined;
88
+ types: {
89
+ [x: string]: {
90
+ type: string;
91
+ name: string;
92
+ }[];
93
+ };
94
+ primaryType: string;
95
+ message: {
96
+ [x: string]: unknown;
97
+ };
98
+ };
99
+ } | {
100
+ type: "personal_sign";
101
+ data: string | {
102
+ raw: `0x${string}`;
103
+ };
104
+ };
105
+ } | {
106
+ type: "authorization";
107
+ chainId: `0x${string}`;
108
+ data: {
109
+ nonce: `0x${string}`;
110
+ address: `0x${string}`;
111
+ };
112
+ signatureRequest: {
113
+ type: "eip7702Auth";
114
+ };
115
+ })[];
116
+ } | {
117
+ type: "user-operation-v060";
17
118
  chainId: `0x${string}`;
18
119
  data: {
19
120
  sender: `0x${string}`;
@@ -26,7 +127,38 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
26
127
  maxFeePerGas: `0x${string}`;
27
128
  maxPriorityFeePerGas: `0x${string}`;
28
129
  paymasterAndData: `0x${string}`;
130
+ };
131
+ signatureRequest: {
132
+ type: "eth_signTypedData_v4";
133
+ data: {
134
+ domain?: {
135
+ chainId?: number | undefined;
136
+ salt?: `0x${string}` | undefined;
137
+ name?: string | undefined;
138
+ verifyingContract?: `0x${string}` | undefined;
139
+ version?: string | undefined;
140
+ } | undefined;
141
+ types: {
142
+ [x: string]: {
143
+ type: string;
144
+ name: string;
145
+ }[];
146
+ };
147
+ primaryType: string;
148
+ message: {
149
+ [x: string]: unknown;
150
+ };
151
+ };
29
152
  } | {
153
+ type: "personal_sign";
154
+ data: string | {
155
+ raw: `0x${string}`;
156
+ };
157
+ };
158
+ } | {
159
+ type: "user-operation-v070";
160
+ chainId: `0x${string}`;
161
+ data: {
30
162
  factory?: `0x${string}` | undefined;
31
163
  factoryData?: `0x${string}` | undefined;
32
164
  paymaster?: `0x${string}` | undefined;
@@ -42,12 +174,7 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
42
174
  maxFeePerGas: `0x${string}`;
43
175
  maxPriorityFeePerGas: `0x${string}`;
44
176
  };
45
- signatureRequest: ({
46
- type: "personal_sign";
47
- data: string | {
48
- raw: `0x${string}`;
49
- };
50
- } | {
177
+ signatureRequest: {
51
178
  type: "eth_signTypedData_v4";
52
179
  data: {
53
180
  domain?: {
@@ -68,12 +195,11 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
68
195
  [x: string]: unknown;
69
196
  };
70
197
  };
71
- }) & {
72
- authorizationRequest?: {
73
- nonce: number;
74
- chainId: number;
75
- address: `0x${string}`;
76
- } | undefined;
198
+ } | {
199
+ type: "personal_sign";
200
+ data: string | {
201
+ raw: `0x${string}`;
202
+ };
77
203
  };
78
204
  }>;
79
205
  sendPreparedCalls: (params: SendPreparedCallsParams) => Promise<{
@@ -1,12 +1,13 @@
1
1
  import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
2
- import { type Authorization, type Address, type Chain, type Transport } from "viem";
2
+ import { type Address, type Chain, type Transport } from "viem";
3
3
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
4
+ import { PreparedCall_Authorization } from "../../schemas.js";
4
5
  import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
5
6
  import type { Static } from "@sinclair/typebox";
6
- export declare const createAuthorization: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
7
+ export declare const createAuthorizationRequest: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
7
8
  address: Address;
8
9
  delegation: Address;
9
- }) => Promise<Authorization<number, false> | undefined>;
10
+ }) => Promise<Static<typeof PreparedCall_Authorization> | undefined>;
10
11
  export declare const EIP_7702_ACCOUNT_TYPE: readonly ["ModularAccountV2"];
11
12
  type Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];
12
13
  export declare const SUPPORTED_DELEGATION_ADDRESSES: "0x69007702764179f14F51cdce752f4f775d74E139"[];