@1sat/cli 0.0.99 → 0.0.101

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/cli",
3
- "version": "0.0.99",
3
+ "version": "0.0.101",
4
4
  "description": "CLI for 1Sat Ordinals SDK",
5
5
  "type": "module",
6
6
  "main": "./src/cli.ts",
@@ -26,13 +26,13 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@1sat/actions": "0.0.197",
30
- "@1sat/client": "0.0.49",
31
- "@1sat/types": "0.0.39",
32
- "@1sat/wallet-node": "0.0.69",
33
- "@1sat/wallet-server": "0.0.45",
29
+ "@1sat/actions": "0.0.199",
30
+ "@1sat/client": "0.0.50",
31
+ "@1sat/types": "0.0.40",
32
+ "@1sat/wallet-node": "0.0.70",
33
+ "@1sat/wallet-server": "0.0.46",
34
34
  "@bsv/sdk": "^2.1.9",
35
- "@bsv/wallet-toolbox": "2.4.4",
35
+ "@bsv/wallet-toolbox": "npm:@bopen-io/wallet-toolbox@2.6.2-brc153.5",
36
36
  "chalk": "^5.0.0",
37
37
  "@clack/prompts": "^0.8.0",
38
38
  "bitcoin-backup": "^0.0.11",
@@ -5,10 +5,13 @@
5
5
 
6
6
  import {
7
7
  deriveDepositAddresses,
8
+ migrateLegacyP1SatBaskets,
9
+ moveBasketOutputs,
8
10
  sendAllBsv,
9
11
  sendBsv,
10
12
  syncAddresses,
11
13
  } from '@1sat/actions'
14
+ import type { WalletInterface } from '@bsv/sdk'
12
15
  import { confirm, isCancel } from '@clack/prompts'
13
16
  import type { GlobalFlags } from '../args'
14
17
  import { extractFlag, extractFlags } from '../args'
@@ -17,6 +20,31 @@ import { printCommandHelp } from '../help'
17
20
  import { loadKey } from '../keys'
18
21
  import { fatal, formatValue, output, printKeyValue } from '../output'
19
22
 
23
+ /**
24
+ * BRC-100 methods reached by passing the method's own args as one JSON
25
+ * argument. The commands above wrap the handful that benefit from flags and
26
+ * formatting; these keep the rest of the interface reachable rather than
27
+ * leaving it to one-off scripts.
28
+ */
29
+ const PASSTHROUGH_METHODS = {
30
+ 'get-public-key': 'getPublicKey',
31
+ encrypt: 'encrypt',
32
+ decrypt: 'decrypt',
33
+ 'create-hmac': 'createHmac',
34
+ 'verify-hmac': 'verifyHmac',
35
+ 'create-signature': 'createSignature',
36
+ 'verify-signature': 'verifySignature',
37
+ 'internalize-action': 'internalizeAction',
38
+ 'acquire-certificate': 'acquireCertificate',
39
+ 'prove-certificate': 'proveCertificate',
40
+ 'discover-by-identity-key': 'discoverByIdentityKey',
41
+ 'discover-by-attributes': 'discoverByAttributes',
42
+ 'get-height': 'getHeight',
43
+ 'get-header-for-height': 'getHeaderForHeight',
44
+ 'get-network': 'getNetwork',
45
+ 'get-version': 'getVersion',
46
+ } as const satisfies Record<string, keyof WalletInterface>
47
+
20
48
  export async function handleWalletCommand(
21
49
  args: string[],
22
50
  opts: GlobalFlags,
@@ -40,6 +68,10 @@ export async function handleWalletCommand(
40
68
  return walletListOutputs(rest, opts)
41
69
  case 'relinquish-output':
42
70
  return walletRelinquishOutput(rest, opts)
71
+ case 'move-basket':
72
+ return walletMoveBasket(rest, opts)
73
+ case 'migrate-baskets':
74
+ return walletMigrateBaskets(rest, opts)
43
75
  case 'list-actions':
44
76
  return walletListActions(rest, opts)
45
77
  case 'create-action':
@@ -52,11 +84,44 @@ export async function handleWalletCommand(
52
84
  return walletListCertificates(rest, opts)
53
85
  case 'relinquish-certificate':
54
86
  return walletRelinquishCertificate(rest, opts)
55
- default:
87
+ default: {
88
+ const method =
89
+ PASSTHROUGH_METHODS[subcommand as keyof typeof PASSTHROUGH_METHODS]
90
+ if (method) return walletPassthrough(method, rest, opts)
56
91
  printCommandHelp('wallet', opts.json)
57
92
  if (subcommand && subcommand !== 'help') {
58
93
  process.exit(1)
59
94
  }
95
+ }
96
+ }
97
+ }
98
+
99
+ /** Calls a BRC-100 method with parsed JSON args; no args means `{}`. */
100
+ async function walletPassthrough(
101
+ method: keyof WalletInterface,
102
+ args: string[],
103
+ opts: GlobalFlags,
104
+ ): Promise<void> {
105
+ const jsonInput = args[0]
106
+ let methodArgs: unknown = {}
107
+ if (jsonInput) {
108
+ try {
109
+ methodArgs = JSON.parse(jsonInput)
110
+ } catch {
111
+ fatal(`Invalid JSON: ${jsonInput}`)
112
+ }
113
+ }
114
+
115
+ const privateKey = await loadKey()
116
+ const { ctx, destroy } = await loadContext(privateKey, {
117
+ chain: opts.chain,
118
+ })
119
+
120
+ try {
121
+ const call = ctx.wallet[method] as (a: unknown) => Promise<unknown>
122
+ output(await call.call(ctx.wallet, methodArgs), opts)
123
+ } finally {
124
+ await destroy()
60
125
  }
61
126
  }
62
127
 
@@ -426,6 +491,58 @@ async function walletRelinquishOutput(
426
491
  }
427
492
  }
