From 4e8766ce08d5487a7b2952cadb9f9bccc098940f Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 25 Aug 2022 13:07:18 +0100 Subject: [PATCH 1/2] removed uid for justa card id --- lnbits/extensions/boltcards/crud.py | 2 -- lnbits/extensions/boltcards/lnurl.py | 14 +++++++------- lnbits/extensions/boltcards/static/js/index.js | 7 +------ .../boltcards/templates/boltcards/index.html | 13 +------------ 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/lnbits/extensions/boltcards/crud.py b/lnbits/extensions/boltcards/crud.py index 1a846d68..6d9f8b1c 100644 --- a/lnbits/extensions/boltcards/crud.py +++ b/lnbits/extensions/boltcards/crud.py @@ -15,7 +15,6 @@ async def create_card(data: CreateCardData, wallet_id: str) -> Card: id, wallet, card_name, - uid, counter, withdraw, k0, @@ -29,7 +28,6 @@ async def create_card(data: CreateCardData, wallet_id: str) -> Card: card_id, wallet_id, data.card_name, - data.uid.upper(), data.counter, data.withdraw, data.k0, diff --git a/lnbits/extensions/boltcards/lnurl.py b/lnbits/extensions/boltcards/lnurl.py index 5d98d28d..1d62199f 100644 --- a/lnbits/extensions/boltcards/lnurl.py +++ b/lnbits/extensions/boltcards/lnurl.py @@ -30,7 +30,7 @@ from .crud import ( create_hit, get_card, get_card_by_otp, - get_card_by_uid, + get_card, get_hit, get_hits_today, update_card, @@ -43,18 +43,18 @@ from .nxp424 import decryptSUN, getSunMAC ###############LNURLWITHDRAW################# # /boltcards/api/v1/scan?p=00000000000000000000000000000000&c=0000000000000000 -@boltcards_ext.get("/api/v1/scan/{card_uid}") -async def api_scan(p, c, request: Request, card_uid: str = None): +@boltcards_ext.get("/api/v1/scan/{card_id}") +async def api_scan(p, c, request: Request, card_id: str = None): # some wallets send everything as lower case, no bueno p = p.upper() c = c.upper() card = None counter = b"" try: - card = await get_card_by_uid(card_uid) - card_uid, counter = decryptSUN(bytes.fromhex(p), bytes.fromhex(card.k1)) + card = await get_card(card_id) + card_id, counter = decryptSUN(bytes.fromhex(p), bytes.fromhex(card.k1)) - if card.uid.upper() != card_uid.hex().upper(): + if card.uid.upper() != card_id.hex().upper(): return {"status": "ERROR", "reason": "Card UID mis-match."} except: return {"status": "ERROR", "reason": "Error decrypting card."} @@ -62,7 +62,7 @@ async def api_scan(p, c, request: Request, card_uid: str = None): if card == None: return {"status": "ERROR", "reason": "Unknown card."} - if c != getSunMAC(card_uid, counter, bytes.fromhex(card.k2)).hex().upper(): + if c != getSunMAC(card_id, counter, bytes.fromhex(card.k2)).hex().upper(): return {"status": "ERROR", "reason": "CMAC does not check."} ctr_int = int.from_bytes(counter, "little") diff --git a/lnbits/extensions/boltcards/static/js/index.js b/lnbits/extensions/boltcards/static/js/index.js index ff23c4d1..4ce6d759 100644 --- a/lnbits/extensions/boltcards/static/js/index.js +++ b/lnbits/extensions/boltcards/static/js/index.js @@ -150,7 +150,6 @@ new Vue({ }, getHits: function () { var self = this - LNbits.api .request( 'GET', @@ -167,7 +166,6 @@ new Vue({ }, getRefunds: function () { var self = this - LNbits.api .request( 'GET', @@ -184,7 +182,6 @@ new Vue({ }, openQrCodeDialog(cardId) { var card = _.findWhere(this.cards, {id: cardId}) - this.qrCodeDialog.data = { link: window.location.origin + '/boltcards/api/v1/auth?a=' + card.otp, name: card.card_name, @@ -197,11 +194,9 @@ new Vue({ }, addCardOpen: function () { this.cardDialog.show = true - var elem = this.$els.myBtn - elem.click() + this.generateKeys() }, generateKeys: function () { - const genRanHex = size => [...Array(size)] .map(() => Math.floor(Math.random() * 16).toString(16)) diff --git a/lnbits/extensions/boltcards/templates/boltcards/index.html b/lnbits/extensions/boltcards/templates/boltcards/index.html index d8421754..1c58f8e5 100644 --- a/lnbits/extensions/boltcards/templates/boltcards/index.html +++ b/lnbits/extensions/boltcards/templates/boltcards/index.html @@ -5,7 +5,7 @@
- Add Card @@ -187,7 +187,6 @@ label="Wallet *" > -
- - - From the NFC 424 ntag card that will be loaded - Date: Sat, 27 Aug 2022 17:26:17 +0100 Subject: [PATCH 2/2] bug --- .../extensions/boltcards/static/js/index.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lnbits/extensions/boltcards/static/js/index.js b/lnbits/extensions/boltcards/static/js/index.js index ceea0508..0575f342 100644 --- a/lnbits/extensions/boltcards/static/js/index.js +++ b/lnbits/extensions/boltcards/static/js/index.js @@ -9,6 +9,7 @@ const mapCards = obj => { return obj } + new Vue({ el: '#vue', mixins: [windowMixin], @@ -18,7 +19,6 @@ new Vue({ cards: [], hits: [], refunds: [], - lnurlLink: location.hostname + '/boltcards/api/v1/scan/', cardDialog: { show: false, data: { @@ -44,10 +44,10 @@ new Vue({ field: 'counter' }, { - name: 'uid', + name: 'withdraw', align: 'left', - label: 'Card ID', - field: 'uid' + label: 'Withdraw ID', + field: 'withdraw' } ], pagination: { @@ -66,7 +66,7 @@ new Vue({ name: 'refund_amount', align: 'left', label: 'Refund Amount', - field: 'oldrefund_amount_ctr' + field: 'refund_amount' }, { name: 'time', @@ -140,13 +140,12 @@ new Vue({ .request( 'GET', '/boltcards/api/v1/cards?all_wallets=true', - this.g.user.wallets[0].adminkey + this.g.user.wallets[0].inkey ) .then(function (response) { self.cards = response.data.map(function (obj) { return mapCards(obj) }) - console.log(self.cards) }) }, getHits: function () { @@ -162,7 +161,6 @@ new Vue({ obj.card_name = self.cards.find(d => d.id == obj.card_id).card_name return mapCards(obj) }) - console.log(self.hits) }) }, getRefunds: function () { @@ -175,10 +173,8 @@ new Vue({ ) .then(function (response) { self.refunds = response.data.map(function (obj) { - obj.card_name = self.cards.find(d => d.id == obj.card_id).card_name return mapCards(obj) }) - console.log(self.hits) }) }, openQrCodeDialog(cardId) { @@ -252,7 +248,6 @@ new Vue({ }, updateCardDialog: function (formId) { var card = _.findWhere(this.cards, {id: formId}) - console.log(card.id) this.cardDialog.data = _.clone(card) this.cardDialog.temp.k0 = this.cardDialog.data.k0 @@ -274,8 +269,6 @@ new Vue({ data.prev_k2 = this.cardDialog.temp.k2 } - console.log(data) - LNbits.api .request( 'PUT', @@ -320,7 +313,13 @@ new Vue({ }, exportCardsCSV: function () { LNbits.utils.exportCSV(this.cardsTable.columns, this.cards) - } + }, + exportHitsCSV: function () { + LNbits.utils.exportCSV(this.hitsTable.columns, this.hits) + }, + exportRefundsCSV: function () { + LNbits.utils.exportCSV(this.refundsTable.columns, this.refunds) + }, }, created: function () { if (this.g.user.wallets.length) {