Skip to content

Commit

Permalink
Merge pull request #5 from boltcard/card-pin-number
Browse files Browse the repository at this point in the history
Added card pin number api calls
  • Loading branch information
chloehjung15 authored Aug 6, 2023
2 parents 62d03f3 + 3376d15 commit 1106f17
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 3 deletions.
108 changes: 107 additions & 1 deletion controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,66 @@ router.post('/createboltcard', async function (req, res) {

})

//creates a boltcard with the wallet login id and the password and return a url
router.post('/createboltcardwithpin', async function (req, res) {
logger.log('/createboltcardwithpin', [req.id]);

let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
return errorBadAuth(res);
}
logger.log('/createboltcardwithpin', [req.id, 'userid: ' + u.getUserId()]);

//talk to the boltcard service and create a new card. get the keys.

let card_name = req.body.card_name;
var tx_max = 1000;
var day_max = 10000;
var enable = 'true';
var uid_privacy = 'false';
var allow_neg_bal = 'false';
var enable_pin = 'false';
var pin_limit_sats = 1000;


var query = `card_name=${card_name}&tx_max=${tx_max}&day_max=${day_max}&enable=${enable}&uid_privacy=${uid_privacy}&allow_neg_bal=${allow_neg_bal}&enable_pin=${enable_pin}&pin_limit_sats=${pin_limit_sats}`;
logger.log('/createboltcardwithpin', `${config.boltcardservice.url}/createboltcardwithpin?${query}`);

//call create bolt card
try {
var createReqResponse = await rp({uri: `${config.boltcardservice.url}/createboltcardwithpin?${query}`, json: true});

logger.log('/createboltcardwithpin CREATE RESPONSE', [createReqResponse]);
if(createReqResponse.status == "ERROR") {
return res.send({
error: true,
code: 6,
message: createReqResponse.reason,
});
}
if(createReqResponse.url) {
//return the url
return res.send(createReqResponse.url);
}
return res.send({
error: true,
code: 6,
message: 'not able to connect to bolt card service',
});


} catch (error) {
logger.log('/createboltcardwithpin ERROR RESPONSE', error.message);

return res.send({
error: true,
code: 6,
message: error.message,
});
}

})

//creates a boltcard with the wallet login id and the password and return keys as json
router.post('/getcardkeys', async function (req, res) {
logger.log('/getcardkeys', [req.id]);
Expand All @@ -671,9 +731,11 @@ router.post('/getcardkeys', async function (req, res) {
var enable = 'true';
var uid_privacy = 'false';
var allow_neg_bal = 'false';
var enable_pin = 'false';
var pin_limit_sats = 1000;


var query = `card_name=${card_name}&tx_max=${tx_max}&day_max=${day_max}&enable=${enable}&uid_privacy=${uid_privacy}&allow_neg_bal=${allow_neg_bal}`;
var query = `card_name=${card_name}&tx_max=${tx_max}&day_max=${day_max}&enable=${enable}&uid_privacy=${uid_privacy}&allow_neg_bal=${allow_neg_bal}&enable_pin=${enable_pin}&pin_limit_sats=${pin_limit_sats}`;
logger.log('/getcardkeys', `${config.boltcardservice.url}/createboltcard?${query}`);

//call create bolt card
Expand Down Expand Up @@ -845,6 +907,50 @@ router.post('/updatecard', async function (req, res) {

});

router.post('/updatecardwithpin', async function (req, res) {
logger.log('/updatecardwithpin', [req.id]);
// u.setCardDisabled(status);

let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
return errorBadAuth(res);
}
logger.log('/updatecardwithpin', [req.id, 'userid: ' + u.getUserId()]);

let tx_max = req.body.tx_max;
let enable = req.body.enable;
let card_name = req.body.card_name;
let day_max = req.body.day_max;
let enable_pin = req.body.enable_pin;
let pin_limit_sats = req.body.pin_limit_sats;
let pin_number_query = req.body.card_pin_number ? '&pin_number='+req.body.card_pin_number : '';
logger.log('/updatecardwithpin', [req.body]);

var query = `card_name=${card_name}&enable=${enable}&tx_max=${tx_max}&day_max=${day_max}&enable_pin=${enable_pin}&pin_limit_sats=${pin_limit_sats}${pin_number_query}`;

//talk to the boltcard service and update the card
try {
var response = await rp({uri: `${config.boltcardservice.url}/updateboltcardwithpin?${query}`, json: true});

if(response.status == "ERROR") {
return res.send({
error: true,
code: 6,
message: response.reason,
});
}
return res.send(response);

} catch (error) {
return res.send({
error: true,
code: 6,
message: error.message,
});
}

});

module.exports = router;

// ################# HELPERS ###########################
Expand Down
3 changes: 2 additions & 1 deletion controllers/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const lightning = require('../lightning');
const logger = require('../utils/logger');
const qr = require('qr-image');
const config = require('../config');
var pjson = require('../package.json');

let lightningGetInfo = {};
let lightningListChannels = {};
Expand Down Expand Up @@ -98,7 +99,7 @@ router.get('/', function (req, res) {
}
res.setHeader('Content-Type', 'text/html');
let html = fs.readFileSync('./templates/index.html').toString('utf8');
return res.status(200).send(mustache.render(html, Object.assign({}, lightningGetInfo, lightningListChannels)));
return res.status(200).send(mustache.render(html, Object.assign({"version_number": pjson.version}, lightningGetInfo, lightningListChannels)));
});

router.get('/qr', function (req, res) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lndhub",
"version": "1.4.2",
"version": "1.5.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ <h2>{{remote_pubkey}}</h2>
{{/uris}}
</div>
<footer>
<p>Version: v{{version_number}}</p>
<a href="https://github.com/boltcard" target="_blank">about</a> |
<a href="https://t.me/bolt_card" target="_blank">community</a>
</div>
Expand Down

0 comments on commit 1106f17

Please sign in to comment.