@account-kit/wallet-client 0.1.0-alpha.4 → 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 (186) hide show
  1. package/dist/esm/capabilities/eip7702Auth.d.ts +4 -0
  2. package/dist/esm/capabilities/eip7702Auth.js +18 -0
  3. package/dist/esm/capabilities/eip7702Auth.js.map +1 -0
  4. package/dist/esm/capabilities/index.d.ts +4 -0
  5. package/dist/esm/capabilities/index.js +2 -0
  6. package/dist/esm/capabilities/index.js.map +1 -1
  7. package/dist/esm/capabilities/overrides.js +8 -8
  8. package/dist/esm/capabilities/overrides.js.map +1 -1
  9. package/dist/esm/capabilities/permissions/index.d.ts +2 -2
  10. package/dist/esm/capabilities/permissions/index.js +6 -3
  11. package/dist/esm/capabilities/permissions/index.js.map +1 -1
  12. package/dist/esm/capabilities/permissions/mav2.js +1 -0
  13. package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
  14. package/dist/esm/client/actions/getCallsStatus.d.ts +1 -2
  15. package/dist/esm/client/actions/getCallsStatus.js +19 -0
  16. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  17. package/dist/esm/client/actions/grantPermissions.d.ts +10 -65
  18. package/dist/esm/client/actions/grantPermissions.js +63 -4
  19. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  20. package/dist/esm/client/actions/prepareCalls.d.ts +4 -4
  21. package/dist/esm/client/actions/prepareCalls.js +38 -5
  22. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  23. package/dist/esm/client/actions/requestAccount.d.ts +3 -4
  24. package/dist/esm/client/actions/requestAccount.js +18 -1
  25. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  26. package/dist/esm/client/actions/sendPreparedCalls.d.ts +6 -14
  27. package/dist/esm/client/actions/sendPreparedCalls.js +11 -12
  28. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  29. package/dist/esm/client/actions/signMessage.d.ts +3 -3
  30. package/dist/esm/client/actions/signMessage.js +18 -0
  31. package/dist/esm/client/actions/signMessage.js.map +1 -1
  32. package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
  33. package/dist/esm/client/actions/signPreparedCalls.js +53 -0
  34. package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
  35. package/dist/esm/client/actions/signSignatureRequest.d.ts +9 -8
  36. package/dist/esm/client/actions/signSignatureRequest.js +69 -31
  37. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  38. package/dist/esm/client/actions/signTypedData.d.ts +2 -2
  39. package/dist/esm/client/actions/signTypedData.js +31 -0
  40. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  41. package/dist/esm/client/client.e2e-test.js +47 -44
  42. package/dist/esm/client/client.e2e-test.js.map +1 -1
  43. package/dist/esm/client/decorator.d.ts +7 -5
  44. package/dist/esm/client/decorator.js +3 -1
  45. package/dist/esm/client/decorator.js.map +1 -1
  46. package/dist/esm/client/index.d.ts +35 -10
  47. package/dist/esm/client/index.js +0 -29
  48. package/dist/esm/client/index.js.map +1 -1
  49. package/dist/esm/exports/index.d.ts +2 -1
  50. package/dist/esm/exports/index.js +2 -1
  51. package/dist/esm/exports/index.js.map +1 -1
  52. package/dist/esm/isomorphic/actions/createSession.js +15 -18
  53. package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
  54. package/dist/esm/isomorphic/actions/getCallsStatus.js +62 -9
  55. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
  56. package/dist/esm/isomorphic/actions/prepareCalls.js +39 -26
  57. package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
  58. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  59. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +77 -37
  60. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
  61. package/dist/esm/isomorphic/client.d.ts +139 -13
  62. package/dist/esm/isomorphic/utils/7702.d.ts +13 -6
  63. package/dist/esm/isomorphic/utils/7702.js +48 -13
  64. package/dist/esm/isomorphic/utils/7702.js.map +1 -1
  65. package/dist/esm/isomorphic/utils/createAccount.d.ts +2 -2
  66. package/dist/esm/isomorphic/utils/createAccount.js +4 -3
  67. package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
  68. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
  69. package/dist/esm/isomorphic/utils/decodeSignature.js +13 -0
  70. package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
  71. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +2 -2
  72. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +8 -7
  73. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
  74. package/dist/esm/local/client.d.ts +2 -2
  75. package/dist/esm/local/client.js +2 -3
  76. package/dist/esm/local/client.js.map +1 -1
  77. package/dist/esm/remote/client.d.ts +8 -2
  78. package/dist/esm/remote/client.js +3 -13
  79. package/dist/esm/remote/client.js.map +1 -1
  80. package/dist/esm/rpc/examples.d.ts +3 -3
  81. package/dist/esm/rpc/examples.js +3 -3
  82. package/dist/esm/rpc/examples.js.map +1 -1
  83. package/dist/esm/rpc/request.d.ts +362 -44
  84. package/dist/esm/rpc/request.js +26 -56
  85. package/dist/esm/rpc/request.js.map +1 -1
  86. package/dist/esm/rpc/schema.d.ts +325 -49
  87. package/dist/esm/rpc/schema.js.map +1 -1
  88. package/dist/esm/schemas.d.ts +454 -14
  89. package/dist/esm/schemas.js +168 -53
  90. package/dist/esm/schemas.js.map +1 -1
  91. package/dist/esm/types.d.ts +10 -10
  92. package/dist/esm/types.js.map +1 -1
  93. package/dist/types/capabilities/eip7702Auth.d.ts +5 -0
  94. package/dist/types/capabilities/eip7702Auth.d.ts.map +1 -0
  95. package/dist/types/capabilities/index.d.ts +4 -0
  96. package/dist/types/capabilities/index.d.ts.map +1 -1
  97. package/dist/types/capabilities/permissions/index.d.ts +2 -2
  98. package/dist/types/capabilities/permissions/index.d.ts.map +1 -1
  99. package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
  100. package/dist/types/client/actions/getCallsStatus.d.ts +1 -2
  101. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  102. package/dist/types/client/actions/grantPermissions.d.ts +10 -65
  103. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  104. package/dist/types/client/actions/prepareCalls.d.ts +4 -4
  105. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  106. package/dist/types/client/actions/requestAccount.d.ts +3 -4
  107. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  108. package/dist/types/client/actions/sendPreparedCalls.d.ts +6 -14
  109. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  110. package/dist/types/client/actions/signMessage.d.ts +3 -3
  111. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  112. package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
  113. package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
  114. package/dist/types/client/actions/signSignatureRequest.d.ts +9 -8
  115. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  116. package/dist/types/client/actions/signTypedData.d.ts +2 -2
  117. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  118. package/dist/types/client/decorator.d.ts +7 -5
  119. package/dist/types/client/decorator.d.ts.map +1 -1
  120. package/dist/types/client/index.d.ts +35 -10
  121. package/dist/types/client/index.d.ts.map +1 -1
  122. package/dist/types/exports/index.d.ts +2 -1
  123. package/dist/types/exports/index.d.ts.map +1 -1
  124. package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
  125. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
  126. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
  127. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -3
  128. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
  129. package/dist/types/isomorphic/client.d.ts +139 -13
  130. package/dist/types/isomorphic/client.d.ts.map +1 -1
  131. package/dist/types/isomorphic/utils/7702.d.ts +13 -6
  132. package/dist/types/isomorphic/utils/7702.d.ts.map +1 -1
  133. package/dist/types/isomorphic/utils/createAccount.d.ts +2 -2
  134. package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
  135. package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
  136. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
  137. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +2 -2
  138. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
  139. package/dist/types/local/client.d.ts +2 -2
  140. package/dist/types/local/client.d.ts.map +1 -1
  141. package/dist/types/remote/client.d.ts +8 -2
  142. package/dist/types/remote/client.d.ts.map +1 -1
  143. package/dist/types/rpc/examples.d.ts +3 -3
  144. package/dist/types/rpc/examples.d.ts.map +1 -1
  145. package/dist/types/rpc/request.d.ts +362 -44
  146. package/dist/types/rpc/request.d.ts.map +1 -1
  147. package/dist/types/rpc/schema.d.ts +325 -49
  148. package/dist/types/rpc/schema.d.ts.map +1 -1
  149. package/dist/types/schemas.d.ts +454 -14
  150. package/dist/types/schemas.d.ts.map +1 -1
  151. package/dist/types/types.d.ts +10 -10
  152. package/dist/types/types.d.ts.map +1 -1
  153. package/package.json +2 -2
  154. package/src/capabilities/eip7702Auth.ts +26 -0
  155. package/src/capabilities/index.ts +2 -0
  156. package/src/capabilities/overrides.ts +8 -8
  157. package/src/capabilities/permissions/index.ts +8 -3
  158. package/src/capabilities/permissions/mav2.ts +1 -0
  159. package/src/client/actions/getCallsStatus.ts +0 -10
  160. package/src/client/actions/grantPermissions.ts +16 -84
  161. package/src/client/actions/prepareCalls.ts +18 -23
  162. package/src/client/actions/requestAccount.ts +9 -26
  163. package/src/client/actions/sendPreparedCalls.ts +17 -17
  164. package/src/client/actions/signMessage.ts +2 -17
  165. package/src/client/actions/signPreparedCalls.ts +71 -0
  166. package/src/client/actions/signSignatureRequest.ts +51 -47
  167. package/src/client/actions/signTypedData.ts +1 -16
  168. package/src/client/client.e2e-test.ts +54 -57
  169. package/src/client/decorator.ts +19 -15
  170. package/src/client/index.ts +16 -39
  171. package/src/exports/index.ts +2 -1
  172. package/src/isomorphic/actions/createSession.ts +17 -20
  173. package/src/isomorphic/actions/getCallsStatus.ts +82 -10
  174. package/src/isomorphic/actions/prepareCalls.ts +43 -27
  175. package/src/isomorphic/actions/sendPreparedCalls.ts +105 -55
  176. package/src/isomorphic/utils/7702.ts +79 -21
  177. package/src/isomorphic/utils/createAccount.ts +5 -5
  178. package/src/isomorphic/utils/decodeSignature.ts +18 -0
  179. package/src/isomorphic/utils/parsePermissionsContext.ts +9 -9
  180. package/src/local/client.ts +5 -11
  181. package/src/remote/client.ts +7 -22
  182. package/src/rpc/examples.ts +3 -4
  183. package/src/rpc/request.ts +41 -64
  184. package/src/rpc/schema.ts +2 -2
  185. package/src/schemas.ts +232 -54
  186. package/src/types.ts +9 -21
