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

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 (91) hide show
  1. package/dist/esm/capabilities/index.d.ts +3 -0
  2. package/dist/esm/capabilities/index.js +2 -0
  3. package/dist/esm/capabilities/index.js.map +1 -1
  4. package/dist/esm/capabilities/multiDimensionalNonce.d.ts +3 -0
  5. package/dist/esm/capabilities/multiDimensionalNonce.js +7 -0
  6. package/dist/esm/capabilities/multiDimensionalNonce.js.map +1 -0
  7. package/dist/esm/client/actions/prepareCalls.d.ts +1 -1
  8. package/dist/esm/client/actions/prepareCalls.js +1 -1
  9. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  10. package/dist/esm/client/actions/signPreparedCalls.js +26 -37
  11. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -1
  12. package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -2
  13. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  14. package/dist/esm/exports/internal.d.ts +1 -0
  15. package/dist/esm/exports/internal.js +1 -0
  16. package/dist/esm/exports/internal.js.map +1 -1
  17. package/dist/esm/isomorphic/actions/createSession.js +20 -5
  18. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  19. package/dist/esm/isomorphic/actions/prepareCalls.js +39 -17
  20. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  21. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +62 -8
  22. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  23. package/dist/esm/isomorphic/client.d.ts +9 -0
  24. package/dist/esm/isomorphic/utils/7702.d.ts +6 -1
  25. package/dist/esm/isomorphic/utils/7702.js +26 -12
  26. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  27. package/dist/esm/isomorphic/utils/createAccount.d.ts +1 -0
  28. package/dist/esm/isomorphic/utils/createAccount.js +96 -34
  29. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  30. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +4 -0
  31. package/dist/esm/isomorphic/utils/supportsFeature.js +21 -0
  32. package/dist/esm/isomorphic/utils/supportsFeature.js.map +1 -0
  33. package/dist/esm/rpc/request.d.ts +54 -0
  34. package/dist/esm/rpc/request.js +1 -0
  35. package/dist/esm/rpc/request.js.map +1 -1
  36. package/dist/esm/rpc/schema.d.ts +54 -0
  37. package/dist/esm/schemas.d.ts +35 -1
  38. package/dist/esm/schemas.js +56 -1
  39. package/dist/esm/schemas.js.map +1 -1
  40. package/dist/esm/types.d.ts +3 -0
  41. package/dist/esm/types.js.map +1 -1
  42. package/dist/esm/utils.d.ts +1 -0
  43. package/dist/esm/utils.js.map +1 -1
  44. package/dist/types/capabilities/index.d.ts +3 -0
  45. package/dist/types/capabilities/index.d.ts.map +1 -1
  46. package/dist/types/capabilities/multiDimensionalNonce.d.ts +4 -0
  47. package/dist/types/capabilities/multiDimensionalNonce.d.ts.map +1 -0
  48. package/dist/types/client/actions/prepareCalls.d.ts +1 -1
  49. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -1
  50. package/dist/types/client/actions/signSignatureRequest.d.ts +3 -2
  51. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  52. package/dist/types/exports/internal.d.ts +1 -0
  53. package/dist/types/exports/internal.d.ts.map +1 -1
  54. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  55. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  56. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  57. package/dist/types/isomorphic/client.d.ts +9 -0
  58. package/dist/types/isomorphic/client.d.ts.map +1 -1
  59. package/dist/types/isomorphic/utils/7702.d.ts +6 -1
  60. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  61. package/dist/types/isomorphic/utils/createAccount.d.ts +1 -0
  62. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  63. package/dist/types/isomorphic/utils/supportsFeature.d.ts +5 -0
  64. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +1 -0
  65. package/dist/types/rpc/request.d.ts +54 -0
  66. package/dist/types/rpc/request.d.ts.map +1 -1
  67. package/dist/types/rpc/schema.d.ts +54 -0
  68. package/dist/types/rpc/schema.d.ts.map +1 -1
  69. package/dist/types/schemas.d.ts +35 -1
  70. package/dist/types/schemas.d.ts.map +1 -1
  71. package/dist/types/types.d.ts +3 -0
  72. package/dist/types/types.d.ts.map +1 -1
  73. package/dist/types/utils.d.ts +1 -0
  74. package/dist/types/utils.d.ts.map +1 -1
  75. package/package.json +5 -5
  76. package/src/capabilities/index.ts +2 -0
  77. package/src/capabilities/multiDimensionalNonce.ts +7 -0
  78. package/src/client/actions/prepareCalls.ts +1 -1
  79. package/src/client/actions/signPreparedCalls.ts +42 -43
  80. package/src/client/actions/signSignatureRequest.ts +4 -2
  81. package/src/exports/internal.ts +1 -0
  82. package/src/isomorphic/actions/createSession.ts +25 -4
  83. package/src/isomorphic/actions/prepareCalls.ts +48 -21
  84. package/src/isomorphic/actions/sendPreparedCalls.ts +69 -9
  85. package/src/isomorphic/utils/7702.ts +41 -14
  86. package/src/isomorphic/utils/createAccount.ts +115 -35
  87. package/src/isomorphic/utils/supportsFeature.ts +34 -0
  88. package/src/rpc/request.ts +1 -0
  89. package/src/schemas.ts +94 -3
  90. package/src/types.ts +4 -0
  91. package/src/utils.ts +2 -0
