'Solana Wallet Address Generation Mechanism

I'm looking to developing on Solana but...I love to understand what I'm Working on. I've take a look at the documentation, and I can't unuderstand how solana-keygen work. I've try so hard to reproduce the same public address from the same mnemonic but nothing seems to work. Anyone that know exactly how address is generated? If you have your private key how you derive the public without using @solana/web3 library.

import * as Bip39 from 'bip39'
import { Keypair } from "@solana/web3.js";

const seed: Buffer Bip39.mnemonicToSeedSync("title spell imitate observe kidney ready interest border inject quiz misery motor")

const derivedSeed = ed25519.derivePath("m/44'/501'/0'/0'", seed.toString('hex')).key;
const keyPair = Keypair.fromSeed(derivedSeed)
console.log(keyPair.publicKey.toString())   

This code work good, so if I go to https://solflare.com/access and try to insert mnemonic I can see the address.

But, in fact, solana-keygen return me this address with that mnemonic: nsaayLiawKPiui9fWYCpRdYkdKeqj2fNn9u8LjauEkn

This is a sample wallet. Feel free to experiment with this parameters.

Please, do not fund this wallet.

How it's possible to get the same address that solana-keygen give me?

I've try to pass all possible parameters on ed25519, pbkd2, but it seems that I'm missing something on the process.



Solution 1:[1]

Actually I ran into the same problem before. I still dont get it upto now. But I use another method to workaround. Basically I used solana-keygen recover 'prompt://?key=0/0' -o file.json to recover the keypair into a json. Then open the file and copy the private key back to the code and use let secretKey = Uint8Array.from(private key) to extract. You may find details from my blog https://medium.com/@lianxiongdi/solana-web3-tutorial-2-connect-your-web3-program-to-wallet-39b335f4b4b .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak