Skip to content

Commit

Permalink
Refactor to Gradle multiproject
Browse files Browse the repository at this point in the history
Tests are still in root project for now.
  • Loading branch information
msgilligan committed Feb 26, 2024
1 parent 21c4fc1 commit a38c4fc
Show file tree
Hide file tree
Showing 74 changed files with 318 additions and 190 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If necessary copy updated, extracted headers into `src/main/java/org/consensusj/

(This assumes a specific hash/version of secp256k1 was installed with nixpkgs)

. `./gradlew -PjavaPath="/nix/store/j9mf1fh4wbb8c3x1zwqfs218bhml1rbw-secp256k1-0.4.0/lib/" run`
. `./gradlew -PjavaPath="/nix/store/j9mf1fh4wbb8c3x1zwqfs218bhml1rbw-secp256k1-0.4.0/lib/" secp256k1-examples-java:run`

== Building with Nix

Expand Down
78 changes: 41 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
plugins {
id "application"
}
allprojects {
apply plugin: 'java'
apply plugin: 'groovy'
//apply plugin: 'test-report-aggregation'

java {
sourceCompatibility = JavaVersion.toVersion("21")
targetCompatibility = JavaVersion.toVersion("21")
}
version = secp256k1Version // set in gradle.properties
group = 'org.bitcoinj.secp256k1'

repositories {
mavenCentral()
}
repositories {
mavenCentral()
}

group = 'org.consensusj'
dependencies {
implementation 'org.bouncycastle:bcprov-jdk18on:1.77' // Bouncy & EggCC-only

dependencies {
implementation 'org.bouncycastle:bcprov-jdk18on:1.77' // Bouncy & EggCC-only
testImplementation("org.bitcoinj:bitcoinj-core:0.17-alpha3");
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.0"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.0"
}

testImplementation("org.bitcoinj:bitcoinj-core:0.17-alpha3");
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.0"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.0"
}
java {
sourceCompatibility = JavaVersion.toVersion("21")
targetCompatibility = JavaVersion.toVersion("21")
}

tasks.withType(JavaCompile).configureEach {
options.release = 21
options.compilerArgs += ['--enable-preview']
}
test {
useJUnitPlatform()
systemProperty "java.library.path", findProperty("javaPath") ?: "/nix/store/j9mf1fh4wbb8c3x1zwqfs218bhml1rbw-secp256k1-0.4.0/lib/"
jvmArgs += '--enable-preview'
jvmArgs += '--enable-native-access=ALL-UNNAMED'
}

tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
jvmArgs += '--enable-native-access=ALL-UNNAMED'
}
tasks.withType(JavaCompile).configureEach {
options.release = 21
options.compilerArgs += ['--enable-preview']
}

test {
useJUnitPlatform()
systemProperty "java.library.path", findProperty("javaPath") ?: "/nix/store/j9mf1fh4wbb8c3x1zwqfs218bhml1rbw-secp256k1-0.4.0/lib/"
jvmArgs += '--enable-preview'
jvmArgs += '--enable-native-access=ALL-UNNAMED'
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
jvmArgs += '--enable-native-access=ALL-UNNAMED'
}
}

application {
// mainClass = 'org.consensusj.secp256k1.examples.Ecdsa'
mainClass = 'org.consensusj.secp256k1.examples.Schnorr'
}
// Currently only Tests are in the root module
// TODO: Move the tests to various submodules

run {
systemProperty "java.library.path", findProperty("javaPath") ?: ""
dependencies {
implementation project(':secp256k1-api')
implementation project(':secp256k1-bouncy')
implementation project(':secp256k1-foreign')
implementation project(':secp256k1-sandbox')
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secp256k1Version = 0.0.1
18 changes: 18 additions & 0 deletions secp256k1-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id 'java-library'
}

tasks.withType(JavaCompile).configureEach {
//options.release = 9
}

ext.moduleName = 'org.bitcoinj.secp256k1.api'

jar {
inputs.property("moduleName", moduleName)
manifest {
attributes 'Implementation-Title': 'Secp256k1 API',
'Automatic-Module-Name': moduleName,
'Implementation-Version': archiveVersion.get()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

/**
* A single object with a private and public key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

import java.math.BigInteger;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

import java.math.BigInteger;
import java.security.interfaces.ECPrivateKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

import java.math.BigInteger;
import java.security.interfaces.ECPublicKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.api;
package org.bitcoinj.secp256k1.api;

/**
*
Expand Down
22 changes: 22 additions & 0 deletions secp256k1-bouncy/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id 'java-library'
}

tasks.withType(JavaCompile).configureEach {
//options.release = 9
}

ext.moduleName = 'org.bitcoinj.secp256k1.bouncy'

dependencies {
api project(':secp256k1-api')
}

jar {
inputs.property("moduleName", moduleName)
manifest {
attributes 'Implementation-Title': 'Secp256k1 Bouncy Castle Implementation',
'Automatic-Module-Name': moduleName,
'Implementation-Version': archiveVersion.get()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.consensusj.secp256k1.bouncy;
package org.bitcoinj.secp256k1.bouncy;

import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
Expand All @@ -7,20 +7,17 @@
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.math.ec.ECFieldElement;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.math.ec.FixedPointCombMultiplier;
import org.bouncycastle.math.ec.FixedPointUtil;
import org.bouncycastle.math.ec.custom.sec.SecP256K1FieldElement;
import org.bouncycastle.math.ec.custom.sec.SecP256K1Point;
import org.consensusj.secp256k1.api.P256K1KeyPair;
import org.consensusj.secp256k1.api.P256K1XOnlyPubKey;
import org.consensusj.secp256k1.api.Secp256k1;
import org.consensusj.secp256k1.api.CompressedPubKeyData;
import org.consensusj.secp256k1.api.CompressedSignatureData;
import org.consensusj.secp256k1.api.P256k1PrivKey;
import org.consensusj.secp256k1.api.P256k1PubKey;
import org.consensusj.secp256k1.api.SignatureData;
import org.bitcoinj.secp256k1.api.P256K1KeyPair;
import org.bitcoinj.secp256k1.api.P256K1XOnlyPubKey;
import org.bitcoinj.secp256k1.api.Secp256k1;
import org.bitcoinj.secp256k1.api.CompressedPubKeyData;
import org.bitcoinj.secp256k1.api.CompressedSignatureData;
import org.bitcoinj.secp256k1.api.P256k1PrivKey;
import org.bitcoinj.secp256k1.api.P256k1PubKey;
import org.bitcoinj.secp256k1.api.SignatureData;

import java.math.BigInteger;
import java.security.SecureRandom;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.consensusj.secp256k1.bouncy;
package org.bitcoinj.secp256k1.bouncy;

import org.consensusj.secp256k1.api.P256K1KeyPair;
import org.bitcoinj.secp256k1.api.P256K1KeyPair;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.consensusj.secp256k1.bouncy;
package org.bitcoinj.secp256k1.bouncy;

import org.bitcoinj.secp256k1.api.P256k1PrivKey;
import org.bouncycastle.math.ec.custom.sec.SecP256K1FieldElement;
import org.consensusj.secp256k1.api.P256k1PrivKey;

import java.math.BigInteger;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.consensusj.secp256k1.bouncy;
package org.bitcoinj.secp256k1.bouncy;


import org.bouncycastle.math.ec.ECPoint;
import org.consensusj.secp256k1.api.P256k1PubKey;
import org.bitcoinj.secp256k1.api.P256k1PubKey;

import static org.consensusj.secp256k1.bouncy.Bouncy256k1.BC_CURVE;
import static org.bitcoinj.secp256k1.bouncy.Bouncy256k1.BC_CURVE;

/**
*
Expand Down
34 changes: 34 additions & 0 deletions secp256k1-examples-java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'java'
id 'application'
}

tasks.withType(JavaCompile).configureEach {
//options.release = 22
}

ext.moduleName = 'org.bitcoinj.secp256k1.examples-java'

dependencies {
implementation project(':secp256k1-api')
implementation project(':secp256k1-bouncy')
implementation project(':secp256k1-foreign')
}

jar {
inputs.property("moduleName", moduleName)
manifest {
attributes 'Implementation-Title': 'Example secp256k1-jdk Apps',
'Automatic-Module-Name': moduleName,
'Implementation-Version': archiveVersion.get()
}
}

application {
// mainClass = 'org.bitcoinj.secp256k1.examples.Ecdsa'
mainClass = 'org.bitcoinj.secp256k1.examples.Schnorr'
}

run {
systemProperty "java.library.path", findProperty("javaPath") ?: ""
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.consensusj.secp256k1.examples;
package org.bitcoinj.secp256k1.examples;

import org.consensusj.secp256k1.api.CompressedPubKeyData;
import org.consensusj.secp256k1.api.CompressedSignatureData;
import org.consensusj.secp256k1.api.P256k1PrivKey;
import org.consensusj.secp256k1.api.P256k1PubKey;
import org.consensusj.secp256k1.api.SignatureData;
import org.consensusj.secp256k1.bouncy.BouncyPrivKey;
import org.consensusj.secp256k1.foreign.Secp256k1Foreign;
import org.bitcoinj.secp256k1.api.CompressedPubKeyData;
import org.bitcoinj.secp256k1.api.CompressedSignatureData;
import org.bitcoinj.secp256k1.api.P256k1PrivKey;
import org.bitcoinj.secp256k1.api.P256k1PubKey;
import org.bitcoinj.secp256k1.api.SignatureData;
import org.bitcoinj.secp256k1.foreign.Secp256k1Foreign;
import org.bitcoinj.secp256k1.foreign.jextract.secp256k1_h;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.HexFormat;

import static org.consensusj.secp256k1.secp256k1_h.SECP256K1_EC_COMPRESSED;
import static org.bitcoinj.secp256k1.foreign.jextract.secp256k1_h.SECP256K1_EC_COMPRESSED;

/**
* Port of secp256k1 sample {@code ecdsa.c} to Java
Expand All @@ -41,7 +40,7 @@ public static void main(String[] args) {
P256k1PubKey pubkey = secp.ecPubKeyCreate(privKey);

/* Serialize the pubkey in a compressed form(33 bytes). */
CompressedPubKeyData compressed_pubkey = secp.ecPubKeySerialize(pubkey, SECP256K1_EC_COMPRESSED());
CompressedPubKeyData compressed_pubkey = secp.ecPubKeySerialize(pubkey, secp256k1_h.SECP256K1_EC_COMPRESSED());

/* === Signing === */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.consensusj.secp256k1.examples;

import org.consensusj.secp256k1.api.P256K1KeyPair;
import org.consensusj.secp256k1.api.P256K1XOnlyPubKey;
import org.consensusj.secp256k1.api.P256k1PrivKey;
import org.consensusj.secp256k1.api.P256k1PubKey;
import org.consensusj.secp256k1.bouncy.BouncyPrivKey;
import org.consensusj.secp256k1.foreign.Secp256k1Foreign;
package org.bitcoinj.secp256k1.examples;

import org.bitcoinj.secp256k1.api.P256K1KeyPair;
import org.bitcoinj.secp256k1.api.P256K1XOnlyPubKey;
import org.bitcoinj.secp256k1.api.P256k1PubKey;
import org.bitcoinj.secp256k1.bouncy.BouncyPrivKey;
import org.bitcoinj.secp256k1.foreign.Secp256k1Foreign;

import java.math.BigInteger;
import java.util.HexFormat;
Expand Down
22 changes: 22 additions & 0 deletions secp256k1-foreign/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id 'java-library'
}

tasks.withType(JavaCompile).configureEach {
//options.release = 22
}

ext.moduleName = 'org.bitcoinj.secp256k1.foreign'

dependencies {
api project(':secp256k1-api')
}

jar {
inputs.property("moduleName", moduleName)
manifest {
attributes 'Implementation-Title': 'Secp256k1 libsecp256k1 Foreign Function & Memory implementation',
'Automatic-Module-Name': moduleName,
'Implementation-Version': archiveVersion.get()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.consensusj.secp256k1.foreign;
package org.bitcoinj.secp256k1.foreign;

import org.consensusj.secp256k1.api.CompressedPubKeyData;
import org.bitcoinj.secp256k1.api.CompressedPubKeyData;

import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.consensusj.secp256k1.foreign;
package org.bitcoinj.secp256k1.foreign;

import org.consensusj.secp256k1.api.CompressedSignatureData;
import org.bitcoinj.secp256k1.api.CompressedSignatureData;

import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
Expand Down
Loading

0 comments on commit a38c4fc

Please sign in to comment.