From 97209540b65fc9fb2b3ee8c96ddf5ec91a6aad7f Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 15 Mar 2014 18:10:46 -0300 Subject: [PATCH] add example to createKey --- examples/CreateKey.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/CreateKey.js diff --git a/examples/CreateKey.js b/examples/CreateKey.js new file mode 100644 index 0000000..91f5aa9 --- /dev/null +++ b/examples/CreateKey.js @@ -0,0 +1,42 @@ +'use strict'; + + +var run = function() { + // Replace '../bitcore' with 'bitcore' if you use this code elsewhere. + var bitcore = require('../bitcore'); + var networks = require('../networks'); + var WalletKey = bitcore.WalletKey; + + + function print(wk) { + + console.log('\n## Network: ' + wk.network.name); + console.log ('\t * Hex Representation'); + console.log ('\tPrivate: ' + bitcore.buffertools.toHex(wk.privKey.private)); + console.log ('\tPublic : ' + bitcore.buffertools.toHex(wk.privKey.public)); + console.log ('\tPublic Compressed : ' + (wk.privKey.compressed?'Yes':'No')); + + var wkObj = wk.storeObj(); + console.log ('\n * WalletKey Store Object'); + console.log ('\tPrivate: ' + wkObj.priv); + console.log ('\tPublic : ' + wkObj.pub); + console.log ('\tAddr : ' + wkObj.addr); + }; + + //Generate a new one + var wk = new WalletKey({network: networks.testnet}); + wk.generate(); + print(wk); + + //Generate from private Key WIF + var wk2 = new WalletKey({network: networks.testnet}); + wk2.fromObj({priv:'cS62Ej4SobZnpFQYN1PEEBr2KWf5sgRYYnELtumcG6WVCfxno39V'}); + print(wk2); + + +}; + +module.exports.run = run; +if (require.main === module) { + run(); +}