mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign). Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files) and align docker/Dockerfile turbo --scope/--filter to the actual remix package name @hanzo/esign (was a pre-existing mismatch with -remix that broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
42 lines
1017 B
TypeScript
42 lines
1017 B
TypeScript
import { z } from 'zod';
|
|
|
|
import { SIGN_ENCRYPTION_SECONDARY_KEY } from '@hanzo/esign-lib/constants/crypto';
|
|
import { symmetricEncrypt } from '@hanzo/esign-lib/universal/crypto';
|
|
|
|
export const ZEncryptedDataSchema = z.object({
|
|
data: z.string(),
|
|
expiresAt: z.number().optional(),
|
|
});
|
|
|
|
export type EncryptDataOptions = {
|
|
data: string;
|
|
|
|
/**
|
|
* When the data should no longer be allowed to be decrypted.
|
|
*
|
|
* Leave this empty to never expire the data.
|
|
*/
|
|
expiresAt?: number;
|
|
};
|
|
|
|
/**
|
|
* Encrypt the passed in data. This uses the secondary encrypt key for miscellaneous data.
|
|
*
|
|
* @returns The encrypted data.
|
|
*/
|
|
export const encryptSecondaryData = ({ data, expiresAt }: EncryptDataOptions) => {
|
|
if (!SIGN_ENCRYPTION_SECONDARY_KEY) {
|
|
throw new Error('Missing encryption key');
|
|
}
|
|
|
|
const dataToEncrypt: z.infer<typeof ZEncryptedDataSchema> = {
|
|
data,
|
|
expiresAt,
|
|
};
|
|
|
|
return symmetricEncrypt({
|
|
key: SIGN_ENCRYPTION_SECONDARY_KEY,
|
|
data: JSON.stringify(dataToEncrypt),
|
|
});
|
|
};
|