@did-btcr2/kms 0.4.1 → 0.5.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/store.js DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * In-memory key-value store backed by a Map.
3
- */
4
- export class MemoryStore {
5
- #store = new Map();
6
- clear() {
7
- this.#store.clear();
8
- }
9
- close() {
10
- /** no-op */
11
- }
12
- delete(key) {
13
- return this.#store.delete(key);
14
- }
15
- get(key) {
16
- return this.#store.get(key);
17
- }
18
- has(key) {
19
- return this.#store.has(key);
20
- }
21
- list() {
22
- return Array.from(this.#store.values());
23
- }
24
- entries() {
25
- return Array.from(this.#store.entries());
26
- }
27
- set(key, value) {
28
- this.#store.set(key, value);
29
- }
30
- }
31
- //# sourceMappingURL=store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB,MAAM,GAAc,IAAI,GAAG,EAAE,CAAC;IAE9B,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,KAAK;QACH,YAAY;IACd,CAAC;IAED,MAAM,CAAC,GAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":""}
package/dist/esm/kms.js DELETED
@@ -1,229 +0,0 @@
1
- import { KeyManagerError } from '@did-btcr2/common';
2
- import { SchnorrKeyPair } from '@did-btcr2/keypair';
3
- import { sha256 } from '@noble/hashes/sha2.js';
4
- import { MemoryStore } from './store.js';
5
- /**
6
- * Key Management System for the did:btcr2 DID method.
7
- *
8
- * Implements the {@link KeyManager} interface with a pluggable
9
- * {@link KeyValueStore} (defaults to {@link MemoryStore}).
10
- *
11
- * Supports both signing (secret key present) and watch-only
12
- * (public-key-only) key entries, and both Schnorr and ECDSA
13
- * signature schemes.
14
- *
15
- */
16
- export class Kms {
17
- #store;
18
- #activeKeyId;
19
- /**
20
- * Create a new KMS instance.
21
- *
22
- * @param {KeyValueStore<KeyIdentifier, KeyEntry>} [store] Optional key-value store.
23
- * Defaults to in-memory store if not provided.
24
- */
25
- constructor(store) {
26
- this.#store = store ?? new MemoryStore();
27
- }
28
- /**
29
- * Get the active key identifier.
30
- *
31
- * @returns {KeyIdentifier | undefined} The active key identifier, or undefined if none is set.
32
- */
33
- get activeKeyId() {
34
- return this.#activeKeyId;
35
- }
36
- /**
37
- * Generate a URN-style key identifier from compressed public key bytes.
38
- * Format: `urn:kms:secp256k1:<fingerprint>` where fingerprint is the
39
- * first 8 bytes of SHA-256(publicKey), hex-encoded.
40
- *
41
- * @param {KeyBytes} publicKeyBytes Compressed secp256k1 public key bytes.
42
- * @returns {KeyIdentifier} The generated key identifier.
43
- */
44
- #generateUrn(publicKeyBytes) {
45
- const hash = sha256(publicKeyBytes);
46
- const fingerprint = Array.from(hash.slice(0, 8))
47
- .map(b => b.toString(16).padStart(2, '0'))
48
- .join('');
49
- return `urn:kms:secp256k1:${fingerprint}`;
50
- }
51
- /**
52
- * Retrieve a key entry or throw if not found / no active key set.
53
- *
54
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
55
- * @returns {KeyEntry} The retrieved key entry.
56
- * @throws {KeyManagerError} If key not found or no active key set.
57
- */
58
- #getEntryOrThrow(id) {
59
- const keyId = id ?? this.#activeKeyId;
60
- if (!keyId) {
61
- throw new KeyManagerError('No active key set', 'ACTIVE_KEY_NOT_SET');
62
- }
63
- const entry = this.#store.get(keyId);
64
- if (!entry) {
65
- throw new KeyManagerError(`Key not found: ${keyId}`, 'KEY_NOT_FOUND');
66
- }
67
- return entry;
68
- }
69
- /**
70
- * Set the active key.
71
- *
72
- * @param id The key identifier to set as active.
73
- * @throws {KeyManagerError} If the key is not found.
74
- */
75
- setActiveKey(id) {
76
- this.#getEntryOrThrow(id);
77
- this.#activeKeyId = id;
78
- }
79
- /**
80
- * Get the compressed public key bytes for a key.
81
- *
82
- * @param id Key identifier. Uses active key if omitted.
83
- * @returns Compressed secp256k1 public key bytes.
84
- * @throws {KeyManagerError} If key not found or no active key set.
85
- */
86
- getPublicKey(id) {
87
- return this.#getEntryOrThrow(id).publicKey;
88
- }
89
- /**
90
- * Sign data using the specified key.
91
- *
92
- * @param {Bytes} data The data to sign.
93
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
94
- * @param {SignOptions} [options] Signing options (scheme defaults to 'schnorr').
95
- * @returns {SignatureBytes} The signature bytes.
96
- * @throws {KeyManagerError} If key not found, no active key, or key cannot sign.
97
- */
98
- sign(data, id, options = {}) {
99
- const entry = this.#getEntryOrThrow(id);
100
- if (!entry.secretKey) {
101
- const keyId = id ?? this.#activeKeyId;
102
- throw new KeyManagerError(`Key is not a signing key: ${keyId}`, 'KEY_NOT_SIGNER');
103
- }
104
- const kp = new SchnorrKeyPair({ secretKey: entry.secretKey });
105
- return kp.secretKey.sign(data, { scheme: options.scheme ?? 'schnorr' });
106
- }
107
- /**
108
- * Verify a signature using the specified key.
109
- *
110
- * @param {SignatureBytes} signature The signature bytes to verify.
111
- * @param {Bytes} data The data that was signed.
112
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
113
- * @param {SignOptions} [options] Verification options (scheme defaults to 'schnorr').
114
- * @returns {boolean} True if the signature is valid, false otherwise.
115
- * @throws {KeyManagerError} If key not found or no active key set.
116
- */
117
- verify(signature, data, id, options = {}) {
118
- const entry = this.#getEntryOrThrow(id);
119
- const kp = new SchnorrKeyPair({ publicKey: entry.publicKey });
120
- return kp.publicKey.verify(signature, data, { scheme: options.scheme ?? 'schnorr' });
121
- }
122
- /**
123
- * Import a key pair into the KMS.
124
- *
125
- * @param {SchnorrKeyPair} keyPair The key pair to import.
126
- * @param {ImportKeyOptions} [options] Import options (id, tags, setActive).
127
- * @returns {KeyIdentifier} The identifier of the imported key.
128
- * @throws {KeyManagerError} If a key with the same identifier already exists.
129
- */
130
- importKey(keyPair, options = {}) {
131
- const id = options.id ?? this.#generateUrn(keyPair.publicKey.compressed);
132
- if (this.#store.has(id)) {
133
- throw new KeyManagerError(`Key already exists: ${id}`, 'KEY_FOUND');
134
- }
135
- // Build key entry — secret key may not be available for watch-only pairs
136
- const entry = {
137
- publicKey: keyPair.publicKey.compressed,
138
- ...(options.tags && { tags: options.tags }),
139
- };
140
- try {
141
- if (keyPair.secretKey) {
142
- entry.secretKey = keyPair.secretKey.bytes;
143
- }
144
- }
145
- catch {
146
- // Public-key-only key pair — secretKey getter throws
147
- }
148
- this.#store.set(id, entry);
149
- if (options.setActive) {
150
- this.#activeKeyId = id;
151
- }
152
- return id;
153
- }
154
- /**
155
- * Remove a key from the KMS.
156
- *
157
- * @param {KeyIdentifier} id The key identifier to remove.
158
- * @param {Object} [options] Removal options.
159
- * @param {boolean} [options.force=false] Force removal of active key.
160
- * @throws {KeyManagerError} If key not found or attempting to remove active key without force.
161
- */
162
- removeKey(id, options = {}) {
163
- if (this.#activeKeyId === id && !options.force) {
164
- throw new KeyManagerError('Cannot remove active key (use "force": true or switch active key)', 'ACTIVE_KEY_DELETE');
165
- }
166
- if (!this.#store.has(id)) {
167
- throw new KeyManagerError(`Key not found: ${id}`, 'KEY_NOT_FOUND');
168
- }
169
- this.#store.delete(id);
170
- if (this.#activeKeyId === id) {
171
- this.#activeKeyId = undefined;
172
- }
173
- }
174
- /**
175
- * List all key identifiers in the KMS.
176
- *
177
- * @returns {KeyIdentifier[]} Array of key identifiers.
178
- */
179
- listKeys() {
180
- return this.#store.entries().map(([k]) => k);
181
- }
182
- /**
183
- * Compute the SHA-256 digest of the given data.
184
- *
185
- * @param {Uint8Array} data The data to digest.
186
- * @returns {HashBytes} The SHA-256 hash of the data.
187
- */
188
- digest(data) {
189
- return sha256(data);
190
- }
191
- /**
192
- * Generate a new secp256k1 key pair and store it in the KMS.
193
- *
194
- * @param {GenerateKeyOptions} [options] Generation options (tags, setActive).
195
- * @returns {KeyIdentifier} The identifier of the generated key.
196
- */
197
- generateKey(options = {}) {
198
- const kp = SchnorrKeyPair.generate();
199
- const id = this.#generateUrn(kp.publicKey.compressed);
200
- const entry = {
201
- secretKey: kp.secretKey.bytes,
202
- publicKey: kp.publicKey.compressed,
203
- ...(options.tags && { tags: options.tags }),
204
- };
205
- this.#store.set(id, entry);
206
- if (options.setActive) {
207
- this.#activeKeyId = id;
208
- }
209
- return id;
210
- }
211
- /**
212
- * Export the key pair for a stored key.
213
- *
214
- * Only available on the concrete {@link Kms} class, not on the
215
- * {@link KeyManager} interface. HSM or hardware-backed implementations
216
- * may not support key export.
217
- *
218
- * @param {KeyIdentifier} id The key identifier to export.
219
- * @returns {SchnorrKeyPair} The reconstructed SchnorrKeyPair.
220
- */
221
- exportKey(id) {
222
- const entry = this.#getEntryOrThrow(id);
223
- if (entry.secretKey) {
224
- return new SchnorrKeyPair({ secretKey: entry.secretKey });
225
- }
226
- return new SchnorrKeyPair({ publicKey: entry.publicKey });
227
- }
228
- }
229
- //# sourceMappingURL=kms.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kms.js","sourceRoot":"","sources":["../../src/kms.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAS/C,OAAO,EAAiB,WAAW,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,GAAG;IACd,MAAM,CAAyC;IAC/C,YAAY,CAAiB;IAE7B;;;;;OAKG;IACH,YAAY,KAA8C;QACxD,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,IAAI,WAAW,EAA2B,CAAC;IACpE,CAAC;IAED;;;;OAIG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,CAAC,cAAwB;QACnC,MAAM,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QACpC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aAC7C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;aACzC,IAAI,CAAC,EAAE,CAAC,CAAC;QACZ,OAAO,qBAAqB,WAAW,EAAE,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAkB;QACjC,MAAM,KAAK,GAAG,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,KAAK,EAAE,CAA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CAAC,IAAI,EAAE,CAAC;SAC5C,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAE3B,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACzB,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAiB;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,IAAI,cAAc,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,IAAI,cAAc,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF"}
package/dist/esm/store.js DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * In-memory key-value store backed by a Map.
3
- */
4
- export class MemoryStore {
5
- #store = new Map();
6
- clear() {
7
- this.#store.clear();
8
- }
9
- close() {
10
- /** no-op */
11
- }
12
- delete(key) {
13
- return this.#store.delete(key);
14
- }
15
- get(key) {
16
- return this.#store.get(key);
17
- }
18
- has(key) {
19
- return this.#store.has(key);
20
- }
21
- list() {
22
- return Array.from(this.#store.values());
23
- }
24
- entries() {
25
- return Array.from(this.#store.entries());
26
- }
27
- set(key, value) {
28
- this.#store.set(key, value);
29
- }
30
- }
31
- //# sourceMappingURL=store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB,MAAM,GAAc,IAAI,GAAG,EAAE,CAAC;IAE9B,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,KAAK;QACH,YAAY;IACd,CAAC;IAED,MAAM,CAAC,GAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF"}
@@ -1,111 +0,0 @@
1
- import { Bytes, HashBytes, KeyBytes, SignatureBytes } from '@did-btcr2/common';
2
- import { SchnorrKeyPair } from '@did-btcr2/keypair';
3
- /** Opaque key identifier string. */
4
- export type KeyIdentifier = string;
5
- /** Supported signature schemes. */
6
- export type SigningScheme = 'schnorr' | 'ecdsa';
7
- /** Options for sign and verify operations. */
8
- export type SignOptions = {
9
- /** Signature scheme. Defaults to 'schnorr'. */
10
- scheme?: SigningScheme;
11
- };
12
- /** Stored key entry with optional secret key and metadata tags. */
13
- export type KeyEntry = {
14
- /** Secret key bytes. Undefined for public-key-only (watch-only) entries. */
15
- secretKey?: KeyBytes;
16
- /** Compressed secp256k1 public key bytes. Always present. */
17
- publicKey: KeyBytes;
18
- /** Arbitrary metadata tags (e.g. derivation path, account, DID). */
19
- tags?: Record<string, string>;
20
- };
21
- /** Options for importing a key. */
22
- export type ImportKeyOptions = {
23
- /** Custom key identifier. Auto-generated URN if omitted. */
24
- id?: KeyIdentifier;
25
- /** Whether to set this key as the active key. Defaults to false. */
26
- setActive?: boolean;
27
- /** Metadata tags to associate with the key. */
28
- tags?: Record<string, string>;
29
- };
30
- /** Options for generating a key. */
31
- export type GenerateKeyOptions = {
32
- /** Whether to set the generated key as the active key. Defaults to false. */
33
- setActive?: boolean;
34
- /** Metadata tags to associate with the key. */
35
- tags?: Record<string, string>;
36
- };
37
- /**
38
- * Interface for key management operations.
39
- * @interface KeyManager
40
- */
41
- export interface KeyManager {
42
- /** The ID of the active key. */
43
- readonly activeKeyId?: KeyIdentifier;
44
- /**
45
- * Set the active key.
46
- * @param id The key identifier to set as active.
47
- * @throws {KeyManagerError} If the key is not found.
48
- */
49
- setActiveKey(id: KeyIdentifier): void;
50
- /**
51
- * Import a key pair. May be public-key-only for watch-only entries.
52
- * @param keyPair The key pair to import.
53
- * @param options Import options.
54
- * @returns The key identifier of the imported key.
55
- * @throws {KeyManagerError} If the key already exists.
56
- */
57
- importKey(keyPair: SchnorrKeyPair, options?: ImportKeyOptions): KeyIdentifier;
58
- /**
59
- * Remove a key from the store.
60
- * @param id The key identifier to remove.
61
- * @param options Removal options.
62
- * @throws {KeyManagerError} If removing the active key without force, or key not found.
63
- */
64
- removeKey(id: KeyIdentifier, options?: {
65
- force?: boolean;
66
- }): void;
67
- /**
68
- * List all key identifiers.
69
- * @returns Array of key identifiers.
70
- */
71
- listKeys(): KeyIdentifier[];
72
- /**
73
- * Get the compressed public key bytes for a key.
74
- * @param id Key identifier. Uses active key if omitted.
75
- * @returns Compressed secp256k1 public key bytes.
76
- * @throws {KeyManagerError} If key not found or no active key set.
77
- */
78
- getPublicKey(id?: KeyIdentifier): KeyBytes;
79
- /**
80
- * Sign data using the specified key.
81
- * @param data The data to sign.
82
- * @param id Key identifier. Uses active key if omitted.
83
- * @param options Signing options (scheme defaults to 'schnorr').
84
- * @returns The signature bytes.
85
- * @throws {KeyManagerError} If key not found, no active key, or key cannot sign.
86
- */
87
- sign(data: Bytes, id?: KeyIdentifier, options?: SignOptions): SignatureBytes;
88
- /**
89
- * Verify a signature using the specified key.
90
- * @param signature The signature to verify.
91
- * @param data The data that was signed.
92
- * @param id Key identifier. Uses active key if omitted.
93
- * @param options Verification options (scheme defaults to 'schnorr').
94
- * @returns True if the signature is valid.
95
- * @throws {KeyManagerError} If key not found or no active key set.
96
- */
97
- verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier, options?: SignOptions): boolean;
98
- /**
99
- * Compute a SHA-256 hash of the given data.
100
- * @param data The data to hash.
101
- * @returns The hash bytes.
102
- */
103
- digest(data: Uint8Array): HashBytes;
104
- /**
105
- * Generate a new key pair and store it.
106
- * @param options Generation options.
107
- * @returns The key identifier of the generated key.
108
- */
109
- generateKey(options?: GenerateKeyOptions): KeyIdentifier;
110
- }
111
- //# sourceMappingURL=interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,oCAAoC;AACpC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,OAAO,CAAC;AAEhD,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG;IACxB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,QAAQ,GAAG;IACrB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,6DAA6D;IAC7D,SAAS,EAAE,QAAQ,CAAC;IACpB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC,MA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AK,EAAE,EAAE,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IAEnG;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAEpC;;;;OAIG;IACH,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAC;CAC1D"}
@@ -1,119 +0,0 @@
1
- import { Bytes, HashBytes, KeyBytes, SignatureBytes } from '@did-btcr2/common';
2
- import { SchnorrKeyPair } from '@did-btcr2/keypair';
3
- import { GenerateKeyOptions, ImportKeyOptions, KeyEntry, KeyIdentifier, KeyManager, SignOptions } from './interface.js';
4
- import { KeyValueStore } from './store.js';
5
- /**
6
- * Key Management System for the did:btcr2 DID method.
7
- *
8
- * Implements the {@link KeyManager} interface with a pluggable
9
- * {@link KeyValueStore} (defaults to {@link MemoryStore}).
10
- *
11
- * Supports both signing (secret key present) and watch-only
12
- * (public-key-only) key entries, and both Schnorr and ECDSA
13
- * signature schemes.
14
- *
15
- */
16
- export declare class Kms implements KeyManager {
17
- #private;
18
- /**
19
- * Create a new KMS instance.
20
- *
21
- * @param {KeyValueStore<KeyIdentifier, KeyEntry>} [store] Optional key-value store.
22
- * Defaults to in-memory store if not provided.
23
- */
24
- constructor(store?: KeyValueStore<KeyIdentifier, KeyEntry>);
25
- /**
26
- * Get the active key identifier.
27
- *
28
- * @returns {KeyIdentifier | undefined} The active key identifier, or undefined if none is set.
29
- */
30
- get activeKeyId(): KeyIdentifier | undefined;
31
- /**
32
- * Set the active key.
33
- *
34
- * @param id The key identifier to set as active.
35
- * @throws {KeyManagerError} If the key is not found.
36
- */
37
- setActiveKey(id: KeyIdentifier): void;
38
- /**
39
- * Get the compressed public key bytes for a key.
40
- *
41
- * @param id Key identifier. Uses active key if omitted.
42
- * @returns Compressed secp256k1 public key bytes.
43
- * @throws {KeyManagerError} If key not found or no active key set.
44
- */
45
- getPublicKey(id?: KeyIdentifier): KeyBytes;
46
- /**
47
- * Sign data using the specified key.
48
- *
49
- * @param {Bytes} data The data to sign.
50
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
51
- * @param {SignOptions} [options] Signing options (scheme defaults to 'schnorr').
52
- * @returns {SignatureBytes} The signature bytes.
53
- * @throws {KeyManagerError} If key not found, no active key, or key cannot sign.
54
- */
55
- sign(data: Bytes, id?: KeyIdentifier, options?: SignOptions): SignatureBytes;
56
- /**
57
- * Verify a signature using the specified key.
58
- *
59
- * @param {SignatureBytes} signature The signature bytes to verify.
60
- * @param {Bytes} data The data that was signed.
61
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
62
- * @param {SignOptions} [options] Verification options (scheme defaults to 'schnorr').
63
- * @returns {boolean} True if the signature is valid, false otherwise.
64
- * @throws {KeyManagerError} If key not found or no active key set.
65
- */
66
- verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier, options?: SignOptions): boolean;
67
- /**
68
- * Import a key pair into the KMS.
69
- *
70
- * @param {SchnorrKeyPair} keyPair The key pair to import.
71
- * @param {ImportKeyOptions} [options] Import options (id, tags, setActive).
72
- * @returns {KeyIdentifier} The identifier of the imported key.
73
- * @throws {KeyManagerError} If a key with the same identifier already exists.
74
- */
75
- importKey(keyPair: SchnorrKeyPair, options?: ImportKeyOptions): KeyIdentifier;
76
- /**
77
- * Remove a key from the KMS.
78
- *
79
- * @param {KeyIdentifier} id The key identifier to remove.
80
- * @param {Object} [options] Removal options.
81
- * @param {boolean} [options.force=false] Force removal of active key.
82
- * @throws {KeyManagerError} If key not found or attempting to remove active key without force.
83
- */
84
- removeKey(id: KeyIdentifier, options?: {
85
- force?: boolean;
86
- }): void;
87
- /**
88
- * List all key identifiers in the KMS.
89
- *
90
- * @returns {KeyIdentifier[]} Array of key identifiers.
91
- */
92
- listKeys(): KeyIdentifier[];
93
- /**
94
- * Compute the SHA-256 digest of the given data.
95
- *
96
- * @param {Uint8Array} data The data to digest.
97
- * @returns {HashBytes} The SHA-256 hash of the data.
98
- */
99
- digest(data: Uint8Array): HashBytes;
100
- /**
101
- * Generate a new secp256k1 key pair and store it in the KMS.
102
- *
103
- * @param {GenerateKeyOptions} [options] Generation options (tags, setActive).
104
- * @returns {KeyIdentifier} The identifier of the generated key.
105
- */
106
- generateKey(options?: GenerateKeyOptions): KeyIdentifier;
107
- /**
108
- * Export the key pair for a stored key.
109
- *
110
- * Only available on the concrete {@link Kms} class, not on the
111
- * {@link KeyManager} interface. HSM or hardware-backed implementations
112
- * may not support key export.
113
- *
114
- * @param {KeyIdentifier} id The key identifier to export.
115
- * @returns {SchnorrKeyPair} The reconstructed SchnorrKeyPair.
116
- */
117
- exportKey(id: KeyIdentifier): SchnorrKeyPair;
118
- }
119
- //# sourceMappingURL=kms.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../src/kms.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,SAAS,EACT,QAAQ,EAER,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,UAAU,EACV,WAAW,EACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAe,MAAM,YAAY,CAAC;AAExD;;;;;;;;;;GAUG;AACH,qBAAa,GAAI,YAAW,UAAU;;IAIpC;;;;;OAKG;gBACS,KAAK,CAAC,EAAE,aAAa,CAAC,aAAa,EAAE,QAAQ,CAAC;IAI1D;;;;OAIG;IACH,IAAI,WAAW,IAAI,aAAa,GAAG,SAAS,CAE3C;IAqCD;;;;;OAKG;IACH,YAAY,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI;IAKrC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,EAAE,aAAa,GAAG,QAAQ;IAI1C;;;;;;;;OAQG;IACH,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,EAAE,OAAO,GAAE,WAAgB,GAAG,cAAc;IAUhF;;;;;;;;;OASG;IACH,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO;IAMtG;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,GAAE,gBAAqB,GAAG,aAAa;IA8BjF;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,IAAI;IAmBrE;;;;OAIG;IACH,QAAQ,IAAI,aAAa,EAAE;IAI3B;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS;IAInC;;;;;OAKG;IACH,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,aAAa;IAmB5D;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,EAAE,aAAa,GAAG,cAAc;CAO7C"}
@@ -1,34 +0,0 @@
1
- /**
2
- * Interface for a generic key-value store.
3
- */
4
- export interface KeyValueStore<K, V> {
5
- /** Clear all entries. */
6
- clear(): void;
7
- /** Close the store, freeing resources. */
8
- close(): void;
9
- /** Delete an entry by key. Returns true if the entry existed. */
10
- delete(key: K): boolean | void;
11
- /** Get an entry by key. Returns undefined if not found. */
12
- get(key: K): V | undefined;
13
- /** Check if a key exists in the store. */
14
- has(key: K): boolean;
15
- /** Set a value for a key. */
16
- set(key: K, value: V): void;
17
- /** Get all entries as key-value tuples. */
18
- entries(): Array<[K, V]>;
19
- }
20
- /**
21
- * In-memory key-value store backed by a Map.
22
- */
23
- export declare class MemoryStore<K, V> implements KeyValueStore<K, V> {
24
- #private;
25
- clear(): void;
26
- close(): void;
27
- delete(key: K): boolean;
28
- get(key: K): V | undefined;
29
- has(key: K): boolean;
30
- list(): Array<V>;
31
- entries(): Array<[K, V]>;
32
- set(key: K, value: V): void;
33
- }
34
- //# sourceMappingURL=store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,CAAC;IACjC,yBAAyB;IACzB,KAAK,IAAI,IAAI,CAAC;IAEd,0CAA0C;IAC1C,KAAK,IAAI,IAAI,CAAC;IAEd,iEAAiE;IACjE,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC;IAE/B,2DAA2D;IAC3D,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAE3B,0CAA0C;IAC1C,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;IAErB,6BAA6B;IAC7B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAE5B,2CAA2C;IAC3C,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;;IAG3D,KAAK,IAAI,IAAI;IAIb,KAAK,IAAI,IAAI;IAIb,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIvB,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAI1B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIpB,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC;IAIhB,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAIxB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;CAG5B"}