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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/esm/capabilities/eip7702Auth.js +3 -1
  2. package/dist/esm/capabilities/eip7702Auth.js.map +1 -1
  3. package/dist/esm/capabilities/overrides.js +8 -8
  4. package/dist/esm/capabilities/overrides.js.map +1 -1
  5. package/dist/esm/capabilities/permissions/index.d.ts +1 -1
  6. package/dist/esm/capabilities/permissions/index.js +6 -3
  7. package/dist/esm/capabilities/permissions/index.js.map +1 -1
  8. package/dist/esm/client/actions/grantPermissions.d.ts +5 -60
  9. package/dist/esm/client/actions/grantPermissions.js +5 -58
  10. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  11. package/dist/esm/client/actions/sendPreparedCalls.d.ts +6 -14
  12. package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
  13. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  14. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  15. package/dist/esm/client/actions/signPreparedCalls.js +53 -0
  16. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  17. package/dist/esm/client/actions/signSignatureRequest.d.ts +8 -7
  18. package/dist/esm/client/actions/signSignatureRequest.js +69 -31
  19. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  20. package/dist/esm/client/client.e2e-test.js +28 -25
  21. package/dist/esm/client/client.e2e-test.js.map +1 -1
  22. package/dist/esm/client/decorator.d.ts +3 -1
  23. package/dist/esm/client/decorator.js +3 -1
  24. package/dist/esm/client/decorator.js.map +1 -1
  25. package/dist/esm/exports/index.d.ts +2 -1
  26. package/dist/esm/exports/index.js +2 -1
  27. package/dist/esm/exports/index.js.map +1 -1
  28. package/dist/esm/isomorphic/actions/createSession.js +18 -32
  29. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  30. package/dist/esm/isomorphic/actions/prepareCalls.js +22 -16
  31. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  32. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  33. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +76 -36
  34. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  35. package/dist/esm/isomorphic/client.d.ts +139 -13
  36. package/dist/esm/isomorphic/utils/7702.d.ts +4 -3
  37. package/dist/esm/isomorphic/utils/7702.js +14 -6
  38. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  39. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  40. package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
  41. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  42. package/dist/esm/local/client.js +2 -3
  43. package/dist/esm/local/client.js.map +1 -1
  44. package/dist/esm/remote/client.js +3 -7
  45. package/dist/esm/remote/client.js.map +1 -1
  46. package/dist/esm/rpc/examples.d.ts +3 -3
  47. package/dist/esm/rpc/examples.js +3 -3
  48. package/dist/esm/rpc/examples.js.map +1 -1
  49. package/dist/esm/rpc/request.d.ts +357 -49
  50. package/dist/esm/rpc/request.js +26 -53
  51. package/dist/esm/rpc/request.js.map +1 -1
  52. package/dist/esm/rpc/schema.d.ts +323 -57
  53. package/dist/esm/rpc/schema.js.map +1 -1
  54. package/dist/esm/schemas.d.ts +451 -13
  55. package/dist/esm/schemas.js +165 -52
  56. package/dist/esm/schemas.js.map +1 -1
  57. package/dist/esm/types.d.ts +3 -0
  58. package/dist/esm/types.js.map +1 -1
  59. package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -1
  60. package/dist/types/capabilities/permissions/index.d.ts +1 -1
  61. package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
  62. package/dist/types/client/actions/grantPermissions.d.ts +5 -60
  63. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  64. package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
  65. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  66. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  67. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  68. package/dist/types/client/actions/signSignatureRequest.d.ts +8 -7
  69. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  70. package/dist/types/client/decorator.d.ts +3 -1
  71. package/dist/types/client/decorator.d.ts.map +1 -1
  72. package/dist/types/exports/index.d.ts +2 -1
  73. package/dist/types/exports/index.d.ts.map +1 -1
  74. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  75. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  76. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  77. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  78. package/dist/types/isomorphic/client.d.ts +139 -13
  79. package/dist/types/isomorphic/client.d.ts.map +1 -1
  80. package/dist/types/isomorphic/utils/7702.d.ts +4 -3
  81. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  82. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  83. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  84. package/dist/types/remote/client.d.ts.map +1 -1
  85. package/dist/types/rpc/examples.d.ts +3 -3
  86. package/dist/types/rpc/examples.d.ts.map +1 -1
  87. package/dist/types/rpc/request.d.ts +357 -49
  88. package/dist/types/rpc/request.d.ts.map +1 -1
  89. package/dist/types/rpc/schema.d.ts +323 -57
  90. package/dist/types/rpc/schema.d.ts.map +1 -1
  91. package/dist/types/schemas.d.ts +451 -13
  92. package/dist/types/schemas.d.ts.map +1 -1
  93. package/dist/types/types.d.ts +3 -0
  94. package/dist/types/types.d.ts.map +1 -1
  95. package/package.json +2 -2
  96. package/src/capabilities/eip7702Auth.ts +17 -10
  97. package/src/capabilities/overrides.ts +8 -8
  98. package/src/capabilities/permissions/index.ts +8 -3
  99. package/src/client/actions/grantPermissions.ts +5 -60
  100. package/src/client/actions/sendPreparedCalls.ts +17 -17
  101. package/src/client/actions/signPreparedCalls.ts +71 -0
  102. package/src/client/actions/signSignatureRequest.ts +50 -46
  103. package/src/client/client.e2e-test.ts +32 -35
  104. package/src/client/decorator.ts +14 -5
  105. package/src/exports/index.ts +2 -1
  106. package/src/isomorphic/actions/createSession.ts +20 -42
  107. package/src/isomorphic/actions/prepareCalls.ts +25 -17
  108. package/src/isomorphic/actions/sendPreparedCalls.ts +104 -54
  109. package/src/isomorphic/utils/7702.ts +18 -8
  110. package/src/isomorphic/utils/decodeSignature.ts +18 -0
  111. package/src/local/client.ts +2 -6
  112. package/src/remote/client.ts +3 -10
  113. package/src/rpc/examples.ts +3 -4
  114. package/src/rpc/request.ts +41 -63
  115. package/src/rpc/schema.ts +2 -2
  116. package/src/schemas.ts +227 -53
  117. package/src/types.ts +4 -0
