Skip to content
Oleg Koretsky edited this page Nov 26, 2021 · 12 revisions

All interaction with TokenD-based system relies on TokendApi instance.

Minimal required data for API initialization is a root URL of the system:

const val ROOT_URL = "https://api.testnet.tokend.org"

val api = TokenDApi(ROOT_URL)

However such instance cannot provide full access to the system because of two important points: requests signing and 2Factor authentication. Let's take a closer look on each at them:

Requests signing

API requests that interacts with sensitive data requires signing by user's Account i.e. the keypair. To create API instance with requests signing you have to specify requestSigner in the constructor:

val requestSigner = AccountRequestSigner(account)
val signedApi = TokenDApi(ROOT_URL, requestSigner)

You can get more info about requests signing in our Knowledge base or in API documentation

2Factor authentication

In theory any API request may require 2Factor authentication of the user if it is set. For example, sign in may require a code from Google Authenticator. To handle 2FA requests API instance requires TfaCallback implementation through which it could get one-time password from user:

val tfaCallback = object : TfaCallback {
    override fun onTfaRequired(exception: NeedTfaException,
                               verifierInterface: TfaVerifier.Interface) {
        val otp = requestAuthenticatorCode()
        verifierInterface.verify(otp)
    }
}

val api = TokenDApi(ROOT_URL, requestSigner, tfaCallback)

User agent

Default User-Agent header is defined by OkHTTP library but can be overriden:

const val USER_AGENT = "TokenD app/1.0"

val api = TokenDApi(ROOT_URL, requestSigner, tfaCallback, userAgent = USER_AGENT)

Logging

HTTP logging is enabled by default and can be disabled:

val api = TokenDApi(ROOT_URL, requestSigner, tfaCallback, withLogs = false)

ProGuard rules for Android

For correct ProGuard minification, add the related rules from TokenD Android client to your project's proguard-rules.pro: