2019-08-05 15:48:26 +00:00
|
|
|
import {PrivateKey} from "../../src/privateKey";
|
|
|
|
import {PublicKey} from "../../src/publicKey";
|
|
|
|
import {Keypair} from "../../src/keypair";
|
|
|
|
import {expect} from "chai";
|
2019-11-27 20:58:41 +00:00
|
|
|
import {destroy, init} from "../../src/context";
|
2019-08-05 15:48:26 +00:00
|
|
|
|
2019-11-27 20:58:41 +00:00
|
|
|
describe("keypair", function() {
|
2019-08-05 15:48:26 +00:00
|
|
|
|
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", () => {
|
|
|
|
const secret = PrivateKey.random();
|
|
|
|
const secret2 = PrivateKey.random();
|
|
|
|
const publicKey = PublicKey.fromBytes(PublicKey.fromPrivateKey(secret2).toBytesCompressed());
|
|
|
|
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", () => {
|
|
|
|
const secret = PrivateKey.random();
|
|
|
|
const publicKey = PublicKey.fromPrivateKey(secret);
|
|
|
|
const keypair = new Keypair(secret);
|
|
|
|
expect(keypair.publicKey.toBytesCompressed().toString("hex"))
|
|
|
|
.to.be.equal(publicKey.toBytesCompressed().toString("hex"));
|
|
|
|
});
|
2019-08-05 15:48:26 +00:00
|
|
|
});
|