@did-btcr2/kms 0.4.2 → 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/kms.js DELETED
@@ -1,232 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Kms = void 0;
4
- const common_1 = require("@did-btcr2/common");
5
- const keypair_1 = require("@did-btcr2/keypair");
6
- const sha2_js_1 = require("@noble/hashes/sha2.js");
7
- const store_js_1 = require("./store.js");
8
- /**
9
- * Key Management System for the did:btcr2 DID method.
10
- *
11
- * Implements the {@link KeyManager} interface with a pluggable
12
- * {@link KeyValueStore} (defaults to {@link MemoryStore}).
13
- *
14
- * Supports both signing (secret key present) and watch-only
15
- * (public-key-only) key entries, and both Schnorr and ECDSA
16
- * signature schemes.
17
- *
18
- */
19
- class Kms {
20
- #store;
21
- #activeKeyId;
22
- /**
23
- * Create a new KMS instance.
24
- *
25
- * @param {KeyValueStore<KeyIdentifier, KeyEntry>} [store] Optional key-value store.
26
- * Defaults to in-memory store if not provided.
27
- */
28
- constructor(store) {
29
- this.#store = store ?? new store_js_1.MemoryStore();
30
- }
31
- /**
32
- * Get the active key identifier.
33
- *
34
- * @returns {KeyIdentifier | undefined} The active key identifier, or undefined if none is set.
35
- */
36
- get activeKeyId() {
37
- return this.#activeKeyId;
38
- }
39
- /**
40
- * Generate a URN-style key identifier from compressed public key bytes.
41
- * Format: `urn:kms:secp256k1:<fingerprint>` where fingerprint is the
42
- * first 8 bytes of SHA-256(publicKey), hex-encoded.
43
- *
44
- * @param {KeyBytes} publicKeyBytes Compressed secp256k1 public key bytes.
45
- * @returns {KeyIdentifier} The generated key identifier.
46
- */
47
- #generateUrn(publicKeyBytes) {
48
- const hash = (0, sha2_js_1.sha256)(publicKeyBytes);
49
- const fingerprint = Array.from(hash.slice(0, 8))
50
- .map(b => b.toString(16).padStart(2, '0'))
51
- .join('');
52
- return `urn:kms:secp256k1:${fingerprint}`;
53
- }
54
- /**
55
- * Retrieve a key entry or throw if not found / no active key set.
56
- *
57
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
58
- * @returns {KeyEntry} The retrieved key entry.
59
- * @throws {KeyManagerError} If key not found or no active key set.
60
- */
61
- #getEntryOrThrow(id) {
62
- const keyId = id ?? this.#activeKeyId;
63
- if (!keyId) {
64
- throw new common_1.KeyManagerError('No active key set', 'ACTIVE_KEY_NOT_SET');
65
- }
66
- const entry = this.#store.get(keyId);
67
- if (!entry) {
68
- throw new common_1.KeyManagerError(`Key not found: ${keyId}`, 'KEY_NOT_FOUND');
69
- }
70
- return entry;
71
- }
72
- /**
73
- * Set the active key.
74
- *
75
- * @param id The key identifier to set as active.
76
- * @throws {KeyManagerError} If the key is not found.
77
- */
78
- setActiveKey(id) {
79
- this.#getEntryOrThrow(id);
80
- this.#activeKeyId = id;
81
- }
82
- /**
83
- * Get the compressed public key bytes for a key.
84
- *
85
- * @param id Key identifier. Uses active key if omitted.
86
- * @returns Compressed secp256k1 public key bytes.
87
- * @throws {KeyManagerError} If key not found or no active key set.
88
- */
89
- getPublicKey(id) {
90
- return this.#getEntryOrThrow(id).publicKey;
91
- }
92
- /**
93
- * Sign data using the specified key.
94
- *
95
- * @param {Bytes} data The data to sign.
96
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
97
- * @param {SignOptions} [options] Signing options (scheme defaults to 'schnorr').
98
- * @returns {SignatureBytes} The signature bytes.
99
- * @throws {KeyManagerError} If key not found, no active key, or key cannot sign.
100
- */
101
- sign(data, id, options = {}) {
102
- const entry = this.#getEntryOrThrow(id);
103
- if (!entry.secretKey) {
104
- const keyId = id ?? this.#activeKeyId;
105
- throw new common_1.KeyManagerError(`Key is not a signing key: ${keyId}`, 'KEY_NOT_SIGNER');
106
- }
107
- const kp = new keypair_1.SchnorrKeyPair({ secretKey: entry.secretKey });
108
- return kp.secretKey.sign(data, { scheme: options.scheme ?? 'schnorr' });
109
- }
110
- /**
111
- * Verify a signature using the specified key.
112
- *
113
- * @param {SignatureBytes} signature The signature bytes to verify.
114
- * @param {Bytes} data The data that was signed.
115
- * @param {KeyIdentifier} [id] Key identifier. Uses active key if omitted.
116
- * @param {SignOptions} [options] Verification options (scheme defaults to 'schnorr').
117
- * @returns {boolean} True if the signature is valid, false otherwise.
118
- * @throws {KeyManagerError} If key not found or no active key set.
119
- */
120
- verify(signature, data, id, options = {}) {
121
- const entry = this.#getEntryOrThrow(id);
122
- const kp = new keypair_1.SchnorrKeyPair({ publicKey: entry.publicKey });
123
- return kp.publicKey.verify(signature, data, { scheme: options.scheme ?? 'schnorr' });
124
- }
125
- /**
126
- * Import a key pair into the KMS.
127
- *
128
- * @param {SchnorrKeyPair} keyPair The key pair to import.
129
- * @param {ImportKeyOptions} [options] Import options (id, tags, setActive).
130
- * @returns {KeyIdentifier} The identifier of the imported key.
131
- * @throws {KeyManagerError} If a key with the same identifier already exists.
132
- */
133
- importKey(keyPair, options = {}) {
134
- const id = options.id ?? this.#generateUrn(keyPair.publicKey.compressed);
135
- if (this.#store.has(id)) {
136
- throw new common_1.KeyManagerError(`Key already exists: ${id}`, 'KEY_FOUND');
137
- }
138
- // Build key entry — secret key may not be available for watch-only pairs
139
- const entry = {
140
- publicKey: keyPair.publicKey.compressed,
141
- ...(options.tags && { tags: options.tags }),
142
- };
143
- try {
144
- if (keyPair.secretKey) {
145
- entry.secretKey = keyPair.secretKey.bytes;
146
- }
147
- }
148
- catch {
149
- // Public-key-only key pair — secretKey getter throws
150
- }
151
- this.#store.set(id, entry);
152
- if (options.setActive) {
153
- this.#activeKeyId = id;
154
- }
155
- return id;
156
- }
157
- /**
158
- * Remove a key from the KMS.
159
- *
160
- * @param {KeyIdentifier} id The key identifier to remove.
161
- * @param {Object} [options] Removal options.
162
- * @param {boolean} [options.force=false] Force removal of active key.
163
- * @throws {KeyManagerError} If key not found or attempting to remove active key without force.
164
- */
165
- removeKey(id, options = {}) {
166
- if (this.#activeKeyId === id && !options.force) {
167
- throw new common_1.KeyManagerError('Cannot remove active key (use "force": true or switch active key)', 'ACTIVE_KEY_DELETE');
168
- }
169
- if (!this.#store.has(id)) {
170
- throw new common_1.KeyManagerError(`Key not found: ${id}`, 'KEY_NOT_FOUND');
171
- }
172
- this.#store.delete(id);
173
- if (this.#activeKeyId === id) {
174
- this.#activeKeyId = undefined;
175
- }
176
- }
177
- /**
178
- * List all key identifiers in the KMS.
179
- *
180
- * @returns {KeyIdentifier[]} Array of key identifiers.
181
- */
182
- listKeys() {
183
- return this.#store.entries().map(([k]) => k);
184
- }
185
- /**
186
- * Compute the SHA-256 digest of the given data.
187
- *
188
- * @param {Uint8Array} data The data to digest.
189
- * @returns {HashBytes} The SHA-256 hash of the data.
190
- */
191
- digest(data) {
192
- return (0, sha2_js_1.sha256)(data);
193
- }
194
- /**
195
- * Generate a new secp256k1 key pair and store it in the KMS.
196
- *
197
- * @param {GenerateKeyOptions} [options] Generation options (tags, setActive).
198
- * @returns {KeyIdentifier} The identifier of the generated key.
199
- */
200
- generateKey(options = {}) {
201
- const kp = keypair_1.SchnorrKeyPair.generate();
202
- const id = this.#generateUrn(kp.publicKey.compressed);
203
- const entry = {
204
- secretKey: kp.secretKey.bytes,
205
- publicKey: kp.publicKey.compressed,
206
- ...(options.tags && { tags: options.tags }),
207
- };
208
- this.#store.set(id, entry);
209
- if (options.setActive) {
210
- this.#activeKeyId = id;
211
- }
212
- return id;
213
- }
214
- /**
215
- * Export the key pair for a stored key.
216
- *
217
- * Only available on the concrete {@link Kms} class, not on the
218
- * {@link KeyManager} interface. HSM or hardware-backed implementations
219
- * may not support key export.
220
- *
221
- * @param {KeyIdentifier} id The key identifier to export.
222
- * @returns {SchnorrKeyPair} The reconstructed SchnorrKeyPair.
223
- */
224
- exportKey(id) {
225
- const entry = this.#getEntryOrThrow(id);
226
- if (entry.secretKey) {
227
- return new keypair_1.SchnorrKeyPair({ secretKey: entry.secretKey });
228
- }
229
- return new keypair_1.SchnorrKeyPair({ publicKey: entry.publicKey });
230
- }
231
- }
232
- exports.Kms = Kms;
package/dist/cjs/store.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryStore = void 0;
4
- /**
5
- * In-memory key-value store backed by a Map.
6
- */
7
- class MemoryStore {
8
- #store = new Map();
9
- clear() {
10
- this.#store.clear();
11
- }
12
- close() {
13
- /** no-op */
14
- }
15
- delete(key) {
16
- return this.#store.delete(key);
17
- }
18
- get(key) {
19
- return this.#store.get(key);
20
- }
21
- has(key) {
22
- return this.#store.has(key);
23
- }
24
- list() {
25
- return Array.from(this.#store.values());
26
- }
27
- entries() {
28
- return Array.from(this.#store.entries());
29
- }
30
- set(key, value) {
31
- this.#store.set(key, value);
32
- }
33
- }
34
- exports.MemoryStore = MemoryStore;
@@ -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":"AAMA,OAAO,EACL,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAU/C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;;;;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,EAA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AE,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAEtD,MAAM,KAAK,GAAa;YACtB,SAAS,EAAG,EAAE,CAAC,SAAS,CAAC,KAAK;YAC9B,SAAS,EAAG,EAAE,CAAC,SAAS,CAAC,UAAU;YACnC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,OAAO,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 type { Bytes, HashBytes, KeyBytes, SignatureBytes } from '@did-btcr2/common';
2
- import type { 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,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,oCAAoC;AACpC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,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