diff --git a/src/crypto/bls.spec.ts b/src/crypto/bls.spec.ts index 682f344e9..b5c1e7d08 100644 --- a/src/crypto/bls.spec.ts +++ b/src/crypto/bls.spec.ts @@ -30,6 +30,11 @@ describe('bls', () => { expect(bls.signatureToBytes(sig)).toEqual(hexToBuffer(sigStr)); }); + it('generates signature correctly', async () => { + const sk = bls.secretKeyFromBytes(skStr); + expect(bls.sign(msg, sk)).toEqual(hexToBuffer(sigStr)); + }); + it('verifies signature correctly', async () => { const pk = bls.publicKeyFromBytes(pkStr); const sig = bls.signatureFromBytes(hexToBuffer(sigStr)); @@ -37,6 +42,14 @@ describe('bls', () => { expect(bls.verify(pk, sig, msg)).toEqual(true); }); + it('generates proof of possession correctly', async () => { + const sk = bls.secretKeyFromBytes(skStr); + const pk = bls.publicKeyFromBytes(pkStr); + const pkBytes = bls.publicKeyToBytes(pk); + + expect(bls.signProofOfPossession(pkBytes, sk)).toEqual(hexToBuffer(popStr)); + }); + it('verifies proof of possession correctly', async () => { const pk = bls.publicKeyFromBytes(pkStr); const pop = bls.signatureFromBytes(hexToBuffer(popStr)); diff --git a/src/crypto/bls.ts b/src/crypto/bls.ts index b95461d9c..573ed8550 100644 --- a/src/crypto/bls.ts +++ b/src/crypto/bls.ts @@ -56,3 +56,22 @@ export function verifyProofOfPossession( DST: proofOfPossessionDST, }); } + +export function sign(msg: Uint8Array | string, sk: SecretKey): Uint8Array { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error Will error until a version of @noble/curves is released with https://github.com/paulmillr/noble-curves/pull/117 + return bls12_381.sign(msg, sk, { + DST: signatureDST, + }); +} + +export function signProofOfPossession( + msg: Uint8Array | string, + sk: SecretKey, +): Uint8Array { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error Will error until a version of @noble/curves is released with https://github.com/paulmillr/noble-curves/pull/117 + return bls12_381.sign(msg, sk, { + DST: proofOfPossessionDST, + }); +}