@alchemy/smart-accounts 0.0.0-alpha.1 → 0.0.0-alpha.10
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/index.d.ts +3 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/light-account/accounts/account.d.ts +3 -2
- package/dist/esm/light-account/accounts/account.js +10 -9
- package/dist/esm/light-account/accounts/account.js.map +1 -1
- package/dist/esm/light-account/accounts/base.d.ts +4 -4
- package/dist/esm/light-account/accounts/base.js +1 -1
- package/dist/esm/light-account/accounts/base.js.map +1 -1
- package/dist/esm/light-account/accounts/multi-owner-account.d.ts +6 -3
- package/dist/esm/light-account/accounts/multi-owner-account.js +10 -9
- package/dist/esm/light-account/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/light-account/decorators/multiOwner.js +2 -1
- package/dist/esm/light-account/decorators/multiOwner.js.map +1 -1
- package/dist/esm/light-account/decorators/singleOwner.js +1 -1
- package/dist/esm/light-account/decorators/singleOwner.js.map +1 -1
- package/dist/esm/light-account/registry.d.ts +1 -1
- package/dist/esm/light-account/registry.js.map +1 -1
- package/dist/esm/light-account/utils.js +1 -1
- package/dist/esm/light-account/utils.js.map +1 -1
- package/dist/esm/ma-v1/accounts/base.d.ts +4 -4
- package/dist/esm/ma-v1/accounts/base.js +1 -1
- package/dist/esm/ma-v1/accounts/base.js.map +1 -1
- package/dist/esm/ma-v1/accounts/multi-owner-account.d.ts +3 -2
- package/dist/esm/ma-v1/accounts/multi-owner-account.js +9 -8
- package/dist/esm/ma-v1/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/ma-v1/decorators/multiOwner.js +2 -1
- package/dist/esm/ma-v1/decorators/multiOwner.js.map +1 -1
- package/dist/esm/ma-v2/accounts/account.d.ts +3 -3
- package/dist/esm/ma-v2/accounts/account.js +2 -2
- package/dist/esm/ma-v2/accounts/account.js.map +1 -1
- package/dist/esm/ma-v2/accounts/base.d.ts +4 -4
- package/dist/esm/ma-v2/accounts/base.js +9 -4
- package/dist/esm/ma-v2/accounts/base.js.map +1 -1
- package/dist/esm/ma-v2/utils/account.js +2 -1
- package/dist/esm/ma-v2/utils/account.js.map +1 -1
- package/dist/esm/ma-v2/utils/signature.d.ts +4 -0
- package/dist/esm/ma-v2/utils/signature.js +4 -0
- package/dist/esm/ma-v2/utils/signature.js.map +1 -1
- package/dist/esm/types.d.ts +8 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +8 -0
- package/dist/esm/utils.js +8 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/light-account/accounts/account.d.ts +3 -2
- package/dist/types/light-account/accounts/account.d.ts.map +1 -1
- package/dist/types/light-account/accounts/base.d.ts +4 -4
- package/dist/types/light-account/accounts/base.d.ts.map +1 -1
- package/dist/types/light-account/accounts/multi-owner-account.d.ts +6 -3
- package/dist/types/light-account/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/light-account/decorators/multiOwner.d.ts.map +1 -1
- package/dist/types/light-account/decorators/singleOwner.d.ts.map +1 -1
- package/dist/types/light-account/registry.d.ts +1 -1
- package/dist/types/light-account/registry.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/base.d.ts +4 -4
- package/dist/types/ma-v1/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts +3 -2
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/ma-v1/decorators/multiOwner.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/account.d.ts +3 -3
- package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/base.d.ts +4 -4
- package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/signature.d.ts +4 -0
- package/dist/types/ma-v2/utils/signature.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +8 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/index.ts +5 -0
- package/src/light-account/accounts/account.ts +14 -12
- package/src/light-account/accounts/base.ts +4 -4
- package/src/light-account/accounts/multi-owner-account.ts +15 -11
- package/src/light-account/decorators/multiOwner.ts +4 -1
- package/src/light-account/decorators/singleOwner.ts +3 -1
- package/src/light-account/registry.ts +3 -1
- package/src/light-account/utils.ts +1 -1
- package/src/ma-v1/accounts/base.ts +8 -5
- package/src/ma-v1/accounts/multi-owner-account.ts +13 -9
- package/src/ma-v1/decorators/multiOwner.ts +4 -1
- package/src/ma-v2/accounts/account.ts +4 -4
- package/src/ma-v2/accounts/base.ts +16 -7
- package/src/ma-v2/utils/account.ts +4 -1
- package/src/ma-v2/utils/signature.ts +6 -0
- package/src/types.ts +15 -1
- package/src/utils.ts +8 -0
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alchemy/smart-accounts",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.10",
|
|
4
4
|
"description": "This package contains all of the viem interfaces for Alchemy's Smart Contract Accounts",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,13 +39,14 @@
|
|
|
39
39
|
"test:run": "vitest run"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@alchemy/aa-infra": "0.0.0-alpha.
|
|
42
|
+
"@alchemy/aa-infra": "^0.0.0-alpha.10",
|
|
43
43
|
"typescript-template": "*"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@alchemy/common": "0.0.0-alpha.
|
|
46
|
+
"@alchemy/common": "^0.0.0-alpha.10",
|
|
47
47
|
"ox": "^0.9.6",
|
|
48
|
-
"viem": "^2.32.0"
|
|
48
|
+
"viem": "^2.32.0",
|
|
49
|
+
"webauthn-p256": "^0.0.10"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"access": "public",
|
|
@@ -59,5 +60,5 @@
|
|
|
59
60
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
60
61
|
},
|
|
61
62
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
62
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "2cf1fd7a6a1ddca5c8a17b3139630b28a2a8b9e2"
|
|
63
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type * from "./types.js";
|
|
2
|
+
|
|
3
|
+
export { chainHas7212 } from "./utils.js";
|
|
4
|
+
|
|
1
5
|
// LightAccount
|
|
2
6
|
export type * from "./light-account/accounts/account.js";
|
|
3
7
|
export { toLightAccount } from "./light-account/accounts/account.js";
|
|
@@ -127,6 +131,7 @@ export {
|
|
|
127
131
|
pack1271Signature,
|
|
128
132
|
toReplaySafeTypedData,
|
|
129
133
|
toWebAuthnSignature,
|
|
134
|
+
WEBAUTHN_DUMMY_SIGNATURE,
|
|
130
135
|
} from "./ma-v2/utils/signature.js";
|
|
131
136
|
|
|
132
137
|
// Errors
|
|
@@ -43,7 +43,8 @@ export type ToLightAccountParams<
|
|
|
43
43
|
owner: JsonRpcAccount | LocalAccount;
|
|
44
44
|
salt?: bigint;
|
|
45
45
|
accountAddress?: Address;
|
|
46
|
-
|
|
46
|
+
factory?: Address;
|
|
47
|
+
factoryData?: Hex;
|
|
47
48
|
version?: TLightAccountVersion;
|
|
48
49
|
};
|
|
49
50
|
|
|
@@ -62,7 +63,8 @@ export async function toLightAccount<
|
|
|
62
63
|
salt: salt_ = 0n,
|
|
63
64
|
accountAddress: accountAddress_,
|
|
64
65
|
version = defaultLightAccountVersion() as TLightAccountVersion,
|
|
65
|
-
|
|
66
|
+
factory = AccountVersionRegistry.LightAccount[version].factoryAddress,
|
|
67
|
+
factoryData: factoryData_,
|
|
66
68
|
}: ToLightAccountParams<TLightAccountVersion>): Promise<
|
|
67
69
|
LightAccount<TLightAccountVersion>
|
|
68
70
|
> {
|
|
@@ -78,16 +80,14 @@ export async function toLightAccount<
|
|
|
78
80
|
? LightAccountFactoryAbi_v2
|
|
79
81
|
: LightAccountFactoryAbi_v1;
|
|
80
82
|
|
|
81
|
-
const salt = LightAccountUnsupported1271Factories.has(
|
|
82
|
-
lowerAddress(factoryAddress),
|
|
83
|
-
)
|
|
83
|
+
const salt = LightAccountUnsupported1271Factories.has(lowerAddress(factory))
|
|
84
84
|
? 0n
|
|
85
85
|
: salt_;
|
|
86
86
|
|
|
87
87
|
const accountAddress =
|
|
88
88
|
accountAddress_ ??
|
|
89
89
|
predictLightAccountAddress({
|
|
90
|
-
factoryAddress,
|
|
90
|
+
factoryAddress: factory,
|
|
91
91
|
salt,
|
|
92
92
|
ownerAddress: owner.address,
|
|
93
93
|
version,
|
|
@@ -96,14 +96,16 @@ export async function toLightAccount<
|
|
|
96
96
|
LOGGER.debug("toLightAccount:address-resolved", { accountAddress });
|
|
97
97
|
|
|
98
98
|
const getFactoryArgs = async () => {
|
|
99
|
-
const factoryData =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
const factoryData =
|
|
100
|
+
factoryData_ ??
|
|
101
|
+
encodeFunctionData({
|
|
102
|
+
abi: factoryAbi,
|
|
103
|
+
functionName: "createAccount",
|
|
104
|
+
args: [owner.address, salt],
|
|
105
|
+
});
|
|
104
106
|
|
|
105
107
|
return {
|
|
106
|
-
factory
|
|
108
|
+
factory,
|
|
107
109
|
factoryData,
|
|
108
110
|
};
|
|
109
111
|
};
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
getUserOperationHash,
|
|
21
21
|
toSmartAccount,
|
|
22
|
-
type SmartAccount,
|
|
23
22
|
type SmartAccountImplementation,
|
|
24
23
|
} from "viem/account-abstraction";
|
|
25
24
|
import { getStorageAt, signMessage, signTypedData } from "viem/actions";
|
|
@@ -38,6 +37,7 @@ import { BaseError, lowerAddress } from "@alchemy/common";
|
|
|
38
37
|
import type {
|
|
39
38
|
SignatureRequest,
|
|
40
39
|
StaticSmartAccountImplementation,
|
|
40
|
+
SmartAccountWithDecodeCalls,
|
|
41
41
|
} from "../../types.js";
|
|
42
42
|
import { getAction } from "viem/utils";
|
|
43
43
|
|
|
@@ -59,7 +59,7 @@ export type BaseLightAccountImplementation<
|
|
|
59
59
|
>["version"],
|
|
60
60
|
{
|
|
61
61
|
getLightAccountVersion: () => TLightAccountVersion;
|
|
62
|
-
|
|
62
|
+
smartAccountType: TLightAccountType;
|
|
63
63
|
encodeUpgradeToAndCall: (params: {
|
|
64
64
|
upgradeToAddress: Address;
|
|
65
65
|
upgradeToInitData: Hex;
|
|
@@ -74,7 +74,7 @@ export type LightAccountBase<
|
|
|
74
74
|
TLightAccountType extends LightAccountType = LightAccountType,
|
|
75
75
|
TLightAccountVersion extends
|
|
76
76
|
LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,
|
|
77
|
-
> =
|
|
77
|
+
> = SmartAccountWithDecodeCalls<
|
|
78
78
|
BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>
|
|
79
79
|
>;
|
|
80
80
|
|
|
@@ -330,7 +330,7 @@ export async function toLightAccountBase<
|
|
|
330
330
|
},
|
|
331
331
|
|
|
332
332
|
extend: {
|
|
333
|
-
|
|
333
|
+
smartAccountType: type,
|
|
334
334
|
getLightAccountVersion: () => version,
|
|
335
335
|
encodeUpgradeToAndCall,
|
|
336
336
|
prepareSignature,
|
|
@@ -32,10 +32,11 @@ export type MultiOwnerLightAccount = LightAccountBase<
|
|
|
32
32
|
|
|
33
33
|
export type ToMultiOwnerLightAccountParams = {
|
|
34
34
|
client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
|
|
35
|
-
owners: OneOf<JsonRpcAccount | LocalAccount
|
|
35
|
+
owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];
|
|
36
36
|
salt?: bigint;
|
|
37
37
|
accountAddress?: Address;
|
|
38
|
-
|
|
38
|
+
factory?: Address;
|
|
39
|
+
factoryData?: Hex;
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
/**
|
|
@@ -47,10 +48,11 @@ export type ToMultiOwnerLightAccountParams = {
|
|
|
47
48
|
export async function toMultiOwnerLightAccount({
|
|
48
49
|
client,
|
|
49
50
|
salt = 0n,
|
|
50
|
-
owners
|
|
51
|
+
owners,
|
|
51
52
|
accountAddress: accountAddress_,
|
|
52
|
-
|
|
53
|
+
factory = AccountVersionRegistry.MultiOwnerLightAccount["v2.0.0"]
|
|
53
54
|
.factoryAddress,
|
|
55
|
+
factoryData: factoryData_,
|
|
54
56
|
}: ToMultiOwnerLightAccountParams): Promise<MultiOwnerLightAccount> {
|
|
55
57
|
const signer = owners[0];
|
|
56
58
|
|
|
@@ -67,20 +69,22 @@ export async function toMultiOwnerLightAccount({
|
|
|
67
69
|
const accountAddress =
|
|
68
70
|
accountAddress_ ??
|
|
69
71
|
predictMultiOwnerLightAccountAddress({
|
|
70
|
-
factoryAddress,
|
|
72
|
+
factoryAddress: factory,
|
|
71
73
|
salt,
|
|
72
74
|
ownerAddresses: sortedOwners,
|
|
73
75
|
});
|
|
74
76
|
|
|
75
77
|
const getFactoryArgs = async () => {
|
|
76
|
-
const factoryData =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const factoryData =
|
|
79
|
+
factoryData_ ??
|
|
80
|
+
encodeFunctionData({
|
|
81
|
+
abi: MultiOwnerLightAccountFactoryAbi,
|
|
82
|
+
functionName: "createAccount",
|
|
83
|
+
args: [sortedOwners, salt],
|
|
84
|
+
});
|
|
81
85
|
|
|
82
86
|
return {
|
|
83
|
-
factory
|
|
87
|
+
factory,
|
|
84
88
|
factoryData,
|
|
85
89
|
};
|
|
86
90
|
};
|
|
@@ -21,7 +21,10 @@ export type MultiOwnerLightAccountActions<
|
|
|
21
21
|
function isMultiOwnerLightAccount(
|
|
22
22
|
account: SmartAccount,
|
|
23
23
|
): account is MultiOwnerLightAccount {
|
|
24
|
-
return
|
|
24
|
+
return (
|
|
25
|
+
"smartAccountType" in account &&
|
|
26
|
+
account.smartAccountType === "MultiOwnerLightAccount"
|
|
27
|
+
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -16,7 +16,9 @@ export type LightAccountActions<
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
function isLightAccount(account: SmartAccount): account is LightAccount {
|
|
19
|
-
return
|
|
19
|
+
return (
|
|
20
|
+
"smartAccountType" in account && account.smartAccountType === "LightAccount"
|
|
21
|
+
);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
/**
|
|
@@ -35,7 +35,9 @@ export type LightAccountVersion<TAccountType extends LightAccountType> =
|
|
|
35
35
|
keyof (typeof AccountVersionRegistry)[TAccountType];
|
|
36
36
|
|
|
37
37
|
export type GetLightAccountType<TAccount extends LightAccountBase> =
|
|
38
|
-
TAccount["
|
|
38
|
+
TAccount["smartAccountType"] extends LightAccountType
|
|
39
|
+
? TAccount["smartAccountType"]
|
|
40
|
+
: never;
|
|
39
41
|
|
|
40
42
|
export type LightAccountAbi<
|
|
41
43
|
TAccountType extends LightAccountType,
|
|
@@ -61,7 +61,7 @@ export async function getLightAccountImplAddress<
|
|
|
61
61
|
throw new ChainNotFoundError();
|
|
62
62
|
}
|
|
63
63
|
const version = account.getLightAccountVersion();
|
|
64
|
-
const type = account.
|
|
64
|
+
const type = account.smartAccountType;
|
|
65
65
|
|
|
66
66
|
const expectedImplAddresses = Object.values(AccountVersionRegistry[type]).map(
|
|
67
67
|
(x) => x.accountImplementation,
|
|
@@ -13,12 +13,14 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
entryPoint06Abi,
|
|
15
15
|
toSmartAccount,
|
|
16
|
-
type SmartAccount,
|
|
17
16
|
type SmartAccountImplementation,
|
|
18
17
|
entryPoint06Address,
|
|
19
18
|
getUserOperationHash,
|
|
20
19
|
} from "viem/account-abstraction";
|
|
21
|
-
import type {
|
|
20
|
+
import type {
|
|
21
|
+
SignatureRequest,
|
|
22
|
+
SmartAccountWithDecodeCalls,
|
|
23
|
+
} from "../../types.js";
|
|
22
24
|
import { IStandardExecutorAbi } from "../abis/IStandardExecutor.js";
|
|
23
25
|
import { signMessage, signTypedData } from "viem/actions";
|
|
24
26
|
import {
|
|
@@ -36,14 +38,15 @@ export type BaseMaV1AccountImplementation = SmartAccountImplementation<
|
|
|
36
38
|
typeof entryPoint06Abi,
|
|
37
39
|
"0.6",
|
|
38
40
|
{
|
|
39
|
-
|
|
41
|
+
smartAccountType: MaV1AccountType;
|
|
40
42
|
prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;
|
|
41
43
|
formatSignature: (signature: Hex) => Promise<Hex>;
|
|
42
44
|
},
|
|
43
45
|
false
|
|
44
46
|
>;
|
|
45
47
|
|
|
46
|
-
export type ModularAccountV1Base =
|
|
48
|
+
export type ModularAccountV1Base =
|
|
49
|
+
SmartAccountWithDecodeCalls<BaseMaV1AccountImplementation>;
|
|
47
50
|
|
|
48
51
|
export type ToModularAccountV1BaseParams<
|
|
49
52
|
TTransport extends Transport = Transport,
|
|
@@ -237,7 +240,7 @@ export async function toModularAccountV1Base<
|
|
|
237
240
|
},
|
|
238
241
|
|
|
239
242
|
extend: {
|
|
240
|
-
|
|
243
|
+
smartAccountType: type,
|
|
241
244
|
prepareSignature,
|
|
242
245
|
formatSignature,
|
|
243
246
|
},
|
|
@@ -35,7 +35,8 @@ export type ToMultiOwnerModularAccountV1Params = {
|
|
|
35
35
|
owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];
|
|
36
36
|
salt?: bigint;
|
|
37
37
|
accountAddress?: Address;
|
|
38
|
-
|
|
38
|
+
factory?: Address;
|
|
39
|
+
factoryData?: Hex;
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
/**
|
|
@@ -49,7 +50,8 @@ export async function toMultiOwnerModularAccountV1({
|
|
|
49
50
|
salt = 0n,
|
|
50
51
|
owners,
|
|
51
52
|
accountAddress: accountAddress_,
|
|
52
|
-
|
|
53
|
+
factory = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,
|
|
54
|
+
factoryData: factoryData_,
|
|
53
55
|
}: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1> {
|
|
54
56
|
const signer = owners[0];
|
|
55
57
|
|
|
@@ -66,20 +68,22 @@ export async function toMultiOwnerModularAccountV1({
|
|
|
66
68
|
const accountAddress =
|
|
67
69
|
accountAddress_ ??
|
|
68
70
|
predictMultiOwnerModularAccountV1Address({
|
|
69
|
-
factoryAddress,
|
|
71
|
+
factoryAddress: factory,
|
|
70
72
|
salt,
|
|
71
73
|
ownerAddresses: sortedOwners,
|
|
72
74
|
});
|
|
73
75
|
|
|
74
76
|
const getFactoryArgs = async () => {
|
|
75
|
-
const factoryData =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const factoryData =
|
|
78
|
+
factoryData_ ??
|
|
79
|
+
encodeFunctionData({
|
|
80
|
+
abi: MultiOwnerModularAccountFactoryAbi,
|
|
81
|
+
functionName: "createAccount",
|
|
82
|
+
args: [salt, sortedOwners],
|
|
83
|
+
});
|
|
80
84
|
|
|
81
85
|
return {
|
|
82
|
-
factory
|
|
86
|
+
factory,
|
|
83
87
|
factoryData,
|
|
84
88
|
};
|
|
85
89
|
};
|
|
@@ -21,7 +21,10 @@ export type MultiOwnerModularAccountV1Actions<
|
|
|
21
21
|
function isMultiOwnerModularAccountV1(
|
|
22
22
|
account: SmartAccount,
|
|
23
23
|
): account is MultiOwnerModularAccountV1 {
|
|
24
|
-
return
|
|
24
|
+
return (
|
|
25
|
+
"smartAccountType" in account &&
|
|
26
|
+
account.smartAccountType === "MultiOwnerModularAccountV1"
|
|
27
|
+
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -41,13 +41,13 @@ export type ToModularAccountV2Params<
|
|
|
41
41
|
} & (TMode extends "7702"
|
|
42
42
|
? {
|
|
43
43
|
salt?: never;
|
|
44
|
-
|
|
44
|
+
factory?: never;
|
|
45
45
|
factoryData?: never;
|
|
46
46
|
implementationAddress?: never;
|
|
47
47
|
}
|
|
48
48
|
: {
|
|
49
49
|
salt?: bigint;
|
|
50
|
-
|
|
50
|
+
factory?: Address;
|
|
51
51
|
factoryData?: Hex;
|
|
52
52
|
implementationAddress?: Address;
|
|
53
53
|
});
|
|
@@ -65,7 +65,7 @@ export async function toModularAccountV2<TMode extends Mode = Mode>({
|
|
|
65
65
|
signerEntity,
|
|
66
66
|
accountAddress: accountAddress_,
|
|
67
67
|
salt = 0n,
|
|
68
|
-
|
|
68
|
+
factory,
|
|
69
69
|
factoryData: factoryData_,
|
|
70
70
|
implementationAddress: implementationAddress_,
|
|
71
71
|
mode,
|
|
@@ -82,7 +82,7 @@ export async function toModularAccountV2<TMode extends Mode = Mode>({
|
|
|
82
82
|
const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;
|
|
83
83
|
|
|
84
84
|
const factoryAddress =
|
|
85
|
-
|
|
85
|
+
factory ??
|
|
86
86
|
(owner.type === "webAuthn"
|
|
87
87
|
? DefaultAddress.MAV2_FACTORY_WEBAUTHN
|
|
88
88
|
: DefaultAddress.MAV2_FACTORY);
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
entryPoint07Abi,
|
|
21
21
|
type SmartAccountImplementation,
|
|
22
|
-
type SmartAccount,
|
|
23
22
|
entryPoint07Address,
|
|
24
23
|
getUserOperationHash,
|
|
25
24
|
toSmartAccount,
|
|
@@ -42,7 +41,10 @@ import {
|
|
|
42
41
|
type ValidationDataView,
|
|
43
42
|
} from "../types.js";
|
|
44
43
|
import { modularAccountAbi } from "../abis/modularAccountAbi.js";
|
|
45
|
-
import type {
|
|
44
|
+
import type {
|
|
45
|
+
SignatureRequest,
|
|
46
|
+
SmartAccountWithDecodeCalls,
|
|
47
|
+
} from "../../types.js";
|
|
46
48
|
import {
|
|
47
49
|
decodeFunctionData,
|
|
48
50
|
getAction,
|
|
@@ -61,6 +63,7 @@ import {
|
|
|
61
63
|
toWebAuthnSignature,
|
|
62
64
|
toReplaySafeTypedData,
|
|
63
65
|
packUOSignature,
|
|
66
|
+
WEBAUTHN_DUMMY_SIGNATURE,
|
|
64
67
|
} from "../utils/signature.js";
|
|
65
68
|
import { chainHas7212 } from "../../utils.js";
|
|
66
69
|
import { InvalidDeferredActionNonceError } from "../../errors/InvalidDeferredActionNonceError.js";
|
|
@@ -81,7 +84,7 @@ export type BaseModularAccountV2Implementation = SmartAccountImplementation<
|
|
|
81
84
|
typeof entryPoint07Abi,
|
|
82
85
|
"0.7",
|
|
83
86
|
{
|
|
84
|
-
|
|
87
|
+
smartAccountType: "ModularAccountV2";
|
|
85
88
|
signerEntity: SignerEntity;
|
|
86
89
|
encodeCallData: (callData: Hex) => Promise<Hex>;
|
|
87
90
|
getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;
|
|
@@ -95,7 +98,7 @@ export type BaseModularAccountV2Implementation = SmartAccountImplementation<
|
|
|
95
98
|
>;
|
|
96
99
|
|
|
97
100
|
export type ModularAccountV2Base =
|
|
98
|
-
|
|
101
|
+
SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;
|
|
99
102
|
|
|
100
103
|
export type ToModularAccountV2BaseParams<
|
|
101
104
|
TTransport extends Transport = Transport,
|
|
@@ -144,10 +147,16 @@ export async function toModularAccountV2Base<
|
|
|
144
147
|
throw new InvalidEntityIdError(entityId);
|
|
145
148
|
}
|
|
146
149
|
|
|
150
|
+
let isDeployed = false;
|
|
151
|
+
|
|
147
152
|
const isAccountDeployed: () => Promise<boolean> = async () => {
|
|
153
|
+
if (isDeployed) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
148
156
|
const action = getAction(client, getCode, "getCode");
|
|
149
157
|
const code = await action({ address: accountAddress });
|
|
150
|
-
|
|
158
|
+
isDeployed = !!code;
|
|
159
|
+
return isDeployed;
|
|
151
160
|
};
|
|
152
161
|
|
|
153
162
|
// These default values signal that we should not use the set deferred action nonce
|
|
@@ -410,7 +419,7 @@ export async function toModularAccountV2Base<
|
|
|
410
419
|
|
|
411
420
|
async getStubSignature() {
|
|
412
421
|
if (owner.type === "webAuthn") {
|
|
413
|
-
return
|
|
422
|
+
return WEBAUTHN_DUMMY_SIGNATURE;
|
|
414
423
|
}
|
|
415
424
|
|
|
416
425
|
const sig = packUOSignature({
|
|
@@ -554,7 +563,7 @@ export async function toModularAccountV2Base<
|
|
|
554
563
|
},
|
|
555
564
|
|
|
556
565
|
extend: {
|
|
557
|
-
|
|
566
|
+
smartAccountType: "ModularAccountV2" as const,
|
|
558
567
|
signerEntity: {
|
|
559
568
|
entityId,
|
|
560
569
|
isGlobalValidation,
|
|
@@ -133,5 +133,8 @@ export function serializeModuleEntity(config: ModuleEntity): Hex {
|
|
|
133
133
|
export function isModularAccountV2(
|
|
134
134
|
account: SmartAccount,
|
|
135
135
|
): account is ModularAccountV2Base {
|
|
136
|
-
return
|
|
136
|
+
return (
|
|
137
|
+
"smartAccountType" in account &&
|
|
138
|
+
account.smartAccountType === "ModularAccountV2"
|
|
139
|
+
);
|
|
137
140
|
}
|
|
@@ -127,3 +127,9 @@ export function toWebAuthnSignature({
|
|
|
127
127
|
],
|
|
128
128
|
);
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A dummy WebAuthn signature used for gas estimation.
|
|
133
|
+
*/
|
|
134
|
+
export const WEBAUTHN_DUMMY_SIGNATURE =
|
|
135
|
+
"0xff000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000001949fc7c88032b9fcb5f6efc7a7b8c63668eae9871b765e23123bb473ff57aa831a7c0d9276168ebcc29f2875a0239cffdf2a9cd1c2007c5c77c071db9264df1d000000000000000000000000000000000000000000000000000000000000002549960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008a7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2273496a396e6164474850596759334b7156384f7a4a666c726275504b474f716d59576f4d57516869467773222c226f726967696e223a2268747470733a2f2f7369676e2e636f696e626173652e636f6d222c2263726f73734f726967696e223a66616c73657d00000000000000000000000000000000000000000000";
|
package/src/types.ts
CHANGED
|
@@ -6,7 +6,11 @@ import type {
|
|
|
6
6
|
SignableMessage,
|
|
7
7
|
TypedDataDefinition,
|
|
8
8
|
} from "viem";
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
EntryPointVersion,
|
|
11
|
+
SmartAccount,
|
|
12
|
+
SmartAccountImplementation,
|
|
13
|
+
} from "viem/account-abstraction";
|
|
10
14
|
|
|
11
15
|
export type GetAccountParameter<
|
|
12
16
|
TAccount extends SmartAccount | undefined = SmartAccount | undefined,
|
|
@@ -16,6 +20,16 @@ export type GetAccountParameter<
|
|
|
16
20
|
? { account: TAccountOverride }
|
|
17
21
|
: { account?: TAccountOverride };
|
|
18
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Helper type that converts a SmartAccount type to have a required `decodeCalls` function.
|
|
25
|
+
* This is useful for account implementations that always provide the `decodeCalls` functionality.
|
|
26
|
+
*/
|
|
27
|
+
export type SmartAccountWithDecodeCalls<
|
|
28
|
+
TImplementation extends SmartAccountImplementation,
|
|
29
|
+
> = SmartAccount<TImplementation> & {
|
|
30
|
+
decodeCalls: NonNullable<SmartAccount<TImplementation>["decodeCalls"]>;
|
|
31
|
+
};
|
|
32
|
+
|
|
19
33
|
export type SignatureRequest =
|
|
20
34
|
| {
|
|
21
35
|
type: "personal_sign";
|
package/src/utils.ts
CHANGED
|
@@ -7,6 +7,14 @@ import { BaseError } from "@alchemy/common";
|
|
|
7
7
|
const RIP_7212_CHECK_BYTECODE =
|
|
8
8
|
"0x60806040526040517f532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25815260056020820152600160408201527f4a03ef9f92eb268cafa601072489a56380fa0dc43171d7712813b3a19a1eb5e560608201527f3e213e28a608ce9a2f4a17fd830c6654018a79b3e0263d91a8ba90622df6f2f0608082015260208160a0836101005afa503d5f823e3d81f3fe";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the current chain supports RIP-7212 (precompiled contract for secp256r1 curve operations).
|
|
12
|
+
* This is used to determine if the chain has native support for P256 signature verification,
|
|
13
|
+
* which is commonly used in WebAuthn/passkey implementations.
|
|
14
|
+
*
|
|
15
|
+
* @param {Client} client - The viem client to use for the check
|
|
16
|
+
* @returns {Promise<boolean>} True if the chain supports RIP-7212, false otherwise
|
|
17
|
+
*/
|
|
10
18
|
export const chainHas7212 = async (client: Client): Promise<boolean> => {
|
|
11
19
|
const callAction = getAction(client, call, "call");
|
|
12
20
|
|
package/src/version.ts
CHANGED