Skip to content

Commit b39d913

Browse files
committed
ENT-14284 - Confidential Identities
1 parent a15e293 commit b39d913

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed

Tokens/stockpaydividend/bridging-flows/src/main/kotlin/com/r3/corda/lib/tokens/bridging/flows/BridgeFungibleTokenFlow.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import net.corda.solana.sdk.instruction.Pubkey
3232
class BridgeFungibleTokenFlow(
3333
val holder: AbstractParty,
3434
val observers: List<Party> = emptyList(),
35-
val token: StateAndRef<FungibleToken>, //TODO should be FungibleToken, TODO change to any TokenType would need amendments to UUID retrieval below
35+
val token: StateAndRef<FungibleToken>,
3636
val bridgeAuthority: Party
3737
) : FlowLogic<SignedTransaction>() {
3838

@@ -70,7 +70,8 @@ class BridgeFungibleTokenFlow(
7070
additionalCommand = additionalCommand,
7171
destination = destination,
7272
mint = mint,
73-
mintAuthority = mintAuthority
73+
mintAuthority = mintAuthority,
74+
holder
7475
)
7576
)
7677
}
@@ -106,14 +107,14 @@ constructor(
106107
val additionalCommand: BridgingContract.BridgingCommand,
107108
val destination: Pubkey,
108109
val mint: Pubkey,
109-
val mintAuthority: Pubkey
110+
val mintAuthority: Pubkey,
111+
val holder: AbstractParty
110112
) : AbstractMoveTokensFlow() { //TODO move away from this abstract class, it's progress tracker mention only token move
111113

112114
@Suspendable
113115
override fun addMove(transactionBuilder: TransactionBuilder) {
114116

115117
val amount = token.state.data.amount
116-
val holder = ourIdentity //TODO confidential identity
117118
val output = FungibleToken(amount, holder)
118119
addMoveTokens(transactionBuilder = transactionBuilder, inputs = listOf(token), outputs = listOf(output))
119120

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.r3.corda.lib.tokens.bridging.flows
2+
3+
import com.r3.corda.lib.tokens.contracts.states.FungibleToken
4+
import net.corda.core.contracts.StateAndRef
5+
import net.corda.core.identity.PartyAndCertificate
6+
import net.corda.core.node.AppServiceHub
7+
import net.corda.core.node.services.CordaService
8+
import net.corda.core.serialization.SingletonSerializeAsToken
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 receivedStates = appServiceHub.vaultService.queryBy(FungibleToken::class.java).states
45+
46+
callFlow(receivedStates, appServiceHub)
47+
addVaultListener(appServiceHub)
48+
}
49+
50+
private fun addVaultListener(appServiceHub: AppServiceHub) {
51+
appServiceHub.vaultService.trackBy(FungibleToken::class.java).updates.subscribe {
52+
val producedStockStates = it.produced
53+
callFlow(producedStockStates, appServiceHub)
54+
}
55+
}
56+
57+
private fun callFlow(fungibleTokens: Collection<StateAndRef<FungibleToken>>, appServiceHub: AppServiceHub) {
58+
fungibleTokens.forEach { token ->
59+
appServiceHub.startFlow(
60+
BridgeFungibleTokenFlow(
61+
holdingIdentityPartyAndCertificate.party,
62+
emptyList(),
63+
token,
64+
bridgeAuthorityParty
65+
)
66+
)
67+
}
68+
}
69+
70+
private fun AppServiceHub.ourIdentity() = myInfo.legalIdentities.first()
71+
}

Tokens/stockpaydividend/bridging-flows/src/main/kotlin/com/r3/corda/lib/tokens/bridging/flows/rpc/BridgeTokens.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import com.r3.corda.lib.tokens.contracts.states.FungibleToken
1010
import net.corda.core.contracts.StateAndRef
1111
import net.corda.core.utilities.ProgressTracker
1212

13+
// This flow is only for tests. In real life the @BridgingAuthorityBootstrapService.kt would run the BridgeFungibleTokenFlow directly.
1314
@InitiatingFlow
1415
@StartableByRPC
1516
class BridgeToken(
16-
val token: StateAndRef<FungibleToken>, //TODO change to a list?
17+
val token: StateAndRef<FungibleToken>,
1718
val bridgeAuthority: Party
1819
) : FlowLogic<String>() {
1920

@@ -25,7 +26,7 @@ class BridgeToken(
2526
//Use built-in flow for move tokens to the recipient
2627
val stx = subFlow(
2728
BridgeFungibleTokenFlow(
28-
ourIdentity, //TODO confidentialIdentity
29+
ourIdentity,
2930
emptyList(),
3031
token,
3132
bridgeAuthority

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)