@@ -35,4 +35,7 @@ export declare const Capabilities: import("@sinclair/typebox").TObject<{
35
35
  account: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">>;
36
36
  delegation: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TLiteral<"0x69007702764179f14F51cdce752f4f775d74E139"> | import("@sinclair/typebox").TLiteral<"ModularAccountV2">)[]>;
37
37
  }>, import("@sinclair/typebox").TLiteral<true>]>>;
38
+ nonceOverride: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
39
+ nonceKey: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
40
+ }>>;
38
41
  }>;
@@ -3,10 +3,12 @@ import { GasParamsOverrideCapability } from "./overrides.js";
3
3
  import { PaymasterCapability } from "./paymaster.js";
4
4
  import { PermissionsCapability } from "./permissions/index.js";
5
5
  import { Eip7702AuthCapability } from "./eip7702Auth.js";
6
+ import { MultiDimensionalNonceCapability } from "./multiDimensionalNonce.js";
6
7
  export const Capabilities = Type.Object({
7
8
  permissions: Type.Optional(PermissionsCapability),
8
9
  paymasterService: Type.Optional(PaymasterCapability),
9
10
  gasParamsOverride: Type.Optional(GasParamsOverrideCapability),
10
11
  eip7702Auth: Type.Optional(Eip7702AuthCapability),
12
+ nonceOverride: Type.Optional(MultiDimensionalNonceCapability),
11
13
  });
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/capabilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;IACtC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IACjD,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IACpD,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IAC7D,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC;CAClD,CAAC,CAAC","sourcesContent":["import { Type } from \"@sinclair/typebox\";\nimport { GasParamsOverrideCapability } from \"./overrides.js\";\nimport { PaymasterCapability } from \"./paymaster.js\";\nimport { PermissionsCapability } from \"./permissions/index.js\";\nimport { Eip7702AuthCapability } from \"./eip7702Auth.js\";\n\nexport const Capabilities = Type.Object({\n permissions: Type.Optional(PermissionsCapability),\n paymasterService: Type.Optional(PaymasterCapability),\n gasParamsOverride: Type.Optional(GasParamsOverrideCapability),\n eip7702Auth: Type.Optional(Eip7702AuthCapability),\n});\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/capabilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;IACtC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IACjD,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IACpD,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IAC7D,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC;IACjD,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,+BAA+B,CAAC;CAC9D,CAAC,CAAC","sourcesContent":["import { Type } from \"@sinclair/typebox\";\nimport { GasParamsOverrideCapability } from \"./overrides.js\";\nimport { PaymasterCapability } from \"./paymaster.js\";\nimport { PermissionsCapability } from \"./permissions/index.js\";\nimport { Eip7702AuthCapability } from \"./eip7702Auth.js\";\nimport { MultiDimensionalNonceCapability } from \"./multiDimensionalNonce.js\";\n\nexport const Capabilities = Type.Object({\n permissions: Type.Optional(PermissionsCapability),\n paymasterService: Type.Optional(PaymasterCapability),\n gasParamsOverride: Type.Optional(GasParamsOverrideCapability),\n eip7702Auth: Type.Optional(Eip7702AuthCapability),\n nonceOverride: Type.Optional(MultiDimensionalNonceCapability),\n});\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const MultiDimensionalNonceCapability: import("@sinclair/typebox").TObject<{
2
+ nonceKey: import("@sinclair/typebox").TTemplateLiteralSyntax<"0x${string}">;
3
+ }>;
@@ -0,0 +1,7 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { TypeHex } from "../schemas.js";
3
+ export const MultiDimensionalNonceCapability = Type.Object({
4
+ // we do not support the optional sequentialNonce param
5
+ nonceKey: TypeHex({ description: "Override nonce key as hex string" }),
6
+ });
7
+ //# sourceMappingURL=multiDimensionalNonce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiDimensionalNonce.js","sourceRoot":"","sources":["../../../src/capabilities/multiDimensionalNonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,MAAM,+BAA+B,GAAG,IAAI,CAAC,MAAM,CAAC;IACzD,uDAAuD;IACvD,QAAQ,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;CACvE,CAAC,CAAC","sourcesContent":["import { Type } from \"@sinclair/typebox\";\nimport { TypeHex } from \"../schemas.js\";\n\nexport const MultiDimensionalNonceCapability = Type.Object({\n // we do not support the optional sequentialNonce param\n nonceKey: TypeHex({ description: \"Override nonce key as hex string\" }),\n});\n"]}
@@ -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"]}
@@ -1,6 +1,6 @@
1
1
  import { signSignatureRequest } from "./signSignatureRequest.js";
2
2
  import { wallet_sendPreparedCalls } from "../../rpc/request.js";
3
- import { assertNever } from "../../utils.js";
3
+ import { PreparedCall_Authorization, PreparedCall_UserOpV060, PreparedCall_UserOpV070, } from "../../schemas.js";
4
4
  /**
5
5
  * Signs prepared calls using the provided signer.
6
6
  *
@@ -9,46 +9,35 @@ import { assertNever } from "../../utils.js";
9
9
  * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls
10
10
  **/
11
11
  export async function signPreparedCalls(signer, params) {
12
- if (params.type !== "array") {
13
- const { signatureRequest, ...call } = params;
12
+ const signAuthorizationCall = async (call) => {
13
+ const { signatureRequest: _signatureRequest, ...rest } = call;
14
+ const signature = await signSignatureRequest(signer, {
15
+ type: "eip7702Auth",
16
+ data: {
17
+ ...rest.data,
18
+ chainId: call.chainId,
19
+ },
20
+ });
21
+ return {
22
+ ...rest,
23
+ signature,
24
+ };
25
+ };
26
+ const signUserOperationCall = async (call) => {
27
+ const { signatureRequest, ...rest } = call;
14
28
  const signature = await signSignatureRequest(signer, signatureRequest);
15
29
  return {
16
- ...call,
30
+ ...rest,
17
31
  signature,
18
32
  };
19
- }
20
- return {
21
- type: "array",
22
- data: await Promise.all(params.data.map(async (call) => {
23
- switch (call.type) {
24
- case "authorization": {
25
- const { signatureRequest: _signatureRequest, ...rest } = call;
26
- const signature = await signSignatureRequest(signer, {
27
- type: "eip7702Auth",
28
- data: {
29
- ...call.data,
30
- chainId: call.chainId,
31
- },
32
- });
33
- return {
34
- ...rest,
35
- signature,
36
- };
37
- }
38
- case "user-operation-v060":
39
- case "user-operation-v070": {
40
- const { signatureRequest, ...rest } = call;
41
- const signature = await signSignatureRequest(signer, signatureRequest);
42
- return {
43
- ...rest,
44
- signature,
45
- };
46
- }
47
- default: {
48
- return assertNever(call, "Unexpected call type");
49
- }
50
- }
51
- })),
52
33
  };
34
+ return params.type === "array"
35
+ ? {
36
+ type: "array",
37
+ data: await Promise.all(params.data.map((call) => call.type === "authorization"
38
+ ? signAuthorizationCall(call)
39
+ : signUserOperationCall(call))),
40
+ }
41
+ : signUserOperationCall(params);
53
42
  }
54
43
  //# sourceMappingURL=signPreparedCalls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signPreparedCalls.js","sourceRoot":"","sources":["../../../../src/client/actions/signPreparedCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAQ7C;;;;;;IAMI;AACJ,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA0B,EAC1B,MAA+B;IAE/B,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC7C,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACvE,OAAO;YACL,GAAG,IAAI;YACP,SAAS;SACV,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,OAAgB;QACtB,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CACrB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC7B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,eAAe,CAAC,CAAC,CAAC;oBACrB,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;oBAC9D,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE;wBACnD,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE;4BACJ,GAAG,IAAI,CAAC,IAAI;4BACZ,OAAO,EAAE,IAAI,CAAC,OAAO;yBACtB;qBACF,CAAC,CAAC;oBACH,OAAO;wBACL,GAAG,IAAI;wBACP,SAAS;qBACV,CAAC;gBACJ,CAAC;gBACD,KAAK,qBAAqB,CAAC;gBAC3B,KAAK,qBAAqB,CAAC,CAAC,CAAC;oBAC3B,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;oBAC3C,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAC1C,MAAM,EACN,gBAAgB,CACjB,CAAC;oBACF,OAAO;wBACL,GAAG,IAAI;wBACP,SAAS;qBACV,CAAC;gBACJ,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACR,OAAO,WAAW,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PrepareCallsResult } from \"./prepareCalls.ts\";\nimport type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { wallet_sendPreparedCalls } from \"../../rpc/request.js\";\nimport { assertNever } from \"../../utils.js\";\n\nexport type SignPreparedCallsParams = PrepareCallsResult;\n\nexport type SignPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\n/**\n * Signs prepared calls using the provided signer.\n *\n * @param {SmartAccountSigner} signer - The signer to use\n * @param {SignPreparedCallsParams} params - The prepared calls with signature requests\n * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls\n **/\nexport async function signPreparedCalls(\n signer: SmartAccountSigner,\n params: SignPreparedCallsParams,\n): Promise<SignPreparedCallsResult> {\n if (params.type !== \"array\") {\n const { signatureRequest, ...call } = params;\n const signature = await signSignatureRequest(signer, signatureRequest);\n return {\n ...call,\n signature,\n };\n }\n\n return {\n type: \"array\" as const,\n data: await Promise.all(\n params.data.map(async (call) => {\n switch (call.type) {\n case \"authorization\": {\n const { signatureRequest: _signatureRequest, ...rest } = call;\n const signature = await signSignatureRequest(signer, {\n type: \"eip7702Auth\",\n data: {\n ...call.data,\n chainId: call.chainId,\n },\n });\n return {\n ...rest,\n signature,\n };\n }\n case \"user-operation-v060\":\n case \"user-operation-v070\": {\n const { signatureRequest, ...rest } = call;\n const signature = await signSignatureRequest(\n signer,\n signatureRequest,\n );\n return {\n ...rest,\n signature,\n };\n }\n default: {\n return assertNever(call, \"Unexpected call type\");\n }\n }\n }),\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"signPreparedCalls.js","sourceRoot":"","sources":["../../../../src/client/actions/signPreparedCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAQ1B;;;;;;IAMI;AACJ,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA0B,EAC1B,MAA+B;IAE/B,MAAM,qBAAqB,GAAG,KAAK,EACjC,IAA+C,EAC/C,EAAE;QACF,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC9D,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE;YACnD,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE;gBACJ,GAAG,IAAI,CAAC,IAAI;gBACZ,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB;SACF,CAAC,CAAC;QACH,OAAO;YACL,GAAG,IAAI;YACP,SAAS;SACV,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,qBAAqB,GAAG,KAAK,EACjC,IAE0C,EAC1C,EAAE;QACF,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC3C,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACvE,OAAO;YACL,GAAG,IAAI;YACP,SAAS;SACV,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,KAAK,OAAO;QAC5B,CAAC,CAAC;YACE,IAAI,EAAE,OAAgB;YACtB,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CACrB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACvB,IAAI,CAAC,IAAI,KAAK,eAAe;gBAC3B,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;gBAC7B,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAChC,CACF;SACF;QACH,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import type { PrepareCallsResult } from \"./prepareCalls.ts\";\nimport type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { wallet_sendPreparedCalls } from \"../../rpc/request.js\";\nimport {\n PreparedCall_Authorization,\n PreparedCall_UserOpV060,\n PreparedCall_UserOpV070,\n} from \"../../schemas.js\";\n\nexport type SignPreparedCallsParams = PrepareCallsResult;\n\nexport type SignPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\n/**\n * Signs prepared calls using the provided signer.\n *\n * @param {SmartAccountSigner} signer - The signer to use\n * @param {SignPreparedCallsParams} params - The prepared calls with signature requests\n * @returns {Promise<SignPreparedCallsResult>} A Promise that resolves to the signed calls\n **/\nexport async function signPreparedCalls(\n signer: SmartAccountSigner,\n params: SignPreparedCallsParams,\n): Promise<SignPreparedCallsResult> {\n const signAuthorizationCall = async (\n call: Static<typeof PreparedCall_Authorization>,\n ) => {\n const { signatureRequest: _signatureRequest, ...rest } = call;\n const signature = await signSignatureRequest(signer, {\n type: \"eip7702Auth\",\n data: {\n ...rest.data,\n chainId: call.chainId,\n },\n });\n return {\n ...rest,\n signature,\n };\n };\n\n const signUserOperationCall = async (\n call:\n | Static<typeof PreparedCall_UserOpV060>\n | Static<typeof PreparedCall_UserOpV070>,\n ) => {\n const { signatureRequest, ...rest } = call;\n const signature = await signSignatureRequest(signer, signatureRequest);\n return {\n ...rest,\n signature,\n };\n };\n\n return params.type === \"array\"\n ? {\n type: \"array\" as const,\n data: await Promise.all(\n params.data.map((call) =>\n call.type === \"authorization\"\n ? signAuthorizationCall(call)\n : signUserOperationCall(call),\n ),\n ),\n }\n : signUserOperationCall(params);\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,M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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"]}
@@ -5,6 +5,7 @@ export * from "../capabilities/permissions/mav2.js";
5
5
  export type * from "../isomorphic/client.js";
6
6
  export { createIsomorphicClient } from "../isomorphic/client.js";
7
7
  export { createDummySigner } from "../isomorphic/utils/createDummySigner.js";
8
+ export { prepareInitialOwners } from "../isomorphic/utils/createAccount.js";
8
9
  export * from "../rpc/request.js";
9
10
  export * as RpcSchemas from "../rpc/request.js";
10
11
  export * from "../rpc/schema.js";
@@ -7,6 +7,7 @@ export * from "../capabilities/permissions/index.js";
7
7
  export * from "../capabilities/permissions/mav2.js";
8
8
  export { createIsomorphicClient } from "../isomorphic/client.js";
9
9
  export { createDummySigner } from "../isomorphic/utils/createDummySigner.js";
10
+ export { prepareInitialOwners } from "../isomorphic/utils/createAccount.js";
10
11
  export * from "../rpc/request.js";
11
12
  export * as RpcSchemas from "../rpc/request.js";
12
13
  export * from "../rpc/schema.js";
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/exports/internal.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qFAAqF;AACrF,wBAAwB;AACxB,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AAEpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAE9B,cAAc,aAAa,CAAC","sourcesContent":["// exports from this file are meant to be imported by our packages in the monorepo\n// we will expose this in the package.json as a named export like `this-pkg/internal`\n// TODO: name `this-pkg`\nexport * from \"../capabilities/index.js\";\nexport * from \"../capabilities/paymaster.js\";\nexport * from \"../capabilities/permissions/index.js\";\nexport * from \"../capabilities/permissions/mav2.js\";\nexport type * from \"../isomorphic/client.js\";\nexport { createIsomorphicClient } from \"../isomorphic/client.js\";\nexport { createDummySigner } from \"../isomorphic/utils/createDummySigner.js\";\nexport * from \"../rpc/request.js\";\nexport * as RpcSchemas from \"../rpc/request.js\";\nexport * from \"../rpc/schema.js\";\nexport * from \"../schemas.js\";\nexport type * from \"../types.ts\";\nexport * from \"../utils.js\";\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/exports/internal.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qFAAqF;AACrF,wBAAwB;AACxB,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AAEpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAE9B,cAAc,aAAa,CAAC","sourcesContent":["// exports from this file are meant to be imported by our packages in the monorepo\n// we will expose this in the package.json as a named export like `this-pkg/internal`\n// TODO: name `this-pkg`\nexport * from \"../capabilities/index.js\";\nexport * from \"../capabilities/paymaster.js\";\nexport * from \"../capabilities/permissions/index.js\";\nexport * from \"../capabilities/permissions/mav2.js\";\nexport type * from \"../isomorphic/client.js\";\nexport { createIsomorphicClient } from \"../isomorphic/client.js\";\nexport { createDummySigner } from \"../isomorphic/utils/createDummySigner.js\";\nexport { prepareInitialOwners } from \"../isomorphic/utils/createAccount.js\";\nexport * from \"../rpc/request.js\";\nexport * as RpcSchemas from \"../rpc/request.js\";\nexport * from \"../rpc/schema.js\";\nexport * from \"../schemas.js\";\nexport type * from \"../types.ts\";\nexport * from \"../utils.js\";\n"]}
@@ -1,12 +1,14 @@
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";
11
+ import { isDelegated } from "../utils/7702.js";
10
12
  export async function createSession(client, params) {
11
13
  if (!client.chain) {
12
14
  throw new ChainNotFoundError();
@@ -20,16 +22,27 @@ export async function createSession(client, params) {
20
22
  },
21
23
  ],
22
24
  });
