How to generate a keypair correctly with Stellar/go?

How to generate a keypair correctly with Stellar/go?

Manage alerts

Loading saved threads...

User · External communityPost link
External question — Stellar Stack Exchange Author: User Original post: https://stellar.stackexchange.com/questions/4551 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Take test seed here: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md seed : "e0eec84fe165cd427cb7bc9b6cfdef0555aa1cb6f9043ff1fe986c3c8ddd22e3" correct result : m/44'/148'/0' GDRXE2BQUC3AZNPVFSCEZ76NJ3WWL25FYFK6RGZGIEKWE4SOOHSUJUJ6 SBGWSG6BTNCKCOB3DIFBGCVMUPQFYPA2G4O34RMTB343OYPXU5DJDVMN How to properly turn seed into a correct result (keypair)? Trying: import ( "github.com/stellar/go/keypair" ) var seeds [32]byte copy(seeds[:], []byte("e0eec84fe165cd427cb7bc9b6cfdef0555aa1cb6f9043ff1fe986c3c8ddd22e3")) pair, err := keypair.FromRawSeed(seeds) xlmAddr := pair.Address() xlmPK := pair.Seed() fmt.Println(xlmAddr) fmt.Println(xlmPK) Result is different...
Quote
Report
User · External communityPost link
External answer — Stellar Stack Exchange Author: User Original post: https://stellar.stackexchange.com/a/4552 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Perhaps someone will need it, https://github.com/stellar/go/issues/3478 I tried to change it to this: xlmSeed, _ := hex.DecodeString("e0eec84fe165cd427cb7bc9b6cfdef0555aa1cb6f9043ff1fe986c3c8ddd22e3") xlmKey, err := xlmDrv.DeriveForPath(xlmDrv.StellarPrimaryAccountPath, xlmSeed) pair, err := keypair.FromRawSeed(xlmKey.RawSeed()) fmt.Println(pair.Seed()) fmt.Println(pair.Address()) Still the wrong result. But it turned out to be wrong... overcat(Jun Luo) answered in my question: You should use BIP39 Seed in SEP-05, not m/44'/148' key. If you want to reproduce test 1 in SEP-10, please use the following code. package main import ( "encoding/hex" "fmt" "github.com/stellar/go/exp/crypto/derivation" "github.com/stellar/go/keypair" ) func main() { // I ignored all errors. bip39Seed, _ := hex.DecodeString("e4a5a632e70943ae7f07659df1332160937fad82587216a4c64315a0fb39497ee4a01f76ddab4cba68147977f3a147b6ad584c41808e8238a07f6cc4b582f186") for i := 0; i < 10; i++ { path := fmt.Sprintf(derivation.StellarAccountPathFormat, i) key, _ := derivation.DeriveForPath(path, bip39Seed) keyPair, _ := keypair.FromRawSeed(key.RawSeed()) fmt.Printf("%s %s %s\n", path, keyPair.Address(), keyPair.Seed()) } } Actually m/44'/148' key is the intermediate value generated during the calculation, if you are interested in it, add a breakpoint here and explore k.Key.
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stellar Stack Exchange Author: User Source score (net votes, not local likes): 0 Original post: https://stellar.stackexchange.com/a/4552 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Perhaps someone will need it, https://github.com/stellar/go/issues/3478 I tried to change it to this: xlmSeed, _ := hex.DecodeString("e0eec84fe165cd427cb7bc9b6cfdef0555aa1cb6f9043ff1fe986c3c8ddd22e3") xlmKey, err := xlmDrv.DeriveForPath(xlmDrv.StellarPrimaryAccountPath, xlmSeed) pair, err := keypair.FromRawSeed(xlmKey.RawSeed()) fmt.Println(pair.Seed()) fmt.Println(pair.Address()) Still the wrong result. But it turned out to be wrong... overcat(Jun Luo) answered in my question: You should use BIP39 Seed in SEP-05, not m/44'/148' key. If you want to reproduce test 1 in SEP-10, please use the following code. package main import ( "encoding/hex" "fmt" "github.com/stellar/go/exp/crypto/derivation" "github.com/stellar/go/keypair" ) func main() { // I ignored all errors. bip39Seed, _ := hex.DecodeString("e4a5a632e70943ae7f07659df1332160937fad82587216a4c64315a0fb39497ee4a01f76ddab4cba68147977f3a147b6ad584c41808e8238a07f6cc4b582f186") for i := 0; i < 10; i++ { path := fmt.Sprintf(derivation.StellarAccountPathFormat, i) key, _ := derivation.DeriveForPath(path, bip39Seed) keyPair, _ := keypair.FromRawSeed(key.RawSeed()) fmt.Printf("%s %s %s\n", path, keyPair.Address(), keyPair.Seed()) } } Actually m/44'/148' key is the intermediate value generated during the calculation, if you are interested in it, add a breakpoint here and explore k.Key.

Cancel quote

Checking account access…