@did-btcr2/cli 0.21.0 → 0.23.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 +29 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +494 -64
- package/dist/esm/src/cli.js +4 -2
- package/dist/esm/src/cli.js.map +1 -1
- package/dist/esm/src/commands/completion.js +1 -1
- package/dist/esm/src/commands/completion.js.map +1 -1
- package/dist/esm/src/commands/create.js +33 -41
- package/dist/esm/src/commands/create.js.map +1 -1
- package/dist/esm/src/commands/genesis.js +119 -0
- package/dist/esm/src/commands/genesis.js.map +1 -0
- package/dist/esm/src/commands/identifier.js +96 -0
- package/dist/esm/src/commands/identifier.js.map +1 -0
- package/dist/esm/src/commands/index.js +2 -0
- package/dist/esm/src/commands/index.js.map +1 -1
- package/dist/esm/src/commands/resolve.js +15 -1
- package/dist/esm/src/commands/resolve.js.map +1 -1
- package/dist/esm/src/commands/write.js +10 -7
- package/dist/esm/src/commands/write.js.map +1 -1
- package/dist/esm/src/genesis-document-file.js +26 -0
- package/dist/esm/src/genesis-document-file.js.map +1 -0
- package/dist/esm/src/genesis-spec.js +93 -0
- package/dist/esm/src/genesis-spec.js.map +1 -0
- package/dist/esm/src/genesis-wizard.js +132 -0
- package/dist/esm/src/genesis-wizard.js.map +1 -0
- package/dist/esm/src/hints.js +14 -3
- package/dist/esm/src/hints.js.map +1 -1
- package/dist/esm/src/network-option.js +39 -0
- package/dist/esm/src/network-option.js.map +1 -0
- package/dist/esm/src/resolution-options.js +19 -2
- package/dist/esm/src/resolution-options.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 +5 -4
- package/dist/types/src/commands/create.d.ts.map +1 -1
- package/dist/types/src/commands/genesis.d.ts +20 -0
- package/dist/types/src/commands/genesis.d.ts.map +1 -0
- package/dist/types/src/commands/identifier.d.ts +12 -0
- package/dist/types/src/commands/identifier.d.ts.map +1 -0
- package/dist/types/src/commands/index.d.ts +2 -0
- package/dist/types/src/commands/index.d.ts.map +1 -1
- package/dist/types/src/commands/resolve.d.ts +7 -0
- package/dist/types/src/commands/resolve.d.ts.map +1 -1
- package/dist/types/src/commands/write.d.ts +2 -1
- package/dist/types/src/commands/write.d.ts.map +1 -1
- package/dist/types/src/genesis-document-file.d.ts +11 -0
- package/dist/types/src/genesis-document-file.d.ts.map +1 -0
- package/dist/types/src/genesis-spec.d.ts +70 -0
- package/dist/types/src/genesis-spec.d.ts.map +1 -0
- package/dist/types/src/genesis-wizard.d.ts +30 -0
- package/dist/types/src/genesis-wizard.d.ts.map +1 -0
- package/dist/types/src/hints.d.ts +7 -0
- package/dist/types/src/hints.d.ts.map +1 -1
- package/dist/types/src/network-option.d.ts +15 -0
- package/dist/types/src/network-option.d.ts.map +1 -0
- package/dist/types/src/resolution-options.d.ts +6 -2
- package/dist/types/src/resolution-options.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +38 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/cli.ts +5 -1
- package/src/commands/completion.ts +1 -1
- package/src/commands/create.ts +39 -55
- package/src/commands/genesis.ts +149 -0
- package/src/commands/identifier.ts +134 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/resolve.ts +20 -1
- package/src/commands/write.ts +10 -7
- package/src/genesis-document-file.ts +35 -0
- package/src/genesis-spec.ts +149 -0
- package/src/genesis-wizard.ts +163 -0
- package/src/hints.ts +13 -2
- package/src/network-option.ts +50 -0
- package/src/resolution-options.ts +21 -2
- package/src/types.ts +34 -2
|
@@ -2,14 +2,24 @@ import { DEFAULT_MIN_CONF } from '@did-btcr2/api';
|
|
|
2
2
|
import type { ResolutionOptions } from '@did-btcr2/method';
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
4
|
import { CLIError } from './error.js';
|
|
5
|
+
import { readGenesisDocumentFile } from './genesis-document-file.js';
|
|
5
6
|
|
|
6
7
|
/** The flags that select the resolution options of a command. */
|
|
7
8
|
export type ResolutionOptionFlags = {
|
|
8
9
|
resolutionOptions? : string;
|
|
9
10
|
resolutionOptionsPath? : string;
|
|
10
11
|
minConf? : number;
|
|
12
|
+
genesisDocument? : string;
|
|
11
13
|
};
|
|
12
14
|
|
|
15
|
+
/** Whether any resolution flag is set. */
|
|
16
|
+
export function hasResolutionFlags(flags: ResolutionOptionFlags): boolean {
|
|
17
|
+
return flags.resolutionOptions !== undefined
|
|
18
|
+
|| flags.resolutionOptionsPath !== undefined
|
|
19
|
+
|| flags.minConf !== undefined
|
|
20
|
+
|| flags.genesisDocument !== undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
/** The help text of `--min-conf`. `resolve`, `update`, and `deactivate` share it. */
|
|
14
24
|
export const MIN_CONF_HELP =
|
|
15
25
|
'Minimum block confirmations a beacon signal needs before resolution applies it '
|
|
@@ -17,8 +27,9 @@ export const MIN_CONF_HELP =
|
|
|
17
27
|
|
|
18
28
|
/**
|
|
19
29
|
* 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
|
-
*
|
|
30
|
+
* the file. The `--min-conf` flag wins over a `minConf` inside the JSON. The
|
|
31
|
+
* `--genesis-document` file wins over a `sidecar.genesisDocument` inside the
|
|
32
|
+
* JSON. Returns `undefined` if no flag is set.
|
|
22
33
|
*/
|
|
23
34
|
export async function readResolutionOptions(flags: ResolutionOptionFlags): Promise<ResolutionOptions | undefined> {
|
|
24
35
|
let resolutionOptions: ResolutionOptions | undefined;
|
|
@@ -48,6 +59,14 @@ export async function readResolutionOptions(flags: ResolutionOptionFlags): Promi
|
|
|
48
59
|
if (flags.minConf !== undefined) {
|
|
49
60
|
resolutionOptions = { ...(resolutionOptions ?? {}), minConf: flags.minConf };
|
|
50
61
|
}
|
|
62
|
+
// The file wins over a sidecar.genesisDocument inside the JSON options.
|
|
63
|
+
if (flags.genesisDocument !== undefined) {
|
|
64
|
+
const genesisDocument = await readGenesisDocumentFile(flags.genesisDocument);
|
|
65
|
+
resolutionOptions = {
|
|
66
|
+
...(resolutionOptions ?? {}),
|
|
67
|
+
sidecar : { ...(resolutionOptions?.sidecar ?? {}), genesisDocument },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
51
70
|
return resolutionOptions;
|
|
52
71
|
}
|
|
53
72
|
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BroadcastOptions, DidUpdateResult, PublishToCasMode, Signer } from '@did-btcr2/api';
|
|
1
|
+
import type { BeaconInfo, BroadcastOptions, DidUpdateResult, IdentifierReport, PublishToCasMode, Signer } from '@did-btcr2/api';
|
|
2
2
|
import type { Btcr2DidDocument, ResolutionOptions } from '@did-btcr2/method';
|
|
3
3
|
import type { DidResolutionResult } from '@web5/dids';
|
|
4
4
|
import type { DoctorReport, EffectiveConfig } from './config.js';
|
|
@@ -54,11 +54,43 @@ export interface UpdateCommandOptions {
|
|
|
54
54
|
broadcastOptions? : BroadcastOptions;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The data that `identifier decode` prints: the decoded components of the
|
|
59
|
+
* identifier with the genesis bytes as hex, plus the initial DID document
|
|
60
|
+
* if the caller asked for it.
|
|
61
|
+
*/
|
|
62
|
+
export interface IdentifierDecodeData {
|
|
63
|
+
did : string;
|
|
64
|
+
idType : string;
|
|
65
|
+
hrp : string;
|
|
66
|
+
version : number;
|
|
67
|
+
network : string;
|
|
68
|
+
genesisBytes : string;
|
|
69
|
+
initialDocument? : Btcr2DidDocument;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The data that `genesis build` prints: the external identifier, its
|
|
74
|
+
* network, its genesis bytes as hex, the path of the written genesis
|
|
75
|
+
* document, and the beacons of the initial DID document with their
|
|
76
|
+
* addresses to fund.
|
|
77
|
+
*/
|
|
78
|
+
export interface GenesisBuildData {
|
|
79
|
+
did : string;
|
|
80
|
+
network : NetworkOption;
|
|
81
|
+
genesisBytes : string;
|
|
82
|
+
path : string;
|
|
83
|
+
beacons : BeaconInfo[];
|
|
84
|
+
}
|
|
85
|
+
|
|
57
86
|
export type CommandResult =
|
|
58
|
-
| { action: 'create'; data: string; keyId?: string; publicKey?: string }
|
|
87
|
+
| { action: 'create'; data: string; keyId?: string; publicKey?: string; genesisBytes?: string }
|
|
59
88
|
| { action: 'resolve'; data: DidResolutionResult }
|
|
60
89
|
| { action: 'update'; data: DidUpdateResult }
|
|
61
90
|
| { action: 'deactivate'; data: DidUpdateResult }
|
|
91
|
+
| { action: 'identifier-decode'; data: IdentifierDecodeData }
|
|
92
|
+
| { action: 'identifier-validate'; data: IdentifierReport }
|
|
93
|
+
| { action: 'genesis-build'; data: GenesisBuildData }
|
|
62
94
|
| { action: 'key-generate'; data: { keyId: string; publicKey: string; active: boolean } }
|
|
63
95
|
| { action: 'key-list'; data: Array<{ keyId: string; fingerprint: string; name?: string; active: boolean }> }
|
|
64
96
|
| { action: 'key-show'; data: { keyId: string; publicKey: string; tags?: Record<string, string> } }
|