具有机密身份的观察者节点
Observer node with confidential identities
我已经开始使用 Observer 节点 (https://docs.corda.net/tutorial-observer-nodes.html) 进行一些测试,并且我刚刚构建了以下简单场景:
- 监管机构向银行 A 发行 10.POUNDS (CashIssueAndPaymentFlow)
- 银行 A 使用机密身份 (CashPaymentFlow, anonymous=true) 向银行 B 发送 4.POUNDS
- 在子流程中,银行 A 同步身份 (IdentitySyncFlow) 并将交易 (SendTransactionFlow) 报告给监管机构
当我查询 Regulator 金库时,它无法将 Bank B 识别为 4.POUNDS 的所有者,也就是说,它无法使用 wellKnownPartyFromAnonymous():
解析身份
6.00 GBP, owner=C=BR,L=Sao Paulo,O=BankA
4.00 GBP, owner=Anonymous(DLEg4Kqd7dwcGqkMrJEWoxugT61SoYKzxqpcMBKbMGXu3q)
也许我遗漏了什么?
Follow the code:
object TransferCashFlow {
@InitiatingFlow
@StartableByRPC
class Initiator(val amount: Amount<Currency>, val otherParty: Party, val regulator: Party) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val tx = subFlow(CashPaymentFlow(amount, otherParty, true)).stx
subFlow(ReportFlow.Initiator(regulator, tx))
return tx
}
}
}
object ReportFlow {
@InitiatingFlow
class Initiator(val regulator: Party, val tx: SignedTransaction) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val regulatorSession = initiateFlow(regulator)
subFlow(IdentitySyncFlow.Send(regulatorSession, tx.tx))
subFlow(SendTransactionFlow(regulatorSession, tx))
}
}
@InitiatedBy(Initiator::class)
class Responder(private val otherPartySession: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
subFlow(IdentitySyncFlow.Receive(otherPartySession))
subFlow(ReceiveTransactionFlow(otherPartySession, true, StatesToRecord.ALL_VISIBLE))
}
}
}
根据设计,IdentitySyncFlow.Send
将仅 发送交易中属于发送节点的机密身份的证书。见IdentitySyncFlow
中extractOurConfidentialIdentities()
的定义:
private fun extractOurConfidentialIdentities(): Map<AbstractParty, PartyAndCertificate?> {
val states: List<ContractState> = (tx.inputs.map { serviceHub.loadState(it) }.requireNoNulls().map { it.data } + tx.outputs.map { it.data })
val identities: Set<AbstractParty> = states.flatMap(ContractState::participants).toSet()
// Filter participants down to the set of those not in the network map (are not well known)
val confidentialIdentities = identities
.filter { serviceHub.networkMapCache.getNodesByLegalIdentityKey(it.owningKey).isEmpty() }
.toList()
return confidentialIdentities
.map { Pair(it, serviceHub.identityService.certificateFromKey(it.owningKey)) }
// Filter down to confidential identities of our well known identity
// TODO: Consider if this too restrictive - we perhaps should be checking the name on the signing certificate in the certificate path instead
.filter { it.second?.name == ourIdentity.name }
.toMap()
}
倒数第二行确保节点不会发送任何不属于它自己的身份证书。这是为了防止节点欺骗交易对手向其发送一堆机密身份。
如果您想发送 所有 机密身份,您必须根据 IdentitySyncFlow
定义自己的流程,该流程不执行此过滤.
我已经开始使用 Observer 节点 (https://docs.corda.net/tutorial-observer-nodes.html) 进行一些测试,并且我刚刚构建了以下简单场景:
- 监管机构向银行 A 发行 10.POUNDS (CashIssueAndPaymentFlow)
- 银行 A 使用机密身份 (CashPaymentFlow, anonymous=true) 向银行 B 发送 4.POUNDS
- 在子流程中,银行 A 同步身份 (IdentitySyncFlow) 并将交易 (SendTransactionFlow) 报告给监管机构
当我查询 Regulator 金库时,它无法将 Bank B 识别为 4.POUNDS 的所有者,也就是说,它无法使用 wellKnownPartyFromAnonymous():
解析身份6.00 GBP, owner=C=BR,L=Sao Paulo,O=BankA
4.00 GBP, owner=Anonymous(DLEg4Kqd7dwcGqkMrJEWoxugT61SoYKzxqpcMBKbMGXu3q)
也许我遗漏了什么?
Follow the code:
object TransferCashFlow { @InitiatingFlow @StartableByRPC class Initiator(val amount: Amount<Currency>, val otherParty: Party, val regulator: Party) : FlowLogic<SignedTransaction>() { @Suspendable override fun call(): SignedTransaction { val tx = subFlow(CashPaymentFlow(amount, otherParty, true)).stx subFlow(ReportFlow.Initiator(regulator, tx)) return tx } } } object ReportFlow { @InitiatingFlow class Initiator(val regulator: Party, val tx: SignedTransaction) : FlowLogic<Unit>() { @Suspendable override fun call() { val regulatorSession = initiateFlow(regulator) subFlow(IdentitySyncFlow.Send(regulatorSession, tx.tx)) subFlow(SendTransactionFlow(regulatorSession, tx)) } } @InitiatedBy(Initiator::class) class Responder(private val otherPartySession: FlowSession) : FlowLogic<Unit>() { @Suspendable override fun call() { subFlow(IdentitySyncFlow.Receive(otherPartySession)) subFlow(ReceiveTransactionFlow(otherPartySession, true, StatesToRecord.ALL_VISIBLE)) } } }
根据设计,IdentitySyncFlow.Send
将仅 发送交易中属于发送节点的机密身份的证书。见IdentitySyncFlow
中extractOurConfidentialIdentities()
的定义:
private fun extractOurConfidentialIdentities(): Map<AbstractParty, PartyAndCertificate?> {
val states: List<ContractState> = (tx.inputs.map { serviceHub.loadState(it) }.requireNoNulls().map { it.data } + tx.outputs.map { it.data })
val identities: Set<AbstractParty> = states.flatMap(ContractState::participants).toSet()
// Filter participants down to the set of those not in the network map (are not well known)
val confidentialIdentities = identities
.filter { serviceHub.networkMapCache.getNodesByLegalIdentityKey(it.owningKey).isEmpty() }
.toList()
return confidentialIdentities
.map { Pair(it, serviceHub.identityService.certificateFromKey(it.owningKey)) }
// Filter down to confidential identities of our well known identity
// TODO: Consider if this too restrictive - we perhaps should be checking the name on the signing certificate in the certificate path instead
.filter { it.second?.name == ourIdentity.name }
.toMap()
}
倒数第二行确保节点不会发送任何不属于它自己的身份证书。这是为了防止节点欺骗交易对手向其发送一堆机密身份。
如果您想发送 所有 机密身份,您必须根据 IdentitySyncFlow
定义自己的流程,该流程不执行此过滤.