@did-btcr2/cli 0.3.1 → 0.4.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.
Files changed (95) hide show
  1. package/LICENSE +373 -1
  2. package/dist/cjs/cli.js +56 -264
  3. package/dist/cjs/cli.js.map +1 -1
  4. package/dist/cjs/commands/create.js +49 -0
  5. package/dist/cjs/commands/create.js.map +1 -0
  6. package/dist/cjs/commands/deactivate.js +41 -0
  7. package/dist/cjs/commands/deactivate.js.map +1 -0
  8. package/dist/cjs/commands/index.js +5 -0
  9. package/dist/cjs/commands/index.js.map +1 -0
  10. package/dist/cjs/commands/resolve.js +59 -0
  11. package/dist/cjs/commands/resolve.js.map +1 -0
  12. package/dist/cjs/commands/update.js +39 -0
  13. package/dist/cjs/commands/update.js.map +1 -0
  14. package/dist/cjs/error.js +1 -1
  15. package/dist/cjs/error.js.map +1 -1
  16. package/dist/cjs/index.js +4 -1
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/output.js +16 -0
  19. package/dist/cjs/output.js.map +1 -0
  20. package/dist/cjs/types.js +4 -0
  21. package/dist/cjs/types.js.map +1 -0
  22. package/dist/cjs/version.js +22 -0
  23. package/dist/cjs/version.js.map +1 -0
  24. package/dist/esm/src/cli.js +56 -264
  25. package/dist/esm/src/cli.js.map +1 -1
  26. package/dist/esm/src/commands/create.js +49 -0
  27. package/dist/esm/src/commands/create.js.map +1 -0
  28. package/dist/esm/src/commands/deactivate.js +41 -0
  29. package/dist/esm/src/commands/deactivate.js.map +1 -0
  30. package/dist/esm/src/commands/index.js +5 -0
  31. package/dist/esm/src/commands/index.js.map +1 -0
  32. package/dist/esm/src/commands/resolve.js +59 -0
  33. package/dist/esm/src/commands/resolve.js.map +1 -0
  34. package/dist/esm/src/commands/update.js +39 -0
  35. package/dist/esm/src/commands/update.js.map +1 -0
  36. package/dist/esm/src/error.js +1 -1
  37. package/dist/esm/src/error.js.map +1 -1
  38. package/dist/esm/src/index.js +4 -1
  39. package/dist/esm/src/index.js.map +1 -1
  40. package/dist/esm/src/output.js +16 -0
  41. package/dist/esm/src/output.js.map +1 -0
  42. package/dist/esm/src/types.js +4 -0
  43. package/dist/esm/src/types.js.map +1 -0
  44. package/dist/esm/src/version.js +22 -0
  45. package/dist/esm/src/version.js.map +1 -0
  46. package/dist/types/cli.d.ts +7 -98
  47. package/dist/types/commands/create.d.ts +3 -0
  48. package/dist/types/commands/deactivate.d.ts +3 -0
  49. package/dist/types/commands/index.d.ts +4 -0
  50. package/dist/types/commands/resolve.d.ts +3 -0
  51. package/dist/types/commands/update.d.ts +3 -0
  52. package/dist/types/index.d.ts +4 -1
  53. package/dist/types/output.d.ts +10 -0
  54. package/dist/types/src/cli.d.ts +7 -98
  55. package/dist/types/src/cli.d.ts.map +1 -1
  56. package/dist/types/src/commands/create.d.ts +4 -0
  57. package/dist/types/src/commands/create.d.ts.map +1 -0
  58. package/dist/types/src/commands/deactivate.d.ts +4 -0
  59. package/dist/types/src/commands/deactivate.d.ts.map +1 -0
  60. package/dist/types/src/commands/index.d.ts +5 -0
  61. package/dist/types/src/commands/index.d.ts.map +1 -0
  62. package/dist/types/src/commands/resolve.d.ts +4 -0
  63. package/dist/types/src/commands/resolve.d.ts.map +1 -0
  64. package/dist/types/src/commands/update.d.ts +4 -0
  65. package/dist/types/src/commands/update.d.ts.map +1 -0
  66. package/dist/types/src/index.d.ts +4 -1
  67. package/dist/types/src/index.d.ts.map +1 -1
  68. package/dist/types/src/output.d.ts +11 -0
  69. package/dist/types/src/output.d.ts.map +1 -0
  70. package/dist/types/src/types.d.ts +54 -0
  71. package/dist/types/src/types.d.ts.map +1 -0
  72. package/dist/types/src/version.d.ts +2 -0
  73. package/dist/types/src/version.d.ts.map +1 -0
  74. package/dist/types/types.d.ts +53 -0
  75. package/dist/types/version.d.ts +1 -0
  76. package/package.json +6 -7
  77. package/src/cli.ts +67 -347
  78. package/src/commands/create.ts +88 -0
  79. package/src/commands/deactivate.ts +71 -0
  80. package/src/commands/index.ts +4 -0
  81. package/src/commands/resolve.ts +89 -0
  82. package/src/commands/update.ts +73 -0
  83. package/src/error.ts +2 -2
  84. package/src/index.ts +4 -1
  85. package/src/output.ts +17 -0
  86. package/src/types.ts +61 -0
  87. package/src/version.ts +21 -0
  88. package/dist/cjs/command.js +0 -35
  89. package/dist/cjs/command.js.map +0 -1
  90. package/dist/esm/src/command.js +0 -35
  91. package/dist/esm/src/command.js.map +0 -1
  92. package/dist/types/command.d.ts +0 -55
  93. package/dist/types/src/command.d.ts +0 -56
  94. package/dist/types/src/command.d.ts.map +0 -1
  95. package/src/command.ts +0 -77
@@ -0,0 +1,39 @@
1
+ import { CLIError } from '../error.js';
2
+ import { formatResult } from '../output.js';
3
+ export function registerUpdateCommand(program, ops, globals) {
4
+ program
5
+ .command('update')
6
+ .description('Update a did:btcr2 document.')
7
+ .requiredOption('-s, --source-document <json>', 'Source DID document as JSON string', parseJsonArg('--source-document'))
8
+ .requiredOption('--source-version-id <number>', 'Source version ID as a number')
9
+ .requiredOption('-p, --patches <json>', 'JSON Patch operations as a JSON string array', parseJsonArg('--patches'))
10
+ .requiredOption('-m, --verification-method-id <id>', 'DID document verification method ID')
11
+ .requiredOption('-b, --beacon-id <json>', 'Beacon ID as a JSON string', parseJsonArg('--beacon-id'))
12
+ .action(async (options) => {
13
+ const parsed = {
14
+ sourceDocument: options.sourceDocument,
15
+ patches: options.patches,
16
+ sourceVersionId: Number(options.sourceVersionId),
17
+ verificationMethodId: options.verificationMethodId,
18
+ beaconId: options.beaconId,
19
+ };
20
+ const data = await ops.update(parsed);
21
+ const result = { action: 'update', data };
22
+ console.log(formatResult(result, globals()));
23
+ });
24
+ }
25
+ /**
26
+ * Returns a commander argParser that validates JSON.
27
+ * Errors at parse time with a clear flag reference.
28
+ */
29
+ function parseJsonArg(flagName) {
30
+ return (value) => {
31
+ try {
32
+ return JSON.parse(value);
33
+ }
34
+ catch {
35
+ throw new CLIError(`Invalid JSON for ${flagName}. Must be a valid JSON string.`, 'INVALID_ARGUMENT_ERROR', { flagName, value });
36
+ }
37
+ };
38
+ }
39
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/commands/update.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,UAAU,qBAAqB,CACnC,OAAiB,EACjB,GAA0B,EAC1B,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,8BAA8B,CAAC;SAC3C,cAAc,CACb,8BAA8B,EAC9B,oCAAoC,EACpC,YAAY,CAAC,mBAAmB,CAAC,CAClC;SACA,cAAc,CACb,8BAA8B,EAC9B,+BAA+B,CAChC;SACA,cAAc,CACb,sBAAsB,EACtB,8CAA8C,EAC9C,YAAY,CAAC,WAAW,CAAC,CAC1B;SACA,cAAc,CACb,mCAAmC,EACnC,qCAAqC,CACtC;SACA,cAAc,CACb,wBAAwB,EACxB,4BAA4B,EAC5B,YAAY,CAAC,aAAa,CAAC,CAC5B;SACA,MAAM,CAAC,KAAK,EAAE,OAMd,EAAE,EAAE;QACH,MAAM,MAAM,GAAyB;YACnC,cAAc,EAAS,OAAO,CAAC,cAAwD;YACvF,OAAO,EAAgB,OAAO,CAAC,OAA0C;YACzE,eAAe,EAAQ,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC;YACtD,oBAAoB,EAAG,OAAO,CAAC,oBAAoB;YACnD,QAAQ,EAAe,OAAO,CAAC,QAA4C;SAC5E,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,QAAiB,EAAE,IAAI,EAAE,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CAAC,QAAgB;IACpC,OAAO,CAAC,KAAa,EAAW,EAAE;QAChC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,QAAQ,CAChB,oBAAoB,QAAQ,gCAAgC,EAC5D,wBAAwB,EACxB,EAAE,QAAQ,EAAE,KAAK,EAAE,CACpB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -4,7 +4,7 @@ import { DidMethodError } from '@did-btcr2/common';
4
4
  */
