@did-btcr2/cli 0.20.0 → 0.21.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.
- package/README.md +31 -26
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +126 -178
- package/dist/esm/src/commands/deactivate.js +11 -88
- package/dist/esm/src/commands/deactivate.js.map +1 -1
- package/dist/esm/src/commands/resolve.js +4 -37
- package/dist/esm/src/commands/resolve.js.map +1 -1
- package/dist/esm/src/commands/update.js +15 -85
- package/dist/esm/src/commands/update.js.map +1 -1
- package/dist/esm/src/commands/write.js +119 -0
- package/dist/esm/src/commands/write.js.map +1 -0
- package/dist/esm/src/resolution-options.js +47 -0
- package/dist/esm/src/resolution-options.js.map +1 -0
- package/dist/esm/src/types.js.map +1 -1
- package/dist/types/src/commands/deactivate.d.ts +1 -1
- package/dist/types/src/commands/deactivate.d.ts.map +1 -1
- package/dist/types/src/commands/resolve.d.ts.map +1 -1
- package/dist/types/src/commands/update.d.ts +1 -1
- package/dist/types/src/commands/update.d.ts.map +1 -1
- package/dist/types/src/commands/write.d.ts +47 -0
- package/dist/types/src/commands/write.d.ts.map +1 -0
- package/dist/types/src/resolution-options.d.ts +21 -0
- package/dist/types/src/resolution-options.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +17 -7
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/commands/deactivate.ts +14 -142
- package/src/commands/resolve.ts +8 -64
- package/src/commands/update.ts +19 -139
- package/src/commands/write.ts +198 -0
- package/src/resolution-options.ts +67 -0
- package/src/types.ts +17 -7
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DEFAULT_MIN_CONF } from '@did-btcr2/api';
|
|
2
|
+
import type { ResolutionOptions } from '@did-btcr2/method';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { CLIError } from './error.js';
|
|
5
|
+
|
|
6
|
+
/** The flags that select the resolution options of a command. */
|
|
7
|
+
export type ResolutionOptionFlags = {
|
|
8
|
+
resolutionOptions? : string;
|
|
9
|
+
resolutionOptionsPath? : string;
|
|
10
|
+
minConf? : number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** The help text of `--min-conf`. `resolve`, `update`, and `deactivate` share it. */
|
|
14
|
+
export const MIN_CONF_HELP =
|
|
15
|
+
'Minimum block confirmations a beacon signal needs before resolution applies it '
|
|
16
|
+
+ `(positive integer, default: ${DEFAULT_MIN_CONF}). Overrides a minConf inside the JSON resolution options`;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Builds the resolution options from the flags. The inline JSON wins over
|
|
20
|
+
* the file. The `--min-conf` flag wins over a `minConf` inside the JSON.
|
|
21
|
+
* Returns `undefined` if no flag is set.
|
|
22
|
+
*/
|
|
23
|
+
export async function readResolutionOptions(flags: ResolutionOptionFlags): Promise<ResolutionOptions | undefined> {
|
|
24
|
+
let resolutionOptions: ResolutionOptions | undefined;
|
|
25
|
+
if (flags.resolutionOptions) {
|
|
26
|
+
try {
|
|
27
|
+
resolutionOptions = JSON.parse(flags.resolutionOptions);
|
|
28
|
+
} catch {
|
|
29
|
+
throw new CLIError(
|
|
30
|
+
'Invalid resolution options. Must be a valid JSON string.',
|
|
31
|
+
'INVALID_ARGUMENT_ERROR',
|
|
32
|
+
{ resolutionOptions: flags.resolutionOptions }
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
} else if (flags.resolutionOptionsPath) {
|
|
36
|
+
try {
|
|
37
|
+
const content = await readFile(flags.resolutionOptionsPath, 'utf-8');
|
|
38
|
+
resolutionOptions = JSON.parse(content);
|
|
39
|
+
} catch {
|
|
40
|
+
throw new CLIError(
|
|
41
|
+
'Invalid resolution options path. Must be a valid path to a JSON file.',
|
|
42
|
+
'INVALID_ARGUMENT_ERROR',
|
|
43
|
+
{ resolutionOptionsPath: flags.resolutionOptionsPath }
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// The flag wins over a minConf inside the JSON options.
|
|
48
|
+
if (flags.minConf !== undefined) {
|
|
49
|
+
resolutionOptions = { ...(resolutionOptions ?? {}), minConf: flags.minConf };
|
|
50
|
+
}
|
|
51
|
+
return resolutionOptions;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Commander argParser for `--min-conf`. Accepts a positive integer (minimum 1),
|
|
56
|
+
* the domain the specification gives `minConf`. Errors at parse time otherwise.
|
|
57
|
+
*/
|
|
58
|
+
export function parseMinConf(value: string): number {
|
|
59
|
+
if (!/^[1-9]\d*$/.test(value)) {
|
|
60
|
+
throw new CLIError(
|
|
61
|
+
'--min-conf must be a positive integer (minimum 1).',
|
|
62
|
+
'INVALID_ARGUMENT_ERROR',
|
|
63
|
+
{ value },
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return Number(value);
|
|
67
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { DidUpdateResult } from '@did-btcr2/api';
|
|
2
|
-
import type { PatchOperation } from '@did-btcr2/common';
|
|
1
|
+
import type { BroadcastOptions, DidUpdateResult, PublishToCasMode, Signer } from '@did-btcr2/api';
|
|
3
2
|
import type { Btcr2DidDocument, ResolutionOptions } from '@did-btcr2/method';
|
|
4
3
|
import type { DidResolutionResult } from '@web5/dids';
|
|
5
4
|
import type { DoctorReport, EffectiveConfig } from './config.js';
|
|
@@ -36,12 +35,23 @@ export interface ResolveCommandOptions {
|
|
|
36
35
|
options? : ResolutionOptions;
|
|
37
36
|
}
|
|
38
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The parameters that `update` and `deactivate` hand to the api's `updateDid`
|
|
40
|
+
* and `deactivateDid`. `update` adds `patches`. An absent source pair lets the
|
|
41
|
+
* api resolve the current document with `resolutionOptions` (ADR 098, ADR
|
|
42
|
+
* 101). An absent `verificationMethodId` or `beaconId` lets the api derive it
|
|
43
|
+
* (ADR 104).
|
|
44
|
+
*/
|
|
39
45
|
export interface UpdateCommandOptions {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
did : string;
|
|
47
|
+
signer : Signer;
|
|
48
|
+
sourceDocument? : Btcr2DidDocument;
|
|
49
|
+
sourceVersionId? : number;
|
|
50
|
+
verificationMethodId? : string;
|
|
51
|
+
beaconId? : string;
|
|
52
|
+
resolutionOptions? : ResolutionOptions;
|
|
53
|
+
publishToCas : PublishToCasMode;
|
|
54
|
+
broadcastOptions? : BroadcastOptions;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
export type CommandResult =
|