@getalby/cli 0.3.0 → 0.4.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/README.md
CHANGED
|
@@ -57,11 +57,8 @@ npx @getalby/cli <command> [options]
|
|
|
57
57
|
# Use a named wallet
|
|
58
58
|
npx @getalby/cli --wallet-name alice <command> [options]
|
|
59
59
|
|
|
60
|
-
#
|
|
60
|
+
# Or pass a connection secret directly
|
|
61
61
|
npx @getalby/cli -c /path/to/secret.txt <command> [options]
|
|
62
|
-
|
|
63
|
-
# Or pass connection string directly
|
|
64
|
-
npx @getalby/cli -c "nostr+walletconnect://..." <command> [options]
|
|
65
62
|
```
|
|
66
63
|
|
|
67
64
|
The `-c` option auto-detects whether you're passing a connection string or a file path. You can get a connection string from your NWC-compatible wallet (e.g., [Alby](https://getalby.com)).
|
|
@@ -92,44 +89,50 @@ curl -X POST "https://faucet.nwc.dev/wallets/<username>/topup?amount=5000"
|
|
|
92
89
|
|
|
93
90
|
### Wallet Commands
|
|
94
91
|
|
|
95
|
-
These commands require a wallet connection
|
|
92
|
+
These commands require a wallet connection - either default connection, or specify a custom connection with `-w`, '-c', or `NWC_URL` environment variable:
|
|
96
93
|
|
|
97
94
|
```bash
|
|
98
95
|
# Get wallet balance
|
|
99
|
-
npx @getalby/cli
|
|
96
|
+
npx @getalby/cli get-balance
|
|
100
97
|
|
|
101
98
|
# Get wallet info
|
|
102
|
-
npx @getalby/cli
|
|
99
|
+
npx @getalby/cli get-info
|
|
103
100
|
|
|
104
101
|
# Get wallet service capabilities
|
|
105
|
-
npx @getalby/cli
|
|
102
|
+
npx @getalby/cli get-wallet-service-info
|
|
106
103
|
|
|
107
104
|
# Create an invoice
|
|
108
|
-
npx @getalby/cli
|
|
105
|
+
npx @getalby/cli make-invoice --amount 1000 --description "Payment"
|
|
109
106
|
|
|
110
107
|
# Pay an invoice
|
|
111
|
-
npx @getalby/cli
|
|
108
|
+
npx @getalby/cli pay-invoice --invoice "lnbc..."
|
|
112
109
|
|
|
113
110
|
# Send a keysend payment
|
|
114
|
-
npx @getalby/cli
|
|
111
|
+
npx @getalby/cli pay-keysend --pubkey "02abc..." --amount 100
|
|
115
112
|
|
|
116
113
|
# Look up an invoice by payment hash
|
|
117
|
-
npx @getalby/cli
|
|
114
|
+
npx @getalby/cli lookup-invoice --payment-hash "abc123..."
|
|
118
115
|
|
|
119
116
|
# List transactions
|
|
120
|
-
npx @getalby/cli
|
|
117
|
+
npx @getalby/cli list-transactions --limit 10
|
|
121
118
|
|
|
122
119
|
# Get wallet budget
|
|
123
|
-
npx @getalby/cli
|
|
120
|
+
npx @getalby/cli get-budget
|
|
124
121
|
|
|
125
122
|
# Sign a message
|
|
126
|
-
npx @getalby/cli
|
|
123
|
+
npx @getalby/cli sign-message --message "Hello, World!"
|
|
124
|
+
|
|
125
|
+
# Fetch a payment-protected resource (auto-detects L402, X402, MPP)
|
|
126
|
+
npx @getalby/cli fetch --url "https://example.com/api"
|
|
127
|
+
|
|
128
|
+
# Fetch with custom method, headers, and body
|
|
129
|
+
npx @getalby/cli fetch --url "https://example.com/api" --method POST --body '{"query":"hello"}' --headers '{"Accept":"application/json"}'
|
|
127
130
|
|
|
128
|
-
# Fetch
|
|
129
|
-
npx @getalby/cli
|
|
131
|
+
# Fetch with a custom max amount (default: 5000 sats, 0 = no limit)
|
|
132
|
+
npx @getalby/cli fetch --url "https://example.com/api" --max-amount 1000
|
|
130
133
|
|
|
131
134
|
# Wait for a payment notification
|
|
132
|
-
npx @getalby/cli
|
|
135
|
+
npx @getalby/cli wait-for-payment --payment-hash "abc123..."
|
|
133
136
|
```
|
|
134
137
|
|
|
135
138
|
### HOLD Invoices
|
|
@@ -138,13 +141,13 @@ HOLD invoices allow you to accept payments conditionally - the payment is held u
|
|
|
138
141
|
|
|
139
142
|
```bash
|
|
140
143
|
# Create a HOLD invoice (you provide the payment hash)
|
|
141
|
-
npx @getalby/cli
|
|
144
|
+
npx @getalby/cli make-hold-invoice --amount 1000 --payment-hash "abc123..."
|
|
142
145
|
|
|
143
146
|
# Settle a HOLD invoice (claim the payment)
|
|
144
|
-
npx @getalby/cli
|
|
147
|
+
npx @getalby/cli settle-hold-invoice --preimage "def456..."
|
|
145
148
|
|
|
146
149
|
# Cancel a HOLD invoice (reject the payment)
|
|
147
|
-
npx @getalby/cli
|
|
150
|
+
npx @getalby/cli cancel-hold-invoice --payment-hash "abc123..."
|
|
148
151
|
```
|
|
149
152
|
|
|
150
153
|
### Lightning Tools
|
|
@@ -170,46 +173,7 @@ npx @getalby/cli request-invoice-from-lightning-address --address "hello@getalby
|
|
|
170
173
|
|
|
171
174
|
## Command Reference
|
|
172
175
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
These require a wallet connection (`-c`, `--wallet-name`, or `NWC_URL`):
|
|
176
|
-
|
|
177
|
-
| Command | Description | Required Options |
|
|
178
|
-
| ------------------------- | ------------------------------ | ------------------------------- |
|
|
179
|
-
| `get-balance` | Get wallet balance | - |
|
|
180
|
-
| `get-info` | Get wallet info | - |
|
|
181
|
-
| `get-wallet-service-info` | Get wallet capabilities | - |
|
|
182
|
-
| `get-budget` | Get wallet budget | - |
|
|
183
|
-
| `make-invoice` | Create a lightning invoice | `--amount` |
|
|
184
|
-
| `pay-invoice` | Pay a lightning invoice | `--invoice` |
|
|
185
|
-
| `pay-keysend` | Send a keysend payment | `--pubkey`, `--amount` |
|
|
186
|
-
| `lookup-invoice` | Look up an invoice | `--payment-hash` or `--invoice` |
|
|
187
|
-
| `list-transactions` | List transactions | - |
|
|
188
|
-
| `sign-message` | Sign a message with wallet key | `--message` |
|
|
189
|
-
| `wait-for-payment` | Wait for payment notification | `--payment-hash` |
|
|
190
|
-
| `fetch-l402` | Fetch L402-protected resource | `--url` |
|
|
191
|
-
|
|
192
|
-
### HOLD Invoice Commands
|
|
193
|
-
|
|
194
|
-
These require a wallet connection (`-c`, `--wallet-name`, or `NWC_URL`):
|
|
195
|
-
|
|
196
|
-
| Command | Description | Required Options |
|
|
197
|
-
| --------------------- | --------------------- | ---------------------------- |
|
|
198
|
-
| `make-hold-invoice` | Create a HOLD invoice | `--amount`, `--payment-hash` |
|
|
199
|
-
| `settle-hold-invoice` | Settle a HOLD invoice | `--preimage` |
|
|
200
|
-
| `cancel-hold-invoice` | Cancel a HOLD invoice | `--payment-hash` |
|
|
201
|
-
|
|
202
|
-
### Lightning Tools
|
|
203
|
-
|
|
204
|
-
These don't require a wallet connection:
|
|
205
|
-
|
|
206
|
-
| Command | Description | Required Options |
|
|
207
|
-
| ---------------------------------------- | -------------------------------------- | ------------------------- |
|
|
208
|
-
| `fiat-to-sats` | Convert fiat to sats | `--currency`, `--amount` |
|
|
209
|
-
| `sats-to-fiat` | Convert sats to fiat | `--amount`, `--currency` |
|
|
210
|
-
| `parse-invoice` | Parse a BOLT-11 invoice | `--invoice` |
|
|
211
|
-
| `verify-preimage` | Verify preimage against invoice | `--invoice`, `--preimage` |
|
|
212
|
-
| `request-invoice-from-lightning-address` | Request invoice from lightning address | `--address`, `--amount` |
|
|
176
|
+
Run `npx @getalby/cli help` for a full list of commands and possible arguments.
|
|
213
177
|
|
|
214
178
|
## Output
|
|
215
179
|
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fetch402 } from "../tools/lightning/fetch.js";
|
|
2
2
|
import { getClient, handleError, output } from "../utils.js";
|
|
3
|
-
export function
|
|
3
|
+
export function registerFetch402Command(program) {
|
|
4
4
|
program
|
|
5
|
-
.command("fetch
|
|
6
|
-
.description("Fetch
|
|
5
|
+
.command("fetch")
|
|
6
|
+
.description("Fetch a payment-protected resource (auto-detects L402, X402, MPP)")
|
|
7
7
|
.requiredOption("-u, --url <url>", "URL to fetch")
|
|
8
8
|
.option("-m, --method <method>", "HTTP method (GET, POST, etc.)")
|
|
9
9
|
.option("-b, --body <json>", "Request body (JSON string)")
|
|
10
10
|
.option("-H, --headers <json>", "Additional headers (JSON string)")
|
|
11
|
+
.option("--max-amount <sats>", "Maximum amount in sats to pay per request. Aborts if the endpoint requests more. (default: 5000, 0 = no limit)", parseInt)
|
|
11
12
|
.action(async (options) => {
|
|
12
13
|
await handleError(async () => {
|
|
13
14
|
const client = await getClient(program);
|
|
14
|
-
const result = await
|
|
15
|
+
const result = await fetch402(client, {
|
|
15
16
|
url: options.url,
|
|
16
17
|
method: options.method,
|
|
17
18
|
body: options.body,
|
|
18
19
|
headers: options.headers ? JSON.parse(options.headers) : undefined,
|
|
20
|
+
maxAmountSats: options.maxAmount,
|
|
19
21
|
});
|
|
20
22
|
output(result);
|
|
21
23
|
});
|
package/build/index.js
CHANGED
|
@@ -19,20 +19,22 @@ import { registerSatsToFiatCommand } from "./commands/sats-to-fiat.js";
|
|
|
19
19
|
import { registerParseInvoiceCommand } from "./commands/parse-invoice.js";
|
|
20
20
|
import { registerVerifyPreimageCommand } from "./commands/verify-preimage.js";
|
|
21
21
|
import { registerRequestInvoiceFromLightningAddressCommand } from "./commands/request-invoice-from-lightning-address.js";
|
|
22
|
-
import {
|
|
22
|
+
import { registerFetch402Command } from "./commands/fetch.js";
|
|
23
23
|
import { registerConnectCommand } from "./commands/connect.js";
|
|
24
24
|
import { registerAuthCommand } from "./commands/auth.js";
|
|
25
25
|
const program = new Command();
|
|
26
26
|
program
|
|
27
27
|
.name("@getalby/cli")
|
|
28
|
-
.description("CLI for Nostr Wallet Connect (NIP-47) with lightning tools\n
|
|
28
|
+
.description("CLI for Nostr Wallet Connect (NIP-47) with lightning tools\n" +
|
|
29
|
+
" Run 'auth' or 'connect' first to set up a wallet connection.\n\n" +
|
|
29
30
|
" Examples:\n" +
|
|
31
|
+
" $ npx @getalby/cli auth https://my.albyhub.com --app-name OpenClaw\n" +
|
|
30
32
|
' $ npx @getalby/cli connect "nostr+walletconnect://..."\n' +
|
|
31
33
|
" $ npx @getalby/cli get-balance\n" +
|
|
32
34
|
" $ npx @getalby/cli pay-invoice --invoice lnbc...")
|
|
33
|
-
.version("0.
|
|
34
|
-
.option("-c, --connection-secret <string>", "NWC connection secret (nostr+walletconnect://...) or path to file containing it (preferred)")
|
|
35
|
+
.version("0.4.1")
|
|
35
36
|
.option("-w, --wallet-name <name>", "Use a named wallet's connection secret (~/.alby-cli/connection-secret-<name>.key)")
|
|
37
|
+
.option("-c, --connection-secret <string>", "NWC connection secret (nostr+walletconnect://...) or path to file containing it (preferred)")
|
|
36
38
|
.option("-v, --verbose", "Print status messages to stderr")
|
|
37
39
|
.addHelpText("after", `
|
|
38
40
|
Connection Secret Resolution (in order of priority):
|
|
@@ -48,7 +50,7 @@ Security:
|
|
|
48
50
|
- NEVER share any part of a connection secret (pubkey, secret, relay etc.) with anyone
|
|
49
51
|
as this can be used to gain access to your wallet or reduce your wallet's privacy.`);
|
|
50
52
|
// Register common wallet commands
|
|
51
|
-
program.commandsGroup("Wallet Commands (
|
|
53
|
+
program.commandsGroup("Wallet Commands (requires wallet connection):");
|
|
52
54
|
registerGetBalanceCommand(program);
|
|
53
55
|
registerGetBudgetCommand(program);
|
|
54
56
|
registerGetInfoCommand(program);
|
|
@@ -57,7 +59,7 @@ registerPayInvoiceCommand(program);
|
|
|
57
59
|
registerLookupInvoiceCommand(program);
|
|
58
60
|
registerListTransactionsCommand(program);
|
|
59
61
|
// Register advanced wallet commands
|
|
60
|
-
program.commandsGroup("Advanced Wallet Commands (
|
|
62
|
+
program.commandsGroup("Advanced Wallet Commands (requires wallet connection):");
|
|
61
63
|
registerPayKeysendCommand(program);
|
|
62
64
|
registerGetWalletServiceInfoCommand(program);
|
|
63
65
|
registerWaitForPaymentCommand(program);
|
|
@@ -66,13 +68,15 @@ registerMakeHoldInvoiceCommand(program);
|
|
|
66
68
|
registerSettleHoldInvoiceCommand(program);
|
|
67
69
|
registerCancelHoldInvoiceCommand(program);
|
|
68
70
|
// Register lightning tool commands
|
|
69
|
-
program.commandsGroup("Lightning Tools (no
|
|
71
|
+
program.commandsGroup("Lightning Tools (no wallet connection required):");
|
|
70
72
|
registerFiatToSatsCommand(program);
|
|
71
73
|
registerSatsToFiatCommand(program);
|
|
72
74
|
registerParseInvoiceCommand(program);
|
|
73
75
|
registerVerifyPreimageCommand(program);
|
|
74
76
|
registerRequestInvoiceFromLightningAddressCommand(program);
|
|
75
|
-
|
|
77
|
+
// Register fetch command for payment-protected resources
|
|
78
|
+
program.commandsGroup("HTTP 402 Payments (requires wallet connection):");
|
|
79
|
+
registerFetch402Command(program);
|
|
76
80
|
// Register setup commands
|
|
77
81
|
program.commandsGroup("Setup:");
|
|
78
82
|
registerAuthCommand(program);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { fetch402 as fetch402Lib } from "@getalby/lightning-tools/402";
|
|
2
|
+
const DEFAULT_MAX_AMOUNT_SATS = 5000;
|
|
3
|
+
export async function fetch402(client, params) {
|
|
4
|
+
const method = params.method?.toUpperCase();
|
|
3
5
|
const requestOptions = {
|
|
4
|
-
method
|
|
6
|
+
method,
|
|
5
7
|
};
|
|
6
|
-
if (
|
|
8
|
+
if (method && method !== "GET" && method !== "HEAD") {
|
|
7
9
|
requestOptions.body = params.body;
|
|
8
10
|
requestOptions.headers = {
|
|
9
11
|
"Content-Type": "application/json",
|
|
@@ -13,13 +15,10 @@ export async function fetchL402(client, params) {
|
|
|
13
15
|
else if (params.headers) {
|
|
14
16
|
requestOptions.headers = params.headers;
|
|
15
17
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return { preimage: result.preimage };
|
|
21
|
-
},
|
|
22
|
-
},
|
|
18
|
+
const maxAmountSats = params.maxAmountSats ?? DEFAULT_MAX_AMOUNT_SATS;
|
|
19
|
+
const result = await fetch402Lib(params.url, requestOptions, {
|
|
20
|
+
wallet: client,
|
|
21
|
+
maxAmount: maxAmountSats || undefined,
|
|
23
22
|
});
|
|
24
23
|
const responseContent = await result.text();
|
|
25
24
|
if (!result.ok) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@getalby/cli",
|
|
3
3
|
"description": "CLI for Nostr Wallet Connect (NIP-47) with a few additional useful lightning tools",
|
|
4
4
|
"repository": "https://github.com/getAlby/cli.git",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.4.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"node": ">=20"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@getalby/lightning-tools": "^
|
|
39
|
+
"@getalby/lightning-tools": "^8.0.0",
|
|
40
40
|
"@getalby/sdk": "^7.0.0",
|
|
41
41
|
"@noble/hashes": "^2.0.1",
|
|
42
42
|
"commander": "^14.0.3",
|