5
5
  export class CLIError extends DidMethodError {
6
6
  constructor(message, type = 'CLIError', data) {
7
- super(message, { type, name: type, data });
7
+ super(message, { type, name: 'CLIError', data });
8
8
  }
9
9
  }
10
10
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,cAAc;IAC1C,YAAY,OAAe,EAAE,OAAe,UAAU,EAAE,IAA0B;QAChF,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;CACF"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,cAAc;IAC1C,YAAY,OAAe,EAAE,OAAe,UAAU,EAAE,IAA0B;QAChF,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;CACF"}
@@ -1,4 +1,7 @@
1
1
  export * from './cli.js';
2
- export * from './command.js';
2
+ export * from './commands/index.js';
3
3
  export * from './error.js';
4
+ export * from './output.js';
5
+ export * from './types.js';
6
+ export * from './version.js';
4
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Formats a CommandResult for console output.
3
+ * In 'json' mode, the full result is serialized.
4
+ * In 'text' mode, only the relevant payload is printed.
5
+ * @param {CommandResult} result - The result to format.
6
+ * @param {GlobalOptions} options - The global options to determine output format.
7
+ * @returns {string} - The formatted output string.
8
+ */
9
+ export function formatResult(result, options) {
10
+ if (options.output === 'json') {
11
+ return JSON.stringify(result, null, 2);
12
+ }
13
+ const { data } = result;
14
+ return typeof data === 'string' ? data : JSON.stringify(data, null, 2);
15
+ }
16
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../../src/output.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqB,EAAE,OAAsB;IACxE,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const SUPPORTED_NETWORKS = [
2
+ 'bitcoin', 'testnet3', 'testnet4', 'signet', 'mutinynet', 'regtest'
3
+ ];
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,kBAAkB,GAAoB;IACjD,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS;CACpE,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ /**
5
+ * Walks up from the compiled file location to find the CLI package.json.
6
+ * Works from both dist/esm/ and tests/compiled/src/.
7
+ */
8
+ function readVersion() {
9
+ let dir = dirname(fileURLToPath(import.meta.url));
10
+ for (let i = 0; i < 5; i++) {
11
+ try {
12
+ const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));
13
+ if (pkg.name === '@did-btcr2/cli')
14
+ return pkg.version;
15
+ }
16
+ catch { /* not found, go up */ }
17
+ dir = dirname(dir);
18
+ }
19
+ return '0.0.0';
20
+ }
21
+ export const VERSION = readVersion();
22
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,SAAS,WAAW;IAClB,IAAI,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;YACzE,IAAI,GAAG,CAAC,IAAI,KAAK,gBAAgB;gBAAE,OAAO,GAAG,CAAC,OAAO,CAAC;QACxD,CAAC;QAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC;QAClC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAW,WAAW,EAAE,CAAC"}
@@ -1,111 +1,20 @@
1
1
  import { Command } from 'commander';
