signal-desktop/ts/updater/curve.ts

31 lines
798 B
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2019 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import { PrivateKey, PublicKey } from '@signalapp/libsignal-client';
2020-09-16 19:31:05 +00:00
export function keyPair(): Record<string, Buffer> {
const privKey = PrivateKey.generate();
const pubKey = privKey.getPublicKey();
return {
publicKey: pubKey.serialize(),
privateKey: privKey.serialize(),
};
}
2019-08-19 22:26:45 +00:00
export function sign(privateKey: Buffer, message: Buffer): Buffer {
const privKeyObj = PrivateKey.deserialize(privateKey);
const signature = privKeyObj.sign(message);
return signature;
}
export function verify(
2019-08-19 22:26:45 +00:00
publicKey: Buffer,
message: Buffer,
signature: Buffer
): boolean {
const pubKeyObj = PublicKey.deserialize(publicKey);
const result = pubKeyObj.verify(message, signature);
return result;
}