Derive taproot addresses from BIP39 mnemonic

0
74


I’ve two questions, however here is some basic data to begin: I wrote a bit of C program to generate addresses for BIP44, BIP49, and BIP84, and I needed to (lastly) replace it to incorporate BIP86. I have been making an attempt to observe the directions right here, however for some purpose it principally is not working. I am utilizing Visible Studio with libsecp256k1 from nuget (secp256k1_vc143). Until in any other case said, I’m utilizing the check vector mnemonic "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about".

First query: Within the hyperlink, there may be the “non-recommended” technique to get the p2tr handle, however there aren’t any check vectors for that. I might similar to to substantiate that for the check vector mnemonic above the end result for m/86'/0'/0'/0 index 0 needs to be bc1pej9yh3jd39aam30mctm8paaghg9nsemezpk0zg3udlza0nt0cy2sqvps98?

Second query: I am making an attempt to make use of libsecp256k1’s secp256k1_ec_pubkey_tweak_add() operate to carry out the tweaking, however it does not appear to be working. Right here is instance code, the place the preliminary personal key you see is the ultimate one when deriving the check vector mnemonic. I additionally hardcoded the SHA256("TapTweak")||SHA256("TapTweak") bit in tweak96.

char* seckey = "41f41d69260df4cf277826a9b65a3717e4eeddbeedf637f212ca096576479361";
uint8_t* privkey = calloc(32, 1);
HexToBin(seckey, privkey, 32);

secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
secp256k1_pubkey* pubkey = malloc(sizeof(*pubkey));
size_t clen = 33;

secp256k1_ec_pubkey_create(ctx, pubkey, privkey);

uint8_t* Pb = calloc(33, 1);
secp256k1_ec_pubkey_serialize(ctx, Pb, &clen, pubkey, SECP256K1_EC_COMPRESSED);

char* tweak96 = "e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e9e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e90000000000000000000000000000000000000000000000000000000000000000";
uint8_t* tweak96B = calloc(96, 1);
HexToBin(tweak96, tweak96B, 96);
memcpy(tweak96B + 64, Pb + 1, 32);

uint8_t* t = calloc(32, 1);
SHA256(tweak96B, 96, t);

secp256k1_ec_pubkey_tweak_add(ctx, pubkey, t);

uint8_t* Qb = calloc(33, 1);
char* addr = calloc(65, 1);

secp256k1_ec_pubkey_serialize(ctx, Qb, &clen, pubkey, SECP256K1_EC_COMPRESSED);

segwit_addr_encode(addr, "bc", 1, Qb + 1, 32);

In response to the check vectors and this website, I ought to get bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr, however I get bc1pvhzh08gqauq66acu3s8a2zwyxlhexsmwqj2gey9965du0u6snwms5x4qv0. For many mnemonics I’ve tried, I get the mistaken end result, apart from "warrior pudding spend capital class hospital village wait planet organ coach churn", the place I get the proper reply of bc1psug2nkgfkemndxq9mwqsdxg4rvdd9s8ztysft0lpxsy0f5jmufksz0tjup and I do not know why. My code works superb for BIP44, BIP49 and BIP84, however not the tweaked BIP86. Can anybody inform me what is going on mistaken right here?

LEAVE A REPLY

Please enter your comment!
Please enter your name here