@account-kit/wallet-client 0.1.0-alpha.11 → 0.1.0-alpha.12

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 (141) hide show
  1. package/dist/esm/client/actions/getCallsStatus.d.ts +4 -3
  2. package/dist/esm/client/actions/getCallsStatus.js +1 -0
  3. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  4. package/dist/esm/client/actions/grantPermissions.d.ts +5 -4
  5. package/dist/esm/client/actions/grantPermissions.js +21 -5
  6. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  7. package/dist/esm/client/actions/prepareCalls.d.ts +4 -3
  8. package/dist/esm/client/actions/prepareCalls.js +1 -0
  9. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  10. package/dist/esm/client/actions/prepareSign.d.ts +4 -3
  11. package/dist/esm/client/actions/prepareSign.js +1 -0
  12. package/dist/esm/client/actions/prepareSign.js.map +1 -1
  13. package/dist/esm/client/actions/requestAccount.js +1 -1
  14. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  15. package/dist/esm/client/client.e2e-test.js +171 -349
  16. package/dist/esm/client/client.e2e-test.js.map +1 -1
  17. package/dist/esm/client/index.d.ts +1 -4
  18. package/dist/esm/client/index.js +13 -18
  19. package/dist/esm/client/index.js.map +1 -1
  20. package/dist/esm/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +1 -5
  21. package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +8 -32
  22. package/dist/esm/internal/account.js.map +1 -0
  23. package/dist/esm/types.d.ts +2 -8
  24. package/dist/esm/types.js.map +1 -1
  25. package/dist/types/client/actions/getCallsStatus.d.ts +4 -3
  26. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  27. package/dist/types/client/actions/grantPermissions.d.ts +5 -4
  28. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  29. package/dist/types/client/actions/prepareCalls.d.ts +4 -3
  30. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  31. package/dist/types/client/actions/prepareSign.d.ts +4 -3
  32. package/dist/types/client/actions/prepareSign.d.ts.map +1 -1
  33. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  34. package/dist/types/client/index.d.ts +1 -4
  35. package/dist/types/client/index.d.ts.map +1 -1
  36. package/dist/types/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +2 -6
  37. package/dist/types/internal/account.d.ts.map +1 -0
  38. package/dist/types/types.d.ts +2 -8
  39. package/dist/types/types.d.ts.map +1 -1
  40. package/package.json +3 -8
  41. package/src/client/actions/getCallsStatus.ts +8 -6
  42. package/src/client/actions/grantPermissions.ts +41 -10
  43. package/src/client/actions/prepareCalls.ts +11 -6
  44. package/src/client/actions/prepareSign.ts +9 -6
  45. package/src/client/actions/requestAccount.ts +1 -1
  46. package/src/client/client.e2e-test.ts +208 -442
  47. package/src/client/index.ts +22 -23
  48. package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +9 -49
  49. package/src/types.ts +4 -15
  50. package/dist/esm/exports/internal.d.ts +0 -4
  51. package/dist/esm/exports/internal.js +0 -3
  52. package/dist/esm/exports/internal.js.map +0 -1
  53. package/dist/esm/isomorphic/actions/createSession.d.ts +0 -13
  54. package/dist/esm/isomorphic/actions/createSession.js +0 -94
  55. package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
  56. package/dist/esm/isomorphic/actions/formatSign.d.ts +0 -8
  57. package/dist/esm/isomorphic/actions/formatSign.js +0 -42
  58. package/dist/esm/isomorphic/actions/formatSign.js.map +0 -1
  59. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -7
  60. package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -71
  61. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
  62. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -7
  63. package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
  64. package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
  65. package/dist/esm/isomorphic/actions/prepareSign.d.ts +0 -7
  66. package/dist/esm/isomorphic/actions/prepareSign.js +0 -49
  67. package/dist/esm/isomorphic/actions/prepareSign.js.map +0 -1
  68. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -7
  69. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -183
  70. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
  71. package/dist/esm/isomorphic/client.d.ts +0 -275
  72. package/dist/esm/isomorphic/client.js +0 -41
  73. package/dist/esm/isomorphic/client.js.map +0 -1
  74. package/dist/esm/isomorphic/utils/7702.d.ts +0 -19
  75. package/dist/esm/isomorphic/utils/7702.js +0 -70
  76. package/dist/esm/isomorphic/utils/7702.js.map +0 -1
  77. package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
  78. package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
  79. package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
  80. package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
  81. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
  82. package/dist/esm/isomorphic/utils/decodeSignature.js +0 -15
  83. package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
  84. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
  85. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
  86. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
  87. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
  88. package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
  89. package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
  90. package/dist/esm/local/client.d.ts +0 -3
  91. package/dist/esm/local/client.js +0 -97
  92. package/dist/esm/local/client.js.map +0 -1
  93. package/dist/esm/remote/client.d.ts +0 -9
  94. package/dist/esm/remote/client.js +0 -41
  95. package/dist/esm/remote/client.js.map +0 -1
  96. package/dist/types/exports/internal.d.ts +0 -5
  97. package/dist/types/exports/internal.d.ts.map +0 -1
  98. package/dist/types/isomorphic/actions/createSession.d.ts +0 -14
  99. package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
  100. package/dist/types/isomorphic/actions/formatSign.d.ts +0 -9
  101. package/dist/types/isomorphic/actions/formatSign.d.ts.map +0 -1
  102. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -8
  103. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
  104. package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -8
  105. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
  106. package/dist/types/isomorphic/actions/prepareSign.d.ts +0 -8
  107. package/dist/types/isomorphic/actions/prepareSign.d.ts.map +0 -1
  108. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
  109. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
  110. package/dist/types/isomorphic/client.d.ts +0 -276
  111. package/dist/types/isomorphic/client.d.ts.map +0 -1
  112. package/dist/types/isomorphic/utils/7702.d.ts +0 -20
  113. package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
  114. package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
  115. package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
  116. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
  117. package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
  118. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
  119. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
  120. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
  121. package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
  122. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
  123. package/dist/types/local/client.d.ts +0 -4
  124. package/dist/types/local/client.d.ts.map +0 -1
  125. package/dist/types/remote/client.d.ts +0 -10
  126. package/dist/types/remote/client.d.ts.map +0 -1
  127. package/src/exports/internal.ts +0 -8
  128. package/src/isomorphic/actions/createSession.ts +0 -163
  129. package/src/isomorphic/actions/formatSign.ts +0 -76
  130. package/src/isomorphic/actions/getCallsStatus.ts +0 -112
  131. package/src/isomorphic/actions/prepareCalls.ts +0 -172
  132. package/src/isomorphic/actions/prepareSign.ts +0 -88
  133. package/src/isomorphic/actions/sendPreparedCalls.ts +0 -271
  134. package/src/isomorphic/client.ts +0 -102
  135. package/src/isomorphic/utils/7702.ts +0 -135
  136. package/src/isomorphic/utils/createDummySigner.ts +0 -27
  137. package/src/isomorphic/utils/decodeSignature.ts +0 -21
  138. package/src/isomorphic/utils/parsePermissionsContext.ts +0 -51
  139. package/src/isomorphic/utils/supportsFeature.ts +0 -34
  140. package/src/local/client.ts +0 -136
  141. package/src/remote/client.ts +0 -67
