@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.3

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 (188) hide show
  1. package/dist/esm/capabilities/index.d.ts +5 -2
  2. package/dist/esm/capabilities/index.js +1 -1
  3. package/dist/esm/capabilities/index.js.map +1 -1
  4. package/dist/esm/capabilities/overrides.js +8 -8
  5. package/dist/esm/capabilities/overrides.js.map +1 -1
  6. package/dist/esm/capabilities/permissions/index.d.ts +10 -3
  7. package/dist/esm/capabilities/permissions/index.js +11 -2
  8. package/dist/esm/capabilities/permissions/index.js.map +1 -1
  9. package/dist/esm/capabilities/permissions/mav2.d.ts +3 -3
  10. package/dist/esm/capabilities/permissions/mav2.js +9 -1
  11. package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
  12. package/dist/esm/client/actions/createAccount.d.ts +27 -2
  13. package/dist/esm/client/actions/createAccount.js +25 -0
  14. package/dist/esm/client/actions/createAccount.js.map +1 -1
  15. package/dist/esm/client/actions/getCallsStatus.d.ts +21 -2
  16. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  17. package/dist/esm/client/actions/grantPermissions.d.ts +114 -2
  18. package/dist/esm/client/actions/grantPermissions.js +1 -0
  19. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  20. package/dist/esm/client/actions/listAccounts.d.ts +26 -2
  21. package/dist/esm/client/actions/listAccounts.js +24 -0
  22. package/dist/esm/client/actions/listAccounts.js.map +1 -1
  23. package/dist/esm/client/actions/prepareCalls.d.ts +28 -2
  24. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  25. package/dist/esm/client/actions/requestAccount.d.ts +21 -2
  26. package/dist/esm/client/actions/requestAccount.js +15 -4
  27. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  28. package/dist/esm/client/actions/sendPreparedCalls.d.ts +39 -2
  29. package/dist/esm/client/actions/sendPreparedCalls.js +37 -0
  30. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  31. package/dist/esm/client/actions/signMessage.d.ts +22 -2
  32. package/dist/esm/client/actions/signMessage.js +4 -2
  33. package/dist/esm/client/actions/signMessage.js.map +1 -1
  34. package/dist/esm/client/actions/signSignatureRequest.d.ts +34 -0
  35. package/dist/esm/client/actions/signSignatureRequest.js +22 -1
  36. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  37. package/dist/esm/client/actions/signTypedData.d.ts +35 -2
  38. package/dist/esm/client/actions/signTypedData.js +3 -1
  39. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  40. package/dist/esm/client/client.e2e-test.js +112 -30
  41. package/dist/esm/client/client.e2e-test.js.map +1 -1
  42. package/dist/esm/client/decorator.d.ts +7 -5
  43. package/dist/esm/client/decorator.js +1 -1
  44. package/dist/esm/client/decorator.js.map +1 -1
  45. package/dist/esm/client/index.d.ts +4 -4
  46. package/dist/esm/client/index.js +29 -3
  47. package/dist/esm/client/index.js.map +1 -1
  48. package/dist/esm/exports/index.d.ts +1 -0
  49. package/dist/esm/exports/index.js +1 -0
  50. package/dist/esm/exports/index.js.map +1 -1
  51. package/dist/esm/exports/internal.d.ts +1 -1
  52. package/dist/esm/exports/internal.js.map +1 -1
  53. package/dist/esm/internal/decorator.d.ts +2 -0
  54. package/dist/esm/internal/decorator.js +10 -0
  55. package/dist/esm/internal/decorator.js.map +1 -0
  56. package/dist/esm/isomorphic/actions/createSession.js +25 -7
  57. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  58. package/dist/esm/isomorphic/actions/prepareCalls.js +35 -12
  59. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  60. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +26 -6
  61. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  62. package/dist/esm/isomorphic/client.d.ts +11 -5
  63. package/dist/esm/isomorphic/utils/7702.d.ts +11 -0
  64. package/dist/esm/isomorphic/utils/7702.js +26 -0
  65. package/dist/esm/isomorphic/utils/7702.js.map +1 -0
  66. package/dist/esm/isomorphic/utils/createAccount.d.ts +2 -1
  67. package/dist/esm/isomorphic/utils/createAccount.js +30 -5
  68. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  69. package/dist/esm/isomorphic/utils/createDummySigner.js +3 -3
  70. package/dist/esm/isomorphic/utils/createDummySigner.js.map +1 -1
  71. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +2 -1
  72. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +17 -5
  73. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
  74. package/dist/esm/local/client.d.ts +1 -1
  75. package/dist/esm/local/client.js +10 -2
  76. package/dist/esm/local/client.js.map +1 -1
  77. package/dist/esm/remote/client.d.ts +1 -1
  78. package/dist/esm/remote/client.js +12 -3
  79. package/dist/esm/remote/client.js.map +1 -1
  80. package/dist/esm/rpc/examples.d.ts +230 -0
  81. package/dist/esm/rpc/examples.js +314 -0
  82. package/dist/esm/rpc/examples.js.map +1 -0
  83. package/dist/esm/rpc/request.d.ts +48 -17
  84. package/dist/esm/rpc/request.js +53 -14
  85. package/dist/esm/rpc/request.js.map +1 -1
  86. package/dist/esm/rpc/schema.d.ts +43 -12
  87. package/dist/esm/schemas.d.ts +29 -7
  88. package/dist/esm/schemas.js +120 -38
  89. package/dist/esm/schemas.js.map +1 -1
  90. package/dist/esm/types.d.ts +15 -4
  91. package/dist/esm/types.js.map +1 -1
  92. package/dist/types/capabilities/index.d.ts +5 -2
  93. package/dist/types/capabilities/index.d.ts.map +1 -1
  94. package/dist/types/capabilities/overrides.d.ts.map +1 -1
  95. package/dist/types/capabilities/permissions/index.d.ts +10 -3
  96. package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
  97. package/dist/types/capabilities/permissions/mav2.d.ts +3 -3
  98. package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
  99. package/dist/types/client/actions/createAccount.d.ts +27 -2
  100. package/dist/types/client/actions/createAccount.d.ts.map +1 -1
  101. package/dist/types/client/actions/getCallsStatus.d.ts +21 -2
  102. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  103. package/dist/types/client/actions/grantPermissions.d.ts +114 -2
  104. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  105. package/dist/types/client/actions/listAccounts.d.ts +26 -2
  106. package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
  107. package/dist/types/client/actions/prepareCalls.d.ts +28 -2
  108. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  109. package/dist/types/client/actions/requestAccount.d.ts +21 -2
  110. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  111. package/dist/types/client/actions/sendPreparedCalls.d.ts +39 -2
  112. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  113. package/dist/types/client/actions/signMessage.d.ts +22 -2
  114. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  115. package/dist/types/client/actions/signSignatureRequest.d.ts +34 -0
  116. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  117. package/dist/types/client/actions/signTypedData.d.ts +35 -2
  118. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  119. package/dist/types/client/decorator.d.ts +7 -5
  120. package/dist/types/client/decorator.d.ts.map +1 -1
  121. package/dist/types/client/index.d.ts +4 -4
  122. package/dist/types/client/index.d.ts.map +1 -1
  123. package/dist/types/exports/index.d.ts +1 -0
  124. package/dist/types/exports/index.d.ts.map +1 -1
  125. package/dist/types/exports/internal.d.ts +1 -1
  126. package/dist/types/exports/internal.d.ts.map +1 -1
  127. package/dist/types/internal/decorator.d.ts +3 -0
  128. package/dist/types/internal/decorator.d.ts.map +1 -0
  129. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  130. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  131. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  132. package/dist/types/isomorphic/client.d.ts +11 -5
  133. package/dist/types/isomorphic/client.d.ts.map +1 -1
  134. package/dist/types/isomorphic/utils/7702.d.ts +12 -0
  135. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
  136. package/dist/types/isomorphic/utils/createAccount.d.ts +2 -1
  137. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  138. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +1 -1
  139. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +2 -1
  140. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
  141. package/dist/types/local/client.d.ts +1 -1
  142. package/dist/types/local/client.d.ts.map +1 -1
  143. package/dist/types/remote/client.d.ts +1 -1
  144. package/dist/types/remote/client.d.ts.map +1 -1
  145. package/dist/types/rpc/examples.d.ts +231 -0
  146. package/dist/types/rpc/examples.d.ts.map +1 -0
  147. package/dist/types/rpc/request.d.ts +48 -17
  148. package/dist/types/rpc/request.d.ts.map +1 -1
  149. package/dist/types/rpc/schema.d.ts +43 -12
  150. package/dist/types/rpc/schema.d.ts.map +1 -1
  151. package/dist/types/schemas.d.ts +29 -7
  152. package/dist/types/schemas.d.ts.map +1 -1
  153. package/dist/types/types.d.ts +15 -4
  154. package/dist/types/types.d.ts.map +1 -1
  155. package/package.json +8 -6
  156. package/src/capabilities/index.ts +5 -8
  157. package/src/capabilities/overrides.ts +23 -8
  158. package/src/capabilities/permissions/index.ts +21 -5
  159. package/src/capabilities/permissions/mav2.ts +13 -3
  160. package/src/client/actions/createAccount.ts +27 -2
  161. package/src/client/actions/getCallsStatus.ts +21 -2
  162. package/src/client/actions/grantPermissions.ts +114 -2
  163. package/src/client/actions/listAccounts.ts +26 -2
  164. package/src/client/actions/prepareCalls.ts +28 -2
  165. package/src/client/actions/requestAccount.ts +41 -7
  166. package/src/client/actions/sendPreparedCalls.ts +39 -2
  167. package/src/client/actions/signMessage.ts +24 -4
  168. package/src/client/actions/signSignatureRequest.ts +61 -2
  169. package/src/client/actions/signTypedData.ts +39 -3
  170. package/src/client/client.e2e-test.ts +134 -32
  171. package/src/client/decorator.ts +10 -12
  172. package/src/client/index.ts +41 -10
  173. package/src/exports/index.ts +1 -0
  174. package/src/exports/internal.ts +1 -1
  175. package/src/internal/decorator.ts +12 -0
  176. package/src/isomorphic/actions/createSession.ts +28 -7
  177. package/src/isomorphic/actions/prepareCalls.ts +38 -11
  178. package/src/isomorphic/actions/sendPreparedCalls.ts +47 -20
  179. package/src/isomorphic/utils/7702.ts +58 -0
  180. package/src/isomorphic/utils/createAccount.ts +38 -6
  181. package/src/isomorphic/utils/createDummySigner.ts +3 -2
  182. package/src/isomorphic/utils/parsePermissionsContext.ts +23 -7
  183. package/src/local/client.ts +54 -45
  184. package/src/remote/client.ts +22 -7
  185. package/src/rpc/examples.ts +343 -0
  186. package/src/rpc/request.ts +75 -26
  187. package/src/schemas.ts +218 -87
  188. package/src/types.ts +18 -4
@@ -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;AAoBlE,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAMC,EACD,MAA2B;IAE3B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,C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AAoC,EAAE,GACvD,MAAM,IAAI,iBAAiB,CAAC;QAC1B,MAAM,EAAE,OAAO;QACf,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,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,OAAO;QACL,SAAS,EAAE,IAAI,EAAE,kDAAkD;QACnE,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;QACzB,gBAAgB,EAAE;YAChB,IAAI,EAAE,sBAAsB;YAC5B,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\";\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 } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n includeCounterfactualInfo: true,\n accountAddress: params.account,\n },\n ],\n });\n if (!counterfactualInfo) {\n throw new Error(\"No counterfactual info found.\");\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 });\n\n if (!isModularAccountV2(account)) {\n throw new Error(\"Sessions are currently only supported by MAv2 accounts.\");\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: params.key,\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 return {\n sessionId: null, // In remote mode, the server will set this later.\n entityId: toHex(entityId),\n signatureRequest: {\n type: \"eth_signTypedData_v4\",\n data: typedData,\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,eA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,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\";\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 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: params.key,\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,14 +1,15 @@
1
- import { deepHexlify, } from "@aa-sdk/core";
2
- import { ChainNotFoundError, custom, fromHex, toHex, zeroAddress, } from "viem";
1
+ import { deepHexlify, default7702GasEstimator, } from "@aa-sdk/core";
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
- // TODO: handle capabilities like permissions and paymaster here
5
+ import { createAuthorization } from "../utils/7702.js";
6
+ import { InvalidRequestError } from "ox/RpcResponse";
6
7
  export async function prepareCalls(client, params) {
7
8
  if (!client.chain) {
8
9
  throw new ChainNotFoundError();
9
10
  }
10
11
  // in local mode, we probably want some kind of caching for this
11
- const { counterfactualInfo } = await client.request({
12
+ const { counterfactualInfo, delegation } = await client.request({
12
13
  method: "wallet_requestAccount",
13
14
  params: [
14
15
  {
@@ -17,17 +18,31 @@ export async function prepareCalls(client, params) {
17
18
  },
18
19
  ],
19
20
  });
20
- if (!counterfactualInfo) {
21
- throw new Error("No counterfactual info found.");
21
+ if (!counterfactualInfo && !delegation) {
22
+ throw new InvalidRequestError({
23
+ message: "No counterfactual info or delegated implementation address found.",
24
+ });
22
25
  }
23
26
  const account = await createAccount({
24
27
  chain: client.chain,
25
28
  transport: custom(client.transport),
26
- signer: createDummySigner(zeroAddress),
29
+ signer: createDummySigner(params.from),
27
30
  accountAddress: params.from,
28
31
  counterfactualInfo,
29
32
  capabilities: params.capabilities,
33
+ delegation,
30
34
  });
35
+ // If using 7702, we need an Authorization (unless it's already authorized).
36
+ const authorizationRequest = delegation
37
+ ? await createAuthorization(client, {
38
+ address: account.address,
39
+ delegation,
40
+ })
41
+ : undefined;
42
+ if (authorizationRequest) {
43
+ // @ts-expect-error - this is available but not typed as public
44
+ client.middleware.gasEstimator = default7702GasEstimator();
45
+ }
31
46
  // TODO: oops we don't actually support setting the policyId as an override here
32
47
  // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly
33
48
  const builtUo = await client.buildUserOperation({
@@ -39,8 +54,18 @@ export async function prepareCalls(client, params) {
39
54
  account,
40
55
  overrides: params.capabilities?.gasParamsOverride,
41
56
  });
57
+ // The eip7702Auth field should never be included in the UO sig
58
+ // request. It's handled by the separate authorization request.
59
+ if ("eip7702Auth" in builtUo) {
60
+ builtUo.eip7702Auth = undefined;
61
+ }
42
62
  const uoRequest = deepHexlify(builtUo);
43
- const hash = account.getEntryPoint().getUserOperationHash(uoRequest);
63
+ const signatureRequest = {
64
+ type: "personal_sign",
65
+ data: {
66
+ raw: account.getEntryPoint().getUserOperationHash(uoRequest),
67
+ },
68
+ };
44
69
  return {
45
70
  type: account.getEntryPoint().version === "0.7.0"
46
71
  ? "user-operation-v070"
@@ -48,10 +73,8 @@ export async function prepareCalls(client, params) {
48
73
  data: uoRequest,
49
74
  chainId: toHex(client.chain.id),
50
75
  signatureRequest: {
51
- type: "personal_sign",
52
- data: {
53
- raw: hash,
54
- },
76
+ ...signatureRequest,
77
+ ...(authorizationRequest ? { authorizationRequest } : {}),
55
78
  },
56
79
  };
57
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAGZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,KAAK,EACL,WAAW,GAGZ,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAalE,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAMC,EACD,MAA0B;IAE1B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,gEAAgE;IAChE,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,OA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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,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE;gBACJ,GAAG,EAAE,IAAI;aACV;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n deepHexlify,\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 zeroAddress,\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\";\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\n// TODO: handle capabilities like permissions and paymaster here\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 // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n if (!counterfactualInfo) {\n throw new Error(\"No counterfactual info found.\");\n }\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(zeroAddress),\n accountAddress: params.from,\n counterfactualInfo,\n capabilities: params.capabilities,\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 const uoRequest = deepHexlify(builtUo);\n\n const hash = account.getEntryPoint().getUserOperationHash(uoRequest);\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 type: \"personal_sign\",\n data: {\n raw: hash,\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,KAAK,GAGN,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAarD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAMC,EACD,MAA0B;IAE1B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,gEAAgE;IAChE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9D,MAAM,EAAE,uBAAuB;QAC/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AAC,CAAC,CAAC,CAAC,SAAS;SACxD,CAAC,CAAC;QACH,OAAO;QACP,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE,iBAAiB;KAClD,CAAC,CAAC;IAEH,+DAA+D;IAC/D,+DAA+D;IAC/D,IAAI,aAAa,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAClC,CAAC;IACD,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEvC,MAAM,gBAAgB,GAAG;QACvB,IAAI,EAAE,eAAwB;QAC9B,IAAI,EAAE;YACJ,GAAG,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,oBAAoB,CAAC,SAAS,CAAC;SAC7D;KACF,CAAC;IAEF,OAAO;QACL,IAAI,EACF,OAAO,CAAC,aAAa,EAAE,CAAC,OAAO,KAAK,OAAO;YACzC,CAAC,CAAC,qBAAqB;YACvB,CAAC,CAAC,qBAAqB;QAC3B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,GAAG,gBAAgB;YACnB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n deepHexlify,\n default7702GasEstimator,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport {\n ChainNotFoundError,\n custom,\n fromHex,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { wallet_prepareCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorization } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\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 // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\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 capabilities: params.capabilities,\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,27 +1,39 @@
1
1
  import { getEntryPoint, } from "@aa-sdk/core";
2
2
  import { Value } from "@sinclair/typebox/value";
3
- import { ChainNotFoundError, concat, concatHex, toHex, } from "viem";
3
+ import { BaseError, ChainNotFoundError, concat, concatHex, toHex, } from "viem";
4
4
  import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
5
5
  import { TypeCallId } from "../../schemas.js";
6
+ import { isSupportedImplementationAddress7702 } from "../utils/7702.js";
7
+ import { InvalidRequestError } from "ox/RpcResponse";
6
8
  // TODO: this only supports MAv2 right now, we need to fix this
7
9
  export async function sendPreparedCalls(client, params) {
8
10
  if (!client.chain) {
9
11
  throw new ChainNotFoundError();
10
12
  }
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
+ }
11
20
  const deferredAction = (() => {
12
- if (!params.capabilities?.permissions?.context) {
21
+ if (!params.capabilities?.permissions) {
13
22
  return;
14
23
  }
15
- const decodedContext = decodePermissionsContext(params.capabilities.permissions.context);
24
+ const decodedContext = decodePermissionsContext(params.capabilities.permissions);
16
25
  if (decodedContext.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
17
- throw new Error("Remote mode deferred action not supported in isomorphic client");
26
+ throw new InvalidRequestError({
27
+ message: "Remote mode deferred action not supported in isomorphic client",
28
+ });
18
29
  }
19
30
  return decodedContext.deferredAction;
20
31
  })();
21
32
  const entryPoint = params.type === "user-operation-v060"
22
33
  ? getEntryPoint(client.chain, { version: "0.6.0" })
23
34
  : getEntryPoint(client.chain, { version: "0.7.0" });
24
- const hash = await client.sendRawUserOperation({
35
+ const hash = await client
36
+ .sendRawUserOperation({
25
37
  ...params.data,
26
38
  signature: deferredAction != null
27
39
  ? concatHex([
@@ -31,7 +43,15 @@ export async function sendPreparedCalls(client, params) {
31
43
  params.signature.signature,
32
44
  ])
33
45
  : concat(["0xFF", "0x00", params.signature.signature]),
34
- }, entryPoint.address);
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
+ });
35
55
  const callId = Value.Encode(TypeCallId, {
36
56
  chainId: toHex(client.chain.id),
37
57
  hash,
@@ -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,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;AAa9C,+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,GAA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AEH,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 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\";\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 const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions?.context) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions.context,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new Error(\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.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 },\n entryPoint.address,\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;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,oCAAoC,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAarD,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAMC,EACD,MAA+B;IAE/B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,6GAA6G;IAC7G,IACE,MAAM,CAAC,mBAAmB;QAC1B,CAAC,oCAAoC,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,EACzE,CAAC;QACD,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,wCAAwC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE;SACtF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,cAAc,GAAoB,CAA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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 { isSupportedImplementationAddress7702 } 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 !isSupportedImplementationAddress7702(params.signedAuthorization.address)\n ) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,\n });\n }\n\n const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message:\n \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return decodedContext.deferredAction;\n })();\n\n const entryPoint =\n params.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : getEntryPoint(client.chain, { version: \"0.7.0\" });\n\n const hash = await client\n .sendRawUserOperation(\n {\n ...params.data,\n signature:\n deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).\n \"0xff\",\n \"0x00\",\n params.signature.signature,\n ])\n : concat([\"0xFF\", \"0x00\", params.signature.signature]),\n eip7702Auth: params.signedAuthorization,\n },\n entryPoint.address,\n )\n .catch((err) => {\n if (\n err instanceof BaseError &&\n err.details.endsWith(\"is not a contract and initCode is empty\")\n ) {\n throw new BaseError(\n `${err.details} (If using 7702, be sure you include the 'signedAuthorization' field in the request parameters)`,\n );\n }\n throw err;\n });\n\n const callId = Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n });\n\n return {\n preparedCallIds: [callId],\n };\n}\n"]}
@@ -13,7 +13,7 @@ type ClientParams = {
13
13
  };
14
14
  export declare function isomorphicClientActions(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>): {
15
15
  prepareCalls: (params: PrepareCallsParams) => Promise<{
16
- type: "user-operation-v060" | "user-operation-v070";
16
+ type: "user-operation-v070" | "user-operation-v060";
17
17
  chainId: `0x${string}`;
18
18
  data: {
19
19
  sender: `0x${string}`;
@@ -42,7 +42,7 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
42
42
  maxFeePerGas: `0x${string}`;
43
43
  maxPriorityFeePerGas: `0x${string}`;
44
44
  };
45
- signatureRequest: {
45
+ signatureRequest: ({
46
46
  type: "personal_sign";
47
47
  data: string | {
48
48
  raw: `0x${string}`;
@@ -51,8 +51,8 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
51
51
  type: "eth_signTypedData_v4";
52
52
  data: {
53
53
  domain?: {
54
- salt?: `0x${string}` | undefined;
55
54
  chainId?: number | undefined;
55
+ salt?: `0x${string}` | undefined;
56
56
  name?: string | undefined;
57
57
  verifyingContract?: `0x${string}` | undefined;
58
58
  version?: string | undefined;
@@ -68,6 +68,12 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
68
68
  [x: string]: unknown;
69
69
  };
70
70
  };
71
+ }) & {
72
+ authorizationRequest?: {
73
+ nonce: number;
74
+ chainId: number;
75
+ address: `0x${string}`;
76
+ } | undefined;
71
77
  };
72
78
  }>;
73
79
  sendPreparedCalls: (params: SendPreparedCallsParams) => Promise<{
@@ -77,8 +83,8 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
77
83
  receipts?: {
78
84
  status: `0x${string}`;
79
85
  logs: {
80
- data: `0x${string}`;
81
86
  address: `0x${string}`;
87
+ data: `0x${string}`;
82
88
  topics: `0x${string}`[];
83
89
  }[];
84
90
  blockHash: `0x${string}`;
@@ -89,7 +95,7 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
89
95
  chainId: `0x${string}`;
90
96
  id: `0x${string}`;
91
97
  atomic: boolean;
92
- status: 100 | 200 | 400 | 500 | 600;
98
+ status: 200 | 100 | 400 | 500 | 600;
93
99
  }>;
94
100
  createSession: (params: CreateSessionParams) => Promise<import("./actions/createSession.js").CreateSessionResult>;
95
101
  };
@@ -0,0 +1,11 @@
1
+ import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
2
+ import { type Authorization, type Address, type Chain, type Transport } from "viem";
3
+ import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
4
+ export declare const createAuthorization: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
5
+ address: Address;
6
+ delegation: Address;
7
+ }) => Promise<Authorization<number, false> | undefined>;
8
+ type Supported7702AccountType = "ModularAccountV2";
9
+ export declare const getAccountTypeForImplementationAddress7702: (address: Address) => Supported7702AccountType | undefined;
10
+ export declare const isSupportedImplementationAddress7702: (address: string) => boolean;
11
+ export {};
@@ -0,0 +1,26 @@
1
+ import { concatHex, } from "viem";
2
+ export const createAuthorization = async (client, params) => {
3
+ const expectedCode = concatHex(["0xef0100", params.delegation]);
4
+ const code = (await client.getCode({ address: params.address })) ?? "0x";
5
+ if (code.toLowerCase() === expectedCode.toLowerCase()) {
6
+ return undefined; // Already authorized.
7
+ }
8
+ return {
9
+ chainId: client.chain.id,
10
+ address: params.delegation,
11
+ nonce: await client.getTransactionCount({
12
+ address: params.address,
13
+ }),
14
+ };
15
+ };
16
+ const IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE = {
17
+ "0x69007702764179f14F51cdce752f4f775d74E139": "ModularAccountV2",
18
+ };
19
+ export const getAccountTypeForImplementationAddress7702 = (address) => {
20
+ return IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE[address];
21
+ };
22
+ const SUPPORTED_IMPLEMENTATION_ADDRESSES = Object.keys(IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE);
23
+ export const isSupportedImplementationAddress7702 = (address) => {
24
+ return SUPPORTED_IMPLEMENTATION_ADDRESSES.includes(address);
25
+ };
26
+ //# sourceMappingURL=7702.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,GAKV,MAAM,MAAM,CAAC;AAGd,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAMC,EACD,MAAiD,EACE,EAAE;IACrD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;IACzE,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC,CAAC,sBAAsB;IAC1C,CAAC;IACD,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,EAAE,MAAM,CAAC,UAAU;QAC1B,KAAK,EAAE,MAAM,MAAM,CAAC,mBAAmB,CAAC;YACtC,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AAIF,MAAM,sCAAsC,GAGxC;IACF,4CAA4C,EAAE,kBAAkB;CACjE,CAAC;AAEF,MAAM,CAAC,MAAM,0CAA0C,GAAG,CACxD,OAAgB,EACsB,EAAE;IACxC,OAAO,sCAAsC,CAAC,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,kCAAkC,GAAG,MAAM,CAAC,IAAI,CACpD,sCAAsC,CACvC,CAAC;AAEF,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAClD,OAAe,EACN,EAAE;IACX,OAAO,kCAAkC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC","sourcesContent":["import type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n concatHex,\n type Authorization,\n type Address,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\n\nexport const createAuthorization = async (\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: { address: Address; delegation: Address },\n): Promise<Authorization<number, false> | undefined> => {\n const expectedCode = concatHex([\"0xef0100\", params.delegation]);\n const code = (await client.getCode({ address: params.address })) ?? \"0x\";\n if (code.toLowerCase() === expectedCode.toLowerCase()) {\n return undefined; // Already authorized.\n }\n return {\n chainId: client.chain.id,\n address: params.delegation,\n nonce: await client.getTransactionCount({\n address: params.address,\n }),\n };\n};\n\ntype Supported7702AccountType = \"ModularAccountV2\";\n\nconst IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE: Record<\n Address,\n Supported7702AccountType\n> = {\n \"0x69007702764179f14F51cdce752f4f775d74E139\": \"ModularAccountV2\",\n};\n\nexport const getAccountTypeForImplementationAddress7702 = (\n address: Address,\n): Supported7702AccountType | undefined => {\n return IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE[address];\n};\n\nconst SUPPORTED_IMPLEMENTATION_ADDRESSES = Object.keys(\n IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE,\n);\n\nexport const isSupportedImplementationAddress7702 = (\n address: string,\n): boolean => {\n return SUPPORTED_IMPLEMENTATION_ADDRESSES.includes(address);\n};\n"]}
@@ -9,7 +9,8 @@ type CreateAccountParams = {
9
9
  transport: Transport;
10
10
  signer: SmartAccountSigner;
11
11
  accountAddress: Address;
12
- counterfactualInfo: StaticDecode<typeof TypeSerializedInitcode>;
12
+ counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>;
13
+ delegation?: Address;
13
14
  capabilities?: StaticDecode<typeof Capabilities>;
14
15
  };
15
16
  /**
@@ -1,6 +1,9 @@
1
1
  import { createModularAccountV2, } from "@account-kit/smart-contracts";
2
2
  import { concatHex, hexToNumber } from "viem";
3
3
  import { parsePermissionsContext } from "./parsePermissionsContext.js";
4
+ import { assertNever } from "../../utils.js";
5
+ import { getAccountTypeForImplementationAddress7702 } from "./7702.js";
6
+ import { InternalError } from "ox/RpcResponse";
4
7
  /**
5
8
  * Creates a smart account instance from the given parameters.
6
9
  * @param params - The parameters for creating a smart account.
@@ -8,22 +11,44 @@ import { parsePermissionsContext } from "./parsePermissionsContext.js";
8
11
  */
9
12
  export async function createAccount(params) {
10
13
  const { counterfactualInfo: ci, ...accountParams } = params;
11
- // TODO: Implement support for other account types.
12
- if (ci.factoryType !== "MAv2.0.0-sma-b") {
13
- throw new Error("Only MAv2 SMA-B accounts are currently supported");
14
+ const mode = params.delegation ? "7702" : "default";
15
+ if (mode === "default") {
16
+ if (!ci) {
17
+ throw new InternalError({
18
+ message: "Counterfactual info not found",
19
+ });
20
+ }
21
+ if (ci.factoryType !== "MAv2.0.0-sma-b") {
22
+ throw new InternalError({
23
+ message: `Factory type ${ci.factoryType} is not currently supported.`,
24
+ });
25
+ }
26
+ }
27
+ else if (mode === "7702") {
28
+ const accountType = getAccountTypeForImplementationAddress7702(params.delegation);
29
+ if (accountType !== "ModularAccountV2") {
30
+ throw new InternalError({
31
+ message: "7702 mode currently only supports ModularAccountV2",
32
+ });
33
+ }
34
+ }
35
+ else {
36
+ assertNever(mode, "Unexpected mode in createAccount");
14
37
  }
15
- const parsedContext = parsePermissionsContext(params.capabilities, ci);
38
+ const parsedContext = parsePermissionsContext(params.capabilities, ci, params.delegation);
16
39
  const signerEntity = parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
17
40
  ? {
18
41
  entityId: hexToNumber(parsedContext.entityId),
19
42
  isGlobalValidation: parsedContext.isGlobalValidation,
20
43
  }
21
44
  : undefined;
45
+ // TODO: clean this up to support different account types.
22
46
  return createModularAccountV2({
23
47
  ...accountParams,
24
48
  signerEntity,
25
49
  deferredAction: parsedContext?.deferredAction,
26
- initCode: concatHex([ci.factoryAddress, ci.factoryData]),
50
+ initCode: ci ? concatHex([ci.factoryAddress, ci.factoryData]) : undefined,
51
+ mode,
27
52
  });
28
53
  }
29
54
  export function isModularAccountV2(account) {
@@ -1 +1 @@
1
- {"version":3,"file":"createAccount.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createAccount.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,GAEvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAG9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAWvE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA2B;IAE3B,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC;IAC5D,mDAAmD;IACnD,IAAI,EAAE,CAAC,WAAW,KAAK,gBAAgB,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,aAAa,GAAG,uBAAuB,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAEvE,MAAM,YAAY,GAChB,aAAa,EAAE,cAAc,KAAK,qBAAqB;QACrD,CAAC,CAAC;YACE,QAAQ,EAAE,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC;YAC7C,kBAAkB,EAAE,aAAa,CAAC,kBAAkB;SACrD;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO,sBAAsB,CAAC;QAC5B,GAAG,aAAa;QAChB,YAAY;QACZ,cAAc,EAAE,aAAa,EAAE,cAAc;QAC7C,QAAQ,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;KACzD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAA6B;IAE7B,OAAO,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC/C,CAAC","sourcesContent":["import type { SmartAccountSigner, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n createModularAccountV2,\n type ModularAccountV2,\n} from \"@account-kit/smart-contracts\";\nimport type { StaticDecode } from \"@sinclair/typebox\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport { concatHex, hexToNumber } from \"viem\";\nimport type { Capabilities } from \"../../capabilities/index.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport { parsePermissionsContext } from \"./parsePermissionsContext.js\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartAccountSigner;\n accountAddress: Address;\n counterfactualInfo: StaticDecode<typeof TypeSerializedInitcode>;\n capabilities?: StaticDecode<typeof Capabilities>;\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n * @param params - The parameters for creating a smart account.\n * @returns A promise that resolves to the created smart account.\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, ...accountParams } = params;\n // TODO: Implement support for other account types.\n if (ci.factoryType !== \"MAv2.0.0-sma-b\") {\n throw new Error(\"Only MAv2 SMA-B accounts are currently supported\");\n }\n\n const parsedContext = parsePermissionsContext(params.capabilities, ci);\n\n const signerEntity =\n parsedContext?.contextVersion === \"NON_DEFERRED_ACTION\"\n ? {\n entityId: hexToNumber(parsedContext.entityId),\n isGlobalValidation: parsedContext.isGlobalValidation,\n }\n : undefined;\n\n return createModularAccountV2({\n ...accountParams,\n signerEntity,\n deferredAction: parsedContext?.deferredAction,\n initCode: concatHex([ci.factoryAddress, ci.factoryData]),\n });\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
1
+ {"version":3,"file":"createAccount.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createAccount.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,GAEvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,MAAM,CAA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EF,MAAM,YAAY,GAChB,aAAa,EAAE,cAAc,KAAK,qBAAqB;QACrD,CAAC,CAAC;YACE,QAAQ,EAAE,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC;YAC7C,kBAAkB,EAAE,aAAa,CAAC,kBAAkB;SACrD;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,0DAA0D;IAC1D,OAAO,sBAAsB,CAAC;QAC5B,GAAG,aAAa;QAChB,YAAY;QACZ,cAAc,EAAE,aAAa,EAAE,cAAc;QAC7C,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QACzE,IAAI;KACL,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAA6B;IAE7B,OAAO,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC/C,CAAC","sourcesContent":["import type { SmartAccountSigner, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n createModularAccountV2,\n type ModularAccountV2,\n} from \"@account-kit/smart-contracts\";\nimport type { StaticDecode } from \"@sinclair/typebox\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport { concatHex, hexToNumber } from \"viem\";\nimport type { Capabilities } from \"../../capabilities/index.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport { parsePermissionsContext } from \"./parsePermissionsContext.js\";\nimport { assertNever } from \"../../utils.js\";\nimport { getAccountTypeForImplementationAddress7702 } from \"./7702.js\";\nimport { InternalError } from \"ox/RpcResponse\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartAccountSigner;\n accountAddress: Address;\n counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts\n delegation?: Address;\n capabilities?: StaticDecode<typeof Capabilities>;\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n * @param params - The parameters for creating a smart account.\n * @returns A promise that resolves to the created smart account.\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, ...accountParams } = params;\n\n const mode = params.delegation ? \"7702\" : \"default\";\n\n if (mode === \"default\") {\n if (!ci) {\n throw new InternalError({\n message: \"Counterfactual info not found\",\n });\n }\n if (ci.factoryType !== \"MAv2.0.0-sma-b\") {\n throw new InternalError({\n message: `Factory type ${ci.factoryType} is not currently supported.`,\n });\n }\n } else if (mode === \"7702\") {\n const accountType = getAccountTypeForImplementationAddress7702(\n params.delegation!,\n );\n if (accountType !== \"ModularAccountV2\") {\n throw new InternalError({\n message: \"7702 mode currently only supports ModularAccountV2\",\n });\n }\n } else {\n assertNever(mode, \"Unexpected mode in createAccount\");\n }\n\n const parsedContext = parsePermissionsContext(\n params.capabilities,\n ci,\n params.delegation,\n );\n\n const signerEntity =\n parsedContext?.contextVersion === \"NON_DEFERRED_ACTION\"\n ? {\n entityId: hexToNumber(parsedContext.entityId),\n isGlobalValidation: parsedContext.isGlobalValidation,\n }\n : undefined;\n\n // TODO: clean this up to support different account types.\n return createModularAccountV2({\n ...accountParams,\n signerEntity,\n deferredAction: parsedContext?.deferredAction,\n initCode: ci ? concatHex([ci.factoryAddress, ci.factoryData]) : undefined,\n mode,\n });\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import {} from "@aa-sdk/core";
2
- import {} from "viem";
2
+ import { BaseError, } from "viem";
3
3
  export const createDummySigner = (address) => ({
4
4
  signerType: "",
5
5
  inner: undefined,
@@ -8,10 +8,10 @@ export const createDummySigner = (address) => ({
8
8
  },
9
9
  // Not supported on the server
10
10
  signMessage: function (_message) {
11
- throw new Error("Function not implemented.");
11
+ throw new BaseError("signMessage not implemented by dummy signer.");
12
12
  },
13
13
  signTypedData: function (_params) {
14
- throw new Error("Function not implemented.");
14
+ throw new BaseError("signTypedData not implemented by dummy signer.");
15
15
  },
16
16
  });
17
17
  //# sourceMappingURL=createDummySigner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createDummySigner.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createDummySigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,cAAc,CAAC;AAEvD,OAAO,EAKN,MAAM,MAAM,CAAC;AAEd,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAgB,EAAsB,EAAE,CAAC,CAAC;IAC1E,UAAU,EAAE,EAAE;IACd,KAAK,EAAE,SAAS;IAChB,UAAU,EAAE,KAAK;QACf,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,8BAA8B;IAC9B,WAAW,EAAE,UAAU,QAAyB;QAC9C,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,aAAa,EAAE,UAGb,OAAsD;QACtD,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { type SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { TypedData } from \"abitype\";\nimport {\n type Address,\n type Hex,\n type SignableMessage,\n type TypedDataDefinition,\n} from \"viem\";\n\nexport const createDummySigner = (address: Address): SmartAccountSigner => ({\n signerType: \"\",\n inner: undefined,\n getAddress: async function (): Promise<`0x${string}`> {\n return address;\n },\n // Not supported on the server\n signMessage: function (_message: SignableMessage): Promise<Hex> {\n throw new Error(\"Function not implemented.\");\n },\n signTypedData: function <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | \"EIP712Domain\" = keyof TTypedData,\n >(_params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {\n throw new Error(\"Function not implemented.\");\n },\n});\n"]}
1
+ {"version":3,"file":"createDummySigner.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createDummySigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,cAAc,CAAC;AAEvD,OAAO,EACL,SAAS,GAKV,MAAM,MAAM,CAAC;AAEd,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAgB,EAAsB,EAAE,CAAC,CAAC;IAC1E,UAAU,EAAE,EAAE;IACd,KAAK,EAAE,SAAS;IAChB,UAAU,EAAE,KAAK;QACf,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,8BAA8B;IAC9B,WAAW,EAAE,UAAU,QAAyB;QAC9C,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAC;IACtE,CAAC;IACD,aAAa,EAAE,UAGb,OAAsD;QACtD,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACxE,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { type SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { TypedData } from \"abitype\";\nimport {\n BaseError,\n type Address,\n type Hex,\n type SignableMessage,\n type TypedDataDefinition,\n} from \"viem\";\n\nexport const createDummySigner = (address: Address): SmartAccountSigner => ({\n signerType: \"\",\n inner: undefined,\n getAddress: async function (): Promise<`0x${string}`> {\n return address;\n },\n // Not supported on the server\n signMessage: function (_message: SignableMessage): Promise<Hex> {\n throw new BaseError(\"signMessage not implemented by dummy signer.\");\n },\n signTypedData: function <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | \"EIP712Domain\" = keyof TTypedData,\n >(_params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {\n throw new BaseError(\"signTypedData not implemented by dummy signer.\");\n },\n});\n"]}
@@ -1,7 +1,8 @@
1
1
  import type { StaticDecode } from "@sinclair/typebox";
2
2
  import type { TypeSerializedInitcode } from "../../schemas.js";
3
3
  import type { PrepareCallsParams } from "../actions/prepareCalls.js";
4
- export declare function parsePermissionsContext(capabilities: PrepareCallsParams["capabilities"], parsedCi: StaticDecode<typeof TypeSerializedInitcode>): ({
4
+ import type { Address } from "viem";
5
+ export declare function parsePermissionsContext(capabilities: PrepareCallsParams["capabilities"], parsedCi: StaticDecode<typeof TypeSerializedInitcode> | undefined, delegation7702?: Address): ({
5
6
  contextVersion: keyof typeof import("../../exports/internal.js").PermissionsContextVersion;
6
7
  } & {
7
8
  contextVersion: "LOCAL_MODE_DEFERRED_ACTION";
@@ -1,16 +1,28 @@
1
1
  import { InvalidRequestError } from "ox/RpcResponse";
2
2
  import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
3
- export function parsePermissionsContext(capabilities, parsedCi) {
4
- if (!capabilities?.permissions?.context) {
3
+ import { getAccountTypeForImplementationAddress7702 } from "./7702.js";
4
+ export function parsePermissionsContext(capabilities, parsedCi, delegation7702) {
5
+ if (!capabilities?.permissions) {
5
6
  return undefined;
6
7
  }
7
- if (capabilities?.permissions?.context &&
8
- parsedCi.factoryType !== "MAv2.0.0-sma-b") {
8
+ if ("sessionId" in capabilities.permissions) {
9
+ throw new InvalidRequestError({
10
+ message: "Remote permissions are not supported in isomorphic client",
11
+ });
12
+ }
13
+ if (!("context" in capabilities.permissions)) {
14
+ return undefined;
15
+ }
16
+ const isMAV2 = (parsedCi && parsedCi.factoryType === "MAv2.0.0-sma-b") ||
17
+ (delegation7702 &&
18
+ getAccountTypeForImplementationAddress7702(delegation7702) ===
19
+ "ModularAccountV2");
20
+ if (!isMAV2) {
9
21
  throw new InvalidRequestError({
10
22
  message: "Permissions are currently only supported by MAv2 accounts",
11
23
  });
12
24
  }
13
- const context = decodePermissionsContext(capabilities.permissions.context);
25
+ const context = decodePermissionsContext(capabilities.permissions);
14
26
  if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
15
27
  throw new InvalidRequestError({
16
28
  message: "Remote mode deferred action not supported in isomorphic client",
@@ -1 +1 @@
1
- {"version":3,"file":"parsePermissionsContext.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/parsePermissionsContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAIlF,MAAM,UAAU,uBAAuB,CACrC,YAAgD,EAChD,QAAqD;IAErD,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IACE,YAAY,EAAE,WAAW,EAAE,OAAO;QAClC,QAAQ,CAAC,WAAW,KAAK,gBAAgB,EACzC,CAAC;QACD,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,wBAAwB,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAE3E,IAAI,OAAO,EAAE,cAAc,KAAK,6BAA6B,EAAE,CAAC;QAC9D,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,gEAAgE;SAC1E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { StaticDecode } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport type { PrepareCallsParams } from \"../actions/prepareCalls.js\";\n\nexport function parsePermissionsContext(\n capabilities: PrepareCallsParams[\"capabilities\"],\n parsedCi: StaticDecode<typeof TypeSerializedInitcode>,\n) {\n if (!capabilities?.permissions?.context) {\n return undefined;\n }\n\n if (\n capabilities?.permissions?.context &&\n parsedCi.factoryType !== \"MAv2.0.0-sma-b\"\n ) {\n throw new InvalidRequestError({\n message: \"Permissions are currently only supported by MAv2 accounts\",\n });\n }\n\n const context = decodePermissionsContext(capabilities.permissions.context);\n\n if (context?.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message: \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return context;\n}\n"]}
1
+ {"version":3,"file":"parsePermissionsContext.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/parsePermissionsContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAIlF,OAAO,EAAE,0CAA0C,EAAE,MAAM,WAAW,CAAC;AAEvE,MAAM,UAAU,uBAAuB,CACrC,YAAgD,EAChD,QAAiE,EACjE,cAAwB;IAExB,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,CAAC,SAAS,IAAI,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GACV,CAAC,QAAQ,IAAI,QAAQ,CAAC,WAAW,KAAK,gBAAgB,CAAC;QACvD,CAAC,cAAc;YACb,0CAA0C,CAAC,cAAc,CAAC;gBACxD,kBAAkB,CAAC,CAAC;IAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,wBAAwB,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAEnE,IAAI,OAAO,EAAE,cAAc,KAAK,6BAA6B,EAAE,CAAC;QAC9D,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,gEAAgE;SAC1E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { StaticDecode } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport type { PrepareCallsParams } from \"../actions/prepareCalls.js\";\nimport type { Address } from \"viem\";\nimport { getAccountTypeForImplementationAddress7702 } from \"./7702.js\";\n\nexport function parsePermissionsContext(\n capabilities: PrepareCallsParams[\"capabilities\"],\n parsedCi: StaticDecode<typeof TypeSerializedInitcode> | undefined,\n delegation7702?: Address,\n) {\n if (!capabilities?.permissions) {\n return undefined;\n }\n\n if (\"sessionId\" in capabilities.permissions) {\n throw new InvalidRequestError({\n message: \"Remote permissions are not supported in isomorphic client\",\n });\n }\n\n if (!(\"context\" in capabilities.permissions)) {\n return undefined;\n }\n\n const isMAV2 =\n (parsedCi && parsedCi.factoryType === \"MAv2.0.0-sma-b\") ||\n (delegation7702 &&\n getAccountTypeForImplementationAddress7702(delegation7702) ===\n \"ModularAccountV2\");\n\n if (!isMAV2) {\n throw new InvalidRequestError({\n message: \"Permissions are currently only supported by MAv2 accounts\",\n });\n }\n\n const context = decodePermissionsContext(capabilities.permissions);\n\n if (context?.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message: \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return context;\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  import { type Address, type JsonRpcAccount } from "viem";
2
- import type { CreateInnerClientParams, InnerWalletApiClient } from "../types";
2
+ import type { CreateInnerClientParams, InnerWalletApiClient } from "../types.ts";
3
3
  export declare function createLocalClient<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient<TAccount>;
@@ -3,6 +3,7 @@ import { buildDeferredActionDigest } from "@account-kit/smart-contracts/experime
3
3
  import { createClient, custom } from "viem";
4
4
  import { encodePermissionsContext, prefixSignatureKeyType, } from "../capabilities/permissions/mav2.js";
5
5
  import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
6
+ import { internalStateDecorator } from "../internal/decorator.js";
6
7
  import { createIsomorphicClient, } from "../isomorphic/client.js";
7
8
  import { assertNever } from "../utils.js";
8
9
  const localMethods = [
@@ -56,6 +57,8 @@ export function createLocalClient(params) {
56
57
  return assertNever(args.method, `Unexpected method: ${args.method}`);
57
58
  }
58
59
  },
60
+ }, {
61
+ retryCount: 0,
59
62
  }),
60
63
  },
61
64
  ],
@@ -65,16 +68,20 @@ export function createLocalClient(params) {
65
68
  transport: innerTransport,
66
69
  chain,
67
70
  account,
68
- }).extend(() => ({
71
+ })
72
+ .extend(() => ({
69
73
  policyId,
70
74
  ...innerClientActions(isomorphicClient),
75
+ }))
76
+ .extend(() => ({
77
+ internal: internalStateDecorator(),
71
78
  }));
72
79
  }
73
80
  const innerClientActions = (isomorphicClient) => {
74
81
  return {
75
82
  grantPermissions: async (signer, params) => {
76
83
  const { signatureRequest, fullPreSignatureDeferredActionDigest } = await isomorphicClient.createSession(params);
77
- const { signature } = await signSignatureRequest(signer, signatureRequest);
84
+ const { signedAuthorization, signature } = await signSignatureRequest(signer, signatureRequest);
78
85
  return {
79
86
  context: encodePermissionsContext({
80
87
  contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
@@ -83,6 +90,7 @@ const innerClientActions = (isomorphicClient) => {
83
90
  sig: prefixSignatureKeyType(signature, "secp256k1"),
84
91
  }),
85
92
  }),
93
+ signedAuthorization,
86
94
  };
87
95
  },
88
96
  };