Skip to content

Commit 9da47cc

Browse files
Added a computeHash function for claims and updated CordaClaim to use this. Moved QueryDsl extensions into separate classes for each extension type.
1 parent 1c65a76 commit 9da47cc

File tree

6 files changed

+202
-111
lines changed

6 files changed

+202
-111
lines changed

onixlabs-corda-identity-framework-contract/src/main/kotlin/io/onixlabs/corda/identityframework/contract/accounts/AccountSchema.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import net.corda.core.crypto.SecureHash
2222
import net.corda.core.identity.AbstractParty
2323
import net.corda.core.schemas.MappedSchema
2424
import net.corda.core.schemas.PersistentState
25+
import net.corda.core.schemas.StatePersistable
2526
import java.util.*
2627
import javax.persistence.*
2728

@@ -117,5 +118,5 @@ object AccountSchema {
117118
JoinColumn(name = "output_index", referencedColumnName = "output_index")
118119
)
119120
val account: AccountEntity = AccountEntity()
120-
)
121+
) : StatePersistable
121122
}

onixlabs-corda-identity-framework-contract/src/main/kotlin/io/onixlabs/corda/identityframework/contract/claims/AbstractClaim.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.onixlabs.corda.identityframework.contract.claims
1818

1919
import io.onixlabs.corda.identityframework.contract.toDataClassString
20+
import net.corda.core.crypto.SecureHash
2021
import net.corda.core.serialization.CordaSerializable
2122
import java.util.*
2223

