Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,42 @@
* @module
*/

import type * as userKeys from '../userKeys.js'

import type {
ApiFromModules,
FilterApi,
FunctionReference,
} from 'convex/server'
import type * as todos from '../todos.js'

declare const fullApi: ApiFromModules<{
userKeys: typeof userKeys
}>

/**
* A utility for referencing Convex functions in your app's API.
* A utility for referencing Convex functions in your app's public API.
*
* Usage:
* ```js
* const myFunctionReference = api.myModule.myFunction;
* ```
*/
declare const fullApi: ApiFromModules<{
todos: typeof todos
}>
export declare const api: FilterApi<
typeof fullApi,
FunctionReference<any, 'public'>
>

/**
* A utility for referencing Convex functions in your app's internal API.
*
* Usage:
* ```js
* const myFunctionReference = internal.myModule.myFunction;
* ```
*/
export declare const internal: FilterApi<
typeof fullApi,
FunctionReference<any, 'internal'>
>

export declare const components: {}
3 changes: 2 additions & 1 deletion convex/_generated/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @module
*/

import { anyApi } from 'convex/server'
import { anyApi, componentsGeneric } from 'convex/server'

/**
* A utility for referencing Convex functions in your app's API.
Expand All @@ -20,3 +20,4 @@ import { anyApi } from 'convex/server'
*/
export const api = anyApi
export const internal = anyApi
export const components = componentsGeneric()
2 changes: 1 addition & 1 deletion convex/_generated/dataModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type Doc<TableName extends TableNames> = DocumentByName<
* Convex documents are uniquely identified by their `Id`, which is accessible
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
*
* Documents can be loaded using `db.get(id)` in query and mutation functions.
* Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
*
* IDs are just strings at runtime, but this type can be used to distinguish them from other
* strings when type checking.
Expand Down
9 changes: 5 additions & 4 deletions convex/_generated/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ export declare const internalAction: ActionBuilder<DataModel, 'internal'>
/**
* Define an HTTP action.
*
* This function will be used to respond to HTTP requests received by a Convex
* deployment if the requests matches the path and method where this action
* is routed. Be sure to route your action in `convex/http.js`.
* The wrapped function will be used to respond to HTTP requests received
* by a Convex deployment if the requests matches the path and method where
* this action is routed. Be sure to route your httpAction in `convex/http.js`.
*
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
* @param func - The function. It receives an {@link ActionCtx} as its first argument
* and a Fetch API `Request` object as its second.
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
*/
export declare const httpAction: HttpActionBuilder
Expand Down
12 changes: 8 additions & 4 deletions convex/_generated/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ export const action = actionGeneric
export const internalAction = internalActionGeneric

/**
* Define a Convex HTTP action.
* Define an HTTP action.
*
* @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
* as its second.
* @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
* The wrapped function will be used to respond to HTTP requests received
* by a Convex deployment if the requests matches the path and method where
* this action is routed. Be sure to route your httpAction in `convex/http.js`.
*
* @param func - The function. It receives an {@link ActionCtx} as its first argument
* and a Fetch API `Request` object as its second.
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
*/
export const httpAction = httpActionGeneric
14 changes: 0 additions & 14 deletions convex/crons.ts

This file was deleted.

165 changes: 0 additions & 165 deletions convex/encryption.ts

This file was deleted.

18 changes: 0 additions & 18 deletions convex/encryptionSessions.ts

This file was deleted.

21 changes: 7 additions & 14 deletions convex/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ import { defineSchema, defineTable } from 'convex/server'
import { v } from 'convex/values'

export default defineSchema({
/**
* User keys
* This table stores the user's encryption keys.
* It is used to store the *encrypted private key* and the *public key*.
*/
userKeys: defineTable({
userId: v.string(), // Clerk user ID
userId: v.string(),
encryptedPrivateKey: v.string(),
publicKey: v.string(),
encryptedPassphrase: v.string(),
createdAt: v.number(),
}).index('by_user', ['userId']),

encryptionSessions: defineTable({
userId: v.string(),
sessionId: v.string(), // Random session identifier
encryptedSessionData: v.string(), // Private key encrypted with session key
sessionKeyHash: v.string(), // Hash of session key (for verification)
expiresAt: v.number(), // Auto-delete after 30 minutes
lastAccessedAt: v.number(), // For activity tracking
createdAt: v.number(),
})
.index('by_user', ['userId'])
.index('by_session_id', ['sessionId'])
.index('by_expiry', ['expiresAt']), // For cleanup
})
51 changes: 51 additions & 0 deletions convex/userKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { v } from 'convex/values'
import { mutation, query } from './_generated/server'

/**
* Get the user's encryption keys
*/
export const getUserKeys = query({
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity()
if (!identity) return null

const keys = await ctx.db
.query('userKeys')
.withIndex('by_user', (q) => q.eq('userId', identity.subject))
.first()

return keys
},
})

/**
* Create the user's encryption data (PGP keys + encrypted passphrase) on signup
*/
export const createUserKeys = mutation({
args: {
encryptedPrivateKey: v.string(),
publicKey: v.string(),
encryptedPassphrase: v.string(),
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity()
if (!identity) throw new Error('Unauthorized')

const existing = await ctx.db
.query('userKeys')
.withIndex('by_user', (q) => q.eq('userId', identity.subject))
.first()

if (existing) {
throw new Error('Keys already exist for this user')
}

return await ctx.db.insert('userKeys', {
userId: identity.subject,
encryptedPrivateKey: args.encryptedPrivateKey,
publicKey: args.publicKey,
encryptedPassphrase: args.encryptedPassphrase,
createdAt: Date.now(),
})
},
})
2 changes: 2 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"$schema": "https://inlang.com/schema/inlang-message-format",
"navigation": {
"dashboard": "Dashboard",
"encrypt": "Encryption Demo",
"logout": "Logout"
},
"sign_in": {
Expand Down
Loading