@exodus/headless 2.0.0-alpha.128 → 2.0.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,21 @@
1
+ import EventEmitter from 'events/'
2
+ import createRemoteConfig from '@exodus/config/remote'
3
+ import keychainDefinition from '@exodus/keychain/module'
4
+ import walletDefinition from '@exodus/wallet/module'
5
+ import walletAccountsDefinition from '@exodus/wallet-accounts/module'
6
+ import blockchainMetadataDefinition from '@exodus/blockchain-metadata/module'
7
+ import enabledAssetsModuleDefinition from '@exodus/enabled-assets/module'
8
+ import availableAssetsModuleDefinition from '@exodus/available-assets/module'
1
9
  import createKeyIdentifierProvider from '@exodus/key-identifier-provider'
2
10
  import walletCompatibilityModesDefinition from '@exodus/wallet-compatibility-modes/module'
11
+ import balancesDefinition from '@exodus/balances/module'
3
12
 
4
13
  import createApplication from '../application'
5
- import unlockEncryptedStorageDefinition from '../unlock-encrypted-storage'
6
14
  import { withType } from './utils'
15
+ import unlockEncryptedStorageDefinition from '../unlock-encrypted-storage'
16
+ import createExodusPricingClient from '@exodus/exodus-pricing-client'
7
17
 
8
- const createModuleDependencies = ({ config }) =>
18
+ const createModuleDependencies = () =>
9
19
  [
10
20
  {
11
21
  definition: {
@@ -21,12 +31,41 @@ const createModuleDependencies = ({ config }) =>
21
31
  dependencies: [],
22
32
  },
23
33
  },
34
+ {
35
+ definition: keychainDefinition,
36
+ },
37
+ {
38
+ definition: walletDefinition,
39
+ },
24
40
  {
25
41
  definition: walletCompatibilityModesDefinition,
26
- storage: { namespace: 'walletCompatibilityModes' },
27
- aliases: [{ implementationId: 'unsafeStorage', interfaceId: 'storage' }],
28
42
  },
29
43
  { definition: unlockEncryptedStorageDefinition },
44
+ { definition: walletAccountsDefinition },
45
+ {
46
+ definition: blockchainMetadataDefinition,
47
+ storage: { namespace: ['blockchain', 'v1'] },
48
+ },
49
+ { definition: enabledAssetsModuleDefinition },
50
+ {
51
+ definition: {
52
+ id: 'remoteConfig',
53
+ factory: (deps) => {
54
+ const eventEmitter = new EventEmitter().setMaxListeners(Number.POSITIVE_INFINITY)
55
+ return createRemoteConfig({ eventEmitter, ...deps })
56
+ },
57
+ dependencies: ['fetch', 'freeze', 'config', 'logger'],
58
+ },
59
+ },
60
+ { definition: availableAssetsModuleDefinition },
61
+ {
62
+ definition: {
63
+ id: 'pricingClient',
64
+ factory: createExodusPricingClient,
65
+ dependencies: ['fetch', 'pricingServerUrlAtom'],
66
+ },
67
+ },
68
+ { definition: balancesDefinition },
30
69
  ].map(withType('module'))
31
70
 
32
71
  export default createModuleDependencies
@@ -0,0 +1,33 @@
1
+ import marketHistoryMonitorDefinition from '@exodus/market-history/module'
2
+ import ratesMonitorDefinition from '@exodus/rates-monitor/module'
3
+
4
+ import { withType } from './utils'
5
+
6
+ const createModuleDependencies = () =>
7
+ [
8
+ {
9
+ definition: marketHistoryMonitorDefinition,
10
+ storage: { namespace: 'marketHistory' },
11
+ aliases: [
12
+ {
13
+ implementationId: 'unsafeStorage',
14
+ interfaceId: 'storage',
15
+ },
16
+ {
17
+ implementationId: 'marketHistoryClearCacheAtom',
18
+ interfaceId: 'clearCacheAtom',
19
+ },
20
+ {
21
+ implementationId: 'remoteConfigClearMarketHistoryCacheAtom',
22
+ interfaceId: 'remoteConfigClearCacheAtom',
23
+ },
24
+ {
25
+ implementationId: 'marketHistoryRefreshIntervalAtom',
26
+ interfaceId: 'remoteConfigRefreshIntervalAtom',
27
+ },
28
+ ],
29
+ },
30
+ { definition: ratesMonitorDefinition },
31
+ ].map(withType('monitor'))
32
+
33
+ export default createModuleDependencies
@@ -2,6 +2,10 @@ export const wrapConstant = ({ id, type, value }) => ({
2
2
  definition: { id, type, factory: () => value },
3
3
  })
