@vainplex/shieldapi-cli 1.1.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vainplex/shieldapi-cli",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Security intelligence from your terminal. Pay-per-request with USDC.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -33,6 +33,7 @@
33
33
  },
34
34
  "homepage": "https://shield.vainplex.dev",
35
35
  "dependencies": {
36
+ "@x402/core": "^2.5.0",
36
37
  "@x402/evm": "^2.5.0",
37
38
  "@x402/fetch": "^2.5.0",
38
39
  "chalk": "^5.3.0",
@@ -17,7 +17,6 @@ function readStdin() {
17
17
  rl.on('line', (line) => { data = line; rl.close(); });
18
18
  rl.on('close', () => resolve(data.trim()));
19
19
  rl.on('error', reject);
20
- // Timeout after 10s
21
20
  setTimeout(() => { rl.close(); reject(new Error('Stdin timeout — no input received')); }, 10000);
22
21
  });
23
22
  }
@@ -27,6 +26,8 @@ function readStdin() {
27
26
  * Hashes locally with SHA-1, sends hash to API.
28
27
  */
29
28
  export async function passwordCommand(password, opts) {
29
+ let spinner = null;
30
+
30
31
  try {
31
32
  let hash;
32
33
 
@@ -62,7 +63,7 @@ export async function passwordCommand(password, opts) {
62
63
  }
63
64
  }
64
65
 
65
- const spinner = opts.quiet ? null : ora({ text: 'Checking password...', stream: process.stderr }).start();
66
+ spinner = opts.quiet ? null : ora({ text: 'Checking password...', stream: process.stderr }).start();
66
67
  const wallet = opts.demo ? null : resolveWallet(opts);
67
68
 
68
69
  const data = await apiRequest('check-password', { hash }, {
@@ -80,7 +81,7 @@ export async function passwordCommand(password, opts) {
80
81
 
81
82
  process.exitCode = exitCodeFromResult(data);
82
83
  } catch (err) {
83
- if (!opts.quiet) process.stderr.write(chalk.red(`✖ ${err.message}\n`));
84
+ spinner?.fail(err.message);
84
85
  process.exitCode = exitCodeFromError(err);
85
86
  }
86
87
  }
package/src/index.js CHANGED
@@ -14,7 +14,7 @@ export function run(argv) {
14
14
  program
15
15
  .name('shieldapi')
16
16
  .description('🛡️ ShieldAPI CLI — Security intelligence from your terminal. Pay-per-request with USDC.')
17
- .version('1.1.0')
17
+ .version('1.2.0')
18
18
  .option('--wallet <key>', 'Private key for x402 payments (or set SHIELDAPI_WALLET_KEY)')
19
19
  .option('--json', 'Output raw JSON instead of formatted output')
20
20
  .option('--no-color', 'Disable colors')
package/src/lib/api.js CHANGED
@@ -7,7 +7,7 @@ const BASE_URL = 'https://shield.vainplex.dev/api';
7
7
  * @param {Record<string, string>} params - Query parameters
8
8
  * @param {object} options
9
9
  * @param {boolean} options.demo - Use demo mode
10
- * @param {{ signer: object }|null} options.wallet - Wallet with x402 signer
10
+ * @param {{ client: object }|null} options.wallet - Wallet with viem client
11
11
  * @returns {Promise<object>} Parsed JSON response
12
12
  */
13
13
  export async function apiRequest(endpoint, params = {}, { demo = false, wallet = null } = {}) {
@@ -28,16 +28,24 @@ export async function apiRequest(endpoint, params = {}, { demo = false, wallet =
28
28
  return res.json();
29
29
  }
30
30
 
31
- // Paid endpoint — need wallet with signer
32
- if (!wallet?.signer) {
31
+ // Paid endpoint — need wallet
32
+ if (!wallet?.client) {
33
33
  throw new Error(
34
34
  'No wallet configured. Use --wallet <key> or set SHIELDAPI_WALLET_KEY environment variable.'
35
35
  );
36
36
  }
37
37
 
38
- // Dynamic import to keep startup fast when not needed
38
+ // Dynamic imports to keep startup fast (PR-2: lazy loading)
39
+ const { x402Client } = await import('@x402/core/client');
40
+ const { registerExactEvmScheme } = await import('@x402/evm/exact/client');
39
41
  const { wrapFetchWithPayment } = await import('@x402/fetch');
40
- const paidFetch = wrapFetchWithPayment(fetch, wallet.signer);
42
+
43
+ // Create x402 client with EVM scheme registered
44
+ const client = new x402Client();
45
+ registerExactEvmScheme(client, { signer: wallet.client });
46
+
47
+ // Wrap fetch with x402 payment handling
48
+ const paidFetch = wrapFetchWithPayment(fetch, client);
41
49
 
42
50
  const res = await paidFetch(url);
43
51
 
package/src/lib/wallet.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { createWalletClient, http, publicActions } from 'viem';
2
2
  import { privateKeyToAccount } from 'viem/accounts';
3
3
  import { base } from 'viem/chains';
4
- import { toClientEvmSigner } from '@x402/evm';
5
4
 
6
5
  /**
7
- * Create a viem wallet client + x402 signer from a private key.
6
+ * Create a viem wallet client from a private key.
7
+ * Returns a wallet client with publicActions (needed for readContract in x402).
8
8
  *
9
9
  * @param {string} privateKey - Hex private key (with or without 0x prefix)
10
- * @returns {{ client: import('viem').WalletClient, signer: object }}
10
+ * @returns {{ client: import('viem').WalletClient, address: string }}
11
11
  */
12
12
  export function createWallet(privateKey) {
13
13
  if (!privateKey) return null;
@@ -22,19 +22,17 @@ export function createWallet(privateKey) {
22
22
  transport: http(),
23
23
  }).extend(publicActions);
24
24
 
25
- const signer = toClientEvmSigner(client);
26
-
27
- return { client, signer, address: account.address };
25
+ return { client, address: account.address };
28
26
  } catch (err) {
29
27
  throw new Error(`Invalid private key: ${err.message}`);
30
28
  }
31
29
  }
32
30
 
33
31
  /**
34
- * Resolve wallet/signer from CLI option or environment variable.
32
+ * Resolve wallet client from CLI option or environment variable.
35
33
  *
36
34
  * @param {object} opts - Commander options
37
- * @returns {{ signer: object, address: string }|null}
35
+ * @returns {{ client: object, address: string }|null}
38
36
  */
39
37
  export function resolveWallet(opts) {
40
38
  const key = opts?.wallet || process.env.SHIELDAPI_WALLET_KEY;