@did-btcr2/kms 0.2.0 → 0.4.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/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 +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interface.d.ts +78 -47
- package/dist/types/interface.d.ts.map +1 -1
- package/dist/types/kms.d.ts +83 -70
- package/dist/types/kms.d.ts.map +1 -1
- package/dist/types/store.d.ts +16 -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/dist/cjs/index.js
CHANGED
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
package/dist/cjs/kms.js
CHANGED
|
@@ -3,268 +3,227 @@ import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
|
3
3
|
import { sha256 } from '@noble/hashes/sha2.js';
|
|
4
4
|
import { MemoryStore } from './store.js';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
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
|
+
*
|
|
9
15
|
*/
|
|
10
16
|
export class Kms {
|
|
11
|
-
/**
|
|
12
|
-
* Singleton instance of the Kms.
|
|
13
|
-
* @private
|
|
14
|
-
* @type {KeyManager}
|
|
15
|
-
*/
|
|
16
|
-
static #instance;
|
|
17
|
-
/**
|
|
18
|
-
* The `store` is a private variable in `KeyManager`. It is a `KeyValueStore` instance used for
|
|
19
|
-
* storing and managing cryptographic keys. It allows the `KeyManager` class to save,
|
|
20
|
-
* retrieve, and handle keys efficiently within the local Key Management System (KMS) context.
|
|
21
|
-
* This variable can be configured to use different storage backends, like in-memory storage or
|
|
22
|
-
* persistent storage, providing flexibility in key management according to the application's
|
|
23
|
-
* requirements.
|
|
24
|
-
* @private
|
|
25
|
-
* @type {KeyValueStore<KeyIdentifier, KeyBytes>} The key store for managing cryptographic keys.
|
|
26
|
-
*/
|
|
27
17
|
#store;
|
|
28
|
-
/**
|
|
29
|
-
* The `#activeKeyId` property is a string that points to the currently active key.
|
|
30
|
-
* It is used to identify the key that will be used for signing and verifying operations.
|
|
31
|
-
* This property is optional and can be set to a specific key ID when initializing the
|
|
32
|
-
* `KeyManager` instance. If not set, the key manager will use the default key id.
|
|
33
|
-
* @private
|
|
34
|
-
* @type {KeyIdentifier}
|
|
35
|
-
*/
|
|
36
18
|
#activeKeyId;
|
|
37
19
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* managed during cryptographic operations.
|
|
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.
|
|
43
24
|
*/
|
|
44
25
|
constructor(store) {
|
|
45
|
-
// Set the default key store to a MemoryStore instance
|
|
46
26
|
this.#store = store ?? new MemoryStore();
|
|
47
27
|
}
|
|
48
28
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
29
|
+
* Get the active key identifier.
|
|
30
|
+
*
|
|
31
|
+
* @returns {KeyIdentifier | undefined} The active key identifier, or undefined if none is set.
|
|
51
32
|
*/
|
|
52
33
|
get activeKeyId() {
|
|
53
34
|
return this.#activeKeyId;
|
|
54
35
|
}
|
|
55
36
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
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.
|
|
60
57
|
*/
|
|
61
|
-
#
|
|
62
|
-
// Get the key id
|
|
58
|
+
#getEntryOrThrow(id) {
|
|
63
59
|
const keyId = id ?? this.#activeKeyId;
|
|
64
|
-
// Throw an error if no active key is set
|
|
65
60
|
if (!keyId) {
|
|
66
|
-
throw new KeyManagerError('No active key set', '
|
|
61
|
+
throw new KeyManagerError('No active key set', 'ACTIVE_KEY_NOT_SET');
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!_secretKey) {
|
|
63
|
+
const entry = this.#store.get(keyId);
|
|
64
|
+
if (!entry) {
|
|
71
65
|
throw new KeyManagerError(`Key not found: ${keyId}`, 'KEY_NOT_FOUND');
|
|
72
66
|
}
|
|
73
|
-
|
|
74
|
-
const kp = new SchnorrKeyPair({ secretKey: _secretKey });
|
|
75
|
-
// Return the secret key
|
|
76
|
-
return kp;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Checks if a key with the given ID exists in the key store.
|
|
80
|
-
* @param {KeyIdentifier} id The ID of the key to check.
|
|
81
|
-
* @returns {boolean} A promise resolving to a boolean indicating if the key exists.
|
|
82
|
-
*/
|
|
83
|
-
#exists(id) {
|
|
84
|
-
const key = this.#store.get(id);
|
|
85
|
-
return !!key;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Removes a key from the key store.
|
|
89
|
-
* @param {KeyIdentifier} id The key identifier of the key to remove.
|
|
90
|
-
* @param {{ force?: boolean }} options The options for removing the key.
|
|
91
|
-
* @param {boolean} [options.force] Whether to force the removal of the key.
|
|
92
|
-
* @returns {void} A promise that resolves when the key is removed.
|
|
93
|
-
* @throws {KeyManagerError} If attempting to remove the active key without force.
|
|
94
|
-
*/
|
|
95
|
-
removeKey(id, options = {}) {
|
|
96
|
-
// Check if trying to remove the active key without force
|
|
97
|
-
if (this.#activeKeyId === id && !options.force) {
|
|
98
|
-
throw new KeyManagerError('Cannot remove active key (use "force": true or switch active key)', 'ACTIVE_KEY_DELETE');
|
|
99
|
-
}
|
|
100
|
-
// Check if the key exists, if not throw an error
|
|
101
|
-
if (!this.#exists(id)) {
|
|
102
|
-
throw new KeyManagerError(`Key not found: ${id}`, 'KEY_NOT_FOUND');
|
|
103
|
-
}
|
|
104
|
-
// Remove the key from the store
|
|
105
|
-
this.#store.delete(id);
|
|
106
|
-
// Clear the active key if it was the one removed
|
|
107
|
-
if (this.#activeKeyId === id) {
|
|
108
|
-
this.#activeKeyId = undefined;
|
|
109
|
-
}
|
|
67
|
+
return entry;
|
|
110
68
|
}
|
|
111
69
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
listKeys() {
|
|
116
|
-
return this.#store.entries().flatMap(([k, _]) => [k]);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Sets the active key to the key associated with the given ID.
|
|
120
|
-
* @param {KeyIdentifier} id The ID of the key to set as active.
|
|
121
|
-
* @returns {Promise<void>} A promise that resolves when the active key is set.
|
|
70
|
+
* Set the active key.
|
|
71
|
+
*
|
|
72
|
+
* @param id The key identifier to set as active.
|
|
122
73
|
* @throws {KeyManagerError} If the key is not found.
|
|
123
74
|
*/
|
|
124
75
|
setActiveKey(id) {
|
|
125
|
-
|
|
126
|
-
this.#getKeyOrThrow(id);
|
|
127
|
-
// Set the active key ID
|
|
76
|
+
this.#getEntryOrThrow(id);
|
|
128
77
|
this.#activeKeyId = id;
|
|
129
78
|
}
|
|
130
79
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @
|
|
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.
|
|
134
85
|
*/
|
|
135
86
|
getPublicKey(id) {
|
|
136
|
-
|
|
137
|
-
const { publicKey } = this.#getKeyOrThrow(id);
|
|
138
|
-
// Return the public key bytes
|
|
139
|
-
return publicKey.compressed;
|
|
87
|
+
return this.#getEntryOrThrow(id).publicKey;
|
|
140
88
|
}
|
|
141
89
|
/**
|
|
142
|
-
*
|
|
90
|
+
* Sign data using the specified key.
|
|
91
|
+
*
|
|
143
92
|
* @param {Bytes} data The data to sign.
|
|
144
|
-
* @param {KeyIdentifier} [id]
|
|
145
|
-
* @
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (!secretKey) {
|
|
152
|
-
|
|
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');
|
|
153
103
|
}
|
|
154
|
-
|
|
155
|
-
return secretKey.sign(data);
|
|
104
|
+
const kp = new SchnorrKeyPair({ secretKey: entry.secretKey });
|
|
105
|
+
return kp.secretKey.sign(data, { scheme: options.scheme ?? 'schnorr' });
|
|
156
106
|
}
|
|
157
107
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* @param {SignatureBytes} signature The signature to verify.
|
|
161
|
-
* @param {
|
|
162
|
-
* @
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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' });
|
|
169
121
|
}
|
|
170
122
|
/**
|
|
171
|
-
*
|
|
123
|
+
* Import a key pair into the KMS.
|
|
124
|
+
*
|
|
172
125
|
* @param {SchnorrKeyPair} keyPair The key pair to import.
|
|
173
|
-
* @param {
|
|
174
|
-
* @
|
|
175
|
-
* @
|
|
176
|
-
* @returns {Promise<KeyIdentifier>} A promise resolving to the ID of the imported key.
|
|
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.
|
|
177
129
|
*/
|
|
178
130
|
importKey(keyPair, options = {}) {
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
keyPair.publicKey = keyPair.secretKey.computePublicKey();
|
|
182
|
-
}
|
|
183
|
-
// Determine the key ID
|
|
184
|
-
const id = options.id ?? keyPair.publicKey.hex;
|
|
185
|
-
// Check if the key already exists
|
|
186
|
-
if (this.#exists(id)) {
|
|
131
|
+
const id = options.id ?? this.#generateUrn(keyPair.publicKey.compressed);
|
|
132
|
+
if (this.#store.has(id)) {
|
|
187
133
|
throw new KeyManagerError(`Key already exists: ${id}`, 'KEY_FOUND');
|
|
188
134
|
}
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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) {
|
|
195
150
|
this.#activeKeyId = id;
|
|
196
151
|
}
|
|
197
|
-
// Return the key ID
|
|
198
152
|
return id;
|
|
199
153
|
}
|
|
200
154
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
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.
|
|
204
161
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
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
|
+
}
|
|
207
173
|
}
|
|
208
174
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
175
|
+
* List all key identifiers in the KMS.
|
|
176
|
+
*
|
|
177
|
+
* @returns {KeyIdentifier[]} Array of key identifiers.
|
|
211
178
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const kp = SchnorrKeyPair.generate();
|
|
215
|
-
// Store the key pair in the key store
|
|
216
|
-
const id = kp.publicKey.hex;
|
|
217
|
-
this.#store.set(id, kp.secretKey.bytes);
|
|
218
|
-
// Set the active key to the newly generated key
|
|
219
|
-
this.#activeKeyId = id;
|
|
220
|
-
// Return the key ID
|
|
221
|
-
return id;
|
|
179
|
+
listKeys() {
|
|
180
|
+
return this.#store.entries().map(([k]) => k);
|
|
222
181
|
}
|
|
223
182
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* @param {
|
|
227
|
-
* @returns {
|
|
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.
|
|
228
187
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (Kms.#instance) {
|
|
232
|
-
console.warn('WARNING: Kms global instance is already initialized.');
|
|
233
|
-
return Kms.#instance;
|
|
234
|
-
}
|
|
235
|
-
// Check if the keypair is provided
|
|
236
|
-
if (!keyPair) {
|
|
237
|
-
// Log a warning message if not provided
|
|
238
|
-
console.warn('WARNING: secretKey not provided, generating new SchnorrKeyPair ...');
|
|
239
|
-
}
|
|
240
|
-
// Generate a new keypair if not provided
|
|
241
|
-
keyPair ??= SchnorrKeyPair.generate();
|
|
242
|
-
// Initialize the singleton key manager with the keypair
|
|
243
|
-
Kms.#instance = new Kms();
|
|
244
|
-
// Import the keypair into the key store
|
|
245
|
-
Kms.#instance.importKey(keyPair, { setActive: true, id });
|
|
246
|
-
// Set the active key URI7
|
|
247
|
-
Kms.#instance.#activeKeyId = id;
|
|
248
|
-
// Log the active key ID
|
|
249
|
-
console.info(`Kms initialized with Active Key ID: ${Kms.#instance.#activeKeyId}`);
|
|
250
|
-
// Return the singleton instance
|
|
251
|
-
return Kms.#instance;
|
|
188
|
+
digest(data) {
|
|
189
|
+
return sha256(data);
|
|
252
190
|
}
|
|
253
191
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* @param {
|
|
257
|
-
* @returns {
|
|
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.
|
|
258
196
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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 });
|
|
263
225
|
}
|
|
264
|
-
|
|
265
|
-
id ??= Kms.#instance.activeKeyId;
|
|
266
|
-
// Instantiate a new Kms with the default key store
|
|
267
|
-
return Kms.#instance.#getKeyOrThrow(id);
|
|
226
|
+
return new SchnorrKeyPair({ publicKey: entry.publicKey });
|
|
268
227
|
}
|
|
269
228
|
}
|
|
270
229
|
//# sourceMappingURL=kms.js.map
|
package/dist/cjs/kms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kms.js","sourceRoot":"","sources":["../../src/kms.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,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,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/cjs/store.js
CHANGED
|
@@ -1,95 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* The `MemoryStore` class is an implementation of
|
|
5
|
-
* `KeyValueStore` that holds data in memory.
|
|
6
|
-
*
|
|
7
|
-
* It provides a basic key-value store that works synchronously and keeps all
|
|
8
|
-
* data in memory. This can be used for testing, or for handling small amounts
|
|
9
|
-
* of data with simple key-value semantics.
|
|
10
|
-
*
|
|
11
|
-
* Example usage:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* const memoryStore = new MemoryStore<string, number>();
|
|
15
|
-
* await memoryStore.set("key1", 1);
|
|
16
|
-
* const value = await memoryStore.get("key1");
|
|
17
|
-
* console.log(value); // 1
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @public
|
|
2
|
+
* In-memory key-value store backed by a Map.
|
|
21
3
|
*/
|
|
22
4
|
export class MemoryStore {
|
|
23
|
-
|
|
24
|
-
* A private field that contains the Map used as the key-value store.
|
|
25
|
-
*/
|
|
26
|
-
store = new Map();
|
|
27
|
-
/**
|
|
28
|
-
* Clears all entries in the key-value store.
|
|
29
|
-
*
|
|
30
|
-
* @returns {void} returns once the operation is complete.
|
|
31
|
-
*/
|
|
5
|
+
#store = new Map();
|
|
32
6
|
clear() {
|
|
33
|
-
this
|
|
7
|
+
this.#store.clear();
|
|
34
8
|
}
|
|
35
|
-
/**
|
|
36
|
-
* This operation is no-op for `MemoryStore`.
|
|
37
|
-
*/
|
|
38
9
|
close() {
|
|
39
10
|
/** no-op */
|
|
40
11
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
* @param {K} id - The key of the entry to delete.
|
|
45
|
-
* @returns {boolean} a boolean indicating whether the entry was successfully deleted.
|
|
46
|
-
*/
|
|
47
|
-
delete(id) {
|
|
48
|
-
return this.store.delete(id);
|
|
12
|
+
delete(key) {
|
|
13
|
+
return this.#store.delete(key);
|
|
49
14
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
* @param {K} id - The key of the entry to retrieve.
|
|
54
|
-
* @returns {V | undefined} the value of the entry, or `undefined` if the entry does not exist.
|
|
55
|
-
*/
|
|
56
|
-
get(id) {
|
|
57
|
-
return this.store.get(id);
|
|
15
|
+
get(key) {
|
|
16
|
+
return this.#store.get(key);
|
|
58
17
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
* @param {K} id - The key to check for the existence of.
|
|
63
|
-
* @returns {boolean} a boolean indicating whether an element with the specified key exists or not.
|
|
64
|
-
*/
|
|
65
|
-
has(id) {
|
|
66
|
-
return this.store.has(id);
|
|
18
|
+
has(key) {
|
|
19
|
+
return this.#store.has(key);
|
|
67
20
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Retrieves all values in the key-value store.
|
|
70
|
-
|
|
71
|
-
* @returns {Array<V>} an array of all values in the store.
|
|
72
|
-
*/
|
|
73
21
|
list() {
|
|
74
|
-
return Array.from(this
|
|
22
|
+
return Array.from(this.#store.values());
|
|
75
23
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Retrieves all entries in the key-value store.
|
|
78
|
-
*
|
|
79
|
-
* @returns {Array<[K, V]>} an array of key-value pairs in the store.
|
|
80
|
-
*/
|
|
81
24
|
entries() {
|
|
82
|
-
return Array.from(this
|
|
25
|
+
return Array.from(this.#store.entries());
|
|
83
26
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
* @param {K} id - The key of the entry to set.
|
|
88
|
-
* @param {V} key - The new value for the entry.
|
|
89
|
-
* @returns {void} once operation is complete.
|
|
90
|
-
*/
|
|
91
|
-
set(id, key) {
|
|
92
|
-
this.store.set(id, key);
|
|
27
|
+
set(key, value) {
|
|
28
|
+
this.#store.set(key, value);
|
|
93
29
|
}
|
|
94
30
|
}
|
|
95
31
|
//# sourceMappingURL=store.js.map
|
package/dist/cjs/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|