@lightprotocol/zk-compression-cli 0.3.0

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 (106) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +189 -0
  3. package/accounts/address_merkle_tree_C83cpRN6oaafjNgMQJvaYgAz592EP5wunKvbokeTKPLn.json +1 -0
  4. package/accounts/address_merkle_tree_queue_HNjtNrjt6irUPYEgxhx2Vcs42koK9fxzm3aFLHVaaRWz.json +1 -0
  5. package/accounts/governance_authority_pda_3MtrKu5Mjgh3JqeE5PeRzw2Ld28XjFgbbph67E6UERSx.json +1 -0
  6. package/accounts/group_pda_Edo2YjXU5eE17CejPBkupPgFLcYuAX47pGZmM7s2hAkj.json +1 -0
  7. package/accounts/merkle_tree_pubkey_5bdFnXU47QjzGpzHfXnxcEi5WXyxzEAZzd1vrE39bf1W.json +1 -0
  8. package/accounts/nullifier_queue_pubkey_44J4oDXpjPAbzHCSc24q7NEiPekss4sAbLd8ka4gd9CZ.json +1 -0
  9. package/accounts/registered_program_pda_ytwwVWhQUMoTKdirKmvEW5xCRVr4B2dJZnToiHtE2L2.json +1 -0
  10. package/bin/account_compression.so +0 -0
  11. package/bin/light_compressed_pda.so +0 -0
  12. package/bin/light_compressed_token.so +0 -0
  13. package/bin/light_registry.so +0 -0
  14. package/bin/light_system_program.so +0 -0
  15. package/bin/prover-darwin-arm64 +0 -0
  16. package/bin/prover-darwin-x64 +0 -0
  17. package/bin/prover-linux-arm64 +0 -0
  18. package/bin/prover-linux-x64 +0 -0
  19. package/bin/prover-windows-arm64.exe +0 -0
  20. package/bin/prover-windows-x64.exe +0 -0
  21. package/bin/proving-keys/combined_26_1_1.key +0 -0
  22. package/bin/proving-keys/combined_26_1_1.vkey +1 -0
  23. package/bin/proving-keys/combined_26_1_2.key +0 -0
  24. package/bin/proving-keys/combined_26_1_2.vkey +1 -0
  25. package/bin/proving-keys/combined_26_2_1.key +0 -0
  26. package/bin/proving-keys/combined_26_2_1.vkey +1 -0
  27. package/bin/proving-keys/combined_26_2_2.key +0 -0
  28. package/bin/proving-keys/combined_26_2_2.vkey +1 -0
  29. package/bin/proving-keys/combined_26_3_1.key +0 -0
  30. package/bin/proving-keys/combined_26_3_1.vkey +1 -0
  31. package/bin/proving-keys/combined_26_3_2.key +0 -0
  32. package/bin/proving-keys/combined_26_3_2.vkey +1 -0
  33. package/bin/proving-keys/combined_26_4_1.key +0 -0
  34. package/bin/proving-keys/combined_26_4_1.vkey +1 -0
  35. package/bin/proving-keys/combined_26_4_2.key +0 -0
  36. package/bin/proving-keys/combined_26_4_2.vkey +1 -0
  37. package/bin/proving-keys/inclusion_26_1.key +0 -0
  38. package/bin/proving-keys/inclusion_26_1.vkey +1 -0
  39. package/bin/proving-keys/inclusion_26_2.key +0 -0
  40. package/bin/proving-keys/inclusion_26_2.vkey +1 -0
  41. package/bin/proving-keys/inclusion_26_3.key +0 -0
  42. package/bin/proving-keys/inclusion_26_3.vkey +1 -0
  43. package/bin/proving-keys/inclusion_26_4.key +0 -0
  44. package/bin/proving-keys/inclusion_26_4.vkey +1 -0
  45. package/bin/proving-keys/inclusion_26_8.key +0 -0
  46. package/bin/proving-keys/inclusion_26_8.vkey +1 -0
  47. package/bin/proving-keys/non-inclusion_26_1.key +0 -0
  48. package/bin/proving-keys/non-inclusion_26_1.vkey +1 -0
  49. package/bin/proving-keys/non-inclusion_26_2.key +0 -0
  50. package/bin/proving-keys/non-inclusion_26_2.vkey +1 -0
  51. package/bin/spl_noop.so +0 -0
  52. package/config.json +3 -0
  53. package/dist/commands/approve-and-mint-to/index.d.ts +14 -0
  54. package/dist/commands/approve-and-mint-to/index.js +64 -0
  55. package/dist/commands/balance/index.d.ts +12 -0
  56. package/dist/commands/balance/index.js +50 -0
  57. package/dist/commands/compress-sol/index.d.ts +12 -0
  58. package/dist/commands/compress-sol/index.js +48 -0
  59. package/dist/commands/compress-spl/index.d.ts +13 -0
  60. package/dist/commands/compress-spl/index.js +61 -0
  61. package/dist/commands/config/config.d.ts +11 -0
  62. package/dist/commands/config/config.js +69 -0
  63. package/dist/commands/config/index.d.ts +2 -0
  64. package/dist/commands/config/index.js +5 -0
  65. package/dist/commands/create-mint/index.d.ts +17 -0
  66. package/dist/commands/create-mint/index.js +67 -0
  67. package/dist/commands/decompress-sol/index.d.ts +12 -0
  68. package/dist/commands/decompress-sol/index.js +46 -0
  69. package/dist/commands/decompress-spl/index.d.ts +13 -0
  70. package/dist/commands/decompress-spl/index.js +60 -0
  71. package/dist/commands/mint-to/index.d.ts +14 -0
  72. package/dist/commands/mint-to/index.js +64 -0
  73. package/dist/commands/register-mint/index.d.ts +14 -0
  74. package/dist/commands/register-mint/index.js +50 -0
  75. package/dist/commands/start-prover/index.d.ts +11 -0
  76. package/dist/commands/start-prover/index.js +30 -0
  77. package/dist/commands/test-validator/index.d.ts +16 -0
  78. package/dist/commands/test-validator/index.js +61 -0
  79. package/dist/commands/transfer/index.d.ts +13 -0
  80. package/dist/commands/transfer/index.js +62 -0
  81. package/dist/index.d.ts +3 -0
  82. package/dist/index.js +8 -0
  83. package/dist/psp-utils/download.d.ts +34 -0
  84. package/dist/psp-utils/download.js +203 -0
  85. package/dist/psp-utils/index.d.ts +1 -0
  86. package/dist/psp-utils/index.js +4 -0
  87. package/dist/utils/constants.d.ts +14 -0
  88. package/dist/utils/constants.js +19 -0
  89. package/dist/utils/index.d.ts +5 -0
  90. package/dist/utils/index.js +8 -0
  91. package/dist/utils/initTestEnv.d.ts +38 -0
  92. package/dist/utils/initTestEnv.js +171 -0
  93. package/dist/utils/process.d.ts +30 -0
  94. package/dist/utils/process.js +162 -0
  95. package/dist/utils/processPhotonIndexer.d.ts +1 -0
  96. package/dist/utils/processPhotonIndexer.js +45 -0
  97. package/dist/utils/processProverServer.d.ts +3 -0
  98. package/dist/utils/processProverServer.js +49 -0
  99. package/dist/utils/standardFlags.d.ts +8 -0
  100. package/dist/utils/standardFlags.js +36 -0
  101. package/dist/utils/utils.d.ts +26 -0
  102. package/dist/utils/utils.js +150 -0
  103. package/oclif.manifest.json +684 -0
  104. package/package.json +122 -0
  105. package/test_bin/dev +17 -0
  106. package/test_bin/run +5 -0
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startIndexer = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const which_1 = tslib_1.__importDefault(require("which"));
6
+ const process_1 = require("./process");
7
+ const constants_1 = require("./constants");
8
+ const node_child_process_1 = require("node:child_process");
9
+ const util = tslib_1.__importStar(require("node:util"));
10
+ async function startIndexer(checkPhotonVersion = true, photonDatabaseUrl) {
11
+ await killIndexer();
12
+ const resolvedOrNull = which_1.default.sync("photon", { nothrow: true });
13
+ if (resolvedOrNull === null ||
14
+ (checkPhotonVersion && !(await isExpectedPhotonVersion(constants_1.PHOTON_VERSION)))) {
15
+ const message = `Photon indexer not found. Please install it by running "cargo install photon-indexer --version ${constants_1.PHOTON_VERSION}"`;
16
+ console.log(message);
17
+ throw new Error(message);
18
+ }
19
+ else {
20
+ console.log("Starting indexer...");
21
+ let args = [];
22
+ if (photonDatabaseUrl) {
23
+ args = ["--db-url", photonDatabaseUrl];
24
+ }
25
+ (0, process_1.spawnBinary)(constants_1.INDEXER_PROCESS_NAME, args);
26
+ await (0, process_1.waitForServers)([{ port: 8784, path: "/getIndexerHealth" }]);
27
+ console.log("Indexer started successfully!");
28
+ }
29
+ }
30
+ exports.startIndexer = startIndexer;
31
+ async function killIndexer() {
32
+ await (0, process_1.killProcess)(constants_1.INDEXER_PROCESS_NAME);
33
+ }
34
+ const execAsync = util.promisify(node_child_process_1.exec);
35
+ async function isExpectedPhotonVersion(requiredVersion) {
36
+ try {
37
+ const { stdout } = await execAsync("photon --version");
38
+ const version = stdout.trim();
39
+ return version.includes(requiredVersion);
40
+ }
41
+ catch (error) {
42
+ console.error("Error checking Photon version:", error);
43
+ return false;
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ export declare function killProver(): Promise<void>;
2
+ export declare function startProver(proveCompressedAccounts: boolean, proveNewAddresses: boolean): Promise<void>;
3
+ export declare function getProverNameByArch(): string;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProverNameByArch = exports.startProver = exports.killProver = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const process_1 = require("./process");
7
+ const constants_1 = require("./constants");
8
+ const KEYS_DIR = "proving-keys/";
9
+ async function killProver() {
10
+ await (0, process_1.killProcess)(getProverNameByArch());
11
+ // Temporary fix for the case when prover is instantiated via prover.sh:
12
+ await (0, process_1.killProcess)(constants_1.LIGHT_PROVER_PROCESS_NAME);
13
+ }
14
+ exports.killProver = killProver;
15
+ async function startProver(proveCompressedAccounts, proveNewAddresses) {
16
+ if (!proveCompressedAccounts && !proveNewAddresses) {
17
+ console.log("No flags provided. Please provide at least one flag to start the prover.");
18
+ process.exit(1);
19
+ }
20
+ console.log("Kill existing prover process...");
21
+ await killProver();
22
+ await (0, process_1.killProcessByPort)("3001");
23
+ const keysDir = path_1.default.join(__dirname, "../..", "bin", KEYS_DIR);
24
+ const args = ["start"];
25
+ args.push(`--inclusion=${proveCompressedAccounts ? "true" : "false"}`);
26
+ args.push(`--non-inclusion=${proveNewAddresses ? "true" : "false"}`);
27
+ args.push("--keys-dir", keysDir);
28
+ console.log("Starting prover...");
29
+ (0, process_1.spawnBinary)(getProverNameByArch(), args);
30
+ await (0, process_1.waitForServers)([{ port: 3001, path: "/" }]);
31
+ console.log("Prover started successfully!");
32
+ }
33
+ exports.startProver = startProver;
34
+ function getProverNameByArch() {
35
+ const platform = process.platform;
36
+ const arch = process.arch;
37
+ if (!platform || !arch) {
38
+ throw new Error("Unsupported platform or architecture");
39
+ }
40
+ let binaryName = `prover-${platform}-${arch}`;
41
+ if (platform.toString() === "windows") {
42
+ binaryName += ".exe";
43
+ }
44
+ // We need to provide the full path to the binary because it's not in the PATH.
45
+ const binDir = path_1.default.join(__dirname, "../..", "bin");
46
+ binaryName = path_1.default.join(binDir, binaryName);
47
+ return binaryName;
48
+ }
49
+ exports.getProverNameByArch = getProverNameByArch;
@@ -0,0 +1,8 @@
1
+ export declare const standardFlags: {
2
+ skipFetchBalance: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
3
+ localTestRpc: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
4
+ };
5
+ export declare const confirmOptionsFlags: {
6
+ spendable: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
+ finalized: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.confirmOptionsFlags = exports.standardFlags = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ exports.standardFlags = {
6
+ skipFetchBalance: core_1.Flags.boolean({
7
+ char: "b",
8
+ description: "Skip fetching the most recent balance prior to the operation",
9
+ required: false,
10
+ default: false,
11
+ parse: async () => true,
12
+ }),
13
+ localTestRpc: core_1.Flags.boolean({
14
+ description: "Using a local test rpc",
15
+ aliases: ["lr"],
16
+ required: false,
17
+ default: true,
18
+ parse: async () => true,
19
+ }),
20
+ };
21
+ exports.confirmOptionsFlags = {
22
+ spendable: core_1.Flags.boolean({
23
+ char: "s",
24
+ description: "Fetch the most recent balance prior to the operation",
25
+ required: false,
26
+ default: false,
27
+ parse: async () => true,
28
+ }),
29
+ finalized: core_1.Flags.boolean({
30
+ char: "f",
31
+ description: "Fetch the most recent balance prior to the operation",
32
+ required: false,
33
+ default: false,
34
+ parse: async () => true,
35
+ }),
36
+ };
@@ -0,0 +1,26 @@
1
+ import * as anchor from "@coral-xyz/anchor";
2
+ import { Keypair } from "@solana/web3.js";
3
+ export declare const defaultSolanaWalletKeypair: () => Keypair;
4
+ export declare const setAnchorProvider: () => Promise<anchor.AnchorProvider>;
5
+ export declare function getPayer(): Promise<anchor.web3.Keypair>;
6
+ export declare function generateSolanaTransactionURL(transactionType: "tx" | "address", transactionHash: string, cluster: string): string;
7
+ type Config = {
8
+ solanaRpcUrl: string;
9
+ };
10
+ export declare const getSolanaRpcUrl: () => string;
11
+ export declare const getConfig: (filePath?: string) => Config;
12
+ export declare function ensureDirectoryExists(dirPath: string): void;
13
+ export declare const setConfig: (config: Partial<Config>, filePath?: string) => void;
14
+ export declare class CustomLoader {
15
+ message: string;
16
+ logInterval: any;
17
+ logTimer: number | null;
18
+ startTime: number;
19
+ constructor(message: string, logInterval?: number);
20
+ start(): void;
21
+ stop(terminateCurve?: boolean): void;
22
+ logElapsedTime(): void;
23
+ }
24
+ export declare function isValidURL(url: string): boolean;
25
+ export declare function isValidBase58SecretKey(secretKey: string): boolean;
26
+ export {};
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidBase58SecretKey = exports.isValidURL = exports.CustomLoader = exports.setConfig = exports.ensureDirectoryExists = exports.getConfig = exports.getSolanaRpcUrl = exports.generateSolanaTransactionURL = exports.getPayer = exports.setAnchorProvider = exports.defaultSolanaWalletKeypair = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const fs_1 = require("fs");
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const anchor = tslib_1.__importStar(require("@coral-xyz/anchor"));
9
+ const solana = tslib_1.__importStar(require("@solana/web3.js"));
10
+ const web3_js_1 = require("@solana/web3.js");
11
+ const stateless_js_1 = require("@lightprotocol/stateless.js");
12
+ const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
13
+ const constants_1 = require("./constants");
14
+ const helpers_1 = require("@solana-developers/helpers");
15
+ const cli_spinners_1 = tslib_1.__importDefault(require("cli-spinners"));
16
+ require("dotenv").config();
17
+ const defaultSolanaWalletKeypair = () => {
18
+ const walletPath = process.env.HOME + "/.config/solana/id.json";
19
+ if (fs.existsSync(walletPath)) {
20
+ return web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(fs.readFileSync(walletPath, "utf-8"))));
21
+ }
22
+ else {
23
+ throw new Error("Wallet file not found");
24
+ }
25
+ };
26
+ exports.defaultSolanaWalletKeypair = defaultSolanaWalletKeypair;
27
+ const setAnchorProvider = async () => {
28
+ process.env.ANCHOR_WALLET = getWalletPath();
29
+ process.env.ANCHOR_PROVIDER_URL = (0, exports.getSolanaRpcUrl)();
30
+ const connection = new solana.Connection((0, exports.getSolanaRpcUrl)(), "confirmed");
31
+ const payer = await getPayer();
32
+ const anchorProvider = new anchor.AnchorProvider(connection, new anchor.Wallet(payer), stateless_js_1.confirmConfig);
33
+ anchor.setProvider(anchorProvider);
34
+ return anchorProvider;
35
+ };
36
+ exports.setAnchorProvider = setAnchorProvider;
37
+ function getWalletPath() {
38
+ return process.env.HOME + "/.config/solana/id.json";
39
+ }
40
+ async function getPayer() {
41
+ return await (0, helpers_1.getKeypairFromFile)(getWalletPath());
42
+ }
43
+ exports.getPayer = getPayer;
44
+ function generateSolanaTransactionURL(transactionType, transactionHash, cluster) {
45
+ return `https://explorer.solana.com/${transactionType}/${transactionHash}?cluster=${cluster}`;
46
+ }
47
+ exports.generateSolanaTransactionURL = generateSolanaTransactionURL;
48
+ const getSolanaRpcUrl = () => {
49
+ const config = (0, exports.getConfig)();
50
+ return config.solanaRpcUrl;
51
+ };
52
+ exports.getSolanaRpcUrl = getSolanaRpcUrl;
53
+ function getConfigPath() {
54
+ // Check for the environment variable
55
+ const envConfigPath = process.env.LIGHT_PROTOCOL_CONFIG;
56
+ if (envConfigPath) {
57
+ console.log(`reading config from custom path ${envConfigPath}`);
58
+ if (!(0, fs_1.existsSync)(envConfigPath)) {
59
+ throw new Error(`Config file not found at ${envConfigPath}, this path is configured with the environment variable LIGHT_PROTOCOL_CONFIG, the default path is ${process.env.HOME + constants_1.CONFIG_PATH + constants_1.CONFIG_FILE_NAME}, to use the default path, remove the environment variable LIGHT_PROTOCOL_CONFIG`);
60
+ }
61
+ return envConfigPath;
62
+ }
63
+ // Default path
64
+ return process.env.HOME + constants_1.CONFIG_PATH + constants_1.CONFIG_FILE_NAME;
65
+ }
66
+ const getConfig = (filePath) => {
67
+ if (!filePath)
68
+ filePath = getConfigPath();
69
+ let configData;
70
+ try {
71
+ configData = fs.readFileSync(filePath, "utf-8");
72
+ }
73
+ catch (error) {
74
+ // Ensure the directory structure exists
75
+ const dir = path.dirname(filePath);
76
+ if (!fs.existsSync(dir)) {
77
+ fs.mkdirSync(dir, { recursive: true });
78
+ }
79
+ ensureDirectoryExists(process.env.HOME + constants_1.CONFIG_PATH);
80
+ if (!fs.existsSync(filePath)) {
81
+ const data = {
82
+ ...constants_1.DEFAULT_CONFIG,
83
+ secretKey: bytes_1.bs58.encode(solana.Keypair.generate().secretKey),
84
+ };
85
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
86
+ console.log("created config file in", filePath);
87
+ configData = fs.readFileSync(filePath, "utf-8");
88
+ }
89
+ }
90
+ return JSON.parse(configData);
91
+ };
92
+ exports.getConfig = getConfig;
93
+ function ensureDirectoryExists(dirPath) {
94
+ if (!fs.existsSync(dirPath)) {
95
+ fs.mkdirSync(dirPath, { recursive: true });
96
+ }
97
+ }
98
+ exports.ensureDirectoryExists = ensureDirectoryExists;
99
+ const setConfig = (config, filePath) => {
100
+ if (!filePath)
101
+ filePath = getConfigPath();
102
+ try {
103
+ const existingConfig = (0, exports.getConfig)();
104
+ const updatedConfig = { ...existingConfig, ...config };
105
+ fs.writeFileSync(filePath, JSON.stringify(updatedConfig, null, 2));
106
+ }
107
+ catch (error) {
108
+ throw new Error("Failed to update configuration file");
109
+ }
110
+ };
111
+ exports.setConfig = setConfig;
112
+ class CustomLoader {
113
+ constructor(message, logInterval = 1000) {
114
+ this.message = message;
115
+ this.logInterval = logInterval;
116
+ this.logTimer = null;
117
+ this.startTime = Date.now();
118
+ }
119
+ start() {
120
+ this.startTime = Date.now();
121
+ process.stdout.write(`\n${cli_spinners_1.default.dots.frames[Math.floor(Math.random() * 10)]} ${this.message}\n`);
122
+ this.logInterval = setInterval(() => { }, this.logInterval);
123
+ }
124
+ stop(terminateCurve = true) {
125
+ clearInterval(this.logInterval);
126
+ if (terminateCurve)
127
+ globalThis.curve_bn128.terminate();
128
+ this.logElapsedTime();
129
+ }
130
+ logElapsedTime() {
131
+ const elapsedTime = ((Date.now() - this.startTime) / 1000).toFixed(2);
132
+ process.stdout.write(`\nElapsed time: ${elapsedTime}s\n`);
133
+ }
134
+ }
135
+ exports.CustomLoader = CustomLoader;
136
+ function isValidURL(url) {
137
+ try {
138
+ new URL(url);
139
+ return true;
140
+ }
141
+ catch (error) {
142
+ return false;
143
+ }
144
+ }
145
+ exports.isValidURL = isValidURL;
146
+ function isValidBase58SecretKey(secretKey) {
147
+ const base58Regex = /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/;
148
+ return base58Regex.test(secretKey);
149
+ }
150
+ exports.isValidBase58SecretKey = isValidBase58SecretKey;