@1sat/cli 0.0.90 → 0.0.91

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.
@@ -1,24 +1,24 @@
1
1
  /**
2
- * Ordinals commands - list, mint, transfer, sell, cancel, buy.
2
+ * Ordinals commands — id-first wallet spends; external buy with outpoint/BEEF.
3
3
  */
4
4
 
5
5
  import { readFileSync } from 'node:fs'
6
6
  import { basename, extname } from 'node:path'
7
7
  import {
8
8
  burnOrdinals,
9
- cancelListing,
10
- deriveDepositAddresses,
9
+ buyOrdinal,
10
+ cancelOrdinalListing,
11
11
  getDisplayValue,
12
- getOrdinals,
13
12
  inscribe,
14
- listOrdinal,
15
- purchaseOrdinal,
16
- transferOrdinals,
13
+ listOrdinals,
14
+ sellOrdinal,
15
+ sendOrdinals,
17
16
  } from '@1sat/actions'
18
17
  import { Utils } from '@bsv/sdk'
19
18
  import { confirm, isCancel } from '@clack/prompts'
20
19
  import type { GlobalFlags } from '../args'
21
- import { extractFlag, extractFlags, hasFlag } from '../args'
20
+ import { extractFlag, hasFlag } from '../args'
21
+ import { idFromTags, parseBeefFlag, parseToFlag } from '../beef'
22
22
  import { loadContext } from '../context'
23
23
  import { printCommandHelp } from '../help'
24
24
  import { loadKey } from '../keys'
