@did-btcr2/cli 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.js +233 -115
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/command.js +27 -33
- package/dist/cjs/command.js.map +1 -1
- package/dist/cjs/error.js +10 -0
- package/dist/cjs/error.js.map +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/bin/btcr2.js +5 -0
- package/dist/esm/bin/btcr2.js.map +1 -0
- package/dist/esm/src/cli.js +294 -0
- package/dist/esm/src/cli.js.map +1 -0
- package/dist/esm/src/command.js +35 -0
- package/dist/esm/src/command.js.map +1 -0
- package/dist/esm/src/error.js +10 -0
- package/dist/esm/src/error.js.map +1 -0
- package/dist/esm/src/index.js +4 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/types/bin/btcr2.d.ts +3 -0
- package/dist/types/bin/btcr2.d.ts.map +1 -0
- package/dist/types/cli.d.ts +99 -18
- package/dist/types/command.d.ts +49 -9
- package/dist/types/error.d.ts +7 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/src/cli.d.ts +113 -0
- package/dist/types/src/cli.d.ts.map +1 -0
- package/dist/types/src/command.d.ts +55 -0
- package/dist/types/src/command.d.ts.map +1 -0
- package/dist/types/src/error.d.ts +8 -0
- package/dist/types/src/error.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/package.json +14 -19
- package/src/cli.ts +302 -161
- package/src/command.ts +66 -38
- package/src/error.ts +10 -0
- package/src/index.ts +2 -1
- package/dist/esm/cli.js +0 -176
- package/dist/esm/cli.js.map +0 -1
- package/dist/esm/command.js +0 -41
- package/dist/esm/command.js.map +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
- package/dist/types/cli.d.ts.map +0 -1
- package/dist/types/command.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
|
@@ -0,0 +1,113 @@
|
|
|
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.identifier The did:btcr2 identifier
|
|
63
|
+
* @param {string} options.sourceDocument The source DID document as a JSON string
|
|
64
|
+
* @param {number} options.sourceVersionId The source version ID as a number
|
|
65
|
+
* @param {string} options.patch The JSON Patch operations as a JSON string array
|
|
66
|
+
* @param {string} options.verificationMethodId The DID document verification method ID as a string
|
|
67
|
+
* @param {string} options.beaconIds The beacon IDs as a JSON string array
|
|
68
|
+
* @returns {UpdateCommandOptions} The parsed update command options
|
|
69
|
+
*/
|
|
70
|
+
private parseUpdateOptions;
|
|
71
|
+
/**
|
|
72
|
+
* Parses a JSON option and throws a CLIError on failure.
|
|
73
|
+
* @param {string} value JSON string to parse
|
|
74
|
+
* @param {string} errorMessage Error message to use on failure
|
|
75
|
+
* @param {Record<string, any>} data Additional data to include in the error
|
|
76
|
+
* @returns {T} Parsed JSON object
|
|
77
|
+
*/
|
|
78
|
+
private parseJsonOption;
|
|
79
|
+
/**
|
|
80
|
+
* Parses resolution options from JSON string or file path.
|
|
81
|
+
* @param {object} options The options containing resolution options
|
|
82
|
+
* @param {string} [options.resolutionOptions] JSON string of resolution options
|
|
83
|
+
* @param {string} [options.resolutionOptionsPath] Path to a JSON file of resolution options
|
|
84
|
+
* @returns {Promise<any>} The parsed resolution options
|
|
85
|
+
*/
|
|
86
|
+
private parseResolutionOptions;
|
|
87
|
+
/**
|
|
88
|
+
* Validates the did:btcr2 identifier format.
|
|
89
|
+
* @param {string} identifier The identifier to validate
|
|
90
|
+
* @param {Record<string, any>} data Additional data to include in the error
|
|
91
|
+
* @returns {void}
|
|
92
|
+
*/
|
|
93
|
+
private validateIdentifier;
|
|
94
|
+
/**
|
|
95
|
+
* Validates if the provided network is supported.
|
|
96
|
+
* @param {string} network The network to validate
|
|
97
|
+
* @returns {boolean} True if the network is valid
|
|
98
|
+
*/
|
|
99
|
+
private isNetworkValid;
|
|
100
|
+
/**
|
|
101
|
+
* Prints the command result to the console.
|
|
102
|
+
* @param {CommandResult} result The command result to print
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
private printResult;
|
|
106
|
+
/**
|
|
107
|
+
* Logs a payload to the console, formatting objects as JSON.
|
|
108
|
+
* @param {unknown} payload The payload to log
|
|
109
|
+
* @returns {void}
|
|
110
|
+
*/
|
|
111
|
+
private log;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +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;IAsEzB;;;;;;;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;;;;;;;;;;OAUG;IACH,OAAO,CAAC,kBAAkB;IAmC1B;;;;;;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"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { PatchOperation } from '@did-btcr2/common';
|
|
2
|
+
import { DidDocument, DidResolutionOptions, DidResolutionResult, SignalsMetadata } from '@did-btcr2/method';
|
|
3
|
+
export type NetworkOption = 'bitcoin' | 'testnet3' | 'testnet4' | 'signet' | 'mutinynet' | 'regtest';
|
|
4
|
+
export interface CommandInterface {
|
|
5
|
+
execute(request: CommandRequest): Promise<CommandResult>;
|
|
6
|
+
}
|
|
7
|
+
export interface CreateCommandOptions {
|
|
8
|
+
type: 'k' | 'x';
|
|
9
|
+
bytes: string;
|
|
10
|
+
network: NetworkOption;
|
|
11
|
+
}
|
|
12
|
+
export interface ResolveCommandOptions {
|
|
13
|
+
identifier: string;
|
|
14
|
+
options?: DidResolutionOptions;
|
|
15
|
+
}
|
|
16
|
+
export interface UpdateCommandOptions {
|
|
17
|
+
identifier: string;
|
|
18
|
+
sourceDocument: DidDocument;
|
|
19
|
+
sourceVersionId: number;
|
|
20
|
+
patch: PatchOperation[];
|
|
21
|
+
verificationMethodId: string;
|
|
22
|
+
beaconIds: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface DeactivateCommandOptions {
|
|
25
|
+
}
|
|
26
|
+
export type CommandRequest = {
|
|
27
|
+
action: 'create';
|
|
28
|
+
options: CreateCommandOptions;
|
|
29
|
+
} | {
|
|
30
|
+
action: 'resolve' | 'read';
|
|
31
|
+
options: ResolveCommandOptions;
|
|
32
|
+
} | {
|
|
33
|
+
action: 'update';
|
|
34
|
+
options: UpdateCommandOptions;
|
|
35
|
+
} | {
|
|
36
|
+
action: 'deactivate' | 'delete';
|
|
37
|
+
options: DeactivateCommandOptions;
|
|
38
|
+
};
|
|
39
|
+
export type CommandResult = {
|
|
40
|
+
action: 'create';
|
|
41
|
+
did: string;
|
|
42
|
+
} | {
|
|
43
|
+
action: 'resolve' | 'read';
|
|
44
|
+
resolution: DidResolutionResult;
|
|
45
|
+
} | {
|
|
46
|
+
action: 'update';
|
|
47
|
+
metadata: SignalsMetadata;
|
|
48
|
+
} | {
|
|
49
|
+
action: 'deactivate' | 'delete';
|
|
50
|
+
message: string;
|
|
51
|
+
};
|
|
52
|
+
export default class Btcr2Command implements CommandInterface {
|
|
53
|
+
execute(request: CommandRequest): Promise<CommandResult>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAY,WAAW,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEtH,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,WAAW,oBAAoB;IACnC,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,oBAAo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4
|
+
*/
|
|
5
|
+
export declare class CLIError extends DidMethodError {
|
|
6
|
+
constructor(message: string, type?: string, data?: Record<string, any>);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,qBAAa,QAAS,SAAQ,cAAc;gBAC9B,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAmB,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGnF"}
|
|
@@ -0,0 +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"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-btcr2/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI for interacting with did-btcr2-js, the JavaScript/TypeScript reference implementation of the did:btcr2 method. Exposes various parts of multiple packages in the did-btcr2-js monorepo.",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
7
7
|
"module": "./dist/esm/index.js",
|
|
8
8
|
"types": "./dist/types/index.d.ts",
|
|
9
9
|
"bin": {
|
|
10
|
-
"btcr2": "./dist/esm/
|
|
10
|
+
"btcr2": "./dist/esm/bin/btcr2.js"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"commander": "^13.1.0",
|
|
60
60
|
"@did-btcr2/common": "2.2.2",
|
|
61
|
-
"@did-btcr2/method": "0.18.
|
|
61
|
+
"@did-btcr2/method": "0.18.1"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@eslint/js": "^9.21.0",
|
|
@@ -86,27 +86,22 @@
|
|
|
86
86
|
"typescript-eslint": "^8.25.0"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
|
-
"clean": "rimraf dist
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"wipe:clean:install": "pnpm wipe:clean && pnpm install",
|
|
89
|
+
"clean:build": "rimraf dist",
|
|
90
|
+
"clean:tests": "rimraf coverage tests/compiled",
|
|
91
|
+
"clean:deps": "rimraf node_modules pnpm-lock.json",
|
|
92
|
+
"clean": "pnpm clean:build && pnpm clean:tests",
|
|
93
|
+
"wipe": "pnpm clean && pnpm clean:deps",
|
|
95
94
|
"reinstall": "pnpm install --force",
|
|
96
|
-
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs",
|
|
95
|
+
"build": "pnpm clean:build && pnpm build:esm && pnpm build:cjs",
|
|
97
96
|
"build:esm": "rimraf dist/esm dist/types && pnpm tsc -p tsconfig.json",
|
|
98
97
|
"build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
|
|
99
|
-
"build:tests": "pnpm tsc -p tests/tsconfig.json",
|
|
98
|
+
"build:tests": "pnpm clean:tests && pnpm tsc -p tests/tsconfig.json",
|
|
100
99
|
"build:all": "pnpm build && pnpm build:tests",
|
|
101
|
-
"release": "pnpm build && pnpm pack && mv *.tgz ../../release/cli",
|
|
102
100
|
"lint": "eslint . --max-warnings 0",
|
|
103
101
|
"lint:fix": "eslint . --fix",
|
|
104
|
-
"test": "pnpm c8
|
|
105
|
-
"build:test": "pnpm build && pnpm build:tests && pnpm c8
|
|
106
|
-
"build:lint
|
|
107
|
-
"prepublish": "pnpm build"
|
|
108
|
-
"version": "pnpm version",
|
|
109
|
-
"version:no-git": "pnpm version --no-commit-hooks --no-git-tag-version",
|
|
110
|
-
"version:new": "[ -z \"$NEW_VERSION\" ] && echo 'ERROR: NEW_VERSION is not set' && exit 1 || (git checkout -b $NEW_VERSION && git tag $NEW_VERSION && pnpm version:no-git $NEW_VERSION)"
|
|
102
|
+
"test": "pnpm c8 mocha",
|
|
103
|
+
"build:test": "pnpm build && pnpm build:tests && pnpm c8 mocha",
|
|
104
|
+
"build:lint": "pnpm build && pnpm build:tests && pnpm lint:fix",
|
|
105
|
+
"prepublish": "pnpm build"
|
|
111
106
|
}
|
|
112
107
|
}
|