@did-btcr2/cli 0.5.1 → 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 (66) hide show
  1. package/README.md +137 -2
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/cjs/index.js +464 -7
  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 -1
  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 +4 -4
  21. package/dist/types/src/commands/create.d.ts.map +1 -1
  22. package/dist/types/src/commands/deactivate.d.ts +4 -4
  23. package/dist/types/src/commands/deactivate.d.ts.map +1 -1
  24. package/dist/types/src/commands/resolve.d.ts +4 -4
  25. package/dist/types/src/commands/resolve.d.ts.map +1 -1
  26. package/dist/types/src/commands/update.d.ts +4 -4
  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/output.d.ts +1 -1
  33. package/dist/types/src/output.d.ts.map +1 -1
  34. package/dist/types/src/types.d.ts +7 -0
  35. package/dist/types/src/types.d.ts.map +1 -1
  36. package/package.json +8 -8
  37. package/src/cli.ts +23 -12
  38. package/src/commands/create.ts +7 -5
  39. package/src/commands/deactivate.ts +14 -4
  40. package/src/commands/resolve.ts +6 -4
  41. package/src/commands/update.ts +14 -4
  42. package/src/config.ts +226 -0
  43. package/src/index.ts +1 -0
  44. package/src/output.ts +1 -1
  45. package/src/types.ts +10 -3
  46. package/dist/cjs/cli.js +0 -77
  47. package/dist/cjs/cli.js.map +0 -1
  48. package/dist/cjs/commands/create.js +0 -48
  49. package/dist/cjs/commands/create.js.map +0 -1
  50. package/dist/cjs/commands/deactivate.js +0 -41
  51. package/dist/cjs/commands/deactivate.js.map +0 -1
  52. package/dist/cjs/commands/index.js +0 -5
  53. package/dist/cjs/commands/index.js.map +0 -1
  54. package/dist/cjs/commands/resolve.js +0 -43
  55. package/dist/cjs/commands/resolve.js.map +0 -1
  56. package/dist/cjs/commands/update.js +0 -39
  57. package/dist/cjs/commands/update.js.map +0 -1
  58. package/dist/cjs/error.js +0 -10
  59. package/dist/cjs/error.js.map +0 -1
  60. package/dist/cjs/index.js.map +0 -1
  61. package/dist/cjs/output.js +0 -16
  62. package/dist/cjs/output.js.map +0 -1
  63. package/dist/cjs/types.js +0 -4
  64. package/dist/cjs/types.js.map +0 -1
  65. package/dist/cjs/version.js +0 -22
  66. package/dist/cjs/version.js.map +0 -1
