Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions secp-examples-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>${bitcoinj.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Runtime implementations -->
<dependency>
Expand Down Expand Up @@ -291,5 +303,40 @@
</plugins>
</build>
</profile>
<profile>
<id>run-sign-many</id>
<activation>
<property>
<name>run-sign-many</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>run-sign-many</id>
<phase>package</phase>
<goals><goal>exec</goal></goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>--enable-native-access=org.bitcoinj.secp.ffm</argument>
<argument>-Djava.library.path=${env.LIBSECP_DIR}</argument>
<argument>--module-path</argument>
<modulepath/>
<argument>--module</argument>
<argument>org.bitcoinj.secp.examples/org.bitcoinj.secp.examples.SignMany</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
1 change: 1 addition & 0 deletions secp-examples-java/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
requires org.bitcoinj.secp;
requires org.bitcoinj.secp.graalvm;
requires org.jspecify;
requires org.bitcoinj.core;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2023-2026 secp256k1-jdk Developers.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitcoinj.secp.examples;

import org.bitcoinj.base.internal.Stopwatch;
import org.bitcoinj.secp.SchnorrSignature;
import org.bitcoinj.secp.Secp256k1;
import org.bitcoinj.secp.SecpKeyPair;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

import static java.lang.IO.println;

public class SignMany {
final int count = 100_000;
final String msg = "Hello, world!";
final String tag = "my_fancy_protocol";

void main() {
try (Secp256k1 secp = Secp256k1.getById(Secp256k1.ProviderId.LIBSECP256K1_FFM)) {
println("Creating " + count + " keyPairs");
Stopwatch createWatch = Stopwatch.start();
var keyPairs = IntStream.range(0, count)
.mapToObj(i -> secp.ecKeyPairCreate())
.toList();
println("Finished in " + createWatch.stop().toString());

println("Signing " + count + " messages");
Stopwatch signWatch = Stopwatch.start();
byte[] messageHash = secp.taggedSha256(tag, msg);
var sigs = IntStream.range(0, count)
.mapToObj(i -> secp.schnorrSigSign32(messageHash, keyPairs.get(i)))
.toList();
println("Finished in " + signWatch.stop().toString());

println("Verifying " + count + " signatures");
Stopwatch verifyWatch = Stopwatch.start();
int verified = IntStream.range(0, count)
.map(i -> secp.schnorrSigVerify(sigs.get(i), messageHash, keyPairs.get(i).publicKey())
.get()
.compareTo(false))
.sum();
println("Signatures verified: " + verified);
println("Finished in " + verifyWatch.stop().toString());
}
}
}
Loading