add derivation to metadata

This commit is contained in:
Niccolo Borgioli 2023-05-23 09:37:49 +02:00
parent b05841a562
commit c2bfe9dd0d
No known key found for this signature in database
GPG Key ID: D93C615F75EE4F0B
1 changed files with 17 additions and 7 deletions

View File

@ -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 = { export type Note = {
contents: string contents: string
@ -8,7 +11,7 @@ export type Note = {
views?: number views?: number
expiration?: number expiration?: number
} }
export type NoteInfo = {} export type NoteInfo = Pick<Note, 'meta'>
export type NotePublic = Pick<Note, 'contents' | 'meta'> export type NotePublic = Pick<Note, 'contents' | 'meta'>
export type NoteCreate = Omit<Note, 'meta'> & { meta: string } export type NoteCreate = Omit<Note, 'meta'> & { meta: string }
@ -71,10 +74,12 @@ export async function get(id: string): Promise<NotePublic> {
method: 'delete', method: 'delete',
}) })
const { contents, meta } = data const { contents, meta } = data
return { const note = {
contents, 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<NoteInfo> { export async function info(id: string): Promise<NoteInfo> {
@ -82,7 +87,12 @@ export async function info(id: string): Promise<NoteInfo> {
url: `notes/${id}`, url: `notes/${id}`,
method: 'get', 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 = { export type Status = {