Skip to content

Commit

Permalink
chore: nit
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu committed Feb 17, 2024
1 parent da7b55d commit eca5dd6
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/crypto/bls.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { stringToBytes } from '@scure/base';
import { hexToBuffer } from '../utils/buffer';
import {
publicKeyFromBytes,
publicKeyToBytes,
secretKeyFromBytes,
secretKeyToBytes,
signatureFromBytes,
signatureToBytes,
verify,
verifyProofOfPossession,
} from './bls';
import * as bls from './bls';

const msgStr = 'test';
const skStr =
Expand All @@ -23,41 +14,41 @@ const sigStr =

describe('bls', () => {
it('serializes correctly', async () => {
const sk = secretKeyFromBytes(skStr);
expect(secretKeyToBytes(sk)).toEqual(hexToBuffer(skStr));
const sk = bls.secretKeyFromBytes(skStr);
expect(bls.secretKeyToBytes(sk)).toEqual(hexToBuffer(skStr));

const pk = publicKeyFromBytes(pkStr);
expect(publicKeyToBytes(pk)).toEqual(hexToBuffer(pkStr));
const pk = bls.publicKeyFromBytes(pkStr);
expect(bls.publicKeyToBytes(pk)).toEqual(hexToBuffer(pkStr));

const pk2 = publicKeyFromBytes(hexToBuffer(pkStr));
expect(publicKeyToBytes(pk2)).toEqual(hexToBuffer(pkStr));
const pk2 = bls.publicKeyFromBytes(hexToBuffer(pkStr));
expect(bls.publicKeyToBytes(pk2)).toEqual(hexToBuffer(pkStr));

const pop = signatureFromBytes(hexToBuffer(popStr));
expect(signatureToBytes(pop)).toEqual(hexToBuffer(popStr));
const pop = bls.signatureFromBytes(hexToBuffer(popStr));
expect(bls.signatureToBytes(pop)).toEqual(hexToBuffer(popStr));

const sig = signatureFromBytes(hexToBuffer(sigStr));
expect(signatureToBytes(sig)).toEqual(hexToBuffer(sigStr));
const sig = bls.signatureFromBytes(hexToBuffer(sigStr));
expect(bls.signatureToBytes(sig)).toEqual(hexToBuffer(sigStr));
});

it('generates signature correctly', async () => {
// TODO
});

it('verifies signature correctly', async () => {
const pk = publicKeyFromBytes(pkStr);
const sig = signatureFromBytes(hexToBuffer(sigStr));
const pk = bls.publicKeyFromBytes(pkStr);
const sig = bls.signatureFromBytes(hexToBuffer(sigStr));

expect(verify(pk, sig, stringToBytes('utf8', msgStr))).toEqual(true);
expect(bls.verify(pk, sig, stringToBytes('utf8', msgStr))).toEqual(true);
});

it('generates proof of possession correctly', async () => {
// TODO
});

it('verifies proof of possession correctly', async () => {
const pk = publicKeyFromBytes(pkStr);
const pop = signatureFromBytes(hexToBuffer(popStr));
const pk = bls.publicKeyFromBytes(pkStr);
const pop = bls.signatureFromBytes(hexToBuffer(popStr));

expect(verifyProofOfPossession(pk, pop, pk.toRawBytes())).toEqual(true);
expect(bls.verifyProofOfPossession(pk, pop, pk.toRawBytes())).toEqual(true);
});
});

0 comments on commit eca5dd6

Please sign in to comment.