From 8f860688077d536a0700f4c127661f3788eb66ee Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 18 Sep 2017 14:19:20 +0100 Subject: [PATCH] Move SwapIdentitiesFlow to confidential-identities module (#1531) * Move SwapIdentitiesFlow to confidential-identities module * Clean up confidential-identities build.gradle * Change description to include Experimental * Move confidential-identities to a dependency of node rather than node-api --- build.gradle | 5 +- confidential-identities/build.gradle | 64 +++++++++++++++++++ .../corda/confidential}/SwapIdentitiesFlow.kt | 5 +- .../confidential/SwapIdentitiesHandler.kt | 27 ++++++++ .../confidential}/SwapIdentitiesFlowTests.kt | 2 +- finance/build.gradle | 1 + .../corda/finance/flows/CashPaymentFlow.kt | 2 +- .../corda/finance/flows/TwoPartyDealFlow.kt | 6 +- node/build.gradle | 1 + .../net/corda/node/internal/AbstractNode.kt | 3 +- .../corda/node/services/CoreFlowHandlers.kt | 27 ++------ settings.gradle | 3 +- 12 files changed, 117 insertions(+), 29 deletions(-) create mode 100644 confidential-identities/build.gradle rename {core/src/main/kotlin/net/corda/core/flows => confidential-identities/src/main/kotlin/net/corda/confidential}/SwapIdentitiesFlow.kt (94%) create mode 100644 confidential-identities/src/main/kotlin/net/corda/confidential/SwapIdentitiesHandler.kt rename {core/src/test/kotlin/net/corda/core/flows => confidential-identities/src/test/kotlin/net/corda/confidential}/SwapIdentitiesFlowTests.kt (98%) diff --git a/build.gradle b/build.gradle index f16c378b85..ba1bf0abf7 100644 --- a/build.gradle +++ b/build.gradle @@ -184,6 +184,7 @@ dependencies { cordaRuntime project(':client:mock') cordaRuntime project(':client:rpc') cordaRuntime project(':core') + cordaRuntime project(':confidential-identities') cordaRuntime project(':finance') cordaRuntime project(':webserver') testCompile project(':test-utils') @@ -251,7 +252,7 @@ bintrayConfig { projectUrl = 'https://github.com/corda/corda' gpgSign = true gpgPassphrase = System.getenv('CORDA_BINTRAY_GPG_PASSPHRASE') - publications = ['corda-jfx', 'corda-mock', 'corda-rpc', 'corda-core', 'corda', 'corda-finance', 'corda-node', 'corda-node-api', 'corda-test-common', 'corda-test-utils', 'corda-jackson', 'corda-verifier', 'corda-webserver-impl', 'corda-webserver', 'corda-node-driver'] + publications = ['corda-jfx', 'corda-mock', 'corda-rpc', 'corda-core', 'corda', 'corda-finance', 'corda-node', 'corda-node-api', 'corda-test-common', 'corda-test-utils', 'corda-jackson', 'corda-verifier', 'corda-webserver-impl', 'corda-webserver', 'corda-node-driver', 'corda-confidential-identities'] license { name = 'Apache-2.0' url = 'https://www.apache.org/licenses/LICENSE-2.0' @@ -286,7 +287,7 @@ artifactory { password = System.getenv('CORDA_ARTIFACTORY_PASSWORD') } defaults { - publications('corda-jfx', 'corda-mock', 'corda-rpc', 'corda-core', 'corda', 'cordform-common', 'corda-finance', 'corda-node', 'corda-node-api', 'corda-test-common', 'corda-test-utils', 'corda-jackson', 'corda-verifier', 'corda-webserver-impl', 'corda-webserver', 'corda-node-driver') + publications('corda-jfx', 'corda-mock', 'corda-rpc', 'corda-core', 'corda', 'cordform-common', 'corda-finance', 'corda-node', 'corda-node-api', 'corda-test-common', 'corda-test-utils', 'corda-jackson', 'corda-verifier', 'corda-webserver-impl', 'corda-webserver', 'corda-node-driver', 'corda-confidential-identities') } } } diff --git a/confidential-identities/build.gradle b/confidential-identities/build.gradle new file mode 100644 index 0000000000..fcad3bbf8c --- /dev/null +++ b/confidential-identities/build.gradle @@ -0,0 +1,64 @@ +// Experimental Confidential Identities support for 1.0 +// This contains the prototype SwapIdentitiesFlow and SwapIdentitiesHandler, which can be used +// for exchanging confidential identities as part of a flow, until a permanent solution is prepared. +// Expect this module to be removed and merged into core in a later release. +apply plugin: 'kotlin' +apply plugin: CanonicalizerPlugin +apply plugin: 'net.corda.plugins.publish-utils' +apply plugin: 'net.corda.plugins.quasar-utils' +apply plugin: 'net.corda.plugins.cordformation' +apply plugin: 'com.jfrog.artifactory' + +description 'Corda Experimental Confidential Identities' + +buildscript { + repositories { + mavenCentral() + } +} + +dependencies { + // Note the :confidential-identities module is a CorDapp in its own right + // and CorDapps using :confidential-identities features should use 'cordapp' not 'compile' linkage. + cordaCompile project(':core') + + testCompile "junit:junit:$junit_version" + + // Guava: Google test library (collections test suite) + testCompile "com.google.guava:guava-testlib:$guava_version" + + // Bring in the MockNode infrastructure for writing protocol unit tests. + testCompile project(":node") + testCompile project(":node-driver") + + compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" + compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" + + // Quasar, for suspendable fibres. + compileOnly "co.paralleluniverse:quasar-core:$quasar_version:jdk8" + + // AssertJ: for fluent assertions for testing + testCompile "org.assertj:assertj-core:${assertj_version}" +} + +configurations { + testArtifacts.extendsFrom testRuntime +} + +task testJar(type: Jar) { + classifier "tests" + from sourceSets.test.output +} + +artifacts { + testArtifacts testJar +} + +jar { + baseName 'corda-confidential-identities' +} + +publish { + name jar.baseName +} diff --git a/core/src/main/kotlin/net/corda/core/flows/SwapIdentitiesFlow.kt b/confidential-identities/src/main/kotlin/net/corda/confidential/SwapIdentitiesFlow.kt similarity index 94% rename from core/src/main/kotlin/net/corda/core/flows/SwapIdentitiesFlow.kt rename to confidential-identities/src/main/kotlin/net/corda/confidential/SwapIdentitiesFlow.kt index 83e20cd5ae..d11bd556a5 100644 --- a/core/src/main/kotlin/net/corda/core/flows/SwapIdentitiesFlow.kt +++ b/confidential-identities/src/main/kotlin/net/corda/confidential/SwapIdentitiesFlow.kt @@ -1,6 +1,9 @@ -package net.corda.core.flows +package net.corda.confidential import co.paralleluniverse.fibers.Suspendable +import net.corda.core.flows.FlowLogic +import net.corda.core.flows.InitiatingFlow +import net.corda.core.flows.StartableByRPC import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party import net.corda.core.identity.PartyAndCertificate diff --git a/confidential-identities/src/main/kotlin/net/corda/confidential/SwapIdentitiesHandler.kt b/confidential-identities/src/main/kotlin/net/corda/confidential/SwapIdentitiesHandler.kt new file mode 100644 index 0000000000..d2b226ec1d --- /dev/null +++ b/confidential-identities/src/main/kotlin/net/corda/confidential/SwapIdentitiesHandler.kt @@ -0,0 +1,27 @@ +package net.corda.confidential; + +import co.paralleluniverse.fibers.Suspendable; +import net.corda.core.flows.FlowLogic +import net.corda.core.identity.Party +import net.corda.core.identity.PartyAndCertificate +import net.corda.core.utilities.ProgressTracker +import net.corda.core.utilities.unwrap + +class SwapIdentitiesHandler(val otherSide: Party, val revocationEnabled: Boolean) : FlowLogic() { + constructor(otherSide: Party) : this(otherSide, false) + companion object { + object SENDING_KEY : ProgressTracker.Step("Sending key") + } + + override val progressTracker: ProgressTracker = ProgressTracker(SENDING_KEY) + + @Suspendable + override fun call(): Unit { + val revocationEnabled = false + progressTracker.currentStep = SENDING_KEY + val legalIdentityAnonymous = serviceHub.keyManagementService.freshKeyAndCert(ourIdentity, revocationEnabled) + sendAndReceive(otherSide, legalIdentityAnonymous).unwrap { confidentialIdentity -> + SwapIdentitiesFlow.validateAndRegisterIdentity(serviceHub.identityService, otherSide, confidentialIdentity) + } + } +} \ No newline at end of file diff --git a/core/src/test/kotlin/net/corda/core/flows/SwapIdentitiesFlowTests.kt b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt similarity index 98% rename from core/src/test/kotlin/net/corda/core/flows/SwapIdentitiesFlowTests.kt rename to confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt index d0eebd1c65..f974216870 100644 --- a/core/src/test/kotlin/net/corda/core/flows/SwapIdentitiesFlowTests.kt +++ b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt @@ -1,4 +1,4 @@ -package net.corda.core.flows +package net.corda.confidential import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty diff --git a/finance/build.gradle b/finance/build.gradle index e67a674738..7ded74b45d 100644 --- a/finance/build.gradle +++ b/finance/build.gradle @@ -14,6 +14,7 @@ dependencies { // Note the :finance module is a CorDapp in its own right // and CorDapps using :finance features should use 'cordapp' not 'compile' linkage. cordaCompile project(':core') + cordaCompile project(':confidential-identities') testCompile project(':test-utils') testCompile project(path: ':core', configuration: 'testArtifacts') diff --git a/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt b/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt index 8ace7c1503..38623c23d2 100644 --- a/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt +++ b/finance/src/main/kotlin/net/corda/finance/flows/CashPaymentFlow.kt @@ -1,10 +1,10 @@ package net.corda.finance.flows import co.paralleluniverse.fibers.Suspendable +import net.corda.confidential.SwapIdentitiesFlow import net.corda.core.contracts.Amount import net.corda.core.contracts.InsufficientBalanceException import net.corda.core.flows.StartableByRPC -import net.corda.core.flows.SwapIdentitiesFlow import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party import net.corda.core.serialization.CordaSerializable diff --git a/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt b/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt index e73c8f2d70..63a05214e0 100644 --- a/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt +++ b/finance/src/main/kotlin/net/corda/finance/flows/TwoPartyDealFlow.kt @@ -1,10 +1,14 @@ package net.corda.finance.flows import co.paralleluniverse.fibers.Suspendable +import net.corda.confidential.SwapIdentitiesFlow import net.corda.core.contracts.requireThat import net.corda.core.crypto.SecureHash import net.corda.core.crypto.TransactionSignature -import net.corda.core.flows.* +import net.corda.core.flows.CollectSignaturesFlow +import net.corda.core.flows.FinalityFlow +import net.corda.core.flows.FlowLogic +import net.corda.core.flows.SignTransactionFlow import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party diff --git a/node/build.gradle b/node/build.gradle index 4afebf95e2..a784504792 100644 --- a/node/build.gradle +++ b/node/build.gradle @@ -77,6 +77,7 @@ processSmokeTestResources { dependencies { compile project(':node-api') + compile project(":confidential-identities") compile project(':client:rpc') compile "net.corda.plugins:cordform-common:$gradle_plugins_version" diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index cf949b89e0..e0f6eb679a 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -4,6 +4,8 @@ import com.codahale.metrics.MetricRegistry import com.google.common.collect.Lists import com.google.common.collect.MutableClassToInstanceMap import com.google.common.util.concurrent.MoreExecutors +import net.corda.confidential.SwapIdentitiesFlow +import net.corda.confidential.SwapIdentitiesHandler import net.corda.core.concurrent.CordaFuture import net.corda.core.crypto.* import net.corda.core.flows.* @@ -35,7 +37,6 @@ import net.corda.node.internal.cordapp.CordappLoader import net.corda.node.internal.cordapp.CordappProvider import net.corda.node.services.NotaryChangeHandler import net.corda.node.services.NotifyTransactionHandler -import net.corda.node.services.SwapIdentitiesHandler import net.corda.node.services.api.* import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.configureWithDevSSLCertificate diff --git a/node/src/main/kotlin/net/corda/node/services/CoreFlowHandlers.kt b/node/src/main/kotlin/net/corda/node/services/CoreFlowHandlers.kt index 77282ee996..622d994c7c 100644 --- a/node/src/main/kotlin/net/corda/node/services/CoreFlowHandlers.kt +++ b/node/src/main/kotlin/net/corda/node/services/CoreFlowHandlers.kt @@ -1,9 +1,13 @@ package net.corda.node.services import co.paralleluniverse.fibers.Suspendable -import net.corda.core.flows.* -import net.corda.core.identity.PartyAndCertificate +import net.corda.confidential.SwapIdentitiesFlow +import net.corda.core.flows.AbstractStateReplacementFlow +import net.corda.core.flows.FlowLogic +import net.corda.core.flows.ReceiveTransactionFlow +import net.corda.core.flows.StateReplacementException import net.corda.core.identity.Party +import net.corda.core.identity.PartyAndCertificate import net.corda.core.transactions.SignedTransaction import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.unwrap @@ -44,22 +48,3 @@ class NotaryChangeHandler(otherSide: Party) : AbstractStateReplacementFlow.Accep } } } - -class SwapIdentitiesHandler(val otherSide: Party, val revocationEnabled: Boolean) : FlowLogic() { - constructor(otherSide: Party) : this(otherSide, false) - companion object { - object SENDING_KEY : ProgressTracker.Step("Sending key") - } - - override val progressTracker: ProgressTracker = ProgressTracker(SENDING_KEY) - - @Suspendable - override fun call(): Unit { - val revocationEnabled = false - progressTracker.currentStep = SENDING_KEY - val legalIdentityAnonymous = serviceHub.keyManagementService.freshKeyAndCert(ourIdentity, revocationEnabled) - sendAndReceive(otherSide, legalIdentityAnonymous).unwrap { confidentialIdentity -> - SwapIdentitiesFlow.validateAndRegisterIdentity(serviceHub.identityService, otherSide, confidentialIdentity) - } - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 4d2f595935..a3b8270486 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,7 @@ // The project is named 'corda-project' and not 'corda' because if this is named the same as the // output JAR from the capsule then the buildCordaJAR task goes into an infinite loop. rootProject.name = 'corda-project' +include 'confidential-identities' include 'finance' include 'finance:isolated' include 'core' @@ -38,4 +39,4 @@ include 'samples:irs-demo' include 'samples:network-visualiser' include 'samples:simm-valuation-demo' include 'samples:notary-demo' -include 'samples:bank-of-corda-demo' \ No newline at end of file +include 'samples:bank-of-corda-demo'