DRM Mina Unity Package
The DRM Mina Unity Package allows game developers to integrate Mina-based DRM protection into their Unity games. The package provides device identification scripts, local prover communication, and Mina blockchain communication scripts out of the box.
Installation
Installation of the DRM Mina Unity Package is simple as importing the package into your Unity project.
- Download the latest version of the DRM Mina Unity Package from the Downloads page (opens in a new tab).
- Open your Unity project and navigate to
Assets
>Import Package
>Custom Package
. - Select the downloaded package and click
Open
. - After the package is imported, you will see the
DRMAuthenticator
object in theAssets
folder. - Drag the
DRMAuthenticator
object into your scene. - Set the contract addresses in the
DRMAuthenticator
object as described in the Set Environment section. - You are now ready to use the DRM Mina Unity Package in your game, check the Status Codes section for the possible status codes.
- integrate the DRM Mina Unity Package logic into your game as you see fit.
Set Environment
To set your contract addresses, open the DRMAuthenticator
object in the Assets
folder or the scene hierarchy. You will see the DRMAuthenticator
script component with the following fields:
Game Token Address
- The address of the game token contract that you deployed on the Mina blockchain.DRM Contract Address
- The address of the DRM contract that you deployed on the Mina blockchain.
see the image below for reference:
Also how to deploy the contracts can be found in the Game Registiration section.
Authentication Setup
Swipe the DRMAuthenticator.prefab
object into your main scene. This object will handle the DRM verification process and return the status codes inside the DRMAuthenticationStarter.cs
script.
Make sure to set the contract addresses in the DRMAuthenticator
object as described in the Set Environment section.
This script will handle the DRM verification process and return the status codes inside the DRMAuthenticator.cs
script.
It is left to the developer to handle the status codes as they see fit. Below is an example of how to handle the status codes in the DRMAuthenticationStarter.cs
script.
using DRMinaUnityPackage;
using UnityEngine;
public class DRMAuthenticationStarter : MonoBehaviour
{
public string gameTokenAddress;
public string drmContractAddress;
private void Start()
{
DRMEnvironment.GAME_TOKEN_ADDRESS = gameTokenAddress;
DRMEnvironment.DRM_CONTRACT_ADDRESS = drmContractAddress;
DRMAuthenticator.OnComplete += DRMAuthenticatorOnOnComplete;
DRMAuthenticator.Start();
}
private void DRMAuthenticatorOnOnComplete(object sender, DRMStatusCode e)
{
// Todo: Handle the DRM status codes
if (e != DRMStatusCode.Success) // If the authentication fails
{
// Todo: Handle the failure as you like
// For example, just kick them :D
// Application.Quit();
}
}
}
Status Codes
Success
- The DRM verification was successful.ProverNotReady
- The prover is not ready to create a proof.ProverError
- An error occurred while creating a proof.DeviceNotCompatible
- The device is not compatible with the DRM system.Timeout
- The verification timed out.GameNotBoughtOrNoConnection
- The game was not bought or there is no connection with local prover. Also caused by if prover could not communicate with the Mina blockchain.MinaNodeError
- An error occurred while communicating with the Mina blockchain.SetEnvironment
- The DRM Environment was not set. Please set contract addresses in the DRMAuthenticator as described in the Set Environment section.Continue
- Internal status code to continue the verification process.