'use strict';

exports.up = async function (db) {
    const eddsaResult = await db.runSql('SELECT value FROM blobs WHERE id = ?', [ 'oidc_key_eddsa' ]);
    if (eddsaResult.length) {
        const key = JSON.parse(eddsaResult[0].value.toString('utf8'));
        key.alg = 'EdDSA';
        await db.runSql('UPDATE blobs SET value = ? WHERE id = ?', [ JSON.stringify(key), 'oidc_key_eddsa' ]);
    }

    const rs256Result = await db.runSql('SELECT value FROM blobs WHERE id = ?', [ 'oidc_key_rs256' ]);
    if (rs256Result.length) {
        const key = JSON.parse(rs256Result[0].value.toString('utf8'));
        key.alg = 'RS256';
        await db.runSql('UPDATE blobs SET value = ? WHERE id = ?', [ JSON.stringify(key), 'oidc_key_rs256' ]);
    }
};

exports.down = async function (db) {
};

