2020-11-30 11:49:37 +00:00
|
|
|
import {expect} from "chai";
|
2022-04-11 15:08:15 +00:00
|
|
|
import {init, bls} from "../../src/index.js";
|
|
|
|
import type {SecretKey, PublicKey, Signature} from "../../src/types.js";
|
2020-11-30 11:49:37 +00:00
|
|
|
|
2022-04-11 15:08:15 +00:00
|
|
|
describe("types named exports", () => {
|
2020-11-30 11:49:37 +00:00
|
|
|
it("Classes and methods should be defined", async () => {
|
|
|
|
await init("herumi");
|
|
|
|
|
2020-11-30 23:53:40 +00:00
|
|
|
/**
|
|
|
|
* Sample helper to test argument typing
|
|
|
|
*/
|
|
|
|
function verifyHelper(pk: PublicKey, sig: Signature, msg: Uint8Array): boolean {
|
|
|
|
return sig.verify(pk, msg);
|
|
|
|
}
|
|
|
|
|
2022-04-11 15:08:15 +00:00
|
|
|
const sk = bls.SecretKey.fromKeygen();
|
2020-11-30 11:49:37 +00:00
|
|
|
const msg = new Uint8Array(32);
|
|
|
|
const sig = sk.sign(msg);
|
|
|
|
const pk = sk.toPublicKey();
|
|
|
|
expect(verifyHelper(pk, sig, msg)).to.be.true;
|
|
|
|
});
|
|
|
|
|
2020-11-30 23:53:40 +00:00
|
|
|
it("Make sure exported classes are compatible with interface", () => {
|
|
|
|
const sk: SecretKey = bls.SecretKey.fromKeygen();
|
|
|
|
const pk: PublicKey = sk.toPublicKey();
|
|
|
|
const sig: Signature = sk.sign(new Uint8Array(32));
|
|
|
|
pk;
|
|
|
|
sig;
|
|
|
|
});
|
2020-11-30 11:49:37 +00:00
|
|
|
});
|