@agirails/sdk 2.4.2 → 2.5.2

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 (54) hide show
  1. package/README.md +24 -11
  2. package/dist/ACTPClient.d.ts.map +1 -1
  3. package/dist/ACTPClient.js +11 -13
  4. package/dist/ACTPClient.js.map +1 -1
  5. package/dist/cli/commands/deploy-check.d.ts +24 -0
  6. package/dist/cli/commands/deploy-check.d.ts.map +1 -0
  7. package/dist/cli/commands/deploy-check.js +316 -0
  8. package/dist/cli/commands/deploy-check.js.map +1 -0
  9. package/dist/cli/commands/deploy-env.d.ts +19 -0
  10. package/dist/cli/commands/deploy-env.d.ts.map +1 -0
  11. package/dist/cli/commands/deploy-env.js +123 -0
  12. package/dist/cli/commands/deploy-env.js.map +1 -0
  13. package/dist/cli/commands/init.d.ts.map +1 -1
  14. package/dist/cli/commands/init.js +15 -1
  15. package/dist/cli/commands/init.js.map +1 -1
  16. package/dist/cli/commands/publish.js +1 -1
  17. package/dist/cli/commands/publish.js.map +1 -1
  18. package/dist/cli/commands/register.js +1 -1
  19. package/dist/cli/commands/register.js.map +1 -1
  20. package/dist/cli/index.js +5 -0
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/cli/utils/client.d.ts.map +1 -1
  23. package/dist/cli/utils/client.js +4 -2
  24. package/dist/cli/utils/client.js.map +1 -1
  25. package/dist/cli/utils/config.d.ts +12 -0
  26. package/dist/cli/utils/config.d.ts.map +1 -1
  27. package/dist/cli/utils/config.js +61 -1
  28. package/dist/cli/utils/config.js.map +1 -1
  29. package/dist/level0/request.js +1 -1
  30. package/dist/level0/request.js.map +1 -1
  31. package/dist/level1/Agent.js +1 -1
  32. package/dist/level1/Agent.js.map +1 -1
  33. package/dist/runtime/BlockchainRuntime.d.ts +9 -0
  34. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  35. package/dist/runtime/BlockchainRuntime.js +14 -0
  36. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  37. package/dist/wallet/keystore.d.ts +10 -3
  38. package/dist/wallet/keystore.d.ts.map +1 -1
  39. package/dist/wallet/keystore.js +91 -11
  40. package/dist/wallet/keystore.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/ACTPClient.ts +12 -14
  43. package/src/cli/commands/deploy-check.ts +364 -0
  44. package/src/cli/commands/deploy-env.ts +120 -0
  45. package/src/cli/commands/init.ts +15 -1
  46. package/src/cli/commands/publish.ts +1 -1
  47. package/src/cli/commands/register.ts +1 -1
  48. package/src/cli/index.ts +6 -0
  49. package/src/cli/utils/client.ts +5 -3
  50. package/src/cli/utils/config.ts +68 -0
  51. package/src/level0/request.ts +1 -1
  52. package/src/level1/Agent.ts +1 -1
  53. package/src/runtime/BlockchainRuntime.ts +20 -0
  54. package/src/wallet/keystore.ts +116 -11
