Skip to content

Commit

Permalink
release: 1.2.1 (#123)
Browse files Browse the repository at this point in the history
* 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 <39158639+KovacZan@users.noreply.github.com>
  • Loading branch information
Kristjan Kosic and KovacZan authored Mar 19, 2020
1 parent 9751b30 commit 8de73ac
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ jobs:
USERNAME: ${{ github.actor }}
PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to Maven OSS Repos
run: gradle publishMavenJavaPublicationToMavenRepoRepository
env:
MVN_USERNAME: ${{ secrets.MAVEN_USER }}
MVN_PASSWORD: ${{ secrets.MAVEN_PASS }}
98 changes: 72 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,93 @@ repositories {
}

group = 'org.arkecosystem'
version = '1.1.2'
version = '1.2.1'

dependencies {
compile group: 'org.bitcoinj', name: 'bitcoinj-core', version: '0.15.8'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile 'com.google.guava:guava:28.2-jre'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
}

publishing {
publishing {
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/arkecosystem/java-crypto")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD")
}
repositories {
jcenter()
mavenCentral() {
name = "MavenRepo"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = System.getenv("MVN_USERNAME")
password = System.getenv("MVN_PASSWORD")
}
}

maven {
name = "github"
url = uri("https://maven.pkg.github.com/arkecosystem/java-crypto")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD")
}
}

publications {
gpr(MavenPublication) {
from(components.java)
}
mavenJava(MavenPublication) {
artifactId = 'java-crypto'
from(components.java)
pom {
name = 'java-crypto'
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
description = 'A Lightweight ARK Core JAVA Crypto SDK Library'
url = 'https://sdk.ark.dev/java/crypto'
licenses {
license {
name = 'MIT License'
url = 'https://github.com/ArkEcosystem/java-crypto/blob/master/LICENSE'
}
}
developers {
developer {
id = 'kovaczan'
name = 'Žan Kovač'
email = 'zan@ark.io'
}
developer {
id = 'kristjank'
name = 'Kristjan Košič'
email = 'kristjan@ark.io'
}
}
scm {
connection = 'scm:git:git://github.com/arkecosystem/java-crypto.git'
developerConnection = 'scm:git:ssh://github.com/arkecosystem/java-crypto.git'
url = 'https://sdk.ark.dev/java/crypto'
}
}
}
}
}
}