@@ -1,13 +1,20 @@
1
1
  import type { SmartAccountSigner } from "@aa-sdk/core";
2
2
  import type { AlchemyTransport } from "@account-kit/infra";
3
- import type { Address, Chain, Prettify } from "viem";
4
- import { createLocalClient } from "../local/client.js";
5
- import { createRemoteClient } from "../remote/client.js";
3
+ import {
4
+ type Address,
5
+ type Chain,
6
+ type Prettify,
7
+ createClient,
8
+ custom,
9
+ } from "viem";
6
10
  import type { InnerWalletApiClient } from "../types.ts";
7
11
  import {
8
12
  smartWalletClientActions,
9
13
  type SmartWalletActions,
10
14
  } from "./decorator.js";
15
+ import { Provider } from "ox";
16
+ import { WalletServerRpcSchema } from "@alchemy/wallet-api-types/rpc";
17
+ import { internalStateDecorator } from "../internal/decorator.js";
11
18
 
12
19
  export type SmartWalletClientParams<
13
20
  TAccount extends Address | undefined = Address | undefined,
@@ -15,7 +22,6 @@ export type SmartWalletClientParams<
15
22
  transport: AlchemyTransport;
16
23
  chain: Chain;
17
24
  signer: SmartAccountSigner;
18
- mode: "local" | "remote";
19
25
  policyId?: string;
20
26
  account?: TAccount | Address | undefined;
21
27
  }>;
@@ -31,7 +37,6 @@ export type SmartWalletClient<
31
37
  * @param {AlchemyTransport} params.transport - The Alchemy transport to use
32
38
  * @param {Chain} params.chain - The chain to use
33
39
  * @param {SmartAccountSigner} params.signer - The signer to use for the smart account
34
- * @param {"local" | "remote"} params.mode - The client's mode (local or remote).
35
40
  * @param {string} [params.policyId] - The policy ID for gas sponsorship (optional)
36
41
  * @param {Address} [params.account] - The smart account address to use (optional)
37
42
  * @returns {SmartWalletClient} - A viem-compatible client
@@ -49,7 +54,6 @@ export type SmartWalletClient<
49
54
  * const client = createSmartWalletClient({
50
55
  * transport,
51
56
  * chain: arbitrumSepolia,
52
- * mode: "remote",
53
57
  * signer,
54
58
  * });
55
59
  */
