Comments (4)
Thanks for the input, Chris!
After looking through the library, I think that the java library is producing the signature in form of compact representation, with the recovery id appended at the end to form a 65 bytes signature.
So I managed to reproduce the same signature as the java library using this
let compactSign = try privateKey.ecdsa.recoverableSignature(for: hashDigest).compactRepresentation
from secp256k1.swift.
Hey @piersonleo 👋 Is this the kind of example you're looking for?
let privateKey = try! secp256k1.Signing.PrivateKey()
let preHashedData = try! "f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342".bytes
let hashDigest = HashDigest(preHashedData)
let signature = try! privateKey.ecdsa.signature(for: hashDigest)
from secp256k1.swift.
Hi Chris, ah yes this is the example I'm looking for. Thank you.
Kinda unrelated, but I've also been using a secp256k1 library in java, but it seems that swift and java libraries returns a different signature result. Do you perhaps know the reason why it could result to that difference?
Here's a sample of the data and the results I got using both the java library and this library
privateKey string = "187dc06196cb99b99ee19afb876b79defd246cc123fb9e0c617345f77d3737df"
preHashedData = "34b90c9d26d0b19bdb348b31570d39bcda88bac94249f7219444a55bcaef1908"
java public key = "b6f264cc07e01b3e48a3ae3557ed752bc5caae20d6cd048af59d7065b47bada4056ee891d570b926c12b5e19af3c6e071b2d0b029f9dc4061391604178235fcf"
java signature result = "54c1d0eb6babd0124987d69d1870efaefbda5abb1ce10cd225a9aacab1b59de641f2c815a7a98db233ad3570a078c4d17a43f0ebb3f04e83e1c16ba260fbecc501"
swift public key = "03b6f264cc07e01b3e48a3ae3557ed752bc5caae20d6cd048af59d7065b47bada4"
swift signature result = "e69db5b1caaaa925d20ce11cbb5adafbaeef70189dd6874912d0ab6bebd0c154c5ecfb60a26bc1e1834ef0b3ebf0437ad1c478a07035ad33b28da9a715c8f241"
When i try to recover the public key and verify both of the signature result using the golang ecdsa library the java signature passed the verification while the swift signature fails.
from secp256k1.swift.
You're welcome Pierson 😁
Looking at the java library, my understanding is it leverages libsodium (this package uses libsecp256k1) and I'm not exactly sure how make these ends meet because subtle differences could end up with completely different outputs.
For example, the java public key you posted is uncompressed but doesn't include 04
which denotes key format. If we switch the swift public key format from compressed, 03
, to uncompressed - we will get the expected public key.
let expectedPrivateKey = "187dc06196cb99b99ee19afb876b79defd246cc123fb9e0c617345f77d3737df"
let privateKeyBytes = try! expectedPrivateKey.bytes
let privateKey = try! secp256k1.Signing.PrivateKey(rawRepresentation: privateKeyBytes, format: .uncompressed)
print(String(bytes: Array(privateKey.publicKey.rawRepresentation))) // 04b6f264cc07e01b3e48a3ae3557ed752bc5caae20d6cd048af59d7065b47bada4056ee891d570b926c12b5e19af3c6e071b2d0b029f9dc4061391604178235fcf
After completing the sanity check, we would want to start debugging the signatures themselves. First thing to notice is that the signatures are different character lengths. This makes me think of questions like, "What are the steps the java library used to create the signature?" and whether you'd get the result you're looking for by using the recovery signature API.
let recoverableSignature = try! privateKey.ecdsa.recoverableSignature(for: hashDigest)
Hope that helps!
from secp256k1.swift.
Related Issues (20)
- nvm I need the podspec for this, i'm so sorry... HOT 2
- Contructing a PublicKey with rawRepresentation fails with incorrect size HOT 3
- value of type `secp256k1_surjectionproof` has no member `data` HOT 13
- Differenct signature result with other libraries HOT 2
- Do you have any examples of how you would sign a taproot input using this library? HOT 1
- Did library already support sign a taproot input? HOT 4
- Taproot address format HOT 9
- Cannot install package via SPM when importing it from another package HOT 3
- Is it possible to generate an invalid PrivateKey when no secret it passed? HOT 9
- How to use secp256k1_ec_pubkey_combine HOT 10
- How to create PrivateKey by importing pem private key? HOT 7
- Test/Example for `sharedSecretFromKeyAgreement` with `handler`? HOT 8
- xcodebuild fails for 0.13.0 HOT 1
- secp256k1/ECDH.swift:180:20 Value of type 'UnsafeMutablePointer<UInt8>' has no member 'update' HOT 1
- #include "./secp256k1.h" Report an error './secp256k1.h' file not found HOT 6
- Is there really a random k injected when calculating an ECDSA signature ? HOT 2
- Recovery of pubic key when manually building signature HOT 11
- Please use semver for release tags HOT 1
- Add support for VisionOS HOT 4
- BitcoinSign Transaction HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from secp256k1.swift.