diff --git a/common/mock-enclave/build.gradle b/common/mock-enclave/build.gradle new file mode 100644 index 0000000000..5b55c0a39e --- /dev/null +++ b/common/mock-enclave/build.gradle @@ -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 +} \ No newline at end of file diff --git a/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/dto/ConclaveLedgerTxModel.kt b/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/dto/ConclaveLedgerTxModel.kt new file mode 100644 index 0000000000..83fa09f293 --- /dev/null +++ b/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/dto/ConclaveLedgerTxModel.kt @@ -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>, + val attachments: Array, + val networkParameters: NetworkParameters, + val references: Array> +) { + 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 + } +} \ No newline at end of file diff --git a/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/enclave/EncryptedTxEnclave.kt b/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/enclave/EncryptedTxEnclave.kt new file mode 100644 index 0000000000..1d9e92a3fe --- /dev/null +++ b/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/enclave/EncryptedTxEnclave.kt @@ -0,0 +1,4 @@ +package com.r3.conclave.encryptedtx.enclave + +class EncryptedTxEnclave { +} \ No newline at end of file diff --git a/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/internal/TransactionUtils.kt b/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/internal/TransactionUtils.kt new file mode 100644 index 0000000000..5768bbefe2 --- /dev/null +++ b/common/mock-enclave/src/main/kotlin/com/r3/conclave/encryptedtx/internal/TransactionUtils.kt @@ -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 + get() = (inputStates.asSequence() + references.asSequence()).map { it.ref.txhash }.toSet() \ No newline at end of file diff --git a/core/src/main/kotlin/net/corda/core/transactions/EncryptedTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/EncryptedTransaction.kt new file mode 100644 index 0000000000..df90356b5c --- /dev/null +++ b/core/src/main/kotlin/net/corda/core/transactions/EncryptedTransaction.kt @@ -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, + override val sigs: List +) : TransactionWithSignatures { + + override val requiredSigningKeys: Set = emptySet() + + override fun getKeyDescriptions(keys: Set): List = 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 + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 97dfbdd783..acb034eec6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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'