-
Notifications
You must be signed in to change notification settings - Fork 62
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
Recovery of pubic key when manually building signature #472
Comments
Hey @mikekelly 👋 Something seems off with the Here is the code I used to check: let sigHex = "283f5723bc367993c7492f8d79087b499e776012e0d744426e1be8e12d57264ab765f52dad6dac7df61d2209e875b037390c181b8c205ad47443c5bfea2f08c149"
let dataHex = "03a69666f5863ecc3b35ac143ef843f2a07ef98a76c09fba6bbd23ea36c7839602"
let sigData = Data(try! sigHex.bytes)
let data = Data(try! dataHex.bytes)
let sig = try! secp256k1.Recovery.ECDSASignature(dataRepresentation: sigData)
print(sig.dataRepresentation.base64EncodedString())
print(try! sig.compactRepresentation.recoveryId)
let expectedSignature = "rPnhleCU8vQOthm5h4gX/5UbmxH6w3zw1ykAmLvvtXT4YGKBoiMaP8eBBF8upN8IaTYmO7+o0Vyhf+cODD1uVgE="
let expectedDerSignature = Data(base64Encoded: expectedSignature, options: .ignoreUnknownCharacters)!
let expectedSig = try! secp256k1.Recovery.ECDSASignature(expectedDerSignature)
print(expectedSig.dataRepresentation.base64EncodedString())
print(try! expectedSig.compactRepresentation.recoveryId) And here is the output:
|
Hi @csjones thanks for having a look. To me, isn't the the rec id of
outputs
ie. the rec id is 40 according to the format? |
sorry, I meant the header is 40 - the rec id is 1 |
I'm not sure how you're getting a How is the signature being created? |
The signature comes from a closed source hardware wallet, doesn't 40 resolve to 1 according to this BIP? |
I can get around all of it by manually picking off the header, deriving the rec id, and then constructing the sig:
where
|
Thanks for the information. Yes, I see how the Might be helpful to use the bindings directly to recreate the issue. Additionally, I think this comment might be related: bitcoin-core/secp256k1#1024 (comment) |
Hey @mikekelly, Investigating this more, it seems we're mixing types, This line, The line that worked for you after dropping the header, |
Right, that makes sense. At some point it may be worth creating something like |
I like the idea and if you're interested in contributing, I'd gladly review the changes for acceptance. 😁 |
Yep for sure man! If/when I get the time to go back and refactor this into a class, I'll create a PR :) |
Hey @csjones, I'm encountering this error when trying to recover a public key:
Steps to reproduce:
I've dug around the library's source but I can't seem to resolve or figure out what I'm doing wrong. Is this a bug?
The text was updated successfully, but these errors were encountered: