@did-btcr2/cli 0.5.0 → 0.5.3
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/.tsbuildinfo +1 -0
- package/dist/cjs/index.js +339 -7
- package/dist/esm/src/cli.js +1 -1
- package/dist/esm/src/cli.js.map +1 -1
- package/dist/esm/src/commands/create.js.map +1 -1
- package/dist/esm/src/commands/resolve.js +2 -0
- package/dist/esm/src/commands/resolve.js.map +1 -1
- package/dist/types/src/cli.d.ts +1 -1
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/commands/create.d.ts +2 -2
- package/dist/types/src/commands/create.d.ts.map +1 -1
- package/dist/types/src/commands/deactivate.d.ts +2 -2
- package/dist/types/src/commands/deactivate.d.ts.map +1 -1
- package/dist/types/src/commands/resolve.d.ts +2 -2
- package/dist/types/src/commands/resolve.d.ts.map +1 -1
- package/dist/types/src/commands/update.d.ts +2 -2
- package/dist/types/src/commands/update.d.ts.map +1 -1
- package/dist/types/src/output.d.ts +1 -1
- package/dist/types/src/output.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/cli.ts +4 -3
- package/src/commands/create.ts +4 -3
- package/src/commands/deactivate.ts +2 -2
- package/src/commands/resolve.ts +4 -2
- package/src/commands/update.ts +2 -2
- package/src/output.ts +1 -1
- package/dist/cjs/cli.js +0 -77
- package/dist/cjs/cli.js.map +0 -1
- package/dist/cjs/commands/create.js +0 -48
- package/dist/cjs/commands/create.js.map +0 -1
- package/dist/cjs/commands/deactivate.js +0 -41
- package/dist/cjs/commands/deactivate.js.map +0 -1
- package/dist/cjs/commands/index.js +0 -5
- package/dist/cjs/commands/index.js.map +0 -1
- package/dist/cjs/commands/resolve.js +0 -43
- package/dist/cjs/commands/resolve.js.map +0 -1
- package/dist/cjs/commands/update.js +0 -39
- package/dist/cjs/commands/update.js.map +0 -1
- package/dist/cjs/error.js +0 -10
- package/dist/cjs/error.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/output.js +0 -16
- package/dist/cjs/output.js.map +0 -1
- package/dist/cjs/types.js +0 -4
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/version.js +0 -22
- package/dist/cjs/version.js.map +0 -1
package/dist/cjs/cli.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Command, CommanderError } from 'commander';
|
|
2
|
-
import { createApi } from '@did-btcr2/api';
|
|
3
|
-
import { registerCreateCommand, registerDeactivateCommand, registerResolveCommand, registerUpdateCommand, } from './commands/index.js';
|
|
4
|
-
import { CLIError } from './error.js';
|
|
5
|
-
import { VERSION } from './version.js';
|
|
6
|
-
/**
|
|
7
|
-
* CLI tool for the did:btcr2 method.
|
|
8
|
-
*/
|
|
9
|
-
export class DidBtcr2Cli {
|
|
10
|
-
program;
|
|
11
|
-
api;
|
|
12
|
-
/**
|
|
13
|
-
* Initializes the CLI with an optional pre-configured API instance.
|
|
14
|
-
* @param {DidBtcr2Api} api - Optional API instance. Defaults to an unconfigured instance.
|
|
15
|
-
*/
|
|
16
|
-
constructor(api = createApi()) {
|
|
17
|
-
this.api = api;
|
|
18
|
-
this.program = new Command('btcr2')
|
|
19
|
-
.version(`btcr2 ${VERSION}`, '-v, --version', 'Output the current version')
|
|
20
|
-
.description('CLI tool for the did:btcr2 method')
|
|
21
|
-
.option('-o, --output <format>', 'Output format <json|text>', 'text')
|
|
22
|
-
.option('--verbose', 'Verbose output', false)
|
|
23
|
-
.option('--quiet', 'Suppress non-essential output', false);
|
|
24
|
-
const globals = () => this.program.opts();
|
|
25
|
-
registerCreateCommand(this.program, this.api, globals);
|
|
26
|
-
registerResolveCommand(this.program, this.api, globals);
|
|
27
|
-
registerUpdateCommand(this.program, this.api, globals);
|
|
28
|
-
registerDeactivateCommand(this.program, this.api, globals);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Runs the CLI with the provided argv or process.argv.
|
|
32
|
-
* @param {string[]} [argv] - Optional array of command-line arguments.
|
|
33
|
-
* @returns {Promise<void>} - Resolves when execution is complete.
|
|
34
|
-
*/
|
|
35
|
-
async run(argv) {
|
|
36
|
-
try {
|
|
37
|
-
const normalized = normalizeArgv(argv ?? process.argv);
|
|
38
|
-
await this.program.parseAsync(normalized, { from: 'node' });
|
|
39
|
-
if (!this.program.args.length)
|
|
40
|
-
this.program.outputHelp();
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
handleError(error);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Normalizes argv to ensure it has at least two elements.
|
|
49
|
-
* @param {string[]} argv - The original argv array.
|
|
50
|
-
* @returns {string[]} - The normalized argv array.
|
|
51
|
-
*/
|
|
52
|
-
function normalizeArgv(argv) {
|
|
53
|
-
if (argv.length >= 2)
|
|
54
|
-
return argv;
|
|
55
|
-
if (argv.length === 1)
|
|
56
|
-
return ['node', argv[0]];
|
|
57
|
-
return ['node', 'btcr2'];
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Handles errors thrown during CLI execution.
|
|
61
|
-
* @param {unknown} error - The error to handle.
|
|
62
|
-
* @returns {void}
|
|
63
|
-
*/
|
|
64
|
-
function handleError(error) {
|
|
65
|
-
if (error instanceof CommanderError &&
|
|
66
|
-
(error.code === 'commander.helpDisplayed' || error.code === 'commander.help')) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (error instanceof CLIError) {
|
|
70
|
-
console.error(error.message);
|
|
71
|
-
process.exitCode ??= 1;
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
console.error(error);
|
|
75
|
-
process.exitCode ??= 1;
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/cjs/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,O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48 +0,0 @@
|
|
|
1
|
-
import { CLIError } from '../error.js';
|
|
2
|
-
import { formatResult } from '../output.js';
|
|
3
|
-
import { SUPPORTED_NETWORKS, } from '../types.js';
|
|
4
|
-
/** Expected byte length per identifier type: compressed secp256k1 = 33, SHA-256 hash = 32. */
|
|
5
|
-
const EXPECTED_BYTES = {
|
|
6
|
-
k: { length: 33, label: 'secp256k1 compressed public key (33 bytes)' },
|
|
7
|
-
x: { length: 32, label: 'SHA-256 hash (32 bytes)' },
|
|
8
|
-
};
|
|
9
|
-
export function registerCreateCommand(program, api, globals) {
|
|
10
|
-
program
|
|
11
|
-
.command('create')
|
|
12
|
-
.description('Create an identifier and initial DID document')
|
|
13
|
-
.requiredOption('-t, --type <type>', 'Identifier type <k|x>', 'k')
|
|
14
|
-
.requiredOption('-n, --network <network>', 'Identifier bitcoin network <bitcoin|testnet3|testnet4|signet|mutinynet|regtest>')
|
|
15
|
-
.requiredOption('-b, --bytes <bytes>', 'Genesis bytes as a hex string. ' +
|
|
16
|
-
'If type=k, MUST be secp256k1 public key. ' +
|
|
17
|
-
'If type=x, MUST be SHA-256 hash of a genesis document')
|
|
18
|
-
.action(async (options) => {
|
|
19
|
-
const parsed = validateCreateOptions(options);
|
|
20
|
-
const type = parsed.type === 'k' ? 'deterministic' : 'external';
|
|
21
|
-
const genesisBytes = Buffer.from(parsed.bytes, 'hex');
|
|
22
|
-
const data = api.createDid(type, genesisBytes, { network: parsed.network });
|
|
23
|
-
const result = { action: 'create', data };
|
|
24
|
-
console.log(formatResult(result, globals()));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function validateCreateOptions(options) {
|
|
28
|
-
if (!['k', 'x'].includes(options.type)) {
|
|
29
|
-
throw new CLIError('Invalid type. Must be "k" or "x".', 'INVALID_ARGUMENT_ERROR', options);
|
|
30
|
-
}
|
|
31
|
-
if (!SUPPORTED_NETWORKS.includes(options.network)) {
|
|
32
|
-
throw new CLIError('Invalid network. Must be one of "bitcoin", "testnet3", "testnet4", "signet", "mutinynet", or "regtest".', 'INVALID_ARGUMENT_ERROR', options);
|
|
33
|
-
}
|
|
34
|
-
const buf = Buffer.from(options.bytes, 'hex');
|
|
35
|
-
if (buf.length === 0) {
|
|
36
|
-
throw new CLIError('Invalid bytes. Must be a non-empty hex string.', 'INVALID_ARGUMENT_ERROR', options);
|
|
37
|
-
}
|
|
38
|
-
const expected = EXPECTED_BYTES[options.type];
|
|
39
|
-
if (buf.length !== expected.length) {
|
|
40
|
-
throw new CLIError(`Invalid bytes length for type="${options.type}": expected ${expected.label}, got ${buf.length} bytes.`, 'INVALID_ARGUMENT_ERROR', options);
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
type: options.type,
|
|
44
|
-
network: options.network,
|
|
45
|
-
bytes: options.bytes,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=create.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/commands/create.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAIL,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,8FAA8F;AAC9F,MAAM,cAAc,GAAyD;IAC3E,CAAC,EAAG,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,4CAA4C,EAAE;IACvE,CAAC,EAAG,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE;CACrD,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,OAAiB,EACjB,GAAqB,EACrB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,+CAA+C,CAAC;SAC5D,cAAc,CAAC,mBAAmB,EAAE,uBAAuB,EAAE,GAAG,CAAC;SACjE,cAAc,CACb,yBAAyB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AC,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"}
|
|
@@ -1,41 +0,0 @@
|
|
|
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, api, 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 api.btcr2.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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deactivate.js","sourceRoot":"","sources":["../../../src/commands/deactivate.ts"],"names":[],"mappings":"AAEA,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,GAAqB,EACrB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,YAAY,CAAC;SACrB,KAAK,CAAC,QAAQ,CAAC;SACf,WAAW,CAAC,wEAAwE,CAAC;SACrF,cAAc,CACb,8BAA8B,EAC9B,qCAAqC,EACr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,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"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Identifier } from '@did-btcr2/api';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { CLIError } from '../error.js';
|
|
4
|
-
import { formatResult } from '../output.js';
|
|
5
|
-
export function registerResolveCommand(program, api, 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 api.resolveDid(parsed.identifier, parsed.options);
|
|
16
|
-
const result = { action: 'resolve', data };
|
|
17
|
-
console.log(formatResult(result, globals()));
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
async function validateResolveOptions(options) {
|
|
21
|
-
// Validate identifier format early
|
|
22
|
-
Identifier.decode(options.identifier);
|
|
23
|
-
let resolutionOptions = undefined;
|
|
24
|
-
if (options.resolutionOptions) {
|
|
25
|
-
try {
|
|
26
|
-
resolutionOptions = JSON.parse(options.resolutionOptions);
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
throw new CLIError('Invalid resolution options. Must be a valid JSON string.', 'INVALID_ARGUMENT_ERROR', options);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else if (options.resolutionOptionsPath) {
|
|
33
|
-
try {
|
|
34
|
-
const content = await readFile(options.resolutionOptionsPath, 'utf-8');
|
|
35
|
-
resolutionOptions = JSON.parse(content);
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
throw new CLIError('Invalid resolution options path. Must be a valid path to a JSON file.', 'INVALID_ARGUMENT_ERROR', options);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return { identifier: options.identifier, options: resolutionOptions };
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=resolve.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../src/commands/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,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,GAAqB,EACrB,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,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACrE,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,SAAkB,EAAE,IAAI,EAAE,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,sBAAsB,CAAC,OAIrC;IACC,mCAAmC;IACnC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEtC,IAAI,iBAAiB,GAAG,SAAS,CAAC;IAClC,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,QAAQ,CAChB,0DAA0D,EAC1D,wBAAwB,EACxB,OAAO,CACR,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;QACzC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;YACvE,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,QAAQ,CAChB,uEAAuE,EACvE,wBAAwB,EACxB,OAAO,CACR,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { CLIError } from '../error.js';
|
|
2
|
-
import { formatResult } from '../output.js';
|
|
3
|
-
export function registerUpdateCommand(program, api, 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 api.btcr2.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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/commands/update.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,UAAU,qBAAqB,CACnC,OAAiB,EACjB,GAAqB,EACrB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,QAAQ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CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/cjs/error.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { DidMethodError } from '@did-btcr2/common';
|
|
2
|
-
/**
|
|
3
|
-
* Custom CLI Error class extending DidMethodError.
|
|
4
|
-
*/
|
|
5
|
-
export class CLIError extends DidMethodError {
|
|
6
|
-
constructor(message, type = 'CLIError', data) {
|
|
7
|
-
super(message, { type, name: 'CLIError', data });
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=error.js.map
|
package/dist/cjs/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/cjs/output.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
|
package/dist/cjs/output.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/cjs/types.js
DELETED
package/dist/cjs/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/cjs/version.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
package/dist/cjs/version.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|