@account-kit/wallet-client 0.1.0-alpha.1 → 0.1.0-alpha.11
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/createAccount.d.ts +27 -2
- package/dist/esm/client/actions/createAccount.js +25 -0
- package/dist/esm/client/actions/createAccount.js.map +1 -1
- package/dist/esm/client/actions/formatSign.d.ts +28 -0
- package/dist/esm/client/actions/formatSign.js +30 -0
- package/dist/esm/client/actions/formatSign.js.map +1 -0
- package/dist/esm/client/actions/getCallsStatus.d.ts +22 -4
- package/dist/esm/client/actions/getCallsStatus.js +19 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +63 -6
- package/dist/esm/client/actions/grantPermissions.js +63 -3
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/listAccounts.d.ts +32 -4
- package/dist/esm/client/actions/listAccounts.js +35 -2
- package/dist/esm/client/actions/listAccounts.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +32 -6
- package/dist/esm/client/actions/prepareCalls.js +39 -5
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +25 -0
- package/dist/esm/client/actions/prepareSign.js +28 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -0
- package/dist/esm/client/actions/requestAccount.d.ts +24 -6
- package/dist/esm/client/actions/requestAccount.js +38 -7
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/sendPreparedCalls.d.ts +33 -4
- package/dist/esm/client/actions/sendPreparedCalls.js +37 -1
- package/dist/esm/client/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/client/actions/signMessage.d.ts +25 -5
- package/dist/esm/client/actions/signMessage.js +22 -2
- package/dist/esm/client/actions/signMessage.js.map +1 -1
- package/dist/esm/client/actions/signPreparedCalls.d.ts +14 -0
- package/dist/esm/client/actions/signPreparedCalls.js +43 -0
- package/dist/esm/client/actions/signPreparedCalls.js.map +1 -0
- package/dist/esm/client/actions/signSignatureRequest.d.ts +39 -5
- package/dist/esm/client/actions/signSignatureRequest.js +69 -11
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/actions/signTypedData.d.ts +37 -4
- package/dist/esm/client/actions/signTypedData.js +34 -1
- package/dist/esm/client/actions/signTypedData.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +249 -45
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/decorator.d.ts +12 -8
- package/dist/esm/client/decorator.js +5 -3
- package/dist/esm/client/decorator.js.map +1 -1
- package/dist/esm/client/index.d.ts +38 -12
- package/dist/esm/client/index.js +0 -3
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/exports/index.d.ts +5 -6
- package/dist/esm/exports/index.js +4 -6
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.d.ts +1 -10
- package/dist/esm/exports/internal.js +0 -12
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/internal/decorator.d.ts +2 -0
- package/dist/esm/internal/decorator.js +10 -0
- package/dist/esm/internal/decorator.js.map +1 -0
- package/dist/esm/isomorphic/actions/createSession.d.ts +1 -2
- package/dist/esm/isomorphic/actions/createSession.js +40 -11
- package/dist/esm/isomorphic/actions/createSession.js.map +1 -1
- package/dist/esm/isomorphic/actions/formatSign.d.ts +8 -0
- package/dist/esm/isomorphic/actions/formatSign.js +42 -0
- package/dist/esm/isomorphic/actions/formatSign.js.map +1 -0
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +1 -15
- package/dist/esm/isomorphic/actions/getCallsStatus.js +38 -27
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +1 -2
- package/dist/esm/isomorphic/actions/prepareCalls.js +78 -20
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +1 -1
- package/dist/esm/isomorphic/actions/prepareSign.d.ts +7 -0
- package/dist/esm/isomorphic/actions/prepareSign.js +49 -0
- package/dist/esm/isomorphic/actions/prepareSign.js.map +1 -0
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +165 -25
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/isomorphic/client.d.ts +204 -27
- package/dist/esm/isomorphic/client.js +6 -2
- package/dist/esm/isomorphic/client.js.map +1 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +19 -0
- package/dist/esm/isomorphic/utils/7702.js +70 -0
- package/dist/esm/isomorphic/utils/7702.js.map +1 -0
- package/dist/esm/isomorphic/utils/createAccount.d.ts +5 -4
- package/dist/esm/isomorphic/utils/createAccount.js +84 -10
- package/dist/esm/isomorphic/utils/createAccount.js.map +1 -1
- package/dist/esm/isomorphic/utils/createDummySigner.js +3 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +1 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +3 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js +15 -0
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +1 -0
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +19 -6
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +1 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +4 -0
- package/dist/esm/isomorphic/utils/supportsFeature.js +21 -0
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +1 -0
- package/dist/esm/local/client.d.ts +3 -3
- package/dist/esm/local/client.js +11 -4
- package/dist/esm/local/client.js.map +1 -1
- package/dist/esm/remote/client.d.ts +9 -3
- package/dist/esm/remote/client.js +10 -11
- package/dist/esm/remote/client.js.map +1 -1
- package/dist/esm/types.d.ts +27 -13
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/client/actions/createAccount.d.ts +27 -2
- package/dist/types/client/actions/createAccount.d.ts.map +1 -1
- package/dist/types/client/actions/formatSign.d.ts +29 -0
- package/dist/types/client/actions/formatSign.d.ts.map +1 -0
- package/dist/types/client/actions/getCallsStatus.d.ts +22 -4
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +63 -6
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/listAccounts.d.ts +32 -4
- package/dist/types/client/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +32 -6
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +26 -0
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/client/actions/requestAccount.d.ts +24 -6
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/sendPreparedCalls.d.ts +33 -4
- package/dist/types/client/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/client/actions/signMessage.d.ts +25 -5
- package/dist/types/client/actions/signMessage.d.ts.map +1 -1
- package/dist/types/client/actions/signPreparedCalls.d.ts +15 -0
- package/dist/types/client/actions/signPreparedCalls.d.ts.map +1 -0
- package/dist/types/client/actions/signSignatureRequest.d.ts +39 -5
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/actions/signTypedData.d.ts +37 -4
- package/dist/types/client/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client/decorator.d.ts +12 -8
- package/dist/types/client/decorator.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +38 -12
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +5 -6
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +1 -10
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/internal/decorator.d.ts +3 -0
- package/dist/types/internal/decorator.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/createSession.d.ts +1 -2
- package/dist/types/isomorphic/actions/createSession.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/formatSign.d.ts +9 -0
- package/dist/types/isomorphic/actions/formatSign.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +1 -15
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +1 -2
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/actions/prepareSign.d.ts +8 -0
- package/dist/types/isomorphic/actions/prepareSign.d.ts.map +1 -0
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +3 -4
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/isomorphic/client.d.ts +204 -27
- package/dist/types/isomorphic/client.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/7702.d.ts +20 -0
- package/dist/types/isomorphic/utils/7702.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/createAccount.d.ts +5 -4
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +4 -0
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +1 -0
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +6 -5
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +1 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +5 -0
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +1 -0
- package/dist/types/local/client.d.ts +3 -3
- package/dist/types/local/client.d.ts.map +1 -1
- package/dist/types/remote/client.d.ts +9 -3
- package/dist/types/remote/client.d.ts.map +1 -1
- package/dist/types/types.d.ts +27 -13
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/client/actions/createAccount.ts +27 -2
- package/src/client/actions/formatSign.ts +53 -0
- package/src/client/actions/getCallsStatus.ts +21 -12
- package/src/client/actions/grantPermissions.ts +69 -26
- package/src/client/actions/listAccounts.ts +44 -6
- package/src/client/actions/prepareCalls.ts +46 -26
- package/src/client/actions/prepareSign.ts +46 -0
- package/src/client/actions/requestAccount.ts +60 -41
- package/src/client/actions/sendPreparedCalls.ts +44 -7
- package/src/client/actions/signMessage.ts +26 -21
- package/src/client/actions/signPreparedCalls.ts +67 -0
- package/src/client/actions/signSignatureRequest.ts +84 -20
- package/src/client/actions/signTypedData.ts +40 -19
- package/src/client/client.e2e-test.ts +408 -127
- package/src/client/decorator.ts +28 -26
- package/src/client/index.ts +50 -40
- package/src/exports/index.ts +5 -13
- package/src/exports/internal.ts +2 -10
- package/src/internal/decorator.ts +12 -0
- package/src/isomorphic/actions/createSession.ts +56 -13
- package/src/isomorphic/actions/formatSign.ts +76 -0
- package/src/isomorphic/actions/getCallsStatus.ts +47 -33
- package/src/isomorphic/actions/prepareCalls.ts +95 -23
- package/src/isomorphic/actions/prepareSign.ts +88 -0
- package/src/isomorphic/actions/sendPreparedCalls.ts +218 -42
- package/src/isomorphic/client.ts +10 -2
- package/src/isomorphic/utils/7702.ts +135 -0
- package/src/isomorphic/utils/createAccount.ts +101 -13
- package/src/isomorphic/utils/createDummySigner.ts +3 -2
- package/src/isomorphic/utils/decodeSignature.ts +21 -0
- package/src/isomorphic/utils/parsePermissionsContext.ts +29 -11
- package/src/isomorphic/utils/supportsFeature.ts +34 -0
- package/src/local/client.ts +58 -55
- package/src/remote/client.ts +19 -19
- package/src/types.ts +29 -23
- package/src/utils.ts +2 -0
- package/dist/esm/capabilities/index.d.ts +0 -31
- package/dist/esm/capabilities/index.js +0 -10
- package/dist/esm/capabilities/index.js.map +0 -1
- package/dist/esm/capabilities/overrides.d.ts +0 -26
- package/dist/esm/capabilities/overrides.js +0 -14
- package/dist/esm/capabilities/overrides.js.map +0 -1
- package/dist/esm/capabilities/paymaster.d.ts +0 -3
- package/dist/esm/capabilities/paymaster.js +0 -5
- package/dist/esm/capabilities/paymaster.js.map +0 -1
- package/dist/esm/capabilities/permissions/index.d.ts +0 -138
- package/dist/esm/capabilities/permissions/index.js +0 -71
- package/dist/esm/capabilities/permissions/index.js.map +0 -1
- package/dist/esm/capabilities/permissions/mav2.d.ts +0 -36
- package/dist/esm/capabilities/permissions/mav2.js +0 -79
- package/dist/esm/capabilities/permissions/mav2.js.map +0 -1
- package/dist/esm/rpc/request.d.ts +0 -352
- package/dist/esm/rpc/request.js +0 -204
- package/dist/esm/rpc/request.js.map +0 -1
- package/dist/esm/rpc/schema.d.ts +0 -342
- package/dist/esm/rpc/schema.js +0 -5
- package/dist/esm/rpc/schema.js.map +0 -1
- package/dist/esm/schemas.d.ts +0 -216
- package/dist/esm/schemas.js +0 -211
- package/dist/esm/schemas.js.map +0 -1
- package/dist/types/capabilities/index.d.ts +0 -32
- package/dist/types/capabilities/index.d.ts.map +0 -1
- package/dist/types/capabilities/overrides.d.ts +0 -27
- package/dist/types/capabilities/overrides.d.ts.map +0 -1
- package/dist/types/capabilities/paymaster.d.ts +0 -4
- package/dist/types/capabilities/paymaster.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/index.d.ts +0 -139
- package/dist/types/capabilities/permissions/index.d.ts.map +0 -1
- package/dist/types/capabilities/permissions/mav2.d.ts +0 -37
- package/dist/types/capabilities/permissions/mav2.d.ts.map +0 -1
- package/dist/types/rpc/request.d.ts +0 -353
- package/dist/types/rpc/request.d.ts.map +0 -1
- package/dist/types/rpc/schema.d.ts +0 -343
- package/dist/types/rpc/schema.d.ts.map +0 -1
- package/dist/types/schemas.d.ts +0 -217
- package/dist/types/schemas.d.ts.map +0 -1
- package/src/capabilities/index.ts +0 -13
- package/src/capabilities/overrides.ts +0 -20
- package/src/capabilities/paymaster.ts +0 -5
- package/src/capabilities/permissions/index.ts +0 -142
- package/src/capabilities/permissions/mav2.ts +0 -127
- package/src/rpc/request.ts +0 -273
- package/src/rpc/schema.ts +0 -40
- package/src/schemas.ts +0 -257
|
@@ -0,0 +1,135 @@
|
|
|
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,22 +1,29 @@
|
|
|
1
1
|
import type { SmartAccountSigner, SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import {
|
|
3
|
+
createLightAccount,
|
|
3
4
|
createModularAccountV2,
|
|
5
|
+
createMultiOwnerLightAccount,
|
|
6
|
+
createMultiOwnerModularAccount,
|
|
4
7
|
type ModularAccountV2,
|
|
5
8
|
} from "@account-kit/smart-contracts";
|
|
6
9
|
import type { StaticDecode } from "@sinclair/typebox";
|
|
7
10
|
import type { Address, Chain, Transport } from "viem";
|
|
8
11
|
import { concatHex, hexToNumber } from "viem";
|
|
9
|
-
import type { Capabilities } from "../../capabilities/index.js";
|
|
10
|
-
import type { TypeSerializedInitcode } from "../../schemas.js";
|
|
11
12
|
import { parsePermissionsContext } from "./parsePermissionsContext.js";
|
|
13
|
+
import { assertNever } from "../../utils.js";
|
|
14
|
+
import { getAccountTypeForDelegationAddress7702 } from "./7702.js";
|
|
15
|
+
import { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
16
|
+
import { PermissionsCapability } from "@alchemy/wallet-api-types/capabilities";
|
|
17
|
+
import { InternalError, InvalidRequestError } from "ox/RpcResponse";
|
|
12
18
|
|
|
13
19
|
type CreateAccountParams = {
|
|
14
20
|
chain: Chain;
|
|
15
21
|
transport: Transport;
|
|
16
22
|
signer: SmartAccountSigner;
|
|
17
23
|
accountAddress: Address;
|
|
18
|
-
counterfactualInfo
|
|
19
|
-
|
|
24
|
+
counterfactualInfo?: StaticDecode<typeof SerializedInitcode>; // undefined for 7702 accounts
|
|
25
|
+
permissions?: StaticDecode<typeof PermissionsCapability>;
|
|
26
|
+
delegation?: Address;
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
/**
|
|
@@ -28,12 +35,14 @@ export async function createAccount(
|
|
|
28
35
|
params: CreateAccountParams,
|
|
29
36
|
): Promise<SmartContractAccount> {
|
|
30
37
|
const { counterfactualInfo: ci, ...accountParams } = params;
|
|
31
|
-
// TODO: Implement support for other account types.
|
|
32
|
-
if (ci.factoryType !== "MAv2.0.0-sma-b") {
|
|
33
|
-
throw new Error("Only MAv2 SMA-B accounts are currently supported");
|
|
34
|
-
}
|
|
35
38
|
|
|
36
|
-
|
|
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
|
+
);
|
|
37
46
|
|
|
38
47
|
const signerEntity =
|
|
39
48
|
parsedContext?.contextVersion === "NON_DEFERRED_ACTION"
|
|
@@ -43,12 +52,91 @@ export async function createAccount(
|
|
|
43
52
|
}
|
|
44
53
|
: undefined;
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
const mode = params.delegation ? "7702" : "default";
|
|
56
|
+
|
|
57
|
+
if (mode === "7702") {
|
|
58
|
+
const accountType = getAccountTypeForDelegationAddress7702(
|
|
59
|
+
params.delegation!,
|
|
60
|
+
);
|
|
61
|
+
if (accountType !== "ModularAccountV2") {
|
|
62
|
+
throw new Error("7702 mode currently only supports ModularAccountV2");
|
|
63
|
+
}
|
|
64
|
+
return createModularAccountV2({
|
|
65
|
+
...accountParams,
|
|
66
|
+
signerEntity,
|
|
67
|
+
deferredAction: parsedContext?.deferredAction,
|
|
68
|
+
mode,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
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
|
+
if (!ci) {
|
|
80
|
+
throw new InternalError({
|
|
81
|
+
message: "Counterfactual info not found",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const factoryType = ci.factoryType;
|
|
86
|
+
const commonParams = {
|
|
47
87
|
...accountParams,
|
|
48
|
-
signerEntity,
|
|
49
|
-
deferredAction: parsedContext?.deferredAction,
|
|
50
88
|
initCode: concatHex([ci.factoryAddress, ci.factoryData]),
|
|
51
|
-
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Return the account created based on the factory type
|
|
92
|
+
switch (factoryType) {
|
|
93
|
+
case "MAv2.0.0-sma-b":
|
|
94
|
+
return createModularAccountV2({
|
|
95
|
+
...commonParams,
|
|
96
|
+
signerEntity,
|
|
97
|
+
deferredAction: parsedContext?.deferredAction,
|
|
98
|
+
mode,
|
|
99
|
+
});
|
|
100
|
+
case "LightAccountV2.0.0":
|
|
101
|
+
return createLightAccount({
|
|
102
|
+
...commonParams,
|
|
103
|
+
version: "v2.0.0",
|
|
104
|
+
});
|
|
105
|
+
case "LightAccountV1.0.1":
|
|
106
|
+
return createLightAccount({
|
|
107
|
+
...commonParams,
|
|
108
|
+
version: "v1.0.1",
|
|
109
|
+
});
|
|
110
|
+
case "LightAccountV1.0.2":
|
|
111
|
+
return createLightAccount({
|
|
112
|
+
...commonParams,
|
|
113
|
+
version: "v1.0.2",
|
|
114
|
+
});
|
|
115
|
+
case "LightAccountV1.1.0":
|
|
116
|
+
return createLightAccount({
|
|
117
|
+
...commonParams,
|
|
118
|
+
version: "v1.1.0",
|
|
119
|
+
});
|
|
120
|
+
case "MAv1.0.0-MultiOwner":
|
|
121
|
+
return createMultiOwnerModularAccount({
|
|
122
|
+
...commonParams,
|
|
123
|
+
});
|
|
124
|
+
case "LightAccountV2.0.0-MultiOwner":
|
|
125
|
+
return createMultiOwnerLightAccount({
|
|
126
|
+
...commonParams,
|
|
127
|
+
version: "v2.0.0",
|
|
128
|
+
});
|
|
129
|
+
case "MAv1.0.0-MultiSig":
|
|
130
|
+
case "MAv2.0.0-ma-ssv":
|
|
131
|
+
case "MAv2.0.0-ma-webauthn":
|
|
132
|
+
case "unknown":
|
|
133
|
+
case undefined:
|
|
134
|
+
throw new InvalidRequestError({
|
|
135
|
+
message: `Account type currently unsupported: ${factoryType}`,
|
|
136
|
+
});
|
|
137
|
+
default:
|
|
138
|
+
return assertNever(factoryType, "Unsupported factory type");
|
|
139
|
+
}
|
|
52
140
|
}
|
|
53
141
|
|
|
54
142
|
export function isModularAccountV2(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type SmartAccountSigner } from "@aa-sdk/core";
|
|
2
2
|
import type { TypedData } from "abitype";
|
|
3
3
|
import {
|
|
4
|
+
BaseError,
|
|
4
5
|
type Address,
|
|
5
6
|
type Hex,
|
|
6
7
|
type SignableMessage,
|
|
@@ -15,12 +16,12 @@ export const createDummySigner = (address: Address): SmartAccountSigner => ({
|
|
|
15
16
|
},
|
|
16
17
|
// Not supported on the server
|
|
17
18
|
signMessage: function (_message: SignableMessage): Promise<Hex> {
|
|
18
|
-
throw new
|
|
19
|
+
throw new BaseError("signMessage not implemented by dummy signer.");
|
|
19
20
|
},
|
|
20
21
|
signTypedData: function <
|
|
21
22
|
const TTypedData extends TypedData | Record<string, unknown>,
|
|
22
23
|
TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData,
|
|
23
24
|
>(_params: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex> {
|
|
24
|
-
throw new
|
|
25
|
+
throw new BaseError("signTypedData not implemented by dummy signer.");
|
|
25
26
|
},
|
|
26
27
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Value } from "@sinclair/typebox/value";
|
|
2
|
+
import type { StaticDecode } from "@sinclair/typebox";
|
|
3
|
+
import {
|
|
4
|
+
EcdsaSig,
|
|
5
|
+
type EcdsaSig as EcdsaSigType,
|
|
6
|
+
} from "@alchemy/wallet-api-types";
|
|
7
|
+
import { assertNever } from "../../utils.js";
|
|
8
|
+
|
|
9
|
+
export const decodeSignature = (
|
|
10
|
+
signature: EcdsaSigType["signature"],
|
|
11
|
+
): StaticDecode<typeof EcdsaSig>["signature"] => {
|
|
12
|
+
switch (signature.type) {
|
|
13
|
+
case "ecdsa":
|
|
14
|
+
case "secp256k1":
|
|
15
|
+
return Value.Decode(EcdsaSig, {
|
|
16
|
+
signature,
|
|
17
|
+
} satisfies EcdsaSigType).signature;
|
|
18
|
+
default:
|
|
19
|
+
return assertNever(signature, "Unexpected signature type");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
import type { StaticDecode } from "@sinclair/typebox";
|
|
2
2
|
import { InvalidRequestError } from "ox/RpcResponse";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
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 { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
6
10
|
|
|
7
11
|
export function parsePermissionsContext(
|
|
8
|
-
|
|
9
|
-
parsedCi
|
|
12
|
+
permissions?: StaticDecode<typeof PermissionsCapability>,
|
|
13
|
+
parsedCi?: StaticDecode<typeof SerializedInitcode> | undefined,
|
|
14
|
+
delegation7702?: Address,
|
|
10
15
|
) {
|
|
11
|
-
if (!
|
|
16
|
+
if (!permissions) {
|
|
12
17
|
return undefined;
|
|
13
18
|
}
|
|
14
19
|
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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) {
|
|
19
37
|
throw new InvalidRequestError({
|
|
20
38
|
message: "Permissions are currently only supported by MAv2 accounts",
|
|
21
39
|
});
|
|
22
40
|
}
|
|
23
41
|
|
|
24
|
-
const context = decodePermissionsContext(
|
|
42
|
+
const context = decodePermissionsContext(permissions);
|
|
25
43
|
|
|
26
44
|
if (context?.contextVersion === "REMOTE_MODE_DEFERRED_ACTION") {
|
|
27
45
|
throw new InvalidRequestError({
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { StaticDecode } from "@sinclair/typebox";
|
|
2
|
+
import type { SerializedInitcode } from "@alchemy/wallet-api-types";
|
|
3
|
+
|
|
4
|
+
export type Feature = "permissions";
|
|
5
|
+
|
|
6
|
+
type FactoryType = StaticDecode<typeof SerializedInitcode>["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 SerializedInitcode>,
|
|
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
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { split } from "@aa-sdk/core";
|
|
2
2
|
import { buildDeferredActionDigest } from "@account-kit/smart-contracts/experimental";
|
|
3
|
-
import { createClient, custom, type Address
|
|
3
|
+
import { createClient, custom, type Address } from "viem";
|
|
4
4
|
import {
|
|
5
5
|
encodePermissionsContext,
|
|
6
6
|
prefixSignatureKeyType,
|
|
7
|
-
} from "
|
|
7
|
+
} from "@alchemy/wallet-api-types/capabilities";
|
|
8
8
|
import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
9
|
-
import
|
|
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 = [
|
|
@@ -27,10 +28,8 @@ const localMethods = [
|
|
|
27
28
|
type LocalMethod = (typeof localMethods)[number];
|
|
28
29
|
|
|
29
30
|
export function createLocalClient<
|
|
30
|
-
TAccount extends
|
|
31
|
-
|
|
32
|
-
| undefined,
|
|
33
|
-
>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient<TAccount>;
|
|
31
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
32
|
+
>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
|
|
34
33
|
|
|
35
34
|
export function createLocalClient(
|
|
36
35
|
params: CreateInnerClientParams,
|
|
@@ -51,46 +50,51 @@ export function createLocalClient(
|
|
|
51
50
|
overrides: [
|
|
52
51
|
{
|
|
53
52
|
methods: localMethods,
|
|
54
|
-
transport: custom(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
);
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
return assertNever(
|
|
88
|
-
args.method,
|
|
89
|
-
`Unexpected method: ${args.method}`,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
+
},
|
|
92
93
|
},
|
|
93
|
-
|
|
94
|
+
{
|
|
95
|
+
retryCount: 0,
|
|
96
|
+
},
|
|
97
|
+
),
|
|
94
98
|
},
|
|
95
99
|
],
|
|
96
100
|
fallback: transport,
|
|
@@ -100,10 +104,14 @@ export function createLocalClient(
|
|
|
100
104
|
transport: innerTransport,
|
|
101
105
|
chain,
|
|
102
106
|
account,
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
})
|
|
108
|
+
.extend(() => ({
|
|
109
|
+
policyId,
|
|
110
|
+
...innerClientActions(isomorphicClient),
|
|
111
|
+
}))
|
|
112
|
+
.extend(() => ({
|
|
113
|
+
internal: internalStateDecorator(),
|
|
114
|
+
}));
|
|
107
115
|
}
|
|
108
116
|
|
|
109
117
|
const innerClientActions = (
|
|
@@ -113,18 +121,13 @@ const innerClientActions = (
|
|
|
113
121
|
grantPermissions: async (signer, params) => {
|
|
114
122
|
const { signatureRequest, fullPreSignatureDeferredActionDigest } =
|
|
115
123
|
await isomorphicClient.createSession(params);
|
|
116
|
-
|
|
117
|
-
const { signature } = await signSignatureRequest(
|
|
118
|
-
signer,
|
|
119
|
-
signatureRequest,
|
|
120
|
-
);
|
|
121
|
-
|
|
124
|
+
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
122
125
|
return {
|
|
123
126
|
context: encodePermissionsContext({
|
|
124
127
|
contextVersion: "LOCAL_MODE_DEFERRED_ACTION",
|
|
125
128
|
deferredAction: buildDeferredActionDigest({
|
|
126
129
|
fullPreSignatureDeferredActionDigest,
|
|
127
|
-
sig: prefixSignatureKeyType(signature,
|
|
130
|
+
sig: prefixSignatureKeyType(signature.data, signature.type),
|
|
128
131
|
}),
|
|
129
132
|
}),
|
|
130
133
|
};
|
package/src/remote/client.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { Provider } from "ox";
|
|
2
|
-
import { createClient, custom, type Address
|
|
3
|
-
import { encodePermissionsContext } from "
|
|
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";
|
|
4
5
|
import { signSignatureRequest } from "../client/actions/signSignatureRequest.js";
|
|
5
|
-
import {
|
|
6
|
+
import { internalStateDecorator } from "../internal/decorator.js";
|
|
6
7
|
import type {
|
|
7
8
|
CreateInnerClientParams,
|
|
8
9
|
InnerClientActions,
|
|
9
10
|
InnerWalletApiClient,
|
|
10
11
|
InnerWalletApiClientBase,
|
|
11
|
-
} from "../types";
|
|
12
|
-
|
|
13
|
-
export function createRemoteClient<
|
|
14
|
-
TAccount extends JsonRpcAccount<Address> | undefined =
|
|
15
|
-
| JsonRpcAccount<Address>
|
|
16
|
-
| undefined,
|
|
17
|
-
>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient<TAccount>;
|
|
12
|
+
} from "../types.ts";
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
15
|
* This is a low-level client just used to make RPC requests in remote mode
|
|
@@ -22,6 +17,10 @@ export function createRemoteClient<
|
|
|
22
17
|
* that uses this client under the hood
|
|
23
18
|
* @returns
|
|
24
19
|
*/
|
|
20
|
+
export function createRemoteClient<
|
|
21
|
+
TAccount extends Address | undefined = Address | undefined,
|
|
22
|
+
>(params: CreateInnerClientParams<TAccount>): InnerWalletApiClient;
|
|
23
|
+
|
|
25
24
|
export function createRemoteClient(
|
|
26
25
|
params: CreateInnerClientParams,
|
|
27
26
|
): InnerWalletApiClient {
|
|
@@ -34,10 +33,14 @@ export function createRemoteClient(
|
|
|
34
33
|
),
|
|
35
34
|
chain,
|
|
36
35
|
account,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
})
|
|
37
|
+
.extend((_client) => ({
|
|
38
|
+
policyId: params.policyId,
|
|
39
|
+
...innerClientActions(_client),
|
|
40
|
+
}))
|
|
41
|
+
.extend(() => ({
|
|
42
|
+
internal: internalStateDecorator(),
|
|
43
|
+
}));
|
|
41
44
|
|
|
42
45
|
return client;
|
|
43
46
|
}
|
|
@@ -51,15 +54,12 @@ const innerClientActions = (
|
|
|
51
54
|
method: "wallet_createSession",
|
|
52
55
|
params: [params],
|
|
53
56
|
});
|
|
54
|
-
const
|
|
55
|
-
signer,
|
|
56
|
-
signatureRequest,
|
|
57
|
-
);
|
|
57
|
+
const signature = await signSignatureRequest(signer, signatureRequest);
|
|
58
58
|
return {
|
|
59
59
|
context: encodePermissionsContext({
|
|
60
60
|
contextVersion: "REMOTE_MODE_DEFERRED_ACTION",
|
|
61
61
|
sessionId,
|
|
62
|
-
signature,
|
|
62
|
+
signature: signature.data,
|
|
63
63
|
}),
|
|
64
64
|
};
|
|
65
65
|
},
|