2
+ import { MethodOperations } from './types.js';
2
3
  /**
3
4
  * CLI tool for the did:btcr2 method.
4
- * @type {DidBtcr2Cli}
5
- * @class DidBtcr2Cli
6
5
  */
7
6
  export declare class DidBtcr2Cli {
8
7
  readonly program: Command;
9
- constructor();
8
+ private readonly ops;
10
9
  /**
11
- * Configures the CLI commands.
12
- * @returns {void}
10
+ * Initializes the CLI with optional custom MethodOperations.
11
+ * @param {MethodOperations} ops - Custom operations for create, resolve, and update.
13
12
  */
14
- private configureCommands;
15
- /**
16
- * Invokes a command with the provided request.
17
- * @param {object} request The command request
18
- * @param {any} request.options The command options
19
- * @param {CommandRequest['action']} request.action The command action
20
- * @param {Btcr2Command} request.command The command instance
21
- * @returns {Promise<CommandResult>} The command result
22
- */
23
- private invokeCommand;
13
+ constructor(ops?: MethodOperations);
24
14
  /**
25
15
  * Runs the CLI with the provided argv or process.argv.
26
- * @param {string[]} [argv] The argv array to use. Defaults to process.argv.
16
+ * @param {string[]} [argv] - Optional array of command-line arguments.
17
+ * @returns {Promise<void>} - Resolves when execution is complete.
27
18
  */
28
19
  run(argv?: string[]): Promise<void>;
29
- /**
30
- * Normalizes argv to ensure it has at least two elements.
31
- * @param {string[]} argv The argv array to normalize
32
- * @returns {string[]} Normalized argv array
33
- */
34
- private normalizeArgv;
35
- /**
36
- * Handles errors thrown during CLI execution.
37
- * @param {unknown} error The error to handle
38
- * @returns {void}
39
- */
40
- private handleError;
41
- /**
42
- * Parses create command options and throws CLIError on invalid input.
43
- * @param {object} options The create command options
44
- * @param {string} options.type The identifier type
45
- * @param {string} options.network The bitcoin network
46
- * @param {string} options.bytes The genesis bytes as a hex string
47
- * @returns {CreateCommandOptions} The parsed create command options
48
- */
49
- private parseCreateOptions;
50
- /**
51
- * Parses resolve command options and throws CLIError on invalid input.
52
- * @param {object} options The resolve command options
53
- * @param {string} options.identifier The did:btcr2 identifier
54
- * @param {string} [options.resolutionOptions] JSON string of resolution options
55
- * @param {string} [options.resolutionOptionsPath] Path to a JSON file of resolution options
56
- * @returns {Promise<ResolveCommandOptions>} The parsed resolve command options
57
- */
58
- private parseResolveOptions;
59
- /**
60
- * Parses update command options and throws CLIError on invalid input.
61
- * @param {object} options The update command options
62
- * @param {string} options.sourceDocument The source DID document as a JSON string
63
- * @param {number} options.sourceVersionId The source version ID as a number
64
- * @param {string} options.patches The JSON Patch operations as a JSON string array
65
- * @param {string} options.verificationMethodId The DID document verification method ID as a string
66
- * @param {string} options.beaconId The beacon IDs as a JSON string array
67
- * @returns {UpdateCommandOptions} The parsed update command options
68
- */
69
- private parseUpdateOptions;
70
- /**
71
- * Parses a JSON option and throws a CLIError on failure.
72
- * @param {string} value JSON string to parse
73
- * @param {string} errorMessage Error message to use on failure
74
- * @param {Record<string, any>} data Additional data to include in the error
75
- * @returns {T} Parsed JSON object
76
- */
77
- private parseJsonOption;
78
- /**
79
- * Parses resolution options from JSON string or file path.
80
- * @param {object} options The options containing resolution options
81
- * @param {string} [options.resolutionOptions] JSON string of resolution options
82
- * @param {string} [options.resolutionOptionsPath] Path to a JSON file of resolution options
83
- * @returns {Promise<any>} The parsed resolution options
84
- */
85
- private parseResolutionOptions;
86
- /**
87
- * Validates the did:btcr2 identifier format.
88
- * @param {string} identifier The identifier to validate
89
- * @param {Record<string, any>} data Additional data to include in the error
90
- * @returns {void}
91
- */
92
- private validateIdentifier;
93
- /**
94
- * Validates if the provided network is supported.
95
- * @param {string} network The network to validate
96
- * @returns {boolean} True if the network is valid
97
- */
98
- private isNetworkValid;
99
- /**
100
- * Prints the command result to the console.
101
- * @param {CommandResult} result The command result to print
102
- * @returns {void}
103
- */
104
- private printResult;
105
- /**
106
- * Logs a payload to the console, formatting objects as JSON.
107
- * @param {unknown} payload The payload to log
108
- * @returns {void}
109
- */
110
- private log;
111
20
  }
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerCreateCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerDeactivateCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
@@ -0,0 +1,4 @@
1
+ export { registerCreateCommand } from './create.js';
2
+ export { registerResolveCommand } from './resolve.js';
3
+ export { registerUpdateCommand } from './update.js';
4
+ export { registerDeactivateCommand } from './deactivate.js';
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerResolveCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerUpdateCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
@@ -1,3 +1,6 @@
1
1
  export * from './cli.js';
