Skip to content

Commit

Permalink
feat: mint sql auth db
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jan 9, 2025
1 parent 6c6b3f1 commit a5bbca7
Showing 5 changed files with 445 additions and 7 deletions.
17 changes: 10 additions & 7 deletions crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ use axum::middleware::Next;
use axum::response::Response;
use axum::{middleware, Router};
use bip39::Mnemonic;
use cdk::cdk_database::{self, MintDatabase, MintMemoryAuthDatabase};
use cdk::cdk_database::{self, MintDatabase};
use cdk::cdk_lightning;
use cdk::cdk_lightning::MintLightning;
use cdk::mint::{MintAuthDatabase, MintBuilder, MintMeltLimits};
@@ -31,6 +31,7 @@ use cdk_mintd::config::{self, DatabaseEngine, LnBackend};
use cdk_mintd::setup::LnBackendSetup;
use cdk_redb::mint::MintRedbAuthDatabase;
use cdk_redb::MintRedbDatabase;
use cdk_sqlite::mint::MintSqliteAuthDatabase;
use cdk_sqlite::MintSqliteDatabase;
use clap::Parser;
use tokio::sync::Notify;
@@ -373,12 +374,14 @@ async fn main() -> anyhow::Result<()> {

let auth_localstore: Arc<dyn MintAuthDatabase<Err = cdk_database::Error> + Send + Sync> =
match settings.database.engine {
DatabaseEngine::Sqlite => Arc::new(MintMemoryAuthDatabase::new(
None,
vec![],
vec![],
HashMap::new(),
)?),
DatabaseEngine::Sqlite => {
let sql_db_path = work_dir.join("cdk-mintd-auth.sqlite");
let sqlite_db = MintSqliteAuthDatabase::new(&sql_db_path).await?;

sqlite_db.migrate().await;

Arc::new(sqlite_db)
}
DatabaseEngine::Redb => {
let redb_path = work_dir.join("cdk-mintd-auth.redb");
Arc::new(MintRedbAuthDatabase::new(&redb_path)?)
37 changes: 37 additions & 0 deletions crates/cdk-sqlite/src/mint/auth/migrations/20250109143347_init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE TABLE IF NOT EXISTS proof (
y BLOB PRIMARY KEY,
keyset_id TEXT NOT NULL,
secret TEXT NOT NULL,
c BLOB NOT NULL,
state TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS state_index ON proof(state);
CREATE INDEX IF NOT EXISTS secret_index ON proof(secret);


-- Keysets Table

CREATE TABLE IF NOT EXISTS keyset (
id TEXT PRIMARY KEY,
unit TEXT NOT NULL,
active BOOL NOT NULL,
valid_from INTEGER NOT NULL,
valid_to INTEGER,
derivation_path TEXT NOT NULL,
max_order INTEGER NOT NULL,
derivation_path_index INTEGER NOT NULL
);

CREATE INDEX IF NOT EXISTS unit_index ON keyset(unit);
CREATE INDEX IF NOT EXISTS active_index ON keyset(active);


CREATE TABLE IF NOT EXISTS blind_signature (
y BLOB PRIMARY KEY,
amount INTEGER NOT NULL,
keyset_id TEXT NOT NULL,
c BLOB NOT NULL
);

CREATE INDEX IF NOT EXISTS keyset_id_index ON blind_signature(keyset_id);
Loading

0 comments on commit a5bbca7

Please sign in to comment.