Unity Package

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.

  1. Download the latest version of the DRM Mina Unity Package from the Downloads page (opens in a new tab).
  2. Open your Unity project and navigate to Assets > Import Package > Custom Package.
  3. Select the downloaded package and click Open.
  4. After the package is imported, you will see the DRMAuthenticator object in the Assets folder.
  5. Drag the DRMAuthenticator object into your scene.
  6. Set the contract addresses in the DRMAuthenticator object as described in the Set Environment section.
  7. You are now ready to use the DRM Mina Unity Package in your game, check the Status Codes section for the possible status codes.
  8. 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:

Set Environment

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.

DRMAuthenticationStarter.cs
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

  1. Success - The DRM verification was successful.
  2. ProverNotReady - The prover is not ready to create a proof.
  3. ProverError - An error occurred while creating a proof.
  4. DeviceNotCompatible - The device is not compatible with the DRM system.
  5. Timeout - The verification timed out.
  6. 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.
  7. MinaNodeError - An error occurred while communicating with the Mina blockchain.
  8. SetEnvironment - The DRM Environment was not set. Please set contract addresses in the DRMAuthenticator as described in the Set Environment section.
  9. Continue - Internal status code to continue the verification process.