Closed aleixisp closed 3 years ago
Hi,
I imported the same mnemonic in sollet.io and TrustWallet and I got the same address 5cHj95qPtR4Xwo8wBkX3b129D8PApqn64LUh5XMVYFo6
(and there is no XhYnQXtkTdbycmGvaJ7xBaSzKMpYzLPm7mn36PkRhQ3
address), so the computed address and keys are correct.
I'm not very familiar with solana-cli and I don't know exactly what the verify
command is doing, maybe it's a problem of data format. I'll try to play around with it.
Hi, I took a look at the source code of solana-cli. Basically, it is working quite differently to other wallets (that's why it's generating different addresses) because it's not an HD-wallet (i.e. it's not deriving any children key, but only generating a master key). So, what solana-cli does is:
So, to replicate this behavior FromPrivateKey method shall be used for construction, by taking only the first 32-byte of the seed, e.g.:
mnemonic = "long mango angle near comic pave useful mandate loop language quantum cruise"
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
bip44_ctx = Bip44.FromPrivateKey(seed_bytes[:32], Bip44Coins.SOLANA)
# Same address of the one printed by solana-cli
print(bip44_ctx.PublicKey().ToAddress())
# Print master key, no need to derive any children key
print(bip44_ctx.PublicKey().RawCompressed().ToHex())
print(bip44_ctx.PrivateKey().Raw().ToHex())
Moreover, the data it saves in the JSON file is not the seed bytes but the key pair, so 32-byte of private key and 32-byte of public key:
priv_key_bytes = bip44_ctx.PrivateKey().Raw().ToBytes()
pub_key_bytes = bip44_ctx.PublicKey().RawCompressed().ToBytes()[1:]
key_pair = priv_key_bytes + pub_key_bytes
print(list(key_pair))
These are the same bytes you'll find in the json file.
Amazing, I was about to give you a brief on how solana-cli
works, since I just started using bip_utils
and i don't know how all methods/classes works, yet.
Thanks for your fast and accurate feedback, worked flawlessly.
Keep in contact for future suggestions and questions
Using solana CLI to verify
seed
andpub_key
raises an error.Steps to Reproduce error
Code Used in Python
To validate credentials using Solana CLI.
sh -c "$(curl -sSfL https://release.solana.com/v1.7.3/install)"
seed_array file
is located and run the following commandsolana-keygen verify <public_key> <file_name_where_seed_array_is_stored>
Using the same output in this example i got the following:
If I recover the account using the same mnemonic from the example using the following command:
solana-keygen recover --force ASK
The recovered public_key is the following oneXhYnQXtkTdbycmGvaJ7xBaSzKMpYzLPm7mn36PkRhQ3
If I validate this
pub_key
with the seed_array running the command above:Any thoughts on why is it failing?