@btc-vision/cli 1.0.6 → 1.0.7

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/build/index.js CHANGED
@@ -50,10 +50,9 @@ program.addCommand(searchCommand);
50
50
  program.showHelpAfterError();
51
51
  program.showSuggestionAfterError();
52
52
  program.exitOverride((err) => {
53
- if (err.code === 'commander.help') {
54
- process.exit(0);
55
- }
56
- if (err.code === 'commander.version') {
53
+ if (err.code === 'commander.help' ||
54
+ err.code === 'commander.helpDisplayed' ||
55
+ err.code === 'commander.version') {
57
56
  process.exit(0);
58
57
  }
59
58
  logger.error(`Error: ${err.message}`);
@@ -11,12 +11,7 @@ export const DEFAULT_CONFIG = {
11
11
  regtest: 'https://regtest.opnet.org',
12
12
  },
13
13
  ipfsGateway: 'https://ipfs.opnet.org/ipfs/',
14
- ipfsGateways: [
15
- 'https://ipfs.opnet.org/ipfs/',
16
- 'https://ipfs.io/ipfs/',
17
- 'https://cloudflare-ipfs.com/ipfs/',
18
- 'https://dweb.link/ipfs/',
19
- ],
14
+ ipfsGateways: ['https://ipfs.opnet.org/ipfs/'],
20
15
  ipfsPinningEndpoint: 'https://ipfs.opnet.org/api/v0/add',
21
16
  ipfsPinningApiKey: '',
22
17
  ipfsPinningSecret: '',
@@ -12,5 +12,3 @@ export declare function buildGatewayUrl(gateway: string, cid: string): string;
12
12
  export declare function isValidCid(cid: string): boolean;
13
13
  export declare function downloadPlugin(cid: string, outputPath: string): Promise<number>;
14
14
  export declare function uploadPlugin(filePath: string): Promise<PinResult>;
15
- export declare function checkAvailability(cid: string): Promise<boolean>;
16
- export declare function getGatewayStatus(): Promise<Record<string, boolean>>;
package/build/lib/ipfs.js CHANGED
@@ -2,7 +2,13 @@ import * as https from 'https';
2
2
  import * as http from 'http';
3
3
  import * as fs from 'fs';
4
4
  import { loadConfig } from './config.js';
5
- async function httpRequest(url, options) {
5
+ const DEFAULT_MAX_REDIRECTS = 10;
6
+ async function httpRequest(url, options, redirectCount = 0) {
7
+ const maxRedirects = options.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
8
+ const followRedirect = options.followRedirect ?? false;
9
+ if (redirectCount > maxRedirects) {
10
+ throw new Error(`Maximum redirects (${maxRedirects}) exceeded`);
11
+ }
6
12
  return new Promise((resolve, reject) => {
7
13
  const parsedUrl = new URL(url);
8
14
  const isHttps = parsedUrl.protocol === 'https:';
@@ -16,17 +22,28 @@ async function httpRequest(url, options) {
16
22
  timeout: options.timeout || 30000,
17
23
  };
18
24
  const req = lib.request(reqOptions, (res) => {
25
+ const statusCode = res.statusCode ?? 0;
26
+ if (followRedirect && statusCode >= 300 && statusCode < 400 && res.headers.location) {
27
+ const redirectUrl = new URL(res.headers.location, url).href;
28
+ res.resume();
29
+ httpRequest(redirectUrl, options, redirectCount + 1)
30
+ .then(resolve)
31
+ .catch(reject);
32
+ return;
33
+ }
19
34
  const chunks = [];
20
35
  res.on('data', (chunk) => {
21
36
  chunks.push(chunk);
22
37
  });
23
38
  res.on('end', () => {
24
39
  const body = Buffer.concat(chunks);
25
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
40
+ if (statusCode >= 200 && statusCode < 300) {
26
41
  resolve(body);
27
42
  }
28
43
  else {
29
- reject(new Error(`HTTP ${res.statusCode}: ${res.statusMessage} - ${body.toString()}`));
44
+ const bodyStr = body.toString().slice(0, 200);
45
+ const truncated = body.length > 200 ? '...' : '';
46
+ reject(new Error(`HTTP ${statusCode}: ${res.statusMessage}${bodyStr ? ` - ${bodyStr}${truncated}` : ''}`));
30
47
  }
31
48
  });
32
49
  });
@@ -104,6 +121,7 @@ export async function pinToIPFS(data, name) {
104
121
  headers,
105
122
  body,
106
123
  timeout: 120000,
124
+ followRedirect: true,
107
125
  });
108
126
  const result = JSON.parse(response.toString());
109
127
  let cid;
@@ -140,8 +158,13 @@ export async function fetchFromIPFS(cid) {
140
158
  try {
141
159
  const url = buildGatewayUrl(gateway, cid);
142
160
  const data = await httpRequest(url, {
161
+ headers: {
162
+ Accept: 'application/octet-stream',
163
+ 'User-Agent': 'OPNet-CLI/1.0',
164
+ },
143
165
  method: 'GET',
144
166
  timeout: 60000,
167
+ followRedirect: true,
145
168
  });
146
169
  return {
147
170
  data,
@@ -159,6 +182,9 @@ export function buildGatewayUrl(gateway, cid) {
159
182
  if (base.includes('{cid}')) {
160
183
  return base.replace('{cid}', cid);
161
184
  }
185
+ else if (base.endsWith('/ipfs')) {
186
+ return `${base}/${cid}`;
187
+ }
162
188
  else if (base.includes('/ipfs/')) {
163
189
  return `${base}${cid}`;
164
190
  }
@@ -188,32 +214,3 @@ export async function uploadPlugin(filePath) {
188
214
  const fileName = filePath.split('/').pop() || 'plugin.opnet';
189
215
  return pinToIPFS(data, fileName);
190
216
  }
191
- export async function checkAvailability(cid) {
192
- try {
193
- await fetchFromIPFS(cid);
194
- return true;
195
- }
196
- catch {
197
- return false;
198
- }
199
- }
200
- export async function getGatewayStatus() {
201
- const config = loadConfig();
202
- const gateways = config.ipfsGateways.length > 0 ? config.ipfsGateways : [config.ipfsGateway];
203
- const testCid = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn';
204
- const status = {};
205
- await Promise.all(gateways.map(async (gateway) => {
206
- try {
207
- const url = buildGatewayUrl(gateway, testCid);
208
- await httpRequest(url, {
209
- method: 'HEAD',
210
- timeout: 10000,
211
- });
212
- status[gateway] = true;
213
- }
214
- catch {
215
- status[gateway] = false;
216
- }
217
- }));
218
- return status;
219
- }
@@ -82,7 +82,7 @@ export class CLIWallet {
82
82
  const securityLevel = getMLDSASecurityLevel(level);
83
83
  const dummyChainCode = new Uint8Array(32);
84
84
  const keypair = QuantumBIP32Factory.fromPublicKey(publicKey, dummyChainCode, networks.bitcoin, securityLevel);
85
- return keypair.verify(data, signature);
85
+ return MessageSigner.verifyMLDSASignature(keypair, data, signature);
86
86
  }
87
87
  signMLDSA(data) {
88
88
  const result = MessageSigner.signMLDSAMessage(this.wallet.mldsaKeypair, data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/cli",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "CLI for the OPNet plugin ecosystem - scaffolding, compilation, signing, and registry interaction",
6
6
  "author": "OP_NET",