@did-btcr2/kms 0.2.0 → 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.
@@ -1,80 +1,110 @@
1
1
  import { Bytes, HashBytes, KeyBytes, SignatureBytes } from '@did-btcr2/common';
2
2
  import { SchnorrKeyPair } from '@did-btcr2/keypair';
3
+ /** Opaque key identifier string. */
3
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
+ };
4
37
  /**
5
- * The interface for the Kms class.
38
+ * Interface for key management operations.
6
39
  * @interface KeyManager
7
- * @type {KeyManager}
8
40
  */
9
41
  export interface KeyManager {
10
- /**
11
- * The ID of the active key.
12
- * @readonly
13
- * @type {KeyIdentifier}
14
- */
42
+ /** The ID of the active key. */
15
43
  readonly activeKeyId?: KeyIdentifier;
16
44
  /**
17
- * Set the active key id.
18
- * @param id The key id to set as active.
45
+ * Set the active key.
46
+ * @param id The key identifier to set as active.
47
+ * @throws {KeyManagerError} If the key is not found.
19
48
  */
20
49
  setActiveKey(id: KeyIdentifier): void;
21
50
  /**
22
- * Import a key pair.
23
- * @param {SchnorrKeyPair} keyPair The secret key to import.
24
- * @param {{ id?: KeyIdentifier, setActive?: boolean }} options The options for importing the key pair.
25
- * @param {KeyIdentifier} [options.id] The ID of the key to import (optional).
26
- * @param {boolean} [options.setActive] Whether to set the key as active (optional, default: false).
27
- * @returns {KeyIdentifier} A promise that resolves to the key identifier of the imported key.
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.
28
56
  */
29
- importKey(keyPair: SchnorrKeyPair, options: {
30
- id?: KeyIdentifier;
31
- setActive?: boolean;
32
- }): KeyIdentifier;
57
+ importKey(keyPair: SchnorrKeyPair, options?: ImportKeyOptions): KeyIdentifier;
33
58
  /**
34
- * Removes a key from the key store.
35
- * @param {KeyIdentifier} id The key identifier of the key to remove.
36
- * @param {{ force?: boolean }} options The options for removing the key.
37
- * @param {boolean} [options.force] Whether to force the removal of the key.
38
- * @returns {void} A promise that resolves when the key is removed.
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.
39
63
  */
40
- removeKey(id: KeyIdentifier, options: {
64
+ removeKey(id: KeyIdentifier, options?: {
41
65
  force?: boolean;
42
66
  }): void;
43
67
  /**
44
- * Lists all key identifiers in the key store.
45
- * @returns {KeyIdentifier[]} An array of key identifiers.
68
+ * List all key identifiers.
69
+ * @returns Array of key identifiers.
46
70
  */
47
71
  listKeys(): KeyIdentifier[];
48
72
  /**
49
- * Gets the public key associated with the ID or active key.
50
- * @param {KeyIdentifier} [id] The ID of the key to get the public key for.
51
- * @returns {KeyBytes} A promise resolving to the public key bytes.
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.
52
77
  */
53
78
  getPublicKey(id?: KeyIdentifier): KeyBytes;
54
79
  /**
55
- * Signs the given data using the key associated with the key ID.
56
- * @param {Bytes} data The data to sign.
57
- * @param {KeyIdentifier} [id] The ID of the key to sign the data with.
58
- * @returns {SignatureBytes} A promise resolving to the signature of the data.
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.
59
86
  */
60
- sign(data: Bytes, id?: KeyIdentifier): SignatureBytes;
87
+ sign(data: Bytes, id?: KeyIdentifier, options?: SignOptions): SignatureBytes;
61
88
  /**
62
- * Verifies a signature using the key associated with the key ID.
63
- * @param {KeyIdentifier} id The ID of the key to verify the signature with.
64
- * @param {SignatureBytes} signature The signature to verify.
65
- * @param {Hex} data The data to verify the signature with.
66
- * @returns {boolean} A promise resolving to a boolean indicating the verification result.
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.
67
96
  */
68
- verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier): boolean;
97
+ verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier, options?: SignOptions): boolean;
69
98
  /**
70
- * Computes the hash of the given data.
71
- * @param {Uint8Array} data The data to hash.
72
- * @returns {HashBytes} The hash of the data.
99
+ * Compute a SHA-256 hash of the given data.
100
+ * @param data The data to hash.
101
+ * @returns The hash bytes.
73
102
  */
74
103
  digest(data: Uint8Array): HashBytes;
75
104
  /**
76
- * Generates a new key pair and stores it in the key store.
77
- * @returns {KeyIdentifier} The identifier of the newly generated key.
105
+ * Generate a new key pair and store it.
106
+ * @param options Generation options.
107
+ * @returns The key identifier of the generated key.
78
108
  */
79
- generateKey(): KeyIdentifier;
109
+ generateKey(options?: GenerateKeyOptions): KeyIdentifier;
80
110
  }
