Skip to content

Adding Verification

The license verification library lets your script confirm that the user has purchased it before allowing execution.

Before you begin

License verification requires a network connection. The check will fail if:

  • The Cereal licensing server is unreachable, or
  • The server response indicates the user does not hold a valid license.

Design your onStart implementation to handle both cases explicitly (see the example below).

Step 1: Create a script in the Developer Console

Go to the Cereal Developer Console and create a new script entry. Inside the script details, open the Licensing section to find the public key for your script. You will need this key in your code.

Step 2: Add the Gradle dependency

Add the Cereal Maven repository to your root build.gradle.kts:

allprojects {
    repositories {
        // ...
        maven {
            url = uri("https://maven.cereal-automation.com/releases")
        }
    }
}

Then add the library to your module's build.gradle.kts:

dependencies {
    implementation("com.cereal.license_verification:<latest_version>")
}

Replace <latest_version> with the latest version available on the Cereal Maven repository.

Step 3: Add the license check

Call LicenseChecker.checkAccess() in onStart. The method returns a LicenseState:

Result Meaning
LicenseState.Licensed User holds a valid license. Allow the script to run.
LicenseState.ErrorValidatingLicense The server could not be reached. Return false so the user can retry.
Any other state User is not licensed. Block execution.
class MySampleScript : Script<MySampleConfiguration> {

    // Replace with the public key from the Cereal Developer Console.
    private val SCRIPT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n" +
        "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtL7rXEYD9WcQCGl8D9Ph\n" +
        "wj0WiPG/01+Y3rJyX5TRBfZLNE3hoLOPFDUzQOSy280e90Qv64Ux5plyUuts1Wbk\n" +
        "5vOH5q/TXEhdPixlwrVIAiMayIvV+t8mYCpOJBqaD+cvPQ1DYehUQ3hzax2XSd5O\n" +
        "K3N3r5iPJwtaLBLfSf8E5OnlCcADj8++3q52keTYkpJCrrJVwdJSs23oTq2aQEYj\n" +
        "WeQenq3Pl/J922kWqI8vZJiIb7kmKzcBdZR0zE39/d363dh/KU2c9v5DKFKG2HI6\n" +
        "I3eUkYGTUUqL+pLw9NtY4/tPmHN7FZXJ9rUvAaPk7oQzjSL2cJ1chmtcipUsZAy3\n" +
        "Fneh2HYlmAQpAc0V60DMzw9tQS2UQ5kQDGcC7h7xuAYHZT6jKhnuZon89Bek9qT+\n" +
        "ULgRMjuGTL4rpiMUabPj1IbGVZ6vTwYOjcltERh19MT8QchPo/UBB8W1CK4T3aLf\n" +
        "O3MHnGBeVTlhpBts57lAUGKP8RmGKLpmjL5lA4nw1B7BVzeJ2VuSy8Jhheq75IFp\n" +
        "kGoSrlqfxtA7SE8negMUEq6fca4J/Y5bABH6KHUrMiVaJGLa51Ert4qdOCvfJBlL\n" +
        "Ho/42AejYUJDi/P/fRiC99i6ObNPGXhQ9bz1Quz6F6VAzMjMmHo+OwQ5R2SHq2Yn\n" +
        "KmW5+hWaT3sqkxMw1a2JfTUCAwEAAQ==\n" +
        "-----END PUBLIC KEY-----\n"

    private var isLicensed = false

    override suspend fun onStart(
        configuration: MySampleConfiguration,
        provider: ComponentProvider
    ): Boolean {
        val licenseChecker = LicenseChecker(
            "com.cereal-automation.sample",
            SCRIPT_PUBLIC_KEY,
            provider.license()
        )
        val licenseResult = licenseChecker.checkAccess()
        isLicensed = licenseResult is LicenseState.Licensed

        // If the server was unreachable, return false so Cereal stops the script.
        // The user can then retry after restoring their connection.
        return licenseResult !is LicenseState.ErrorValidatingLicense
    }

    override suspend fun execute(
        configuration: MySampleConfiguration,
        provider: ComponentProvider,
        statusUpdate: StatusUpdate
    ): ExecutionResult {
        if (!isLicensed) {
            return ExecutionResult.Error("Unlicensed")
        }
        // Your script logic here
    }
}

Next steps