# Owner

It provides an Owner capability that stores the IDs of other objects, Modules can assert or check if a certain ID is stored in the Owner to prove its ownership. It is used to provide access control.&#x20;

## Structs

### <mark style="color:blue;">**OwnerCap**</mark>

```rust
struct OwnerCap<phantom T> has key, store {
    id: UID,
    of: VecSet<ID>
 }
```

* **of - A set of IDs to prove that the Owner Capability has privileged access to it.**&#x20;

## Interface

### <mark style="color:blue;">new</mark>

**It creates an OwnerCap capability.**&#x20;

```rust
public fun new<T: drop>(_: T, of: vector<ID>, ctx: &mut TxContext): OwnerCap<T>
```

* **@param \_:** A witness to link an OwnerCap with the module that owns the witness.
* **@param of:** Vector of `sui::object::ID` that this capability owns.
* **@return** OwnerCap.

### <mark style="color:blue;">contains</mark>

**It checks if an ID is stored in the Owner Capability.**&#x20;

```rust
public fun contains<T: drop>(self: &OwnerCap<T>, x: ID): bool 
```

* **@param self:** An OwnerCap object.
* **@param x:** The `sui::object::ID` of an object.
* **@return** bool. True if the `self` owns `x`.

### <mark style="color:blue;">of</mark>

**Returns the vector of `sui::object::ID` that the `self` owns.**

```rust
public fun of<T: drop>(self: &OwnerCap<T>): vector<ID>
```

* **@param self:** A {OwnerCap} object.
* **@return** vector. The vector of `sui::object::ID`.

### <mark style="color:blue;">add</mark>

**Assigns the `self` OwnerCap as the owner of `x`.**

```rust
public fun add<T: drop>(self: &mut OwnerCap<T>, _: T, x: ID)
```

* **@param self:** An OwnerCap object.
* **@param \_:** A witness to make sure only the allowed module can add `sui::object::ID` to the self.
* **@param x:** The `sui::object::ID` of the object, which the `self` will have ownership rights to.

### <mark style="color:blue;">remove</mark>

**Removes the `self` OwnerCap as the owner of `x`.**

```rust
public fun remove<T: drop>(self: &mut OwnerCap<T>, _: T, x: ID)
```

* **@param self:** An OwnerCap object.
* **@param \_:** A witness to make sure only the right module can add the `sui::object::ID` to the self.
* **@param x:** The `sui::object::ID` of the object, which the `self` will lose its ownership rights to.

### <mark style="color:blue;">destroy</mark>

**Destroys an OwnerCap. It does not require the of vector to be empty.**

```rust
public fun destroy<T: drop>(self: OwnerCap<T>)
```

* **@param self:** An OwnerCap object.

### <mark style="color:blue;">destroy\_empty</mark>

**Destroys an OwnerCap. It requires the of vector to be empty.**

```rust
public fun destroy<T: drop>(self: OwnerCap<T>)
```

* **@param self:** A OwnerCap object.

**Aborts**

* If `of` vector is not empty.&#x20;

### <mark style="color:blue;">assert\_ownership</mark>

**Asserts that the `self` owns `x`.**

```rust
public fun destroy<T: drop>(self: OwnerCap<T>)
```

* **@param self:** An OwnerCap object.
* **@param x:** The `sui::object::ID` of the object, which must belong to the capability.

**Aborts**

* If the ID is not owned by the capability.
