SignatureBouncer
contract SignatureBouncer
Bouncer allows users to submit a signature as a permission to do an action. If the signature is from one of the authorized bouncer addresses, the signature is valid. The owner of the contract adds/removes bouncers. Bouncer addresses can be individual servers signing grants or different users within a decentralized club that have permission to invite other members. This technique is useful for whitelists and airdrops; instead of putting all valid addresses on-chain, simply sign a grant of the form keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address. Then restrict access to your crowdsale/whitelist/airdrop using the `onlyValidSignature` modifier (or implement your own using isValidSignature). In addition to `onlyValidSignature`, `onlyValidSignatureAndMethod` and `onlyValidSignatureAndData` can be used to restrict access to only a given method or a given method with given parameters respectively. See the tests Bouncer.test.js for specific usage examples., A method that uses the `onlyValidSignatureAndData` modifier must make the _sig parameter the "last" parameter. You cannot sign a message that has its own signature in it so the last 128 bytes of msg.data (which represents the length of the _sig data and the _sig data itself) is ignored when validating. Also non fixed sized parameters make constructing the data in the signature much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
Index
Reference
Modifiers
onlyValidSignature
modifier onlyValidSignature(bytes _sig)
Requires that a valid signature of a bouncer was provided.
- Parameters:
_sig
- bytes
onlyValidSignatureAndData
modifier onlyValidSignatureAndData(bytes _sig)
Requires that a valid signature with a specifed method and params of a bouncer was provided.
- Parameters:
_sig
- bytes
onlyValidSignatureAndMethod
modifier onlyValidSignatureAndMethod(bytes _sig)
Requires that a valid signature with a specifed method of a bouncer was provided.
- Parameters:
_sig
- bytes
Functions
addBouncer
function addBouncer(address _bouncer) public
Allows the owner to add additional bouncer addresses.
- Modifiers:
- onlyOwner
- Parameters:
_bouncer
- address
isValidDataHash
function isValidDataHash(bytes32 hash, bytes _sig) internal view returns (bool)
Internal function to convert a hash to an eth signed message and then recover the signature and check it against the bouncer role.
- Parameters:
hash
- bytes32_sig
- bytes- Returns:
- bool
isValidSignature
function isValidSignature(address _address, bytes _sig) internal view returns (bool)
Is the signature of `this + sender` from a bouncer?.
- Parameters:
_address
- address_sig
- bytes- Returns:
- bool
isValidSignatureAndData
function isValidSignatureAndData(address _address, bytes _sig) internal view returns (bool)
Is the signature of `this + sender + methodId + params(s)` from a bouncer?, the _sig parameter of the method being validated must be the "last" parameter.
- Parameters:
_address
- address_sig
- bytes- Returns:
- bool
isValidSignatureAndMethod
function isValidSignatureAndMethod(address _address, bytes _sig) internal view returns (bool)
Is the signature of `this + sender + methodId` from a bouncer?.
- Parameters:
_address
- address_sig
- bytes- Returns:
- bool
removeBouncer
function removeBouncer(address _bouncer) public
Allows the owner to remove bouncer addresses.
- Modifiers:
- onlyOwner
- Parameters:
_bouncer
- address