@@ -60,22 +64,19 @@ export function createSmartWalletClient<
60
64
  export function createSmartWalletClient(
61
65
  params: SmartWalletClientParams,
62
66
  ): SmartWalletClient {
63
- const { transport, chain, policyId, mode, account, signer } = params;
67
+ const { transport, chain, policyId, account, signer } = params;
64
68
 
65
- const innerClient =
66
- mode === "local"
67
- ? createLocalClient({
68
- transport,
69
- chain,
70
- policyId,
71
- account,
72
- })
73
- : createRemoteClient({
74
- transport,
75
- chain,
76
- policyId,
77
- account,
78
- });
69
+ const innerClient = createClient({
70
+ transport: (opts) =>
71
+ custom(Provider.from(transport(opts), { schema: WalletServerRpcSchema }))(
72
+ opts,
73
+ ),
74
+ chain,
75
+ account,
76
+ }).extend(() => ({
77
+ policyId,
78
+ internal: internalStateDecorator(),
79
+ }));
79
80
 
80
81
  // TODO: we need to do a few things here:
81
82
  // 1. decorate the client with the wallet api actions
@@ -90,7 +91,6 @@ export function createSmartWalletClient(
90
91
  // transport: alchemy({ apiKey: "123" }),
91
92
  // chain: baseSepolia,
92
93
  // signer: createDummySigner(zeroAddress),
93
- // mode: "local",
94
94
  // });
95
95
 
96
96
  // const account1 = await clientWithoutAccount.requestAccount();
@@ -99,7 +99,6 @@ export function createSmartWalletClient(
99
99
  // transport: alchemy({ apiKey: "123" }),
100
100
  // chain: baseSepolia,
101
101
  // signer: createDummySigner(zeroAddress),
102
- // mode: "local",
103
102
  // account: zeroAddress,
104
103
  // });
105
104
 
@@ -1,20 +1,16 @@
1
1
  import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
2
2
  import {
3
- createLightAccount,
4
3
  createModularAccountV2,
4
+ createLightAccount,
5
5
  createMultiOwnerLightAccount,
6
6
  createMultiOwnerModularAccount,
7
- type ModularAccountV2,
8
7
  } from "@account-kit/smart-contracts";
8
+ import { concatHex, type Chain, type Transport, type Address } from "viem";
9
9
  import type { StaticDecode } from "@sinclair/typebox";
10
- import type { Address, Chain, Transport } from "viem";
11
- import { concatHex, hexToNumber } from "viem";
12
- import { parsePermissionsContext } from "./parsePermissionsContext.js";
13
- import { assertNever } from "../../utils.js";
14
- import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
15
10
  import { SerializedInitcode } from "@alchemy/wallet-api-types";
16
- import { PermissionsCapability } from "@alchemy/wallet-api-types/capabilities";
17
11
  import { InternalError, InvalidRequestError } from "ox/RpcResponse";
12
+ import { assertNever } from "../utils.js";
13
+ import { getAccountTypeForDelegationAddress7702 } from "@alchemy/wallet-api-types/capabilities";
18
14
 
19
15
  type CreateAccountParams = {
20
16
  chain: Chain;
@@ -22,8 +18,7 @@ type CreateAccountParams = {
22
18
  signer: SmartAccountSigner;
23
19
  accountAddress: Address;
24
20
  counterfactualInfo?: StaticDecode<typeof SerializedInitcode>; // undefined for 7702 accounts
25
- permissions?: StaticDecode<typeof PermissionsCapability>;
26
- delegation?: Address;
21
+ delegation?: Address; // for 7702 accounts
27
22
  };
28
23
 
29
24
  /**
@@ -36,46 +31,19 @@ export async function createAccount(
36
31
  ): Promise<SmartContractAccount> {
37
32
  const { counterfactualInfo: ci, ...accountParams } = params;
38
33
 
39
- // This throws if we pass a permission context and the account is not MA-v2
40
- // TODO: test that this edge case is handled correctly
41
- const parsedContext = parsePermissionsContext(
42
- params.permissions,
43
- ci,
44
- params.delegation,
45
- );
46
-
47
- const signerEntity =
48
- parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
49
- ? {
50
- entityId: hexToNumber(parsedContext.entityId),
51
- isGlobalValidation: parsedContext.isGlobalValidation,
52
- }
53
- : undefined;
54
-
55
- const mode = params.delegation ? "7702" : "default";
56
-
57
- if (mode === "7702") {
34
+ if (params.delegation) {
58
35
  const accountType = getAccountTypeForDelegationAddress7702(
59
- params.delegation!,
36
+ params.delegation,
60
37
  );
61
38
  if (accountType !== "ModularAccountV2") {
62
39
  throw new Error("7702 mode currently only supports ModularAccountV2");
63
40
  }
64
41
  return createModularAccountV2({
65
42
  ...accountParams,
66
- signerEntity,
67
- deferredAction: parsedContext?.deferredAction,
68
- mode,
43
+ mode: "7702",
69
44
  });
70
45
  }
71
46
 
72
- if (mode !== "default") {
73
- return assertNever(mode, "Unexpected mode in createAccount");
74
- }
75
-
76
- // At this point, we are guaranteed to be in default mode, where ci
77
- // (counterfactualInfo) must be defined
78
-
79
47
  if (!ci) {
80
48
  throw new InternalError({
81
49
  message: "Counterfactual info not found",
@@ -93,9 +61,7 @@ export async function createAccount(
93
61
  case "MAv2.0.0-sma-b":
94
62
  return createModularAccountV2({
95
63
  ...commonParams,
96
- signerEntity,
97
- deferredAction: parsedContext?.deferredAction,
98
- mode,
64
+ mode: "default",
99
65
  });
100
66
  case "LightAccountV2.0.0":
101
67
  return createLightAccount({
@@ -138,9 +104,3 @@ export async function createAccount(
138
104
  return assertNever(factoryType, "Unsupported factory type");
139
105
  }
140
106
  }
141
-
142
- export function isModularAccountV2(
143
- account: SmartContractAccount,
144
- ): account is ModularAccountV2 {
145
- return account.source === "ModularAccountV2";
146
- }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
1
+ import type { SmartContractAccount } from "@aa-sdk/core";
2
2
  import type { AlchemyTransport } from "@account-kit/infra";
3
3
  import type {
4
4
  Address,
@@ -8,10 +8,6 @@ import type {
8
8
  JsonRpcAccount,
9
9
  Transport,
10
10
  } from "viem";
11
- import type {
12
- GrantPermissionsParams,
13
- GrantPermissionsResult,
14
- } from "./client/actions/grantPermissions.ts";
15
11
  import type { RequestAccountParams } from "./client/actions/requestAccount.ts";
16
12
  import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
17
13
 
@@ -36,13 +32,6 @@ export type InnerWalletApiClientBase<
36
32
  { policyId?: string } & TExtend
37
33
  >;
38
34
 
39
- export type InnerClientActions = {
40
- grantPermissions: (
41
- signer: SmartAccountSigner,
42
- params: GrantPermissionsParams & { chainId: Hex },
43
- ) => Promise<GrantPermissionsResult>;
44
- };
45
-
46
35
  export type CachedAccount = {
47
36
  account: SmartContractAccount;
48
37
  requestParams: RequestAccountParams;
@@ -53,9 +42,9 @@ export type InternalState = {
53
42
  getAccount: () => CachedAccount | undefined;
54
43
  };
55
44
 
56
- export type InnerWalletApiClient = InnerWalletApiClientBase<
57
- InnerClientActions & { internal: InternalState }
58
- >;
45
+ export type InnerWalletApiClient = InnerWalletApiClientBase<{
46
+ internal: InternalState;
47
+ }>;
59
48
 
60
49
  export type WithoutChainId<T> = T extends { chainId: Hex }
61
50
  ? Omit<T, "chainId">
@@ -1,4 +0,0 @@
1
- export type * from "../isomorphic/client.js";
2
- export { createIsomorphicClient } from "../isomorphic/client.js";
3
- export { createDummySigner } from "../isomorphic/utils/createDummySigner.js";
4
- export type * from "../types.ts";
@@ -1,3 +0,0 @@
1
- export { createIsomorphicClient } from "../isomorphic/client.js";
2
- export { createDummySigner } from "../isomorphic/utils/createDummySigner.js";
3
- //# sourceMappingURL=internal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/exports/internal.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC","sourcesContent":["// exports from this file are meant to be imported by our packages in the monorepo\n// we will expose this in the package.json as a named export like `this-pkg/internal`\n// TODO: name `this-pkg`\nexport type * from \"../isomorphic/client.js\";\nexport { createIsomorphicClient } from \"../isomorphic/client.js\";\nexport { createDummySigner } from \"../isomorphic/utils/createDummySigner.js\";\n\nexport type * from \"../types.ts\";\n"]}
@@ -1,13 +0,0 @@
1
- import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
- import type { Static } from "@sinclair/typebox";
3
- import { type Chain, type Hex, type Transport } from "viem";
4
- import type { wallet_createSession, WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
5
- export type CreateSessionParams = Omit<Static<(typeof wallet_createSession)["properties"]["Request"]["properties"]["params"]>[0], "chainId"> & {
6
- entityId?: Hex;
7
- };
8
- export type CreateSessionResult = Omit<Static<(typeof wallet_createSession)["properties"]["ReturnType"]>, "sessionId"> & {
9
- sessionId: Hex | null;
10
- entityId: Hex;
11
- fullPreSignatureDeferredActionDigest: Hex;
12
- };
13
- export declare function createSession(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: CreateSessionParams): Promise<CreateSessionResult>;
@@ -1,94 +0,0 @@
1
- import { createSmartAccountClient, } from "@aa-sdk/core";
2
- import { deferralActions, PermissionBuilder, } from "@account-kit/smart-contracts/experimental";
3
- import { Value } from "@sinclair/typebox/value";
4
- import { ChainNotFoundError, custom, hashTypedData, hexToNumber, toHex, } from "viem";
5
- import { InvalidRequestError } from "ox/RpcResponse";
6
- import { Permission, isGlobalValidation, } from "@alchemy/wallet-api-types/capabilities";
7
- import { createAccount, isModularAccountV2 } from "../utils/createAccount.js";
8
- import { createDummySigner } from "../utils/createDummySigner.js";
9
- import { supportsFeature } from "../utils/supportsFeature.js";
10
- import { isDelegated } from "../utils/7702.js";
11
- export async function createSession(client, params) {
12
- if (!client.chain) {
13
- throw new ChainNotFoundError();
14
- }
15
- const { counterfactualInfo, delegation } = await client.request({
16
- method: "wallet_requestAccount",
17
- params: [
18
- {
19
- accountAddress: params.account,
20
- includeCounterfactualInfo: true,
21
- },
22
- ],
23
- });
24
- if (delegation &&
25
- !(await isDelegated(client, {
26
- address: params.account,
27
- delegation,
28
- }))) {
29
- throw new InvalidRequestError({
30
- message: "7702 account must be delegated before calling `wallet_createSession`",
31
- });
32
- }
33
- if (!delegation && !counterfactualInfo) {
34
- throw new InvalidRequestError({
35
- message: "No counterfactual info found.",
36
- });
37
- }
38
- if (counterfactualInfo &&
39
- !supportsFeature(counterfactualInfo, "permissions")) {
40
- throw new InvalidRequestError({
41
- message: "Account type does not support createSession",
42
- });
43
- }
44
- // At this point we know the account supports the permission feature
45
- const account = await createAccount({
46
- chain: client.chain,
47
- transport: custom(client.transport),
48
- signer: createDummySigner(params.account),
49
- accountAddress: params.account,
50
- counterfactualInfo,
51
- delegation,
52
- });
53
- if (!isModularAccountV2(account)) {
54
- throw new InvalidRequestError({
55
- message: "Sessions are currently only supported by MAv2 accounts.",
56
- });
57
- }
58
- const _client = createSmartAccountClient({
59
- chain: client.chain,
60
- transport: custom(client.transport),
61
- account,
62
- }).extend(deferralActions);
63
- const { entityId, nonce } = await _client.getEntityIdAndNonce({
64
- entityId: params.entityId ? hexToNumber(params.entityId) : undefined,
65
- isGlobalValidation: isGlobalValidation(params),
66
- });
67
- const { typedData, fullPreSignatureDeferredActionDigest } = await new PermissionBuilder({
68
- client: _client,
69
- key: {
70
- ...params.key,
71
- // Alias 'ecdsa' to 'secp256k1'
72
- type: params.key.type === "ecdsa" ? "secp256k1" : params.key.type,
73
- },
74
- entityId,
75
- nonce,
76
- deadline: params.expirySec,
77
- })
78
- .addPermissions({
79
- permissions: params.permissions.map((permission) => Value.Encode(Permission, permission)),
80
- })
81
- .compileDeferred();
82
- return {
83
- sessionId: null, // In remote mode, the server will set this later.
84
- chainId: toHex(client.chain.id),
85
- entityId: toHex(entityId),
86
- signatureRequest: {
87
- type: "eth_signTypedData_v4",
88
- data: typedData,
89
- rawPayload: hashTypedData(typedData),
90
- },
91
- fullPreSignatureDeferredActionDigest,
92
- };
93
- }
94
- //# sourceMappingURL=createSession.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createSession.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/createSession.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n createSmartAccountClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport {\n deferralActions,\n PermissionBuilder,\n} from \"@account-kit/smart-contracts/experimental\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n ChainNotFoundError,\n custom,\n hashTypedData,\n hexToNumber,\n toHex,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { InvalidRequestError } from \"ox/RpcResponse\";\nimport {\n Permission,\n isGlobalValidation,\n} from \"@alchemy/wallet-api-types/capabilities\";\nimport type {\n wallet_createSession,\n WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { createAccount, isModularAccountV2 } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { supportsFeature } from \"../utils/supportsFeature.js\";\nimport { isDelegated } from \"../utils/7702.js\";\n\nexport type CreateSessionParams = Omit<\n Static<\n (typeof wallet_createSession)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n >[0],\n \"chainId\"\n> & {\n entityId?: Hex;\n};\n\nexport type CreateSessionResult = Omit<\n Static<(typeof wallet_createSession)[\"properties\"][\"ReturnType\"]>,\n \"sessionId\"\n> & {\n sessionId: Hex | null;\n entityId: Hex;\n fullPreSignatureDeferredActionDigest: Hex;\n};\n\nexport async function createSession(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: CreateSessionParams,\n): Promise<CreateSessionResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.account,\n includeCounterfactualInfo: true,\n },\n ],\n });\n\n if (\n delegation &&\n !(await isDelegated(client, {\n address: params.account,\n delegation,\n }))\n ) {\n throw new InvalidRequestError({\n message:\n \"7702 account must be delegated before calling `wallet_createSession`\",\n });\n }\n\n if (!delegation && !counterfactualInfo) {\n throw new InvalidRequestError({\n message: \"No counterfactual info found.\",\n });\n }\n\n if (\n counterfactualInfo &&\n !supportsFeature(counterfactualInfo, \"permissions\")\n ) {\n throw new InvalidRequestError({\n message: \"Account type does not support createSession\",\n });\n }\n\n // At this point we know the account supports the permission feature\n const account = await createAccount({\n chain: client.chain,\n transport: custom(client.transport),\n signer: createDummySigner(params.account),\n accountAddress: params.account,\n counterfactualInfo,\n delegation,\n });\n\n if (!isModularAccountV2(account)) {\n throw new InvalidRequestError({\n message: \"Sessions are currently only supported by MAv2 accounts.\",\n });\n }\n\n const _client = createSmartAccountClient({\n chain: client.chain,\n transport: custom(client.transport),\n account,\n }).extend(deferralActions);\n\n const { entityId, nonce } = await _client.getEntityIdAndNonce({\n entityId: params.entityId ? hexToNumber(params.entityId) : undefined,\n isGlobalValidation: isGlobalValidation(params),\n });\n\n const { typedData, fullPreSignatureDeferredActionDigest } =\n await new PermissionBuilder({\n client: _client,\n key: {\n ...params.key,\n // Alias 'ecdsa' to 'secp256k1'\n type: params.key.type === \"ecdsa\" ? \"secp256k1\" : params.key.type,\n },\n entityId,\n nonce,\n deadline: params.expirySec,\n })\n .addPermissions({\n permissions: params.permissions.map((permission) =>\n Value.Encode(Permission, permission),\n ),\n })\n .compileDeferred();\n\n return {\n sessionId: null, // In remote mode, the server will set this later.\n chainId: toHex(client.chain.id),\n entityId: toHex(entityId),\n signatureRequest: {\n type: \"eth_signTypedData_v4\" as const,\n data: typedData,\n rawPayload: hashTypedData(typedData),\n },\n fullPreSignatureDeferredActionDigest,\n };\n}\n"]}
@@ -1,8 +0,0 @@
1
- import type { Static } from "@sinclair/typebox";
2
- import type { wallet_formatSign } from "@alchemy/wallet-api-types/rpc";
3
- import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
4
- import { type Chain, type Transport } from "viem";
5
- import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
6
- export type FormatSignParams = Static<(typeof wallet_formatSign)["properties"]["Request"]["properties"]["params"]>[0];
7
- export type FormatSignResult = Static<(typeof wallet_formatSign)["properties"]["ReturnType"]>;
8
- export declare function formatSign(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: FormatSignParams): Promise<FormatSignResult>;
@@ -1,42 +0,0 @@
1
- import { ChainNotFoundError, concat, custom, encodeAbiParameters, parseAbiParameters, } from "viem";
2
- import { createAccount } from "../utils/createAccount.js";
3
- import { createDummySigner } from "../utils/createDummySigner.js";
4
- import { magicBytes } from "ox/erc6492/WrappedSignature";
5
- export async function formatSign(client, params) {
6
- if (!client.chain) {
7
- throw new ChainNotFoundError();
8
- }
9
- const { counterfactualInfo, delegation } = await client.request({
10
- method: "wallet_requestAccount",
11
- params: [
12
- {
13
- accountAddress: params.from,
14
- includeCounterfactualInfo: true,
15
- },
16
- ],
17
- });
18
- const account = await createAccount({
19
- chain: client.chain,
20
- transport: custom(client.transport),
21
- signer: createDummySigner(params.from),
22
- accountAddress: params.from,
23
- counterfactualInfo,
24
- permissions: params.capabilities?.permissions,
25
- delegation,
26
- });
27
- let formattedSignature = await account.formatSign(params.signature.data);
28
- if (counterfactualInfo && !(await account.isAccountDeployed())) {
29
- formattedSignature = concat([
30
- encodeAbiParameters(parseAbiParameters("address, bytes, bytes"), [
31
- counterfactualInfo.factoryAddress,
32
- counterfactualInfo.factoryData,
33
- formattedSignature,
34
- ]),
35
- magicBytes,
36
- ]);
37
- }
38
- return {
39
- signature: formattedSignature,
40
- };
41
- }
42
- //# sourceMappingURL=formatSign.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/formatSign.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,MAAM,EACN,mBAAmB,EACnB,kBAAkB,GAGnB,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAUzD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAMC,EACD,MAAwB;IAExB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9D,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE;YACN;gBACE,cAAc,EAAE,MAAM,CAAC,IAAI;gBAC3B,yBAAyB,EAAE,IAAI;aAChC;SACF;KACF,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC;QAClC,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;QACnC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;QACtC,cAAc,EAAE,MAAM,CAAC,IAAI;QAC3B,kBAAkB;QAClB,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,WAAW;QAC7C,UAAU;KACX,CAAC,CAAC;IAEH,IAAI,kBAAkB,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAEzE,IAAI,kBAAkB,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC;QAC/D,kBAAkB,GAAG,MAAM,CAAC;YAC1B,mBAAmB,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,EAAE;gBAC/D,kBAAkB,CAAC,cAAc;gBACjC,kBAAkB,CAAC,WAAW;gBAC9B,kBAAkB;aACnB,CAAC;YACF,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,SAAS,EAAE,kBAAkB;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type { Static } from \"@sinclair/typebox\";\nimport type { wallet_formatSign } from \"@alchemy/wallet-api-types/rpc\";\nimport type { SmartAccountClient, SmartContractAccount } from \"@aa-sdk/core\";\nimport {\n ChainNotFoundError,\n concat,\n custom,\n encodeAbiParameters,\n parseAbiParameters,\n type Chain,\n type Transport,\n} from \"viem\";\nimport type { WalletServerViemRpcSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { createAccount } from \"../utils/createAccount.js\";\nimport { createDummySigner } from \"../utils/createDummySigner.js\";\nimport { magicBytes } from \"ox/erc6492/WrappedSignature\";\n\nexport type FormatSignParams = Static<\n (typeof wallet_formatSign)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type FormatSignResult = Static<\n (typeof wallet_formatSign)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function formatSign(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n params: FormatSignParams,\n): Promise<FormatSignResult> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const { counterfactualInfo, delegation } = await client.request({\n method: \"wallet_requestAccount\",\n params: [\n {\n accountAddress: params.from,\n includeCounterfactualInfo: true,\n },\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 let formattedSignature = await account.formatSign(params.signature.data);\n\n if (counterfactualInfo && !(await account.isAccountDeployed())) {\n formattedSignature = concat([\n encodeAbiParameters(parseAbiParameters(\"address, bytes, bytes\"), [\n counterfactualInfo.factoryAddress,\n counterfactualInfo.factoryData,\n formattedSignature,\n ]),\n magicBytes,\n ]);\n }\n\n return {\n signature: formattedSignature,\n };\n}\n"]}
@@ -1,7 +0,0 @@
1
- import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
- import type { Static } from "@sinclair/typebox";
3
- import { type Chain, type Transport } from "viem";
4
- import { type wallet_getCallsStatus, type WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
5
- export type GetCallsStatusParams = Static<(typeof wallet_getCallsStatus)["properties"]["Request"]["properties"]["params"]>[0];
6
- export type GetCallsStatusResponse = Static<(typeof wallet_getCallsStatus)["properties"]["ReturnType"]>;
7
- export declare function getCallsStatus(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, callId: GetCallsStatusParams): Promise<GetCallsStatusResponse>;
@@ -1,71 +0,0 @@
1
- import {} from "@aa-sdk/core";
2
- import { Value } from "@sinclair/typebox/value";
3
- import { ChainNotFoundError, isHex, } from "viem";
4
- import { BaseError } from "ox/RpcResponse";
5
- import { CallStatusCode, CallStatusErrorCode, } from "@alchemy/wallet-api-types/rpc";
6
- import { CallId } from "@alchemy/wallet-api-types";
7
- import { castToHex } from "../../utils.js";
8
- export async function getCallsStatus(client, callId) {
9
- if (!client.chain) {
10
- throw new ChainNotFoundError();
11
- }
12
- const { chainId, hash } = Value.Decode(CallId, callId);
13
- const baseResp = {
14
- id: callId,
15
- chainId,
16
- atomic: true,
17
- };
18
- const result = await client.getUserOperationByHash(hash);
19
- if (!result) {
20
- throw new BaseError({
21
- message: `callId ${callId} not found`,
22
- code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,
23
- });
24
- }
25
- if (result && !result.transactionHash) {
26
- // A result but no txn hash means it's valid but pending.
27
- return {
28
- ...baseResp,
29
- status: CallStatusCode.PENDING,
30
- };
31
- }
32
- const receipt = await client.getUserOperationReceipt(hash);
33
- if (!receipt) {
34
- // Handles edge case of hash being retrieved immediately before the 150 block limit falloff.
35
- throw new BaseError({
36
- message: `callId ${callId} not found`,
37
- code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,
38
- });
39
- }
40
- return {
41
- ...baseResp,
42
- status: receipt.success
43
- ? CallStatusCode.CONFIRMED
44
- : CallStatusCode.CHAIN_RULES_FAILURE,
45
- receipts: [transformReceipt(receipt.receipt)],
46
- };
47
- }
48
- const ReceiptStatus = {
49
- reverted: "0x0",
50
- success: "0x1",
51
- };
52
- function transformReceipt(receipt) {
53
- return {
54
- // viem's type for status is "success" | "reverted", but the actual value seems to already be 0x0 or 0x1
55
- status: isHex(receipt.status)
56
- ? receipt.status
57
- : ReceiptStatus[receipt.status],
58
- blockHash: receipt.blockHash,
59
- // viem's type for blockNumber is bigint, but the actual value seems to already be a hex string
60
- blockNumber: castToHex(receipt.blockNumber),
61
- // viem's type for gasUsed is bigint, but the actual value seems to already be a hex string
62
- gasUsed: castToHex(receipt.gasUsed),
63
- transactionHash: receipt.transactionHash,
64
- logs: receipt.logs.map((log) => ({
65
- address: log.address,
66
- data: log.data,
67
- topics: log.topics,
68
- })),
69
- };
70
- }
71
- //# sourceMappingURL=getCallsStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getCallsStatus.js","sourceRoot":"","sources":["../../../../src/isomorphic/actions/getCallsStatus.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Static } from \"@sinclair/typebox\";\nimport { Value } from \"@sinclair/typebox/value\";\nimport {\n ChainNotFoundError,\n isHex,\n type Chain,\n type Hex,\n type TransactionReceipt,\n type Transport,\n} from \"viem\";\nimport { BaseError } from \"ox/RpcResponse\";\nimport {\n CallStatusCode,\n CallStatusErrorCode,\n type wallet_getCallsStatus,\n type WalletServerViemRpcSchema,\n} from \"@alchemy/wallet-api-types/rpc\";\nimport { CallId } from \"@alchemy/wallet-api-types\";\nimport { castToHex } from \"../../utils.js\";\n\nexport type GetCallsStatusParams = Static<\n (typeof wallet_getCallsStatus)[\"properties\"][\"Request\"][\"properties\"][\"params\"]\n>[0];\n\nexport type GetCallsStatusResponse = Static<\n (typeof wallet_getCallsStatus)[\"properties\"][\"ReturnType\"]\n>;\n\nexport async function getCallsStatus(\n client: SmartAccountClient<\n Transport,\n Chain,\n SmartContractAccount | undefined,\n Record<string, unknown>,\n WalletServerViemRpcSchema\n >,\n callId: GetCallsStatusParams,\n): Promise<GetCallsStatusResponse> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n const { chainId, hash } = Value.Decode(CallId, callId);\n\n const baseResp = {\n id: callId,\n chainId,\n atomic: true,\n };\n\n const result = await client.getUserOperationByHash(hash);\n if (!result) {\n throw new BaseError({\n message: `callId ${callId} not found`,\n code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,\n });\n }\n if (result && !result.transactionHash) {\n // A result but no txn hash means it's valid but pending.\n return {\n ...baseResp,\n status: CallStatusCode.PENDING,\n };\n }\n\n const receipt = await client.getUserOperationReceipt(hash);\n if (!receipt) {\n // Handles edge case of hash being retrieved immediately before the 150 block limit falloff.\n throw new BaseError({\n message: `callId ${callId} not found`,\n code: CallStatusErrorCode.UNKNOWN_BUNDLE_ID,\n });\n }\n\n return {\n ...baseResp,\n status: receipt.success\n ? CallStatusCode.CONFIRMED\n : CallStatusCode.CHAIN_RULES_FAILURE,\n receipts: [transformReceipt(receipt.receipt)],\n };\n}\n\nconst ReceiptStatus: Record<TransactionReceipt[\"status\"], Hex> = {\n reverted: \"0x0\",\n success: \"0x1\",\n};\n\nfunction transformReceipt(\n receipt: TransactionReceipt,\n): NonNullable<GetCallsStatusResponse[\"receipts\"]>[number] {\n return {\n // viem's type for status is \"success\" | \"reverted\", but the actual value seems to already be 0x0 or 0x1\n status: isHex(receipt.status)\n ? receipt.status\n : ReceiptStatus[receipt.status],\n blockHash: receipt.blockHash,\n // viem's type for blockNumber is bigint, but the actual value seems to already be a hex string\n blockNumber: castToHex(receipt.blockNumber),\n // viem's type for gasUsed is bigint, but the actual value seems to already be a hex string\n gasUsed: castToHex(receipt.gasUsed),\n transactionHash: receipt.transactionHash,\n logs: receipt.logs.map((log) => ({\n address: log.address,\n data: log.data,\n topics: log.topics,\n })),\n };\n}\n"]}
@@ -1,7 +0,0 @@
1
- import { type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
- import type { Static } from "@sinclair/typebox";
3
- import { type Chain, type Transport } from "viem";
4
- import type { wallet_prepareCalls, WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
5
- export type PrepareCallsParams = Omit<Static<(typeof wallet_prepareCalls)["properties"]["Request"]["properties"]["params"]>[0], "chainId">;
6
- export type PrepareCallsResult = Static<(typeof wallet_prepareCalls)["properties"]["ReturnType"]>;
7
- export declare function prepareCalls(client: SmartAccountClient<Transport, Chain, SmartContractAccount | undefined, Record<string, unknown>, WalletServerViemRpcSchema>, params: PrepareCallsParams): Promise<PrepareCallsResult>;