Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6934 from LiskHQ/6840_sign_certificate
Browse files Browse the repository at this point in the history
Implement signCertificate for CommitPool - Closes #6840
  • Loading branch information
shuse2 authored Nov 23, 2021
2 parents 79947b0 + f7b65b8 commit abe254c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
25 changes: 16 additions & 9 deletions framework/src/node/consensus/certificate_generation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
* Removal or modification of this copyright notice is prohibited.
*/

import { signBLS, verifyWeightedAggSig } from '@liskhq/lisk-cryptography';
import { BlockHeader } from '@liskhq/lisk-chain';
import { codec } from '@liskhq/lisk-codec';
import { verifyWeightedAggSig } from '@liskhq/lisk-cryptography';
import { MESSAGE_TAG_CERTIFICATE } from './constants';
import { certificateSchema } from './schema';
import { Certificate } from './types';
import { certificateSchema } from './schema';
import { MESSAGE_TAG_CERTIFICATE } from './constants';

export const computeCertificateFromBlockHeader = (blockHeader: BlockHeader): Certificate => {
if (!blockHeader.stateRoot) {
Expand All @@ -37,13 +37,20 @@ export const computeCertificateFromBlockHeader = (blockHeader: BlockHeader): Cer
};
};

// TODO: https://github.com/LiskHQ/lisk-sdk/issues/6840
export const signCertificate = (
_sk: Buffer,
_networkIdentifier: Buffer,
_blockHeader: BlockHeader,
// eslint-disable-next-line @typescript-eslint/no-empty-function
): Buffer => Buffer.from('');
sk: Buffer,
networkIdentifier: Buffer,
certificate: Certificate,
): Buffer => {
const { aggregationBits, signature, ...rawCertificate } = certificate;

return signBLS(
MESSAGE_TAG_CERTIFICATE,
networkIdentifier,
codec.encode(certificateSchema, rawCertificate),
sk,
);
};

// TODO: https://github.com/LiskHQ/lisk-sdk/issues/6841
export const verifySingleCertificateSignature = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BlockHeader } from '@liskhq/lisk-chain';
import {
signBLS,
Expand All @@ -26,6 +27,7 @@ import { certificateSchema } from '../../../../../src/node/consensus/certificate
import {
verifyAggregateCertificateSignature,
computeCertificateFromBlockHeader,
signCertificate,
} from '../../../../../src/node/consensus/certificate_generation/utils';
import { createFakeBlockHeader } from '../../../../../src/testing';

Expand Down Expand Up @@ -65,8 +67,35 @@ describe('utils', () => {
);
});
});

describe('signCertificate', () => {
it.todo('');
let privateKey: Buffer;
let certificate: Certificate;
let signature: Buffer;

beforeEach(() => {
privateKey = generatePrivateKey(getRandomBytes(32));
certificate = {
blockID: Buffer.alloc(0),
height: 1000,
stateRoot: Buffer.alloc(0),
timestamp: 10000,
validatorsHash: Buffer.alloc(0),
};
const encodedCertificate = codec.encode(certificateSchema, certificate);
signature = signBLS(
MESSAGE_TAG_CERTIFICATE,
networkIdentifier,
encodedCertificate,
privateKey,
);
(certificate as any).aggregationBits = getRandomBytes(4);
(certificate as any).signature = getRandomBytes(4);
});

it('should sign certificate', () => {
expect(signCertificate(privateKey, networkIdentifier, certificate)).toEqual(signature);
});
});
describe('verifySingleCertificateSignature', () => {
it.todo('');
Expand Down

0 comments on commit abe254c

Please sign in to comment.