Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coinables/3505fa0c65031894325af9b954ea5bff to your computer and use it in GitHub Desktop.
Save coinables/3505fa0c65031894325af9b954ea5bff to your computer and use it in GitHub Desktop.
app.js
const express = require("express");
const request = require("request");
const bodyparser = require("body-parser");
const bitcore = require("bitcore-lib");
const app = express();
app.use(
bodyparser.urlencoded({
extended: true
})
);
app.use(bodyparser.json());
app.set("view engine", "ejs");
function brainWallet(uinput, callback) {
const input = new Buffer(uinput);
const hash = bitcore.crypto.Hash.sha256(input);
const bn = bitcore.crypto.BN.fromBuffer(hash);
const pk = new bitcore.PrivateKey(bn).toWIF();
const addy = new bitcore.PrivateKey(bn).toAddress();
callback(pk, addy);
}
request(
{
url: "https://api.coindesk.com/v1/bpi/currentprice.json",
json: true
},
(err, res, body) => {
price = body.bpi.USD.rate
priceFloat = parseFloat(price.replace(/,/g, ''));
}
);
app.get("/", (req, res) => {
res.render("index", {
lastPrice: priceFloat
});
});
app.get("/brain", (req, res) => {
res.render("brain", {
lastPrice: price
});
});
app.get("/converter", (req, res) => {
console.log(price);
res.render("converter", {
lastPrice: price
});
});
app.post("/wallet", (req, res) => {
const brainsrc = req.body.brainsrc;
console.log(brainsrc);
brainWallet(brainsrc, (priv, addr) => {
res.send(
"brain wallet of " +
brainsrc +
"<br>Addy: " +
addr +
"<br>Private Key: " +
priv
);
});
});
app.listen(3000, () => {
console.log("server started");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment