Skip to content
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
Prev Previous commit
Next Next commit
Improve encapsulation on SignatureBouncer
  • Loading branch information
Leo Arias committed Sep 3, 2018
commit 58ba593d523f8da2a3c574736256cd67a4fe2d32
21 changes: 16 additions & 5 deletions contracts/access/SignatureBouncer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ import "../ECRecovery.sol";
contract SignatureBouncer is Ownable, RBAC {
using ECRecovery for bytes32;

string public constant ROLE_BOUNCER = "bouncer";
uint internal constant METHOD_ID_SIZE = 4;
// signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
uint internal constant SIGNATURE_SIZE = 96;
// Name of the bouncer role.
string private constant ROLE_BOUNCER = "bouncer";
// Function selectors are 4 bytes long, as documented in
// https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector
uint256 private constant METHOD_ID_SIZE = 4;
// Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
uint256 private constant SIGNATURE_SIZE = 96;

/**
* @dev requires that a valid signature of a bouncer was provided
Expand Down Expand Up @@ -64,6 +67,14 @@ contract SignatureBouncer is Ownable, RBAC {
_;
}

/**
* @dev Determine if an account has the bouncer role.
* @return true if the account is a bouncer, false otherwise.
*/
function isBouncer(address _account) public view returns(bool) {
return hasRole(_account, ROLE_BOUNCER);
}

/**
* @dev allows the owner to add additional bouncer addresses
*/
Expand Down Expand Up @@ -153,6 +164,6 @@ contract SignatureBouncer is Ownable, RBAC {
address signer = _hash
.toEthSignedMessageHash()
.recover(_signature);
return hasRole(signer, ROLE_BOUNCER);
return isBouncer(signer);
}
}
3 changes: 1 addition & 2 deletions test/access/SignatureBouncer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const INVALID_SIGNATURE = '0xabcd';
contract('Bouncer', function ([_, owner, anyone, bouncerAddress, authorizedUser]) {
beforeEach(async function () {
this.bouncer = await Bouncer.new({ from: owner });
this.roleBouncer = await this.bouncer.ROLE_BOUNCER();
});

context('management', function () {
Expand All @@ -26,7 +25,7 @@ contract('Bouncer', function ([_, owner, anyone, bouncerAddress, authorizedUser]

it('allows the owner to add a bouncer', async function () {
await this.bouncer.addBouncer(bouncerAddress, { from: owner });
(await this.bouncer.hasRole(bouncerAddress, this.roleBouncer)).should.equal(true);
(await this.bouncer.isBouncer(bouncerAddress)).should.equal(true);
});

it('does not allow adding an invalid address', async function () {
Expand Down