@did-btcr2/cli 0.5.3 → 0.6.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 (42) hide show
  1. package/README.md +137 -2
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/cjs/index.js +149 -24
  4. package/dist/esm/src/cli.js +22 -11
  5. package/dist/esm/src/cli.js.map +1 -1
  6. package/dist/esm/src/commands/create.js +2 -1
  7. package/dist/esm/src/commands/create.js.map +1 -1
  8. package/dist/esm/src/commands/deactivate.js +8 -1
  9. package/dist/esm/src/commands/deactivate.js.map +1 -1
  10. package/dist/esm/src/commands/resolve.js +4 -3
  11. package/dist/esm/src/commands/resolve.js.map +1 -1
  12. package/dist/esm/src/commands/update.js +8 -1
  13. package/dist/esm/src/commands/update.js.map +1 -1
  14. package/dist/esm/src/config.js +142 -0
  15. package/dist/esm/src/config.js.map +1 -0
  16. package/dist/esm/src/index.js +1 -0
  17. package/dist/esm/src/index.js.map +1 -1
  18. package/dist/types/src/cli.d.ts +10 -5
  19. package/dist/types/src/cli.d.ts.map +1 -1
  20. package/dist/types/src/commands/create.d.ts +2 -2
  21. package/dist/types/src/commands/create.d.ts.map +1 -1
  22. package/dist/types/src/commands/deactivate.d.ts +2 -2
  23. package/dist/types/src/commands/deactivate.d.ts.map +1 -1
  24. package/dist/types/src/commands/resolve.d.ts +2 -2
  25. package/dist/types/src/commands/resolve.d.ts.map +1 -1
  26. package/dist/types/src/commands/update.d.ts +2 -2
  27. package/dist/types/src/commands/update.d.ts.map +1 -1
  28. package/dist/types/src/config.d.ts +131 -0
  29. package/dist/types/src/config.d.ts.map +1 -0
  30. package/dist/types/src/index.d.ts +1 -0
  31. package/dist/types/src/index.d.ts.map +1 -1
  32. package/dist/types/src/types.d.ts +7 -0
  33. package/dist/types/src/types.d.ts.map +1 -1
  34. package/package.json +4 -4
  35. package/src/cli.ts +22 -12
  36. package/src/commands/create.ts +3 -2
  37. package/src/commands/deactivate.ts +12 -2
  38. package/src/commands/resolve.ts +4 -4
  39. package/src/commands/update.ts +12 -2
  40. package/src/config.ts +226 -0
  41. package/src/index.ts +1 -0
  42. package/src/types.ts +10 -3
@@ -1,16 +1,21 @@
1
1
  import { Command } from 'commander';
2
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
+ import { type ApiFactory } from './config.js';
3
3
  /**
4
4
  * CLI tool for the did:btcr2 method.
5
5
  */
6
6
  export declare class DidBtcr2Cli {
7
7
  readonly program: Command;
8
- private readonly api;
9
8
  /**
10
- * Initializes the CLI with an optional pre-configured API instance.
11
- * @param {DidBtcr2Api} api - Optional API instance. Defaults to an unconfigured instance.
9
+ * Initializes the CLI with an optional API factory.
10
+ *
11
+ * The factory is called lazily by each command with the appropriate
12
+ * network derived from the DID being operated on. Defaults to
13
+ * {@link defaultApiFactory} which uses public endpoints (mempool.space)
14
+ * for known networks and localhost Polar for regtest.
15
+ *
16
+ * @param factory - Optional API factory. Defaults to {@link defaultApiFactory}.
12
17
  */
13
- constructor(api?: DidBtcr2Api);
18
+ constructor(factory?: ApiFactory);
14
19
  /**
15
20
  * Runs the CLI with the provided argv or process.argv.
16
21
  * @param {string[]} [argv] - Optional array of command-line arguments.
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAYjD;;GAEG;AACH,qBAAa,WAAW;IACtB,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAElC;;;OAGG;gBACS,GAAG,GAAE,WAA0D;IAiB3E;;;;OAIG;IACU,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CASjD"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAOpD,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAKjE;;GAEG;AACH,qBAAa,WAAW;IACtB,SAAgB,OAAO,EAAE,OAAO,CAAC;IAEjC;;;;;;;;;OASG;gBACS,OAAO,GAAE,UAA8B;IAuBnD;;;;OAIG;IACU,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CASjD"}
@@ -1,5 +1,5 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import type { Command } from 'commander';
2
+ import type { ApiFactory } from '../config.js';
3
3
  import type { GlobalOptions } from '../types.js';
4
- export declare function registerCreateCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
4
+ export declare function registerCreateCommand(program: Command, factory: ApiFactory, globals: () => GlobalOptions): void;
5
5
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,KAAK,EAEV,aAAa,EACC,MAAM,aAAa,CAAC;AAWpC,wBAAgB,qBAAqB,CACnC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,WAAW,EACrB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAuBN"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,KAAK,EAEV,aAAa,EACC,MAAM,aAAa,CAAC;AAWpC,wBAAgB,qBAAqB,CACnC,OAAO,EAAG,OAAO,EACjB,OAAO,EAAG,UAAU,EACpB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAwBN"}
@@ -1,5 +1,5 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import type { Command } from 'commander';
2
+ import { type ApiFactory } from '../config.js';
3
3
  import type { GlobalOptions } from '../types.js';
4
- export declare function registerDeactivateCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
4
+ export declare function registerDeactivateCommand(program: Command, factory: ApiFactory, globals: () => GlobalOptions): void;
5
5
  //# sourceMappingURL=deactivate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deactivate.d.ts","sourceRoot":"","sources":["../../../../src/commands/deactivate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,KAAK,EAAE,aAAa,EAAwB,MAAM,aAAa,CAAC;AAKvE,wBAAgB,yBAAyB,CACvC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,WAAW,EACrB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAwCN"}
1
+ {"version":3,"file":"deactivate.d.ts","sourceRoot":"","sources":["../../../../src/commands/deactivate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAG9D,OAAO,KAAK,EAAE,aAAa,EAAwB,MAAM,aAAa,CAAC;AAKvE,wBAAgB,yBAAyB,CACvC,OAAO,EAAG,OAAO,EACjB,OAAO,EAAG,UAAU,EACpB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAkDN"}
@@ -1,5 +1,5 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import type { Command } from 'commander';
2
+ import { type ApiFactory } from '../config.js';
3
3
  import type { GlobalOptions } from '../types.js';
4
- export declare function registerResolveCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
4
+ export declare function registerResolveCommand(program: Command, factory: ApiFactory, globals: () => GlobalOptions): void;
5
5
  //# sourceMappingURL=resolve.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAC;AAExE,wBAAgB,sBAAsB,CACpC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,WAAW,EACrB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAoBN"}
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAG9D,OAAO,KAAK,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAC;AAExE,wBAAgB,sBAAsB,CACpC,OAAO,EAAG,OAAO,EACjB,OAAO,EAAG,UAAU,EACpB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAoBN"}
@@ -1,5 +1,5 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import type { Command } from 'commander';
2
+ import { type ApiFactory } from '../config.js';
3
3
  import type { GlobalOptions } from '../types.js';
4
- export declare function registerUpdateCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
4
+ export declare function registerUpdateCommand(program: Command, factory: ApiFactory, globals: () => GlobalOptions): void;
5
5
  //# sourceMappingURL=update.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,KAAK,EAAE,aAAa,EAAwB,MAAM,aAAa,CAAC;AAEvE,wBAAgB,qBAAqB,CACnC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,WAAW,EACrB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CA6CN"}
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAG9D,OAAO,KAAK,EAAE,aAAa,EAAwB,MAAM,aAAa,CAAC;AAEvE,wBAAgB,qBAAqB,CACnC,OAAO,EAAG,OAAO,EACjB,OAAO,EAAG,UAAU,EACpB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAuDN"}
@@ -0,0 +1,131 @@
1
+ import { type DidBtcr2Api } from '@did-btcr2/api';
2
+ import { type NetworkOption } from './types.js';
3
+ /**
4
+ * Endpoint overrides provided via CLI flags, env vars, or config file.
5
+ * These override the per-network defaults from
6
+ * `DEFAULT_BITCOIN_NETWORK_CONFIG`.
7
+ *
8
+ * `config` and `profile` control config-file resolution and are only
9
+ * meaningful when passed through the full merge chain.
10
+ */
11
+ export type ConnectionOverrides = {
12
+ btcRest?: string;
13
+ btcRpcUrl?: string;
14
+ btcRpcUser?: string;
15
+ btcRpcPass?: string;
16
+ casGateway?: string;
17
+ config?: string;
18
+ profile?: string;
19
+ };
20
+ /**
21
+ * On-disk config file schema.
22
+ *
23
+ * @example
24
+ * ```json
25
+ * {
26
+ * "profiles": {
27
+ * "regtest": {
28
+ * "btc": {
29
+ * "rest": "http://localhost:3000",
30
+ * "rpcUrl": "http://localhost:18443",
31
+ * "rpcUser": "polaruser",
32
+ * "rpcPass": "polarpass"
33
+ * }
34
+ * },
35
+ * "bitcoin": {
36
+ * "btc": { "rest": "https://my-mempool/api" },
37
+ * "cas": { "gateway": "https://ipfs.io" }
38
+ * }
39
+ * }
40
+ * }
41
+ * ```
42
+ */
43
+ export type ConfigFile = {
44
+ profiles?: Record<string, {
45
+ btc?: {
46
+ rest?: string;
47
+ rpcUrl?: string;
48
+ rpcUser?: string;
49
+ rpcPass?: string;
50
+ };
51
+ cas?: {
52
+ gateway?: string;
53
+ };
54
+ }>;
55
+ };
56
+ /**
57
+ * Factory function that creates a configured {@link DidBtcr2Api} instance.
58
+ *
59
+ * When `network` is provided, the returned API is wired to that network's
60
+ * default Bitcoin endpoints (mempool.space for public networks, localhost
61
+ * Polar for regtest). Optional `overrides` let callers replace individual
62
+ * endpoints on top of the defaults. When `network` is omitted, no Bitcoin
63
+ * or CAS is configured — suitable for offline operations like `create`.
64
+ */
65
+ export type ApiFactory = (network?: NetworkOption, overrides?: ConnectionOverrides) => DidBtcr2Api;
66
+ /**
67
+ * Environment variable names consulted by {@link defaultApiFactory}.
68
+ *
69
+ * | Variable | Equivalent flag |
70
+ * |-----------------------|--------------------|
71
+ * | `BTCR2_BTC_REST` | `--btc-rest` |
72
+ * | `BTCR2_BTC_RPC_URL` | `--btc-rpc-url` |
73
+ * | `BTCR2_BTC_RPC_USER` | `--btc-rpc-user` |
74
+ * | `BTCR2_BTC_RPC_PASS` | `--btc-rpc-pass` |
75
+ * | `BTCR2_CAS_GATEWAY` | `--cas-gateway` |
76
+ */
77
+ export declare const ENV_VARS: {
78
+ readonly BTC_REST: "BTCR2_BTC_REST";
79
+ readonly BTC_RPC_URL: "BTCR2_BTC_RPC_URL";
80
+ readonly BTC_RPC_USER: "BTCR2_BTC_RPC_USER";
81
+ readonly BTC_RPC_PASS: "BTCR2_BTC_RPC_PASS";
82
+ readonly CAS_GATEWAY: "BTCR2_CAS_GATEWAY";
83
+ };
84
+ /**
85
+ * Reads {@link ConnectionOverrides} from environment variables.
86
+ * Only defined (non-empty) values are included.
87
+ */
88
+ export declare function readEnvOverrides(): ConnectionOverrides;
89
+ /**
90
+ * Default config file path following the XDG Base Directory Specification.
91
+ *
92
+ * Resolution order:
93
+ * 1. `$XDG_CONFIG_HOME/btcr2/config.json`
94
+ * 2. `%APPDATA%/btcr2/config.json` (Windows)
95
+ * 3. `~/.config/btcr2/config.json` (fallback)
96
+ */
97
+ export declare function defaultConfigPath(): string;
98
+ /**
99
+ * Reads and parses a config file. Returns `undefined` if the file does
100
+ * not exist or cannot be parsed.
101
+ */
102
+ export declare function readConfigFile(path: string): ConfigFile | undefined;
103
+ /**
104
+ * Extracts {@link ConnectionOverrides} from a named profile in a
105
+ * {@link ConfigFile}. Returns an empty object if the profile does not exist.
106
+ */
107
+ export declare function profileToOverrides(config: ConfigFile, profileName: string): ConnectionOverrides;
108
+ /**
109
+ * Default {@link ApiFactory} backed by network defaults from
110
+ * `@did-btcr2/bitcoin` (mempool.space for public networks, localhost for
111
+ * regtest).
112
+ *
113
+ * Override precedence (highest wins):
114
+ * CLI flags → env vars → config file profile → network defaults.
115
+ *
116
+ * When no `--profile` is given, the network name is used as the profile
117
+ * key (e.g. a regtest DID auto-selects the `"regtest"` profile).
118
+ */
119
+ export declare function defaultApiFactory(network?: NetworkOption, overrides?: ConnectionOverrides): DidBtcr2Api;
120
+ /**
121
+ * Extracts and validates the Bitcoin network from a DID string.
122
+ *
123
+ * Decodes the DID via {@link Identifier.decode}, then checks that the
124
+ * embedded network is one of the supported values.
125
+ *
126
+ * @param did A `did:btcr2:...` identifier string.
127
+ * @returns The validated {@link NetworkOption}.
128
+ * @throws {CLIError} If the network is unsupported.
129
+ */
130
+ export declare function deriveNetwork(did: string): NetworkOption;
131
+ //# sourceMappingURL=config.d.ts.map
@@ -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AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAOnE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAQ,UAAU,EACxB,WAAW,EAAG,MAAM,GACnB,mBAAmB,CAUrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,mBAAmB,GAAG,WAAW,CAsCvG;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAUxD"}
@@ -1,5 +1,6 @@
1
1
  export * from './cli.js';
2
2
  export * from './commands/index.js';
3
+ export * from './config.js';
3
4
  export * from './error.js';
4
5
  export * from './output.js';
5
6
  export * from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -38,5 +38,12 @@ export interface GlobalOptions {
38
38
  output: OutputFormat;
39
39
  verbose: boolean;
40
40
  quiet: boolean;
41
+ config?: string;
42
+ profile?: string;
43
+ btcRest?: string;
44
+ btcRpcUrl?: string;
45
+ btcRpcUser?: string;
46
+ btcRpcPass?: string;
47
+ casGateway?: string;
41
48
  }
42
49
  //# sourceMappingURL=types.d.ts.map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E,MAAM,CAAA;CAAE,GAClC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,mBAAmB,CAAA;CAAE,GAChD;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAO,YAAY,CAAC;IAC1B,OAAO,EAAM,OAAO,CAAC;IACrB,KAAK,EAAQ,OAAO,CAAC;IACrB,MAAM,CAAC,EAAM,MAAM,CAAC;IACpB,OAAO,CAAC,EAAK,MAAM,CAAC;IACpB,OAAO,CAAC,EAAK,MAAM,CAAC;IACpB,SAAS,CAAC,EAAG,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-btcr2/cli",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
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",
@@ -58,10 +58,10 @@
58
58
  "dependencies": {
59
59
  "@web5/dids": "^1.2.0",
60
60
  "commander": "^13.1.0",
61
- "@did-btcr2/api": "^0.4.0",
61
+ "@did-btcr2/api": "^0.5.0",
62
+ "@did-btcr2/method": "^0.26.0",
62
63
  "@did-btcr2/common": "^9.0.0",
63
- "@did-btcr2/cryptosuite": "^6.0.6",
64
- "@did-btcr2/method": "^0.26.0"
64
+ "@did-btcr2/cryptosuite": "^6.0.6"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@eslint/js": "^9.21.0",
package/src/cli.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { Command, CommanderError } from 'commander';
2
- import type { DidBtcr2Api} from '@did-btcr2/api';
3
- import { createApi } from '@did-btcr2/api';
4
2
  import {
5
3
  registerCreateCommand,
6
4
  registerDeactivateCommand,
7
5
  registerResolveCommand,
8
6
  registerUpdateCommand,
9
7
  } from './commands/index.js';
8
+ import { defaultApiFactory, type ApiFactory } from './config.js';
10
9
  import { CLIError } from './error.js';
11
10
  import type { GlobalOptions } from './types.js';
12
11
  import { VERSION } from './version.js';
@@ -16,27 +15,38 @@ import { VERSION } from './version.js';
16
15
  */
17
16
  export class DidBtcr2Cli {
18
17
  public readonly program: Command;
19
- private readonly api: DidBtcr2Api;
20
18
 
21
19
  /**
22
- * Initializes the CLI with an optional pre-configured API instance.
23
- * @param {DidBtcr2Api} api - Optional API instance. Defaults to an unconfigured instance.
20
+ * Initializes the CLI with an optional API factory.
21
+ *
22
+ * The factory is called lazily by each command with the appropriate
23
+ * network derived from the DID being operated on. Defaults to
24
+ * {@link defaultApiFactory} which uses public endpoints (mempool.space)
25
+ * for known networks and localhost Polar for regtest.
26
+ *
27
+ * @param factory - Optional API factory. Defaults to {@link defaultApiFactory}.
24
28
  */
25
- constructor(api: DidBtcr2Api = createApi({ btc: { network: 'mutinynet' } })) {
26
- this.api = api;
29
+ constructor(factory: ApiFactory = defaultApiFactory) {
27
30
  this.program = new Command('btcr2')
28
31
  .version(`btcr2 ${VERSION}`, '-v, --version', 'Output the current version')
29
32
  .description('CLI tool for the did:btcr2 method')
30
33
  .option('-o, --output <format>', 'Output format <json|text>', 'text')
31
34
  .option('--verbose', 'Verbose output', false)
32
- .option('--quiet', 'Suppress non-essential output', false);
35
+ .option('--quiet', 'Suppress non-essential output', false)
36
+ .option('-c, --config <path>', 'Path to config file (default: $XDG_CONFIG_HOME/btcr2/config.json)')
37
+ .option('--profile <name>', 'Config profile name (default: auto-detected from network)')
38
+ .option('--btc-rest <url>', 'Override Bitcoin REST endpoint (Esplora API)')
39
+ .option('--btc-rpc-url <url>', 'Override Bitcoin Core RPC endpoint')
40
+ .option('--btc-rpc-user <user>', 'Bitcoin Core RPC username')
41
+ .option('--btc-rpc-pass <pass>', 'Bitcoin Core RPC password')
42
+ .option('--cas-gateway <url>', 'IPFS HTTP gateway for CAS reads');
33
43
 
34
44
  const globals = (): GlobalOptions => this.program.opts() as GlobalOptions;
35
45
 
36
- registerCreateCommand(this.program, this.api, globals);
37
- registerResolveCommand(this.program, this.api, globals);
38
- registerUpdateCommand(this.program, this.api, globals);
39
- registerDeactivateCommand(this.program, this.api, globals);
46
+ registerCreateCommand(this.program, factory, globals);
47
+ registerResolveCommand(this.program, factory, globals);
48
+ registerUpdateCommand(this.program, factory, globals);
49
+ registerDeactivateCommand(this.program, factory, globals);
40
50
  }
41
51
 
42
52
  /**
@@ -1,5 +1,5 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import type { Command } from 'commander';
2
+ import type { ApiFactory } from '../config.js';
3
3
  import { CLIError } from '../error.js';
4
4
  import { formatResult } from '../output.js';
5
5
  import type {
@@ -18,7 +18,7 @@ const EXPECTED_BYTES: Record<'k' | 'x', { length: number; label: string }> = {
18
18
 
19
19
  export function registerCreateCommand(
20
20
  program : Command,
21
- api : DidBtcr2Api,
21
+ factory : ApiFactory,
22
22
  globals : () => GlobalOptions,
23
23
  ): void {
24
24
  program
@@ -37,6 +37,7 @@ export function registerCreateCommand(
37
37
  )
38
38
  .action(async (options: { type: string; network: string; bytes: string }) => {
39
39
  const parsed = validateCreateOptions(options);
40
+ const api = factory();
40
41
  const type = parsed.type === 'k' ? 'deterministic' : 'external';
41
42
  const genesisBytes = Buffer.from(parsed.bytes, 'hex');
42
43
  const data = api.createDid(type, genesisBytes, { network: parsed.network });
@@ -1,5 +1,5 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import type { Command } from 'commander';
2
+ import { deriveNetwork, type ApiFactory } from '../config.js';
3
3
  import { CLIError } from '../error.js';
4
4
  import { formatResult } from '../output.js';
5
5
  import type { GlobalOptions, UpdateCommandOptions } from '../types.js';
@@ -9,7 +9,7 @@ const DEACTIVATION_PATCH = [{ op: 'add' as const, path: '/deactivated', value: t
9
9
 
10
10
  export function registerDeactivateCommand(
11
11
  program : Command,
12
- api : DidBtcr2Api,
12
+ factory : ApiFactory,
13
13
  globals : () => GlobalOptions,
14
14
  ): void {
15
15
  program
@@ -47,6 +47,16 @@ export function registerDeactivateCommand(
47
47
  verificationMethodId : options.verificationMethodId,
48
48
  beaconId : options.beaconId as UpdateCommandOptions['beaconId'],
49
49
  };
50
+ const did = parsed.sourceDocument?.id;
51
+ if (!did) {
52
+ throw new CLIError(
53
+ 'Source document must contain an "id" field.',
54
+ 'INVALID_ARGUMENT_ERROR',
55
+ options
56
+ );
57
+ }
58
+ const network = deriveNetwork(did);
59
+ const api = factory(network, globals());
50
60
  const data = await api.btcr2.update(parsed);
51
61
  const result = { action: 'deactivate' as const, data };
52
62
  console.log(formatResult(result, globals()));
@@ -1,14 +1,14 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import { Identifier } from '@did-btcr2/api';
3
2
  import type { Command } from 'commander';
4
3
  import { readFile } from 'node:fs/promises';
4
+ import { deriveNetwork, type ApiFactory } from '../config.js';
5
5
  import { CLIError } from '../error.js';
6
6
  import { formatResult } from '../output.js';
7
7
  import type { GlobalOptions, ResolveCommandOptions } from '../types.js';
8
8
 
9
9
  export function registerResolveCommand(
10
10
  program : Command,
11
- api : DidBtcr2Api,
11
+ factory : ApiFactory,
12
12
  globals : () => GlobalOptions,
13
13
  ): void {
14
14
  program
@@ -23,9 +23,9 @@ export function registerResolveCommand(
23
23
  resolutionOptions?: string;
24
24
  resolutionOptionsPath?: string;
25
25
  }) => {
26
- console.log('resolve command options prevalidation', options);
27
26
  const parsed = await validateResolveOptions(options);
28
- console.log('resolve command options postvalidation', options);
27
+ const network = deriveNetwork(parsed.identifier);
28
+ const api = factory(network, globals());
29
29
  const data = await api.resolveDid(parsed.identifier, parsed.options);
30
30
  const result = { action: 'resolve' as const, data };
31
31
  console.log(formatResult(result, globals()));
@@ -1,12 +1,12 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
1
  import type { Command } from 'commander';
2
+ import { deriveNetwork, type ApiFactory } from '../config.js';
3
3
  import { CLIError } from '../error.js';
4
4
  import { formatResult } from '../output.js';
5
5
  import type { GlobalOptions, UpdateCommandOptions } from '../types.js';
6
6
 
7
7
  export function registerUpdateCommand(
8
8
  program : Command,
9
- api : DidBtcr2Api,
9
+ factory : ApiFactory,
10
10
  globals : () => GlobalOptions,
11
11
  ): void {
12
12
  program
@@ -49,6 +49,16 @@ export function registerUpdateCommand(
49
49
  verificationMethodId : options.verificationMethodId,
50
50
  beaconId : options.beaconId as UpdateCommandOptions['beaconId'],
51
51
  };
52
+ const did = parsed.sourceDocument?.id;
53
+ if (!did) {
54
+ throw new CLIError(
55
+ 'Source document must contain an "id" field.',
56
+ 'INVALID_ARGUMENT_ERROR',
57
+ options
58
+ );
59
+ }
60
+ const network = deriveNetwork(did);
61
+ const api = factory(network, globals());
52
62
  const data = await api.btcr2.update(parsed);
53
63
  const result = { action: 'update' as const, data };
54
64
  console.log(formatResult(result, globals()));