@paytaca/opencode-plugin 0.1.4 → 0.1.6
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/dist/proxy.js +47 -2
- package/dist/wallet.js +93 -32
- package/package.json +1 -1
- package/src/proxy.ts +50 -3
- package/src/wallet.ts +99 -34
- package/dist/package.json +0 -43
package/dist/proxy.js
CHANGED
|
@@ -48,10 +48,55 @@ const proxy_1 = require("./bundled/proxy");
|
|
|
48
48
|
const wrapper_1 = require("./bundled/wrapper");
|
|
49
49
|
// Store heartbeat interval reference
|
|
50
50
|
let heartbeatInterval = null;
|
|
51
|
-
// Get path to
|
|
51
|
+
// Get path to paytaca binary (multi-strategy resolution)
|
|
52
52
|
function getPaytacaCommand() {
|
|
53
|
+
// Priority 1: Local node_modules (via require.resolve)
|
|
54
|
+
try {
|
|
55
|
+
const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
|
|
56
|
+
return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
|
|
57
|
+
}
|
|
58
|
+
catch { }
|
|
59
|
+
// Priority 2: Local .bin symlink
|
|
53
60
|
const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
|
|
54
|
-
|
|
61
|
+
if (fs.existsSync(localPaytaca)) {
|
|
62
|
+
return localPaytaca;
|
|
63
|
+
}
|
|
64
|
+
// Priority 3: Global npm root
|
|
65
|
+
try {
|
|
66
|
+
const globalRoot = (0, child_process_1.execSync)('npm root -g', { encoding: 'utf8' }).trim();
|
|
67
|
+
const pathsToCheck = [
|
|
68
|
+
path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js'),
|
|
69
|
+
path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js'),
|
|
70
|
+
];
|
|
71
|
+
for (const p of pathsToCheck) {
|
|
72
|
+
if (fs.existsSync(p)) {
|
|
73
|
+
return p;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch { }
|
|
78
|
+
// Priority 4: Common global installation paths
|
|
79
|
+
const commonPaths = [
|
|
80
|
+
'/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
81
|
+
'/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
82
|
+
'/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
83
|
+
];
|
|
84
|
+
for (const p of commonPaths) {
|
|
85
|
+
if (fs.existsSync(p)) {
|
|
86
|
+
return p;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Priority 5: which/where on PATH
|
|
90
|
+
try {
|
|
91
|
+
const which = process.platform === 'win32' ? 'where' : 'which';
|
|
92
|
+
const result = (0, child_process_1.execSync)(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
|
|
93
|
+
if (result) {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch { }
|
|
98
|
+
// Priority 6: Bare command (rely on PATH at runtime)
|
|
99
|
+
return 'paytaca';
|
|
55
100
|
}
|
|
56
101
|
async function isPortAvailable(port) {
|
|
57
102
|
return new Promise((resolve) => {
|
package/dist/wallet.js
CHANGED
|
@@ -42,20 +42,65 @@ exports.importWallet = importWallet;
|
|
|
42
42
|
exports.extractWalletHash = extractWalletHash;
|
|
43
43
|
exports.getReceivingAddress = getReceivingAddress;
|
|
44
44
|
exports.getWalletBalance = getWalletBalance;
|
|
45
|
+
const child_process_1 = require("child_process");
|
|
45
46
|
const fs = __importStar(require("fs"));
|
|
47
|
+
const os = __importStar(require("os"));
|
|
46
48
|
const util_1 = require("util");
|
|
47
49
|
const path = __importStar(require("path"));
|
|
48
50
|
const execAsync = (0, util_1.promisify)(require('child_process').exec);
|
|
51
|
+
function getGlobalNpmRoot() {
|
|
52
|
+
try {
|
|
53
|
+
return (0, child_process_1.execSync)('npm root -g', { encoding: 'utf8' }).trim();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
49
59
|
function getPaytacaCommand() {
|
|
60
|
+
// Priority 1: Local node_modules (via require.resolve)
|
|
50
61
|
try {
|
|
51
62
|
const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
|
|
52
63
|
return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
|
|
53
64
|
}
|
|
54
65
|
catch { }
|
|
66
|
+
// Priority 2: Local .bin symlink
|
|
55
67
|
const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
|
|
56
68
|
if (fs.existsSync(localPaytaca)) {
|
|
57
69
|
return localPaytaca;
|
|
58
70
|
}
|
|
71
|
+
// Priority 3: Global npm root
|
|
72
|
+
const globalRoot = getGlobalNpmRoot();
|
|
73
|
+
if (globalRoot) {
|
|
74
|
+
const globalPaytaca = path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js');
|
|
75
|
+
if (fs.existsSync(globalPaytaca)) {
|
|
76
|
+
return globalPaytaca;
|
|
77
|
+
}
|
|
78
|
+
const scopedPaytaca = path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js');
|
|
79
|
+
if (fs.existsSync(scopedPaytaca)) {
|
|
80
|
+
return scopedPaytaca;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Priority 4: Common global installation paths
|
|
84
|
+
const commonPaths = [
|
|
85
|
+
'/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
86
|
+
'/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
87
|
+
'/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
88
|
+
];
|
|
89
|
+
for (const p of commonPaths) {
|
|
90
|
+
if (fs.existsSync(p)) {
|
|
91
|
+
return p;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Priority 5: which/where on PATH
|
|
95
|
+
try {
|
|
96
|
+
const which = process.platform === 'win32' ? 'where' : 'which';
|
|
97
|
+
const result = (0, child_process_1.execSync)(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
|
|
98
|
+
if (result) {
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch { }
|
|
103
|
+
// Priority 6: Bare command (rely on PATH at runtime)
|
|
59
104
|
return 'paytaca';
|
|
60
105
|
}
|
|
61
106
|
const PAYTACA_CMD = getPaytacaCommand();
|
|
@@ -88,19 +133,47 @@ async function checkWallet() {
|
|
|
88
133
|
};
|
|
89
134
|
}
|
|
90
135
|
}
|
|
136
|
+
function addToPath(dir) {
|
|
137
|
+
if (dir && fs.existsSync(dir) && !process.env.PATH?.includes(dir)) {
|
|
138
|
+
process.env.PATH = `${dir}${path.delimiter}${process.env.PATH}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
91
141
|
function ensurePaytacaOnPath() {
|
|
142
|
+
// Priority 1: Local node_modules .bin dir
|
|
92
143
|
try {
|
|
93
144
|
const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
|
|
94
145
|
const binDir = path.resolve(path.dirname(paytacaCliPkg), '..', '.bin');
|
|
95
146
|
const paytacaBin = path.join(binDir, 'paytaca');
|
|
96
147
|
if (fs.existsSync(paytacaBin)) {
|
|
97
|
-
|
|
98
|
-
process.env.PATH = `${binDir}${path.delimiter}${process.env.PATH}`;
|
|
99
|
-
}
|
|
148
|
+
addToPath(binDir);
|
|
100
149
|
return binDir;
|
|
101
150
|
}
|
|
102
151
|
}
|
|
103
152
|
catch { }
|
|
153
|
+
// Priority 2: Global npm root .bin dir
|
|
154
|
+
const globalRoot = getGlobalNpmRoot();
|
|
155
|
+
if (globalRoot) {
|
|
156
|
+
const globalBinDir = path.resolve(globalRoot, '..', '.bin');
|
|
157
|
+
const globalPaytaca = path.join(globalBinDir, 'paytaca');
|
|
158
|
+
if (fs.existsSync(globalPaytaca)) {
|
|
159
|
+
addToPath(globalBinDir);
|
|
160
|
+
return globalBinDir;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Priority 3: Common global bin directories
|
|
164
|
+
const commonBinDirs = [
|
|
165
|
+
'/usr/local/bin',
|
|
166
|
+
'/usr/bin',
|
|
167
|
+
path.join(os.homedir(), '.npm-global', 'bin'),
|
|
168
|
+
process.env.NVM_BIN,
|
|
169
|
+
].filter((p) => !!p);
|
|
170
|
+
for (const binDir of commonBinDirs) {
|
|
171
|
+
const paytacaBin = path.join(binDir, 'paytaca');
|
|
172
|
+
if (fs.existsSync(paytacaBin)) {
|
|
173
|
+
addToPath(binDir);
|
|
174
|
+
return binDir;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
104
177
|
return null;
|
|
105
178
|
}
|
|
106
179
|
async function checkPaytacaCli() {
|
|
@@ -116,44 +189,32 @@ async function createWallet() {
|
|
|
116
189
|
try {
|
|
117
190
|
// Generate a new wallet using paytaca CLI
|
|
118
191
|
// This will create a wallet and display the mnemonic
|
|
119
|
-
const { stdout, stderr } = await execAsync(`"${PAYTACA_CMD}" wallet create
|
|
192
|
+
const { stdout, stderr } = await execAsync(`"${PAYTACA_CMD}" wallet create`);
|
|
120
193
|
let output = stdout.toString();
|
|
121
194
|
if (!output && stderr) {
|
|
122
195
|
output = stderr.toString();
|
|
123
196
|
}
|
|
124
|
-
// Try to parse JSON output if available
|
|
125
|
-
try {
|
|
126
|
-
const jsonOutput = JSON.parse(output);
|
|
127
|
-
if (jsonOutput.mnemonic) {
|
|
128
|
-
// Show warning to user
|
|
129
|
-
console.log('\\n⚠️ IMPORTANT: Your wallet has been created!');
|
|
130
|
-
console.log('\\nSAVE THIS RECOVERY PHRASE SECURELY:');
|
|
131
|
-
console.log('═'.repeat(60));
|
|
132
|
-
console.log(jsonOutput.mnemonic);
|
|
133
|
-
console.log('═'.repeat(60));
|
|
134
|
-
console.log('\\nWithout this phrase, you CANNOT recover your funds if you');
|
|
135
|
-
console.log('lose access to this device. Write it down and store it safely.\\n');
|
|
136
|
-
return {
|
|
137
|
-
exists: true,
|
|
138
|
-
hash: jsonOutput.hash,
|
|
139
|
-
address: jsonOutput.address,
|
|
140
|
-
balance: '0 BCH',
|
|
141
|
-
mnemonic: jsonOutput.mnemonic
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
146
|
-
// Fall through to regex parsing
|
|
147
|
-
}
|
|
148
197
|
// Parse from text output
|
|
149
198
|
const hashMatch = output.match(/Wallet hash:\s*(.+)/i);
|
|
150
199
|
const addressMatch = output.match(/Address:\s*(.+)/i);
|
|
151
|
-
|
|
152
|
-
|
|
200
|
+
// Extract mnemonic from numbered seed phrase list
|
|
201
|
+
const phraseSection = output.match(/Seed phrase:\s*\n([\s\S]*?)(?=\n\s*Wallet hash)/i);
|
|
202
|
+
let mnemonic = undefined;
|
|
203
|
+
if (phraseSection) {
|
|
204
|
+
const words = [];
|
|
205
|
+
for (const line of phraseSection[1].trim().split('\n')) {
|
|
206
|
+
const m = line.match(/^\s*\d+\.\s+(\w+)/);
|
|
207
|
+
if (m)
|
|
208
|
+
words.push(m[1]);
|
|
209
|
+
}
|
|
210
|
+
if (words.length >= 12)
|
|
211
|
+
mnemonic = words.join(' ');
|
|
212
|
+
}
|
|
213
|
+
if (mnemonic) {
|
|
153
214
|
console.log('\\n⚠️ IMPORTANT: Your wallet has been created!');
|
|
154
215
|
console.log('\\nSAVE THIS RECOVERY PHRASE SECURELY:');
|
|
155
216
|
console.log('═'.repeat(60));
|
|
156
|
-
console.log(
|
|
217
|
+
console.log(mnemonic);
|
|
157
218
|
console.log('═'.repeat(60));
|
|
158
219
|
console.log('\\nWithout this phrase, you CANNOT recover your funds if you');
|
|
159
220
|
console.log('lose access to this device. Write it down and store it safely.\\n');
|
|
@@ -163,7 +224,7 @@ async function createWallet() {
|
|
|
163
224
|
hash: hashMatch ? hashMatch[1].trim() : undefined,
|
|
164
225
|
address: addressMatch ? addressMatch[1].trim() : undefined,
|
|
165
226
|
balance: '0 BCH',
|
|
166
|
-
mnemonic
|
|
227
|
+
mnemonic
|
|
167
228
|
};
|
|
168
229
|
}
|
|
169
230
|
catch (err) {
|
package/package.json
CHANGED
package/src/proxy.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import { spawn } from 'child_process';
|
|
3
|
+
import { spawn, execSync } from 'child_process';
|
|
4
4
|
import { Config, ProxyInfo } from './types';
|
|
5
5
|
import {
|
|
6
6
|
getConfigDir,
|
|
@@ -19,10 +19,57 @@ import { WRAPPER_SCRIPT_CONTENT } from './bundled/wrapper';
|
|
|
19
19
|
// Store heartbeat interval reference
|
|
20
20
|
let heartbeatInterval: NodeJS.Timeout | null = null;
|
|
21
21
|
|
|
22
|
-
// Get path to
|
|
22
|
+
// Get path to paytaca binary (multi-strategy resolution)
|
|
23
23
|
function getPaytacaCommand(): string {
|
|
24
|
+
// Priority 1: Local node_modules (via require.resolve)
|
|
25
|
+
try {
|
|
26
|
+
const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
|
|
27
|
+
return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
|
|
28
|
+
} catch {}
|
|
29
|
+
|
|
30
|
+
// Priority 2: Local .bin symlink
|
|
24
31
|
const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
|
|
25
|
-
|
|
32
|
+
if (fs.existsSync(localPaytaca)) {
|
|
33
|
+
return localPaytaca;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Priority 3: Global npm root
|
|
37
|
+
try {
|
|
38
|
+
const globalRoot = execSync('npm root -g', { encoding: 'utf8' }).trim();
|
|
39
|
+
const pathsToCheck = [
|
|
40
|
+
path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js'),
|
|
41
|
+
path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js'),
|
|
42
|
+
];
|
|
43
|
+
for (const p of pathsToCheck) {
|
|
44
|
+
if (fs.existsSync(p)) {
|
|
45
|
+
return p;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch {}
|
|
49
|
+
|
|
50
|
+
// Priority 4: Common global installation paths
|
|
51
|
+
const commonPaths = [
|
|
52
|
+
'/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
53
|
+
'/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
54
|
+
'/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
55
|
+
];
|
|
56
|
+
for (const p of commonPaths) {
|
|
57
|
+
if (fs.existsSync(p)) {
|
|
58
|
+
return p;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Priority 5: which/where on PATH
|
|
63
|
+
try {
|
|
64
|
+
const which = process.platform === 'win32' ? 'where' : 'which';
|
|
65
|
+
const result = execSync(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
|
|
66
|
+
if (result) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
} catch {}
|
|
70
|
+
|
|
71
|
+
// Priority 6: Bare command (rely on PATH at runtime)
|
|
72
|
+
return 'paytaca';
|
|
26
73
|
}
|
|
27
74
|
|
|
28
75
|
export async function isPortAvailable(port: number): Promise<boolean> {
|
package/src/wallet.ts
CHANGED
|
@@ -1,22 +1,68 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
1
|
+
import { spawn, execSync } from 'child_process';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
|
+
import * as os from 'os';
|
|
3
4
|
import { promisify } from 'util';
|
|
4
5
|
import * as path from 'path';
|
|
5
6
|
import { WalletInfo } from './types';
|
|
6
7
|
|
|
7
8
|
const execAsync = promisify(require('child_process').exec);
|
|
8
9
|
|
|
10
|
+
function getGlobalNpmRoot(): string | null {
|
|
11
|
+
try {
|
|
12
|
+
return execSync('npm root -g', { encoding: 'utf8' }).trim();
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
function getPaytacaCommand(): string {
|
|
19
|
+
// Priority 1: Local node_modules (via require.resolve)
|
|
10
20
|
try {
|
|
11
21
|
const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
|
|
12
22
|
return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
|
|
13
23
|
} catch {}
|
|
14
24
|
|
|
25
|
+
// Priority 2: Local .bin symlink
|
|
15
26
|
const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
|
|
16
27
|
if (fs.existsSync(localPaytaca)) {
|
|
17
28
|
return localPaytaca;
|
|
18
29
|
}
|
|
19
30
|
|
|
31
|
+
// Priority 3: Global npm root
|
|
32
|
+
const globalRoot = getGlobalNpmRoot();
|
|
33
|
+
if (globalRoot) {
|
|
34
|
+
const globalPaytaca = path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js');
|
|
35
|
+
if (fs.existsSync(globalPaytaca)) {
|
|
36
|
+
return globalPaytaca;
|
|
37
|
+
}
|
|
38
|
+
const scopedPaytaca = path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js');
|
|
39
|
+
if (fs.existsSync(scopedPaytaca)) {
|
|
40
|
+
return scopedPaytaca;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Priority 4: Common global installation paths
|
|
45
|
+
const commonPaths = [
|
|
46
|
+
'/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
47
|
+
'/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
48
|
+
'/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
|
|
49
|
+
];
|
|
50
|
+
for (const p of commonPaths) {
|
|
51
|
+
if (fs.existsSync(p)) {
|
|
52
|
+
return p;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Priority 5: which/where on PATH
|
|
57
|
+
try {
|
|
58
|
+
const which = process.platform === 'win32' ? 'where' : 'which';
|
|
59
|
+
const result = execSync(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
|
|
60
|
+
if (result) {
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
|
|
65
|
+
// Priority 6: Bare command (rely on PATH at runtime)
|
|
20
66
|
return 'paytaca';
|
|
21
67
|
}
|
|
22
68
|
|
|
@@ -56,18 +102,51 @@ export async function checkWallet(): Promise<WalletInfo> {
|
|
|
56
102
|
}
|
|
57
103
|
}
|
|
58
104
|
|
|
105
|
+
function addToPath(dir: string): void {
|
|
106
|
+
if (dir && fs.existsSync(dir) && !process.env.PATH?.includes(dir)) {
|
|
107
|
+
process.env.PATH = `${dir}${path.delimiter}${process.env.PATH}`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
59
111
|
export function ensurePaytacaOnPath(): string | null {
|
|
112
|
+
// Priority 1: Local node_modules .bin dir
|
|
60
113
|
try {
|
|
61
114
|
const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
|
|
62
115
|
const binDir = path.resolve(path.dirname(paytacaCliPkg), '..', '.bin');
|
|
63
116
|
const paytacaBin = path.join(binDir, 'paytaca');
|
|
64
117
|
if (fs.existsSync(paytacaBin)) {
|
|
65
|
-
|
|
66
|
-
process.env.PATH = `${binDir}${path.delimiter}${process.env.PATH}`;
|
|
67
|
-
}
|
|
118
|
+
addToPath(binDir);
|
|
68
119
|
return binDir;
|
|
69
120
|
}
|
|
70
121
|
} catch {}
|
|
122
|
+
|
|
123
|
+
// Priority 2: Global npm root .bin dir
|
|
124
|
+
const globalRoot = getGlobalNpmRoot();
|
|
125
|
+
if (globalRoot) {
|
|
126
|
+
const globalBinDir = path.resolve(globalRoot, '..', '.bin');
|
|
127
|
+
const globalPaytaca = path.join(globalBinDir, 'paytaca');
|
|
128
|
+
if (fs.existsSync(globalPaytaca)) {
|
|
129
|
+
addToPath(globalBinDir);
|
|
130
|
+
return globalBinDir;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Priority 3: Common global bin directories
|
|
135
|
+
const commonBinDirs = [
|
|
136
|
+
'/usr/local/bin',
|
|
137
|
+
'/usr/bin',
|
|
138
|
+
path.join(os.homedir(), '.npm-global', 'bin'),
|
|
139
|
+
process.env.NVM_BIN,
|
|
140
|
+
].filter((p): p is string => !!p);
|
|
141
|
+
|
|
142
|
+
for (const binDir of commonBinDirs) {
|
|
143
|
+
const paytacaBin = path.join(binDir, 'paytaca');
|
|
144
|
+
if (fs.existsSync(paytacaBin)) {
|
|
145
|
+
addToPath(binDir);
|
|
146
|
+
return binDir;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
71
150
|
return null;
|
|
72
151
|
}
|
|
73
152
|
|
|
@@ -84,48 +163,34 @@ export async function createWallet(): Promise<WalletInfo> {
|
|
|
84
163
|
try {
|
|
85
164
|
// Generate a new wallet using paytaca CLI
|
|
86
165
|
// This will create a wallet and display the mnemonic
|
|
87
|
-
const { stdout, stderr } = await execAsync(`"${PAYTACA_CMD}" wallet create
|
|
166
|
+
const { stdout, stderr } = await execAsync(`"${PAYTACA_CMD}" wallet create`);
|
|
88
167
|
|
|
89
168
|
let output = stdout.toString();
|
|
90
169
|
if (!output && stderr) {
|
|
91
170
|
output = stderr.toString();
|
|
92
171
|
}
|
|
93
172
|
|
|
94
|
-
// Try to parse JSON output if available
|
|
95
|
-
try {
|
|
96
|
-
const jsonOutput = JSON.parse(output);
|
|
97
|
-
if (jsonOutput.mnemonic) {
|
|
98
|
-
// Show warning to user
|
|
99
|
-
console.log('\\n⚠️ IMPORTANT: Your wallet has been created!');
|
|
100
|
-
console.log('\\nSAVE THIS RECOVERY PHRASE SECURELY:');
|
|
101
|
-
console.log('═'.repeat(60));
|
|
102
|
-
console.log(jsonOutput.mnemonic);
|
|
103
|
-
console.log('═'.repeat(60));
|
|
104
|
-
console.log('\\nWithout this phrase, you CANNOT recover your funds if you');
|
|
105
|
-
console.log('lose access to this device. Write it down and store it safely.\\n');
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
exists: true,
|
|
109
|
-
hash: jsonOutput.hash,
|
|
110
|
-
address: jsonOutput.address,
|
|
111
|
-
balance: '0 BCH',
|
|
112
|
-
mnemonic: jsonOutput.mnemonic
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
} catch {
|
|
116
|
-
// Fall through to regex parsing
|
|
117
|
-
}
|
|
118
|
-
|
|
119
173
|
// Parse from text output
|
|
120
174
|
const hashMatch = output.match(/Wallet hash:\s*(.+)/i);
|
|
121
175
|
const addressMatch = output.match(/Address:\s*(.+)/i);
|
|
122
|
-
const mnemonicMatch = output.match(/Recovery phrase[\s\S]*?([a-z]+(?:\s+[a-z]+){11,23})/i);
|
|
123
176
|
|
|
124
|
-
|
|
177
|
+
// Extract mnemonic from numbered seed phrase list
|
|
178
|
+
const phraseSection = output.match(/Seed phrase:\s*\n([\s\S]*?)(?=\n\s*Wallet hash)/i);
|
|
179
|
+
let mnemonic = undefined;
|
|
180
|
+
if (phraseSection) {
|
|
181
|
+
const words = [];
|
|
182
|
+
for (const line of phraseSection[1].trim().split('\n')) {
|
|
183
|
+
const m = line.match(/^\s*\d+\.\s+(\w+)/);
|
|
184
|
+
if (m) words.push(m[1]);
|
|
185
|
+
}
|
|
186
|
+
if (words.length >= 12) mnemonic = words.join(' ');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (mnemonic) {
|
|
125
190
|
console.log('\\n⚠️ IMPORTANT: Your wallet has been created!');
|
|
126
191
|
console.log('\\nSAVE THIS RECOVERY PHRASE SECURELY:');
|
|
127
192
|
console.log('═'.repeat(60));
|
|
128
|
-
console.log(
|
|
193
|
+
console.log(mnemonic);
|
|
129
194
|
console.log('═'.repeat(60));
|
|
130
195
|
console.log('\\nWithout this phrase, you CANNOT recover your funds if you');
|
|
131
196
|
console.log('lose access to this device. Write it down and store it safely.\\n');
|
|
@@ -136,7 +201,7 @@ export async function createWallet(): Promise<WalletInfo> {
|
|
|
136
201
|
hash: hashMatch ? hashMatch[1].trim() : undefined,
|
|
137
202
|
address: addressMatch ? addressMatch[1].trim() : undefined,
|
|
138
203
|
balance: '0 BCH',
|
|
139
|
-
mnemonic
|
|
204
|
+
mnemonic
|
|
140
205
|
};
|
|
141
206
|
} catch (err: any) {
|
|
142
207
|
console.error('Failed to create wallet:', err.message || err);
|
package/dist/package.json
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@paytaca/opencode-plugin",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "OpenCode plugin for Paytaca AI - BCH micropayment provider for DeepSeek V4 Flash",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"engines": {
|
|
8
|
-
"node": ">=20.0.0"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"prepare": "npm run build"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"opencode",
|
|
16
|
-
"plugin",
|
|
17
|
-
"paytaca",
|
|
18
|
-
"bch",
|
|
19
|
-
"ai",
|
|
20
|
-
"provider"
|
|
21
|
-
],
|
|
22
|
-
"author": "Paytaca",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@opencode-ai/plugin": "^1.16.0",
|
|
26
|
-
"paytaca-cli": "^0.3.2"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/node": "^20.0.0",
|
|
30
|
-
"typescript": "^5.0.0"
|
|
31
|
-
},
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"opencode": ">=1.0.0"
|
|
34
|
-
},
|
|
35
|
-
"peerDependenciesMeta": {
|
|
36
|
-
"opencode": {
|
|
37
|
-
"optional": true
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"publishConfig": {
|
|
41
|
-
"access": "public"
|
|
42
|
-
}
|
|
43
|
-
}
|