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

Add convenience methods for keys #430

Merged
merged 3 commits into from Apr 30, 2022

Commits on Apr 4, 2022

  1. Borrow secret key

    `SecretKey` implements `Copy` and it is fine to take owneship of it; we
    have multiple methods called `from_secret_key` and they all borrow the
    secret key parameter. Favour consistency over perfection.
    
    Borrow secret key parameter as is done in other `from_secret_key`
    methods.
    tcharding committed Apr 4, 2022
    Copy the full SHA
    c612130 View commit details
    Browse the repository at this point in the history
  2. Let the compiler work out int size

    We have two places in the code where we pass a mutable parity integer
    to ffi code. At one callsite we tell the compiler explicitly what type
    it is (`::secp256k1_sys::types::c_int`) and at the other call site we
    let the compiler figure out the type.
    
    Is one way better than the other? I don't know. But letting the compiler
    figure it out seems to make the code easier to read.
    tcharding committed Apr 4, 2022
    Copy the full SHA
    b4c7fa0 View commit details
    Browse the repository at this point in the history
  3. Add convenience methods for keys

    We have a bunch of `from_<key>` methods for converting between key types.
    To improve the API and make it more ergonomic to use we can add methods
    that do the same but can be called on the initial key instead of on the
    resulting key's type. E.g. once applied the following are equivalent:
    
    - `let pk = PublicKey::from_keypair(kp)`
    - `let pk = kp.public_key()`
    
    Do this for `SecretKey`, `PublicKey`, `KeyPair`, and `XOnlyKeyPair`.
    tcharding committed Apr 4, 2022
    Copy the full SHA
    f08276a View commit details
    Browse the repository at this point in the history