Skip to content

Commit 063e51b

Browse files
committed
ENT-14284 - Confidential Identity.
1 parent a15e293 commit 063e51b

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

Tokens/stockpaydividend/bridging-flows/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dependencies {
4949

5050
// CorDapp dependencies.
5151
cordapp project(":bridging-contracts")
52+
cordapp project(":contracts")
5253

5354
// Token SDK dependencies.
5455
cordaProvided "$tokens_release_group:tokens-contracts:$tokens_release_version"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.r3.corda.lib.tokens.bridging.flows
2+
3+
import com.r3.corda.lib.tokens.workflows.utilities.tokenAmountsByToken
4+
import net.corda.core.identity.PartyAndCertificate
5+
import net.corda.core.node.AppServiceHub
6+
import net.corda.core.node.services.CordaService
7+
import net.corda.core.serialization.SingletonSerializeAsToken
8+
import net.corda.samples.stockpaydividend.states.StockState
9+
import java.util.*
10+
11+
@CordaService
12+
class BridgingAuthorityBootstrapService(appServiceHub: AppServiceHub) : SingletonSerializeAsToken() {
13+
val holdingIdentityPartyAndCertificate: PartyAndCertificate
14+
val bridgeAuthorityParty = appServiceHub.ourIdentity()
15+
16+
init {
17+
val cfg = appServiceHub.getAppContext().config
18+
val holdingIdentityLabel = UUID.fromString(cfg.getString("holdingIdentityLabel"))
19+
val holdingIdentityPublicKey = appServiceHub
20+
.identityService
21+
.publicKeysForExternalId(holdingIdentityLabel)
22+
.singleOrNull()
23+
holdingIdentityPartyAndCertificate = if (holdingIdentityPublicKey == null) {
24+
// Generate a new key pair and self-signed certificate for the holding identity
25+
appServiceHub.keyManagementService.freshKeyAndCert(
26+
identity = requireNotNull(appServiceHub.identityService.certificateFromKey(bridgeAuthorityParty.owningKey)) {
27+
"Could not find certificate for key ${bridgeAuthorityParty.owningKey}"
28+
},
29+
revocationEnabled = false,
30+
externalId = holdingIdentityLabel
31+
)
32+
} else {
33+
// Reuse the existing key pair and certificate for the holding identity
34+
checkNotNull(appServiceHub.identityService.certificateFromKey(holdingIdentityPublicKey)) {
35+
"Could not find certificate for key $holdingIdentityPublicKey"
36+
}
37+
}
38+
39+
onStartup(appServiceHub)
40+
}
41+
42+
private fun onStartup(appServiceHub: AppServiceHub) {
43+
//Retrieve states from receiver
44+
val receivedStockStatesPages = appServiceHub.vaultService.queryBy(StockState::class.java).states
45+
val receivedStockStates = receivedStockStatesPages.map { it.state.data }
46+
47+
callFlow(receivedStockStates, appServiceHub)
48+
addVaultListener(appServiceHub)
49+
}
50+
51+
private fun addVaultListener(appServiceHub: AppServiceHub) {
52+
appServiceHub.vaultService.trackBy(StockState::class.java).updates.subscribe {
53+
val producedStockStates = it.produced.map { it.state.data }
54+
callFlow(producedStockStates, appServiceHub)
55+
}
56+
}
57+
58+
private fun callFlow(producedStockStates: Collection<StockState>, appServiceHub: AppServiceHub) {
59+
producedStockStates.forEach { stockState ->
60+
val tokens = appServiceHub.vaultService.tokenAmountsByToken(
61+
stockState.toPointer(
62+
stockState.javaClass
63+
)
64+
).states
65+
appServiceHub.startFlow(
66+
BridgeFungibleTokenFlow(
67+
holdingIdentityPartyAndCertificate.party,
68+
emptyList(),
69+
tokens.first(), //TODO handle multiple tokens
70+
bridgeAuthorityParty
71+
)
72+
)
73+
}
74+
}
75+
76+
private fun AppServiceHub.ourIdentity() = myInfo.legalIdentities.first()
77+
}

Tokens/stockpaydividend/workflows/src/test/kotlin/net/corda/samples/stockpaydividend/FlowTests.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ class FlowTests {
126126
val baConfig = mapOf(
127127
"participants" to mapOf(COMPANY.name.toString() to tokenAccount.base58()),
128128
"mints" to mapOf(LINEAR_ID.toString() to tokenMint.base58()),
129-
"mintAuthorities" to mapOf(LINEAR_ID.toString() to mintAuthority.account.base58())
129+
"mintAuthorities" to mapOf(LINEAR_ID.toString() to mintAuthority.account.base58()),
130+
"holdingIdentityLabel" to UUID.randomUUID().toString()
130131
)
131132
network = MockNetwork(
132133
MockNetworkParameters(

0 commit comments

Comments
 (0)