@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,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,291 +1,83 @@
1
- import { Identifier } from '@did-btcr2/method';
2
1
  import { Command, CommanderError } from 'commander';
3
- import { readFile } from 'fs/promises';
4
- import Btcr2Command from './command.js';
2
+ import { DidBtcr2 } from '@did-btcr2/method';
3
+ import { registerCreateCommand, registerDeactivateCommand, registerResolveCommand, registerUpdateCommand, } from './commands/index.js';
5
4
  import { CLIError } from './error.js';
6
- const SUPPORTED_NETWORKS = ['bitcoin', 'testnet3', 'testnet4', 'signet', 'mutinynet', 'regtest'];
5
+ import { VERSION } from './version.js';
6
+ /** Default MethodOperations delegating to DidBtcr2 static methods. */
7
+ const defaultOps = {
8
+ create: (genesisBytes, options) => DidBtcr2.create(genesisBytes, options),
9
+ resolve: (identifier, options) => DidBtcr2.resolve(identifier, options),
10
+ update: (params) => DidBtcr2.update(params),
11
+ };
7
12
  /**
8
13
  * CLI tool for the did:btcr2 method.
9
- * @type {DidBtcr2Cli}
10
- * @class DidBtcr2Cli
11
14
  */
12
15
  export class DidBtcr2Cli {
13
16
  program;
14
- constructor() {
15
- this.program = new Command('btcr2')
16
- .version('btcr2 0.1.0', '-v, --version', 'Output the current version')
17
- .description('CLI tool for the did:btcr2 method');
18
- this.configureCommands();
19
- }
20
- /**
21
- * Configures the CLI commands.
22
- * @returns {void}
23
- */
24
- configureCommands() {
25
- // Create command
26
- this.program
27
- .command('create')
28
- .description('Create an identifier and initial DID document')
29
- .requiredOption('-t, --type <type>', 'Identifier type <k|x>', 'k')
30
- .requiredOption('-n, --network <network>', 'Identifier bitcoin network <bitcoin|testnet3|testnet4|signet|mutinynet|regtest>')
31
- .requiredOption('-b, --bytes <bytes>', 'The genesis bytes used to create a DID and DID document as a hex string. ' +
32
- 'If type=k, MUST be secp256k1 public key. ' +
33
- 'If type=x, MUST be SHA-256 hash of a genesis document')
34
- .action(async (options) => {
35
- const parsedOptions = this.parseCreateOptions(options);
36
- const result = await this.invokeCommand({ options: parsedOptions, action: 'create', command: new Btcr2Command() });
37
- this.printResult(result);
38
- });
39
- // Resolve command
40
- this.program
41
- .command('resolve')
42
- .alias('read')
43
- .description('Resolve the DID document of the identifier.')
44
- .requiredOption('-i, --identifier <identifier>', 'did:btcr2 identifier')
45
- .option('-r, --resolutionOptions <resolutionOptions>', 'JSON string containing resolution options')
46
- .option('-p, --resolutionOptionsPath <resolutionOptionsPath>', 'Path to a JSON file containing resolution options')
47
- .action(async (options) => {
48
- const parsedOptions = await this.parseResolveOptions(options);
49
- const result = await this.invokeCommand({ options: parsedOptions, action: 'resolve', command: new Btcr2Command() });
50
- this.printResult(result);
51
- });
52
- // Update command
53
- this.program
54
- .command('update')
55
- .description('Update a did:btcr2 document.')
56
- .requiredOption('-i, --identifier <identifier>', 'did:btcr2 identifier')
57
- .requiredOption('-s, --sourceDocument <sourceDocument>', 'Source DID document as JSON string')
58
- .requiredOption('-v, --sourceVersionId <sourceVersionId>', 'Source version ID as a number')
59
- .requiredOption('-p, --patch <patch>', 'JSON Patch operations as a JSON string array')
60
- .requiredOption('-m, --verificationMethodId <verificationMethodId>', 'Did document verification method ID as a string')
61
- .requiredOption('-b, --beaconIds <beaconIds>', 'Beacon IDs as a JSON string array')
62
- .action(async (options) => {
63
- const parsedOptions = this.parseUpdateOptions(options);
64
- const result = await this.invokeCommand({ options: parsedOptions, action: 'update', command: new Btcr2Command() });
65
- this.printResult(result);
66
- });
67
- // Deactivate command
68
- this.program
69
- .command('deactivate')
70
- .alias('delete')
71
- .description('Deactivate the did:btcr2 identifier permanently.')
72
- .action(async () => {
73
- const result = await this.invokeCommand({ options: {}, action: 'deactivate', command: new Btcr2Command() });
74
- this.printResult(result);
75
- });
76
- }
17
+ ops;
77
18
  /**
78
- * Invokes a command with the provided request.
79
- * @param {object} request The command request
80
- * @param {any} request.options The command options
81
- * @param {CommandRequest['action']} request.action The command action
82
- * @param {Btcr2Command} request.command The command instance
83
- * @returns {Promise<CommandResult>} The command result
19
+ * Initializes the CLI with optional custom MethodOperations.
20
+ * @param {MethodOperations} ops - Custom operations for create, resolve, and update.
84
21
  */
85
- async invokeCommand(request) {
86
- return await request.command.execute({ action: request.action, options: request.options });
22
+ constructor(ops = defaultOps) {
23
+ this.ops = ops;
24
+ this.program = new Command('btcr2')
25
+ .version(`btcr2 ${VERSION}`, '-v, --version', 'Output the current version')
26
+ .description('CLI tool for the did:btcr2 method')
27
+ .option('-o, --output <format>', 'Output format <json|text>', 'text')
28
+ .option('--verbose', 'Verbose output', false)
29
+ .option('--quiet', 'Suppress non-essential output', false);
30
+ const globals = () => this.program.opts();
31
+ registerCreateCommand(this.program, this.ops, globals);
32
+ registerResolveCommand(this.program, this.ops, globals);
33
+ registerUpdateCommand(this.program, this.ops, globals);
34
+ registerDeactivateCommand(this.program, this.ops, globals);
87
35
  }
88
36
  /**
89
37
  * Runs the CLI with the provided argv or process.argv.
90
- * @param {string[]} [argv] The argv array to use. Defaults to process.argv.
38
+ * @param {string[]} [argv] - Optional array of command-line arguments.
39
+ * @returns {Promise<void>} - Resolves when execution is complete.
91
40
  */
92
41
  async run(argv) {
93
42
  try {
94
- const normalized = this.normalizeArgv(argv ?? process.argv);
43
+ const normalized = normalizeArgv(argv ?? process.argv);
95
44
  await this.program.parseAsync(normalized, { from: 'node' });
96
45
  if (!this.program.args.length)
97
46
  this.program.outputHelp();
98
47
  }
99
48
  catch (error) {
100
- this.handleError(error);
49
+ handleError(error);
101
50
  }
102
51
  }
103
- /**
104
- * Normalizes argv to ensure it has at least two elements.
105
- * @param {string[]} argv The argv array to normalize
106
- * @returns {string[]} Normalized argv array
107
- */
108
- normalizeArgv(argv) {
109
- if (argv.length >= 2)
110
- return argv;
111
- if (argv.length === 1)
112
- return ['node', argv[0]];
113
- return ['node', 'btcr2'];
52
+ }
53
+ /**
54
+ * Normalizes argv to ensure it has at least two elements.
55
+ * @param {string[]} argv - The original argv array.
56
+ * @returns {string[]} - The normalized argv array.
57
+ */
58
+ function normalizeArgv(argv) {
59
+ if (argv.length >= 2)
60
+ return argv;
61
+ if (argv.length === 1)
62
+ return ['node', argv[0]];
63
+ return ['node', 'btcr2'];
64
+ }
65
+ /**
66
+ * Handles errors thrown during CLI execution.
67
+ * @param {unknown} error - The error to handle.
68
+ * @returns {void}
69
+ */
70
+ function handleError(error) {
71
+ if (error instanceof CommanderError &&
72
+ (error.code === 'commander.helpDisplayed' || error.code === 'commander.help')) {
73
+ return;
114
74
  }
115
- /**
116
- * Handles errors thrown during CLI execution.
117
- * @param {unknown} error The error to handle
118
- * @returns {void}
119
- */
120
- handleError(error) {
121
- if (error instanceof CommanderError && (error.code === 'commander.helpDisplayed' || error.code === 'commander.help')) {
122
- return;
123
- }
124
- if (error instanceof CLIError) {
125
- console.error(error.message);
126
- process.exitCode ??= 1;
127
- return;
128
- }
129
- console.error(error);
75
+ if (error instanceof CLIError) {
76
+ console.error(error.message);
130
77
  process.exitCode ??= 1;
78
+ return;
131
79
  }
132
- /**
133
- * Parses create command options and throws CLIError on invalid input.
134
- * @param {object} options The create command options
135
- * @param {string} options.type The identifier type
136
- * @param {string} options.network The bitcoin network
137
- * @param {string} options.bytes The genesis bytes as a hex string
138
- * @returns {CreateCommandOptions} The parsed create command options
139
- */
140
- parseCreateOptions(options) {
141
- if (!['k', 'x'].includes(options.type)) {
142
- throw new CLIError('Invalid type. Must be "k" or "x".', 'INVALID_ARGUMENT_ERROR', options);
143
- }
144
- if (!this.isNetworkValid(options.network)) {
145
- throw new CLIError('Invalid network. Must be one of "bitcoin", "testnet3", "testnet4", "signet", "mutinynet", or "regtest".', 'INVALID_ARGUMENT_ERROR', options);
146
- }
147
- if (Buffer.from(options.bytes, 'hex').length === 0) {
148
- throw new CLIError('Invalid bytes. Must be a non-empty hex string.', 'INVALID_ARGUMENT_ERROR', options);
149
- }
150
- return {
151
- type: options.type,
152
- network: options.network,
153
- bytes: options.bytes,
154
- };
155
- }
156
- /**
157
- * Parses resolve command options and throws CLIError on invalid input.
158
- * @param {object} options The resolve command options
159
- * @param {string} options.identifier The did:btcr2 identifier
160
- * @param {string} [options.resolutionOptions] JSON string of resolution options
161
- * @param {string} [options.resolutionOptionsPath] Path to a JSON file of resolution options
162
- * @returns {Promise<ResolveCommandOptions>} The parsed resolve command options
163
- */
164
- async parseResolveOptions(options) {
165
- this.validateIdentifier(options.identifier, options);
166
- const resolutionOptions = await this.parseResolutionOptions(options);
167
- return {
168
- identifier: options.identifier,
169
- ...(resolutionOptions && { options: resolutionOptions }),
170
- };
171
- }
172
- /**
173
- * Parses update command options and throws CLIError on invalid input.
174
- * @param {object} options The update command options
175
- * @param {string} options.sourceDocument The source DID document as a JSON string
176
- * @param {number} options.sourceVersionId The source version ID as a number
177
- * @param {string} options.patches The JSON Patch operations as a JSON string array
178
- * @param {string} options.verificationMethodId The DID document verification method ID as a string
179
- * @param {string} options.beaconId The beacon IDs as a JSON string array
180
- * @returns {UpdateCommandOptions} The parsed update command options
181
- */
182
- parseUpdateOptions(options) {
183
- const sourceDocument = this.parseJsonOption(options.sourceDocument, 'Invalid options. Must be a valid JSON string.', options);
184
- const patches = this.parseJsonOption(options.patches, 'Invalid options. Must be a valid JSON string.', options);
185
- const beaconId = this.parseJsonOption(options.beaconId, 'Invalid options. Must be a valid JSON string.', options);
186
- return {
187
- sourceDocument,
188
- sourceVersionId: Number(options.sourceVersionId),
189
- patches,
190
- verificationMethodId: options.verificationMethodId,
191
- beaconId,
192
- };
193
- }
194
- /**
195
- * Parses a JSON option and throws a CLIError on failure.
196
- * @param {string} value JSON string to parse
197
- * @param {string} errorMessage Error message to use on failure
198
- * @param {Record<string, any>} data Additional data to include in the error
199
- * @returns {T} Parsed JSON object
200
- */
201
- parseJsonOption(value, errorMessage, data) {
202
- try {
203
- return JSON.parse(value);
204
- }
205
- catch {
206
- throw new CLIError(errorMessage, 'INVALID_ARGUMENT_ERROR', data);
207
- }
208
- }
209
- /**
210
- * Parses resolution options from JSON string or file path.
211
- * @param {object} options The options containing resolution options
212
- * @param {string} [options.resolutionOptions] JSON string of resolution options
213
- * @param {string} [options.resolutionOptionsPath] Path to a JSON file of resolution options
214
- * @returns {Promise<any>} The parsed resolution options
215
- */
216
- async parseResolutionOptions(options) {
217
- if (options.resolutionOptions) {
218
- return this.parseJsonOption(options.resolutionOptions, 'Invalid options. Must be a valid JSON string.', options);
219
- }
220
- if (options.resolutionOptionsPath) {
221
- try {
222
- const data = await readFile(options.resolutionOptionsPath, 'utf-8');
223
- return JSON.parse(data);
224
- }
225
- catch {
226
- throw new CLIError('Invalid options path. Must be a valid path to a JSON file.', 'INVALID_ARGUMENT_ERROR', options);
227
- }
228
- }
229
- return undefined;
230
- }
231
- /**
232
- * Validates the did:btcr2 identifier format.
233
- * @param {string} identifier The identifier to validate
234
- * @param {Record<string, any>} data Additional data to include in the error
235
- * @returns {void}
236
- */
237
- validateIdentifier(identifier, data) {
238
- try {
239
- Identifier.decode(identifier);
240
- }
241
- catch {
242
- throw new CLIError('Invalid identifier. Must be a valid did:btcr2 identifier.', 'INVALID_ARGUMENT_ERROR', data);
243
- }
244
- }
245
- /**
246
- * Validates if the provided network is supported.
247
- * @param {string} network The network to validate
248
- * @returns {boolean} True if the network is valid
249
- */
250
- isNetworkValid(network) {
251
- return SUPPORTED_NETWORKS.includes(network);
252
- }
253
- /**
254
- * Prints the command result to the console.
255
- * @param {CommandResult} result The command result to print
256
- * @returns {void}
257
- */
258
- printResult(result) {
259
- switch (result.action) {
260
- case 'create':
261
- this.log(result.did);
262
- break;
263
- case 'resolve':
264
- case 'read':
265
- this.log(result.resolution);
266
- break;
267
- case 'update':
268
- this.log(result.signed);
269
- break;
270
- case 'deactivate':
271
- case 'delete':
272
- this.log(result.message);
273
- break;
274
- default:
275
- this.log(result);
276
- }
277
- }
278
- /**
279
- * Logs a payload to the console, formatting objects as JSON.
280
- * @param {unknown} payload The payload to log
281
- * @returns {void}
282
- */
283
- log(payload) {
284
- if (typeof payload === 'string') {
285
- console.log(payload);
286
- return;
287
- }
288
- console.log(JSON.stringify(payload, null, 2));
289
- }
80
+ console.error(error);
81
+ process.exitCode ??= 1;
290
82
  }
291
83
  //# sourceMappingURL=cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,YAON,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,kBAAkB,GAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;AAElH;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACN,OAAO,CAAU;IAEjC;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;aAChC,OAAO,CAAC,aAAa,EAAE,eAAe,EAAE,4BAA4B,CAAC;aACrE,WAAW,CAAC,mCAAmC,CAAC,CAAC;QAEpD,IAAI,CAAC,iBAAiB,EAAE,C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,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAc;IACjC,IACE,KAAK,YAAY,cAAc;QAC/B,CAAC,KAAK,CAAC,IAAI,KAAK,yBAAyB,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,CAAC,EAC7E,CAAC;QACD,OAAO;IACT,CAAC;IACD,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { IdentifierTypes } from '@did-btcr2/common';
2
+ import { CLIError } from '../error.js';
3
+ import { formatResult } from '../output.js';
4
+ import { SUPPORTED_NETWORKS, } from '../types.js';
5
+ /** Expected byte length per identifier type: compressed secp256k1 = 33, SHA-256 hash = 32. */
6
+ const EXPECTED_BYTES = {
7
+ k: { length: 33, label: 'secp256k1 compressed public key (33 bytes)' },
8
+ x: { length: 32, label: 'SHA-256 hash (32 bytes)' },
9
+ };
10
+ export function registerCreateCommand(program, ops, globals) {
11
+ program
12
+ .command('create')
13
+ .description('Create an identifier and initial DID document')
14
+ .requiredOption('-t, --type <type>', 'Identifier type <k|x>', 'k')
15
+ .requiredOption('-n, --network <network>', 'Identifier bitcoin network <bitcoin|testnet3|testnet4|signet|mutinynet|regtest>')
16
+ .requiredOption('-b, --bytes <bytes>', 'Genesis bytes as a hex string. ' +
17
+ 'If type=k, MUST be secp256k1 public key. ' +
18
+ 'If type=x, MUST be SHA-256 hash of a genesis document')
19
+ .action(async (options) => {
20
+ const parsed = validateCreateOptions(options);
21
+ const idType = parsed.type === 'k' ? IdentifierTypes.KEY : IdentifierTypes.EXTERNAL;
22
+ const genesisBytes = Buffer.from(parsed.bytes, 'hex');
23
+ const data = ops.create(genesisBytes, { idType, network: parsed.network });
24
+ const result = { action: 'create', data };
25
+ console.log(formatResult(result, globals()));
26
+ });
27
+ }
28
+ function validateCreateOptions(options) {
29
+ if (!['k', 'x'].includes(options.type)) {
30
+ throw new CLIError('Invalid type. Must be "k" or "x".', 'INVALID_ARGUMENT_ERROR', options);
31
+ }
32
+ if (!SUPPORTED_NETWORKS.includes(options.network)) {
33
+ throw new CLIError('Invalid network. Must be one of "bitcoin", "testnet3", "testnet4", "signet", "mutinynet", or "regtest".', 'INVALID_ARGUMENT_ERROR', options);
34
+ }
35
+ const buf = Buffer.from(options.bytes, 'hex');
36
+ if (buf.length === 0) {
37
+ throw new CLIError('Invalid bytes. Must be a non-empty hex string.', 'INVALID_ARGUMENT_ERROR', options);
38
+ }
39
+ const expected = EXPECTED_BYTES[options.type];
40
+ if (buf.length !== expected.length) {
41
+ throw new CLIError(`Invalid bytes length for type="${options.type}": expected ${expected.label}, got ${buf.length} bytes.`, 'INVALID_ARGUMENT_ERROR', options);
42
+ }
43
+ return {
44
+ type: options.type,
45
+ network: options.network,
46
+ bytes: options.bytes,
47
+ };
48
+ }
49
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAKL,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,8FAA8F;AAC9F,MAAM,cAAc,GAAyD;IAC3E,CAAC,EAAG,EAAE,MAAM,EAAE,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E,CAAC;QACvC,MAAM,IAAI,QAAQ,CAChB,mCAAmC,EACnC,wBAAwB,EACxB,OAAO,CACR,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAwB,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,QAAQ,CAChB,yGAAyG,EACzG,wBAAwB,EACxB,OAAO,CACR,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,QAAQ,CAChB,gDAAgD,EAChD,wBAAwB,EACxB,OAAO,CACR,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,IAAiB,CAAC,CAAC;IAC3D,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QACnC,MAAM,IAAI,QAAQ,CAChB,kCAAkC,OAAO,CAAC,IAAI,eAAe,QAAQ,CAAC,KAAK,SAAS,GAAG,CAAC,MAAM,SAAS,EACvG,wBAAwB,EACxB,OAAO,CACR,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAM,OAAO,CAAC,IAAiB;QACnC,OAAO,EAAG,OAAO,CAAC,OAAwB;QAC1C,KAAK,EAAK,OAAO,CAAC,KAAK;KACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { CLIError } from '../error.js';
2
+ import { formatResult } from '../output.js';
3
+ /** The JSON Patch that marks a DID document as permanently deactivated. */
4
+ const DEACTIVATION_PATCH = [{ op: 'add', path: '/deactivated', value: true }];
5
+ export function registerDeactivateCommand(program, ops, globals) {
6
+ program
7
+ .command('deactivate')
8
+ .alias('delete')
9
+ .description('Deactivate the did:btcr2 identifier permanently. This is irreversible.')
10
+ .requiredOption('-s, --source-document <json>', 'Current DID document as JSON string', parseJsonArg('--source-document'))
11
+ .requiredOption('--source-version-id <number>', 'Current version ID of the DID document')
12
+ .requiredOption('-m, --verification-method-id <id>', 'DID document verification method ID used to sign the deactivation')
13
+ .requiredOption('-b, --beacon-id <json>', 'Beacon ID as a JSON string', parseJsonArg('--beacon-id'))
14
+ .action(async (options) => {
15
+ const parsed = {
16
+ sourceDocument: options.sourceDocument,
17
+ patches: DEACTIVATION_PATCH,
18
+ sourceVersionId: Number(options.sourceVersionId),
19
+ verificationMethodId: options.verificationMethodId,
20
+ beaconId: options.beaconId,
21
+ };
22
+ const data = await ops.update(parsed);
23
+ const result = { action: 'deactivate', data };
24
+ console.log(formatResult(result, globals()));
25
+ });
26
+ }
27
+ /**
28
+ * Returns a commander argParser that validates JSON.
29
+ * Errors at parse time with a clear flag reference.
30
+ */
31
+ function parseJsonArg(flagName) {
32
+ return (value) => {
33
+ try {
34
+ return JSON.parse(value);
35
+ }
36
+ catch {
37
+ throw new CLIError(`Invalid JSON for ${flagName}. Must be a valid JSON string.`, 'INVALID_ARGUMENT_ERROR', { flagName, value });
38
+ }
39
+ };
40
+ }
41
+ //# sourceMappingURL=deactivate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deactivate.js","sourceRoot":"","sources":["../../../../src/commands/deactivate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,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,GAA0B,EAC1B,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,YAAY,CAAC;SACrB,KAAK,CAAC,QAAQ,CAAC;SACf,WAAW,CAAC,w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export { registerUpdateCommand } from './update.js';
4
+ export { registerDeactivateCommand } from './deactivate.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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,59 @@
1
+ import { Identifier } from '@did-btcr2/method';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { CLIError } from '../error.js';
4
+ import { formatResult } from '../output.js';
5
+ export function registerResolveCommand(program, ops, globals) {
6
+ program
7
+ .command('resolve')
8
+ .alias('read')
9
+ .description('Resolve the DID document of the identifier.')
10
+ .requiredOption('-i, --identifier <identifier>', 'did:btcr2 identifier')
11
+ .option('-r, --resolution-options <json>', 'JSON string containing resolution options')
12
+ .option('-p, --resolution-options-path <path>', 'Path to a JSON file containing resolution options')
13
+ .action(async (options) => {
14
+ const parsed = await validateResolveOptions(options);
15
+ const data = await ops.resolve(parsed.identifier, parsed.options);
16
+ const result = { action: 'resolve', data };
17
+ console.log(formatResult(result, globals()));
18
+ });
19
+ }
20
+ async function validateResolveOptions(options) {
21
+ validateIdentifier(options.identifier, options);
22
+ const resolutionOptions = await parseResolutionOptions(options);
23
+ return {
24
+ identifier: options.identifier,
25
+ ...(resolutionOptions && { options: resolutionOptions }),
26
+ };
27
+ }
28
+ function validateIdentifier(identifier, data) {
29
+ try {
30
+ Identifier.decode(identifier);
31
+ }
32
+ catch {
33
+ throw new CLIError('Invalid identifier. Must be a valid did:btcr2 identifier.', 'INVALID_ARGUMENT_ERROR', data);
34
+ }
35
+ }
36
+ function parseJson(value, errorMessage, data) {
37
+ try {
38
+ return JSON.parse(value);
39
+ }
40
+ catch {
41
+ throw new CLIError(errorMessage, 'INVALID_ARGUMENT_ERROR', data);
42
+ }
43
+ }
44
+ async function parseResolutionOptions(options) {
45
+ if (options.resolutionOptions) {
46
+ return parseJson(options.resolutionOptions, 'Invalid resolution options. Must be a valid JSON string.', options);
47
+ }
48
+ if (options.resolutionOptionsPath) {
49
+ try {
50
+ const data = await readFile(options.resolutionOptionsPath, 'utf-8');
51
+ return JSON.parse(data);
52
+ }
53
+ catch {
54
+ throw new CLIError('Invalid resolution options path. Must be a valid path to a JSON file.', 'INVALID_ARGUMENT_ERROR', options);
55
+ }
56
+ }
57
+ return undefined;
58
+ }
59
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,UAAU,sBAAsB,CACpC,OAAiB,EACjB,GAA0B,EAC1B,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,CAAC,KAAK,EAAE,OAId,EAAE,EAAE;QACH,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACrD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC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