@account-kit/wallet-client 0.1.0-alpha.10 → 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 (146) 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 +3 -3
  14. package/dist/esm/client/actions/requestAccount.js.map +1 -1
  15. package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -3
  16. package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
  17. package/dist/esm/client/client.e2e-test.js +190 -329
  18. package/dist/esm/client/client.e2e-test.js.map +1 -1
  19. package/dist/esm/client/index.d.ts +1 -4
  20. package/dist/esm/client/index.js +13 -18
  21. package/dist/esm/client/index.js.map +1 -1
  22. package/dist/esm/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +3 -7
  23. package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +9 -33
  24. package/dist/esm/internal/account.js.map +1 -0
  25. package/dist/esm/types.d.ts +2 -8
  26. package/dist/esm/types.js.map +1 -1
  27. package/dist/types/client/actions/getCallsStatus.d.ts +4 -3
  28. package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
  29. package/dist/types/client/actions/grantPermissions.d.ts +5 -4
  30. package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
  31. package/dist/types/client/actions/prepareCalls.d.ts +4 -3
  32. package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
  33. package/dist/types/client/actions/prepareSign.d.ts +4 -3
  34. package/dist/types/client/actions/prepareSign.d.ts.map +1 -1
  35. package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
  36. package/dist/types/client/actions/signSignatureRequest.d.ts +3 -3
  37. package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
  38. package/dist/types/client/index.d.ts +1 -4
  39. package/dist/types/client/index.d.ts.map +1 -1
  40. package/dist/types/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +4 -8
  41. package/dist/types/internal/account.d.ts.map +1 -0
  42. package/dist/types/types.d.ts +2 -8
  43. package/dist/types/types.d.ts.map +1 -1
  44. package/package.json +3 -8
  45. package/src/client/actions/getCallsStatus.ts +8 -6
  46. package/src/client/actions/grantPermissions.ts +41 -10
  47. package/src/client/actions/prepareCalls.ts +11 -6
  48. package/src/client/actions/prepareSign.ts +9 -6
  49. package/src/client/actions/requestAccount.ts +3 -3
  50. package/src/client/actions/signSignatureRequest.ts +8 -8
  51. package/src/client/client.e2e-test.ts +143 -298
  52. package/src/client/index.ts +22 -23
  53. package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +11 -51
  54. package/src/types.ts +4 -15
  55. package/dist/esm/exports/internal.d.ts +0 -4
  56. package/dist/esm/exports/internal.js +0 -3
  57. package/dist/esm/exports/internal.js.map +0 -1
  58. package/dist/esm/isomorphic/actions/createSession.d.ts +0 -13
  59. package/dist/esm/isomorphic/actions/createSession.js +0 -94
  60. package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
  61. package/dist/esm/isomorphic/actions/formatSign.d.ts +0 -8
  62. package/dist/esm/isomorphic/actions/formatSign.js +0 -42
  63. package/dist/esm/isomorphic/actions/formatSign.js.map +0 -1
  64. package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -7
  65. package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -71
  66. package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
  67. package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -7
  68. package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
  69. package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
  70. package/dist/esm/isomorphic/actions/prepareSign.d.ts +0 -7
  71. package/dist/esm/isomorphic/actions/prepareSign.js +0 -49
  72. package/dist/esm/isomorphic/actions/prepareSign.js.map +0 -1
  73. package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -7
  74. package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -156
  75. package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
  76. package/dist/esm/isomorphic/client.d.ts +0 -275
  77. package/dist/esm/isomorphic/client.js +0 -41
  78. package/dist/esm/isomorphic/client.js.map +0 -1
  79. package/dist/esm/isomorphic/utils/7702.d.ts +0 -19
  80. package/dist/esm/isomorphic/utils/7702.js +0 -70
  81. package/dist/esm/isomorphic/utils/7702.js.map +0 -1
  82. package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
  83. package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
  84. package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
  85. package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
  86. package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
  87. package/dist/esm/isomorphic/utils/decodeSignature.js +0 -15
  88. package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
  89. package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
  90. package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
  91. package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
  92. package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
  93. package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
  94. package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
  95. package/dist/esm/local/client.d.ts +0 -3
  96. package/dist/esm/local/client.js +0 -97
  97. package/dist/esm/local/client.js.map +0 -1
  98. package/dist/esm/remote/client.d.ts +0 -9
  99. package/dist/esm/remote/client.js +0 -41
  100. package/dist/esm/remote/client.js.map +0 -1
  101. package/dist/types/exports/internal.d.ts +0 -5
  102. package/dist/types/exports/internal.d.ts.map +0 -1
  103. package/dist/types/isomorphic/actions/createSession.d.ts +0 -14
  104. package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
  105. package/dist/types/isomorphic/actions/formatSign.d.ts +0 -9
  106. package/dist/types/isomorphic/actions/formatSign.d.ts.map +0 -1
  107. package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -8
  108. package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
  109. package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -8
  110. package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
  111. package/dist/types/isomorphic/actions/prepareSign.d.ts +0 -8
  112. package/dist/types/isomorphic/actions/prepareSign.d.ts.map +0 -1
  113. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
  114. package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
  115. package/dist/types/isomorphic/client.d.ts +0 -276
  116. package/dist/types/isomorphic/client.d.ts.map +0 -1
  117. package/dist/types/isomorphic/utils/7702.d.ts +0 -20
  118. package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
  119. package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
  120. package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
  121. package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
  122. package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
  123. package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
  124. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
  125. package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
  126. package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
  127. package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
  128. package/dist/types/local/client.d.ts +0 -4
  129. package/dist/types/local/client.d.ts.map +0 -1
  130. package/dist/types/remote/client.d.ts +0 -10
  131. package/dist/types/remote/client.d.ts.map +0 -1
  132. package/src/exports/internal.ts +0 -8
  133. package/src/isomorphic/actions/createSession.ts +0 -163
  134. package/src/isomorphic/actions/formatSign.ts +0 -76
  135. package/src/isomorphic/actions/getCallsStatus.ts +0 -112
  136. package/src/isomorphic/actions/prepareCalls.ts +0 -172
  137. package/src/isomorphic/actions/prepareSign.ts +0 -91
  138. package/src/isomorphic/actions/sendPreparedCalls.ts +0 -234
  139. package/src/isomorphic/client.ts +0 -102
  140. package/src/isomorphic/utils/7702.ts +0 -135
  141. package/src/isomorphic/utils/createDummySigner.ts +0 -27
  142. package/src/isomorphic/utils/decodeSignature.ts +0 -21
  143. package/src/isomorphic/utils/parsePermissionsContext.ts +0 -51
  144. package/src/isomorphic/utils/supportsFeature.ts +0 -34
  145. package/src/local/client.ts +0 -136
  146. package/src/remote/client.ts +0 -67
