Mobile SDK Wallets
Mobile SDK Wallets

Credentials

Every transaction that changes the state of a blockchain (a swap, a token transfer, etc.) requires Credentials as a parameter. Credentials class is an abstraction over transaction signing and consists of:
  1. 1.
    Address,
  2. 2.
    TransactionSigner interface that signs a transaction that should be sent from this address. A TransactionSigner interface can be either TransactionSigner.Blocking (a blocking mode) or TransactionSigner.Async (a non-blocking mode).
Symbiosis Mobile SDK implements transaction signing with a mnemonic phrase and a private key.

Wallet authorization

Mnemonic phrase

There is a recommended way to create KeyPhrase.
  1. 1.
    Wrap a string into KeyPhrase:
val keyPhrase = KeyPhrase.wrapChecked(
keyPhrase = "..."
) ?: error("This keyphrase is invalid")
It returns null, if the string is not valid.
2. Create Credentials:
val credentials = Credentials.createFromKeyPhrase(keyPhrase)
Credentials.createFromKeyPhrase doesn't throw an error since any KeyPhrase can be used to create a valid Credentials

Private key

There is an example of how to create Credentials with a private key:
val credentials: Credentials = Credentials.createFromPrivateKey(
key = Hex32String("...")
)
Credentials.createFromPrivateKey doesn't throw an error since anyHex32String can be used to create a valid Credentials

Common way

Credentials.createFromKeyPhraseOrPrivateKey() recognizes a string without spaces as a private key and a string with spaces as a mnemonic phrase.
val credentials: Credentials? = Credentials.createFromKeyPhraseOrPrivateKey(
value = "..."
)
Credentials.createFromKeyPhraseOrPrivateKey returns null, if a mnemonic phrase is not valid.

Other ways

You can define an additional way to sign a transaction, e.g., via MetaMask. To do this, define a new class first and then pass an instance of that class to Credentials as in the example below:
class MetaMaskSigner(
private val address: WalletAddress
) : TransactionSigner.Async {
override suspend fun signTransferTransaction(
nonce: BigInt,
chainId: BigInt,
to: WalletAddress,
value: BigInt,
gasConfiguration: GasConfiguration
): SignedTransaction = TODO()
override suspend fun signContractTransaction(
nonce: BigInt,
chainId: BigInt,
to: ContractAddress,
contractData: String,
value: BigInt,
gasConfiguration: GasConfiguration
): SignedTransaction = TODO()
}
// defining an extension function
fun Credentials.Companion.createFromMetaMask(address: WalletAddress) =
Credentials(address, MetaMaskSigner(address))
// using the extension function
val metaMask = Credentials.createFromMetaMask(/*...*/)
Copy link
On this page
Credentials
Wallet authorization
Mnemonic phrase
Private key
Common way
Other ways