'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var nanoid = require('nanoid');
var libp2pCrypto = require('libp2p-crypto');
var chai_js = require('aegir/utils/chai.js');
var mocha = require('../utils/mocha.js');

function testImport(factory, options) {
  const describe = mocha.getDescribe(options);
  const it = mocha.getIt(options);
  describe('.key.import', () => {
    let ipfs;
    before(async () => {
      ipfs = (await factory.spawn()).api;
    });
    after(() => factory.clean());
    it('should import an exported key', async () => {
      const password = nanoid.nanoid();
      const key = await libp2pCrypto.keys.generateKeyPair('Ed25519');
      const exported = await key.export(password);
      const importedKey = await ipfs.key.import('clone', exported, password);
      chai_js.expect(importedKey).to.exist();
      chai_js.expect(importedKey).to.have.property('name', 'clone');
      chai_js.expect(importedKey).to.have.property('id');
    });
  });
}

exports.testImport = testImport;