@@ -1 +1 @@
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,CAAC;SACjB,WAAW,CAAC,8BAA8B,CAAC;SAC3C,cAAc,CACb,8BAA8B,EAC9B,oCAAoC,EACpC,YAAY,CAAC,mBAAmB,CAAC,CAClC;SACA,cAAc,CACb,8B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AG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,QAAiB,EAAE,IAAI,EAAE,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CAAC,QAAgB;IACpC,OAAO,CAAC,KAAa,EAAW,EAAE;QAChC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,QAAQ,CAChB,oBAAoB,QAAQ,gCAAgC,EAC5D,wBAAwB,EACxB,EAAE,QAAQ,EAAE,KAAK,EAAE,CACpB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,142 @@
1
+ import { createApi, Identifier } from '@did-btcr2/api';
2
+ import { readFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { CLIError } from './error.js';
6
+ import { SUPPORTED_NETWORKS } from './types.js';
7
+ /**
8
+ * Environment variable names consulted by {@link defaultApiFactory}.
9
+ *
10
+ * | Variable | Equivalent flag |
11
+ * |-----------------------|--------------------|
12
+ * | `BTCR2_BTC_REST` | `--btc-rest` |
13
+ * | `BTCR2_BTC_RPC_URL` | `--btc-rpc-url` |
14
+ * | `BTCR2_BTC_RPC_USER` | `--btc-rpc-user` |
15
+ * | `BTCR2_BTC_RPC_PASS` | `--btc-rpc-pass` |
16
+ * | `BTCR2_CAS_GATEWAY` | `--cas-gateway` |
17
+ */
18
+ export const ENV_VARS = {
19
+ BTC_REST: 'BTCR2_BTC_REST',
20
+ BTC_RPC_URL: 'BTCR2_BTC_RPC_URL',
21
+ BTC_RPC_USER: 'BTCR2_BTC_RPC_USER',
22
+ BTC_RPC_PASS: 'BTCR2_BTC_RPC_PASS',
23
+ CAS_GATEWAY: 'BTCR2_CAS_GATEWAY',
24
+ };
25
+ /**
26
+ * Reads {@link ConnectionOverrides} from environment variables.
27
+ * Only defined (non-empty) values are included.
28
+ */
29
+ export function readEnvOverrides() {
30
+ const env = (key) => process.env[key] || undefined;
31
+ return {
32
+ btcRest: env(ENV_VARS.BTC_REST),
33
+ btcRpcUrl: env(ENV_VARS.BTC_RPC_URL),
34
+ btcRpcUser: env(ENV_VARS.BTC_RPC_USER),
35
+ btcRpcPass: env(ENV_VARS.BTC_RPC_PASS),
36
+ casGateway: env(ENV_VARS.CAS_GATEWAY),
37
+ };
38
+ }
39
+ /**
40
+ * Default config file path following the XDG Base Directory Specification.
41
+ *
42
+ * Resolution order:
43
+ * 1. `$XDG_CONFIG_HOME/btcr2/config.json`
44
+ * 2. `%APPDATA%/btcr2/config.json` (Windows)
45
+ * 3. `~/.config/btcr2/config.json` (fallback)
46
+ */
47
+ export function defaultConfigPath() {
48
+ const base = process.env.XDG_CONFIG_HOME
49
+ ?? process.env.APPDATA
50
+ ?? join(homedir(), '.config');
51
+ return join(base, 'btcr2', 'config.json');
52
+ }
53
+ /**
54
+ * Reads and parses a config file. Returns `undefined` if the file does
55
+ * not exist or cannot be parsed.
56
+ */
57
+ export function readConfigFile(path) {
58
+ try {
59
+ const content = readFileSync(path, 'utf-8');
60
+ return JSON.parse(content);
61
+ }
62
+ catch {
63
+ return undefined;
64
+ }
65
+ }
66
+ /**
67
+ * Extracts {@link ConnectionOverrides} from a named profile in a
68
+ * {@link ConfigFile}. Returns an empty object if the profile does not exist.
69
+ */
70
+ export function profileToOverrides(config, profileName) {
71
+ const profile = config.profiles?.[profileName];
72
+ if (!profile)
73
+ return {};
74
+ return {
75
+ btcRest: profile.btc?.rest,
76
+ btcRpcUrl: profile.btc?.rpcUrl,
77
+ btcRpcUser: profile.btc?.rpcUser,
78
+ btcRpcPass: profile.btc?.rpcPass,
79
+ casGateway: profile.cas?.gateway,
80
+ };
81
+ }
82
+ /**
83
+ * Default {@link ApiFactory} backed by network defaults from
84
+ * `@did-btcr2/bitcoin` (mempool.space for public networks, localhost for
85
+ * regtest).
86
+ *
87
+ * Override precedence (highest wins):
88
+ * CLI flags → env vars → config file profile → network defaults.
89
+ *
90
+ * When no `--profile` is given, the network name is used as the profile
91
+ * key (e.g. a regtest DID auto-selects the `"regtest"` profile).
92
+ */
93
+ export function defaultApiFactory(network, overrides) {
94
+ if (!network)
95
+ return createApi();
96
+ // Layer 1: Config file profile (lowest precedence of the three override layers)
97
+ const configPath = overrides?.config ?? defaultConfigPath();
98
+ const profileName = overrides?.profile ?? network;
99
+ const file = readConfigFile(configPath);
100
+ const fileOverrides = file ? profileToOverrides(file, profileName) : {};
101
+ // Layer 2: Environment variables
102
+ const env = readEnvOverrides();
103
+ // Merge: CLI flags → env vars → config file → (network defaults handled by BitcoinConnection)
104
+ const merged = {
105
+ btcRest: overrides?.btcRest ?? env.btcRest ?? fileOverrides.btcRest,
106
+ btcRpcUrl: overrides?.btcRpcUrl ?? env.btcRpcUrl ?? fileOverrides.btcRpcUrl,
107
+ btcRpcUser: overrides?.btcRpcUser ?? env.btcRpcUser ?? fileOverrides.btcRpcUser,
108
+ btcRpcPass: overrides?.btcRpcPass ?? env.btcRpcPass ?? fileOverrides.btcRpcPass,
109
+ casGateway: overrides?.casGateway ?? env.casGateway ?? fileOverrides.casGateway,
110
+ };
111
+ const btc = { network };
112
+ if (merged.btcRest) {
113
+ btc.rest = { host: merged.btcRest };
114
+ }
115
+ if (merged.btcRpcUrl) {
116
+ btc.rpc = {
117
+ host: merged.btcRpcUrl,
118
+ username: merged.btcRpcUser,
119
+ password: merged.btcRpcPass,
120
+ };
121
+ }
122
+ const cas = merged.casGateway ? { gateway: merged.casGateway } : undefined;
123
+ return createApi({ btc, ...(cas && { cas }) });
124
+ }
125
+ /**
126
+ * Extracts and validates the Bitcoin network from a DID string.
127
+ *
128
+ * Decodes the DID via {@link Identifier.decode}, then checks that the
129
+ * embedded network is one of the supported values.
130
+ *
131
+ * @param did A `did:btcr2:...` identifier string.
132
+ * @returns The validated {@link NetworkOption}.
133
+ * @throws {CLIError} If the network is unsupported.
134
+ */
135
+ export function deriveNetwork(did) {
136
+ const { network } = Identifier.decode(did);
137
+ if (!SUPPORTED_NETWORKS.includes(network)) {
138
+ throw new CLIError(`Unsupported network "${network}" in DID.`, 'INVALID_ARGUMENT_ERROR', { did, network });
139
+ }
140
+ return network;
141
+ }
142
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAA2C,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAsB,MAAM,YAAY,CAAC;AAoEpE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAO,gBAAgB;IAC/B,WAAW,EAAI,mBAAmB;IAClC,YAAY,EAAG,oBAAoB;IACnC,YAAY,EAAG,oBAAoB;IACnC,WAAW,EAAI,mBAAmB;CAC1B,CAAC;AAEX;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,CAAC,GAAW,EAAsB,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IAC/E,OAAO;QACL,OAAO,EAAM,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACnC,SAAS,EAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC;QACtC,UAAU,EAAG,GAA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AC,UAAU;YAC5B,QAAQ,EAAG,MAAM,CAAC,UAAU;SAC7B,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3E,OAAO,SAAS,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3C,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAwB,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,QAAQ,CAChB,wBAAwB,OAAO,WAAW,EAC1C,wBAAwB,EACxB,EAAE,GAAG,EAAE,OAAO,EAAE,CACjB,CAAC;IACJ,CAAC;IACD,OAAO,OAAwB,CAAC;AAClC,CAAC"}
@@ -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.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"}
1
+ {"version":3,"file":"index.js","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"}
@@ -1,16 +1,21 @@
1
1
  import { Command } from 'commander';
2
- import { 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,EAAE,WAAW,EAAa,MAAM,gBAAgB,CAAC;AAWxD;;GAEG;AACH,qBAAa,WAAW;IACtB,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAElC;;;OAGG;gBACS,GAAG,GAAE,WAAyB;IAiB1C;;;;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
- import { Command } from 'commander';
3
- import { GlobalOptions } from '../types.js';
4
- export declare function registerCreateCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
1
+ import type { Command } from 'commander';
2
+ import type { ApiFactory } from '../config.js';
3
+ import type { GlobalOptions } from '../types.js';
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,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAEL,aAAa,EAGd,MAAM,aAAa,CAAC;AAQrB,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
- import { Command } from 'commander';
3
- import { GlobalOptions } from '../types.js';
4
- export declare function registerDeactivateCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
1
+ import type { Command } from 'commander';
2
+ import { type ApiFactory } from '../config.js';
3
+ import type { GlobalOptions } from '../types.js';
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,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAwB,MAAM,aAAa,CAAC;AAKlE,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
- import { Command } from 'commander';
3
- import { GlobalOptions } from '../types.js';
4
- export declare function registerResolveCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
1
+ import type { Command } from 'commander';
2
+ import { type ApiFactory } from '../config.js';
3
+ import type { GlobalOptions } from '../types.js';
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,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAC;AAEnE,wBAAgB,sBAAsB,CACpC,OAAO,EAAG,OAAO,EACjB,GAAG,EAAO,WAAW,EACrB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAkBN"}
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
- import { Command } from 'commander';
3
- import { GlobalOptions } from '../types.js';
4
- export declare function registerUpdateCommand(program: Command, api: DidBtcr2Api, globals: () => GlobalOptions): void;
1
+ import type { Command } from 'commander';
2
+ import { type ApiFactory } from '../config.js';
3
+ import type { GlobalOptions } from '../types.js';
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,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,aAAa,EAAwB,MAAM,aAAa,CAAC;AAElE,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKhG,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,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;IACpB,MAAM,CAAC,EAAM,MAAM,CAAC;IACpB,OAAO,CAAC,EAAK,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QACxB,GAAG,CAAC,EAAE;YACJ,IAAI,CAAC,EAAM,MAAM,CAAC;YAClB,MAAM,CAAC,EAAI,MAAM,CAAC;YAClB,OAAO,CAAC,EAAG,MAAM,CAAC;YAClB,OAAO,CAAC,EAAG,MAAM,CAAC;SACnB,CAAC;QACF,GAAG,CAAC,EAAE;YACJ,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,CAAC,CAAC;CACJ,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,mBAAmB,KAAK,WAAW,CAAC;AAEnG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ;;;;;;CAMX,CAAC;AAEX;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,mBAAmB,CAStD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAK1C;AAED;;;GAGG;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"}
@@ -1,4 +1,4 @@
1
- import { CommandResult, GlobalOptions } from './types.js';
1
+ import type { CommandResult, GlobalOptions } from './types.js';
2
2
  /**
3
3
  * Formats a CommandResult for console output.
4
4
  * In 'json' mode, the full result is serialized.
@@ -1 +1 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAMlF"}
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE/D;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAMlF"}
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AACrG,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAE3C,eAAO,MAAM,kBAAkB,EAAE,aAAa,EAE7C,CAAC;AAE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M,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@did-btcr2/cli",
3
- "version": "0.5.1",
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",
7
- "module": "./dist/esm/index.js",
7
+ "module": "./dist/esm/src/index.js",
8
8
  "types": "./dist/types/index.d.ts",
9
9
  "bin": {
10
10
  "btcr2": "./dist/esm/bin/btcr2.js"
@@ -12,7 +12,7 @@
12
12
  "exports": {
13
13
  ".": {
14
14
  "types": "./dist/types/index.d.ts",
15
- "import": "./dist/esm/index.js",
15
+ "import": "./dist/esm/src/index.js",
16
16
  "require": "./dist/cjs/index.js"
17
17
  }
18
18
  },
@@ -58,10 +58,10 @@
58
58
  "dependencies": {
59
59
  "@web5/dids": "^1.2.0",
60
60
  "commander": "^13.1.0",
61
- "@did-btcr2/cryptosuite": "^6.0.5",
62
- "@did-btcr2/common": "^8.0.1",
63
- "@did-btcr2/method": "^0.25.3",
64
- "@did-btcr2/api": "^0.3.1"
61
+ "@did-btcr2/api": "^0.5.0",
62
+ "@did-btcr2/method": "^0.26.0",
63
+ "@did-btcr2/common": "^9.0.0",
64
+ "@did-btcr2/cryptosuite": "^6.0.6"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@eslint/js": "^9.21.0",
@@ -97,7 +97,7 @@
97
97
  "reinstall": "pnpm install --force",
98
98
  "build": "pnpm clean:build && pnpm build:esm && pnpm build:cjs",
99
99
  "build:esm": "rimraf dist/esm dist/types && pnpm tsc -p tsconfig.json && chmod +x dist/esm/bin/btcr2.js",
100
- "build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
100
+ "build:cjs": "tsup && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
101
101
  "build:tests": "pnpm clean:tests && pnpm tsc -p tests/tsconfig.json",
102
102
  "build:all": "pnpm build && pnpm build:tests",
103
103
  "lint": "eslint . --max-warnings 0",
package/src/cli.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Command, CommanderError } from 'commander';
2
- import { DidBtcr2Api, createApi } from '@did-btcr2/api';
3
2
  import {
4
3
  registerCreateCommand,
5
4
  registerDeactivateCommand,
6
5
  registerResolveCommand,
7
6
  registerUpdateCommand,
8
7
  } from './commands/index.js';
8
+ import { defaultApiFactory, type ApiFactory } from './config.js';
9
9
  import { CLIError } from './error.js';
10
- import { GlobalOptions } from './types.js';
10
+ import type { GlobalOptions } from './types.js';
11
11
  import { VERSION } from './version.js';
12
12
 
13
13
  /**
@@ -15,27 +15,38 @@ import { VERSION } from './version.js';
15
15
  */
16
16
  export class DidBtcr2Cli {
17
17
  public readonly program: Command;
18
- private readonly api: DidBtcr2Api;
19
18
 
20
19
  /**
21
- * Initializes the CLI with an optional pre-configured API instance.
22
- * @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}.
23
28
  */
24
- constructor(api: DidBtcr2Api = createApi()) {
25
- this.api = api;
29
+ constructor(factory: ApiFactory = defaultApiFactory) {
26
30
  this.program = new Command('btcr2')
27
31
  .version(`btcr2 ${VERSION}`, '-v, --version', 'Output the current version')
28
32
  .description('CLI tool for the did:btcr2 method')
29
33
  .option('-o, --output <format>', 'Output format <json|text>', 'text')
30
34
  .option('--verbose', 'Verbose output', false)
31
- .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');
32
43
 
33
44
  const globals = (): GlobalOptions => this.program.opts() as GlobalOptions;
34
45
 
35
- registerCreateCommand(this.program, this.api, globals);
36
- registerResolveCommand(this.program, this.api, globals);
37
- registerUpdateCommand(this.program, this.api, globals);
38
- 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);
39
50
  }
40
51
 
41
52
  /**
@@ -1,11 +1,12 @@
1
- import type { DidBtcr2Api } from '@did-btcr2/api';
2
- import { Command } from 'commander';
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
- import {
5
+ import type {
6
6
  CreateCommandOptions,
7
7
  GlobalOptions,
8
- NetworkOption,
8
+ NetworkOption} from '../types.js';
9
+ import {
9
10
  SUPPORTED_NETWORKS,
10
11
  } from '../types.js';
11
12
 
@@ -17,7 +18,7 @@ const EXPECTED_BYTES: Record<'k' | 'x', { length: number; label: string }> = {
17
18
 
18
19
  export function registerCreateCommand(
19
20
  program : Command,
20
- api : DidBtcr2Api,
21
+ factory : ApiFactory,
21
22
  globals : () => GlobalOptions,
22
23
  ): void {
23
24
  program
@@ -36,6 +37,7 @@ export function registerCreateCommand(
36
37
  )
37
38
  .action(async (options: { type: string; network: string; bytes: string }) => {
38
39
  const parsed = validateCreateOptions(options);
40
+ const api = factory();
39
41
  const type = parsed.type === 'k' ? 'deterministic' : 'external';
40
42
  const genesisBytes = Buffer.from(parsed.bytes, 'hex');
41
43
  const data = api.createDid(type, genesisBytes, { network: parsed.network });