@1sat/cli 0.0.75 → 0.0.77

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
@@ -72,6 +72,12 @@ export PRIVATE_KEY_WIF="<your WIF key>"
72
72
  1sat wallet balance
73
73
  ```
74
74
 
75
+ **Env file** (same keys as above; file values override the process environment for this run):
76
+
77
+ ```bash
78
+ 1sat --env-file mint.env wallet balance
79
+ ```
80
+
75
81
  **Encrypted keyfile (interactive use):**
76
82
 
77
83
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/cli",
3
- "version": "0.0.75",
3
+ "version": "0.0.77",
4
4
  "description": "CLI for 1Sat Ordinals SDK",
5
5
  "type": "module",
6
6
  "main": "./src/cli.ts",
@@ -26,12 +26,12 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@1sat/actions": "0.0.173",
29
+ "@1sat/actions": "0.0.184",
30
30
  "@1sat/client": "0.0.42",
31
- "@1sat/types": "0.0.33",
32
- "@1sat/wallet-node": "0.0.56",
33
- "@1sat/wallet-server": "0.0.25",
34
- "@bsv/sdk": "^2.0.13",
31
+ "@1sat/types": "0.0.34",
32
+ "@1sat/wallet-node": "0.0.57",
33
+ "@1sat/wallet-server": "0.0.26",
34
+ "@bsv/sdk": "^2.1.6",
35
35
  "@bsv/wallet-toolbox": "2.1.24",
36
36
  "chalk": "^5.0.0",
37
37
  "@clack/prompts": "^0.8.0",
package/src/args.ts CHANGED
@@ -9,6 +9,8 @@ export interface GlobalFlags {
9
9
  quiet: boolean
10
10
  yes: boolean
11
11
  chain: 'main' | 'test'
12
+ /** Paths from `--env-file` / `--env-file=path` (may be empty). */
13
+ envFiles: string[]
12
14
  help: boolean
13
15
  version: boolean
14
16
  rest: string[]
@@ -24,6 +26,7 @@ export function parseGlobalFlags(args: string[]): GlobalFlags {
24
26
  let chain: 'main' | 'test' = 'main'
25
27
  let help = false
26
28
  let version = false
29
+ const envFiles: string[] = []
27
30
  const rest: string[] = []
28
31
  const skip = new Set<number>()
29
32
 
@@ -56,6 +59,15 @@ export function parseGlobalFlags(args: string[]): GlobalFlags {
56
59
  }
57
60
  break
58
61
  }
62
+ case '--env-file': {
63
+ const value = args[i + 1]
64
+ if (!value || value.startsWith('-')) {
65
+ throw new Error('--env-file requires a path')
66
+ }
67
+ envFiles.push(value)
68
+ skip.add(i + 1)
69
+ break
70
+ }
59
71
  case '--help':
60
72
  case '-h':
61
73
  help = true
@@ -65,11 +77,19 @@ export function parseGlobalFlags(args: string[]): GlobalFlags {
65
77
  version = true
66
78
  break
67
79
  default:
68
- rest.push(arg)
80
+ if (arg.startsWith('--env-file=')) {
81
+ const value = arg.slice('--env-file='.length)
82
+ if (!value) {
83
+ throw new Error('--env-file requires a path')
84
+ }
85
+ envFiles.push(value)
86
+ } else {
87
+ rest.push(arg)
88
+ }
69
89
  }
70
90
  }
71
91
 
72
- return { json, quiet, yes, chain, help, version, rest }
92
+ return { json, quiet, yes, chain, envFiles, help, version, rest }
73
93
  }
74
94
 
75
95
  /**
package/src/cli.ts CHANGED
@@ -6,6 +6,9 @@
6
6
  * Pure Bun CLI with manual arg parsing. No frameworks.
7
7
  */
8
8
 
9
+ import { existsSync } from 'node:fs'
10
+ import { resolve } from 'node:path'
11
+ import { config as loadEnv } from 'dotenv'
9
12
  import { parseGlobalFlags } from './args'
10
13
  import { handleActionCommand } from './commands/action'
11
14
  import { handleConfigCommand } from './commands/config'
@@ -27,8 +30,25 @@ import { formatError } from './output'
27
30
 
28
31
  const rawArgs = process.argv.slice(2)
29
32
 
33
+ /** Load `--env-file` paths into process.env. File values win over existing env. */
34
+ function applyEnvFiles(paths: string[]): void {
35
+ for (const p of paths) {
36
+ const abs = resolve(p)
37
+ if (!existsSync(abs)) {
38
+ throw new Error(`Env file not found: ${p}`)
39
+ }
40
+ const result = loadEnv({ path: abs, quiet: true, override: true })
41
+ if (result.error) {
42
+ throw result.error
43
+ }
44
+ }
45
+ }
46
+
30
47
  async function main(): Promise<void> {
31
48
  const flags = parseGlobalFlags(rawArgs)
49
+ if (flags.envFiles.length > 0) {
50
+ applyEnvFiles(flags.envFiles)
51
+ }
32
52
 
33
53
  if (flags.version) {
34
54
  printVersion()
@@ -1,16 +1,13 @@
1
1
  /**
2
- * OpNS commands - register, deregister, lookup, mine.
2
+ * OpNS commands - register, deregister, lookup.
3
3
  *
4
- * Manage OpNS name identity bindings and paid mining jobs.
4
+ * Manage OpNS name identity bindings. Paid mining is product code on 1sat.name.
5
5
  */
6
6
 
7
7
  import {
8
8
  getDisplayValue,
9
9
  getOpnsNames,
10
10
  opnsDeregister as opnsDeregisterAction,
11
- opnsMine as opnsMineAction,
12
- opnsMineRefund as opnsMineRefundAction,
13
- opnsMineStatus as opnsMineStatusAction,
14
11
  opnsRegister as opnsRegisterAction,
15
12
  } from '@1sat/actions'
16
13
  import { confirm, isCancel } from '@clack/prompts'
@@ -34,12 +31,6 @@ export async function handleOpnsCommand(
34
31
  return opnsDeregister(rest, opts)
35
32
  case 'lookup':
36
33
  return opnsLookup(rest, opts)
37
- case 'mine':
38
- return opnsMine(rest, opts)
39
- case 'mine-status':
40
- return opnsMineStatus(rest, opts)
41
- case 'mine-refund':
42
- return opnsMineRefund(rest, opts)
43
34
  default:
44
35
  printCommandHelp('opns', opts.json)
45
36
  if (subcommand && subcommand !== 'help') {
@@ -135,113 +126,6 @@ async function opnsDeregister(
135
126
  }
136
127
  }
137
128
 
138
- async function opnsMine(args: string[], opts: GlobalFlags): Promise<void> {
139
- const name = extractFlag(args, '--name')
140
- const serviceUrl = extractFlag(args, '--service')
141
- const receiveAddress = extractFlag(args, '--receive-address')
142
- const timeout = extractFlag(args, '--timeout')
143
-
144
- if (!name) fatal('Missing --name <name>')
145
- if (!serviceUrl) fatal('Missing --service <url>')
146
-
147
- if (!opts.yes) {
148
- const ok = await confirm({
149
- message: `Pay ${serviceUrl} to mine "${name}"? The full price is charged upfront.`,
150
- })
151
- if (isCancel(ok) || !ok) {
152
- fatal('Mine cancelled.')
153
- }
154
- }
155
-
156
- const privateKey = await loadKey()
157
- const { ctx, destroy } = await loadContext(privateKey, {
158
- chain: opts.chain,
159
- })
160
-
161
- try {
162
- const result = await opnsMineAction.execute(ctx, {
163
- name,
164
- serviceUrl,
165
- receiveAddress: receiveAddress ?? undefined,
166
- timeoutMs: timeout ? Number.parseInt(timeout, 10) : undefined,
167
- })
168
- if (result.error && !result.jobId) {
169
- fatal(result.error)
170
- }
171
- output(
172
- opts.json
173
- ? result
174
- : {
175
- jobId: result.jobId,
176
- state: result.state,
177
- txid: result.txid,
178
- ...(result.error ? { error: result.error } : {}),
179
- },
180
- opts,
181
- )
182
- } finally {
183
- await destroy()
184
- }
185
- }
186
-
187
- async function opnsMineStatus(
188
- args: string[],
189
- opts: GlobalFlags,
190
- ): Promise<void> {
191
- const jobId = extractFlag(args, '--job')
192
- const serviceUrl = extractFlag(args, '--service')
193
-
194
- if (!jobId) fatal('Missing --job <paymentTxid>')
195
- if (!serviceUrl) fatal('Missing --service <url>')
196
-
197
- const privateKey = await loadKey()
198
- const { ctx, destroy } = await loadContext(privateKey, {
199
- chain: opts.chain,
200
- })
201
-
202
- try {
203
- const result = await opnsMineStatusAction.execute(ctx, {
204
- jobId,
205
- serviceUrl,
206
- })
207
- if (result.error && !result.state) {
208
- fatal(result.error)
209
- }
210
- output(result, opts)
211
- } finally {
212
- await destroy()
213
- }
214
- }
215
-
216
- async function opnsMineRefund(
217
- args: string[],
218
- opts: GlobalFlags,
219
- ): Promise<void> {
220
- const jobId = extractFlag(args, '--job')
221
- const serviceUrl = extractFlag(args, '--service')
222
-
223
- if (!jobId) fatal('Missing --job <paymentTxid>')
224
- if (!serviceUrl) fatal('Missing --service <url>')
225
-
226
- const privateKey = await loadKey()
227
- const { ctx, destroy } = await loadContext(privateKey, {
228
- chain: opts.chain,
229
- })
230
-
231
- try {
232
- const result = await opnsMineRefundAction.execute(ctx, {
233
- jobId,
234
- serviceUrl,
235
- })
236
- if (result.error) {
237
- fatal(result.error)
238
- }
239
- output(result, opts)
240
- } finally {
241
- await destroy()
242
- }
243
- }
244
-
245
129
  async function opnsLookup(_args: string[], opts: GlobalFlags): Promise<void> {
246
130
  const privateKey = await loadKey()
247
131
  const { ctx, destroy } = await loadContext(privateKey, {
package/src/help.ts CHANGED
@@ -62,6 +62,12 @@ export const GLOBAL_OPTIONS: ArgSpec[] = [
62
62
  values: '<main|test>',
63
63
  description: 'Network (default: main)',
64
64
  },
65
+ {
66
+ flag: '--env-file',
67
+ values: '<path>',
68
+ description:
69
+ 'Load env vars from a file (repeatable; file values override existing env)',
70
+ },
65
71
  { flag: '--help', description: 'Show help (also -h)' },
66
72
  { flag: '--version', description: 'Show version (also -v)' },
67
73
  ]
@@ -503,32 +509,6 @@ export const COMMANDS: CommandSpec[] = [
503
509
  args: [{ flag: '--outpoint', values: '<txid.vout>', required: true }],
504
510
  },
505
511
  { name: 'lookup', description: 'List OpNS names from wallet' },
506
- {
507
- name: 'mine',
508
- description: 'Pay a mine service to mine a name into this wallet',
509
- args: [
510
- { flag: '--name', values: '<name>', required: true },
511
- { flag: '--service', values: '<url>', required: true },
512
- { flag: '--receive-address', values: '<addr>' },
513
- { flag: '--timeout', values: '<ms>' },
514
- ],
515
- },
516
- {
517
- name: 'mine-status',
518
- description: 'Check a mine job; internalize the name if complete',
519
- args: [
520
- { flag: '--job', values: '<paymentTxid>', required: true },
521
- { flag: '--service', values: '<url>', required: true },
522
- ],
523
- },
524
- {
525
- name: 'mine-refund',
526
- description: 'Claim the remaining funds of a failed mine job',
527
- args: [
528
- { flag: '--job', values: '<paymentTxid>', required: true },
529
- { flag: '--service', values: '<url>', required: true },
530
- ],
531
- },
532
512
  ],
533
513
  },
534
514