Something went wrong. Try again.
Share secure logs from the command line
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344import { DatabaseSync } from "node:sqlite";import { randomBytes } from "node:crypto";import { DB_PATH } from "./constants.js";
const db = new DatabaseSync(DB_PATH || ":memory:");
db.exec(` CREATE TABLE IF NOT EXISTS gists ( uuid TEXT PRIMARY KEY, iv TEXT NOT NULL, cipherText BLOB NOT NULL, createdAt DATETIME DEFAULT CURRENT_TIMESTAMP );`);
/** * @param {Uint8Array<ArrayBuffer>} iv * @param {ArrayBuffer} cipherText * @return {string} uuid */export const addGist = (iv, cipherText) => { const uuid = randomBytes(16).toString("base64url"); // 22 length const query = db.prepare( "INSERT INTO gists (uuid, iv, cipherText) VALUES (?, ?, ?)", ); query.run(uuid, iv.toString(), Buffer.from(cipherText));
return uuid;};
/** * @typedef {Object} PartialGist * @property {string} iv * @property {ArrayBuffer} cipherText * * @param {string} uuid * @return {PartialGist|undefined} {iv, cipherText} */export const getGist = (uuid) => { const query = db.prepare("SELECT cipherText, iv FROM gists WHERE uuid = ?");
return query.get(uuid);};