@vainplex/shieldapi-cli 1.1.1 → 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 +2 -1
- package/src/index.js +1 -1
- package/src/lib/api.js +12 -3
- package/src/lib/wallet.js +13 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vainplex/shieldapi-cli",
|
|
3
|
-
"version": "1.
|
|
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": {
|
|
@@ -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",
|
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.
|
|
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 {{ signer: object }|null} options.wallet - Wallet with x402
|
|
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 } = {}) {
|
|
@@ -35,9 +35,18 @@ export async function apiRequest(endpoint, params = {}, { demo = false, wallet =
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// Dynamic
|
|
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
|
-
|
|
42
|
+
|
|
43
|
+
// Create x402 client with EVM scheme registered
|
|
44
|
+
// wallet.signer is a ClientEvmSigner (from toClientEvmSigner) with .address + .signTypedData + .readContract
|
|
45
|
+
const client = new x402Client();
|
|
46
|
+
registerExactEvmScheme(client, { signer: wallet.signer });
|
|
47
|
+
|
|
48
|
+
// Wrap fetch with x402 payment handling
|
|
49
|
+
const paidFetch = wrapFetchWithPayment(fetch, client);
|
|
41
50
|
|
|
42
51
|
const res = await paidFetch(url);
|
|
43
52
|
|
package/src/lib/wallet.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { createWalletClient,
|
|
1
|
+
import { createWalletClient, createPublicClient, http } from 'viem';
|
|
2
2
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
3
3
|
import { base } from 'viem/chains';
|
|
4
4
|
import { toClientEvmSigner } from '@x402/evm';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Create a
|
|
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 {{
|
|
14
|
+
* @returns {{ signer: object, address: string }}
|
|
11
15
|
*/
|
|
12
16
|
export function createWallet(privateKey) {
|
|
13
17
|
if (!privateKey) return null;
|
|
@@ -16,15 +20,16 @@ export function createWallet(privateKey) {
|
|
|
16
20
|
|
|
17
21
|
try {
|
|
18
22
|
const account = privateKeyToAccount(key);
|
|
19
|
-
const
|
|
20
|
-
account,
|
|
23
|
+
const publicClient = createPublicClient({
|
|
21
24
|
chain: base,
|
|
22
25
|
transport: http(),
|
|
23
|
-
})
|
|
26
|
+
});
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
// toClientEvmSigner composes account.signTypedData + publicClient.readContract
|
|
29
|
+
// and exposes .address correctly
|
|
30
|
+
const signer = toClientEvmSigner(account, publicClient);
|
|
26
31
|
|
|
27
|
-
return {
|
|
32
|
+
return { signer, address: account.address };
|
|
28
33
|
} catch (err) {
|
|
29
34
|
throw new Error(`Invalid private key: ${err.message}`);
|
|
30
35
|
}
|