@@ -1 +1 @@
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,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,aAAa,CAAA;IAEpC;;;OAGG;IACH,YAAY,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAEtC;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE;QAAE,EAAE,CAAC,EAAE,aAAa,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,aAAa,CAAC;IAExG;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAEjE;;;OAGG;IACH,QAAQ,IAAI,aAAa,EAAE,CAAC;IAE5B;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,EAAE,aAAa,GAAG,QAAQ,CAAC;IAE3C;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,cAAc,CAAC;IAEtD;;;;;;OAMG;IACH,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eyIdentifier, KeyManager } from './interface.js';
3
+ import { GenerateKeyOptions, ImportKeyOptions, KeyEntry, KeyIdentifier, KeyManager, SignOptions } from './interface.js';
4
4
  import { KeyValueStore } from './store.js';
5
5
  /**
6
- * Class for managing cryptographic keys for the BTCR2 DID method.
7
- * @class Kms
8
- * @type {Kms}
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 declare class Kms implements KeyManager {
11
17
  #private;
12
18
  /**
13
- * Creates an instance of KeyManager.
14
- * @param {KeyValueStore<KeyIdentifier, KeyBytes>} store An optional property to specify a custom
15
- * `KeyValueStore` instance for key management. If not provided, {@link KeyManager} uses a default `MemoryStore`
16
- * instance. This store is responsible for managing cryptographic keys, allowing them to be retrieved, stored, and
17
- * managed during cryptographic operations.
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.
18
23
  */
19
- constructor(store?: KeyValueStore<KeyIdentifier, KeyBytes>);
24
+ constructor(store?: KeyValueStore<KeyIdentifier, KeyEntry>);
20
25
  /**
21
- * Gets the ID of the active key.
22
- * @returns {KeyIdentifier | undefined} The ID of the active key.
26
+ * Get the active key identifier.
27
+ *
28
+ * @returns {KeyIdentifier | undefined} The active key identifier, or undefined if none is set.
23
29
  */
24
30
  get activeKeyId(): KeyIdentifier | undefined;
25
31
  /**
26
- * Removes a key from the key store.
27
- * @param {KeyIdentifier} id The key identifier of the key to remove.
28
- * @param {{ force?: boolean }} options The options for removing the key.
29
- * @param {boolean} [options.force] Whether to force the removal of the key.
30
- * @returns {void} A promise that resolves when the key is removed.
31
- * @throws {KeyManagerError} If attempting to remove the active key without force.
32
- */
33
- removeKey(id: KeyIdentifier, options?: {
34
- force?: boolean;
35
- }): void;
36
- /**
37
- * Lists all key identifiers in the key store.
38
- * @returns {Promise<KeyIdentifier[]>} A promise that resolves to an array of key identifiers.
39
- */
40
- listKeys(): KeyIdentifier[];
41
- /**
42
- * Sets the active key to the key associated with the given ID.
43
- * @param {KeyIdentifier} id The ID of the key to set as active.
44
- * @returns {Promise<void>} A promise that resolves when the active key is set.
32
+ * Set the active key.
33
+ *
34
+ * @param id The key identifier to set as active.
45
35
  * @throws {KeyManagerError} If the key is not found.
46
36
  */
47
37
  setActiveKey(id: KeyIdentifier): void;
48
38
  /**
49
- * Gets the public key associated with the given ID or the active key if no ID is provided.
50
- * @param {KeyIdentifier} [id] The ID of the key to get the public key for.
51
- * @returns {Promise<KeyBytes>} A promise resolving to the public key bytes.
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.
52
44
  */
53
45
  getPublicKey(id?: KeyIdentifier): KeyBytes;
54
46
  /**
55
- * Signs the given data using the key associated with the key ID.
47
+ * Sign data using the specified key.
48
+ *
56
49
  * @param {Bytes} data The data to sign.
57
- * @param {KeyIdentifier} [id] The ID of the key to sign the data with.
58
- * @returns {Promise<SignatureBytes>} A promise resolving to the signature of the data.
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.
59
54
  */
60
- sign(data: Bytes, id?: KeyIdentifier): SignatureBytes;
55
+ sign(data: Bytes, id?: KeyIdentifier, options?: SignOptions): SignatureBytes;
61
56
  /**
62
- * Verifies a signature using the key associated with the key ID.
63
- * @param {KeyIdentifier} id The ID of the key to verify the signature with.
64
- * @param {SignatureBytes} signature The signature to verify.
65
- * @param {Hex} data The data to verify the signature with.
66
- * @returns {Promise<boolean>} A promise resolving to a boolean indicating the verification result.
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.
67
65
  */