@@ -1,135 +0,0 @@
1
- import type { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
2
- import {
3
- concatHex,
4
- numberToHex,
5
- type Address,
6
- type Chain,
7
- type Transport,
8
- isAddress,
9
- hexToNumber,
10
- } from "viem";
11
- import type { WalletServerViemRpcSchema } from "@alchemy/wallet-api-types/rpc";
12
- import {
13
- Eip7702AccountTypeToDelegationAddress,
14
- SUPPORTED_DELEGATION_ADDRESSES,
15
- type Supported7702AccountType,
16
- type Eip7702AuthCapability,
17
- } from "@alchemy/wallet-api-types/capabilities";
18
- import type { PreparedCall_Authorization } from "@alchemy/wallet-api-types";
19
- import { InvalidRequestError } from "ox/RpcResponse";
20
- import { hashAuthorization } from "viem/utils";
21
-
22
- /** Checks if an address is actively delegated on-chain. */
23
- export const isDelegated = async (
24
- client: SmartAccountClient<
25
- Transport,
26
- Chain,
27
- SmartContractAccount | undefined,
28
- Record<string, unknown>,
29
- WalletServerViemRpcSchema
30
- >,
31
- params: { address: Address; delegation: Address },
32
- ): Promise<boolean> => {
33
- const expectedCode = concatHex(["0xef0100", params.delegation]);
34
- const code = (await client.getCode({ address: params.address })) ?? "0x";
35
- return code.toLowerCase() === expectedCode.toLowerCase();
36
- };
37
-
38
- export const createAuthorizationRequest = async (
39
- client: SmartAccountClient<
40
- Transport,
41
- Chain,
42
- SmartContractAccount | undefined,
43
- Record<string, unknown>,
44
- WalletServerViemRpcSchema
45
- >,
46
- params: { address: Address; delegation: Address },
47
- ): Promise<PreparedCall_Authorization> => {
48
- const data = {
49
- address: params.delegation,
50
- nonce: numberToHex(
51
- await client.getTransactionCount({
52
- address: params.address,
53
- }),
54
- ),
55
- };
56
- return {
57
- type: "authorization" as const,
58
- data,
59
- chainId: numberToHex(client.chain.id),
60
- signatureRequest: {
61
- type: "eip7702Auth" as const,
62
- rawPayload: hashAuthorization({
63
- chainId: client.chain.id,
64
- nonce: hexToNumber(data.nonce),
65
- address: params.delegation,
66
- }),
67
- },
68
- };
69
- };
70
-
71
- export const DelegationAddressToAccountType: Record<
72
- Address,
73
- Supported7702AccountType
74
- > = Object.fromEntries(
75
- Object.entries(Eip7702AccountTypeToDelegationAddress).map(([key, value]) => [
76
- value,
77
- key,
78
- ]),
79
- ) as Record<Address, Supported7702AccountType>;
80
-
81
- export const isSupportedDelegationAddress7702 = (address: Address): boolean => {
82
- return (SUPPORTED_DELEGATION_ADDRESSES as Address[]).includes(address);
83
- };
84
-
85
- export const getAccountTypeForDelegationAddress7702 = (
86
- address: Address,
87
- ): Supported7702AccountType | undefined => {
88
- return DelegationAddressToAccountType[address];
89
- };
90
-
91
- const getDelegationAddressForAccountType7702 = (
92
- accountType: Supported7702AccountType,
93
- ): (typeof SUPPORTED_DELEGATION_ADDRESSES)[number] => {
94
- return Eip7702AccountTypeToDelegationAddress[accountType];
95
- };
96
-
97
- const DEFAULT_7702_DELEGATION_ADDR =
98
- Eip7702AccountTypeToDelegationAddress["ModularAccountV2"];
99
-
100
- export const parseDelegation = (
101
- eip7702AuthCapability: Eip7702AuthCapability,
102
- ) => {
103
- return eip7702AuthCapability === true
104
- ? DEFAULT_7702_DELEGATION_ADDR
105
- : isAddress(eip7702AuthCapability.delegation)
106
- ? eip7702AuthCapability.delegation
107
- : getDelegationAddressForAccountType7702(
108
- eip7702AuthCapability.delegation,
109
- );
110
- };
111
-
112
- export const assertValid7702AccountAddress = (
113
- fromAddress: Address,
114
- eip7702AuthCapability: Eip7702AuthCapability | undefined,
115
- ) => {
116
- if (eip7702AuthCapability) {
117
- if (
118
- typeof eip7702AuthCapability === "object" &&
119
- "account" in eip7702AuthCapability &&
120
- eip7702AuthCapability?.account !== fromAddress
121
- ) {
122
- throw new InvalidRequestError({
123
- message: `EIP-7702 delegation account ${eip7702AuthCapability.account} must match 'from' address ${fromAddress}.`,
124
- });
125
- }
126
-
127
- const delegation = parseDelegation(eip7702AuthCapability);
128
-
129
- if (!isSupportedDelegationAddress7702(delegation)) {
130
- throw new InvalidRequestError({
131
- message: `Unsupported 7702 delegation address: ${delegation}`,
132
- });
133
- }
134
- }
135
- };
@@ -1,27 +0,0 @@
1
- import { type SmartAccountSigner } from "@aa-sdk/core";
2
- import type { TypedData } from "abitype";
3
- import {
4
- BaseError,
5
- type Address,
6
- type Hex,
7
- type SignableMessage,
8
- type TypedDataDefinition,
9
- } from "viem";
10
-
11
- export const createDummySigner = (address: Address): SmartAccountSigner => ({
12
- signerType: "",
13
- inner: undefined,
14
- getAddress: async function (): Promise<`0x${string}`> {
15
- return address;
16
- },
17
- // Not supported on the server
18
- signMessage: function (_message: SignableMessage): Promise<Hex> {
19
- throw new BaseError("signMessage not implemented by dummy signer.");
20
- },
21
- signTypedData: function <
22
- const TTypedData extends TypedData | Record<string, unknown>,
23
- TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData,
24
- >(_params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {
25
- throw new BaseError("signTypedData not implemented by dummy signer.");
26
- },
27
- });
@@ -1,21 +0,0 @@
1
- import { Value } from "@sinclair/typebox/value";
2
- import type { StaticDecode } from "@sinclair/typebox";
3
- import {
4
- TypeEcdsaSig,
5
- type TypeEcdsaSig as TypeEcdsaSigType,
6
- } from "@alchemy/wallet-api-types";
7
- import { assertNever } from "../../utils.js";
8
-
9
- export const decodeSignature = (
10
- signature: TypeEcdsaSigType["signature"],
11
- ): StaticDecode<typeof TypeEcdsaSig>["signature"] => {
12
- switch (signature.type) {
13
- case "ecdsa":
14
- case "secp256k1":
15
- return Value.Decode(TypeEcdsaSig, {
16
- signature,
17
- } satisfies TypeEcdsaSigType).signature;
18
- default:
19
- return assertNever(signature, "Unexpected signature type");
20
- }
21
- };
@@ -1,51 +0,0 @@
1
- import type { StaticDecode } from "@sinclair/typebox";
2
- import { InvalidRequestError } from "ox/RpcResponse";
3
- import type { Address } from "viem";
4
- import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
5
- import {
6
- decodePermissionsContext,
7
- PermissionsCapability,
8
- } from "@alchemy/wallet-api-types/capabilities";
9
- import { TypeSerializedInitcode } from "@alchemy/wallet-api-types";
10
-
11
- export function parsePermissionsContext(
12
- permissions?: StaticDecode<typeof PermissionsCapability>,
13
- parsedCi?: StaticDecode<typeof TypeSerializedInitcode> | undefined,
14
- delegation7702?: Address,
15
- ) {
16
- if (!permissions) {
17
- return undefined;
18
- }
19
-
20
- if ("sessionId" in permissions) {
21
- throw new InvalidRequestError({
22
- message: "Remote permissions are not supported in isomorphic client",
23
- });
24
- }
25
-
26
- if (!("context" in permissions)) {
27
- return undefined;
28
- }
29
-
30
- const isMAV2 =
31
- (parsedCi && parsedCi.factoryType === "MAv2.0.0-sma-b") ||
32
- (delegation7702 &&
33
- getAccountTypeForDelegationAddress7702(delegation7702) ===
34
- "ModularAccountV2");
35
-
36
- if (!isMAV2) {
37
- throw new InvalidRequestError({
38
- message: "Permissions are currently only supported by MAv2 accounts",
39
- });
40
- }
41
-
42
- const context = decodePermissionsContext(permissions);
43
-
44
- if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
45
- throw new InvalidRequestError({
46
- message: "Remote mode deferred action not supported in isomorphic client",
47
- });
48
- }
49
-
50
- return context;
51
- }
@@ -1,34 +0,0 @@
1
- import type { StaticDecode } from "@sinclair/typebox";
2
- import type { TypeSerializedInitcode } from "@alchemy/wallet-api-types";
3
-
4
- export type Feature = "permissions";
5
-
6
- type FactoryType = StaticDecode<typeof TypeSerializedInitcode>["factoryType"];
7
-
8
- const supportedFeatures: Record<FactoryType, Feature[]> = {
9
- "LightAccountV1.0.1": [],
10
- "LightAccountV1.0.2": [],
11
- "LightAccountV1.1.0": [],
12
- "LightAccountV2.0.0": [],
13
- "LightAccountV2.0.0-MultiOwner": [],
14
- "MAv1.0.0-MultiOwner": [],
15
- "MAv1.0.0-MultiSig": [],
16
- "MAv2.0.0-sma-b": ["permissions"],
17
- "MAv2.0.0-ma-ssv": ["permissions"],
18
- "MAv2.0.0-ma-webauthn": [],
19
- unknown: [],
20
- };
21
-
22
- export function supportsFeature(
23
- counterfactualInfo: StaticDecode<typeof TypeSerializedInitcode>,
24
- feature: Feature,
25
- ): boolean {
26
- const factorySupportedFeatures =
27
- supportedFeatures[counterfactualInfo.factoryType];
28
- if (factorySupportedFeatures === undefined) {
29
- throw new Error(
30
- "Unsupported FactoryType: " + counterfactualInfo.factoryType,
31
- );
32
- }
33
- return factorySupportedFeatures.includes(feature);
34
- }
@@ -1,136 +0,0 @@
1
- import { split } from "@aa-sdk/core";
2
- import { buildDeferredActionDigest } from "@account-kit/smart-contracts/experimental";
3
- import { createClient, custom, type Address } from "viem";
4
- import {
5
- encodePermissionsContext,
6
- prefixSignatureKeyType,
7
- } from "@alchemy/wallet-api-types/capabilities";
8
- import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
9
- import { internalStateDecorator } from "../internal/decorator.js";
10
- import type { PrepareCallsParams } from "../isomorphic/actions/prepareCalls.ts";
11
- import {
12
- createIsomorphicClient,
13
- type IsomorphicClient,
14
- } from "../isomorphic/client.js";
15
- import type {
16
- CreateInnerClientParams,
17
- InnerClientActions,
18
- InnerWalletApiClient,
19
- } from "../types.ts";
20
- import { assertNever } from "../utils.js";
21
-
22
- const localMethods = [
23
- "wallet_prepareCalls",
24
- "wallet_sendPreparedCalls",
25
- "wallet_getCallsStatus",
26
- "wallet_createSession",
27
- ] as const satisfies string[];
28
- type LocalMethod = (typeof localMethods)[number];
29
-
30
- export function createLocalClient<
31
- TAccount extends Address | undefined = Address | undefined,
32
- >(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
33
-
34
- export function createLocalClient(
35
- params: CreateInnerClientParams,
36
- ): InnerWalletApiClient {
37
- const { chain, transport, policyId, account } = params;
38
- const isomorphicClient = createIsomorphicClient({
39
- transport,
40
- chain,
41
- policyId,
42
- useErc7677middleware: false,
43
- });
44
-
45
- const clientMap: Record<string, ReturnType<typeof createIsomorphicClient>> = {
46
- [policyId ?? "default"]: isomorphicClient,
47
- };
48
-
49
- const innerTransport = split({
50
- overrides: [
51
- {
52
- methods: localMethods,
53
- transport: custom(
54
- {
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;
62
-
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
- }
74
-
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]);
85
- }
86
- default:
87
- return assertNever(
88
- args.method,
89
- `Unexpected method: ${args.method}`,
90
- );
91
- }
92
- },
93
- },
94
- {
95
- retryCount: 0,
96
- },
97
- ),
98
- },
99
- ],
100
- fallback: transport,
101
- });
102
-
103
- return createClient({
104
- transport: innerTransport,
105
- chain,
106
- account,
107
- })
108
- .extend(() => ({
109
- policyId,
110
- ...innerClientActions(isomorphicClient),
111
- }))
112
- .extend(() => ({
113
- internal: internalStateDecorator(),
114
- }));
115
- }
116
-
117
- const innerClientActions = (
118
- isomorphicClient: IsomorphicClient,
119
- ): InnerClientActions => {
120
- return {
121
- grantPermissions: async (signer, params) => {
122
- const { signatureRequest, fullPreSignatureDeferredActionDigest } =
123
- await isomorphicClient.createSession(params);
124
- const signature = await signSignatureRequest(signer, signatureRequest);
125
- return {
126
- context: encodePermissionsContext({
127
- contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
128
- deferredAction: buildDeferredActionDigest({
129
- fullPreSignatureDeferredActionDigest,
130
- sig: prefixSignatureKeyType(signature.data, signature.type),
131
- }),
132
- }),
133
- };
134
- },
135
- };
136
- };
@@ -1,67 +0,0 @@
1
- import { Provider } from "ox";
2
- import { createClient, custom, type Address } from "viem";
3
- import { encodePermissionsContext } from "@alchemy/wallet-api-types/capabilities";
4
- import { WalletServerRpcSchema } from "@alchemy/wallet-api-types/rpc";
5
- import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
6
- import { internalStateDecorator } from "../internal/decorator.js";
7
- import type {
8
- CreateInnerClientParams,
9
- InnerClientActions,
10
- InnerWalletApiClient,
11
- InnerWalletApiClientBase,
12
- } from "../types.ts";
13
-
14
- /**
15
- * This is a low-level client just used to make RPC requests in remote mode
16
- * This should be wrapped by a higher-level smart account client that provides actions
17
- * that uses this client under the hood
18
- * @returns
19
- */
20
- export function createRemoteClient<
21
- TAccount extends Address | undefined = Address | undefined,
22
- >(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
23
-
24
- export function createRemoteClient(
25
- params: CreateInnerClientParams,
26
- ): InnerWalletApiClient {
27
- const { transport, chain, account } = params;
28
-
29
- const client = createClient({
30
- transport: (opts) =>
31
- custom(Provider.from(transport(opts), { schema: WalletServerRpcSchema }))(
32
- opts,
33
- ),
34
- chain,
35
- account,
36
- })
37
- .extend((_client) => ({
38
- policyId: params.policyId,
39
- ...innerClientActions(_client),
40
- }))
41
- .extend(() => ({
42
- internal: internalStateDecorator(),
43
- }));
44
-
45
- return client;
46
- }
47
-
48
- const innerClientActions = (
49
- apiClient: InnerWalletApiClientBase,
50
- ): InnerClientActions => {
51
- return {
52
- grantPermissions: async (signer, params) => {
53
- const { sessionId, signatureRequest } = await apiClient.request({
54
- method: "wallet_createSession",
55
- params: [params],
56
- });
57
- const signature = await signSignatureRequest(signer, signatureRequest);
58
- return {
59
- context: encodePermissionsContext({
60
- contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
61
- sessionId,
62
- signature: signature.data,
63
- }),
64
- };
65
- },
66
- };
67
- };