Author

Topic: How to verify ECDSA of a sample litecoin tx using pycoin? (Read 5065 times)

member
Activity: 88
Merit: 12
Thank you very much! Seeing your ArrayUtils.reverse clarified what the issue was for me.

When I reversed the hash, I turned "1234" into "4321", where as it should have been "3412".
sr. member
Activity: 467
Merit: 267
Should work with the hash reversed

Code:
    Security.addProvider(new BouncyCastleProvider())
    val bigR = BigInt(Hex.decode("258ad2725e66da0ae9825bb849a8e73f86e4767cf256c9fae44d18fbc1aacc2e"))
    val bigS = BigInt(Hex.decode("406638a5b3369bb83d8a4f38a17b2f048c1495ebfd6fdff1a8c7b268e07f69cd"))
    val pub = Hex.decode("03ec539eb3d882c07575f6143d891c18d580cd9d2726add0d71d262f2f6f2d4ccf")
    val hash = Hex.decode("eed300fc63a973b668af66af746fde378ec6556f4b330ec1eeccc6a77aa535b0")
    ArrayUtils.reverse(hash)

    val f = KeyFactory.getInstance("ECDSA", "BC");
    val ecSpec = ECNamedCurveTable.getParameterSpec("secp256k1")
    val ecDomain = new ECDomainParameters(ecSpec.getCurve, ecSpec.getG, ecSpec.getN)
    val signer = new ECDSASigner

    val pubKey = ecSpec.getCurve().decodePoint(pub)
    val params = new ECPublicKeyParameters(pubKey, ecDomain)
    signer.init(false, params)
    val check = signer.verifySignature(hash, bigR.bigInteger, bigS.bigInteger)
   
    println(bigR, bigS)
    println(pubKey)
    println(Hex.toHexString(hash))
    println(check)

Code:
(16980852742628685644910148209432903671752523748137798365042615749252787915822,29128631674996429161026020280872095602306489412358940898112602484852964420045)
(ec539eb3d882c07575f6143d891c18d580cd9d2726add0d71d262f2f6f2d4ccf,227874efbedb02b88568b55106634b9b4e3eca128ab46fa98abe7066aece0a51,1)
b035a57aa7c6cceec10e334b6f55c68e37de6f74af66af68b673a963fc00d3ee
true
member
Activity: 88
Merit: 12
I had not tried reversing the hash. I tried, still no luck.

Thank you, though.
sr. member
Activity: 467
Merit: 267
Did you try reversing the bytes of the hash? The ToString() seems to be flipping them.
member
Activity: 88
Merit: 12
The question is laid out here: http://bitcoin.stackexchange.com/questions/32194/how-to-verify-ecdsa-of-a-sample-litecoin-tx-using-pycoin

Looking for some help, might even give a BTC tip for a really good answer!
Jump to: