@0xobelisk/sui-cli 1.1.4 → 1.1.6

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.
@@ -3,44 +3,44 @@ import { ZodError } from 'zod';
3
3
  import { fromZodError, ValidationError } from 'zod-validation-error';
4
4
 
5
5
  export class NotInsideProjectError extends Error {
6
- name = 'NotInsideProjectError';
7
- message = 'You are not inside a Dubhe project';
6
+ name = 'NotInsideProjectError';
7
+ message = 'You are not inside a Dubhe project';
8
8
  }
9
9
 
10
10
  export class DubheCliError extends Error {
11
- name = 'DubheCliError';
11
+ name = 'DubheCliError';
12
12
  }
13
13
 
14
14
  export class UpgradeError extends Error {
15
- name = 'UpgradeError';
15
+ name = 'UpgradeError';
16
16
  }
17
17
 
18
18
  export class FsIibError extends Error {
19
- name = 'FsIibError';
19
+ name = 'FsIibError';
20
20
  }
21
21
 
22
22
  export function logError(error: unknown) {
23
- if (error instanceof ValidationError) {
24
- console.log(chalk.redBright(error.message));
25
- } else if (error instanceof ZodError) {
26
- // TODO currently this error shouldn't happen, use `fromZodErrorCustom`
27
- const validationError = fromZodError(error, {
28
- prefixSeparator: '\n- ',
29
- issueSeparator: '\n- ',
30
- });
31
- console.log(chalk.redBright(validationError.message));
32
- } else if (error instanceof NotInsideProjectError) {
33
- console.log(chalk.red(error.message));
34
- console.log('');
35
- // TODO add docs to the website and update the link to the specific page
36
- console.log(
37
- chalk.blue(
38
- `To learn more about Dubhe's configuration, please go to https://github.com/0xobelisk`
39
- )
40
- );
41
- } else if (error instanceof DubheCliError) {
42
- console.log(chalk.red(error));
43
- } else {
44
- console.log(error);
45
- }
23
+ if (error instanceof ValidationError) {
24
+ console.log(chalk.redBright(error.message));
25
+ } else if (error instanceof ZodError) {
26
+ // TODO currently this error shouldn't happen, use `fromZodErrorCustom`
27
+ const validationError = fromZodError(error, {
28
+ prefixSeparator: '\n- ',
29
+ issueSeparator: '\n- '
30
+ });
31
+ console.log(chalk.redBright(validationError.message));
32
+ } else if (error instanceof NotInsideProjectError) {
33
+ console.log(chalk.red(error.message));
34
+ console.log('');
35
+ // TODO add docs to the website and update the link to the specific page
36
+ console.log(
37
+ chalk.blue(
38
+ `To learn more about Dubhe's configuration, please go to https://github.com/0xobelisk`
39
+ )
40
+ );
41
+ } else if (error instanceof DubheCliError) {
42
+ console.log(chalk.red(error));
43
+ } else {
44
+ console.log(error);
45
+ }
46
46
  }
@@ -2,111 +2,96 @@ import { Dubhe } from '@0xobelisk/sui-client';
2
2
  import * as fs from 'fs';
3
3
  import chalk from 'chalk';
4
4
 
5
- export async function generateAccountHandler(
6
- force: boolean = false,
7
- outputTsPath?: string
8
- ) {
9
- if (outputTsPath) {
10
- console.log(
11
- chalk.blue(
12
- 'Note: The generated account will be stored in the .env file and the TypeScript file specified by the --output-ts-path option.'
13
- )
14
- );
15
- console.log(
16
- chalk.yellow(
17
- 'Warning: Do not expose the key file. It is intended for local testing only.\n'
18
- )
19
- );
20
- }
21
- const path = process.cwd();
22
- let privateKey: string;
5
+ export async function generateAccountHandler(force: boolean = false, outputTsPath?: string) {
6
+ if (outputTsPath) {
7
+ console.log(
8
+ chalk.blue(
9
+ 'Note: The generated account will be stored in the .env file and the TypeScript file specified by the --output-ts-path option.'
10
+ )
11
+ );
12
+ console.log(
13
+ chalk.yellow('Warning: Do not expose the key file. It is intended for local testing only.\n')
14
+ );
15
+ }
16
+ const path = process.cwd();
17
+ let privateKey: string;
23
18
 
24
- if (force) {
25
- const dubhe = new Dubhe();
26
- const keypair = dubhe.getSigner();
27
- privateKey = keypair.getSecretKey();
19
+ if (force) {
20
+ const dubhe = new Dubhe();
21
+ const keypair = dubhe.getSigner();
22
+ privateKey = keypair.getSecretKey();
28
23
 
29
- fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
30
- console.log(chalk.green(`File created at: ${path}/.env`));
24
+ fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
25
+ console.log(chalk.green(`File created at: ${path}/.env`));
31
26
 
32
- if (outputTsPath) {
33
- const dir = outputTsPath.substring(
34
- 0,
35
- outputTsPath.lastIndexOf('/')
36
- );
37
- if (!fs.existsSync(dir)) {
38
- fs.mkdirSync(dir, { recursive: true });
39
- }
40
- fs.writeFileSync(
41
- outputTsPath,
42
- `export const PRIVATEKEY = '${privateKey}';
27
+ if (outputTsPath) {
28
+ const dir = outputTsPath.substring(0, outputTsPath.lastIndexOf('/'));
29
+ if (!fs.existsSync(dir)) {
30
+ fs.mkdirSync(dir, { recursive: true });
31
+ }
32
+ fs.writeFileSync(
33
+ outputTsPath,
34
+ `export const PRIVATEKEY = '${privateKey}';
43
35
  export const ACCOUNT = '${keypair.toSuiAddress()}';
44
36
  `
45
- );
46
- console.log(chalk.green(`File created at: ${outputTsPath}\n`));
47
- }
37
+ );
38
+ console.log(chalk.green(`File created at: ${outputTsPath}\n`));
39
+ }
48
40
 
49
- console.log(
50
- chalk.blue(`Force generate new Account: ${keypair.toSuiAddress()}`)
51
- );
52
- return;
53
- }
41
+ console.log(chalk.blue(`Force generate new Account: ${keypair.toSuiAddress()}`));
42
+ return;
43
+ }
54
44
 
55
- // Check if .env file exists and has content
56
- try {
57
- const envContent = fs.readFileSync(`${path}/.env`, 'utf8');
58
- const match = envContent.match(/PRIVATE_KEY=(.+)/);
59
- if (match && match[1]) {
60
- privateKey = match[1];
61
- const dubhe = new Dubhe({ secretKey: privateKey });
62
- const keypair = dubhe.getSigner();
45
+ // Check if .env file exists and has content
46
+ try {
47
+ const envContent = fs.readFileSync(`${path}/.env`, 'utf8');
48
+ const match = envContent.match(/PRIVATE_KEY=(.+)/);
49
+ if (match && match[1]) {
50
+ privateKey = match[1];
51
+ const dubhe = new Dubhe({ secretKey: privateKey });
52
+ const keypair = dubhe.getSigner();
63
53
 
64
- if (outputTsPath) {
65
- const dir = outputTsPath.substring(
66
- 0,
67
- outputTsPath.lastIndexOf('/')
68
- );
69
- if (!fs.existsSync(dir)) {
70
- fs.mkdirSync(dir, { recursive: true });
71
- }
72
- fs.writeFileSync(
73
- outputTsPath,
74
- `export const PRIVATEKEY = '${privateKey}';
54
+ if (outputTsPath) {
55
+ const dir = outputTsPath.substring(0, outputTsPath.lastIndexOf('/'));
56
+ if (!fs.existsSync(dir)) {
57
+ fs.mkdirSync(dir, { recursive: true });
58
+ }
59
+ fs.writeFileSync(
60
+ outputTsPath,
61
+ `export const PRIVATEKEY = '${privateKey}';
75
62
  export const ACCOUNT = '${keypair.toSuiAddress()}';
76
63
  `
77
- );
78
- console.log(chalk.green(`File created at: ${outputTsPath}\n`));
79
- }
64
+ );
65
+ console.log(chalk.green(`File created at: ${outputTsPath}\n`));
66
+ }
80
67
 
81
- console.log(
82
- chalk.blue(`Using existing Account: ${keypair.toSuiAddress()}`)
83
- );
84
- return;
85
- }
86
- } catch (error) {
87
- // .env file doesn't exist or failed to read, continue to generate new account
88
- }
68
+ console.log(chalk.blue(`Using existing Account: ${keypair.toSuiAddress()}`));
69
+ return;
70
+ }
71
+ } catch (error) {
72
+ // .env file doesn't exist or failed to read, continue to generate new account
73
+ }
89
74
 
90
- // If no existing private key, generate new account
91
- const dubhe = new Dubhe();
92
- const keypair = dubhe.getSigner();
93
- privateKey = keypair.getSecretKey();
94
- fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
95
- console.log(chalk.green(`File created at: ${path}/.env`));
75
+ // If no existing private key, generate new account
76
+ const dubhe = new Dubhe();
77
+ const keypair = dubhe.getSigner();
78
+ privateKey = keypair.getSecretKey();
79
+ fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
80
+ console.log(chalk.green(`File created at: ${path}/.env`));
96
81
 
97
- if (outputTsPath) {
98
- const dir = outputTsPath.substring(0, outputTsPath.lastIndexOf('/'));
99
- if (!fs.existsSync(dir)) {
100
- fs.mkdirSync(dir, { recursive: true });
101
- }
102
- fs.writeFileSync(
103
- outputTsPath,
104
- `export const PRIVATEKEY = '${privateKey}';
82
+ if (outputTsPath) {
83
+ const dir = outputTsPath.substring(0, outputTsPath.lastIndexOf('/'));
84
+ if (!fs.existsSync(dir)) {
85
+ fs.mkdirSync(dir, { recursive: true });
86
+ }
87
+ fs.writeFileSync(
88
+ outputTsPath,
89
+ `export const PRIVATEKEY = '${privateKey}';
105
90
  export const ACCOUNT = '${keypair.toSuiAddress()}';
106
91
  `
107
- );
108
- console.log(chalk.green(`File created at: ${outputTsPath}\n`));
109
- }
92
+ );
93
+ console.log(chalk.green(`File created at: ${outputTsPath}\n`));
94
+ }
110
95
 
111
- console.log(chalk.blue(`Generate new Account: ${keypair.toSuiAddress()}`));
96
+ console.log(chalk.blue(`Generate new Account: ${keypair.toSuiAddress()}`));
112
97
  }