Comparing version 0.1.2 to 0.1.3
@@ -6,10 +6,20 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var secp256k1_1 = __importDefault(require("secp256k1")); | ||
var axios_1 = __importDefault(require("axios")); | ||
var chai_1 = require("chai"); | ||
var crypto_1 = require("crypto"); | ||
var querystring_1 = require("querystring"); | ||
var index_1 = require("../index"); | ||
var keys_1 = require("../keys"); | ||
var utils_1 = require("../utils"); | ||
describe("test aes", function () { | ||
var ETH_PRVHEX = "0x95d3c5e483e9b1d4f5fc8e79b2deaf51362980de62dbb082a9a4257eef653d7d"; | ||
var ETH_PUBHEX = "0x98afe4f150642cd05cc9d2fa36458ce0a58567daeaf5fde7333ba9b403011140" | ||
+ "a4e28911fcf83ab1f457a30b4959efc4b9306f514a4c3711a16a80e3b47eb58b"; | ||
var PYTHON_BACKEND = "https://eciespy.herokuapp.com/"; | ||
describe("test encrypt and decrypt", function () { | ||
var text = "helloworld"; | ||
var config = { | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
}; | ||
it("tests aes with random key", function () { | ||
@@ -20,3 +30,3 @@ var key = crypto_1.randomBytes(32); | ||
}); | ||
it("tests aes decrypt with known key and text 'helloworld'", function () { | ||
it("tests aes decrypt with known key and text", function () { | ||
var key = Buffer.from(utils_1.decodeHex("0000000000000000000000000000000000000000000000000000000000000000")); | ||
@@ -30,12 +40,19 @@ var nonce = Buffer.from(utils_1.decodeHex("f3e1ba810d2c8900b11312b7c725565f")); | ||
}); | ||
it("test aes with key", function () { | ||
var prv = new keys_1.PrivateKey(utils_1.decodeHex("0x95d3c5e483e9b1d4f5fc8e79b2deaf51362980de62dbb082a9a4257eef653d7d")); | ||
var encryptedKnown = Buffer.from(utils_1.decodeHex("04496071a70de6a27b690d3ccfed47fddd47b5a2e6de389dd661edc4e53a3a67f" + | ||
"73278cf1e4a74e1a5332b4a6606585385b3d8e05c08a7ced1e3287e8fdc243520" + | ||
"ff276a665c5fcf9e5767a3ff4e423eec935148c81d4f650191423f1be996cef5e" + | ||
"deb2fc40387e6b511dd")); | ||
var decrypted = index_1.decrypt(prv.toHex(), encryptedKnown); | ||
chai_1.expect(decrypted.toString()).to.be.equal(text); | ||
it("test encrypt/decrypt against python version", function () { | ||
var prv = new keys_1.PrivateKey(utils_1.decodeHex(ETH_PRVHEX)); | ||
axios_1.default.post(PYTHON_BACKEND, querystring_1.stringify({ | ||
data: text, | ||
pub: ETH_PUBHEX, | ||
})).then(function (res) { | ||
var encryptedKnown = Buffer.from(utils_1.decodeHex(res.data)); | ||
var decrypted = index_1.decrypt(prv.toHex(), encryptedKnown); | ||
chai_1.expect(decrypted.toString()).to.be.equal(text); | ||
}); | ||
var encrypted = index_1.encrypt(prv.publicKey.toHex(), Buffer.from(text)); | ||
chai_1.expect(decrypted.toString()).to.be.equal(text); | ||
axios_1.default.post(PYTHON_BACKEND, querystring_1.stringify({ | ||
data: encrypted.toString("hex"), | ||
prv: prv.toHex(), | ||
})).then(function (res) { | ||
chai_1.expect(text).to.be.equal(res.data); | ||
}); | ||
}); | ||
@@ -45,3 +62,8 @@ }); | ||
it("test invalid", function () { | ||
chai_1.expect(function () { return new keys_1.PrivateKey(utils_1.decodeHex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142")); }).to.throw(Error); | ||
// 0 < private key < group order int | ||
var groupOrderInt = "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"; | ||
chai_1.expect(function () { return new keys_1.PrivateKey(utils_1.decodeHex(groupOrderInt)); }).to.throw(Error); | ||
var groupOrderIntAdd1 = "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364142"; | ||
chai_1.expect(function () { return new keys_1.PrivateKey(utils_1.decodeHex(groupOrderIntAdd1)); }).to.throw(Error); | ||
chai_1.expect(function () { return new keys_1.PrivateKey(utils_1.decodeHex("0")); }).to.throw(Error); | ||
}); | ||
@@ -55,7 +77,6 @@ it("tests equal", function () { | ||
chai_1.expect(isFromHexWorking).to.be.equal(true); | ||
var ethPrvHex = "0x95d3c5e483e9b1d4f5fc8e79b2deaf51362980de62dbb082a9a4257eef653d7d"; | ||
var ethPubHex = "0x98afe4f150642cd05cc9d2fa36458ce0a58567daeaf5fde7333ba9b403011140" | ||
+ "a4e28911fcf83ab1f457a30b4959efc4b9306f514a4c3711a16a80e3b47eb58b"; | ||
var ethPrv = keys_1.PrivateKey.fromHex(ethPrvHex); | ||
var ethPub = keys_1.PublicKey.fromHex(ethPubHex); | ||
}); | ||
it("tests eth key compatibility", function () { | ||
var ethPrv = keys_1.PrivateKey.fromHex(ETH_PRVHEX); | ||
var ethPub = keys_1.PublicKey.fromHex(ETH_PUBHEX); | ||
chai_1.expect(ethPub.equals(ethPrv.publicKey)).to.be.equal(true); | ||
@@ -73,23 +94,2 @@ }); | ||
}); | ||
describe("test string <-> buffer utils ", function () { | ||
it("tests sha256", function () { | ||
var digest = utils_1.sha256(Buffer.from(new Uint8Array(16))).toString("hex"); | ||
var allZeroDigest = "374708fff7719dd5979ec875d56cd2286f6d3cf7ec317a3b25632aab28ec37bb"; | ||
chai_1.expect(digest).to.equal(allZeroDigest); | ||
}); | ||
it("should remove 0x", function () { | ||
chai_1.expect(utils_1.remove0x("0x0011")).to.equal("0011"); | ||
chai_1.expect(utils_1.remove0x("0011")).to.equal("0011"); | ||
chai_1.expect(utils_1.remove0x("0X0022")).to.equal("0022"); | ||
chai_1.expect(utils_1.remove0x("0022")).to.equal("0022"); | ||
}); | ||
it("should generate valid secret", function () { | ||
var key = utils_1.getValidSecret(); | ||
chai_1.expect(secp256k1_1.default.privateKeyVerify(key)).to.equal(true); | ||
}); | ||
it("should convert hex to buffer", function () { | ||
var decoded = utils_1.decodeHex("0x0011"); | ||
chai_1.expect(decoded.equals(Buffer.from([0, 0x11]))).to.equal(true); | ||
}); | ||
}); | ||
//# sourceMappingURL=crypt.test.js.map |
@@ -29,6 +29,7 @@ { | ||
}, | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"devDependencies": { | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.5", | ||
"axios": "^0.18.0", | ||
"chai": "^4.2.0", | ||
@@ -40,3 +41,3 @@ "codecov": "^3.1.0", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.1.6" | ||
"typescript": "^3.2.1" | ||
}, | ||
@@ -43,0 +44,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18277
17
310
0
10