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

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-08-05 15:48:26 +00:00
import {PrivateKey} from "../../src/privateKey";
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
describe("privateKey", function() {
2019-08-05 15:48:26 +00:00
before(async function () {
await init();
});
2019-08-05 15:48:26 +00:00
after(function () {
destroy();
});
2019-08-05 15:48:26 +00:00
it("should generate random private key", function () {
const privateKey1 = PrivateKey.random();
const privateKey2 = PrivateKey.random();
expect(privateKey1.toHexString()).to.not.be.equal(privateKey2.toHexString());
});
it("should export private key to hex string", function () {
const privateKey = "0x07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7";
expect(PrivateKey.fromHexString(privateKey).toHexString()).to.be.equal(privateKey);
const privateKey2 = "07656fd676da43883d163f49566c72b9cbf0a5a294f26808c807700732456da7";
expect(PrivateKey.fromHexString(privateKey2).toHexString()).to.be.equal(privateKey);
});
it("should export private key to bytes", function () {
expect(PrivateKey.random().toBytes().length).to.be.equal(SECRET_KEY_LENGTH);
});
it("should not accept too short private key", function () {
expect(() => PrivateKey.fromHexString("0x2123")).to.throw();
});
2019-08-05 15:48:26 +00:00
});