'use strict';

module.exports = function id(self) {
  return function (opts, callback) {
    if (typeof opts === 'function') {
      callback = opts;
      opts = {};
    }
    if (!self._peerInfo) {
      // because of split second warmup
      setTimeout(ready, 100);
    } else {
      ready();
    }

    function ready() {
      callback(null, {
        ID: self._peerInfo.id.toB58String(),
        PublicKey: self._peerInfo.id.pubKey.toString('base64'),
        Addresses: self._peerInfo.multiaddrs.map(function (ma) {
          return ma.toString();
        }),
        AgentVersion: 'js-ipfs',
        ProtocolVersion: '9000'
      });
    }
  };
};