Перейти к содержанию

Installation

Currently, the following modules need to be installed:

  • com.spatium:spatium-sdk - the main Spatium SDK package containing protocol and core cryptography logic.
  • com.spatium:signer-client-kotlin - an auxiliary package that contains specific components for working with the SDK and Spatium Signer Service.

Access

Both packages are available in the private Maven repository of Spatium. Access credentials can be obtained directly from the Spatium team.

In settings.gradle add the Spatium Maven repository:

dependencyResolutionManagement {
    ...
    repositories {
        ...
        maven {
            url "https://registry.spatium.io/repository/maven-develop-spt/"
            credentials {
                username = 'YOUR_USERNAME'
                password = 'YOUR_PASSWORD'
            }
        }
    }
}

In your app module's gradle file add dependencies like so:

dependencies {
    ...
    implementation 'com.spatium:spatium-sdk:1.0.2'
    implementation 'com.spatium:signer-client-kotlin:1.0.2'
}

Connection

The following snippet allows you to verify a connection by registering a new pair of secrets and synchronizing the public key.

import com.spatium.signerclient.AuthorizationSession
import com.spatium.signerclient.SignerClient
import com.spatium.spatiumsdk.EcdsaCurve
import com.spatium.spatiumsdk.MemoryStorageDriver
import com.spatium.spatiumsdk.SpatiumCrypto
import com.spatium.spatiumsdk.syncDistributedEcdsaKey

suspend fun syncECDSA(username: String, password: String): String {
    val auth = AuthorizationSession(
        url = "https://api-cloud-dev.spatium.io/authorization/v1",
        tokenId = UUID.randomUUID().toString(),
        permissions = listOf("read", "secret")
    )

    val clientCache = MemoryStorageDriver()
    val clientStorage = MemoryStorageDriver()

    val clientCrypto = SpatiumCrypto(cache = clientCache, storage = clientStorage)

    val clientProtocol = SignerClient(
        url = "https://api-cloud-dev.spatium.io/signer/v1",
        auth = auth,
        crypto = clientCrypto,
        timeout = (60 * 1000).toUInt()
    )

    // Retrieve a securityToken for an existing user via Cloud API

    clientProtocol.auth.establish(listOf(securityToken))

    clientProtocol.connect((60*1000).toUInt())

    delay(4000)

    val secretId = UUID.randomUUID().toString()
    clientProtocol.generateDistributedSecret(
        secretId = secretId);

    val syncSessionId = UUID.randomUUID().toString()

    val publicKey = syncDistributedEcdsaKey(
        driver = clientProtocol,
        secretId = secretId,
        syncSessionId = syncSessionId,
        curve = EcdsaCurve.secp256k1,
        derivationCoin = 0U,
        derivationAccount = 0U
    )
    return publicKey
}