This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/test/unit/privateKey.test.ts

27 lines
978 B
TypeScript
Raw Normal View History

2020-11-05 20:55:25 +00:00
import {expect} from "chai";
2020-11-20 19:03:17 +00:00
import {IBls} from "../../src/interface";
2019-08-05 15:48:26 +00:00
export function runPrivateKeyTests(bls: IBls): void {
describe("PrivateKey", () => {
it("should generate fromKeygen private key", () => {
const privateKey1 = bls.PrivateKey.fromKeygen();
const privateKey2 = bls.PrivateKey.fromKeygen();
expect(privateKey1.toHex()).to.not.be.equal(privateKey2.toHex());
});
2020-11-05 20:55:25 +00:00
const privateKey = "0x07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7";
it("should export private key to hex string", () => {
expect(bls.PrivateKey.fromHex(privateKey).toHex()).to.be.equal(privateKey);
});
it("should export private key to hex string from non-prefixed hex", () => {
expect(bls.PrivateKey.fromHex(privateKey.replace("0x", "")).toHex()).to.be.equal(privateKey);
});
2020-11-04 17:40:36 +00:00
it("should not accept too short private key", () => {
expect(() => bls.PrivateKey.fromHex("0x2123")).to.throw();
});
});
2020-11-20 19:03:17 +00:00
}