2
- export * from './command.js';
2
+ export * from './commands/index.js';
3
3
  export * from './error.js';
4
+ export * from './output.js';
5
+ export * from './types.js';
6
+ export * from './version.js';
@@ -0,0 +1,10 @@
1
+ import { CommandResult, GlobalOptions } from './types.js';
2
+ /**
3
+ * Formats a CommandResult for console output.
4
+ * In 'json' mode, the full result is serialized.
5
+ * In 'text' mode, only the relevant payload is printed.
6
+ * @param {CommandResult} result - The result to format.
7
+ * @param {GlobalOptions} options - The global options to determine output format.
8
+ * @returns {string} - The formatted output string.
9
+ */
10
+ export declare function formatResult(result: CommandResult, options: GlobalOptions): string;
@@ -1,112 +1,21 @@
1
1
  import { Command } from 'commander';
2
+ import { MethodOperations } from './types.js';
2
3
  /**
3
4
  * CLI tool for the did:btcr2 method.
4
- * @type {DidBtcr2Cli}
5
- * @class DidBtcr2Cli
6
5
  */
7
6
  export declare class DidBtcr2Cli {
8
7
  readonly program: Command;
9
- constructor();
8
+ private readonly ops;
10
9
  /**
11
- * Configures the CLI commands.
12
- * @returns {void}
10
+ * Initializes the CLI with optional custom MethodOperations.
11
+ * @param {MethodOperations} ops - Custom operations for create, resolve, and update.
13
12
  */
14
- private configureCommands;
15
- /**
16
- * Invokes a command with the provided request.
17
- * @param {object} request The command request
18
- * @param {any} request.options The command options
19
- * @param {CommandRequest['action']} request.action The command action
20
- * @param {Btcr2Command} request.command The command instance
21
- * @returns {Promise<CommandResult>} The command result
22
- */
23
- private invokeCommand;
13
+ constructor(ops?: MethodOperations);
24
14
  /**
25
15
  * Runs the CLI with the provided argv or process.argv.
26
- * @param {string[]} [argv] The argv array to use. Defaults to process.argv.
16
+ * @param {string[]} [argv] - Optional array of command-line arguments.
17
+ * @returns {Promise<void>} - Resolves when execution is complete.
27
18
  */
28
19
  run(argv?: string[]): Promise<void>;
29
- /**
30
- * Normalizes argv to ensure it has at least two elements.
31
- * @param {string[]} argv The argv array to normalize
32
- * @returns {string[]} Normalized argv array
33
- */
34
- private normalizeArgv;
35
- /**
36
- * Handles errors thrown during CLI execution.
37
- * @param {unknown} error The error to handle
38
- * @returns {void}
39
- */
40
- private handleError;
41
- /**
42
- * Parses create command options and throws CLIError on invalid input.
43
- * @param {object} options The create command options
44
- * @param {string} options.type The identifier type
45
- * @param {string} options.network The bitcoin network
46
- * @param {string} options.bytes The genesis bytes as a hex string
47
- * @returns {CreateCommandOptions} The parsed create command options
48
- */
49
- private parseCreateOptions;
50
- /**
51
- * Parses resolve command options and throws CLIError on invalid input.
52
- * @param {object} options The resolve command options
53
- * @param {string} options.identifier The did:btcr2 identifier
54
- * @param {string} [options.resolutionOptions] JSON string of resolution options
55
- * @param {string} [options.resolutionOptionsPath] Path to a JSON file of resolution options
56
- * @returns {Promise<ResolveCommandOptions>} The parsed resolve command options
57
- */
58
- private parseResolveOptions;
59
- /**
60
- * Parses update command options and throws CLIError on invalid input.
61
- * @param {object} options The update command options
62
- * @param {string} options.sourceDocument The source DID document as a JSON string
63
- * @param {number} options.sourceVersionId The source version ID as a number
64
- * @param {string} options.patches The JSON Patch operations as a JSON string array
65
- * @param {string} options.verificationMethodId The DID document verification method ID as a string
66
- * @param {string} options.beaconId The beacon IDs as a JSON string array
67
- * @returns {UpdateCommandOptions} The parsed update command options
68
- */
69
- private parseUpdateOptions;
70
- /**
71
- * Parses a JSON option and throws a CLIError on failure.
72
- * @param {string} value JSON string to parse
73
- * @param {string} errorMessage Error message to use on failure
74
- * @param {Record<string, any>} data Additional data to include in the error
75
- * @returns {T} Parsed JSON object
76
- */
77
- private parseJsonOption;
78
- /**
79
- * Parses resolution options from JSON string or file path.
80
- * @param {object} options The options containing resolution options
81
- * @param {string} [options.resolutionOptions] JSON string of resolution options
82
- * @param {string} [options.resolutionOptionsPath] Path to a JSON file of resolution options
83
- * @returns {Promise<any>} The parsed resolution options
84
- */
85
- private parseResolutionOptions;
86
- /**
87
- * Validates the did:btcr2 identifier format.
88
- * @param {string} identifier The identifier to validate
89
- * @param {Record<string, any>} data Additional data to include in the error
90
- * @returns {void}
91
- */
92
- private validateIdentifier;
93
- /**
94
- * Validates if the provided network is supported.
95
- * @param {string} network The network to validate
96
- * @returns {boolean} True if the network is valid
97
- */
98
- private isNetworkValid;
99
- /**
100
- * Prints the command result to the console.
101
- * @param {CommandResult} result The command result to print
102
- * @returns {void}
103
- */
104
- private printResult;
105
- /**
106
- * Logs a payload to the console, formatting objects as JSON.
107
- * @param {unknown} payload The payload to log
108
- * @returns {void}
109
- */
110
- private log;
111
20
  }
