@@ -101,7 +101,7 @@ int zkp_bip340_get_public_key(const uint8_t *private_key_bytes,
101101// private_key_bytes has 32 bytes
102102// digest has 32 bytes
103103// signature_bytes has 64 bytes
104- // auxiliary_data has 32 bytes or is NULL
104+ // auxiliary_data has 32 bytes or is NULL (32 zero bytes are used)
105105// returns 0 on success
106106int zkp_bip340_sign_digest (const uint8_t * private_key_bytes ,
107107 const uint8_t * digest , uint8_t * signature_bytes ,
@@ -136,8 +136,8 @@ int zkp_bip340_sign_digest(const uint8_t *private_key_bytes,
136136 }
137137
138138 if (result == 0 ) {
139- if (secp256k1_schnorrsig_sign (context_writable , signature_bytes , digest ,
140- & keypair , auxiliary_data ) != 1 ) {
139+ if (secp256k1_schnorrsig_sign32 (context_writable , signature_bytes , digest ,
140+ & keypair , auxiliary_data ) != 1 ) {
141141 result = -1 ;
142142 }
143143 }
@@ -184,6 +184,27 @@ int zkp_bip340_verify_digest(const uint8_t *public_key_bytes,
184184 return result ;
185185}
186186
187+ // BIP340 Schnorr public key verification
188+ // public_key_bytes has 32 bytes
189+ // returns 0 if verification succeeded
190+ int zkp_bip340_verify_publickey (const uint8_t * public_key_bytes ) {
191+ int result = 0 ;
192+
193+ secp256k1_xonly_pubkey xonly_pubkey = {0 };
194+ const secp256k1_context * context_read_only = zkp_context_get_read_only ();
195+
196+ if (result == 0 ) {
197+ if (secp256k1_xonly_pubkey_parse (context_read_only , & xonly_pubkey ,
198+ public_key_bytes ) != 1 ) {
199+ result = 1 ;
200+ }
201+ }
202+
203+ memzero (& xonly_pubkey , sizeof (xonly_pubkey ));
204+
205+ return result ;
206+ }
207+
187208// BIP340 Schnorr public key tweak
188209// internal_public_key has 32 bytes
189210// root_hash has 32 bytes or is empty (NULL)
0 commit comments