signal-desktop/ts/updater/curve.ts

31 lines
628 B
TypeScript
Raw Normal View History

import { randomBytes } from 'crypto';
2019-08-19 22:26:45 +00:00
import {
calculateSignature,
generateKeyPair,
verifySignature,
} from 'curve25519-n';
export function keyPair() {
const privateKey = randomBytes(32);
2019-08-19 22:26:45 +00:00
const { pubKey, privKey } = generateKeyPair(privateKey);
return {
publicKey: pubKey,
privateKey: privKey,
};
}
2019-08-19 22:26:45 +00:00
export function sign(privateKey: Buffer, message: Buffer): Buffer {
return calculateSignature(privateKey, message);
}
export function verify(
2019-08-19 22:26:45 +00:00
publicKey: Buffer,
message: Buffer,
signature: Buffer
): boolean {
const failed = verifySignature(publicKey, message, signature);
return !failed;
}