Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from abstraction-hq/20-use-credential-id-as-sa…
Browse files Browse the repository at this point in the history
…lt-for-passkey-module

use credential id as salt for passkey module
  • Loading branch information
imduchuyyy authored Jun 22, 2024
2 parents 3b6cd14 + 44fcd13 commit 8646cb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 6 additions & 8 deletions src/WalletFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ contract WalletFactory is IWalletFactory {
return Wallet(walletAddress);
}

function _createPasskeyModule(uint256 x, uint256 y) internal returns (PasskeyModule) {
bytes32 salt = keccak256(abi.encodePacked(x, y));
address passkeyModuleAddress = getPasskeyAddress(x, y);
function _createPasskeyModule(uint256 x, uint256 y, bytes32 salt) internal returns (PasskeyModule) {
address passkeyModuleAddress = getPasskeyAddress(salt);
if (passkeyModuleAddress.code.length > 0) {
return PasskeyModule(passkeyModuleAddress);
}
Expand All @@ -50,12 +49,12 @@ contract WalletFactory is IWalletFactory {
return _createWallet(initKey, salt);
}

function createPasskey(uint256 x, uint256 y) external returns (PasskeyModule) {
return _createPasskeyModule(x, y);
function createPasskey(uint256 x, uint256 y, bytes32 salt) external returns (PasskeyModule) {
return _createPasskeyModule(x, y, salt);
}

function createWalletWithPasskey(uint256 x, uint256 y, bytes32 salt) external returns (Wallet) {
PasskeyModule passkeyModule = _createPasskeyModule(x, y);
PasskeyModule passkeyModule = _createPasskeyModule(x, y, salt);
return _createWallet(address(passkeyModule), salt);
}

Expand All @@ -77,8 +76,7 @@ contract WalletFactory is IWalletFactory {
);
}

function getPasskeyAddress(uint256 x, uint256 y) public view returns (address) {
bytes32 salt = keccak256(abi.encodePacked(x, y));
function getPasskeyAddress(bytes32 salt) public view returns (address) {
return payable(
Create2.computeAddress(
salt,
Expand Down
3 changes: 1 addition & 2 deletions test/WalletFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract WalletFactoryTest is Test {
uint256 y = 79473938854726638551736530376995476499049493858003728502280535141260854783821;

Wallet wallet = walletFactory.createWalletWithPasskey(x, y, salt);
PasskeyModule passkeyModule = PasskeyModule(walletFactory.getPasskeyAddress(x, y));
PasskeyModule passkeyModule = PasskeyModule(walletFactory.getPasskeyAddress(salt));

require(wallet.isValidKey(address(passkeyModule)), "passkey module should be valid key");
require(passkeyModule.x() == x, "x should be equal");
Expand All @@ -41,7 +41,6 @@ contract WalletFactoryTest is Test {
function testComputeAddress() external {
bytes32 salt = keccak256("test wallet");
address walletAddress = walletFactory.getWalletAddress(salt);

Wallet wallet = walletFactory.createWallet(address(this), salt);

require(walletAddress == address(wallet), "wallet address should be equal");
Expand Down
9 changes: 6 additions & 3 deletions test/modules/PasskeyModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ contract PasskeyModuleTest is Test {
}

function testPassKey() external {
bytes32 salt = keccak256("testCreateWalletWithPasskey");
passkeyModule = walletFactory.createPasskey(
28203248099655634232680422976510411012986437076966613883671554831358983509938,
79473938854726638551736530376995476499049493858003728502280535141260854783821
79473938854726638551736530376995476499049493858003728502280535141260854783821,
salt
);
bytes memory signature =
hex"00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000001eb6f6689e7b96f60dcae3542888f9d094a9abb8e04bd391104d6ee79a9f0967d3bc293dc51c51b23f9063ae81bb2e4a99b520f5f04cda804f0dd80b4c8d7f353000000000000000000000000000000000000000000000000000000000000002549960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97631d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000867b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a22644c4836595a6f78345332616a6f4e4a384c374d47734657436c75584c6258514a62306e466c7377685930222c226f726967696e223a22687474703a2f2f6c6f63616c686f73743a33303030222c2263726f73734f726967696e223a66616c73657d0000000000000000000000000000000000000000000000000000";
Expand All @@ -37,10 +39,11 @@ contract PasskeyModuleTest is Test {
}

function testComputeAddress() external {
bytes32 salt = keccak256("testCreateWalletWithPasskey");
uint256 x = 28203248099655634232680422976510411012986437076966613883671554831358983509938;
uint256 y = 79473938854726638551736530376995476499049493858003728502280535141260854783821;
address passkeyModuleAddress = walletFactory.getPasskeyAddress(x, y);
passkeyModule = walletFactory.createPasskey(x, y);
address passkeyModuleAddress = walletFactory.getPasskeyAddress(salt);
passkeyModule = walletFactory.createPasskey(x, y, salt);

require(passkeyModuleAddress == address(passkeyModule), "passkey module address should be equal");
}
Expand Down

0 comments on commit 8646cb3

Please sign in to comment.