text: 'use strict';
  
  Object.defineProperty(exports, '__esModule', { value: true });
  
  var key = require('interface-datastore/key');
  var libp2pRecord = require('libp2p-record');
  var errCode = require('err-code');
  var debug = require('debug');
  var toString = require('uint8arrays/to-string');
  
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  
  var errCode__default = /*#__PURE__*/_interopDefaultLegacy(errCode);
  var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
  
  const log = Object.assign(debug__default["default"]('ipfs:ipns:offline-datastore'), { error: debug__default["default"]('ipfs:ipns:offline-datastore:error') });
  class OfflineDatastore {
    constructor(repo) {
      this._repo = repo;
      this.stores = [];
    }
    async put(key, value) {
      if (!(key instanceof Uint8Array)) {
        throw errCode__default["default"](new Error('Offline datastore key must be a Uint8Array'), 'ERR_INVALID_KEY');
      }
      if (!(value instanceof Uint8Array)) {
        throw errCode__default["default"](new Error('Offline datastore value must be a Uint8Array'), 'ERR_INVALID_VALUE');
      }
      let routingKey;
      try {
        routingKey = this._routingKey(key);
      } catch (err) {
        log.error(err);
        throw errCode__default["default"](new Error('Not possible to generate the routing key'), 'ERR_GENERATING_ROUTING_KEY');
      }
      const record = new libp2pRecord.Record(key, value);
      return this._repo.datastore.put(routingKey, record.serialize());
    }
    async get(key) {
      if (!(key instanceof Uint8Array)) {
        throw errCode__default["default"](new Error('Offline datastore key must be a Uint8Array'), 'ERR_INVALID_KEY');
      }
      let routingKey;
      try {
        routingKey = this._routingKey(key);
      } catch (err) {
        log.error(err);
        throw errCode__default["default"](new Error('Not possible to generate the routing key'), 'ERR_GENERATING_ROUTING_KEY');
      }
      const res = await this._repo.datastore.get(routingKey);
      let record;
      try {
        record = libp2pRecord.Record.deserialize(res);
      } catch (err) {
        log.error(err);
        throw err;
      }
      return record.value;
    }
    _routingKey(key$1) {
      return new key.Key('/dht/record/' + toString.toString(key$1, 'base32'), false);
    }
  }
  
  exports.OfflineDatastore = OfflineDatastore;
  