@0xobelisk/sui-cli 0.5.7 → 0.5.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.
@@ -1,153 +1,163 @@
1
- import * as fsAsync from "fs/promises";
2
- import { mkdirSync, writeFileSync } from "fs";
3
- import { dirname } from "path";
4
- import { FsIibError } from "./errors";
1
+ import * as fsAsync from 'fs/promises';
2
+ import { mkdirSync, writeFileSync } from 'fs';
3
+ import { dirname } from 'path';
4
+ import {
5
+ SUI_PRIVATE_KEY_PREFIX,
6
+ decodeSuiPrivateKey,
7
+ } from '@mysten/sui.js/cryptography';
8
+ import { FsIibError } from './errors';
5
9
 
6
10
  export type DeploymentJsonType = {
7
- projectName: string;
8
- network: "mainnet" | "testnet" | "devnet" | "localnet";
9
- packageId: string;
10
- worldId: string;
11
- upgradeCap: string;
12
- adminCap: string;
13
- version: number;
11
+ projectName: string;
12
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
13
+ packageId: string;
14
+ worldId: string;
15
+ upgradeCap: string;
16
+ adminCap: string;
17
+ version: number;
14
18
  };
15
19
 
16
- export function validatePrivateKey(privateKey: string): boolean | string {
17
- if (privateKey.startsWith("0x")) {
18
- const strippedPrivateKey = privateKey.slice(2);
19
- if (strippedPrivateKey.length === 64) {
20
- return strippedPrivateKey;
21
- } else {
22
- return false;
23
- }
24
- } else {
25
- if (privateKey.length === 64) {
26
- return privateKey;
27
- } else {
28
- return false;
29
- }
30
- }
20
+ export function validatePrivateKey(privateKey: string): false | string {
21
+ if (privateKey.startsWith(SUI_PRIVATE_KEY_PREFIX)) {
22
+ if (privateKey.length === 70) {
23
+ return privateKey;
24
+ } else {
25
+ return false;
26
+ }
27
+ } else if (privateKey.startsWith('0x')) {
28
+ const strippedPrivateKey = privateKey.slice(2);
29
+ if (strippedPrivateKey.length === 64) {
30
+ return strippedPrivateKey;
31
+ } else {
32
+ return false;
33
+ }
34
+ } else {
35
+ if (privateKey.length === 64) {
36
+ return privateKey;
37
+ } else {
38
+ return false;
39
+ }
40
+ }
31
41
  }
32
42
 
33
43
  export async function updateVersionInFile(
34
- projectPath: string,
35
- newVersion: string
44
+ projectPath: string,
45
+ newVersion: string
36
46
  ) {
37
- try {
38
- const filePath = `${projectPath}/sources/codegen/eps/world.move`;
39
- const data = await fsAsync.readFile(filePath, "utf8");
40
-
41
- // update version data
42
- const updatedData = data.replace(
43
- /const VERSION: u64 = \d+;/,
44
- `const VERSION: u64 = ${newVersion};`
45
- );
46
-
47
- // write new version
48
- writeOutput(updatedData, filePath, "Update package version");
49
- } catch {
50
- throw new FsIibError("Fs update version failed.");
51
- }
47
+ try {
48
+ const filePath = `${projectPath}/sources/codegen/eps/world.move`;
49
+ const data = await fsAsync.readFile(filePath, 'utf8');
50
+
51
+ // update version data
52
+ const updatedData = data.replace(
53
+ /const VERSION: u64 = \d+;/,
54
+ `const VERSION: u64 = ${newVersion};`
55
+ );
56
+
57
+ // write new version
58
+ writeOutput(updatedData, filePath, 'Update package version');
59
+ } catch {
60
+ throw new FsIibError('Fs update version failed.');
61
+ }
52
62
  }
53
63
 
54
64
  async function getDeploymentJson(projectPath: string, network: string) {
55
- try {
56
- const data = await fsAsync.readFile(
57
- `${projectPath}/.history/sui_${network}/latest.json`,
58
- "utf8"
59
- );
60
- return JSON.parse(data) as DeploymentJsonType;
61
- } catch {
62
- throw new FsIibError("Fs read deployment file failed.");
63
- }
65
+ try {
66
+ const data = await fsAsync.readFile(
67
+ `${projectPath}/.history/sui_${network}/latest.json`,
68
+ 'utf8'
69
+ );
70
+ return JSON.parse(data) as DeploymentJsonType;
71
+ } catch {
72
+ throw new FsIibError('Fs read deployment file failed.');
73
+ }
64
74
  }
65
75
 
66
76
  export async function getVersion(
67
- projectPath: string,
68
- network: string
77
+ projectPath: string,
78
+ network: string
69
79
  ): Promise<number> {
70
- const deployment = await getDeploymentJson(projectPath, network);
71
- return deployment.version;
80
+ const deployment = await getDeploymentJson(projectPath, network);
81
+ return deployment.version;
72
82
  }
73
83
 
74
84
  export async function getNetwork(
75
- projectPath: string,
76
- network: string
77
- ): Promise<"mainnet" | "testnet" | "devnet" | "localnet"> {
78
- const deployment = await getDeploymentJson(projectPath, network);
79
- return deployment.network;
85
+ projectPath: string,
86
+ network: string
87
+ ): Promise<'mainnet' | 'testnet' | 'devnet' | 'localnet'> {
88
+ const deployment = await getDeploymentJson(projectPath, network);
89
+ return deployment.network;
80
90
  }
81
91
 
82
92
  export async function getOldPackageId(
83
- projectPath: string,
84
- network: string
93
+ projectPath: string,
94
+ network: string
85
95
  ): Promise<string> {
86
- const deployment = await getDeploymentJson(projectPath, network);
87
- return deployment.packageId;
96
+ const deployment = await getDeploymentJson(projectPath, network);
97
+ return deployment.packageId;
88
98
  }
89
99
 
90
100
  export async function getWorldId(
91
- projectPath: string,
92
- network: string
101
+ projectPath: string,
102
+ network: string
93
103
  ): Promise<string> {
94
- const deployment = await getDeploymentJson(projectPath, network);
95
- return deployment.worldId;
104
+ const deployment = await getDeploymentJson(projectPath, network);
105
+ return deployment.worldId;
96
106
  }
97
107
 
98
108
  export async function getUpgradeCap(
99
- projectPath: string,
100
- network: string
109
+ projectPath: string,
110
+ network: string
101
111
  ): Promise<string> {
102
- const deployment = await getDeploymentJson(projectPath, network);
103
- return deployment.upgradeCap;
112
+ const deployment = await getDeploymentJson(projectPath, network);
113
+ return deployment.upgradeCap;
104
114
  }
105
115
 
106
116
  export async function getAdminCap(
107
- projectPath: string,
108
- network: string
117
+ projectPath: string,
118
+ network: string
109
119
  ): Promise<string> {
110
- const deployment = await getDeploymentJson(projectPath, network);
111
- return deployment.adminCap;
120
+ const deployment = await getDeploymentJson(projectPath, network);
121
+ return deployment.adminCap;
112
122
  }
113
123
 
114
124
  export function saveContractData(
115
- projectName: string,
116
- network: "mainnet" | "testnet" | "devnet" | "localnet",
117
- packageId: string,
118
- worldId: string,
119
- upgradeCap: string,
120
- adminCap: string,
121
- version: number
125
+ projectName: string,
126
+ network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
127
+ packageId: string,
128
+ worldId: string,
129
+ upgradeCap: string,
130
+ adminCap: string,
131
+ version: number
122
132
  ) {
123
- const DeploymentData: DeploymentJsonType = {
124
- projectName,
125
- network,
126
- packageId,
127
- worldId,
128
- upgradeCap,
129
- adminCap,
130
- version,
131
- };
132
-
133
- const path = process.cwd();
134
- const storeDeploymentData = JSON.stringify(DeploymentData, null, 2);
135
- writeOutput(
136
- storeDeploymentData,
137
- `${path}/contracts/${projectName}/.history/sui_${network}/latest.json`,
138
- "Update deploy log"
139
- );
133
+ const DeploymentData: DeploymentJsonType = {
134
+ projectName,
135
+ network,
136
+ packageId,
137
+ worldId,
138
+ upgradeCap,
139
+ adminCap,
140
+ version,
141
+ };
142
+
143
+ const path = process.cwd();
144
+ const storeDeploymentData = JSON.stringify(DeploymentData, null, 2);
145
+ writeOutput(
146
+ storeDeploymentData,
147
+ `${path}/contracts/${projectName}/.history/sui_${network}/latest.json`,
148
+ 'Update deploy log'
149
+ );
140
150
  }
141
151
 
142
152
  export async function writeOutput(
143
- output: string,
144
- fullOutputPath: string,
145
- logPrefix?: string
153
+ output: string,
154
+ fullOutputPath: string,
155
+ logPrefix?: string
146
156
  ): Promise<void> {
147
- mkdirSync(dirname(fullOutputPath), { recursive: true });
157
+ mkdirSync(dirname(fullOutputPath), { recursive: true });
148
158
 
149
- writeFileSync(fullOutputPath, output);
150
- if (logPrefix !== undefined) {
151
- console.log(`${logPrefix}: ${fullOutputPath}`);
152
- }
159
+ writeFileSync(fullOutputPath, output);
160
+ if (logPrefix !== undefined) {
161
+ console.log(`${logPrefix}: ${fullOutputPath}`);
162
+ }
153
163
  }