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
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
which validates the address without relying on any third party api/service calls.
decodedBase58Result
for DBKh7QAP9gkXncVK32jtfae4QXChPwsyKH
would be 1e43d1c5e88853622efe39e7a838cebf01cf3029589a614274
.
crypto.createHash('sha256').update(crypto.createHash('sha256').update((new Buffer('1e43d1c5e88853622efe39e7a838cebf01cf3029589a614274', 'hex')).slice(0,21)).digest('buffer')).digest('buffer')
<SlowBuffer 9a 61 42 74 97 0b 64 ae 2e 7f d6 f8 b1 81 90 12 f3 5e 3a 0b a1 f4 f2 c2 47 fe 20 7e 4f a1 27 25>
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.