@@ -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-v070" | "user-operation-v060";
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,11 +1,18 @@
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
- export declare const createAuthorization: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
4
+ import { PreparedCall_Authorization } from "../../schemas.js";
5
+ import type { Eip7702AuthCapability } from "../../capabilities/eip7702Auth.ts";
6
+ import type { Static } from "@sinclair/typebox";
7
+ export declare const createAuthorizationRequest: (client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: {
5
8
  address: Address;
6
9
  delegation: Address;
7
- }) => Promise<Authorization<number, false> | undefined>;
8
- type Supported7702AccountType = "ModularAccountV2";
9
- export declare const getAccountTypeForImplementationAddress7702: (address: Address) => Supported7702AccountType | undefined;
10
- export declare const isSupportedImplementationAddress7702: (address: string) => boolean;
10
+ }) => Promise<Static<typeof PreparedCall_Authorization> | undefined>;
11
+ export declare const EIP_7702_ACCOUNT_TYPE: readonly ["ModularAccountV2"];
12
+ type Supported7702AccountType = (typeof EIP_7702_ACCOUNT_TYPE)[number];
13
+ export declare const SUPPORTED_DELEGATION_ADDRESSES: "0x69007702764179f14F51cdce752f4f775d74E139"[];
14
+ export declare const isSupportedDelegationAddress7702: (address: Address) => boolean;
15
+ export declare const getAccountTypeForDelegationAddress7702: (address: Address) => Supported7702AccountType | undefined;
16
+ export declare const parseDelegation: (eip7702AuthCapability: Static<typeof Eip7702AuthCapability>) => "0x69007702764179f14F51cdce752f4f775d74E139";
17
+ export declare const assertValid7702AccountAddress: (fromAddress: Address, eip7702AuthCapability: Static<typeof Eip7702AuthCapability> | undefined) => void;
11
18
  export {};
