Add encryption transaction data model

This commit is contained in:
lemjclarke 2022-03-07 15:46:07 +00:00
parent 8fa7efd867
commit 7822888ad7
6 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,25 @@
apply plugin: 'kotlin'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'com.jfrog.artifactory'
dependencies {
compile group: "org.jetbrains.kotlin", name: "kotlin-stdlib-jdk8", version: kotlin_version
compile group: "org.jetbrains.kotlin", name: "kotlin-reflect", version: kotlin_version
compile group: "com.typesafe", name: "config", version: typesafe_config_version
compile project(":core")
// test dependencies
testImplementation "junit:junit:$junit_version"
testCompile group: "org.jetbrains.kotlin", name: "kotlin-test", version: kotlin_version
}
jar {
baseName 'corda-common-mock-enclave'
}
publish {
name jar.baseName
}

View File

@ -0,0 +1,50 @@
package com.r3.conclave.encryptedtx.dto
import net.corda.core.contracts.Attachment
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateAndRef
import net.corda.core.node.NetworkParameters
import net.corda.core.transactions.WireTransaction
/**
* Enclave representation of a ledger transaction.
* ConclaveLedgerTxModel wraps a [WireTransaction] and additional properties to allow an enclave to reconstruct and
* verify a ledger transaction.
* @property wireTransaction a serializable transaction without signatures.
* @property inputStates an array of input states that will be consumed by the wrapped transaction.
* @property attachments an array of attachment objects that are required for this transaction to verify.
* @property networkParameters the network parameters that were in force when the enclosed wire transaction was
* constructed.
* @property references an array of reference states.
*/
data class ConclaveLedgerTxModel(
val wireTransaction: WireTransaction,
val inputStates: Array<StateAndRef<ContractState>>,
val attachments: Array<Attachment>,
val networkParameters: NetworkParameters,
val references: Array<StateAndRef<ContractState>>
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConclaveLedgerTxModel
if (wireTransaction != other.wireTransaction) return false
if (!inputStates.contentEquals(other.inputStates)) return false
if (!attachments.contentEquals(other.attachments)) return false
if (networkParameters != other.networkParameters) return false
if (!references.contentEquals(other.references)) return false
return true
}
override fun hashCode(): Int {
var result = wireTransaction.hashCode()
result = 31 * result + inputStates.contentHashCode()
result = 31 * result + attachments.contentHashCode()
result = 31 * result + networkParameters.hashCode()
result = 31 * result + references.contentHashCode()
return result
}
}

View File

@ -0,0 +1,4 @@
package com.r3.conclave.encryptedtx.enclave
class EncryptedTxEnclave {
}

View File

@ -0,0 +1,7 @@
package com.r3.conclave.encryptedtx.internal
import com.r3.conclave.encryptedtx.dto.ConclaveLedgerTxModel
import net.corda.core.crypto.SecureHash
val ConclaveLedgerTxModel.dependencies: Set<SecureHash>
get() = (inputStates.asSequence() + references.asSequence()).map { it.ref.txhash }.toSet()

View File

@ -0,0 +1,47 @@
package net.corda.core.transactions
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.TransactionSignature
import net.corda.core.serialization.CordaSerializable
import java.security.PublicKey
/**
* EncryptedTransaction wraps a serialized and encrypted enclave representation of a ledger transaction (a wire
* transaction with inputs, references, attachments and network parameters).
* @property id the hash of the [WireTransaction] Merkle tree root.
* @property encryptedBytes the serialized and encrypted enclave ledger tx.
* @property dependencies a set of transaction hashes this transaction depends on.
* @property sigs a list of signatures from individual public keys.
*/
@CordaSerializable
data class EncryptedTransaction(
override val id: SecureHash,
val encryptedBytes: ByteArray,
val dependencies: Set<SecureHash>,
override val sigs: List<TransactionSignature>
) : TransactionWithSignatures {
override val requiredSigningKeys: Set<PublicKey> = emptySet()
override fun getKeyDescriptions(keys: Set<PublicKey>): List<String> = emptyList()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as EncryptedTransaction
if (id != other.id) return false
if (!encryptedBytes.contentEquals(other.encryptedBytes)) return false
if (sigs != other.sigs) return false
return true
}
override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + encryptedBytes.contentHashCode()
result = 31 * result + sigs.hashCode()
return result
}
}

View File

@ -112,6 +112,9 @@ project(":common-configuration-parsing").projectDir = new File("$settingsDir/com
include 'common-logging'
project(":common-logging").projectDir = new File("$settingsDir/common/logging")
include 'common-mock-enclave'
project(":common-mock-enclave").projectDir = new File("$settingsDir/common/mock-enclave")
// Common libraries - end
apply from: 'buildCacheSettings.gradle'