@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.2

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 (113) hide show
  1. package/dist/esm/capabilities/permissions/mav2.d.ts +2 -2
  2. package/dist/esm/capabilities/permissions/mav2.js.map +1 -1
  3. package/dist/esm/client/actions/createAccount.d.ts +27 -2
  4. package/dist/esm/client/actions/createAccount.js +25 -0
  5. package/dist/esm/client/actions/createAccount.js.map +1 -1
  6. package/dist/esm/client/actions/getCallsStatus.d.ts +21 -2
  7. package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
  8. package/dist/esm/client/actions/grantPermissions.d.ts +60 -2
  9. package/dist/esm/client/actions/grantPermissions.js.map +1 -1
  10. package/dist/esm/client/actions/listAccounts.d.ts +26 -2
  11. package/dist/esm/client/actions/listAccounts.js +24 -0
  12. package/dist/esm/client/actions/listAccounts.js.map +1 -1
  13. package/dist/esm/client/actions/prepareCalls.d.ts +28 -2
  14. package/dist/esm/client/actions/prepareCalls.js.map +1 -1
  15. package/dist/esm/client/actions/requestAccount.d.ts +21 -2
  16. package/dist/esm/client/actions/requestAccount.js +14 -3
  17. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  18. package/dist/esm/client/actions/sendPreparedCalls.d.ts +39 -2
  19. package/dist/esm/client/actions/sendPreparedCalls.js +37 -0
  20. package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
  21. package/dist/esm/client/actions/signMessage.d.ts +22 -2
  22. package/dist/esm/client/actions/signMessage.js +4 -2
  23. package/dist/esm/client/actions/signMessage.js.map +1 -1
  24. package/dist/esm/client/actions/signSignatureRequest.d.ts +31 -0
  25. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  26. package/dist/esm/client/actions/signTypedData.d.ts +35 -2
  27. package/dist/esm/client/actions/signTypedData.js +3 -1
  28. package/dist/esm/client/actions/signTypedData.js.map +1 -1
  29. package/dist/esm/client/client.e2e-test.js +99 -11
  30. package/dist/esm/client/client.e2e-test.js.map +1 -1
  31. package/dist/esm/client/decorator.d.ts +7 -5
  32. package/dist/esm/client/decorator.js +1 -1
  33. package/dist/esm/client/decorator.js.map +1 -1
  34. package/dist/esm/client/index.d.ts +4 -4
  35. package/dist/esm/client/index.js +29 -3
  36. package/dist/esm/client/index.js.map +1 -1
  37. package/dist/esm/exports/index.d.ts +1 -0
  38. package/dist/esm/exports/index.js +1 -0
  39. package/dist/esm/exports/index.js.map +1 -1
  40. package/dist/esm/exports/internal.d.ts +1 -1
  41. package/dist/esm/exports/internal.js.map +1 -1
  42. package/dist/esm/internal/decorator.d.ts +2 -0
  43. package/dist/esm/internal/decorator.js +10 -0
  44. package/dist/esm/internal/decorator.js.map +1 -0
  45. package/dist/esm/local/client.d.ts +1 -1
  46. package/dist/esm/local/client.js +8 -1
  47. package/dist/esm/local/client.js.map +1 -1
  48. package/dist/esm/remote/client.d.ts +1 -1
  49. package/dist/esm/remote/client.js +6 -1
  50. package/dist/esm/remote/client.js.map +1 -1
  51. package/dist/esm/rpc/schema.d.ts +1 -1
  52. package/dist/esm/types.d.ts +15 -4
  53. package/dist/esm/types.js.map +1 -1
  54. package/dist/types/capabilities/permissions/mav2.d.ts +2 -2
  55. package/dist/types/capabilities/permissions/mav2.d.ts.map +1 -1
  56. package/dist/types/client/actions/createAccount.d.ts +27 -2
  57. package/dist/types/client/actions/createAccount.d.ts.map +1 -1
  58. package/dist/types/client/actions/getCallsStatus.d.ts +21 -2
  59. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  60. package/dist/types/client/actions/grantPermissions.d.ts +60 -2
  61. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  62. package/dist/types/client/actions/listAccounts.d.ts +26 -2
  63. package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
  64. package/dist/types/client/actions/prepareCalls.d.ts +28 -2
  65. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  66. package/dist/types/client/actions/requestAccount.d.ts +21 -2
  67. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  68. package/dist/types/client/actions/sendPreparedCalls.d.ts +39 -2
  69. package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
  70. package/dist/types/client/actions/signMessage.d.ts +22 -2
  71. package/dist/types/client/actions/signMessage.d.ts.map +1 -1
  72. package/dist/types/client/actions/signSignatureRequest.d.ts +31 -0
  73. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  74. package/dist/types/client/actions/signTypedData.d.ts +35 -2
  75. package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
  76. package/dist/types/client/decorator.d.ts +7 -5
  77. package/dist/types/client/decorator.d.ts.map +1 -1
  78. package/dist/types/client/index.d.ts +4 -4
  79. package/dist/types/client/index.d.ts.map +1 -1
  80. package/dist/types/exports/index.d.ts +1 -0
  81. package/dist/types/exports/index.d.ts.map +1 -1
  82. package/dist/types/exports/internal.d.ts +1 -1
  83. package/dist/types/exports/internal.d.ts.map +1 -1
  84. package/dist/types/internal/decorator.d.ts +3 -0
  85. package/dist/types/internal/decorator.d.ts.map +1 -0
  86. package/dist/types/local/client.d.ts +1 -1
  87. package/dist/types/local/client.d.ts.map +1 -1
  88. package/dist/types/remote/client.d.ts +1 -1
  89. package/dist/types/remote/client.d.ts.map +1 -1
  90. package/dist/types/rpc/schema.d.ts +1 -1
  91. package/dist/types/types.d.ts +15 -4
  92. package/dist/types/types.d.ts.map +1 -1
  93. package/package.json +8 -6
  94. package/src/capabilities/permissions/mav2.ts +2 -2
  95. package/src/client/actions/createAccount.ts +27 -2
  96. package/src/client/actions/getCallsStatus.ts +21 -2
  97. package/src/client/actions/grantPermissions.ts +60 -2
  98. package/src/client/actions/listAccounts.ts +26 -2
  99. package/src/client/actions/prepareCalls.ts +28 -2
  100. package/src/client/actions/requestAccount.ts +40 -5
  101. package/src/client/actions/sendPreparedCalls.ts +39 -2
  102. package/src/client/actions/signMessage.ts +24 -4
  103. package/src/client/actions/signSignatureRequest.ts +31 -0
  104. package/src/client/actions/signTypedData.ts +39 -3
  105. package/src/client/client.e2e-test.ts +120 -11
  106. package/src/client/decorator.ts +10 -12
  107. package/src/client/index.ts +41 -10
  108. package/src/exports/index.ts +1 -0
  109. package/src/exports/internal.ts +1 -1
  110. package/src/internal/decorator.ts +12 -0
  111. package/src/local/client.ts +52 -42
  112. package/src/remote/client.ts +10 -5
  113. package/src/types.ts +18 -4
