@did-btcr2/cli 0.19.3 → 0.21.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 +35 -26
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +136 -171
- package/dist/esm/src/commands/deactivate.js +11 -88
- package/dist/esm/src/commands/deactivate.js.map +1 -1
- package/dist/esm/src/commands/resolve.js +3 -20
- package/dist/esm/src/commands/resolve.js.map +1 -1
- package/dist/esm/src/commands/update.js +15 -85
- package/dist/esm/src/commands/update.js.map +1 -1
- package/dist/esm/src/commands/write.js +119 -0
- package/dist/esm/src/commands/write.js.map +1 -0
- package/dist/esm/src/resolution-options.js +47 -0
- package/dist/esm/src/resolution-options.js.map +1 -0
- package/dist/esm/src/types.js.map +1 -1
- package/dist/types/src/commands/deactivate.d.ts +1 -1
- package/dist/types/src/commands/deactivate.d.ts.map +1 -1
- package/dist/types/src/commands/resolve.d.ts.map +1 -1
- package/dist/types/src/commands/update.d.ts +1 -1
- package/dist/types/src/commands/update.d.ts.map +1 -1
- package/dist/types/src/commands/write.d.ts +47 -0
- package/dist/types/src/commands/write.d.ts.map +1 -0
- package/dist/types/src/resolution-options.d.ts +21 -0
- package/dist/types/src/resolution-options.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +17 -7
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/commands/deactivate.ts +14 -142
- package/src/commands/resolve.ts +7 -36
- package/src/commands/update.ts +19 -139
- package/src/commands/write.ts +198 -0
- package/src/resolution-options.ts +67 -0
- package/src/types.ts +17 -7
package/dist/cjs/index.js
CHANGED
|
@@ -2294,68 +2294,93 @@ function parseGenesisBytes(hex, type) {
|
|
|
2294
2294
|
}
|
|
2295
2295
|
|
|
2296
2296
|
// src/commands/resolve.ts
|
|
2297
|
+
var import_api5 = require("@did-btcr2/api");
|
|
2298
|
+
|
|
2299
|
+
// src/resolution-options.ts
|
|
2297
2300
|
var import_api4 = require("@did-btcr2/api");
|
|
2298
2301
|
var import_promises = require("fs/promises");
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
const api = factory(network, globals());
|
|
2304
|
-
const data = await api.resolveDid(parsed.identifier, parsed.options);
|
|
2305
|
-
const result = { action: "resolve", data };
|
|
2306
|
-
console.log(formatResult(result, globals()));
|
|
2307
|
-
});
|
|
2308
|
-
}
|
|
2309
|
-
async function validateResolveOptions(options) {
|
|
2310
|
-
import_api4.Identifier.decode(options.identifier);
|
|
2311
|
-
let resolutionOptions = void 0;
|
|
2312
|
-
if (options.resolutionOptions) {
|
|
2302
|
+
var MIN_CONF_HELP = `Minimum block confirmations a beacon signal needs before resolution applies it (positive integer, default: ${import_api4.DEFAULT_MIN_CONF}). Overrides a minConf inside the JSON resolution options`;
|
|
2303
|
+
async function readResolutionOptions(flags) {
|
|
2304
|
+
let resolutionOptions;
|
|
2305
|
+
if (flags.resolutionOptions) {
|
|
2313
2306
|
try {
|
|
2314
|
-
resolutionOptions = JSON.parse(
|
|
2307
|
+
resolutionOptions = JSON.parse(flags.resolutionOptions);
|
|
2315
2308
|
} catch {
|
|
2316
2309
|
throw new CLIError(
|
|
2317
2310
|
"Invalid resolution options. Must be a valid JSON string.",
|
|
2318
2311
|
"INVALID_ARGUMENT_ERROR",
|
|
2319
|
-
|
|
2312
|
+
{ resolutionOptions: flags.resolutionOptions }
|
|
2320
2313
|
);
|
|
2321
2314
|
}
|
|
2322
|
-
} else if (
|
|
2315
|
+
} else if (flags.resolutionOptionsPath) {
|
|
2323
2316
|
try {
|
|
2324
|
-
const content = await (0, import_promises.readFile)(
|
|
2317
|
+
const content = await (0, import_promises.readFile)(flags.resolutionOptionsPath, "utf-8");
|
|
2325
2318
|
resolutionOptions = JSON.parse(content);
|
|
2326
2319
|
} catch {
|
|
2327
2320
|
throw new CLIError(
|
|
2328
2321
|
"Invalid resolution options path. Must be a valid path to a JSON file.",
|
|
2329
2322
|
"INVALID_ARGUMENT_ERROR",
|
|
2330
|
-
|
|
2323
|
+
{ resolutionOptionsPath: flags.resolutionOptionsPath }
|
|
2331
2324
|
);
|
|
2332
2325
|
}
|
|
2333
2326
|
}
|
|
2327
|
+
if (flags.minConf !== void 0) {
|
|
2328
|
+
resolutionOptions = { ...resolutionOptions ?? {}, minConf: flags.minConf };
|
|
2329
|
+
}
|
|
2330
|
+
return resolutionOptions;
|
|
2331
|
+
}
|
|
2332
|
+
function parseMinConf(value) {
|
|
2333
|
+
if (!/^[1-9]\d*$/.test(value)) {
|
|
2334
|
+
throw new CLIError(
|
|
2335
|
+
"--min-conf must be a positive integer (minimum 1).",
|
|
2336
|
+
"INVALID_ARGUMENT_ERROR",
|
|
2337
|
+
{ value }
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2340
|
+
return Number(value);
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
// src/commands/resolve.ts
|
|
2344
|
+
function registerResolveCommand(program, factory, globals) {
|
|
2345
|
+
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").option("--min-conf <n>", MIN_CONF_HELP, parseMinConf).action(async (options) => {
|
|
2346
|
+
const parsed = await validateResolveOptions(options);
|
|
2347
|
+
const network = deriveNetwork(parsed.identifier);
|
|
2348
|
+
const api = factory(network, globals());
|
|
2349
|
+
const data = await api.resolveDid(parsed.identifier, parsed.options);
|
|
2350
|
+
const result = { action: "resolve", data };
|
|
2351
|
+
console.log(formatResult(result, globals()));
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
async function validateResolveOptions(options) {
|
|
2355
|
+
import_api5.Identifier.decode(options.identifier);
|
|
2356
|
+
const resolutionOptions = await readResolutionOptions(options);
|
|
2334
2357
|
return { identifier: options.identifier, options: resolutionOptions };
|
|
2335
2358
|
}
|
|
2336
2359
|
|
|
2337
|
-
// src/commands/
|
|
2360
|
+
// src/commands/write.ts
|
|
2338
2361
|
var import_key_manager2 = require("@did-btcr2/key-manager");
|
|
2339
|
-
function
|
|
2340
|
-
|
|
2362
|
+
function registerWriteOptions(command) {
|
|
2363
|
+
return command.option(
|
|
2341
2364
|
"-s, --source-document <json>",
|
|
2342
|
-
"Source DID document as JSON string",
|
|
2365
|
+
"Source DID document as a JSON string. Requires --source-version-id. Omit both to resolve the current document first",
|
|
2343
2366
|
parseJsonArg("--source-document")
|
|
2344
|
-
).
|
|
2367
|
+
).option(
|
|
2345
2368
|
"--source-version-id <number>",
|
|
2346
|
-
"
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
"JSON Patch operations as a JSON string array",
|
|
2350
|
-
parseJsonArg("--patches")
|
|
2351
|
-
).requiredOption(
|
|
2369
|
+
"Version ID of the source document, a non-negative integer. Requires --source-document",
|
|
2370
|
+
parseSourceVersionId
|
|
2371
|
+
).option(
|
|
2352
2372
|
"-m, --verification-method-id <id>",
|
|
2353
|
-
"
|
|
2354
|
-
).
|
|
2355
|
-
"-b, --beacon-id <
|
|
2356
|
-
"Beacon
|
|
2357
|
-
|
|
2373
|
+
"Verification method that signs the update (default: the one method of the document that publishes the signing key)"
|
|
2374
|
+
).option(
|
|
2375
|
+
"-b, --beacon-id <id>",
|
|
2376
|
+
"Beacon service that announces the update, as a DID URL (default: the only beacon of the document, else the one beacon with a spendable UTXO)"
|
|
2377
|
+
).option(
|
|
2378
|
+
"-r, --resolution-options <json>",
|
|
2379
|
+
"Resolution options as a JSON string, for the resolution of the source document"
|
|
2358
2380
|
).option(
|
|
2381
|
+
"--resolution-options-path <path>",
|
|
2382
|
+
"Path to a JSON file with resolution options, for the resolution of the source document"
|
|
2383
|
+
).option("--min-conf <n>", MIN_CONF_HELP, parseMinConf).option(
|
|
2359
2384
|
"--publish-to-cas <mode>",
|
|
2360
2385
|
"Publish update artifacts to a writable CAS before broadcast: auto|always|never. CAS publication is optional; the default distributes the returned artifacts via sidecar.",
|
|
2361
2386
|
parsePublishToCasMode,
|
|
@@ -2366,51 +2391,62 @@ function registerUpdateCommand(program, factory, globals) {
|
|
|
2366
2391
|
).option(
|
|
2367
2392
|
"--change-address <address>",
|
|
2368
2393
|
"Send transaction change to this address instead of the beacon address, so a DID's announcements are not linked on-chain (ADR 044)."
|
|
2369
|
-
)
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2394
|
+
);
|
|
2395
|
+
}
|
|
2396
|
+
async function prepareWrite(options, factory, g) {
|
|
2397
|
+
const did = options.identifier;
|
|
2398
|
+
const network = deriveNetwork(did);
|
|
2399
|
+
const hasDocument = options.sourceDocument !== void 0;
|
|
2400
|
+
const hasVersion = options.sourceVersionId !== void 0;
|
|
2401
|
+
if (hasDocument !== hasVersion) {
|
|
2402
|
+
throw new CLIError(
|
|
2403
|
+
"Provide both --source-document and --source-version-id, or neither. Omit both to resolve the current document first.",
|
|
2404
|
+
"INVALID_ARGUMENT_ERROR",
|
|
2405
|
+
{ did }
|
|
2406
|
+
);
|
|
2407
|
+
}
|
|
2408
|
+
const hasResolutionFlags = options.resolutionOptions !== void 0 || options.resolutionOptionsPath !== void 0 || options.minConf !== void 0;
|
|
2409
|
+
if (hasDocument && hasResolutionFlags) {
|
|
2410
|
+
throw new CLIError(
|
|
2411
|
+
"--resolution-options, --resolution-options-path, and --min-conf apply only when --source-document and --source-version-id are omitted. A supplied source pair skips resolution.",
|
|
2412
|
+
"INVALID_ARGUMENT_ERROR",
|
|
2413
|
+
{ did }
|
|
2414
|
+
);
|
|
2415
|
+
}
|
|
2416
|
+
assertKeystoreAllowedForNetwork(network, g);
|
|
2417
|
+
const resolutionOptions = await readResolutionOptions(options);
|
|
2418
|
+
const api = factory(network, g);
|
|
2419
|
+
const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(g));
|
|
2420
|
+
const signer = new import_key_manager2.KeyManagerSigner(api.kms.kms, keyId);
|
|
2421
|
+
const broadcastOptions = resolveBroadcastOptions(network, g, {
|
|
2422
|
+
feeRate: options.feeRate,
|
|
2423
|
+
changeAddress: options.changeAddress
|
|
2424
|
+
});
|
|
2425
|
+
return {
|
|
2426
|
+
network,
|
|
2427
|
+
api,
|
|
2428
|
+
params: {
|
|
2429
|
+
did,
|
|
2430
|
+
signer,
|
|
2378
2431
|
sourceDocument: options.sourceDocument,
|
|
2379
|
-
|
|
2380
|
-
sourceVersionId: Number(options.sourceVersionId),
|
|
2432
|
+
sourceVersionId: options.sourceVersionId,
|
|
2381
2433
|
verificationMethodId: options.verificationMethodId,
|
|
2382
|
-
beaconId: options.beaconId
|
|
2383
|
-
|
|
2384
|
-
const did = parsed.sourceDocument?.id;
|
|
2385
|
-
if (!did) {
|
|
2386
|
-
throw new CLIError(
|
|
2387
|
-
'Source document must contain an "id" field.',
|
|
2388
|
-
"INVALID_ARGUMENT_ERROR",
|
|
2389
|
-
options
|
|
2390
|
-
);
|
|
2391
|
-
}
|
|
2392
|
-
const network = deriveNetwork(did);
|
|
2393
|
-
assertKeystoreAllowedForNetwork(network, globals());
|
|
2394
|
-
const api = factory(network, globals());
|
|
2395
|
-
const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(globals()));
|
|
2396
|
-
const signer = new import_key_manager2.KeyManagerSigner(api.kms.kms, keyId);
|
|
2397
|
-
const broadcastOptions = resolveBroadcastOptions(network, globals(), {
|
|
2398
|
-
feeRate: options.feeRate,
|
|
2399
|
-
changeAddress: options.changeAddress
|
|
2400
|
-
});
|
|
2401
|
-
const data = await api.btcr2.update({
|
|
2402
|
-
sourceDocument: parsed.sourceDocument,
|
|
2403
|
-
patches: parsed.patches,
|
|
2404
|
-
sourceVersionId: parsed.sourceVersionId,
|
|
2405
|
-
verificationMethodId: parsed.verificationMethodId,
|
|
2406
|
-
beaconId: parsed.beaconId,
|
|
2407
|
-
signer,
|
|
2434
|
+
beaconId: options.beaconId,
|
|
2435
|
+
resolutionOptions,
|
|
2408
2436
|
publishToCas: options.publishToCas,
|
|
2409
|
-
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2437
|
+
broadcastOptions
|
|
2438
|
+
}
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
function parseSourceVersionId(value) {
|
|
2442
|
+
if (!/^\d+$/.test(value)) {
|
|
2443
|
+
throw new CLIError(
|
|
2444
|
+
"--source-version-id must be a non-negative integer.",
|
|
2445
|
+
"INVALID_ARGUMENT_ERROR",
|
|
2446
|
+
{ value }
|
|
2447
|
+
);
|
|
2448
|
+
}
|
|
2449
|
+
return Number(value);
|
|
2414
2450
|
}
|
|
2415
2451
|
function parsePublishToCasMode(value) {
|
|
2416
2452
|
if (value !== "auto" && value !== "always" && value !== "never") {
|
|
@@ -2436,104 +2472,33 @@ function parseJsonArg(flagName) {
|
|
|
2436
2472
|
};
|
|
2437
2473
|
}
|
|
2438
2474
|
|
|
2475
|
+
// src/commands/update.ts
|
|
2476
|
+
function registerUpdateCommand(program, factory, globals) {
|
|
2477
|
+
const command = program.command("update").description("Update a did:btcr2 document.").requiredOption("-i, --identifier <identifier>", "did:btcr2 identifier to update").requiredOption(
|
|
2478
|
+
"-p, --patches <json>",
|
|
2479
|
+
"JSON Patch operations as a JSON string array",
|
|
2480
|
+
parseJsonArg("--patches")
|
|
2481
|
+
);
|
|
2482
|
+
registerWriteOptions(command).action(async (options) => {
|
|
2483
|
+
const g = globals();
|
|
2484
|
+
const { network, api, params } = await prepareWrite(options, factory, g);
|
|
2485
|
+
const data = await api.updateDid({ ...params, patches: options.patches });
|
|
2486
|
+
console.log(formatResult({ action: "update", data }, g));
|
|
2487
|
+
printWatchHint(g, network, data.txid);
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2439
2491
|
// src/commands/deactivate.ts
|
|
2440
|
-
var import_key_manager3 = require("@did-btcr2/key-manager");
|
|
2441
|
-
var DEACTIVATION_PATCH = [{ op: "add", path: "/deactivated", value: true }];
|
|
2442
2492
|
function registerDeactivateCommand(program, factory, globals) {
|
|
2443
|
-
program.command("deactivate").alias("delete").description("Deactivate the did:btcr2 identifier permanently. This is irreversible.").requiredOption(
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
).requiredOption(
|
|
2451
|
-
"-m, --verification-method-id <id>",
|
|
2452
|
-
"DID document verification method ID used to sign the deactivation"
|
|
2453
|
-
).requiredOption(
|
|
2454
|
-
"-b, --beacon-id <json>",
|
|
2455
|
-
"Beacon ID as a JSON string",
|
|
2456
|
-
parseJsonArg2("--beacon-id")
|
|
2457
|
-
).option(
|
|
2458
|
-
"--publish-to-cas <mode>",
|
|
2459
|
-
"Publish update artifacts to a writable CAS before broadcast: auto|always|never. CAS publication is optional; the default distributes the returned artifacts via sidecar.",
|
|
2460
|
-
parsePublishToCasMode2,
|
|
2461
|
-
"never"
|
|
2462
|
-
).option(
|
|
2463
|
-
"--fee-rate <satsPerVByte>",
|
|
2464
|
-
"Fee rate in sats/vByte for the beacon transaction (default: 5). Raise it under congestion so the transaction confirms."
|
|
2465
|
-
).option(
|
|
2466
|
-
"--change-address <address>",
|
|
2467
|
-
"Send transaction change to this address instead of the beacon address, so a DID's announcements are not linked on-chain (ADR 044)."
|
|
2468
|
-
).action(async (options) => {
|
|
2469
|
-
if (!/^\d+$/.test(options.sourceVersionId)) {
|
|
2470
|
-
throw new CLIError(
|
|
2471
|
-
"--source-version-id must be a non-negative integer.",
|
|
2472
|
-
"INVALID_ARGUMENT_ERROR",
|
|
2473
|
-
{ value: options.sourceVersionId }
|
|
2474
|
-
);
|
|
2475
|
-
}
|
|
2476
|
-
const parsed = {
|
|
2477
|
-
sourceDocument: options.sourceDocument,
|
|
2478
|
-
patches: DEACTIVATION_PATCH,
|
|
2479
|
-
sourceVersionId: Number(options.sourceVersionId),
|
|
2480
|
-
verificationMethodId: options.verificationMethodId,
|
|
2481
|
-
beaconId: options.beaconId
|
|
2482
|
-
};
|
|
2483
|
-
const did = parsed.sourceDocument?.id;
|
|
2484
|
-
if (!did) {
|
|
2485
|
-
throw new CLIError(
|
|
2486
|
-
'Source document must contain an "id" field.',
|
|
2487
|
-
"INVALID_ARGUMENT_ERROR",
|
|
2488
|
-
options
|
|
2489
|
-
);
|
|
2490
|
-
}
|
|
2491
|
-
const network = deriveNetwork(did);
|
|
2492
|
-
assertKeystoreAllowedForNetwork(network, globals());
|
|
2493
|
-
const api = factory(network, globals());
|
|
2494
|
-
const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(globals()));
|
|
2495
|
-
const signer = new import_key_manager3.KeyManagerSigner(api.kms.kms, keyId);
|
|
2496
|
-
const broadcastOptions = resolveBroadcastOptions(network, globals(), {
|
|
2497
|
-
feeRate: options.feeRate,
|
|
2498
|
-
changeAddress: options.changeAddress
|
|
2499
|
-
});
|
|
2500
|
-
const data = await api.btcr2.update({
|
|
2501
|
-
sourceDocument: parsed.sourceDocument,
|
|
2502
|
-
patches: parsed.patches,
|
|
2503
|
-
sourceVersionId: parsed.sourceVersionId,
|
|
2504
|
-
verificationMethodId: parsed.verificationMethodId,
|
|
2505
|
-
beaconId: parsed.beaconId,
|
|
2506
|
-
signer,
|
|
2507
|
-
publishToCas: options.publishToCas,
|
|
2508
|
-
...broadcastOptions ? { broadcastOptions } : {}
|
|
2509
|
-
});
|
|
2510
|
-
console.log(formatResult({ action: "deactivate", data }, globals()));
|
|
2511
|
-
printWatchHint(globals(), network, data.txid);
|
|
2493
|
+
const command = program.command("deactivate").alias("delete").description("Deactivate the did:btcr2 identifier permanently. This is irreversible.").requiredOption("-i, --identifier <identifier>", "did:btcr2 identifier to deactivate");
|
|
2494
|
+
registerWriteOptions(command).action(async (options) => {
|
|
2495
|
+
const g = globals();
|
|
2496
|
+
const { network, api, params } = await prepareWrite(options, factory, g);
|
|
2497
|
+
const data = await api.deactivateDid(params);
|
|
2498
|
+
console.log(formatResult({ action: "deactivate", data }, g));
|
|
2499
|
+
printWatchHint(g, network, data.txid);
|
|
2512
2500
|
});
|
|
2513
2501
|
}
|
|
2514
|
-
function parsePublishToCasMode2(value) {
|
|
2515
|
-
if (value !== "auto" && value !== "always" && value !== "never") {
|
|
2516
|
-
throw new CLIError(
|
|
2517
|
-
'--publish-to-cas must be one of "auto", "always", or "never".',
|
|
2518
|
-
"INVALID_ARGUMENT_ERROR",
|
|
2519
|
-
{ value }
|
|
2520
|
-
);
|
|
2521
|
-
}
|
|
2522
|
-
return value;
|
|
2523
|
-
}
|
|
2524
|
-
function parseJsonArg2(flagName) {
|
|
2525
|
-
return (value) => {
|
|
2526
|
-
try {
|
|
2527
|
-
return JSON.parse(value);
|
|
2528
|
-
} catch {
|
|
2529
|
-
throw new CLIError(
|
|
2530
|
-
`Invalid JSON for ${flagName}. Must be a valid JSON string.`,
|
|
2531
|
-
"INVALID_ARGUMENT_ERROR",
|
|
2532
|
-
{ flagName, value }
|
|
2533
|
-
);
|
|
2534
|
-
}
|
|
2535
|
-
};
|
|
2536
|
-
}
|
|
2537
2502
|
|
|
2538
2503
|
// src/commands/key.ts
|
|
2539
2504
|
var import_keypair = require("@did-btcr2/keypair");
|
|
@@ -1,98 +1,21 @@
|
|
|
1
|
-
import { KeyManagerSigner } from '@did-btcr2/key-manager';
|
|
2
|
-
import { assertKeystoreAllowedForNetwork, deriveNetwork, resolveBroadcastOptions, resolveSigningKeyRef } from '../config.js';
|
|
3
|
-
import { CLIError } from '../error.js';
|
|
4
1
|
import { printWatchHint } from '../hints.js';
|
|
5
|
-
import { resolveKeyRef } from '../keystore/resolve-key-ref.js';
|
|
6
2
|
import { formatResult } from '../output.js';
|
|
7
|
-
|
|
8
|
-
const DEACTIVATION_PATCH = [{ op: 'add', path: '/deactivated', value: true }];
|
|
3
|
+
import { prepareWrite, registerWriteOptions } from './write.js';
|
|
9
4
|
export function registerDeactivateCommand(program, factory, globals) {
|
|
10
|
-
program
|
|
5
|
+
const command = program
|
|
11
6
|
.command('deactivate')
|
|
12
7
|
.alias('delete')
|
|
13
8
|
.description('Deactivate the did:btcr2 identifier permanently. This is irreversible.')
|
|
14
|
-
.requiredOption('-
|
|
15
|
-
|
|
16
|
-
.requiredOption('-m, --verification-method-id <id>', 'DID document verification method ID used to sign the deactivation')
|
|
17
|
-
.requiredOption('-b, --beacon-id <json>', 'Beacon ID as a JSON string', parseJsonArg('--beacon-id'))
|
|
18
|
-
.option('--publish-to-cas <mode>', 'Publish update artifacts to a writable CAS before broadcast: auto|always|never. '
|
|
19
|
-
+ 'CAS publication is optional; the default distributes the returned artifacts via sidecar.', parsePublishToCasMode, 'never')
|
|
20
|
-
.option('--fee-rate <satsPerVByte>', 'Fee rate in sats/vByte for the beacon transaction (default: 5). '
|
|
21
|
-
+ 'Raise it under congestion so the transaction confirms.')
|
|
22
|
-
.option('--change-address <address>', 'Send transaction change to this address instead of the beacon address, '
|
|
23
|
-
+ 'so a DID\'s announcements are not linked on-chain (ADR 044).')
|
|
9
|
+
.requiredOption('-i, --identifier <identifier>', 'did:btcr2 identifier to deactivate');
|
|
10
|
+
registerWriteOptions(command)
|
|
24
11
|
.action(async (options) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
verificationMethodId: options.verificationMethodId,
|
|
33
|
-
beaconId: options.beaconId,
|
|
34
|
-
};
|
|
35
|
-
const did = parsed.sourceDocument?.id;
|
|
36
|
-
if (!did) {
|
|
37
|
-
throw new CLIError('Source document must contain an "id" field.', 'INVALID_ARGUMENT_ERROR', options);
|
|
38
|
-
}
|
|
39
|
-
// Deactivation is an update that applies the deactivation patch. The core
|
|
40
|
-
// method has no separate deactivate path, so this routes through update.
|
|
41
|
-
const network = deriveNetwork(did);
|
|
42
|
-
// Refuse to sign a mainnet deactivation with an unencrypted dev keystore (ADR 080).
|
|
43
|
-
assertKeystoreAllowedForNetwork(network, globals());
|
|
44
|
-
const api = factory(network, globals());
|
|
45
|
-
const keyId = resolveKeyRef(api.kms.kms, resolveSigningKeyRef(globals()));
|
|
46
|
-
const signer = new KeyManagerSigner(api.kms.kms, keyId);
|
|
47
|
-
// Resolve fee-rate/change-address through the flag -> env -> profile chain
|
|
48
|
-
// into beacon broadcast options. Undefined when neither is set, so the
|
|
49
|
-
// SDK defaults (5 sat/vB, change back to the beacon address) still apply.
|
|
50
|
-
const broadcastOptions = resolveBroadcastOptions(network, globals(), {
|
|
51
|
-
feeRate: options.feeRate,
|
|
52
|
-
changeAddress: options.changeAddress,
|
|
53
|
-
});
|
|
54
|
-
// CAS publication is optional and never required: every beacon update can
|
|
55
|
-
// be completed and shared via sidecar alone. It is opt-in and defaults to
|
|
56
|
-
// 'never'; pass --publish-to-cas auto|always to publish the signed update
|
|
57
|
-
// (and, for CAS beacons, the announcement) to a writable CAS configured
|
|
58
|
-
// via --cas-rpc-url. The returned artifacts (txid, announcement, proof)
|
|
59
|
-
// are always printed for sidecar distribution regardless.
|
|
60
|
-
const data = await api.btcr2.update({
|
|
61
|
-
sourceDocument: parsed.sourceDocument,
|
|
62
|
-
patches: parsed.patches,
|
|
63
|
-
sourceVersionId: parsed.sourceVersionId,
|
|
64
|
-
verificationMethodId: parsed.verificationMethodId,
|
|
65
|
-
beaconId: parsed.beaconId,
|
|
66
|
-
signer,
|
|
67
|
-
publishToCas: options.publishToCas,
|
|
68
|
-
...(broadcastOptions ? { broadcastOptions } : {}),
|
|
69
|
-
});
|
|
70
|
-
console.log(formatResult({ action: 'deactivate', data }, globals()));
|
|
71
|
-
printWatchHint(globals(), network, data.txid);
|
|
12
|
+
const g = globals();
|
|
13
|
+
const { network, api, params } = await prepareWrite(options, factory, g);
|
|
14
|
+
// The api supplies the deactivation patch (ADR 094) and refuses a
|
|
15
|
+
// document that is deactivated already (ADR 100).
|
|
16
|
+
const data = await api.deactivateDid(params);
|
|
17
|
+
console.log(formatResult({ action: 'deactivate', data }, g));
|
|
18
|
+
printWatchHint(g, network, data.txid);
|
|
72
19
|
});
|
|
73
20
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Commander argParser for `--publish-to-cas`. Validates the value is one of the
|
|
76
|
-
* three {@link PublishToCasMode} policies, erroring at parse time otherwise.
|
|
77
|
-
*/
|
|
78
|
-
function parsePublishToCasMode(value) {
|
|
79
|
-
if (value !== 'auto' && value !== 'always' && value !== 'never') {
|
|
80
|
-
throw new CLIError('--publish-to-cas must be one of "auto", "always", or "never".', 'INVALID_ARGUMENT_ERROR', { value });
|
|
81
|
-
}
|
|
82
|
-
return value;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Returns a commander argParser that validates JSON.
|
|
86
|
-
* Errors at parse time with a clear flag reference.
|
|
87
|
-
*/
|
|
88
|
-
function parseJsonArg(flagName) {
|
|
89
|
-
return (value) => {
|
|
90
|
-
try {
|
|
91
|
-
return JSON.parse(value);
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
throw new CLIError(`Invalid JSON for ${flagName}. Must be a valid JSON string.`, 'INVALID_ARGUMENT_ERROR', { flagName, value });
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
21
|
//# sourceMappingURL=deactivate.js.map
|
|
@@ -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":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAmB,MAAM,YAAY,CAAC;AAEjF,MAAM,UAAU,yBAAyB,CACvC,OAAiB,EACjB,OAAoB,EACpB,OAA6B;IAE7B,MAAM,OAAO,GAAG,OAAO;SACpB,OAAO,CAAC,YAAY,CAAC;SACrB,KAAK,CAAC,QAAQ,CAAC;SACf,WAAW,CAAC,wEAAwE,CAAC;SACrF,cAAc,CAAC,+BAA+B,EAAE,oCAAoC,CAAC,CAAC;IACzF,oBAAoB,CAAC,OAAO,CAAC;SAC1B,MAAM,CAAC,KAAK,EAAE,OAAmB,EAAE,EAAE;QACpC,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;QACpB,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QACzE,kEAAkE;QAClE,kDAAkD;QAClD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7D,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Identifier } from '@did-btcr2/api';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
2
|
import { deriveNetwork } from '../config.js';
|
|
4
|
-
import { CLIError } from '../error.js';
|
|
5
3
|
import { formatResult } from '../output.js';
|
|
4
|
+
import { MIN_CONF_HELP, parseMinConf, readResolutionOptions } from '../resolution-options.js';
|
|
6
5
|
export function registerResolveCommand(program, factory, globals) {
|
|
7
6
|
program
|
|
8
7
|
.command('resolve')
|
|
@@ -11,6 +10,7 @@ export function registerResolveCommand(program, factory, globals) {
|
|
|
11
10
|
.requiredOption('-i, --identifier <identifier>', 'did:btcr2 identifier')
|
|
12
11
|
.option('-r, --resolution-options <json>', 'JSON string containing resolution options')
|
|
13
12
|
.option('-p, --resolution-options-path <path>', 'Path to a JSON file containing resolution options')
|
|
13
|
+
.option('--min-conf <n>', MIN_CONF_HELP, parseMinConf)
|
|
14
14
|
.action(async (options) => {
|
|
15
15
|
const parsed = await validateResolveOptions(options);
|
|
16
16
|
const network = deriveNetwork(parsed.identifier);
|
|
@@ -23,24 +23,7 @@ export function registerResolveCommand(program, factory, globals) {
|
|
|
23
23
|
async function validateResolveOptions(options) {
|
|
24
24
|
// Validate identifier format early
|
|
25
25
|
Identifier.decode(options.identifier);
|
|
26
|
-
|
|
27
|
-
if (options.resolutionOptions) {
|
|
28
|
-
try {
|
|
29
|
-
resolutionOptions = JSON.parse(options.resolutionOptions);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
throw new CLIError('Invalid resolution options. Must be a valid JSON string.', 'INVALID_ARGUMENT_ERROR', options);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (options.resolutionOptionsPath) {
|
|
36
|
-
try {
|
|
37
|
-
const content = await readFile(options.resolutionOptionsPath, 'utf-8');
|
|
38
|
-
resolutionOptions = JSON.parse(content);
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
throw new CLIError('Invalid resolution options path. Must be a valid path to a JSON file.', 'INVALID_ARGUMENT_ERROR', options);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
26
|
+
const resolutionOptions = await readResolutionOptions(options);
|
|
44
27
|
return { identifier: options.identifier, options: resolutionOptions };
|
|
45
28
|
}
|
|
46
29
|
//# sourceMappingURL=resolve.js.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,qBAAqB,EAA8B,MAAM,0BAA0B,CAAC;AAG1H,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,gBAAgB,EAAE,aAAa,EAAE,YAAY,CAAC;SACrD,MAAM,CAAC,KAAK,EAAE,OAAuD,EAAE,EAAE;QACxE,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QACrE,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,SAAkB,EAAE,IAAI,EAAE,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,sBAAsB,CACnC,OAAuD;IAEvD,mCAAmC;IACnC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC,MAAM,iBAAiB,GAAG,MAAM,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC/D,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AACxE,CAAC"}
|