Comments (3)
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:
- Generate a standard BIP39 seed
- Take the first 32-byte of this seed and use it directly as a private key (it's not computing the private key using HMAC-SHA512 like in BIP32, so the FromSeed method is not suitable for this, but it's just considering the bytes as the private key)
- Get the public key from the private key and compute the address
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.
from bip_utils.
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.
from bip_utils.
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
from bip_utils.
Related Issues (20)
- ImportError: cannot import 'Bip32' from 'bip_utils' HOT 1
- WifDecoder throws error when presented with the Optional 0x01 suffix for a privatekey with a compressed public key HOT 7
- How to use uncompressed public key mode for derivation? HOT 2
- Errors when generating BIP86 taproot addresses HOT 6
- Generate Secret Key using mnemonic seeds for Pi Network HOT 1
- Not installing on M1 w/Python 3.11.4 HOT 5
- support for Injective HOT 6
- Generator Etherum and Ripple XRP address HOT 1
- Language error when using ElectrumV1MnemonicDecoder HOT 4
- atomic XRP HOT 1
- Update PyPi to latest changes HOT 1
- problem create address from mnemonic CARDANO HOT 8
- Problem installing "ed25519-blake2b" HOT 1
- Ed25519 missing variables, invalid escape sequence, atrribute error? HOT 2
- Typo
- Creating P2SH Addresses for Networks Without SegWit Support HOT 1
- How to derive BTC address from BIP39? HOT 1
- How to derive address using bip_32_ctx HOT 3
- Deriving a bip44 address with chain code and PrivateKey swapped HOT 8
- ImportError: cannot import name 'Bip44Ethereum' from 'bip_utils.bip.conf.bip44' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bip_utils.