Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identities component #88

Open
encody opened this issue Oct 21, 2022 · 1 comment
Open

Identities component #88

encody opened this issue Oct 21, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@encody
Copy link
Member

encody commented Oct 21, 2022

Like a generic version of Owner. Like Rbac, but there is a 1:0..1 relationship between an identity and an account ID. It will also be possible to retrieve the holder of an identity (enumeration is not possible in the current version of Rbac). Identity transfer (via propose/accept) and renunciation are optionally allowed.

Possible Example

enum Identity {
    Owner,
    Administrator,
    Manager,
}

#[derive(Identities)]
#[identities(identities = "Identity")]
#[near_bindgen]
struct MyContract {}

#[near_bindgen]
impl MyContract {
    #[init]
    fn init() -> Self {
        let mut contract = Self {};

        contract.initialize_identity(&Identity::Owner, env::predecessor_account_id());
        contract.initialize_identity(&Identity::Administrator, env::predecessor_account_id());
        contract.initialize_identity(&Identity::Manager, env::predecessor_account_id());
    }

    fn only_owner(&self, account: AccountId) {
        self.require_identity(&Identity::Owner);
    }

    fn only_administrator(&self, account: AccountId) {
        self.require_identity(&Identity::Administrator);
    }
}

impl IdentityHook<Identity> for MyContract {
    fn on_transfer(identity: &Identity, from: AccountId, to: AccountId) -> Result<(), ?> { }

    fn on_propose(identity: &Identity, account: AccountId) -> Result<(), ?> { }

    fn on_accept(identity: &Identity, account: AccountId) -> Result<(), ?> { }
}

Would expose the following interface to the blockchain:

(Caveat: Identities need a to/from string serialization)

trait IdentityExternal<Identity> {
    fn id_is(&self, account: AccountId, identity: Identity) -> bool;
    fn id_get(&self, identity: Identity) -> Option<AccountId>;
    fn id_renounce(&mut self, identity: Identity);
    fn id_propose(&mut self, identity: Identity, to: AccountId);
    fn id_accept(&mut self, identity: Identity, from: AccountId);
}
@encody encody added the enhancement New feature or request label Oct 21, 2022
@encody
Copy link
Member Author

encody commented Oct 31, 2022

Alternatively: extend/generalize the Rbac component to support these features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant