taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 920f4f0aedfa9640ee401a6e17e8eb272ceb32a0
parent 5ab5000d67b1e3abf7082c20af3b6026031b1976
Author: Florian Dold <dold@taler.net>
Date:   Wed, 25 Nov 2026 19:56:20 +0100

wallet database: store CS R-pairs with refresh sessions

Port the storage change from 2e954d002 to SQLite schema 32. Existing
sessions retain their seed and confirmed no-reveal index.

Co-authored-by: Özgür Kesim <oec@codeblau.de>
Issue: https://bugs.taler.net/n/12286

Diffstat:
Mpackages/taler-wallet-core/src/db/records.ts | 2++
Mpackages/taler-wallet-core/src/db/sqlite/schema-migrations.test.ts | 37+++++++++++++++++++++++++++++++++++++
Mpackages/taler-wallet-core/src/db/sqlite/schema.ts | 7++++++-
Mpackages/taler-wallet-core/src/db/sqlite/transaction.ts | 11++++++++---
Mpackages/taler-wallet-core/src/db/testing/conformance-cases.ts | 20++++++++++++++++++++
5 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/packages/taler-wallet-core/src/db/records.ts b/packages/taler-wallet-core/src/db/records.ts @@ -475,6 +475,8 @@ export interface WalletRefreshGroup { export interface WalletRefreshSession { /** Original CS seed when recovering a refresh made by another wallet. */ blindingSeed?: string; + /** Exchange R-pairs in CS output order, saved before submitting the melt. */ + csRPubs?: [string, string][]; /** The melt may have reached the exchange. Reconcile a rejection before changing outputs. */ autoRefreshMeltStarted?: boolean; refreshGroupId: string; diff --git a/packages/taler-wallet-core/src/db/sqlite/schema-migrations.test.ts b/packages/taler-wallet-core/src/db/sqlite/schema-migrations.test.ts @@ -861,6 +861,43 @@ test("refund snapshot migration preserves refunds across purchase deletion", asy } }); +test("schema 32 preserves a confirmed refresh from schema 31", async () => { + const { path, cleanup } = withTempDb(); + try { + let db = await openRaw(path); + await initSqliteWalletDb( + db, + schemaMigrations.filter((m) => m.version <= 31), + ); + await ( + await db.prepare(`INSERT INTO refresh_groups + (refresh_group_id, operation_status, currency, reason, old_coin_pubs, input_per_coin, + expected_output_per_coin, status_per_coin, refund_requests, timestamp_created) + VALUES ('old', 16777216, 'TESTKUDOS', 'manual', '["coin"]', '["TESTKUDOS:1"]', + '["TESTKUDOS:1"]', '[16777216]', '{}', 0)`) + ).run({}); + await ( + await db.prepare(`INSERT INTO refresh_sessions + (refresh_group_id, coin_index, session_public_seed, noreveal_index, new_denoms, amount_refresh_output) + VALUES ('old', 0, x'1234', 2, '[{"denomPubHash":"cs","count":1}]', 'TESTKUDOS:1')`) + ).run({}); + await db.close(); + db = await openRaw(path); + await initSqliteWalletDb(db); + const [row] = await queryAll( + db, + `SELECT hex(session_public_seed) AS seed, noreveal_index, cs_r_pubs + FROM refresh_sessions WHERE refresh_group_id = 'old'`, + ); + assert.equal(row.seed, "1234"); + assert.equal(row.noreveal_index, 2); + assert.strictEqual(row.cs_r_pubs, null); + await db.close(); + } finally { + cleanup(); + } +}); + test("refund snapshot backfill reads purchases from an upgraded database", async () => { const { path, cleanup } = withTempDb(); try { diff --git a/packages/taler-wallet-core/src/db/sqlite/schema.ts b/packages/taler-wallet-core/src/db/sqlite/schema.ts @@ -85,7 +85,7 @@ * * Bump this when adding a migration to {@link schemaMigrations}. */ -export const SQLITE_SCHEMA_VERSION = 31; +export const SQLITE_SCHEMA_VERSION = 32; /** * Tables of the IndexedDB emulation, children before parents. @@ -1610,6 +1610,11 @@ export const schemaMigrations: SchemaMigration[] = [ "CREATE INDEX refund_groups_by_status ON refund_groups (status)", ], }, + { + version: 32, + name: "refresh-cs-r-pubs", + statements: ["ALTER TABLE refresh_sessions ADD COLUMN cs_r_pubs TEXT"], + }, ]; /** Native data tables present after the specified migration. */ diff --git a/packages/taler-wallet-core/src/db/sqlite/transaction.ts b/packages/taler-wallet-core/src/db/sqlite/transaction.ts @@ -5468,6 +5468,7 @@ export class SqliteWalletTransaction implements WalletDbTransaction { ...(row.blinding_seed != null ? { blindingSeed: dbToCrock(row.blinding_seed) } : {}), + ...(row.cs_r_pubs != null ? { csRPubs: dbToJson(row.cs_r_pubs) } : {}), ...(row.session_public_seed != null ? { sessionPublicSeed: dbToCrock(row.session_public_seed) } : undefined), @@ -5500,8 +5501,10 @@ export class SqliteWalletTransaction implements WalletDbTransaction { `INSERT INTO refresh_sessions ( refresh_group_id, coin_index, session_public_seed, refresh_protocol_version, amount_refresh_output, new_denoms, - noreveal_index, last_error, auto_refresh_melt_started, blinding_seed - ) VALUES ($id, $idx, $seed, $rpv, $amt, $newDenoms, $nri, $err, $arms, $blindingSeed) + noreveal_index, last_error, auto_refresh_melt_started, blinding_seed, + cs_r_pubs + ) VALUES ($id, $idx, $seed, $rpv, $amt, $newDenoms, $nri, $err, $arms, $blindingSeed, + $csRPubs) ON CONFLICT(refresh_group_id, coin_index) DO UPDATE SET session_public_seed = excluded.session_public_seed, refresh_protocol_version = excluded.refresh_protocol_version, @@ -5510,12 +5513,14 @@ export class SqliteWalletTransaction implements WalletDbTransaction { noreveal_index = excluded.noreveal_index, last_error = excluded.last_error, auto_refresh_melt_started = excluded.auto_refresh_melt_started, - blinding_seed = excluded.blinding_seed`, + blinding_seed = excluded.blinding_seed, + cs_r_pubs = excluded.cs_r_pubs`, { id: rec.refreshGroupId, idx: rec.coinIndex, arms: boolToDb(rec.autoRefreshMeltStarted), blindingSeed: optCrockToDb(rec.blindingSeed), + csRPubs: rec.csRPubs === undefined ? null : jsonToDb(rec.csRPubs), seed: optCrockToDb(rec.sessionPublicSeed), rpv: rec.refreshProtocolVersion ?? null, amt: rec.amountRefreshOutput, diff --git a/packages/taler-wallet-core/src/db/testing/conformance-cases.ts b/packages/taler-wallet-core/src/db/testing/conformance-cases.ts @@ -1237,6 +1237,26 @@ export const conformanceCases: ConformanceCase[] = [ // ---------------------------------------------------------------- basics { + name: "refresh session: CS R-values survive a round trip", + async run(t, runner) { + const refresh = makeRefreshGroup("cs-r-refresh"); + const session = makeRefreshSession(refresh.refreshGroupId, 0); + session.csRPubs = [ + [ck("r0-a"), ck("r1-a")], + [ck("r0-b"), ck("r1-b")], + ]; + await runner.runReadWriteTx(async (tx) => { + await tx.upsertRefreshGroup(refresh); + await tx.upsertRefreshSession(session); + }); + const got = await runner.runReadWriteTx((tx) => + tx.getRefreshSession(refresh.refreshGroupId, 0), + ); + t.deepEqual(got?.csRPubs, session.csRPubs); + }, + }, + + { name: "config: upsert then get round trips", async run(t, runner) { await runner.runReadWriteTx(async (tx) => {