signature
abstract suspend fun signature(keyshare: ByteArray, message: String, derivationPath: String = "m"): Result<ByteArray>
Creates a cryptographic signature using two-party threshold signing.
Supports HD (Hierarchical Deterministic) derivation for managing multiple addresses from a single keyshare.
Example: Sign Transaction
// Prepare transaction for your blockchain
val transaction = buildTransaction(
to = recipientAddress,
amount = amount,
nonce = nonce
)
// Hash transaction according to your blockchain's requirements
val txHash = hashTransaction(transaction)
// Sign with MPC
val signature = session.signature(
keyshare = keyshare,
message = txHash.toHexString(),
derivationPath = "m/44'/X'/0'/0/0" // X = your coin type
).getOrThrow()
// Apply signature and broadcast
val signedTx = transaction.withSignature(signature)
val txHash = blockchainClient.broadcast(signedTx)
println("Transaction broadcast: $txHash")Content copied to clipboard
Example: Sign Arbitrary Message
val message = "Authentication request for user login"
// Hash the message
val messageHash = hashMessage(message)
// Sign
val signature = session.signature(
keyshare = keyshare,
message = messageHash.toHexString(),
derivationPath = "m/44'/X'/0'/0/0"
).getOrThrow()
// Use for authentication
authenticate(address, message, signature)Content copied to clipboard
Example: Multi-Account Signing
// Sign from different derived accounts
val accounts = listOf(
"m/44'/X'/0'/0/0", // Account 0
"m/44'/X'/0'/0/1", // Account 1
"m/44'/X'/0'/0/2" // Account 2
)
accounts.forEachIndexed { index, path ->
val signature = session.signature(
keyshare = keyshare,
message = messageHash,
derivationPath = path
).getOrThrow()
println("Account $index signed successfully")
}Content copied to clipboard
Example: Batch Signing with Error Handling
suspend fun signMultipleTransactions(
transactions: List<Transaction>,
session: DuoSession,
keyshare: ByteArray
): List<Result<ByteArray>> {
return transactions.map { tx ->
try {
val txHash = hashTransaction(tx)
session.signature(
keyshare = keyshare,
message = txHash.toHexString(),
derivationPath = tx.derivationPath
)
} catch (e: Exception) {
Result.failure(e)
}
}
}Content copied to clipboard
Return
Parameters
keyshare
The keyshare to use for signing
message
The message hash to sign (hexadecimal string). Must be a cryptographic hash (SHA256, Keccak256, Blake2b, etc.), not raw data.
derivationPath
BIP32 HD derivation path. Default: "m" (root key). Format: "m/44'/X'/0'/0/0" where X is your coin type.
See also
for address derivation