23
- if (delegation) {
25
+ if (delegation &&
26
+ !(await isDelegated(client, {
27
+ address: params.account,
28
+ delegation,
29
+ }))) {
24
30
  throw new InvalidRequestError({
25
- message: "'wallet_createSession' does not currently support 7702 accounts.",
31
+ message: "7702 account must be delegated before calling `wallet_createSession`",
26
32
  });
27
33
  }
28
- if (!counterfactualInfo) {
34
+ if (!delegation && !counterfactualInfo) {
29
35
  throw new InvalidRequestError({
30
36
  message: "No counterfactual info found.",
31
37
  });
32
38
  }
39
+ if (counterfactualInfo &&
40
+ !supportsFeature(counterfactualInfo, "permissions")) {
41
+ throw new InvalidRequestError({
42
+ message: "Account type does not support createSession",
43
+ });
44
+ }
45
+ // At this point we know the account supports the permission feature
33
46
  const account = await createAccount({
34
47
  chain: client.chain,
35
48
  transport: custom(client.transport),
@@ -69,10 +82,12 @@ export async function createSession(client, params) {
69
82
  .compileDeferred();
70
83
  return {
71
84
  sessionId: null, // In remote mode, the server will set this later.
85
+ chainId: toHex(client.chain.id),
72
86
  entityId: toHex(entityId),
73
87
  signatureRequest: {
74
88
  type: "eth_signTypedData_v4",
75
89
  data: typedData,
90
+ rawPayload: hashTypedData(typedData),
76
91
  },
77
92
  fullPreSignatureDeferredActionDigest,
78
93
  };
@@ -1 +1 @@
1
- {"version":3,"file":"createSession.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/createSession.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAGzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,iBAAiB,GAClB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,WAAW,EACX,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAoBrD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAMC,EACD,MAA2B;IAE3B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AAmB,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,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAoB/C,MAAM,CAAC,KAAK,UAA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QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;QACzB,gBAAgB,EAAE;YAChB,IAAI,EAAE,sBAA+B;YACrC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,aAAa,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\";\nimport { isDelegated } from \"../utils/7702.js\";\n\nexport type CreateSessionParams = Omit<\n Static<\n (typeof wallet_createSession)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n> & {\n entityId?: Hex;\n};\n\nexport type CreateSessionResult = Omit<\n Static<(typeof wallet_createSession)[\"properties\"][\"ReturnType\"]>,\n \"sessionId\"\n> & {\n sessionId: Hex | null;\n entityId: Hex;\n fullPreSignatureDeferredActionDigest: Hex;\n};\n\nexport async function createSession(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: CreateSessionParams,\n): Promise<CreateSessionResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n 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 (\n delegation &&\n !(await isDelegated(client, {\n address: params.account,\n delegation,\n }))\n ) {\n throw new InvalidRequestError({\n message:\n \"7702 account must be delegated before calling `wallet_createSession`\",\n });\n }\n\n if (!delegation && !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 chainId: toHex(client.chain.id),\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, isDelegated } 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.",
@@ -40,13 +43,23 @@ export async function prepareCalls(client, params) {
40
43
  permissions: params.capabilities?.permissions,
41
44
  delegation,
42
45
  });
43
- // If using 7702, we need an Authorization (unless it's already authorized).
44
- const authorizationRequest = delegation
46
+ const authorizationRequest = delegation &&
47
+ !(await isDelegated(client, {
48
+ address: account.address,
49
+ delegation,
50
+ }))
45
51
  ? await createAuthorizationRequest(client, {
46
52
  address: account.address,
47
53
  delegation,
48
54
  })
49
55
  : undefined;
56
+ if (params.capabilities?.permissions && authorizationRequest) {
57
+ // The user shouldn't see this in most cases since we require
58
+ // the account to be delegated before creating the session.
59
+ throw new InvalidRequestError({
60
+ message: "When using a 7702 account with a session key, the account must be delegated before preparing calls.",
61
+ });
62
+ }
50
63
  if (authorizationRequest) {
51
64
  // @ts-expect-error - this is available but not typed as public
52
65
  client.middleware.gasEstimator = default7702GasEstimator();
@@ -60,7 +73,12 @@ export async function prepareCalls(client, params) {
60
73
  value: x.value ? fromHex(x.value, "bigint") : undefined,
61
74
  })),
62
75
  account,
63
- overrides: params.capabilities?.gasParamsOverride,
76
+ overrides: {
77
+ ...params.capabilities?.gasParamsOverride,
78
+ nonceKey: params.capabilities?.nonceOverride?.nonceKey
79
+ ? fromHex(params.capabilities.nonceOverride.nonceKey, "bigint")
80
+ : undefined,
81
+ },
64
82
  });
65
83
  // The eip7702Auth field should never be included in the UO sig
66
84
  // request. It's handled by a separate authorization request.
@@ -69,6 +87,7 @@ export async function prepareCalls(client, params) {
69
87
  }
70
88
  const hexlifiedUo = deepHexlify(builtUo);
71
89
  const ep = account.getEntryPoint();
90
+ const uoHash = ep.getUserOperationHash(hexlifiedUo);
72
91
  const uoRequest = {
73
92
  type: ep.version === "0.7.0"
74
93
  ? "user-operation-v070"
@@ -80,8 +99,11 @@ export async function prepareCalls(client, params) {
80
99
  signatureRequest: {
81
100
  type: "personal_sign",
82
101
  data: {
83
- raw: ep.getUserOperationHash(hexlifiedUo),
102
+ raw: uoHash,
84
103
  },
104
+ rawPayload: hashMessage({
105
+ raw: uoHash,
106
+ }),
85
107
  },
86
108
  };
87
109
  return authorizationRequest
@@ -1 +1 @@
1
- {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WA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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,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3E,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,MAMC,EACD,MAA0B;IAE1B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CA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GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAEnC,MAAM,MAAM,GAAG,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAEpD,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,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, isDelegated } 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 const authorizationRequest =\n delegation &&\n !(await isDelegated(client, {\n address: account.address,\n delegation,\n }))\n ? await createAuthorizationRequest(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n if (params.capabilities?.permissions && authorizationRequest) {\n // The user shouldn't see this in most cases since we require\n // the account to be delegated before creating the session.\n throw new InvalidRequestError({\n message:\n \"When using a 7702 account with a session key, the account must be delegated before preparing calls.\",\n });\n }\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: {\n ...params.capabilities?.gasParamsOverride,\n nonceKey: params.capabilities?.nonceOverride?.nonceKey\n ? fromHex(params.capabilities.nonceOverride.nonceKey, \"bigint\")\n : undefined,\n },\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"]}
@@ -37,6 +37,11 @@ export async function sendPreparedCalls(client, params) {
37
37
  return isUserOp;
38
38
  })
39
39
  : [params];
40
+ if (!userOps.length) {
41
+ throw new InvalidRequestError({
42
+ message: "Calls must include at least one user operation",
43
+ });
44
+ }
40
45
  const authorizations = params.type === "array"
41
46
  ? params.data.filter((it) => it.type === "authorization")
42
47
  : [];
@@ -63,17 +68,66 @@ export async function sendPreparedCalls(client, params) {
63
68
  ? parseSignature(decodeSignature(authorization.signature).data)
64
69
  : undefined;
65
70
  const uoSigHex = decodeSignature(userOp.signature).data;
71
+ const { counterfactualInfo, delegation } = await client.request({
72
+ method: "wallet_requestAccount",
73
+ params: [
74
+ {
75
+ accountAddress: userOp.data.sender,
76
+ includeCounterfactualInfo: true,
77
+ },
78
+ ],
79
+ });
80
+ if (!counterfactualInfo && !delegation) {
81
+ throw new InvalidRequestError({
82
+ message: "No counterfactual info or delegated implementation address found.",
83
+ });
84
+ }
85
+ const factoryType = counterfactualInfo?.factoryType;
86
+ // build signature based on account type
87
+ const signature = (() => {
88
+ switch (factoryType) {
89
+ // light accounts
90
+ case "LightAccountV1.0.1":
91
+ case "LightAccountV1.0.2":
92
+ case "LightAccountV1.1.0":
93
+ case "MAv1.0.0-MultiOwner":
94
+ // For LAv1 and MAv1-MultiOwner, we always just pass the signature.
95
+ return uoSigHex;
96
+ case "LightAccountV2.0.0":
97
+ // for LAv2, we need to prepend the "SignatureType.EOA" byte.
98
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type.
99
+ return concat(["0x00", uoSigHex]);
100
+ case undefined: // undefined defaults to sma-b
101
+ case "MAv2.0.0-sma-b":
102
+ // For sma-b, we need to handle deferred actions if needed and prepend the "Reserved
103
+ // Signature Segment" and "SignatureType.EOA" bytes
104
+ return deferredAction != null
105
+ ? concatHex([
106
+ `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc.).
107
+ "0xFF",
108
+ "0x00",
109
+ uoSigHex,
110
+ ])
111
+ : concat(["0xFF", "0x00", uoSigHex]);
112
+ case "LightAccountV2.0.0-MultiOwner":
113
+ // for LAv2-MultiOwner, we need to prepend the "SignatureType.EOA" byte
114
+ // TODO: Once we support nested smart accounts, switch this byte depending on the signature type, and add the smart account signer's address.
115
+ return concat(["0x00", uoSigHex]);
116
+ case "MAv2.0.0-ma-ssv":
117
+ case "MAv2.0.0-ma-webauthn":
118
+ case "MAv1.0.0-MultiSig":
119
+ case "unknown":
120
+ throw new InvalidRequestError({
121
+ message: `Unsupported factory type: ${factoryType}`,
122
+ });
123
+ default:
124
+ return assertNever(factoryType, "Unsupported factory type");
125
+ }
126
+ })();
66
127
  return client
67
128
  .sendRawUserOperation({
68
129
  ...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]),
130
+ signature,
77
131
  eip7702Auth: idx === 0 && authorization && authSig
78
132
  ? {
79
133
  ...authorization.data,