@1sat/cli 0.0.131 → 0.0.133

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/cli.js CHANGED
@@ -1,22 +1,14 @@
1
1
  #!/usr/bin/env node
2
- var __esm = (fn, res, err) => () => {
3
- if (fn)
4
- try {
5
- res = fn(fn = 0);
6
- } catch (e) {
7
- err = [e];
8
- }
9
- if (err)
10
- throw err[0];
11
- return res;
12
- };
2
+ import { createRequire } from "node:module";
3
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
4
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
13
5
 
14
6
  // src/args.ts
15
- function parseGlobalFlags(args) {
7
+ function parseGlobalFlags(args, defaultChain = "main") {
16
8
  let json = false;
17
9
  let quiet = false;
18
10
  let yes = false;
19
- let chain = "main";
11
+ let chain = defaultChain;
20
12
  let help = false;
21
13
  let version = false;
22
14
  const envFiles = [];
@@ -630,11 +622,11 @@ async function handleActionCommand(args, opts) {
630
622
  Registered actions:
631
623
  `);
632
624
  const grouped = new Map;
633
- for (const action of actions) {
634
- const cat = action.meta.category;
625
+ for (const action2 of actions) {
626
+ const cat = action2.meta.category;
635
627
  if (!grouped.has(cat))
636
628
  grouped.set(cat, []);
637
- grouped.get(cat).push(action);
629
+ grouped.get(cat).push(action2);
638
630
  }
639
631
  for (const [category, categoryActions] of grouped) {
640
632
  console.log(` ${category}:`);
@@ -1673,7 +1665,7 @@ function createApprovalAuth(wallet) {
1673
1665
  get(target, property) {
1674
1666
  if (property === "createAction")
1675
1667
  return async (...args) => {
1676
- const satoshis = args[0].outputs?.reduce((sum, output) => sum + output.satoshis, 0) ?? 0;
1668
+ const satoshis = args[0].outputs?.reduce((sum, output2) => sum + output2.satoshis, 0) ?? 0;
1677
1669
  if (!Number.isSafeInteger(satoshis) || satoshis <= 0)
1678
1670
  throw new Error("Invalid HTTP payment amount");
1679
1671
  if (approved === false)
@@ -2197,15 +2189,15 @@ async function handleInitCommand(_args, opts) {
2197
2189
  }
2198
2190
  let wif;
2199
2191
  if (keySource === "generate") {
2200
- const pk = PrivateKey2.fromRandom();
2201
- wif = pk.toWif();
2202
- const address = pk.toPublicKey().toAddress();
2192
+ const pk2 = PrivateKey2.fromRandom();
2193
+ wif = pk2.toWif();
2194
+ const address2 = pk2.toPublicKey().toAddress(chain === "test" ? "test" : "main");
2203
2195
  console.log();
2204
2196
  console.log(formatWarning(" IMPORTANT: Back up your private key!"));
2205
2197
  console.log(formatWarning(" If you lose it, your funds are gone forever."));
2206
2198
  console.log();
2207
2199
  console.log(` ${formatValue("WIF:")} ${wif}`);
2208
- console.log(` ${formatValue("Address:")} ${address}`);
2200
+ console.log(` ${formatValue("Address:")} ${address2}`);
2209
2201
  console.log();
2210
2202
  const confirmed = await confirm2({
2211
2203
  message: "Have you saved your private key somewhere safe?"
@@ -2261,7 +2253,7 @@ async function handleInitCommand(_args, opts) {
2261
2253
  storageIdentityKey: storageId
2262
2254
  });
2263
2255
  const pk = PrivateKey2.fromWif(wif);
2264
- const address = pk.toPublicKey().toAddress();
2256
+ const address = pk.toPublicKey().toAddress(chain === "test" ? "test" : "main");
2265
2257
  outro(formatSuccess(`Wallet configured! Address: ${address}`));
2266
2258
  console.log();
2267
2259
  console.log(` Want hosted storage? Run ${formatValue("1sat remote add <url>")} to attach a backup remote,`);
@@ -3538,12 +3530,12 @@ async function permissionsRevoke(args, opts) {
3538
3530
  const originator = normalizeOriginator2(origin);
3539
3531
  const { store, path } = openStore(opts);
3540
3532
  if (hasFlag(args, "--all")) {
3541
- const removed = await store.deleteAllForOriginator(originator);
3533
+ const removed2 = await store.deleteAllForOriginator(originator);
3542
3534
  if (opts.json) {
3543
- output({ originator, removed, store: path }, opts);
3535
+ output({ originator, removed: removed2, store: path }, opts);
3544
3536
  return;
3545
3537
  }
3546
- output(`revoked ${removed} grant(s) for ${originator}`, opts);
3538
+ output(`revoked ${removed2} grant(s) for ${originator}`, opts);
3547
3539
  return;
3548
3540
  }
3549
3541
  let specs;
@@ -4267,7 +4259,7 @@ async function resolveServe(opts) {
4267
4259
  fatal("server.storage.provider is pg but server.storage.dbUrl is not set. " + "Set it with: 1sat config set server.storage.dbUrl postgres://…");
4268
4260
  }
4269
4261
  const dataDir = ensureDataDir();
4270
- const chain = opts.chain ?? config.chain ?? "main";
4262
+ const chain = opts.chain;
4271
4263
  let privateKey;
4272
4264
  try {
4273
4265
  privateKey = await loadKey();
@@ -4693,7 +4685,7 @@ function parseWindow(raw) {
4693
4685
  }
4694
4686
  async function openServeStorage(opts) {
4695
4687
  const config = loadConfig();
4696
- const chain = opts.chain ?? config.chain ?? "main";
4688
+ const chain = opts.chain;
4697
4689
  const storageConfig = config.server?.storage ?? { provider: "bun-sqlite" };
4698
4690
  const baseOptions = StorageProvider2.createStorageBaseOptions(chain);
4699
4691
  let storage;
@@ -4739,11 +4731,11 @@ function selectedSweepClasses(only, skip) {
4739
4731
  throw new Error("--only and --skip are mutually exclusive");
4740
4732
  }
4741
4733
  if (only) {
4742
- const selected = parseSweepClasses(only, "--only");
4743
- if (selected.size === 0) {
4734
+ const selected2 = parseSweepClasses(only, "--only");
4735
+ if (selected2.size === 0) {
4744
4736
  throw new Error("--only requires at least one class");
4745
4737
  }
4746
- return selected;
4738
+ return selected2;
4747
4739
  }
4748
4740
  const selected = new Set(SWEEP_CLASSES);
4749
4741
  if (skip) {
@@ -4877,13 +4869,13 @@ async function handleSweepCommand(args, opts) {
4877
4869
  }
4878
4870
  }
4879
4871
  }
4880
- function loadSweepKey(args) {
4872
+ function loadSweepKey(args, chain) {
4881
4873
  const wif = extractFlag(args, "--wif");
4882
4874
  if (!wif)
4883
4875
  fatal("Missing --wif <private-key>");
4884
4876
  try {
4885
4877
  const pk = PrivateKey4.fromWif(wif);
4886
- return { wif, address: pk.toPublicKey().toAddress() };
4878
+ return { wif, address: pk.toPublicKey().toAddress(chain) };
4887
4879
  } catch {
4888
4880
  fatal("Invalid WIF private key");
4889
4881
  }
@@ -4966,7 +4958,7 @@ function printInventory(address, plan, opts, mode) {
4966
4958
  ${transferable} transferable UTXO(s) in selected classes.`);
4967
4959
  }
4968
4960
  async function sweepScan(args, opts) {
4969
- const { address } = loadSweepKey(args);
4961
+ const { address } = loadSweepKey(args, opts.chain);
4970
4962
  const classes = loadClasses(args);
4971
4963
  const privateKey = await loadKey();
4972
4964
  const { ctx, destroy } = await loadContext(privateKey, {
@@ -4982,7 +4974,7 @@ async function sweepScan(args, opts) {
4982
4974
  }
4983
4975
  }
4984
4976
  async function sweepImport(args, opts) {
4985
- const { wif, address } = loadSweepKey(args);
4977
+ const { wif, address } = loadSweepKey(args, opts.chain);
4986
4978
  const classes = loadClasses(args);
4987
4979
  const dryRun = hasFlag(args, "--dry-run");
4988
4980
  const sweepKey = PrivateKey4.fromWif(wif);
@@ -5840,8 +5832,8 @@ async function walletListOutputs(args, opts) {
5840
5832
  ${result.totalOutputs} total outputs in basket '${basket}':
5841
5833
  `);
5842
5834
  for (const out of result.outputs) {
5843
- const tags = out.tags?.join(", ") || "none";
5844
- console.log(` ${out.outpoint} | ${out.satoshis} sats | tags: ${tags}`);
5835
+ const tags2 = out.tags?.join(", ") || "none";
5836
+ console.log(` ${out.outpoint} | ${out.satoshis} sats | tags: ${tags2}`);
5845
5837
  }
5846
5838
  console.log();
5847
5839
  }
@@ -6056,6 +6048,7 @@ var init_wallet = __esm(() => {
6056
6048
  });
6057
6049
 
6058
6050
  // src/main.ts
6051
+ var exports_main = {};
6059
6052
  import { existsSync as existsSync5 } from "node:fs";
6060
6053
  import { resolve } from "node:path";
6061
6054
  import { config as loadEnv } from "dotenv";
@@ -6072,7 +6065,7 @@ function applyEnvFiles(paths) {
6072
6065
  }
6073
6066
  }
6074
6067
  async function main() {
6075
- const flags = parseGlobalFlags(rawArgs);
6068
+ const flags = parseGlobalFlags(rawArgs, loadConfig().chain);
6076
6069
  if (flags.envFiles.length > 0) {
6077
6070
  applyEnvFiles(flags.envFiles);
6078
6071
  }
@@ -6185,6 +6178,7 @@ var init_main = __esm(() => {
6185
6178
  init_tokens();
6186
6179
  init_tx();
6187
6180
  init_wallet();
6181
+ init_config();
6188
6182
  init_help();
6189
6183
  init_monitor_once();
6190
6184
  init_output();
@@ -6199,4 +6193,4 @@ var init_main = __esm(() => {
6199
6193
 
6200
6194
  // src/cli.ts
6201
6195
  process.env.DOTENV_CONFIG_QUIET = "true";
6202
- await Promise.resolve().then(() => (init_main(), {}));
6196
+ await Promise.resolve().then(() => (init_main(), exports_main));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/cli",
3
- "version": "0.0.131",
3
+ "version": "0.0.133",
4
4
  "description": "CLI for 1Sat Ordinals SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/cli.js",
@@ -27,16 +27,16 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@1sat/actions": "0.0.233",
31
- "@1sat/client": "0.0.62",
32
- "@1sat/types": "0.0.52",
33
- "@1sat/wallet": "0.0.119",
34
- "@1sat/wallet-node": "0.0.86",
35
- "@1sat/wallet-server": "0.0.64",
30
+ "@1sat/actions": "0.0.235",
31
+ "@1sat/client": "0.0.64",
32
+ "@1sat/types": "0.0.53",
33
+ "@1sat/wallet": "0.0.121",
34
+ "@1sat/wallet-node": "0.0.88",
35
+ "@1sat/wallet-server": "0.0.66",
36
36
  "@bopen-io/messagebox-server": "^1.3.2",
37
37
  "@bsv/sdk": "^2.6.0",
38
- "@bsv/wallet-toolbox": "npm:@bopen-io/wallet-toolbox@2.14.7",
39
- "@bsv/wallet-toolbox-client": "npm:@bopen-io/wallet-toolbox-client@2.14.7",
38
+ "@bsv/wallet-toolbox": "npm:@bopen-io/wallet-toolbox@2.14.8",
39
+ "@bsv/wallet-toolbox-client": "npm:@bopen-io/wallet-toolbox-client@2.14.8",
40
40
  "@clack/prompts": "^0.8.0",
41
41
  "bitcoin-backup": "^0.0.11",
42
42
  "chalk": "^5.0.0",
package/src/args.ts CHANGED
@@ -18,12 +18,16 @@ export interface GlobalFlags {
18
18
 
19
19
  /**
20
20
  * Parse global flags from raw argv, returning structured flags and remaining args.
21
+ * `chain` is `--chain` when given, otherwise `defaultChain` (the configured chain).
21
22
  */
22
- export function parseGlobalFlags(args: string[]): GlobalFlags {
23
+ export function parseGlobalFlags(
24
+ args: string[],
25
+ defaultChain: 'main' | 'test' = 'main',
26
+ ): GlobalFlags {
23
27
  let json = false
24
28
  let quiet = false
25
29
  let yes = false
26
- let chain: 'main' | 'test' = 'main'
30
+ let chain = defaultChain
27
31
  let help = false
28
32
  let version = false
29
33
  const envFiles: string[] = []
@@ -85,7 +85,9 @@ export async function handleInitCommand(
85
85
  if (keySource === 'generate') {
86
86
  const pk = PrivateKey.fromRandom()
87
87
  wif = pk.toWif()
88
- const address = pk.toPublicKey().toAddress()
88
+ const address = pk
89
+ .toPublicKey()
90
+ .toAddress(chain === 'test' ? 'test' : 'main')
89
91
 
90
92
  console.log()
91
93
  console.log(formatWarning(' IMPORTANT: Back up your private key!'))
@@ -159,7 +161,7 @@ export async function handleInitCommand(
159
161
  })
160
162
 
161
163
  const pk = PrivateKey.fromWif(wif)
162
- const address = pk.toPublicKey().toAddress()
164
+ const address = pk.toPublicKey().toAddress(chain === 'test' ? 'test' : 'main')
163
165
 
164
166
  outro(formatSuccess(`Wallet configured! Address: ${address}`))
165
167
 
@@ -163,7 +163,7 @@ async function resolveServe(opts: GlobalFlags): Promise<ResolvedServe> {
163
163
  }
164
164
 
165
165
  const dataDir = ensureDataDir()
166
- const chain = opts.chain ?? config.chain ?? 'main'
166
+ const chain = opts.chain
167
167
 
168
168
  let privateKey: PrivateKey
169
169
  try {
@@ -91,7 +91,7 @@ function parseWindow(raw: string): number | undefined {
91
91
  /** Open the serve wallet's storage exactly as `1sat serve` resolves it. */
92
92
  async function openServeStorage(opts: GlobalFlags): Promise<StorageProvider> {
93
93
  const config = loadConfig()
94
- const chain = opts.chain ?? config.chain ?? 'main'
94
+ const chain = opts.chain
95
95
  const storageConfig = config.server?.storage ?? { provider: 'bun-sqlite' }
96
96
  const baseOptions = StorageProvider.createStorageBaseOptions(chain)
97
97
 
@@ -56,12 +56,15 @@ export async function handleSweepCommand(
56
56
  }
57
57
  }
58
58
 
59
- function loadSweepKey(args: string[]): { wif: string; address: string } {
59
+ function loadSweepKey(
60
+ args: string[],
61
+ chain: 'main' | 'test',
62
+ ): { wif: string; address: string } {
60
63
  const wif = extractFlag(args, '--wif')
61
64
  if (!wif) fatal('Missing --wif <private-key>')
62
65
  try {
63
66
  const pk = PrivateKey.fromWif(wif)
64
- return { wif, address: pk.toPublicKey().toAddress() }
67
+ return { wif, address: pk.toPublicKey().toAddress(chain) }
65
68
  } catch {
66
69
  fatal('Invalid WIF private key')
67
70
  }
@@ -174,7 +177,7 @@ function printInventory(
174
177
  }
175
178
 
176
179
  async function sweepScan(args: string[], opts: GlobalFlags): Promise<void> {
177
- const { address } = loadSweepKey(args)
180
+ const { address } = loadSweepKey(args, opts.chain)
178
181
  const classes = loadClasses(args)
179
182
 
180
183
  const privateKey = await loadKey()
@@ -192,7 +195,7 @@ async function sweepScan(args: string[], opts: GlobalFlags): Promise<void> {
192
195
  }
193
196
 
194
197
  async function sweepImport(args: string[], opts: GlobalFlags): Promise<void> {
195
- const { wif, address } = loadSweepKey(args)
198
+ const { wif, address } = loadSweepKey(args, opts.chain)
196
199
  const classes = loadClasses(args)
197
200
  const dryRun = hasFlag(args, '--dry-run')
198
201
  const sweepKey = PrivateKey.fromWif(wif)
package/src/main.ts CHANGED
@@ -30,6 +30,7 @@ import { handleSweepCommand } from './commands/sweep.js'
30
30
  import { handleTokensCommand } from './commands/tokens.js'
31
31
  import { handleTxCommand } from './commands/tx.js'
32
32
  import { handleWalletCommand } from './commands/wallet.js'
33
+ import { loadConfig } from './config.js'
33
34
  import {
34
35
  getCommand,
35
36
  printCommandHelp,
@@ -56,7 +57,7 @@ function applyEnvFiles(paths: string[]): void {
56
57
  }
57
58
 
58
59
  async function main(): Promise<void> {
59
- const flags = parseGlobalFlags(rawArgs)
60
+ const flags = parseGlobalFlags(rawArgs, loadConfig().chain)
60
61
  if (flags.envFiles.length > 0) {
61
62
  applyEnvFiles(flags.envFiles)
62
63
  }