@constellation-network/node-pilot 0.0.7 → 0.0.9

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.
Files changed (96) hide show
  1. package/README.md +26 -18
  2. package/bin/dev.js +1 -6
  3. package/bin/run.js +1 -1
  4. package/dist/base-command.d.ts +9 -0
  5. package/dist/base-command.js +20 -0
  6. package/dist/checks/check-dependencies.d.ts +1 -0
  7. package/dist/checks/check-dependencies.js +44 -0
  8. package/dist/checks/check-hardware.js +3 -3
  9. package/dist/checks/check-initial-setup.js +6 -4
  10. package/dist/checks/check-layers.js +7 -7
  11. package/dist/checks/check-network.d.ts +3 -0
  12. package/dist/checks/check-network.js +92 -9
  13. package/dist/checks/check-node-ctl.d.ts +5 -0
  14. package/dist/checks/check-node-ctl.js +88 -0
  15. package/dist/checks/check-project.js +33 -13
  16. package/dist/checks/check-wallet.d.ts +3 -0
  17. package/dist/checks/check-wallet.js +37 -0
  18. package/dist/clm.d.ts +1 -0
  19. package/dist/clm.js +4 -1
  20. package/dist/commands/config/get.d.ts +6 -0
  21. package/dist/commands/config/get.js +57 -11
  22. package/dist/commands/config/set.d.ts +0 -1
  23. package/dist/commands/config/set.js +13 -11
  24. package/dist/commands/config.js +17 -22
  25. package/dist/commands/info.js +3 -2
  26. package/dist/commands/logs.d.ts +2 -1
  27. package/dist/commands/logs.js +12 -6
  28. package/dist/commands/restart.d.ts +5 -2
  29. package/dist/commands/restart.js +25 -5
  30. package/dist/commands/shutdown.js +3 -3
  31. package/dist/commands/status.js +8 -0
  32. package/dist/commands/test.d.ts +1 -0
  33. package/dist/commands/test.js +35 -5
  34. package/dist/config-store.d.ts +50 -34
  35. package/dist/config-store.js +80 -32
  36. package/dist/helpers/config-helper.js +2 -2
  37. package/dist/helpers/env-templates.d.ts +4 -3
  38. package/dist/helpers/env-templates.js +28 -20
  39. package/dist/helpers/key-file-helper.d.ts +2 -0
  40. package/dist/helpers/key-file-helper.js +52 -17
  41. package/dist/helpers/project-helper.d.ts +3 -2
  42. package/dist/helpers/project-helper.js +86 -35
  43. package/dist/helpers/prompt-helper.d.ts +0 -2
  44. package/dist/helpers/prompt-helper.js +15 -66
  45. package/dist/services/archiver-service.d.ts +17 -0
  46. package/dist/services/archiver-service.js +104 -0
  47. package/dist/services/cluster-service.d.ts +10 -5
  48. package/dist/services/cluster-service.js +46 -36
  49. package/dist/services/docker-service.d.ts +9 -0
  50. package/dist/services/docker-service.js +53 -0
  51. package/dist/services/fastforward-service.js +12 -6
  52. package/dist/services/get-random-node.d.ts +2 -0
  53. package/dist/services/get-random-node.js +16 -0
  54. package/dist/{helpers/github-helper.d.ts → services/github-service.d.ts} +1 -1
  55. package/dist/{helpers/github-helper.js → services/github-service.js} +1 -1
  56. package/dist/services/node-service.d.ts +4 -0
  57. package/dist/services/node-service.js +29 -14
  58. package/dist/services/shell-service.d.ts +3 -1
  59. package/dist/services/shell-service.js +32 -6
  60. package/dist/test.d.ts +1 -0
  61. package/dist/test.js +50 -0
  62. package/dist/types.d.ts +42 -3
  63. package/install-dependencies.sh +98 -0
  64. package/oclif.manifest.json +31 -4
  65. package/package.json +12 -8
  66. package/projects/hypergraph/Dockerfile +27 -18
  67. package/projects/hypergraph/docker-compose.yml +14 -12
  68. package/projects/hypergraph/networks/integrationnet/gl0.env +4 -0
  69. package/projects/hypergraph/networks/integrationnet/gl1.env +4 -0
  70. package/projects/hypergraph/networks/integrationnet/network.env +8 -0
  71. package/projects/hypergraph/networks/integrationnet/source-nodes.env +9 -0
  72. package/projects/hypergraph/networks/mainnet/gl0.env +4 -0
  73. package/projects/hypergraph/networks/mainnet/gl1.env +4 -0
  74. package/projects/hypergraph/networks/mainnet/network.env +8 -0
  75. package/projects/hypergraph/networks/mainnet/source-nodes.env +9 -0
  76. package/projects/hypergraph/networks/testnet/gl0.env +5 -0
  77. package/projects/hypergraph/networks/testnet/gl1.env +4 -0
  78. package/projects/hypergraph/networks/testnet/network.env +8 -0
  79. package/projects/hypergraph/networks/testnet/source-nodes.env +9 -0
  80. package/projects/hypergraph/scripts/check-version.sh +31 -0
  81. package/projects/hypergraph/scripts/docker-build.sh +12 -1
  82. package/projects/hypergraph/scripts/install-dependencies.sh +3 -3
  83. package/projects/hypergraph/scripts/install.sh +34 -31
  84. package/projects/hypergraph/seedlist +268 -0
  85. package/scripts/autoheal.sh +8 -0
  86. package/scripts/services/io.constellationnetwork.nodepilot.Updater.plist +16 -0
  87. package/scripts/services/node-pilot-autoheal.service +14 -0
  88. package/scripts/services/node-pilot-updater-hypergraph.service +15 -0
  89. package/scripts/updater.sh +13 -0
  90. package/dist/helpers/docker-helper.d.ts +0 -7
  91. package/dist/helpers/docker-helper.js +0 -37
  92. package/projects/hypergraph/layers/gl1.env +0 -3
  93. package/projects/hypergraph/networks/integrationnet.env +0 -9
  94. package/projects/hypergraph/networks/mainnet.env +0 -8
  95. package/projects/hypergraph/networks/testnet.env +0 -9
  96. package/projects/scripts/docker-cleanup.sh +0 -64
@@ -1,92 +1,109 @@
1
- import { TessellationLayer } from "./types.js";
1
+ import { ClusterStats, TessellationLayer } from "./types.js";
2
2
  declare class ConfigStore {
3
3
  private pilotStore;
4
4
  private projectStore;
5
5
  constructor();
6
6
  applyNewProjectStore(name: string): Promise<void>;
7
7
  changeProjectStore(name: string): void;
8
+ getAppDir(): string;
8
9
  getDockerEnvInfo(): object;
9
- getEnvCommonInfo(): EnvCommonInfo;
10
10
  getEnvInfo(): EnvInfo;
11
- getEnvLayerInfo(layer: TessellationLayer): EnvLayerInfo;
11
+ getEnvLayerInfo(network: NetworkType, layer: TessellationLayer): EnvLayerInfo;
12
+ getEnvNetworkInfo(network: NetworkType): EnvNetworkInfo;
12
13
  getLayerPortInfo(layer: TessellationLayer): PortInfo;
13
- getNetworkEnvInfo(network: NetworkType): EnvCommonInfo;
14
14
  getNetworkInfo(): NetworkInfo;
15
15
  getProjectInfo(): ProjectInfo;
16
+ getProjects(): string[];
16
17
  getSystemInfo(): SystemInfo;
18
+ hasProjectFlag(name: string): any;
17
19
  hasProjects(): boolean;
20
+ setClusterStats(info: Partial<ClusterStats>): void;
18
21
  setDockerEnvInfo(info: Partial<{
19
22
  DOCKER_IMAGE_VERSION: string;
20
23
  DOCKER_USER_ID: string;
21
24
  }>): void;
22
- setEnvCommonInfo(info: Partial<EnvCommonInfo>): void;
23
- setEnvInfo(info: DeepPartial<EnvInfo>): void;
24
- setEnvLayerInfo(layer: TessellationLayer, info: Partial<EnvLayerInfo>): void;
25
- setNetworkEnvInfo(info: NetworkEnvInfo): void;
25
+ setEnvInfo(info: Partial<EnvInfo>): void;
26
+ setEnvLayerInfo(network: NetworkType, layer: TessellationLayer, info: Partial<EnvLayerInfo>): void;
27
+ setEnvNetworkInfo(network: NetworkType, info: Partial<EnvNetworkInfo>): void;
26
28
  setNetworkInfo(info: Partial<NetworkInfo>): void;
29
+ setProjectFlag(name: string, value: boolean): any;
27
30
  setProjectInfo(info: Partial<ProjectInfo>): void;
28
- setSystemInfo(info: SystemInfo): void;
31
+ setSystemInfo(info: Partial<SystemInfo>): void;
32
+ private getPilotInfo;
33
+ private setPilotInfo;
29
34
  }
30
35
  export declare const configStore: ConfigStore;
31
- type DeepPartial<T> = {
32
- [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
36
+ export type EnvInfo = EnvKeyInfo & {
37
+ CL_ARCHIVE_NODE: boolean;
38
+ CL_EXTERNAL_IP: string;
33
39
  };
34
- export type EnvInfo = {
35
- common: EnvCommonInfo;
36
- layers: Record<TessellationLayer, EnvLayerInfo>;
40
+ export declare const envNames: {
41
+ CL_EXTERNAL_IP: number;
42
+ CL_KEYALIAS: number;
43
+ CL_KEYSTORE: number;
44
+ CL_PASSWORD: number;
37
45
  };
38
- export type EnvCommonInfo = {
46
+ export type EnvCombinedInfo = EnvInfo & EnvLayerInfo & EnvNetworkInfo;
47
+ export type EnvNetworkInfo = EnvPeerInfo & {
39
48
  CL_APP_ENV: string;
40
- CL_EXTERNAL_IP: string;
49
+ CL_COLLATERAL: string;
50
+ CL_L0_TOKEN_IDENTIFIER: string;
51
+ };
52
+ export type EnvKeyInfo = {
53
+ CL_KEYALIAS: string;
54
+ CL_KEYSTORE: string;
55
+ CL_PASSWORD: string;
56
+ };
57
+ export type EnvPeerInfo = {
41
58
  CL_GLOBAL_L0_PEER_HOST: string;
42
59
  CL_GLOBAL_L0_PEER_HTTP_PORT: string;
43
60
  CL_GLOBAL_L0_PEER_ID: string;
44
- CL_KEYALIAS: string;
45
- CL_KEYSTORE: string;
46
61
  CL_L0_PEER_HTTP_HOST: string;
47
62
  CL_L0_PEER_HTTP_PORT: string;
48
63
  CL_L0_PEER_ID: string;
49
64
  CL_L0_PEER_P2P_PORT: string;
50
- CL_L0_TOKEN_IDENTIFIER: string;
51
- CL_PASSWORD: string;
52
65
  };
53
- export declare const commonEnvNames: {
66
+ export declare const networkEnvNames: {
54
67
  CL_APP_ENV: number;
55
- CL_EXTERNAL_IP: number;
56
68
  CL_GLOBAL_L0_PEER_HOST: number;
57
69
  CL_GLOBAL_L0_PEER_HTTP_PORT: number;
58
70
  CL_GLOBAL_L0_PEER_ID: number;
59
- CL_KEYALIAS: number;
60
- CL_KEYSTORE: number;
61
71
  CL_L0_PEER_HTTP_HOST: number;
62
72
  CL_L0_PEER_HTTP_PORT: number;
63
73
  CL_L0_PEER_ID: number;
74
+ CL_L0_PEER_P2P_PORT: number;
64
75
  CL_L0_TOKEN_IDENTIFIER: number;
65
- CL_PASSWORD: number;
66
76
  };
67
- export type EnvLayerInfo = {
77
+ export type EnvLayerInfo = EnvPeerInfo & {
68
78
  CL_CLI_HTTP_PORT: string;
69
79
  CL_DOCKER_JAVA_OPTS: string;
80
+ CL_LB: string;
70
81
  CL_P2P_HTTP_PORT: string;
71
82
  CL_PUBLIC_HTTP_PORT: string;
72
83
  };
73
84
  export declare const layerEnvNames: {
74
85
  CL_CLI_HTTP_PORT: number;
75
86
  CL_DOCKER_JAVA_OPTS: number;
87
+ CL_GLOBAL_L0_PEER_HOST: number;
88
+ CL_GLOBAL_L0_PEER_HTTP_PORT: number;
89
+ CL_GLOBAL_L0_PEER_ID: number;
90
+ CL_L0_PEER_HTTP_HOST: number;
91
+ CL_L0_PEER_HTTP_PORT: number;
92
+ CL_L0_PEER_ID: number;
93
+ CL_L0_PEER_P2P_PORT: number;
94
+ CL_LB: number;
76
95
  CL_P2P_HTTP_PORT: number;
77
96
  CL_PUBLIC_HTTP_PORT: number;
78
97
  };
79
98
  export type SystemInfo = {
80
- cores?: number;
81
- disk?: string;
82
- memory?: string;
83
- platform?: string;
99
+ cores: number;
100
+ disk: string;
101
+ isDockerInstalled: boolean;
102
+ memory: string;
103
+ platform: string;
84
104
  };
85
105
  export type NetworkType = 'integrationnet' | 'mainnet' | 'testnet';
86
106
  export type ProjectInfo = {
87
- autoRestart: boolean;
88
- autoStart: boolean;
89
- autoUpdate: boolean;
90
107
  dagAddress: string;
91
108
  fastForward: boolean;
92
109
  homeDir: string;
@@ -100,7 +117,6 @@ export type NetworkInfo = {
100
117
  type: NetworkType;
101
118
  version: string;
102
119
  };
103
- export type NetworkEnvInfo = Record<NetworkType, EnvCommonInfo>;
104
120
  export type PortInfo = {
105
121
  CLI: string;
106
122
  P2P: string;
@@ -41,84 +41,113 @@ class ConfigStore {
41
41
  }
42
42
  }
43
43
  else {
44
- this.pilotStore.setItem('pilot', { appDir, project: name, projects: [...projects, name] });
44
+ this.setPilotInfo({ project: name, projects: [...projects, name] });
45
45
  }
46
46
  fs.mkdirSync(path.join(projectDir, 'config'), { recursive: true });
47
47
  this.projectStore = new JSONStorage(path.join(projectDir, 'config'));
48
48
  this.setDockerEnvInfo({ DOCKER_IMAGE_VERSION: 'test' });
49
49
  this.setProjectInfo({ name, projectDir });
50
- this.setEnvInfo({ common: { CL_GLOBAL_L0_PEER_HTTP_PORT: '9000' }, layers: { gl0: { CL_PUBLIC_HTTP_PORT: "9000" } } });
51
50
  }
52
51
  changeProjectStore(name) {
53
- const { appDir, projects } = this.pilotStore.getItem('pilot');
52
+ const { appDir, project, projects } = this.pilotStore.getItem('pilot');
54
53
  if (projects && projects.includes(name)) {
54
+ if (project === name)
55
+ return;
55
56
  this.projectStore = new JSONStorage(path.join(appDir, name, 'config'));
57
+ this.setPilotInfo({ project: name });
56
58
  }
57
59
  else {
58
60
  throw new Error(`Project ${name} doesn't exist.`);
59
61
  }
60
62
  }
63
+ getAppDir() {
64
+ const { appDir } = this.pilotStore.getItem('pilot');
65
+ return appDir;
66
+ }
61
67
  getDockerEnvInfo() {
62
68
  return this.projectStore.getItem('docker');
63
69
  }
64
- getEnvCommonInfo() {
65
- return this.projectStore.getItem('env')?.common;
66
- }
67
70
  getEnvInfo() {
68
- return this.projectStore.getItem('env');
71
+ return this.projectStore.getItem('env') || {};
72
+ }
73
+ getEnvLayerInfo(network, layer) {
74
+ const envInfo = this.projectStore.getItem('layer-env');
75
+ if (!envInfo)
76
+ return { [network]: {} };
77
+ return envInfo[network][layer] || {};
69
78
  }
70
- getEnvLayerInfo(layer) {
71
- const envInfo = this.projectStore.getItem('env');
79
+ getEnvNetworkInfo(network) {
80
+ const envInfo = this.projectStore.getItem('network-env');
72
81
  if (!envInfo)
73
82
  return {};
74
- return { ...envInfo.common, ...envInfo.layers[layer] };
83
+ return envInfo[network];
75
84
  }
76
85
  getLayerPortInfo(layer) {
77
- const layerInfo = this.getEnvLayerInfo(layer);
86
+ const { type: network } = this.getNetworkInfo();
87
+ const layerInfo = this.getEnvLayerInfo(network, layer);
78
88
  return { CLI: layerInfo.CL_CLI_HTTP_PORT, P2P: layerInfo.CL_P2P_HTTP_PORT, PUBLIC: layerInfo.CL_PUBLIC_HTTP_PORT };
79
89
  }
80
- getNetworkEnvInfo(network) {
81
- const info = this.projectStore.getItem('network-env');
82
- return info ? info[network] : {};
83
- }
84
90
  getNetworkInfo() {
85
91
  return this.projectStore.getItem('network');
86
92
  }
87
93
  getProjectInfo() {
88
94
  return this.projectStore.getItem('project');
89
95
  }
96
+ getProjects() {
97
+ const { projects } = this.pilotStore.getItem('pilot');
98
+ return projects;
99
+ }
90
100
  getSystemInfo() {
91
101
  return this.pilotStore.getItem('system');
92
102
  }
103
+ hasProjectFlag(name) {
104
+ const flags = this.projectStore.getItem('flags') || {};
105
+ return flags[name] || false;
106
+ }
93
107
  hasProjects() {
94
108
  const { projects } = this.pilotStore.getItem('pilot');
95
109
  return projects.length > 0;
96
110
  }
111
+ // setCurrentEnvNetworkInfo(info: Partial<EnvNetworkInfo>) {
112
+ // const {type} = this.getNetworkInfo();
113
+ // this.setEnvNetworkInfo(type, info);
114
+ // }
115
+ setClusterStats(info) {
116
+ const oldInfo = this.projectStore.getItem('cluster-stats');
117
+ this.projectStore.setItem('cluster-stats', { ...oldInfo, ...info });
118
+ }
97
119
  setDockerEnvInfo(info) {
98
120
  const oldInfo = this.projectStore.getItem('docker');
99
121
  this.projectStore.setItem('docker', { ...oldInfo, ...info });
100
122
  }
101
- setEnvCommonInfo(info) {
102
- const oldInfo = this.projectStore.getItem('env');
103
- this.projectStore.setItem('env', { common: { ...oldInfo.common, ...info }, layers: oldInfo.layers });
104
- }
105
123
  setEnvInfo(info) {
106
124
  const oldInfo = this.projectStore.getItem('env');
107
125
  this.projectStore.setItem('env', { ...oldInfo, ...info });
108
126
  }
109
- setEnvLayerInfo(layer, info) {
110
- const envInfo = this.projectStore.getItem('env');
111
- const { common, layers } = envInfo;
112
- this.projectStore.setItem('env', { common, layers: { ...layers, [layer]: { ...layers[layer], ...info } } });
127
+ setEnvLayerInfo(network, layer, info) {
128
+ let layers = this.projectStore.getItem('layer-env');
129
+ if (!layers)
130
+ layers = {};
131
+ if (!layers[network])
132
+ layers[network] = {};
133
+ this.projectStore.setItem('layer-env', { ...layers, [network]: { ...layers[network], [layer]: { ...layers[network][layer], ...info } } });
113
134
  }
114
- setNetworkEnvInfo(info) {
115
- const oldInfo = this.projectStore.getItem('network-env');
116
- this.projectStore.setItem('network-env', { ...oldInfo, ...info });
135
+ setEnvNetworkInfo(network, info) {
136
+ let networks = this.projectStore.getItem('network-env');
137
+ if (!networks)
138
+ networks = {};
139
+ this.projectStore.setItem('network-env', { ...networks, [network]: { ...networks[network], ...info } });
117
140
  }
118
141
  setNetworkInfo(info) {
119
142
  const oldInfo = this.projectStore.getItem('network');
120
143
  this.projectStore.setItem('network', { ...oldInfo, ...info });
121
144
  }
145
+ setProjectFlag(name, value) {
146
+ const flags = this.projectStore.getItem('flags') || {};
147
+ flags[name] = value;
148
+ this.projectStore.setItem('flags', flags);
149
+ return flags;
150
+ }
122
151
  setProjectInfo(info) {
123
152
  const oldInfo = this.projectStore.getItem('project');
124
153
  this.projectStore.setItem('project', { ...oldInfo, ...info });
@@ -127,25 +156,44 @@ class ConfigStore {
127
156
  const oldInfo = this.projectStore.getItem('system');
128
157
  this.pilotStore.setItem('system', { ...oldInfo, ...info });
129
158
  }
159
+ getPilotInfo() {
160
+ return this.pilotStore.getItem('pilot');
161
+ }
162
+ setPilotInfo(info) {
163
+ const oldInfo = this.pilotStore.getItem('pilot');
164
+ this.pilotStore.setItem('pilot', { ...oldInfo, ...info });
165
+ }
130
166
  }
131
167
  export const configStore = new ConfigStore();
132
- export const commonEnvNames = {
133
- CL_APP_ENV: 1,
168
+ export const envNames = {
134
169
  CL_EXTERNAL_IP: 1,
170
+ CL_KEYALIAS: 1,
171
+ CL_KEYSTORE: 1,
172
+ CL_PASSWORD: 1
173
+ };
174
+ export const networkEnvNames = {
175
+ CL_APP_ENV: 1,
135
176
  CL_GLOBAL_L0_PEER_HOST: 1,
136
177
  CL_GLOBAL_L0_PEER_HTTP_PORT: 1,
137
178
  CL_GLOBAL_L0_PEER_ID: 1,
138
- CL_KEYALIAS: 1,
139
- CL_KEYSTORE: 1,
140
179
  CL_L0_PEER_HTTP_HOST: 1,
141
180
  CL_L0_PEER_HTTP_PORT: 1,
142
181
  CL_L0_PEER_ID: 1,
182
+ CL_L0_PEER_P2P_PORT: 1,
143
183
  CL_L0_TOKEN_IDENTIFIER: 1,
144
- CL_PASSWORD: 1
145
184
  };
185
+ // NETWORK LAYER
146
186
  export const layerEnvNames = {
147
187
  CL_CLI_HTTP_PORT: 1,
148
188
  CL_DOCKER_JAVA_OPTS: 1,
189
+ CL_GLOBAL_L0_PEER_HOST: 1,
190
+ CL_GLOBAL_L0_PEER_HTTP_PORT: 1,
191
+ CL_GLOBAL_L0_PEER_ID: 1,
192
+ CL_L0_PEER_HTTP_HOST: 1,
193
+ CL_L0_PEER_HTTP_PORT: 1,
194
+ CL_L0_PEER_ID: 1,
195
+ CL_L0_PEER_P2P_PORT: 1,
196
+ CL_LB: 1,
149
197
  CL_P2P_HTTP_PORT: 1,
150
- CL_PUBLIC_HTTP_PORT: 1,
198
+ CL_PUBLIC_HTTP_PORT: 1
151
199
  };
@@ -18,8 +18,8 @@ export const configHelper = {
18
18
  }
19
19
  const versionObj = this.parseEnvFile(lastInstallVersion);
20
20
  return {
21
- network: versionObj.RELEASE_NETWORK_TYPE,
22
- version: versionObj.RELEASE_NETWORK_VERSION
21
+ network: versionObj.INSTALLED_NETWORK_TYPE,
22
+ version: versionObj.INSTALLED_NETWORK_VERSION
23
23
  };
24
24
  },
25
25
  parseEnvFile(filePath) {
@@ -1,4 +1,5 @@
1
- import { EnvCommonInfo, EnvLayerInfo, NetworkType } from "../config-store.js";
1
+ import { EnvCombinedInfo, EnvInfo } from "../config-store.js";
2
2
  import { TessellationLayer } from "../types.js";
3
- export declare function getLayerEnvFileContent(layer: TessellationLayer, network: NetworkType, commonInfo: EnvCommonInfo, layerInfo: EnvLayerInfo): string;
4
- export declare function getKeyFileContent(commonInfo: EnvCommonInfo): string;
3
+ export declare function getLayerEnvFileContent(layer: TessellationLayer, env: EnvCombinedInfo): string;
4
+ export declare function getKeyFileContent(env: EnvInfo): string;
5
+ export declare function getObjectToEnvContent(obj: object): string;
@@ -1,33 +1,41 @@
1
- export function getLayerEnvFileContent(layer, network, commonInfo, layerInfo) {
1
+ export function getLayerEnvFileContent(layer, env) {
2
2
  return `
3
+ DEBUG=${process.env.DEBUG || ''}
4
+ NODE_PILOT_SESSION=${Date.now()}
5
+
3
6
  # Node
4
- CL_EXTERNAL_IP=${commonInfo.CL_EXTERNAL_IP}
5
- CL_DOCKER_JAVA_OPTS='${layerInfo.CL_DOCKER_JAVA_OPTS}'
7
+ CL_ARCHIVE_NODE=${env.CL_ARCHIVE_NODE || ''}
8
+ CL_EXTERNAL_IP=${env.CL_EXTERNAL_IP}
9
+ CL_DOCKER_JAVA_OPTS='${env.CL_DOCKER_JAVA_OPTS}'
6
10
  CL_KEYSTORE='/app/key.p12'
7
- CL_KEYALIAS='${commonInfo.CL_KEYALIAS}'
8
- CL_PASSWORD='${commonInfo.CL_PASSWORD}'
11
+ CL_KEYALIAS='${env.CL_KEYALIAS}'
12
+ CL_PASSWORD='${env.CL_PASSWORD}'
9
13
  CL_TESSELATION_LAYER=${layer}
10
14
 
11
15
  # NETWORK
12
- CL_APP_ENV=${commonInfo.CL_APP_ENV}
13
- CL_COLLATERAL=${network === 'mainnet' ? 25000000000000 : 0}
14
- CL_L0_PEER_HTTP_PORT=${commonInfo.CL_L0_PEER_HTTP_PORT}
15
- CL_L0_PEER_HTTP_HOST=${commonInfo.CL_L0_PEER_HTTP_HOST}
16
- CL_L0_PEER_ID=${commonInfo.CL_L0_PEER_ID}
17
- CL_GLOBAL_L0_PEER_HTTP_PORT=${commonInfo.CL_GLOBAL_L0_PEER_HTTP_PORT}
18
- CL_GLOBAL_L0_PEER_HOST=${commonInfo.CL_GLOBAL_L0_PEER_HOST}
19
- CL_GLOBAL_L0_PEER_ID=${commonInfo.CL_GLOBAL_L0_PEER_ID}
16
+ CL_LB=${env.CL_LB}
17
+ CL_APP_ENV=${env.CL_APP_ENV}
18
+ CL_COLLATERAL=${env.CL_COLLATERAL}
19
+ CL_L0_PEER_HTTP_PORT=${env.CL_L0_PEER_HTTP_PORT}
20
+ CL_L0_PEER_HTTP_HOST=${env.CL_L0_PEER_HTTP_HOST}
21
+ CL_L0_PEER_ID=${env.CL_L0_PEER_ID}
22
+ CL_GLOBAL_L0_PEER_HTTP_PORT=${env.CL_GLOBAL_L0_PEER_HTTP_PORT}
23
+ CL_GLOBAL_L0_PEER_HOST=${env.CL_GLOBAL_L0_PEER_HOST}
24
+ CL_GLOBAL_L0_PEER_ID=${env.CL_GLOBAL_L0_PEER_ID}
20
25
 
21
26
  # LAYER
22
- CL_PUBLIC_HTTP_PORT=${layerInfo.CL_PUBLIC_HTTP_PORT}
23
- CL_P2P_HTTP_PORT=${layerInfo.CL_P2P_HTTP_PORT}
24
- CL_CLI_HTTP_PORT=${layerInfo.CL_CLI_HTTP_PORT}
27
+ CL_PUBLIC_HTTP_PORT=${env.CL_PUBLIC_HTTP_PORT}
28
+ CL_P2P_HTTP_PORT=${env.CL_P2P_HTTP_PORT}
29
+ CL_CLI_HTTP_PORT=${env.CL_CLI_HTTP_PORT}
25
30
  `;
26
31
  }
27
- export function getKeyFileContent(commonInfo) {
32
+ export function getKeyFileContent(env) {
28
33
  return `
29
- export CL_KEYSTORE='${commonInfo.CL_KEYSTORE}'
30
- export CL_KEYALIAS='${commonInfo.CL_KEYALIAS}'
31
- export CL_PASSWORD='${commonInfo.CL_PASSWORD}'
34
+ export CL_KEYSTORE='${env.CL_KEYSTORE}'
35
+ export CL_KEYALIAS='${env.CL_KEYALIAS}'
36
+ export CL_PASSWORD='${env.CL_PASSWORD}'
32
37
  `;
33
38
  }
39
+ export function getObjectToEnvContent(obj) {
40
+ return Object.entries(obj).map(([k, v]) => `${k}='${v}'`).join('\n') + '\n';
41
+ }
@@ -1,9 +1,11 @@
1
1
  export declare const keyFileHelper: {
2
+ changePassword(newPassword: string): Promise<void>;
2
3
  generate(): Promise<void>;
3
4
  getAddress(): Promise<string>;
4
5
  getId(): Promise<string>;
5
6
  importKeyFile(): Promise<void>;
6
7
  promptForKeyFile(): Promise<void>;
7
8
  promptIfNoKeyFile(): Promise<void>;
9
+ promptSaveBackup(env: object): Promise<void>;
8
10
  showKeyFileInfo(prompt4ShowPassword?: boolean): Promise<void>;
9
11
  };
@@ -7,12 +7,27 @@ import { clm } from "../clm.js";
7
7
  import { configStore } from "../config-store.js";
8
8
  import { shellService } from "../services/shell-service.js";
9
9
  import { configHelper } from "./config-helper.js";
10
- import { getKeyFileContent } from "./env-templates.js";
10
+ import { getObjectToEnvContent } from "./env-templates.js";
11
11
  export const keyFileHelper = {
12
+ async changePassword(newPassword) {
13
+ const { projectDir } = configStore.getProjectInfo();
14
+ const keyFilePath = path.join(projectDir, "key.p12");
15
+ if (!fs.existsSync(keyFilePath)) {
16
+ clm.error('No key file found. Please generate a new key file first.');
17
+ }
18
+ const { CL_PASSWORD: currentPassword } = configStore.getEnvInfo();
19
+ if (currentPassword === newPassword) {
20
+ clm.error('The new password is the same as the current password. Please try again with a different password.');
21
+ }
22
+ await shellService.runCommand(`keytool -importkeystore -srckeystore ${keyFilePath} -srcstoretype PKCS12 -srcstorepass '${currentPassword}' -destkeystore ${path.join(projectDir, "temp.p12")} -deststoretype PKCS12 -deststorepass '${newPassword}' -destkeypass '${newPassword}'`);
23
+ await this.promptSaveBackup({ CL_KEYALIAS: 'alias', CL_KEYSTORE: keyFilePath, CL_PASSWORD: newPassword });
24
+ },
12
25
  async generate() {
13
26
  const { projectDir } = configStore.getProjectInfo();
14
27
  const keyFilePath = path.join(projectDir, "key.p12");
28
+ let modifier = '';
15
29
  if (fs.existsSync(keyFilePath)) {
30
+ modifier = 'new ';
16
31
  const answer = await input({ default: 'n', message: 'A key file already exists. Do you want to overwrite it? (y/n): ' });
17
32
  if (answer.toLowerCase() === 'y') {
18
33
  fs.rmSync(keyFilePath, { force: true });
@@ -22,31 +37,26 @@ export const keyFileHelper = {
22
37
  process.exit(0);
23
38
  }
24
39
  }
25
- const keyPassword = await password({ message: 'Enter the key file password:', validate: value => value.length > 0 });
40
+ const keyPassword = await password({ message: `Enter the ${modifier}key file password:`, validate: value => value.length > 0 });
26
41
  const env = {
27
42
  CL_KEYALIAS: "alias", CL_KEYSTORE: keyFilePath, CL_PASSWORD: keyPassword
28
43
  };
29
44
  await shellService.runCommand(`java -jar ${projectDir}/dist/keytool.jar generate`, env);
30
- configStore.setEnvCommonInfo(env);
45
+ configStore.setEnvInfo(env);
31
46
  const dagAddress = await this.getAddress();
32
47
  const nodeId = await this.getId();
33
48
  configStore.setProjectInfo({ dagAddress, nodeId });
34
49
  clm.postStep('Key file generated successfully.\n');
35
- const answer = await input({ default: 'y', message: 'Would you like to save a backup of the key file to your home directory? (y/n): ' });
36
- if (answer.toLowerCase() === 'y') {
37
- fs.cpSync(keyFilePath, path.join(os.homedir(), 'key.p12'));
38
- fs.writeFileSync(path.join(os.homedir(), 'key-env.sh'), getKeyFileContent({ ...env, CL_KEYSTORE: 'key.p12' }));
39
- clm.postStep(`A copy of the Key file has been saved to your home directory - ${chalk.cyan(path.join(os.homedir(), 'key.p12'))}`);
40
- }
50
+ await this.promptSaveBackup(env);
41
51
  },
42
52
  async getAddress() {
43
53
  const { projectDir } = configStore.getProjectInfo();
44
- const env = configStore.getEnvCommonInfo();
54
+ const env = configStore.getEnvInfo();
45
55
  return shellService.runCommandWithOutput(`java -jar ${projectDir}/dist/wallet.jar show-address`, env);
46
56
  },
47
57
  async getId() {
48
58
  const { projectDir } = configStore.getProjectInfo();
49
- const env = configStore.getEnvCommonInfo();
59
+ const env = configStore.getEnvInfo();
50
60
  return shellService.runCommandWithOutput(`java -jar ${projectDir}/dist/wallet.jar show-id`, env);
51
61
  },
52
62
  async importKeyFile() {
@@ -72,17 +82,17 @@ export const keyFileHelper = {
72
82
  // prompt for password
73
83
  const keyPassword = await password({ message: 'Enter the key file password:' });
74
84
  const keyAlias = await input({ message: 'Enter the key file alias:' });
75
- configStore.setEnvCommonInfo({ CL_KEYALIAS: keyAlias, CL_KEYSTORE: keyStorePath, CL_PASSWORD: keyPassword });
85
+ configStore.setEnvInfo({ CL_KEYALIAS: keyAlias, CL_KEYSTORE: keyStorePath, CL_PASSWORD: keyPassword });
76
86
  try {
77
87
  const dagAddress = await this.getAddress();
78
88
  const nodeId = await this.getId();
79
89
  configStore.setProjectInfo({ dagAddress, nodeId });
80
90
  }
81
91
  catch {
82
- clm.warn('Failed to unlock the key file. Please check your key file information and try again.');
83
92
  fs.rmSync(keyStorePath);
84
- await this.promptForKeyFile();
85
- return;
93
+ clm.error('Failed to unlock the key file. Please check your key file information and try again.');
94
+ // await this.promptForKeyFile();
95
+ // return;
86
96
  }
87
97
  clm.postStep('Key file imported successfully.\n');
88
98
  },
@@ -108,6 +118,8 @@ export const keyFileHelper = {
108
118
  await this.importKeyFile();
109
119
  await this.showKeyFileInfo(false);
110
120
  }
121
+ configStore.setProjectFlag('duplicateNodeIdChecked', false);
122
+ configStore.setProjectFlag('seedListChecked', false);
111
123
  },
112
124
  async promptIfNoKeyFile() {
113
125
  const { projectDir } = configStore.getProjectInfo();
@@ -117,12 +129,35 @@ export const keyFileHelper = {
117
129
  }
118
130
  await this.promptForKeyFile();
119
131
  },
132
+ async promptSaveBackup(env) {
133
+ const { projectDir } = configStore.getProjectInfo();
134
+ const keyFilePath = path.join(projectDir, "key.p12");
135
+ const { dagAddress, nodeId } = configStore.getProjectInfo();
136
+ const answer = await input({ default: 'y', message: 'Would you like to save a backup of the key file to your home directory? (y/n): ' });
137
+ if (answer.toLowerCase() === 'y') {
138
+ const homeKeyPath = path.join(os.homedir(), 'key.p12');
139
+ const homeKeyInfoPath = path.join(os.homedir(), 'key-info');
140
+ if (fs.existsSync(homeKeyPath)) {
141
+ const backupUniqueName = new Date().toISOString().replaceAll(':', '-');
142
+ const backupKeyName = `key-${backupUniqueName}.p12`;
143
+ const backupKeyPath = path.join(os.homedir(), backupKeyName);
144
+ fs.renameSync(homeKeyPath, backupKeyPath);
145
+ clm.postStep(`An existing key file was found in your home directory and has been renamed to ${chalk.cyan(backupKeyName)}`);
146
+ if (fs.existsSync(homeKeyInfoPath)) {
147
+ fs.renameSync(homeKeyInfoPath, path.join(os.homedir(), `key-info-${backupUniqueName}`));
148
+ }
149
+ }
150
+ fs.cpSync(keyFilePath, homeKeyPath);
151
+ fs.writeFileSync(path.join(os.homedir(), 'key-info'), getObjectToEnvContent({ ...env, CL_KEYSTORE: 'key.p12', CL_PASSWORD: '****', NODE_ADDRESS: dagAddress, NODE_ID: nodeId }));
152
+ clm.postStep(`A copy of the Key file has been saved to your home directory - ${chalk.cyan(homeKeyPath)}`);
153
+ }
154
+ },
120
155
  async showKeyFileInfo(prompt4ShowPassword = true) {
121
- clm.preStep('Key File Information:');
156
+ clm.preStep('Current key file information:');
122
157
  const { dagAddress, nodeId } = configStore.getProjectInfo();
123
158
  configHelper.showEnvInfo('Node ID', nodeId);
124
159
  configHelper.showEnvInfo('DAG Address', dagAddress);
125
- const { CL_KEYALIAS, CL_KEYSTORE, CL_PASSWORD } = configStore.getEnvCommonInfo();
160
+ const { CL_KEYALIAS, CL_KEYSTORE, CL_PASSWORD } = configStore.getEnvInfo();
126
161
  configHelper.showEnvInfo('CL_KEYSTORE', CL_KEYSTORE || '');
127
162
  configHelper.showEnvInfo('CL_KEYALIAS', CL_KEYALIAS || '');
128
163
  configHelper.showEnvInfo('CL_PASSWORD', '*********');
@@ -1,9 +1,10 @@
1
1
  import { TessellationLayer } from "../types.js";
2
2
  export declare const projectHelper: {
3
3
  generateLayerEnvFiles(layers?: TessellationLayer[]): Promise<void>;
4
- importLayerEnvFiles(): Promise<void>;
5
- importNetworkEnvFiles(): Promise<void>;
4
+ importEnvFiles(): void;
6
5
  installEmbedded(name: string): Promise<void>;
7
6
  installFromGithub(_repo: string): Promise<never>;
8
7
  installHypergraph(): Promise<void>;
8
+ installProject(name: string, projectFolder: string): Promise<void>;
9
+ selectProject(): Promise<void>;
9
10
  };