@did-btcr2/cli 0.10.3 → 0.11.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/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +889 -43
- package/dist/esm/src/cli.js +30 -12
- package/dist/esm/src/cli.js.map +1 -1
- package/dist/esm/src/commands/completion.js +36 -0
- package/dist/esm/src/commands/completion.js.map +1 -0
- package/dist/esm/src/commands/config.js +69 -0
- package/dist/esm/src/commands/config.js.map +1 -0
- package/dist/esm/src/commands/deactivate.js +21 -8
- package/dist/esm/src/commands/deactivate.js.map +1 -1
- package/dist/esm/src/commands/index.js +4 -0
- package/dist/esm/src/commands/index.js.map +1 -1
- package/dist/esm/src/commands/key.js +175 -0
- package/dist/esm/src/commands/key.js.map +1 -0
- package/dist/esm/src/commands/profile.js +63 -0
- package/dist/esm/src/commands/profile.js.map +1 -0
- package/dist/esm/src/commands/update.js +19 -9
- package/dist/esm/src/commands/update.js.map +1 -1
- package/dist/esm/src/config.js +99 -12
- package/dist/esm/src/config.js.map +1 -1
- package/dist/esm/src/keystore/atomic.js +64 -0
- package/dist/esm/src/keystore/atomic.js.map +1 -0
- package/dist/esm/src/keystore/envelope.js +123 -0
- package/dist/esm/src/keystore/envelope.js.map +1 -0
- package/dist/esm/src/keystore/error.js +16 -0
- package/dist/esm/src/keystore/error.js.map +1 -0
- package/dist/esm/src/keystore/file-backed-key-manager.js +78 -0
- package/dist/esm/src/keystore/file-backed-key-manager.js.map +1 -0
- package/dist/esm/src/keystore/file-key-store.js +184 -0
- package/dist/esm/src/keystore/file-key-store.js.map +1 -0
- package/dist/esm/src/keystore/passphrase.js +87 -0
- package/dist/esm/src/keystore/passphrase.js.map +1 -0
- package/dist/esm/src/keystore/paths.js +20 -0
- package/dist/esm/src/keystore/paths.js.map +1 -0
- package/dist/esm/src/keystore/resolve-key-ref.js +47 -0
- package/dist/esm/src/keystore/resolve-key-ref.js.map +1 -0
- package/dist/types/src/cli.d.ts +6 -2
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/commands/completion.d.ts +5 -0
- package/dist/types/src/commands/completion.d.ts.map +1 -0
- package/dist/types/src/commands/config.d.ts +5 -0
- package/dist/types/src/commands/config.d.ts.map +1 -0
- package/dist/types/src/commands/deactivate.d.ts.map +1 -1
- package/dist/types/src/commands/index.d.ts +4 -0
- package/dist/types/src/commands/index.d.ts.map +1 -1
- package/dist/types/src/commands/key.d.ts +10 -0
- package/dist/types/src/commands/key.d.ts.map +1 -0
- package/dist/types/src/commands/profile.d.ts +5 -0
- package/dist/types/src/commands/profile.d.ts.map +1 -0
- package/dist/types/src/commands/update.d.ts.map +1 -1
- package/dist/types/src/config.d.ts +48 -5
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/keystore/atomic.d.ts +19 -0
- package/dist/types/src/keystore/atomic.d.ts.map +1 -0
- package/dist/types/src/keystore/envelope.d.ts +64 -0
- package/dist/types/src/keystore/envelope.d.ts.map +1 -0
- package/dist/types/src/keystore/error.d.ts +14 -0
- package/dist/types/src/keystore/error.d.ts.map +1 -0
- package/dist/types/src/keystore/file-backed-key-manager.d.ts +41 -0
- package/dist/types/src/keystore/file-backed-key-manager.d.ts.map +1 -0
- package/dist/types/src/keystore/file-key-store.d.ts +52 -0
- package/dist/types/src/keystore/file-key-store.d.ts.map +1 -0
- package/dist/types/src/keystore/passphrase.d.ts +20 -0
- package/dist/types/src/keystore/passphrase.d.ts.map +1 -0
- package/dist/types/src/keystore/paths.d.ts +13 -0
- package/dist/types/src/keystore/paths.d.ts.map +1 -0
- package/dist/types/src/keystore/resolve-key-ref.d.ts +19 -0
- package/dist/types/src/keystore/resolve-key-ref.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +91 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +9 -4
- package/src/cli.ts +36 -11
- package/src/commands/completion.ts +40 -0
- package/src/commands/config.ts +84 -0
- package/src/commands/deactivate.ts +25 -12
- package/src/commands/index.ts +4 -0
- package/src/commands/key.ts +193 -0
- package/src/commands/profile.ts +65 -0
- package/src/commands/update.ts +23 -13
- package/src/config.ts +142 -20
- package/src/keystore/atomic.ts +73 -0
- package/src/keystore/envelope.ts +172 -0
- package/src/keystore/error.ts +16 -0
- package/src/keystore/file-backed-key-manager.ts +99 -0
- package/src/keystore/file-key-store.ts +242 -0
- package/src/keystore/passphrase.ts +99 -0
- package/src/keystore/paths.ts +20 -0
- package/src/keystore/resolve-key-ref.ts +62 -0
- package/src/types.ts +30 -11
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { KeyIdentifier, KeyManager } from '@did-btcr2/key-manager';
|
|
2
|
+
import { CLIError } from '../error.js';
|
|
3
|
+
|
|
4
|
+
/** Extracts the 32-hex fingerprint from a `urn:kms:secp256k1:<hex>` identifier. */
|
|
5
|
+
function fingerprintOf(id: KeyIdentifier): string | undefined {
|
|
6
|
+
return /^urn:kms:secp256k1:([0-9a-f]{32})$/.exec(id)?.[1];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Resolves a user-supplied key reference to a key identifier. Resolution order:
|
|
11
|
+
* 1. No reference: the active key (errors if none is set).
|
|
12
|
+
* 2. Exact URN identifier match.
|
|
13
|
+
* 3. Unique fingerprint-prefix match (against the hex tail of the URN).
|
|
14
|
+
* 4. Unique `name` tag match.
|
|
15
|
+
*
|
|
16
|
+
* Reads only public material (listKeys + getEntry), so resolving a reference
|
|
17
|
+
* never decrypts a secret or prompts for a passphrase.
|
|
18
|
+
*
|
|
19
|
+
* @param kms The key manager to resolve against.
|
|
20
|
+
* @param ref The reference to resolve. When omitted, the active key is used.
|
|
21
|
+
* @returns The resolved key identifier.
|
|
22
|
+
* @throws {CLIError} If no key matches, the reference is ambiguous, or no
|
|
23
|
+
* reference is given and no active key is set.
|
|
24
|
+
*/
|
|
25
|
+
export function resolveKeyRef(kms: KeyManager, ref?: string): KeyIdentifier {
|
|
26
|
+
if (!ref) {
|
|
27
|
+
if (!kms.activeKeyId) {
|
|
28
|
+
throw new CLIError(
|
|
29
|
+
'No key specified and no active key is set. Use --key <ref> or set one with `btcr2 key use <ref>`.',
|
|
30
|
+
'INVALID_ARGUMENT_ERROR',
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return kms.activeKeyId;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ids = kms.listKeys();
|
|
37
|
+
|
|
38
|
+
if (ids.includes(ref)) return ref;
|
|
39
|
+
|
|
40
|
+
const prefix = ref.toLowerCase();
|
|
41
|
+
const byPrefix = ids.filter(id => fingerprintOf(id)?.startsWith(prefix));
|
|
42
|
+
if (byPrefix.length === 1) return byPrefix[0];
|
|
43
|
+
if (byPrefix.length > 1) {
|
|
44
|
+
throw new CLIError(
|
|
45
|
+
`Ambiguous key reference "${ref}" matches ${byPrefix.length} keys by fingerprint.`,
|
|
46
|
+
'KEY_REF_AMBIGUOUS_ERROR',
|
|
47
|
+
{ ref },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const byName = ids.filter(id => kms.getEntry(id).tags?.name === ref);
|
|
52
|
+
if (byName.length === 1) return byName[0];
|
|
53
|
+
if (byName.length > 1) {
|
|
54
|
+
throw new CLIError(
|
|
55
|
+
`Ambiguous key name "${ref}" matches ${byName.length} keys.`,
|
|
56
|
+
'KEY_REF_AMBIGUOUS_ERROR',
|
|
57
|
+
{ ref },
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
throw new CLIError(`No key matches reference "${ref}".`, 'KEY_NOT_FOUND_ERROR', { ref });
|
|
62
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -33,17 +33,36 @@ export type CommandResult =
|
|
|
33
33
|
| { action: 'create'; data: string }
|
|
34
34
|
| { action: 'resolve'; data: DidResolutionResult }
|
|
35
35
|
| { action: 'update'; data: SignedBTCR2Update }
|
|
36
|
-
| { action: 'deactivate'; data: SignedBTCR2Update }
|
|
36
|
+
| { action: 'deactivate'; data: SignedBTCR2Update }
|
|
37
|
+
| { action: 'key-generate'; data: { keyId: string; publicKey: string; active: boolean } }
|
|
38
|
+
| { action: 'key-list'; data: Array<{ keyId: string; fingerprint: string; name?: string; active: boolean }> }
|
|
39
|
+
| { action: 'key-show'; data: { keyId: string; publicKey: string; tags?: Record<string, string> } }
|
|
40
|
+
| { action: 'key-import'; data: { keyId: string; publicKey: string; watchOnly: boolean; active: boolean } }
|
|
41
|
+
| { action: 'key-export'; data: { keyId: string; publicKey?: string; secretWrittenTo?: string } }
|
|
42
|
+
| { action: 'key-delete'; data: { keyId: string; deleted: true } }
|
|
43
|
+
| { action: 'key-use'; data: { keyId: string; active: true } }
|
|
44
|
+
| { action: 'config-init'; data: { path: string } }
|
|
45
|
+
| { action: 'config-get'; data: unknown }
|
|
46
|
+
| { action: 'config-set'; data: { path: string } }
|
|
47
|
+
| { action: 'config-unset'; data: { path: string } }
|
|
48
|
+
| { action: 'config-list'; data: unknown }
|
|
49
|
+
| { action: 'profile-add'; data: { profile: string } }
|
|
50
|
+
| { action: 'profile-use'; data: { profile: string } }
|
|
51
|
+
| { action: 'profile-show'; data: unknown }
|
|
52
|
+
| { action: 'profile-remove'; data: { profile: string } };
|
|
37
53
|
|
|
38
54
|
export interface GlobalOptions {
|
|
39
|
-
output
|
|
40
|
-
verbose
|
|
41
|
-
quiet
|
|
42
|
-
config?
|
|
43
|
-
profile?
|
|
44
|
-
btcRest?
|
|
45
|
-
btcRpcUrl?
|
|
46
|
-
btcRpcUser
|
|
47
|
-
btcRpcPass
|
|
48
|
-
casGateway
|
|
55
|
+
output : OutputFormat;
|
|
56
|
+
verbose : boolean;
|
|
57
|
+
quiet : boolean;
|
|
58
|
+
config? : string;
|
|
59
|
+
profile? : string;
|
|
60
|
+
btcRest? : string;
|
|
61
|
+
btcRpcUrl? : string;
|
|
62
|
+
btcRpcUser? : string;
|
|
63
|
+
btcRpcPass? : string;
|
|
64
|
+
casGateway? : string;
|
|
65
|
+
keystore? : string;
|
|
66
|
+
passphraseFile?: string;
|
|
67
|
+
signingKey? : string;
|
|
49
68
|
}
|