mirror of
https://github.com/Blah-IM/Weblah.git
synced 2025-05-01 00:31:08 +00:00
fix(accounts): Do not attempt to decode ID key if password is not provided
This commit is contained in:
parent
924427a810
commit
35315ca5f3
2 changed files with 7 additions and 6 deletions
|
@ -4,7 +4,7 @@ import {
|
||||||
type BlahIdentityDescription,
|
type BlahIdentityDescription,
|
||||||
type BlahProfile
|
type BlahProfile
|
||||||
} from '@blah-im/core/identity';
|
} 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 { BlahKeyPair } from '@blah-im/core/crypto';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
|
|
||||||
|
@ -89,15 +89,16 @@ class AccountManager {
|
||||||
|
|
||||||
const accountCreds = await this.keyDB.fetchAccount(idKeyId);
|
const accountCreds = await this.keyDB.fetchAccount(idKeyId);
|
||||||
const encodedIdKeyPair = accountCreds?.encodedIdKeyPair;
|
const encodedIdKeyPair = accountCreds?.encodedIdKeyPair;
|
||||||
const idKeyPair = encodedIdKeyPair
|
const idKeyPair =
|
||||||
? await BlahKeyPair.fromEncoded(encodedIdKeyPair, password)
|
encodedIdKeyPair && password
|
||||||
: undefined;
|
? await BlahKeyPair.fromEncoded(encodedIdKeyPair, password)
|
||||||
|
: undefined;
|
||||||
const actKeyPair = accountCreds?.actKeyPair;
|
const actKeyPair = accountCreds?.actKeyPair;
|
||||||
|
|
||||||
return await BlahIdentity.fromIdentityDescription(identityFile, idKeyPair, 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');
|
if (!this.identityDB) throw new Error('Account manager not initialized');
|
||||||
|
|
||||||
const identityDesc = identity.generateIdentityDescription();
|
const identityDesc = identity.generateIdentityDescription();
|
||||||
|
@ -113,7 +114,7 @@ class AccountManager {
|
||||||
const identity = await BlahIdentity.create(idKeyPair, actKeyPair, profile);
|
const identity = await BlahIdentity.create(idKeyPair, actKeyPair, profile);
|
||||||
const encodedIdKeyPair = await idKeyPair.encode(password);
|
const encodedIdKeyPair = await idKeyPair.encode(password);
|
||||||
await this.keyDB.addAccount(idKeyPair.id, actKeyPair, encodedIdKeyPair);
|
await this.keyDB.addAccount(idKeyPair.id, actKeyPair, encodedIdKeyPair);
|
||||||
await this.saveIdentityDescription(identity);
|
await this.saveIdentity(identity);
|
||||||
return idKeyPair.id;
|
return idKeyPair.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue