@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.
Files changed (75) hide show
  1. package/README.md +29 -2
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/cjs/index.js +494 -64
  4. package/dist/esm/src/cli.js +4 -2
  5. package/dist/esm/src/cli.js.map +1 -1
  6. package/dist/esm/src/commands/completion.js +1 -1
  7. package/dist/esm/src/commands/completion.js.map +1 -1
  8. package/dist/esm/src/commands/create.js +33 -41
  9. package/dist/esm/src/commands/create.js.map +1 -1
  10. package/dist/esm/src/commands/genesis.js +119 -0
  11. package/dist/esm/src/commands/genesis.js.map +1 -0
  12. package/dist/esm/src/commands/identifier.js +96 -0
  13. package/dist/esm/src/commands/identifier.js.map +1 -0
  14. package/dist/esm/src/commands/index.js +2 -0
  15. package/dist/esm/src/commands/index.js.map +1 -1
  16. package/dist/esm/src/commands/resolve.js +15 -1
  17. package/dist/esm/src/commands/resolve.js.map +1 -1
  18. package/dist/esm/src/commands/write.js +10 -7
  19. package/dist/esm/src/commands/write.js.map +1 -1
  20. package/dist/esm/src/genesis-document-file.js +26 -0
  21. package/dist/esm/src/genesis-document-file.js.map +1 -0
  22. package/dist/esm/src/genesis-spec.js +93 -0
  23. package/dist/esm/src/genesis-spec.js.map +1 -0
  24. package/dist/esm/src/genesis-wizard.js +132 -0
  25. package/dist/esm/src/genesis-wizard.js.map +1 -0
  26. package/dist/esm/src/hints.js +14 -3
  27. package/dist/esm/src/hints.js.map +1 -1
  28. package/dist/esm/src/network-option.js +39 -0
  29. package/dist/esm/src/network-option.js.map +1 -0
  30. package/dist/esm/src/resolution-options.js +19 -2
  31. package/dist/esm/src/resolution-options.js.map +1 -1
  32. package/dist/types/src/cli.d.ts +1 -1
  33. package/dist/types/src/cli.d.ts.map +1 -1
  34. package/dist/types/src/commands/create.d.ts +5 -4
  35. package/dist/types/src/commands/create.d.ts.map +1 -1
  36. package/dist/types/src/commands/genesis.d.ts +20 -0
  37. package/dist/types/src/commands/genesis.d.ts.map +1 -0
  38. package/dist/types/src/commands/identifier.d.ts +12 -0
  39. package/dist/types/src/commands/identifier.d.ts.map +1 -0
  40. package/dist/types/src/commands/index.d.ts +2 -0
  41. package/dist/types/src/commands/index.d.ts.map +1 -1
  42. package/dist/types/src/commands/resolve.d.ts +7 -0
  43. package/dist/types/src/commands/resolve.d.ts.map +1 -1
  44. package/dist/types/src/commands/write.d.ts +2 -1
  45. package/dist/types/src/commands/write.d.ts.map +1 -1
  46. package/dist/types/src/genesis-document-file.d.ts +11 -0
  47. package/dist/types/src/genesis-document-file.d.ts.map +1 -0
  48. package/dist/types/src/genesis-spec.d.ts +70 -0
  49. package/dist/types/src/genesis-spec.d.ts.map +1 -0
  50. package/dist/types/src/genesis-wizard.d.ts +30 -0
  51. package/dist/types/src/genesis-wizard.d.ts.map +1 -0
  52. package/dist/types/src/hints.d.ts +7 -0
  53. package/dist/types/src/hints.d.ts.map +1 -1
  54. package/dist/types/src/network-option.d.ts +15 -0
  55. package/dist/types/src/network-option.d.ts.map +1 -0
  56. package/dist/types/src/resolution-options.d.ts +6 -2
  57. package/dist/types/src/resolution-options.d.ts.map +1 -1
  58. package/dist/types/src/types.d.ts +38 -1
  59. package/dist/types/src/types.d.ts.map +1 -1
  60. package/package.json +3 -3
  61. package/src/cli.ts +5 -1
  62. package/src/commands/completion.ts +1 -1
  63. package/src/commands/create.ts +39 -55
  64. package/src/commands/genesis.ts +149 -0
  65. package/src/commands/identifier.ts +134 -0
  66. package/src/commands/index.ts +2 -0
  67. package/src/commands/resolve.ts +20 -1
  68. package/src/commands/write.ts +10 -7
  69. package/src/genesis-document-file.ts +35 -0
  70. package/src/genesis-spec.ts +149 -0
  71. package/src/genesis-wizard.ts +163 -0
  72. package/src/hints.ts +13 -2
  73. package/src/network-option.ts +50 -0
  74. package/src/resolution-options.ts +21 -2
  75. 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
- * Returns `undefined` if no flag is set.
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> } }