Skip to content

Commit

Permalink
[#397] Emit event on signer deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Apr 29, 2024
1 parent 64fda14 commit 5b2f5d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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);

/**
* @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

0 comments on commit 5b2f5d0

Please sign in to comment.