signal-desktop/ts/updater/curve.ts

34 lines
740 B
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { randomBytes } from 'crypto';
2019-08-19 22:26:45 +00:00
import {
calculateSignature,
generateKeyPair,
verifySignature,
} from 'curve25519-n';
2020-09-16 19:31:05 +00:00
export function keyPair(): Record<string, Buffer> {
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;
}