Skip to content

Commit 8de73ac

Browse files
Kristjan KosicKovacZan
andauthored
release: 1.2.1 (#123)
* refactor: make abstract instance method public (#120) * test: increase test coverage (#122) * test: test type specific hashMaps * style: apply spotless * refactor: made dynamic byteBuffer allocation * test: MultiSignatureBuilder Test * style: spotless on tests * chore: update build.gradle (version bump and removed deprecated properties) * chore: added maven settings * chore: use github secrets * chore: mvn actions adjusting to Github Automation * chore: call corret gh action * chore: version bump * chore: fix maven repo stuff Co-authored-by: KovacZan <[email protected]>
1 parent 9751b30 commit 8de73ac

15 files changed

+245
-69
lines changed

.github/workflows/publish-release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ jobs:
2525
USERNAME: ${{ github.actor }}
2626
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
2727

28+
- name: Publish to Maven OSS Repos
29+
run: gradle publishMavenJavaPublicationToMavenRepoRepository
30+
env:
31+
MVN_USERNAME: ${{ secrets.MAVEN_USER }}
32+
MVN_PASSWORD: ${{ secrets.MAVEN_PASS }}

build.gradle

Lines changed: 72 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,93 @@ repositories {
1111
}
1212

1313
group = 'org.arkecosystem'
14-
version = '1.1.2'
14+
version = '1.2.1'
15+
16+
dependencies {
17+
compile group: 'org.bitcoinj', name: 'bitcoinj-core', version: '0.15.8'
18+
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
19+
compile 'com.google.guava:guava:28.2-jre'
20+
21+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
22+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
23+
}
1524

1625
publishing {
17-
publishing {
18-
repositories {
19-
maven {
20-
name = "github"
21-
url = uri("https://maven.pkg.github.com/arkecosystem/java-crypto")
22-
credentials {
23-
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
24-
password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD")
25-
}
26+
repositories {
27+
jcenter()
28+
mavenCentral() {
29+
name = "MavenRepo"
30+
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
31+
credentials {
32+
username = System.getenv("MVN_USERNAME")
33+
password = System.getenv("MVN_PASSWORD")
2634
}
2735
}
36+
37+
maven {
38+
name = "github"
39+
url = uri("https://maven.pkg.github.com/arkecosystem/java-crypto")
40+
credentials {
41+
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
42+
password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD")
43+
}
44+
}
45+
2846
publications {
2947
gpr(MavenPublication) {
3048
from(components.java)
3149
}
50+
mavenJava(MavenPublication) {
51+
artifactId = 'java-crypto'
52+
from(components.java)
53+
pom {
54+
name = 'java-crypto'
55+
versionMapping {
56+
usage('java-api') {
57+
fromResolutionOf('runtimeClasspath')
58+
}
59+
usage('java-runtime') {
60+
fromResolutionResult()
61+
}
62+
}
63+
description = 'A Lightweight ARK Core JAVA Crypto SDK Library'
64+
url = 'https://sdk.ark.dev/java/crypto'
65+
licenses {
66+
license {
67+
name = 'MIT License'
68+
url = 'https://github.com/ArkEcosystem/java-crypto/blob/master/LICENSE'
69+
}
70+
}
71+
developers {
72+
developer {
73+
id = 'kovaczan'
74+
name = 'Žan Kovač'
75+
76+
}
77+
developer {
78+
id = 'kristjank'
79+
name = 'Kristjan Košič'
80+
81+
}
82+
}
83+
scm {
84+
connection = 'scm:git:git://github.com/arkecosystem/java-crypto.git'
85+
developerConnection = 'scm:git:ssh://github.com/arkecosystem/java-crypto.git'
86+
url = 'https://sdk.ark.dev/java/crypto'
87+
}
88+
}
89+
}
3290
}
3391
}
92+
}
3493

35-
javadoc {
36-
if (JavaVersion.current().isJava9Compatible()) {
37-
options.addBooleanOption('html5', true)
38-
}
94+
javadoc {
95+
if (JavaVersion.current().isJava9Compatible()) {
96+
options.addBooleanOption('html5', true)
3997
}
4098
}
4199

42100

43-
dependencies {
44-
compile group: 'org.bitcoinj', name: 'bitcoinj-core', version: '0.15.8'
45-
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
46-
compile 'com.google.guava:guava:28.2-jre'
47-
48-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
49-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
50-
}
51-
52101
test {
53102
useJUnitPlatform()
54103
failFast = true
@@ -83,7 +132,6 @@ task formatCode(dependsOn: ['spotlessApply'])
83132

84133
task fatJar(type: Jar) {
85134
manifest.from jar.manifest
86-
classifier = 'standalone'
87135
from {
88136
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
89137
} {
@@ -95,12 +143,10 @@ task fatJar(type: Jar) {
95143
}
96144

97145
task javadocJar(type: Jar) {
98-
classifier = 'javadoc'
99146
from javadoc
100147
}
101148

102149
task sourcesJar(type: Jar) {
103-
classifier = 'sources'
104150
from sourceSets.main.allSource
105151
}
106152

src/main/java/org/arkecosystem/crypto/transactions/Serializer.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,31 @@ public static byte[] serialize(
2424
}
2525

2626
public byte[] serialize(boolean skipSignature, boolean skipSecondSignature) {
27-
ByteBuffer buffer = ByteBuffer.allocate(512);
28-
buffer.order(ByteOrder.LITTLE_ENDIAN);
2927

30-
serializeCommon(buffer);
31-
serializeVendorField(buffer);
28+
byte[] common = serializeCommon();
29+
byte[] vendorField = serializeVendorField();
3230

3331
byte[] typeBuffer = this.transaction.serialize();
34-
buffer.put(typeBuffer);
3532

36-
serializeSignatures(buffer, skipSignature, skipSecondSignature);
33+
byte[] signatures = serializeSignatures(skipSignature, skipSecondSignature);
3734

38-
byte[] result = new byte[buffer.position()];
39-
buffer.rewind();
40-
buffer.get(result);
35+
ByteBuffer buffer =
36+
ByteBuffer.allocate(
37+
common.length + vendorField.length + typeBuffer.length + signatures.length);
38+
buffer.order(ByteOrder.LITTLE_ENDIAN);
4139

42-
return result;
40+
buffer.put(common);
41+
buffer.put(vendorField);
42+
buffer.put(typeBuffer);
43+
buffer.put(signatures);
44+
45+
return buffer.array();
4346
}
4447

45-
private void serializeCommon(ByteBuffer buffer) {
48+
private byte[] serializeCommon() {
49+
ByteBuffer buffer = ByteBuffer.allocate(58);
50+
buffer.order(ByteOrder.LITTLE_ENDIAN);
51+
4652
buffer.put((byte) 0xff);
4753
if (this.transaction.version > 0) {
4854
buffer.put((byte) this.transaction.version);
@@ -61,17 +67,24 @@ private void serializeCommon(ByteBuffer buffer) {
6167

6268
buffer.put(Hex.decode(this.transaction.senderPublicKey));
6369
buffer.putLong(this.transaction.fee);
70+
71+
return buffer.array();
6472
}
6573

66-
private void serializeVendorField(ByteBuffer buffer) {
74+
private byte[] serializeVendorField() {
75+
ByteBuffer buffer = ByteBuffer.allocate(1);
76+
buffer.order(ByteOrder.LITTLE_ENDIAN);
77+
6778
if (this.transaction.hasVendorField()) {
6879
if (this.transaction.vendorField != null && !this.transaction.vendorField.equals("")) {
6980
int vendorFieldLength = this.transaction.vendorField.length();
81+
buffer = ByteBuffer.allocate(vendorFieldLength + 1);
7082
buffer.put((byte) vendorFieldLength);
7183
buffer.put(this.transaction.vendorField.getBytes());
7284
} else if (this.transaction.vendorFieldHex != null
73-
&& !this.transaction.vendorFieldHex.equals("")) {
85+
&& !this.transaction.vendorFieldHex.isEmpty()) {
7486
int vendorFieldHexLength = this.transaction.vendorFieldHex.length();
87+
buffer = ByteBuffer.allocate(vendorFieldHexLength + 1);
7588
buffer.put((byte) (vendorFieldHexLength / 2));
7689
buffer.put(Hex.decode(this.transaction.vendorFieldHex));
7790
} else {
@@ -80,10 +93,13 @@ private void serializeVendorField(ByteBuffer buffer) {
8093
} else {
8194
buffer.put((byte) 0x00);
8295
}
96+
97+
return buffer.array();
8398
}
8499

85-
private void serializeSignatures(
86-
ByteBuffer buffer, boolean skipSignature, boolean skipSecondSignature) {
100+
private byte[] serializeSignatures(boolean skipSignature, boolean skipSecondSignature) {
101+
ByteBuffer buffer = ByteBuffer.allocate(144);
102+
buffer.order(ByteOrder.LITTLE_ENDIAN);
87103

88104
if (!skipSignature && this.transaction.signature != null) {
89105
buffer.put(Hex.decode(this.transaction.signature));
@@ -92,5 +108,10 @@ private void serializeSignatures(
92108
if (!skipSecondSignature && this.transaction.secondSignature != null) {
93109
buffer.put(Hex.decode(this.transaction.secondSignature));
94110
}
111+
byte[] result = new byte[buffer.position()];
112+
buffer.rewind();
113+
buffer.get(result);
114+
115+
return result;
95116
}
96117
}

src/main/java/org/arkecosystem/crypto/transactions/builder/AbstractTransactionBuilder.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ public TBuilder version(int version) {
2323
return this.instance();
2424
};
2525

26-
public TBuilder typeGroup(int typeGroup) {
27-
if (typeGroup > Short.MAX_VALUE) {
28-
throw new IllegalArgumentException(
29-
"Type group should not be bigger then 2 bytes (bigger then 32767)");
30-
}
31-
this.transaction.typeGroup = typeGroup;
32-
return this.instance();
33-
}
34-
3526
public TBuilder nonce(long nonce) {
3627
this.transaction.nonce = nonce;
3728
return this.instance();
@@ -73,5 +64,5 @@ public TBuilder sign(String passphrase) {
7364

7465
public abstract Transaction getTransactionInstance();
7566

76-
abstract TBuilder instance();
67+
public abstract TBuilder instance();
7768
}

src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilderTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.arkecosystem.crypto.transactions.builder;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.*;
44

5+
import java.util.HashMap;
56
import org.arkecosystem.crypto.transactions.types.Transaction;
67
import org.junit.jupiter.api.Test;
78

@@ -16,6 +17,11 @@ void build() {
1617
.sign("this is a top secret passphrase")
1718
.transaction;
1819

20+
HashMap actualHashMap = actual.toHashMap();
21+
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
22+
HashMap delegate = (HashMap) actualAsset.get("delegate");
23+
assertEquals(delegate.get("username"), "java");
24+
1925
assertTrue(actual.verify());
2026
}
2127

src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilderTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.arkecosystem.crypto.transactions.builder;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.*;
44

5+
import java.util.HashMap;
56
import org.arkecosystem.crypto.transactions.types.Transaction;
67
import org.junit.jupiter.api.Test;
78

@@ -15,6 +16,10 @@ void build() {
1516
.sign("this is a top secret passphrase")
1617
.transaction;
1718

19+
HashMap actualHashMap = actual.toHashMap();
20+
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
21+
assertNull(actualAsset);
22+
1823
assertTrue(actual.verify());
1924
}
2025

src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilderTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.arkecosystem.crypto.transactions.builder;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.*;
44

5+
import java.util.HashMap;
56
import org.arkecosystem.crypto.transactions.types.Transaction;
67
import org.junit.jupiter.api.Test;
78

@@ -17,6 +18,14 @@ void build() {
1718
.sign("this is a top secret passphrase")
1819
.transaction;
1920

21+
HashMap actualHashMap = actual.toHashMap();
22+
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
23+
HashMap claim = (HashMap) actualAsset.get("claim");
24+
assertEquals(
25+
claim.get("lockTransactionId"),
26+
"943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4");
27+
assertEquals(claim.get("unlockSecret"), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
28+
2029
assertTrue(actual.verify());
2130
}
2231

src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilderTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.arkecosystem.crypto.transactions.builder;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.*;
44

5+
import java.util.HashMap;
56
import org.arkecosystem.crypto.enums.HtlcLockExpirationType;
67
import org.arkecosystem.crypto.transactions.types.Transaction;
78
import org.junit.jupiter.api.Test;
@@ -16,10 +17,22 @@ void build() {
1617
.secretHash(
1718
"0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454")
1819
.expirationType(HtlcLockExpirationType.EPOCH_TIMESTAMP, 1)
20+
.vendorField("This is vendor field java")
1921
.nonce(3)
2022
.sign("this is a top secret passphrase")
2123
.transaction;
2224

25+
HashMap actualHashMap = actual.toHashMap();
26+
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
27+
HashMap lock = (HashMap) actualAsset.get("lock");
28+
HashMap expiration = (HashMap) lock.get("expiration");
29+
30+
assertEquals(
31+
lock.get("secretHash"),
32+
"0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454");
33+
assertEquals(expiration.get("type"), HtlcLockExpirationType.EPOCH_TIMESTAMP.getValue());
34+
assertEquals(expiration.get("value"), 1);
35+
2336
assertTrue(actual.verify());
2437
}
2538

src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilderTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.arkecosystem.crypto.transactions.builder;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertTrue;
45

6+
import java.util.HashMap;
57
import org.arkecosystem.crypto.transactions.types.Transaction;
68
import org.junit.jupiter.api.Test;
79

@@ -16,6 +18,13 @@ void build() {
1618
.sign("this is a top secret passphrase")
1719
.transaction;
1820

21+
HashMap actualHashMap = actual.toHashMap();
22+
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
23+
HashMap refund = (HashMap) actualAsset.get("refund");
24+
assertEquals(
25+
refund.get("lockTransactionId"),
26+
"943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4");
27+
1928
assertTrue(actual.verify());
2029
}
2130

0 commit comments

Comments
 (0)