@did-btcr2/cli 0.22.0 → 0.23.1
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 +36 -396
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +404 -83
- package/dist/esm/src/cli.js +2 -1
- package/dist/esm/src/cli.js.map +1 -1
- package/dist/esm/src/commands/completion.js +20 -7
- package/dist/esm/src/commands/completion.js.map +1 -1
- package/dist/esm/src/commands/create.js +33 -41
- package/dist/esm/src/commands/create.js.map +1 -1
- package/dist/esm/src/commands/genesis.js +119 -0
- package/dist/esm/src/commands/genesis.js.map +1 -0
- package/dist/esm/src/commands/identifier.js +3 -17
- package/dist/esm/src/commands/identifier.js.map +1 -1
- package/dist/esm/src/commands/index.js +1 -0
- package/dist/esm/src/commands/index.js.map +1 -1
- package/dist/esm/src/commands/resolve.js +15 -1
- package/dist/esm/src/commands/resolve.js.map +1 -1
- package/dist/esm/src/commands/write.js +10 -7
- package/dist/esm/src/commands/write.js.map +1 -1
- package/dist/esm/src/genesis-document-file.js +26 -0
- package/dist/esm/src/genesis-document-file.js.map +1 -0
- package/dist/esm/src/genesis-spec.js +93 -0
- package/dist/esm/src/genesis-spec.js.map +1 -0
- package/dist/esm/src/genesis-wizard.js +132 -0
- package/dist/esm/src/genesis-wizard.js.map +1 -0
- package/dist/esm/src/hints.js +14 -3
- package/dist/esm/src/hints.js.map +1 -1
- package/dist/esm/src/network-option.js +39 -0
- package/dist/esm/src/network-option.js.map +1 -0
- package/dist/esm/src/resolution-options.js +19 -2
- package/dist/esm/src/resolution-options.js.map +1 -1
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/commands/completion.d.ts.map +1 -1
- package/dist/types/src/commands/create.d.ts +5 -4
- package/dist/types/src/commands/create.d.ts.map +1 -1
- package/dist/types/src/commands/genesis.d.ts +20 -0
- package/dist/types/src/commands/genesis.d.ts.map +1 -0
- package/dist/types/src/commands/identifier.d.ts.map +1 -1
- package/dist/types/src/commands/index.d.ts +1 -0
- package/dist/types/src/commands/index.d.ts.map +1 -1
- package/dist/types/src/commands/resolve.d.ts +7 -0
- package/dist/types/src/commands/resolve.d.ts.map +1 -1
- package/dist/types/src/commands/write.d.ts +2 -1
- package/dist/types/src/commands/write.d.ts.map +1 -1
- package/dist/types/src/genesis-document-file.d.ts +11 -0
- package/dist/types/src/genesis-document-file.d.ts.map +1 -0
- package/dist/types/src/genesis-spec.d.ts +70 -0
- package/dist/types/src/genesis-spec.d.ts.map +1 -0
- package/dist/types/src/genesis-wizard.d.ts +30 -0
- package/dist/types/src/genesis-wizard.d.ts.map +1 -0
- package/dist/types/src/hints.d.ts +7 -0
- package/dist/types/src/hints.d.ts.map +1 -1
- package/dist/types/src/network-option.d.ts +15 -0
- package/dist/types/src/network-option.d.ts.map +1 -0
- package/dist/types/src/resolution-options.d.ts +6 -2
- package/dist/types/src/resolution-options.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +18 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +2 -0
- package/src/commands/completion.ts +21 -7
- package/src/commands/create.ts +39 -55
- package/src/commands/genesis.ts +149 -0
- package/src/commands/identifier.ts +3 -25
- package/src/commands/index.ts +1 -0
- package/src/commands/resolve.ts +20 -1
- package/src/commands/write.ts +10 -7
- package/src/genesis-document-file.ts +35 -0
- package/src/genesis-spec.ts +149 -0
- package/src/genesis-wizard.ts +163 -0
- package/src/hints.ts +13 -2
- package/src/network-option.ts +50 -0
- package/src/resolution-options.ts +21 -2
- package/src/types.ts +17 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { CLIError } from './error.js';
|
|
3
|
+
/** The help text of `--genesis-document`. `resolve`, `update`, and `deactivate` share it. */
|
|
4
|
+
export const GENESIS_DOCUMENT_HELP = 'Path to the JSON genesis document of an external identifier (x). '
|
|
5
|
+
+ 'Fills sidecar.genesisDocument of the resolution options';
|
|
6
|
+
/**
|
|
7
|
+
* Reads and parses a genesis document file. The content must be a JSON
|
|
8
|
+
* object. The shape of the document is checked by the api, not here.
|
|
9
|
+
* @param path The path of the JSON file.
|
|
10
|
+
* @returns The parsed object.
|
|
11
|
+
* @throws {CLIError} If the file is unreadable, not JSON, or not an object.
|
|
12
|
+
*/
|
|
13
|
+
export async function readGenesisDocumentFile(path) {
|
|
14
|
+
let parsed;
|
|
15
|
+
try {
|
|
16
|
+
parsed = JSON.parse(await readFile(path, 'utf-8'));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new CLIError('Invalid genesis document path. Must be a valid path to a JSON file.', 'INVALID_ARGUMENT_ERROR', { genesisDocument: path });
|
|
20
|
+
}
|
|
21
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
22
|
+
throw new CLIError('Invalid genesis document. The file must contain a JSON object.', 'INVALID_ARGUMENT_ERROR', { genesisDocument: path });
|
|
23
|
+
}
|
|
24
|
+
return parsed;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=genesis-document-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genesis-document-file.js","sourceRoot":"","sources":["../../../src/genesis-document-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,qBAAqB,GAChC,mEAAmE;MACjE,yDAAyD,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAY;IACxD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,QAAQ,CAChB,qEAAqE,EACrE,wBAAwB,EACxB,EAAE,eAAe,EAAE,IAAI,EAAE,CAC1B,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,QAAQ,CAChB,gEAAgE,EAChE,wBAAwB,EACxB,EAAE,eAAe,EAAE,IAAI,EAAE,CAC1B,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { hexToBytes } from '@noble/hashes/utils.js';
|
|
2
|
+
import { CLIError } from './error.js';
|
|
3
|
+
/**
|
|
4
|
+
* Checks the shape of a parsed genesis spec file. The values (relationship
|
|
5
|
+
* names, beacon types, addresses) are checked by the api when it builds the
|
|
6
|
+
* document; this function checks only what the api cannot see: that each
|
|
7
|
+
* verification method names exactly one key source, and that each beacon
|
|
8
|
+
* names at most one.
|
|
9
|
+
* @param value The parsed JSON value.
|
|
10
|
+
* @param source The file path, for the error data.
|
|
11
|
+
* @returns The spec.
|
|
12
|
+
* @throws {CLIError} If the shape is not valid.
|
|
13
|
+
*/
|
|
14
|
+
export function parseGenesisSpec(value, source) {
|
|
15
|
+
const fail = (message) => {
|
|
16
|
+
throw new CLIError(`Invalid genesis spec: ${message}`, 'INVALID_ARGUMENT_ERROR', { spec: source });
|
|
17
|
+
};
|
|
18
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
19
|
+
return fail('the file must contain a JSON object.');
|
|
20
|
+
}
|
|
21
|
+
const spec = value;
|
|
22
|
+
if (!Array.isArray(spec.verificationMethods) || spec.verificationMethods.length === 0) {
|
|
23
|
+
return fail('"verificationMethods" must be a non-empty array.');
|
|
24
|
+
}
|
|
25
|
+
spec.verificationMethods.forEach((vm, index) => {
|
|
26
|
+
if (vm === null || typeof vm !== 'object')
|
|
27
|
+
return fail(`verificationMethods[${index}] must be an object.`);
|
|
28
|
+
const hasKey = typeof vm.key === 'string' && vm.key.length > 0;
|
|
29
|
+
const hasPublicKey = typeof vm.publicKey === 'string' && vm.publicKey.length > 0;
|
|
30
|
+
if (hasKey === hasPublicKey) {
|
|
31
|
+
return fail(`verificationMethods[${index}] needs exactly one of "key" (a keystore reference) or "publicKey" (hex).`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (spec.beacons !== undefined) {
|
|
35
|
+
if (!Array.isArray(spec.beacons))
|
|
36
|
+
return fail('"beacons" must be an array.');
|
|
37
|
+
spec.beacons.forEach((beacon, index) => {
|
|
38
|
+
if (beacon === null || typeof beacon !== 'object')
|
|
39
|
+
return fail(`beacons[${index}] must be an object.`);
|
|
40
|
+
const sources = ['key', 'publicKey', 'address'].filter(name => beacon[name] !== undefined);
|
|
41
|
+
if (sources.length > 1) {
|
|
42
|
+
return fail(`beacons[${index}] names ${sources.join(' and ')}. Give only one of "key", "publicKey", or "address".`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (spec.services !== undefined && !Array.isArray(spec.services)) {
|
|
47
|
+
return fail('"services" must be an array.');
|
|
48
|
+
}
|
|
49
|
+
return spec;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts a genesis spec file to the api spec: resolves each keystore
|
|
53
|
+
* reference to its public key, parses each hex public key, and passes the
|
|
54
|
+
* other values through for the api to check.
|
|
55
|
+
* @param spec The spec file.
|
|
56
|
+
* @param network The network of the beacon addresses.
|
|
57
|
+
* @param resolvePublicKey Resolves a keystore reference to the public key.
|
|
58
|
+
* @returns The api spec.
|
|
59
|
+
* @throws {CLIError} If a hex public key is not hex.
|
|
60
|
+
*/
|
|
61
|
+
export function toApiSpec(spec, network, resolvePublicKey) {
|
|
62
|
+
const keyBytes = (entry, label) => entry.key !== undefined ? resolvePublicKey(entry.key) : parseHexPublicKey(entry.publicKey, label);
|
|
63
|
+
const verificationMethods = spec.verificationMethods.map((vm, index) => ({
|
|
64
|
+
publicKey: keyBytes(vm, `verificationMethods[${index}].publicKey`),
|
|
65
|
+
relationships: vm.relationships,
|
|
66
|
+
fragment: vm.fragment,
|
|
67
|
+
}));
|
|
68
|
+
const beacons = spec.beacons?.map((beacon, index) => ({
|
|
69
|
+
type: beacon.type,
|
|
70
|
+
publicKey: beacon.key !== undefined || beacon.publicKey !== undefined
|
|
71
|
+
? keyBytes(beacon, `beacons[${index}].publicKey`)
|
|
72
|
+
: undefined,
|
|
73
|
+
addressType: beacon.addressType,
|
|
74
|
+
address: beacon.address,
|
|
75
|
+
fragment: beacon.fragment,
|
|
76
|
+
}));
|
|
77
|
+
return {
|
|
78
|
+
network,
|
|
79
|
+
verificationMethods,
|
|
80
|
+
beacons,
|
|
81
|
+
services: spec.services,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Parses a hex public key. The length and the curve check belong to the api. */
|
|
85
|
+
export function parseHexPublicKey(hex, label) {
|
|
86
|
+
try {
|
|
87
|
+
return hexToBytes(hex.trim());
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
throw new CLIError(`Invalid ${label}: not valid hex.`, 'INVALID_ARGUMENT_ERROR', { publicKey: hex });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=genesis-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genesis-spec.js","sourceRoot":"","sources":["../../../src/genesis-spec.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAkDtC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,MAAc;IAC7D,MAAM,IAAI,GAAG,CAAC,OAAe,EAAS,EAAE;QACtC,MAAM,IAAI,QAAQ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X = /^0[23][0-9a-fA-F]{64}$/;
|
|
4
|
+
/**
|
|
5
|
+
* Collects a genesis spec through questions: the verification methods with
|
|
6
|
+
* their relationships, the beacons, and the other services. The answers are
|
|
7
|
+
* not checked against the network here; the api checks them when it builds
|
|
8
|
+
* the document, and the command reports the failure.
|
|
9
|
+
* @param ask Asks one question.
|
|
10
|
+
* @param ctx The output, the key list, and the key resolver.
|
|
11
|
+
* @returns The spec.
|
|
12
|
+
*/
|
|
13
|
+
export async function collectGenesisSpec(ask, ctx) {
|
|
14
|
+
const verificationMethods = await collectVerificationMethods(ask, ctx);
|
|
15
|
+
const beacons = await collectBeacons(ask, ctx, verificationMethods[0]);
|
|
16
|
+
const services = await collectServices(ask, ctx);
|
|
17
|
+
return { verificationMethods, beacons, ...(services.length > 0 && { services }) };
|
|
18
|
+
}
|
|
19
|
+
/** Asks for the verification methods. The first one defaults to the active key. */
|
|
20
|
+
async function collectVerificationMethods(ask, ctx) {
|
|
21
|
+
if (ctx.keys.length === 0) {
|
|
22
|
+
ctx.say('The keystore has no keys. Enter each key as a 33-byte compressed public key in hex.');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
ctx.say('Keys in the keystore:');
|
|
26
|
+
for (const key of ctx.keys) {
|
|
27
|
+
ctx.say(` ${key.fingerprint}${key.name ? ` ${key.name}` : ''}${key.active ? ' (active)' : ''}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const active = ctx.keys.find(key => key.active);
|
|
31
|
+
const methods = [];
|
|
32
|
+
for (let n = 1;; n++) {
|
|
33
|
+
const defaultRef = n === 1 && active ? (active.name ?? active.fingerprint) : undefined;
|
|
34
|
+
const source = await askKeySource(ask, ctx, `Verification method ${n}: key reference or public key hex`, defaultRef);
|
|
35
|
+
const relationships = await askRelationships(ask, ctx, n);
|
|
36
|
+
methods.push({ ...source, ...(relationships && { relationships }) });
|
|
37
|
+
if (!(await askYesNo(ask, 'Add another verification method?')))
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return methods;
|
|
41
|
+
}
|
|
42
|
+
/** Asks for the beacons. The first one defaults to a Singleton beacon on the first key. */
|
|
43
|
+
async function collectBeacons(ask, ctx, firstMethod) {
|
|
44
|
+
const beacons = [];
|
|
45
|
+
for (let n = 1;; n++) {
|
|
46
|
+
const type = await askChoice(ask, ctx, `Beacon ${n} type`, BEACON_TYPES, 'SingletonBeacon');
|
|
47
|
+
const address = (await ask(`Beacon ${n} address (blank: derive the address from the key of method 1): `)).trim();
|
|
48
|
+
if (address.length === 0) {
|
|
49
|
+
const addressType = await askChoice(ask, ctx, `Beacon ${n} address type`, BEACON_ADDRESS_TYPES, DEFAULT_BEACON_ADDRESS_TYPE);
|
|
50
|
+
const keySource = firstMethod.key !== undefined ? { key: firstMethod.key } : { publicKey: firstMethod.publicKey };
|
|
51
|
+
beacons.push({ type, ...keySource, addressType });
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
beacons.push({ type, address });
|
|
55
|
+
}
|
|
56
|
+
if (!(await askYesNo(ask, 'Add another beacon?')))
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return beacons;
|
|
60
|
+
}
|
|
61
|
+
/** Asks for the other services, if any. */
|
|
62
|
+
async function collectServices(ask, ctx) {
|
|
63
|
+
const services = [];
|
|
64
|
+
while (await askYesNo(ask, 'Add a service?')) {
|
|
65
|
+
const n = services.length + 1;
|
|
66
|
+
const fragment = (await ask(`Service ${n} id fragment (blank: service-<position>): `)).trim();
|
|
67
|
+
const type = await askRequired(ask, ctx, `Service ${n} type`);
|
|
68
|
+
const serviceEndpoint = await askRequired(ask, ctx, `Service ${n} endpoint`);
|
|
69
|
+
services.push({ ...(fragment.length > 0 && { id: `#${fragment.replace(/^#/, '')}` }), type, serviceEndpoint });
|
|
70
|
+
}
|
|
71
|
+
return services;
|
|
72
|
+
}
|
|
73
|
+
/** Asks for a key reference or a public key hex, until the answer resolves. */
|
|
74
|
+
async function askKeySource(ask, ctx, question, defaultRef) {
|
|
75
|
+
for (;;) {
|
|
76
|
+
const raw = (await ask(`${question}${defaultRef ? ` [${defaultRef}]` : ''}: `)).trim();
|
|
77
|
+
const answer = raw.length > 0 ? raw : defaultRef;
|
|
78
|
+
if (answer === undefined) {
|
|
79
|
+
ctx.say('A key is required.');
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (PUBLIC_KEY_HEX.test(answer))
|
|
83
|
+
return { publicKey: answer.toLowerCase() };
|
|
84
|
+
try {
|
|
85
|
+
ctx.resolveKey(answer);
|
|
86
|
+
return { key: answer };
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
ctx.say(error.message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Asks for the relationships of a method. Blank means all four (the api default). */
|
|
94
|
+
async function askRelationships(ask, ctx, n) {
|
|
95
|
+
const names = VERIFICATION_RELATIONSHIPS.join(', ');
|
|
96
|
+
for (;;) {
|
|
97
|
+
const raw = (await ask(`Relationships of method ${n} (comma-separated: ${names}) [all]: `)).trim();
|
|
98
|
+
if (raw.length === 0)
|
|
99
|
+
return undefined;
|
|
100
|
+
const chosen = raw.split(',').map(s => s.trim()).filter(s => s.length > 0);
|
|
101
|
+
const unknown = chosen.filter(name => !VERIFICATION_RELATIONSHIPS.includes(name));
|
|
102
|
+
if (unknown.length === 0)
|
|
103
|
+
return chosen;
|
|
104
|
+
ctx.say(`Unknown relationship: ${unknown.join(', ')}. Expected one of ${names}.`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Asks for one value of a list, with a default. */
|
|
108
|
+
async function askChoice(ask, ctx, question, choices, defaultValue) {
|
|
109
|
+
for (;;) {
|
|
110
|
+
const raw = (await ask(`${question} (${choices.join(', ')}) [${defaultValue}]: `)).trim();
|
|
111
|
+
if (raw.length === 0)
|
|
112
|
+
return defaultValue;
|
|
113
|
+
if (choices.includes(raw))
|
|
114
|
+
return raw;
|
|
115
|
+
ctx.say(`Unknown value "${raw}". Expected one of ${choices.join(', ')}.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Asks for a non-empty value. */
|
|
119
|
+
async function askRequired(ask, ctx, question) {
|
|
120
|
+
for (;;) {
|
|
121
|
+
const raw = (await ask(`${question}: `)).trim();
|
|
122
|
+
if (raw.length > 0)
|
|
123
|
+
return raw;
|
|
124
|
+
ctx.say('A value is required.');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Asks a yes/no question. Blank means no. */
|
|
128
|
+
async function askYesNo(ask, question) {
|
|
129
|
+
const raw = (await ask(`${question} [y/N]: `)).trim();
|
|
130
|
+
return /^y(es)?$/i.test(raw);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=genesis-wizard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genesis-wizard.js","sourceRoot":"","sources":["../../../src/genesis-wizard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAwB7H,8CAA8C;AAC9C,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAQ,EAAE,GAAkB;IACnE,MAAM,mBAAmB,GAAG,MAAM,0BAA0B,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACjD,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AACpF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;IACtD,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/esm/src/hints.js
CHANGED
|
@@ -18,9 +18,6 @@ import { BeaconUtils } from '@did-btcr2/method';
|
|
|
18
18
|
export function printCreateFundingHint(g, network, did) {
|
|
19
19
|
if (g.quiet || g.output === 'json')
|
|
20
20
|
return;
|
|
21
|
-
const faucet = faucetUrl(network);
|
|
22
|
-
if (!faucet)
|
|
23
|
-
return;
|
|
24
21
|
let beaconAddress;
|
|
25
22
|
try {
|
|
26
23
|
const { serviceEndpoint } = BeaconUtils.createBeaconService(did, 'p2wpkh', 'SingletonBeacon');
|
|
@@ -29,6 +26,20 @@ export function printCreateFundingHint(g, network, did) {
|
|
|
29
26
|
catch {
|
|
30
27
|
return;
|
|
31
28
|
}
|
|
29
|
+
printBeaconFundingHint(g, network, beaconAddress);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Prints a funding hint for a beacon address on a network with a public
|
|
33
|
+
* faucet: the address next to the faucet and explorer links. A no-op on a
|
|
34
|
+
* network without a faucet (regtest/mainnet). `create -t x --document` and
|
|
35
|
+
* `genesis build` use it for the first beacon of the genesis document.
|
|
36
|
+
*/
|
|
37
|
+
export function printBeaconFundingHint(g, network, beaconAddress) {
|
|
38
|
+
if (g.quiet || g.output === 'json')
|
|
39
|
+
return;
|
|
40
|
+
const faucet = faucetUrl(network);
|
|
41
|
+
if (!faucet)
|
|
42
|
+
return;
|
|
32
43
|
const explorer = explorerAddressUrl(network, beaconAddress);
|
|
33
44
|
const lines = [
|
|
34
45
|
'Fund the initial beacon to anchor updates:',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hints.js","sourceRoot":"","sources":["../../../src/hints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAm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AAE,aAAa,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG;QACZ,4CAA4C;QAC5C,eAAe,aAAa,EAAE;QAC9B,eAAe,MAAM,EAAE;KACxB,CAAC;IACF,IAAI,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,QAAQ,EAAE,CAAC,CAAC;IACpD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,CAAgB,EAAE,OAAsB,EAAE,IAAY;IACnF,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO;IAC3C,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzC,IAAI,GAAG;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { profileNetworkMismatch, resolveDefaultNetwork } from './config.js';
|
|
2
|
+
import { CLIError } from './error.js';
|
|
3
|
+
import { SUPPORTED_NETWORKS } from './types.js';
|
|
4
|
+
/** The help text of `-n, --network` on the offline creation commands. */
|
|
5
|
+
export const NETWORK_OPTION_HELP = 'Identifier bitcoin network <bitcoin|testnet3|testnet4|signet|mutinynet|regtest> '
|
|
6
|
+
+ '(default: config defaults.network, else regtest)';
|
|
7
|
+
/** Builds the keystore- and config-resolution overrides from the global flags. */
|
|
8
|
+
export function overridesFromGlobals(g) {
|
|
9
|
+
return {
|
|
10
|
+
home: g.home,
|
|
11
|
+
config: g.config,
|
|
12
|
+
profile: g.profile,
|
|
13
|
+
keystore: g.keystore,
|
|
14
|
+
passphraseFile: g.passphraseFile,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Validates an explicit `--network`, or resolves the default from configuration. */
|
|
18
|
+
export function resolveNetworkOption(explicit, overrides) {
|
|
19
|
+
if (!explicit)
|
|
20
|
+
return resolveDefaultNetwork(overrides);
|
|
21
|
+
if (!SUPPORTED_NETWORKS.includes(explicit)) {
|
|
22
|
+
throw new CLIError('Invalid network. Must be one of "bitcoin", "testnet3", "testnet4", "signet", "mutinynet", or "regtest".', 'INVALID_ARGUMENT_ERROR', { network: explicit });
|
|
23
|
+
}
|
|
24
|
+
return explicit;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Warns on stderr, and never blocks, when the network of a new identifier
|
|
28
|
+
* disagrees with the network that the active profile declares. A `production`
|
|
29
|
+
* profile that holds mainnet endpoints must not mint a regtest DID in silence.
|
|
30
|
+
*/
|
|
31
|
+
export function warnProfileNetworkMismatch(g, network, overrides) {
|
|
32
|
+
const mismatch = profileNetworkMismatch(network, overrides);
|
|
33
|
+
if (mismatch && !g.quiet) {
|
|
34
|
+
process.stderr.write(`Warning: creating a "${network}" identifier while the active profile `
|
|
35
|
+
+ `"${mismatch.profile}" declares network "${mismatch.declared}". The `
|
|
36
|
+
+ 'identifier\'s network and the profile\'s endpoints may not match.\n');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=network-option.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network-option.js","sourceRoot":"","sources":["../../../src/network-option.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,yEAAyE;AACzE,MAAM,CAAC,MAAM,mBAAmB,GAC9B,kFAAkF;MAChF,kDAAkD,CAAC;AAEvD,kFAAkF;AAClF,MAAM,UAAU,oBAAoB,CAAC,CAAgB;IACnD,OAAO;QACL,IAAI,EAAa,CAAC,CAAC,IAAI;QACvB,MAAM,EAAW,CAAC,CAAC,MAAM;QACzB,OAAO,EAAU,CAAC,CAAC,OAAO;QAC1B,QAAQ,EAAS,CAAC,CAAC,QAAQ;QAC3B,cAAc,EAAG,CAAC,CAAC,cAAc;KAClC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,oBAAoB,CAAC,QAA4B,EAAE,SAA8B;IAC/F,IAAI,CAAC,QAAQ;QAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACvD,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAyB,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,QAAQ,CAChB,yGAAyG,EACzG,wBAAwB,EACxB,EAAE,OAAO,EAAE,QAAQ,EAAE,CACtB,CAAC;IACJ,CAAC;IACD,OAAO,QAAyB,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,CAAgB,EAAE,OAAsB,EAAE,SAA8B;IACjH,MAAM,QAAQ,GAAG,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,IAAI,QAAQ,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,wBAAwB,OAAO,wCAAwC;cACrE,IAAI,QAAQ,CAAC,OAAO,uBAAuB,QAAQ,CAAC,QAAQ,SAAS;cACrE,qEAAqE,CACxE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { DEFAULT_MIN_CONF } from '@did-btcr2/api';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { CLIError } from './error.js';
|
|
4
|
+
import { readGenesisDocumentFile } from './genesis-document-file.js';
|
|
5
|
+
/** Whether any resolution flag is set. */
|
|
6
|
+
export function hasResolutionFlags(flags) {
|
|
7
|
+
return flags.resolutionOptions !== undefined
|
|
8
|
+
|| flags.resolutionOptionsPath !== undefined
|
|
9
|
+
|| flags.minConf !== undefined
|
|
10
|
+
|| flags.genesisDocument !== undefined;
|
|
11
|
+
}
|
|
4
12
|
/** The help text of `--min-conf`. `resolve`, `update`, and `deactivate` share it. */
|
|
5
13
|
export const MIN_CONF_HELP = 'Minimum block confirmations a beacon signal needs before resolution applies it '
|
|
6
14
|
+ `(positive integer, default: ${DEFAULT_MIN_CONF}). Overrides a minConf inside the JSON resolution options`;
|
|
7
15
|
/**
|
|
8
16
|
* Builds the resolution options from the flags. The inline JSON wins over
|
|
9
|
-
* the file. The `--min-conf` flag wins over a `minConf` inside the JSON.
|
|
10
|
-
*
|
|
17
|
+
* the file. The `--min-conf` flag wins over a `minConf` inside the JSON. The
|
|
18
|
+
* `--genesis-document` file wins over a `sidecar.genesisDocument` inside the
|
|
19
|
+
* JSON. Returns `undefined` if no flag is set.
|
|
11
20
|
*/
|
|
12
21
|
export async function readResolutionOptions(flags) {
|
|
13
22
|
let resolutionOptions;
|
|
@@ -32,6 +41,14 @@ export async function readResolutionOptions(flags) {
|
|
|
32
41
|
if (flags.minConf !== undefined) {
|
|
33
42
|
resolutionOptions = { ...(resolutionOptions ?? {}), minConf: flags.minConf };
|
|
34
43
|
}
|
|
44
|
+
// The file wins over a sidecar.genesisDocument inside the JSON options.
|
|
45
|
+
if (flags.genesisDocument !== undefined) {
|
|
46
|
+
const genesisDocument = await readGenesisDocumentFile(flags.genesisDocument);
|
|
47
|
+
resolutionOptions = {
|
|
48
|
+
...(resolutionOptions ?? {}),
|
|
49
|
+
sidecar: { ...(resolutionOptions?.sidecar ?? {}), genesisDocument },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
35
52
|
return resolutionOptions;
|
|
36
53
|
}
|
|
37
54
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolution-options.js","sourceRoot":"","sources":["../../../src/resolution-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MA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A,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAgBpD,OAAO,EAA8D,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAI1G;;GAEG;AACH,qBAAa,WAAW;IACtB,SAAgB,OAAO,EAAE,OAAO,CAAC;IAEjC;;;;;;;;;;;;;OAaG;gBAED,OAAO,GAAE,UAA8B,EACvC,eAAe,GAAE,UAA+B;IA2DlD;;;;OAIG;IACU,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CASjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../../../../src/commands/completion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../../../../src/commands/completion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQjD,4FAA4F;AAC5F,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,GAAG,IAAI,CAO/F"}
|
|
@@ -13,11 +13,12 @@ import type { GlobalOptions } from '../types.js';
|
|
|
13
13
|
* genesis bytes. Reading a public key never decrypts, so this never prompts.
|
|
14
14
|
* - raw (`--bytes <hex>`): a 33-byte public key as hex. Offline, keystore-free.
|
|
15
15
|
*
|
|
16
|
-
* An external (`-t x`) identifier
|
|
17
|
-
*
|
|
16
|
+
* An external (`-t x`) identifier has two input modes: the genesis document
|
|
17
|
+
* file (`--document <path>`), which the api hashes, or the 32-byte hash as
|
|
18
|
+
* hex (`--bytes`). Generation and `--signing-key` apply only to `-t k`.
|
|
18
19
|
*
|
|
19
|
-
* The keystore-free `factory` serves the raw-bytes
|
|
20
|
-
* `keystoreFactory` serves the generate and existing-key paths.
|
|
20
|
+
* The keystore-free `factory` serves the raw-bytes and document paths; the
|
|
21
|
+
* keystore-aware `keystoreFactory` serves the generate and existing-key paths.
|
|
21
22
|
*/
|
|
22
23
|
export declare function registerCreateCommand(program: Command, factory: ApiFactory, keystoreFactory: ApiFactory, globals: () => GlobalOptions): void;
|
|
23
24
|
//# sourceMappingURL=create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/commands/create.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAQ/C,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,aAAa,CAAC;AAQhE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAW,OAAO,EACzB,OAAO,EAAW,UAAU,EAC5B,eAAe,EAAG,UAAU,EAC5B,OAAO,EAAW,MAAM,aAAa,GACpC,IAAI,CAkHN"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import type { ApiFactory } from '../config.js';
|
|
3
|
+
import type { GlobalOptions } from '../types.js';
|
|
4
|
+
/** The default path of the genesis document that `genesis build` writes. */
|
|
5
|
+
export declare const DEFAULT_GENESIS_PATH = "genesis.json";
|
|
6
|
+
/**
|
|
7
|
+
* Registers the `genesis` command group. `genesis build` builds the genesis
|
|
8
|
+
* document of an external (`x`) identifier, writes it to a file, and prints
|
|
9
|
+
* the identifier. On a terminal the command asks for the keys, the beacons,
|
|
10
|
+
* and the services. With `--spec <path>` it reads them from a JSON file and
|
|
11
|
+
* asks nothing. The command is offline: it derives the beacon addresses from
|
|
12
|
+
* the keys and opens no Bitcoin connection.
|
|
13
|
+
*
|
|
14
|
+
* The keystore-free `factory` builds the document; the keystore-aware
|
|
15
|
+
* `keystoreFactory` resolves key references and lists the keys for the
|
|
16
|
+
* wizard. Reading a public key never decrypts, so the command never prompts
|
|
17
|
+
* for the passphrase.
|
|
18
|
+
*/
|
|
19
|
+
export declare function registerGenesisCommand(program: Command, factory: ApiFactory, keystoreFactory: ApiFactory, globals: () => GlobalOptions): void;
|
|
20
|
+
//# sourceMappingURL=genesis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genesis.d.ts","sourceRoot":"","sources":["../../../../src/commands/genesis.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAQ/C,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,aAAa,CAAC;AAEhE,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,iBAAiB,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAW,OAAO,EACzB,OAAO,EAAW,UAAU,EAC5B,eAAe,EAAG,UAAU,EAC5B,OAAO,EAAW,MAAM,aAAa,GACpC,IAAI,CA2DN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifier.d.ts","sourceRoot":"","sources":["../../../../src/commands/identifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"identifier.d.ts","sourceRoot":"","sources":["../../../../src/commands/identifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,KAAK,EAAiB,aAAa,EAAwB,MAAM,aAAa,CAAC;AAEtF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAG,OAAO,EACjB,OAAO,EAAG,UAAU,EACpB,OAAO,EAAG,MAAM,aAAa,GAC5B,IAAI,CAuFN"}
|
|
@@ -5,6 +5,7 @@ export { registerResolveCommand } from './resolve.js';
|
|
|
5
5
|
export { registerUpdateCommand } from './update.js';
|
|
6
6
|
export { registerDeactivateCommand } from './deactivate.js';
|
|
7
7
|
export { registerIdentifierCommand } from './identifier.js';
|
|
8
|
+
export { registerGenesisCommand } from './genesis.js';
|
|
8
9
|
export { registerKeyCommand } from './key.js';
|
|
9
10
|
export { registerKeystoreCommand } from './keystore.js';
|
|
10
11
|
export { registerConfigCommand } from './config.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
2
|
import { type ApiFactory } from '../config.js';
|
|
3
|
+
import { type ResolutionOptionFlags } from '../resolution-options.js';
|
|
3
4
|
import type { GlobalOptions } from '../types.js';
|
|
4
5
|
export declare function registerResolveCommand(program: Command, factory: ApiFactory, globals: () => GlobalOptions): void;
|
|
6
|
+
/**
|
|
7
|
+
* Refuses `--genesis-document` for a KEY identifier before the file is read.
|
|
8
|
+
* A KEY identifier has no genesis document; the resolver would ignore the
|
|
9
|
+
* file in silence. `resolve`, `update`, and `deactivate` share the check.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertGenesisDocumentApplies(flags: ResolutionOptionFlags, hrp: string): void;
|
|
5
12
|
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../../src/commands/resolve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAI9D,OAAO,EAAsD,KAAK,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC1H,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,CAkBN;AAYD;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAQ5F"}
|
|
@@ -32,7 +32,8 @@ export declare function registerWriteOptions(command: Command): Command;
|
|
|
32
32
|
* 3. The resolution flags come only without the source pair. The api ignores
|
|
33
33
|
* `resolutionOptions` when the pair is supplied (ADR 098). A silent ignore
|
|
34
34
|
* of `--min-conf` would mislead.
|
|
35
|
-
* 4.
|
|
35
|
+
* 4. `--genesis-document` comes only with an external (x) identifier.
|
|
36
|
+
* 5. A mainnet write is refused with an unencrypted dev keystore (ADR 080).
|
|
36
37
|
*/
|
|
37
38
|
export declare function prepareWrite(options: WriteFlags, factory: ApiFactory, g: GlobalOptions): Promise<{
|
|
38
39
|
network: NetworkOption;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../../src/commands/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEtF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../../src/commands/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,WAAW,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEtF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;AAKtB,OAAO,EAA0E,KAAK,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC9I,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGtF,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG,qBAAqB,GAAG;IAC/C,UAAU,EAAc,MAAM,CAAC;IAC/B,cAAc,CAAC,EAAS,OAAO,CAAC;IAChC,eAAe,CAAC,EAAQ,MAAM,CAAC;IAC/B,oBAAoB,CAAC,EAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAe,MAAM,CAAC;IAC/B,YAAY,EAAY,gBAAgB,CAAC;IACzC,OAAO,CAAC,EAAgB,MAAM,CAAC;IAC/B,aAAa,CAAC,EAAU,MAAM,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAkD9D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAG,UAAU,EACpB,OAAO,EAAG,UAAU,EACpB,CAAC,EAAS,aAAa,GACtB,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,GAAG,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAA;CAAE,CAAC,CAiDrF;AA6BD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAYzE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The help text of `--genesis-document`. `resolve`, `update`, and `deactivate` share it. */
|
|
2
|
+
export declare const GENESIS_DOCUMENT_HELP: string;
|
|
3
|
+
/**
|
|
4
|
+
* Reads and parses a genesis document file. The content must be a JSON
|
|
5
|
+
* object. The shape of the document is checked by the api, not here.
|
|
6
|
+
* @param path The path of the JSON file.
|
|
7
|
+
* @returns The parsed object.
|
|
8
|
+
* @throws {CLIError} If the file is unreadable, not JSON, or not an object.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readGenesisDocumentFile(path: string): Promise<object>;
|
|
11
|
+
//# sourceMappingURL=genesis-document-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genesis-document-file.d.ts","sourceRoot":"","sources":["../../../src/genesis-document-file.ts"],"names":[],"mappings":"AAGA,6FAA6F;AAC7F,eAAO,MAAM,qBAAqB,QAE2B,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmB3E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { GenesisDocumentSpec } from '@did-btcr2/api';
|
|
2
|
+
import type { NetworkOption } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* One verification method of a genesis spec file. `key` is a keystore
|
|
5
|
+
* reference (URN, name, or fingerprint prefix); `publicKey` is a 33-byte
|
|
6
|
+
* compressed public key as hex. Exactly one of the two.
|
|
7
|
+
*/
|
|
8
|
+
export interface GenesisSpecVerificationMethod {
|
|
9
|
+
key?: string;
|
|
10
|
+
publicKey?: string;
|
|
11
|
+
relationships?: string[];
|
|
12
|
+
fragment?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* One beacon of a genesis spec file. `key` or `publicKey` derives the beacon
|
|
16
|
+
* address from a key; `address` uses a Bitcoin address as given. At most one
|
|
17
|
+
* of the three; the api requires one.
|
|
18
|
+
*/
|
|
19
|
+
export interface GenesisSpecBeacon {
|
|
20
|
+
type: string;
|
|
21
|
+
key?: string;
|
|
22
|
+
publicKey?: string;
|
|
23
|
+
addressType?: string;
|
|
24
|
+
address?: string;
|
|
25
|
+
fragment?: string;
|
|
26
|
+
}
|
|
27
|
+
/** One other service of a genesis spec file. */
|
|
28
|
+
export interface GenesisSpecService {
|
|
29
|
+
id?: string;
|
|
30
|
+
type: string;
|
|
31
|
+
serviceEndpoint: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The genesis spec file that `btcr2 genesis build --spec <path>` reads, and
|
|
35
|
+
* that the wizard collects. The network comes from `-n` or the configuration,
|
|
36
|
+
* not from the file.
|
|
37
|
+
*/
|
|
38
|
+
export interface GenesisSpecFile {
|
|
39
|
+
verificationMethods: GenesisSpecVerificationMethod[];
|
|
40
|
+
beacons?: GenesisSpecBeacon[];
|
|
41
|
+
services?: GenesisSpecService[];
|
|
42
|
+
}
|
|
43
|
+
/** Resolves a keystore key reference to the 33-byte public key. */
|
|
44
|
+
export type ResolvePublicKey = (ref: string) => Uint8Array;
|
|
45
|
+
/**
|
|
46
|
+
* Checks the shape of a parsed genesis spec file. The values (relationship
|
|
47
|
+
* names, beacon types, addresses) are checked by the api when it builds the
|
|
48
|
+
* document; this function checks only what the api cannot see: that each
|
|
49
|
+
* verification method names exactly one key source, and that each beacon
|
|
50
|
+
* names at most one.
|
|
51
|
+
* @param value The parsed JSON value.
|
|
52
|
+
* @param source The file path, for the error data.
|
|
53
|
+
* @returns The spec.
|
|
54
|
+
* @throws {CLIError} If the shape is not valid.
|
|
55
|
+
*/
|
|
56
|
+
export declare function parseGenesisSpec(value: unknown, source: string): GenesisSpecFile;
|
|
57
|
+
/**
|
|
58
|
+
* Converts a genesis spec file to the api spec: resolves each keystore
|
|
59
|
+
* reference to its public key, parses each hex public key, and passes the
|
|
60
|
+
* other values through for the api to check.
|
|
61
|
+
* @param spec The spec file.
|
|
62
|
+
* @param network The network of the beacon addresses.
|
|
63
|
+
* @param resolvePublicKey Resolves a keystore reference to the public key.
|
|
64
|
+
* @returns The api spec.
|
|
65
|
+
* @throws {CLIError} If a hex public key is not hex.
|
|
66
|
+
*/
|
|
67
|
+
export declare function toApiSpec(spec: GenesisSpecFile, network: NetworkOption, resolvePublicKey: ResolvePublicKey): GenesisDocumentSpec;
|
|
68
|
+
/** Parses a hex public key. The length and the curve check belong to the api. */
|
|
69
|
+
export declare function parseHexPublicKey(hex: string, label: string): Uint8Array;
|
|
70
|
+
//# sourceMappingURL=genesis-spec.d.ts.map
|