how can i generate a secp256k1 seckey in c to be used in libsecp256k1?

nostr:nprofile1qqsxwkuyle67y94tj378gw8w2xw2wa6nwmwlqhddlwnz0z7sztsaw2qppemhxue69uhkummn9ekx7mp0su9alh nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gprfmhxue69uhhq7tjv9kkjepwve5kzar2v9nzucm0d5hszxmhwden5te0wfjkccte9emk2um5v4exucn5vvhxxmmd9uq3xamnwvaz7tmhda6zuat50phjummwv5hsx7c9z9 nostr:nprofile1qqsr9cvzwc652r4m83d86ykplrnm9dg5gwdvzzn8ameanlvut35wy3gpz3mhxue69uhhyetvv9ujuerpd46hxtnfduq3qamnwvaz7tmwdaehgu3wwa5kuegpzemhxue69uhhyetvv9ujuurjd9kkzmpwdejhglzevy3

#asknostr #c

Reply to this note

Please Login to reply.

Discussion

There isn't a call to generate it in the API itself? (check in the .h file)

I guess it could also be just a constructor of course

no, i checked those files. i can drive a keypair from a seckey. but i can't generate a seckey. based on what i saw.

Right, i just looked. I think you just get 32 bytes from /dev/urandom, as it notes there you have a negligible chance of an invalid seckey. But also you can check there, right.

Mostly you just use bip32 master secrets ofc, in practice.

thanks a lot. i was thinking about that as well, but i thought its too simple to be real. that's wonderful!

generally im writing some golang bindings for this library and im trying to provide an api to generate a keypair. im not sure how much it makes sense at all. since the original source says you can read random bytes yourself.

Just use /dev/urandom if on linux. It's a pretty good randomness generator fit for crypto purposes.

Just read 32 bytes from it and feed it to a seckey.

Never reuse any of the same number in any capacity.

thanks a lot. going to try it tomorrow.

As other's have mentioned. A secret key is just a securely random 32byte number. That's it. The reason that libraries don't include this, is because there is no safe, unified, and guaranteed place to get random data from on all platforms.

yes, i understand the concept behind it. ive just leaved this part in my binding library as well. or at most i would add a secret key generate method with warning and documents about how it works.

the library: https://github.com/kehiy/go-secp256k1

i would appreciate any kind of contributions as well. 🫡

I have a project that might interest you, or at least make some things easier for you.

https://www.vaughnnugent.com/resources/software/modules/noscrypt

thanks a lot. i would take a look at it. 🫡