-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
36 lines (26 loc) · 897 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const os = require('os')
const path = require('path')
const keytar = require('keytar')
const bs = require('@signalapp/better-sqlite3') // https://github.com/signalapp/better-sqlite3
let db
async function getPassword() {
const key = await keytar.getPassword('com.kishanbagaria.jack', 'etilqs_key')
const keyBuffer = Buffer.from(key, 'base64')
const keyHex = keyBuffer.toString('hex')
return keyHex
}
async function getUnlockedDb() {
if (db) return db
const keyHex = await getPassword()
const dbPath = path.join(os.homedir(), 'Library/Application Support/jack/.index.db')
db = bs(dbPath)
const pragmaKeySql = `PRAGMA key = "x'${keyHex}'";`
db.exec(pragmaKeySql)
return db
}
async function findMessagesCount() {
const db = await getUnlockedDb()
const count = db.prepare('select count(*) from messages').pluck().get()
console.log({ count })
}
findMessagesCount()