428
493
 
494
+ async function walletMoveBasket(
495
+ args: string[],
496
+ opts: GlobalFlags,
497
+ ): Promise<void> {
498
+ const from = extractFlag(args, '--from')
499
+ const to = extractFlag(args, '--to')
500
+ if (!from) fatal('Missing required --from <basket>')
501
+ if (!to) fatal('Missing required --to <basket>')
502
+
503
+ const privateKey = await loadKey()
504
+ const { ctx, destroy } = await loadContext(privateKey, {
505
+ chain: opts.chain,
506
+ })
507
+ try {
508
+ const result = await moveBasketOutputs(ctx.wallet, from, to)
509
+ output(result, opts)
510
+ } finally {
511
+ await destroy()
512
+ }
513
+ }
514
+
515
+ async function walletMigrateBaskets(
516
+ args: string[],
517
+ opts: GlobalFlags,
518
+ ): Promise<void> {
519
+ void args
520
+ const privateKey = await loadKey()
521
+ const { ctx, destroy } = await loadContext(privateKey, {
522
+ chain: opts.chain,
523
+ })
524
+ try {
525
+ const result = await migrateLegacyP1SatBaskets(ctx.wallet)
526
+ if (opts.json) {
527
+ output(result, opts)
528
+ } else {
529
+ console.log(`Moved ${result.totalMoved} output(s) across legacy baskets\n`)
530
+ for (const r of result.results) {
531
+ if (r.moved === 0 && r.errors.length === 0) continue
532
+ console.log(
533
+ ` ${r.from} → ${r.to}: moved ${r.moved}` +
534
+ (r.skipped ? `, skipped ${r.skipped}` : ''),
535
+ )
536
+ for (const e of r.errors) {
537
+ console.log(` ! ${e.outpoint}: ${e.error}`)
538
+ }
539
+ }
540
+ }
541
+ } finally {
542
+ await destroy()
543
+ }
544
+ }
545
+
429
546
  async function walletListActions(
430
547
  args: string[],
431
548
  opts: GlobalFlags,
package/src/help.ts CHANGED
@@ -267,6 +267,75 @@ export const COMMANDS: CommandSpec[] = [
267
267
  { flag: '--certifier', values: '<c>', required: true },
268
268
  ],
269
269
  },
270
+ {
271
+ name: 'get-public-key',
272
+ description: 'Derive a public key (BRC-100)',
273
+ positional: "'<json>'",
274
+ },
275
+ {
276
+ name: 'encrypt',
277
+ description: 'Encrypt to a counterparty (BRC-100)',
278
+ positional: "'<json>'",
279
+ },
280
+ {
281
+ name: 'decrypt',
282
+ description: 'Decrypt from a counterparty (BRC-100)',
283
+ positional: "'<json>'",
284
+ },
285
+ {
286
+ name: 'create-hmac',
287
+ description: 'Create an HMAC (BRC-100)',
288
+ positional: "'<json>'",
289
+ },
290
+ {
291
+ name: 'verify-hmac',
292
+ description: 'Verify an HMAC (BRC-100)',
293
+ positional: "'<json>'",
294
+ },
295
+ {
296
+ name: 'create-signature',
297
+ description: 'Create a signature (BRC-100)',
298
+ positional: "'<json>'",
299
+ },
300
+ {
301
+ name: 'verify-signature',
302
+ description: 'Verify a signature (BRC-100)',
303
+ positional: "'<json>'",
304
+ },
305
+ {
306
+ name: 'internalize-action',
307
+ description:
308
+ 'Take ownership of an output — wallet payment or basket insertion (BRC-100)',
309
+ positional: "'<json>'",
310
+ },
311
+ {
312
+ name: 'acquire-certificate',
313
+ description: 'Acquire a certificate (BRC-100)',
314
+ positional: "'<json>'",
315
+ },
316
+ {
317
+ name: 'prove-certificate',
318
+ description: 'Prove fields of a certificate (BRC-100)',
319
+ positional: "'<json>'",
320
+ },
321
+ {
322
+ name: 'discover-by-identity-key',
323
+ description: 'Discover certificates by identity key (BRC-100)',
324
+ positional: "'<json>'",
325
+ },
326
+ {
327
+ name: 'discover-by-attributes',
328
+ description: 'Discover certificates by attributes (BRC-100)',
329
+ positional: "'<json>'",
330
+ },
331
+ { name: 'get-height', description: 'Current block height (BRC-100)' },
332
+ {
333
+ name: 'get-header-for-height',
334
+ description: 'Block header at a height (BRC-100)',
335
+ positional: "'<json>'",
336
+ },
337
+ { name: 'get-network', description: 'Wallet network (BRC-100)' },
338
+ { name: 'get-version', description: 'Wallet version (BRC-100)' },
270
339
  ],
271
340
  },
272
341