Nostr_sdk: derive npub from nsec

Using nostr_sdk fetching nsec and derving the npub

ever4st

23. Februar 2025February 23, 2025 · 1 Min. Lesezeit1 min read

Derive npub from nsec given as parameter

import argparse
import asyncio
from nostr_sdk import Keys, init_logger, LogLevel

async def main(nsec):
    init_logger(LogLevel.INFO)
    keys = Keys.parse(nsec)
    public_key = keys.public_key()
    print(f"Public key (hex): {public_key.to_hex()}")
    print(f"Public key (npub): {public_key.to_bech32()}")

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Fetch all relay from a given nsec')
    parser.add_argument('nsec', type=str, help='The nsec of the user')
    args = parser.parse_args()
    asyncio.run(main(args.nsec))

https://docs.rs/nostr_rust/latest/nostr_rust/keys/fn.get_public_key_from_secret.html

https://github.com/ev3rst/nostr_sdk_examples/blob/main/ns-derive-npub.py

#coding#nostr_sdk#nsec#programming#python

Written by

Comments

No comments yet. Start the conversation.