working end-2-end with conclave

This commit is contained in:
stefano 2022-03-25 13:19:52 +00:00
parent ca1d6b89c7
commit 98a43101d1
2 changed files with 11 additions and 17 deletions

View File

@ -1,9 +1,7 @@
package net.corda.core.flows package net.corda.core.flows
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.core.conclave.common.dto.ConclaveLedgerTxModel
import net.corda.core.conclave.common.dto.EncryptedVerifiableTxAndDependencies import net.corda.core.conclave.common.dto.EncryptedVerifiableTxAndDependencies
import net.corda.core.conclave.common.dto.VerifiableTxAndDependencies
import net.corda.core.crypto.TransactionSignature import net.corda.core.crypto.TransactionSignature
import net.corda.core.crypto.isFulfilledBy import net.corda.core.crypto.isFulfilledBy
import net.corda.core.crypto.toStringShort import net.corda.core.crypto.toStringShort
@ -264,7 +262,7 @@ class CollectSignatureFlow(val partiallySignedTx: SignedTransaction, val session
* @param otherSideSession The session which is providing you a transaction to sign. * @param otherSideSession The session which is providing you a transaction to sign.
*/ */
abstract class SignTransactionFlow @JvmOverloads constructor(val otherSideSession: FlowSession, abstract class SignTransactionFlow @JvmOverloads constructor(val otherSideSession: FlowSession,
override val progressTracker: ProgressTracker = SignTransactionFlow.tracker(), val encrypted : Boolean = false) : FlowLogic<SignedTransaction>() { override val progressTracker: ProgressTracker = SignTransactionFlow.tracker(), val encrypted: Boolean = false) : FlowLogic<SignedTransaction>() {
companion object { companion object {
object RECEIVING : ProgressTracker.Step("Receiving transaction proposal for signing.") object RECEIVING : ProgressTracker.Step("Receiving transaction proposal for signing.")
@ -280,11 +278,11 @@ abstract class SignTransactionFlow @JvmOverloads constructor(val otherSideSessio
progressTracker.currentStep = RECEIVING progressTracker.currentStep = RECEIVING
// Receive transaction and resolve dependencies, check sufficient signatures is disabled as we don't have all signatures. // Receive transaction and resolve dependencies, check sufficient signatures is disabled as we don't have all signatures.
var receivedEncryptedTx : EncryptedTransaction? = null var usableLocallyEncryptedTransaction: EncryptedTransaction? = null
val stx = if (encrypted) { val stx = if (encrypted) {
val stxAndEncrypted = subFlow(ReceiveTransactionWithEncryptedFlow(otherSideSession, checkSufficientSignatures = false)) val stxAndEncrypted = subFlow(ReceiveTransactionWithEncryptedFlow(otherSideSession, checkSufficientSignatures = false))
receivedEncryptedTx = stxAndEncrypted.encryptedTransaction usableLocallyEncryptedTransaction = stxAndEncrypted.encryptedTransaction
stxAndEncrypted.signedTransaction stxAndEncrypted.signedTransaction
} else { } else {
subFlow(ReceiveTransactionFlow(otherSideSession, checkSufficientSignatures = false, encrypted = true)) subFlow(ReceiveTransactionFlow(otherSideSession, checkSufficientSignatures = false, encrypted = true))
@ -305,11 +303,7 @@ abstract class SignTransactionFlow @JvmOverloads constructor(val otherSideSessio
if (encrypted) { if (encrypted) {
val encryptionService = serviceHub.encryptedTransactionService val encryptionService = serviceHub.encryptedTransactionService
val validatedTxSvc = serviceHub.validatedTransactions val validatedTxSvc = serviceHub.validatedTransactions
val locallyEncryptedTransaction = usableLocallyEncryptedTransaction ?: throw IllegalStateException("An encrypted transaction is required")
val usableReceivedTx = receivedEncryptedTx ?: throw IllegalStateException("An encrypted transaction is required")
val locallyEncryptedTransaction = encryptionService.encryptTransactionForLocal(usableReceivedTx)
val encryptedTxs = stx.dependencies.mapNotNull { val encryptedTxs = stx.dependencies.mapNotNull {
validatedTxSvc.getEncryptedTransaction(it) validatedTxSvc.getEncryptedTransaction(it)
}.toSet() }.toSet()
@ -319,11 +313,11 @@ abstract class SignTransactionFlow @JvmOverloads constructor(val otherSideSessio
}.toSet() }.toSet()
encryptionService.enclaveVerifyWithoutSignatures( encryptionService.enclaveVerifyWithoutSignatures(
EncryptedVerifiableTxAndDependencies( EncryptedVerifiableTxAndDependencies(
locallyEncryptedTransaction, locallyEncryptedTransaction,
signedTxs, signedTxs,
encryptedTxs encryptedTxs
) )
) )
} else { } else {
stx.tx.toLedgerTransaction(serviceHub).verify() stx.tx.toLedgerTransaction(serviceHub).verify()

View File

@ -96,7 +96,7 @@ abstract class ReceiveTransactionFlowBase<T> @JvmOverloads constructor(private v
checkParameterHash(it.networkParametersHash) checkParameterHash(it.networkParametersHash)
if (encryptedTx != null) { if (encryptedTx != null) {
require(encryptedTx.id == it.id) { require(encryptedTx!!.id == it.id) {
"The supplied signed transaction and encrypted transactions are different" "The supplied signed transaction and encrypted transactions are different"
} }
} }
@ -112,7 +112,7 @@ abstract class ReceiveTransactionFlowBase<T> @JvmOverloads constructor(private v
val usableEncryptedTransaction = encryptedTxSvc.encryptTransactionForLocal( val usableEncryptedTransaction = encryptedTxSvc.encryptTransactionForLocal(
encryptedTx ?: throw IllegalStateException("And encrypted transaction is required") encryptedTx ?: throw IllegalStateException("And encrypted transaction is required")
) )
encryptedTx = usableEncryptedTransaction
val signedTxs = it.dependencies.mapNotNull { val signedTxs = it.dependencies.mapNotNull {
validatedTxId -> validatedTxId ->
validatedTxSvc.getTransaction(validatedTxId) validatedTxSvc.getTransaction(validatedTxId)