mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-03 12:41:45 +02:00
fix: notes locking/unlocking
This commit is contained in:
@@ -3,13 +3,13 @@ import { showPasswordDialog } from "../components/dialogs/passworddialog";
|
||||
|
||||
class Vault {
|
||||
static createVault() {
|
||||
return showPasswordDialog("create_vault", password =>
|
||||
return showPasswordDialog("create_vault", (password) =>
|
||||
db.vault.create(password)
|
||||
);
|
||||
}
|
||||
|
||||
static unlockVault() {
|
||||
return showPasswordDialog("unlock_vault", password => {
|
||||
return showPasswordDialog("unlock_vault", (password) => {
|
||||
return db.vault
|
||||
.unlock(password)
|
||||
.then(() => true)
|
||||
@@ -18,28 +18,31 @@ class Vault {
|
||||
}
|
||||
|
||||
static unlockNote(id, done) {
|
||||
showPasswordDialog("unlock_note", password => {
|
||||
showPasswordDialog("unlock_note", (password) => {
|
||||
return db.vault
|
||||
.remove(id, password)
|
||||
.then(() => true)
|
||||
.catch(e => {
|
||||
.catch((e) => {
|
||||
if (e.message === "ERR_WRNG_PWD") return false;
|
||||
else console.error(e);
|
||||
});
|
||||
}).then(res => res && done());
|
||||
}).then((res) => res && done());
|
||||
}
|
||||
|
||||
static openNote(id) {
|
||||
return showPasswordDialog("unlock_note", password => {
|
||||
return db.vault
|
||||
.open(id, password)
|
||||
.then(note => {
|
||||
return note.content;
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.message === "ERR_WRNG_PwD") return;
|
||||
else console.error(e);
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
showPasswordDialog("unlock_note", (password) => {
|
||||
return db.vault
|
||||
.open(id, password)
|
||||
.then((note) => {
|
||||
resolve(note.content);
|
||||
return true;
|
||||
})
|
||||
.catch((e) => {
|
||||
if (e.message === "ERR_WRNG_PwD") return;
|
||||
else console.error(e);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -57,7 +60,7 @@ class Vault {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.then(result => result && Vault.lockNote(id));
|
||||
.then((result) => result && Vault.lockNote(id));
|
||||
}
|
||||
}
|
||||
export default Vault;
|
||||
|
||||
@@ -38,14 +38,14 @@ class Crypto {
|
||||
};
|
||||
|
||||
_getKey = async (passwordOrKey) => {
|
||||
let key, salt;
|
||||
if (passwordOrKey.password) {
|
||||
const result = await this.deriveKey(passwordOrKey.password);
|
||||
let { salt, key, password } = passwordOrKey;
|
||||
if (password) {
|
||||
const result = await this.deriveKey(password, salt);
|
||||
key = result.key;
|
||||
salt = result.salt;
|
||||
} else if (passwordOrKey.key && passwordOrKey.salt) {
|
||||
} else if (key && salt) {
|
||||
salt = passwordOrKey.salt;
|
||||
key = this.sodium.from_base64(passwordOrKey.key);
|
||||
key = this.sodium.from_base64(key);
|
||||
}
|
||||
return { key, salt };
|
||||
};
|
||||
@@ -89,9 +89,9 @@ class Crypto {
|
||||
* @param {{password: string}|{key:string, salt: string}} passwordOrKey - password or derived key
|
||||
* @param {{salt: string, iv: string, cipher: string}} cipher - the cipher data
|
||||
*/
|
||||
decrypt = async (passwordOrKey, { iv, cipher }) => {
|
||||
decrypt = async (passwordOrKey, { iv, cipher, salt }) => {
|
||||
await this._initialize();
|
||||
const { key } = await this._getKey(passwordOrKey);
|
||||
const { key } = await this._getKey({ salt, ...passwordOrKey });
|
||||
|
||||
const plainText = this.sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||
undefined,
|
||||
|
||||
@@ -7251,9 +7251,9 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
|
||||
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
|
||||
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
|
||||
|
||||
"notes-core@git+ssh://git@github.com:thecodrr/notes-core.git":
|
||||
version "1.2.0"
|
||||
resolved "git+ssh://git@github.com:thecodrr/notes-core.git#61249bc5f6452c9490c1be77ba4b1b5489949400"
|
||||
"notes-core@git+ssh://git@github.com:streetwriters/notesnook-core.git":
|
||||
version "1.3.0"
|
||||
resolved "git+ssh://git@github.com:streetwriters/notesnook-core.git#51209ca353908393e54e810382c940eb158849fc"
|
||||
dependencies:
|
||||
fast-sort "^2.0.1"
|
||||
fuzzysearch "^1.0.3"
|
||||
|
||||
Reference in New Issue
Block a user