Skip to content

Commit c9b9e82

Browse files
linnalldslovinskydphilipsonAlchemy Botblakecduncan
committed
feat: enables installValidation to take a Modular Account with no signer (#1663)
* fix: run api spec generate as part of aa-sdk deploy (#1654) * fix: run api spec generate as part of aa-sdk deploy * ci: create aa-sdk copy of setup-pnpm composite action * ci: remove unnecessary install node in pnpm composite action * ci: try installing pnpm with exact action version * ci: test with pnpm moved out of its own composite * ci: fuck you install pnpm * ci: ?????? * revert: install pnpm in its own setup composite * ci: specify package.json for pnpm --------- Co-authored-by: dslovinsky <[email protected]> * feat(rn-signer): support passkeys in React Native (#1653) * chore(release): publish v4.37.0 [skip-ci] * feat: add erc20 sponsorship card (#1631) * fix: remove trailing slash from alchemy rpc url (#1657) * chore(release): publish v4.38.0 [skip-ci] * fix: update copy (#1658) * feat: add alchemy_requestPaymasterTokenQuote to aa-sdk (#1659) * feat: add alchemy_requestPaymasterTokenQuote to aa-sdk * fix: typo * chore(release): publish v4.39.0 [skip-ci] * feat: enables installValidation to take a Modular Account with no signer * fix: test thank you howy * test: update the rundler version we use in prool (#1646) * chore: experimenting with types (#1665) * chore: modifies types --------- Co-authored-by: Daniel Slovinsky <[email protected]> Co-authored-by: dslovinsky <[email protected]> Co-authored-by: David Philipson <[email protected]> Co-authored-by: Alchemy Bot <[email protected]> Co-authored-by: Blake Duncan <[email protected]> Co-authored-by: jakehobbs <[email protected]> Co-authored-by: Andy <[email protected]> Co-authored-by: Michael Moldoveanu <[email protected]> Co-authored-by: howy <[email protected]>
1 parent c375b00 commit c9b9e82

File tree

3 files changed

+191
-92
lines changed

3 files changed

+191
-92
lines changed

account-kit/smart-contracts/src/ma-v2/actions/install-validation/installValidation.ts

Lines changed: 113 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type SendUserOperationResult,
88
type UserOperationOverridesParameter,
99
type SmartAccountSigner,
10+
isSmartAccountWithSigner,
1011
} from "@aa-sdk/core";
1112
import {
1213
type Address,
@@ -24,12 +25,20 @@ import {
2425
serializeModuleEntity,
2526
} from "../common/utils.js";
2627

27-
import { type ModularAccountV2Client } from "../../client/client.js";
28-
import { type ModularAccountV2 } from "../../account/common/modularAccountV2Base.js";
28+
import {
29+
type ModularAccountV2Client,
30+
type WebauthnModularAccountV2Client,
31+
} from "../../client/client.js";
32+
import {
33+
type ModularAccountV2,
34+
type WebauthnModularAccountV2,
35+
} from "../../account/common/modularAccountV2Base.js";
2936
import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
3037

3138
export type InstallValidationParams<
32-
TSigner extends SmartAccountSigner = SmartAccountSigner,
39+
TSigner extends SmartAccountSigner | undefined =
40+
| SmartAccountSigner
41+
| undefined,
3342
> = {
3443
validationConfig: ValidationConfig;
3544
selectors: Hex[];
@@ -38,25 +47,41 @@ export type InstallValidationParams<
3847
hookConfig: HookConfig;
3948
initData: Hex;
4049
}[];
41-
account?: ModularAccountV2<TSigner> | undefined;
50+
account?: TSigner extends SmartAccountSigner
51+
? ModularAccountV2<TSigner>
52+
: WebauthnModularAccountV2;
4253
} & UserOperationOverridesParameter<
43-
GetEntryPointFromAccount<ModularAccountV2<TSigner>>
54+
GetEntryPointFromAccount<
55+
TSigner extends SmartAccountSigner
56+
? ModularAccountV2<TSigner>
57+
: WebauthnModularAccountV2
58+
>
4459
>;
4560

4661
export type UninstallValidationParams<
47-
TSigner extends SmartAccountSigner = SmartAccountSigner,
62+
TSigner extends SmartAccountSigner | undefined =
63+
| SmartAccountSigner
64+
| undefined,
4865
> = {
4966
moduleAddress: Address;
5067
entityId: number;
5168
uninstallData: Hex;
5269
hookUninstallDatas: Hex[];
53-
account?: ModularAccountV2<TSigner> | undefined;
70+
account?: TSigner extends SmartAccountSigner
71+
? ModularAccountV2<TSigner>
72+
: WebauthnModularAccountV2;
5473
} & UserOperationOverridesParameter<
55-
GetEntryPointFromAccount<ModularAccountV2<TSigner>>
74+
GetEntryPointFromAccount<
75+
TSigner extends SmartAccountSigner
76+
? ModularAccountV2<TSigner>
77+
: WebauthnModularAccountV2
78+
>
5679
>;
5780

5881
export type InstallValidationActions<
59-
TSigner extends SmartAccountSigner = SmartAccountSigner,
82+
TSigner extends SmartAccountSigner | undefined =
83+
| SmartAccountSigner
84+
| undefined,
6085
> = {
6186
installValidation: (
6287
args: InstallValidationParams<TSigner>,
@@ -73,6 +98,10 @@ export type InstallValidationActions<
7398
) => Promise<Hex>;
7499
};
75100

101+
export function installValidationActions<
102+
TSigner extends SmartAccountSigner = SmartAccountSigner,
103+
>(client: ModularAccountV2Client<TSigner>): InstallValidationActions<TSigner>;
104+
76105
/**
77106
* Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
78107
*
@@ -117,11 +146,13 @@ export type InstallValidationActions<
117146
* @param {object} client - The client instance which provides account and sendUserOperation functionality.
118147
* @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.
119148
*/
120-
export const installValidationActions: <
149+
export function installValidationActions<
121150
TSigner extends SmartAccountSigner = SmartAccountSigner,
122151
>(
123-
client: ModularAccountV2Client<TSigner>,
124-
) => InstallValidationActions<TSigner> = (client) => {
152+
client: TSigner extends SmartAccountSigner
153+
? ModularAccountV2Client<TSigner>
154+
: WebauthnModularAccountV2Client,
155+
): InstallValidationActions<TSigner> {
125156
const encodeInstallValidation = async ({
126157
validationConfig,
127158
selectors,
@@ -133,7 +164,18 @@ export const installValidationActions: <
133164
throw new AccountNotFoundError();
134165
}
135166

136-
if (!isSmartAccountClient(client)) {
167+
if (isSmartAccountWithSigner(account)) {
168+
if (!isSmartAccountClient(client as ModularAccountV2Client<TSigner>)) {
169+
// if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains
170+
throw new IncompatibleClientError(
171+
"SmartAccountClient",
172+
"installValidation",
173+
client,
174+
);
175+
}
176+
} else if (
177+
!isSmartAccountClient(client as WebauthnModularAccountV2Client)
178+
) {
137179
throw new IncompatibleClientError(
138180
"SmartAccountClient",
139181
"installValidation",
@@ -176,10 +218,21 @@ export const installValidationActions: <
176218
throw new AccountNotFoundError();
177219
}
178220

179-
if (!isSmartAccountClient(client)) {
221+
if (isSmartAccountWithSigner(account)) {
222+
if (!isSmartAccountClient(client as ModularAccountV2Client<TSigner>)) {
223+
// if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains
224+
throw new IncompatibleClientError(
225+
"SmartAccountClient",
226+
"installValidation",
227+
client,
228+
);
229+
}
230+
} else if (
231+
!isSmartAccountClient(client as WebauthnModularAccountV2Client)
232+
) {
180233
throw new IncompatibleClientError(
181234
"SmartAccountClient",
182-
"uninstallValidation",
235+
"installValidation",
183236
client,
184237
);
185238
}
@@ -210,14 +263,28 @@ export const installValidationActions: <
210263
hooks,
211264
account = client.account,
212265
overrides,
213-
}) => {
214-
const callData = await encodeInstallValidation({
215-
validationConfig,
216-
selectors,
217-
installData,
218-
hooks,
219-
account,
220-
});
266+
}: InstallValidationParams) => {
267+
const signer = "signer" in account ? account.signer : undefined;
268+
let callData: Hex;
269+
if (signer) {
270+
const _account = account as ModularAccountV2<TSigner>;
271+
callData = await encodeInstallValidation({
272+
validationConfig,
273+
selectors,
274+
installData,
275+
hooks,
276+
account: _account,
277+
});
278+
} else {
279+
const _account = account as WebauthnModularAccountV2;
280+
callData = await encodeInstallValidation({
281+
validationConfig,
282+
selectors,
283+
installData,
284+
hooks,
285+
account: _account,
286+
});
287+
}
221288

222289
return client.sendUserOperation({
223290
uo: callData,
@@ -233,14 +300,28 @@ export const installValidationActions: <
233300
hookUninstallDatas,
234301
account = client.account,
235302
overrides,
236-
}) => {
237-
const callData = await encodeUninstallValidation({
238-
moduleAddress,
239-
entityId,
240-
uninstallData,
241-
hookUninstallDatas,
242-
account,
243-
});
303+
}: UninstallValidationParams) => {
304+
const signer = "signer" in account ? account.signer : undefined;
305+
let callData: Hex;
306+
if (signer) {
307+
const _account = account as ModularAccountV2<TSigner>;
308+
callData = await encodeUninstallValidation({
309+
moduleAddress,
310+
entityId,
311+
uninstallData,
312+
hookUninstallDatas,
313+
account: _account,
314+
});
315+
} else {
316+
const _account = account as WebauthnModularAccountV2;
317+
callData = await encodeUninstallValidation({
318+
moduleAddress,
319+
entityId,
320+
uninstallData,
321+
hookUninstallDatas,
322+
account: _account,
323+
});
324+
}
244325

245326
return client.sendUserOperation({
246327
uo: callData,
@@ -249,4 +330,4 @@ export const installValidationActions: <
249330
});
250331
},
251332
};
252-
};
333+
}

0 commit comments

Comments
 (0)