@@ -278,16 +278,24 @@ private MemorySegment pubKeyParse(P256k1PubKey pubKeyData) {
278278
279279 @ Override
280280 public Result <SignatureData > ecdsaSign (byte [] msg_hash_data , P256k1PrivKey seckey ) {
281+ return ecdsaSign (msg_hash_data , seckey , secp256k1_h .NULL ());
282+ }
283+
284+ public Result <SignatureData > ecdsaSign (byte [] msg_hash_data , P256k1PrivKey seckey , byte [] ndata ) {
285+ // TODO: validate ndata is exactly 32-bytes long
286+ return ecdsaSign (msg_hash_data , seckey , arena .allocateFrom (JAVA_BYTE , ndata ));
287+ }
288+
289+ private Result <SignatureData > ecdsaSign (byte [] msg_hash_data , P256k1PrivKey seckey , MemorySegment ndataSegment ) {
281290 /* Generate an ECDSA signature `noncefp` and `ndata` allows you to pass a
282291 * custom nonce function, passing `NULL` will use the RFC-6979 safe default.
283292 * Signing with a valid context, verified secret key
284293 * and the default nonce function should never fail. */
285294 MemorySegment msg_hash = arena .allocateFrom (JAVA_BYTE , msg_hash_data );
286295 MemorySegment sig = secp256k1_ecdsa_signature .allocate (arena );
287- MemorySegment nullCallback = secp256k1_h .NULL (); // Double-check this (normally you shouldn't use a NULL pointer for a null callback)
288- MemorySegment nullPointer = secp256k1_h .NULL ();
296+ MemorySegment nonceFpNull = secp256k1_h .NULL (); // Double-check this (normally you shouldn't use a NULL pointer for a null callback)
289297 MemorySegment privKeySeg = arena .allocateFrom (JAVA_BYTE , seckey .getEncoded ());
290- int return_val = secp256k1_h .secp256k1_ecdsa_sign (ctx , sig , msg_hash , privKeySeg , nullCallback , nullPointer );
298+ int return_val = secp256k1_h .secp256k1_ecdsa_sign (ctx , sig , msg_hash , privKeySeg , nonceFpNull , ndataSegment );
291299 privKeySeg .fill ((byte ) 0x00 );
292300 return Result .checked (return_val , new SignaturePojo (sig ));
293301 }
0 commit comments