@@ -1,26 +1,61 @@
1
- import { concatHex, } from "viem";
2
- export const createAuthorization = async (client, params) => {
1
+ import { concatHex, numberToHex, isAddress, } from "viem";
2
+ import { PreparedCall_Authorization } from "../../schemas.js";
3
+ import { InvalidRequestError } from "ox/RpcResponse";
4
+ export const createAuthorizationRequest = async (client, params) => {
3
5
  const expectedCode = concatHex(["0xef0100", params.delegation]);
4
6
  const code = (await client.getCode({ address: params.address })) ?? "0x";
5
7
  if (code.toLowerCase() === expectedCode.toLowerCase()) {
6
8
  return undefined; // Already authorized.
7
9
  }
8
- return {
9
- chainId: client.chain.id,
10
+ const data = {
10
11
  address: params.delegation,
11
- nonce: await client.getTransactionCount({
12
+ nonce: numberToHex(await client.getTransactionCount({
12
13
  address: params.address,
13
- }),
14
+ })),
15
+ };
16
+ return {
17
+ type: "authorization",
18
+ data,
19
+ chainId: numberToHex(client.chain.id),
20
+ signatureRequest: {
21
+ type: "eip7702Auth",
22
+ },
14
23
  };
15
24
  };
16
- const IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE = {
17
- "0x69007702764179f14F51cdce752f4f775d74E139": "ModularAccountV2",
25
+ export const EIP_7702_ACCOUNT_TYPE = ["ModularAccountV2"];
26
+ const Eip7702AccountTypeToDelegationAddress = {
27
+ ModularAccountV2: "0x69007702764179f14F51cdce752f4f775d74E139",
28
+ };
29
+ const DelegationAddressToAccountType = Object.fromEntries(Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
30
+ value,
31
+ key,
32
+ ]));
33
+ export const SUPPORTED_DELEGATION_ADDRESSES = Object.values(Eip7702AccountTypeToDelegationAddress);
34
+ export const isSupportedDelegationAddress7702 = (address) => {
35
+ return SUPPORTED_DELEGATION_ADDRESSES.includes(address);
18
36
  };
19
- export const getAccountTypeForImplementationAddress7702 = (address) => {
20
- return IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE[address];
37
+ export const getAccountTypeForDelegationAddress7702 = (address) => {
38
+ return DelegationAddressToAccountType[address];
21
39
  };
22
- const SUPPORTED_IMPLEMENTATION_ADDRESSES = Object.keys(IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE);
23
- export const isSupportedImplementationAddress7702 = (address) => {
24
- return SUPPORTED_IMPLEMENTATION_ADDRESSES.includes(address);
40
+ const getDelegationAddressForAccountType7702 = (accountType) => {
41
+ return Eip7702AccountTypeToDelegationAddress[accountType];
42
+ };
43
+ const DEFAULT_7702_DELEGATION_ADDR = Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
44
+ export const parseDelegation = (eip7702AuthCapability) => {
45
+ return eip7702AuthCapability === true
46
+ ? DEFAULT_7702_DELEGATION_ADDR
47
+ : isAddress(eip7702AuthCapability.delegation)
48
+ ? eip7702AuthCapability.delegation
49
+ : getDelegationAddressForAccountType7702(eip7702AuthCapability.delegation);
50
+ };
51
+ export const assertValid7702AccountAddress = (fromAddress, eip7702AuthCapability) => {
52
+ if (eip7702AuthCapability &&
53
+ typeof eip7702AuthCapability === "object" &&
54
+ "account" in eip7702AuthCapability &&
55
+ eip7702AuthCapability?.account !== fromAddress) {
56
+ throw new InvalidRequestError({
57
+ message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
58
+ });
59
+ }
25
60
  };
26
61
  //# sourceMappingURL=7702.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,GAKV,MAAM,MAAM,CAAC;AAGd,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAMC,EACD,MAAiD,EACE,EAAE;IACrD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;IACzE,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC,CAAC,sBAAsB;IAC1C,CAAC;IACD,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,EAAE,MAAM,CAAC,UAAU;QAC1B,KAAK,EAAE,MAAM,MAAM,CAAC,mBAAmB,CAAC;YACtC,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AAIF,MAAM,sCAAsC,GAGxC;IACF,4CAA4C,EAAE,kBAAkB;CACjE,CAAC;AAEF,MAAM,CAAC,MAAM,0CAA0C,GAAG,CACxD,OAAgB,EACsB,EAAE;IACxC,OAAO,sCAAsC,CAAC,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,kCAAkC,GAAG,MAAM,CAAC,IAAI,CACpD,sCAAsC,CACvC,CAAC;AAEF,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAClD,OAAe,EACN,EAAE;IACX,OAAO,kCAAkC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC","sourcesContent":["import type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n concatHex,\n type Authorization,\n type Address,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"../../rpc/schema.js\";\n\nexport const createAuthorization = async (\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: { address: Address; delegation: Address },\n): Promise<Authorization<number, false> | undefined> => {\n const expectedCode = concatHex([\"0xef0100\", params.delegation]);\n const code = (await client.getCode({ address: params.address })) ?? \"0x\";\n if (code.toLowerCase() === expectedCode.toLowerCase()) {\n return undefined; // Already authorized.\n }\n return {\n chainId: client.chain.id,\n address: params.delegation,\n nonce: await client.getTransactionCount({\n address: params.address,\n }),\n };\n};\n\ntype Supported7702AccountType = \"ModularAccountV2\";\n\nconst IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE: Record<\n Address,\n Supported7702AccountType\n> = {\n \"0x69007702764179f14F51cdce752f4f775d74E139\": \"ModularAccountV2\",\n};\n\nexport const getAccountTypeForImplementationAddress7702 = (\n address: Address,\n): Supported7702AccountType | undefined => {\n return IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE[address];\n};\n\nconst SUPPORTED_IMPLEMENTATION_ADDRESSES = Object.keys(\n IMPLEMENTATION_ADDRESS_TO_ACCOUNT_TYPE,\n);\n\nexport const isSupportedImplementationAddress7702 = (\n address: string,\n): boolean => {\n return SUPPORTED_IMPLEMENTATION_ADDRESSES.includes(address);\n};\n"]}
1
+ {"version":3,"file":"7702.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/7702.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,WAAW,EAIX,SAAS,GACV,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAC7C,MAMC,EACD,MAAiD,EACe,EAAE;IAClE,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;IACzE,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC,CAAC,sBAAsB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AChC,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"]}
@@ -2,16 +2,16 @@ import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
2
2
  import { type ModularAccountV2 } from "@account-kit/smart-contracts";
3
3
  import type { StaticDecode } from "@sinclair/typebox";
4
4
  import type { Address, Chain, Transport } from "viem";
5
- import type { Capabilities } from "../../capabilities/index.js";
6
5
  import type { TypeSerializedInitcode } from "../../schemas.js";
6
+ import { PermissionsCapability } from "../../capabilities/permissions/index.js";
7
7
  type CreateAccountParams = {
8
8
  chain: Chain;
9
9
  transport: Transport;
10
10
  signer: SmartAccountSigner;
11
11
  accountAddress: Address;
12
12
  counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>;
13
+ permissions?: StaticDecode<typeof PermissionsCapability>;
13
14
  delegation?: Address;
14
- capabilities?: StaticDecode<typeof Capabilities>;
15
15
  };
16
16
  /**
17
17
  * Creates a smart account instance from the given parameters.
@@ -2,8 +2,9 @@ import { createModularAccountV2, } from "@account-kit/smart-contracts";
2
2
  import { concatHex, hexToNumber } from "viem";
3
3
  import { parsePermissionsContext } from "./parsePermissionsContext.js";
4
4
  import { assertNever } from "../../utils.js";
5
- import { getAccountTypeForImplementationAddress7702 } from "./7702.js";
5
+ import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
6
6
  import { InternalError } from "ox/RpcResponse";
7
+ import { PermissionsCapability } from "../../capabilities/permissions/index.js";
7
8
  /**
8
9
  * Creates a smart account instance from the given parameters.
9
10
  * @param params - The parameters for creating a smart account.
@@ -25,7 +26,7 @@ export async function createAccount(params) {
25
26
  }
26
27
  }
27
28
  else if (mode === "7702") {
28
- const accountType = getAccountTypeForImplementationAddress7702(params.delegation);
29
+ const accountType = getAccountTypeForDelegationAddress7702(params.delegation);
29
30
  if (accountType !== "ModularAccountV2") {
30
31
  throw new InternalError({
31
32
  message: "7702 mode currently only supports ModularAccountV2",
@@ -35,7 +36,7 @@ export async function createAccount(params) {
35
36
  else {
36
37
  assertNever(mode, "Unexpected mode in createAccount");
37
38
  }
38
- const parsedContext = parsePermissionsContext(params.capabilities, ci, params.delegation);
39
+ const parsedContext = parsePermissionsContext(params.permissions, ci, params.delegation);
39
40
  const signerEntity = parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
40
41
  ? {
41
42
  entityId: hexToNumber(parsedContext.entityId),
@@ -1 +1 @@
1
- {"version":3,"file":"createAccount.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createAccount.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,GAEvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAG9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,0CAA0C,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAY/C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA2B;IAE3B,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC;IAE5D,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAEpD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,IAAI,CAAC,EAAE,EAAE,CAAC;Y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IAE7B,OAAO,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC/C,CAAC","sourcesContent":["import type { SmartAccountSigner, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n createModularAccountV2,\n type ModularAccountV2,\n} from \"@account-kit/smart-contracts\";\nimport type { StaticDecode } from \"@sinclair/typebox\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport { concatHex, hexToNumber } from \"viem\";\nimport type { Capabilities } from \"../../capabilities/index.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport { parsePermissionsContext } from \"./parsePermissionsContext.js\";\nimport { assertNever } from \"../../utils.js\";\nimport { getAccountTypeForImplementationAddress7702 } from \"./7702.js\";\nimport { InternalError } from \"ox/RpcResponse\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartAccountSigner;\n accountAddress: Address;\n counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts\n delegation?: Address;\n capabilities?: StaticDecode<typeof Capabilities>;\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n * @param params - The parameters for creating a smart account.\n * @returns A promise that resolves to the created smart account.\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, ...accountParams } = params;\n\n const mode = params.delegation ? \"7702\" : \"default\";\n\n if (mode === \"default\") {\n if (!ci) {\n throw new InternalError({\n message: \"Counterfactual info not found\",\n });\n }\n if (ci.factoryType !== \"MAv2.0.0-sma-b\") {\n throw new InternalError({\n message: `Factory type ${ci.factoryType} is not currently supported.`,\n });\n }\n } else if (mode === \"7702\") {\n const accountType = getAccountTypeForImplementationAddress7702(\n params.delegation!,\n );\n if (accountType !== \"ModularAccountV2\") {\n throw new InternalError({\n message: \"7702 mode currently only supports ModularAccountV2\",\n });\n }\n } else {\n assertNever(mode, \"Unexpected mode in createAccount\");\n }\n\n const parsedContext = parsePermissionsContext(\n params.capabilities,\n ci,\n params.delegation,\n );\n\n const signerEntity =\n parsedContext?.contextVersion === \"NON_DEFERRED_ACTION\"\n ? {\n entityId: hexToNumber(parsedContext.entityId),\n isGlobalValidation: parsedContext.isGlobalValidation,\n }\n : undefined;\n\n // TODO: clean this up to support different account types.\n return createModularAccountV2({\n ...accountParams,\n signerEntity,\n deferredAction: parsedContext?.deferredAction,\n initCode: ci ? concatHex([ci.factoryAddress, ci.factoryData]) : undefined,\n mode,\n });\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
1
+ {"version":3,"file":"createAccount.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/createAccount.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,GAEvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,sCAAsC,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAYhF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAA2B;IAE3B,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC;IAE5D,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAEpD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,MAAM,IAAI,aAAa,CAAC;gBACtB,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAC;QACL,CAAC;QACD,I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martContractAccount } from \"@aa-sdk/core\";\nimport {\n createModularAccountV2,\n type ModularAccountV2,\n} from \"@account-kit/smart-contracts\";\nimport type { StaticDecode } from \"@sinclair/typebox\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport { concatHex, hexToNumber } from \"viem\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport { parsePermissionsContext } from \"./parsePermissionsContext.js\";\nimport { assertNever } from \"../../utils.js\";\nimport { getAccountTypeForDelegationAddress7702 } from \"./7702.js\";\nimport { InternalError } from \"ox/RpcResponse\";\nimport { PermissionsCapability } from \"../../capabilities/permissions/index.js\";\n\ntype CreateAccountParams = {\n chain: Chain;\n transport: Transport;\n signer: SmartAccountSigner;\n accountAddress: Address;\n counterfactualInfo?: StaticDecode<typeof TypeSerializedInitcode>; // undefined for 7702 accounts\n permissions?: StaticDecode<typeof PermissionsCapability>;\n delegation?: Address;\n};\n\n/**\n * Creates a smart account instance from the given parameters.\n * @param params - The parameters for creating a smart account.\n * @returns A promise that resolves to the created smart account.\n */\nexport async function createAccount(\n params: CreateAccountParams,\n): Promise<SmartContractAccount> {\n const { counterfactualInfo: ci, ...accountParams } = params;\n\n const mode = params.delegation ? \"7702\" : \"default\";\n\n if (mode === \"default\") {\n if (!ci) {\n throw new InternalError({\n message: \"Counterfactual info not found\",\n });\n }\n if (ci.factoryType !== \"MAv2.0.0-sma-b\") {\n throw new InternalError({\n message: `Factory type ${ci.factoryType} is not currently supported.`,\n });\n }\n } else if (mode === \"7702\") {\n const accountType = getAccountTypeForDelegationAddress7702(\n params.delegation!,\n );\n if (accountType !== \"ModularAccountV2\") {\n throw new InternalError({\n message: \"7702 mode currently only supports ModularAccountV2\",\n });\n }\n } else {\n assertNever(mode, \"Unexpected mode in createAccount\");\n }\n\n const parsedContext = parsePermissionsContext(\n params.permissions,\n ci,\n params.delegation,\n );\n\n const signerEntity =\n parsedContext?.contextVersion === \"NON_DEFERRED_ACTION\"\n ? {\n entityId: hexToNumber(parsedContext.entityId),\n isGlobalValidation: parsedContext.isGlobalValidation,\n }\n : undefined;\n\n // TODO: clean this up to support different account types.\n return createModularAccountV2({\n ...accountParams,\n signerEntity,\n deferredAction: parsedContext?.deferredAction,\n initCode: ci ? concatHex([ci.factoryAddress, ci.factoryData]) : undefined,\n mode,\n });\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
@@ -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"]}
@@ -1,8 +1,8 @@
1
1
  import type { StaticDecode } from "@sinclair/typebox";
2
2
  import type { TypeSerializedInitcode } from "../../schemas.js";
3
- import type { PrepareCallsParams } from "../actions/prepareCalls.js";
4
3
  import type { Address } from "viem";
5
- export declare function parsePermissionsContext(capabilities: PrepareCallsParams["capabilities"], parsedCi: StaticDecode<typeof TypeSerializedInitcode> | undefined, delegation7702?: Address): ({
4
+ import { PermissionsCapability } from "../../capabilities/permissions/index.js";
5
+ export declare function parsePermissionsContext(permissions?: StaticDecode<typeof PermissionsCapability>, parsedCi?: StaticDecode<typeof TypeSerializedInitcode> | undefined, delegation7702?: Address): ({
6
6
  contextVersion: keyof typeof import("../../exports/internal.js").PermissionsContextVersion;
7
7
  } & {
8
8
  contextVersion: "LOCAL_MODE_DEFERRED_ACTION";
@@ -1,28 +1,29 @@
1
1
  import { InvalidRequestError } from "ox/RpcResponse";
2
2
  import { decodePermissionsContext } from "../../capabilities/permissions/mav2.js";
3
- import { getAccountTypeForImplementationAddress7702 } from "./7702.js";
4
- export function parsePermissionsContext(capabilities, parsedCi, delegation7702) {
5
- if (!capabilities?.permissions) {
3
+ import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
4
+ import { PermissionsCapability } from "../../capabilities/permissions/index.js";
5
+ export function parsePermissionsContext(permissions, parsedCi, delegation7702) {
6
+ if (!permissions) {
6
7
  return undefined;
7
8
  }
8
- if ("sessionId" in capabilities.permissions) {
9
+ if ("sessionId" in permissions) {
9
10
  throw new InvalidRequestError({
10
11
  message: "Remote permissions are not supported in isomorphic client",
11
12
  });
12
13
  }
13
- if (!("context" in capabilities.permissions)) {
14
+ if (!("context" in permissions)) {
14
15
  return undefined;
15
16
  }
16
17
  const isMAV2 = (parsedCi && parsedCi.factoryType === "MAv2.0.0-sma-b") ||
17
18
  (delegation7702 &&
18
- getAccountTypeForImplementationAddress7702(delegation7702) ===
19
+ getAccountTypeForDelegationAddress7702(delegation7702) ===
19
20
  "ModularAccountV2");
20
21
  if (!isMAV2) {
21
22
  throw new InvalidRequestError({
22
23
  message: "Permissions are currently only supported by MAv2 accounts",
23
24
  });
24
25
  }
25
- const context = decodePermissionsContext(capabilities.permissions);
26
+ const context = decodePermissionsContext(permissions);
26
27
  if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
27
28
  throw new InvalidRequestError({
28
29
  message: "Remote mode deferred action not supported in isomorphic client",
@@ -1 +1 @@
1
- {"version":3,"file":"parsePermissionsContext.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/parsePermissionsContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAIlF,OAAO,EAAE,0CAA0C,EAAE,MAAM,WAAW,CAAC;AAEvE,MAAM,UAAU,uBAAuB,CACrC,YAAgD,EAChD,QAAiE,EACjE,cAAwB;IAExB,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,CAAC,SAAS,IAAI,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GACV,CAAC,QAAQ,IAAI,QAAQ,CAAC,WAAW,KAAK,gBAAgB,CAAC;QACvD,CAAC,cAAc;YACb,0CAA0C,CAAC,cAAc,CAAC;gBACxD,kBAAkB,CAAC,CAAC;IAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,wBAAwB,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAEnE,IAAI,OAAO,EAAE,cAAc,KAAK,6BAA6B,EAAE,CAAC;QAC9D,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,gEAAgE;SAC1E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { StaticDecode } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport type { PrepareCallsParams } from \"../actions/prepareCalls.js\";\nimport type { Address } from \"viem\";\nimport { getAccountTypeForImplementationAddress7702 } from \"./7702.js\";\n\nexport function parsePermissionsContext(\n capabilities: PrepareCallsParams[\"capabilities\"],\n parsedCi: StaticDecode<typeof TypeSerializedInitcode> | undefined,\n delegation7702?: Address,\n) {\n if (!capabilities?.permissions) {\n return undefined;\n }\n\n if (\"sessionId\" in capabilities.permissions) {\n throw new InvalidRequestError({\n message: \"Remote permissions are not supported in isomorphic client\",\n });\n }\n\n if (!(\"context\" in capabilities.permissions)) {\n return undefined;\n }\n\n const isMAV2 =\n (parsedCi && parsedCi.factoryType === \"MAv2.0.0-sma-b\") ||\n (delegation7702 &&\n getAccountTypeForImplementationAddress7702(delegation7702) ===\n \"ModularAccountV2\");\n\n if (!isMAV2) {\n throw new InvalidRequestError({\n message: \"Permissions are currently only supported by MAv2 accounts\",\n });\n }\n\n const context = decodePermissionsContext(capabilities.permissions);\n\n if (context?.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message: \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return context;\n}\n"]}
1
+ {"version":3,"file":"parsePermissionsContext.js","sourceRoot":"","sources":["../../../../src/isomorphic/utils/parsePermissionsContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,sCAAsC,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAEhF,MAAM,UAAU,uBAAuB,CACrC,WAAwD,EACxD,QAAkE,EAClE,cAAwB;IAExB,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,WAAW,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,CAAC,SAAS,IAAI,WAAW,CAAC,EAAE,CAAC;QAChC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GACV,CAAC,QAAQ,IAAI,QAAQ,CAAC,WAAW,KAAK,gBAAgB,CAAC;QACvD,CAAC,cAAc;YACb,sCAAsC,CAAC,cAAc,CAAC;gBACpD,kBAAkB,CAAC,CAAC;IAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,2DAA2D;SACrE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IAEtD,IAAI,OAAO,EAAE,cAAc,KAAK,6BAA6B,EAAE,CAAC;QAC9D,MAAM,IAAI,mBAAmB,CAAC;YAC5B,OAAO,EAAE,gEAAgE;SAC1E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { StaticDecode } from \"@sinclair/typebox\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport { decodePermissionsContext } from \"../../capabilities/permissions/mav2.js\";\nimport type { TypeSerializedInitcode } from \"../../schemas.js\";\nimport type { Address } from \"viem\";\nimport { getAccountTypeForDelegationAddress7702 } from \"./7702.js\";\nimport { PermissionsCapability } from \"../../capabilities/permissions/index.js\";\n\nexport function parsePermissionsContext(\n permissions?: StaticDecode<typeof PermissionsCapability>,\n parsedCi?: StaticDecode<typeof TypeSerializedInitcode> | undefined,\n delegation7702?: Address,\n) {\n if (!permissions) {\n return undefined;\n }\n\n if (\"sessionId\" in permissions) {\n throw new InvalidRequestError({\n message: \"Remote permissions are not supported in isomorphic client\",\n });\n }\n\n if (!(\"context\" in permissions)) {\n return undefined;\n }\n\n const isMAV2 =\n (parsedCi && parsedCi.factoryType === \"MAv2.0.0-sma-b\") ||\n (delegation7702 &&\n getAccountTypeForDelegationAddress7702(delegation7702) ===\n \"ModularAccountV2\");\n\n if (!isMAV2) {\n throw new InvalidRequestError({\n message: \"Permissions are currently only supported by MAv2 accounts\",\n });\n }\n\n const context = decodePermissionsContext(permissions);\n\n if (context?.contextVersion === \"REMOTE_MODE_DEFERRED_ACTION\") {\n throw new InvalidRequestError({\n message: \"Remote mode deferred action not supported in isomorphic client\",\n });\n }\n\n return context;\n}\n"]}
@@ -1,3 +1,3 @@
1
- import { type Address, type JsonRpcAccount } from "viem";
1
+ import { type Address } from "viem";
2
2
  import type { CreateInnerClientParams, InnerWalletApiClient } from "../types.ts";
3
- export declare function createLocalClient<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient<TAccount>;
3
+ export declare function createLocalClient<TAccount extends Address | undefined = Address | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
@@ -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
  };
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/local/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,EAAqC,MAAM,MAAM,CAAC;AAC/E,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EACL,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa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AC;YACF,OAAO;gBACL,OAAO,EAAE,wBAAwB,CAAC;oBAChC,cAAc,EAAE,4BAA4B;oBAC5C,cAAc,EAAE,yBAAyB,CAAC;wBACxC,oCAAoC;wBACpC,GAAG,EAAE,sBAAsB,CAAC,SAAS,EAAE,WAAW,CAAC;qBACpD,CAAC;iBACH,CAAC;gBACF,mBAAmB;aACpB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { split } from \"@aa-sdk/core\";\nimport { buildDeferredActionDigest } from \"@account-kit/smart-contracts/experimental\";\nimport { createClient, custom, type Address, type JsonRpcAccount } from \"viem\";\nimport {\n encodePermissionsContext,\n prefixSignatureKeyType,\n} from \"../capabilities/permissions/mav2.js\";\nimport { signSignatureRequest } from \"../client/actions/signSignatureRequest.js\";\nimport { internalStateDecorator } from \"../internal/decorator.js\";\nimport type { PrepareCallsParams } from \"../isomorphic/actions/prepareCalls.ts\";\nimport {\n createIsomorphicClient,\n type IsomorphicClient,\n} from \"../isomorphic/client.js\";\nimport type {\n CreateInnerClientParams,\n InnerClientActions,\n InnerWalletApiClient,\n} from \"../types.ts\";\nimport { assertNever } from \"../utils.js\";\n\nconst localMethods = [\n \"wallet_prepareCalls\",\n \"wallet_sendPreparedCalls\",\n \"wallet_getCallsStatus\",\n \"wallet_createSession\",\n] as const satisfies string[];\ntype LocalMethod = (typeof localMethods)[number];\n\nexport function createLocalClient<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient<TAccount>;\n\nexport function createLocalClient(\n params: CreateInnerClientParams,\n): InnerWalletApiClient {\n const { chain, transport, policyId, account } = params;\n const isomorphicClient = createIsomorphicClient({\n transport,\n chain,\n policyId,\n useErc7677middleware: false,\n });\n\n const clientMap: Record<string, ReturnType<typeof createIsomorphicClient>> = {\n [policyId ?? \"default\"]: isomorphicClient,\n };\n\n const innerTransport = split({\n overrides: [\n {\n methods: localMethods,\n transport: custom(\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async request(args: { method: LocalMethod; params: any }) {\n switch (args.method) {\n case \"wallet_prepareCalls\": {\n const params = args.params[0] as PrepareCallsParams;\n const capabilityPolicyId =\n params.capabilities?.paymasterService?.policyId;\n\n if (\n capabilityPolicyId != null &&\n policyId !== capabilityPolicyId &&\n !clientMap[capabilityPolicyId]\n ) {\n clientMap[capabilityPolicyId] = createIsomorphicClient({\n transport,\n chain,\n policyId: capabilityPolicyId,\n });\n }\n\n const client =\n clientMap[capabilityPolicyId ?? policyId ?? \"default\"];\n return client.prepareCalls(params);\n }\n case \"wallet_sendPreparedCalls\":\n return isomorphicClient.sendPreparedCalls(args.params[0]);\n case \"wallet_getCallsStatus\":\n return isomorphicClient.getCallsStatus(args.params[0]);\n case \"wallet_createSession\": {\n return isomorphicClient.createSession(args.params[0]);\n }\n default:\n return assertNever(\n args.method,\n `Unexpected method: ${args.method}`,\n );\n }\n },\n },\n {\n retryCount: 0,\n },\n ),\n },\n ],\n fallback: transport,\n });\n\n return createClient({\n transport: innerTransport,\n chain,\n account,\n })\n .extend(() => ({\n policyId,\n ...innerClientActions(isomorphicClient),\n }))\n .extend(() => ({\n internal: internalStateDecorator(),\n }));\n}\n\nconst innerClientActions = (\n isomorphicClient: IsomorphicClient,\n): InnerClientActions => {\n return {\n grantPermissions: async (signer, params) => {\n const { signatureRequest, fullPreSignatureDeferredActionDigest } =\n await isomorphicClient.createSession(params);\n const { signedAuthorization, signature } = await signSignatureRequest(\n signer,\n signatureRequest,\n );\n return {\n context: encodePermissionsContext({\n contextVersion: \"LOCAL_MODE_DEFERRED_ACTION\",\n deferredAction: buildDeferredActionDigest({\n fullPreSignatureDeferredActionDigest,\n sig: prefixSignatureKeyType(signature, \"secp256k1\"),\n }),\n }),\n signedAuthorization,\n };\n },\n };\n};\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/local/client.ts"],"names":[],"mappings":"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MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACb,QAAQ,EAAE,sBAAsB,EAAE;KACnC,CAAC,CAAC,CAAC;AACR,CAAC;AAED,MAAM,kBAAkB,GAAG,CACzB,gBAAkC,EACd,EAAE;IACtB,OAAO;QACL,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACzC,MAAM,EAAE,gBAAgB,EAAE,oCAAoC,EAAE,GAC9D,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YAC/C,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACvE,OAAO;gBACL,OAAO,EAAE,wBAAwB,CAAC;oBAChC,cAAc,EAAE,4BAA4B;oBAC5C,cAAc,EAAE,yBAAyB,CAAC;wBACxC,oCAAoC;wBACpC,GAAG,EAAE,sBAAsB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC;qBAC5D,CAAC;iBACH,CAAC;aACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { split } from \"@aa-sdk/core\";\nimport { buildDeferredActionDigest } from \"@account-kit/smart-contracts/experimental\";\nimport { createClient, custom, type Address } from \"viem\";\nimport {\n encodePermissionsContext,\n prefixSignatureKeyType,\n} from \"../capabilities/permissions/mav2.js\";\nimport { signSignatureRequest } from \"../client/actions/signSignatureRequest.js\";\nimport { internalStateDecorator } from \"../internal/decorator.js\";\nimport type { PrepareCallsParams } from \"../isomorphic/actions/prepareCalls.ts\";\nimport {\n createIsomorphicClient,\n type IsomorphicClient,\n} from \"../isomorphic/client.js\";\nimport type {\n CreateInnerClientParams,\n InnerClientActions,\n InnerWalletApiClient,\n} from \"../types.ts\";\nimport { assertNever } from \"../utils.js\";\n\nconst localMethods = [\n \"wallet_prepareCalls\",\n \"wallet_sendPreparedCalls\",\n \"wallet_getCallsStatus\",\n \"wallet_createSession\",\n] as const satisfies string[];\ntype LocalMethod = (typeof localMethods)[number];\n\nexport function createLocalClient<\n TAccount extends Address | undefined = Address | undefined,\n>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;\n\nexport function createLocalClient(\n params: CreateInnerClientParams,\n): InnerWalletApiClient {\n const { chain, transport, policyId, account } = params;\n const isomorphicClient = createIsomorphicClient({\n transport,\n chain,\n policyId,\n useErc7677middleware: false,\n });\n\n const clientMap: Record<string, ReturnType<typeof createIsomorphicClient>> = {\n [policyId ?? \"default\"]: isomorphicClient,\n };\n\n const innerTransport = split({\n overrides: [\n {\n methods: localMethods,\n transport: custom(\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async request(args: { method: LocalMethod; params: any }) {\n switch (args.method) {\n case \"wallet_prepareCalls\": {\n const params = args.params[0] as PrepareCallsParams;\n const capabilityPolicyId =\n params.capabilities?.paymasterService?.policyId;\n\n if (\n capabilityPolicyId != null &&\n policyId !== capabilityPolicyId &&\n !clientMap[capabilityPolicyId]\n ) {\n clientMap[capabilityPolicyId] = createIsomorphicClient({\n transport,\n chain,\n policyId: capabilityPolicyId,\n });\n }\n\n const client =\n clientMap[capabilityPolicyId ?? policyId ?? \"default\"];\n return client.prepareCalls(params);\n }\n case \"wallet_sendPreparedCalls\":\n return isomorphicClient.sendPreparedCalls(args.params[0]);\n case \"wallet_getCallsStatus\":\n return isomorphicClient.getCallsStatus(args.params[0]);\n case \"wallet_createSession\": {\n return isomorphicClient.createSession(args.params[0]);\n }\n default:\n return assertNever(\n args.method,\n `Unexpected method: ${args.method}`,\n );\n }\n },\n },\n {\n retryCount: 0,\n },\n ),\n },\n ],\n fallback: transport,\n });\n\n return createClient({\n transport: innerTransport,\n chain,\n account,\n })\n .extend(() => ({\n policyId,\n ...innerClientActions(isomorphicClient),\n }))\n .extend(() => ({\n internal: internalStateDecorator(),\n }));\n}\n\nconst innerClientActions = (\n isomorphicClient: IsomorphicClient,\n): InnerClientActions => {\n return {\n grantPermissions: async (signer, params) => {\n const { signatureRequest, fullPreSignatureDeferredActionDigest } =\n await isomorphicClient.createSession(params);\n const signature = await signSignatureRequest(signer, signatureRequest);\n return {\n context: encodePermissionsContext({\n contextVersion: \"LOCAL_MODE_DEFERRED_ACTION\",\n deferredAction: buildDeferredActionDigest({\n fullPreSignatureDeferredActionDigest,\n sig: prefixSignatureKeyType(signature.data, signature.type),\n }),\n }),\n };\n },\n };\n};\n"]}
@@ -1,3 +1,9 @@
1
- import { type Address, type JsonRpcAccount } from "viem";
1
+ import { type Address } from "viem";
2
2
  import type { CreateInnerClientParams, InnerWalletApiClient } from "../types.ts";
3
- export declare function createRemoteClient<TAccount extends JsonRpcAccount<Address> | undefined = JsonRpcAccount<Address> | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient<TAccount>;
3
+ /**
4
+ * This is a low-level client just used to make RPC requests in remote mode
5
+ * This should be wrapped by a higher-level smart account client that provides actions
6
+ * that uses this client under the hood
7
+ * @returns
8
+ */
9
+ export declare function createRemoteClient<TAccount extends Address | undefined = Address | undefined>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
@@ -1,15 +1,9 @@
1
1
  import { Provider } from "ox";
2
- import { BaseError, createClient, custom, } from "viem";
2
+ import { createClient, custom } from "viem";
3
3
  import { encodePermissionsContext } from "../capabilities/permissions/mav2.js";
4
4
  import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
5
5
  import { internalStateDecorator } from "../internal/decorator.js";
6
6
  import { WalletServerRpcSchema } from "../rpc/schema.js";
7
- /**
8
- * This is a low-level client just used to make RPC requests in remote mode
9
- * This should be wrapped by a higher-level smart account client that provides actions
10
- * that uses this client under the hood
11
- * @returns
12
- */
13
7
  export function createRemoteClient(params) {
14
8
  const { transport, chain, account } = params;
15
9
  const client = createClient({
@@ -33,17 +27,13 @@ const innerClientActions = (apiClient) => {
33
27
  method: "wallet_createSession",
34
28
  params: [params],
35
29
  });
36
- if (signatureRequest.type !== "eth_signTypedData_v4") {
37
- throw new BaseError("Unexpected signature request type");
38
- }
39
- const { signedAuthorization, signature } = await signSignatureRequest(signer, signatureRequest);
30
+ const signature = await signSignatureRequest(signer, signatureRequest);
40
31
  return {
41
32
  context: encodePermissionsContext({
42
33
  contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
43
34
  sessionId,
44
- signature,
35
+ signature: signature.data,
45
36
  }),
46
- signedAuthorization,
47
37
  };
48
38
  },
49
39
  };
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/remote/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,YAAY,EACZ,MAAM,GAGP,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAczD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAA+B;IAE/B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE7C,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAClB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAAC,CACvE,IAAI,CACL;QACH,KAAK;QACL,OAAO;KACR,CAAC;SACC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,GAAG,kBAAkB,CAAC,OAAO,CAAC;KAC/B,CAAC,CAAC;SACF,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACb,QAAQ,EAAE,sBAAsB,EAAE;KACnC,CAAC,CAAC,CAAC;IAEN,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,kBAAkB,GAAG,CACzB,SAAmC,EACf,EAAE;IACtB,OAAO;QACL,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACzC,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC;gBAC9D,MAAM,EAAE,sBAAsB;gBAC9B,MAAM,EAAE,CAAC,MAAM,CAAC;aACjB,CAAC,CAAC;YACH,IAAI,gBAAgB,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;gBACrD,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;YAC3D,CAAC;YACD,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,MAAM,oBAAoB,CACnE,MAAM,EACN,gBAAgB,CACjB,CAAC;YACF,OAAO;gBACL,OAAO,EAAE,wBAAwB,CAAC;oBAChC,cAAc,EAAE,6BAA6B;oBAC7C,SAAS;oBACT,SAAS;iBACV,CAAC;gBACF,mBAAmB;aACpB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Provider } from \"ox\";\nimport {\n BaseError,\n createClient,\n custom,\n type Address,\n type JsonRpcAccount,\n} from \"viem\";\nimport { encodePermissionsContext } from \"../capabilities/permissions/mav2.js\";\nimport { signSignatureRequest } from \"../client/actions/signSignatureRequest.js\";\nimport { internalStateDecorator } from \"../internal/decorator.js\";\nimport { WalletServerRpcSchema } from \"../rpc/schema.js\";\nimport type {\n CreateInnerClientParams,\n InnerClientActions,\n InnerWalletApiClient,\n InnerWalletApiClientBase,\n} from \"../types.ts\";\n\nexport function createRemoteClient<\n TAccount extends JsonRpcAccount<Address> | undefined =\n | JsonRpcAccount<Address>\n | undefined,\n>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient<TAccount>;\n\n/**\n * This is a low-level client just used to make RPC requests in remote mode\n * This should be wrapped by a higher-level smart account client that provides actions\n * that uses this client under the hood\n * @returns\n */\nexport function createRemoteClient(\n params: CreateInnerClientParams,\n): InnerWalletApiClient {\n const { transport, chain, account } = params;\n\n const client = createClient({\n transport: (opts) =>\n custom(Provider.from(transport(opts), { schema: WalletServerRpcSchema }))(\n opts,\n ),\n chain,\n account,\n })\n .extend((_client) => ({\n policyId: params.policyId,\n ...innerClientActions(_client),\n }))\n .extend(() => ({\n internal: internalStateDecorator(),\n }));\n\n return client;\n}\n\nconst innerClientActions = (\n apiClient: InnerWalletApiClientBase,\n): InnerClientActions => {\n return {\n grantPermissions: async (signer, params) => {\n const { sessionId, signatureRequest } = await apiClient.request({\n method: \"wallet_createSession\",\n params: [params],\n });\n if (signatureRequest.type !== \"eth_signTypedData_v4\") {\n throw new BaseError(\"Unexpected signature request type\");\n }\n const { signedAuthorization, signature } = await signSignatureRequest(\n signer,\n signatureRequest,\n );\n return {\n context: encodePermissionsContext({\n contextVersion: \"REMOTE_MODE_DEFERRED_ACTION\",\n sessionId,\n signature,\n }),\n signedAuthorization,\n };\n },\n };\n};\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/remote/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,EAAgB,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAkBzD,MAAM,UAAU,kBAAkB,CAChC,MAA+B;IAE/B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE7C,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAClB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAAC,CACvE,IAAI,CACL;QACH,KAAK;QACL,OAAO;KACR,CAAC;SACC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,GAAG,kBAAkB,CAAC,OAAO,CAAC;KAC/B,CAAC,CAAC;SACF,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACb,QAAQ,EAAE,sBAAsB,EAAE;KACnC,CAAC,CAAC,CAAC;IAEN,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,kBAAkB,GAAG,CACzB,SAAmC,EACf,EAAE;IACtB,OAAO;QACL,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACzC,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC;gBAC9D,MAAM,EAAE,sBAAsB;gBAC9B,MAAM,EAAE,CAAC,MAAM,CAAC;aACjB,CAAC,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACvE,OAAO;gBACL,OAAO,EAAE,wBAAwB,CAAC;oBAChC,cAAc,EAAE,6BAA6B;oBAC7C,SAAS;oBACT,SAAS,EAAE,SAAS,CAAC,IAAI;iBAC1B,CAAC;aACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Provider } from \"ox\";\nimport { createClient, custom, type Address } from \"viem\";\nimport { encodePermissionsContext } from \"../capabilities/permissions/mav2.js\";\nimport { signSignatureRequest } from \"../client/actions/signSignatureRequest.js\";\nimport { internalStateDecorator } from \"../internal/decorator.js\";\nimport { WalletServerRpcSchema } from \"../rpc/schema.js\";\nimport type {\n CreateInnerClientParams,\n InnerClientActions,\n InnerWalletApiClient,\n InnerWalletApiClientBase,\n} from \"../types.ts\";\n\n/**\n * This is a low-level client just used to make RPC requests in remote mode\n * This should be wrapped by a higher-level smart account client that provides actions\n * that uses this client under the hood\n * @returns\n */\nexport function createRemoteClient<\n TAccount extends Address | undefined = Address | undefined,\n>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;\n\nexport function createRemoteClient(\n params: CreateInnerClientParams,\n): InnerWalletApiClient {\n const { transport, chain, account } = params;\n\n const client = createClient({\n transport: (opts) =>\n custom(Provider.from(transport(opts), { schema: WalletServerRpcSchema }))(\n opts,\n ),\n chain,\n account,\n })\n .extend((_client) => ({\n policyId: params.policyId,\n ...innerClientActions(_client),\n }))\n .extend(() => ({\n internal: internalStateDecorator(),\n }));\n\n return client;\n}\n\nconst innerClientActions = (\n apiClient: InnerWalletApiClientBase,\n): InnerClientActions => {\n return {\n grantPermissions: async (signer, params) => {\n const { sessionId, signatureRequest } = await apiClient.request({\n method: \"wallet_createSession\",\n params: [params],\n });\n const signature = await signSignatureRequest(signer, signatureRequest);\n return {\n context: encodePermissionsContext({\n contextVersion: \"REMOTE_MODE_DEFERRED_ACTION\",\n sessionId,\n signature: signature.data,\n }),\n };\n },\n };\n};\n"]}