Bitcoin Forum
May 05, 2024, 08:51:44 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Generating key pair for nostr protocol with Schnorr standard and secp256k1 curve  (Read 66 times)
darkv0rt3x (OP)
Hero Member
*****
Offline Offline

Activity: 1204
Merit: 658


I rather die on my feet than to live on my knees


View Profile
June 15, 2023, 11:36:15 AM
Merited by RickDeckard (2), hugeblack (1)
 #1

Hi.

I would like to create my own code to generate a key pair to use with nostr protocol which is the way we are identified in the network. It's like the username and password.

From their github docs:
https://github.com/nostr-protocol/nips/blob/master/01.md

they send us to https://bips.xyz/340 to generate the keys. However, this is the a depth I didn't want to have to go through.

Then, I found an example code for Schnorr sigs and secp256k1 but in the Bitcoin Core repository but probably, the example code is not exactly what the nostr protocol asks.

I would like some help and guidance to be able to write my own piece of code to generate my own keys to use them in the nostr protocol!

Bitcoin is energy. Bitcoin is freedom
I rather die on my feet than living on my knees!
1714942304
Hero Member
*
Offline Offline

Posts: 1714942304

View Profile Personal Message (Offline)

Ignore
1714942304
Reply with quote  #2

1714942304
Report to moderator
Make sure you back up your wallet regularly! Unlike a bank account, nobody can help you if you lose access to your BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714942304
Hero Member
*
Offline Offline

Posts: 1714942304

View Profile Personal Message (Offline)

Ignore
1714942304
Reply with quote  #2

1714942304
Report to moderator
1714942304
Hero Member
*
Offline Offline

Posts: 1714942304

View Profile Personal Message (Offline)

Ignore
1714942304
Reply with quote  #2

1714942304
Report to moderator
1714942304
Hero Member
*
Offline Offline

Posts: 1714942304

View Profile Personal Message (Offline)

Ignore
1714942304
Reply with quote  #2

1714942304
Report to moderator
Carlton Banks
Legendary
*
Offline Offline

Activity: 3430
Merit: 3071



View Profile
June 16, 2023, 10:06:51 PM
Merited by hugeblack (3), darkv0rt3x (1)
 #2

is it not detailed in the nostr protocol documents? Huh edit: sorry, I can't read Cheesy

I imagine they've used the exact same method that Bitcoin uses, which means you could do some copy-pasta funny business directly from the appropriate section of Bitcoin Core's code, providing you're either writing C++ or that the pertaining portion of the code is valid C, in which case you could use C instead (not much consolation seeing as writing good C is arguably even harder than writing good C++)

AFAIR, BIP 340's use of schnorr sigs over the secp256k curve was previously not something anyone else had done (at least in publicly available code, I believe schnorr signatures were still patented in the early days of Bitcoin, and so segwit v1 was one of the first widespread uses of schnorr sigs after the patent expired). with that in mind, there's probably no better place to go than BIP340 and it's implementation in the Bitcoin Core codebase

Vires in numeris
darkv0rt3x (OP)
Hero Member
*****
Offline Offline

Activity: 1204
Merit: 658


I rather die on my feet than to live on my knees


View Profile
June 17, 2023, 10:15:25 PM
 #3

is it not detailed in the nostr protocol documents? Huh edit: sorry, I can't read Cheesy

I imagine they've used the exact same method that Bitcoin uses, which means you could do some copy-pasta funny business directly from the appropriate section of Bitcoin Core's code, providing you're either writing C++ or that the pertaining portion of the code is valid C, in which case you could use C instead (not much consolation seeing as writing good C is arguably even harder than writing good C++)

AFAIR, BIP 340's use of schnorr sigs over the secp256k curve was previously not something anyone else had done (at least in publicly available code, I believe schnorr signatures were still patented in the early days of Bitcoin, and so segwit v1 was one of the first widespread uses of schnorr sigs after the patent expired). with that in mind, there's probably no better place to go than BIP340 and it's implementation in the Bitcoin Core codebase

I didn't read the entire nostr protocol documentation. In fact, I stop when they send us to that link I posted in my original post. It goes to a depth I didn't want to go.
However, after searching a bit more, I found an example code for schnorr over secp256k1 in Bitcoin Core github repository. I was able to compile it and run the example, giving me a pair of keys that are working in nostr!

There are some other nuances in the nostr protocol that changes the keys so that they are a bit more readable by prefixing a few chars and probably a few other mechanisms, but I think I don't even care about those.
For now, I just want to experiment a bit this protocol.

the example from Bitcoin Core repository I found and used is this:
https://github.com/bitcoin-core/secp256k1/blob/master/examples/schnorr.c

Bitcoin is energy. Bitcoin is freedom
I rather die on my feet than living on my knees!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!