@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.
- package/dist/esm/client/actions/getCallsStatus.d.ts +4 -3
- package/dist/esm/client/actions/getCallsStatus.js +1 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +5 -4
- package/dist/esm/client/actions/grantPermissions.js +21 -5
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +4 -3
- package/dist/esm/client/actions/prepareCalls.js +1 -0
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +4 -3
- package/dist/esm/client/actions/prepareSign.js +1 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.js +3 -3
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +190 -329
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/index.d.ts +1 -4
- package/dist/esm/client/index.js +13 -18
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +3 -7
- package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +9 -33
- package/dist/esm/internal/account.js.map +1 -0
- package/dist/esm/types.d.ts +2 -8
- package/dist/esm/types.js.map +1 -1
- package/dist/types/client/actions/getCallsStatus.d.ts +4 -3
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +5 -4
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +4 -3
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +4 -3
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -4
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +4 -8
- package/dist/types/internal/account.d.ts.map +1 -0
- package/dist/types/types.d.ts +2 -8
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +3 -8
- package/src/client/actions/getCallsStatus.ts +8 -6
- package/src/client/actions/grantPermissions.ts +41 -10
- package/src/client/actions/prepareCalls.ts +11 -6
- package/src/client/actions/prepareSign.ts +9 -6
- package/src/client/actions/requestAccount.ts +3 -3
- package/src/client/actions/signSignatureRequest.ts +8 -8
- package/src/client/client.e2e-test.ts +143 -298
- package/src/client/index.ts +22 -23
- package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +11 -51
- package/src/types.ts +4 -15
- package/dist/esm/exports/internal.d.ts +0 -4
- package/dist/esm/exports/internal.js +0 -3
- package/dist/esm/exports/internal.js.map +0 -1
- package/dist/esm/isomorphic/actions/createSession.d.ts +0 -13
- package/dist/esm/isomorphic/actions/createSession.js +0 -94
- package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
- package/dist/esm/isomorphic/actions/formatSign.d.ts +0 -8
- package/dist/esm/isomorphic/actions/formatSign.js +0 -42
- package/dist/esm/isomorphic/actions/formatSign.js.map +0 -1
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -7
- package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -71
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -7
- package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareSign.d.ts +0 -7
- package/dist/esm/isomorphic/actions/prepareSign.js +0 -49
- package/dist/esm/isomorphic/actions/prepareSign.js.map +0 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -7
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -156
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
- package/dist/esm/isomorphic/client.d.ts +0 -275
- package/dist/esm/isomorphic/client.js +0 -41
- package/dist/esm/isomorphic/client.js.map +0 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +0 -19
- package/dist/esm/isomorphic/utils/7702.js +0 -70
- package/dist/esm/isomorphic/utils/7702.js.map +0 -1
- package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
- package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
- package/dist/esm/isomorphic/utils/decodeSignature.js +0 -15
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
- package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
- package/dist/esm/local/client.d.ts +0 -3
- package/dist/esm/local/client.js +0 -97
- package/dist/esm/local/client.js.map +0 -1
- package/dist/esm/remote/client.d.ts +0 -9
- package/dist/esm/remote/client.js +0 -41
- package/dist/esm/remote/client.js.map +0 -1
- package/dist/types/exports/internal.d.ts +0 -5
- package/dist/types/exports/internal.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/createSession.d.ts +0 -14
- package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/formatSign.d.ts +0 -9
- package/dist/types/isomorphic/actions/formatSign.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -8
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -8
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareSign.d.ts +0 -8
- package/dist/types/isomorphic/actions/prepareSign.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/client.d.ts +0 -276
- package/dist/types/isomorphic/client.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/7702.d.ts +0 -20
- package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
- package/dist/types/local/client.d.ts +0 -4
- package/dist/types/local/client.d.ts.map +0 -1
- package/dist/types/remote/client.d.ts +0 -10
- package/dist/types/remote/client.d.ts.map +0 -1
- package/src/exports/internal.ts +0 -8
- package/src/isomorphic/actions/createSession.ts +0 -163
- package/src/isomorphic/actions/formatSign.ts +0 -76
- package/src/isomorphic/actions/getCallsStatus.ts +0 -112
- package/src/isomorphic/actions/prepareCalls.ts +0 -172
- package/src/isomorphic/actions/prepareSign.ts +0 -91
- package/src/isomorphic/actions/sendPreparedCalls.ts +0 -234
- package/src/isomorphic/client.ts +0 -102
- package/src/isomorphic/utils/7702.ts +0 -135
- package/src/isomorphic/utils/createDummySigner.ts +0 -27
- package/src/isomorphic/utils/decodeSignature.ts +0 -21
- package/src/isomorphic/utils/parsePermissionsContext.ts +0 -51
- package/src/isomorphic/utils/supportsFeature.ts +0 -34
- package/src/local/client.ts +0 -136
- 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
|
-
}
|
package/src/local/client.ts
DELETED
|
@@ -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
|
-
};
|
package/src/remote/client.ts
DELETED
|
@@ -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
|
-
};
|