Nostr Identification Protocol-06 (NIP-06)
Nostr (Notes and Other Stuff Transmitted by Relays) uses clients and relays, and where users run clients, and where anyone can be a relay. Users identify themselves with these public key, and every post to a relay is then signed. There is no communications between relays, and each relay only services its associated clients. A client then subscribes by posting their public key to the relay and then receives updates in a chronological manner.
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)
The following is some sample code [here]:
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 [here]:
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
We can see that we have 32 words, and 128 hex characters. This gives 512 bits of a seed value. BIP32 was created by Pieter Wuilla in order to support for the recover of Bitcoin wallets. It focuses on deriving a private and public key from a master seed.