@@ -4,6 +4,7 @@ import type { PasswordMemLimit, PasswordOpsLimit } from '../keys/types';
4
4
import path from 'path' ;
5
5
import Logger from '@matrixai/logger' ;
6
6
import { DB } from '@matrixai/db' ;
7
+ import { CertManager } from '@/keys' ;
7
8
import * as bootstrapErrors from './errors' ;
8
9
import TaskManager from '../tasks/TaskManager' ;
9
10
import { IdentitiesManager } from '../identities' ;
@@ -14,7 +15,7 @@ import { Sigchain } from '../sigchain';
14
15
import { ACL } from '../acl' ;
15
16
import { GestaltGraph } from '../gestalts' ;
16
17
import { KeyRing } from '../keys' ;
17
- import { NodeConnectionManager , NodeGraph , NodeManager } from '../nodes' ;
18
+ import { NodeGraph , NodeManager } from '../nodes' ;
18
19
import { VaultManager } from '../vaults' ;
19
20
import { NotificationsManager } from '../notifications' ;
20
21
import { mkdirExists } from '../utils' ;
@@ -43,8 +44,6 @@ async function bootstrapState({
43
44
// Required parameters
44
45
password,
45
46
// Optional configuration
46
- // nodePath = config.defaults.nodePath,
47
- // keyRingConfig = {},
48
47
options = { } ,
49
48
fresh = false ,
50
49
// Optional dependencies
@@ -53,30 +52,37 @@ async function bootstrapState({
53
52
} : {
54
53
password : string ;
55
54
options ?: DeepPartial < BootstrapOptions > ;
56
- // NodePath?: string;
57
- // keyRingConfig?: {
58
- // recoveryCode?: RecoveryCode;
59
- // privateKey?: PrivateKey;
60
- // privateKeyPath?: string;
61
- // passwordOpsLimit?: PasswordOpsLimit;
62
- // passwordMemLimit?: PasswordMemLimit;
63
- // };
64
55
fresh ?: boolean ;
65
56
fs ?: FileSystem ;
66
57
logger ?: Logger ;
67
58
} ) : Promise < RecoveryCode | undefined > {
68
59
const umask = 0o077 ;
69
60
logger . info ( `Setting umask to ${ umask . toString ( 8 ) . padStart ( 3 , '0' ) } ` ) ;
70
61
process . umask ( umask ) ;
71
- logger . info ( `Setting node path to ${ nodePath } ` ) ;
72
- if ( nodePath == null ) {
62
+ const optionsDefaulted = utils . mergeObjects ( options , {
63
+ nodePath : config . defaultsUser . nodePath ,
64
+ keys : {
65
+ certDuration : config . defaultsUser . certDuration ,
66
+ } ,
67
+ } ) ;
68
+ logger . info ( `Setting node path to ${ optionsDefaulted . nodePath } ` ) ;
69
+ if ( optionsDefaulted . nodePath == null ) {
73
70
throw new errors . ErrorUtilsNodePath ( ) ;
74
71
}
75
- await mkdirExists ( fs , nodePath ) ;
72
+ await mkdirExists ( fs , optionsDefaulted . nodePath ) ;
76
73
// Setup node path and sub paths
77
- const statusPath = path . join ( nodePath , config . paths . statusBase ) ;
78
- const statusLockPath = path . join ( nodePath , config . paths . statusLockBase ) ;
79
- const statePath = path . join ( nodePath , config . paths . stateBase ) ;
74
+ const statusPath = path . join (
75
+ optionsDefaulted . nodePath ,
76
+ config . paths . statusBase ,
77
+ ) ;
78
+ const statusLockPath = path . join (
79
+ optionsDefaulted . nodePath ,
80
+ config . paths . statusLockBase ,
81
+ ) ;
82
+ const statePath = path . join (
83
+ optionsDefaulted . nodePath ,
84
+ config . paths . stateBase ,
85
+ ) ;
80
86
const dbPath = path . join ( statePath , config . paths . dbBase ) ;
81
87
const keysPath = path . join ( statePath , config . paths . keysBase ) ;
82
88
const vaultsPath = path . join ( statePath , config . paths . vaultsBase ) ;
@@ -90,7 +96,7 @@ async function bootstrapState({
90
96
await status . start ( { pid : process . pid } ) ;
91
97
if ( ! fresh ) {
92
98
// Check the if number of directory entries is greater than 1 due to status.json and status.lock
93
- if ( ( await fs . promises . readdir ( nodePath ) ) . length > 2 ) {
99
+ if ( ( await fs . promises . readdir ( optionsDefaulted . nodePath ) ) . length > 2 ) {
94
100
throw new bootstrapErrors . ErrorBootstrapExistingState ( ) ;
95
101
}
96
102
}
@@ -110,7 +116,12 @@ async function bootstrapState({
110
116
fs,
111
117
logger : logger . getChild ( KeyRing . name ) ,
112
118
fresh,
113
- ...keyRingConfig ,
119
+ recoveryCode : optionsDefaulted . recoveryCode ,
120
+ privateKey : optionsDefaulted . privateKey ,
121
+ privateKeyPath : optionsDefaulted . privateKeyPath ,
122
+ passwordOpsLimit : optionsDefaulted . passwordOpsLimit ,
123
+ passwordMemLimit : optionsDefaulted . passwordMemLimit ,
124
+ strictMemoryLock : optionsDefaulted . strictMemoryLock ,
114
125
} ) ;
115
126
const db = await DB . createDB ( {
116
127
dbPath,
@@ -135,6 +146,19 @@ async function bootstrapState({
135
146
} ,
136
147
fresh,
137
148
} ) ;
149
+ const taskManager = await TaskManager . createTaskManager ( {
150
+ db,
151
+ logger,
152
+ lazy : true ,
153
+ } ) ;
154
+ const certManager = await CertManager . createCertManager ( {
155
+ keyRing,
156
+ db,
157
+ taskManager,
158
+ fresh,
159
+ logger,
160
+ certDuration : optionsDefaulted . certDuration ,
161
+ } ) ;
138
162
const sigchain = await Sigchain . createSigchain ( {
139
163
db,
140
164
keyRing,
@@ -166,26 +190,12 @@ async function bootstrapState({
166
190
keyRing,
167
191
logger : logger . getChild ( NodeGraph . name ) ,
168
192
} ) ;
169
- const taskManager = await TaskManager . createTaskManager ( {
170
- db,
171
- logger,
172
- lazy : true ,
173
- } ) ;
174
- const nodeConnectionManager = new NodeConnectionManager ( {
175
- // No streams are created
176
- handleStream : ( ) => { } ,
177
- keyRing,
178
- nodeGraph,
179
- quicClientConfig : { } as any , // No connections are attempted
180
- crypto : { } as any , // No connections are attempted
181
- quicSocket : { } as any , // No connections are attempted
182
- logger : logger . getChild ( NodeConnectionManager . name ) ,
183
- } ) ;
193
+
184
194
const nodeManager = new NodeManager ( {
185
195
db,
186
196
keyRing,
187
197
nodeGraph,
188
- nodeConnectionManager,
198
+ nodeConnectionManager : { } as any , // No connections are attempted
189
199
sigchain,
190
200
taskManager,
191
201
gestaltGraph,
@@ -195,7 +205,7 @@ async function bootstrapState({
195
205
await NotificationsManager . createNotificationsManager ( {
196
206
acl,
197
207
db,
198
- nodeConnectionManager,
208
+ nodeConnectionManager : { } as any , // No connections are attempted
199
209
nodeManager,
200
210
keyRing,
201
211
logger : logger . getChild ( NotificationsManager . name ) ,
@@ -206,7 +216,7 @@ async function bootstrapState({
206
216
db,
207
217
gestaltGraph,
208
218
keyRing,
209
- nodeConnectionManager,
219
+ nodeConnectionManager : { } as any , // No connections are attempted
210
220
vaultsPath,
211
221
notificationsManager,
212
222
logger : logger . getChild ( VaultManager . name ) ,
@@ -227,6 +237,7 @@ async function bootstrapState({
227
237
await gestaltGraph . stop ( ) ;
228
238
await acl . stop ( ) ;
229
239
await sigchain . stop ( ) ;
240
+ await certManager . stop ( ) ;
230
241
await taskManager . stop ( ) ;
231
242
await db . stop ( ) ;
232
243
await keyRing . stop ( ) ;
0 commit comments