@did-btcr2/kms 0.1.1 → 0.4.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/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/kms.js +161 -202
- package/dist/cjs/kms.js.map +1 -1
- package/dist/cjs/store.js +13 -77
- package/dist/cjs/store.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/kms.js +161 -202
- package/dist/esm/kms.js.map +1 -1
- package/dist/esm/store.js +13 -77
- package/dist/esm/store.js.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interface.d.ts +77 -47
- package/dist/types/interface.d.ts.map +1 -1
- package/dist/types/kms.d.ts +82 -70
- package/dist/types/kms.d.ts.map +1 -1
- package/dist/types/store.d.ts +15 -105
- package/dist/types/store.d.ts.map +1 -1
- package/package.json +3 -5
- package/src/index.ts +0 -1
- package/src/interface.ts +84 -46
- package/src/kms.ts +185 -237
- package/src/store.ts +24 -113
- package/dist/cjs/signer.js +0 -53
- package/dist/cjs/signer.js.map +0 -1
- package/dist/esm/signer.js +0 -53
- package/dist/esm/signer.js.map +0 -1
- package/dist/types/signer.d.ts +0 -48
- package/dist/types/signer.d.ts.map +0 -1
- package/src/signer.ts +0 -60
package/src/interface.ts
CHANGED
|
@@ -1,86 +1,124 @@
|
|
|
1
1
|
import { Bytes, HashBytes, KeyBytes, SignatureBytes } from '@did-btcr2/common';
|
|
2
2
|
import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
3
|
|
|
4
|
+
/** Opaque key identifier string. */
|
|
4
5
|
export type KeyIdentifier = string;
|
|
5
6
|
|
|
7
|
+
/** Supported signature schemes. */
|
|
8
|
+
export type SigningScheme = 'schnorr' | 'ecdsa';
|
|
9
|
+
|
|
10
|
+
/** Options for sign and verify operations. */
|
|
11
|
+
export type SignOptions = {
|
|
12
|
+
/** Signature scheme. Defaults to 'schnorr'. */
|
|
13
|
+
scheme?: SigningScheme;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Stored key entry with optional secret key and metadata tags. */
|
|
17
|
+
export type KeyEntry = {
|
|
18
|
+
/** Secret key bytes. Undefined for public-key-only (watch-only) entries. */
|
|
19
|
+
secretKey?: KeyBytes;
|
|
20
|
+
/** Compressed secp256k1 public key bytes. Always present. */
|
|
21
|
+
publicKey: KeyBytes;
|
|
22
|
+
/** Arbitrary metadata tags (e.g. derivation path, account, DID). */
|
|
23
|
+
tags?: Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Options for importing a key. */
|
|
27
|
+
export type ImportKeyOptions = {
|
|
28
|
+
/** Custom key identifier. Auto-generated URN if omitted. */
|
|
29
|
+
id?: KeyIdentifier;
|
|
30
|
+
/** Whether to set this key as the active key. Defaults to false. */
|
|
31
|
+
setActive?: boolean;
|
|
32
|
+
/** Metadata tags to associate with the key. */
|
|
33
|
+
tags?: Record<string, string>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Options for generating a key. */
|
|
37
|
+
export type GenerateKeyOptions = {
|
|
38
|
+
/** Whether to set the generated key as the active key. Defaults to false. */
|
|
39
|
+
setActive?: boolean;
|
|
40
|
+
/** Metadata tags to associate with the key. */
|
|
41
|
+
tags?: Record<string, string>;
|
|
42
|
+
};
|
|
43
|
+
|
|
6
44
|
/**
|
|
7
|
-
*
|
|
45
|
+
* Interface for key management operations.
|
|
8
46
|
* @interface KeyManager
|
|
9
|
-
* @type {KeyManager}
|
|
10
47
|
*/
|
|
11
48
|
export interface KeyManager {
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
* @readonly
|
|
15
|
-
* @type {KeyIdentifier}
|
|
16
|
-
*/
|
|
17
|
-
readonly activeKeyId?: KeyIdentifier
|
|
49
|
+
/** The ID of the active key. */
|
|
50
|
+
readonly activeKeyId?: KeyIdentifier;
|
|
18
51
|
|
|
19
52
|
/**
|
|
20
|
-
* Set the active key
|
|
21
|
-
* @param id The key
|
|
53
|
+
* Set the active key.
|
|
54
|
+
* @param id The key identifier to set as active.
|
|
55
|
+
* @throws {KeyManagerError} If the key is not found.
|
|
22
56
|
*/
|
|
23
57
|
setActiveKey(id: KeyIdentifier): void;
|
|
24
58
|
|
|
25
59
|
/**
|
|
26
|
-
* Import a key pair.
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @
|
|
30
|
-
* @
|
|
31
|
-
* @returns {KeyIdentifier} A promise that resolves to the key identifier of the imported key.
|
|
60
|
+
* Import a key pair. May be public-key-only for watch-only entries.
|
|
61
|
+
* @param keyPair The key pair to import.
|
|
62
|
+
* @param options Import options.
|
|
63
|
+
* @returns The key identifier of the imported key.
|
|
64
|
+
* @throws {KeyManagerError} If the key already exists.
|
|
32
65
|
*/
|
|
33
|
-
importKey(keyPair: SchnorrKeyPair, options
|
|
66
|
+
importKey(keyPair: SchnorrKeyPair, options?: ImportKeyOptions): KeyIdentifier;
|
|
34
67
|
|
|
35
68
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @
|
|
40
|
-
* @returns {void} A promise that resolves when the key is removed.
|
|
69
|
+
* Remove a key from the store.
|
|
70
|
+
* @param id The key identifier to remove.
|
|
71
|
+
* @param options Removal options.
|
|
72
|
+
* @throws {KeyManagerError} If removing the active key without force, or key not found.
|
|
41
73
|
*/
|
|
42
|
-
removeKey(id: KeyIdentifier, options
|
|
74
|
+
removeKey(id: KeyIdentifier, options?: { force?: boolean }): void;
|
|
43
75
|
|
|
44
76
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @returns
|
|
77
|
+
* List all key identifiers.
|
|
78
|
+
* @returns Array of key identifiers.
|
|
47
79
|
*/
|
|
48
80
|
listKeys(): KeyIdentifier[];
|
|
49
81
|
|
|
50
82
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @param
|
|
53
|
-
* @returns
|
|
83
|
+
* Get the compressed public key bytes for a key.
|
|
84
|
+
* @param id Key identifier. Uses active key if omitted.
|
|
85
|
+
* @returns Compressed secp256k1 public key bytes.
|
|
86
|
+
* @throws {KeyManagerError} If key not found or no active key set.
|
|
54
87
|
*/
|
|
55
88
|
getPublicKey(id?: KeyIdentifier): KeyBytes;
|
|
56
89
|
|
|
57
90
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @
|
|
91
|
+
* Sign data using the specified key.
|
|
92
|
+
* @param data The data to sign.
|
|
93
|
+
* @param id Key identifier. Uses active key if omitted.
|
|
94
|
+
* @param options Signing options (scheme defaults to 'schnorr').
|
|
95
|
+
* @returns The signature bytes.
|
|
96
|
+
* @throws {KeyManagerError} If key not found, no active key, or key cannot sign.
|
|
62
97
|
*/
|
|
63
|
-
sign(data: Bytes, id?: KeyIdentifier): SignatureBytes;
|
|
98
|
+
sign(data: Bytes, id?: KeyIdentifier, options?: SignOptions): SignatureBytes;
|
|
64
99
|
|
|
65
100
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @
|
|
101
|
+
* Verify a signature using the specified key.
|
|
102
|
+
* @param signature The signature to verify.
|
|
103
|
+
* @param data The data that was signed.
|
|
104
|
+
* @param id Key identifier. Uses active key if omitted.
|
|
105
|
+
* @param options Verification options (scheme defaults to 'schnorr').
|
|
106
|
+
* @returns True if the signature is valid.
|
|
107
|
+
* @throws {KeyManagerError} If key not found or no active key set.
|
|
71
108
|
*/
|
|
72
|
-
verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier): boolean;
|
|
109
|
+
verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier, options?: SignOptions): boolean;
|
|
73
110
|
|
|
74
111
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @returns
|
|
112
|
+
* Compute a SHA-256 hash of the given data.
|
|
113
|
+
* @param data The data to hash.
|
|
114
|
+
* @returns The hash bytes.
|
|
78
115
|
*/
|
|
79
116
|
digest(data: Uint8Array): HashBytes;
|
|
80
117
|
|
|
81
118
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
119
|
+
* Generate a new key pair and store it.
|
|
120
|
+
* @param options Generation options.
|
|
121
|
+
* @returns The key identifier of the generated key.
|
|
84
122
|
*/
|
|
85
|
-
generateKey(): KeyIdentifier;
|
|
86
|
-
}
|
|
123
|
+
generateKey(options?: GenerateKeyOptions): KeyIdentifier;
|
|
124
|
+
}
|