@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.
- package/README.md +137 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +149 -24
- package/dist/esm/src/cli.js +22 -11
- package/dist/esm/src/cli.js.map +1 -1
- package/dist/esm/src/commands/create.js +2 -1
- package/dist/esm/src/commands/create.js.map +1 -1
- package/dist/esm/src/commands/deactivate.js +8 -1
- package/dist/esm/src/commands/deactivate.js.map +1 -1
- package/dist/esm/src/commands/resolve.js +4 -3
- package/dist/esm/src/commands/resolve.js.map +1 -1
- package/dist/esm/src/commands/update.js +8 -1
- package/dist/esm/src/commands/update.js.map +1 -1
- package/dist/esm/src/config.js +142 -0
- package/dist/esm/src/config.js.map +1 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/types/src/cli.d.ts +10 -5
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/commands/create.d.ts +2 -2
- package/dist/types/src/commands/create.d.ts.map +1 -1
- package/dist/types/src/commands/deactivate.d.ts +2 -2
- package/dist/types/src/commands/deactivate.d.ts.map +1 -1
- package/dist/types/src/commands/resolve.d.ts +2 -2
- package/dist/types/src/commands/resolve.d.ts.map +1 -1
- package/dist/types/src/commands/update.d.ts +2 -2
- package/dist/types/src/commands/update.d.ts.map +1 -1
- package/dist/types/src/config.d.ts +131 -0
- package/dist/types/src/config.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +7 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/cli.ts +22 -12
- package/src/commands/create.ts +3 -2
- package/src/commands/deactivate.ts +12 -2
- package/src/commands/resolve.ts +4 -4
- package/src/commands/update.ts +12 -2
- package/src/config.ts +226 -0
- package/src/index.ts +1 -0
- package/src/types.ts +10 -3
package/dist/cjs/index.js
CHANGED
|
@@ -22,9 +22,16 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CLIError: () => CLIError,
|
|
24
24
|
DidBtcr2Cli: () => DidBtcr2Cli,
|
|
25
|
+
ENV_VARS: () => ENV_VARS,
|
|
25
26
|
SUPPORTED_NETWORKS: () => SUPPORTED_NETWORKS,
|
|
26
27
|
VERSION: () => VERSION,
|
|
28
|
+
defaultApiFactory: () => defaultApiFactory,
|
|
29
|
+
defaultConfigPath: () => defaultConfigPath,
|
|
30
|
+
deriveNetwork: () => deriveNetwork,
|
|
27
31
|
formatResult: () => formatResult,
|
|
32
|
+
profileToOverrides: () => profileToOverrides,
|
|
33
|
+
readConfigFile: () => readConfigFile,
|
|
34
|
+
readEnvOverrides: () => readEnvOverrides,
|
|
28
35
|
registerCreateCommand: () => registerCreateCommand,
|
|
29
36
|
registerDeactivateCommand: () => registerDeactivateCommand,
|
|
30
37
|
registerResolveCommand: () => registerResolveCommand,
|
|
@@ -38,7 +45,6 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
|
38
45
|
|
|
39
46
|
// src/cli.ts
|
|
40
47
|
var import_commander = require("commander");
|
|
41
|
-
var import_api2 = require("@did-btcr2/api");
|
|
42
48
|
|
|
43
49
|
// src/error.ts
|
|
44
50
|
var import_common = require("@did-btcr2/common");
|
|
@@ -72,7 +78,7 @@ var EXPECTED_BYTES = {
|
|
|
72
78
|
k: { length: 33, label: "secp256k1 compressed public key (33 bytes)" },
|
|
73
79
|
x: { length: 32, label: "SHA-256 hash (32 bytes)" }
|
|
74
80
|
};
|
|
75
|
-
function registerCreateCommand(program,
|
|
81
|
+
function registerCreateCommand(program, factory, globals) {
|
|
76
82
|
program.command("create").description("Create an identifier and initial DID document").requiredOption("-t, --type <type>", "Identifier type <k|x>", "k").requiredOption(
|
|
77
83
|
"-n, --network <network>",
|
|
78
84
|
"Identifier bitcoin network <bitcoin|testnet3|testnet4|signet|mutinynet|regtest>"
|
|
@@ -81,6 +87,7 @@ function registerCreateCommand(program, api, globals) {
|
|
|
81
87
|
"Genesis bytes as a hex string. If type=k, MUST be secp256k1 public key. If type=x, MUST be SHA-256 hash of a genesis document"
|
|
82
88
|
).action(async (options) => {
|
|
83
89
|
const parsed = validateCreateOptions(options);
|
|
90
|
+
const api = factory();
|
|
84
91
|
const type = parsed.type === "k" ? "deterministic" : "external";
|
|
85
92
|
const genesisBytes = Buffer.from(parsed.bytes, "hex");
|
|
86
93
|
const data = api.createDid(type, genesisBytes, { network: parsed.network });
|
|
@@ -127,20 +134,107 @@ function validateCreateOptions(options) {
|
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
// src/commands/resolve.ts
|
|
130
|
-
var
|
|
137
|
+
var import_api2 = require("@did-btcr2/api");
|
|
131
138
|
var import_promises = require("fs/promises");
|
|
132
|
-
|
|
139
|
+
|
|
140
|
+
// src/config.ts
|
|
141
|
+
var import_api = require("@did-btcr2/api");
|
|
142
|
+
var import_node_fs = require("fs");
|
|
143
|
+
var import_node_os = require("os");
|
|
144
|
+
var import_node_path = require("path");
|
|
145
|
+
var ENV_VARS = {
|
|
146
|
+
BTC_REST: "BTCR2_BTC_REST",
|
|
147
|
+
BTC_RPC_URL: "BTCR2_BTC_RPC_URL",
|
|
148
|
+
BTC_RPC_USER: "BTCR2_BTC_RPC_USER",
|
|
149
|
+
BTC_RPC_PASS: "BTCR2_BTC_RPC_PASS",
|
|
150
|
+
CAS_GATEWAY: "BTCR2_CAS_GATEWAY"
|
|
151
|
+
};
|
|
152
|
+
function readEnvOverrides() {
|
|
153
|
+
const env = (key) => process.env[key] || void 0;
|
|
154
|
+
return {
|
|
155
|
+
btcRest: env(ENV_VARS.BTC_REST),
|
|
156
|
+
btcRpcUrl: env(ENV_VARS.BTC_RPC_URL),
|
|
157
|
+
btcRpcUser: env(ENV_VARS.BTC_RPC_USER),
|
|
158
|
+
btcRpcPass: env(ENV_VARS.BTC_RPC_PASS),
|
|
159
|
+
casGateway: env(ENV_VARS.CAS_GATEWAY)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function defaultConfigPath() {
|
|
163
|
+
const base = process.env.XDG_CONFIG_HOME ?? process.env.APPDATA ?? (0, import_node_path.join)((0, import_node_os.homedir)(), ".config");
|
|
164
|
+
return (0, import_node_path.join)(base, "btcr2", "config.json");
|
|
165
|
+
}
|
|
166
|
+
function readConfigFile(path) {
|
|
167
|
+
try {
|
|
168
|
+
const content = (0, import_node_fs.readFileSync)(path, "utf-8");
|
|
169
|
+
return JSON.parse(content);
|
|
170
|
+
} catch {
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function profileToOverrides(config, profileName) {
|
|
175
|
+
const profile = config.profiles?.[profileName];
|
|
176
|
+
if (!profile) return {};
|
|
177
|
+
return {
|
|
178
|
+
btcRest: profile.btc?.rest,
|
|
179
|
+
btcRpcUrl: profile.btc?.rpcUrl,
|
|
180
|
+
btcRpcUser: profile.btc?.rpcUser,
|
|
181
|
+
btcRpcPass: profile.btc?.rpcPass,
|
|
182
|
+
casGateway: profile.cas?.gateway
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function defaultApiFactory(network, overrides) {
|
|
186
|
+
if (!network) return (0, import_api.createApi)();
|
|
187
|
+
const configPath = overrides?.config ?? defaultConfigPath();
|
|
188
|
+
const profileName = overrides?.profile ?? network;
|
|
189
|
+
const file = readConfigFile(configPath);
|
|
190
|
+
const fileOverrides = file ? profileToOverrides(file, profileName) : {};
|
|
191
|
+
const env = readEnvOverrides();
|
|
192
|
+
const merged = {
|
|
193
|
+
btcRest: overrides?.btcRest ?? env.btcRest ?? fileOverrides.btcRest,
|
|
194
|
+
btcRpcUrl: overrides?.btcRpcUrl ?? env.btcRpcUrl ?? fileOverrides.btcRpcUrl,
|
|
195
|
+
btcRpcUser: overrides?.btcRpcUser ?? env.btcRpcUser ?? fileOverrides.btcRpcUser,
|
|
196
|
+
btcRpcPass: overrides?.btcRpcPass ?? env.btcRpcPass ?? fileOverrides.btcRpcPass,
|
|
197
|
+
casGateway: overrides?.casGateway ?? env.casGateway ?? fileOverrides.casGateway
|
|
198
|
+
};
|
|
199
|
+
const btc = { network };
|
|
200
|
+
if (merged.btcRest) {
|
|
201
|
+
btc.rest = { host: merged.btcRest };
|
|
202
|
+
}
|
|
203
|
+
if (merged.btcRpcUrl) {
|
|
204
|
+
btc.rpc = {
|
|
205
|
+
host: merged.btcRpcUrl,
|
|
206
|
+
username: merged.btcRpcUser,
|
|
207
|
+
password: merged.btcRpcPass
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const cas = merged.casGateway ? { gateway: merged.casGateway } : void 0;
|
|
211
|
+
return (0, import_api.createApi)({ btc, ...cas && { cas } });
|
|
212
|
+
}
|
|
213
|
+
function deriveNetwork(did) {
|
|
214
|
+
const { network } = import_api.Identifier.decode(did);
|
|
215
|
+
if (!SUPPORTED_NETWORKS.includes(network)) {
|
|
216
|
+
throw new CLIError(
|
|
217
|
+
`Unsupported network "${network}" in DID.`,
|
|
218
|
+
"INVALID_ARGUMENT_ERROR",
|
|
219
|
+
{ did, network }
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return network;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/commands/resolve.ts
|
|
226
|
+
function registerResolveCommand(program, factory, globals) {
|
|
133
227
|
program.command("resolve").alias("read").description("Resolve the DID document of the identifier.").requiredOption("-i, --identifier <identifier>", "did:btcr2 identifier").option("-r, --resolution-options <json>", "JSON string containing resolution options").option("-p, --resolution-options-path <path>", "Path to a JSON file containing resolution options").action(async (options) => {
|
|
134
|
-
console.log("resolve command options prevalidation", options);
|
|
135
228
|
const parsed = await validateResolveOptions(options);
|
|
136
|
-
|
|
229
|
+
const network = deriveNetwork(parsed.identifier);
|
|
230
|
+
const api = factory(network, globals());
|
|
137
231
|
const data = await api.resolveDid(parsed.identifier, parsed.options);
|
|
138
232
|
const result = { action: "resolve", data };
|
|
139
233
|
console.log(formatResult(result, globals()));
|
|
140
234
|
});
|
|
141
235
|
}
|
|
142
236
|
async function validateResolveOptions(options) {
|
|
143
|
-
|
|
237
|
+
import_api2.Identifier.decode(options.identifier);
|
|
144
238
|
let resolutionOptions = void 0;
|
|
145
239
|
if (options.resolutionOptions) {
|
|
146
240
|
try {
|
|
@@ -168,7 +262,7 @@ async function validateResolveOptions(options) {
|
|
|
168
262
|
}
|
|
169
263
|
|
|
170
264
|
// src/commands/update.ts
|
|
171
|
-
function registerUpdateCommand(program,
|
|
265
|
+
function registerUpdateCommand(program, factory, globals) {
|
|
172
266
|
program.command("update").description("Update a did:btcr2 document.").requiredOption(
|
|
173
267
|
"-s, --source-document <json>",
|
|
174
268
|
"Source DID document as JSON string",
|
|
@@ -195,6 +289,16 @@ function registerUpdateCommand(program, api, globals) {
|
|
|
195
289
|
verificationMethodId: options.verificationMethodId,
|
|
196
290
|
beaconId: options.beaconId
|
|
197
291
|
};
|
|
292
|
+
const did = parsed.sourceDocument?.id;
|
|
293
|
+
if (!did) {
|
|
294
|
+
throw new CLIError(
|
|
295
|
+
'Source document must contain an "id" field.',
|
|
296
|
+
"INVALID_ARGUMENT_ERROR",
|
|
297
|
+
options
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
const network = deriveNetwork(did);
|
|
301
|
+
const api = factory(network, globals());
|
|
198
302
|
const data = await api.btcr2.update(parsed);
|
|
199
303
|
const result = { action: "update", data };
|
|
200
304
|
console.log(formatResult(result, globals()));
|
|
@@ -216,7 +320,7 @@ function parseJsonArg(flagName) {
|
|
|
216
320
|
|
|
217
321
|
// src/commands/deactivate.ts
|
|
218
322
|
var DEACTIVATION_PATCH = [{ op: "add", path: "/deactivated", value: true }];
|
|
219
|
-
function registerDeactivateCommand(program,
|
|
323
|
+
function registerDeactivateCommand(program, factory, globals) {
|
|
220
324
|
program.command("deactivate").alias("delete").description("Deactivate the did:btcr2 identifier permanently. This is irreversible.").requiredOption(
|
|
221
325
|
"-s, --source-document <json>",
|
|
222
326
|
"Current DID document as JSON string",
|
|
@@ -239,6 +343,16 @@ function registerDeactivateCommand(program, api, globals) {
|
|
|
239
343
|
verificationMethodId: options.verificationMethodId,
|
|
240
344
|
beaconId: options.beaconId
|
|
241
345
|
};
|
|
346
|
+
const did = parsed.sourceDocument?.id;
|
|
347
|
+
if (!did) {
|
|
348
|
+
throw new CLIError(
|
|
349
|
+
'Source document must contain an "id" field.',
|
|
350
|
+
"INVALID_ARGUMENT_ERROR",
|
|
351
|
+
options
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
const network = deriveNetwork(did);
|
|
355
|
+
const api = factory(network, globals());
|
|
242
356
|
const data = await api.btcr2.update(parsed);
|
|
243
357
|
const result = { action: "deactivate", data };
|
|
244
358
|
console.log(formatResult(result, globals()));
|
|
@@ -259,18 +373,18 @@ function parseJsonArg2(flagName) {
|
|
|
259
373
|
}
|
|
260
374
|
|
|
261
375
|
// src/version.ts
|
|
262
|
-
var
|
|
263
|
-
var
|
|
376
|
+
var import_node_fs2 = require("fs");
|
|
377
|
+
var import_node_path2 = require("path");
|
|
264
378
|
var import_node_url = require("url");
|
|
265
379
|
function readVersion() {
|
|
266
|
-
let dir = (0,
|
|
380
|
+
let dir = (0, import_node_path2.dirname)((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
267
381
|
for (let i = 0; i < 5; i++) {
|
|
268
382
|
try {
|
|
269
|
-
const pkg = JSON.parse((0,
|
|
383
|
+
const pkg = JSON.parse((0, import_node_fs2.readFileSync)((0, import_node_path2.join)(dir, "package.json"), "utf-8"));
|
|
270
384
|
if (pkg.name === "@did-btcr2/cli") return pkg.version;
|
|
271
385
|
} catch {
|
|
272
386
|
}
|
|
273
|
-
dir = (0,
|
|
387
|
+
dir = (0, import_node_path2.dirname)(dir);
|
|
274
388
|
}
|
|
275
389
|
return "0.0.0";
|
|
276
390
|
}
|
|
@@ -279,19 +393,23 @@ var VERSION = readVersion();
|
|
|
279
393
|
// src/cli.ts
|
|
280
394
|
var DidBtcr2Cli = class {
|
|
281
395
|
program;
|
|
282
|
-
api;
|
|
283
396
|
/**
|
|
284
|
-
* Initializes the CLI with an optional
|
|
285
|
-
*
|
|
397
|
+
* Initializes the CLI with an optional API factory.
|
|
398
|
+
*
|
|
399
|
+
* The factory is called lazily by each command with the appropriate
|
|
400
|
+
* network derived from the DID being operated on. Defaults to
|
|
401
|
+
* {@link defaultApiFactory} which uses public endpoints (mempool.space)
|
|
402
|
+
* for known networks and localhost Polar for regtest.
|
|
403
|
+
*
|
|
404
|
+
* @param factory - Optional API factory. Defaults to {@link defaultApiFactory}.
|
|
286
405
|
*/
|
|
287
|
-
constructor(
|
|
288
|
-
this.
|
|
289
|
-
this.program = new import_commander.Command("btcr2").version(`btcr2 ${VERSION}`, "-v, --version", "Output the current version").description("CLI tool for the did:btcr2 method").option("-o, --output <format>", "Output format <json|text>", "text").option("--verbose", "Verbose output", false).option("--quiet", "Suppress non-essential output", false);
|
|
406
|
+
constructor(factory = defaultApiFactory) {
|
|
407
|
+
this.program = new import_commander.Command("btcr2").version(`btcr2 ${VERSION}`, "-v, --version", "Output the current version").description("CLI tool for the did:btcr2 method").option("-o, --output <format>", "Output format <json|text>", "text").option("--verbose", "Verbose output", false).option("--quiet", "Suppress non-essential output", false).option("-c, --config <path>", "Path to config file (default: $XDG_CONFIG_HOME/btcr2/config.json)").option("--profile <name>", "Config profile name (default: auto-detected from network)").option("--btc-rest <url>", "Override Bitcoin REST endpoint (Esplora API)").option("--btc-rpc-url <url>", "Override Bitcoin Core RPC endpoint").option("--btc-rpc-user <user>", "Bitcoin Core RPC username").option("--btc-rpc-pass <pass>", "Bitcoin Core RPC password").option("--cas-gateway <url>", "IPFS HTTP gateway for CAS reads");
|
|
290
408
|
const globals = () => this.program.opts();
|
|
291
|
-
registerCreateCommand(this.program,
|
|
292
|
-
registerResolveCommand(this.program,
|
|
293
|
-
registerUpdateCommand(this.program,
|
|
294
|
-
registerDeactivateCommand(this.program,
|
|
409
|
+
registerCreateCommand(this.program, factory, globals);
|
|
410
|
+
registerResolveCommand(this.program, factory, globals);
|
|
411
|
+
registerUpdateCommand(this.program, factory, globals);
|
|
412
|
+
registerDeactivateCommand(this.program, factory, globals);
|
|
295
413
|
}
|
|
296
414
|
/**
|
|
297
415
|
* Runs the CLI with the provided argv or process.argv.
|
|
@@ -329,9 +447,16 @@ function handleError(error) {
|
|
|
329
447
|
0 && (module.exports = {
|
|
330
448
|
CLIError,
|
|
331
449
|
DidBtcr2Cli,
|
|
450
|
+
ENV_VARS,
|
|
332
451
|
SUPPORTED_NETWORKS,
|
|
333
452
|
VERSION,
|
|
453
|
+
defaultApiFactory,
|
|
454
|
+
defaultConfigPath,
|
|
455
|
+
deriveNetwork,
|
|
334
456
|
formatResult,
|
|
457
|
+
profileToOverrides,
|
|
458
|
+
readConfigFile,
|
|
459
|
+
readEnvOverrides,
|
|
335
460
|
registerCreateCommand,
|
|
336
461
|
registerDeactivateCommand,
|
|
337
462
|
registerResolveCommand,
|
package/dist/esm/src/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command, CommanderError } from 'commander';
|
|
2
|
-
import { createApi } from '@did-btcr2/api';
|
|
3
2
|
import { registerCreateCommand, registerDeactivateCommand, registerResolveCommand, registerUpdateCommand, } from './commands/index.js';
|
|
3
|
+
import { defaultApiFactory } from './config.js';
|
|
4
4
|
import { CLIError } from './error.js';
|
|
5
5
|
import { VERSION } from './version.js';
|
|
6
6
|
/**
|
|
@@ -8,24 +8,35 @@ import { VERSION } from './version.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export class DidBtcr2Cli {
|
|
10
10
|
program;
|
|
11
|
-
api;
|
|
12
11
|
/**
|
|
13
|
-
* Initializes the CLI with an optional
|
|
14
|
-
*
|
|
12
|
+
* Initializes the CLI with an optional API factory.
|
|
13
|
+
*
|
|
14
|
+
* The factory is called lazily by each command with the appropriate
|
|
15
|
+
* network derived from the DID being operated on. Defaults to
|
|
16
|
+
* {@link defaultApiFactory} which uses public endpoints (mempool.space)
|
|
17
|
+
* for known networks and localhost Polar for regtest.
|
|
18
|
+
*
|
|
19
|
+
* @param factory - Optional API factory. Defaults to {@link defaultApiFactory}.
|
|
15
20
|
*/
|
|
16
|
-
constructor(
|
|
17
|
-
this.api = api;
|
|
21
|
+
constructor(factory = defaultApiFactory) {
|
|
18
22
|
this.program = new Command('btcr2')
|
|
19
23
|
.version(`btcr2 ${VERSION}`, '-v, --version', 'Output the current version')
|
|
20
24
|
.description('CLI tool for the did:btcr2 method')
|
|
21
25
|
.option('-o, --output <format>', 'Output format <json|text>', 'text')
|
|
22
26
|
.option('--verbose', 'Verbose output', false)
|
|
23
|
-
.option('--quiet', 'Suppress non-essential output', false)
|
|
27
|
+
.option('--quiet', 'Suppress non-essential output', false)
|
|
28
|
+
.option('-c, --config <path>', 'Path to config file (default: $XDG_CONFIG_HOME/btcr2/config.json)')
|
|
29
|
+
.option('--profile <name>', 'Config profile name (default: auto-detected from network)')
|
|
30
|
+
.option('--btc-rest <url>', 'Override Bitcoin REST endpoint (Esplora API)')
|
|
31
|
+
.option('--btc-rpc-url <url>', 'Override Bitcoin Core RPC endpoint')
|
|
32
|
+
.option('--btc-rpc-user <user>', 'Bitcoin Core RPC username')
|
|
33
|
+
.option('--btc-rpc-pass <pass>', 'Bitcoin Core RPC password')
|
|
34
|
+
.option('--cas-gateway <url>', 'IPFS HTTP gateway for CAS reads');
|
|
24
35
|
const globals = () => this.program.opts();
|
|
25
|
-
registerCreateCommand(this.program,
|
|
26
|
-
registerResolveCommand(this.program,
|
|
27
|
-
registerUpdateCommand(this.program,
|
|
28
|
-
registerDeactivateCommand(this.program,
|
|
36
|
+
registerCreateCommand(this.program, factory, globals);
|
|
37
|
+
registerResolveCommand(this.program, factory, globals);
|
|
38
|
+
registerUpdateCommand(this.program, factory, globals);
|
|
39
|
+
registerDeactivateCommand(this.program, factory, globals);
|
|
29
40
|
}
|
|
30
41
|
/**
|
|
31
42
|
* Runs the CLI with the provided argv or process.argv.
|
package/dist/esm/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAmB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,MAAM,OAAO,WAAW;IACN,OAAO,CAAU;IAEjC;;;;;;;;;OASG;IACH,YAAY,UAAsB,iBAAiB;QACjD,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;aAChC,OAAO,CAAC,SAAS,OAAO,EAAE,EAAE,eAAe,EAAE,4BAA4B,CAAC;aAC1E,WAAW,CAAC,mCAAmC,CAAC;aAChD,MAAM,CAAC,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,CAAC;aACpE,MAAM,CAAC,WAAW,EAAE,gBAAgB,EAAE,KAAK,CAAC;aAC5C,MAAM,CAAC,SAAS,EAAE,+BAA+B,EAAE,KAAK,CAAC;aACzD,MAAM,CAAC,qBAAqB,EAAE,mEAAmE,CAAC;aAClG,MAAM,CAAC,kBAAkB,EAAE,2DAA2D,CAAC;aACvF,MAAM,CAAC,kBAAkB,EAAE,8CAA8C,CAAC;aAC1E,MAAM,CAAC,qBAAqB,EA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,CAAC,CAAC,CAAC;IAChD,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAc;IACjC,IACE,KAAK,YAAY,cAAc;QAC/B,CAAC,KAAK,CAAC,IAAI,KAAK,yBAAyB,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,CAAC,EAC7E,CAAC;QACD,OAAO;IACT,CAAC;IACD,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -6,7 +6,7 @@ const EXPECTED_BYTES = {
|
|
|
6
6
|
k: { length: 33, label: 'secp256k1 compressed public key (33 bytes)' },
|
|
7
7
|
x: { length: 32, label: 'SHA-256 hash (32 bytes)' },
|
|
8
8
|
};
|
|
9
|
-
export function registerCreateCommand(program,
|
|
9
|
+
export function registerCreateCommand(program, factory, globals) {
|
|
10
10
|
program
|
|
11
11
|
.command('create')
|
|
12
12
|
.description('Create an identifier and initial DID document')
|
|
@@ -17,6 +17,7 @@ export function registerCreateCommand(program, api, globals) {
|
|
|
17
17
|
'If type=x, MUST be SHA-256 hash of a genesis document')
|
|
18
18
|
.action(async (options) => {
|
|
19
19
|
const parsed = validateCreateOptions(options);
|
|
20
|
+
const api = factory();
|
|
20
21
|
const type = parsed.type === 'k' ? 'deterministic' : 'external';
|
|
21
22
|
const genesisBytes = Buffer.from(parsed.bytes, 'hex');
|
|
22
23
|
const data = api.createDid(type, genesisBytes, { network: parsed.network });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C,OAAO,EACL,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,8FAA8F;AAC9F,MAAM,cAAc,GAAyD;IAC3E,CAAC,EAAG,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,4CAA4C,EAAE;IACvE,CAAC,EAAG,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE;CACrD,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,OAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C,OAAO,EACL,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,8FAA8F;AAC9F,MAAM,cAAc,GAAyD;IAC3E,CAAC,EAAG,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,4CAA4C,EAAE;IACvE,CAAC,EAAG,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE;CACrD,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,OAAiB,EACjB,OAAoB,EACpB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,+CAA+C,CAAC;SAC5D,cAAc,CAAC,mBAAmB,EAAE,uBAAuB,EAAE,GAAG,CAAC;SACjE,cAAc,CACb,yBAAyB,EACzB,iFAAiF,CAClF;SACA,cAAc,CACb,qBAAqB,EACrB,iCAAiC;QACjC,2CAA2C;QAC3C,uDAAuD,CACxD;SACA,MAAM,CAAC,KAAK,EAAE,OAAyD,EAAE,EAAE;QAC1E,MAAM,MA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AAC;IACD,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,IAAiB,CAAC,CAAC;IAC3D,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QACnC,MAAM,IAAI,QAAQ,CAChB,kCAAkC,OAAO,CAAC,IAAI,eAAe,QAAQ,CAAC,KAAK,SAAS,GAAG,CAAC,MAAM,SAAS,EACvG,wBAAwB,EACxB,OAAO,CACR,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAM,OAAO,CAAC,IAAiB;QACnC,OAAO,EAAG,OAAO,CAAC,OAAwB;QAC1C,KAAK,EAAK,OAAO,CAAC,KAAK;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { deriveNetwork } from '../config.js';
|
|
1
2
|
import { CLIError } from '../error.js';
|
|
2
3
|
import { formatResult } from '../output.js';
|
|
3
4
|
/** The JSON Patch that marks a DID document as permanently deactivated. */
|
|
4
5
|
const DEACTIVATION_PATCH = [{ op: 'add', path: '/deactivated', value: true }];
|
|
5
|
-
export function registerDeactivateCommand(program,
|
|
6
|
+
export function registerDeactivateCommand(program, factory, globals) {
|
|
6
7
|
program
|
|
7
8
|
.command('deactivate')
|
|
8
9
|
.alias('delete')
|
|
@@ -19,6 +20,12 @@ export function registerDeactivateCommand(program, api, globals) {
|
|
|
19
20
|
verificationMethodId: options.verificationMethodId,
|
|
20
21
|
beaconId: options.beaconId,
|
|
21
22
|
};
|
|
23
|
+
const did = parsed.sourceDocument?.id;
|
|
24
|
+
if (!did) {
|
|
25
|
+
throw new CLIError('Source document must contain an "id" field.', 'INVALID_ARGUMENT_ERROR', options);
|
|
26
|
+
}
|
|
27
|
+
const network = deriveNetwork(did);
|
|
28
|
+
const api = factory(network, globals());
|
|
22
29
|
const data = await api.btcr2.update(parsed);
|
|
23
30
|
const result = { action: 'deactivate', data };
|
|
24
31
|
console.log(formatResult(result, globals()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deactivate.js","sourceRoot":"","sources":["../../../../src/commands/deactivate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deactivate.js","sourceRoot":"","sources":["../../../../src/commands/deactivate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,2EAA2E;AAC3E,MAAM,kBAAkB,GAAG,CAAC,EAAE,EAAE,EAAE,KAAc,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAEvF,MAAM,UAAU,yBAAyB,CACvC,OAAiB,EACjB,OAAoB,EACpB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,YAAY,CAAC;SACrB,KAAK,CAAC,QAAQ,CAAC;SACf,WAAW,CAAC,wEAAwE,CAAC;SACrF,cAAc,CACb,8BAA8B,EAC9B,qCAAqC,EACrC,YAAY,CAAC,mBAAmB,CAAC,CAClC;SACA,cAAc,CACb,8BAA8B,EAC9B,wCAAwC,CACzC;SACA,cAAc,CACb,mCAAmC,EACnC,mEAAmE,CACpE;SACA,cAAc,CACb,wBAAwB,EACxB,4BAA4B,EAC5B,YAAY,CAAC,aAAa,CAAC,CAC5B;SACA,MAAM,CAAC,KAAK,EAAE,OAKd,EAAE,EAAE;QACH,MAAM,MAAM,GAAyB;YACnC,cAAc,EAAS,OAAO,CAAC,cAAwD;YACvF,OAAO,EAAgB,kBAAkB;YACzC,eAAe,EAAQ,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC;YACtD,oBAAoB,EAAG,OAAO,CAAC,oBAAoB;YACnD,QAAQ,EAAe,OAAO,CAAC,QAA4C;SAC5E,CAAC;QACF,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,QAAQ,CAChB,6CAA6C,EAC7C,wBAAwB,EACxB,OAAO,CACR,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,YAAqB,EAAE,IAAI,EAAE,CAAC;QACvD,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"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Identifier } from '@did-btcr2/api';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { deriveNetwork } from '../config.js';
|
|
3
4
|
import { CLIError } from '../error.js';
|
|
4
5
|
import { formatResult } from '../output.js';
|
|
5
|
-
export function registerResolveCommand(program,
|
|
6
|
+
export function registerResolveCommand(program, factory, globals) {
|
|
6
7
|
program
|
|
7
8
|
.command('resolve')
|
|
8
9
|
.alias('read')
|
|
@@ -11,9 +12,9 @@ export function registerResolveCommand(program, api, globals) {
|
|
|
11
12
|
.option('-r, --resolution-options <json>', 'JSON string containing resolution options')
|
|
12
13
|
.option('-p, --resolution-options-path <path>', 'Path to a JSON file containing resolution options')
|
|
13
14
|
.action(async (options) => {
|
|
14
|
-
console.log('resolve command options prevalidation', options);
|
|
15
15
|
const parsed = await validateResolveOptions(options);
|
|
16
|
-
|
|
16
|
+
const network = deriveNetwork(parsed.identifier);
|
|
17
|
+
const api = factory(network, globals());
|
|
17
18
|
const data = await api.resolveDid(parsed.identifier, parsed.options);
|
|
18
19
|
const result = { action: 'resolve', data };
|
|
19
20
|
console.log(formatResult(result, globals()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,UAAU,sBAAsB,CACpC,OAAiB,EACjB,OAAoB,EACpB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,SAAS,CAAC;SAClB,KAAK,CAAC,MAAM,CAAC;SACb,WAAW,CAAC,6CAA6C,CAAC;SAC1D,cAAc,CAAC,+BAA+B,EAAE,sBAAsB,CAAC;SACvE,MAAM,CAAC,iCAAiC,EAAE,2CAA2C,CAAC;SACtF,MAAM,CAAC,sCAAsC,EAAE,mDAAmD,CAAC;SACnG,MAAM,CAAC,KAAK,EAAE,OAId,EAAE,EAAE;QACH,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAC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E,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { deriveNetwork } from '../config.js';
|
|
1
2
|
import { CLIError } from '../error.js';
|
|
2
3
|
import { formatResult } from '../output.js';
|
|
3
|
-
export function registerUpdateCommand(program,
|
|
4
|
+
export function registerUpdateCommand(program, factory, globals) {
|
|
4
5
|
program
|
|
5
6
|
.command('update')
|
|
6
7
|
.description('Update a did:btcr2 document.')
|
|
@@ -17,6 +18,12 @@ export function registerUpdateCommand(program, api, globals) {
|
|
|
17
18
|
verificationMethodId: options.verificationMethodId,
|
|
18
19
|
beaconId: options.beaconId,
|
|
19
20
|
};
|
|
21
|
+
const did = parsed.sourceDocument?.id;
|
|
22
|
+
if (!did) {
|
|
23
|
+
throw new CLIError('Source document must contain an "id" field.', 'INVALID_ARGUMENT_ERROR', options);
|
|
24
|
+
}
|
|
25
|
+
const network = deriveNetwork(did);
|
|
26
|
+
const api = factory(network, globals());
|
|
20
27
|
const data = await api.btcr2.update(parsed);
|
|
21
28
|
const result = { action: 'update', data };
|
|
22
29
|
console.log(formatResult(result, globals()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/commands/update.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/commands/update.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,UAAU,qBAAqB,CACnC,OAAiB,EACjB,OAAoB,EACpB,OAA6B;IAE7B,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,8BAA8B,CAAC;SAC3C,cAAc,CACb,8BAA8B,E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AO,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,CA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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"}
|
package/dist/esm/src/index.js
CHANGED
|
@@ -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"}
|