create-mn-app 0.3.8 → 0.3.10

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,74 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { NetworkId, setNetworkId } from "@midnight-ntwrk/midnight-js-network-id";
4
- import { NetworkConfig } from "../providers/midnight-providers.js";
5
-
6
- const SUPPORTED_NETWORKS = ["preprod"] as const;
7
- type SupportedNetwork = (typeof SUPPORTED_NETWORKS)[number];
8
-
9
- export class EnvironmentManager {
10
- private static networkConfig: NetworkConfig | null = null;
11
-
12
- static getNetworkConfig(): NetworkConfig {
13
- if (this.networkConfig) return this.networkConfig;
14
-
15
- const network = process.env.MIDNIGHT_NETWORK || "preprod";
16
-
17
- if (!SUPPORTED_NETWORKS.includes(network as SupportedNetwork)) {
18
- console.warn(
19
- `Warning: Unknown network "${network}", falling back to "preprod". ` +
20
- `Supported networks: ${SUPPORTED_NETWORKS.join(", ")}`
21
- );
22
- }
23
-
24
- const networks: Record<SupportedNetwork, NetworkConfig> = {
25
- preprod: {
26
- indexer: "https://indexer.preprod.midnight.network/api/v3/graphql",
27
- indexerWS: "wss://indexer.preprod.midnight.network/api/v3/graphql/ws",
28
- node: "https://rpc.preprod.midnight.network",
29
- proofServer: process.env.PROOF_SERVER_URL || "http://127.0.0.1:6300",
30
- name: "Preprod",
31
- faucetUrl: "https://faucet.preprod.midnight.network/",
32
- networkId: NetworkId.TestNet,
33
- },
34
- };
35
-
36
- this.networkConfig = networks[network as SupportedNetwork] || networks.preprod;
37
- return this.networkConfig;
38
- }
39
-
40
- static initializeNetwork(): NetworkConfig {
41
- const config = this.getNetworkConfig();
42
- setNetworkId(config.networkId);
43
- return config;
44
- }
45
-
46
- static validateEnvironment(): void {
47
- const required = ["WALLET_SEED"];
48
- const missing = required.filter((key) => !process.env[key]);
49
-
50
- if (missing.length > 0) {
51
- throw new Error(
52
- `Missing required environment variables: ${missing.join(", ")}`
53
- );
54
- }
55
-
56
- const walletSeed = process.env.WALLET_SEED!;
57
- if (!/^[a-fA-F0-9]{64}$/.test(walletSeed)) {
58
- throw new Error("WALLET_SEED must be a 64-character hexadecimal string");
59
- }
60
- }
61
-
62
- static checkContractCompiled(contractName: string): boolean {
63
- const contractPath = path.join(
64
- process.cwd(),
65
- "contracts",
66
- "managed",
67
- contractName
68
- );
69
- const keysPath = path.join(contractPath, "keys");
70
- const contractModulePath = path.join(contractPath, "contract", "index.cjs");
71
-
72
- return fs.existsSync(keysPath) && fs.existsSync(contractModulePath);
73
- }
74
- }