Skip to content

Instantly share code, notes, and snippets.

@morloy
Last active September 12, 2018 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morloy/da43a8cbab4c3d61eb41a4578fd51461 to your computer and use it in GitHub Desktop.
Save morloy/da43a8cbab4c3d61eb41a4578fd51461 to your computer and use it in GitHub Desktop.
import { sign } from 'tweetnacl';
import { Buffer } from 'buffer';
const secretKey = Buffer.from('…', 'base64');
const generateCertificateForDocument =
(filename: string, sha256: string, user: string, email: string, userId: string, companyId: string, createdByLedgy: boolean): string => {
const certificate = JSON.stringify({
filename, sha256, user, email, company, createdByLedgy, userId, companyId, version: '1.0.0',
});
const signedCertificate = sign(Buffer.from(certificate), secretKey);
return Buffer.from(signedCertificate).toString('base64');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment