diff --git a/test.js b/test.js index 164d93c..1470a34 100644 --- a/test.js +++ b/test.js @@ -205,6 +205,26 @@ describe("ECIES", function() { var encOpts = {ephemPrivateKey: ephemPrivateKey, iv: iv}; var decOpts = {iv: iv, ephemPublicKey: ephemPublicKey, ciphertext: ciphertext, mac: mac}; + // To comply to the Spec + const samplePrivateKey = Buffer.from( + "5be6facd941b76e9d3ead03029fbdb6b6e0809293f7fb197d0c51f84e96b8ba4", + "hex"), + sampleIV = Buffer.from("bddb7c2829b08038753084a2f3991681", "hex"), + // notice the simple (not encoded) pubkey here + samplePublicKey = Buffer.from( + "0409d4e5c0ab3d25fe048c64c9da1a242c7f19417e9517cd266950d72c755713585c6178e97fe092fc897c9a1f1720d5770ae8eaad2fa8fcbd08e9324a5dde1857", "hex"), + sampleData = "The quick brown fox jumps over the lazy dog.", + sampleCiphertext = Buffer.from( + "64203d5b24688e2547bba345fa139a5a1d962220d4d48a0cf3b1572c0d95b61643a6f9a0d75af7eacc1bd957147bf723", "hex"), + // a pubkey encoded with curve number and length + sampleEphemPublicKey = Buffer.from( + "02ca00200293213dcf1388b61c2ae5cf80fee6ffffc049a2f9fe7365fe3867813ca812920020df94686c6afb565ac6149b153d61b3b287ee2c7f997c14238796c12b43a3865a", + "hex"), + sampleMAC = Buffer.from( + "f2526d61b4851fb23409863826fd206165edc021368c7946571cead69046e619", + "hex"); + + it("should encrypt", function() { return eccrypto.encrypt(publicKeyB, Buffer.from("test"), encOpts) .then(function(enc) { @@ -266,6 +286,18 @@ describe("ECIES", function() { }); }); + // To comply to the Spec and the network + it("should comply to the Spec", function() { + return eccrypto.encrypt(samplePublicKey, sampleData, { + iv: sampleIV, ephemPrivateKey: samplePrivateKey + }).then( + function(enc) { + expect(bufferEqual(enc.iv, sampleIV)).to.be.true; + expect(bufferEqual(enc.ciphertext, sampleCiphertext)).to.be.true; + expect(bufferEqual(enc.ephemPublicKey, sampleEphemPublicKey)).to.be.true; + expect(bufferEqual(enc.mac, sampleMAC)).to.be.true; + }); + }); it("should reject promise on bad private key when decrypting", function(done) { eccrypto.encrypt(publicKeyA, Buffer.from("test")).then(function(enc) {