2020-11-05 20:55:25 +00:00
|
|
|
import {PrivateKey, PublicKey, Keypair} from "../../src";
|
|
|
|
import {expect} from "chai";
|
|
|
|
import {destroy, init} from "../../src/context";
|
2019-08-05 15:48:26 +00:00
|
|
|
|
2020-11-04 17:40:36 +00:00
|
|
|
describe("keypair", function () {
|
2019-11-27 20:58:41 +00:00
|
|
|
before(async function () {
|
|
|
|
await init();
|
|
|
|
});
|
2019-08-05 15:48:26 +00:00
|
|
|
|
2019-11-27 20:58:41 +00:00
|
|
|
after(function () {
|
|
|
|
destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create from private and public key", () => {
|
2020-11-19 00:23:34 +00:00
|
|
|
const secret = PrivateKey.fromKeygen();
|
|
|
|
const secret2 = PrivateKey.fromKeygen();
|
|
|
|
const publicKey = PublicKey.fromBytes(secret2.toPublicKey().toBytes());
|
2019-11-27 20:58:41 +00:00
|
|
|
const keypair = new Keypair(secret, publicKey);
|
|
|
|
expect(keypair.publicKey).to.be.equal(publicKey);
|
|
|
|
expect(keypair.privateKey).to.be.equal(secret);
|
|
|
|
expect(keypair.privateKey).to.not.be.equal(secret2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create from private", () => {
|
2020-11-19 00:23:34 +00:00
|
|
|
const secret = PrivateKey.fromKeygen();
|
|
|
|
const publicKey = secret.toPublicKey();
|
2019-11-27 20:58:41 +00:00
|
|
|
const keypair = new Keypair(secret);
|
2020-11-19 00:23:34 +00:00
|
|
|
expect(keypair.publicKey.toBytes().toString("hex")).to.be.equal(publicKey.toBytes().toString("hex"));
|
2019-11-27 20:58:41 +00:00
|
|
|
});
|
2019-08-05 15:48:26 +00:00
|
|
|
});
|