Skip to content

Commit

Permalink
✨(gateway) Add arguments to errors
Browse files Browse the repository at this point in the history
- Remove requirement on sender being the identity owner
  • Loading branch information
Nakasar committed Jul 17, 2023
1 parent 748769a commit 202868f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
37 changes: 17 additions & 20 deletions contracts/gateway/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ error ZeroAddress();
/// The maximum number of signers was reached at deployment.
error TooManySigners();
/// The signed attempted to add was already approved.
error SignerAlreadyApproved();
error SignerAlreadyApproved(address signer);
/// The signed attempted to remove was not approved.
error SignerAlreadyNotApproved();
error SignerAlreadyNotApproved(address signer);
/// A requested ONCHAINID deployment was requested without a valid signature while the Gateway requires one.
error UnsignedDeployment();
/// A requested ONCHAINID deployment was requested and signer by a non approved signer.
error UnapprovedSigner();
error UnapprovedSigner(address signer);
/// A requested ONCHAINID deployment was requested with a signature revoked.
error RevokedSignature();
error RevokedSignature(bytes signature);
/// A requested ONCHAINID deployment was requested with a signature that expired.
error ExpiredSignature();
error ExpiredSignature(bytes signature);
/// Attempted to revoke a signature that was already revoked.
error SignatureAlreadyRevoked();
error SignatureAlreadyRevoked(bytes signature);
/// Attempted to approve a signature that was not revoked.
error SignatureNotRevoked();
error SignatureNotRevoked(bytes signature);

contract Gateway is Ownable {
IdFactory public idFactory;
Expand Down Expand Up @@ -69,7 +69,7 @@ contract Gateway is Ownable {
}

if (approvedSigners[signer]) {
revert SignerAlreadyApproved();
revert SignerAlreadyApproved(signer);
}

approvedSigners[signer] = true;
Expand All @@ -87,7 +87,7 @@ contract Gateway is Ownable {
}

if (!approvedSigners[signer]) {
revert SignerAlreadyNotApproved();
revert SignerAlreadyNotApproved(signer);
}

delete approvedSigners[signer];
Expand All @@ -114,7 +114,7 @@ contract Gateway is Ownable {
}

if (signatureExpiry != 0 && signatureExpiry < block.timestamp) {
revert ExpiredSignature();
revert ExpiredSignature(signature);
}

address signer = ECDSA.recover(
Expand All @@ -130,11 +130,11 @@ contract Gateway is Ownable {
);

if (!approvedSigners[signer]) {
revert UnapprovedSigner();
revert UnapprovedSigner(signer);
}

if (revokedSignatures[signature]) {
revert RevokedSignature();
revert RevokedSignature(signature);
}

return idFactory.createIdentity(identityOwner, salt);
Expand All @@ -152,7 +152,7 @@ contract Gateway is Ownable {
}

if (signatureExpiry != 0 && signatureExpiry < block.timestamp) {
revert ExpiredSignature();
revert ExpiredSignature(signature);
}

address signer = ECDSA.recover(
Expand All @@ -169,11 +169,11 @@ contract Gateway is Ownable {
);

if (!approvedSigners[signer]) {
revert UnapprovedSigner();
revert UnapprovedSigner(signer);
}

if (revokedSignatures[signature]) {
revert RevokedSignature();
revert RevokedSignature(signature);
}

return idFactory.createIdentityWithManagementKeys(identityOwner, salt, managementKeys);
Expand All @@ -187,9 +187,6 @@ contract Gateway is Ownable {
if (identityOwner == address(0)) {
revert ZeroAddress();
}
if (identityOwner != msg.sender) {
revert UnapprovedSigner();
}

return idFactory.createIdentity(identityOwner, Strings.toHexString(identityOwner));
}
Expand All @@ -200,7 +197,7 @@ contract Gateway is Ownable {
*/
function revokeSignature(bytes calldata signature) external onlyOwner {
if (revokedSignatures[signature]) {
revert SignatureAlreadyRevoked();
revert SignatureAlreadyRevoked(signature);
}

revokedSignatures[signature] = true;
Expand All @@ -214,7 +211,7 @@ contract Gateway is Ownable {
*/
function approveSignature(bytes calldata signature) external onlyOwner {
if (!revokedSignatures[signature]) {
revert SignatureNotRevoked();
revert SignatureNotRevoked(signature);
}

delete revokedSignatures[signature];
Expand Down
12 changes: 10 additions & 2 deletions test/gateway/gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,19 @@ describe('Gateway', () => {
});

describe('when sender is not the desired identity owner', () => {
it('should revert', async () => {
it('should deploy the identity for the identity owner', async () => {
const {identityFactory, aliceWallet, bobWallet, carolWallet} = await loadFixture(deployFactoryFixture);
const gateway = await ethers.deployContract('Gateway', [identityFactory.address, [carolWallet.address]]);
await identityFactory.transferOwnership(gateway.address);
await expect(gateway.deployIdentityForWallet(aliceWallet.address)).to.revertedWithCustomError(gateway, 'UnapprovedSigner');

const tx = await gateway.connect(bobWallet).deployIdentityForWallet(aliceWallet.address);

await expect(tx).to.emit(identityFactory, "WalletLinked").withArgs(aliceWallet.address, await identityFactory.getIdentity(aliceWallet.address));
await expect(tx).to.emit(identityFactory, "Deployed").withArgs(await identityFactory.getIdentity(aliceWallet.address));
const identityAddress = await identityFactory.getIdentity(aliceWallet.address);
const identity = await ethers.getContractAt('Identity', identityAddress);

expect(await identity.keyHasPurpose(ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(['address'], [aliceWallet.address])), 1)).to.be.true;
});
});

Expand Down

0 comments on commit 202868f

Please sign in to comment.