68
- verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier): boolean;
66
+ verify(signature: SignatureBytes, data: Bytes, id?: KeyIdentifier, options?: SignOptions): boolean;
69
67
  /**
70
- * Imports a key pair into the key store.
68
+ * Import a key pair into the KMS.
69
+ *
71
70
  * @param {SchnorrKeyPair} keyPair The key pair to import.
72
- * @param {{ id?: KeyIdentifier; setActive?: boolean }} options The options for importing the key pair.
73
- * @param {KeyIdentifier} [options.id] The ID of the key to import (optional).
74
- * @param {boolean} [options.setActive] Whether to set the key as active (optional, default: true).
75
- * @returns {Promise<KeyIdentifier>} A promise resolving to the ID of the imported key.
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.
76
74
  */
77
- importKey(keyPair: SchnorrKeyPair, options?: {
78
- id?: KeyIdentifier;
79
- setActive?: boolean;
80
- }): KeyIdentifier;
75
+ importKey(keyPair: SchnorrKeyPair, options?: ImportKeyOptions): KeyIdentifier;
81
76
  /**
82
- * Computes the hash of the given data.
83
- * @param {Uint8Array} data The data to hash.
84
- * @returns {HashBytes} The hash of the data.
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.
85
83
  */
86
- digest(data: Uint8Array): HashBytes;
84
+ removeKey(id: KeyIdentifier, options?: {
85
+ force?: boolean;
86
+ }): void;
87
87
  /**
88
- * Generates a new key pair and stores it in the key store.
89
- * @returns {KeyIdentifier} The key identifier of the generated key.
88
+ * List all key identifiers in the KMS.
89
+ *
90
+ * @returns {KeyIdentifier[]} Array of key identifiers.
90
91
  */
91
- generateKey(): KeyIdentifier;
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;
92
100
  /**
93
- * Initializes a singleton KeyManager instance.
94
- * @param {SchnorrKeyPair} keyPair The secret key to import.
95
- * @param {string} id The ID to set as the active key.
96
- * @returns {void}
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.
97
105
  */
98
- static initialize(keyPair: SchnorrKeyPair, id: string): Kms;
106
+ generateKey(options?: GenerateKeyOptions): KeyIdentifier;
99
107
  /**
100
- * Retrieves a keypair from the key store using the provided key ID.
101
- * @public
102
- * @param {KeyIdentifier} id The ID of the keypair to retrieve.
103
- * @returns {Promise<SchnorrKeyPair | undefined>} The retrieved keypair, or undefined if not found.
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.
104
116
  */
105
- static getKey(id?: KeyIdentifier): SchnorrKeyPair | undefined;
117
+ exportKey(id: KeyIdentifier): SchnorrKeyPair;
106
118
  }
