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

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-11-05 20:55:25 +00:00
import {PrivateKey} from "../../src";
import {expect} from "chai";
import {SECRET_KEY_LENGTH} from "../../src/constants";
import {destroy, init} from "../../src/context";
2019-08-05 15:48:26 +00:00
2020-11-04 17:40:36 +00:00
describe("privateKey", function () {
before(async function () {
await init();
});
2019-08-05 15:48:26 +00:00
after(function () {
destroy();
});
2019-08-05 15:48:26 +00:00
2020-11-19 00:23:34 +00:00
it("should generate fromKeygen private key", function () {
const privateKey1 = PrivateKey.fromKeygen();
const privateKey2 = PrivateKey.fromKeygen();
expect(privateKey1.toHex()).to.not.be.equal(privateKey2.toHex());
});
it("should export private key to hex string", function () {
2020-11-05 20:55:25 +00:00
const privateKey = "0x07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7";
2020-11-19 00:23:34 +00:00
expect(PrivateKey.fromHex(privateKey).toHex()).to.be.equal(privateKey);
2020-11-05 20:55:25 +00:00
const privateKey2 = "07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7";
2020-11-19 00:23:34 +00:00
expect(PrivateKey.fromHex(privateKey2).toHex()).to.be.equal(privateKey);
});
it("should export private key to bytes", function () {
2020-11-19 00:23:34 +00:00
expect(PrivateKey.fromKeygen().toBytes().length).to.be.equal(SECRET_KEY_LENGTH);
});
2020-11-04 17:40:36 +00:00
it("should not accept too short private key", function () {
2020-11-19 00:23:34 +00:00
expect(() => PrivateKey.fromHex("0x2123")).to.throw();
});
2019-08-05 15:48:26 +00:00
});