CryptoOps

org.sigilaris.core.crypto.CryptoOps
object CryptoOps extends CryptoOpsLike

JVM implementation of cryptographic operations using BouncyCastle.

Provides secp256k1 elliptic curve operations including:

  • Keccak-256 hashing (thread-safe via pool)
  • Key pair generation and derivation
  • ECDSA signing with deterministic k (RFC 6979) and Low-S normalization
  • Public key recovery from signatures

All operations use BouncyCastle's secp256k1 implementation with performance optimizations including thread-local digest pooling and optional coordinate caching.

Attributes

See also

CryptoOpsLike for the cross-platform interface

Note

This is the JVM-specific implementation. Cross-platform code should use CryptoOpsLike interface.

Example
 // Generate a key pair
 val keyPair = CryptoOps.generate()
 // Hash and sign
 val message = "hello".getBytes
 val hash    = CryptoOps.keccak256(message)
 val sig     = CryptoOps.sign(keyPair, hash).toOption.get
 // Recover public key
 val recovered = CryptoOps.recover(sig, hash)
 assert(recovered.contains(keyPair.publicKey))
Source
CryptoOps.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
CryptoOps.type

Members list

Value members

Concrete methods

def fromPrivate(privateKey: BigInt): KeyPair

Derives a KeyPair from an existing private key.

Derives a KeyPair from an existing private key.

Performs privateKey mod n then scalar multiplication on the secp256k1 generator point to compute the corresponding public key. The caller is expected to supply a value in [1, n-1]; out-of-range inputs are reduced rather than rejected.

Value parameters

privateKey

private key as BigInt; should be in range [1, n-1] (prevalidated)

Attributes

Returns

KeyPair containing the private key and its derived public key

Throws
Exception

if privateKey cannot be represented as a UInt256

Source
CryptoOps.scala
def generate(): KeyPair

Generates a new random secp256k1 key pair.

Generates a new random secp256k1 key pair.

Attributes

Returns

freshly generated KeyPair with 32-byte private key and 64-byte uncompressed public key (x||y), big-endian

Source
CryptoOps.scala
def keccak256(input: Array[Byte]): Array[Byte]

Computes Keccak-256 hash using thread-local digest pool.

Computes Keccak-256 hash using thread-local digest pool.

Value parameters

input

message bytes (not modified)

Attributes

Returns

32-byte hash (freshly allocated copy)

Note

Thread-safe via internal.KeccakPool

Source
CryptoOps.scala
def recover(signature: Signature, hashArray: Array[Byte]): Either[SigilarisFailure, PublicKey]

Recovers the public key from a (v, r, s) signature and message hash.

Recovers the public key from a (v, r, s) signature and message hash.

Accepts signatures with either High-S or Low-S; internally normalizes s to Low-S before recovery. The recovery parameter v determines which candidate public key to return.

Value parameters

hashArray

32-byte message hash that was signed

signature

ECDSA signature with recovery parameter v (27-30)

Attributes

Returns

Right(PublicKey) on success, Left(failure) if recovery fails

Source
CryptoOps.scala
def sign(keyPair: KeyPair, transactionHash: Array[Byte]): Either[SigilarisFailure, Signature]

Signs a message hash with ECDSA using deterministic k-generation (RFC 6979).

Signs a message hash with ECDSA using deterministic k-generation (RFC 6979).

Normalizes the s-value to Low-S form (s <= n/2) and computes the recovery parameter by trial recovery.

Value parameters

keyPair

key pair whose private key is used for signing

transactionHash

32-byte message hash to sign

Attributes

Returns

Right(Signature) with (v, r, s) on success, Left(failure) if signing or recovery parameter computation fails

Source
CryptoOps.scala

Concrete fields

val secureRandom: SecureRandom

Cryptographically secure random number generator for key generation.

Cryptographically secure random number generator for key generation.

Uses the JVM's default SecureRandom provider.

Attributes

Source
CryptoOps.scala