@exodus/headless 2.0.0-alpha.102 → 2.0.0-alpha.103
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.
- package/CHANGELOG.md +6 -0
- package/package.json +5 -3
- package/src/index.js +11 -0
- package/src/migrations/attach.js +60 -0
- package/src/utils/fusion.js +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.0-alpha.103](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/headless@2.0.0-alpha.102...@exodus/headless@2.0.0-alpha.103) (2023-08-09)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **headless:** attach migrations ([#3279](https://github.com/ExodusMovement/exodus-hydra/issues/3279)) ([4f78909](https://github.com/ExodusMovement/exodus-hydra/commit/4f78909223b6517855f12ea31ee5976cdf8a3513))
|
|
11
|
+
|
|
6
12
|
## [2.0.0-alpha.102](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/headless@2.0.0-alpha.101...@exodus/headless@2.0.0-alpha.102) (2023-08-09)
|
|
7
13
|
|
|
8
14
|
### ⚠ BREAKING CHANGES
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/headless",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.103",
|
|
4
4
|
"description": "The platform-agnostic Exodus wallet SDK",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@exodus/fee-monitors": "^2.1.0",
|
|
41
41
|
"@exodus/fetch": "^1.2.1",
|
|
42
42
|
"@exodus/geolocation": "^2.1.1",
|
|
43
|
+
"@exodus/hd-key-slip-10": "^2.0.0",
|
|
43
44
|
"@exodus/key-identifier-provider": "^1.1.3",
|
|
44
45
|
"@exodus/keychain": "^4.1.0",
|
|
45
46
|
"@exodus/locale": "^1.1.0",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"@exodus/rates-monitor": "^3.0.0",
|
|
49
50
|
"@exodus/remote-config": "^2.0.0",
|
|
50
51
|
"@exodus/restore-progress-tracker": "^2.0.5",
|
|
52
|
+
"@exodus/sodium-crypto": "^3.2.0",
|
|
51
53
|
"@exodus/wallet": "^9.0.0",
|
|
52
54
|
"@exodus/wallet-accounts": "^12.0.0",
|
|
53
55
|
"@exodus/wallet-compatibility-modes": "^3.0.0",
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
"@exodus/market-history": "^5.0.1",
|
|
74
76
|
"@exodus/models": "^8.11.1",
|
|
75
77
|
"@exodus/nfts": "^5.0.1",
|
|
76
|
-
"@exodus/personal-notes": "^3.
|
|
78
|
+
"@exodus/personal-notes": "^3.4.0",
|
|
77
79
|
"@exodus/referrals": "^7.0.0",
|
|
78
80
|
"@exodus/solana-lib": "^1.3.11",
|
|
79
81
|
"@exodus/solana-meta": "^1.0.2",
|
|
@@ -92,5 +94,5 @@
|
|
|
92
94
|
"nock": "^13.3.1",
|
|
93
95
|
"p-defer": "^4.0.0"
|
|
94
96
|
},
|
|
95
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "1d20c726b9b3b7997c7d026c53b4cb9a83ec298e"
|
|
96
98
|
}
|
package/src/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import createApi from './api'
|
|
|
20
20
|
import attachAtoms from './atoms/attach'
|
|
21
21
|
import { atomsToAttach } from './constants'
|
|
22
22
|
import createIOC from './ioc'
|
|
23
|
+
import attachMigrations from './migrations/attach'
|
|
23
24
|
import attachPlugins from './plugins/attach'
|
|
24
25
|
|
|
25
26
|
const createExodus = ({ adapters, config, port }) => {
|
|
@@ -51,6 +52,8 @@ const createExodus = ({ adapters, config, port }) => {
|
|
|
51
52
|
|
|
52
53
|
const { application, wallet, unlockEncryptedStorage } = ioc.getByType('module')
|
|
53
54
|
|
|
55
|
+
const { migrations } = ioc.getAll()
|
|
56
|
+
|
|
54
57
|
application.on('start', (payload) => port.emit('start', payload))
|
|
55
58
|
|
|
56
59
|
application.on('load', (args) => port.emit('load', args))
|
|
@@ -97,6 +100,14 @@ const createExodus = ({ adapters, config, port }) => {
|
|
|
97
100
|
|
|
98
101
|
application.on('restart', (payload) => port.emit('restart', payload))
|
|
99
102
|
|
|
103
|
+
attachMigrations({
|
|
104
|
+
migrations,
|
|
105
|
+
adapters,
|
|
106
|
+
application,
|
|
107
|
+
atoms: ioc.getByType('atom'),
|
|
108
|
+
modules: ioc.getByType('module'),
|
|
109
|
+
})
|
|
110
|
+
|
|
100
111
|
attachAtoms({
|
|
101
112
|
port,
|
|
102
113
|
application,
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
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
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|