# MindLake.Permission

In Mind Lake, users can access others' data, but private encrypted data is presented as ciphertext. To share private data with a specific user, the data owner must grant the target user permission to decrypt the ciphertext, thereby enabling access to the plaintext.

{% hint style="info" %}
During testing, only existing users of Mind Lake can be designated as targets for permission sharing.
{% endhint %}

## 1. grant() Method

Grant decryption permissions to the recipient to enable them to access the encrypted data in the specified columns.

{% hint style="warning" %}
When the `Grant` method is called by a grantor for the same recipient again, the existing grant policy from the grantor to the recipient is overwritten. The previous policy becomes invalid immediately, and the new policy, which includes the new set of columns, takes effect only after the recipient invokes the `Confirm` method for this grant policy.
{% endhint %}

```python
mindlake.permission.grant(targetWalletAddress: str, columns: list) -> ResultType
# mindlake is an instance of MindLake
```

### Parameters

1. `targetWalletAddress` - `str`: the wallet address of the recipient
2. `columns` - `list<str>`: the columns to be shared with the recipient. Each column should be defined as a string that combines the table name, and column name, separated by dots. Specifically, the format for defining a column should be `"TableName.ColumnName"`

### Returns

An object of [`ResultType`](#user-content-fn-1)[^1]. [For more information](https://docs.mindnetwork.xyz/mind-lake-sdk/mindlake#2.-mindlake.resulttype).

* `data` - `str`: the UUID string of the grant policy. The granter should share this UUID with the recipient. The recipient then needs to confirm the policy for it to take effect.

### Example

```python
result = mindlake.permission.grant(targetWalletAddress, ['TableName1.ColumnName1', 'TableName2.Column2'])
assert result, result.message
policyID = result.data
```

## 2. confirm() Method

Confirm the grant policy as the recipient. The policy will take effect after the confirmation.

```python
mindlake.permission.confirm(policyID: str) -> ResultType
# mindlake is an instance of MindLake
```

### Parameters

1. policyID - `str`: the UUID string of the grant policy. The recipient should get it from the granter.

### Returns

An object of [`ResultType`](#user-content-fn-1)[^1]. [For more information](https://docs.mindnetwork.xyz/mind-lake-sdk/mindlake#2.-mindlake.resulttype).

### Example

```python
result = mindlake.permission.confirm(policyID)
assert result, result.message
```

## 3. revoke() Method

Revoke decryption permissions for the target user. Consequently, the target user loses access to all the encrypted data belonging to the owner who invokes this method.

```python
mindlake.permission.revoke(targetWalletAddress: str)
# mindlake is an instance of MindLake
```

### Parameters

* `targetWalletAddress` - `str`: the wallet address of the target whose permission is to be revoked.

### Returns

An object of [`ResultType`](#user-content-fn-1)[^1]. [For more information](https://docs.mindnetwork.xyz/mind-lake-sdk/mindlake#2.-mindlake.resulttype).

### Example

```python
result = mindlake.permission.revoke(targetWalletAddress)
assert result, result.message
```

## 4. listGrantee() Method

Retrieve a list of wallet addresses of users who have been granted permission by the invoking user.

```python
mindlake.permission.listGrantee()
# mindlake is an instance of MindLake
```

### Returns

An object of [`ResultType`](#user-content-fn-1)[^1]. [For more information](https://docs.mindnetwork.xyz/mind-lake-sdk/mindlake#2.-mindlake.resulttype).

* `data` - `list<str>`: a list of wallet addresses of users who have been granted permission by the invoking user.

### Example

```python
result = mindlake.permission.listGrantee()
assert result, result.message
granteeList = result.data
```

## 5. listOwner() Method

Retrieve a list of wallet addresses of users who have granted permission to the invoking user.

```python
mindlake.permission.listOwner()
# mindlake is an instance of MindLake
```

### Returns

An object of [`ResultType`](#user-content-fn-1)[^1]. [For more information](https://docs.mindnetwork.xyz/mind-lake-sdk/mindlake#2.-mindlake.resulttype).

* `data` - `list<str>`: a list of wallet addresses of users who have granted permission to the invoking user.

### Example

```python
result = mindlake.permission.listOwner()
assert result, result.message
ownerList = result.data
```

## 6. listGrantedColumn() Method

Retrieve a list of column names for which decryption permission has been granted to the specified user.

```python
mindlake.permission.listGrantedColumn(targetWalletAddress)
# mindlake is an instance of MindLake
```

### Parameters

1. `targetWalletAddress` - `str`: specify the target user by the wallet address.

### Returns

An object of [`ResultType`](#user-content-fn-1)[^1]. [For more information](https://docs.mindnetwork.xyz/mind-lake-sdk/mindlake#2.-mindlake.resulttype).

* `data` - `list<str>`: a list of column names for which decryption permission has been granted to the specified user.

### Example

```python
result = mindlake.permission.ListGrantedColumn(targetWalletAddress)
assert result, result.message
grantedColumnList = result.data
```

## 7. listOwnerColumn() Method

Retrieve a list of column names authorized for decryption by the specified user.

```python
mindlake.permission.listOwnerColumn(targetWalletAddress)
# mindlake is an instance of MindLake
```

### Parameters

1. `targetWalletAddress` - `str`: specify the owner user of the authorized columns by the wallet address.

### Returns

An object of [`ResultType`](#user-content-fn-1)[^1]. [For more information](https://docs.mindnetwork.xyz/mind-lake-sdk/mindlake#2.-mindlake.resulttype).

* `data` - `list<str>`: a list of column names authorized for decryption by the specified user.

### Example

```python
result = mindlake.permission.ListOwnerColumn(targetWalletAddress)
assert result, result.message
ownerColumnList = result.data
```

[^1]: ```python
    class ResultType:
        def __init__(self, code: int, message: str = None, data = None):
            self.code = code
            self.message = message
            self.data = data
                
        def __bool__(self):
            return self.code == 0
    ```
