Skip to content

Permissions

This section provides details about pre-configured permission tokens in Iroha 2. For more general information on permission tokens and permission groups (roles), refer to the Permissions chapter in Guide.

Permission Tokens

Note

A permission token can only grant a user's account the ability to perform an operation in relation to the Subject that the token is registered with.

e.g., ???

Permission TokenSubjectOperation
[CanUnregisterDomain]DomainAllows the user to unregister the Domain.
[CanSetKeyValueInDomain]DomainAllows the user to add metadata key-values to the Domain.
[CanRemoveKeyValueInDomain]DomainAllows the user to remove metadata key-values from the Domain.
[CanUnregisterAccount]AccountAllows the user to unregister the Account.
[CanMintUserPublicKeys]AccountAllows the user to add a public key to the Account.
[CanBurnUserPublicKeys]AccountAllows the user to remove a public key from the Account.
[CanMintUserSignatureCheckConditions]AccountAllows the user to set check conditions for a signature
[CanSetKeyValueInUserAccount]AccountAllows to add user's metadata key value
[CanRemoveKeyValueInUserAccount]AccountAllows to remove user's metadata key value
[CanRegisterAssetsWithDefinition]AssetAllows to register a new asset with this definition
[CanUnregisterAssetsWithDefinition]AssetAllows to unregister a new asset with this definition
[CanUnregisterUserAsset]AssetAllows to remove asset from a user
[CanMintAssetsWithDefinition]AssetAllows to mint quantity of assets with this definition
[CanBurnAssetsWithDefinition]AssetAllows to burn quantity of assets with this definition
[CanTransferAssetsWithDefinition]AssetAllows to transfer quantity of assets with this definition
[CanBurnUserAsset]AssetAllows to burn user's asset quantity
[CanTransferUserAsset]AssetAllows to transfer user's asset quantity
[CanSetKeyValueInUserAsset]AssetAllows to set key value to user's asset metadata
[CanRemoveKeyValueInUserAsset]AssetAllows to remove key value from user's asset metadata
[CanSetKeyValueInAssetDefinition]Asset DefinitionAllows to add key value to metadata for this asset definition
[CanRemoveKeyValueInAssetDefinition]Asset DefinitionAllows to remove key value from metadata for this asset definition
[CanUnregisterAssetDefinition]Asset DefinitionAllows to unregister this asset definition

INFO

The way permissions work in Iroha 2 is subject to change. Only the owner of a subject can grant users permissions to perform operations with that subject.

By default, all assets and accounts defined in the genesis block configuration file are created by genesis@genesis account. This means that alice@wonderland is not the owner of rose#wonderland and cannot grant permission for rose#wonderland.

To avoid this, you can do one of the following:

  • Edit the genesis.json file so that it only includes the creation of alice@wonderland, then redeploy Iroha 2.
  • Create a subject (e.g., an asset definition) on behalf of alice@wonderland, and then give another account the permission to manage this subject.

Granting Permission Tokens

With this example, the owner-account can give permission for its subject to another account.

The example is based on the following preconditions:

  • The subject is created by the owner-account.
  • The recipient account is created.
rust
// Define the asset definition owner
let asset_definition_owner = AccountId::from_str("alice@wonderland").unwrap();
// Define the asset definition id which was created by the owner
let asset_definition_id = AssetDefinitionId::from_str("coolAsset#wonderland").unwrap();
// Define the account which we want to give the permission
let recipient_account = AccountId::from_str("actor@wonderland").unwrap();
// Create a token that we chose. And define its structure according to `iroha_executor\smart_contract\executor\src\default.rs`
let can_mint_asset_with_definition_token = PermissionToken::new(
"CanMintAssetsWithDefinition".parse().unwrap(),
&json!({ "asset_definition_id": asset_definition_id }),
);
// Create a permission expression (Grant\Revoke)
let permission_expression = GrantExpr::new(can_mint_asset_with_definition_token, recipients_account);
// Submit the transaction with the permission expression
iroha_client.submit_blocking(permission_expression).unwrap();