@1sat/cli 0.0.132 → 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
@@ -4,11 +4,11 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
4
4
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
5
 
6
6
  // src/args.ts
7
- function parseGlobalFlags(args) {
7
+ function parseGlobalFlags(args, defaultChain = "main") {
8
8
  let json = false;
9
9
  let quiet = false;
10
10
  let yes = false;
11
- let chain = "main";
11
+ let chain = defaultChain;
12
12
  let help = false;
13
13
  let version = false;
14
14
  const envFiles = [];
@@ -2191,7 +2191,7 @@ async function handleInitCommand(_args, opts) {
2191
2191
  if (keySource === "generate") {
2192
2192
  const pk2 = PrivateKey2.fromRandom();
2193
2193
  wif = pk2.toWif();
2194
- const address2 = pk2.toPublicKey().toAddress();
2194
+ const address2 = pk2.toPublicKey().toAddress(chain === "test" ? "test" : "main");
2195
2195
  console.log();
2196
2196
  console.log(formatWarning(" IMPORTANT: Back up your private key!"));
2197
2197
  console.log(formatWarning(" If you lose it, your funds are gone forever."));
@@ -2253,7 +2253,7 @@ async function handleInitCommand(_args, opts) {
2253
2253
  storageIdentityKey: storageId
2254
2254
  });
2255
2255
  const pk = PrivateKey2.fromWif(wif);
2256
- const address = pk.toPublicKey().toAddress();
2256
+ const address = pk.toPublicKey().toAddress(chain === "test" ? "test" : "main");
2257
2257
  outro(formatSuccess(`Wallet configured! Address: ${address}`));
2258
2258
  console.log();
2259
2259
  console.log(` Want hosted storage? Run ${formatValue("1sat remote add <url>")} to attach a backup remote,`);
@@ -4259,7 +4259,7 @@ async function resolveServe(opts) {
4259
4259
  fatal("server.storage.provider is pg but server.storage.dbUrl is not set. " + "Set it with: 1sat config set server.storage.dbUrl postgres://…");
4260
4260
  }
4261
4261
  const dataDir = ensureDataDir();
4262
- const chain = opts.chain ?? config.chain ?? "main";
4262
+ const chain = opts.chain;
4263
4263
  let privateKey;
4264
4264
  try {
4265
4265
  privateKey = await loadKey();
@@ -4685,7 +4685,7 @@ function parseWindow(raw) {
4685
4685
  }
4686
4686
  async function openServeStorage(opts) {
4687
4687
  const config = loadConfig();
4688
- const chain = opts.chain ?? config.chain ?? "main";
4688
+ const chain = opts.chain;
4689
4689
  const storageConfig = config.server?.storage ?? { provider: "bun-sqlite" };
4690
4690
  const baseOptions = StorageProvider2.createStorageBaseOptions(chain);
4691
4691
  let storage;
@@ -4869,13 +4869,13 @@ async function handleSweepCommand(args, opts) {
4869
4869
  }
4870
4870
  }
4871
4871
  }
4872
- function loadSweepKey(args) {
4872
+ function loadSweepKey(args, chain) {
4873
4873
  const wif = extractFlag(args, "--wif");
4874
4874
  if (!wif)
4875
4875
  fatal("Missing --wif <private-key>");
4876
4876
  try {
4877
4877
  const pk = PrivateKey4.fromWif(wif);
4878
- return { wif, address: pk.toPublicKey().toAddress() };
4878
+ return { wif, address: pk.toPublicKey().toAddress(chain) };
4879
4879
  } catch {
4880
4880
  fatal("Invalid WIF private key");
4881
4881
  }
@@ -4958,7 +4958,7 @@ function printInventory(address, plan, opts, mode) {
4958
4958
  ${transferable} transferable UTXO(s) in selected classes.`);
4959
4959
  }
4960
4960
  async function sweepScan(args, opts) {
4961
- const { address } = loadSweepKey(args);
4961
+ const { address } = loadSweepKey(args, opts.chain);
4962
4962
  const classes = loadClasses(args);
4963
4963
  const privateKey = await loadKey();
4964
4964
  const { ctx, destroy } = await loadContext(privateKey, {
@@ -4974,7 +4974,7 @@ async function sweepScan(args, opts) {
4974
4974
  }
4975
4975
  }
4976
4976
  async function sweepImport(args, opts) {
4977
- const { wif, address } = loadSweepKey(args);
4977
+ const { wif, address } = loadSweepKey(args, opts.chain);
4978
4978
  const classes = loadClasses(args);
4979
4979
  const dryRun = hasFlag(args, "--dry-run");
4980
4980
  const sweepKey = PrivateKey4.fromWif(wif);
@@ -6065,7 +6065,7 @@ function applyEnvFiles(paths) {
6065
6065
  }
6066
6066
  }
6067
6067
  async function main() {
6068
- const flags = parseGlobalFlags(rawArgs);
6068
+ const flags = parseGlobalFlags(rawArgs, loadConfig().chain);
6069
6069
  if (flags.envFiles.length > 0) {
6070
6070
  applyEnvFiles(flags.envFiles);
6071
6071
  }
@@ -6178,6 +6178,7 @@ var init_main = __esm(() => {
6178
6178
  init_tokens();
6179
6179
  init_tx();
6180
6180
  init_wallet();
6181
+ init_config();
6181
6182
  init_help();
6182
6183
  init_monitor_once();
6183
6184
  init_output();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/cli",
3
- "version": "0.0.132",
3
+ "version": "0.0.133",
4
4
  "description": "CLI for 1Sat Ordinals SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/cli.js",
@@ -27,12 +27,12 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@1sat/actions": "0.0.234",
31
- "@1sat/client": "0.0.63",
32
- "@1sat/types": "0.0.52",
33
- "@1sat/wallet": "0.0.120",
34
- "@1sat/wallet-node": "0.0.87",
35
- "@1sat/wallet-server": "0.0.65",
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
38
  "@bsv/wallet-toolbox": "npm:@bopen-io/wallet-toolbox@2.14.8",
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
  }