@did-btcr2/cli 0.20.0 → 0.21.0

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/cjs/index.js CHANGED
@@ -2294,51 +2294,40 @@ function parseGenesisBytes(hex, type) {
2294
2294
  }
2295
2295
 
2296
2296
  // src/commands/resolve.ts
2297
+ var import_api5 = require("@did-btcr2/api");
2298
+
2299
+ // src/resolution-options.ts
2297
2300
  var import_api4 = require("@did-btcr2/api");
2298
2301
  var import_promises = require("fs/promises");
2299
- function registerResolveCommand(program, factory, globals) {
2300
- program.command("resolve").alias("read").description("Resolve the DID document of the identifier.").requiredOption("-i, --identifier <identifier>", "did:btcr2 identifier").option("-r, --resolution-options <json>", "JSON string containing resolution options").option("-p, --resolution-options-path <path>", "Path to a JSON file containing resolution options").option(
2301
- "--min-conf <n>",
2302
- `Minimum block confirmations a beacon signal needs before resolution applies it (positive integer, default: ${import_api4.DEFAULT_MIN_CONF}). Overrides minConf inside -r/-p`,
2303
- parseMinConf
2304
- ).action(async (options) => {
2305
- const parsed = await validateResolveOptions(options);
2306
- const network = deriveNetwork(parsed.identifier);
2307
- const api = factory(network, globals());
2308
- const data = await api.resolveDid(parsed.identifier, parsed.options);
2309
- const result = { action: "resolve", data };
2310
- console.log(formatResult(result, globals()));
2311
- });
2312
- }
2313
- async function validateResolveOptions(options) {
2314
- import_api4.Identifier.decode(options.identifier);
2315
- let resolutionOptions = void 0;
2316
- if (options.resolutionOptions) {
2302
+ var MIN_CONF_HELP = `Minimum block confirmations a beacon signal needs before resolution applies it (positive integer, default: ${import_api4.DEFAULT_MIN_CONF}). Overrides a minConf inside the JSON resolution options`;
2303
+ async function readResolutionOptions(flags) {
2304
+ let resolutionOptions;
2305
+ if (flags.resolutionOptions) {
2317
2306
  try {
2318
- resolutionOptions = JSON.parse(options.resolutionOptions);
2307
+ resolutionOptions = JSON.parse(flags.resolutionOptions);
2319
2308
  } catch {
2320
2309
  throw new CLIError(
2321
2310
  "Invalid resolution options. Must be a valid JSON string.",
2322
2311
  "INVALID_ARGUMENT_ERROR",
2323
- options
2312
+ { resolutionOptions: flags.resolutionOptions }
2324
2313
  );
2325
2314
  }
2326
- } else if (options.resolutionOptionsPath) {
2315
+ } else if (flags.resolutionOptionsPath) {
2327
2316
  try {
2328
- const content = await (0, import_promises.readFile)(options.resolutionOptionsPath, "utf-8");
2317
+ const content = await (0, import_promises.readFile)(flags.resolutionOptionsPath, "utf-8");
2329
2318
  resolutionOptions = JSON.parse(content);
2330
2319
  } catch {
2331
2320
  throw new CLIError(
2332
2321
  "Invalid resolution options path. Must be a valid path to a JSON file.",
2333
2322
  "INVALID_ARGUMENT_ERROR",
2334
- options
2323
+ { resolutionOptionsPath: flags.resolutionOptionsPath }
2335
2324
  );
2336
2325
  }
2337
2326
  }
2338
- if (options.minConf !== void 0) {
2339
- resolutionOptions = { ...resolutionOptions ?? {}, minConf: options.minConf };
2327
+ if (flags.minConf !== void 0) {
2328
+ resolutionOptions = { ...resolutionOptions ?? {}, minConf: flags.minConf };
2340
2329
  }
2341
- return { identifier: options.identifier, options: resolutionOptions };
2330
+ return resolutionOptions;
2342
2331
  }
2343
2332
  function parseMinConf(value) {
2344
2333
  if (!/^[1-9]\d*$/.test(value)) {
@@ -2351,28 +2340,47 @@ function parseMinConf(value) {
2351
2340
  return Number(value);
2352
2341
  }
2353
2342
 
2354
- // src/commands/update.ts
2343
+ // src/commands/resolve.ts
2344
+ function registerResolveCommand(program, factory, globals) {
2345
+ program.command("resolve").alias("read").description("Resolve the DID document of the identifier.").requiredOption("-i, --identifier <identifier>", "did:btcr2 identifier").option("-r, --resolution-options <json>", "JSON string containing resolution options").option("-p, --resolution-options-path <path>", "Path to a JSON file containing resolution options").option("--min-conf <n>", MIN_CONF_HELP, parseMinConf).action(async (options) => {
2346
+ const parsed = await validateResolveOptions(options);
2347
+ const network = deriveNetwork(parsed.identifier);
2348
+ const api = factory(network, globals());
2349
+ const data = await api.resolveDid(parsed.identifier, parsed.options);
2350
+ const result = { action: "resolve", data };
2351
+ console.log(formatResult(result, globals()));
2352
+ });
2353
+ }
2354
+ async function validateResolveOptions(options) {
2355
+ import_api5.Identifier.decode(options.identifier);
2356
+ const resolutionOptions = await readResolutionOptions(options);
2357
+ return { identifier: options.identifier, options: resolutionOptions };
2358
+ }
2359
+
2360
+ // src/commands/write.ts
2355
2361
  var import_key_manager2 = require("@did-btcr2/key-manager");
2356
- function registerUpdateCommand(program, factory, globals) {
2357
- program.command("update").description("Update a did:btcr2 document.").requiredOption(
2362
+ function registerWriteOptions(command) {
2363
+ return command.option(
2358
2364
  "-s, --source-document <json>",
2359
- "Source DID document as JSON string",
2365
+ "Source DID document as a JSON string. Requires --source-version-id. Omit both to resolve the current document first",
2360
2366
  parseJsonArg("--source-document")
2361
- ).requiredOption(
2367
+ ).option(
2362
2368
  "--source-version-id <number>",
2363
- "Source version ID as a number"
2364
- ).requiredOption(
2365
- "-p, --patches <json>",
2366
- "JSON Patch operations as a JSON string array",
2367
- parseJsonArg("--patches")
2368
- ).requiredOption(
2369
+ "Version ID of the source document, a non-negative integer. Requires --source-document",
2370
+ parseSourceVersionId
2371
+ ).option(
2369
2372
  "-m, --verification-method-id <id>",
2370
- "DID document verification method ID"
2371
- ).requiredOption(
2372
- "-b, --beacon-id <json>",
2373
- "Beacon ID as a JSON string",
2374
- parseJsonArg("--beacon-id")
2373
+ "Verification method that signs the update (default: the one method of the document that publishes the signing key)"
2375
2374
  ).option(
2375
+ "-b, --beacon-id <id>",
2376
+ "Beacon service that announces the update, as a DID URL (default: the only beacon of the document, else the one beacon with a spendable UTXO)"
2377
+ ).option(
2378
+ "-r, --resolution-options <json>",
2379
+ "Resolution options as a JSON string, for the resolution of the source document"
2380
+ ).option(
2381
+ "--resolution-options-path <path>",
2382
+ "Path to a JSON file with resolution options, for the resolution of the source document"
2383
+ ).option("--min-conf <n>", MIN_CONF_HELP, parseMinConf).option(
2376
2384
  "--publish-to-cas <mode>",
2377
2385
  "Publish update artifacts to a writable CAS before broadcast: auto|always|never. CAS publication is optional; the default distributes the returned artifacts via sidecar.",
2378
2386
  parsePublishToCasMode,
@@ -2383,51 +2391,62 @@ function registerUpdateCommand(program, factory, globals) {
2383
2391
  ).option(
2384
2392
  "--change-address <address>",
2385
2393
  "Send transaction change to this address instead of the beacon address, so a DID's announcements are not linked on-chain (ADR 044)."
2386
- ).action(async (options) => {
2387
- if (!/^\d+$/.test(options.sourceVersionId)) {
2388
- throw new CLIError(
2389
- "--source-version-id must be a non-negative integer.",
2390
- "INVALID_ARGUMENT_ERROR",
2391
- { value: options.sourceVersionId }
2392
- );
2393
- }
2394
- const parsed = {
2394
+ );
2395
+ }
2396
+ async function prepareWrite(options, factory, g) {
2397
+ const did = options.identifier;
2398
+ const network = deriveNetwork(did);
2399
+ const hasDocument = options.sourceDocument !== void 0;
2400
+ const hasVersion = options.sourceVersionId !== void 0;
2401
+ if (hasDocument !== hasVersion) {
2402
+ throw new CLIError(
2403
+ "Provide both --source-document and --source-version-id, or neither. Omit both to resolve the current document first.",
2404
+ "INVALID_ARGUMENT_ERROR",
2405
+ { did }
2406
+ );
2407
+ }
2408
+ const hasResolutionFlags = options.resolutionOptions !== void 0 || options.resolutionOptionsPath !== void 0 || options.minConf !== void 0;
2409
+ if (hasDocument && hasResolutionFlags) {
2410
+ throw new CLIError(
2411
+ "--resolution-options, --resolution-options-path, and --min-conf apply only when --source-document and --source-version-id are omitted. A supplied source pair skips resolution.",
2412
+ "INVALID_ARGUMENT_ERROR",
2413
+ { did }
2414
+ );
2415
+ }
2416
+ assertKeystoreAllowedForNetwork(network, g);
2417
+ const resolutionOptions = await readResolutionOptions(options);
2418
+ const api = factory(network, g);
2419
+ const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(g));
2420
+ const signer = new import_key_manager2.KeyManagerSigner(api.kms.kms, keyId);
2421
+ const broadcastOptions = resolveBroadcastOptions(network, g, {
2422
+ feeRate: options.feeRate,
2423
+ changeAddress: options.changeAddress
2424
+ });
2425
+ return {
2426
+ network,
2427
+ api,
2428
+ params: {
2429
+ did,
2430
+ signer,
2395
2431
  sourceDocument: options.sourceDocument,
2396
- patches: options.patches,
2397
- sourceVersionId: Number(options.sourceVersionId),
2432
+ sourceVersionId: options.sourceVersionId,
2398
2433
  verificationMethodId: options.verificationMethodId,
2399
- beaconId: options.beaconId
2400
- };
2401
- const did = parsed.sourceDocument?.id;
2402
- if (!did) {
2403
- throw new CLIError(
2404
- 'Source document must contain an "id" field.',
2405
- "INVALID_ARGUMENT_ERROR",
2406
- options
2407
- );
2408
- }
2409
- const network = deriveNetwork(did);
2410
- assertKeystoreAllowedForNetwork(network, globals());
2411
- const api = factory(network, globals());
2412
- const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(globals()));
2413
- const signer = new import_key_manager2.KeyManagerSigner(api.kms.kms, keyId);
2414
- const broadcastOptions = resolveBroadcastOptions(network, globals(), {
2415
- feeRate: options.feeRate,
2416
- changeAddress: options.changeAddress
2417
- });
2418
- const data = await api.btcr2.update({
2419
- sourceDocument: parsed.sourceDocument,
2420
- patches: parsed.patches,
2421
- sourceVersionId: parsed.sourceVersionId,
2422
- verificationMethodId: parsed.verificationMethodId,
2423
- beaconId: parsed.beaconId,
2424
- signer,
2434
+ beaconId: options.beaconId,
2435
+ resolutionOptions,
2425
2436
  publishToCas: options.publishToCas,
2426
- ...broadcastOptions ? { broadcastOptions } : {}
2427
- });
2428
- console.log(formatResult({ action: "update", data }, globals()));
2429
- printWatchHint(globals(), network, data.txid);
2430
- });
2437
+ broadcastOptions
2438
+ }
2439
+ };
2440
+ }
2441
+ function parseSourceVersionId(value) {
2442
+ if (!/^\d+$/.test(value)) {
2443
+ throw new CLIError(
2444
+ "--source-version-id must be a non-negative integer.",
2445
+ "INVALID_ARGUMENT_ERROR",
2446
+ { value }
2447
+ );
2448
+ }
2449
+ return Number(value);
2431
2450
  }
2432
2451
  function parsePublishToCasMode(value) {
2433
2452
  if (value !== "auto" && value !== "always" && value !== "never") {
@@ -2453,104 +2472,33 @@ function parseJsonArg(flagName) {
2453
2472
  };
2454
2473
  }
2455
2474
 
2475
+ // src/commands/update.ts
2476
+ function registerUpdateCommand(program, factory, globals) {
2477
+ const command = program.command("update").description("Update a did:btcr2 document.").requiredOption("-i, --identifier <identifier>", "did:btcr2 identifier to update").requiredOption(
2478
+ "-p, --patches <json>",
2479
+ "JSON Patch operations as a JSON string array",
2480
+ parseJsonArg("--patches")
2481
+ );
2482
+ registerWriteOptions(command).action(async (options) => {
2483
+ const g = globals();
2484
+ const { network, api, params } = await prepareWrite(options, factory, g);
2485
+ const data = await api.updateDid({ ...params, patches: options.patches });
2486
+ console.log(formatResult({ action: "update", data }, g));
2487
+ printWatchHint(g, network, data.txid);
2488
+ });
2489
+ }
2490
+
2456
2491
  // src/commands/deactivate.ts
2457
- var import_key_manager3 = require("@did-btcr2/key-manager");
2458
- var DEACTIVATION_PATCH = [{ op: "add", path: "/deactivated", value: true }];
2459
2492
  function registerDeactivateCommand(program, factory, globals) {
2460
- program.command("deactivate").alias("delete").description("Deactivate the did:btcr2 identifier permanently. This is irreversible.").requiredOption(
2461
- "-s, --source-document <json>",
2462
- "Current DID document as JSON string",
2463
- parseJsonArg2("--source-document")
2464
- ).requiredOption(
2465
- "--source-version-id <number>",
2466
- "Current version ID of the DID document"
2467
- ).requiredOption(
2468
- "-m, --verification-method-id <id>",
2469
- "DID document verification method ID used to sign the deactivation"
2470
- ).requiredOption(
2471
- "-b, --beacon-id <json>",
2472
- "Beacon ID as a JSON string",
2473
- parseJsonArg2("--beacon-id")
2474
- ).option(
2475
- "--publish-to-cas <mode>",
2476
- "Publish update artifacts to a writable CAS before broadcast: auto|always|never. CAS publication is optional; the default distributes the returned artifacts via sidecar.",
2477
- parsePublishToCasMode2,
2478
- "never"
2479
- ).option(
2480
- "--fee-rate <satsPerVByte>",
2481
- "Fee rate in sats/vByte for the beacon transaction (default: 5). Raise it under congestion so the transaction confirms."
2482
- ).option(
2483
- "--change-address <address>",
2484
- "Send transaction change to this address instead of the beacon address, so a DID's announcements are not linked on-chain (ADR 044)."
2485
- ).action(async (options) => {
2486
- if (!/^\d+$/.test(options.sourceVersionId)) {
2487
- throw new CLIError(
2488
- "--source-version-id must be a non-negative integer.",
2489
- "INVALID_ARGUMENT_ERROR",
2490
- { value: options.sourceVersionId }
2491
- );
2492
- }
2493
- const parsed = {
2494
- sourceDocument: options.sourceDocument,
2495
- patches: DEACTIVATION_PATCH,
2496
- sourceVersionId: Number(options.sourceVersionId),
2497
- verificationMethodId: options.verificationMethodId,
2498
- beaconId: options.beaconId
2499
- };
2500
- const did = parsed.sourceDocument?.id;
2501
- if (!did) {
2502
- throw new CLIError(
2503
- 'Source document must contain an "id" field.',
2504
- "INVALID_ARGUMENT_ERROR",
2505
- options
2506
- );
2507
- }
2508
- const network = deriveNetwork(did);
2509
- assertKeystoreAllowedForNetwork(network, globals());
2510
- const api = factory(network, globals());
2511
- const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(globals()));
2512
- const signer = new import_key_manager3.KeyManagerSigner(api.kms.kms, keyId);
2513
- const broadcastOptions = resolveBroadcastOptions(network, globals(), {
2514
- feeRate: options.feeRate,
2515
- changeAddress: options.changeAddress
2516
- });
2517
- const data = await api.btcr2.update({
2518
- sourceDocument: parsed.sourceDocument,
2519
- patches: parsed.patches,
2520
- sourceVersionId: parsed.sourceVersionId,
2521
- verificationMethodId: parsed.verificationMethodId,
2522
- beaconId: parsed.beaconId,
2523
- signer,
2524
- publishToCas: options.publishToCas,
2525
- ...broadcastOptions ? { broadcastOptions } : {}
2526
- });
2527
- console.log(formatResult({ action: "deactivate", data }, globals()));
2528
- printWatchHint(globals(), network, data.txid);
2493
+ const command = program.command("deactivate").alias("delete").description("Deactivate the did:btcr2 identifier permanently. This is irreversible.").requiredOption("-i, --identifier <identifier>", "did:btcr2 identifier to deactivate");
2494
+ registerWriteOptions(command).action(async (options) => {
2495
+ const g = globals();
2496
+ const { network, api, params } = await prepareWrite(options, factory, g);
2497
+ const data = await api.deactivateDid(params);
2498
+ console.log(formatResult({ action: "deactivate", data }, g));
2499
+ printWatchHint(g, network, data.txid);
2529
2500
  });
2530
2501
  }
2531
- function parsePublishToCasMode2(value) {
2532
- if (value !== "auto" && value !== "always" && value !== "never") {
2533
- throw new CLIError(
2534
- '--publish-to-cas must be one of "auto", "always", or "never".',
2535
- "INVALID_ARGUMENT_ERROR",
2536
- { value }
2537
- );
2538
- }
2539
- return value;
2540
- }
2541
- function parseJsonArg2(flagName) {
2542
- return (value) => {
2543
- try {
2544
- return JSON.parse(value);
2545
- } catch {
2546
- throw new CLIError(
2547
- `Invalid JSON for ${flagName}. Must be a valid JSON string.`,
2548
- "INVALID_ARGUMENT_ERROR",
2549
- { flagName, value }
2550
- );
2551
- }
2552
- };
2553
- }
2554
2502
 
2555
2503
  // src/commands/key.ts
2556
2504
  var import_keypair = require("@did-btcr2/keypair");
@@ -1,98 +1,21 @@
1
- import { KeyManagerSigner } from '@did-btcr2/key-manager';
2
- import { assertKeystoreAllowedForNetwork, deriveNetwork, resolveBroadcastOptions, resolveSigningKeyRef } from '../config.js';
3
- import { CLIError } from '../error.js';
4
1
  import { printWatchHint } from '../hints.js';
5
- import { resolveKeyRef } from '../keystore/resolve-key-ref.js';
6
2
  import { formatResult } from '../output.js';
7
- /** The JSON Patch that marks a DID document as permanently deactivated. */
8
- const DEACTIVATION_PATCH = [{ op: 'add', path: '/deactivated', value: true }];
3
+ import { prepareWrite, registerWriteOptions } from './write.js';
9
4
  export function registerDeactivateCommand(program, factory, globals) {
10
- program
5
+ const command = program
11
6
  .command('deactivate')
12
7
  .alias('delete')
13
8
  .description('Deactivate the did:btcr2 identifier permanently. This is irreversible.')
14
- .requiredOption('-s, --source-document <json>', 'Current DID document as JSON string', parseJsonArg('--source-document'))
15
- .requiredOption('--source-version-id <number>', 'Current version ID of the DID document')
16
- .requiredOption('-m, --verification-method-id <id>', 'DID document verification method ID used to sign the deactivation')
17
- .requiredOption('-b, --beacon-id <json>', 'Beacon ID as a JSON string', parseJsonArg('--beacon-id'))
18
- .option('--publish-to-cas <mode>', 'Publish update artifacts to a writable CAS before broadcast: auto|always|never. '
19
- + 'CAS publication is optional; the default distributes the returned artifacts via sidecar.', parsePublishToCasMode, 'never')
20
- .option('--fee-rate <satsPerVByte>', 'Fee rate in sats/vByte for the beacon transaction (default: 5). '
21
- + 'Raise it under congestion so the transaction confirms.')
22
- .option('--change-address <address>', 'Send transaction change to this address instead of the beacon address, '
23
- + 'so a DID\'s announcements are not linked on-chain (ADR 044).')
9
+ .requiredOption('-i, --identifier <identifier>', 'did:btcr2 identifier to deactivate');
10
+ registerWriteOptions(command)
24
11
  .action(async (options) => {
25
- if (!/^\d+$/.test(options.sourceVersionId)) {
26
- throw new CLIError('--source-version-id must be a non-negative integer.', 'INVALID_ARGUMENT_ERROR', { value: options.sourceVersionId });
27
- }
28
- const parsed = {
29
- sourceDocument: options.sourceDocument,
30
- patches: DEACTIVATION_PATCH,
31
- sourceVersionId: Number(options.sourceVersionId),
32
- verificationMethodId: options.verificationMethodId,
33
- beaconId: options.beaconId,
34
- };
35
- const did = parsed.sourceDocument?.id;
36
- if (!did) {
37
- throw new CLIError('Source document must contain an "id" field.', 'INVALID_ARGUMENT_ERROR', options);
38
- }
39
- // Deactivation is an update that applies the deactivation patch. The core
40
- // method has no separate deactivate path, so this routes through update.
41
- const network = deriveNetwork(did);
42
- // Refuse to sign a mainnet deactivation with an unencrypted dev keystore (ADR 080).
43
- assertKeystoreAllowedForNetwork(network, globals());
44
- const api = factory(network, globals());
45
- const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(globals()));
46
- const signer = new KeyManagerSigner(api.kms.kms, keyId);
47
- // Resolve fee-rate/change-address through the flag -> env -> profile chain
48
- // into beacon broadcast options. Undefined when neither is set, so the
49
- // SDK defaults (5 sat/vB, change back to the beacon address) still apply.
50
- const broadcastOptions = resolveBroadcastOptions(network, globals(), {
51
- feeRate: options.feeRate,
52
- changeAddress: options.changeAddress,
53
- });
54
- // CAS publication is optional and never required: every beacon update can
55
- // be completed and shared via sidecar alone. It is opt-in and defaults to
56
- // 'never'; pass --publish-to-cas auto|always to publish the signed update
57
- // (and, for CAS beacons, the announcement) to a writable CAS configured
58
- // via --cas-rpc-url. The returned artifacts (txid, announcement, proof)
59
- // are always printed for sidecar distribution regardless.
60
- const data = await api.btcr2.update({
61
- sourceDocument: parsed.sourceDocument,
62
- patches: parsed.patches,
63
- sourceVersionId: parsed.sourceVersionId,
64
- verificationMethodId: parsed.verificationMethodId,
65
- beaconId: parsed.beaconId,
66
- signer,
67
- publishToCas: options.publishToCas,
68
- ...(broadcastOptions ? { broadcastOptions } : {}),
69
- });
70
- console.log(formatResult({ action: 'deactivate', data }, globals()));
71
- printWatchHint(globals(), network, data.txid);
12
+ const g = globals();
13
+ const { network, api, params } = await prepareWrite(options, factory, g);
14
+ // The api supplies the deactivation patch (ADR 094) and refuses a
15
+ // document that is deactivated already (ADR 100).
16
+ const data = await api.deactivateDid(params);
17
+ console.log(formatResult({ action: 'deactivate', data }, g));
18
+ printWatchHint(g, network, data.txid);
72
19
  });
73
20
  }
74
- /**
75
- * Commander argParser for `--publish-to-cas`. Validates the value is one of the
76
- * three {@link PublishToCasMode} policies, erroring at parse time otherwise.
77
- */
78
- function parsePublishToCasMode(value) {
79
- if (value !== 'auto' && value !== 'always' && value !== 'never') {
80
- throw new CLIError('--publish-to-cas must be one of "auto", "always", or "never".', 'INVALID_ARGUMENT_ERROR', { value });
81
- }
82
- return value;
83
- }
84
- /**
85
- * Returns a commander argParser that validates JSON.
86
- * Errors at parse time with a clear flag reference.
87
- */
88
- function parseJsonArg(flagName) {
89
- return (value) => {
90
- try {
91
- return JSON.parse(value);
92
- }
93
- catch {
94
- throw new CLIError(`Invalid JSON for ${flagName}. Must be a valid JSON string.`, 'INVALID_ARGUMENT_ERROR', { flagName, value });
95
- }
96
- };
97
- }
98
21
  //# sourceMappingURL=deactivate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deactivate.js","sourceRoot":"","sources":["../../../../src/commands/deactivate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,+BAA+B,EAAE,aAAa,EAAE,uBAAuB,EAAE,oBAAoB,EAAmB,MAAM,cAAc,CAAC;AAC9I,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,2EAA2E;AAC3E,MAAM,kBAAkB,GAAG,CAAC,EAAE,EAAE,EAAE,KAAc,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAEvF,MAAM,UAAU,yBAAyB,CACvC,OAAiB,EACjB,OAAoB,EACpB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,YAAY,CAAC;SACrB,KAAK,CAAC,QAAQ,CAAC;SACf,WAAW,CAAC,wEAAwE,CAAC;SACrF,cAAc,CACb,8BAA8B,EAC9B,qCAAqC,EACrC,YAAY,CAAC,mBAAmB,CAAC,CAClC;SACA,cAAc,CACb,8BAA8B,EAC9B,wCAAwC,CACzC;SACA,cAAc,CACb,mCAAmC,EACnC,mEAAmE,CACpE;SACA,cAAc,CACb,wBAAwB,EACxB,4BAA4B,EAC5B,YAAY,CAAC,aAAa,CAAC,CAC5B;SACA,MAAM,CACL,yBAAyB,EACzB,kFAAkF;UAC9E,0FAA0F,EAC9F,qBAAqB,EACrB,OAAO,CACR;SACA,MAAM,CACL,2BAA2B,EAC3B,kEAAkE;UAC9D,wDAAwD,CAC7D;SACA,MAAM,CACL,4BAA4B,EAC5B,yEAAyE;UACrE,8DAA8D,CACnE;SACA,MAAM,CAAC,KAA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C,CAAC;AACP,CAAC"}
@@ -1,8 +1,7 @@
1
- import { DEFAULT_MIN_CONF, Identifier } from '@did-btcr2/api';
2
- import { readFile } from 'node:fs/promises';
1
+ import { Identifier } from '@did-btcr2/api';
3
2
  import { deriveNetwork } from '../config.js';
4
- import { CLIError } from '../error.js';
5
3
  import { formatResult } from '../output.js';
4
+ import { MIN_CONF_HELP, parseMinConf, readResolutionOptions } from '../resolution-options.js';
6
5
  export function registerResolveCommand(program, factory, globals) {
7
6
  program
8
7
  .command('resolve')
@@ -11,8 +10,7 @@ export function registerResolveCommand(program, factory, globals) {
11
10
  .requiredOption('-i, --identifier <identifier>', 'did:btcr2 identifier')
12
11
  .option('-r, --resolution-options <json>', 'JSON string containing resolution options')
13
12
  .option('-p, --resolution-options-path <path>', 'Path to a JSON file containing resolution options')
14
- .option('--min-conf <n>', 'Minimum block confirmations a beacon signal needs before resolution applies it '
15
- + `(positive integer, default: ${DEFAULT_MIN_CONF}). Overrides minConf inside -r/-p`, parseMinConf)
13
+ .option('--min-conf <n>', MIN_CONF_HELP, parseMinConf)
16
14
  .action(async (options) => {
17
15
  const parsed = await validateResolveOptions(options);
18
16
  const network = deriveNetwork(parsed.identifier);
@@ -25,38 +23,7 @@ export function registerResolveCommand(program, factory, globals) {
25
23
  async function validateResolveOptions(options) {
26
24
  // Validate identifier format early
27
25
  Identifier.decode(options.identifier);
28
- let resolutionOptions = undefined;
29
- if (options.resolutionOptions) {
30
- try {
31
- resolutionOptions = JSON.parse(options.resolutionOptions);
32
- }
33
- catch {
34
- throw new CLIError('Invalid resolution options. Must be a valid JSON string.', 'INVALID_ARGUMENT_ERROR', options);
35
- }
36
- }
37
- else if (options.resolutionOptionsPath) {
38
- try {
39
- const content = await readFile(options.resolutionOptionsPath, 'utf-8');
40
- resolutionOptions = JSON.parse(content);
41
- }
42
- catch {
43
- throw new CLIError('Invalid resolution options path. Must be a valid path to a JSON file.', 'INVALID_ARGUMENT_ERROR', options);
44
- }
45
- }
46
- // The flag wins over a minConf inside the JSON options.
47
- if (options.minConf !== undefined) {
48
- resolutionOptions = { ...(resolutionOptions ?? {}), minConf: options.minConf };
49
- }
26
+ const resolutionOptions = await readResolutionOptions(options);
50
27
  return { identifier: options.identifier, options: resolutionOptions };
51
28
  }
52
- /**
53
- * Commander argParser for `--min-conf`. Accepts a positive integer (minimum 1),
54
- * the domain the specification gives `minConf`. Errors at parse time otherwise.
55
- */
56
- function parseMinConf(value) {
57
- if (!/^[1-9]\d*$/.test(value)) {
58
- throw new CLIError('--min-conf must be a positive integer (minimum 1).', 'INVALID_ARGUMENT_ERROR', { value });
59
- }
60
- return Number(value);
61
- }
62
29
  //# sourceMappingURL=resolve.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,UAAU,sBAAsB,CACpC,OAAiB,EACjB,OAAoB,EACpB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,SAAS,CAAC;SAClB,KAAK,CAAC,MAAM,CAAC;SACb,WAAW,CAAC,6CAA6C,CAAC;SAC1D,cAAc,CAAC,+BAA+B,EAAE,sBAAsB,CAAC;SACvE,MAAM,CAAC,iCAAiC,EAAE,2CAA2C,CAAC;SACtF,MAAM,CAAC,sCAAsC,EAAE,mDAAmD,CAAC;SACnG,MAAM,CACL,gBAAgB,EAChB,iFAAiF;UAC/E,+BAA+B,gBAAgB,mCAAmC,EACpF,YAAY,CACb;SACA,MAAM,CAAC,KAAK,EAAE,OAKd,EAAE,EAA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