update create_bolt_card API

This commit is contained in:
Peter Rounce 2022-08-24 09:03:50 +00:00
parent 1fd70e31d6
commit 8edb9a3993
28 changed files with 2365 additions and 140 deletions

View file

@ -46,7 +46,14 @@ func db_delete_expired() error {
return nil
}
func db_insert_card(one_time_code string, lock_key string, aes_cmac string) error {
func db_insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k3 string, k4 string,
tx_max_sats int, day_max_sats int, enable_flag bool, card_name string) error {
enable_flag_yn := "N"
if enable_flag == true {
enable_flag_yn = "Y"
}
db, err := db_open()
if err != nil {
@ -57,10 +64,12 @@ func db_insert_card(one_time_code string, lock_key string, aes_cmac string) erro
// insert a new record into cards
sqlStatement := `INSERT INTO cards` +
` (one_time_code, lock_key, aes_cmac, uid, last_counter_value,` +
` lnurlw_request_timeout_sec, tx_limit_sats, day_limit_sats, one_time_code_used)` +
` VALUES ($1, $2, $3, '', 0, 60, 1000, 10000, 'N');`
res, err := db.Exec(sqlStatement, one_time_code, lock_key, aes_cmac)
` (one_time_code, k0_auth_key, k2_cmac_key, k3, k4, uid, last_counter_value,` +
` lnurlw_request_timeout_sec, tx_limit_sats, day_limit_sats, enable_flag,` +
` one_time_code_used, card_name)` +
` VALUES ($1, $2, $3, $4, $5, '', 0, 60, $6, $7, $8, 'N', $9);`
res, err := db.Exec(sqlStatement, one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
tx_max_sats, day_max_sats, enable_flag_yn, card_name)
if err != nil {
return err
}

View file

@ -3,6 +3,7 @@ package main
import (
"crypto/rand"
"encoding/hex"
"flag"
"fmt"
log "github.com/sirupsen/logrus"
qrcode "github.com/skip2/go-qrcode"
@ -21,13 +22,37 @@ func random_hex() string {
}
func main() {
help_flag_ptr := flag.Bool("help", false, "show the command line options")
tx_max_ptr := flag.Int("tx_max", 0, "set the maximum satoshis per transaction")
day_max_ptr := flag.Int("day_max", 0, "set the maximum satoshis per day (24 hours)")
enable_flag_ptr := flag.Bool("enable", false, "enable the card for payments")
card_name_ptr := flag.String("name", "", "set a name for the card")
flag.Parse()
// handle -help
if *help_flag_ptr == true {
flag.PrintDefaults()
return
}
fmt.Println()
fmt.Println("use './createboltcard -help' to show command line options")
// create the keys
one_time_code := random_hex()
lock_key := random_hex()
aes_cmac := random_hex()
k0_auth_key := random_hex()
k2_cmac_key := random_hex()
k3 := random_hex()
k4 := random_hex()
// create the new card record
err := db_insert_card(one_time_code, lock_key, aes_cmac)
err := db_insert_card(one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
*tx_max_ptr, *day_max_ptr, *enable_flag_ptr, *card_name_ptr)
if err != nil {
log.Warn(err.Error())
return
@ -45,7 +70,9 @@ func main() {
hostdomain := os.Getenv("HOST_DOMAIN")
url := "https://" + hostdomain + "/new?a=" + one_time_code
fmt.Println()
fmt.Println(url)
fmt.Println()
q, err := qrcode.New(url, qrcode.Medium)
fmt.Println(q.ToSmallString(false))
}