httpcat-cli 0.0.22 → 0.0.25

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.
@@ -0,0 +1,134 @@
1
+ import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@scure/bip39';
2
+ import { wordlist } from '@scure/bip39/wordlists/english.js';
3
+ import { HDKey } from '@scure/bip32';
4
+ import { randomBytes, createCipheriv, createDecipheriv, pbkdf2Sync } from 'crypto';
5
+ import { privateKeyToAccount } from 'viem/accounts';
6
+ const PBKDF2_ITERATIONS = 100000;
7
+ const SALT_LENGTH = 32;
8
+ const IV_LENGTH = 16;
9
+ const KEY_LENGTH = 32; // AES-256
10
+ /**
11
+ * Generate a BIP-39 seed phrase
12
+ * @param wordCount - Number of words (12 or 24)
13
+ * @returns Seed phrase as space-separated words
14
+ */
15
+ export function generateSeedPhrase(wordCount = 12) {
16
+ const strength = wordCount === 12 ? 128 : 256;
17
+ return generateMnemonic(wordlist, strength);
18
+ }
19
+ /**
20
+ * Validate a BIP-39 seed phrase
21
+ * @param phrase - Seed phrase to validate
22
+ * @returns True if valid
23
+ */
24
+ export function validateSeedPhrase(phrase) {
25
+ return validateMnemonic(phrase, wordlist);
26
+ }
27
+ /**
28
+ * Derive a private key from a seed phrase using BIP-32/BIP-44
29
+ * @param seedPhrase - BIP-39 seed phrase
30
+ * @param index - Account index (default 0)
31
+ * @returns Private key as Hex
32
+ */
33
+ export function seedPhraseToPrivateKey(seedPhrase, index = 0) {
34
+ if (!validateSeedPhrase(seedPhrase)) {
35
+ throw new Error('Invalid seed phrase');
36
+ }
37
+ // Convert mnemonic to seed
38
+ const seed = mnemonicToSeedSync(seedPhrase);
39
+ // Create HD key from seed
40
+ const hdKey = HDKey.fromMasterSeed(seed);
41
+ // Derive using BIP-44 path: m/44'/60'/0'/0/index
42
+ // 44' = BIP-44
43
+ // 60' = Ethereum coin type
44
+ // 0' = Account
45
+ // 0 = Change (external addresses)
46
+ // index = Address index
47
+ const derived = hdKey.derive(`m/44'/60'/0'/0/${index}`);
48
+ if (!derived.privateKey) {
49
+ throw new Error('Failed to derive private key from seed phrase');
50
+ }
51
+ // Convert to hex with 0x prefix
52
+ return `0x${Buffer.from(derived.privateKey).toString('hex')}`;
53
+ }
54
+ /**
55
+ * Derive key from password using PBKDF2
56
+ * @param password - Password string
57
+ * @param salt - Salt buffer
58
+ * @returns Derived key buffer
59
+ */
60
+ function deriveKeyFromPassword(password, salt) {
61
+ return pbkdf2Sync(password, salt, PBKDF2_ITERATIONS, KEY_LENGTH, 'sha256');
62
+ }
63
+ /**
64
+ * Encrypt data using AES-256-GCM
65
+ * @param data - Data to encrypt (plain text)
66
+ * @param password - Password for encryption
67
+ * @returns Encrypted data as base64 string (format: salt:iv:encrypted:authTag)
68
+ */
69
+ export function encryptData(data, password) {
70
+ if (!password) {
71
+ throw new Error('Password is required for encryption');
72
+ }
73
+ // Generate random salt and IV
74
+ const salt = randomBytes(SALT_LENGTH);
75
+ const iv = randomBytes(IV_LENGTH);
76
+ // Derive key from password
77
+ const key = deriveKeyFromPassword(password, salt);
78
+ // Create cipher
79
+ const cipher = createCipheriv('aes-256-gcm', key, iv);
80
+ // Encrypt
81
+ let encrypted = cipher.update(data, 'utf8');
82
+ encrypted = Buffer.concat([encrypted, cipher.final()]);
83
+ // Get auth tag
84
+ const authTag = cipher.getAuthTag();
85
+ // Combine: salt:iv:encrypted:authTag (all base64)
86
+ const result = [
87
+ salt.toString('base64'),
88
+ iv.toString('base64'),
89
+ encrypted.toString('base64'),
90
+ authTag.toString('base64'),
91
+ ].join(':');
92
+ return result;
93
+ }
94
+ /**
95
+ * Decrypt data using AES-256-GCM
96
+ * @param encryptedData - Encrypted data as base64 string (format: salt:iv:encrypted:authTag)
97
+ * @param password - Password for decryption
98
+ * @returns Decrypted data (plain text)
99
+ */
100
+ export function decryptData(encryptedData, password) {
101
+ if (!password) {
102
+ throw new Error('Password is required for decryption');
103
+ }
104
+ // Split encrypted data
105
+ const parts = encryptedData.split(':');
106
+ if (parts.length !== 4) {
107
+ throw new Error('Invalid encrypted data format');
108
+ }
109
+ const [saltB64, ivB64, encryptedB64, authTagB64] = parts;
110
+ // Decode from base64
111
+ const salt = Buffer.from(saltB64, 'base64');
112
+ const iv = Buffer.from(ivB64, 'base64');
113
+ const encrypted = Buffer.from(encryptedB64, 'base64');
114
+ const authTag = Buffer.from(authTagB64, 'base64');
115
+ // Derive key from password
116
+ const key = deriveKeyFromPassword(password, salt);
117
+ // Create decipher
118
+ const decipher = createDecipheriv('aes-256-gcm', key, iv);
119
+ decipher.setAuthTag(authTag);
120
+ // Decrypt
121
+ let decrypted = decipher.update(encrypted);
122
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
123
+ return decrypted.toString('utf8');
124
+ }
125
+ /**
126
+ * Get address from private key
127
+ * @param privateKey - Private key as Hex
128
+ * @returns Ethereum address
129
+ */
130
+ export function getAddressFromPrivateKey(privateKey) {
131
+ const account = privateKeyToAccount(privateKey);
132
+ return account.address;
133
+ }
134
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/utils/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAc,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,UA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C,OAAO,CAAC;AACxB,CAAC"}
@@ -1,8 +1,8 @@
1
1
  class Httpcat < Formula