@@ -6,7 +6,8 @@ import {
6
6
  prefixSignatureKeyType,
7
7
  } from "../capabilities/permissions/mav2.js";
8
8
  import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
9
- import type { PrepareCallsParams } from "../isomorphic/actions/prepareCalls";
9
+ import { internalStateDecorator } from "../internal/decorator.js";
10
+ import type { PrepareCallsParams } from "../isomorphic/actions/prepareCalls.ts";
10
11
  import {
11
12
  createIsomorphicClient,
12
13
  type IsomorphicClient,
@@ -15,7 +16,7 @@ import type {
15
16
  CreateInnerClientParams,
16
17
  InnerClientActions,
17
18
  InnerWalletApiClient,
18
- } from "../types";
19
+ } from "../types.ts";
19
20
  import { assertNever } from "../utils.js";
20
21
 
21
22
  const localMethods = [
@@ -51,46 +52,51 @@ export function createLocalClient(
51
52
  overrides: [
52
53
  {
53
54
  methods: localMethods,
54
- transport: custom({
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- async request(args: { method: LocalMethod; params: any }) {
57
- switch (args.method) {
58
- case "wallet_prepareCalls": {
59
- const params = args.params[0] as PrepareCallsParams;
60
- const capabilityPolicyId =
61
- params.capabilities?.paymasterService?.policyId;
55
+ transport: custom(
56
+ {
57
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+ async request(args: { method: LocalMethod; params: any }) {
59
+ switch (args.method) {
60
+ case "wallet_prepareCalls": {
61
+ const params = args.params[0] as PrepareCallsParams;
62
+ const capabilityPolicyId =
63
+ params.capabilities?.paymasterService?.policyId;
62
64
 
63
- if (
64
- capabilityPolicyId != null &&
65
- policyId !== capabilityPolicyId &&
66
- !clientMap[capabilityPolicyId]
67
- ) {
68
- clientMap[capabilityPolicyId] = createIsomorphicClient({
69
- transport,
70
- chain,
71
- policyId: capabilityPolicyId,
72
- });
73
- }
65
+ if (
66
+ capabilityPolicyId != null &&
67
+ policyId !== capabilityPolicyId &&
68
+ !clientMap[capabilityPolicyId]
69
+ ) {
70
+ clientMap[capabilityPolicyId] = createIsomorphicClient({
71
+ transport,
72
+ chain,
73
+ policyId: capabilityPolicyId,
74
+ });
75
+ }
74
76
 
75
- const client =
76
- clientMap[capabilityPolicyId ?? policyId ?? "default"];
77
- return client.prepareCalls(params);
78
- }
79
- case "wallet_sendPreparedCalls":
80
- return isomorphicClient.sendPreparedCalls(args.params[0]);
81
- case "wallet_getCallsStatus":
82
- return isomorphicClient.getCallsStatus(args.params[0]);
83
- case "wallet_createSession": {
84
- return isomorphicClient.createSession(args.params[0]);
77
+ const client =
78
+ clientMap[capabilityPolicyId ?? policyId ?? "default"];
79
+ return client.prepareCalls(params);
80
+ }
81
+ case "wallet_sendPreparedCalls":
82
+ return isomorphicClient.sendPreparedCalls(args.params[0]);
83
+ case "wallet_getCallsStatus":
84
+ return isomorphicClient.getCallsStatus(args.params[0]);
85
+ case "wallet_createSession": {
86
+ return isomorphicClient.createSession(args.params[0]);
87
+ }
88
+ default:
89
+ return assertNever(
90
+ args.method,
91
+ `Unexpected method: ${args.method}`,
92
+ );
85
93
  }
86
- default:
87
- return assertNever(
88
- args.method,
89
- `Unexpected method: ${args.method}`,
90
- );
91
- }
94
+ },
92
95
  },
93
- }),
96
+ {
97
+ retryCount: 0,
98
+ },
99
+ ),
94
100
  },
95
101
  ],
96
102
  fallback: transport,
@@ -100,10 +106,14 @@ export function createLocalClient(
100
106
  transport: innerTransport,
101
107
  chain,
102
108
  account,
103
- }).extend(() => ({
104
- policyId,
105
- ...innerClientActions(isomorphicClient),
106
- }));
109
+ })
110
+ .extend(() => ({
111
+ policyId,
112
+ ...innerClientActions(isomorphicClient),
113
+ }))
114
+ .extend(() => ({
115
+ internal: internalStateDecorator(),
116
+ }));
107
117
  }
