diff --git a/src/sdk/account/toNexusAccount.ts b/src/sdk/account/toNexusAccount.ts index f4381e12..1f007a0c 100644 --- a/src/sdk/account/toNexusAccount.ts +++ b/src/sdk/account/toNexusAccount.ts @@ -402,6 +402,7 @@ export const toNexusAccount = async ( const getNonce = async (parameters?: { key?: bigint validationMode?: "0x00" | "0x01" + moduleAddress?: Address }): Promise => { try { const TIMESTAMP_ADJUSTMENT = 16777215n @@ -410,7 +411,7 @@ export const toNexusAccount = async ( const key: string = concat([ toHex(defaultedKey, { size: 3 }), defaultedValidationMode, - module.address as Hex + parameters?.moduleAddress ?? (module.address as Hex) ]) const accountAddress = await getCounterFactualAddress() diff --git a/src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts b/src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts index 55bcab8d..367a4cd0 100644 --- a/src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts +++ b/src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts @@ -1,10 +1,12 @@ import { getAccount } from "@rhinestone/module-sdk/account" import { + OWNABLE_VALIDATOR_ADDRESS, type Session, SmartSessionMode, - decodeSmartSessionSignature, encodeSmartSessionSignature, + encodeValidationData, getEnableSessionDetails, + getOwnableValidatorMockSignature, getSmartSessionsValidator, getSudoPolicy } from "@rhinestone/module-sdk/module" @@ -27,7 +29,7 @@ import { getUserOperationHash } from "viem/account-abstraction" import { generatePrivateKey, privateKeyToAccount } from "viem/accounts" -import { afterAll, beforeAll, describe, expect, test } from "vitest" +import { beforeAll, describe, expect, test } from "vitest" import { CounterAbi } from "../../../test/__contracts/abi/CounterAbi" import { testAddresses } from "../../../test/callDatas" import { toNetwork } from "../../../test/testSetup" @@ -38,11 +40,8 @@ import { type NexusClient, createSmartAccountClient } from "../../clients/createSmartAccountClient" -import { - MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS, - SIMPLE_SESSION_VALIDATOR_ADDRESS -} from "../../constants" import { generateSalt } from "./Helpers" +import { MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS } from "../../constants" describe("modules.smartSessions.enable.mode.dx", async () => { let network: NetworkConfig @@ -161,8 +160,11 @@ describe("modules.smartSessions.enable.mode.dx", async () => { } const session: Session = { - sessionValidator: SIMPLE_SESSION_VALIDATOR_ADDRESS, - sessionValidatorInitData: sessionPublicKey, + sessionValidator: OWNABLE_VALIDATOR_ADDRESS, + sessionValidatorInitData: encodeValidationData({ + threshold: 1, + owners: [sessionPublicKey] + }), salt: generateSalt(), userOpPolicies: [], erc7739Policies: { @@ -199,23 +201,35 @@ describe("modules.smartSessions.enable.mode.dx", async () => { const sessionDetailKeys = Object.keys(sessionDetails) console.log({ sessionDetailKeys }) + const permissionEnableRawSig = await eoaAccount.signMessage({ + message: { raw: permissionEnableHash } + }) + sessionDetails.enableSessionData.enableSession.permissionEnableSig = - await eoaAccount.signMessage({ - message: { raw: permissionEnableHash } - }) + encodePacked( + ["address", "bytes"], + [MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS, permissionEnableRawSig] + ) + + const nonce = await nexusClient.account.getNonce({ + // @ts-ignore + moduleAddress: OWNABLE_VALIDATOR_ADDRESS + }) - const signature = encodeSmartSessionSignature(sessionDetails) + console.log({ nonce }) - const decodededSignature = decodeSmartSessionSignature({ - signature, - account: nexusAccount - }) + // const signature = encodeSmartSessionSignature(sessionDetails) + + // const decodededSignature = decodeSmartSessionSignature({ + // signature, + // account: nexusAccount + // }) - expect(decodededSignature.mode).toBe(SmartSessionMode.UNSAFE_ENABLE) - expect(decodededSignature.permissionId).toBe(sessionDetails.permissionId) - expect(decodededSignature.signature).toBe(sessionDetails.signature) + // expect(decodededSignature.mode).toBe(SmartSessionMode.UNSAFE_ENABLE) + // expect(decodededSignature.permissionId).toBe(sessionDetails.permissionId) + // expect(decodededSignature.signature).toBe(sessionDetails.signature) - console.log({ decodededSignature }) + // console.log({ decodededSignature }) const calls = [ { @@ -233,10 +247,15 @@ describe("modules.smartSessions.enable.mode.dx", async () => { console.log({ calls }) + sessionDetails.signature = getOwnableValidatorMockSignature({ + threshold: 1 + }) + const userOperation = await nexusClient.prepareUserOperation({ account: nexusClient.account, calls, - signature + nonce, + signature: encodeSmartSessionSignature(sessionDetails) }) const userOpHashToSign = getUserOperationHash({