mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 10:34:20 +01:00
* produce dleq * start working on verification * wip dleq * Use C_ instead of C in verify DLEQ! (#176) * Fix comments (DLEQ sign error) * Fix alice_verify_dleq in d_dhke.py * Fix_generate_promise in ledger.py * Fix verify_proofs_dleq in wallet.py * Fix: invalid public key (#182) * Use C_ instead of C in verify DLEQ! * Fix comments (DLEQ sign error) * Fix alice_verify_dleq in d_dhke.py * Fix_generate_promise in ledger.py * Fix verify_proofs_dleq in wallet.py * Fix: invalid public key * Exception: Mint Error: invalid public key * Update cashu/wallet/wallet.py --------- Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> * Update cashu/core/b_dhke.py * Update tests/test_cli.py * verify all constructed proofs * dleq upon receive * serialize without dleq * all tests passing * make format * remove print * remove debug * option to send with dleq * add tests * fix test * deterministic p in step2_dleq and fix mypy error for hash_to_curve * test crypto/hash_e and crypto/step2_bob_dleq * rename A to K in b_dhke.py and test_alice_verify_dleq * rename tests * make format * store dleq in mint db (and readd balance view) * remove `r` from dleq in tests * add pending output * make format * works with pre-dleq mints * fix comments * make format * fix some tests * fix last test * test serialize dleq fix * flake * flake * keyset.id must be str * fix test decorators * start removing the duplicate fields from the dleq * format * remove print * cleanup * add type anotations to dleq functions * remove unnecessary fields from BlindedSignature * tests not working yet * spelling mistakes * spelling mistakes * fix more spelling mistakes * revert to normal * add comments * bdhke: generalize hash_e * remove P2PKSecret changes * revert tests for P2PKSecret * revert tests * revert test fully * revert p2pksecret changes * refactor proof invalidation * store dleq proofs in wallet db * make mypy happy --------- Co-authored-by: moonsettler <moonsettler@protonmail.com>
171 lines
4.9 KiB
Python
171 lines
4.9 KiB
Python
from ..core.db import Database, table_with_schema
|
|
|
|
|
|
async def m000_create_migrations_table(db: Database):
|
|
await db.execute(f"""
|
|
CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'dbversions')} (
|
|
db TEXT PRIMARY KEY,
|
|
version INT NOT NULL
|
|
)
|
|
""")
|
|
|
|
|
|
async def m001_initial(db: Database):
|
|
await db.execute(f"""
|
|
CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'promises')} (
|
|
amount {db.big_int} NOT NULL,
|
|
B_b TEXT NOT NULL,
|
|
C_b TEXT NOT NULL,
|
|
|
|
UNIQUE (B_b)
|
|
|
|
);
|
|
""")
|
|
|
|
await db.execute(f"""
|
|
CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_used')} (
|
|
amount {db.big_int} NOT NULL,
|
|
C TEXT NOT NULL,
|
|
secret TEXT NOT NULL,
|
|
|
|
UNIQUE (secret)
|
|
|
|
);
|
|
""")
|
|
|
|
await db.execute(f"""
|
|
CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'invoices')} (
|
|
amount {db.big_int} NOT NULL,
|
|
pr TEXT NOT NULL,
|
|
hash TEXT NOT NULL,
|
|
issued BOOL NOT NULL,
|
|
|
|
UNIQUE (hash)
|
|
|
|
);
|
|
""")
|
|
|
|
await db.execute(f"""
|
|
CREATE VIEW {table_with_schema(db, 'balance_issued')} AS
|
|
SELECT COALESCE(SUM(s), 0) AS balance FROM (
|
|
SELECT SUM(amount)
|
|
FROM {table_with_schema(db, 'promises')}
|
|
WHERE amount > 0
|
|
) AS s;
|
|
""")
|
|
|
|
await db.execute(f"""
|
|
CREATE VIEW {table_with_schema(db, 'balance_redeemed')} AS
|
|
SELECT COALESCE(SUM(s), 0) AS balance FROM (
|
|
SELECT SUM(amount)
|
|
FROM {table_with_schema(db, 'proofs_used')}
|
|
WHERE amount > 0
|
|
) AS s;
|
|
""")
|
|
|
|
await db.execute(f"""
|
|
CREATE VIEW {table_with_schema(db, 'balance')} AS
|
|
SELECT s_issued - s_used FROM (
|
|
SELECT bi.balance AS s_issued, bu.balance AS s_used
|
|
FROM {table_with_schema(db, 'balance_issued')} bi
|
|
CROSS JOIN {table_with_schema(db, 'balance_redeemed')} bu
|
|
) AS balance;
|
|
""")
|
|
|
|
|
|
async def m003_mint_keysets(db: Database):
|
|
"""
|
|
Stores mint keysets from different mints and epochs.
|
|
"""
|
|
await db.execute(f"""
|
|
CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'keysets')} (
|
|
id TEXT NOT NULL,
|
|
derivation_path TEXT,
|
|
valid_from TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
|
|
valid_to TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
|
|
first_seen TIMESTAMP NOT NULL DEFAULT {db.timestamp_now},
|
|
active BOOL DEFAULT TRUE,
|
|
|
|
UNIQUE (derivation_path)
|
|
|
|
);
|
|
""")
|
|
await db.execute(f"""
|
|
CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'mint_pubkeys')} (
|
|
id TEXT NOT NULL,
|
|
amount INTEGER NOT NULL,
|
|
pubkey TEXT NOT NULL,
|
|
|
|
UNIQUE (id, pubkey)
|
|
|
|
);
|
|
""")
|
|
|
|
|
|
async def m004_keysets_add_version(db: Database):
|
|
"""
|
|
Column that remembers with which version
|
|
"""
|
|
await db.execute(
|
|
f"ALTER TABLE {table_with_schema(db, 'keysets')} ADD COLUMN version TEXT"
|
|
)
|
|
|
|
|
|
async def m005_pending_proofs_table(db: Database) -> None:
|
|
"""
|
|
Store pending proofs.
|
|
"""
|
|
await db.execute(f"""
|
|
CREATE TABLE IF NOT EXISTS {table_with_schema(db, 'proofs_pending')} (
|
|
amount INTEGER NOT NULL,
|
|
C TEXT NOT NULL,
|
|
secret TEXT NOT NULL,
|
|
|
|
UNIQUE (secret)
|
|
|
|
);
|
|
""")
|
|
|
|
|
|
async def m006_invoices_add_payment_hash(db: Database):
|
|
"""
|
|
Column that remembers the payment_hash as we're using
|
|
the column hash as a random identifier now
|
|
(see https://github.com/cashubtc/nuts/pull/14).
|
|
"""
|
|
await db.execute(
|
|
f"ALTER TABLE {table_with_schema(db, 'invoices')} ADD COLUMN payment_hash TEXT"
|
|
)
|
|
await db.execute(
|
|
f"UPDATE {table_with_schema(db, 'invoices')} SET payment_hash = hash"
|
|
)
|
|
|
|
|
|
async def m007_proofs_and_promises_store_id(db: Database):
|
|
"""
|
|
Column that remembers the payment_hash as we're using
|
|
the column hash as a random identifier now
|
|
(see https://github.com/cashubtc/nuts/pull/14).
|
|
"""
|
|
await db.execute(
|
|
f"ALTER TABLE {table_with_schema(db, 'proofs_used')} ADD COLUMN id TEXT"
|
|
)
|
|
await db.execute(
|
|
f"ALTER TABLE {table_with_schema(db, 'proofs_pending')} ADD COLUMN id TEXT"
|
|
)
|
|
await db.execute(
|
|
f"ALTER TABLE {table_with_schema(db, 'promises')} ADD COLUMN id TEXT"
|
|
)
|
|
|
|
|
|
async def m008_promises_dleq(db: Database):
|
|
"""
|
|
Add columns for DLEQ proof to promises table.
|
|
"""
|
|
await db.execute(
|
|
f"ALTER TABLE {table_with_schema(db, 'promises')} ADD COLUMN e TEXT"
|
|
)
|
|
await db.execute(
|
|
f"ALTER TABLE {table_with_schema(db, 'promises')} ADD COLUMN s TEXT"
|
|
)
|