Version 1 - mainnet - 0xb8...125e9a
Readme
Versions
1
Dependencies
0
Dependents
0
Analytics
On the way
Access Control is a simple library to manage access control for your package. It allows the creation of admins with custom roles.
The package resolves around three objects:
ACL object.SuperAdmin has the highest authority in the system, it should be kept safe under a multisig or under a DAO if possible. Admins issue a Witness to prove their capability rights.
The SuperAdmin is a key only object that can only be transferred via a two-step function with a delay in between to allow users to adjust before ownership is transferred.
Functions can be admin gated by accepting a reference of an AdminWitness in their arguments.
# testnet
mvr add @interest/acl --network testnet
# mainnet
mvr add @interest/acl --network mainnet
To add this library to your project, add this to your Move.toml.
# goes into [dependencies] section
interest_access_control = { r.mvr = "@interest/acl" }
# add this section to your Move.toml
[r.mvr]
network = "mainnet"
Access control is an immutable package for security reasons. The UpgradeCap has been deleted in this transaction.
It is deployed on Sui Network mainnet at: 0xb877fe150db8e9af55c399b4e49ba8afe658bd05317cb378c940344851125e9a
It is deployed on Sui Network testnet at: 0x32ffaa298a6d6528864bf2b32acfcb7976a95e26dcc24e40e2535c0551b9d68a
In your code, import and use the package as:
module my::awesome_project;
use interest_access_control::access_control::{Self, AdminWitness};
const MINT_ROLE: u8 = 0;
public struct AWESOME_PROJECT() has drop;
fun init(otw: AWESOME_PROJECT, ctx: &mut TxContext) {
let acl = access_control::default<AWESOME_PROJECT>(&otw, ctx);
}
/// Admin only Function
public fun only_admin(admin_witness: &AdminWitness<AWESOME_PROJECT>) {
/// ... admin ops
}
/// Admin only Function With Mint Role
public fun only_mint_admin(admin_witness: &AdminWitness<AWESOME_PROJECT>) {
admin_witness.assert_has_role(MINT_ROLE);
/// ... admin ops
}
ACL objects require a One Time Witness for security reasons. You can read more about OTWs here.
new: It creates a ACLand SuperAdmin. The SuperAdmin is sent to the super_admin_recipient. The delay is the number of epochs that must pass before the SuperAdmin can be transferred.
public fun new<T: drop>(
otw: &T,
delay: u64,
super_admin_recipient: address,
ctx: &mut TxContext,
): ACL<T>
default: It calls new with default arguments. The delay is set to 3 epochs and the SuperAdmin is sent to the ctx.sender.
public fun default<T: drop>(otw: &T, ctx: &mut TxContext): ACL<T>
new_admin: It allows the SuperAdmin to create an Admin.
public fun new_admin<T: drop>(acl: &mut ACL<T>, _: &SuperAdmin<T>, ctx: &mut TxContext): Admin<T>
add_role: It allows the SuperAdmin to create a role for an Admin using its address.
public fun add_role<T: drop>(acl: &mut ACL<T>, _: &SuperAdmin<T>, admin: address, role: u8)
remove_role: It allows the SuperAdmin to remove a role from an Admin using its address.
public fun remove_role<T: drop>(acl: &mut ACL<T>, _: &SuperAdmin<T>, admin: address, role: u8)
revoke: It allows the SuperAdmin to remove a an Admin. This operation removes an Admin from the ACL shared object. It will prevent the removed Admin from issuing an AdminWitness.
public fun revoke<T: drop>(acl: &mut ACL<T>, _: &SuperAdmin<T>, to_revoke: address)
sign_in: It allows an Admin to prove its access rights by issuing an AdminWitness with its roles.
public fun sign_in<T: drop>(acl: &ACL<T>, admin: &Admin<T>): AdminWitness<T>
destroy_admin: It allows an Admin to revoke its rights and delete the object for a Sui rebate.
public fun destroy_admin<T: drop>(acl: &mut ACL<T>, admin: Admin<T>)
destroy_super_admin: It allows a SuperAdmin to revoke its rights and delete the object for a Sui rebate. Please note, this is irreversible.
public fun destroy_super_admin<T: drop>(super_admin: SuperAdmin<T>)
start_transfer: It initiates the SuperAdmin transfer process.
public fun start_transfer<T: drop>(
super_admin: &mut SuperAdmin<T>,
new_super_admin: address,
ctx: &mut TxContext,
)
finish_transfer: It transfers the SuperAdmin to the recipient set at start_transfer. It can only be called after the delay period.
public fun finish_transfer<T: drop>(mut super_admin: SuperAdmin<T>, ctx: &mut TxContext)
assert_has_role: It asserts that an AdminWitness has a role.
public fun assert_has_role<T: drop>(witness: &AdminWitness<T>, role: u8)
admin_address: Returns the address of the Admin.
public fun admin_address<T: drop>(admin: &Admin<T>): address
is_admin: Checks if the address is an Admin.
public fun is_admin<T: drop>(acl: &ACL<T>, admin: address): bool
has_role: Checks if the address is an Admin has the role.
public fun has_role<T: drop>(acl: &ACL<T>, admin: address, role: u8): bool
permissions: Returns all the roles of an Admin. It is tracked via bit map.
public fun permissions<T: drop>(acl: &ACL<T>, admin: address): Option<u128>
Errors are encoded in u64 .
| Error code | Reason |
|---|---|
| 0 | The new function was called without a One Time Witness. It is to make sure it can only be called in init functions. |
| 1 | finish_transfer was called before the delay has passed. |
| 2 | The Admin is not listed in the ACL. |
| 3 | Caller tried to start the SuperAdmin transfer to the dead address or to himself/herself. |
| 4 | The maximum allowed role is 127u8. |
| 5 | The Admin does not have a specific role. |
Adds the following modules:
access_control.move - access control logicerrors.move - error codes thrown by the packageevents.move - events emitted by the packageThis is provided on an "as is" and "as available" basis.
We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.
While Interest Access Control has been heavily tested, there may be parts that may exhibit unexpected emergent behavior when used with other code, or may break in future Move versions.
Please always include your own thorough tests when using Interest Access Control to make sure it works correctly with your code.
This package is licensed under Apache-2.0.
You can install this package in your Move project by calling
mvr add @interest/interest-aclA package to manage access control lists.
jose@interestprotocol.com