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

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 (57) hide show
  1. package/dist/esm/client/actions/prepareCalls.d.ts +1 -1
  2. package/dist/esm/client/actions/prepareCalls.js +1 -1
  3. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  4. package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -2
  5. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  6. package/dist/esm/isomorphic/actions/createSession.js +11 -2
  7. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  8. package/dist/esm/isomorphic/actions/prepareCalls.js +21 -14
  9. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  10. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +53 -8
  11. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  12. package/dist/esm/isomorphic/client.d.ts +9 -0
  13. package/dist/esm/isomorphic/utils/7702.js +21 -8
  14. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  15. package/dist/esm/isomorphic/utils/createAccount.js +73 -33
  16. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  17. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +4 -0
  18. package/dist/esm/isomorphic/utils/supportsFeature.js +21 -0
  19. package/dist/esm/isomorphic/utils/supportsFeature.js.map +1 -0
  20. package/dist/esm/rpc/request.d.ts +12 -2
  21. package/dist/esm/rpc/schema.d.ts +12 -2
  22. package/dist/esm/schemas.d.ts +16 -1
  23. package/dist/esm/schemas.js +12 -1
  24. package/dist/esm/schemas.js.map +1 -1
  25. package/dist/esm/types.d.ts +3 -0
  26. package/dist/esm/types.js.map +1 -1
  27. package/dist/types/client/actions/prepareCalls.d.ts +1 -1
  28. package/dist/types/client/actions/signSignatureRequest.d.ts +3 -2
  29. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  30. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  31. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  32. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  33. package/dist/types/isomorphic/client.d.ts +9 -0
  34. package/dist/types/isomorphic/client.d.ts.map +1 -1
  35. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  36. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  37. package/dist/types/isomorphic/utils/supportsFeature.d.ts +5 -0
  38. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +1 -0
  39. package/dist/types/rpc/request.d.ts +12 -2
  40. package/dist/types/rpc/request.d.ts.map +1 -1
  41. package/dist/types/rpc/schema.d.ts +12 -2
  42. package/dist/types/rpc/schema.d.ts.map +1 -1
  43. package/dist/types/schemas.d.ts +16 -1
  44. package/dist/types/schemas.d.ts.map +1 -1
  45. package/dist/types/types.d.ts +3 -0
  46. package/dist/types/types.d.ts.map +1 -1
  47. package/package.json +2 -2
  48. package/src/client/actions/prepareCalls.ts +1 -1
  49. package/src/client/actions/signSignatureRequest.ts +4 -2
  50. package/src/isomorphic/actions/createSession.ts +14 -1
  51. package/src/isomorphic/actions/prepareCalls.ts +22 -13
  52. package/src/isomorphic/actions/sendPreparedCalls.ts +59 -9
  53. package/src/isomorphic/utils/7702.ts +25 -9
  54. package/src/isomorphic/utils/createAccount.ts +81 -34
  55. package/src/isomorphic/utils/supportsFeature.ts +34 -0
  56. package/src/schemas.ts +20 -1
  57. package/src/types.ts +4 -0
@@ -26,7 +26,7 @@ export type PrepareCallsResult = IsomorphicPrepareCallsResult;
26
26
  * the user operation data and signature request
27
27
  *
28
28
  * @example
