You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import * as EteSync from './api/EteSync';
|
|
|
|
import { CredentialsData, UserInfoData } from './store';
|
|
import { addEntries } from './store/actions';
|
|
|
|
export function createJournalEntry(
|
|
etesync: CredentialsData,
|
|
userInfo: UserInfoData,
|
|
journal: EteSync.Journal,
|
|
prevUid: string | null,
|
|
action: EteSync.SyncEntryAction,
|
|
content: string) {
|
|
|
|
const syncEntry = new EteSync.SyncEntry();
|
|
syncEntry.action = action;
|
|
syncEntry.content = content;
|
|
|
|
return createJournalEntryFromSyncEntry(etesync, userInfo, journal, prevUid, syncEntry);
|
|
}
|
|
|
|
export function createJournalEntryFromSyncEntry(
|
|
etesync: CredentialsData,
|
|
userInfo: UserInfoData,
|
|
journal: EteSync.Journal,
|
|
prevUid: string | null,
|
|
syncEntry: EteSync.SyncEntry) {
|
|
|
|
const derived = etesync.encryptionKey;
|
|
|
|
let cryptoManager: EteSync.CryptoManager;
|
|
if (journal.key) {
|
|
const keyPair = userInfo.getKeyPair(new EteSync.CryptoManager(derived, 'userInfo', userInfo.version));
|
|
const asymmetricCryptoManager = new EteSync.AsymmetricCryptoManager(keyPair);
|
|
const derivedJournalKey = asymmetricCryptoManager.decryptBytes(journal.key);
|
|
cryptoManager = EteSync.CryptoManager.fromDerivedKey(derivedJournalKey, journal.version);
|
|
} else {
|
|
cryptoManager = new EteSync.CryptoManager(derived, journal.uid, journal.version);
|
|
}
|
|
const entry = new EteSync.Entry();
|
|
entry.setSyncEntry(cryptoManager, syncEntry, prevUid);
|
|
|
|
return entry;
|
|
}
|
|
|
|
export function addJournalEntry(
|
|
etesync: CredentialsData,
|
|
userInfo: UserInfoData,
|
|
journal: EteSync.Journal,
|
|
prevUid: string | null,
|
|
action: EteSync.SyncEntryAction,
|
|
content: string) {
|
|
|
|
const entry = createJournalEntry(etesync, userInfo, journal, prevUid, action, content);
|
|
return addEntries(etesync, journal.uid, [entry], prevUid);
|
|
}
|