Help Bitcoin Public Key Why can’t I convert the taproot public key through the private key? #1601

issue Xxxxxx-dot openend this issue on September 3, 2024
  1. Xxxxxx-dot commented at 12:52 pm on September 3, 2024: none

    #include <stdio.h> #include <stdlib.h> #include <secp256k1.h> #include <secp256k1_extrakeys.h>

    int main() {

    secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
    
    
    unsigned char privkey[32] = {
        0x7d, 0x48, 0x1e, 0x43, 0x55, 0xd5, 0x1c, 0x82,
        0x4e, 0x8d, 0x02, 0xe6, 0x17, 0xd0, 0xe1, 0x88,
        0xba, 0x97, 0x68, 0x5e, 0x55, 0xf8, 0x65, 0x57,
        0xd1, 0xd8, 0x3d, 0x64, 0xd1, 0xc8, 0x95, 0x4b
    };
    
    
    if (!secp256k1_ec_seckey_verify(ctx, privkey)) {
        printf("Invalid private key\n");
        secp256k1_context_destroy(ctx);
        return 1;
    }
    
    
    secp256k1_pubkey pubkey;
    
    
    if (!secp256k1_ec_pubkey_create(ctx, &pubkey, privkey)) {
        printf("Failed to create public key\n");
        secp256k1_context_destroy(ctx);
        return 1;
    }
    
    
    secp256k1_xonly_pubkey xonly_pubkey;
    if (!secp256k1_xonly_pubkey_from_pubkey(ctx, &xonly_pubkey, NULL, &pubkey)) {
        printf("Failed to convert to x-only public key\n");
        secp256k1_context_destroy(ctx);
        return 1;
    }
    
    unsigned char output[32];
    if (!secp256k1_xonly_pubkey_serialize(ctx, output, &xonly_pubkey)) {
        printf("Failed to serialize x-only public key\n");
        secp256k1_context_destroy(ctx);
        return 1;
    }
    
    
    printf("Taproot public key (x-only): ");
    for (size_t i = 0; i < 32; i++) {
        printf("%02x", output[i]);
    }
    printf("\n");
    
    
    secp256k1_context_destroy(ctx);
    
    return 0;
    

    }

    I need t2pr public key

    I need an example, can anyone help me?

  2. Xxxxxx-dot commented at 12:53 pm on September 3, 2024: none
    Such a conversion is wrong taproot public key
  3. bitcoin-core locked this on Sep 3, 2024
  4. ?
    converted_to_discussion real-or-random


Xxxxxx-dot


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 05:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me