Nostr Identification Protocol-06 (NIP-06)With Nostr Identification Protocol-06 (NIP-06), we have the basis for a key derivation method using a mnemonic seed phrase using the BIP32 (Bitcoin Improvement Proposal 32) protocol. We can then use the BIP39 protocol that will convert mnemonic seed words into a binary seed, and vice-versa. In this way we create a random key that can identify an account. In this case, we will generate a random seed value, and then use this to create a private key (sk) and then from this, we will create a public key (pk). |
Theory
With Nostr Identification Protocol-06 (NIP-06), we have the basis for a key derivation method using a mnemonic seed phrase using the BIP32 (Bitcoin Improvement Proposal 32) protocol. We can then use the BIP39 protocol that will convert mnemonic seed words into a binary seed, and vice-versa. In this way we create a random key that can identify an account. In this case, we will generate a random seed value, and then use this to create a private key (sk) and then from this, we will create a public key (pk). We can create seed words using:
words,_:=nip06.GenerateSeedWords()
and then generate a key seed from these words with:
seed:=nip06.SeedFromWords(words)
From this seed, we can now create a private key and a public key:
sk,_:=nip06.PrivateKeyFromSeed(seed) pk, _ := nostr.GetPublicKey(sk)
Code
The following is some sample code:
ppackage main import ( "fmt" "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip06" ) func main() { words,_:=nip06.GenerateSeedWords() fmt.Printf("Seed:\t%v\n",words) seed:=nip06.SeedFromWords(words) fmt.Printf("\nSeed:\t%x\n",seed) sk,_:=nip06.PrivateKeyFromSeed(seed) pk, _ := nostr.GetPublicKey(sk) nostr_priv, _ := nip19.EncodePrivateKey(sk) nostr_pub, _ := nip19.EncodePublicKey(pk) fmt.Printf("\n\nPrivate key:\t%v\n",sk) fmt.Printf("Public key:\t%v\n", pk) fmt.Printf("Private Nosstr encoded:\t%v\n",nostr_priv) fmt.Printf("Public Nosstr encoded\t%v\n",nostr_pub) }
And a sample run:
Seed: metal leaf fit intact live today twice spend traffic together this hawk palace rug sheriff satoshi float own update valley hat model electric earth Seed: f9a154e2a8759a26630b190466de71885e8ac6bc8a7d6b18fb1682d71aae7839e3c87acc38519196b0494a5bbaf582743eae14251ab4d5f17319e5f3f90c2f50 Private key: 0a045eb0d2744a2fa8f68303c2b6ce9d19b913e96c22152f6c60c9b1b68c705b Public key: df9ff61b710443e2e551164f4d4d510dc3fe2734876cbbf5acadbe212cd9560e Private Nosstr encoded: nsec1pgz9avxjw39zl28ksvpu9dkwn5vmjylfds3p2tmvvrymrd5vwpds5avtv9 Public Nosstr encoded npub1m70lvxm3q3p79e23ze856n23phplufe5sakthadv4klzztxe2c8q9nj3kf