minor refactor, cleanup

This commit is contained in:
Nystik
2026-03-11 22:08:30 +01:00
parent 2b9ebf1fbd
commit 9789be6d70
38 changed files with 259 additions and 379 deletions

View File

@@ -1,12 +1,5 @@
// Shim for crypto.scrypt
// Delegates to window.scrypt which is already loaded by Obsidian's own scrypt.js
export function scrypt(password, salt, keylen, options, callback) {
// Node signature: scrypt(password, salt, keylen, options, callback)
// Obsidian's app.js checks for window.require("crypto") and uses it if available,
// otherwise falls back to window.scrypt - so this shim just delegates to the latter.
if (typeof options === 'function') {
if (typeof options === "function") {
callback = options;
options = {};
}
@@ -16,14 +9,18 @@ export function scrypt(password, salt, keylen, options, callback) {
const p = options?.p || 1;
if (window.scrypt && window.scrypt.scrypt) {
// Use the browser scrypt library already loaded by Obsidian
const pwBytes = typeof password === 'string' ? new TextEncoder().encode(password) : password;
const saltBytes = typeof salt === 'string' ? new TextEncoder().encode(salt) : salt;
const pwBytes =
typeof password === "string"
? new TextEncoder().encode(password)
: password;
const saltBytes =
typeof salt === "string" ? new TextEncoder().encode(salt) : salt;
window.scrypt.scrypt(pwBytes, saltBytes, N, r, p, keylen)
window.scrypt
.scrypt(pwBytes, saltBytes, N, r, p, keylen)
.then((result) => callback(null, new Uint8Array(result)))
.catch((err) => callback(err));
} else {
callback(new Error('scrypt not available'));
callback(new Error("scrypt not available"));
}
}