@@ -32,6 +33,15 @@ abstract class AbstractClaim<T : Any> {
3233
abstract val property: String
3334
abstract val value: T
3435

36+
/**
37+
* Computes the unique hash of this claim.
38+
*
39+
* @return Return's the unique hash of this claim.
40+
*/
41+
fun computeHash(): SecureHash {
42+
return SecureHash.sha256("$javaClass$property$value${value.javaClass}")
43+
}
44+
3545
/**
3646
* Determines whether the specified object is equal to the current object.
3747
*

onixlabs-corda-identity-framework-contract/src/main/kotlin/io/onixlabs/corda/identityframework/contract/claims/CordaClaim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ open class CordaClaim<T : Any>(
7575
get() = issuer == holder
7676

7777
final override val hash: SecureHash
78-
get() = SecureHash.sha256("$issuer$holder$property$value${value.javaClass}$previousStateRef")
78+
get() = computeHash().concatenate(SecureHash.sha256("$issuer$holder$previousStateRef"))
7979

8080
override val participants: List<AbstractParty>
8181
get() = setOf(issuer, holder).toList()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2020-2021 ONIXLabs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.onixlabs.corda.identityframework.workflow
18+
19+
import io.onixlabs.corda.core.services.QueryDsl
20+
import io.onixlabs.corda.core.services.QueryDslContext
21+
import io.onixlabs.corda.core.services.equalTo
22+
import io.onixlabs.corda.identityframework.contract.accounts.Account
23+
import io.onixlabs.corda.identityframework.contract.accounts.AccountSchema.AccountClaim
24+
import io.onixlabs.corda.identityframework.contract.accounts.AccountSchema.AccountEntity
25+
import io.onixlabs.corda.identityframework.contract.claims.AbstractClaim
26+
import net.corda.core.identity.AbstractParty
27+
28+
/**
29+
* Adds a vault query expression to filter by account owner equal to the specified value.
30+
*
31+
* @param value The value to filter by in the vault query expression.
32+
*/
33+
@QueryDslContext
34+
fun QueryDsl<out Account>.accountOwner(value: AbstractParty) {
35+
expression(AccountEntity::owner equalTo value)
36+
}
37+
38+
/**
39+
* Adds a vault query expression to filter by account claim equal to the specified value.
40+
*
41+
* @param value The value to filter by in the vault query expression.
42+
*/
43+
@QueryDslContext
44+
fun QueryDsl<out Account>.accountClaim(value: AbstractClaim<*>) {
45+
expression(AccountClaim::hash equalTo value.computeHash().toString())
46+
}
47+
48+
/**
49+
* Adds a vault query expression to filter by account claim equal property to the specified value.
50+
*
51+
* @param value The value to filter by in the vault query expression.
52+
*/
53+
@QueryDslContext
54+
fun QueryDsl<out Account>.accountClaimProperty(value: String) {
55+
expression(AccountClaim::property equalTo value)
56+
}
57+
58+
/**
59+
* Adds a vault query expression to filter by account claim equal value to the specified value.
60+
*
61+
* @param value The value to filter by in the vault query expression.
62+
*/
63+
@QueryDslContext
64+
fun QueryDsl<out Account>.accountClaimValue(value: Any) {
65+
expression(AccountClaim::value equalTo value.toString())
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright 2020-2021 ONIXLabs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.onixlabs.corda.identityframework.workflow
18+
19+
import io.onixlabs.corda.core.services.QueryDsl
20+
import io.onixlabs.corda.core.services.QueryDslContext
21+
import io.onixlabs.corda.core.services.equalTo
22+
import io.onixlabs.corda.core.services.isNull
23+
import io.onixlabs.corda.identityframework.contract.attestations.Attestation
24+
import io.onixlabs.corda.identityframework.contract.attestations.AttestationSchema.AttestationEntity
25+
import io.onixlabs.corda.identityframework.contract.attestations.AttestationStatus
26+
import io.onixlabs.corda.identityframework.contract.attestations.AttestationTypeInfo
27+
import net.corda.core.contracts.ContractState
28+
import net.corda.core.contracts.StateRef
29+
import net.corda.core.crypto.SecureHash
30+
import net.corda.core.identity.AbstractParty
31+
32+
/**
33+
* Adds a vault query expression to filter by attestation attestor equal to the specified value.
34+
*
35+
* @param value The value to filter by in the vault query expression.
36+
*/
37+
@QueryDslContext
38+
fun <T : Attestation<*>> QueryDsl<in T>.attestationAttestor(value: AbstractParty) {
39+
expression(AttestationEntity::attestor equalTo value)
40+
}
41+
42+
/**
43+
* Adds a vault query expression to filter by attestation pointer equal to the specified value.
44+
*
45+
* @param value The value to filter by in the vault query expression.
46+
*/
47+
@QueryDslContext
48+
fun <T : Attestation<*>> QueryDsl<in T>.attestationPointer(value: Any) {
49+
expression(AttestationEntity::pointer equalTo value.toString())
50+
}
51+
52+
/**
53+
* Adds a vault query expression to filter by attestation pointer type equal to the specified value.
54+
*
55+
* @param value The value to filter by in the vault query expression.
56+
*/
57+
@QueryDslContext
58+
fun <T : Attestation<*>> QueryDsl<in T>.attestationPointerType(value: Class<out ContractState>) {
59+
expression(AttestationEntity::pointerStateType equalTo value.canonicalName)
60+
}
61+
62+
/**
63+
* Adds a vault query expression to filter by attestation pointer hash equal to the specified value.
64+
*
65+
* @param value The value to filter by in the vault query expression.
66+
*/
67+
@QueryDslContext
68+
fun <T : Attestation<*>> QueryDsl<in T>.attestationPointerHash(value: SecureHash) {
69+
expression(AttestationEntity::pointerHash equalTo value.toString())
70+
}
71+
72+
/**
73+
* Adds a vault query expression to filter by attestation status equal to the specified value.
74+
*
75+
* @param value The value to filter by in the vault query expression.
76+
*/
77+
@QueryDslContext
78+
fun <T : Attestation<*>> QueryDsl<in T>.attestationStatus(value: AttestationStatus) {
79+
expression(AttestationEntity::status equalTo value)
80+
}
81+
82+
/**
83+
* Adds a vault query expression to filter by attestation previous state reference equal to the specified value.
84+
*
85+
* @param value The value to filter by in the vault query expression.
86+
*/
87+
@QueryDslContext
88+
fun <T : Attestation<*>> QueryDsl<in T>.attestationPreviousStateRef(value: StateRef?) {
89+
if (value == null) expression(AttestationEntity::previousStateRef.isNull())
90+
else expression(AttestationEntity::previousStateRef equalTo value.toString())
91+
}
92+
93+
/**
94+
* Adds a vault query expression to filter by attestation hash equal to the specified value.
95+
*
96+
* @param value The value to filter by in the vault query expression.
97+
*/
98+
@QueryDslContext
99+
fun <T : Attestation<*>> QueryDsl<in T>.attestationHash(value: SecureHash) {
100+
expression(AttestationEntity::hash equalTo value.toString())
101+
}
102+
103+
/**
104+
* Adds a vault query expression to filter by attestation type equal to the specified value.
105+
*
106+
* @param value The value to filter by in the vault query expression.
107+
*/
108+
@QueryDslContext
109+
fun <T : Attestation<*>> QueryDsl<in T>.attestationType(value: Class<in T>) {
110+
expression(AttestationEntity::attestationType equalTo value.canonicalName)
111+
}
112+
113+
/**
114+
* Adds a vault query expression to filter by attestation type equal to the specified value.
115+
* This will also filter by the attestation pointer type unless it's specified as a wildcard.
116+
*/
117+
@QueryDslContext
118+
inline fun <reified T : Attestation<*>> QueryDsl<in T>.attestationType() {
119+
with(object : AttestationTypeInfo<T>() {}) {
120+
attestationType(attestationType)
121+
attestationStateType?.let { expression(AttestationEntity::pointerStateType equalTo it.canonicalName) }
122+
}
123+
}
Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@ import io.onixlabs.corda.core.services.QueryDslContext
55
import io.onixlabs.corda.core.services.equalTo
66
import io.onixlabs.corda.core.services.isNull
77
import io.onixlabs.corda.identityframework.contract.accounts.Account
8-
import io.onixlabs.corda.identityframework.contract.accounts.AccountSchema.AccountEntity
9-
import io.onixlabs.corda.identityframework.contract.attestations.Attestation
10-
import io.onixlabs.corda.identityframework.contract.attestations.AttestationSchema.AttestationEntity
11-
import io.onixlabs.corda.identityframework.contract.attestations.AttestationStatus
12-
import io.onixlabs.corda.identityframework.contract.attestations.AttestationTypeInfo
138
import io.onixlabs.corda.identityframework.contract.claims.ClaimTypeInfo
149
import io.onixlabs.corda.identityframework.contract.claims.CordaClaim
1510
import io.onixlabs.corda.identityframework.contract.claims.CordaClaimSchema.CordaClaimEntity
16-
import net.corda.core.contracts.ContractState
1711
import net.corda.core.contracts.StateRef
1812
import net.corda.core.contracts.UniqueIdentifier
1913
import net.corda.core.crypto.SecureHash
@@ -173,106 +167,3 @@ inline fun <reified T : CordaClaim<*>> QueryDsl<in T>.claimType() {
173167
claimValueType?.let { expression(CordaClaimEntity::valueType equalTo it.canonicalName) }
174168
}
175169
}
176-
177-
/**
178-
* Adds a vault query expression to filter by attestation attestor equal to the specified value.
179-
*
180-
* @param value The value to filter by in the vault query expression.
181-
*/
182-
@QueryDslContext
183-
fun <T : Attestation<*>> QueryDsl<in T>.attestationAttestor(value: AbstractParty) {
184-
expression(AttestationEntity::attestor equalTo value)
185-
}
186-
187-
/**
188-
* Adds a vault query expression to filter by attestation pointer equal to the specified value.
189-
*
190-
* @param value The value to filter by in the vault query expression.
191-
*/
192-
@QueryDslContext
193-
fun <T : Attestation<*>> QueryDsl<in T>.attestationPointer(value: Any) {
194-
expression(AttestationEntity::pointer equalTo value.toString())
195-
}
196-
197-
/**
198-
* Adds a vault query expression to filter by attestation pointer type equal to the specified value.
199-
*
200-
* @param value The value to filter by in the vault query expression.
201-
*/
202-
@QueryDslContext
203-
fun <T : Attestation<*>> QueryDsl<in T>.attestationPointerType(value: Class<out ContractState>) {
204-
expression(AttestationEntity::pointerStateType equalTo value.canonicalName)
205-
}
206-
207-
/**
208-
* Adds a vault query expression to filter by attestation pointer hash equal to the specified value.
209-
*
210-
* @param value The value to filter by in the vault query expression.
211-
*/
212-
@QueryDslContext
213-
fun <T : Attestation<*>> QueryDsl<in T>.attestationPointerHash(value: SecureHash) {
214-
expression(AttestationEntity::pointerHash equalTo value.toString())
215-
}
216-
217-
/**
218-
* Adds a vault query expression to filter by attestation status equal to the specified value.
219-
*
220-
* @param value The value to filter by in the vault query expression.
221-
*/
222-
@QueryDslContext
223-
fun <T : Attestation<*>> QueryDsl<in T>.attestationStatus(value: AttestationStatus) {
224-
expression(AttestationEntity::status equalTo value)
225-
}
226-
227-
/**
228-
* Adds a vault query expression to filter by attestation previous state reference equal to the specified value.
229-
*
230-
* @param value The value to filter by in the vault query expression.
231-
*/
232-
@QueryDslContext
233-
fun <T : Attestation<*>> QueryDsl<in T>.attestationPreviousStateRef(value: StateRef?) {
234-
if (value == null) expression(AttestationEntity::previousStateRef.isNull())
235-
else expression(AttestationEntity::previousStateRef equalTo value.toString())
236-
}
237-
238-
/**
239-
* Adds a vault query expression to filter by attestation hash equal to the specified value.
240-
*
241-
* @param value The value to filter by in the vault query expression.
242-
*/
243-
@QueryDslContext
244-
fun <T : Attestation<*>> QueryDsl<in T>.attestationHash(value: SecureHash) {
245-
expression(AttestationEntity::hash equalTo value.toString())
246-
}
247-
248-
/**
249-
* Adds a vault query expression to filter by attestation type equal to the specified value.
250-
*
251-
* @param value The value to filter by in the vault query expression.
252-
*/
253-
@QueryDslContext
254-
fun <T : Attestation<*>> QueryDsl<in T>.attestationType(value: Class<in T>) {
255-
expression(AttestationEntity::attestationType equalTo value.canonicalName)
256-
}
257-
258-
/**
259-
* Adds a vault query expression to filter by attestation type equal to the specified value.
260-
* This will also filter by the attestation pointer type unless it's specified as a wildcard.
261-
*/
262-
@QueryDslContext
263-
inline fun <reified T : Attestation<*>> QueryDsl<in T>.attestationType() {
264-
with(object : AttestationTypeInfo<T>() {}) {
265-
attestationType(attestationType)
266-
attestationStateType?.let { expression(AttestationEntity::pointerStateType equalTo it.canonicalName) }
267-
}
268-
}
269-
270-
/**
271-
* Adds a vault query expression to filter by account owner equal to the specified value.
272-
*
273-
* @param value The value to filter by in the vault query expression.
274-
*/
275-
@QueryDslContext
276-
fun QueryDsl<out Account>.accountOwner(value: AbstractParty) {
277-
expression(AccountEntity::owner equalTo value)
278-
}

0 commit comments

Comments
 (0)