Coder Social home page Coder Social logo

Comments (3)

csjones avatar csjones commented on June 1, 2024 1

Hey @pseudoramdom

You're correct, pubkeyHex does seem to be a x-only key. Maybe I'm misunderstanding what you're trying to accomplish but I don't think it makes sense to always pad a pubkeyHex with a [3] because the key's parity determines whether it should be padded with a [2] or [3]. Here is a thread about an approach bitcoin-core/secp256k1#1097

More recent versions of this package started the initial work to handle this conversion, looks like this:

let pubkeyHex = "11cc106e72c654b64bb037d0ccbe2ff47187fa5bb77330dd70398c2cb051fbd6"
let xonlyKey = try! secp256k1.Signing.XonlyKey(rawRepresentation: pubkeyHex.bytes, keyParity: 1)

This requires knowing the key's parity to correctly pad the public key automatically. I'd like to get to the ideal usage of:

let pubkeyHex = "11cc106e72c654b64bb037d0ccbe2ff47187fa5bb77330dd70398c2cb051fbd6"
let xonlyKey = try! secp256k1.Signing.XonlyKey(rawRepresentation: pubkeyHex.bytes)

Once we have a XonlyKey object, creating a secp256k1.Signing.PublicKey is simply one more line:

let pubkeyHex = "11cc106e72c654b64bb037d0ccbe2ff47187fa5bb77330dd70398c2cb051fbd6"
let xonlyKey = try! secp256k1.Signing.XonlyKey(rawRepresentation: pubkeyHex.bytes)
let pubKey = try! secp256k1.Signing.PublicKey(xonlyKey: xonlyKey)

from secp256k1.swift.

pseudoramdom avatar pseudoramdom commented on June 1, 2024 1

Got it. Thanks for clarifying. Much appreciated.

from secp256k1.swift.

pseudoramdom avatar pseudoramdom commented on June 1, 2024

(not a cryptography expert) I believe my pubkeyHex is an xOnlyKey. So I had to pad it with a [3] similar to https://github.com/GigaBitcoin/secp256k1.swift/pull/239/files

from secp256k1.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.