SiweAuth
Inherits: A13e
Inherit this contract, if you wish to enable SIWE-based authentication for your contract methods that require authenticated calls. The smart contract needs to be bound to a domain (passed in constructor).
Example
contract MyContract is SiweAuth {
address private _owner;
modifier onlyOwner(bytes calldata bearer) {
if (authMsgSender(bearer) != _owner) {
revert("not allowed");
}
_;
}
constructor(string memory domain) SiweAuth(domain) {
_owner = msg.sender;
}
function getSecretMessage(bytes calldata bearer) external view onlyOwner(bearer) returns (string memory) {
return "Very secret message";
}
}
State Variables
_domain
Domain which the dApp is associated with
string private _domain;
_bearerEncKey
Encryption key which the bearer tokens are encrypted with
bytes32 private _bearerEncKey;
DEFAULT_VALIDITY
Default bearer token validity, if no expiration-time provided
uint256 private constant DEFAULT_VALIDITY = 24 hours;
Functions
constructor
Instantiate the contract which uses SIWE for authentication and runs on the specified domain.
constructor(string memory inDomain);
login
function login(string calldata siweMsg, SignatureRSV calldata sig) external view override returns (bytes memory);
domain
Return the domain associated with the dApp.
function domain() public view returns (string memory);
authMsgSender
function authMsgSender(bytes calldata bearer) internal view override checkRevokedBearer(bearer) returns (address);
Errors
ChainIdMismatch
Chain ID in the SIWE message does not match the actual chain ID
error ChainIdMismatch();
DomainMismatch
Domain in the SIWE message does not match the domain of a dApp
error DomainMismatch();
AddressMismatch
User address in the SIWE message does not match the message signer's address
error AddressMismatch();
NotBeforeInFuture
The Not before value in the SIWE message is still in the future
error NotBeforeInFuture();
Expired
The bearer token validity or the Expires value in the SIWE message is in the past
error Expired();