From 35315ca5f3ff1f9a208ebaa3992d995f4ca62973 Mon Sep 17 00:00:00 2001 From: Shibo Lyu Date: Mon, 14 Apr 2025 03:40:51 +0800 Subject: [PATCH] fix(accounts): Do not attempt to decode ID key if password is not provided --- .../accounts/{identityFileDB.ts => identityDB.ts} | 0 src/lib/accounts/manager.svelte.ts | 13 +++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) rename src/lib/accounts/{identityFileDB.ts => identityDB.ts} (100%) diff --git a/src/lib/accounts/identityFileDB.ts b/src/lib/accounts/identityDB.ts similarity index 100% rename from src/lib/accounts/identityFileDB.ts rename to src/lib/accounts/identityDB.ts diff --git a/src/lib/accounts/manager.svelte.ts b/src/lib/accounts/manager.svelte.ts index bcfbc1d..714a122 100644 --- a/src/lib/accounts/manager.svelte.ts +++ b/src/lib/accounts/manager.svelte.ts @@ -4,7 +4,7 @@ import { type BlahIdentityDescription, type BlahProfile } from '@blah-im/core/identity'; -import { type IdentityDB, openIdentityDB } from './identityFileDB'; +import { type IdentityDB, openIdentityDB } from './identityDB'; import { BlahKeyPair } from '@blah-im/core/crypto'; import { browser } from '$app/environment'; @@ -89,15 +89,16 @@ class AccountManager { const accountCreds = await this.keyDB.fetchAccount(idKeyId); const encodedIdKeyPair = accountCreds?.encodedIdKeyPair; - const idKeyPair = encodedIdKeyPair - ? await BlahKeyPair.fromEncoded(encodedIdKeyPair, password) - : undefined; + const idKeyPair = + encodedIdKeyPair && password + ? await BlahKeyPair.fromEncoded(encodedIdKeyPair, password) + : undefined; const actKeyPair = accountCreds?.actKeyPair; return await BlahIdentity.fromIdentityDescription(identityFile, idKeyPair, actKeyPair); } - async saveIdentityDescription(identity: BlahIdentity) { + async saveIdentity(identity: BlahIdentity) { if (!this.identityDB) throw new Error('Account manager not initialized'); const identityDesc = identity.generateIdentityDescription(); @@ -113,7 +114,7 @@ class AccountManager { const identity = await BlahIdentity.create(idKeyPair, actKeyPair, profile); const encodedIdKeyPair = await idKeyPair.encode(password); await this.keyDB.addAccount(idKeyPair.id, actKeyPair, encodedIdKeyPair); - await this.saveIdentityDescription(identity); + await this.saveIdentity(identity); return idKeyPair.id; } }