Secp256k1
A cryptographic object responsible for key generation, signature creation, and signature verification utilizing the SECP256K1 elliptic curve, widely used for Bitcoin and Ethereum transactions.
The object uses the Nimbus JOSE+JWT library and implements the KeyGenerator and Signer interfaces, providing specific implementation details for SECP256K1.
Key Points:
Utilizes the ES256K algorithm for signing JWTs.
Utilizes BouncyCastle as the underlying security provider.
Public and private keys can be encoded with PUB_MULTICODEC and PRIV_MULTICODEC respectively.
Example Usage:
val privateKey = Secp256k1.generatePrivateKey()
val publicKey = Secp256k1.getPublicKey(privateKey)
Key Generation and Management:
generatePrivateKey
: Generates a private key for the SECP256K1 curve.getPublicKey
: Derives the corresponding public key from a private key.
Signing and Verification:
sign
: Generates a digital signature.verify
: Verifies a digital signature.
See also
for generating key details.
for handling signing operations.
Properties
Compressed key leading byte that indicates whether the Y coordinate is even.
Compressed key leading byte that indicates whether the Y coordinate is odd.
The byte size of a compressed public key.
Range that defines the position of the X coordinate in an uncompressed public key byte array.
Range that defines the position of the Y coordinate in an uncompressed public key byte array.
uncompressed key leading byte.
Size of an uncompressed public key in bytes.
Functions
Converts a private key as bytes into a Jwk.
Converts a public key as bytes into a Jwk. Applicable for asymmetric Key Generators only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception
Compresses a public key represented by its X and Y coordinates concatenated in a single byte array.
Derives a public key from the private key provided. Applicable for asymmetric Key Generators only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception
Generates a private key using the SECP256K1 curve and ES256K algorithm.
Inflates a compressed public key.
Converts a private key to bytes.
Converts a public key to bytes. Applicable for asymmetric KeyGenerator implementations only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception
Validates the provided Jwk (JSON Web Key) to ensure it conforms to the expected key type and format.
Verifies a signature against a given payload using the ECDSA (Elliptic Curve Digital Signature Algorithm) with the curve secp256k1
. This function supports deterministic k-value generation through HMAC and SHA-256, ensuring consistent verification outcomes for identical payloads and signatures.