112
21
  //# sourceMappingURL=cli.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAcpD;;;;GAIG;AACH,qBAAa,WAAW;IACtB,SAAgB,OAAO,EAAE,OAAO,CAAC;;IAUjC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAqEzB;;;;;;;OAOG;YACW,aAAa;IAQ3B;;;OAGG;IACU,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE;IAUhC;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAMrB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAanB;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;;;;;;OAOG;YACW,mBAAmB;IAajC;;;;;;;;;OASG;IACH,OAAO,CAAC,kBAAkB;IAgC1B;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAYvB;;;;;;OAMG;YACW,sBAAsB;IAmBpC;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAItB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAqBnB;;;;OAIG;IACH,OAAO,CAAC,GAAG;CAOZ"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AASpD,OAAO,EAAiB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAU7D;;GAEG;AACH,qBAAa,WAAW;IACtB,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAmB;IAEvC;;;OAGG;gBACS,GAAG,GAAE,gBAA6B;IAiB9C;;;;OAIG;IACU,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CASjD"}
@@ -0,0 +1,4 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerCreateCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
4
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAEL,aAAa,EACb,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAQrB,wBAAgB,qBAAqB,CACnC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,gBAAgB,EAC1B,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAuBN"}
@@ -0,0 +1,4 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerDeactivateCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
4
+ //# sourceMappingURL=deactivate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deactivate.d.ts","sourceRoot":"","sources":["../../../../src/commands/deactivate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAwB,MAAM,aAAa,CAAC;AAKpF,wBAAgB,yBAAyB,CACvC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,gBAAgB,EAC1B,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAwCN"}
@@ -0,0 +1,5 @@
1
+ export { registerCreateCommand } from './create.js';
2
+ export { registerResolveCommand } from './resolve.js';
3
+ export { registerUpdateCommand } from './update.js';
4
+ export { registerDeactivateCommand } from './deactivate.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerResolveCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
4
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAyB,MAAM,aAAa,CAAC;AAErF,wBAAgB,sBAAsB,CACpC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,gBAAgB,EAC1B,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAkBN"}
@@ -0,0 +1,4 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalOptions, MethodOperations } from '../types.js';
3
+ export declare function registerUpdateCommand(program: Command, ops: MethodOperations, globals: () => GlobalOptions): void;
4
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAwB,MAAM,aAAa,CAAC;AAEpF,wBAAgB,qBAAqB,CACnC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,gBAAgB,EAC1B,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CA6CN"}
@@ -1,4 +1,7 @@
1
1
  export * from './cli.js';
