diff --git a/src/migration/network-private-key-migration.js b/src/migration/network-private-key-migration.js index bcf7a04929..48e91d34e7 100644 --- a/src/migration/network-private-key-migration.js +++ b/src/migration/network-private-key-migration.js @@ -1,4 +1,5 @@ import { join } from 'path'; +import appRootPath from 'app-root-path'; import { mkdir, writeFile } from 'fs/promises'; import BaseMigration from './base-migration.js'; import { LIBP2P_KEY_DIRECTORY, LIBP2P_KEY_FILENAME } from '../constants/constants.js'; @@ -9,7 +10,21 @@ class NetworkPrivateKeyMigration extends BaseMigration { this.config.modules?.network?.implementation?.['libp2p-service']?.config?.privateKey; if (networkPrivateKey) { - const directoryPath = join(this.config.appDataPath, LIBP2P_KEY_DIRECTORY); + let directoryPath; + if (process.env.NODE_ENV === 'testnet' || process.env.NODE_ENV === 'mainnet') { + directoryPath = join( + appRootPath.path, + '..', + this.config.appDataPath, + LIBP2P_KEY_DIRECTORY, + ); + } else { + directoryPath = join( + appRootPath.path, + this.config.appDataPath, + LIBP2P_KEY_DIRECTORY, + ); + } const fullPath = join(directoryPath, LIBP2P_KEY_FILENAME); await mkdir(directoryPath, { recursive: true }); await writeFile(fullPath, networkPrivateKey);