Simple usage example #496

issue josephernest openend this issue on January 8, 2018
  1. josephernest commented at 0:56 am on January 8, 2018: none

    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?
    
  2. elichai commented at 11:32 am on April 3, 2018: contributor
    :+1:
  3. afk11 commented at 12:39 pm on April 3, 2018: contributor

    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.

  4. jenokizm commented at 12:08 pm on May 6, 2018: none
    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?
  5. sipa commented at 5:45 pm on May 6, 2018: contributor
    EC private keys are just random bytes.
  6. gmaxwell commented at 11:17 am on February 20, 2019: contributor
    Dupe of #184
  7. gmaxwell closed this on Feb 20, 2019


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-30 03:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me