2
- export * from './command.js';
2
+ export * from './commands/index.js';
3
3
  export * from './error.js';
4
+ export * from './output.js';
5
+ export * from './types.js';
6
+ export * from './version.js';
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { CommandResult, GlobalOptions } from './types.js';
2
+ /**
3
+ * Formats a CommandResult for console output.
4
+ * In 'json' mode, the full result is serialized.
5
+ * In 'text' mode, only the relevant payload is printed.
6
+ * @param {CommandResult} result - The result to format.
7
+ * @param {GlobalOptions} options - The global options to determine output format.
8
+ * @returns {string} - The formatted output string.
9
+ */
10
+ export declare function formatResult(result: CommandResult, options: GlobalOptions): string;
11
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAMlF"}
@@ -0,0 +1,54 @@
1
+ import { PatchOperation } from '@did-btcr2/common';
2
+ import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
+ import { Btcr2DidDocument, DidCreateOptions, ResolutionOptions } from '@did-btcr2/method';
4
+ import { DidResolutionResult } from '@web5/dids';
5
+ export type NetworkOption = 'bitcoin' | 'testnet3' | 'testnet4' | 'signet' | 'mutinynet' | 'regtest';
6
+ export type OutputFormat = 'json' | 'text';
7
+ export declare const SUPPORTED_NETWORKS: NetworkOption[];
8
+ /** Dependency-injection interface for the DID method operations the CLI calls. */
9
+ export interface MethodOperations {
10
+ create(genesisBytes: Uint8Array, options: DidCreateOptions): string;
11
+ resolve(identifier: string, options?: ResolutionOptions): Promise<DidResolutionResult>;
12
+ update(params: {
13
+ sourceDocument: Btcr2DidDocument;
14
+ patches: PatchOperation[];
15
+ sourceVersionId: number;
16
+ verificationMethodId: string;
17
+ beaconId: string;
18
+ }): Promise<SignedBTCR2Update>;
19
+ }
20
+ export interface CreateCommandOptions {
21
+ type: 'k' | 'x';
22
+ bytes: string;
23
+ network: NetworkOption;
24
+ }
25
+ export interface ResolveCommandOptions {
26
+ identifier: string;
27
+ options?: ResolutionOptions;
28
+ }
29
+ export interface UpdateCommandOptions {
30
+ sourceDocument: Btcr2DidDocument;
31
+ patches: PatchOperation[];
32
+ sourceVersionId: number;
33
+ verificationMethodId: string;
34
+ beaconId: string;
35
+ }
36
+ export type CommandResult = {
37
+ action: 'create';
38
+ data: string;
39
+ } | {
40
+ action: 'resolve';
41
+ data: DidResolutionResult;
42
+ } | {
43
+ action: 'update';
44
+ data: SignedBTCR2Update;
45
+ } | {
46
+ action: 'deactivate';
47
+ data: SignedBTCR2Update;
48
+ };
49
+ export interface GlobalOptions {
50
+ output: OutputFormat;
51
+ verbose: boolean;
52
+ quiet: boolean;
53
+ }
54
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AACrG,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAE3C,eAAO,MAAM,kBAAkB,EAAE,aAAa,EAE7C,CAAC;AAEF,kFAAkF;AAClF,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CACJ,YAAY,EAAE,UAAU,EACxB,OAAO,EAAE,gBAAgB,GACxB,MAAM,CAAC;IACV,OAAO,CACL,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAChC,MAAM,CAAC,MAAM,EAAE;QACb,cAAc,EAAS,gBAAgB,CAAC;QACxC,OAAO,EAAgB,cAAc,EAAE,CAAC;QACxC,eAAe,EAAQ,MAAM,CAAC;QAC9B,oBAAoB,EAAG,MAAM,CAAC;QAC9B,QAAQ,EAAe,MAAM,CAAC;KAC/B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAM,GAAG,GAAG,GAAG,CAAC;IACpB,KAAK,EAAK,MAAM,CAAC;IACjB,OAAO,EAAG,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAG,MAAM,CAAC;IACpB,OAAO,CAAC,EAAK,iBAAiB,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAS,gBAAgB,CAAC;IACxC,OAAO,EAAgB,cAAc,EAAE,CAAC;IACxC,eAAe,EAAQ,MAAM,CAAC;IAC9B,oBAAoB,EAAG,MAAM,CAAC;IAC9B,QAAQ,EAAe,MAAM,CAAC;CAC/B;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,mBAAmB,CAAA;CAAE,GAChD;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAI,YAAY,CAAC;IACvB,OAAO,EAAG,OAAO,CAAC;IAClB,KAAK,EAAK,OAAO,CAAC;CACnB"}
@@ -0,0 +1,2 @@
1
+ export declare const VERSION: string;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,OAAO,EAAE,MAAsB,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { PatchOperation } from '@did-btcr2/common';
2
+ import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
+ import { Btcr2DidDocument, DidCreateOptions, ResolutionOptions } from '@did-btcr2/method';
4
+ import { DidResolutionResult } from '@web5/dids';
5
+ export type NetworkOption = 'bitcoin' | 'testnet3' | 'testnet4' | 'signet' | 'mutinynet' | 'regtest';
6
+ export type OutputFormat = 'json' | 'text';
7
+ export declare const SUPPORTED_NETWORKS: NetworkOption[];
8
+ /** Dependency-injection interface for the DID method operations the CLI calls. */
9
+ export interface MethodOperations {
10
+ create(genesisBytes: Uint8Array, options: DidCreateOptions): string;
11
+ resolve(identifier: string, options?: ResolutionOptions): Promise<DidResolutionResult>;
12
+ update(params: {
13
+ sourceDocument: Btcr2DidDocument;
14
+ patches: PatchOperation[];
15
+ sourceVersionId: number;
16
+ verificationMethodId: string;
17
+ beaconId: string;
18
+ }): Promise<SignedBTCR2Update>;
19
+ }
20
+ export interface CreateCommandOptions {
21
+ type: 'k' | 'x';
22
+ bytes: string;
23
+ network: NetworkOption;
24
+ }
25
+ export interface ResolveCommandOptions {
26
+ identifier: string;
27
+ options?: ResolutionOptions;
28
+ }
29
+ export interface UpdateCommandOptions {
30
+ sourceDocument: Btcr2DidDocument;
31
+ patches: PatchOperation[];
32
+ sourceVersionId: number;
33
+ verificationMethodId: string;
34
+ beaconId: string;
35
+ }
36
+ export type CommandResult = {
37
+ action: 'create';
38
+ data: string;
39
+ } | {
40
+ action: 'resolve';
41
+ data: DidResolutionResult;
42
+ } | {
43
+ action: 'update';
44
+ data: SignedBTCR2Update;
45
+ } | {
46
+ action: 'deactivate';
47
+ data: SignedBTCR2Update;
48
+ };
49
+ export interface GlobalOptions {
50
+ output: OutputFormat;
51
+ verbose: boolean;
52
+ quiet: boolean;
53
+ }
@@ -0,0 +1 @@
1
+ export declare const VERSION: string;