diff --git a/packages/shared/src/api.ts b/packages/shared/src/api.ts index fe65566..e0257a8 100644 --- a/packages/shared/src/api.ts +++ b/packages/shared/src/api.ts @@ -1,6 +1,9 @@ -import type { TypedArray } from 'occulto' +import type { KeyData, TypedArray } from 'occulto' -export type NoteMeta = { type: 'text' | 'file' } +export type NoteMeta = { + type: 'text' | 'file' + derivation?: KeyData +} export type Note = { contents: string @@ -8,7 +11,7 @@ export type Note = { views?: number expiration?: number } -export type NoteInfo = {} +export type NoteInfo = Pick export type NotePublic = Pick export type NoteCreate = Omit & { meta: string } @@ -71,10 +74,12 @@ export async function get(id: string): Promise { method: 'delete', }) const { contents, meta } = data - return { + const note = { contents, - meta: JSON.parse(meta) as NoteMeta, - } + meta: JSON.parse(meta), + } satisfies NotePublic + if (note.meta.derivation) note.meta.derivation.salt = new Uint8Array(Object.values(note.meta.derivation.salt)) + return note } export async function info(id: string): Promise { @@ -82,7 +87,12 @@ export async function info(id: string): Promise { url: `notes/${id}`, method: 'get', }) - return data + const { meta } = data + const note = { + meta: JSON.parse(meta), + } satisfies NoteInfo + if (note.meta.derivation) note.meta.derivation.salt = new Uint8Array(Object.values(note.meta.derivation.salt)) + return note } export type Status = {