Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple usage example #496

Closed
josephernest opened this issue Jan 8, 2018 · 5 comments
Closed

Simple usage example #496

josephernest opened this issue Jan 8, 2018 · 5 comments

Comments

@josephernest
Copy link

It would be interesting to provide a simple usage example in C / C++, i.e. how to use the library on an input private key to produce an output public key, ready to be SHA256d and RIPEMD160d.

Example:

// private key: abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234
unsigned char private[32] = { 0xAB, 0xCD, 0x12, 0x34, 0xAB, 0xCD, 0x12, 0x34, 0xAB, 0xCD, 0x12, 0x34, 0xAB, 0xCD, 0x12, 0x34, 0xAB, 0xCD, 0x12, 0x34, 0xAB, 0xCD, 0x12, 0x34, 0xAB, 0xCD, 0x12, 0x34, 0xAB, 0xCD, 0x12, 0x34 };

unsigned char pub[65] = ?secp256k1_pub_from_pvt?(private);   // which function to use here?
unsigned char pub_compr[33] = ?secp256k1_pub_compr_from_pvt?(private);
unsigned char hash160[20] = ripemd160(sha256(...));         // what is the common implementation used here?
@elichai
Copy link
Contributor

elichai commented Apr 3, 2018

👍

@afk11
Copy link
Contributor

afk11 commented Apr 3, 2018

The best place to start is the header file:

Creating a context: https://github.com/bitcoin-core/secp256k1/blob/master/include/secp256k1.h#L182
Creating a public key: https://github.com/bitcoin-core/secp256k1/blob/master/include/secp256k1.h#L518
Serialize a public key (for hashing): https://github.com/bitcoin-core/secp256k1/blob/master/include/secp256k1.h#L317

For example usage, see the tests.

@jenokizm
Copy link

jenokizm commented May 6, 2018

Hi! secret key this is the private key? If so, how to generate it?
and how to get key as string or char array for printf or cout to console?

@sipa
Copy link
Contributor

sipa commented May 6, 2018

EC private keys are just random bytes.

@gmaxwell
Copy link
Contributor

Dupe of #184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants