feat: allow sharing of secrets publicly

This commit is contained in:
ShubhamPalriwala
2024-06-10 07:59:58 +05:30
parent 6c596092b0
commit 5df53a25fc
11 changed files with 195 additions and 61 deletions
@@ -70,6 +70,43 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
}
});
server.route({
method: "POST",
url: "/public",
config: {
rateLimit: writeLimit
},
schema: {
body: z.object({
encryptedValue: z.string(),
iv: z.string(),
tag: z.string(),
hashedHex: z.string(),
expiresAt: z
.string()
.refine((date) => date === undefined || new Date(date) > new Date(), "Expires at should be a future date"),
expiresAfterViews: z.number()
}),
response: {
200: z.object({
id: z.string().uuid()
})
}
},
handler: async (req) => {
const { encryptedValue, iv, tag, hashedHex, expiresAt, expiresAfterViews } = req.body;
const sharedSecret = await req.server.services.secretSharing.createPublicSharedSecret({
encryptedValue,
iv,
tag,
hashedHex,
expiresAt: new Date(expiresAt),
expiresAfterViews
});
return { id: sharedSecret.id };
}
});
server.route({
method: "POST",
url: "/",