diff --git a/app/sdk/__mocks__/identity.ts b/app/sdk/__mocks__/identity.ts index e57f3dea..ebdd7f1d 100644 --- a/app/sdk/__mocks__/identity.ts +++ b/app/sdk/__mocks__/identity.ts @@ -20,7 +20,7 @@ export class MockIdentityModule implements Identity { this.emitter.off('profile', ev); } - public close(): void { + public async close(): Promise { } public async setRevision(rev: number): Promise { @@ -33,7 +33,8 @@ export class MockIdentityModule implements Identity { public async setProfileImage(image: string): Promise { } - public async getHandleStatus(handle: string): Promise { + public async getHandleStatus(handle: string): Promise { + return false; } public getProfileImageUrl(): string { diff --git a/app/sdk/src/api.ts b/app/sdk/src/api.ts index bce9043d..c3572056 100644 --- a/app/sdk/src/api.ts +++ b/app/sdk/src/api.ts @@ -28,7 +28,7 @@ export interface Logging { } export interface Session { - close(): { node: string, secure: boolean, token: string }; + close(): Promise<{ node: string, secure: boolean, token: string }>; getAccount(): Account; getIdentity(): Identity; @@ -81,7 +81,7 @@ export interface Account { export interface Identity { setProfileData(name: string, location: string, description: string): Promise; setProfileImage(image: string): Promise; - getHandleStatus(handle: string): Promise; + getHandleStatus(handle: string): Promise; getProfileImageUrl(): string; diff --git a/app/sdk/src/entities.ts b/app/sdk/src/entities.ts index 15145b5e..e198da76 100644 --- a/app/sdk/src/entities.ts +++ b/app/sdk/src/entities.ts @@ -1,4 +1,4 @@ -import type { Seal, Profile } from './types'; +import type { Profile } from './types'; export type CardEntity = { id: string, @@ -142,6 +142,13 @@ export type ArticleEntity = { } } +export type SealEntity = { + passwordSalt: string, + privateKeyIv: string, + privateKeyEncrypted: string, + publicKey: string, +} + export type AccountEntity = { disabled: boolean, storageUsed: number, @@ -151,7 +158,7 @@ export type AccountEntity = { allowUnsealed: boolean, pushEnabled: boolean, sealable: boolean, - seal: Seal, + seal: SealEntity, enableIce: boolean, multiFactorAuth: boolean, webPushKey: string, diff --git a/app/sdk/src/identity.ts b/app/sdk/src/identity.ts index 6a63e4b3..0a66da3f 100644 --- a/app/sdk/src/identity.ts +++ b/app/sdk/src/identity.ts @@ -6,6 +6,7 @@ import { getProfile } from './net/getProfile'; import { getProfileImageUrl } from './net/getProfileImageUrl'; import { setProfileData } from './net/setProfileData'; import { setProfileImage } from './net/setProfileImage'; +import { getUsername } from './net/getUsername'; import { ProfileEntity, defaultProfileEntity } from './entities'; const CLOSE_POLL_MS = 100; @@ -63,6 +64,7 @@ export class IdentityModule implements Identity { const profile = await getProfile(node, secure, token); await this.store.setProfileData(guid, profile); await this.store.setProfileRevision(guid, nextRev); + this.profile = profile; this.emitter.emit('profile', this.getProfile()); this.revision = nextRev; if (this.nextRevision === nextRev) { @@ -94,7 +96,7 @@ export class IdentityModule implements Identity { this.emitter.off('profile', ev); } - public async close(): void { + public async close(): Promise { this.closing = true; while(this.syncing) { await new Promise(r => setTimeout(r, CLOSE_POLL_MS)); @@ -107,16 +109,23 @@ export class IdentityModule implements Identity { } public async setProfileData(name: string, location: string, description: string): Promise { + const { node, secure, token } = this; + await setProfileData(node, secure, token, name, location, description); } public async setProfileImage(image: string): Promise { + const { node, secure, token } = this; + await setProfileImage(node, secure, token, image); } - public async getHandleStatus(handle: string): Promise { + public async getHandleStatus(handle: string): Promise { + const { node, secure, token } = this; + return await getUsername(handle, token, node, secure); } public getProfileImageUrl(): string { - return getProfileImageUrl(this.node, this.secure, this.token, this.revision); + const { node, secure, token, revision } = this; + return getProfileImageUrl(node, secure, token, revision); } } diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index 3c2ae7b6..b7883675 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -76,7 +76,7 @@ export class DatabagSDK { } public async logout(session: Session, all: boolean): Promise { - const params = session.close(); + const params = await session.close(); try { const { node, secure, token } = params; await clearLogin(node, secure, token, all); diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index 2c837d71..1d751250 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -133,7 +133,7 @@ export class SessionModule implements Session { } } - public async close(): { node: string, secure: boolean, token: string } { + public async close(): Promise<{ node: string, secure: boolean, token: string }> { await this.content.close(); await this.attribute.close(); await this.alias.close(); @@ -142,7 +142,8 @@ export class SessionModule implements Session { await this.account.close(); await this.stream.close(); this.connection.close(); - return { node: this.node, secure: this.secure, token: this.token }; + const { node, secure, token } = this; + return { node: node, secure: secure, token: token }; } public getAccount(): Account { diff --git a/app/sdk/src/stream.ts b/app/sdk/src/stream.ts index 826654f6..161d0db7 100644 --- a/app/sdk/src/stream.ts +++ b/app/sdk/src/stream.ts @@ -27,6 +27,6 @@ export class StreamModule implements Stream { this.emitter.off('channel', ev); } - public async close(): void { + public async close(): Promise { } }