@@ -1 +1 @@
1
- {"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../src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S,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,123 +1,33 @@
1
1
  /**
2
- * Re-implmentation of a interface for a generic key-value store.
2
+ * Interface for a generic key-value store.
3
3
  */
4
4
  export interface KeyValueStore<K, V> {
5
- /**
6
- * Clears the store, removing all key-value pairs.
7
- *
8
- * @returns {void} when the store has been cleared.
9
- */
5
+ /** Clear all entries. */
10
6
  clear(): void;
11
- /**
12
- * Closes the store, freeing up any resources used. After calling this method, no other operations can be performed on the store.
13
- *
14
- * @returns {void} when the store has been closed.
15
- */
7
+ /** Close the store, freeing resources. */
16
8
  close(): void;
17
- /**
18
- * Deletes a key-value pair from the store.
19
- *
20
- * @param {K} key - The key of the value to delete.
21
- * @returns {boolean | void} True if the element existed and has been removed, or false if the element does not exist.
22
- */
9
+ /** Delete an entry by key. Returns true if the entry existed. */
23
10
  delete(key: K): boolean | void;
24
- /**
25
- * Fetches a value from the store given its key.
26
- *
27
- * @param {K} key - The key of the value to retrieve.
28
- * @returns {V | undefined} The value associated with the key, or `undefined` if no value exists for that key.
29
- */
11
+ /** Get an entry by key. Returns undefined if not found. */
30
12
  get(key: K): V | undefined;
31
- /**
32
- * Sets the value for a key in the store.
33
- *
34
- * @param {K} key - The key under which to store the value.
35
- * @param {V} value - The value to be stored.
36
- * @returns {void} once the value has been set.
37
- */
13
+ /** Check if a key exists in the store. */
14
+ has(key: K): boolean;
15
+ /** Set a value for a key. */
38
16
  set(key: K, value: V): void;
39
- /**
40
- * Fetches the keys and values as a nested array.
41
- *
42
- * @returns {Array<[K, V]>} An array of key-value pair arrays in the store.
43
- */
17
+ /** Get all entries as key-value tuples. */
44
18
  entries(): Array<[K, V]>;
45
19
  }
46
20
  /**
47
- * Re-implementation of a simple in-memory key-value store.
48
- *
49
- * The `MemoryStore` class is an implementation of
50
- * `KeyValueStore` that holds data in memory.
51
- *
52
- * It provides a basic key-value store that works synchronously and keeps all
53
- * data in memory. This can be used for testing, or for handling small amounts
54
- * of data with simple key-value semantics.
55
- *
56
- * Example usage:
57
- *
58
- * ```ts
59
- * const memoryStore = new MemoryStore<string, number>();
60
- * await memoryStore.set("key1", 1);
61
- * const value = await memoryStore.get("key1");
62
- * console.log(value); // 1
63
- * ```
64
- *
65
- * @public
21
+ * In-memory key-value store backed by a Map.
66
22
  */
67
23
  export declare class MemoryStore<K, V> implements KeyValueStore<K, V> {
68
- /**
69
- * A private field that contains the Map used as the key-value store.
70
- */
71
- private store;
72
- /**
73
- * Clears all entries in the key-value store.
74
- *
75
- * @returns {void} returns once the operation is complete.
76
- */
24
+ #private;
77
25
  clear(): void;
78
- /**
79
- * This operation is no-op for `MemoryStore`.
80
- */
81
26
  close(): void;
82
- /**
83
- * Deletes an entry from the key-value store by its key.
84
- *
85
- * @param {K} id - The key of the entry to delete.
86
- * @returns {boolean} a boolean indicating whether the entry was successfully deleted.
87
- */
88
- delete(id: K): boolean;
89
- /**
90
- * Retrieves the value of an entry by its key.
91
- *
92
- * @param {K} id - The key of the entry to retrieve.
93
- * @returns {V | undefined} the value of the entry, or `undefined` if the entry does not exist.
94
- */
95
- get(id: K): V | undefined;
96
- /**
97
- * Checks for the presence of an entry by key.
98
- *
99
- * @param {K} id - The key to check for the existence of.
100
- * @returns {boolean} a boolean indicating whether an element with the specified key exists or not.
101
- */
102
- has(id: K): boolean;
103
- /**
104
- * Retrieves all values in the key-value store.
105
-
106
- * @returns {Array<V>} an array of all values in the store.
107
- */
27
+ delete(key: K): boolean;
28
+ get(key: K): V | undefined;
29
+ has(key: K): boolean;
108
30
  list(): Array<V>;
109
- /**
110
- * Retrieves all entries in the key-value store.
111
- *
112
- * @returns {Array<[K, V]>} an array of key-value pairs in the store.
113
- */
114
31
  entries(): Array<[K, V]>;
115
- /**
116
- * Sets the value of an entry in the key-value store.
117
- *
118
- * @param {K} id - The key of the entry to set.
119
- * @param {V} key - The new value for the entry.
120
- * @returns {void} once operation is complete.
121
- */
122
- set(id: K, key: V): void;
32
+ set(key: K, value: V): void;
123
33
  }
@@ -1 +1 @@
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;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC;IAE/B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAE3B;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAE5B;;;;OAIG;IACH,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,WAAW,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;IAC3D;;OAEG;IACH,OAAO,CAAC,KAAK,CAAwB;IAErC;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,KAAK,IAA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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-btcr2/kms",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Key manager that can be used with the did:btcr2 DID method",
6
6
  "main": "./dist/cjs/index.js",
@@ -56,10 +56,8 @@
56
56
  ],
57
57
  "dependencies": {
58
58
  "@noble/hashes": "^2.0.1",
59
- "@did-btcr2/bitcoin": "0.3.4",
60
- "@did-btcr2/common": "3.1.0",
61
- "@did-btcr2/cryptosuite": "5.0.0",
62
- "@did-btcr2/keypair": "0.9.0"
59
+ "@did-btcr2/common": "5.0.0",
60
+ "@did-btcr2/keypair": "0.10.0"
63
61
  },
64
62
  "devDependencies": {
65
63
  "@eslint/js": "^9.22.0",
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './interface.js';
2
2
  export * from './kms.js';
3
- export * from './signer.js';
4
3
  export * from './store.js';