@alchemy/smart-accounts 0.0.0-alpha.9 → 5.0.0-beta.2
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/LICENSE +1 -1
- package/README.md +36 -0
- package/dist/esm/index.d.ts +2 -4
- package/dist/esm/index.js +2 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/light-account/accounts/account.d.ts +7 -3
- package/dist/esm/light-account/accounts/account.js +20 -10
- package/dist/esm/light-account/accounts/account.js.map +1 -1
- package/dist/esm/light-account/accounts/base.js +50 -23
- package/dist/esm/light-account/accounts/base.js.map +1 -1
- package/dist/esm/light-account/accounts/calldataCodec.js +3 -2
- package/dist/esm/light-account/accounts/calldataCodec.js.map +1 -1
- package/dist/esm/light-account/accounts/multi-owner-account.d.ts +6 -2
- package/dist/esm/light-account/accounts/multi-owner-account.js +14 -6
- package/dist/esm/light-account/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/light-account/lightAccountStaticImpl.d.ts +3 -1
- package/dist/esm/light-account/lightAccountStaticImpl.js +57 -7
- package/dist/esm/light-account/lightAccountStaticImpl.js.map +1 -1
- package/dist/esm/light-account/predictAddress.d.ts +40 -2
- package/dist/esm/light-account/predictAddress.js +83 -3
- package/dist/esm/light-account/predictAddress.js.map +1 -1
- package/dist/esm/light-account/registry.d.ts +3410 -0
- package/dist/esm/light-account/registry.js +33 -1
- package/dist/esm/light-account/registry.js.map +1 -1
- package/dist/esm/logger.d.ts +1 -1
- package/dist/esm/logger.js +1 -1
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/ma-v1/accounts/multi-owner-account.d.ts +6 -2
- package/dist/esm/ma-v1/accounts/multi-owner-account.js +18 -7
- package/dist/esm/ma-v1/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/ma-v1/predictAddress.d.ts +20 -1
- package/dist/esm/ma-v1/predictAddress.js +38 -2
- package/dist/esm/ma-v1/predictAddress.js.map +1 -1
- package/dist/esm/ma-v2/accounts/account.d.ts +8 -5
- package/dist/esm/ma-v2/accounts/account.js +23 -42
- package/dist/esm/ma-v2/accounts/account.js.map +1 -1
- package/dist/esm/ma-v2/accounts/base.d.ts +2 -2
- package/dist/esm/ma-v2/accounts/base.js +12 -59
- package/dist/esm/ma-v2/accounts/base.js.map +1 -1
- package/dist/esm/ma-v2/mav2StaticImpl.d.ts +1 -15
- package/dist/esm/ma-v2/mav2StaticImpl.js +0 -33
- package/dist/esm/ma-v2/mav2StaticImpl.js.map +1 -1
- package/dist/esm/ma-v2/modules/time-range-module/module.js +3 -2
- package/dist/esm/ma-v2/modules/time-range-module/module.js.map +1 -1
- package/dist/esm/ma-v2/predictAddress.d.ts +22 -6
- package/dist/esm/ma-v2/predictAddress.js +46 -12
- package/dist/esm/ma-v2/predictAddress.js.map +1 -1
- package/dist/esm/ma-v2/utils/account.d.ts +0 -3
- package/dist/esm/ma-v2/utils/account.js +0 -3
- package/dist/esm/ma-v2/utils/account.js.map +1 -1
- package/dist/esm/ma-v2/utils/signature.d.ts +1 -16
- package/dist/esm/ma-v2/utils/signature.js +1 -38
- package/dist/esm/ma-v2/utils/signature.js.map +1 -1
- package/dist/esm/utils.d.ts +24 -11
- package/dist/esm/utils.js +67 -21
- 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 +2 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/light-account/accounts/account.d.ts +7 -3
- package/dist/types/light-account/accounts/account.d.ts.map +1 -1
- package/dist/types/light-account/accounts/base.d.ts.map +1 -1
- package/dist/types/light-account/accounts/calldataCodec.d.ts.map +1 -1
- package/dist/types/light-account/accounts/multi-owner-account.d.ts +6 -2
- package/dist/types/light-account/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/light-account/lightAccountStaticImpl.d.ts +3 -1
- package/dist/types/light-account/lightAccountStaticImpl.d.ts.map +1 -1
- package/dist/types/light-account/predictAddress.d.ts +40 -2
- package/dist/types/light-account/predictAddress.d.ts.map +1 -1
- package/dist/types/light-account/registry.d.ts +3410 -0
- package/dist/types/light-account/registry.d.ts.map +1 -1
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/logger.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts +6 -2
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/ma-v1/predictAddress.d.ts +20 -1
- package/dist/types/ma-v1/predictAddress.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/account.d.ts +8 -5
- package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/base.d.ts +2 -2
- package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v2/mav2StaticImpl.d.ts +1 -15
- package/dist/types/ma-v2/mav2StaticImpl.d.ts.map +1 -1
- package/dist/types/ma-v2/modules/time-range-module/module.d.ts.map +1 -1
- package/dist/types/ma-v2/predictAddress.d.ts +22 -6
- package/dist/types/ma-v2/predictAddress.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/account.d.ts +0 -3
- package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/signature.d.ts +1 -16
- package/dist/types/ma-v2/utils/signature.d.ts.map +1 -1
- package/dist/types/utils.d.ts +24 -11
- 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 +9 -8
- package/src/index.ts +0 -6
- package/src/light-account/accounts/account.ts +30 -16
- package/src/light-account/accounts/base.ts +62 -23
- package/src/light-account/accounts/calldataCodec.ts +3 -2
- package/src/light-account/accounts/multi-owner-account.ts +22 -9
- package/src/light-account/lightAccountStaticImpl.ts +84 -11
- package/src/light-account/predictAddress.ts +124 -3
- package/src/light-account/registry.ts +44 -0
- package/src/logger.ts +2 -2
- package/src/ma-v1/accounts/multi-owner-account.ts +26 -11
- package/src/ma-v1/predictAddress.ts +60 -3
- package/src/ma-v2/accounts/account.ts +39 -52
- package/src/ma-v2/accounts/base.ts +11 -84
- package/src/ma-v2/mav2StaticImpl.ts +1 -52
- package/src/ma-v2/modules/time-range-module/module.ts +3 -2
- package/src/ma-v2/predictAddress.ts +68 -30
- package/src/ma-v2/utils/account.ts +0 -3
- package/src/ma-v2/utils/signature.ts +2 -57
- package/src/utils.ts +111 -27
- package/src/version.ts +1 -1
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -330
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js +0 -260
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js.map +0 -1
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -287
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js +0 -374
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js.map +0 -1
- package/dist/esm/ma-v2/modules/webauthn-validation/module.d.ts +0 -11
- package/dist/esm/ma-v2/modules/webauthn-validation/module.js +0 -16
- package/dist/esm/ma-v2/modules/webauthn-validation/module.js.map +0 -1
- package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -331
- package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts.map +0 -1
- package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -288
- package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts.map +0 -1
- package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts +0 -12
- package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts.map +0 -1
- package/src/ma-v2/abis/webAuthnFactoryAbi.ts +0 -259
- package/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.ts +0 -373
- package/src/ma-v2/modules/webauthn-validation/module.ts +0 -28
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { concat, concatHex, encodeFunctionData, hashMessage, hashTypedData, maxUint32, maxUint152, zeroAddress, } from "viem";
|
|
2
|
-
import { entryPoint07Abi, entryPoint07Address, getUserOperationHash, toSmartAccount,
|
|
2
|
+
import { entryPoint07Abi, entryPoint07Address, getUserOperationHash, toSmartAccount, } from "viem/account-abstraction";
|
|
3
3
|
import { getCode, readContract, signMessage, signTypedData, } from "viem/actions";
|
|
4
4
|
import { assertNever, BaseError } from "@alchemy/common";
|
|
5
5
|
import { SignaturePrefix, } from "../types.js";
|
|
@@ -7,11 +7,11 @@ import { modularAccountAbi } from "../abis/modularAccountAbi.js";
|
|
|
7
7
|
import { decodeFunctionData, getAction, isAddressEqual, sliceHex, } from "viem/utils";
|
|
8
8
|
import { DEFAULT_OWNER_ENTITY_ID, DefaultModuleAddress, EXECUTE_USER_OP_SELECTOR, serializeModuleEntity, } from "../utils/account.js";
|
|
9
9
|
import { parseDeferredAction } from "../utils/deferredActions.js";
|
|
10
|
-
import { pack1271Signature,
|
|
11
|
-
import { chainHas7212 } from "../../utils.js";
|
|
10
|
+
import { pack1271Signature, toReplaySafeTypedData, packUOSignature, } from "../utils/signature.js";
|
|
12
11
|
import { InvalidDeferredActionNonceError } from "../../errors/InvalidDeferredActionNonceError.js";
|
|
13
12
|
import { InvalidNonceKeyError } from "../../errors/InvalidNonceKeyError.js";
|
|
14
13
|
import { InvalidEntityIdError } from "../../errors/InvalidEntityIdError.js";
|
|
14
|
+
import { is7702Delegated } from "../../utils.js";
|
|
15
15
|
/**
|
|
16
16
|
* Creates a ModularAccountV2Base instance.
|
|
17
17
|
*
|
|
@@ -38,7 +38,9 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
38
38
|
}
|
|
39
39
|
const action = getAction(client, getCode, "getCode");
|
|
40
40
|
const code = await action({ address: accountAddress });
|
|
41
|
-
isDeployed =
|
|
41
|
+
isDeployed = authorization
|
|
42
|
+
? is7702Delegated(authorization.address, code)
|
|
43
|
+
: !!code;
|
|
42
44
|
return isDeployed;
|
|
43
45
|
};
|
|
44
46
|
// These default values signal that we should not use the set deferred action nonce
|
|
@@ -159,24 +161,19 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
159
161
|
data: toReplaySafeTypedData({
|
|
160
162
|
chainId: client.chain.id,
|
|
161
163
|
hash,
|
|
162
|
-
...(
|
|
163
|
-
? {
|
|
164
|
-
|
|
164
|
+
...(entityId === DEFAULT_OWNER_ENTITY_ID
|
|
165
|
+
? { address: accountAddress }
|
|
166
|
+
: {
|
|
167
|
+
address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,
|
|
165
168
|
salt: concatHex([`0x${"00".repeat(12)}`, accountAddress]),
|
|
166
|
-
}
|
|
167
|
-
: entityId === DEFAULT_OWNER_ENTITY_ID
|
|
168
|
-
? { address: accountAddress }
|
|
169
|
-
: {
|
|
170
|
-
address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,
|
|
171
|
-
salt: concatHex([`0x${"00".repeat(12)}`, accountAddress]),
|
|
172
|
-
}),
|
|
169
|
+
}),
|
|
173
170
|
}),
|
|
174
171
|
};
|
|
175
172
|
};
|
|
176
173
|
const formatSignature = async (signature) => {
|
|
177
174
|
return pack1271Signature({
|
|
178
175
|
entityId,
|
|
179
|
-
validationSignaturePrefix:
|
|
176
|
+
validationSignaturePrefix: SignaturePrefix.EOA,
|
|
180
177
|
validationSignature: signature,
|
|
181
178
|
});
|
|
182
179
|
};
|
|
@@ -254,9 +251,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
254
251
|
];
|
|
255
252
|
},
|
|
256
253
|
async getStubSignature() {
|
|
257
|
-
if (owner.type === "webAuthn") {
|
|
258
|
-
return WEBAUTHN_DUMMY_SIGNATURE;
|
|
259
|
-
}
|
|
260
254
|
const sig = packUOSignature({
|
|
261
255
|
validationSignature: "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
|
|
262
256
|
});
|
|
@@ -267,10 +261,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
267
261
|
type: "personal_sign",
|
|
268
262
|
data: message,
|
|
269
263
|
});
|
|
270
|
-
if (owner.type === "webAuthn") {
|
|
271
|
-
const validationSignature = toWebAuthnSignature(await owner.sign({ hash: hashTypedData(data) }));
|
|
272
|
-
return formatSignature(validationSignature);
|
|
273
|
-
}
|
|
274
264
|
const action = getAction(client, signTypedData, "signTypedData");
|
|
275
265
|
const signature = await action({
|
|
276
266
|
...data,
|
|
@@ -288,12 +278,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
288
278
|
type: "eth_signTypedData_v4",
|
|
289
279
|
data: td, // TODO(v5): Try harder to satisfy this w/o casting.
|
|
290
280
|
});
|
|
291
|
-
if (owner.type === "webAuthn") {
|
|
292
|
-
const validationSignature = toWebAuthnSignature(await owner.sign({ hash: hashTypedData(data) }));
|
|
293
|
-
return isDeferredAction
|
|
294
|
-
? validationSignature
|
|
295
|
-
: formatSignature(validationSignature);
|
|
296
|
-
}
|
|
297
281
|
const action = getAction(client, signTypedData, "signTypedData");
|
|
298
282
|
const signature = await action({
|
|
299
283
|
...data,
|
|
@@ -313,17 +297,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
313
297
|
sender: accountAddress,
|
|
314
298
|
},
|
|
315
299
|
});
|
|
316
|
-
if (owner.type === "webAuthn") {
|
|
317
|
-
const validationSignature = toWebAuthnSignature(await owner.sign({
|
|
318
|
-
hash: hashMessage({ raw: hash }),
|
|
319
|
-
}));
|
|
320
|
-
const signature = deferredActionData
|
|
321
|
-
? concatHex([deferredActionData, validationSignature])
|
|
322
|
-
: validationSignature;
|
|
323
|
-
deferredActionData = undefined; // clear once used
|
|
324
|
-
hasAssociatedExecHooks = false; // set to falsy value once used
|
|
325
|
-
return concatHex(["0xff", signature]);
|
|
326
|
-
}
|
|
327
300
|
const signMessageAction = getAction(client, signMessage, "signMessage");
|
|
328
301
|
const validationSignature = await signMessageAction({
|
|
329
302
|
account: owner,
|
|
@@ -339,26 +312,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
339
312
|
hasAssociatedExecHooks = false; // set to falsy value once used
|
|
340
313
|
return signature;
|
|
341
314
|
},
|
|
342
|
-
userOperation: {
|
|
343
|
-
estimateGas: async (uo) => {
|
|
344
|
-
if (owner.type !== "webAuthn") {
|
|
345
|
-
// Uses the default gas estimator.
|
|
346
|
-
// Note that we get 7702 support automatically from Viem.
|
|
347
|
-
return undefined;
|
|
348
|
-
}
|
|
349
|
-
const estimateGasAction = getAction(client, estimateUserOperationGas, "estimateUserOperationGas");
|
|
350
|
-
const estimate = await estimateGasAction({
|
|
351
|
-
...uo,
|
|
352
|
-
entryPointAddress: entryPoint.address,
|
|
353
|
-
});
|
|
354
|
-
const buffer = (await chainHas7212(client)) ? 10000n : 300000n;
|
|
355
|
-
// TODO(v4): iterate numbers. Aim to have ~1000 gas buffer to account for longer authenticatorDatas and clientDataJSONs.
|
|
356
|
-
return {
|
|
357
|
-
...estimate,
|
|
358
|
-
verificationGasLimit: estimate.verificationGasLimit + buffer,
|
|
359
|
-
};
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
315
|
extend: {
|
|
363
316
|
smartAccountType: "ModularAccountV2",
|
|
364
317
|
signerEntity: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EAGd,wBAAwB,GAEzB,MAAM,0BAA0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AC,IAAI,KAAK,UAAU,EAAE,CAAC;oBAC9B,kCAAkC;oBAClC,yDAAyD;oBACzD,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,MAAM,iBAAiB,GAAG,SAAS,CACjC,MAAM,EACN,wBAAwB,EACxB,0BAA0B,CAC3B,CAAC;gBAEF,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC;oBACvC,GAAI,EAA+C;oBACnD,iBAAiB,EAAE,UAAU,CAAC,OAAO;iBACtC,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;gBAE/D,wHAAwH;gBACxH,OAAO;oBACL,GAAG,QAAQ;oBACX,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB,GAAG,MAAM;iBAC7D,CAAC;YACJ,CAAC;SACF;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,kBAA2B;YAC7C,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n encodeFunctionData,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type WebAuthnAccount,\n type ToSmartAccountParameters,\n estimateUserOperationGas,\n type UserOperation,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport {\n decodeFunctionData,\n getAction,\n isAddressEqual,\n sliceHex,\n} from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toWebAuthnSignature,\n toReplaySafeTypedData,\n packUOSignature,\n WEBAUTHN_DUMMY_SIGNATURE,\n} from \"../utils/signature.js\";\nimport { chainHas7212 } from \"../../utils.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n smartAccountType: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount | WebAuthnAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n let isDeployed = false;\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n if (isDeployed) {\n return true;\n }\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n isDeployed = !!code;\n return isDeployed;\n };\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\n };\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ],\n });\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(owner.type === \"webAuthn\"\n ? {\n address: DefaultModuleAddress.WEBAUTHN_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }\n : entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix:\n owner.type === \"webAuthn\" ? null : SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data === undefined) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n }),\n );\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n }),\n );\n },\n\n async decodeCalls(data) {\n // Inverse of `encodeCalls`.\n // Trim the EXECUTE_USER_OP_SELECTOR if it is present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n if (owner.type === \"webAuthn\") {\n return WEBAUTHN_DUMMY_SIGNATURE;\n }\n\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n if (owner.type === \"webAuthn\") {\n const validationSignature = toWebAuthnSignature(\n await owner.sign({ hash: hashTypedData(data) }),\n );\n return formatSignature(validationSignature);\n }\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition, // TODO(v5): Try harder to satisfy this w/o casting.\n });\n\n if (owner.type === \"webAuthn\") {\n const validationSignature = toWebAuthnSignature(\n await owner.sign({ hash: hashTypedData(data) }),\n );\n return isDeferredAction\n ? validationSignature\n : formatSignature(validationSignature);\n }\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n if (owner.type === \"webAuthn\") {\n const validationSignature = toWebAuthnSignature(\n await owner.sign({\n hash: hashMessage({ raw: hash }),\n }),\n );\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, validationSignature])\n : validationSignature;\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n return concatHex([\"0xff\", signature]);\n }\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n userOperation: {\n estimateGas: async (uo) => {\n if (owner.type !== \"webAuthn\") {\n // Uses the default gas estimator.\n // Note that we get 7702 support automatically from Viem.\n return undefined;\n }\n\n const estimateGasAction = getAction(\n client,\n estimateUserOperationGas,\n \"estimateUserOperationGas\",\n );\n\n const estimate = await estimateGasAction({\n ...(uo as UserOperation<typeof entryPoint.version>),\n entryPointAddress: entryPoint.address,\n });\n\n const buffer = (await chainHas7212(client)) ? 10000n : 300000n;\n\n // TODO(v4): iterate numbers. Aim to have ~1000 gas buffer to account for longer authenticatorDatas and clientDataJSONs.\n return {\n ...estimate,\n verificationGasLimit: estimate.verificationGasLimit + buffer,\n };\n },\n },\n\n extend: {\n smartAccountType: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACL,eAAe,GAIhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,e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AClD,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;aACvB,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,eAAe,CAAC;gBACtC,mBAAmB;aACpB,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,kBAAkB;gBAClC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;gBAClD,CAAC,CAAC,eAAe,CAAC;YAEpB,kBAAkB,GAAG,SAAS,CAAC,CAAC,kBAAkB;YAClD,sBAAsB,GAAG,KAAK,CAAC,CAAC,+BAA+B;YAE/D,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,kBAA2B;YAC7C,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n encodeFunctionData,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport {\n decodeFunctionData,\n getAction,\n isAddressEqual,\n sliceHex,\n} from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toReplaySafeTypedData,\n packUOSignature,\n} from \"../utils/signature.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\nimport { is7702Delegated } from \"../../utils.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n smartAccountType: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n let isDeployed = false;\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n if (isDeployed) {\n return true;\n }\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n isDeployed = authorization\n ? is7702Delegated(authorization.address, code)\n : !!code;\n return isDeployed;\n };\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\n };\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ],\n });\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix: SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data === undefined) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n }),\n );\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n }),\n );\n },\n\n async decodeCalls(data) {\n // Inverse of `encodeCalls`.\n // Trim the EXECUTE_USER_OP_SELECTOR if it is present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition, // TODO(v5): Try harder to satisfy this w/o casting.\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n extend: {\n smartAccountType: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { type Address
|
|
1
|
+
import { type Address } from "viem";
|
|
2
2
|
import { entryPoint07Abi } from "viem/account-abstraction";
|
|
3
3
|
import type { StaticSmartAccountImplementation } from "../types.js";
|
|
4
4
|
import { semiModularAccountBytecodeAbi } from "./abis/semiModularAccountBytecodeAbi.js";
|
|
5
5
|
import { accountFactoryAbi } from "./abis/accountFactoryAbi.js";
|
|
6
|
-
import { webAuthnFactoryAbi } from "./abis/webAuthnFactoryAbi.js";
|
|
7
|
-
import { modularAccountAbi } from "./abis/modularAccountAbi.js";
|
|
8
6
|
export type SemiModularAccountV2FactoryArgs = {
|
|
9
7
|
owner: Address;
|
|
10
8
|
salt: bigint;
|
|
@@ -23,15 +21,3 @@ export type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<
|
|
|
23
21
|
* TODO(v5): update JSDoc format when doc-gen supports structs or records.
|
|
24
22
|
*/
|
|
25
23
|
export declare const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl;
|
|
26
|
-
export type WebAuthnModularAccountV2FactoryArgs = {
|
|
27
|
-
ownerPublicKey: Hex;
|
|
28
|
-
salt: bigint;
|
|
29
|
-
entityId: number;
|
|
30
|
-
};
|
|
31
|
-
export type WebAuthnModularAccountV2StaticImpl = StaticSmartAccountImplementation<false, "0.7", WebAuthnModularAccountV2FactoryArgs, typeof entryPoint07Abi, typeof modularAccountAbi, typeof webAuthnFactoryAbi>;
|
|
32
|
-
/**
|
|
33
|
-
* Static implementation logic for WebAuthnModularAccountV2.
|
|
34
|
-
*
|
|
35
|
-
* TODO(v5): update JSDoc format when doc-gen supports structs or records.
|
|
36
|
-
*/
|
|
37
|
-
export declare const webAuthnModularAccountV2StaticImpl: WebAuthnModularAccountV2StaticImpl;
|
|
@@ -3,11 +3,8 @@ import { entryPoint07Abi, entryPoint07Address } from "viem/account-abstraction";
|
|
|
3
3
|
import { lowerAddress } from "@alchemy/common";
|
|
4
4
|
import { semiModularAccountBytecodeAbi } from "./abis/semiModularAccountBytecodeAbi.js";
|
|
5
5
|
import { accountFactoryAbi } from "./abis/accountFactoryAbi.js";
|
|
6
|
-
import { webAuthnFactoryAbi } from "./abis/webAuthnFactoryAbi.js";
|
|
7
6
|
import { DefaultAddress as DefaultMAV2Address } from "./utils/account.js";
|
|
8
7
|
import { predictModularAccountV2Address } from "./predictAddress.js";
|
|
9
|
-
import { modularAccountAbi } from "./abis/modularAccountAbi.js";
|
|
10
|
-
import { parsePublicKey } from "webauthn-p256";
|
|
11
8
|
// Shared entryPoint configuration across all modular account v2 implementations
|
|
12
9
|
const entryPoint = {
|
|
13
10
|
abi: entryPoint07Abi,
|
|
@@ -55,34 +52,4 @@ export const semiModularAccount7702StaticImpl = {
|
|
|
55
52
|
...semiModularAccountBase,
|
|
56
53
|
delegationAddress: lowerAddress(DefaultMAV2Address.SMAV2_7702),
|
|
57
54
|
};
|
|
58
|
-
/**
|
|
59
|
-
* Static implementation logic for WebAuthnModularAccountV2.
|
|
60
|
-
*
|
|
61
|
-
* TODO(v5): update JSDoc format when doc-gen supports structs or records.
|
|
62
|
-
*/
|
|
63
|
-
export const webAuthnModularAccountV2StaticImpl = {
|
|
64
|
-
entryPoint,
|
|
65
|
-
accountAbi: modularAccountAbi,
|
|
66
|
-
accountImplementation: lowerAddress(DefaultMAV2Address.MAV2),
|
|
67
|
-
factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY_WEBAUTHN),
|
|
68
|
-
factoryAbi: webAuthnFactoryAbi,
|
|
69
|
-
getFactoryData: (args) => {
|
|
70
|
-
const { x, y } = parsePublicKey(args.ownerPublicKey);
|
|
71
|
-
return encodeFunctionData({
|
|
72
|
-
abi: webAuthnFactoryAbi,
|
|
73
|
-
functionName: "createWebAuthnAccount",
|
|
74
|
-
args: [x, y, args.salt, args.entityId],
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
predictAccountAddress: (args) => {
|
|
78
|
-
return predictModularAccountV2Address({
|
|
79
|
-
factoryAddress: DefaultMAV2Address.MAV2_FACTORY_WEBAUTHN,
|
|
80
|
-
implementationAddress: DefaultMAV2Address.MAV2,
|
|
81
|
-
type: "WebAuthn",
|
|
82
|
-
salt: args.salt,
|
|
83
|
-
ownerPublicKey: args.ownerPublicKey,
|
|
84
|
-
entityId: args.entityId,
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
55
|
//# sourceMappingURL=mav2StaticImpl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mav2StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v2/mav2StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"mav2StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v2/mav2StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAgBrE,gFAAgF;AAChF,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,eAAe;IACpB,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,sEAAsE;AACtE,MAAM,sBAAsB,GAAG;IAC7B,UAAU;IACV,UAAU,EAAE,6BAA6B;CACQ,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAmC;IAC5E,GAAG,sBAAsB;IACzB,qBAAqB,EAAE,YAAY,CAAC,kBAAkB,CAAC,cAAc,CAAC;IACtE,cAAc,EAAE,YAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC;IAC7D,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,CAAC,IAAqC,EAAE,EAAE;QACxD,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,iBAAiB;YACtB,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;IACD,qBAAqB,EAAE,CAAC,IAAqC,EAAE,EAAE;QAC/D,OAAO,8BAA8B,CAAC;YACpC,cAAc,EAAE,kBAAkB,CAAC,YAAY;YAC/C,qBAAqB,EAAE,kBAAkB,CAAC,cAAc;YACxD,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,KAAK;SACzB,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAWF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAC3C;IACE,GAAG,sBAAsB;IACzB,iBAAiB,EAAE,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC;CAC/D,CAAC","sourcesContent":["import { encodeFunctionData, type Address } from \"viem\";\nimport { entryPoint07Abi, entryPoint07Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nimport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nimport { DefaultAddress as DefaultMAV2Address } from \"./utils/account.js\";\nimport { predictModularAccountV2Address } from \"./predictAddress.js\";\n\nexport type SemiModularAccountV2FactoryArgs = {\n owner: Address;\n salt: bigint;\n};\n\nexport type SemiModularAccountV2StaticImpl = StaticSmartAccountImplementation<\n false,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n// Shared entryPoint configuration across all modular account v2 implementations\nconst entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address,\n version: \"0.7\",\n} as const;\n\n// Shared base for semi-modular account implementations (SMA and 7702)\nconst semiModularAccountBase = {\n entryPoint,\n accountAbi: semiModularAccountBytecodeAbi,\n} satisfies Partial<SemiModularAccountV2StaticImpl>;\n\n/**\n * Static implementation logic for SemiModularAccountV2.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccountV2StaticImpl: SemiModularAccountV2StaticImpl = {\n ...semiModularAccountBase,\n accountImplementation: lowerAddress(DefaultMAV2Address.SMAV2_BYTECODE),\n factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY),\n factoryAbi: accountFactoryAbi,\n getFactoryData: (args: SemiModularAccountV2FactoryArgs) => {\n return encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [args.owner, args.salt],\n });\n },\n predictAccountAddress: (args: SemiModularAccountV2FactoryArgs) => {\n return predictModularAccountV2Address({\n factoryAddress: DefaultMAV2Address.MAV2_FACTORY,\n implementationAddress: DefaultMAV2Address.SMAV2_BYTECODE,\n type: \"SMA\",\n salt: args.salt,\n ownerAddress: args.owner,\n });\n },\n};\n\nexport type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<\n true,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n/**\n * Static implementation logic for SemiModularAccount7702.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl =\n {\n ...semiModularAccountBase,\n delegationAddress: lowerAddress(DefaultMAV2Address.SMAV2_7702),\n };\n"]}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { encodeAbiParameters } from "viem";
|
|
2
2
|
import { timeRangeModuleAbi } from "./abis/timeRangeModuleAbi.js";
|
|
3
3
|
import { HookType } from "../../types.js";
|
|
4
|
+
import { BaseError } from "@alchemy/common";
|
|
4
5
|
export const TimeRangeModule = {
|
|
5
6
|
abi: timeRangeModuleAbi,
|
|
6
7
|
buildHook: (installArgs, address) => {
|
|
7
8
|
if (installArgs.validUntil > 2 ** 48 - 1) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new BaseError("TimeRangeModule.buildHook: validUntil > type(uint48).max");
|
|
9
10
|
}
|
|
10
11
|
if (installArgs.validAfter > 2 ** 48 - 1) {
|
|
11
|
-
throw new
|
|
12
|
+
throw new BaseError("TimeRangeModule.buildHook: validAfter > type(uint48).max");
|
|
12
13
|
}
|
|
13
14
|
const installData = TimeRangeModule.encodeOnInstallData(installArgs);
|
|
14
15
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../../../src/ma-v2/modules/time-range-module/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAA0B,MAAM,MAAM,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
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AE,QAAQ;aACf;SACF,EACD,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,CACnC,CAAC;IACJ,CAAC;IACD,qBAAqB,EAAE,CAAC,IAA0B,EAAO,EAAE;QACzD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,OAAO,mBAAmB,CACxB;YACE;gBACE,IAAI,EAAE,QAAQ;aACf;SACF,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IACJ,CAAC;IACD,kBAAkB,EAAE,CAAC,IAIpB,EAAO,EAAE;QACR,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;QAElD,OAAO,mBAAmB,CACxB;YACE;gBACE,IAAI,EAAE,QAAQ;aACf;YACD;gBACE,IAAI,EAAE,QAAQ;aACf;YACD;gBACE,IAAI,EAAE,QAAQ;aACf;SACF,EACD,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,CACnC,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { encodeAbiParameters, type Address, type Hex } from \"viem\";\n\nimport { timeRangeModuleAbi } from \"./abis/timeRangeModuleAbi.js\";\nimport { HookType, type HookConfig } from \"../../types.js\";\nimport { BaseError } from \"@alchemy/common\";\n\nexport const TimeRangeModule = {\n abi: timeRangeModuleAbi,\n buildHook: (\n installArgs: {\n entityId: number;\n validUntil: number;\n validAfter: number;\n },\n address: Address,\n ): { hookConfig: HookConfig; initData: Hex } => {\n if (installArgs.validUntil > 2 ** 48 - 1) {\n throw new BaseError(\n \"TimeRangeModule.buildHook: validUntil > type(uint48).max\",\n );\n }\n\n if (installArgs.validAfter > 2 ** 48 - 1) {\n throw new BaseError(\n \"TimeRangeModule.buildHook: validAfter > type(uint48).max\",\n );\n }\n\n const installData = TimeRangeModule.encodeOnInstallData(installArgs);\n return {\n hookConfig: {\n address: address,\n entityId: installArgs.entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: false,\n hasPostHooks: false,\n },\n initData: installData,\n };\n },\n encodeOnInstallData: (args: {\n entityId: number;\n validUntil: number;\n validAfter: number;\n }): Hex => {\n const { entityId, validUntil, validAfter } = args;\n\n return encodeAbiParameters(\n [\n {\n type: \"uint32\",\n },\n {\n type: \"uint48\",\n },\n {\n type: \"uint48\",\n },\n ],\n [entityId, validUntil, validAfter],\n );\n },\n encodeOnUninstallData: (args: { entityId: number }): Hex => {\n const { entityId } = args;\n\n return encodeAbiParameters(\n [\n {\n type: \"uint32\",\n },\n ],\n [entityId],\n );\n },\n encodeSetTimeRange: (args: {\n entityId: number;\n validUntil: number;\n validAfter: number;\n }): Hex => {\n const { entityId, validUntil, validAfter } = args;\n\n return encodeAbiParameters(\n [\n {\n type: \"uint32\",\n },\n {\n type: \"uint48\",\n },\n {\n type: \"uint48\",\n },\n ],\n [entityId, validUntil, validAfter],\n );\n },\n};\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type Address, type Hex } from "viem";
|
|
1
|
+
import { type Address, type Client, type Hex } from "viem";
|
|
2
|
+
import { type EntryPointVersion } from "viem/account-abstraction";
|
|
2
3
|
export type PredictModularAccountV2AddressParams = {
|
|
3
4
|
factoryAddress: Address;
|
|
4
5
|
implementationAddress: Address;
|
|
@@ -10,13 +11,9 @@ export type PredictModularAccountV2AddressParams = {
|
|
|
10
11
|
} | {
|
|
11
12
|
type: "SMA";
|
|
12
13
|
ownerAddress: Address;
|
|
13
|
-
} | {
|
|
14
|
-
type: "WebAuthn";
|
|
15
|
-
ownerPublicKey: Hex;
|
|
16
|
-
entityId: number;
|
|
17
14
|
});
|
|
18
15
|
/**
|
|
19
|
-
* Predicts the address of a modular account V2 based on the provided parameters, which include factory address, salt, and implementation address. This function supports different types of accounts including "SMA"
|
|
16
|
+
* Predicts the address of a modular account V2 based on the provided parameters, which include factory address, salt, and implementation address. This function supports different types of accounts including "SMA" and "MA".
|
|
20
17
|
*
|
|
21
18
|
* @example
|
|
22
19
|
* ```ts
|
|
@@ -35,3 +32,22 @@ export type PredictModularAccountV2AddressParams = {
|
|
|
35
32
|
* @returns {Address} The predicted address for the modular account V2.
|
|
36
33
|
*/
|
|
37
34
|
export declare function predictModularAccountV2Address(params: PredictModularAccountV2AddressParams): Address;
|
|
35
|
+
export type GetModularAccountV2AddressFromFactoryDataParams = {
|
|
36
|
+
client: Client;
|
|
37
|
+
factoryAddress: Address;
|
|
38
|
+
factoryData: Hex;
|
|
39
|
+
implementationAddress: Address;
|
|
40
|
+
entryPoint?: {
|
|
41
|
+
version: EntryPointVersion;
|
|
42
|
+
address: Address;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Gets the modular account v2 address from factory data.
|
|
47
|
+
* If the factory is a known default (SMA), decodes the args and predicts without RPC.
|
|
48
|
+
* Otherwise falls back to calling the entry point's getSenderAddress.
|
|
49
|
+
*
|
|
50
|
+
* @param {GetModularAccountV2AddressFromFactoryDataParams} params - The parameters
|
|
51
|
+
* @returns {Promise<Address>} The account address
|
|
52
|
+
*/
|
|
53
|
+
export declare function getModularAccountV2AddressFromFactoryData({ client, factoryAddress, factoryData, implementationAddress, entryPoint, }: GetModularAccountV2AddressFromFactoryDataParams): Promise<Address>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { assertNever } from "@alchemy/common";
|
|
2
|
-
import { concatHex, encodePacked, getContractAddress, keccak256, } from "viem";
|
|
3
|
-
import {
|
|
2
|
+
import { concatHex, decodeFunctionData, encodePacked, getContractAddress, isAddressEqual, keccak256, } from "viem";
|
|
3
|
+
import { entryPoint07Address, } from "viem/account-abstraction";
|
|
4
|
+
import { accountFactoryAbi } from "./abis/accountFactoryAbi.js";
|
|
5
|
+
import { DefaultAddress } from "./utils/account.js";
|
|
6
|
+
import { getSenderFromFactoryData } from "../utils.js";
|
|
4
7
|
/**
|
|
5
|
-
* Predicts the address of a modular account V2 based on the provided parameters, which include factory address, salt, and implementation address. This function supports different types of accounts including "SMA"
|
|
8
|
+
* Predicts the address of a modular account V2 based on the provided parameters, which include factory address, salt, and implementation address. This function supports different types of accounts including "SMA" and "MA".
|
|
6
9
|
*
|
|
7
10
|
* @example
|
|
8
11
|
* ```ts
|
|
@@ -37,12 +40,6 @@ export function predictModularAccountV2Address(params) {
|
|
|
37
40
|
combinedSalt: getCombinedSaltK1(params.ownerAddress, salt, params.entityId),
|
|
38
41
|
initcode: getProxyBytecode(implementationAddress),
|
|
39
42
|
};
|
|
40
|
-
case "WebAuthn":
|
|
41
|
-
const { x, y } = parsePublicKey(params.ownerPublicKey);
|
|
42
|
-
return {
|
|
43
|
-
combinedSalt: getCombinedSaltWebAuthn({ x, y }, salt, params.entityId),
|
|
44
|
-
initcode: getProxyBytecode(implementationAddress),
|
|
45
|
-
};
|
|
46
43
|
default:
|
|
47
44
|
return assertNever(params, "Unexpected MAv2 type");
|
|
48
45
|
}
|
|
@@ -57,9 +54,6 @@ export function predictModularAccountV2Address(params) {
|
|
|
57
54
|
function getCombinedSaltK1(ownerAddress, salt, entityId) {
|
|
58
55
|
return keccak256(encodePacked(["address", "uint256", "uint32"], [ownerAddress, salt, entityId]));
|
|
59
56
|
}
|
|
60
|
-
function getCombinedSaltWebAuthn(ownerPublicKey, salt, entityId) {
|
|
61
|
-
return keccak256(encodePacked(["uint256", "uint256", "uint256", "uint32"], [ownerPublicKey.x, ownerPublicKey.y, salt, entityId]));
|
|
62
|
-
}
|
|
63
57
|
function getProxyBytecode(implementationAddress) {
|
|
64
58
|
return concatHex([
|
|
65
59
|
"0x603d3d8160223d3973",
|
|
@@ -70,4 +64,44 @@ function getProxyBytecode(implementationAddress) {
|
|
|
70
64
|
function getProxyBytecodeWithImmutableArgs(implementationAddress, immutableArgs) {
|
|
71
65
|
return `0x6100513d8160233d3973${implementationAddress.slice(2)}60095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3${immutableArgs.slice(2)}`;
|
|
72
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the modular account v2 address from factory data.
|
|
69
|
+
* If the factory is a known default (SMA), decodes the args and predicts without RPC.
|
|
70
|
+
* Otherwise falls back to calling the entry point's getSenderAddress.
|
|
71
|
+
*
|
|
72
|
+
* @param {GetModularAccountV2AddressFromFactoryDataParams} params - The parameters
|
|
73
|
+
* @returns {Promise<Address>} The account address
|
|
74
|
+
*/
|
|
75
|
+
export async function getModularAccountV2AddressFromFactoryData({ client, factoryAddress, factoryData, implementationAddress, entryPoint = {
|
|
76
|
+
version: "0.7",
|
|
77
|
+
address: entryPoint07Address,
|
|
78
|
+
}, }) {
|
|
79
|
+
// Try SMA factory
|
|
80
|
+
if (isAddressEqual(factoryAddress, DefaultAddress.MAV2_FACTORY)) {
|
|
81
|
+
try {
|
|
82
|
+
const decoded = decodeFunctionData({
|
|
83
|
+
abi: accountFactoryAbi,
|
|
84
|
+
data: factoryData,
|
|
85
|
+
});
|
|
86
|
+
if (decoded.functionName === "createSemiModularAccount") {
|
|
87
|
+
const [decodedOwner, decodedSalt] = decoded.args;
|
|
88
|
+
return predictModularAccountV2Address({
|
|
89
|
+
factoryAddress,
|
|
90
|
+
implementationAddress,
|
|
91
|
+
salt: decodedSalt,
|
|
92
|
+
type: "SMA",
|
|
93
|
+
ownerAddress: decodedOwner,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Decode failed, fall through to RPC
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return getSenderFromFactoryData(client, {
|
|
102
|
+
factory: factoryAddress,
|
|
103
|
+
factoryData,
|
|
104
|
+
entryPoint,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
73
107
|
//# sourceMappingURL=predictAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predictAddress.js","sourceRoot":"","sources":["../../../src/ma-v2/predictAddress.ts"],"names":[],"mappings":"AAAA,OAAO,E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0B,EAAE,CAAC;gBACxD,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;gBACjD,OAAO,8BAA8B,CAAC;oBACpC,cAAc;oBACd,qBAAqB;oBACrB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,KAAK;oBACX,YAAY,EAAE,YAAY;iBAC3B,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,wBAAwB,CAAC,MAAM,EAAE;QACtC,OAAO,EAAE,cAAc;QACvB,WAAW;QACX,UAAU;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assertNever } from \"@alchemy/common\";\nimport {\n concatHex,\n decodeFunctionData,\n encodePacked,\n getContractAddress,\n isAddressEqual,\n keccak256,\n type Address,\n type Client,\n type Hex,\n} from \"viem\";\nimport {\n entryPoint07Address,\n type EntryPointVersion,\n} from \"viem/account-abstraction\";\nimport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nimport { DefaultAddress } from \"./utils/account.js\";\nimport { getSenderFromFactoryData } from \"../utils.js\";\n\nexport type PredictModularAccountV2AddressParams = {\n factoryAddress: Address;\n implementationAddress: Address; // Should be the implementation address of the account type you are predicting the address for.\n salt: bigint;\n} & (\n | {\n type: \"MA\";\n ownerAddress: Address;\n entityId: number;\n }\n | {\n type: \"SMA\";\n ownerAddress: Address;\n }\n);\n\n/**\n * Predicts the address of a modular account V2 based on the provided parameters, which include factory address, salt, and implementation address. This function supports different types of accounts including \"SMA\" and \"MA\".\n *\n * @example\n * ```ts\n * import { predictModularAccountV2Address } from \"@alchemy/smart-accounts\";\n *\n * const accountAddress = predictModularAccountV2Address({\n * factoryAddress: \"0xFactoryAddress\" as Address,\n * implementationAddress: \"0xImplementation\" as Address,\n * salt: 0n,\n * type: \"SMA\",\n * ownerAddress: \"0xOwner\" as Address,\n * });\n * ```\n *\n * @param {PredictModularAccountV2AddressParams} params The parameters for predicting the modular account address, including `factoryAddress`, `salt`, `implementationAddress`, and additional properties based on the account type.\n * @returns {Address} The predicted address for the modular account V2.\n */\nexport function predictModularAccountV2Address(\n params: PredictModularAccountV2AddressParams,\n): Address {\n const { factoryAddress, salt, implementationAddress } = params;\n\n // Note(v4): prediction for MA is currently untested, because it is not supported as an account type yet.\n // Prior to using this prediction logic, ensure that the counterfactual computation is correct by updating `predictAddress.test.ts` to include a test for MA.\n const { combinedSalt, initcode } = (() => {\n switch (params.type) {\n case \"SMA\":\n // MAv2 factory uses max uint32 for SMA entityId\n return {\n combinedSalt: getCombinedSaltK1(\n params.ownerAddress,\n salt,\n 0xffffffff,\n ),\n initcode: getProxyBytecodeWithImmutableArgs(\n implementationAddress,\n params.ownerAddress,\n ),\n };\n case \"MA\":\n return {\n combinedSalt: getCombinedSaltK1(\n params.ownerAddress,\n salt,\n params.entityId,\n ),\n initcode: getProxyBytecode(implementationAddress),\n };\n default:\n return assertNever(params, \"Unexpected MAv2 type\");\n }\n })();\n\n return getContractAddress({\n from: factoryAddress,\n opcode: \"CREATE2\",\n salt: combinedSalt,\n bytecode: initcode,\n });\n}\n\nfunction getCombinedSaltK1(\n ownerAddress: Address,\n salt: bigint,\n entityId: number,\n): Hex {\n return keccak256(\n encodePacked(\n [\"address\", \"uint256\", \"uint32\"],\n [ownerAddress, salt, entityId],\n ),\n );\n}\n\nfunction getProxyBytecode(implementationAddress: Address): Hex {\n return concatHex([\n \"0x603d3d8160223d3973\",\n implementationAddress,\n \"0x60095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3\",\n ]);\n}\n\nfunction getProxyBytecodeWithImmutableArgs(\n implementationAddress: Address,\n immutableArgs: Hex,\n): Hex {\n return `0x6100513d8160233d3973${implementationAddress.slice(\n 2,\n )}60095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3${immutableArgs.slice(\n 2,\n )}`;\n}\n\nexport type GetModularAccountV2AddressFromFactoryDataParams = {\n client: Client;\n factoryAddress: Address;\n factoryData: Hex;\n implementationAddress: Address;\n entryPoint?: {\n version: EntryPointVersion;\n address: Address;\n };\n};\n\n/**\n * Gets the modular account v2 address from factory data.\n * If the factory is a known default (SMA), decodes the args and predicts without RPC.\n * Otherwise falls back to calling the entry point's getSenderAddress.\n *\n * @param {GetModularAccountV2AddressFromFactoryDataParams} params - The parameters\n * @returns {Promise<Address>} The account address\n */\nexport async function getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData,\n implementationAddress,\n entryPoint = {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n}: GetModularAccountV2AddressFromFactoryDataParams): Promise<Address> {\n // Try SMA factory\n if (isAddressEqual(factoryAddress, DefaultAddress.MAV2_FACTORY)) {\n try {\n const decoded = decodeFunctionData({\n abi: accountFactoryAbi,\n data: factoryData,\n });\n if (decoded.functionName === \"createSemiModularAccount\") {\n const [decodedOwner, decodedSalt] = decoded.args;\n return predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt: decodedSalt,\n type: \"SMA\",\n ownerAddress: decodedOwner,\n });\n }\n } catch {\n // Decode failed, fall through to RPC\n }\n }\n return getSenderFromFactoryData(client, {\n factory: factoryAddress,\n factoryData,\n entryPoint,\n });\n}\n"]}
|
|
@@ -8,18 +8,15 @@ import type { ModularAccountV2Base } from "../accounts/base.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const DefaultAddress: {
|
|
10
10
|
MAV2_FACTORY: "0x00000000000017c61b5bEe81050EC8eFc9c6fecd";
|
|
11
|
-
MAV2_FACTORY_WEBAUTHN: "0x55010E571dCf07e254994bfc88b9C1C8FAe31960";
|
|
12
11
|
SMAV2_BYTECODE: "0x000000000000c5A9089039570Dd36455b5C07383";
|
|
13
12
|
SMAV2_STORAGE: "0x0000000000006E2f9d80CaEc0Da6500f005EB25A";
|
|
14
13
|
SMAV2_7702: "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
15
|
-
MAV2: "0x00000000000002377B26b1EdA7b0BC371C60DD4f";
|
|
16
14
|
};
|
|
17
15
|
/**
|
|
18
16
|
* A mapping of default addresses for the ModularAccountV2 modules.
|
|
19
17
|
*/
|
|
20
18
|
export declare const DefaultModuleAddress: {
|
|
21
19
|
SINGLE_SIGNER_VALIDATION: "0x00000000000099DE0BF6fA90dEB851E2A2df7d83";
|
|
22
|
-
WEBAUTHN_VALIDATION: "0x0000000000001D9d34E07D9834274dF9ae575217";
|
|
23
20
|
TIME_RANGE: "0x00000000000082B8e2012be914dFA4f62A0573eA";
|
|
24
21
|
PAYMASTER_GUARD: "0x0000000000001aA7A7F7E29abe0be06c72FD42A1";
|
|
25
22
|
NATIVE_TOKEN_LIMIT: "0x00000000000001e541f0D090868FBe24b59Fbe06";
|