'use strict';

// import test from 'tape'

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.runEncryptionTests = runEncryptionTests;

var _tape = require('tape-promise/tape');

var _tape2 = _interopRequireDefault(_tape);

var _encryption = require('../../../lib/encryption');

var _sampleData = require('./sampleData');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function runEncryptionTests() {
  var privateKey = 'a5c61c6ca7b3e7e55edee68566aeab22e4da26baa285c7bd10e8d2218aa3b229';
  var publicKey = '027d28f9951ce46538951e3697c62588a87f1f1f295de4a14fdd4c780fc52cfe69';
  var nameLookupURL = 'https://explorer-api.appartisan.com/get_name_blockchain_record/';

  (0, _tape2.default)('encrypt-to-decrypt works', function (t) {
    t.plan(2);

    var testString = "all work and no play makes jack a dull boy";
    var cipherObj = (0, _encryption.encryptECIES)(publicKey, testString);
    var deciphered = (0, _encryption.decryptECIES)(privateKey, cipherObj);
    t.equal(deciphered, testString, 'Decrypted ciphertext does not match expected plaintext');

    var testBuffer = new Buffer(testString);
    cipherObj = (0, _encryption.encryptECIES)(publicKey, testBuffer);
    deciphered = (0, _encryption.decryptECIES)(privateKey, cipherObj);
    t.equal(deciphered.toString('hex'), testBuffer.toString('hex'), 'Decrypted cipherbuffer does not match expected plainbuffer');
  });

  (0, _tape2.default)('encrypt-to-decrypt fails on bad mac', function (t) {
    t.plan(1);

    var testString = "all work and no play makes jack a dull boy";
    var cipherObj = (0, _encryption.encryptECIES)(publicKey, testString);
    var evilString = "some work and some play makes jack a dull boy";
    var evilObj = (0, _encryption.encryptECIES)(publicKey, evilString);

    cipherObj.cipherText = evilObj.cipherText;

    try {
      (0, _encryption.decryptECIES)(privateKey, cipherObj);
      t.true(false, 'Decryption should have failed when ciphertext modified');
    } catch (e) {
      t.true(true, 'Decryption correctly fails when ciphertext modified');
    }
  });
}