@vainplex/shieldapi-cli 1.2.0 → 1.2.1

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.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Security intelligence from your terminal. Pay-per-request with USDC.",
5
5
  "type": "module",
6
6
  "bin": {
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.2.0')
17
+ .version('1.2.1')
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 {{ client: object }|null} options.wallet - Wallet with viem client
10
+ * @param {{ signer: object }|null} options.wallet - Wallet with x402 ClientEvmSigner
11
11
  * @returns {Promise<object>} Parsed JSON response
12
12
  */
13
13
  export async function apiRequest(endpoint, params = {}, { demo = false, wallet = null } = {}) {
@@ -28,8 +28,8 @@ export async function apiRequest(endpoint, params = {}, { demo = false, wallet =
28
28
  return res.json();
29
29
  }
30
30
 
31
- // Paid endpoint — need wallet
32
- if (!wallet?.client) {
31
+ // Paid endpoint — need wallet with signer
32
+ if (!wallet?.signer) {
33
33
  throw new Error(
34
34
  'No wallet configured. Use --wallet <key> or set SHIELDAPI_WALLET_KEY environment variable.'
35
35
  );
@@ -41,8 +41,9 @@ export async function apiRequest(endpoint, params = {}, { demo = false, wallet =
41
41
  const { wrapFetchWithPayment } = await import('@x402/fetch');
42
42
 
43
43
  // Create x402 client with EVM scheme registered
44
+ // wallet.signer is a ClientEvmSigner (from toClientEvmSigner) with .address + .signTypedData + .readContract
44
45
  const client = new x402Client();
45
- registerExactEvmScheme(client, { signer: wallet.client });
46
+ registerExactEvmScheme(client, { signer: wallet.signer });
46
47
 
47
48
  // Wrap fetch with x402 payment handling
48
49
  const paidFetch = wrapFetchWithPayment(fetch, client);
package/src/lib/wallet.js CHANGED
@@ -1,13 +1,17 @@
1
- import { createWalletClient, http, publicActions } from 'viem';
1
+ import { createWalletClient, createPublicClient, http } from 'viem';
2
2
  import { privateKeyToAccount } from 'viem/accounts';
3
3
  import { base } from 'viem/chains';
4
+ import { toClientEvmSigner } from '@x402/evm';
4
5
 
5
6
  /**
6
- * Create a viem wallet client from a private key.
7
- * Returns a wallet client with publicActions (needed for readContract in x402).
7
+ * Create a wallet + x402-compatible signer from a private key.
8
+ *
9
+ * Uses toClientEvmSigner to compose an account (for signing) with
10
+ * a publicClient (for readContract), producing a ClientEvmSigner
11
+ * that has both `.address` and `.signTypedData` + `.readContract`.
8
12
  *
9
13
  * @param {string} privateKey - Hex private key (with or without 0x prefix)
10
- * @returns {{ client: import('viem').WalletClient, address: string }}
14
+ * @returns {{ signer: object, address: string }}
11
15
  */
12
16
  export function createWallet(privateKey) {
13
17
  if (!privateKey) return null;
@@ -16,23 +20,26 @@ export function createWallet(privateKey) {
16
20
 
17
21
  try {
18
22
  const account = privateKeyToAccount(key);
19
- const client = createWalletClient({
20
- account,
23
+ const publicClient = createPublicClient({
21
24
  chain: base,
22
25
  transport: http(),
23
- }).extend(publicActions);
26
+ });
27
+
28
+ // toClientEvmSigner composes account.signTypedData + publicClient.readContract
29
+ // and exposes .address correctly
30
+ const signer = toClientEvmSigner(account, publicClient);
24
31
 
25
- return { client, address: account.address };
32
+ return { signer, address: account.address };
26
33
  } catch (err) {
27
34
  throw new Error(`Invalid private key: ${err.message}`);
28
35
  }
29
36
  }
30
37
 
31
38
  /**
32
- * Resolve wallet client from CLI option or environment variable.
39
+ * Resolve wallet/signer from CLI option or environment variable.
33
40
  *
34
41
  * @param {object} opts - Commander options
35
- * @returns {{ client: object, address: string }|null}
42
+ * @returns {{ signer: object, address: string }|null}
36
43
  */
37
44
  export function resolveWallet(opts) {
38
45
  const key = opts?.wallet || process.env.SHIELDAPI_WALLET_KEY;