2
2
  desc "CLI tool for interacting with httpcat agent - create, buy, and sell tokens with x402 payments"
3
3
  homepage "https://github.com/hathbanger/httpcat-cli"
4
- url "https://registry.npmjs.org/httpcat-cli/-/httpcat-cli-0.0.21.tgz"
5
- sha256 "ae2c316c466df93cdc6f5a21729b4b2b68473df15f08e02a97ab6e917fae190d"
4
+ url "https://registry.npmjs.org/httpcat-cli/-/httpcat-cli-0.0.23.tgz"
5
+ sha256 "9e340aaf557a6f359e8a4525e7891373b098eb297a32af3a8577b6c648f6051a"
6
6
  license "MIT"
7
7
 
8
8
  depends_on "node"
@@ -13,6 +13,6 @@ class Httpcat < Formula
13
13
  end
14
14
 
15
15
  test do
16
- assert_match "0.0.21", shell_output("#{bin}/httpcat --version")
16
+ assert_match "0.0.23", shell_output("#{bin}/httpcat --version")
17
17
  end
18
18
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "httpcat-cli",
3
- "version": "0.0.22",
3
+ "version": "0.0.25",
4
4
  "description": "CLI tool for interacting with httpcat agent - create, buy, and sell tokens with x402 payments",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -39,6 +39,8 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@modelcontextprotocol/sdk": "^1.23.0",
42
+ "@scure/bip32": "^2.0.1",
43
+ "@scure/bip39": "^2.0.1",
42
44
  "chalk": "^5.3.0",
43
45
  "cli-table3": "^0.6.3",
44
46
  "commander": "^11.1.0",
@@ -53,12 +55,12 @@
53
55
  "zod": "^4.1.13"
54
56
  },
55
57
  "devDependencies": {
58
+ "@jest/globals": "^29.7.0",
56
59
  "@types/blessed": "^0.1.26",
57
60
  "@types/inquirer": "^9.0.7",
58
61
  "@types/jest": "^29.5.12",
59
62
  "@types/node": "^20.10.0",
60
63
  "@types/ws": "^8.5.13",
61
- "@jest/globals": "^29.7.0",
62
64
  "jest": "^29.7.0",
63
65
  "ts-jest": "^29.1.2",
64
66
  "typescript": "^5.3.3"