108
118
 
109
119
  const innerClientActions = (
@@ -2,13 +2,14 @@ import { Provider } from "ox";
2
2
  import { createClient, custom, type Address, type JsonRpcAccount } from "viem";
3
3
  import { encodePermissionsContext } from "../capabilities/permissions/mav2.js";
4
4
  import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
5
+ import { internalStateDecorator } from "../internal/decorator.js";
5
6
  import { WalletServerRpcSchema } from "../rpc/schema.js";
6
7
  import type {
7
8
  CreateInnerClientParams,
8
9
  InnerClientActions,
9
10
  InnerWalletApiClient,
10
11
  InnerWalletApiClientBase,
11
- } from "../types";
12
+ } from "../types.ts";
12
13
 
13
14
  export function createRemoteClient<
14
15
  TAccount extends JsonRpcAccount<Address> | undefined =
@@ -34,10 +35,14 @@ export function createRemoteClient(
34
35
  ),
35
36
  chain,
36
37
  account,
37
- }).extend((_client) => ({
38
- policyId: params.policyId,
39
- ...innerClientActions(_client),
40
- }));
38
+ })
39
+ .extend((_client) => ({
40
+ policyId: params.policyId,
41
+ ...innerClientActions(_client),
42
+ }))
43
+ .extend(() => ({
44
+ internal: internalStateDecorator(),
45
+ }));
41
46
 
42
47
  return client;
43
48
  }
package/src/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
1
2
  import type { AlchemyTransport } from "@account-kit/infra";
2
3
  import type {
3
4
  Address,
@@ -8,12 +9,12 @@ import type {
8
9
  JsonRpcAccount,
9
10
  Transport,
10
11
  } from "viem";
11
- import type { WalletServerViemRpcSchema } from "./rpc/schema";
12
- import type { SmartAccountSigner } from "@aa-sdk/core";
13
12
  import type {
14
13
  GrantPermissionsParams,
15
14
  GrantPermissionsResult,
16
- } from "./client/actions/grantPermissions";
15
+ } from "./client/actions/grantPermissions.ts";
16
+ import type { RequestAccountParams } from "./client/actions/requestAccount.ts";
17
+ import type { WalletServerViemRpcSchema } from "./rpc/schema.ts";
17
18
 
18
19
  export type CreateInnerClientParams<
19
20
  TAccount extends JsonRpcAccount<Address> | undefined =
@@ -53,8 +54,21 @@ export type InnerClientActions = {
53
54
  ) => Promise<GrantPermissionsResult>;
54
55
  };
55
56
 
57
+ export type CachedAccount = {
58
+ account: SmartContractAccount;
59
+ requestParams: RequestAccountParams;
60
+ };
61
+
62
+ export type InternalState = {
63
+ setAccount: (account: CachedAccount) => void;
64
+ getAccount: () => CachedAccount | undefined;
65
+ };
66
+
56
67
  export type InnerWalletApiClient<
57
68
  TAccount extends JsonRpcAccount<Address> | undefined =
58
69
  | JsonRpcAccount<Address>
59
70
  | undefined,
60
- > = InnerWalletApiClientBase<TAccount, InnerClientActions>;
71
+ > = InnerWalletApiClientBase<
72
+ TAccount,
73
+ InnerClientActions & { internal: InternalState }
74
+ >;