By the way, here's a trivial utility to create an nsec/npub key pair using a BIP0039 conformant seed recovery mnemonic (such as one generated by BIP0085 key derivation):
#!/usr/bin/env python
## Tested under pyenv 3.10.5
# Standard Libraries:
import sys
## Requirements:
import bip39
from nostr.key import PrivateKey
## NOSTR derivation path from SLIP44
path = "m/44'/393'/0'/0/0"
if __name__ == '__main__':
if len(sys.argv[1:]) != 2:
print('Must supply mnemonic and passphrase as two arguments')
sys.exit(1)
mnemonic = sys.argv[1]
passphrase = sys.argv[2]
seed = bip39.phrase_to_seed(mnemonic, passphrase)
npriv = PrivateKey(seed[:32])
# Why only 32 octets and is the first half appropriate? Optimal?
print(npriv.bech32(), '\t', npriv.hex())
print(npriv.public_key.bech32(), '\t', npriv.public_key.hex())
To use code, simply paste it into a file, pip install nostr and bip39, and run it with a command like:
./bip39tonostr.py "$(cat mnemonic.txt)" "$PASSPHRASE"
β¦ where mnemonic.txt is a 12 or 24 word seed recovery mnemonic on a single line, separated by spaces.
As noted in the comments, I don't know why the nostr.key.PrivateKey() class initialization requires 32 bytes (of the 64 provided by bip39.phrase_to_seed()).
I don't know if all of this is cryptographically sound, and I'd rather have a qualified cryptographer or cryptologist review it before posting it to github.
USE AT YOUR OWN RISK (or don't use it at all).
If you break anything with this, you get to keep all the pieces.