@@ -0,0 +1,364 @@
1
+ /**
2
+ * Deploy:check Command - Pre-deploy security audit (AIP-13)
3
+ *
4
+ * Scans the project for common deployment security issues:
5
+ * - Missing ignore files
6
+ * - Raw private keys in env files, Dockerfiles, CI configs
7
+ * - Symlinked keystore
8
+ * - Incorrect file permissions
9
+ *
10
+ * Exit code 0: all checks pass (warnings allowed)
11
+ * Exit code 1: at least one FAIL check
12
+ *
13
+ * @module cli/commands/deploy-check
14
+ */
15
+
16
+ import * as fs from 'fs';
17
+ import * as path from 'path';
18
+ import { Command } from 'commander';
19
+ import { Output, ExitCode } from '../utils/output';
20
+ import { getActpDir } from '../utils/config';
21
+
22
+ // ============================================================================
23
+ // Types
24
+ // ============================================================================
25
+
26
+ type CheckSeverity = 'FAIL' | 'WARN';
27
+ type CheckResult = 'PASS' | 'FAIL' | 'WARN' | 'SKIP';
28
+
29
+ interface CheckOutput {
30
+ name: string;
31
+ result: CheckResult;
32
+ message?: string;
33
+ }
34
+
35
+ // ============================================================================
36
+ // Command Definition
37
+ // ============================================================================
38
+
39
+ export function createDeployCheckCommand(): Command {
40
+ const cmd = new Command('deploy:check')
41
+ .description('Pre-deploy security audit (AIP-13)')
42
+ .option('--json', 'Output as JSON')
43
+ .option('-q, --quiet', 'Only show failures')
44
+ .action(async (options) => {
45
+ const output = new Output(
46
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
47
+ );
48
+
49
+ try {
50
+ const exitCode = runDeployCheck(options, output);
51
+ process.exit(exitCode);
52
+ } catch (error) {
53
+ output.errorResult({
54
+ code: 'DEPLOY_CHECK_FAILED',
55
+ message: (error as Error).message,
56
+ });
57
+ process.exit(ExitCode.ERROR);
58
+ }
59
+ });
60
+
61
+ return cmd;
62
+ }
63
+
64
+ // ============================================================================
65
+ // Implementation
66
+ // ============================================================================
67
+
68
+ /** Regex matching a raw private key pattern */
69
+ const RAW_KEY_PATTERN = /0x[0-9a-fA-F]{64}/;
70
+ const RAW_KEY_ENV_PATTERN = /ACTP_PRIVATE_KEY\s*=\s*0x/;
71
+
72
+ interface DeployCheckOptions {
73
+ json?: boolean;
74
+ quiet?: boolean;
75
+ }
76
+
77
+ export function runDeployCheck(options: DeployCheckOptions, output: Output): number {
78
+ const projectRoot = process.cwd();
79
+ const actpDir = getActpDir(projectRoot);
80
+ const results: CheckOutput[] = [];
81
+ let failCount = 0;
82
+ let warnCount = 0;
83
+ let passCount = 0;
84
+
85
+ // ── FAIL checks ──────────────────────────────────────────────────────
86
+
87
+ // 1. .actp/ in .gitignore
88
+ results.push(checkIgnoreFile(projectRoot, '.gitignore', '.actp', 'FAIL'));
89
+
90
+ // 2. .actp/ in .dockerignore
91
+ results.push(checkIgnoreFile(projectRoot, '.dockerignore', '.actp', 'FAIL'));
92
+
93
+ // 3. No ACTP_PRIVATE_KEY in .env* files
94
+ results.push(checkNoRawKeysInEnvFiles(projectRoot));
95
+
96
+ // 4. No raw keys in Dockerfiles
97
+ results.push(checkNoRawKeysInFiles(
98
+ projectRoot,
99
+ ['Dockerfile', 'Dockerfile.*', 'docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml'],
100
+ 'No raw keys in Dockerfiles'
101
+ ));
102
+
103
+ // 5. No raw keys in CI/workflow files
104
+ results.push(checkNoRawKeysInCIFiles(projectRoot));
105
+
106
+ // 6. Keystore is not a symlink
107
+ results.push(checkKeystoreNotSymlink(actpDir));
108
+
109
+ // ── WARN checks ──────────────────────────────────────────────────────
110
+
111
+ // 7. ACTP_KEYSTORE_BASE64 or keystore.json exists
112
+ results.push(checkKeystoreAvailable(actpDir));
113
+
114
+ // 8. Keystore file permissions (POSIX only)
115
+ results.push(checkKeystorePermissions(actpDir));
116
+
117
+ // ── Output ───────────────────────────────────────────────────────────
118
+
119
+ for (const check of results) {
120
+ if (check.result === 'FAIL') failCount++;
121
+ else if (check.result === 'WARN') warnCount++;
122
+ else if (check.result === 'PASS') passCount++;
123
+ }
124
+
125
+ if (options.json) {
126
+ output.result({
127
+ checks: results,
128
+ summary: { passed: passCount, warnings: warnCount, failed: failCount },
129
+ });
130
+ } else {
131
+ output.print('actp deploy:check');
132
+ for (const check of results) {
133
+ if (options.quiet && check.result !== 'FAIL') continue;
134
+ const tag = `[${check.result}]`;
135
+ const msg = check.message ? ` ${check.message}` : '';
136
+ output.print(` ${tag} ${check.name}${msg}`);
137
+ }
138
+ output.print('');
139
+ output.print(` ${passCount} passed, ${warnCount} warnings, ${failCount} failed`);
140
+ }
141
+
142
+ return failCount > 0 ? ExitCode.ERROR : ExitCode.SUCCESS;
143
+ }
144
+
145
+ // ============================================================================
146
+ // Individual Checks
147
+ // ============================================================================
148
+
149
+ function checkIgnoreFile(
150
+ projectRoot: string,
151
+ fileName: string,
152
+ entry: string,
153
+ _severity: CheckSeverity
154
+ ): CheckOutput {
155
+ const filePath = path.join(projectRoot, fileName);
156
+ const name = `${entry} in ${fileName}`;
157
+
158
+ if (!fs.existsSync(filePath)) {
159
+ return { name, result: 'FAIL', message: `${fileName} does not exist` };
160
+ }
161
+
162
+ const content = fs.readFileSync(filePath, 'utf-8');
163
+ if (content.includes(entry)) {
164
+ return { name, result: 'PASS' };
165
+ }
166
+
167
+ return { name, result: 'FAIL', message: `${entry} not found in ${fileName}` };
168
+ }
169
+
170
+ function checkNoRawKeysInEnvFiles(projectRoot: string): CheckOutput {
171
+ const name = 'No raw keys in .env files';
172
+ const envFiles = findMatchingFiles(projectRoot, ['.env', '.env.*', '.env.local', '.env.production']);
173
+
174
+ for (const file of envFiles) {
175
+ const content = safeReadFile(file);
176
+ if (content && (RAW_KEY_PATTERN.test(content) || RAW_KEY_ENV_PATTERN.test(content))) {
177
+ return { name, result: 'FAIL', message: `Raw key found in ${path.basename(file)}` };
178
+ }
179
+ }
180
+
181
+ return { name, result: 'PASS' };
182
+ }
183
+
184
+ function checkNoRawKeysInFiles(
185
+ projectRoot: string,
186
+ patterns: string[],
187
+ name: string
188
+ ): CheckOutput {
189
+ const files = findMatchingFiles(projectRoot, patterns);
190
+
191
+ for (const file of files) {
192
+ const content = safeReadFile(file);
193
+ if (content && RAW_KEY_PATTERN.test(content)) {
194
+ return { name, result: 'FAIL', message: `Raw key found in ${path.basename(file)}` };
195
+ }
196
+ }
197
+
198
+ return { name, result: 'PASS' };
199
+ }
200
+
201
+ function checkNoRawKeysInCIFiles(projectRoot: string): CheckOutput {
202
+ const name = 'No raw keys in CI/workflow files';
203
+
204
+ // Collect all CI-related files
205
+ const files: string[] = [];
206
+
207
+ // GitHub workflows
208
+ const workflowDir = path.join(projectRoot, '.github', 'workflows');
209
+ if (fs.existsSync(workflowDir)) {
210
+ try {
211
+ const entries = fs.readdirSync(workflowDir);
212
+ for (const entry of entries) {
213
+ if (entry.endsWith('.yml') || entry.endsWith('.yaml')) {
214
+ files.push(path.join(workflowDir, entry));
215
+ }
216
+ }
217
+ } catch { /* ignore read errors */ }
218
+ }
219
+
220
+ // Platform config files
221
+ const platformFiles = [
222
+ 'railway.json', 'fly.toml', 'vercel.json',
223
+ 'pm2.config.js', 'pm2.config.cjs', 'ecosystem.config.js', 'ecosystem.config.cjs',
224
+ ];
225
+ for (const pf of platformFiles) {
226
+ const fp = path.join(projectRoot, pf);
227
+ if (fs.existsSync(fp)) files.push(fp);
228
+ }
229
+
230
+ for (const file of files) {
231
+ const content = safeReadFile(file);
232
+ if (content && (RAW_KEY_PATTERN.test(content) || RAW_KEY_ENV_PATTERN.test(content))) {
233
+ return { name, result: 'FAIL', message: `Raw key found in ${path.relative(projectRoot, file)}` };
234
+ }
235
+ }
236
+
237
+ return { name, result: 'PASS' };
238
+ }
239
+
240
+ function checkKeystoreNotSymlink(actpDir: string): CheckOutput {
241
+ const name = 'Keystore is not a symlink';
242
+ const keystorePath = path.join(actpDir, 'keystore.json');
243
+
244
+ if (!fs.existsSync(keystorePath)) {
245
+ return { name, result: 'PASS' };
246
+ }
247
+
248
+ try {
249
+ const stat = fs.lstatSync(keystorePath);
250
+ if (stat.isSymbolicLink()) {
251
+ return { name, result: 'FAIL', message: 'keystore.json is a symlink (security risk)' };
252
+ }
253
+ } catch { /* ignore */ }
254
+
255
+ return { name, result: 'PASS' };
256
+ }
257
+
258
+ function checkKeystoreAvailable(actpDir: string): CheckOutput {
259
+ const name = 'Keystore available';
260
+ const keystorePath = path.join(actpDir, 'keystore.json');
261
+
262
+ if (process.env.ACTP_KEYSTORE_BASE64) {
263
+ return { name, result: 'PASS' };
264
+ }
265
+
266
+ if (fs.existsSync(keystorePath)) {
267
+ return { name, result: 'PASS' };
268
+ }
269
+
270
+ return { name, result: 'WARN', message: 'ACTP_KEYSTORE_BASE64 not set (OK for local dev)' };
271
+ }
272
+
273
+ function checkKeystorePermissions(actpDir: string): CheckOutput {
274
+ const name = 'Keystore file permissions';
275
+ const keystorePath = path.join(actpDir, 'keystore.json');
276
+
277
+ // Skip on Windows
278
+ if (process.platform === 'win32') {
279
+ return { name, result: 'SKIP', message: 'Permission check skipped on Windows' };
280
+ }
281
+
282
+ if (!fs.existsSync(keystorePath)) {
283
+ return { name, result: 'PASS' };
284
+ }
285
+
286
+ try {
287
+ const stat = fs.statSync(keystorePath);
288
+ const mode = stat.mode & 0o777;
289
+ if (mode === 0o600) {
290
+ return { name, result: 'PASS' };
291
+ }
292
+ return { name, result: 'WARN', message: `Permissions are 0o${mode.toString(8)} (expected 0o600)` };
293
+ } catch {
294
+ return { name, result: 'WARN', message: 'Could not check file permissions' };
295
+ }
296
+ }
297
+
298
+ // ============================================================================
299
+ // Helpers
300
+ // ============================================================================
301
+
302
+ /** Directories to skip during recursive scan */
303
+ const SKIP_DIRS = new Set(['node_modules', '.git', '.actp', 'dist', 'build', '.next', 'coverage']);
304
+
305
+ /** Max recursion depth to prevent runaway scans */
306
+ const MAX_SCAN_DEPTH = 5;
307
+
308
+ function findMatchingFiles(projectRoot: string, patterns: string[], maxDepth = MAX_SCAN_DEPTH): string[] {
309
+ const files: string[] = [];
310
+ walkDir(projectRoot, patterns, files, 0, maxDepth);
311
+ return files;
312
+ }
313
+
314
+ function walkDir(dir: string, patterns: string[], files: string[], depth: number, maxDepth: number): void {
315
+ if (depth > maxDepth) return;
316
+
317
+ let entries: string[];
318
+ try {
319
+ entries = fs.readdirSync(dir);
320
+ } catch { return; }
321
+
322
+ for (const entry of entries) {
323
+ const fullPath = path.join(dir, entry);
324
+
325
+ // Match files against patterns
326
+ for (const pattern of patterns) {
327
+ if (matchPattern(entry, pattern)) {
328
+ try {
329
+ if (fs.statSync(fullPath).isFile()) {
330
+ files.push(fullPath);
331
+ }
332
+ } catch { /* ignore */ }
333
+ break;
334
+ }
335
+ }
336
+
337
+ // Recurse into subdirectories (skip noise dirs)
338
+ if (!SKIP_DIRS.has(entry)) {
339
+ try {
340
+ if (fs.statSync(fullPath).isDirectory()) {
341
+ walkDir(fullPath, patterns, files, depth + 1, maxDepth);
342
+ }
343
+ } catch { /* ignore */ }
344
+ }
345
+ }
346
+ }
347
+
348
+ function matchPattern(filename: string, pattern: string): boolean {
349
+ // Simple glob: support * and exact match
350
+ if (pattern === filename) return true;
351
+ if (pattern.includes('*')) {
352
+ const regex = new RegExp('^' + pattern.replace(/\./g, '\\.').replace(/\*/g, '.*') + '$');
353
+ return regex.test(filename);
354
+ }
355
+ return false;
356
+ }
357
+
358
+ function safeReadFile(filePath: string): string | null {
359
+ try {
360
+ return fs.readFileSync(filePath, 'utf-8');
361
+ } catch {
362
+ return null;
363
+ }
364
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Deploy:env Command - Generate deployment environment variables (AIP-13)
3
+ *
4
+ * Reads .actp/keystore.json, base64-encodes it, and outputs env vars
5
+ * ready for any deployment platform (Railway, Vercel, Fly.io, Hetzner, etc.).
6
+ *
7
+ * @module cli/commands/deploy-env
8
+ */
9
+
10
+ import * as fs from 'fs';
11
+ import * as path from 'path';
12
+ import { Command } from 'commander';
13
+ import { Output, ExitCode } from '../utils/output';
14
+ import { getActpDir } from '../utils/config';
15
+
16
+ // ============================================================================
17
+ // Command Definition
18
+ // ============================================================================
19
+
20
+ export function createDeployEnvCommand(): Command {
21
+ const cmd = new Command('deploy:env')
22
+ .description('Generate deployment env vars from keystore (AIP-13)')
23
+ .option('--format <format>', 'Output format: shell (default), docker, json', 'shell')
24
+ .option('--json', 'Machine-readable JSON output')
25
+ .option('-q, --quiet', 'Output only the base64 string (for piping)')
26
+ .action(async (options) => {
27
+ const output = new Output(
28
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
29
+ );
30
+
31
+ try {
32
+ runDeployEnv(options, output);
33
+ } catch (error) {
34
+ output.errorResult({
35
+ code: 'DEPLOY_ENV_FAILED',
36
+ message: (error as Error).message,
37
+ });
38
+ process.exit(ExitCode.ERROR);
39
+ }
40
+ });
41
+
42
+ return cmd;
43
+ }
44
+
45
+ // ============================================================================
46
+ // Implementation
47
+ // ============================================================================
48
+
49
+ interface DeployEnvOptions {
50
+ format: string;
51
+ json?: boolean;
52
+ quiet?: boolean;
53
+ }
54
+
55
+ export function runDeployEnv(options: DeployEnvOptions, output: Output): void {
56
+ const projectRoot = process.cwd();
57
+ const actpDir = getActpDir(projectRoot);
58
+ const keystorePath = path.join(actpDir, 'keystore.json');
59
+
60
+ if (!fs.existsSync(keystorePath)) {
61
+ throw new Error(
62
+ 'No keystore found at ' + keystorePath + '\n' +
63
+ 'Run "actp init" first to generate a wallet.'
64
+ );
65
+ }
66
+
67
+ const keystoreContent = fs.readFileSync(keystorePath, 'utf-8');
68
+
69
+ // Validate it's valid JSON
70
+ try {
71
+ JSON.parse(keystoreContent);
72
+ } catch {
73
+ throw new Error('Keystore file is corrupted (not valid JSON).');
74
+ }
75
+
76
+ const base64 = Buffer.from(keystoreContent).toString('base64');
77
+
78
+ // Quiet mode: just the base64 string (for piping)
79
+ if (options.quiet) {
80
+ output.result({ keystoreBase64: base64 }, { quietKey: 'keystoreBase64' });
81
+ return;
82
+ }
83
+
84
+ // JSON mode
85
+ if (options.json || options.format === 'json') {
86
+ output.result({
87
+ keystoreBase64: base64,
88
+ passwordVar: 'ACTP_KEY_PASSWORD',
89
+ });
90
+ return;
91
+ }
92
+
93
+ // Docker format
94
+ if (options.format === 'docker') {
95
+ output.print('# Add to your Dockerfile:');
96
+ output.print(`ENV ACTP_KEYSTORE_BASE64="${base64}"`);
97
+ output.print('ENV ACTP_KEY_PASSWORD="<your keystore password>"');
98
+ output.print('');
99
+ output.print('# WARNING: Prefer build args or secrets over ENV for sensitive values.');
100
+ return;
101
+ }
102
+
103
+ // Shell format (default)
104
+ output.print('# Set these environment variables on your deployment platform:');
105
+ output.print(`ACTP_KEYSTORE_BASE64=${base64}`);
106
+ output.print('ACTP_KEY_PASSWORD=<your keystore password>');
107
+ output.print('');
108
+ output.print('# SECURITY BEST PRACTICE:');
109
+ output.print('# Store ACTP_KEYSTORE_BASE64 and ACTP_KEY_PASSWORD in SEPARATE secret scopes');
110
+ output.print('# where your platform supports it (e.g., different secret groups, vaults, or teams).');
111
+ output.print('# This preserves the two-factor security model.');
112
+ output.print('#');
113
+ output.print('# WARNING: Never echo these values in CI/CD logs or commit them to git.');
114
+ output.print('');
115
+ output.print('# Platform-specific examples:');
116
+ output.print(`# Railway: railway variables set ACTP_KEYSTORE_BASE64="${base64}"`);
117
+ output.print('# Vercel: vercel env add ACTP_KEYSTORE_BASE64');
118
+ output.print(`# Fly.io: fly secrets set ACTP_KEYSTORE_BASE64="${base64}"`);
119
+ output.print('# Hetzner: Add to your .env on the server (ensure .env is in .gitignore)');
120
+ }
@@ -14,6 +14,8 @@ import { Command } from 'commander';
14
14
  import {
15
15
  saveConfig,
16
16
  addToGitignore,
17
+ addToDockerignore,
18
+ addToRailwayignore,
17
19
  isInitialized,
18
20
  getActpDir,
19
21
  CLIConfig,
@@ -236,13 +238,25 @@ async function runInit(options: InitOptions, output: Output, cmd?: Command): Pro
236
238
  output.info('Minted 10,000 USDC to your address');
237
239
  }
238
240
 
239
- // Add to gitignore
241
+ // Add to ignore files (AIP-13: gitignore + dockerignore + railwayignore)
240
242
  try {
241
243
  addToGitignore(projectRoot);
242
244
  output.success('Added .actp/ to .gitignore');
243
245
  } catch {
244
246
  output.warning('Could not update .gitignore (may not exist)');
245
247
  }
248
+ try {
249
+ addToDockerignore(projectRoot);
250
+ output.success('Added .actp/ to .dockerignore');
251
+ } catch {
252
+ output.warning('Could not update .dockerignore');
253
+ }
254
+ try {
255
+ addToRailwayignore(projectRoot);
256
+ output.success('Added .actp/ to .railwayignore');
257
+ } catch {
258
+ output.warning('Could not update .railwayignore');
259
+ }
246
260
 
247
261
  // Output result
248
262
  output.blank();
@@ -394,7 +394,7 @@ async function activateOnTestnet(
394
394
  const { buildActivationBatch, buildTestnetMintBatch } = await import('../../wallet/aa/TransactionBatcher');
395
395
  const { getOnChainAgentState, detectLazyPublishScenario } = await import('../../ACTPClient');
396
396
 
397
- const privateKey = await resolvePrivateKey(projectRoot);
397
+ const privateKey = await resolvePrivateKey(projectRoot, { network: 'testnet' });
398
398
  if (!privateKey) {
399
399
  throw new Error('No wallet found. Cannot activate on testnet.');
400
400
  }
@@ -85,7 +85,7 @@ async function runRegister(
85
85
  }
86
86
 
87
87
  // Resolve private key
88
- const privateKey = await resolvePrivateKey(projectRoot);
88
+ const privateKey = await resolvePrivateKey(projectRoot, { network: config.mode });
89
89
  if (!privateKey) {
90
90
  throw new Error(
91
91
  'No wallet found. Run "actp init" first to generate a wallet.'
package/src/cli/index.ts CHANGED
@@ -52,6 +52,8 @@ import { createPublishCommand } from './commands/publish';
52
52
  import { createPullCommand } from './commands/pull';
53
53
  import { createDiffCommand } from './commands/diff';
54
54
  import { createRegisterCommand } from './commands/register';
55
+ import { createDeployEnvCommand } from './commands/deploy-env';
56
+ import { createDeployCheckCommand } from './commands/deploy-check';
55
57
 
56
58
  // ============================================================================
57
59
  // Program Setup
@@ -104,6 +106,10 @@ program.addCommand(createDiffCommand());
104
106
  // AIP-12: Gas-free registration
105
107
  program.addCommand(createRegisterCommand());
106
108
 
109
+ // AIP-13: Deployment security
110
+ program.addCommand(createDeployEnvCommand());
111
+ program.addCommand(createDeployCheckCommand());
112
+
107
113
  // ============================================================================
108
114
  // Error Handling
109
115
  // ============================================================================
@@ -11,7 +11,7 @@
11
11
 
12
12
  import * as os from 'os';
13
13
  import { ACTPClient, ACTPClientConfig } from '../../ACTPClient';
14
- import { loadConfig, validateConfigForMode } from './config';
14
+ import { loadConfig } from './config';
15
15
 
16
16
  // ============================================================================
17
17
  // Security: Path Sanitization
@@ -54,8 +54,10 @@ export async function createClient(
54
54
  // Load configuration
55
55
  const config = loadConfig(projectRoot);
56
56
 
57
- // Validate config for the mode
58
- validateConfigForMode(config);
57
+ // NOTE: We intentionally do NOT call validateConfigForMode() here.
58
+ // ACTPClient.create() handles keystore resolution (AIP-13) and provides
59
+ // proper error messages if no credentials are found. Premature validation
60
+ // would block keystore/env-var-based auth flows.
59
61
 
60
62
  // Build client config
61
63
  const clientConfig: ACTPClientConfig = {
@@ -319,3 +319,71 @@ export function addToGitignore(projectRoot: string = process.cwd()): void {
319
319
 
320
320
  fs.writeFileSync(gitignorePath, newContent, 'utf-8');
321
321
  }
322
+
323
+ // ============================================================================
324
+ // Ignore File Management (AIP-13)
325
+ // ============================================================================
326
+
327
+ const IGNORE_ENTRIES = ['.actp/', '.env', '.env.*', 'node_modules/'];
328
+ const IGNORE_HEADER = '# ACTP deployment security (AIP-13)';
329
+
330
+ /**
331
+ * Validate that a file path is not a symlink.
332
+ * Throws if the path exists and is a symlink (security: prevents symlink attacks).
333
+ */
334
+ function assertNotSymlink(filePath: string): void {
335
+ try {
336
+ const stat = fs.lstatSync(filePath);
337
+ if (stat.isSymbolicLink()) {
338
+ throw new Error(
339
+ `Refusing to write ${path.basename(filePath)}: path is a symlink. Remove the symlink and retry.`
340
+ );
341
+ }
342
+ } catch (err) {
343
+ // Re-throw symlink errors; ENOENT (file doesn't exist) is fine
344
+ if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err;
345
+ }
346
+ }
347
+
348
+ /**
349
+ * Add standard ignore entries to a file (idempotent).
350
+ * Creates the file if it doesn't exist.
351
+ */
352
+ function addIgnoreEntries(filePath: string): void {
353
+ assertNotSymlink(filePath);
354
+
355
+ let content = '';
356
+ if (fs.existsSync(filePath)) {
357
+ content = fs.readFileSync(filePath, 'utf-8');
358
+ }
359
+
360
+ // Only add entries that are missing (check each individually)
361
+ const missingEntries = IGNORE_ENTRIES.filter(entry => !content.includes(entry));
362
+ if (missingEntries.length === 0) return;
363
+
364
+ const newContent =
365
+ content +
366
+ (content.length > 0 && !content.endsWith('\n') ? '\n' : '') +
367
+ IGNORE_HEADER + '\n' +
368
+ missingEntries.join('\n') + '\n';
369
+
370
+ fs.writeFileSync(filePath, newContent, 'utf-8');
371
+ }
372
+
373
+ /**
374
+ * Add .actp/ and related entries to .dockerignore (AIP-13).
375
+ * Creates the file if it doesn't exist. Idempotent.
376
+ * Throws if .dockerignore is a symlink.
377
+ */
378
+ export function addToDockerignore(projectRoot: string = process.cwd()): void {
379
+ addIgnoreEntries(path.join(projectRoot, '.dockerignore'));
380
+ }
381
+
382
+ /**
383
+ * Add .actp/ and related entries to .railwayignore (AIP-13).
384
+ * Creates the file if it doesn't exist. Idempotent.
385
+ * Throws if .railwayignore is a symlink.
386
+ */
387
+ export function addToRailwayignore(projectRoot: string = process.cwd()): void {
388
+ addIgnoreEntries(path.join(projectRoot, '.railwayignore'));
389
+ }
@@ -320,7 +320,7 @@ async function resolveKeyIfNeeded(
320
320
  ): Promise<string | undefined> {
321
321
  if (wallet && wallet !== 'auto') return undefined; // explicit wallet, skip auto-detect
322
322
  if (network !== 'testnet' && network !== 'mainnet') return undefined;
323
- return resolvePrivateKey(stateDirectory);
323
+ return resolvePrivateKey(stateDirectory, { network });
324
324
  }
325
325
 
326
326
  /**
@@ -1391,7 +1391,7 @@ export class Agent extends EventEmitter {
1391
1391
  private async getPrivateKey(): Promise<string | undefined> {
1392
1392
  if (!this.config.wallet || this.config.wallet === 'auto') {
1393
1393
  if (this.network === 'testnet' || this.network === 'mainnet') {
1394
- return resolvePrivateKey(this.config.stateDirectory);
1394
+ return resolvePrivateKey(this.config.stateDirectory, { network: this.network });
1395
1395
  }
1396
1396
  return undefined;
1397
1397
  }