2024-09-27 11:45:42 -04:00
# `x/macaroon`
2024-09-26 18:01:49 -04:00
2024-10-21 17:00:59 -04:00
The Macaroon module is responsible for providing decentralized access control and service authorization for the Sonr ecosystem. It implements macaroon-based authentication and authorization mechanisms.
2024-09-27 11:45:42 -04:00
## Concepts
2024-10-21 17:00:59 -04:00
Macaroons are a type of bearer credential that allow for decentralized delegation, attenuation, and third-party caveats. This module implements the core functionality for creating, validating, and managing macaroons within the Sonr ecosystem.
2024-09-27 11:45:42 -04:00
## State
2024-10-21 17:00:59 -04:00
The module maintains the following state:
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
### Grant
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
Represents a permission grant with the following fields:
- `id` : Unique identifier (auto-incremented)
- `controller` : Address of the controller
- `subject` : Subject of the grant
- `origin` : Origin of the grant
- `expiry_height` : Block height at which the grant expires
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
### Macaroon
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
Represents a macaroon token with the following fields:
- `id` : Unique identifier (auto-incremented)
- `controller` : Address of the controller
- `subject` : Subject of the macaroon
- `origin` : Origin of the macaroon
- `expiry_height` : Block height at which the macaroon expires
- `macaroon` : The actual macaroon token
2024-09-27 11:45:42 -04:00
## State Transitions
2024-10-21 17:00:59 -04:00
State transitions occur through the following messages:
- `MsgUpdateParams` : Updates the module parameters
- `MsgIssueMacaroon` : Issues a new macaroon
2024-09-27 11:45:42 -04:00
## Messages
2024-10-21 17:00:59 -04:00
### MsgUpdateParams
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
Updates the module parameters. Can only be executed by the governance account.
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
Fields:
- `authority` : Address of the governance account
- `params` : New parameter values
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
### MsgIssueMacaroon
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
Issues a new macaroon for a given controller and origin.
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
Fields:
- `controller` : Address of the controller
- `origin` : Origin of the request in wildcard form
- `permissions` : Map of permissions
- `token` : Macaroon token to authenticate the operation
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
## Queries
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
The module provides the following queries:
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
- `Params` : Retrieves the current module parameters
- `RefreshToken` : Refreshes a macaroon token (post-authentication)
- `ValidateToken` : Validates a macaroon token (pre-authentication)
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
## Parameters
The module has the following parameters:
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
- `methods` : Defines the available DID methods
- `default` : Default method
- `supported` : List of supported methods
- `scopes` : Defines the set of scopes
- `base` : Base scope
- `supported` : List of supported scopes
- `caveats` : Defines the available caveats
- `supported_first_party` : List of supported first-party caveats
- `supported_third_party` : List of supported third-party caveats
- `transactions` : Defines the allowlist and denylist for transactions
- `allowlist` : List of allowed transactions
- `denylist` : List of denied transactions
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
## Events
The module may emit events related to macaroon issuance, validation, and refreshing. (Specific event details to be implemented)
## Client
2024-09-27 11:45:42 -04:00
2024-10-21 17:00:59 -04:00
The module provides gRPC endpoints for all queries and message types defined in the protobuf files.
2024-09-27 11:45:42 -04:00
## Future Improvements
2024-10-21 17:00:59 -04:00
- Implement more advanced caveat types
- Add support for third-party caveats
- Enhance macaroon revocation mechanisms
- Implement additional security features and checks
2024-09-27 11:45:42 -04:00
## Tests
2024-10-21 17:00:59 -04:00
(To be implemented: Acceptance tests for the module's functionality)
2024-09-27 11:45:42 -04:00
## Appendix
2024-10-21 17:00:59 -04:00
For more information on macaroons and their implementation, refer to the original macaroon paper: "Macaroons: Cookies with Contextual Caveats for Decentralized Authorization in the Cloud" by Arnar Birgisson, et al.