import { nanoid } from 'nanoid';
import { keys } from 'libp2p-crypto';
import { expect } from 'aegir/utils/chai.js';
import {
  getDescribe,
  getIt
} from '../utils/mocha.js';
export function testImport(factory, options) {
  const describe = getDescribe(options);
  const it = 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();
      const key = await keys.generateKeyPair('Ed25519');
      const exported = await key.export(password);
      const importedKey = await ipfs.key.import('clone', exported, password);
      expect(importedKey).to.exist();
      expect(importedKey).to.have.property('name', 'clone');
      expect(importedKey).to.have.property('id');
    });
  });
}