Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit signer created event #402

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/passkey/contracts/SafeWebAuthnSignerFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contract SafeWebAuthnSignerFactory is ISafeSignerFactory {
if (_hasNoCode(signer)) {
SafeWebAuthnSignerProxy created = new SafeWebAuthnSignerProxy{salt: bytes32(0)}(address(SINGLETON), x, y, verifiers);
require(address(created) == signer);
emit Created(signer, x, y, verifiers);
}
}

Expand Down
9 changes: 9 additions & 0 deletions modules/passkey/contracts/interfaces/ISafeSignerFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import {P256} from "../libraries/P256.sol";
* @custom:security-contact bounty@safe.global
*/
interface ISafeSignerFactory {
/**
* @notice Emitted when a new signer is created.
* @param signer The signer address.
* @param x The x-coordinate of the public key.
* @param y The y-coordinate of the public key.
* @param verifiers The P-256 verifiers to use.
*/
event Created(address signer, uint256 x, uint256 y, P256.Verifiers verifiers);
akshay-ap marked this conversation as resolved.
Show resolved Hide resolved

/**
* @notice Gets the unique signer address for the specified data.
* @dev The unique signer address must be unique for some given data. The signer is not
Expand Down
14 changes: 14 additions & 0 deletions modules/passkey/test/SafeWebAuthnSignerProxyFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ describe('SafeWebAuthnSignerFactory', () => {
expect(await factory.createSigner.staticCall(x, y, verifiers)).to.eq(signer)
await expect(factory.createSigner(x, y, verifiers)).to.not.be.reverted
})

it('Should emit event only once', async () => {
const { factory, verifiers } = await setupTests()

const x = ethers.id('publicKey.x')
const y = ethers.id('publicKey.y')

const signer = await factory.createSigner.staticCall(x, y, verifiers)

await expect(factory.createSigner(x, y, verifiers))
.to.emit(factory, 'Created')
.withArgs(signer, x, y, verifiers)
await expect(factory.createSigner(x, y, verifiers)).not.to.emit(factory, 'Created')
})
})

describe('isValidSignatureForSigner', function () {
Expand Down
Loading