29
- * // Prepare a sponosored user operation call
29
+ * // Prepare a sponsored user operation call
30
30
  * const result = await client.prepareCalls({
31
31
  * calls: [{
32
32
  * to: "0x1234...",
@@ -14,7 +14,7 @@ import { toHex } from "viem";
14
14
  * the user operation data and signature request
15
15
  *
16
16
  * @example
17
- * // Prepare a sponosored user operation call
17
+ * // Prepare a sponsored user operation call
18
18
  * const result = await client.prepareCalls({
19
19
  * calls: [{
20
20
  * to: "0x1234...",
@@ -1 +1 @@
1
- {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/client/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,KAAK,EAAkC,MAAM,MAAM,CAAC;AAmB7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAGhC,MAA4B,EAC5B,MAAoC;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IAEpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,gBAAgB,EAAE,CAAC;QAC9D,MAAM,CAAC,YAAY,GAAG;YACpB,GAAG,MAAM,CAAC,YAAY;YACtB,gBAAgB,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE;SAChD,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG;QACd,GAAG,MAAM;QACT,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,IAAI;KACL,CAAC;IAEF,OAAO,MAAM,MAAM,CAAC,OAAO,CAAC;QAC1B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,CAAC,OAAO,CAAC;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { AccountNotFoundError } from \"@aa-sdk/core\";\nimport { toHex, type Address, type IsUndefined } from \"viem\";\nimport type {\n PrepareCallsParams as IsomorphicPrepareCallsParams,\n PrepareCallsResult as IsomorphicPrepareCallsResult,\n} from \"../../isomorphic/actions/prepareCalls.ts\";\nimport type { InnerWalletApiClient } from \"../../types.ts\";\n\nexport type GetAccountParam<TAccount> =\n IsUndefined<TAccount> extends true\n ? { account: Address }\n : { account?: Address };\n\nexport type PrepareCallsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Omit<IsomorphicPrepareCallsParams, \"from\" | \"chainId\"> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never });\n\nexport type PrepareCallsResult = IsomorphicPrepareCallsResult;\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request\n * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * // Prepare a sponosored user operation call\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n */\nexport async function prepareCalls<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareCallsParams<TAccount>,\n): Promise<PrepareCallsResult> {\n const from = params.from ?? client.account?.address;\n\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n if (client.policyId && !params.capabilities?.paymasterService) {\n params.capabilities = {\n ...params.capabilities,\n paymasterService: { policyId: client.policyId },\n };\n }\n\n const params_ = {\n ...params,\n chainId: toHex(client.chain.id),\n from,\n };\n\n return await client.request({\n method: \"wallet_prepareCalls\",\n params: [params_],\n });\n}\n"]}
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/client/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,KAAK,EAAkC,MAAM,MAAM,CAAC;AAmB7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAGhC,MAA4B,EAC5B,MAAoC;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;IAEpD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,gBAAgB,EAAE,CAAC;QAC9D,MAAM,CAAC,YAAY,GAAG;YACpB,GAAG,MAAM,CAAC,YAAY;YACtB,gBAAgB,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE;SAChD,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG;QACd,GAAG,MAAM;QACT,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,IAAI;KACL,CAAC;IAEF,OAAO,MAAM,MAAM,CAAC,OAAO,CAAC;QAC1B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,CAAC,OAAO,CAAC;KAClB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { AccountNotFoundError } from \"@aa-sdk/core\";\nimport { toHex, type Address, type IsUndefined } from \"viem\";\nimport type {\n PrepareCallsParams as IsomorphicPrepareCallsParams,\n PrepareCallsResult as IsomorphicPrepareCallsResult,\n} from \"../../isomorphic/actions/prepareCalls.ts\";\nimport type { InnerWalletApiClient } from \"../../types.ts\";\n\nexport type GetAccountParam<TAccount> =\n IsUndefined<TAccount> extends true\n ? { account: Address }\n : { account?: Address };\n\nexport type PrepareCallsParams<\n TAccount extends Address | undefined = Address | undefined,\n> = Omit<IsomorphicPrepareCallsParams, \"from\" | \"chainId\"> &\n (IsUndefined<TAccount> extends true ? { from: Address } : { from?: never });\n\nexport type PrepareCallsResult = IsomorphicPrepareCallsResult;\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * @param {InnerWalletApiClient<TAccount>} client - The wallet API client to use for the request\n * @param {PrepareCallsParams<TAccount>} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} params.calls - Array of contract calls to execute\n * @param {Address} [params.from] - The address to execute the calls from (required if the client wasn't initialized with an account)\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * // Prepare a sponsored user operation call\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: \"0x0\"\n * }],\n * capabilities: {\n * paymasterService: { policyId: \"your-policy-id\" }\n * }\n * });\n */\nexport async function prepareCalls<\n TAccount extends Address | undefined = Address | undefined,\n>(\n client: InnerWalletApiClient,\n params: PrepareCallsParams<TAccount>,\n): Promise<PrepareCallsResult> {\n const from = params.from ?? client.account?.address;\n\n if (!from) {\n throw new AccountNotFoundError();\n }\n\n if (client.policyId && !params.capabilities?.paymasterService) {\n params.capabilities = {\n ...params.capabilities,\n paymasterService: { policyId: client.policyId },\n };\n }\n\n const params_ = {\n ...params,\n chainId: toHex(client.chain.id),\n from,\n };\n\n return await client.request({\n method: \"wallet_prepareCalls\",\n params: [params_],\n });\n}\n"]}
@@ -3,9 +3,10 @@ import type { Static } from "@sinclair/typebox";
3
3
  import { type Hex } from "viem";
4
4
  import { TypeAuthorizationSignatureRequest, TypePersonalSignSignatureRequest, TypeTypedDataSignatureRequest } from "../../schemas.js";
5
5
  import { TypeEip7702UnsignedAuth } from "../../schemas.js";
6
- export type SignSignatureRequestParams = Static<typeof TypePersonalSignSignatureRequest> | Static<typeof TypeTypedDataSignatureRequest> | (Static<typeof TypeAuthorizationSignatureRequest> & {
6
+ import type { WithoutRawPayload } from "../../types.ts";
7
+ export type SignSignatureRequestParams = WithoutRawPayload<Static<typeof TypePersonalSignSignatureRequest> | Static<typeof TypeTypedDataSignatureRequest> | (Static<typeof TypeAuthorizationSignatureRequest> & {
7
8
  data: Static<typeof TypeEip7702UnsignedAuth>;
8
- });
9
+ })>;
9
10
  export type SignSignatureRequestResult = {
10
11
  type: "secp256k1";
11
12
  data: Hex;
@@ -1 +1 @@
1
- {"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,WAAW,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAChC,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAc1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA0B,EAC1B,MAAkC;IAElC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;aAC5C,CAAC;QACJ,CAAC;QACD,KAAK,sBAAsB,CAAC,CAAC,CAAC;YAC5B,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;aAC9C,CAAC;QACJ,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;gBAC1D,GAAG,MAAM,CAAC,IAAI;gBACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;gBACzC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;aACtC,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,CAAC;oBACD,CAAC;oBACD,OAAO,EAAE,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAC1C,CAAC;aACH,CAAC;QACJ,CAAC;QACD;YACE,OAAO,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { type Hex, hexToNumber, serializeSignature } from \"viem\";\nimport { assertNever } from \"../../utils.js\";\nimport {\n TypeAuthorizationSignatureRequest,\n TypePersonalSignSignatureRequest,\n TypeTypedDataSignatureRequest,\n} from \"../../schemas.js\";\nimport { TypeEip7702UnsignedAuth } from \"../../schemas.js\";\nimport { vToYParity } from \"ox/Signature\";\n\nexport type SignSignatureRequestParams =\n | Static<typeof TypePersonalSignSignatureRequest>\n | Static<typeof TypeTypedDataSignatureRequest>\n | (Static<typeof TypeAuthorizationSignatureRequest> & {\n data: Static<typeof TypeEip7702UnsignedAuth>;\n });\n\nexport type SignSignatureRequestResult = {\n type: \"secp256k1\";\n data: Hex;\n};\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.\n *\n * @param {SmartAccountSigner} signer - The signer to use for signing the request\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {any} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n * @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)\n * @returns {Hex} result.signature - The hex-encoded signature\n * @returns {Eip7702ExtendedFields[\"eip7702Auth\"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable\n *\n * @example\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * @example\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n */\n\nexport async function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n switch (params.type) {\n case \"personal_sign\": {\n return {\n type: \"secp256k1\",\n data: await signer.signMessage(params.data),\n };\n }\n case \"eth_signTypedData_v4\": {\n return {\n type: \"secp256k1\",\n data: await signer.signTypedData(params.data),\n };\n }\n case \"eip7702Auth\": {\n if (!signer.signAuthorization) {\n throw new Error(\"Signer does not implement signAuthorization\");\n }\n const { r, s, v, yParity } = await signer.signAuthorization({\n ...params.data,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n });\n\n return {\n type: \"secp256k1\",\n data: serializeSignature({\n r,\n s,\n yParity: yParity ?? vToYParity(Number(v)),\n }),\n };\n }\n default:\n return assertNever(params, `Unexpected signature request type.`);\n }\n}\n"]}
1
+ {"version":3,"file":"signSignatureRequest.js","sourceRoot":"","sources":["../../../../src/client/actions/signSignatureRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,WAAW,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAChC,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAgB1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA0B,EAC1B,MAAkC;IAElC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;aAC5C,CAAC;QACJ,CAAC;QACD,KAAK,sBAAsB,CAAC,CAAC,CAAC;YAC5B,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;aAC9C,CAAC;QACJ,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;gBAC1D,GAAG,MAAM,CAAC,IAAI;gBACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;gBACzC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;aACtC,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,kBAAkB,CAAC;oBACvB,CAAC;oBACD,CAAC;oBACD,OAAO,EAAE,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAC1C,CAAC;aACH,CAAC;QACJ,CAAC;QACD;YACE,OAAO,WAAW,CAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { type Hex, hexToNumber, serializeSignature } from \"viem\";\nimport { assertNever } from \"../../utils.js\";\nimport {\n TypeAuthorizationSignatureRequest,\n TypePersonalSignSignatureRequest,\n TypeTypedDataSignatureRequest,\n} from \"../../schemas.js\";\nimport { TypeEip7702UnsignedAuth } from \"../../schemas.js\";\nimport { vToYParity } from \"ox/Signature\";\nimport type { WithoutRawPayload } from \"../../types.ts\";\n\nexport type SignSignatureRequestParams = WithoutRawPayload<\n | Static<typeof TypePersonalSignSignatureRequest>\n | Static<typeof TypeTypedDataSignatureRequest>\n | (Static<typeof TypeAuthorizationSignatureRequest> & {\n data: Static<typeof TypeEip7702UnsignedAuth>;\n })\n>;\n\nexport type SignSignatureRequestResult = {\n type: \"secp256k1\";\n data: Hex;\n};\n\n/**\n * Signs a signature request using the provided signer.\n * This method handles different types of signature requests including personal_sign, eth_signTypedData_v4, and authorization.\n *\n * @param {SmartAccountSigner} signer - The signer to use for signing the request\n * @param {SignSignatureRequestParams} params - The signature request parameters\n * @param {string} params.type - The type of signature request ('personal_sign', 'eth_signTypedData_v4', or 'signature_with_authorization')\n * @param {any} params.data - The data to sign, format depends on the signature type\n * @returns {Promise<SignSignatureRequestResult>} A Promise that resolves to the signature result\n * @returns {string} result.type - The signature type (currently only 'secp256k1' is supported)\n * @returns {Hex} result.signature - The hex-encoded signature\n * @returns {Eip7702ExtendedFields[\"eip7702Auth\"]} result.signedAuthorization - The signed EIP-7702 authorization, if applicable\n *\n * @example\n * // Sign a personal message\n * const result = await client.signSignatureRequest({\n * type: 'personal_sign',\n * data: 'Hello, world!'\n * });\n *\n * @example\n * // Sign typed data (EIP-712)\n * const result = await client.signSignatureRequest({\n * type: 'eth_signTypedData_v4',\n * data: {\n * domain: { ... },\n * types: { ... },\n * primaryType: '...',\n * message: { ... }\n * }\n * });\n */\n\nexport async function signSignatureRequest(\n signer: SmartAccountSigner,\n params: SignSignatureRequestParams,\n): Promise<SignSignatureRequestResult> {\n switch (params.type) {\n case \"personal_sign\": {\n return {\n type: \"secp256k1\",\n data: await signer.signMessage(params.data),\n };\n }\n case \"eth_signTypedData_v4\": {\n return {\n type: \"secp256k1\",\n data: await signer.signTypedData(params.data),\n };\n }\n case \"eip7702Auth\": {\n if (!signer.signAuthorization) {\n throw new Error(\"Signer does not implement signAuthorization\");\n }\n const { r, s, v, yParity } = await signer.signAuthorization({\n ...params.data,\n chainId: hexToNumber(params.data.chainId),\n nonce: hexToNumber(params.data.nonce),\n });\n\n return {\n type: \"secp256k1\",\n data: serializeSignature({\n r,\n s,\n yParity: yParity ?? vToYParity(Number(v)),\n }),\n };\n }\n default:\n return assertNever(params, `Unexpected signature request type.`);\n }\n}\n"]}
@@ -1,12 +1,13 @@
1
1
  import { createSmartAccountClient, } from "@aa-sdk/core";
2
2
  import { deferralActions, PermissionBuilder, } from "@account-kit/smart-contracts/experimental";
3
3
  import { Value } from "@sinclair/typebox/value";
4
- import { ChainNotFoundError, custom, hexToNumber, toHex, } from "viem";
4
+ import { ChainNotFoundError, custom, hashTypedData, hexToNumber, toHex, } from "viem";
5
+ import { InvalidRequestError } from "ox/RpcResponse";
5
6
  import { TypePermission } from "../../capabilities/permissions/index.js";
6
7
  import { isGlobalValidation } from "../../capabilities/permissions/mav2.js";
7
8
  import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
8
9
  import { createDummySigner } from "../utils/createDummySigner.js";
9
- import { InvalidRequestError } from "ox/RpcResponse";
10
+ import { supportsFeature } from "../utils/supportsFeature.js";
10
11
  export async function createSession(client, params) {
11
12
  if (!client.chain) {
12
13
  throw new ChainNotFoundError();
@@ -30,6 +31,13 @@ export async function createSession(client, params) {
30
31
  message: "No counterfactual info found.",
31
32
  });
32
33
  }
34
+ if (counterfactualInfo &&
35
+ !supportsFeature(counterfactualInfo, "permissions")) {
36
+ throw new InvalidRequestError({
37
+ message: "Account type does not support createSession",
38
+ });
39
+ }
40
+ // At this point we know the account supports the permission feature
33
41
  const account = await createAccount({
34
42
  chain: client.chain,
35
43
  transport: custom(client.transport),
@@ -73,6 +81,7 @@ export async function createSession(client, params) {
73
81
  signatureRequest: {
74
82
  type: "eth_signTypedData_v4",
75
83
  data: typedData,
84
+ rawPayload: hashTypedData(typedData),
76
85
  },
77
86
  fullPreSignatureDeferredActionDigest,
78
87
  };
@@ -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;AA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;KACR,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"]}
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,aAAa,EACb,WAAW,EACX,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,E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Aa,CAAC,SAAS,CAAC;SACrC;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 hashTypedData,\n hexToNumber,\n toHex,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\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 { supportsFeature } from \"../utils/supportsFeature.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, 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 if (\n counterfactualInfo &&\n !supportsFeature(counterfactualInfo, \"permissions\")\n ) {\n throw new InvalidRequestError({\n message: \"Account type does not support createSession\",\n });\n }\n\n // At this point we know the account supports the permission feature\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 rawPayload: hashTypedData(typedData),\n },\n fullPreSignatureDeferredActionDigest,\n };\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { deepHexlify, default7702GasEstimator, } from "@aa-sdk/core";
2
- import { ChainNotFoundError, custom, fromHex, toHex, } from "viem";
2
+ import { ChainNotFoundError, custom, fromHex, hashMessage, toHex, } from "viem";
3
3
  import { createAccount } from "../utils/createAccount.js";
4
4
  import { createDummySigner } from "../utils/createDummySigner.js";
5
- import { createAuthorizationRequest, parseDelegation } from "../utils/7702.js";
5
+ import { createAuthorizationRequest } from "../utils/7702.js";
6
6
  import { InvalidRequestError } from "ox/RpcResponse";
7
7
  import { assertNever } from "../../utils.js";
8
8
  import { assertValid7702AccountAddress } from "../utils/7702.js";
@@ -12,20 +12,23 @@ export async function prepareCalls(client, params) {
12
12
  }
13
13
  assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);
14
14
  // in local mode, we probably want some kind of caching for this
15
- const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth
16
- ? {
17
- counterfactualInfo: undefined,
18
- delegation: parseDelegation(params.capabilities.eip7702Auth),
19
- }
20
- : await client.request({
21
- method: "wallet_requestAccount",
22
- params: [
23
- {
15
+ const { counterfactualInfo, delegation } = await client.request({
16
+ method: "wallet_requestAccount",
17
+ params: [
18
+ params.capabilities?.eip7702Auth
19
+ ? {
20
+ signerAddress: params.from,
21
+ creationHint: {
22
+ accountType: "7702",
23
+ },
24
+ includeCounterfactualInfo: true,
25
+ }
26
+ : {
24
27
  accountAddress: params.from,
25
28
  includeCounterfactualInfo: true,
26
29
  },
27
- ],
28
- });
30
+ ],
31
+ });
29
32
  if (!counterfactualInfo && !delegation) {
30
33
  throw new InvalidRequestError({
31
34
  message: "No counterfactual info or delegated implementation address found.",
@@ -69,6 +72,7 @@ export async function prepareCalls(client, params) {
69
72
  }
70
73
  const hexlifiedUo = deepHexlify(builtUo);
71
74
  const ep = account.getEntryPoint();
75
+ const uoHash = ep.getUserOperationHash(hexlifiedUo);
72
76
  const uoRequest = {
73
77
  type: ep.version === "0.7.0"
74
78
  ? "user-operation-v070"
@@ -80,8 +84,11 @@ export async function prepareCalls(client, params) {
80
84
  signatureRequest: {
81
85
  type: "personal_sign",
82
86
  data: {
83
- raw: ep.getUserOperationHash(hexlifiedUo),
87
+ raw: uoHash,
84
88
  },
89
+ rawPayload: hashMessage({
90
+ raw: uoHash,
91
+ }),
85
92
  },
86
93
  };
87
94
  return authorizationRequ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AAiB;KAClD,CAAC,CAAC;IAEH,+DAA+D;IAC/D,6DAA6D;IAC7D,IAAI,aAAa,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAClC,CAAC;IAED,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEzC,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAEnC,MAAM,SAAS,GAAG;QAChB,IAAI,EACF,EAAE,CAAC,OAAO,KAAK,OAAO;YACpB,CAAC,CAAE,qBAA+B;YAClC,CAAC,CAAC,EAAE,CAAC,OAAO,KAAK,OAAO;gBACtB,CAAC,CAAE,qBAA+B;gBAClC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,gCAAgC,CAAC;QACjE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAwB;YAC9B,IAAI,EAAE;gBACJ,GAAG,EAAE,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC;aAC1C;SACF;KACF,CAAC;IAEF,OAAO,oBAAoB;QACzB,CAAC,CAAC;YACE,IAAI,EAAE,OAAgB;YACtB,IAAI,EAAE,CAAC,oBAAoB,EAAE,SAAS,CAAC;SACxC;QACH,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC","sourcesContent":["import {\n deepHexlify,\n default7702GasEstimator,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport {\n ChainNotFoundError,\n custom,\n fromHex,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { wallet_prepareCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorizationRequest, parseDelegation } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport { assertValid7702AccountAddress } from \"../utils/7702.js\";\n\nexport type PrepareCallsParams = Omit<\n Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type PrepareCallsResult = Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function prepareCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);\n\n // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth\n ? {\n counterfactualInfo: undefined,\n delegation: parseDelegation(params.capabilities.eip7702Auth),\n }\n : await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.from),\n accountAddress: params.from,\n counterfactualInfo,\n permissions: params.capabilities?.permissions,\n delegation,\n });\n\n // If using 7702, we need an Authorization (unless it's already authorized).\n const authorizationRequest = delegation\n ? await createAuthorizationRequest(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n if (authorizationRequest) {\n // @ts-expect-error - this is available but not typed as public\n client.middleware.gasEstimator = default7702GasEstimator();\n }\n\n // TODO: oops we don't actually support setting the policyId as an override here\n // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly\n const builtUo = await client.buildUserOperation({\n uo: params.calls.map((x) => ({\n target: x.to,\n data: x.data ?? \"0x\",\n value: x.value ? fromHex(x.value, \"bigint\") : undefined,\n })),\n account,\n overrides: params.capabilities?.gasParamsOverride,\n });\n\n // The eip7702Auth field should never be included in the UO sig\n // request. It's handled by a separate authorization request.\n if (\"eip7702Auth\" in builtUo) {\n builtUo.eip7702Auth = undefined;\n }\n\n const hexlifiedUo = deepHexlify(builtUo);\n\n const ep = account.getEntryPoint();\n\n const uoRequest = {\n type:\n ep.version === \"0.7.0\"\n ? (\"user-operation-v070\" as const)\n : ep.version === \"0.6.0\"\n ? (\"user-operation-v060\" as const)\n : assertNever(ep.version, \"Unexpected entry point version\"),\n data: hexlifiedUo,\n chainId: toHex(client.chain.id),\n signatureRequest: {\n type: \"personal_sign\" as const,\n data: {\n raw: ep.getUserOperationHash(hexlifiedUo),\n },\n },\n };\n\n return authorizationRequest\n ? {\n type: \"array\" as const,\n data: [authorizationRequest, uoRequest],\n }\n : uoRequest;\n}\n"]}
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,WAAW,EACX,KAAK,GAGN,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAajE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAM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W;QACjB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAwB;YAC9B,IAAI,EAAE;gBACJ,GAAG,EAAE,MAAM;aACZ;YACD,UAAU,EAAE,WAAW,CAAC;gBACtB,GAAG,EAAE,MAAM;aACZ,CAAC;SACH;KACF,CAAC;IAEF,OAAO,oBAAoB;QACzB,CAAC,CAAC;YACE,IAAI,EAAE,OAAgB;YACtB,IAAI,EAAE,CAAC,oBAAoB,EAAE,SAAS,CAAC;SACxC;QACH,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC","sourcesContent":["import {\n deepHexlify,\n default7702GasEstimator,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport {\n ChainNotFoundError,\n custom,\n fromHex,\n hashMessage,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { wallet_prepareCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorizationRequest } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport { assertValid7702AccountAddress } from \"../utils/7702.js\";\n\nexport type PrepareCallsParams = Omit<\n Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type PrepareCallsResult = Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function prepareCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);\n\n // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n params.capabilities?.eip7702Auth\n ? {\n signerAddress: params.from,\n creationHint: {\n accountType: \"7702\",\n },\n includeCounterfactualInfo: true,\n }\n : {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.from),\n accountAddress: params.from,\n counterfactualInfo,\n permissions: params.capabilities?.permissions,\n delegation,\n });\n\n // If using 7702, we need an Authorization (unless it's already authorized).\n const authorizationRequest = delegation\n ? await createAuthorizationRequest(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n if (authorizationRequest) {\n // @ts-expect-error - this is available but not typed as public\n client.middleware.gasEstimator = default7702GasEstimator();\n }\n\n // TODO: oops we don't actually support setting the policyId as an override here\n // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly\n const builtUo = await client.buildUserOperation({\n uo: params.calls.map((x) => ({\n target: x.to,\n data: x.data ?? \"0x\",\n value: x.value ? fromHex(x.value, \"bigint\") : undefined,\n })),\n account,\n overrides: params.capabilities?.gasParamsOverride,\n });\n\n // The eip7702Auth field should never be included in the UO sig\n // request. It's handled by a separate authorization request.\n if (\"eip7702Auth\" in builtUo) {\n builtUo.eip7702Auth = undefined;\n }\n\n const hexlifiedUo = deepHexlify(builtUo);\n\n const ep = account.getEntryPoint();\n\n const uoHash = ep.getUserOperationHash(hexlifiedUo);\n\n const uoRequest = {\n type:\n ep.version === \"0.7.0\"\n ? (\"user-operation-v070\" as const)\n : ep.version === \"0.6.0\"\n ? (\"user-operation-v060\" as const)\n : assertNever(ep.version, \"Unexpected entry point version\"),\n data: hexlifiedUo,\n chainId: toHex(client.chain.id),\n signatureRequest: {\n type: \"personal_sign\" as const,\n data: {\n raw: uoHash,\n },\n rawPayload: hashMessage({\n raw: uoHash,\n }),\n },\n };\n\n return authorizationRequest\n ? {\n type: \"array\" as const,\n data: [authorizationRequest, uoRequest],\n }\n : uoRequest;\n}\n"]}
@@ -63,17 +63,62 @@ export async function sendPreparedCalls(client, params) {
63
63
  ? parseSignature(decodeSignature(authorization.signature).data)
64
64
  : undefined;
65
65
  const uoSigHex = decodeSignature(userOp.signature).data;
66
+ const { counterfactualInfo, delegation } = await client.request({
67
+ method: "wallet_requestAccount",
68
+ params: [
69
+ {
70
+ accountAddress: userOp.data.sender,
71
+ includeCounterfactualInfo: true,
72
+ },
73
+ ],
74
+ });
75
+ if (!counterfactualInfo && !delegation) {
76
+ throw new InvalidRequestError({
77
+ message: "No counterfactual info or delegated implementation address found.",
78
+ });
79
+ }
80
+ const factoryType = counterfactualInfo?.factoryType;
81
+ // build signature based on account type
82
+ const signature = (() => {
83
+ switch (factoryType) {
84
+ // light accounts
85
+ case "LightAccountV1.0.1":
86
+ case "LightAccountV1.0.2":
87
+ case "LightAccountV1.1.0":
88
+ // For LAv1, we always just pass the signature.
89
+ return uoSigHex;
90
+ case "LightAccountV2.0.0":
91
+ // for LAv2, we need to prepend the "SignatureType.EOA" byte
92
+ return concat(["0x00", uoSigHex]);
93
+ case undefined: // undefined defaults to sma-b
94
+ case "MAv2.0.0-sma-b":
95
+ // For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
96
+ // Signature Segment" and "SignatureType.EOA" bytes
97
+ return deferredAction != null
98
+ ? concatHex([
99
+ `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
100
+ "0xFF",
101
+ "0x00",
102
+ uoSigHex,
103
+ ])
104
+ : concat(["0xFF", "0x00", uoSigHex]);
105
+ case "MAv2.0.0-ma-ssv":
106
+ case "MAv2.0.0-ma-webauthn":
107
+ case "LightAccountV2.0.0-MultiOwner":
108
+ case "MAv1.0.0-MultiOwner":
109
+ case "MAv1.0.0-MultiSig":
110
+ case "unknown":
111
+ throw new InvalidRequestError({
112
+ message: `Unsupported factory type: ${factoryType}`,
113
+ });
114
+ default:
115
+ return assertNever(factoryType, "Unsupported factory type");
116
+ }
117
+ })();
66
118
  return client
67
119
  .sendRawUserOperation({
68
120
  ...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]),
121
+ signature,
77
122
  eip7702Auth: idx === 0 && authorization && authSig
78
123
  ? {
79
124
  ...authorization.data,
@@ -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;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,CAA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SAAS,CAAC;oBACR,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,+EAA+E;oBAChH,MAAM;oBACN,MAAM;oBACN,QAAQ;iBACT,CAAC;gBACJ,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YACxC,WAAW,EACT,GAAG,KAAK,CAAC,IAAI,aAAa,IAAI,OAAO;gBACnC,CAAC,CAAC;oBACE,GAAG,aAAa,CAAC,IAAI;oBACrB,OAAO,EAAE,aAAa,CAAC,OAAO;oBAC9B,GAAG;wBACD,GAAG,OAAO;wBACV,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC;qBACtC;iBACF;gBACH,CAAC,CAAC,SAAS;SAChB,EACD,EAAE,CAAC,OAAO,CACX;aACA,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,IACE,GAAG,YAAY,SAAS;gBACxB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,yCAAyC,CAAC,EAC/D,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,GAAG,GAAG,CAAC,OAAO,0FAA0F,CACzG,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;YACvB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,IAAI;SACL,CAAC,CACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n getEntryPoint,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n BaseError,\n ChainNotFoundError,\n concat,\n concatHex,\n numberToHex,\n parseSignature,\n toHex,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport { type wallet_sendPreparedCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { TypeCallId } from \"../../schemas.js\";\nimport { isSupportedDelegationAddress7702 } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { decodeSignature } from \"../utils/decodeSignature.js\";\n\nexport type SendPreparedCallsParams = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type SendPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"ReturnType\"]\n>;\n\n// TODO: this only supports MAv2 right now, we need to fix this\nexport async function sendPreparedCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message:\n \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return decodedContext.deferredAction;\n })();\n\n const userOps =\n params.type === \"array\"\n ? params.data.filter((it) => {\n const isUserOp =\n it.type === \"user-operation-v060\" ||\n it.type === \"user-operation-v070\";\n if (isUserOp && it.chainId !== toHex(client.chain.id)) {\n throw new InvalidRequestError({\n message:\n \"Multiple chain IDs in a single request are not currently supported.\",\n });\n }\n return isUserOp;\n })\n : [params];\n\n const authorizations =\n params.type === \"array\"\n ? params.data.filter((it) => it.type === \"authorization\")\n : [];\n\n if (authorizations.length > 1) {\n throw new InvalidRequestError({\n message:\n \"Multiple authorizations in a single request are not currently supported\",\n });\n }\n const [authorization] = authorizations;\n\n // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.\n if (\n authorization &&\n !isSupportedDelegationAddress7702(authorization.data.address)\n ) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${authorization.data.address}`,\n });\n }\n\n const hashes = await Promise.all(\n userOps.map(async (userOp, idx) => {\n const ep: { address: Address } =\n userOp.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : userOp.type === \"user-operation-v070\"\n ? getEntryPoint(client.chain, { version: \"0.7.0\" })\n : assertNever(userOp, \"Unexpected user op type\");\n const authSig = authorization\n ? parseSignature(decodeSignature(authorization.signature).data)\n : undefined;\n const uoSigHex = decodeSignature(userOp.signature).data;\n return client\n .sendRawUserOperation(\n {\n ...userOp.data,\n signature:\n deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc. that we had previously).\n \"0xff\",\n \"0x00\",\n uoSigHex,\n ])\n : concat([\"0xFF\", \"0x00\", uoSigHex]),\n eip7702Auth:\n idx === 0 && authorization && authSig\n ? {\n ...authorization.data,\n chainId: authorization.chainId,\n ...{\n ...authSig,\n yParity: numberToHex(authSig.yParity),\n },\n }\n : undefined,\n },\n ep.address,\n )\n .catch((err) => {\n if (\n err instanceof BaseError &&\n err.details.endsWith(\"is not a contract and initCode is empty\")\n ) {\n throw new BaseError(\n `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,\n );\n }\n throw err;\n });\n }),\n );\n\n return {\n preparedCallIds: hashes.map((hash) =>\n Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n }),\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.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E;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\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: userOp.data.sender,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const factoryType = counterfactualInfo?.factoryType;\n\n // build signature based on account type\n const signature = (() => {\n switch (factoryType) {\n // light accounts\n case \"LightAccountV1.0.1\":\n case \"LightAccountV1.0.2\":\n case \"LightAccountV1.1.0\":\n // For LAv1, we always just pass the signature.\n return uoSigHex;\n case \"LightAccountV2.0.0\":\n // for LAv2, we need to prepend the \"SignatureType.EOA\" byte\n return concat([\"0x00\", uoSigHex]);\n case undefined: // undefined defaults to sma-b\n case \"MAv2.0.0-sma-b\":\n // For sma-b, we need to handle deferred actions if needed and prepend the \"Reserved\n // Signature Segment\" and \"SignatureType.EOA\" bytes\n return deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).\n \"0xFF\",\n \"0x00\",\n uoSigHex,\n ])\n : concat([\"0xFF\", \"0x00\", uoSigHex]);\n case \"MAv2.0.0-ma-ssv\":\n case \"MAv2.0.0-ma-webauthn\":\n case \"LightAccountV2.0.0-MultiOwner\":\n case \"MAv1.0.0-MultiOwner\":\n case \"MAv1.0.0-MultiSig\":\n case \"unknown\":\n throw new InvalidRequestError({\n message: `Unsupported factory type: ${factoryType}`,\n });\n default:\n return assertNever(factoryType, \"Unsupported factory type\");\n }\n })();\n\n return client\n .sendRawUserOperation(\n {\n ...userOp.data,\n signature,\n eip7702Auth:\n idx === 0 && authorization && authSig\n ? {\n ...authorization.data,\n chainId: authorization.chainId,\n ...{\n ...authSig,\n yParity: numberToHex(authSig.yParity),\n },\n }\n : undefined,\n },\n ep.address,\n )\n .catch((err) => {\n if (\n err instanceof BaseError &&\n err.details.endsWith(\"is not a contract and initCode is empty\")\n ) {\n throw new BaseError(\n `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,\n );\n }\n throw err;\n });\n }),\n );\n\n return {\n preparedCallIds: hashes.map((hash) =>\n Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n }),\n ),\n };\n}\n"]}
@@ -50,11 +50,13 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
50
50
  [x: string]: unknown;
51
51
  };
52
52
  };
53
+ rawPayload: `0x${string}`;
53
54
  } | {
54
55
  type: "personal_sign";
55
56
  data: string | {
56
57
  raw: `0x${string}`;
57
58
  };
59
+ rawPayload: `0x${string}`;
58
60
  };
59
61
  } | {
60
62
  type: "user-operation-v070";
@@ -96,11 +98,13 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
96
98
  [x: string]: unknown;
97
99
  };
98
100
  };
101
+ rawPayload: `0x${string}`;
99
102
  } | {
100
103
  type: "personal_sign";
101
104
  data: string | {
102
105
  raw: `0x${string}`;
103
106
  };
107
+ rawPayload: `0x${string}`;
104
108
  };
105
109
  } | {
106
110
  type: "authorization";
@@ -111,6 +115,7 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
111
115
  };
112
116
  signatureRequest: {
113
117
  type: "eip7702Auth";
118
+ rawPayload: `0x${string}`;
114
119
  };
115
120
  })[];
116
121
  } | {
@@ -149,11 +154,13 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
149
154
  [x: string]: unknown;
150
155
  };
151
156
  };
157
+ rawPayload: `0x${string}`;
152
158
  } | {
153
159
  type: "personal_sign";
154
160
  data: string | {
155
161
  raw: `0x${string}`;
156
162
  };
163
+ rawPayload: `0x${string}`;
157
164
  };
158
165
  } | {
159
166
  type: "user-operation-v070";
@@ -195,11 +202,13 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
195
202
  [x: string]: unknown;
196
203
  };
197
204
  };
205
+ rawPayload: `0x${string}`;
198
206
  } | {
199
207
  type: "personal_sign";
200
208
  data: string | {
201
209
  raw: `0x${string}`;
202
210
  };
211
+ rawPayload: `0x${string}`;
203
212
  };
