Skip to content

Conversation

@enis-incentiv
Copy link
Collaborator

Story:

https://incentiv-net.atlassian.net/browse/IND-180

Summary:

This PR updates the SimpleAccountAPI in the UI SDK to align with the merged SimpleAccountFactory contract, which now supports both Externally Owned Accounts (EOA) and Passkey accounts within a single factory. Additionally, the PR introduces versioned signatures to differentiate between EOA (version == 0) and Passkey (version == 1) signatures, ensuring compatibility with the unified contract structure.


Changes Implemented:

1. Updated getAccountInitCode Method

  • ABI Adjustment: Updated the createAccount ABI in getAccountInitCode to reflect the new contract’s unified structure:
    "function createAccount(address owner, bytes32[2] memory publicKey, uint256 salt) external payable returns (SimpleAccount)"
  • Parameter Adjustment:
    • For EOA accounts, provided ownerAddress, set publicKey to [HashZero, HashZero], and used this.index as the salt.
    • For Passkey accounts, provided publicKey values from the owner, set owner to AddressZero, and used this.index as the salt.
  • Encoded Function Data: Used the adjusted ABI and parameters to encode the function data for createAccount.
  • Factory Address Concatenation: Concatenated this.factory.address with the encoded function data, ensuring correct initialization code for the account type.

2. Versioned Signature Support in signUserOpHash

  • Version Byte Addition:
    • Added a version byte to the signUserOpHash return value to distinguish between EOA (version == 0) and Passkey (version == 1) signatures.
    • Used zeroPad and hexlify to prepend a 0x00 byte for EOAs or 0x01 for Passkey accounts to the signed message.
  • Simplified Signature Concatenation: Concatenated the version byte with the signed message, ensuring consistent versioning across account types.

Testing Recommendations:

  1. Account Initialization Tests:

    • Verify that getAccountInitCode produces the correct initialization code for:
      • EOA Accounts: Confirm that the owner is populated with ownerAddress, publicKey is zeroed, and the correct salt is used.
      • Passkey Accounts: Confirm that publicKey is set with the owner’s publicKey coordinates, owner is zeroed, and the correct salt is used.
    • Test initialization for both account types using sample-aa-wallet to ensure compatibility.
  2. Signature Versioning Tests:

    • Verify that signUserOpHash prepends the correct version byte:
      • 0x00 for EOA accounts.
      • 0x01 for Passkey accounts.
    • Confirm that the resulting signature is valid for both EOA and Passkey accounts using the sample-aa-wallet.
  3. Edge Case Tests:

    • Incorrect Account Type: Confirm that initialization fails if neither owner nor publicKey is correctly set in the account configuration.

Additional Notes:

  • Compatibility: This update aligns the UI SDK with the merged SimpleAccountFactory and versioned signature changes, ensuring seamless interaction with both EOA and Passkey accounts.
  • Sample AA Wallet Testing: Use sample-aa-wallet to test both MetaMask (EOA) and Passkey account flows, ensuring backward compatibility and functionality consistency.

This PR improves flexibility and compatibility with the unified SimpleAccountFactory, enhancing user experience across account types. Please review and test to ensure seamless functionality.

@enis-incentiv enis-incentiv force-pushed the IND-180-update-ui-sdk-for-unified-account-factory-and-versioned-signatures branch from d6e31e0 to 8f30c68 Compare October 25, 2024 19:41
@DrenIncentiv
Copy link
Contributor

Looks great, thank you!

@DrenIncentiv DrenIncentiv merged commit 5a117f1 into main Oct 27, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants