diff --git a/src/mysky.ts b/src/mysky.ts index efc51b0f..3e4df29d 100644 --- a/src/mysky.ts +++ b/src/mysky.ts @@ -26,6 +26,7 @@ export const PORTAL_STORAGE_KEY = "portal"; export const SEED_STORAGE_KEY = "seed"; export const PORTAL_LOGIN_COMPLETE_SENTINEL_KEY = "portal-login-complete"; +const PORTAL_LOGIN_COMPLETE_SUCCESS_VALUE = "1"; export const INITIAL_PORTAL = "https://siasky.net"; @@ -717,7 +718,7 @@ export class MySky { await this.loginFromUi(seed); // Signal to MySky UI that we are done. - localStorage.setItem(PORTAL_LOGIN_COMPLETE_SENTINEL_KEY, "1"); + localStorage.setItem(PORTAL_LOGIN_COMPLETE_SENTINEL_KEY, PORTAL_LOGIN_COMPLETE_SUCCESS_VALUE); } catch (e) { log(`Error in storage event listener: ${e}`); @@ -888,7 +889,7 @@ export async function getCurrentAndReferrerDomains(): Promise<{ // anywhere else for now. let currentDomain; if (ALPHA_ENABLED && DEV_ENABLED) { - throw new Error("Alpha and dev modes cannot both be enbaled"); + throw new Error("Alpha and dev modes cannot both be enabled"); } else if (ALPHA_ENABLED) { currentDomain = "sandbridge.hns"; } else if (DEV_ENABLED) { diff --git a/src/provider.ts b/src/provider.ts index 507b26fb..d46ec1da 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -24,6 +24,10 @@ export type SeedProviderResponse = { action: SeedProviderAction; }; +// TODO: Either remove, or fully implement if we still want to have custom +// permissions providers. This is from when we decided that users can choose +// their own permissions providers, but we didn't yet have a way to access/save +// user settings. /** * Tries to get the saved permissions provider preference, returning the default provider if not found. * diff --git a/src/skydb_internal.ts b/src/skydb_internal.ts index c3065ce2..41cf5c67 100644 --- a/src/skydb_internal.ts +++ b/src/skydb_internal.ts @@ -21,7 +21,7 @@ import { log, validateObject, validateString } from "./util"; * Gets Encrypted JSON at the given path through MySky. * * @param client - The Skynet client. - * @param seed - The user seed. + * @param seed - The root MySky user seed. * @param path - The data path. * @returns - An object containing the decrypted json data. * @throws - Will throw if the user does not have Hidden Read permission on the path. @@ -57,7 +57,7 @@ export async function getJSONEncryptedInternal( * Sets Encrypted JSON at the given path through MySky. * * @param client - The Skynet client. - * @param seed - The user seed. + * @param seed - The root MySky user seed. * @param path - The data path. * @param json - The json to encrypt and set. * @returns - An object containing the original json data. @@ -80,36 +80,40 @@ export async function setJSONEncryptedInternal( const opts = { hashedDataKeyHex: true }; // Immediately fail if the mutex is not available. - return await client.db.revisionNumberCache.withCachedEntryLock(publicKey, dataKey, async (cachedRevisionEntry) => { - // Get the cached revision number before doing anything else. - const newRevision = incrementRevision(cachedRevisionEntry.revision); + return await client.db.revisionNumberCache.withCachedEntryLock( + publicKey, + dataKey, + async (cachedRevisionEntry: { revision: bigint }) => { + // Get the cached revision number before doing anything else. + const newRevision = incrementRevision(cachedRevisionEntry.revision); - // Derive the key. - const encryptionKey = deriveEncryptedFileKeyEntropy(pathSeed); + // Derive the key. + const encryptionKey = deriveEncryptedFileKeyEntropy(pathSeed); - // Pad and encrypt json file. - log("Calling encryptJSONFile"); - const data = encryptJSONFile(json, { version: ENCRYPTED_JSON_RESPONSE_VERSION }, encryptionKey); + // Pad and encrypt json file. + log("Calling encryptJSONFile"); + const data = encryptJSONFile(json, { version: ENCRYPTED_JSON_RESPONSE_VERSION }, encryptionKey); - log("Calling getOrCreateSkyDBRegistryEntry"); - const [entry] = await getOrCreateSkyDBRegistryEntry(client, dataKey, data, newRevision, opts); + log("Calling getOrCreateSkyDBRegistryEntry"); + const [entry] = await getOrCreateSkyDBRegistryEntry(client, dataKey, data, newRevision, opts); - // Sign the entry. - log("Calling signEncryptedRegistryEntryInternal"); - const signature = await signEncryptedRegistryEntryInternal(seed, entry, path); + // Sign the entry. + log("Calling signEncryptedRegistryEntryInternal"); + const signature = await signEncryptedRegistryEntryInternal(seed, entry, path); - log("Calling postSignedEntry"); - await client.registry.postSignedEntry(publicKey, entry, signature, opts); + log("Calling postSignedEntry"); + await client.registry.postSignedEntry(publicKey, entry, signature, opts); - return { data: json }; - }); + return { data: json }; + } + ); } /** * Gets the encrypted path seed for the given path without requiring * permissions. This should NOT be exported - for internal use only. * - * @param seed - The user seed. + * @param seed - The root MySky user seed. * @param path - The given file or directory path. * @param isDirectory - Whether the path corresponds to a directory. * @returns - The hex-encoded encrypted path seed. @@ -147,7 +151,7 @@ function incrementRevision(revision: bigint): bigint { * Signs the encrypted registry entry without requiring permissions. For * internal use only. * - * @param seed - The user seed. + * @param seed - The root MySky user seed. * @param entry - The encrypted registry entry. * @param path - The MySky path. * @returns - The signature. @@ -175,7 +179,7 @@ async function signEncryptedRegistryEntryInternal( * Internal version of `signRegistryEntryHelper` that does not check for * permissions. * - * @param seed - The user seed. + * @param seed - The root MySky user seed. * @param entry - The registry entry. * @returns - The signature. */ @@ -186,7 +190,5 @@ async function signRegistryEntryHelperInternal(seed: Uint8Array, entry: Registry const { privateKey } = genKeyPairFromSeed(seed); // Sign the entry. - const signature = await signEntry(privateKey, entry, true); - - return signature; + return await signEntry(privateKey, entry, true); } diff --git a/src/user_settings.ts b/src/user_settings.ts index eab0124e..a4cab487 100644 --- a/src/user_settings.ts +++ b/src/user_settings.ts @@ -16,7 +16,7 @@ type UserSettings = { portal: string | null; email: string | null }; * them if found. * * @param client - The Skynet client. - * @param seed - The user seed. + * @param seed - The root MySky user seed. * @param mySkyDomain - The domain of the current MySky instance. * @returns - The portal and email, if found. */ @@ -47,7 +47,7 @@ export async function getUserSettings( * Sets the user settings. * * @param client - The Skynet client. - * @param seed - The user seed. + * @param seed - The root MySky user seed. * @param mySkyDomain - The domain of the current MySky instance. * @param settings - The given user settings. */