@@ -2,8 +2,9 @@ import { deepHexlify, default7702GasEstimator, } from "@aa-sdk/core";
2
2
  import { ChainNotFoundError, custom, fromHex, toHex, } from "viem";
3
3
  import { createAccount } from "../utils/createAccount.js";
4
4
  import { createDummySigner } from "../utils/createDummySigner.js";
5
- import { createAuthorization, parseDelegation } from "../utils/7702.js";
5
+ import { createAuthorizationRequest, parseDelegation } from "../utils/7702.js";
6
6
  import { InvalidRequestError } from "ox/RpcResponse";
7
+ import { assertNever } from "../../utils.js";
7
8
  import { assertValid7702AccountAddress } from "../utils/7702.js";
8
9
  export async function prepareCalls(client, params) {
9
10
  if (!client.chain) {
@@ -41,7 +42,7 @@ export async function prepareCalls(client, params) {
41
42
  });
42
43
  // If using 7702, we need an Authorization (unless it's already authorized).
43
44
  const authorizationRequest = delegation
44
- ? await createAuthorization(client, {
45
+ ? await createAuthorizationRequest(client, {
45
46
  address: account.address,
46
47
  delegation,
47
48
  })
@@ -62,27 +63,32 @@ export async function prepareCalls(client, params) {
62
63
  overrides: params.capabilities?.gasParamsOverride,
63
64
  });
64
65
  // The eip7702Auth field should never be included in the UO sig
65
- // request. It's handled by the separate authorization request.
66
+ // request. It's handled by a separate authorization request.
66
67
  if ("eip7702Auth" in builtUo) {
67
68
  builtUo.eip7702Auth = undefined;
68
69
  }
69
- const uoRequest = deepHexlify(builtUo);
70
- const signatureRequest = {
71
- type: "personal_sign",
72
- data: {
73
- raw: account.getEntryPoint().getUserOperationHash(uoRequest),
74
- },
75
- };
76
- return {
77
- type: account.getEntryPoint().version === "0.7.0"
70
+ const hexlifiedUo = deepHexlify(builtUo);
71
+ const ep = account.getEntryPoint();
72
+ const uoRequest = {
73
+ type: ep.version === "0.7.0"
78
74
  ? "user-operation-v070"
79
- : "user-operation-v060",
80
- data: uoRequest,
75
+ : ep.version === "0.6.0"
76
+ ? "user-operation-v060"
77
+ : assertNever(ep.version, "Unexpected entry point version"),
78
+ data: hexlifiedUo,
81
79
  chainId: toHex(client.chain.id),
82
80
  signatureRequest: {
83
- ...signatureRequest,
84
- ...(authorizationRequest ? { authorizationRequest } : {}),
81
+ type: "personal_sign",
82
+ data: {
83
+ raw: ep.getUserOperationHash(hexlifiedUo),
84
+ },
85
85
  },
86
86
  };
87
+ return authorizationRequest
88
+ ? {
89
+ type: "array",
90
+ data: [authorizationRequest, uoRequest],
91
+ }
92
+ : uoRequest;
87
93
  }
88
94
  //# sourceMappingURL=prepareCalls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,KAAK,GAGN,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,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BAAqB;YACvB,CAAC,CAAC,qBAAqB;QAC3B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,GAAG,gBAAgB;YACnB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n deepHexlify,\n default7702GasEstimator,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport {\n ChainNotFoundError,\n custom,\n fromHex,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { wallet_prepareCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorization, parseDelegation } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertValid7702AccountAddress } from \"../utils/7702.js\";\n\nexport type PrepareCallsParams = Omit<\n Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type PrepareCallsResult = Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function prepareCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);\n\n // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth\n ? {\n counterfactualInfo: undefined,\n delegation: parseDelegation(params.capabilities.eip7702Auth),\n }\n : await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.from),\n accountAddress: params.from,\n counterfactualInfo,\n permissions: params.capabilities?.permissions,\n delegation,\n });\n\n // If using 7702, we need an Authorization (unless it's already authorized).\n const authorizationRequest = delegation\n ? await createAuthorization(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n if (authorizationRequest) {\n // @ts-expect-error - this is available but not typed as public\n client.middleware.gasEstimator = default7702GasEstimator();\n }\n\n // TODO: oops we don't actually support setting the policyId as an override here\n // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly\n const builtUo = await client.buildUserOperation({\n uo: params.calls.map((x) => ({\n target: x.to,\n data: x.data ?? \"0x\",\n value: x.value ? fromHex(x.value, \"bigint\") : undefined,\n })),\n account,\n overrides: params.capabilities?.gasParamsOverride,\n });\n\n // The eip7702Auth field should never be included in the UO sig\n // request. It's handled by the separate authorization request.\n if (\"eip7702Auth\" in builtUo) {\n builtUo.eip7702Auth = undefined;\n }\n const uoRequest = deepHexlify(builtUo);\n\n const signatureRequest = {\n type: \"personal_sign\" as const,\n data: {\n raw: account.getEntryPoint().getUserOperationHash(uoRequest),\n },\n };\n\n return {\n type:\n account.getEntryPoint().version === \"0.7.0\"\n ? \"user-operation-v070\"\n : \"user-operation-v060\",\n data: uoRequest,\n chainId: toHex(client.chain.id),\n signatureRequest: {\n ...signatureRequest,\n ...(authorizationRequest ? { authorizationRequest } : {}),\n },\n };\n}\n"]}
1
+ {"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,u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S,CAAC;IAClC,CAAC;IAED,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAEzC,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAEnC,MAAM,SAAS,GAAG;QAChB,IAAI,EACF,EAAE,CAAC,OAAO,KAAK,OAAO;YACpB,CAAC,CAAE,qBAA+B;YAClC,CAAC,CAAC,EAAE,CAAC,OAAO,KAAK,OAAO;gBACtB,CAAC,CAAE,qBAA+B;gBAClC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,gCAAgC,CAAC;QACjE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,gBAAgB,EAAE;YAChB,IAAI,EAAE,eAAwB;YAC9B,IAAI,EAAE;gBACJ,GAAG,EAAE,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC;aAC1C;SACF;KACF,CAAC;IAEF,OAAO,oBAAoB;QACzB,CAAC,CAAC;YACE,IAAI,EAAE,OAAgB;YACtB,IAAI,EAAE,CAAC,oBAAoB,EAAE,SAAS,CAAC;SACxC;QACH,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC","sourcesContent":["import {\n deepHexlify,\n default7702GasEstimator,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport {\n ChainNotFoundError,\n custom,\n fromHex,\n toHex,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { wallet_prepareCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { createAuthorizationRequest, parseDelegation } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport { assertValid7702AccountAddress } from \"../utils/7702.js\";\n\nexport type PrepareCallsParams = Omit<\n Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type PrepareCallsResult = Static<\n (typeof wallet_prepareCalls)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function prepareCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n assertValid7702AccountAddress(params.from, params.capabilities?.eip7702Auth);\n\n // in local mode, we probably want some kind of caching for this\n const { counterfactualInfo, delegation } = params.capabilities?.eip7702Auth\n ? {\n counterfactualInfo: undefined,\n delegation: parseDelegation(params.capabilities.eip7702Auth),\n }\n : await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (!counterfactualInfo && !delegation) {\n throw new InvalidRequestError({\n message:\n \"No counterfactual info or delegated implementation address found.\",\n });\n }\n\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.from),\n accountAddress: params.from,\n counterfactualInfo,\n permissions: params.capabilities?.permissions,\n delegation,\n });\n\n // If using 7702, we need an Authorization (unless it's already authorized).\n const authorizationRequest = delegation\n ? await createAuthorizationRequest(client, {\n address: account.address,\n delegation,\n })\n : undefined;\n\n if (authorizationRequest) {\n // @ts-expect-error - this is available but not typed as public\n client.middleware.gasEstimator = default7702GasEstimator();\n }\n\n // TODO: oops we don't actually support setting the policyId as an override here\n // if we assume that the the isomorphic client is never used directly, then we can assume that this is handled upstream correctly\n const builtUo = await client.buildUserOperation({\n uo: params.calls.map((x) => ({\n target: x.to,\n data: x.data ?? \"0x\",\n value: x.value ? fromHex(x.value, \"bigint\") : undefined,\n })),\n account,\n overrides: params.capabilities?.gasParamsOverride,\n });\n\n // The eip7702Auth field should never be included in the UO sig\n // request. It's handled by a separate authorization request.\n if (\"eip7702Auth\" in builtUo) {\n builtUo.eip7702Auth = undefined;\n }\n\n const hexlifiedUo = deepHexlify(builtUo);\n\n const ep = account.getEntryPoint();\n\n const uoRequest = {\n type:\n ep.version === \"0.7.0\"\n ? (\"user-operation-v070\" as const)\n : ep.version === \"0.6.0\"\n ? (\"user-operation-v060\" as const)\n : assertNever(ep.version, \"Unexpected entry point version\"),\n data: hexlifiedUo,\n chainId: toHex(client.chain.id),\n signatureRequest: {\n type: \"personal_sign\" as const,\n data: {\n raw: ep.getUserOperationHash(hexlifiedUo),\n },\n },\n };\n\n return authorizationRequest\n ? {\n type: \"array\" as const,\n data: [authorizationRequest, uoRequest],\n }\n : uoRequest;\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
- import type { Static, StaticDecode } from "@sinclair/typebox";
3
2
  import { type Chain, type Transport } from "viem";
4
- import type { wallet_sendPreparedCalls } from "../../rpc/request.js";
3
+ import { type wallet_sendPreparedCalls } from "../../rpc/request.js";
5
4
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
6
- export type SendPreparedCallsParams = Omit<StaticDecode<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0], "chainId">;
5
+ import type { Static } from "@sinclair/typebox";
6
+ export type SendPreparedCallsParams = Static<(typeof wallet_sendPreparedCalls)["properties"]["Request"]["properties"]["params"]>[0];
7
7
  export type SendPreparedCallsResult = Static<(typeof wallet_sendPreparedCalls)["properties"]["ReturnType"]>;
8
8
  export declare function sendPreparedCalls(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: SendPreparedCallsParams): Promise<SendPreparedCallsResult>;
@@ -1,22 +1,18 @@
1
1
  import { getEntryPoint, } from "@aa-sdk/core";
2
2
  import { Value } from "@sinclair/typebox/value";
3
- import { BaseError, ChainNotFoundError, concat, concatHex, toHex, } from "viem";
3
+ import { BaseError, ChainNotFoundError, concat, concatHex, numberToHex, parseSignature, toHex, } from "viem";
4
4
  import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
5
+ import {} from "../../rpc/request.js";
5
6
  import { TypeCallId } from "../../schemas.js";
6
7
  import { isSupportedDelegationAddress7702 } from "../utils/7702.js";
7
8
  import { InvalidRequestError } from "ox/RpcResponse";
9
+ import { assertNever } from "../../utils.js";
10
+ import { decodeSignature } from "../utils/decodeSignature.js";
8
11
  // TODO: this only supports MAv2 right now, we need to fix this
9
12
  export async function sendPreparedCalls(client, params) {
10
13
  if (!client.chain) {
11
14
  throw new ChainNotFoundError();
12
15
  }
13
- // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
14
- if (params.signedAuthorization &&
15
- !isSupportedDelegationAddress7702(params.signedAuthorization.address)) {
16
- throw new InvalidRequestError({
17
- message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,
18
- });
19
- }
20
16
  const deferredAction = (() => {
21
17
  if (!params.capabilities?.permissions) {
22
18
  return;
@@ -29,35 +25,79 @@ export async function sendPreparedCalls(client, params) {
29
25
  }
30
26
  return decodedContext.deferredAction;
31
27
  })();
32
- const entryPoint = params.type === "user-operation-v060"
33
- ? getEntryPoint(client.chain, { version: "0.6.0" })
34
- : getEntryPoint(client.chain, { version: "0.7.0" });
35
- const hash = await client
36
- .sendRawUserOperation({
37
- ...params.data,
38
- signature: deferredAction != null
39
- ? concatHex([
40
- `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).
41
- "0xff",
42
- "0x00",
43
- params.signature.signature,
44
- ])
45
- : concat(["0xFF", "0x00", params.signature.signature]),
46
- eip7702Auth: params.signedAuthorization,
47
- }, entryPoint.address)
48
- .catch((err) => {
49
- if (err instanceof BaseError &&
50
- err.details.endsWith("is not a contract and initCode is empty")) {
51
- throw new BaseError(`${err.details} (If using 7702, be sure you include the 'signedAuthorization' field in the request parameters)`);
52
- }
53
- throw err;
54
- });
55
- const callId = Value.Encode(TypeCallId, {
56
- chainId: toHex(client.chain.id),
57
- hash,
58
- });
28
+ const userOps = params.type === "array"
29
+ ? params.data.filter((it) => {
30
+ const isUserOp = it.type === "user-operation-v060" ||
31
+ it.type === "user-operation-v070";
32
+ if (isUserOp && it.chainId !== toHex(client.chain.id)) {
33
+ throw new InvalidRequestError({
34
+ message: "Multiple chain IDs in a single request are not currently supported.",
35
+ });
36
+ }
37
+ return isUserOp;
38
+ })
39
+ : [params];
40
+ const authorizations = params.type === "array"
41
+ ? params.data.filter((it) => it.type === "authorization")
42
+ : [];
43
+ if (authorizations.length > 1) {
44
+ throw new InvalidRequestError({
45
+ message: "Multiple authorizations in a single request are not currently supported",
46
+ });
47
+ }
48
+ const [authorization] = authorizations;
49
+ // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.
50
+ if (authorization &&
51
+ !isSupportedDelegationAddress7702(authorization.data.address)) {
52
+ throw new InvalidRequestError({
53
+ message: `Unsupported 7702 delegation address: ${authorization.data.address}`,
54
+ });
55
+ }
56
+ const hashes = await Promise.all(userOps.map(async (userOp, idx) => {
57
+ const ep = userOp.type === "user-operation-v060"
58
+ ? getEntryPoint(client.chain, { version: "0.6.0" })
59
+ : userOp.type === "user-operation-v070"
60
+ ? getEntryPoint(client.chain, { version: "0.7.0" })
61
+ : assertNever(userOp, "Unexpected user op type");
62
+ const authSig = authorization
63
+ ? parseSignature(decodeSignature(authorization.signature).data)
64
+ : undefined;
65
+ const uoSigHex = decodeSignature(userOp.signature).data;
66
+ return client
67
+ .sendRawUserOperation({
68
+ ...userOp.data,
69
+ signature: deferredAction != null
70
+ ? concatHex([
71
+ `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc. that we had previously).
72
+ "0xff",
73
+ "0x00",
74
+ uoSigHex,
75
+ ])
76
+ : concat(["0xFF", "0x00", uoSigHex]),
77
+ eip7702Auth: idx === 0 && authorization && authSig
78
+ ? {
79
+ ...authorization.data,
80
+ chainId: authorization.chainId,
81
+ ...{
82
+ ...authSig,
83
+ yParity: numberToHex(authSig.yParity),
84
+ },
85
+ }
86
+ : undefined,
87
+ }, ep.address)
88
+ .catch((err) => {
89
+ if (err instanceof BaseError &&
90
+ err.details.endsWith("is not a contract and initCode is empty")) {
91
+ throw new BaseError(`${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`);
92
+ }
93
+ throw err;
94
+ });
95
+ }));
59
96
  return {
60
- preparedCallIds: [callId],
97
+ preparedCallIds: hashes.map((hash) => Value.Encode(TypeCallId, {
98
+ chainId: toHex(client.chain.id),
99
+ hash,
100
+ })),
61
101
  };
62
102
  }
