Closed coincrypto closed 6 years ago
What value is not correct?
var CoinKey = require('coinkey'); var ci = require('coininfo'); var ck = CoinKey.createRandom(ci('DCR')); const result = { address: ck.publicAddress } console.log(JSON.stringify(result));
I'm sorry I'm not familiar with Go in https://github.com/decred/dcrd/ so I could not find correct value. But please take a look code above, your lib can run well with Litecoin, MonaCoin, Bitcoin, Dash...except Decred. It generate wrong Decred address, I guess it has some missing value in your config. Please take a look....
But Decred uses blake256 and address versions is 2 byte instead 1.
Simplified example:
const payload = Buffer.alloc(2 + 20)
payload.writeUInt16BE(coinInfo(decred).versions.public)
const hash32 = createBlakeHash('blake256').update(publicKey).digest()
const hash20 = crypto.createHash('ripemd160').update(hash32).digest()
hash20.copy(payload, 2)
return bs58check.encode(payload)
I got it, thank you!
var CoinKey = require('coinkey');
var ci = require('coininfo');
var bs58check = require('bs58check')
var createBlakeHash = require('blake-hash')
var crypto = require('crypto')
const args = process.argv;
const network = 'DCR';
var ck = CoinKey.createRandom(ci(network));
var publicKey = ck.publicKey;
var payload = Buffer.allocUnsafe(22)
payload.writeUInt16BE(ci(network).versions.public)
var hash32 = createBlakeHash('blake256').update(publicKey).digest()
var hash20 = crypto.createHash('ripemd160').update(hash32).digest()
hash20.copy(payload, 2)
console.log(bs58check.encode(payload))
@fanatid I'm sorry to bother you again, I tried to test your guide with code above, It will generate a DCR address (for example: Dsb2wKQRGwJchRod3Rr17CfHwkgoCoUUipD). But this address is not valid on DCR network. https://mainnet.decred.org/api/addr/Dsb2wKQRGwJchRod3Rr17CfHwkgoCoUUipD/balance
Example of correct address here: https://mainnet.decred.org/api/addr/DsZKDL4fXKwMiEVv1RhEk33KHBJ6UVeVV1K/balance
I'm a newbie and I tried on google but I could not find solution :( Please take a look when you have time. Your help is greatly appreciated Thank you very much!
This code generated wallet addresses not work on decred mainnet network.
coininfo for dcr https://github.com/cryptocoinjs/coininfo/blob/master/lib/coins/dcr.js is not correct now. Please help to fix.