@hardkas/config 0.1.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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +105 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Javier Rodriguez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { NetworkId } from '@hardkas/core';
|
|
2
|
+
|
|
3
|
+
type HardkasTargetKind = "simulated" | "kaspa-node" | "kaspa-rpc" | "igra";
|
|
4
|
+
type HardkasNetworkName = string;
|
|
5
|
+
interface HardkasSimulatedTarget {
|
|
6
|
+
kind: "simulated";
|
|
7
|
+
}
|
|
8
|
+
interface HardkasKaspaNodeTarget {
|
|
9
|
+
kind: "kaspa-node";
|
|
10
|
+
network: "mainnet" | "testnet-10" | "testnet-11" | "testnet-12" | "devnet";
|
|
11
|
+
rpcUrl?: string;
|
|
12
|
+
dataDir?: string;
|
|
13
|
+
binaryPath?: string;
|
|
14
|
+
}
|
|
15
|
+
interface HardkasKaspaRpcTarget {
|
|
16
|
+
kind: "kaspa-rpc";
|
|
17
|
+
network: "mainnet" | "testnet-10" | "testnet-11" | "testnet-12" | "devnet";
|
|
18
|
+
rpcUrl: string;
|
|
19
|
+
}
|
|
20
|
+
interface HardkasIgraTarget {
|
|
21
|
+
kind: "igra";
|
|
22
|
+
chainId: number;
|
|
23
|
+
rpcUrl: string;
|
|
24
|
+
currencySymbol?: "iKAS";
|
|
25
|
+
}
|
|
26
|
+
type HardkasNetworkTarget = HardkasSimulatedTarget | HardkasKaspaNodeTarget | HardkasKaspaRpcTarget | HardkasIgraTarget;
|
|
27
|
+
type HardkasAccountConfig = {
|
|
28
|
+
kind: "simulated";
|
|
29
|
+
address?: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "kaspa-private-key";
|
|
32
|
+
privateKeyEnv: string;
|
|
33
|
+
address?: string;
|
|
34
|
+
} | {
|
|
35
|
+
kind: "external-wallet";
|
|
36
|
+
walletId?: string;
|
|
37
|
+
address?: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "evm-private-key";
|
|
40
|
+
privateKeyEnv: string;
|
|
41
|
+
address?: string;
|
|
42
|
+
};
|
|
43
|
+
interface HardkasConfig {
|
|
44
|
+
defaultNetwork?: HardkasNetworkName;
|
|
45
|
+
networks?: Record<HardkasNetworkName, HardkasNetworkTarget>;
|
|
46
|
+
accounts?: Record<string, HardkasAccountConfig>;
|
|
47
|
+
}
|
|
48
|
+
interface LoadedHardkasConfig {
|
|
49
|
+
path?: string;
|
|
50
|
+
cwd: string;
|
|
51
|
+
config: HardkasConfig;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare function defineHardkasConfig(config: HardkasConfig): HardkasConfig;
|
|
55
|
+
|
|
56
|
+
interface LoadHardkasConfigOptions {
|
|
57
|
+
cwd?: string;
|
|
58
|
+
configPath?: string;
|
|
59
|
+
}
|
|
60
|
+
declare function loadHardkasConfig(options?: LoadHardkasConfigOptions): Promise<LoadedHardkasConfig>;
|
|
61
|
+
|
|
62
|
+
interface ResolveNetworkTargetOptions {
|
|
63
|
+
config: HardkasConfig;
|
|
64
|
+
network?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare function resolveNetworkTarget(options: ResolveNetworkTargetOptions): {
|
|
68
|
+
name: NetworkId;
|
|
69
|
+
target: HardkasNetworkTarget;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
declare const DEFAULT_HARDKAS_CONFIG: HardkasConfig;
|
|
73
|
+
|
|
74
|
+
export { DEFAULT_HARDKAS_CONFIG, type HardkasAccountConfig, type HardkasConfig, type HardkasIgraTarget, type HardkasKaspaNodeTarget, type HardkasKaspaRpcTarget, type HardkasNetworkName, type HardkasNetworkTarget, type HardkasSimulatedTarget, type HardkasTargetKind, type LoadHardkasConfigOptions, type LoadedHardkasConfig, type ResolveNetworkTargetOptions, defineHardkasConfig, loadHardkasConfig, resolveNetworkTarget };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// src/define.ts
|
|
2
|
+
function defineHardkasConfig(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/load.ts
|
|
7
|
+
import path from "path";
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import { createJiti } from "jiti";
|
|
10
|
+
|
|
11
|
+
// src/defaults.ts
|
|
12
|
+
var DEFAULT_HARDKAS_CONFIG = {
|
|
13
|
+
defaultNetwork: "simnet",
|
|
14
|
+
networks: {
|
|
15
|
+
simnet: {
|
|
16
|
+
kind: "simulated"
|
|
17
|
+
},
|
|
18
|
+
devnet: {
|
|
19
|
+
kind: "kaspa-node",
|
|
20
|
+
network: "devnet",
|
|
21
|
+
rpcUrl: "ws://127.0.0.1:18310"
|
|
22
|
+
},
|
|
23
|
+
testnet10: {
|
|
24
|
+
kind: "kaspa-rpc",
|
|
25
|
+
network: "testnet-10",
|
|
26
|
+
rpcUrl: "ws://127.0.0.1:18210"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
accounts: {
|
|
30
|
+
alice: { kind: "simulated", address: "kaspa:sim_alice" },
|
|
31
|
+
bob: { kind: "simulated", address: "kaspa:sim_bob" },
|
|
32
|
+
carol: { kind: "simulated", address: "kaspa:sim_carol" }
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/load.ts
|
|
37
|
+
async function loadHardkasConfig(options = {}) {
|
|
38
|
+
const cwd = options.cwd ?? process.cwd();
|
|
39
|
+
if (options.configPath) {
|
|
40
|
+
const absolutePath = path.resolve(cwd, options.configPath);
|
|
41
|
+
if (!fs.existsSync(absolutePath)) {
|
|
42
|
+
throw new Error(`HardKAS config file not found at ${absolutePath}`);
|
|
43
|
+
}
|
|
44
|
+
return loadConfigFile(absolutePath, cwd);
|
|
45
|
+
}
|
|
46
|
+
const indicators = [
|
|
47
|
+
"hardkas.config.ts",
|
|
48
|
+
"hardkas.config.mts",
|
|
49
|
+
"hardkas.config.js",
|
|
50
|
+
"hardkas.config.mjs"
|
|
51
|
+
];
|
|
52
|
+
let current = cwd;
|
|
53
|
+
const root = path.parse(current).root;
|
|
54
|
+
while (current !== root) {
|
|
55
|
+
for (const indicator of indicators) {
|
|
56
|
+
const p = path.join(current, indicator);
|
|
57
|
+
if (fs.existsSync(p)) {
|
|
58
|
+
return loadConfigFile(p, current);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const parent = path.dirname(current);
|
|
62
|
+
if (parent === current) break;
|
|
63
|
+
current = parent;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
cwd,
|
|
67
|
+
config: DEFAULT_HARDKAS_CONFIG
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function loadConfigFile(filePath, cwd) {
|
|
71
|
+
try {
|
|
72
|
+
const jiti = createJiti(import.meta.url);
|
|
73
|
+
const module = await jiti.import(filePath);
|
|
74
|
+
const config = module.default || module.config || module;
|
|
75
|
+
return {
|
|
76
|
+
path: filePath,
|
|
77
|
+
cwd,
|
|
78
|
+
config
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error(`Failed to load HardKAS config at ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/resolve.ts
|
|
86
|
+
function resolveNetworkTarget(options) {
|
|
87
|
+
const { config, network } = options;
|
|
88
|
+
const name = network || config.defaultNetwork || "simnet";
|
|
89
|
+
const networks = config.networks && Object.keys(config.networks).length > 0 ? config.networks : DEFAULT_HARDKAS_CONFIG.networks;
|
|
90
|
+
const target = networks[name];
|
|
91
|
+
if (!target) {
|
|
92
|
+
const available = Object.keys(networks).join(", ");
|
|
93
|
+
throw new Error(`Unknown HardKAS network '${name}'. Available networks: ${available}`);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
name,
|
|
97
|
+
target
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
DEFAULT_HARDKAS_CONFIG,
|
|
102
|
+
defineHardkasConfig,
|
|
103
|
+
loadHardkasConfig,
|
|
104
|
+
resolveNetworkTarget
|
|
105
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hardkas/config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"jiti": "^2.4.2",
|
|
20
|
+
"@hardkas/core": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsup": "^8.3.5",
|
|
24
|
+
"typescript": "^5.7.2",
|
|
25
|
+
"vitest": "^2.1.8"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "Javier Rodriguez",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/jrodrg92/Hardkas.git",
|
|
32
|
+
"directory": "packages/config"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/jrodrg92/Hardkas/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/jrodrg92/Hardkas/tree/main/packages/config#readme",
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
40
|
+
"dev": "tsup src/index.ts --format esm --watch --dts",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
43
|
+
}
|
|
44
|
+
}
|