@@ -776,6 +776,120 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_create(
776776 const unsigned char * seckey
777777) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
778778
779+ /** Converts a secp256k1_pubkey into a secp256k1_xonly_pubkey. This
780+ * function optionally outputs a sign bit that can be used to convert
781+ * the secp256k1_xonly_pubkey back into the same secp256k1_pubkey.
782+ * The sign bit is 0 if the input pubkey encodes a positive point (has a Y
783+ * coordinate that is a quadratic residue), otherwise it is 1.
784+ *
785+ * Returns: 1 if the public key was successfully converted
786+ * 0 otherwise
787+ *
788+ * Args: ctx: pointer to a context object
789+ * Out: xonly_pubkey: pointer to an x-only public key object for placing the
790+ * converted public key (cannot be NULL)
791+ * sign: sign bit of the pubkey. Can be used to reconstruct a
792+ * public key from x-only public key (can be NULL)
793+ * In: pubkey: pointer to a public key that is converted (cannot be
794+ * NULL)
795+ */
796+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_from_pubkey (
797+ const secp256k1_context * ctx ,
798+ secp256k1_xonly_pubkey * xonly_pubkey ,
799+ int * sign ,
800+ const secp256k1_pubkey * pubkey
801+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 );
802+
803+ /** Convert a secp256k1_xonly_pubkey into a secp256k1_pubkey. If this
804+ * function is used to invert secp256k1_xonly_pubkey_from_pubkey, the
805+ * sign bit must be set to the output of that function. If the sign bit
806+ * is 0 the output pubkey encodes a positive point (has a Y coordinate that is a
807+ * quadratic residue), otherwise it is negative.
808+ *
809+ * Returns: 1 if the public key was successfully converted
810+ * 0 otherwise
811+ *
812+ * Args: ctx: pointer to a context object
813+ * Out: pubkey: pointer to a public key object for placing the
814+ * converted public key (cannot be NULL)
815+ * In: xonly_pubkey: pointer to an x-only public key that is converted
816+ * (cannot be NULL)
817+ * sign: sign bit of the resulting public key (can be NULL)
818+ */
819+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_to_pubkey (
820+ const secp256k1_context * ctx ,
821+ secp256k1_pubkey * pubkey ,
822+ const secp256k1_xonly_pubkey * xonly_pubkey ,
823+ int sign
824+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
825+
826+ /** Tweak the private key of an x-only pubkey by adding a tweak to it. The public
827+ * key of the resulting private key will be the same as the output of
828+ * secp256k1_xonly_pubkey_tweak_add called with the same tweak and corresponding
829+ * input public key.
830+ *
831+ * If the public key corresponds to a positive point, tweak32 is added to the
832+ * seckey (modulo the group order). If the public key corresponds to a
833+ * negative point, tweak32 is added to the negation of the seckey (modulo the
834+ * group order).
835+ *
836+ * Returns: 1 if the tweak was successfully added to seckey
837+ * 0 if the tweak was out of range or the resulting private key would be
838+ * invalid (only when the tweak is the complement of the private key) or
839+ * seckey is 0.
840+ *
841+ * Args: ctx: pointer to a context object, initialized for signing (cannot be NULL)
842+ * In/Out: seckey: pointer to a 32-byte private key
843+ * In: tweak32: pointer to a 32-byte tweak
844+ */
845+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_privkey_tweak_add (
846+ const secp256k1_context * ctx ,
847+ unsigned char * seckey ,
848+ const unsigned char * tweak32
849+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
850+
851+ /** Tweak an x-only public key by adding tweak times the generator to it. Note that
852+ * the output is a secp256k1_pubkey and not a secp256k1_xonly_pubkey.
853+ * Returns: 1 if tweak times the generator was successfully added to pubkey
854+ * 0 if the tweak was out of range or the resulting public key would be
855+ * invalid (only when the tweak is the complement of the corresponding
856+ * private key).
857+ *
858+ * Args: ctx: pointer to a context object initialized for validation
859+ * (cannot be NULL)
860+ * Out: output_pubkey: pointer to a public key object (cannot be NULL)
861+ * In: internal_pubkey: pointer to an x-only public key object to apply the
862+ * tweak to (cannot be NULL)
863+ * tweak32: pointer to a 32-byte tweak (cannot be NULL)
864+ */
865+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_tweak_add (
866+ const secp256k1_context * ctx ,
867+ secp256k1_pubkey * output_pubkey ,
868+ const secp256k1_xonly_pubkey * internal_pubkey ,
869+ const unsigned char * tweak32
870+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
871+
872+ /** Verifies that output_pubkey is the result of calling
873+ * secp256k1_xonly_pubkey_tweak_add with internal_pubkey and tweak32.
874+ *
875+ * Returns: 1 if output_pubkey is the result of tweaking the internal_pubkey with
876+ * tweak32
877+ * 0 otherwise
878+ *
879+ * Args: ctx: pointer to a context object initialized for validation
880+ * (cannot be NULL)
881+ * In: output_pubkey: pointer to a public key object (cannot be NULL)
882+ * internal_pubkey: pointer to an x-only public key object to apply the
883+ * tweak to (cannot be NULL)
884+ * tweak32: pointer to a 32-byte tweak (cannot be NULL)
885+ */
886+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_tweak_verify (
887+ const secp256k1_context * ctx ,
888+ const secp256k1_pubkey * output_pubkey ,
889+ const secp256k1_xonly_pubkey * internal_pubkey ,
890+ const unsigned char * tweak32
891+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
892+
779893#ifdef __cplusplus
780894}
781895#endif
0 commit comments