Skip to content

Commit 7899ab3

Browse files
authored
Feature/immutable-crypto-conditions (#68)
* Fix Build Tests * Remove gradle in favor of maven. * Update pom for Nexus staging and deploy. * Fix test coverage and artifact generation. * Fix Checkstyle checks. * Remove HexDump.java * Update README * Add new Tests and Test Vectors * Fixes test vectors to accomadate (rfcs/crypto-conditions#4) * Adds improved test coverage for RFC test vectors. * Fix URI ordering for test vector * Update guava * Improve ignored threshold test. * Made all Conditions Immutable. * Made all Fulfillments Immutable. * Extracted encoding and URI generation to classes external to main Condition and Fulfillment classes. * Misc formatting improvements. * Add and cleanuip Javadoc * Update all fulfillments to be immutable * Limit Guava to test scope only… * Enable paremeterized RSA signature tests * Introduce Base Fulfillment * Fix equals, hashcode, and toString for all fulfillments. * Remove TODOs * Fix Checkstyle Errors * Reduce the number of default threads for test purposes
1 parent c07ba6d commit 7899ab3

File tree

97 files changed

+4198
-3105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4198
-3105
lines changed

.gitmodules

-3
This file was deleted.

README.md

+20-28
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
Java implementation of Crypto-Conditions (See [RFC](https://datatracker.ietf.org/doc/draft-thomas-crypto-conditions/)).
1212

13-
v2.0 implements the latest RFC (draft-02)
13+
* v0.0.2-SNAPSHOT implements the latest RFC [draft-02](https://tools.ietf.org/html/draft-thomas-crypto-conditions-02).
14+
* v0.0.3-SNAPSHOT implements the latest RFC [draft-03](https://tools.ietf.org/html/draft-thomas-crypto-conditions-03).
1415

1516
## Dependencies
1617

@@ -24,51 +25,47 @@ For ED25519 the library depends on [net.i2p.crypto.eddsa](https://github.com/str
2425
## Usage
2526

2627
### Requirements
27-
This project uses Gradle to manage dependencies and other aspects of the build.
28-
To install Gradle, follow the instructions at [https://gradle.org](https://gradle.org/).
28+
This project uses Maven to manage dependencies and other aspects of the build.
29+
To install Maven, follow the instructions at [https://maven.apache.org/install.html](https://maven.apache.org/install.html).
30+
2931

3032
### Get the code
3133

3234
``` sh
3335
git clone https://github.com/interledger/java-crypto-conditions
34-
3536
cd java-crypto-conditions
3637
```
3738

3839
### Build the Project
3940
To build the project, execute the following command:
4041

4142
```bash
42-
$ gradle build test
43+
$ mvn clean install
4344
```
4445

4546
#### Checkstyle
46-
The project uses checkstyle to keep code style consistent. To run the style checks:
47+
The project uses checkstyle to keep code style consistent. All Checkstyle checks are run by default during the build, but if you would like to run checkstyle checks, use the following command:
4748

48-
```bash
49-
$ gradle build check
50-
```
5149

52-
#### Maven is also supported:
53-
```
54-
mvn clean install [checkstyle:check]
50+
```bash
51+
$ mvn checkstyle:checkstyle
5552
```
5653

5754
### Step 3: Use
5855

5956
#### PREIMAGE-SHA-256 Example:
60-
~~~java
57+
```java
6158
byte[] preimage = "Hello World!".getBytes(Charset.defaultCharset());
6259
PreimageSha256Condition condition = new PreimageSha256Condition(preimage);
6360

6461
PreimageSha256Fulfillment fulfillment = new PreimageSha256Fulfillment(preimage);
6562
if(fulfillment.validate(condition)) {
6663
System.out.println("Fulfillment is valid!");
6764
}
68-
~~~
65+
```
6966

7067
#### THRESHOLD-SHA-256, ED25519-SHA-256 and RSA-SHA-256 Example:
71-
~~~java
68+
```java
7269
//Generate RSA-SHA-256 condition
7370
KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
7471
rsaKpg.initialize(new RSAKeyGenParameterSpec(2048, new BigInteger("65537")));
@@ -81,17 +78,16 @@ net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPai
8178
KeyPair edDsaKeyPair = edDsaKpg.generateKeyPair();
8279
Signature edDsaSigner = new EdDSAEngine(sha512Digest);
8380

84-
8581
PreimageSha256Fulfillment fulfillment = new PreimageSha256Fulfillment(preimage);
8682
//Verify against empty message
8783
if(fulfillment.verify(condition, new byte[0])) {
8884
System.out.println("Fulfillment is valid!");
8985
}
90-
~~~
86+
```
9187

9288

9389
#### Encoding Example:
94-
~~~java
90+
```java
9591
//Read a condition from a stream (InputStream in)
9692
DERInputStream derStream = new DERInputStream(in);
9793
Condition condition = CryptoConditionReader.readCondition(derStream);
@@ -107,15 +103,14 @@ Condition condition = CryptoConditionReader.readCondition(buffer);
107103
Fulfillment fulfillment = CryptoConditionReader.readFulfillment(buffer);
108104

109105
//Get binary encoding of condition that can be written to stream
110-
byte[] binaryEncodedCondition = condition.getEncoded();
106+
byte[] binaryEncodedCondition = CryptoConditionWriter.writeCondition(condition);
111107

112108
//Get binary encoding of fulfillment that can be written to stream
113-
byte[] binaryEncodedCondition = fulfillment.getEncoded();
109+
byte[] binaryEncodedCondition = CryptoConditionWriter.writeFulfillment(fulfillment);
114110

115111
//Get ni: URI form for sharing via text-based protocols
116-
URI uriEncodedCondition = condition.getUri();
117-
118-
~~~
112+
URI uriEncodedCondition = CryptoConditionUri.toUri(condition);
113+
```
119114

120115
## Contributors
121116

@@ -125,11 +120,8 @@ Any contribution is very much appreciated!
125120

126121
## TODO
127122

128-
- More Unit tests
129-
- Finish implementing test runner for shared integration tests from [https://github.com/rfcs/crypto-conditions](https://github.com/rfcs/crypto-conditions).
130-
- Helper functions for generating fulfillments
131-
- From private keys and messages
132-
- Using a builder
123+
- More Unit tests (see #62)
124+
- Replace current ASN.1 DER Input/Outputstream code with Codec framework (see java-ilp-core).
133125
- Validate condition against a global max cost
134126

135127
## License

build.gradle

-251
This file was deleted.

0 commit comments

Comments
 (0)