63
103
  //# sourceMappingURL=sendPreparedCalls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,KAAK,GAIN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAarD,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAMC,EACD,MAA+B;IAE/B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,6GAA6G;IAC7G,IACE,MAAM,CAAC,mBAAmB;QAC1B,CAAC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S,CAAC,CAAC;QAC1D,WAAW,EAAE,MAAM,CAAC,mBAAmB;KACxC,EACD,UAAU,CAAC,OAAO,CACnB;SACA,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IACE,GAAG,YAAY,SAAS;YACxB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,yCAAyC,CAAC,EAC/D,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,GAAG,GAAG,CAAC,OAAO,iGAAiG,CAChH,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;IAEL,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;QACtC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,IAAI;KACL,CAAC,CAAC;IAEH,OAAO;QACL,eAAe,EAAE,CAAC,MAAM,CAAC;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import {\n getEntryPoint,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static, StaticDecode } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n BaseError,\n ChainNotFoundError,\n concat,\n concatHex,\n toHex,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport type { wallet_sendPreparedCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { TypeCallId } from \"../../schemas.js\";\nimport { isSupportedDelegationAddress7702 } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\n\nexport type SendPreparedCallsParams = Omit<\n StaticDecode<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n>;\n\nexport type SendPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"ReturnType\"]\n>;\n\n// TODO: this only supports MAv2 right now, we need to fix this\nexport async function sendPreparedCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.\n if (\n params.signedAuthorization &&\n !isSupportedDelegationAddress7702(params.signedAuthorization.address)\n ) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${params.signedAuthorization.address}`,\n });\n }\n\n const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message:\n \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return decodedContext.deferredAction;\n })();\n\n const entryPoint =\n params.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : getEntryPoint(client.chain, { version: \"0.7.0\" });\n\n const hash = await client\n .sendRawUserOperation(\n {\n ...params.data,\n signature:\n deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff preprended to the digest (nonce, etc. that we had previously).\n \"0xff\",\n \"0x00\",\n params.signature.signature,\n ])\n : concat([\"0xFF\", \"0x00\", params.signature.signature]),\n eip7702Auth: params.signedAuthorization,\n },\n entryPoint.address,\n )\n .catch((err) => {\n if (\n err instanceof BaseError &&\n err.details.endsWith(\"is not a contract and initCode is empty\")\n ) {\n throw new BaseError(\n `${err.details} (If using 7702, be sure you include the 'signedAuthorization' field in the request parameters)`,\n );\n }\n throw err;\n });\n\n const callId = Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n });\n\n return {\n preparedCallIds: [callId],\n };\n}\n"]}
