@did-btcr2/cli 0.3.1 → 0.5.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 (88) hide show
  1. package/LICENSE +373 -1
  2. package/dist/cjs/cli.js +50 -264
  3. package/dist/cjs/cli.js.map +1 -1
  4. package/dist/cjs/commands/create.js +48 -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 +43 -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 +50 -264
  25. package/dist/esm/src/cli.js.map +1 -1
  26. package/dist/esm/src/commands/create.js +48 -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 +43 -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/src/cli.d.ts +7 -98
  47. package/dist/types/src/cli.d.ts.map +1 -1
  48. package/dist/types/src/commands/create.d.ts +5 -0
  49. package/dist/types/src/commands/create.d.ts.map +1 -0
  50. package/dist/types/src/commands/deactivate.d.ts +5 -0
  51. package/dist/types/src/commands/deactivate.d.ts.map +1 -0
  52. package/dist/types/src/commands/index.d.ts +5 -0
  53. package/dist/types/src/commands/index.d.ts.map +1 -0
  54. package/dist/types/src/commands/resolve.d.ts +5 -0
  55. package/dist/types/src/commands/resolve.d.ts.map +1 -0
  56. package/dist/types/src/commands/update.d.ts +5 -0
  57. package/dist/types/src/commands/update.d.ts.map +1 -0
  58. package/dist/types/src/index.d.ts +4 -1
  59. package/dist/types/src/index.d.ts.map +1 -1
  60. package/dist/types/src/output.d.ts +11 -0
  61. package/dist/types/src/output.d.ts.map +1 -0
  62. package/dist/types/src/types.d.ts +42 -0
  63. package/dist/types/src/types.d.ts.map +1 -0
  64. package/dist/types/src/version.d.ts +2 -0
  65. package/dist/types/src/version.d.ts.map +1 -0
  66. package/package.json +7 -7
  67. package/src/cli.ts +61 -348
  68. package/src/commands/create.ts +87 -0
  69. package/src/commands/deactivate.ts +72 -0
  70. package/src/commands/index.ts +4 -0
  71. package/src/commands/resolve.ts +65 -0
  72. package/src/commands/update.ts +74 -0
  73. package/src/error.ts +2 -2
  74. package/src/index.ts +4 -1
  75. package/src/output.ts +17 -0
  76. package/src/types.ts +42 -0
  77. package/src/version.ts +21 -0
  78. package/dist/cjs/command.js +0 -35
  79. package/dist/cjs/command.js.map +0 -1
  80. package/dist/esm/src/command.js +0 -35
  81. package/dist/esm/src/command.js.map +0 -1
  82. package/dist/types/cli.d.ts +0 -111
  83. package/dist/types/command.d.ts +0 -55
  84. package/dist/types/error.d.ts +0 -7
  85. package/dist/types/index.d.ts +0 -3
  86. package/dist/types/src/command.d.ts +0 -56
  87. package/dist/types/src/command.d.ts.map +0 -1
  88. package/src/command.ts +0 -77
