Following is my code:

const bip39 = require("bip39");
var HDKey = require('hdkey');
var bip32 = require("bip32");
var bitcoin = require('bitcore-lib');
var EthereumBip44 = require('ethereum-bip44');
const secp256k1 = require('secp256k1')
var sha256 = require("sha256")

var mnemonic = bip39.generateMnemonic()
var seed = bip39.mnemonicToSeedSync(mnemonic).toString('hex');
var hdkey = HDKey.fromMasterSeed(seed);
var HDkey = hdkey.privateExtendedKey
var node = bip32.fromBase58(HDkey)
var child = node.derivePath("m/44'/0'/0'/0/0");
bitcoinKey = child.toWIF();
var key = bitcoin.HDPrivateKey(HDkey);
var wallet = new EthereumBip44(key);
var ethereumKey = wallet.getPrivateKey(0).toString('hex')
console.log('PK: %s',ethereumKey)
var re = secp256k1.publicKeyCreate(Buffer.from(ethereumKey,"hex"), false).slice(1)
var cicAddress = "cx"+sha256("0x"+re.toString("hex")).substr(24,64)
console.log('Public key: %s',re);
console.log('CIC Address: %s',cicAddress)

This gives me following output:

Seed: 3eef6daf3a65b84448a699837a476033a792f413041d080da2a18a77f462cd9a2f76ca4e922dfb8de0d2817a3b092a098d7f335993a0554e3e997e1eab22daaa

PK: f4c06b254d5ac46b6db9baf0fbdfb4b58aa392002f0808d54dfd3ceed5697967 �*x��� key: c�b�!��^�Q �����͇R��9��2$7K�+��)m����g�K5�Ǽ=]��e�����m CIC Address: cxb2d307b96327e2e535a52f93c23751417520398d

Why the public key is getting generated symbollically? How can I solve this?

  • This seems like a basic programming question, rather than something Bitcoin related. You'll need a function to turn the public key object into something human readable. One way of doing so is already on the line above: re.toString("hex"). Jun 14 '19 at 14:42
  • Thanx @Pieter Wuille for the comment. It gives expected output.
    – Varsh
    Jun 15 '19 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.