1
+ {"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,WAAW,EACX,cAAc,EACd,KAAK,GAKN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAiC,MAAM,sBAAsB,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAU9D,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAMC,EACD,MAA+B;IAE/B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,cAAc,GAAoB,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;YACtC,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,wBAAwB,CAC7C,MAAM,CAAC,YAAY,CAAC,WAAW,CAChC,CAAC;QAEF,IAAI,cAAc,CAAC,cAAc,KAAK,6BAA6B,EAAE,CAAC;YACpE,MAAM,IAAI,mBAAmB,CAAC;gBAC5B,OAAO,EACL,gEAAgE;aACnE,CAAC,CAAC;QACL,CAAC;QAED,OAAO,cAAc,CAAC,cAAc,CAAC;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AAC,SAAS;SAChB,EACD,EAAE,CAAC,OAAO,CACX;aACA,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,IACE,GAAG,YAAY,SAAS;gBACxB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,yCAAyC,CAAC,EAC/D,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,GAAG,GAAG,CAAC,OAAO,0FAA0F,CACzG,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;YACvB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,IAAI;SACL,CAAC,CACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n getEntryPoint,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n BaseError,\n ChainNotFoundError,\n concat,\n concatHex,\n numberToHex,\n parseSignature,\n toHex,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport { type wallet_sendPreparedCalls } from \"../../rpc/request.js\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport { TypeCallId } from \"../../schemas.js\";\nimport { isSupportedDelegationAddress7702 } from \"../utils/7702.js\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { assertNever } from \"../../utils.js\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { decodeSignature } from \"../utils/decodeSignature.js\";\n\nexport type SendPreparedCallsParams = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type SendPreparedCallsResult = Static<\n (typeof wallet_sendPreparedCalls)[\"properties\"][\"ReturnType\"]\n>;\n\n// TODO: this only supports MAv2 right now, we need to fix this\nexport async function sendPreparedCalls(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const deferredAction: Hex | undefined = (() => {\n if (!params.capabilities?.permissions) {\n return;\n }\n\n const decodedContext = decodePermissionsContext(\n params.capabilities.permissions,\n );\n\n if (decodedContext.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message:\n \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return decodedContext.deferredAction;\n })();\n\n const userOps =\n params.type === \"array\"\n ? params.data.filter((it) => {\n const isUserOp =\n it.type === \"user-operation-v060\" ||\n it.type === \"user-operation-v070\";\n if (isUserOp && it.chainId !== toHex(client.chain.id)) {\n throw new InvalidRequestError({\n message:\n \"Multiple chain IDs in a single request are not currently supported.\",\n });\n }\n return isUserOp;\n })\n : [params];\n\n const authorizations =\n params.type === \"array\"\n ? params.data.filter((it) => it.type === \"authorization\")\n : [];\n\n if (authorizations.length > 1) {\n throw new InvalidRequestError({\n message:\n \"Multiple authorizations in a single request are not currently supported\",\n });\n }\n const [authorization] = authorizations;\n\n // One last safety check to be sure the UO wasn't modified to include an unsupported 7702 delegation address.\n if (\n authorization &&\n !isSupportedDelegationAddress7702(authorization.data.address)\n ) {\n throw new InvalidRequestError({\n message: `Unsupported 7702 delegation address: ${authorization.data.address}`,\n });\n }\n\n const hashes = await Promise.all(\n userOps.map(async (userOp, idx) => {\n const ep: { address: Address } =\n userOp.type === \"user-operation-v060\"\n ? getEntryPoint(client.chain, { version: \"0.6.0\" })\n : userOp.type === \"user-operation-v070\"\n ? getEntryPoint(client.chain, { version: \"0.7.0\" })\n : assertNever(userOp, \"Unexpected user op type\");\n const authSig = authorization\n ? parseSignature(decodeSignature(authorization.signature).data)\n : undefined;\n const uoSigHex = decodeSignature(userOp.signature).data;\n return client\n .sendRawUserOperation(\n {\n ...userOp.data,\n signature:\n deferredAction != null\n ? concatHex([\n `0x${deferredAction.slice(68)}`, // Cuts off stuff prepended to the digest (nonce, etc. that we had previously).\n \"0xff\",\n \"0x00\",\n uoSigHex,\n ])\n : concat([\"0xFF\", \"0x00\", uoSigHex]),\n eip7702Auth:\n idx === 0 && authorization && authSig\n ? {\n ...authorization.data,\n chainId: authorization.chainId,\n ...{\n ...authSig,\n yParity: numberToHex(authSig.yParity),\n },\n }\n : undefined,\n },\n ep.address,\n )\n .catch((err) => {\n if (\n err instanceof BaseError &&\n err.details.endsWith(\"is not a contract and initCode is empty\")\n ) {\n throw new BaseError(\n `${err.details} (If using 7702, be sure you include the signed authorization in the request parameters)`,\n );\n }\n throw err;\n });\n }),\n );\n\n return {\n preparedCallIds: hashes.map((hash) =>\n Value.Encode(TypeCallId, {\n chainId: toHex(client.chain.id),\n hash,\n }),\n ),\n };\n}\n"]}
@@ -13,7 +13,108 @@ type ClientParams = {
13
13
  };