@@ -0,0 +1,74 @@
1
+ import type { DidBtcr2Api } from '@did-btcr2/api';
2
+ import { Command } from 'commander';
3
+ import { CLIError } from '../error.js';
4
+ import { formatResult } from '../output.js';
5
+ import { GlobalOptions, UpdateCommandOptions } from '../types.js';
6
+
7
+ export function registerUpdateCommand(
8
+ program : Command,
9
+ api : DidBtcr2Api,
10
+ globals : () => GlobalOptions,
11
+ ): void {
12
+ program
13
+ .command('update')
14
+ .description('Update a did:btcr2 document.')
15
+ .requiredOption(
16
+ '-s, --source-document <json>',
17
+ 'Source DID document as JSON string',
18
+ parseJsonArg('--source-document'),
19
+ )
20
+ .requiredOption(
21
+ '--source-version-id <number>',
22
+ 'Source version ID as a number'
23
+ )
24
+ .requiredOption(
25
+ '-p, --patches <json>',
26
+ 'JSON Patch operations as a JSON string array',
27
+ parseJsonArg('--patches'),
28
+ )
29
+ .requiredOption(
30
+ '-m, --verification-method-id <id>',
31
+ 'DID document verification method ID'
32
+ )
33
+ .requiredOption(
34
+ '-b, --beacon-id <json>',
35
+ 'Beacon ID as a JSON string',
36
+ parseJsonArg('--beacon-id'),
37
+ )
38
+ .action(async (options: {
39
+ sourceDocument : unknown;
40
+ sourceVersionId : string;
41
+ patches : unknown;
42
+ verificationMethodId : string;
43
+ beaconId : unknown;
44
+ }) => {
45
+ const parsed: UpdateCommandOptions = {
46
+ sourceDocument : options.sourceDocument as UpdateCommandOptions['sourceDocument'],
47
+ patches : options.patches as UpdateCommandOptions['patches'],
48
+ sourceVersionId : Number(options.sourceVersionId),
49
+ verificationMethodId : options.verificationMethodId,
50
+ beaconId : options.beaconId as UpdateCommandOptions['beaconId'],
51
+ };
52
+ const data = await api.btcr2.update(parsed);
53
+ const result = { action: 'update' as const, data };
54
+ console.log(formatResult(result, globals()));
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Returns a commander argParser that validates JSON.
60
+ * Errors at parse time with a clear flag reference.
61
+ */
62
+ function parseJsonArg(flagName: string): (value: string) => unknown {
63
+ return (value: string): unknown => {
64
+ try {
65
+ return JSON.parse(value);
66
+ } catch {
67
+ throw new CLIError(
68
+ `Invalid JSON for ${flagName}. Must be a valid JSON string.`,
69
+ 'INVALID_ARGUMENT_ERROR',
70
+ { flagName, value }
71
+ );
72
+ }
73
+ };
74
+ }
package/src/error.ts CHANGED
@@ -5,6 +5,6 @@ import { DidMethodError } from '@did-btcr2/common';
5
5
  */
6
6
  export class CLIError extends DidMethodError {
7
7
  constructor(message: string, type: string = 'CLIError', data?: Record<string, any>) {
8
- super(message, { type, name: type, data });
8
+ super(message, { type, name: 'CLIError', data });
9
9
  }
10
- }
10
+ }
package/src/index.ts CHANGED
@@ -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';
package/src/output.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { CommandResult, GlobalOptions } from './types.js';
2
+
3
+ /**
4
+ * Formats a CommandResult for console output.
5
+ * In 'json' mode, the full result is serialized.
6
+ * In 'text' mode, only the relevant payload is printed.
7
+ * @param {CommandResult} result - The result to format.
8
+ * @param {GlobalOptions} options - The global options to determine output format.
9
+ * @returns {string} - The formatted output string.
10
+ */
11
+ export function formatResult(result: CommandResult, options: GlobalOptions): string {
12
+ if (options.output === 'json') {
13
+ return JSON.stringify(result, null, 2);
14
+ }
15
+ const { data } = result;
16
+ return typeof data === 'string' ? data : JSON.stringify(data, null, 2);
17
+ }
package/src/types.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { PatchOperation } from '@did-btcr2/common';
2
+ import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
+ import type { Btcr2DidDocument, ResolutionOptions } from '@did-btcr2/method';
4
+ import type { DidResolutionResult } from '@web5/dids';
5
+
6
+ export type NetworkOption = 'bitcoin' | 'testnet3' | 'testnet4' | 'signet' | 'mutinynet' | 'regtest';
7
+ export type OutputFormat = 'json' | 'text';
8
+
9
+ export const SUPPORTED_NETWORKS: NetworkOption[] = [
10
+ 'bitcoin', 'testnet3', 'testnet4', 'signet', 'mutinynet', 'regtest'
11
+ ];
12
+
13
+ export interface CreateCommandOptions {
14
+ type : 'k' | 'x';
15
+ bytes : string;
16
+ network : NetworkOption;
17
+ }
18
+
19
+ export interface ResolveCommandOptions {
20
+ identifier : string;
21
+ options? : ResolutionOptions;
22
+ }
23
+
24
+ export interface UpdateCommandOptions {
25
+ sourceDocument : Btcr2DidDocument;
26
+ patches : PatchOperation[];
27
+ sourceVersionId : number;
28
+ verificationMethodId : string;
29
+ beaconId : string;
30
+ }
31
+
32
+ export type CommandResult =
33
+ | { action: 'create'; data: string }
34
+ | { action: 'resolve'; data: DidResolutionResult }
35
+ | { action: 'update'; data: SignedBTCR2Update }
36
+ | { action: 'deactivate'; data: SignedBTCR2Update };
37
+
38
+ export interface GlobalOptions {
39
+ output : OutputFormat;
40
+ verbose : boolean;
41
+ quiet : boolean;
42
+ }
package/src/version.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ /**
6
+ * Walks up from the compiled file location to find the CLI package.json.
7
+ * Works from both dist/esm/ and tests/compiled/src/.
8
+ */
9
+ function readVersion(): string {
10
+ let dir = dirname(fileURLToPath(import.meta.url));
11
+ for (let i = 0; i < 5; i++) {
12
+ try {
13
+ const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));
14
+ if (pkg.name === '@did-btcr2/cli') return pkg.version;
15
+ } catch { /* not found, go up */ }
16
+ dir = dirname(dir);
17
+ }
18
+ return '0.0.0';
19
+ }
20
+
21
+ export const VERSION: string = readVersion();
@@ -1,35 +0,0 @@
1
- import { IdentifierTypes, Logger, MethodError } from '@did-btcr2/common';
2
- import { DidBtcr2 } from '@did-btcr2/method';
3
- export default class Btcr2Command {
4
- async execute(request) {
5
- const action = request.action;
6
- switch (action) {
7
- case 'create': {
8
- const { type, bytes, network } = request.options;
9
- const idType = type === 'k' ? IdentifierTypes.KEY : IdentifierTypes.EXTERNAL;
10
- const genesisBytes = Buffer.from(bytes, 'hex');
11
- const did = DidBtcr2.create(genesisBytes, { idType, network });
12
- return { action: 'create', did };
13
- }
14
- case 'read':
15
- case 'resolve': {
16
- const { identifier, options } = request.options;
17
- const resolution = await DidBtcr2.resolve(identifier, options);
18
- return { action: request.action, resolution };
19
- }
20
- case 'update': {
21
- const signed = await DidBtcr2.update(request.options);
22
- return { action: 'update', signed };
23
- }
24
- case 'delete':
25
- case 'deactivate': {
26
- Logger.warn('// TODO: Update once DidBtcr2.deactivate implemented');
27
- return { action: 'deactivate', message: 'Deactivate not yet implemented' };
28
- }
29
- default: {
30
- throw new MethodError(`Invalid command: ${action}`, 'INVALID_COMMAND');
31
- }
32
- }
33
- }
34
- }
35
- //# sourceMappingURL=command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAEzF,OAAO,EAAoB,QAAQ,EAAqB,MAAM,mBAAmB,CAAC;AA2ClF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,KAAK,CAAC,OAAO,CAAC,OAAuB;QACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,QAAQ,CAAC,CAAC,CAAC;gBACd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,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IACH,CAAC;CACF"}
@@ -1,35 +0,0 @@
1
- import { IdentifierTypes, Logger, MethodError } from '@did-btcr2/common';
2
- import { DidBtcr2 } from '@did-btcr2/method';
3
- export default class Btcr2Command {
4
- async execute(request) {
5
- const action = request.action;
6
- switch (action) {
7
- case 'create': {
8
- const { type, bytes, network } = request.options;
9
- const idType = type === 'k' ? IdentifierTypes.KEY : IdentifierTypes.EXTERNAL;
10
- const genesisBytes = Buffer.from(bytes, 'hex');
11
- const did = DidBtcr2.create(genesisBytes, { idType, network });
12
- return { action: 'create', did };
13
- }
14
- case 'read':
15
- case 'resolve': {
16
- const { identifier, options } = request.options;
17
- const resolution = await DidBtcr2.resolve(identifier, options);
18
- return { action: request.action, resolution };
19
- }
20
- case 'update': {
21
- const signed = await DidBtcr2.update(request.options);
22
- return { action: 'update', signed };
23
- }
24
- case 'delete':
25
- case 'deactivate': {
26
- Logger.warn('// TODO: Update once DidBtcr2.deactivate implemented');
27
- return { action: 'deactivate', message: 'Deactivate not yet implemented' };
28
- }
29
- default: {
30
- throw new MethodError(`Invalid command: ${action}`, 'INVALID_COMMAND');
31
- }
32
- }
33
- }
34
- }
35
- //# sourceMappingURL=command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAEzF,OAAO,EAAoB,QAAQ,EAAqB,MAAM,mBAAmB,CAAC;AA2ClF,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,KAAK,CAAC,OAAO,CAAC,OAAuB;QACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,QAAQ,CAAC,CAAC,CAAC;gBACd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;gBACjD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,111 +0,0 @@
1
- import { Command } from 'commander';
2
- /**
3
- * CLI tool for the did:btcr2 method.
4
- * @type {DidBtcr2Cli}
5
- * @class DidBtcr2Cli
6
- */
7
- export declare class DidBtcr2Cli {
8
- readonly program: Command;
9
- constructor();
10
- /**
11
- * Configures the CLI commands.
12
- * @returns {void}
13
- */
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;
24
- /**
25
- * Runs the CLI with the provided argv or process.argv.
26
- * @param {string[]} [argv] The argv array to use. Defaults to process.argv.
27
- */
28
- 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
- }
@@ -1,55 +0,0 @@
1
- import { PatchOperation } from '@did-btcr2/common';
2
- import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
- import { Btcr2DidDocument, ResolutionOptions } from '@did-btcr2/method';
4
- import { DidResolutionResult } from '@web5/dids';
5
- export type NetworkOption = 'bitcoin' | 'testnet3' | 'testnet4' | 'signet' | 'mutinynet' | 'regtest';
6
- export interface CommandInterface {
7
- execute(request: CommandRequest): Promise<CommandResult>;
8
- }
9
- export interface CreateCommandOptions {
10
- type: 'k' | 'x';
11
- bytes: string;
12
- network: NetworkOption;
13
- }
14
- export interface ResolveCommandOptions {
15
- identifier: string;
16
- options?: ResolutionOptions;
17
- }
18
- export interface UpdateCommandOptions {
19
- sourceDocument: Btcr2DidDocument;
20
- sourceVersionId: number;
21
- patches: PatchOperation[];
22
- verificationMethodId: string;
23
- beaconId: string;
24
- }
25
- export interface DeactivateCommandOptions {
26
- }
27
- export type CommandRequest = {
28
- action: 'create';
29
- options: CreateCommandOptions;
30
- } | {
31
- action: 'resolve' | 'read';
32
- options: ResolveCommandOptions;
33
- } | {
34
- action: 'update';
35
- options: UpdateCommandOptions;
36
- } | {
37
- action: 'deactivate' | 'delete';
38
- options: DeactivateCommandOptions;
39
- };
40
- export type CommandResult = {
41
- action: 'create';
42
- did: string;
43
- } | {
44
- action: 'resolve' | 'read';
45
- resolution: DidResolutionResult;
46
- } | {
47
- action: 'update';
48
- signed: SignedBTCR2Update;
49
- } | {
50
- action: 'deactivate' | 'delete';
51
- message: string;
52
- };
53
- export default class Btcr2Command implements CommandInterface {
54
- execute(request: CommandRequest): Promise<CommandResult>;
55
- }
@@ -1,7 +0,0 @@
1
- import { DidMethodError } from '@did-btcr2/common';
2
- /**
3
- * Custom CLI Error class extending DidMethodError.
4
- */
5
- export declare class CLIError extends DidMethodError {
6
- constructor(message: string, type?: string, data?: Record<string, any>);
7
- }
@@ -1,3 +0,0 @@
1
- export * from './cli.js';
2
- export * from './command.js';
3
- export * from './error.js';
@@ -1,56 +0,0 @@
1
- import { PatchOperation } from '@did-btcr2/common';
2
- import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
- import { Btcr2DidDocument, ResolutionOptions } from '@did-btcr2/method';
4
- import { DidResolutionResult } from '@web5/dids';
5
- export type NetworkOption = 'bitcoin' | 'testnet3' | 'testnet4' | 'signet' | 'mutinynet' | 'regtest';
6
- export interface CommandInterface {
7
- execute(request: CommandRequest): Promise<CommandResult>;
8
- }
9
- export interface CreateCommandOptions {
10
- type: 'k' | 'x';
11
- bytes: string;
12
- network: NetworkOption;
13
- }
14
- export interface ResolveCommandOptions {
15
- identifier: string;
16
- options?: ResolutionOptions;
17
- }
18
- export interface UpdateCommandOptions {
19
- sourceDocument: Btcr2DidDocument;
20
- sourceVersionId: number;
21
- patches: PatchOperation[];
22
- verificationMethodId: string;
23
- beaconId: string;
24
- }
25
- export interface DeactivateCommandOptions {
26
- }
27
- export type CommandRequest = {
28
- action: 'create';
29
- options: CreateCommandOptions;
30
- } | {
31
- action: 'resolve' | 'read';
32
- options: ResolveCommandOptions;
33
- } | {
34
- action: 'update';
35
- options: UpdateCommandOptions;
36
- } | {
37
- action: 'deactivate' | 'delete';
38
- options: DeactivateCommandOptions;
39
- };
40
- export type CommandResult = {
41
- action: 'create';
42
- did: string;
43
- } | {
44
- action: 'resolve' | 'read';
45
- resolution: DidResolutionResult;
46
- } | {
47
- action: 'update';
48
- signed: SignedBTCR2Update;
49
- } | {
50
- action: 'deactivate' | 'delete';
51
- message: string;
52
- };
53
- export default class Btcr2Command implements CommandInterface {
54
- execute(request: CommandRequest): Promise<CommandResult>;
55
- }
56
- //# sourceMappingURL=command.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAY,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AAErG,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC1D;AAED,MAAM,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O,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CA8B/D"}
package/src/command.ts DELETED
@@ -1,77 +0,0 @@
1
- import { IdentifierTypes, Logger, MethodError, PatchOperation } from '@did-btcr2/common';
2
- import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
- import { Btcr2DidDocument, DidBtcr2, ResolutionOptions } from '@did-btcr2/method';
4
- import { DidResolutionResult } from '@web5/dids';
5
-
6
- export type NetworkOption = 'bitcoin' | 'testnet3' | 'testnet4' | 'signet' | 'mutinynet' | 'regtest';
7
-
8
- export interface CommandInterface {
9
- execute(request: CommandRequest): Promise<CommandResult>;
10
- }
11
-
12
- export interface CreateCommandOptions {
13
- type: 'k' | 'x';
14
- bytes: string;
15
- network: NetworkOption;
16
- }
17
-
18
- export interface ResolveCommandOptions {
19
- identifier: string;
20
- options?: ResolutionOptions;
21
- }
22
-
23
- export interface UpdateCommandOptions {
24
- sourceDocument: Btcr2DidDocument;
25
- sourceVersionId: number;
26
- patches: PatchOperation[];
27
- verificationMethodId: string;
28
- beaconId: string;
29
- }
30
- export interface DeactivateCommandOptions {
31
- // Placeholder for future deactivate payload once implemented.
32
- }
33
-
34
- export type CommandRequest =
35
- | { action: 'create'; options: CreateCommandOptions; }
36
- | { action: 'resolve' | 'read'; options: ResolveCommandOptions; }
37
- | { action: 'update'; options: UpdateCommandOptions; }
38
- | { action: 'deactivate' | 'delete'; options: DeactivateCommandOptions; };
39
-
40
- export type CommandResult =
41
- | { action: 'create'; did: string; }
42
- | { action: 'resolve' | 'read'; resolution: DidResolutionResult; }
43
- | { action: 'update'; signed: SignedBTCR2Update; }
44
- | { action: 'deactivate' | 'delete'; message: string; };
45
-
46
- export default class Btcr2Command implements CommandInterface {
47
- async execute(request: CommandRequest): Promise<CommandResult> {
48
- const action = request.action;
49
- switch (action) {
50
- case 'create': {
51
- const { type, bytes, network } = request.options;
52
- const idType = type === 'k' ? IdentifierTypes.KEY : IdentifierTypes.EXTERNAL;
53
- const genesisBytes = Buffer.from(bytes, 'hex');
54
- const did = DidBtcr2.create(genesisBytes, { idType, network });
55
- return { action: 'create', did };
56
- }
57
- case 'read':
58
- case 'resolve': {
59
- const { identifier, options } = request.options;
60
- const resolution = await DidBtcr2.resolve(identifier, options);
61
- return { action: request.action, resolution };
62
- }
63
- case 'update': {
64
- const signed = await DidBtcr2.update(request.options);
65
- return { action: 'update', signed };
66
- }
67
- case 'delete':
68
- case 'deactivate': {
69
- Logger.warn('// TODO: Update once DidBtcr2.deactivate implemented');
70
- return { action: 'deactivate', message: 'Deactivate not yet implemented' };
71
- }
72
- default:{
73
- throw new MethodError(`Invalid command: ${action}`, 'INVALID_COMMAND');
74
- }
75
- }
76
- }
77
- }