Skip to content

Commit 60c7e59

Browse files
Merge pull request #13 from onix-labs/feature-v3
feature-v3
2 parents f545494 + 5eb92d6 commit 60c7e59

File tree

28 files changed

+209
-27
lines changed

28 files changed

+209
-27
lines changed

.idea/runConfigurations/Release__Local_.xml

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Release__Public_.xml

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Run_Contract_Tests.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Run_Workflow_Tests.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ buildscript {
4040
}
4141
}
4242

43-
group 'io.onixlabs'
44-
version '2.1.2'
43+
group getProperty('group')
44+
version getProperty('version')
4545

4646
subprojects {
4747
repositories {
@@ -73,6 +73,11 @@ subprojects {
7373
}
7474
}
7575

76+
task sourceJar(type: Jar) {
77+
from sourceSets.main.allSource
78+
archiveClassifier = "sources"
79+
}
80+
7681
jar {
7782
exclude '**/log4j2*.xml'
7883
}

docs/CHANGELOG-2.1.2.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,3 @@ In this version the property is declared using the `open` modifier, allowing der
5050

5151
---
5252

53-
###

docs/CHANGELOG-3.0.0.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
![ONIX Labs](https://raw.githubusercontent.com/onix-labs/onix-labs.github.io/master/content/logo/master_full_md.png)
2+
3+
# Change Log - Version 3.0.0
4+
5+
This document serves as the change log for the ONIXLabs Corda Core API.
6+
7+
## Release Notes
8+
9+
This release publishes source code along with the compiled dependencies, enabling developers debug into the ONIXLabs APIs and understand what's going on under the hood.
10+
11+
---
12+
13+
### sortAndReduce _Extension Function_
14+
15+
**Module:** onixlabs-corda-core-contract
16+
17+
**Package:** io.onixlabs.corda.core.contract
18+
19+
Sorts and reduces an `Iterable` of `SecureHash` into a single hash.
20+
21+
```kotlin
22+
fun Iterable<SecureHash>.sortAndReduce(): SecureHash
23+
```
24+
25+
---
26+
27+
### SignatureData *Class*
28+
29+
**Module:** onixlabs-corda-core-contract
30+
31+
**Package:** io.onixlabs.corda.core.contract
32+
33+
#### Description
34+
35+
Represents an array of unsigned bytes, and its signed equivalent.
36+
37+
```kotlin
38+
@CordaSerializable
39+
data class SignatureData(
40+
val content: ByteArray,
41+
val signature: DigitalSignature
42+
)
43+
```
44+
45+
> 🔵 **INFORMATION**
46+
>
47+
> This API exists in version 1.2.0 however in version 3.0.0 the `verify` function no longer returns `Boolean`. Instead, the `isValid` function replaces the `verify` function, and the `verify` function now returns `Unit`, or throws a `SignatureException` if the digital signature could not be verified by the specified public key.
48+
49+
---
50+
51+
###

gradle.properties

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
name=onixlabs-corda-core
22
group=io.onixlabs
3-
version=2.1.2
4-
5-
kotlin.incremental=false
6-
kotlin.code.style=official
7-
3+
version=3.0.0
84
onixlabs.development.jarsign.keystore=../lib/onixlabs.development.pkcs12
9-
onixlabs.development.jarsign.password=5891f47942424d2acbe108691fdb5ba258712fca7e4762be4327241ebf3dbfa3
5+
onixlabs.development.jarsign.password=5891f47942424d2acbe108691fdb5ba258712fca7e4762be4327241ebf3dbfa3

onixlabs-corda-core-contract/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ publishing {
4949
groupId = project.parent.group
5050
version = project.parent.version
5151
artifactId = 'onixlabs-corda-core-contract'
52+
artifact sourceJar
5253
from components.java
5354
}
5455
}

onixlabs-corda-core-contract/src/main/kotlin/io/onixlabs/corda/core/contract/Extensions.AbstractParty.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ val Iterable<AbstractParty>.owningKeys: Set<PublicKey>
3434
* @return Returns a [SecureHash] representing the participants of the initial [Iterable].
3535
*/
3636
val Iterable<AbstractParty>.participantHash: SecureHash
37-
get() = SecureHash.sha256(map { SecureHash.sha256(it.toString()) }.toSortedSet().joinToString())
37+
get() = map { SecureHash.sha256(it.toString()) }.sortAndReduce()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.core.contract
18+
19+
import net.corda.core.crypto.SecureHash
20+
21+
/**
22+
* Sorts and reduces an [Iterable] of [SecureHash] into a single hash.
23+
*
24+
* @return Returns a single hash representing the sorted and reduced input hashes.
25+
*/
26+
fun Iterable<SecureHash>.sortAndReduce(): SecureHash {
27+
return sorted().reduce { lhs, rhs -> lhs.concatenate(rhs) }
28+
}

onixlabs-corda-core-contract/src/main/kotlin/io/onixlabs/corda/core/contract/SignatureData.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import net.corda.core.crypto.sign
2222
import net.corda.core.node.ServiceHub
2323
import net.corda.core.node.services.KeyManagementService
2424
import net.corda.core.serialization.CordaSerializable
25+
import net.corda.core.utilities.toBase58String
2526
import net.corda.core.utilities.toBase64
2627
import java.security.PrivateKey
2728
import java.security.PublicKey
@@ -81,14 +82,26 @@ data class SignatureData(val content: ByteArray, val signature: DigitalSignature
8182
}
8283
}
8384

