Class Secp256k1Foreign
java.lang.Object
org.bitcoinj.secp.ffm.Secp256k1Foreign
- All Implemented Interfaces:
Closeable, AutoCloseable, Secp256k1
Implementation of
Secp256k1 using the secp256k1 C-language library and the Java Foreign Function & Memory API.-
Nested Class Summary
Nested classes/interfaces inherited from interface Secp256k1
Secp256k1.Provider, Secp256k1.ProviderId -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Override close and declare that no checked exceptions are thrownecdh(SecpPubKey pubKey, SecpPrivKey secKey) ECDH key agreementecdsaSign(byte[] msg_hash_data, SecpPrivKey seckey) Sign a message hash using the ECDSA algorithmecdsaSignatureParseCompact(byte[] serialized_signature) Parse a Bitcoin compact signature.byte[]Serialize aEcdsaSignatureas a Bitcoin compact signature.static booleanecdsaVerify(MemorySegment sig, MemorySegment msg_hash, MemorySegment pubkey) TBD: Static verify method that doesn't require a class instance.ecdsaVerify(EcdsaSignature sig, byte[] msg_hash_data, SecpPubKey pubKey) Verify an ECDSA signature.Create a new, randomly-generated private key and return it with its matching public keyecKeyPairCreate(SecpPrivKey privKey) Create a key pair structure from a known private keyCreate a new, randomly-generated private key.ecPubKeyCombine(SecpPubKey key1) ecPubKeyCombine(SecpPubKey key1, SecpPubKey key2) Combine two public keys by adding them.ecPubKeyCreate(SecpPrivKey privkey) Create a public key from the given private key.ecPubKeyParse(byte[] inputData) Parse a byte array as a public keybyte[]ecPubKeySerialize(SecpPubKey pubKey, int flags) SincePubKeyDatais serializable without using the native lib, this method serialized without a native call.ecPubKeyTweakMul(SecpPubKey pubKey, BigInteger scalarMultiplier) Multiply a public key by a scalar, this is known as key "tweaking"static MemorySegmentfill_random(SegmentAllocator allocator, int size) schnorrSigSign32(byte[] messageHash, SecpKeyPair keyPair) Create a Schnorr signature for a message.schnorrSigVerify(SchnorrSignature signature, byte[] msg_hash, SecpXOnlyPubKey pubKey) Verify a Schnorr signature.byte[]taggedSha256(byte[] tag, byte[] message) Generate a tagged SHA-256 hash.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Secp256k1
ecPointUncompress, schnorrSigVerify, taggedSha256
-
Constructor Details
-
Secp256k1Foreign
public Secp256k1Foreign() -
Secp256k1Foreign
public Secp256k1Foreign(int flags) -
Secp256k1Foreign
public Secp256k1Foreign(int flags, boolean randomize)
-
-
Method Details
-
ecdsaVerify
TBD: Static verify method that doesn't require a class instance. -
close
-
ecPrivKeyCreate
Description copied from interface:Secp256k1Create a new, randomly-generated private key.- Specified by:
ecPrivKeyCreatein interfaceSecp256k1- Returns:
- the private key
-
ecPubKeyCreate
Description copied from interface:Secp256k1Create a public key from the given private key.- Specified by:
ecPubKeyCreatein interfaceSecp256k1- Parameters:
privkey- the private key- Returns:
- derived public key
-
ecKeyPairCreate
Description copied from interface:Secp256k1Create a new, randomly-generated private key and return it with its matching public key- Specified by:
ecKeyPairCreatein interfaceSecp256k1- Returns:
- newly generated key pair
-
ecKeyPairCreate
Description copied from interface:Secp256k1Create a key pair structure from a known private key- Specified by:
ecKeyPairCreatein interfaceSecp256k1- Parameters:
privKey- the private key- Returns:
- object containing both public and private key
-
ecPubKeyTweakMul
Description copied from interface:Secp256k1Multiply a public key by a scalar, this is known as key "tweaking"- Specified by:
ecPubKeyTweakMulin interfaceSecp256k1- Parameters:
pubKey- public key representing a point on the curvescalarMultiplier- scalar multiplier- Returns:
- the product
-
ecPubKeyCombine
Description copied from interface:Secp256k1Combine two public keys by adding them.- Specified by:
ecPubKeyCombinein interfaceSecp256k1- Parameters:
key1- first keykey2- second key- Returns:
- the sum
-
ecPubKeyCombine
-
ecPubKeySerialize
SincePubKeyDatais serializable without using the native lib, this method serialized without a native call.- Specified by:
ecPubKeySerializein interfaceSecp256k1- Parameters:
pubKey-flags-- Returns:
-
ecPubKeyParse
Description copied from interface:Secp256k1Parse a byte array as a public key- Specified by:
ecPubKeyParsein interfaceSecp256k1- Parameters:
inputData- raw data to parse as public key- Returns:
- public key result or error
-
ecdsaSign
Description copied from interface:Secp256k1Sign a message hash using the ECDSA algorithm -
ecdsaSignatureSerializeCompact
Description copied from interface:Secp256k1Serialize aEcdsaSignatureas a Bitcoin compact signature. A compact signature is the two signature component field integers (known asrands) serialized in-order as binary data in big-endian format.- Specified by:
ecdsaSignatureSerializeCompactin interfaceSecp256k1- Parameters:
sig- signature object- Returns:
- compact signature bytes
-
ecdsaSignatureParseCompact
Description copied from interface:Secp256k1Parse a Bitcoin compact signature. A compact signature is the two signature component field integers (known asrands) serialized in-order as binary data in big-endian format.- Specified by:
ecdsaSignatureParseCompactin interfaceSecp256k1- Parameters:
serialized_signature- compact signature bytes- Returns:
- signature object
-
ecdsaVerify
Description copied from interface:Secp256k1Verify an ECDSA signature.- Specified by:
ecdsaVerifyin interfaceSecp256k1- Parameters:
sig- 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:Secp256k1Generate a tagged SHA-256 hash.- Specified by:
taggedSha256in interfaceSecp256k1- Parameters:
tag- a tag specifying the context of usagemessage- the message itself- Returns:
- the SHA-256 HASH
-
schnorrSigSign32
Description copied from interface:Secp256k1Create a Schnorr signature for a message.- Specified by:
schnorrSigSign32in interfaceSecp256k1- Parameters:
messageHash- a hash of a message to signkeyPair- the keypair for signing- Returns:
- the signature
-
schnorrSigVerify
public SecpResult<Boolean> schnorrSigVerify(SchnorrSignature signature, byte[] msg_hash, SecpXOnlyPubKey pubKey) Description copied from interface:Secp256k1Verify a Schnorr signature.- Specified by:
schnorrSigVerifyin interfaceSecp256k1- Parameters:
signature- the signature to verifymsg_hash- hash of the messagepubKey- x-only pubkey that must have signed the message- Returns:
- true, false, or error
-
ecdh
Description copied from interface:Secp256k1ECDH key agreement -
fill_random
- Parameters:
allocator- allocator to create segment withsize- size in bytes of random data- Returns:
- A newly-allocated memory segment full of random data
-