@@ -33,10 +33,12 @@ export async function handleOrdinalsCommand(
33
33
  switch (subcommand) {
34
34
  case 'list':
35
35
  return ordinalsList(rest, opts)
36
- case 'mint':
37
- return ordinalsMint(rest, opts)
38
- case 'transfer':
39
- return ordinalsTransfer(rest, opts)
36
+ case 'inscribe':
37
+ case 'mint': // deprecated alias
38
+ return ordinalsInscribe(rest, opts)
39
+ case 'send':
40
+ case 'transfer': // deprecated alias
41
+ return ordinalsSend(rest, opts)
40
42
  case 'sell':
41
43
  return ordinalsSell(rest, opts)
42
44
  case 'cancel':
@@ -53,16 +55,37 @@ export async function handleOrdinalsCommand(
53
55
  }
54
56
  }
55
57
 
56
- async function ordinalsList(_args: string[], opts: GlobalFlags): Promise<void> {
58
+ function requireId(args: string[]): string {
59
+ const id = extractFlag(args, '--id')
60
+ if (!id) fatal('Missing --id <tracking-id>')
61
+ return id
62
+ }
63
+
64
+ async function ordinalsList(args: string[], opts: GlobalFlags): Promise<void> {
65
+ const limit = Number(extractFlag(args, '--limit') ?? '100')
66
+ const offset = Number(extractFlag(args, '--offset') ?? '0')
67
+ const ids = extractFlag(args, '--ids')?.split(',').filter(Boolean)
68
+ const tags = extractFlag(args, '--tags')?.split(',').filter(Boolean)
69
+ const tagQueryMode = extractFlag(args, '--tag-query-mode') as
70
+ | 'all'
71
+ | 'any'
72
+ | undefined
73
+ const include = extractFlag(args, '--include') as
74
+ | 'locking scripts'
75
+ | 'entire transactions'
76
+ | undefined
77
+
57
78
  const privateKey = await loadKey()
58
- const { ctx, destroy } = await loadContext(privateKey, {
59
- chain: opts.chain,
60
- })
79
+ const { ctx, destroy } = await loadContext(privateKey, { chain: opts.chain })
61
80
 
62
81
  try {
63
- const result = await getOrdinals.execute(ctx, {
64
- limit: 100,
65
- offset: 0,
82
+ const result = await listOrdinals.execute(ctx, {
83
+ limit,
84
+ offset,
85
+ ids,
86
+ tags,
87
+ tagQueryMode,
88
+ include,
66
89
  })
67
90
 
68
91
  if (opts.json) {
@@ -76,6 +99,7 @@ async function ordinalsList(_args: string[], opts: GlobalFlags): Promise<void> {
76
99
  }
77
100
 
78
101
  for (const o of result.outputs) {
102
+ const id = idFromTags(o.tags) ?? ''
79
103
  const typeTag =
80
104
  o.tags?.find((t) => t.startsWith('type:'))?.slice(5) ?? 'unknown'
81
105
  const originTag =
@@ -83,7 +107,7 @@ async function ordinalsList(_args: string[], opts: GlobalFlags): Promise<void> {
83
107
  const nameTag = getDisplayValue(o, 'name', 'name') ?? ''
84
108
 
85
109
  console.log(
86
- ` ${formatValue(o.outpoint)} ${formatLabel(typeTag)}${nameTag ? ` ${nameTag}` : ''}${originTag ? ` origin:${originTag}` : ''}`,
110
+ ` ${formatValue(id)} ${formatValue(o.outpoint)} ${formatLabel(typeTag)}${nameTag ? ` ${nameTag}` : ''}${originTag ? ` origin:${originTag}` : ''}`,
87
111
  )
88
112
  }
89
113
 
@@ -114,11 +138,16 @@ const MIME_TYPES: Record<string, string> = {
114
138
  '.pdf': 'application/pdf',
115
139
  }
116
140
 
117
- async function ordinalsMint(args: string[], opts: GlobalFlags): Promise<void> {
141
+ async function ordinalsInscribe(
142
+ args: string[],
143
+ opts: GlobalFlags,
144
+ ): Promise<void> {
118
145
  const file = extractFlag(args, '--file')
119
146
  const type = extractFlag(args, '--type')
120
147
  const mapStr = extractFlag(args, '--map')
121
148
  const signWithBAP = hasFlag(args, '--sign-with-bap')
149
+ const stream = hasFlag(args, '--stream')
150
+ const streamChunkSize = extractFlag(args, '--stream-chunk-size')
122
151
 
123
152
  if (!file) fatal('Missing --file <path>')
124
153
 
@@ -165,15 +194,11 @@ async function ordinalsMint(args: string[], opts: GlobalFlags): Promise<void> {
165
194
  const ok = await confirm({
166
195
  message: `Inscribe ${basename(file)} (${contentType}, ${fileBytes.length} bytes)?`,
167
196
  })
168
- if (isCancel(ok) || !ok) {
169
- fatal('Inscription cancelled.')
170
- }
197
+ if (isCancel(ok) || !ok) fatal('Inscription cancelled.')
171
198
  }
172
199
 
173
200
  const privateKey = await loadKey()
174
- const { ctx, destroy } = await loadContext(privateKey, {
175
- chain: opts.chain,
176
- })
201
+ const { ctx, destroy } = await loadContext(privateKey, { chain: opts.chain })
177
202
 
178
203
  try {
179
204
  const result = await inscribe.execute(ctx, {
@@ -181,59 +206,39 @@ async function ordinalsMint(args: string[], opts: GlobalFlags): Promise<void> {
181
206
  contentType,
182
207
  ...(map ? { map } : {}),
183
208
  ...(signWithBAP ? { signWithBAP: true } : {}),
209
+ ...(stream ? { stream: true } : {}),
210
+ ...(streamChunkSize ? { streamChunkSize: Number(streamChunkSize) } : {}),
184
211
  })
185
212
 
186
- if (result.error) {
187
- fatal(result.error)
188
- }
189
-
213
+ if (result.error) fatal(result.error)
190
214
  output(opts.json ? result : { txid: result.txid }, opts)
191
215
  } finally {
192
216
  await destroy()
193
217
  }
194
218
  }
195
219
 
196
- async function ordinalsTransfer(
197
- args: string[],
198
- opts: GlobalFlags,
199
- ): Promise<void> {
200
- const outpoint = extractFlag(args, '--outpoint')
220
+ async function ordinalsSend(args: string[], opts: GlobalFlags): Promise<void> {
221
+ const id = requireId(args)
201
222
  const to = extractFlag(args, '--to')
223
+ if (!to) fatal('Missing --to <address|identityKey>')
202
224
 
203
- if (!outpoint) fatal('Missing --outpoint <txid.vout>')
204
- if (!to) fatal('Missing --to <address>')
225
+ const dest = parseToFlag(to)
205
226
 
206
227
  if (!opts.yes) {
207
228
  const ok = await confirm({
208
- message: `Transfer ordinal ${outpoint} to ${to}?`,
229
+ message: `Send ordinal id ${id} to ${to}?`,
209
230
  })
210
- if (isCancel(ok) || !ok) {
211
- fatal('Transfer cancelled.')
212
- }
231
+ if (isCancel(ok) || !ok) fatal('Send cancelled.')
213
232
  }
214
233
 
215
234
  const privateKey = await loadKey()
216
- const { ctx, destroy } = await loadContext(privateKey, {
217
- chain: opts.chain,
218
- })
235
+ const { ctx, destroy } = await loadContext(privateKey, { chain: opts.chain })
219
236
 
220
237
  try {
221
- // Look up the ordinal from the wallet
222
- const ordinalsResult = await getOrdinals.execute(ctx, { limit: 10000 })
223
- const ordinal = ordinalsResult.outputs.find((o) => o.outpoint === outpoint)
224
- if (!ordinal) {
225
- fatal(`Ordinal not found in wallet: ${outpoint}`)
226
- }
227
-
228
- const result = await transferOrdinals.execute(ctx, {
229
- transfers: [{ ordinal, address: to }],
230
- inputBEEF: ordinalsResult.BEEF as number[] | undefined,
238
+ const result = await sendOrdinals.execute(ctx, {
239
+ transfers: [{ id, ...dest }],
231
240
  })
232
-
233
- if (result.error) {
234
- fatal(result.error)
235
- }
236
-
241
+ if (result.error) fatal(result.error)
237
242
  output(opts.json ? result : { txid: result.txid }, opts)
238
243
  } finally {
239
244
  await destroy()
@@ -241,12 +246,11 @@ async function ordinalsTransfer(
241
246
  }
242
247
 
243
248
  async function ordinalsSell(args: string[], opts: GlobalFlags): Promise<void> {
244
- const outpoint = extractFlag(args, '--outpoint')
249
+ const id = requireId(args)
245
250
  const priceStr = extractFlag(args, '--price')
251
+ const payAddress = extractFlag(args, '--pay-address')
246
252
 
247
- if (!outpoint) fatal('Missing --outpoint <txid.vout>')
248
253
  if (!priceStr) fatal('Missing --price <satoshis>')
249
-
250
254
  const price = Number(priceStr)
251
255
  if (!Number.isFinite(price) || price <= 0) {
252
256
  fatal('--price must be a positive number')
@@ -254,47 +258,21 @@ async function ordinalsSell(args: string[], opts: GlobalFlags): Promise<void> {
254
258
 
255
259
  if (!opts.yes) {
256
260
  const ok = await confirm({
257
- message: `List ordinal ${outpoint} for sale at ${price} satoshis?`,
261
+ message: `List ordinal id ${id} for sale at ${price} satoshis?`,
258
262
  })
259
- if (isCancel(ok) || !ok) {
260
- fatal('Listing cancelled.')
261
- }
263
+ if (isCancel(ok) || !ok) fatal('Listing cancelled.')
262
264
  }
263
265
 
264
266
  const privateKey = await loadKey()
265
- const { ctx, destroy } = await loadContext(privateKey, {
266
- chain: opts.chain,
267
- })
267
+ const { ctx, destroy } = await loadContext(privateKey, { chain: opts.chain })
268
268
 
269
269
  try {
270
- // Look up the ordinal from the wallet
271
- const ordinalsResult = await getOrdinals.execute(ctx, { limit: 10000 })
272
- const ordinal = ordinalsResult.outputs.find((o) => o.outpoint === outpoint)
273
- if (!ordinal) {
274
- fatal(`Ordinal not found in wallet: ${outpoint}`)
275
- }
276
-
277
- // Derive a BRC-29 address to receive payment
278
- const addressResult = await deriveDepositAddresses.execute(ctx, {
279
- prefix: '1sat',
280
- count: 1,
281
- })
282
- const payAddress = addressResult.derivations[0]?.address
283
- if (!payAddress) {
284
- fatal('Failed to derive pay address')
285
- }
286
-
287
- const result = await listOrdinal.execute(ctx, {
288
- ordinal,
270
+ const result = await sellOrdinal.execute(ctx, {
271
+ id,
289
272
  price,
290
- payAddress,
291
- inputBEEF: ordinalsResult.BEEF as number[] | undefined,
273
+ ...(payAddress && { payAddress }),
292
274
  })
293
-
294
- if (result.error) {
295
- fatal(result.error)
296
- }
297
-
275
+ if (result.error) fatal(result.error)
298
276
  output(opts.json ? result : { txid: result.txid }, opts)
299
277
  } finally {
300
278
  await destroy()
@@ -305,41 +283,21 @@ async function ordinalsCancel(
305
283
  args: string[],
306
284
  opts: GlobalFlags,
307
285
  ): Promise<void> {
308
- const outpoint = extractFlag(args, '--outpoint')
309
-
310
- if (!outpoint) fatal('Missing --outpoint <txid.vout>')
286
+ const id = requireId(args)
311
287
 
312
288
  if (!opts.yes) {
313
289
  const ok = await confirm({
314
- message: `Cancel listing for ordinal ${outpoint}?`,
290
+ message: `Cancel listing for ordinal id ${id}?`,
315
291
  })
316
- if (isCancel(ok) || !ok) {
317
- fatal('Cancellation cancelled.')
318
- }
292
+ if (isCancel(ok) || !ok) fatal('Cancellation cancelled.')
319
293
  }
320
294
 
321
295
  const privateKey = await loadKey()
322
- const { ctx, destroy } = await loadContext(privateKey, {
323
- chain: opts.chain,
324
- })
296
+ const { ctx, destroy } = await loadContext(privateKey, { chain: opts.chain })
325
297
 
326
298
  try {
327
- // Look up the listing from the wallet (listings are in ordinals basket with ordlock tag)
328
- const ordinalsResult = await getOrdinals.execute(ctx, { limit: 10000 })
329
- const listing = ordinalsResult.outputs.find((o) => o.outpoint === outpoint)
330
- if (!listing) {
331
- fatal(`Listing not found in wallet: ${outpoint}`)
332
- }
333
-
334
- const result = await cancelListing.execute(ctx, {
335
- listing,
336
- inputBEEF: ordinalsResult.BEEF as number[] | undefined,
337
- })
338
-
339
- if (result.error) {
340
- fatal(result.error)
341
- }
342
-
299
+ const result = await cancelOrdinalListing.execute(ctx, { id })
300
+ if (result.error) fatal(result.error)
343
301
  output(opts.json ? result : { txid: result.txid }, opts)
344
302
  } finally {
345
303
  await destroy()
@@ -348,6 +306,7 @@ async function ordinalsCancel(
348
306
 
349
307
  async function ordinalsBuy(args: string[], opts: GlobalFlags): Promise<void> {
350
308
  const outpoint = extractFlag(args, '--outpoint')
309
+ const beef = parseBeefFlag(extractFlag(args, '--beef'))
351
310
 
352
311
  if (!outpoint) fatal('Missing --outpoint <txid.vout>')
353
312
 
@@ -355,23 +314,18 @@ async function ordinalsBuy(args: string[], opts: GlobalFlags): Promise<void> {
355
314
  const ok = await confirm({
356
315
  message: `Purchase ordinal listing ${outpoint}?`,
357
316
  })
358
- if (isCancel(ok) || !ok) {
359
- fatal('Purchase cancelled.')
360
- }
317
+ if (isCancel(ok) || !ok) fatal('Purchase cancelled.')
361
318
  }
362
319
 
363
320
  const privateKey = await loadKey()
364
- const { ctx, destroy } = await loadContext(privateKey, {
365
- chain: opts.chain,
366
- })
321
+ const { ctx, destroy } = await loadContext(privateKey, { chain: opts.chain })
367
322
 
368
323
  try {
369
- const result = await purchaseOrdinal.execute(ctx, { outpoint })
370
-
371
- if (result.error) {
372
- fatal(result.error)
373
- }
374
-
324
+ const result = await buyOrdinal.execute(ctx, {
325
+ outpoint,
326
+ ...(beef && { inputBEEF: beef }),
327
+ })
328
+ if (result.error) fatal(result.error)
375
329
  output(opts.json ? result : { txid: result.txid }, opts)
376
330
  } finally {
377
331
  await destroy()
@@ -379,42 +333,27 @@ async function ordinalsBuy(args: string[], opts: GlobalFlags): Promise<void> {
379
333
  }
380
334
 
381
335
  async function ordinalsBurn(args: string[], opts: GlobalFlags): Promise<void> {
382
- const outpoints = extractFlags(args, '--outpoints')
383
- if (!outpoints.length) {
384
- fatal('Missing --outpoints <txid.vout[,txid.vout...]>')
385
- }
336
+ const idsStr = extractFlag(args, '--ids')
337
+ if (!idsStr) fatal('Missing --ids <id1,id2,...>')
338
+ const ids = idsStr
339
+ .split(',')
340
+ .map((s) => s.trim())
341
+ .filter(Boolean)
342
+ if (!ids.length) fatal('--ids must include at least one id')
386
343
 
387
344
  if (!opts.yes) {
388
345
  const ok = await confirm({
389
- message: `Burn ${outpoints.length} ordinal(s) permanently? This cannot be undone.`,
346
+ message: `Burn ${ids.length} ordinal(s) permanently? This cannot be undone.`,
390
347
  })
391
- if (isCancel(ok) || !ok) {
392
- fatal('Burn cancelled.')
393
- }
348
+ if (isCancel(ok) || !ok) fatal('Burn cancelled.')
394
349
  }
395
350
 
396
351
  const privateKey = await loadKey()
397
- const { ctx, destroy } = await loadContext(privateKey, {
398
- chain: opts.chain,
399
- })
352
+ const { ctx, destroy } = await loadContext(privateKey, { chain: opts.chain })
400
353
 
401
354
  try {
402
- const ordinalsResult = await getOrdinals.execute(ctx, { limit: 10000 })
403
- const selected = outpoints.map((op) => {
404
- const match = ordinalsResult.outputs.find((o) => o.outpoint === op)
405
- if (!match) fatal(`Ordinal not found in wallet: ${op}`)
406
- return match
407
- })
408
-
409
- const result = await burnOrdinals.execute(ctx, {
410
- ordinals: selected,
411
- inputBEEF: ordinalsResult.BEEF as number[] | undefined,
412
- })
413
-
414
- if (result.error) {
415
- fatal(result.error)
416
- }
417
-
355
+ const result = await burnOrdinals.execute(ctx, { ids })
356
+ if (result.error) fatal(result.error)
418
357
  output(opts.json ? result : { txid: result.txid }, opts)
419
358
  } finally {
420
359
  await destroy()
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Token commands - balances, list, send, deploy, buy.
2
+ * BSV21 commands (group was `tokens`) — balances, list, send, deploy, buy.
3
3
  */
4
4
 
5
5
  import {
6
+ buyBsv21,
6
7
  deployBsv21Auth,
7
8
  deployBsv21Mint,
8
9
  getBsv21Balances,
9
10
  getDisplayValue,
10
- listTokens,
11
+ listBsv21,
11
12
  mintBsv21,
12
- purchaseBsv21,
13
13
  sendBsv21,
14
14
  } from '@1sat/actions'
15
15
  import type { Destination } from '@1sat/types'
@@ -21,7 +21,7 @@ import { printCommandHelp } from '../help'
21
21
  import { loadKey } from '../keys'
22
22
  import { fatal, formatLabel, formatValue, output } from '../output'
23
23
 
24
- export async function handleTokensCommand(
24
+ export async function handleBsv21Command(
25
25
  args: string[],
26
26
  opts: GlobalFlags,
27
27
  ): Promise<void> {
@@ -43,13 +43,16 @@ export async function handleTokensCommand(
43
43
  case 'buy':
44
44
  return tokenBuy(rest, opts)
45
45
  default:
46
- printCommandHelp('tokens', opts.json)
46
+ printCommandHelp('bsv21', opts.json)
47
47
  if (subcommand && subcommand !== 'help') {
48
48
  process.exit(1)
49
49
  }
50
50
  }
51
51
  }
52
52
 
53
+ /** @deprecated Use handleBsv21Command */
54
+ export const handleTokensCommand = handleBsv21Command
55
+
53
56
  async function tokenBalances(
54
57
  _args: string[],
55
58
  opts: GlobalFlags,
@@ -92,7 +95,7 @@ async function tokenList(args: string[], opts: GlobalFlags): Promise<void> {
92
95
  })
93
96
 
94
97
  try {
95
- const outputs = await listTokens.execute(ctx, { limit: 10000 })
98
+ const outputs = await listBsv21.execute(ctx, { limit: 10000 })
96
99
 
97
100
  const filtered = tokenId
98
101
  ? outputs.filter((o) => {
@@ -417,7 +420,6 @@ async function tokenBuy(args: string[], opts: GlobalFlags): Promise<void> {
417
420
  const outpoint = extractFlag(args, '--outpoint')
418
421
  const tokenId = extractFlag(args, '--token-id')
419
422
  const amountStr = extractFlag(args, '--amount')
420
-
421
423
  if (!outpoint) fatal('Missing --outpoint <txid.vout>')
422
424
  if (!tokenId) fatal('Missing --token-id <id>')
423
425
  if (!amountStr) fatal('Missing --amount <token-amount>')
@@ -437,7 +439,7 @@ async function tokenBuy(args: string[], opts: GlobalFlags): Promise<void> {
437
439
  })
438
440
 
439
441
  try {
440
- const result = await purchaseBsv21.execute(ctx, {
442
+ const result = await buyBsv21.execute(ctx, {
441
443
  tokenId,
442
444
  outpoint,
443
445
  amount: amountStr,