4
4
 
5
+ export const insertIf = (module, enabled) => {
6
+ return enabled ? [module] : []
7
+ }
8
+
5
9
  export const withType =
6
10
  (type) =>
7
11
  ({ definition, ...rest }) => ({
package/src/index.js CHANGED
@@ -1,121 +1,114 @@
1
- import addressProvider from '@exodus/address-provider'
2
- import assetsFeature from '@exodus/assets-feature'
3
- import availableAssets from '@exodus/available-assets'
4
- import balances from '@exodus/balances'
5
- import blockchainMetadata from '@exodus/blockchain-metadata'
6
- import enabledAssets from '@exodus/enabled-assets'
7
- import featureFlags from '@exodus/feature-flags'
8
- import fees from '@exodus/fee-data-monitors'
9
- import geolocation from '@exodus/geolocation'
10
- import keychain from '@exodus/keychain'
11
- import locale from '@exodus/locale'
12
- import pricing from '@exodus/pricing'
13
- import rates from '@exodus/rates-monitor'
14
- import remoteConfig from '@exodus/remote-config'
15
- import restoreProgressTracker from '@exodus/restore-progress-tracker'
16
- import wallet from '@exodus/wallet'
17
- import walletAccounts from '@exodus/wallet-accounts'
18
-
19
- import createApi from './api'
1
+ import { pick } from '@exodus/basic-utils'
20
2
  import createIOC from './ioc'
21
- import attachMigrations from './migrations/attach'
3
+ import createApi from './api'
4
+ import {
5
+ createAccountStatesUpdateHandler,
6
+ createLoadWalletAccountsHandler,
7
+ } from './utils/blockchain-metadata'
8
+
22
9
  import attachPlugins from './plugins/attach'
10
+ import attachAtoms from './atoms/attach'
11
+ import { atomsToAttach } from './constants'
23
12
 
24
13
  const createExodus = ({ adapters, config, port }) => {
25
14
  const ioc = createIOC({ adapters, config })
26
-
27
- ioc.use(assetsFeature())
28
- ioc.use(addressProvider({ config: config.addressProvider }))
29
- ioc.use(availableAssets())
30
- ioc.use(balances(config.balances))
31
- ioc.use(blockchainMetadata())
32
- ioc.use(enabledAssets())
33
- ioc.use(featureFlags())
34
- ioc.use(fees())
35
- ioc.use(geolocation())
36
- ioc.use(keychain(config.keychain))
37
- ioc.use(locale())
38
- ioc.use(pricing())
39
- ioc.use(rates())
40
- ioc.use(remoteConfig())
41
- ioc.use(restoreProgressTracker())
42
- ioc.use(wallet())
43
- ioc.use(walletAccounts())
44
-
45
- ioc.register({ definition: { id: 'port', type: 'port', factory: () => port } })
15
+ const { headless: headlessConfig } = config
46
16
 
47
17
  const resolve = () => {
48
18
  ioc.resolve()
49
19
 
50
- const { storage, fusion } = ioc.getByType('adapter')
20
+ const { assetsModule, storage } = ioc.getByType('adapter')
51
21
 
52
- const { lockedAtom } = ioc.getByType('atom')
22
+ const {
23
+ application,
24
+ blockchainMetadata,
25
+ enabledAssets,
26
+ remoteConfig,
27
+ unlockEncryptedStorage,
28
+ walletAccounts,
29
+ } = ioc.getByType('module')
30
+
31
+ const { marketHistory, ratesMonitor } = ioc.getByType('monitor')
32
+
33
+ const handleLoadWalletAccounts = createLoadWalletAccountsHandler({
34
+ blockchainMetadata,
35
+ port,
36
+ config,
37
+ })
53
38
 
54
- const { application, wallet, unlockEncryptedStorage } = ioc.getByType('module')
39
+ const handleAccountStatesUpdate = createAccountStatesUpdateHandler({
40
+ blockchainMetadata,
41
+ port,
42
+ config,
43
+ })
55
44
 
56
- const { migrations, assetsModule } = ioc.getAll()
45
+ blockchainMetadata.on('load-wallet-accounts', handleLoadWalletAccounts)
46
+ blockchainMetadata.on('tx-logs-update', (payload) => port.emit('tx-logs-update', payload))
47
+ blockchainMetadata.on('account-states-update', handleAccountStatesUpdate)
57
48
 
58
- application.on('start', (payload) => port.emit('start', payload))
49
+ remoteConfig.on('sync', ({ current }) => port.emit('remote-config', current))
59
50
 
60
- application.hook('load', (args) => port.emit('pre-load', args))
51
+ // TODO: migrate to marketHistoryAtom. Will be easier once it's on headless
52
+ marketHistory.on('market-history', (payload) => port.emit('market-history', payload))
61
53
 
62
- application.on('load', (args) => port.emit('load', args))
54
+ // TODO: migrate to ratesAtom. Will be easier once it's on headless
55
+ ratesMonitor.on('rates', (payload) => port.emit('rates', payload))
63
56
 
64
- application.on('create', async ({ hasPassphraseSet }) => {
65
- const isLocked = await wallet.isLocked()
57
+ application.hook('start', () => {
58
+ remoteConfig.load()
66
59
 
67
- port.emit('create', {
68
- walletExists: true,
69
- hasPassphraseSet,
70
- isLocked,
71
- isBackedUp: false,
72
- isRestoring: false,
73
- })
60
+ port.emit('start')
74
61
  })
75
62
 
76
- application.on('unlock', () => port.emit('unlock'))
77
-
78
- application.on('lock', () => port.emit('lock'))
79
-
80
- application.on('backup', () => port.emit('backup'))
81
-
82
- application.on('restore', () => port.emit('restore'))
63
+ application.hook('unlock', async () => {
64
+ if (typeof storage.unlock === 'function') unlockEncryptedStorage(storage)
83
65
 
84
- application.on('restore-completed', () => {
85
- port.emit('restore-completed')
66
+ remoteConfig.sync()
67
+ marketHistory.start()
68
+ ratesMonitor.start()
69
+
70
+ await assetsModule.load()
71
+ await walletAccounts.load()
72
+ await Promise.all([
73
+ //
74
+ blockchainMetadata.load(),
75
+ enabledAssets.load(),
76
+ ])
86
77
  })
87
78
 
88
- application.on('change-passphrase', () => port.emit('passphrase-changed'))
89
-
90
- application.on('import', () => port.emit('import', { walletExists: true }))
91
-
92
- application.hook('unlock', async () => {
93
- if (typeof storage.unlock === 'function') unlockEncryptedStorage(storage)
79
+ application.on('unlock', () => {
80
+ port.emit('unlock')
94
81
  })
95
82
 
96
83
  application.hook('clear', async () => {
97
- await Promise.all([assetsModule.clear(), fusion.clearStorage()])
84
+ await Promise.all([
85
+ //
86
+ assetsModule.clear(),
87
+ walletAccounts.clear(),
88
+ blockchainMetadata.clear(),
89
+ enabledAssets.clear(),
90
+ ])
91
+
92
+ port.emit('clear')
98
93
  })
99
94
 
100
- application.on('clear', () => port.emit('clear'))
101
-
102
- application.on('restart', (payload) => port.emit('restart', payload))
103
-
104
- attachMigrations({
105
- migrations,
106
- adapters,
107
- application,
108
- atoms: ioc.getByType('atom'),
109
- modules: ioc.getByType('module'),
95
+ application.on('restart', (payload) => {
96
+ port.emit('restart', payload)
110
97
  })
111
98
 
112
- attachPlugins({
99
+ attachAtoms({
100
+ port,
113
101
  application,
114
- plugins: ioc.getByType('plugin'),
115
- logger: ioc.get('createLogger')('attachPlugins'),
102
+ logger: ioc.get('createLogger')('attachAtoms'),
103
+ atoms: pick(ioc.getByType('atom'), atomsToAttach),
104
+ lifecycleEvents: headlessConfig?.attachAtomsLifecycleEvents,
116
105
  })
117
106
 
118
- return createApi({ ioc, port, lockedAtom })
107
+ attachPlugins({ application, plugins: ioc.getByType('plugin') })
108
+
109
+ application.start()
110
+
111
+ return createApi({ ioc, port })
119
112
  }
120
113
 
121
114
  return { ...ioc, resolve }
package/src/ioc.js CHANGED
@@ -1,74 +1,30 @@
1
1
  import createIocContainer from '@exodus/dependency-injection'
2
2
  import preprocess from '@exodus/dependency-preprocessors'
3
3
  import alias from '@exodus/dependency-preprocessors/src/preprocessors/alias'
4
- import configPreprocessor from '@exodus/dependency-preprocessors/src/preprocessors/config'
5
- import devModeAtoms from '@exodus/dependency-preprocessors/src/preprocessors/dev-mode-atoms'
6
4
  import logify from '@exodus/dependency-preprocessors/src/preprocessors/logify'
5
+ import namespaceConfig from '@exodus/dependency-preprocessors/src/preprocessors/namespace-config'
7
6
  import namespaceStorage from '@exodus/dependency-preprocessors/src/preprocessors/namespace-storage'
8
- import optional from '@exodus/dependency-preprocessors/src/preprocessors/optional'
9
- import performanceMonitor from '@exodus/dependency-preprocessors/src/preprocessors/performance-monitor'
10
- import readOnlyAtoms from '@exodus/dependency-preprocessors/src/preprocessors/read-only-atoms'
11
- import assert from 'minimalistic-assert'
12
7
 
13
8
  import createDependencies from './dependencies'
14
9
 
15
10
  const createIOC = ({ adapters, config }) => {
16
- const { createLogger, performance = {} } = adapters
17
- const {
18
- readOnlyAtoms: readOnlyAtomsConfig,
19
- devModeAtoms: devModeAtomsConfig,
20
- performanceMonitor: performanceMonitorConfig,
21
- } = config.ioc ?? {}
22
-
23
- const ioc = createIocContainer({ logger: createLogger('exodus:ioc') })
24
-
25
- const performanceLogger = createLogger('exodus:performance')
11
+ const { createLogger } = adapters
26
12
 
13
+ const logger = createLogger('exodus:ioc')
14
+ const dependencies = createDependencies({ adapters, config })
27
15
  const preprocessors = [
28
16
  logify({ createLogger }),
29
- performanceMonitorConfig?.enabled &&
30
- performanceMonitor({
31
- now: performance.now,
32
- onAboveThreshold:
33
- performance.onAboveThreshold ??
34
- (({ id, method, async, duration }) =>
35
- performanceLogger.log(
36
- `${id}.${method} ${async ? 'resolved after' : 'took'} ${duration}ms`
37
- )),
38
- config: performanceMonitorConfig,
39
- }),
40
- configPreprocessor(),
17
+ namespaceConfig(),
41
18
  alias(),
42
19
  // NOTE: order matters, this should come after `alias`
43
20
  namespaceStorage(),
44
- readOnlyAtoms({
45
- logger: createLogger('exodus:read-only-atoms'),
46
- warn: true,
47
- ...readOnlyAtomsConfig,
48
- }),
49
- optional(),
50
- devModeAtomsConfig && devModeAtoms(devModeAtomsConfig),
51
- ].filter(Boolean)
52
-
53
- const registerMultiple = (dependencies) => {
54
- ioc.registerMultiple(preprocess({ dependencies, preprocessors }))
55
- }
56
-
57
- const register = (dependency) => {
58
- registerMultiple([dependency])
59
- }
60
-
61
- const use = (module) => {
62
- for (const { definition } of module.definitions) {
63
- assert(definition.type, `ioc.use: "${definition.id}" is missing type field`)
64
- }
65
-
66
- registerMultiple(module.definitions)
67
- }
21
+ ]
22
+ const definitions = preprocess({ dependencies, preprocessors })
23
+ const ioc = createIocContainer({ logger })
68
24
 
69
- registerMultiple(createDependencies({ adapters, config }))
25
+ ioc.registerMultiple(definitions)
70
26
 
71
- return { ...ioc, register, registerMultiple, use }
27
+ return ioc
72
28
  }
73
29
 
74
30
  export default createIOC
@@ -1,38 +1,17 @@
1
- import { LifecycleHook } from '../constants'
1
+ import { kebabCase, memoize } from 'lodash'
2
2
 
3
- const LIFECYCLE_METHOD_TO_HOOK_NAME = Object.fromEntries(
4
- Object.entries(LifecycleHook).map(([pascalCaseName, hookName]) => [
5
- `on${pascalCaseName}`,
6
- hookName,
7
- ])
3
+ // e.g. onUnlock -> unlock -> onUnlock, onChangePassphrase -> change-passphrase
4
+ const getApplicationHookName = memoize((lifecycleMethod) =>
5
+ kebabCase(lifecycleMethod.replace(/^on/, ''))
8
6
  )
9
7
 
10
- const attachPlugins = ({ plugins, application, logger }) => {
11
- const timeFn = (fn, name) => {
12
- const pluginWrapper = async (...args) => {
13
- const start = Date.now()
14
- try {
15
- return await fn(...args)
16
- } finally {
17
- logger.debug(name, `${Date.now() - start}ms`)
18
- }
19
- }
20
-
21
- Object.defineProperty(pluginWrapper, 'name', { value: name, writable: false })
22
-
23
- return pluginWrapper
24
- }
25
-
8
+ const attachPlugins = ({ plugins, application }) => {
26
9
  Object.entries(plugins).forEach(([name, lifecycleMethods]) => {
27
10
  const entries = Object.entries(lifecycleMethods || {})
28
11
 
29
12
  for (const [lifecycleMethod, fn] of entries) {
30
- const hookName = LIFECYCLE_METHOD_TO_HOOK_NAME[lifecycleMethod]
31
- if (hookName) {
32
- application.hook(hookName, timeFn(fn, `plugin ${name}.${lifecycleMethod}`))
33
- } else {
34
- logger.error(`plugin "${name}" declares unsupported lifecycle method "${lifecycleMethod}"`)
35
- }
13
+ const hookName = getApplicationHookName(lifecycleMethod)
14
+ application.hook(hookName, fn)
36
15
  }
37
16
  })
38
17
  }
@@ -1,5 +1,3 @@
1
- import autoEnableAssetsPlugin from '@exodus/auto-enable-assets-plugin'
2
-
3
1
  import logLifecyclePlugin from './log-lifecycle'
4
2
 
5
- export default [logLifecyclePlugin, autoEnableAssetsPlugin]
3
+ export default [logLifecyclePlugin]
@@ -9,7 +9,6 @@ const logLifecycle = {
9
9
  onImport: () => logger.debug('onImport'),
10
10
  onMigrate: () => logger.debug('onMigrate'),
11
11
  onStart: () => logger.debug('onStart'),
12
- onRestart: () => logger.debug('onRestart'),
13
12
  onLoad: () => logger.debug('onLoad'),
14
13
  onUnload: () => logger.debug('onUnload'),
15
14
  onCreate: () => logger.debug('onCreate'),
@@ -12,10 +12,8 @@ const createUnlockEncryptedStorage = ({ keychain }) => {
12
12
  }
13
13
  }
14
14
 
15
- // eslint-disable-next-line @exodus/export-default/named
16
15
  export default {
17
16
  id: 'unlockEncryptedStorage',
18
- type: 'module',
19
17
  factory: createUnlockEncryptedStorage,
20
18
  dependencies: ['keychain'],
21
19
  }
@@ -0,0 +1,48 @@
1
+ import { mapValues } from '@exodus/basic-utils'
2
+
3
+ const createAccountStatesTransformer = ({ serializePortPayloads, blockchainMetadata }) => {
4
+ return serializePortPayloads
5
+ ? (payload) =>
6
+ mapValues(payload, (byAsset, walletAccount) =>
7
+ mapValues(
8
+ byAsset,
9
+ (accountState, assetName) =>
10
+ blockchainMetadata.serializePayload({ walletAccount, assetName, accountState })
11
+ .accountState
12
+ )
13
+ )
14
+ : (payload) => payload
15
+ }
16
+
17
+ export function createAccountStatesUpdateHandler({
18
+ port,
19
+ blockchainMetadata,
20
+ config: { serializePortPayloads = false },
21
+ }) {
22
+ const transform = createAccountStatesTransformer({ serializePortPayloads, blockchainMetadata })
23
+
24
+ return (payload) => {
25
+ port.emit('account-states-update', transform(payload))
26
+ }
27
+ }
28
+
29
+ export function createLoadWalletAccountsHandler({
30
+ port,
31
+ blockchainMetadata,
32
+ config: { serializePortPayloads = false },
33
+ }) {
34
+ const transformAccountStates = createAccountStatesTransformer({
35
+ serializePortPayloads,
36
+ blockchainMetadata,
37
+ })
38
+
39
+ return async () => {
40
+ const [txLogs, accountStates] = await Promise.all([
41
+ blockchainMetadata.getLoadedTxLogs(),
42
+ blockchainMetadata.getLoadedAccountStates(),
43
+ ])
44
+
45
+ port.emit('tx-logs', txLogs)
46
+ port.emit('account-states', transformAccountStates(accountStates))
47
+ }
48
+ }
@@ -1,40 +0,0 @@
1
- import { combine, compute, dedupe } from '@exodus/atoms'
2
- import { uniq } from 'lodash'
3
-
4
- const getNetworks = (assetNames, assets) =>
5
- uniq(
6
- assetNames
7
- .map((assetName) => assets[assetName]?.baseAsset.name)
8
- .filter((assetName) => !!assetName && !assets[assetName].isCombined)
9
- )
10
-
11
- const createBaseAssetNamesToMonitorAtom = ({
12
- assetsModule,
13
- enabledAssetsAtom,
14
- restoreAtom,
15
- availableAssetNamesAtom,
16
- }) => {
17
- const selector = ({ isRestore, enabledAssets, availableAssetNames }) => {
18
- const assetNames = isRestore ? availableAssetNames : Object.keys(enabledAssets)
19
- return getNetworks(assetNames, assetsModule.getAssets())
20
- }
21
-
22
- return dedupe(
23
- compute({
24
- atom: combine({
25
- isRestore: restoreAtom,
26
- enabledAssets: enabledAssetsAtom,
27
- availableAssetNames: availableAssetNamesAtom,
28
- }),
29
- selector,
30
- })
31
- )
32
- }
33
-
34
- // eslint-disable-next-line @exodus/export-default/named
35
- export default {
36
- id: 'baseAssetNamesToMonitorAtom',
37
- type: 'atom',
38
- factory: createBaseAssetNamesToMonitorAtom,
39
- dependencies: ['assetsModule', 'availableAssetNamesAtom', 'enabledAssetsAtom', 'restoreAtom'],
40
- }
@@ -1,60 +0,0 @@
1
- import { deriveSyncKeys } from '../utils/fusion'
2
-
3
- const attachMigrations = ({ migrations = [], application, modules, adapters, ...deps }) => {
4
- const { analytics, unlockEncryptedStorage, wallet } = modules
5
- const { unsafeStorage, migrateableStorage, fusionKeysDeferred, migrateableFusion } = adapters
6
-
7
- // Override encrypted storage with migrations own instance to make sure no modules reads from it before migrations ran
8
- const migrationFlagsStorage = unsafeStorage.namespace('migrations')
9
- const migrationAdapters = { ...adapters, storage: migrateableStorage, fusion: migrateableFusion }
10
-
11
- const attachMigration = async (migration) => {
12
- const { name, factory } = migration
13
- const logger = adapters.createLogger(`exodus:migration:${name}`)
14
-
15
- logger.log('running migration')
16
-
17
- let success = false
18
-
19
- try {
20
- const start = performance.now()
21
-
22
- await factory({ ...deps, adapters: migrationAdapters, modules, logger })
23
-
24
- const time = performance.now() - start
25
-
26
- logger.log(`migration successful in ${time.toFixed(2)}ms`)
27
-
28
- await migrationFlagsStorage.set(name, true)
29
-
30
- success = true
31
- } catch (error) {
32
- logger.log(`migration failed: ${error.stack}`)
33
- } finally {
34
- analytics.track({
35
- event: 'ClientMigrationRun',
36
- properties: { migrationId: name, success },
37
- force: true,
38
- })
39
- }
40
- }
41
-
42
- application.hook('migrate', async () => {
43
- await unlockEncryptedStorage(migrateableStorage)
44
- if (fusionKeysDeferred) await deriveSyncKeys(wallet.seed).then(fusionKeysDeferred.resolve)
45
-
46
- const migrationNames = migrations.map((migration) => migration.name)
47
- const migrationFlags = await migrationFlagsStorage.batchGet(migrationNames)
48
- const migrationsDiff = migrations.filter((v, k) => !migrationFlags[k])
49
-
50
- for (const migration of migrationsDiff) {
51
- await attachMigration(migration)
52
- }
53
- })
54
-
55
- application.hook('clear', async () => {
56
- await migrationFlagsStorage.clear()
57
- })
58
- }
59
-
60
- export default attachMigrations
package/src/reporting.js DELETED
@@ -1,27 +0,0 @@
1
- import { zipObject } from 'lodash'
2
-
3
- const createReporting = ({ ioc, lockedAtom }) => {
4
- const getReports = async () => {
5
- if (await lockedAtom.get()) throw new Error('Unable to export when locked')
6
-
7
- const nodes = ioc.getByType('report')
8
- const reports = Object.values(nodes)
9
-
10
- const resolvedReports = await Promise.allSettled(reports.map((report) => report.export()))
11
-
12
- const namespaces = reports.map((report) => report.namespace)
13
- const data = resolvedReports.map((outcome) =>
14
- outcome.status === 'fulfilled' ? outcome.value : { error: outcome.reason }
15
- )
16
-
17
- return zipObject(namespaces, data)
18
- }
19
-
20
- return {
21
- reporting: {
22
- export: getReports,
23
- },
24
- }
25
- }
26
-
27
- export default createReporting
@@ -1,17 +0,0 @@
1
- import { pick } from '@exodus/basic-utils'
2
- import HDKeySlip10 from '@exodus/hd-key-slip-10'
3
- import sodium from '@exodus/sodium-crypto'
4
-
5
- const EXODUS_PURPOSE = Number.parseInt(Buffer.from('exo').toString('hex'), '16')
6
-
7
- const EXO_2_PATH = `m/${EXODUS_PURPOSE}'/2'`
8
-
9
- const BIP43_PURPOSE_SYNC = `${EXO_2_PATH}/0'`
10
-
11
- export const deriveSyncKeys = async (seed) => {
12
- const derived = HDKeySlip10.fromSeed(seed).derive(BIP43_PURPOSE_SYNC).key
13
-
14
- const keys = await sodium.getSodiumKeysFromSeed(derived)
15
-
16
- return pick(keys, ['box', 'sign', 'secret', 'derived'])
17
- }