85+
/**
86+
* Determines whether the signature data was signed by the specified key.
87+
*
88+
* @param publicKey The public key to verify against the signature.
89+
* @return Returns true if the signature data was signed by the specified key; otherwise, false.
90+
*/
91+
fun isValid(publicKey: PublicKey): Boolean {
92+
return Crypto.isValid(publicKey, signature.bytes, content)
93+
}
94+
8495
/**
8596
* Verifies the signature data using the specified public key.
8697
*
8798
* @param publicKey The public key to verify against the signature.
8899
* @return Returns true if the public key was used to sign the data; otherwise, false.
89100
*/
90-
fun verify(publicKey: PublicKey): Boolean {
91-
return Crypto.isValid(publicKey, signature.bytes, content)
101+
fun verify(publicKey: PublicKey) {
102+
if (!isValid(publicKey)) {
103+
throw SignatureException("Signature was not signed by the specified key: ${publicKey.toBase58String()}")
104+
}
92105
}
93106

94107
/**

onixlabs-corda-core-integration/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ publishing {
3232
groupId = project.parent.group
3333
version = project.parent.version
3434
artifactId = 'onixlabs-corda-core-integration'
35+
artifact sourceJar
3536
from components.java
3637
}
3738
}

onixlabs-corda-core-workflow/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ publishing {
5252
groupId = project.parent.group
5353
version = project.parent.version
5454
artifactId = 'onixlabs-corda-core-workflow'
55+
artifact sourceJar
5556
from components.java
5657
}
5758
}

onixlabs-corda-core-workflow/src/main/kotlin/io/onixlabs/corda/core/services/QueryDsl.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ class QueryDsl<T : ContractState> internal constructor(
410410
criteria = criteria.and(criteriaToAdd.updateQueryCriteria())
411411
}
412412

413+
/**
414+
* Applies a sub-query to the current query criteria using logical AND.
415+
*
416+
* @param queryCriteria The sub-query criteria which will be appended to the current query criteria.
417+
*/
418+
@QueryDslContext
419+
fun and(queryCriteria: QueryCriteria) {
420+
criteria = criteria.and(queryCriteria)
421+
}
422+
413423
/**
414424
* Applies a sub-query to the current query criteria using logical AND.
415425
*
@@ -419,7 +429,17 @@ class QueryDsl<T : ContractState> internal constructor(
419429
fun and(action: QueryDsl<T>.() -> Unit) {
420430
val query = QueryDsl<T>(VaultQueryCriteria().updateQueryCriteria(), paging, sorting)
421431
action(query)
422-
criteria = criteria.and(query.criteria)
432+
and(query.criteria)
433+
}
434+
435+
/**
436+
* Applies a sub-query to the current query criteria using logical OR.
437+
*
438+
* @param queryCriteria The sub-query criteria which will be appended to the current query criteria.
439+
*/
440+
@QueryDslContext
441+
fun or(queryCriteria: QueryCriteria) {
442+
criteria = criteria.or(queryCriteria)
423443
}
424444

425445
/**
@@ -431,7 +451,7 @@ class QueryDsl<T : ContractState> internal constructor(
431451
fun or(action: QueryDsl<T>.() -> Unit) {
432452
val query = QueryDsl<T>(VaultQueryCriteria().updateQueryCriteria(), paging, sorting)
433453
action(query)
434-
criteria = criteria.or(query.criteria)
454+
or(query.criteria)
435455
}
436456

437457
/**

onixlabs-corda-core-workflow/src/main/kotlin/io/onixlabs/corda/core/workflow/Extensions.FlowLogic.Notaries.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fun FlowLogic<*>.getPreferredNotary(
5353
defaultSelector: (ServiceHub) -> Party = { firstNotary }
5454
): Party {
5555
val cordappContext: CordappContext = serviceHub.getAppContext()
56-
logger.info("Using the specified cordapp for notary selection: ${cordappContext.cordapp.name}")
56+
logger.info("Using the specified CorDapp for notary selection: ${cordappContext.cordapp.name}")
5757
return if (serviceHub.getAppContext().config.exists("notary")) {
5858
val name = CordaX500Name.parse(serviceHub.getAppContext().config.getString("notary"))
5959
serviceHub.networkMapCache.getNotary(name) ?: throw IllegalArgumentException(

onixlabs-corda-test-contract/src/main/kotlin/io/onixlabs/corda/test/contract/RewardContract.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RewardContract : Contract {
7070

7171
CONTRACT_RULE_OWNER using (rewardOutput.owner == customerReference.owner)
7272
CONTRACT_RULE_SIGNATURE_DATA using (rewardOutput.hash().bytes.contentEquals(signature.content))
73-
CONTRACT_RULE_SIGNATURE_SIGNER using (signature.verify(rewardOutput.issuer.owningKey))
73+
CONTRACT_RULE_SIGNATURE_SIGNER using (signature.isValid(rewardOutput.issuer.owningKey))
7474
CONTRACT_RULE_SIGNERS using (rewardOutput.participants.owningKeys.all { it in signers })
7575
}
7676
}
@@ -114,7 +114,7 @@ class RewardContract : Contract {
114114

115115
CONTRACT_RULE_OWNER using (rewardInput.owner == customerReference.owner)
116116
CONTRACT_RULE_SIGNATURE_DATA using (rewardInput.hash().bytes.contentEquals(signature.content))
117-
CONTRACT_RULE_SIGNATURE_SIGNER using (signature.verify(rewardInput.owner.owningKey))
117+
CONTRACT_RULE_SIGNATURE_SIGNER using (signature.isValid(rewardInput.owner.owningKey))
118118
CONTRACT_RULE_SIGNERS using (rewardInput.participants.owningKeys.all { it in signers })
119119
}
120120
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.onixlabs.corda.test.contract
17+
package io.onixlabs.corda.test
1818

19+
import io.onixlabs.corda.test.contract.Customer
20+
import io.onixlabs.corda.test.contract.CustomerContract
21+
import io.onixlabs.corda.test.contract.RewardContract
1922
import net.corda.core.contracts.StateAndRef
2023
import net.corda.core.contracts.StateRef
2124
import net.corda.core.crypto.SecureHash

onixlabs-corda-test-contract/src/test/kotlin/io/onixlabs/corda/test/contract/MockData.kt renamed to onixlabs-corda-test-contract/src/test/kotlin/io/onixlabs/corda/test/MockData.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.onixlabs.corda.test.contract
17+
package io.onixlabs.corda.test
1818

19+
import io.onixlabs.corda.test.contract.Customer
20+
import io.onixlabs.corda.test.contract.Reward
1921
import net.corda.core.contracts.StateRef
2022
import net.corda.core.crypto.SecureHash
2123
import net.corda.core.identity.CordaX500Name

onixlabs-corda-test-contract/src/test/kotlin/io/onixlabs/corda/test/contract/CustomerContractAmendCommandTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.onixlabs.corda.test.contract
1818

19+
import io.onixlabs.corda.test.*
1920
import net.corda.testing.node.ledger
2021
import org.junit.jupiter.api.Test
2122

onixlabs-corda-test-contract/src/test/kotlin/io/onixlabs/corda/test/contract/CustomerContractIssueCommandTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.onixlabs.corda.test.contract
1818

19+
import io.onixlabs.corda.test.*
1920
import net.corda.testing.node.ledger
2021
import org.junit.jupiter.api.Test
2122

onixlabs-corda-test-contract/src/test/kotlin/io/onixlabs/corda/test/contract/CustomerContractRevokeCommandTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.onixlabs.corda.test.contract
1818

19+
import io.onixlabs.corda.test.*
1920
import net.corda.testing.node.ledger
2021
import org.junit.jupiter.api.Test
2122

onixlabs-corda-test-contract/src/test/kotlin/io/onixlabs/corda/test/contract/RewardContractIssueCommandTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.onixlabs.corda.test.contract
1818

1919
import io.onixlabs.corda.core.contract.SignatureData
20+
import io.onixlabs.corda.test.*
2021
import net.corda.core.contracts.hash
2122
import net.corda.testing.node.ledger
2223
import org.junit.jupiter.api.Test

onixlabs-corda-test-contract/src/test/kotlin/io/onixlabs/corda/test/contract/RewardContractSpendCommandTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.onixlabs.corda.test.contract
1818

1919
import io.onixlabs.corda.core.contract.SignatureData
20+
import io.onixlabs.corda.test.*
2021
import net.corda.core.contracts.hash
2122
import net.corda.testing.node.ledger
2223
import org.junit.jupiter.api.Test

0 commit comments

Comments
 (0)