204
213
  }>;
205
214
  sendPreparedCalls: (params: SendPreparedCallsParams) => Promise<{
@@ -1,6 +1,7 @@
1
- import { concatHex, numberToHex, isAddress, } from "viem";
1
+ import { concatHex, numberToHex, isAddress, hexToNumber, } from "viem";
2
2
  import { PreparedCall_Authorization } from "../../schemas.js";
3
3
  import { InvalidRequestError } from "ox/RpcResponse";
4
+ import { hashAuthorization } from "viem/utils";
4
5
  export const createAuthorizationRequest = async (client, params) => {
5
6
  const expectedCode = concatHex(["0xef0100", params.delegation]);
6
7
  const code = (await client.getCode({ address: params.address })) ?? "0x";
@@ -19,6 +20,11 @@ export const createAuthorizationRequest = async (client, params) => {
19
20
  chainId: numberToHex(client.chain.id),
20
21
  signatureRequest: {
21
22
  type: "eip7702Auth",
23
+ rawPayload: hashAuthorization({
24
+ chainId: client.chain.id,
25
+ nonce: hexToNumber(data.nonce),
26
+ address: params.delegation,
27
+ }),
22
28
  },
23
29
  };
24
30
  };
@@ -49,13 +55,20 @@ export const parseDelegation = (eip7702AuthCapability) => {
49
55
  : getDelegationAddressForAccountType7702(eip7702AuthCapability.delegation);
50
56
  };
51
57
  export const assertValid7702AccountAddress = (fromAddress, eip7702AuthCapability) => {
52
- if (eip7702AuthCapability &&
53
- typeof eip7702AuthCapability === "object" &&
54
- "account" in eip7702AuthCapability &&
55
- eip7702AuthCapability?.account !== fromAddress) {
56
- throw new InvalidRequestError({
57
- message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
58
- });
58
+ if (eip7702AuthCapability) {
59
+ if (typeof eip7702AuthCapability === "object" &&
60
+ "account" in eip7702AuthCapability &&
61
+ eip7702AuthCapability?.account !== fromAddress) {
62
+ throw new InvalidRequestError({
63
+ message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
64
+ });
65
+ }
66
+ const delegation = parseDelegation(eip7702AuthCapability);
67
+ if (!isSupportedDelegationAddress7702(delegation)) {
68
+ throw new InvalidRequestError({
69
+ message: `Unsupported 7702 delegation address: ${delegation}`,
70
+ });
71
+ }
59
72
  }
60
73
  };
61
74
  //# sourceMappingURL=7702.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,WAAW,EAIX,SAAS,GACV,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAC7C,MAMC,EACD,MAAiD,EACe,EAAE;IAClE,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,MAAM,IAAI,GAAG;QACX,OAAO,EAAE,MAAM,CAAC,UAAU;QAC1B,KAAK,EAAE,WAAW,CAChB,MAAM,MAAM,CAAC,mBAAmB,CAAC;YAC/B,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CACH;KACF,CAAC;IACF,OAAO;QACL,IAAI,EAAE,eAAwB;QAC9B,IAAI;QACJ,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,gBAAgB,EAAE;YAChB,IAAI,EAAE,aAAsB;SAC7B;KACF,CAAC;AACJ,CAAC,CAAC;AAE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,qBAAuE,EACvE,EAAE;IACF,IACE,qBAAqB;QACrB,OAAO,qBAAqB,KAAK,QAAQ;QACzC,SAAS,IAAI,qBAAqB;QAClC,qBAAqB,EAAE,OAAO,KAAK,WAAW,EAC9C,CAAC;QACD,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,+BAA+B,qBAAqB,CAAC,OAAO,8BAA8B,WAAW,GAAG;SAClH,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n concatHex,\n numberToHex,\n type Address,\n type Chain,\n type Transport,\n isAddress,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { PreparedCall_Authorization } from \"../../schemas.js\";\nimport type { Eip7702AuthCapability } from \"../../capabilities/eip7702Auth.ts\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\n\nexport const createAuthorizationRequest = 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<Static<typeof PreparedCall_Authorization> | 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 const data = {\n address: params.delegation,\n nonce: numberToHex(\n await client.getTransactionCount({\n address: params.address,\n }),\n ),\n };\n return {\n type: \"authorization\" as const,\n data,\n chainId: numberToHex(client.chain.id),\n signatureRequest: {\n type: \"eip7702Auth\" as const,\n },\n };\n};\n\nexport const EIP_7702_ACCOUNT_TYPE = [\"ModularAccountV2\"] as const;\n\ntype Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];\n\nconst Eip7702AccountTypeToDelegationAddress = {\n ModularAccountV2: \"0x69007702764179f14F51cdce752f4f775d74E139\",\n} as const satisfies Record<Supported7702AccountType, Address>;\n\nconst DelegationAddressToAccountType: Record<\n Address,\n Supported7702AccountType\n> = Object.fromEntries(\n Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [\n value,\n key,\n ]),\n) as Record<Address, Supported7702AccountType>;\n\nexport const SUPPORTED_DELEGATION_ADDRESSES = Object.values(\n Eip7702AccountTypeToDelegationAddress,\n);\n\nexport const isSupportedDelegationAddress7702 = (address: Address): boolean => {\n return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);\n};\n\nexport const getAccountTypeForDelegationAddress7702 = (\n address: Address,\n): Supported7702AccountType | undefined => {\n return DelegationAddressToAccountType[address];\n};\n\nconst getDelegationAddressForAccountType7702 = (\n accountType: Supported7702AccountType,\n): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {\n return Eip7702AccountTypeToDelegationAddress[accountType];\n};\n\nconst DEFAULT_7702_DELEGATION_ADDR =\n Eip7702AccountTypeToDelegationAddress[\"ModularAccountV2\"];\n\nexport const parseDelegation = (\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability>,\n) => {\n return eip7702AuthCapability === true\n ? DEFAULT_7702_DELEGATION_ADDR\n : isAddress(eip7702AuthCapability.delegation)\n ? eip7702AuthCapability.delegation\n : getDelegationAddressForAccountType7702(\n eip7702AuthCapability.delegation,\n );\n};\n\nexport const assertValid7702AccountAddress = (\n fromAddress: Address,\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined,\n) => {\n if (\n eip7702AuthCapability &&\n typeof eip7702AuthCapability === \"object\" &&\n \"account\" in eip7702AuthCapability &&\n eip7702AuthCapability?.account !== fromAddress\n ) {\n throw new InvalidRequestError({\n message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,\n });\n }\n};\n"]}
1
+ {"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAA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,EACpB,qBAAuE,EACvE,EAAE;IACF,IAAI,qBAAqB,EAAE,CAAC;QAC1B,IACE,OAAO,qBAAqB,KAAK,QAAQ;YACzC,SAAS,IAAI,qBAAqB;YAClC,qBAAqB,EAAE,OAAO,KAAK,WAAW,EAC9C,CAAC;YACD,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EAAE,+BAA+B,qBAAqB,CAAC,OAAO,8BAA8B,WAAW,GAAG;aAClH,CAAC,CAAC;QACL,CAAC;QAED,MAAM,UAAU,GAAG,eAAe,CAAC,qBAAqB,CAAC,CAAC;QAE1D,IAAI,CAAC,gCAAgC,CAAC,UAAU,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EAAE,wCAAwC,UAAU,EAAE;aAC9D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n concatHex,\n numberToHex,\n type Address,\n type Chain,\n type Transport,\n isAddress,\n hexToNumber,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { PreparedCall_Authorization } from \"../../schemas.js\";\nimport type { Eip7702AuthCapability } from \"../../capabilities/eip7702Auth.ts\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { hashAuthorization } from \"viem/utils\";\n\nexport const createAuthorizationRequest = 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<Static<typeof PreparedCall_Authorization> | 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 const data = {\n address: params.delegation,\n nonce: numberToHex(\n await client.getTransactionCount({\n address: params.address,\n }),\n ),\n };\n return {\n type: \"authorization\" as const,\n data,\n chainId: numberToHex(client.chain.id),\n signatureRequest: {\n type: \"eip7702Auth\" as const,\n rawPayload: hashAuthorization({\n chainId: client.chain.id,\n nonce: hexToNumber(data.nonce),\n address: params.delegation,\n }),\n },\n };\n};\n\nexport const EIP_7702_ACCOUNT_TYPE = [\"ModularAccountV2\"] as const;\n\ntype Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];\n\nconst Eip7702AccountTypeToDelegationAddress = {\n ModularAccountV2: \"0x69007702764179f14F51cdce752f4f775d74E139\",\n} as const satisfies Record<Supported7702AccountType, Address>;\n\nconst DelegationAddressToAccountType: Record<\n Address,\n Supported7702AccountType\n> = Object.fromEntries(\n Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [\n value,\n key,\n ]),\n) as Record<Address, Supported7702AccountType>;\n\nexport const SUPPORTED_DELEGATION_ADDRESSES = Object.values(\n Eip7702AccountTypeToDelegationAddress,\n);\n\nexport const isSupportedDelegationAddress7702 = (address: Address): boolean => {\n return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);\n};\n\nexport const getAccountTypeForDelegationAddress7702 = (\n address: Address,\n): Supported7702AccountType | undefined => {\n return DelegationAddressToAccountType[address];\n};\n\nconst getDelegationAddressForAccountType7702 = (\n accountType: Supported7702AccountType,\n): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {\n return Eip7702AccountTypeToDelegationAddress[accountType];\n};\n\nconst DEFAULT_7702_DELEGATION_ADDR =\n Eip7702AccountTypeToDelegationAddress[\"ModularAccountV2\"];\n\nexport const parseDelegation = (\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability>,\n) => {\n return eip7702AuthCapability === true\n ? DEFAULT_7702_DELEGATION_ADDR\n : isAddress(eip7702AuthCapability.delegation)\n ? eip7702AuthCapability.delegation\n : getDelegationAddressForAccountType7702(\n eip7702AuthCapability.delegation,\n );\n};\n\nexport const assertValid7702AccountAddress = (\n fromAddress: Address,\n eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined,\n) => {\n if (eip7702AuthCapability) {\n if (\n typeof eip7702AuthCapability === \"object\" &&\n \"account\" in eip7702AuthCapability &&\n eip7702AuthCapability?.account !== fromAddress\n ) {\n throw new InvalidRequestError({\n message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,\n });\n }\n\n const delegation = parseDelegation(eip7702AuthCapability);\n\n if (!isSupportedDelegationAddress7702(delegation)) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${delegation}`,\n });\n }\n }\n};\n"]}