Last active
August 4, 2025 11:32
-
-
Save thaarok/829d3167a336152b92b50152d737c31f to your computer and use it in GitHub Desktop.
BIB32 keystores generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/ecdsa" | |
"fmt" | |
"github.com/ethereum/go-ethereum/accounts/keystore" | |
"log" | |
"github.com/ethereum/go-ethereum/crypto" | |
"github.com/tyler-smith/go-bip32" | |
"github.com/tyler-smith/go-bip39" | |
) | |
// generate BIB32 mnemonic, derive BIB44 key and store the private key in ethereum-json-keystore | |
func main() { | |
entropy, err := bip39.NewEntropy(256) // 24-word mnemonic | |
if err != nil { | |
log.Fatal(err) | |
} | |
mnemonic, err := bip39.NewMnemonic(entropy) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Mnemonic:", mnemonic) | |
seed := bip39.NewSeed(mnemonic, "") | |
masterKey, err := bip32.NewMasterKey(seed) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for i := uint32(0); i < 3; i++ { | |
// m/44'/60'/0'/0/i | |
childKey := masterKey | |
path := []uint32{bip32.FirstHardenedChild + 44, bip32.FirstHardenedChild + 60, bip32.FirstHardenedChild, 0, i} | |
for _, ix := range path { | |
childKey, err = childKey.NewChildKey(ix) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
privateKey, err := crypto.ToECDSA(childKey.Key) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("Address %d: %v\n", i, crypto.PubkeyToAddress(*privateKey.Public().(*ecdsa.PublicKey))) | |
ks := keystore.NewKeyStore("./", keystore.StandardScryptN, keystore.StandardScryptP) | |
acc, err := ks.ImportECDSA(privateKey, "password") | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("Keystore %d: %v\n", i, acc.URL.Path) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module keygen | |
go 1.24 | |
require ( | |
github.com/ethereum/go-ethereum v1.16.1 | |
github.com/tyler-smith/go-bip32 v1.0.0 | |
github.com/tyler-smith/go-bip39 v1.1.0 | |
) | |
require ( | |
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect | |
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect | |
github.com/bits-and-blooms/bitset v1.20.0 // indirect | |
github.com/consensys/gnark-crypto v0.18.0 // indirect | |
github.com/crate-crypto/go-eth-kzg v1.3.0 // indirect | |
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect | |
github.com/deckarep/golang-set/v2 v2.6.0 // indirect | |
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect | |
github.com/ethereum/c-kzg-4844/v2 v2.1.0 // indirect | |
github.com/ethereum/go-verkle v0.2.2 // indirect | |
github.com/fsnotify/fsnotify v1.6.0 // indirect | |
github.com/google/uuid v1.3.0 // indirect | |
github.com/holiman/uint256 v1.3.2 // indirect | |
github.com/supranational/blst v0.3.14 // indirect | |
golang.org/x/crypto v0.36.0 // indirect | |
golang.org/x/sync v0.12.0 // indirect | |
golang.org/x/sys v0.31.0 // indirect | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment