"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.migrateToAskar = 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 _askarReactNative = require("@openwallet-foundation/askar-react-native");
var _reactNative2 = require("react-native");
var RNFS = _interopRequireWildcard(require("react-native-fs"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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: _askarReactNative.askar
      })
    },
    dependencies: _reactNative.agentDependencies
  });
  const updater = await _indySdkToAskarMigration.IndySdkToAskarMigrationUpdater.initialize({
    dbPath,
    agent: aAgent
  });
  await updater.update();
};
exports.migrateToAskar = migrateToAskar;
//# sourceMappingURL=migration.js.map