ncantu 8208809f03 UserWallet login flow, website-skeleton contract verify, data init/migrate
**Motivations:**
- Parcours login contrat: sélection service → membre → build path → proof, vérification côté parent (service-login-verify)
- Scripts data: initialisation SQLite (utxos, anchors, fees), migration depuis fichiers, sync UTXOs
- Website-skeleton: intégration contrat, extraction validateurs login, vérification preuve

**Root causes:**
- N/A (évolutions)

**Correctifs:**
- N/A

**Evolutions:**
- UserWallet: MemberSelectionScreen, LoginScreen machine à états (S_LOGIN_SELECT_SERVICE → S_LOGIN_SELECT_MEMBER → build path), service/membre via query params, useChannel/iframeChannel
- Website-skeleton: contract.ts (extractLoginValidators, isValidContract, isValidAction), main.ts validateurs depuis contrat, config étendu
- Data: init-db.js (tables utxos/anchors/fees), migrate-from-files.js

**Pages affectées:**
- data/init-db.js, data/migrate-from-files.js, data/sync-utxos.log
- userwallet: App, LoginCollectShare, LoginScreen, MemberSelectionScreen, ServiceListScreen, useChannel, iframeChannel
- website-skeleton: README, config, contract, main
2026-01-28 01:20:43 +01:00

96 lines
2.8 KiB
JavaScript

/**
* Script d'initialisation de la base de données SQLite
* Crée les tables et les index nécessaires
*/
import Database from 'better-sqlite3';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const dbPath = join(__dirname, 'signet.db');
const db = new Database(dbPath);
// Activer les clés étrangères
db.pragma('foreign_keys = ON');
// Table utxos
db.exec(`
CREATE TABLE IF NOT EXISTS utxos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
category TEXT NOT NULL,
txid TEXT NOT NULL,
vout INTEGER NOT NULL,
address TEXT,
amount REAL NOT NULL,
confirmations INTEGER DEFAULT 0,
is_anchor_change BOOLEAN DEFAULT FALSE,
block_time INTEGER,
is_spent_onchain BOOLEAN DEFAULT FALSE,
is_locked_in_mutex BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(txid, vout)
);
CREATE INDEX IF NOT EXISTS idx_utxos_category ON utxos(category);
CREATE INDEX IF NOT EXISTS idx_utxos_txid_vout ON utxos(txid, vout);
CREATE INDEX IF NOT EXISTS idx_utxos_confirmations ON utxos(confirmations);
CREATE INDEX IF NOT EXISTS idx_utxos_amount ON utxos(amount);
CREATE INDEX IF NOT EXISTS idx_utxos_is_spent ON utxos(is_spent_onchain);
`);
// Table anchors (hash_list.txt)
db.exec(`
CREATE TABLE IF NOT EXISTS anchors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
hash TEXT NOT NULL UNIQUE,
txid TEXT NOT NULL,
block_height INTEGER,
confirmations INTEGER DEFAULT 0,
date TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_anchors_hash ON anchors(hash);
CREATE INDEX IF NOT EXISTS idx_anchors_txid ON anchors(txid);
CREATE INDEX IF NOT EXISTS idx_anchors_block_height ON anchors(block_height);
`);
// Table fees (fees_list.txt)
db.exec(`
CREATE TABLE IF NOT EXISTS fees (
id INTEGER PRIMARY KEY AUTOINCREMENT,
txid TEXT NOT NULL UNIQUE,
fee REAL NOT NULL,
fee_sats INTEGER NOT NULL,
block_height INTEGER,
block_time INTEGER,
confirmations INTEGER DEFAULT 0,
change_address TEXT,
change_amount REAL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_fees_txid ON fees(txid);
CREATE INDEX IF NOT EXISTS idx_fees_block_height ON fees(block_height);
`);
// Table cache pour suivre les mises à jour
db.exec(`
CREATE TABLE IF NOT EXISTS cache (
key TEXT PRIMARY KEY,
value TEXT NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`);
console.log('✅ Base de données initialisée avec succès');
console.log(`📁 Fichier: ${dbPath}`);
db.close();