Skip to content

Commit 1cd2dd0

Browse files
authored
BLS Support (#11)
1 parent 4618dc1 commit 1cd2dd0

File tree

7 files changed

+112
-95
lines changed

7 files changed

+112
-95
lines changed

.github/workflows/mvn-publish.yml

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,12 @@ on:
1111

1212
jobs:
1313
publish:
14-
runs-on: ubuntu-latest
15-
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-java@v1
18-
with:
19-
java-version: 1.8
20-
- uses: actions/cache@v2
21-
with:
22-
key: ${{ hashFiles('pom.xml') }}
23-
path: ~/.m2/repository
24-
- name: Prepare version
25-
id: maven-version
26-
run: |
27-
mvn_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
28-
git_ref=${GITHUB_REF##*/}
29-
pr_number=${{ github.event.number }}
30-
if [[ $git_ref =~ v[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then
31-
if [[ v$mvn_version != $git_ref ]] ; then
32-
echo Maven version $mvn_version does not match tag $git_ref
33-
exit 1
34-
fi
35-
elif [[ $pr_number != "" && $mvn_version =~ -SNAPSHOT$ ]] ; then
36-
pattern="s/(.+)-SNAPSHOT/\1-"$pr_number"-SNAPSHOT/g"
37-
mvn_version=$(echo $mvn_version | sed -E $pattern)
38-
mvn versions:set -DnewVersion=$mvn_version -DgenerateBackupPoms=false -q -DforceStdout
39-
elif [[ ! $mvn_version =~ -SNAPSHOT$ ]] ; then
40-
echo Refusing to publish non-snapshot version $mvn_version
41-
echo '::set-output name=skip-publish::true'
42-
fi
43-
- uses: samuelmeuli/[email protected]
44-
if:
45-
${{ steps.maven-version.outputs.skip-publish != 'true' }}
46-
with:
47-
gpg_private_key: ${{ secrets.OSSRH_GPG_KEY_ASCII }}
48-
gpg_passphrase: ${{ secrets.OSSRH_GPG_PASSPHRASE }}
49-
nexus_username: ${{ secrets.OSSRH_USERNAME }}
50-
nexus_password: ${{ secrets.OSSRH_PASSWORD }}
14+
uses: wavesplatform/protobuf-schemas/.github/workflows/mvn-publish.yml@5b4331ab892b44ad1fdd71862654421482dcd49c
15+
with:
16+
github-ref-name: ${{ github.ref_name }}
17+
github-event-number: ${{ github.event.number }}
18+
secrets:
19+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
20+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
21+
OSSRH_GPG_KEY: ${{ secrets.OSSRH_GPG_KEY }}
22+
OSSRH_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PASSPHRASE }}

.github/workflows/tests.yml

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,13 @@ on:
1010

1111
jobs:
1212
run_tests:
13-
1413
runs-on: ubuntu-latest
15-
1614
steps:
17-
- name: Checkout the repository
18-
uses: actions/checkout@v2
19-
with:
20-
fetch-depth: 1
21-
22-
- name: Set up JDK 8
23-
uses: actions/setup-java@v1
24-
with:
25-
java-version: 8
26-
27-
- name: Cache Maven packages
28-
uses: actions/cache@v2
29-
with:
30-
path: ~/.m2
31-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
32-
restore-keys: ${{ runner.os }}-m2
33-
34-
- name: Run tests
35-
run: mvn -B test -Dmaven.test.failure.ignore=true
36-
37-
- name: Publish test report
38-
uses: scacap/action-surefire-report@v1
15+
- uses: actions/checkout@v5
16+
- uses: actions/setup-java@v5
3917
with:
40-
github_token: ${{ secrets.GITHUB_TOKEN }}
18+
java-version: 11
19+
distribution: temurin
20+
cache: maven
21+
- run: mvn -B test -Dmaven.test.failure.ignore=true
22+
- uses: scacap/action-surefire-report@v1

pom.xml

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.wavesplatform</groupId>
88
<artifactId>waves-crypto</artifactId>
9-
<version>2.0.5</version>
9+
<version>2.0.6-SNAPSHOT</version>
1010

1111
<name>Waves Crypto for Java</name>
1212
<description>Tools to work with cryptographic primitives used in the Waves blockchain</description>
@@ -46,29 +46,48 @@
4646
<build>
4747
<plugins>
4848
<plugin>
49-
<groupId>org.sonatype.plugins</groupId>
50-
<artifactId>nexus-staging-maven-plugin</artifactId>
51-
<version>1.6.8</version>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-enforcer-plugin</artifactId>
51+
<version>3.6.1</version>
52+
<executions>
53+
<execution>
54+
<id>enforce-maven</id>
55+
<goals>
56+
<goal>enforce</goal>
57+
</goals>
58+
<configuration>
59+
<rules>
60+
<requireMavenVersion>
61+
<version>3.6.3</version>
62+
</requireMavenVersion>
63+
</rules>
64+
</configuration>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
<plugin>
69+
<groupId>org.sonatype.central</groupId>
70+
<artifactId>central-publishing-maven-plugin</artifactId>
71+
<version>0.9.0</version>
5272
<extensions>true</extensions>
5373
<configuration>
54-
<serverId>ossrh</serverId>
55-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
56-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
74+
<autoPublish>true</autoPublish>
75+
<waitUntil>published</waitUntil>
5776
</configuration>
5877
</plugin>
5978
<plugin>
6079
<groupId>org.apache.maven.plugins</groupId>
6180
<artifactId>maven-compiler-plugin</artifactId>
62-
<version>3.8.1</version>
81+
<version>3.14.1</version>
6382
<configuration>
64-
<source>8</source>
65-
<target>8</target>
83+
<source>11</source>
84+
<target>11</target>
6685
</configuration>
6786
</plugin>
6887
<plugin>
6988
<groupId>org.apache.maven.plugins</groupId>
7089
<artifactId>maven-source-plugin</artifactId>
71-
<version>3.1.0</version>
90+
<version>3.3.1</version>
7291
<executions>
7392
<execution>
7493
<id>attach-sources</id>
@@ -81,7 +100,7 @@
81100
<plugin>
82101
<groupId>org.apache.maven.plugins</groupId>
83102
<artifactId>maven-gpg-plugin</artifactId>
84-
<version>1.6</version>
103+
<version>3.2.8</version>
85104
<executions>
86105
<execution>
87106
<id>sign-artifacts</id>
@@ -91,23 +110,16 @@
91110
</goals>
92111
</execution>
93112
</executions>
94-
<configuration>
95-
<!-- Prevent `gpg` from using pinentry programs -->
96-
<gpgArguments>
97-
<arg>--pinentry-mode</arg>
98-
<arg>loopback</arg>
99-
</gpgArguments>
100-
</configuration>
101113
</plugin>
102114
<plugin>
103115
<groupId>org.apache.maven.plugins</groupId>
104116
<artifactId>maven-surefire-plugin</artifactId>
105-
<version>2.22.2</version>
117+
<version>3.5.4</version>
106118
</plugin>
107119
<plugin>
108120
<groupId>org.apache.maven.plugins</groupId>
109121
<artifactId>maven-jar-plugin</artifactId>
110-
<version>3.1.2</version>
122+
<version>3.4.2</version>
111123
<configuration>
112124
<archive>
113125
<manifest>
@@ -126,44 +138,59 @@
126138
<plugin>
127139
<groupId>org.apache.maven.plugins</groupId>
128140
<artifactId>maven-javadoc-plugin</artifactId>
129-
<version>3.1.1</version>
141+
<version>3.12.0</version>
130142
<executions>
131143
<execution>
132144
<id>attach-javadocs</id>
133145
<goals>
134146
<goal>jar</goal>
135147
</goals>
148+
<configuration>
149+
<source>11</source>
150+
<doclint>none</doclint>
151+
</configuration>
136152
</execution>
137153
</executions>
138154
<configuration>
139-
<source>8</source>
155+
<source>11</source>
156+
<doclint>none</doclint>
140157
</configuration>
141158
</plugin>
142159
</plugins>
143160
</build>
144161

145162
<distributionManagement>
146163
<snapshotRepository>
147-
<id>ossrh</id>
148-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
164+
<id>central</id>
165+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
149166
</snapshotRepository>
167+
</distributionManagement>
168+
169+
<repositories>
150170
<repository>
151-
<id>ossrh</id>
152-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
171+
<name>Central Portal Snapshots</name>
172+
<id>central-portal-snapshots</id>
173+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
174+
<releases>
175+
<enabled>false</enabled>
176+
</releases>
177+
<snapshots>
178+
<enabled>true</enabled>
179+
</snapshots>
153180
</repository>
154-
</distributionManagement>
181+
</repositories>
155182

156183
<dependencies>
157184
<!-- crypto -->
158185
<dependency>
159186
<groupId>org.bouncycastle</groupId>
160187
<artifactId>bcpkix-jdk18on</artifactId>
161-
<version>1.77</version>
188+
<version>1.82</version>
162189
</dependency>
163190
<dependency>
164191
<groupId>org.bouncycastle</groupId>
165192
<artifactId>bcprov-jdk18on</artifactId>
166-
<version>1.77</version>
193+
<version>1.82</version>
167194
</dependency>
168195
<dependency>
169196
<groupId>com.wavesplatform</groupId>
@@ -184,6 +211,11 @@
184211
<version>3.20.2</version>
185212
<scope>test</scope>
186213
</dependency>
214+
<dependency>
215+
<groupId>com.wavesplatform</groupId>
216+
<artifactId>blst-java</artifactId>
217+
<version>0.3.15-SNAPSHOT</version>
218+
</dependency>
187219
</dependencies>
188220

189221
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.wavesplatform.crypto;
2+
3+
import supranational.blst.*;
4+
5+
public class BlsUtils {
6+
private static final String DST = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_";
7+
8+
public static SecretKey mkBlsSecretKey(byte[] seed) {
9+
SecretKey sk = new SecretKey();
10+
sk.keygen(seed);
11+
return sk;
12+
}
13+
14+
public static byte[] mkBlsPublicKey(SecretKey sk) {
15+
return new P1(sk).compress();
16+
}
17+
18+
public static byte[] sign(SecretKey sk, byte[] message) {
19+
return new P2()
20+
.hash_to(message, DST)
21+
.sign_with(sk)
22+
.compress();
23+
}
24+
25+
public static boolean verify(byte[] sigBytes, byte[] message, byte[] pkBytes) {
26+
P2_Affine sig = new P2_Affine(sigBytes);
27+
P1_Affine pk = new P1_Affine(pkBytes);
28+
29+
Pairing ctx = new Pairing(true, DST);
30+
ctx.aggregate(pk, sig, message);
31+
ctx.commit();
32+
return ctx.finalverify();
33+
}
34+
}

src/main/java/com/wavesplatform/crypto/base/Base16.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/**
44
* Base16 is used to represent byte arrays as a readable string.
5-
*
65
* Not used in Waves blockchain, but can be used in Ride smart contracts.
76
*/
87
public abstract class Base16 {

src/main/java/com/wavesplatform/crypto/rsa/RsaKeyPair.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* Pair of RSA private and public keys to encrypt/decrypt or signing data.
16-
*
1716
* RSA signatures are supported in Ride language.
1817
*/
1918
@SuppressWarnings("WeakerAccess")

src/main/java/com/wavesplatform/crypto/rsa/RsaPublicKey.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
/**
1313
* RSA public key to encrypt data or verify that data is actually signed by the private key of the public key.
14-
*
1514
* RSA signatures are supported in Ride language.
1615
*/
1716
@SuppressWarnings("WeakerAccess")

0 commit comments

Comments
 (0)