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")

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)

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")
}

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)
}
}
}

Return

Result containing the signature as ByteArray

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