i'm trying to validate a dogecoin address using node.js javascript.
But i'm still trying to understand, the algorithm.
my current node.js version is v0.10.22
from what i was able to understand (correct me if i'm wrong) its a dogecoin address is no different from a bitcoin address.
So i try to do the following
- Base58 decode the address
- calculate sha256 of the returned result of a sha256 of the decoded address (two times sha256)
- do a comparison of the first 4 bytes of sha256 result with the last 4 bytes of the decoded address (i think i'm making a mistake here) ..
when i attempted to write this to javascript the base58 decoded result is correct, when i try to create a buffer from the decoded value , it throws error pointing that the value is not correct
var decodedHex = new Buffer(decodedBase58Result,'hex')
the above throws an error, if i do decodedBase58Result.toString()
which will stringify the number the script continues but doesn't return expected result.
So, is there a solution to this? without depending on third-party api calls
Update: i researched a lot and i found a client-side validator, with a small piece of code i made an npm package
which validates the address without relying on any third party api/service calls.
decodedBase58Result
forDBKh7QAP9gkXncVK32jtfae4QXChPwsyKH
would be1e43d1c5e88853622efe39e7a838cebf01cf3029589a614274
.Compare last 4 bytes from the address -
...9a614274
- with the resulting hash -9a614274...
, if you get a match, address is valid.So no, it's the same as bitcoin, code samples are here.
5.868133917508844e+59
is an address decoded as an integer. The issue with it is that javascript uses 52 bits to represent integers, but you have 200 bit address. So the decoder you're using won't work here.