14
14
  export declare function isomorphicClientActions(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>): {
15
15
  prepareCalls: (params: PrepareCallsParams) => Promise<{
16
- type: "user-operation-v060" | "user-operation-v070";
16
+ type: "array";
17
+ data: ({
18
+ type: "user-operation-v060";
19
+ chainId: `0x${string}`;
20
+ data: {
21
+ sender: `0x${string}`;
22
+ nonce: `0x${string}`;
23
+ initCode: `0x${string}`;
24
+ callData: `0x${string}`;
25
+ callGasLimit: `0x${string}`;
26
+ verificationGasLimit: `0x${string}`;
27
+ preVerificationGas: `0x${string}`;
28
+ maxFeePerGas: `0x${string}`;
29
+ maxPriorityFeePerGas: `0x${string}`;
30
+ paymasterAndData: `0x${string}`;
31
+ };
32
+ signatureRequest: {
33
+ type: "eth_signTypedData_v4";
34
+ data: {
35
+ domain?: {
36
+ chainId?: number | undefined;
37
+ salt?: `0x${string}` | undefined;
38
+ name?: string | undefined;
39
+ verifyingContract?: `0x${string}` | undefined;
40
+ version?: string | undefined;
41
+ } | undefined;
42
+ types: {
43
+ [x: string]: {
44
+ type: string;
45
+ name: string;
46
+ }[];
47
+ };
48
+ primaryType: string;
49
+ message: {
50
+ [x: string]: unknown;
51
+ };
52
+ };
53
+ } | {
54
+ type: "personal_sign";
55
+ data: string | {
56
+ raw: `0x${string}`;
57
+ };
58
+ };
59
+ } | {
60
+ type: "user-operation-v070";
61
+ chainId: `0x${string}`;
62
+ data: {
63
+ factory?: `0x${string}` | undefined;
64
+ factoryData?: `0x${string}` | undefined;
65
+ paymaster?: `0x${string}` | undefined;
66
+ paymasterData?: `0x${string}` | undefined;
67
+ paymasterVerificationGasLimit?: `0x${string}` | undefined;
68
+ paymasterPostOpGasLimit?: `0x${string}` | undefined;
69
+ sender: `0x${string}`;
70
+ nonce: `0x${string}`;
71
+ callData: `0x${string}`;
72
+ callGasLimit: `0x${string}`;
73
+ verificationGasLimit: `0x${string}`;
74
+ preVerificationGas: `0x${string}`;
75
+ maxFeePerGas: `0x${string}`;
76
+ maxPriorityFeePerGas: `0x${string}`;
77
+ };
78
+ signatureRequest: {
79
+ type: "eth_signTypedData_v4";
80
+ data: {
81
+ domain?: {
82
+ chainId?: number | undefined;
83
+ salt?: `0x${string}` | undefined;
84
+ name?: string | undefined;
85
+ verifyingContract?: `0x${string}` | undefined;
86
+ version?: string | undefined;
87
+ } | undefined;
88
+ types: {
89
+ [x: string]: {
90
+ type: string;
91
+ name: string;
92
+ }[];
93
+ };
94
+ primaryType: string;
95
+ message: {
96
+ [x: string]: unknown;
97
+ };
98
+ };
99
+ } | {
100
+ type: "personal_sign";
101
+ data: string | {
102
+ raw: `0x${string}`;
103
+ };
104
+ };
105
+ } | {
106
+ type: "authorization";
107
+ chainId: `0x${string}`;
108
+ data: {
109
+ nonce: `0x${string}`;
110
+ address: `0x${string}`;
111
+ };
112
+ signatureRequest: {
113
+ type: "eip7702Auth";
114
+ };
115
+ })[];
116
+ } | {
117
+ type: "user-operation-v060";
17
118
  chainId: `0x${string}`;
18
119
  data: {
19
120
  sender: `0x${string}`;
@@ -26,7 +127,38 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
26
127
  maxFeePerGas: `0x${string}`;
27
128
  maxPriorityFeePerGas: `0x${string}`;
28
129
  paymasterAndData: `0x${string}`;
130
+ };
131
+ signatureRequest: {
132
+ type: "eth_signTypedData_v4";
133
+ data: {
134
+ domain?: {
135
+ chainId?: number | undefined;
136
+ salt?: `0x${string}` | undefined;
137
+ name?: string | undefined;
138
+ verifyingContract?: `0x${string}` | undefined;
139
+ version?: string | undefined;
140
+ } | undefined;
141
+ types: {
142
+ [x: string]: {
143
+ type: string;
144
+ name: string;
145
+ }[];
146
+ };
147
+ primaryType: string;
148
+ message: {
149
+ [x: string]: unknown;
150
+ };
151
+ };
29
152
  } | {
153
+ type: "personal_sign";
154
+ data: string | {
155
+ raw: `0x${string}`;
156
+ };
157
+ };
158
+ } | {
159
+ type: "user-operation-v070";
160
+ chainId: `0x${string}`;
161
+ data: {
30
162
  factory?: `0x${string}` | undefined;
31
163
  factoryData?: `0x${string}` | undefined;
32
164
  paymaster?: `0x${string}` | undefined;
@@ -42,12 +174,7 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
42
174
  maxFeePerGas: `0x${string}`;
43
175
  maxPriorityFeePerGas: `0x${string}`;
44
176
  };
45
- signatureRequest: ({
46
- type: "personal_sign";
47
- data: string | {
48
- raw: `0x${string}`;
49
- };
50
- } | {
177
+ signatureRequest: {
51
178
  type: "eth_signTypedData_v4";
52
179
  data: {
53
180
  domain?: {
@@ -68,12 +195,11 @@ export declare function isomorphicClientActions(client: SmartAccountClient<Trans
68
195
  [x: string]: unknown;
69
196
  };
70
197
  };
71
- }) & {
72
- authorizationRequest?: {
73
- nonce: number;
74
- chainId: number;
75
- address: `0x${string}`;
76
- } | undefined;
198
+ } | {
199
+ type: "personal_sign";
200
+ data: string | {
201
+ raw: `0x${string}`;
202
+ };
77
203
  };
78
204
  }>;
79
205
  sendPreparedCalls: (params: SendPreparedCallsParams) => Promise<{
@@ -1,12 +1,13 @@
1
1
  import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
2
- import { type Authorization, type Address, type Chain, type Transport } from "viem";
2
+ import { type Address, type Chain, type Transport } from "viem";
3
3
  import type { WalletServerViemRpcSchema } from "../../rpc/schema.js";
4
+ import { PreparedCall_Authorization } from "../../schemas.js";
4
5
  import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
5
6
  import type { Static } from "@sinclair/typebox";
6
- export declare const createAuthorization: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
7
+ export declare const createAuthorizationRequest: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
7
8
  address: Address;
8
9
  delegation: Address;
9
- }) => Promise<Authorization<number, false> | undefined>;
10
+ }) => Promise<Static<typeof PreparedCall_Authorization> | undefined>;
10
11
  export declare const EIP_7702_ACCOUNT_TYPE: readonly ["ModularAccountV2"];
11
12
  type Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];
12
13
  export declare const SUPPORTED_DELEGATION_ADDRESSES: "0x69007702764179f14F51cdce752f4f775d74E139"[];
@@ -1,17 +1,25 @@
1
- import { concatHex, isAddress, } from "viem";
1
+ import { concatHex, numberToHex, isAddress, } from "viem";
2
+ import { PreparedCall_Authorization } from "../../schemas.js";
2
3
  import { InvalidRequestError } from "ox/RpcResponse";
3
- export const createAuthorization = async (client, params) => {
4
+ export const createAuthorizationRequest = async (client, params) => {
4
5
  const expectedCode = concatHex(["0xef0100", params.delegation]);
5
6
  const code = (await client.getCode({ address: params.address })) ?? "0x";
6
7
  if (code.toLowerCase() === expectedCode.toLowerCase()) {
7
8
  return undefined; // Already authorized.
8
9
  }
9
- return {
10
- chainId: client.chain.id,
10
+ const data = {
11
11
  address: params.delegation,
12
- nonce: await client.getTransactionCount({
12
+ nonce: numberToHex(await client.getTransactionCount({
13
13
  address: params.address,
14
- }),
14
+ })),
15
+ };
16
+ return {
17
+ type: "authorization",
18
+ data,
19
+ chainId: numberToHex(client.chain.id),
20
+ signatureRequest: {
21
+ type: "eip7702Auth",
22
+ },
15
23
  };
16
24
  };
17
25
  export const EIP_7702_ACCOUNT_TYPE = ["ModularAccountV2"];
@@ -1 +1 @@
1
- {"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAKT,SAAS,GACV,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAMC,EACD,MAAiD,EACE,EAAE;IACrD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;IACzE,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC,CAAC,sBAAsB;IAC1C,CAAC;IACD,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,EAAE,MAAM,CAAC,UAAU;QAC1B,KAAK,EAAE,MAAM,MAAM,CAAC,mBAAmB,CAAC;YACtC,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,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;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 type Authorization,\n type Address,\n type Chain,\n type Transport,\n isAddress,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\nimport type { Eip7702AuthCapability } from \"../../capabilities/eip7702Auth.ts\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\n\nexport const createAuthorization = async (\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: { address: Address; delegation: Address },\n): Promise<Authorization<number, false> | undefined> => {\n const expectedCode = concatHex([\"0xef0100\", params.delegation]);\n const code = (await client.getCode({ address: params.address })) ?? \"0x\";\n if (code.toLowerCase() === expectedCode.toLowerCase()) {\n return undefined; // Already authorized.\n }\n return {\n chainId: client.chain.id,\n address: params.delegation,\n nonce: await client.getTransactionCount({\n address: params.address,\n }),\n };\n};\n\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,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,CA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AqC,CACtC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,OAAgB,EAAW,EAAE;IAC5E,OAAQ,8BAA4C,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sCAAsC,GAAG,CACpD,OAAgB,EACsB,EAAE;IACxC,OAAO,8BAA8B,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,sCAAsC,GAAG,CAC7C,WAAqC,EACY,EAAE;IACnD,OAAO,qCAAqC,CAAC,WAAW,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAChC,qCAAqC,CAAC,kBAAkB,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,qBAA2D,EAC3D,EAAE;IACF,OAAO,qBAAqB,KAAK,IAAI;QACnC,CAAC,CAAC,4BAA4B;QAC9B,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,UAAU,CAAC;YAC3C,CAAC,CAAC,qBAAqB,CAAC,UAAU;YAClC,CAAC,CAAC,sCAAsC,CACpC,qBAAqB,CAAC,UAAU,CACjC,CAAC;AACV,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,WAAoB,EACpB,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"]}
@@ -0,0 +1,3 @@
1
+ import type { Static, StaticDecode } from "@sinclair/typebox";
2
+ import { TypeEcdsaSig } from "../../schemas.js";
3
+ export declare const decodeSignature: (signature: Static<typeof TypeEcdsaSig>["signature"]) => StaticDecode<typeof TypeEcdsaSig>["signature"];
@@ -0,0 +1,13 @@
1
+ import { Value } from "@sinclair/typebox/value";
2
+ import { TypeEcdsaSig } from "../../schemas.js";
3
+ import { assertNever } from "../../utils.js";
4
+ export const decodeSignature = (signature) => {
5
+ switch (signature.type) {
6
+ case "ecdsa":
7
+ case "secp256k1":
8
+ return Value.Decode(TypeEcdsaSig, { signature }).signature;
9
+ default:
10
+ return assertNever(signature, "Unexpected signature type");
11
+ }
12
+ };
13
+ //# sourceMappingURL=decodeSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeSignature.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/decodeSignature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAmD,EACH,EAAE;IAClD,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,OAAO,CAAC;QACb,KAAK,WAAW;YACd,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,SAAS,EAE5C,CAAC,CAAC,SAAS,CAAC;QACf;YACE,OAAO,WAAW,CAAC,SAAS,EAAE,2BAA2B,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { Value } from \"@sinclair/typebox/value\";\nimport type { Static, StaticDecode } from \"@sinclair/typebox\";\nimport { TypeEcdsaSig } from \"../../schemas.js\";\nimport { assertNever } from \"../../utils.js\";\n\nexport const decodeSignature = (\n signature: Static<typeof TypeEcdsaSig>[\"signature\"],\n): StaticDecode<typeof TypeEcdsaSig>[\"signature\"] => {\n switch (signature.type) {\n case \"ecdsa\":\n case \"secp256k1\":\n return Value.Decode(TypeEcdsaSig, { signature } satisfies Static<\n typeof TypeEcdsaSig\n >).signature;\n default:\n return assertNever(signature, \"Unexpected signature type\");\n }\n};\n"]}
@@ -81,16 +81,15 @@ const innerClientActions = (isomorphicClient) => {
81
81
  return {
82
82
  grantPermissions: async (signer, params) => {
83
83
  const { signatureRequest, fullPreSignatureDeferredActionDigest } = await isomorphicClient.createSession(params);
84
- const { signedAuthorization, signature } = await signSignatureRequest(signer, signatureRequest);
84
+ const signature = await signSignatureRequest(signer, signatureRequest);
85
85
  return {
86
86
  context: encodePermissionsContext({
87
87
  contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
88
88
  deferredAction: buildDeferredActionDigest({
89
89
  fullPreSignatureDeferredActionDigest,
90
- sig: prefixSignatureKeyType(signature, "secp256k1"),
90
+ sig: prefixSignatureKeyType(signature.data, signature.type),
91
91
  }),
92
92
  }),
93
- signedAuthorization,
94
93
  };
95
94
  },
96
95
  };