Class Bouncy256k1

java.lang.Object
org.bitcoinj.secp.bouncy.Bouncy256k1
All Implemented Interfaces:
Closeable, AutoCloseable, Secp256k1

public class Bouncy256k1 extends Object implements Secp256k1
Implementation of Secp256k1 using the Bouncy Castle library.
  • Constructor Details

    • Bouncy256k1

      public Bouncy256k1()
      Default constructor.
  • Method Details

    • ecPrivKeyCreate

      public SecpPrivKey ecPrivKeyCreate()
      Description copied from interface: Secp256k1
      Create a new, randomly-generated private key.
      Specified by:
      ecPrivKeyCreate in interface Secp256k1
      Returns:
      the private key
    • ecPubKeyCreate

      public SecpPubKey ecPubKeyCreate(SecpPrivKey seckey)
      Description copied from interface: Secp256k1
      Create a public key from the given private key.
      Specified by:
      ecPubKeyCreate in interface Secp256k1
      Parameters:
      seckey - the private key
      Returns:
      derived public key
    • ecKeyPairCreate

      public SecpKeyPair ecKeyPairCreate()
      Description copied from interface: Secp256k1
      Create a new, randomly-generated private key and return it with its matching public key
      Specified by:
      ecKeyPairCreate in interface Secp256k1
      Returns:
      newly generated key pair
    • ecKeyPairCreate

      public SecpKeyPair ecKeyPairCreate(SecpPrivKey privKey)
      Description copied from interface: Secp256k1
      Create a key pair structure from a known private key
      Specified by:
      ecKeyPairCreate in interface Secp256k1
      Parameters:
      privKey - the private key
      Returns:
      object containing both public and private key
    • ecPubKeyTweakMul

      public SecpPubKey ecPubKeyTweakMul(SecpPubKey pubKey, BigInteger scalarMultiplier)
      Description copied from interface: Secp256k1
      Multiply a public key by a scalar, this is known as key "tweaking"
      Specified by:
      ecPubKeyTweakMul in interface Secp256k1
      Parameters:
      pubKey - public key representing a point on the curve
      scalarMultiplier - scalar multiplier
      Returns:
      the product
    • ecPubKeyCombine

      public SecpPubKey ecPubKeyCombine(SecpPubKey key1, SecpPubKey key2)
      Description copied from interface: Secp256k1
      Combine two public keys by adding them.
      Specified by:
      ecPubKeyCombine in interface Secp256k1
      Parameters:
      key1 - first key
      key2 - second key
      Returns:
      the sum
    • ecPubKeySerialize

      public byte[] ecPubKeySerialize(SecpPubKey pubKey, int flags)
      Description copied from interface: Secp256k1
      Serialize a public key
      Specified by:
      ecPubKeySerialize in interface Secp256k1
      Parameters:
      pubKey - public key to serialize
      flags - serialization flags
      Returns:
      pubKey serialized as a byte array
    • ecPubKeyParse

      public SecpResult<SecpPubKey> ecPubKeyParse(byte[] inputData)
      Description copied from interface: Secp256k1
      Parse a byte array as a public key
      Specified by:
      ecPubKeyParse in interface Secp256k1
      Parameters:
      inputData - raw data to parse as public key
      Returns:
      public key result or error
    • ecdsaSign

      public SecpResult<EcdsaSignature> ecdsaSign(byte[] msg_hash_data, SecpPrivKey seckey)
      Description copied from interface: Secp256k1
      Sign a message hash using the ECDSA algorithm
      Specified by:
      ecdsaSign in interface Secp256k1
      Parameters:
      msg_hash_data - hash of message to sign
      seckey - private key
      Returns:
      the signature
    • ecdsaSignatureSerializeCompact

      public byte[] ecdsaSignatureSerializeCompact(EcdsaSignature sig)
      Description copied from interface: Secp256k1
      Serialize a EcdsaSignature as a Bitcoin compact signature. A compact signature is the two signature component field integers (known as r and s) serialized in-order as binary data in big-endian format.
      Specified by:
      ecdsaSignatureSerializeCompact in interface Secp256k1
      Parameters:
      sig - signature object
      Returns:
      compact signature bytes
    • ecdsaSignatureParseCompact

      public SecpResult<EcdsaSignature> ecdsaSignatureParseCompact(byte[] serialized_signature)
      Description copied from interface: Secp256k1
      Parse a Bitcoin compact signature. A compact signature is the two signature component field integers (known as r and s) serialized in-order as binary data in big-endian format.
      Specified by:
      ecdsaSignatureParseCompact in interface Secp256k1
      Parameters:
      serialized_signature - compact signature bytes
      Returns:
      signature object
    • ecdsaVerify

      public SecpResult<Boolean> ecdsaVerify(EcdsaSignature signature, byte[] msg_hash_data, SecpPubKey pubKey)
      Description copied from interface: Secp256k1
      Verify an ECDSA signature.
      Specified by:
      ecdsaVerify in interface Secp256k1
      Parameters:
      signature - The signature to verify.
      msg_hash_data - A hash of the message to verify.
      pubKey - The pubkey that must have signed the message
      Returns:
      true, false, or error
    • taggedSha256

      public byte[] taggedSha256(byte[] tag, byte[] message)
      Description copied from interface: Secp256k1
      Generate a tagged SHA-256 hash.
      Specified by:
      taggedSha256 in interface Secp256k1
      Parameters:
      tag - a tag specifying the context of usage
      message - the message itself
      Returns:
      the SHA-256 HASH
    • schnorrSigSign32

      public SchnorrSignature schnorrSigSign32(byte[] msg_hash, SecpKeyPair keyPair)
      Description copied from interface: Secp256k1
      Create a Schnorr signature for a message.
      Specified by:
      schnorrSigSign32 in interface Secp256k1
      Parameters:
      msg_hash - a hash of a message to sign
      keyPair - the keypair for signing
      Returns:
      the signature
    • schnorrSigVerify

      public SecpResult<Boolean> schnorrSigVerify(SchnorrSignature signature, byte[] msg_hash, SecpXOnlyPubKey pubKey)
      Description copied from interface: Secp256k1
      Verify a Schnorr signature.
      Specified by:
      schnorrSigVerify in interface Secp256k1
      Parameters:
      signature - the signature to verify
      msg_hash - hash of the message
      pubKey - x-only pubkey that must have signed the message
      Returns:
      true, false, or error
    • ecdh

      public SecpResult<EcdhSharedSecret> ecdh(SecpPubKey pubKey, SecpPrivKey secKey)
      Description copied from interface: Secp256k1
      ECDH key agreement
      Specified by:
      ecdh in interface Secp256k1
      Parameters:
      pubKey - pubkey of the other party
      secKey - secret key
      Returns:
      ecdh key agreement
    • close

      public void close()
      Description copied from interface: Secp256k1
      Override close and declare that no checked exceptions are thrown
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Secp256k1