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
|
|
|
|
|
2022-03-24 21:47:21 +00:00
|
|
|
import { PrivateKey, PublicKey } from '@signalapp/libsignal-client';
|
2019-03-28 17:09:26 +00:00
|
|
|
|
2020-09-16 19:31:05 +00:00
|
|
|
export function keyPair(): Record<string, Buffer> {
|
2021-01-27 22:39:09 +00:00
|
|
|
const privKey = PrivateKey.generate();
|
|
|
|
const pubKey = privKey.getPublicKey();
|
2019-03-28 17:09:26 +00:00
|
|
|
|
|
|
|
return {
|
2021-01-27 22:39:09 +00:00
|
|
|
publicKey: pubKey.serialize(),
|
|
|
|
privateKey: privKey.serialize(),
|
2019-03-28 17:09:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-19 22:26:45 +00:00
|
|
|
export function sign(privateKey: Buffer, message: Buffer): Buffer {
|
2021-01-27 22:39:09 +00:00
|
|
|
const privKeyObj = PrivateKey.deserialize(privateKey);
|
|
|
|
const signature = privKeyObj.sign(message);
|
|
|
|
return signature;
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function verify(
|
2019-08-19 22:26:45 +00:00
|
|
|
publicKey: Buffer,
|
|
|
|
message: Buffer,
|
|
|
|
signature: Buffer
|
|
|
|
): boolean {
|
2021-01-27 22:39:09 +00:00
|
|
|
const pubKeyObj = PublicKey.deserialize(publicKey);
|
|
|
|
const result = pubKeyObj.verify(message, signature);
|
|
|
|
return result;
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|