"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.migrateToAskar = exports.didMigrateToAskar = void 0;
var _askar = require("@credo-ts/askar");
var _core = require("@credo-ts/core");
var _indySdkToAskarMigration = require("@credo-ts/indy-sdk-to-askar-migration");
var _reactNative = require("@credo-ts/react-native");
var _ariesAskarReactNative = require("@hyperledger/aries-askar-react-native");
var _reactNative2 = require("react-native");
var RNFS = _interopRequireWildcard(require("react-native-fs"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const didMigrateToAskar = state => state.didMigrateToAskar;
exports.didMigrateToAskar = didMigrateToAskar;
const migrateToAskar = async (walletId, key, agent) => {
  // The backup file is kept in case anything goes wrong. this will allow us to release patches and still update the
  // original indy-sdk database in a future version we could manually add a check to remove the old file from storage.
  const basePath = _reactNative2.Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath : RNFS.ExternalDirectoryPath;
  const dbPath = `${basePath}/.indy_client/wallet/${walletId}/sqlite.db`;
  const aAgent = agent ?? new _core.Agent({
    config: {
      label: 'Aries Bifold',
      walletConfig: {
        id: walletId,
        key
      },
      logger: new _core.ConsoleLogger(_core.LogLevel.trace),
      autoUpdateStorageOnStartup: false
    },
    modules: {
      askar: new _askar.AskarModule({
        ariesAskar: _ariesAskarReactNative.ariesAskar
      })
    },
    dependencies: _reactNative.agentDependencies
  });
  const updater = await _indySdkToAskarMigration.IndySdkToAskarMigrationUpdater.initialize({
    dbPath,
    agent: aAgent
  });
  await updater.update();
};
exports.migrateToAskar = migrateToAskar;
//# sourceMappingURL=migration.js.map