No key exchange needed
Encrypt data using nothing more than the recipient's email address. There are no public keys to look up and no certificates to manage.
Send encrypted messages and files to anyone using just their email address. No key exchange, no certificates, no hassle.
Install the SDK:
npm install @e4a/pg-js @e4a/pg-wasmInitialize PostGuard and encrypt files for delivery:
export interface EncryptAndSendOptions {
files: File[];
citizen: CitizenRecipient;
organisation: OrganisationRecipient;
apiKey: string;
message: string | null;
onProgress?: (percentage: number) => void;
abortController?: AbortController;
}
export async function encryptAndSend(options: EncryptAndSendOptions): Promise<void> {
const {
files,
citizen,
organisation,
apiKey,
message,
onProgress,
abortController = new AbortController()
} = options;
// Fetch MPK and signing keys in parallel
const [mpk, signingKeys] = await Promise.all([fetchMPK(), fetchSigningKeys(apiKey)]);
// Build encryption policy
const ts = Math.round(Date.now() / 1000);
const policy: Record<string, { ts: number; con: { t: string; v?: string }[] }> = {};
// Citizen: must prove exact email address
policy[citizen.email] = {
ts,
con: [{ t: 'pbdf.sidn-pbdf.email.email', v: citizen.email }]
};
// Organisation: must prove an email at the correct domain
policy[organisation.email] = {
ts,
con: [{ t: 'pbdf.sidn-pbdf.email.domain', v: extractDomain(organisation.email) }]
};Read the concepts guide to understand how this works, or jump straight to getting started.