nirium-cli 3.2.0 → 3.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.
Files changed (2) hide show
  1. package/bin/nirium.js +29 -16
  2. package/package.json +3 -3
package/bin/nirium.js CHANGED
@@ -686,6 +686,32 @@ async function executeConfigCommand(action, key, value) {
686
686
  // pay — sign and settle an x402 payment from the terminal
687
687
  // ═══════════════════════════════════════════════════════════════
688
688
 
689
+ // PAYMENT-RESPONSE in x402 v2 is a JSON object base64-encoded onto the header,
690
+ // not a bare hash. The real tx hash lives under `transaction`, not `txHash`/
691
+ // `transactionHash`/`hash` — those were guesses that never matched the actual
692
+ // shape of the header and silently printed the whole encoded blob as the
693
+ // "hash" — a base64 PAYMENT-RESPONSE that doesn't start with "{" was never
694
+ // decoded, so it fell straight through to being treated as the hash.
695
+ function parsePaymentResponse(raw) {
696
+ const value = (raw || '').trim();
697
+ if (!value) return { txHash: '', meta: null };
698
+ let text = value;
699
+ if (!text.startsWith('{')) {
700
+ try {
701
+ const decoded = Buffer.from(text, 'base64').toString('utf8').trim();
702
+ if (decoded.startsWith('{')) text = decoded;
703
+ } catch {}
704
+ }
705
+ if (text.startsWith('{')) {
706
+ try {
707
+ const meta = JSON.parse(text);
708
+ const tx = meta.transaction || meta.txHash || meta.transactionHash || meta.hash || '';
709
+ return { txHash: /^[0-9a-f]{64}$/i.test(tx) ? tx : '', meta };
710
+ } catch {}
711
+ }
712
+ return { txHash: /^[0-9a-f]{64}$/i.test(value) ? value : '', meta: null };
713
+ }
714
+
689
715
  async function executePayCommand(url, options) {
690
716
  const config = loadConfig(options.config);
691
717
  const network = options.network || process.env.NIRIUM_NETWORK || config.network || 'stellar:testnet';
@@ -799,21 +825,7 @@ async function executePayCommand(url, options) {
799
825
  || response.headers.get('payment-tx-hash')
800
826
  || '';
801
827
 
802
- let txHash = '';
803
- let paymentMeta = null;
804
- if (paymentResponseHeader) {
805
- try {
806
- if (paymentResponseHeader.startsWith('{')) {
807
- const parsed = JSON.parse(paymentResponseHeader);
808
- txHash = parsed.txHash || parsed.transactionHash || parsed.hash || '';
809
- paymentMeta = parsed;
810
- } else {
811
- txHash = paymentResponseHeader;
812
- }
813
- } catch {
814
- txHash = paymentResponseHeader;
815
- }
816
- }
828
+ const { txHash, meta: paymentMeta } = parsePaymentResponse(paymentResponseHeader);
817
829
 
818
830
  let responseBody;
819
831
  const contentType = response.headers.get('content-type') || '';
@@ -846,8 +858,9 @@ async function executePayCommand(url, options) {
846
858
  }
847
859
  console.log(` Response Time: ${durationMs}ms`);
848
860
  if (txHash) {
861
+ const explorerNetwork = paymentMeta?.network || network;
849
862
  console.log(` Tx Reference: ${txHash}`);
850
- console.log(` Explorer: https://stellar.expert/explorer/${network.includes('testnet') ? 'testnet' : 'public'}/tx/${txHash}`);
863
+ console.log(` Explorer: https://stellar.expert/explorer/${explorerNetwork.includes('testnet') ? 'testnet' : 'public'}/tx/${txHash}`);
851
864
  }
852
865
  console.log(`\n--- Response Payload ---`);
853
866
  console.log(typeof responseBody === 'object' ? JSON.stringify(responseBody, null, 2) : responseBody);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nirium-cli",
3
- "version": "3.2.0",
4
- "description": "Nirium CLI \u2014 scaffold Stellar agent projects and check agent status",
3
+ "version": "3.2.1",
4
+ "description": "Nirium CLI — scaffold Stellar agent projects and check agent status",
5
5
  "main": "bin/nirium.js",
6
6
  "type": "module",
7
7
  "bin": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "prepublishOnly": "node --check bin/nirium.js",
12
- "test": "node --test test/doctor-seller.test.js test/config-secret.test.js test/serve-api-key.test.js test/verify-hash-only.test.js test/verify-retry-gateway.test.js test/pay-agent-construction.test.js test/pay-status-and-cap.test.js test/status.test.js test/anchor.test.js test/anchor-sign.test.js test/report.test.js"
12
+ "test": "node --test test/doctor-seller.test.js test/config-secret.test.js test/serve-api-key.test.js test/verify-hash-only.test.js test/verify-retry-gateway.test.js test/pay-agent-construction.test.js test/pay-status-and-cap.test.js test/pay-payment-response-parsing.test.js test/status.test.js test/anchor.test.js test/anchor-sign.test.js test/report.test.js"
13
13
  },
14
14
  "keywords": [
15
15
  "stellar",