refactor: identityFile -> identityDesc

This commit is contained in:
Shibo Lyu 2024-10-31 02:25:27 +08:00
parent 42aeca58e7
commit a5042980dd

View file

@ -1,11 +1,15 @@
import { writable, type Readable } from 'svelte/store'; import { writable, type Readable } from 'svelte/store';
import { type AccountKeyDB, openAccountKeyDB } from './accountKeyDB'; import { type AccountKeyDB, openAccountKeyDB } from './accountKeyDB';
import { BlahIdentity, type BlahIdentityFile, type BlahProfile } from '@blah-im/core/identity'; import {
BlahIdentity,
type BlahIdentityDescription,
type BlahProfile
} from '@blah-im/core/identity';
import { type IdentityFileDB, openIdentityFileDB } from '$lib/identityFiles/identityFileDB'; import { type IdentityFileDB, openIdentityFileDB } from '$lib/identityFiles/identityFileDB';
import { BlahKeyPair } from '@blah-im/core/crypto'; import { BlahKeyPair } from '@blah-im/core/crypto';
import { persisted } from 'svelte-persisted-store'; import { persisted } from 'svelte-persisted-store';
export type Account = BlahIdentityFile & { export type Account = BlahIdentityDescription & {
holdingKeyPrivate: boolean; holdingKeyPrivate: boolean;
holdingPrivateOfActKey?: string; holdingPrivateOfActKey?: string;
}; };
@ -67,12 +71,12 @@ class AccountStore implements Readable<Account[]> {
: undefined; : undefined;
const actKeyPair = accountCreds?.actKeyPair; const actKeyPair = accountCreds?.actKeyPair;
return await BlahIdentity.fromIdentityFile(identityFile, idKeyPair, actKeyPair); return await BlahIdentity.fromIdentityDescription(identityFile, idKeyPair, actKeyPair);
} }
async saveIdentityFile(identity: BlahIdentity) { async saveIdentityDescription(identity: BlahIdentity) {
const identityFile = identity.generateIdentityFile(); const identityDesc = identity.generateIdentityDescription();
await this.identityFileDB.updateIdentityFile(identityFile); await this.identityFileDB.updateIdentityFile(identityDesc);
} }
async createAccount(profile: BlahProfile, password: string): Promise<string> { async createAccount(profile: BlahProfile, password: string): Promise<string> {
@ -81,7 +85,7 @@ class AccountStore implements Readable<Account[]> {
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.saveIdentityFile(identity); await this.saveIdentityDescription(identity);
await this.loadAccounts(); await this.loadAccounts();
return idKeyPair.id; return idKeyPair.id;
} }