File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed
secp-api/src/main/java/org/bitcoinj/secp/api
secp-examples-java/src/main/java/org/bitcoinj/secp/examples
secp-examples-kotlin/src/main/java/org/bitcoinj/secp/kotlin/examples Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1616package org .bitcoinj .secp .api ;
1717
1818import java .math .BigInteger ;
19+ import java .util .HexFormat ;
1920
2021/**
2122 *
@@ -55,6 +56,7 @@ static P256K1XOnlyPubKey of(BigInteger x) {
5556 * Default implementation. Currently used by all known implementations
5657 */
5758 class P256K1XOnlyPubKeyImpl implements P256K1XOnlyPubKey {
59+ private static final HexFormat formatter = HexFormat .of ();
5860 private final BigInteger x ;
5961
6062 public P256K1XOnlyPubKeyImpl (P256k1PubKey pubKey ) {
@@ -78,5 +80,13 @@ public BigInteger getX() {
7880 public byte [] getSerialized () {
7981 return P256k1PubKey .integerTo32Bytes (x );
8082 }
83+
84+ /**
85+ * @return A hex string representing the default binary serialization format
86+ */
87+ @ Override
88+ public String toString () {
89+ return formatter .formatHex (getSerialized ());
90+ }
8191 }
8292}
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ public static void main(String[] args) {
6565
6666 System .out .printf ("Is the signature valid? %s\n " , is_signature_valid );
6767 System .out .printf ("Secret Key: %s\n " , keyPair .getS ().toString (16 ));
68- System .out .printf ("Public Key (as ECPoint): %s\n " , formatter . formatHex ( xOnly2 . getSerialized ()) );
68+ System .out .printf ("Public Key (as ECPoint): %s\n " , xOnly2 );
6969 System .out .printf ("Signature: %s\n " , formatter .formatHex (signature ));
7070
7171 /* It's best practice to try to clear secrets from memory after using them.
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ object Schnorr {
6060
6161 System .out .printf(" Is the signature valid? %s\n " , is_signature_valid)
6262 System .out .printf(" Secret Key: %s\n " , keyPair.s.toString(16 ))
63- System .out .printf(" Public Key (as ECPoint): %s\n " , formatter.formatHex( xOnly2.serialized) )
63+ System .out .printf(" Public Key (as ECPoint): %s\n " , xOnly2)
6464 System .out .printf(" Signature: %s\n " , formatter.formatHex(signature))
6565
6666 /* It's best practice to try to clear secrets from memory after using them.
You can’t perform that action at this time.
0 commit comments