javadoc {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
javadoc {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}


dependencies {
compile group: 'org.bitcoinj', name: 'bitcoinj-core', version: '0.15.8'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile 'com.google.guava:guava:28.2-jre'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
}

test {
useJUnitPlatform()
failFast = true
Expand Down Expand Up @@ -83,7 +132,6 @@ task formatCode(dependsOn: ['spotlessApply'])

task fatJar(type: Jar) {
manifest.from jar.manifest
classifier = 'standalone'
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
Expand All @@ -95,12 +143,10 @@ task fatJar(type: Jar) {
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

Expand Down
51 changes: 36 additions & 15 deletions src/main/java/org/arkecosystem/crypto/transactions/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,31 @@ public static byte[] serialize(
}

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

serializeCommon(buffer);
serializeVendorField(buffer);
byte[] common = serializeCommon();
byte[] vendorField = serializeVendorField();

byte[] typeBuffer = this.transaction.serialize();
buffer.put(typeBuffer);

serializeSignatures(buffer, skipSignature, skipSecondSignature);
byte[] signatures = serializeSignatures(skipSignature, skipSecondSignature);

byte[] result = new byte[buffer.position()];
buffer.rewind();
buffer.get(result);
ByteBuffer buffer =
ByteBuffer.allocate(
common.length + vendorField.length + typeBuffer.length + signatures.length);
buffer.order(ByteOrder.LITTLE_ENDIAN);

return result;
buffer.put(common);
buffer.put(vendorField);
buffer.put(typeBuffer);
buffer.put(signatures);

return buffer.array();
}

private void serializeCommon(ByteBuffer buffer) {
private byte[] serializeCommon() {
ByteBuffer buffer = ByteBuffer.allocate(58);
buffer.order(ByteOrder.LITTLE_ENDIAN);

buffer.put((byte) 0xff);
if (this.transaction.version > 0) {
buffer.put((byte) this.transaction.version);
Expand All @@ -61,17 +67,24 @@ private void serializeCommon(ByteBuffer buffer) {

buffer.put(Hex.decode(this.transaction.senderPublicKey));
buffer.putLong(this.transaction.fee);

return buffer.array();
}

private void serializeVendorField(ByteBuffer buffer) {
private byte[] serializeVendorField() {
ByteBuffer buffer = ByteBuffer.allocate(1);
buffer.order(ByteOrder.LITTLE_ENDIAN);

if (this.transaction.hasVendorField()) {
if (this.transaction.vendorField != null && !this.transaction.vendorField.equals("")) {
int vendorFieldLength = this.transaction.vendorField.length();
buffer = ByteBuffer.allocate(vendorFieldLength + 1);
buffer.put((byte) vendorFieldLength);
buffer.put(this.transaction.vendorField.getBytes());
} else if (this.transaction.vendorFieldHex != null
&& !this.transaction.vendorFieldHex.equals("")) {
&& !this.transaction.vendorFieldHex.isEmpty()) {
int vendorFieldHexLength = this.transaction.vendorFieldHex.length();
buffer = ByteBuffer.allocate(vendorFieldHexLength + 1);
buffer.put((byte) (vendorFieldHexLength / 2));
buffer.put(Hex.decode(this.transaction.vendorFieldHex));
} else {
Expand All @@ -80,10 +93,13 @@ private void serializeVendorField(ByteBuffer buffer) {
} else {
buffer.put((byte) 0x00);
}

return buffer.array();
}

private void serializeSignatures(
ByteBuffer buffer, boolean skipSignature, boolean skipSecondSignature) {
private byte[] serializeSignatures(boolean skipSignature, boolean skipSecondSignature) {
ByteBuffer buffer = ByteBuffer.allocate(144);
buffer.order(ByteOrder.LITTLE_ENDIAN);

if (!skipSignature && this.transaction.signature != null) {
buffer.put(Hex.decode(this.transaction.signature));
Expand All @@ -92,5 +108,10 @@ private void serializeSignatures(
if (!skipSecondSignature && this.transaction.secondSignature != null) {
buffer.put(Hex.decode(this.transaction.secondSignature));
}
byte[] result = new byte[buffer.position()];
buffer.rewind();
buffer.get(result);

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ public TBuilder version(int version) {
return this.instance();
};

public TBuilder typeGroup(int typeGroup) {
if (typeGroup > Short.MAX_VALUE) {
throw new IllegalArgumentException(
"Type group should not be bigger then 2 bytes (bigger then 32767)");
}
this.transaction.typeGroup = typeGroup;
return this.instance();
}

public TBuilder nonce(long nonce) {
this.transaction.nonce = nonce;
return this.instance();
Expand Down Expand Up @@ -73,5 +64,5 @@ public TBuilder sign(String passphrase) {

public abstract Transaction getTransactionInstance();

abstract TBuilder instance();
public abstract TBuilder instance();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.arkecosystem.crypto.transactions.builder;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.util.HashMap;
import org.arkecosystem.crypto.transactions.types.Transaction;
import org.junit.jupiter.api.Test;

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

HashMap actualHashMap = actual.toHashMap();
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
HashMap delegate = (HashMap) actualAsset.get("delegate");
assertEquals(delegate.get("username"), "java");

assertTrue(actual.verify());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.arkecosystem.crypto.transactions.builder;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.util.HashMap;
import org.arkecosystem.crypto.transactions.types.Transaction;
import org.junit.jupiter.api.Test;

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

HashMap actualHashMap = actual.toHashMap();
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
assertNull(actualAsset);

assertTrue(actual.verify());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.arkecosystem.crypto.transactions.builder;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.util.HashMap;
import org.arkecosystem.crypto.transactions.types.Transaction;
import org.junit.jupiter.api.Test;

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

HashMap actualHashMap = actual.toHashMap();
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
HashMap claim = (HashMap) actualAsset.get("claim");
assertEquals(
claim.get("lockTransactionId"),
"943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4");
assertEquals(claim.get("unlockSecret"), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

assertTrue(actual.verify());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.arkecosystem.crypto.transactions.builder;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.util.HashMap;
import org.arkecosystem.crypto.enums.HtlcLockExpirationType;
import org.arkecosystem.crypto.transactions.types.Transaction;
import org.junit.jupiter.api.Test;
Expand All @@ -16,10 +17,22 @@ void build() {
.secretHash(
"0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454")
.expirationType(HtlcLockExpirationType.EPOCH_TIMESTAMP, 1)
.vendorField("This is vendor field java")
.nonce(3)
.sign("this is a top secret passphrase")
.transaction;

HashMap actualHashMap = actual.toHashMap();
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
HashMap lock = (HashMap) actualAsset.get("lock");
HashMap expiration = (HashMap) lock.get("expiration");

assertEquals(
lock.get("secretHash"),
"0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454");
assertEquals(expiration.get("type"), HtlcLockExpirationType.EPOCH_TIMESTAMP.getValue());
assertEquals(expiration.get("value"), 1);

assertTrue(actual.verify());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.arkecosystem.crypto.transactions.builder;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
import org.arkecosystem.crypto.transactions.types.Transaction;
import org.junit.jupiter.api.Test;

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

HashMap actualHashMap = actual.toHashMap();
HashMap actualAsset = (HashMap) actualHashMap.get("asset");
HashMap refund = (HashMap) actualAsset.get("refund");
assertEquals(
refund.get("lockTransactionId"),
"943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4");

assertTrue(actual.verify());
}

Expand Down
Loading

0 comments on commit 8de73ac

Please sign in to comment.