Created
October 17, 2023 15:15
-
-
Save ohac/0bc56e7c0463787509096a880ed76386 to your computer and use it in GitHub Desktop.
get Nostr nsec from BIP-0039 Mnemonic
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 ( | |
"fmt" | |
"github.com/nbd-wtf/go-nostr" | |
"github.com/nbd-wtf/go-nostr/nip19" | |
"github.com/tyler-smith/go-bip32" | |
"github.com/tyler-smith/go-bip39" | |
) | |
func main() { | |
//entropy, _ := bip39.NewEntropy(256) | |
entropy, _ := bip39.EntropyFromMnemonic("decide intact title offer slab wife swear family tumble initial sheriff dance canoe siren chicken wait eyebrow flee slide day slide boy patch average") | |
mnemonic, _ := bip39.NewMnemonic(entropy) | |
fmt.Println("Mnemonic: ", mnemonic) | |
secret := "" // or "Secret Passphrase" | |
seed := bip39.NewSeed(mnemonic, secret) | |
masterKey, _ := bip32.NewMasterKey(seed) | |
masterKey, _ = masterKey.NewChildKey(0) | |
s, _ := masterKey.Serialize() | |
raw := s[46:78] | |
hexstr := "" | |
for _, v := range raw { | |
hexstr += fmt.Sprintf("%02x", v) | |
} | |
pk, _ := nostr.GetPublicKey(hexstr) | |
nsec, _ := nip19.EncodePrivateKey(hexstr) | |
npub, _ := nip19.EncodePublicKey(pk) | |
fmt.Println(nsec) | |
fmt.Println(npub) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment