add external_id field for external use

This commit is contained in:
Lee Salminen 2022-08-29 14:51:18 -06:00
parent 81ed71a2e4
commit 4e63662f42
7 changed files with 30 additions and 9 deletions

View File

@ -22,7 +22,8 @@ The key #00, K0 (also know as auth key) is skipped to be use as authentification
So far, regarding the keys, the app can only write a new key set on an empty card (with zero keys). **When you write non zero (and 'non debug') keys, they can't be rewrite with this app.** You have to do it on your computer. So far, regarding the keys, the app can only write a new key set on an empty card (with zero keys). **When you write non zero (and 'non debug') keys, they can't be rewrite with this app.** You have to do it on your computer.
- Read the card with the app. Note UID so you can fill it in the extension later. - Read the card with the app. Note UID so you can fill it in the extension later.
- Write the link on the card. It shoud be like `YOUR_LNBITS_DOMAIN/boltcards/api/v1/scan/{card_uid}` - Write the link on the card. It shoud be like `YOUR_LNBITS_DOMAIN/boltcards/api/v1/scan/{external_id}`
- `{external_id}` should be replaced with the External ID found in the LNBits dialog.
- Add new card in the extension. - Add new card in the extension.
- Set a max sats per transaction. Any transaction greater than this amount will be rejected. - Set a max sats per transaction. Any transaction greater than this amount will be rejected.
@ -43,7 +44,7 @@ So far, regarding the keys, the app can only write a new key set on an empty car
Follow the guide. Follow the guide.
The URI should be `lnurlw://YOUR-DOMAIN.COM/boltcards/api/v1/scan/{YOUR_card_uid}?p=00000000000000000000000000000000&c=0000000000000000` The URI should be `lnurlw://YOUR-DOMAIN.COM/boltcards/api/v1/scan/{YOUR_card_external_id}?p=00000000000000000000000000000000&c=0000000000000000`
Then fill up the card parameters in the extension. Card Auth key (K0) can be omitted. Initical counter can be 0. Then fill up the card parameters in the extension. Card Auth key (K0) can be omitted. Initical counter can be 0.
@ -52,7 +53,7 @@ Then fill up the card parameters in the extension. Card Auth key (K0) can be omi
- In the TagWriter app tap Write tags - In the TagWriter app tap Write tags
- New Data Set > Link - New Data Set > Link
- Set URI type to Custom URL - Set URI type to Custom URL
- URL should look like lnurlw://YOUR_LNBITS_DOMAIN/boltcards/api/v1/scan/{YOUR_card_uid}?p=00000000000000000000000000000000&c=0000000000000000 - URL should look like lnurlw://YOUR_LNBITS_DOMAIN/boltcards/api/v1/scan/{YOUR_card_external_id}?p=00000000000000000000000000000000&c=0000000000000000
- click Configure mirroring options - click Configure mirroring options
- Select Card Type NTAG 424 DNA - Select Card Type NTAG 424 DNA
- Check Enable SDM Mirroring - Check Enable SDM Mirroring

View File

@ -9,11 +9,14 @@ from .models import Card, CreateCardData, Hit, Refund
async def create_card(data: CreateCardData, wallet_id: str) -> Card: async def create_card(data: CreateCardData, wallet_id: str) -> Card:
card_id = urlsafe_short_hash().upper() card_id = urlsafe_short_hash().upper()
extenal_id = urlsafe_short_hash().lower()
await db.execute( await db.execute(
""" """
INSERT INTO boltcards.cards ( INSERT INTO boltcards.cards (
id, id,
uid, uid,
external_id,
wallet, wallet,
card_name, card_name,
counter, counter,
@ -25,11 +28,12 @@ async def create_card(data: CreateCardData, wallet_id: str) -> Card:
k2, k2,
otp otp
) )
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", """,
( (
card_id, card_id,
data.uid.upper(), data.uid.upper(),
extenal_id,
wallet_id, wallet_id,
data.card_name, data.card_name,
data.counter, data.counter,
@ -95,6 +99,18 @@ async def get_card_by_uid(card_uid: str) -> Optional[Card]:
return Card.parse_obj(card) return Card.parse_obj(card)
async def get_card_by_external_id(external_id: str) -> Optional[Card]:
row = await db.fetchone(
"SELECT * FROM boltcards.cards WHERE external_id = ?", (external_id.lower(),)
)
if not row:
return None
card = dict(**row)
return Card.parse_obj(card)
async def get_card_by_otp(otp: str) -> Optional[Card]: async def get_card_by_otp(otp: str) -> Optional[Card]:
row = await db.fetchone("SELECT * FROM boltcards.cards WHERE otp = ?", (otp,)) row = await db.fetchone("SELECT * FROM boltcards.cards WHERE otp = ?", (otp,))
if not row: if not row:

View File

@ -26,8 +26,8 @@ from . import boltcards_ext
from .crud import ( from .crud import (
create_hit, create_hit,
get_card, get_card,
get_card_by_external_id,
get_card_by_otp, get_card_by_otp,
get_card_by_uid,
get_hit, get_hit,
get_hits_today, get_hits_today,
spend_hit, spend_hit,
@ -41,14 +41,14 @@ from .nxp424 import decryptSUN, getSunMAC
###############LNURLWITHDRAW################# ###############LNURLWITHDRAW#################
# /boltcards/api/v1/scan?p=00000000000000000000000000000000&c=0000000000000000 # /boltcards/api/v1/scan?p=00000000000000000000000000000000&c=0000000000000000
@boltcards_ext.get("/api/v1/scan/{card_uid}") @boltcards_ext.get("/api/v1/scan/{external_id}")
async def api_scan(p, c, request: Request, card_uid: str = None): async def api_scan(p, c, request: Request, external_id: str = None):
# some wallets send everything as lower case, no bueno # some wallets send everything as lower case, no bueno
p = p.upper() p = p.upper()
c = c.upper() c = c.upper()
card = None card = None
counter = b"" counter = b""
card = await get_card_by_uid(card_uid) card = await get_card_by_external_id(external_id)
if not card: if not card:
return {"status": "ERROR", "reason": "No card."} return {"status": "ERROR", "reason": "No card."}
if not card.enable: if not card.enable:

View File

@ -9,6 +9,7 @@ async def m001_initial(db):
wallet TEXT NOT NULL, wallet TEXT NOT NULL,
card_name TEXT NOT NULL, card_name TEXT NOT NULL,
uid TEXT NOT NULL UNIQUE, uid TEXT NOT NULL UNIQUE,
external_id TEXT NOT NULL UNIQUE,
counter INT NOT NULL DEFAULT 0, counter INT NOT NULL DEFAULT 0,
tx_limit TEXT NOT NULL, tx_limit TEXT NOT NULL,
daily_limit TEXT NOT NULL, daily_limit TEXT NOT NULL,

View File

@ -18,6 +18,7 @@ class Card(BaseModel):
wallet: str wallet: str
card_name: str card_name: str
uid: str uid: str
external_id: str
counter: int counter: int
tx_limit: int tx_limit: int
daily_limit: int daily_limit: int

View File

@ -259,6 +259,7 @@ new Vue({
link: window.location.origin + '/boltcards/api/v1/auth?a=' + card.otp, link: window.location.origin + '/boltcards/api/v1/auth?a=' + card.otp,
name: card.card_name, name: card.card_name,
uid: card.uid, uid: card.uid,
external_id: card.external_id,
k0: card.k0, k0: card.k0,
k1: card.k1, k1: card.k1,
k2: card.k2 k2: card.k2

View File

@ -376,6 +376,7 @@
<p style="word-break: break-all"> <p style="word-break: break-all">
<strong>Name:</strong> {{ qrCodeDialog.data.name }}<br /> <strong>Name:</strong> {{ qrCodeDialog.data.name }}<br />
<strong>UID:</strong> {{ qrCodeDialog.data.uid }}<br /> <strong>UID:</strong> {{ qrCodeDialog.data.uid }}<br />
<strong>External ID:</strong> {{ qrCodeDialog.data.external_id }}<br />
<strong>Lock key:</strong> {{ qrCodeDialog.data.k0 }}<br /> <strong>Lock key:</strong> {{ qrCodeDialog.data.k0 }}<br />
<strong>Meta key:</strong> {{ qrCodeDialog.data.k1 }}<br /> <strong>Meta key:</strong> {{ qrCodeDialog.data.k1 }}<br />
<strong>File key:</strong> {{ qrCodeDialog.data.k2 }}<br /> <strong>File key:</strong> {{ qrCodeDialog.data.k2 }}<br />
@ -386,7 +387,7 @@
unelevated unelevated
outline outline
color="grey" color="grey"
@click="copyText(lnurlLink + qrCodeDialog.data.uid)" @click="copyText(lnurlLink + qrCodeDialog.data.external_id)"
label="Base url (LNURL://)" label="Base url (LNURL://)"
> >
</q-btn> </q-btn>