> For the complete documentation index, see [llms.txt](https://elacity.gitbook.io/elacity-sdks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://elacity.gitbook.io/elacity-sdks/protocol/v2.0/references/modules/licensemodule.md).

# LicenseModule

Abstract module providing core licensing capabilities for Digital Assets within the DRM ecosystem.

*Handles license issuance, access checks over operatives, and EIP-712 based license requests. `EIP712Decoder` contract is generated by eip712-codegen check on <https://github.com/danfinlay/eip712-codegen#readme> `./node_modules/.bin/712gen ./typedData.js | sed "s/0.8.13/0.8.12/g" > contracts/modules/utils/TypedDataDecoder.sol`*

## InvalidSignature

```solidity
error InvalidSignature(address accessor, address signer)
```

Thrown when a license request signature does not match the expected signer.

### Parameters

| Name     | Type    | Description                                              |
| -------- | ------- | -------------------------------------------------------- |
| accessor | address | The address of the user or system acquiring the license. |
| signer   | address | The recovered/declared signer that failed validation.    |

## WrongSignatureFormat

```solidity
error WrongSignatureFormat()
```

Emitted when the signature format is invalid.

## AccessDenied

```solidity
error AccessDenied(address accessor, address channel, uint256 tokenId)
```

Emitted when the accessor does not have the right to access the asset.

### Parameters

| Name     | Type    | Description                             |
| -------- | ------- | --------------------------------------- |
| accessor | address | The address of the user seeking access. |
| channel  | address | The address of the channel.             |
| tokenId  | uint256 | The unique token ID within the ledger.  |

## LICENSE\_MANAGER\_ROLE

```solidity
bytes32 LICENSE_MANAGER_ROLE
```

## \_\_LicenseModule\_init

```solidity
function __LicenseModule_init(string contractName, string version) internal
```

Initializes the LicenseModule

*Sets up the VerifierModule, SecurityModule, and grants the LICENSE\_MANAGER\_ROLE to the deployer.*

### Parameters

| Name         | Type   | Description                                                |
| ------------ | ------ | ---------------------------------------------------------- |
| contractName | string | The name of the contract for EIP-712 domain separation.    |
| version      | string | The version of the contract for EIP-712 domain separation. |

## \_issueLicenseFor

```solidity
function _issueLicenseFor(address accessor, struct IPEntity _entity) internal view returns (struct ILicenseProvider.License)
```

Issues a license for a given Digital Asset based on the entity provided.

*Creates a License struct containing the accessor and the internal IP keys.*

### Parameters

| Name     | Type            | Description                                              |
| -------- | --------------- | -------------------------------------------------------- |
| accessor | address         | The address of the user or system acquiring the license. |
| \_entity | struct IPEntity | The IP entity to issue the license for.                  |

### Return Values

| Name | Type                            | Description                                                                                                                                                                                         |
| ---- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \[0] | struct ILicenseProvider.License | A populated License struct. TODO: find a more secure way to store the license and never expose the private key instead we could implement a kind of signed key that can only be decrypt from a dApp |

## \_requestUserAccess

```solidity
function _requestUserAccess(contract IStorage store, address accessor, address ledger, uint256 tokenId) internal view returns (bool haveAccess, uint256[] entitlements)
```

Check the access to a given Digital Asset.

*This will check over Operative contract in order to detect if a user have token(s) that allows to access the asset.*

### Parameters

| Name     | Type              | Description                                                          |
| -------- | ----------------- | -------------------------------------------------------------------- |
| store    | contract IStorage | The storage contract used to locate the operator for a ledger/token. |
| accessor | address           | The address of the user seeking access.                              |
| ledger   | address           | The address of the ledger contract hosting the digital asset.        |
| tokenId  | uint256           | The unique token ID within the ledger.                               |

### Return Values

| Name         | Type       | Description                                                   |
| ------------ | ---------- | ------------------------------------------------------------- |
| haveAccess   | bool       | A boolean indicating if the accessor has the right to access. |
| entitlements | uint256\[] | An array of entitlements granted to the accessor.             |

## \_requestAccess

```solidity
function _requestAccess(contract IStorage store, address ledger, uint256 tokenId) internal view returns (bool haveAccess, uint256[] entitlements)
```

Check if the current sender has access to a given Digital Asset.

\_Helper wrapper over *requestUserAccess using msg.sender as the accessor.*

### Parameters

| Name    | Type              | Description                                       |
| ------- | ----------------- | ------------------------------------------------- |
| store   | contract IStorage | The storage contract used to locate the operator. |
| ledger  | address           | The address of the ledger contract.               |
| tokenId | uint256           | The unique token ID within the ledger.            |

### Return Values

| Name         | Type       | Description                                                 |
| ------------ | ---------- | ----------------------------------------------------------- |
| haveAccess   | bool       | A boolean indicating if the caller has the right to access. |
| entitlements | uint256\[] | An array of entitlements granted to the caller.             |

## \_acquireLicense

```solidity
function _acquireLicense(contract IStorage store, bytes payload) internal view returns (bytes4, bytes)
```

Processes a license request, verifying signatures and checking access rights before issuing.

*Unwraps an EIP-712 LicenseRequest payload, confirms signature, verifies operative access, and issues license.*

### Parameters

| Name    | Type              | Description                                            |
| ------- | ----------------- | ------------------------------------------------------ |
| store   | contract IStorage | The storage contract to query for operator assignment. |
| payload | bytes             | The encoded license request payload.                   |

### Return Values

| Name | Type   | Description                                                        |
| ---- | ------ | ------------------------------------------------------------------ |
| \[0] | bytes4 | cs The callback selector configured by the handler.                |
| \[1] | bytes  | A tuple containing the response payload with the enclosed license. |

## acquireLicense

```solidity
function acquireLicense(bytes req) external view virtual returns (bytes4, bytes)
```

Acquire a license for a requested digital asset

*To be implemented by inheriting contracts, serving as the public entrypoint for license acquisition.*

### Parameters

| Name | Type  | Description                                               |
| ---- | ----- | --------------------------------------------------------- |
| req  | bytes | The encoded license request detailing the required asset. |

### Return Values

| Name | Type   | Description                                                       |
| ---- | ------ | ----------------------------------------------------------------- |
| \[0] | bytes4 | A tuple containing the selector and the wrapped license response. |
| \[1] | bytes  |                                                                   |

## registerIPWithKey

```solidity
function registerIPWithKey(address ledger, bytes16 _contentId, bytes _ipKey) external returns (bytes32, bytes)
```

Register a new IP in the system using a given key

*for version 1.0, this method is the only relevant as we deal with clearkey. Public and private are used to encrypt and decrypt the content and client on playback need to know the private key to decrypt the content in a clear manner.*

### Parameters

| Name        | Type    | Description                           |
| ----------- | ------- | ------------------------------------- |
| ledger      | address | The address of the ledger contract    |
| \_contentId | bytes16 | The content id of the asset           |
| \_ipKey     | bytes   | The key to use to encrypt the content |

### Return Values

| Name | Type    | Description                                                      |
| ---- | ------- | ---------------------------------------------------------------- |
| \[0] | bytes32 | The hash of the newly registered IP entity and the key provided. |
| \[1] | bytes   |                                                                  |

## \_registerIPWithKey

```solidity
function _registerIPWithKey(address ledger, bytes16 _contentId, bytes _ipKey) internal returns (bytes32, bytes)
```

Internal logic to bind a plain-text cryptographic key to an asset's identity.

*Reverts if the IP is already registered.*

### Parameters

| Name        | Type    | Description                                          |
| ----------- | ------- | ---------------------------------------------------- |
| ledger      | address | The address of the ledger contract.                  |
| \_contentId | bytes16 | The unique 16-byte identifier for the digital asset. |
| \_ipKey     | bytes   | The raw key payload to associate with the asset.     |

### Return Values

| Name | Type    | Description                                                   |
| ---- | ------- | ------------------------------------------------------------- |
| \[0] | bytes32 | The canonical identity hash of the IP and the associated key. |
| \[1] | bytes   |                                                               |
