"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.migrateToAskar = exports.didMigrateToAskar = void 0;
var _askar = require("@aries-framework/askar");
var _core = require("@aries-framework/core");
var _indySdkToAskarMigration = require("@aries-framework/indy-sdk-to-askar-migration");
var _reactNative = require("@aries-framework/react-native");
var _ariesAskarReactNative = require("@hyperledger/aries-askar-react-native");
var _reactNative2 = require("react-native");
var RNFS = _interopRequireWildcard(require("react-native-fs"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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