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

Differenct signature result with other libraries #296

Closed
FaiChou opened this issue Feb 15, 2023 · 3 comments
Closed

Differenct signature result with other libraries #296

FaiChou opened this issue Feb 15, 2023 · 3 comments

Comments

@FaiChou
Copy link

FaiChou commented Feb 15, 2023

I am using the sample code to test:

let privateBytes = try! "14E4A74438858920D8A35FB2D88677580B6A2EE9BE4E711AE34EC6B396D87B5C".bytes
let privateKey = try! secp256k1.Signing.PrivateKey(rawRepresentation: privateBytes)
print("private key: \(String(bytes: privateKey.rawRepresentation))")
print("public key: \(String(bytes: privateKey.publicKey.rawRepresentation))")
// ECDSA
let str = "We're all Satoshi."
let messageData = str.data(using: .utf8)!
let signature = try! privateKey.ecdsa.signature(for: messageData)
print("signature: \(String(bytes: signature.rawRepresentation))")

the results are:

private key: 14e4a74438858920d8a35fb2d88677580b6a2ee9be4e711ae34ec6b396d87b5c
public key: 02734b3511150a60fc8cac329cd5ff804555728740f2f2e98bc4242135ef5d5e4e
signature: 09b7cc8f9c570c6cec33e926615879c7b4ad0dbdfed2180d893f0de50d31063e1201f0847ea4b43c4e3f13955a19a53f52a9a7eddaec3368efa2a45d172bf456

When I put the same private key and message to the other libraries, the values are not the same, you can test on the website: https://paulmillr.com/noble/

image

@csjones
Copy link
Contributor

csjones commented Feb 15, 2023

Hi @FaiChou

Looks like you are trying to compare signatures with a compact representation. Have you tried using the compactRepresentation property?

let signature = try! privateKey.ecdsa.signature(for: messageData).compactRepresentation

@FaiChou FaiChou closed this as completed Feb 16, 2023
@FaiChou
Copy link
Author

FaiChou commented Feb 16, 2023

@csjones thanks, a great help

@aheze
Copy link

aheze commented Nov 20, 2024

Awesome, had the same issue and this worked great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants