Precompute Sign
Presign allows the signing parties to offline precompute expensive signanture material. Offline means before any active user needs to sign a specific message. By doing so the total running time for computing signatures is almost instant minimizing net work traffic load and computation demand.
We can finalise the precomputed signature with actual message later.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Precompute Signature
-
Call trioSession.preSignature() which returns
ResultofSuccesswith Precompute SignatureByteArrayorFailurewith exception.trioSession.preSignature(keyshare = keyshare).onSuccess { preComputedSignature ->
//todo: Do final signature later using preComputedSignature (lambda argument received here)
Log.i(
"PreComputeSignature","Success, Pre Computed Signature size : ${preComputedSignature.size}")
}.onFailure { failureReason ->
Log.e("PreComputeSignature", failureReason.message ?: "")
}keyshareis the client's "share" of the MPC wallet.preComputedSignatureis the pre computed signature asByteArraywhich could later be used to perform final signature.
Step 3 : Finalise Precompute Signature (Later in the future)
-
Call trioSession.preSignatureFinal() which returns
ResultofSuccesswith the Final SignatureByteArrayorFailurewith exception.val messageHash = "e2a159d17b7bb714aed7675d7c7d394dec8d2e4337842848104694bf89c71c03"
//preSignature for context (Step 2)
trioSession.preSignature(keyshare = keyshare).onSuccess { preComputedSignature ->
Log.i(
"PreComputeSignature","Success, Pre Computed Signature size : ${preComputedSignature.size}")
trioSession.preSignatureFinal(
preSignature = preComputedSignature, message = messageHash
).onSuccess { finalSignature ->
Log.i("PreSignatureFinal", "Success, Signature size : ${finalSignature.size}")
}.onFailure { reason ->
Log.e("PreSignatureFinal", reason.message ?: "")
}
}.onFailure { failureReason ->
Log.e("PreComputeSignature", failureReason.message ?: "")
}
}.onFailure { failureReason ->
Log.e("PreComputeSignature", failureReason.message ?: "")
}preComputedSignatureis the pre computed signature asByteArraygenerated in step 2.messageHashis the messageHash in Hex string without 0x suffix (absolute hex-string).
Example (Precompute Signature and Finalise Precomputed Signature)
Example.kt
val messageHash = "e2a159d17b7bb714aed7675d7c7d394dec8d2e4337842848104694bf89c71c03"
suspend fun performPreComputeSignatureAndFinalisePreComputeSignature(
keyshare: ByteArray,
trioSession: TrioSession,
): Result<ByteArray> {
//suspending operation
return withContext(Dispatchers.IO) {
//compute pre-signature
trioSession.preSignature(keyshare = keyshare)
.onSuccess { preComputedSignature: ByteArray ->
//preSign success
Log.i(
"PreComputeSignature",
"Success, Pre Computed Signature size : ${preComputedSignature.size}"
)
//since preSign was success, we can now perform the signature (finalize pre-sign) with the message
trioSession.preSignatureFinal(
preSignature = preComputedSignature, message = messageHash,
derivationPath = "m" // This is the default, use your desired path here. For e.g 'm/1/2'
).onSuccess { finalSignature: ByteArray ->
//preSignFinal was a success
Log.i("PreSignatureFinal", "Success, Signature size : ${finalSignature.size}")
}.onFailure { reason: Throwable ->
//preSignFinal failed
Log.e("PreSignatureFinal", reason.message ?: "")
}
}
//preSign fail
.onFailure { failureReason: Throwable ->
Log.e("PreComputeSignature", failureReason.message ?: "")
}
}
}
keyshareis the client's "share" of the MPC wallet.preComputedSignatureis the pre computed signature asByteArraywhich could later be used to perform final signature.messageHashis the messageHash in Hex string without 0x suffix (absolute hex-string).
- trioSession.preSignature() performs message exchange between mobile and server to generate a pre computed ECDSA/EdDSA signature as ByteArray which is expected to be used to finalise the signature later with message.
- Result of trioSession.preSignature() could be a
SuccesswithByteArray(ECDSA/EdDSA pre-computed signature), corresponding to the public key (or address) of the wallet orFailurewithException.
- trioSession.preSignatureFinal() performs message exchange between mobile and server to generate a ECDSA/EdDSA signature.
- Result of trioSession.preSignatureFinal() could be a
SuccesswithByteArray(ECDSA/EdDSA signature) ofmessageHash, corresponding to the public key (or address) of the wallet orFailurewithException.