Add Keypair test

This commit is contained in:
dapplion 2020-11-19 14:50:08 +00:00
parent f8cd6e7afa
commit 523d547171
2 changed files with 27 additions and 4 deletions

View File

@ -31,10 +31,6 @@ export class PrivateKey {
return this.fromBytes(sk); return this.fromBytes(sk);
} }
getValue(): SecretKeyType {
return this.value;
}
signMessage(message: Uint8Array): Signature { signMessage(message: Uint8Array): Signature {
return new Signature(this.value.sign(message)); return new Signature(this.value.sign(message));
} }

27
test/unit/keypair.test.ts Normal file
View File

@ -0,0 +1,27 @@
import {expect} from "chai";
import {forEachImplementation} from "../switch";
forEachImplementation((bls) => {
describe("Keypair", () => {
it("should create from private and public key", () => {
const sk = bls.PrivateKey.fromKeygen();
const sk2 = bls.PrivateKey.fromKeygen();
const pk = sk.toPublicKey();
const keypair = new bls.Keypair(sk as any, pk as any);
expect(keypair.publicKey).to.be.equal(pk);
expect(keypair.privateKey).to.be.equal(sk);
expect(keypair.privateKey).to.not.be.equal(sk2);
});
it("should create from PrivateKey", () => {
const sk = bls.PrivateKey.fromKeygen();
const pk = sk.toPublicKey();
const keypair = new bls.Keypair(sk as any);
expect(keypair.publicKey.toHex()).to.equal(pk.toHex());
});
});
});