@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/src/store.ts CHANGED
@@ -1,153 +1,64 @@
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
7
 
12
- /**
13
- * Closes the store, freeing up any resources used. After calling this method, no other operations can be performed on the store.
14
- *
15
- * @returns {void} when the store has been closed.
16
- */
8
+ /** Close the store, freeing resources. */
17
9
  close(): void;
18
10
 
19
- /**
20
- * Deletes a key-value pair from the store.
21
- *
22
- * @param {K} key - The key of the value to delete.
23
- * @returns {boolean | void} True if the element existed and has been removed, or false if the element does not exist.
24
- */
11
+ /** Delete an entry by key. Returns true if the entry existed. */
25
12
  delete(key: K): boolean | void;
26
13
 
27
- /**
28
- * Fetches a value from the store given its key.
29
- *
30
- * @param {K} key - The key of the value to retrieve.
31
- * @returns {V | undefined} The value associated with the key, or `undefined` if no value exists for that key.
32
- */
14
+ /** Get an entry by key. Returns undefined if not found. */
33
15
  get(key: K): V | undefined;
34
16
 
35
- /**
36
- * Sets the value for a key in the store.
37
- *
38
- * @param {K} key - The key under which to store the value.
39
- * @param {V} value - The value to be stored.
40
- * @returns {void} once the value has been set.
41
- */
17
+ /** Check if a key exists in the store. */
18
+ has(key: K): boolean;
19
+
20
+ /** Set a value for a key. */
42
21
  set(key: K, value: V): void;
43
22
 
44
- /**
45
- * Fetches the keys and values as a nested array.
46
- *
47
- * @returns {Array<[K, V]>} An array of key-value pair arrays in the store.
48
- */
23
+ /** Get all entries as key-value tuples. */
49
24
  entries(): Array<[K, V]>;
50
25
  }
51
26
 
52
27
  /**
53
- * Re-implementation of a simple in-memory key-value store.
54
- *
55
- * The `MemoryStore` class is an implementation of
56
- * `KeyValueStore` that holds data in memory.
57
- *
58
- * It provides a basic key-value store that works synchronously and keeps all
59
- * data in memory. This can be used for testing, or for handling small amounts
60
- * of data with simple key-value semantics.
61
- *
62
- * Example usage:
63
- *
64
- * ```ts
65
- * const memoryStore = new MemoryStore<string, number>();
66
- * await memoryStore.set("key1", 1);
67
- * const value = await memoryStore.get("key1");
68
- * console.log(value); // 1
69
- * ```
70
- *
71
- * @public
28
+ * In-memory key-value store backed by a Map.
72
29
  */
73
30
  export class MemoryStore<K, V> implements KeyValueStore<K, V> {
74
- /**
75
- * A private field that contains the Map used as the key-value store.
76
- */
77
- private store: Map<K, V> = new Map();
31
+ #store: Map<K, V> = new Map();
78
32
 
79
- /**
80
- * Clears all entries in the key-value store.
81
- *
82
- * @returns {void} returns once the operation is complete.
83
- */
84
33
  clear(): void {
85
- this.store.clear();
34
+ this.#store.clear();
86
35
  }
87
36
 
88
- /**
89
- * This operation is no-op for `MemoryStore`.
90
- */
91
37
  close(): void {
92
38
  /** no-op */
93
39
  }
94
40
 
95
- /**
96
- * Deletes an entry from the key-value store by its key.
97
- *
98
- * @param {K} id - The key of the entry to delete.
99
- * @returns {boolean} a boolean indicating whether the entry was successfully deleted.
100
- */
101
- delete(id: K): boolean {
102
- return this.store.delete(id);
41
+ delete(key: K): boolean {
42
+ return this.#store.delete(key);
103
43
  }
104
44
 
105
- /**
106
- * Retrieves the value of an entry by its key.
107
- *
108
- * @param {K} id - The key of the entry to retrieve.
109
- * @returns {V | undefined} the value of the entry, or `undefined` if the entry does not exist.
110
- */
111
- get(id: K): V | undefined {
112
- return this.store.get(id);
45
+ get(key: K): V | undefined {
46
+ return this.#store.get(key);
113
47
  }
114
48
 
115
- /**
116
- * Checks for the presence of an entry by key.
117
- *
118
- * @param {K} id - The key to check for the existence of.
119
- * @returns {boolean} a boolean indicating whether an element with the specified key exists or not.
120
- */
121
- has(id: K): boolean {
122
- return this.store.has(id);
49
+ has(key: K): boolean {
50
+ return this.#store.has(key);
123
51
  }
124
52
 
125
- /**
126
- * Retrieves all values in the key-value store.
127
-
128
- * @returns {Array<V>} an array of all values in the store.
129
- */
130
53
  list(): Array<V> {
131
- return Array.from(this.store.values());
54
+ return Array.from(this.#store.values());
132
55
  }
133
56
 
134
- /**
135
- * Retrieves all entries in the key-value store.
136
- *
137
- * @returns {Array<[K, V]>} an array of key-value pairs in the store.
138
- */
139
57
  entries(): Array<[K, V]> {
140
- return Array.from(this.store.entries());
58
+ return Array.from(this.#store.entries());
141
59
  }
142
60
 
143
- /**
144
- * Sets the value of an entry in the key-value store.
145
- *
146
- * @param {K} id - The key of the entry to set.
147
- * @param {V} key - The new value for the entry.
148
- * @returns {void} once operation is complete.
149
- */
150
- set(id: K, key: V): void {
151
- this.store.set(id, key);
61
+ set(key: K, value: V): void {
62
+ this.#store.set(key, value);
152
63
  }
153
- }
64
+ }
@@ -1,53 +0,0 @@
1
- /**
2
- * Class representing a signer for cryptographic operations.
3
- * Remains for backwards compatibility. Plan to migrate to Kms.
4
- * @class Signer
5
- * @type {Signer}
6
- */
7
- export class Signer {
8
- /**
9
- * The key pair used for signing.
10
- * @type {SchnorrKeyPair}
11
- */
12
- keyPair;
13
- /**
14
- * The network associated with the signer.
15
- * @type {keyof AvailableNetworks}
16
- */
17
- network;
18
- /**
19
- * Creates an instance of Signer.
20
- * @param {{ keyPair: SchnorrKeyPair; network: keyof AvailableNetworks; }} params The parameters for the signer.
21
- * @param {SchnorrKeyPair} params.keyPair The key pair used for signing.
22
- * @param {keyof AvailableNetworks} params.network The network associated with the signer.
23
- */
24
- constructor(params) {
25
- this.keyPair = params.keyPair;
26
- this.network = params.network;
27
- }
28
- /**
29
- * Gets the public key bytes.
30
- * @returns {KeyBytes} The public key bytes.
31
- */
32
- get publicKey() {
33
- return this.keyPair.publicKey.compressed;
34
- }
35
- /**
36
- * Signs the given hash using ECDSA.
37
- * @param {Bytes} hash The hash to sign.
38
- * @returns {SignatureBytes} The signature of the hash.
39
- */
40
- sign(hash) {
41
- return this.keyPair.secretKey.sign(hash, { scheme: 'ecdsa' });
42
- }
43
- ;
44
- /**
45
- * Signs the given hash using Schnorr signature.
46
- * @param {Bytes} hash The hash to sign.
47
- * @returns {SignatureBytes} The Schnorr signature of the hash.
48
- */
49
- signSchnorr(hash) {
50
- return this.keyPair.secretKey.sign(hash);
51
- }
52
- }
53
- //# sourceMappingURL=signer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,OAAO,MAAM;IACjB;;;OAGG;IACH,OAAO,CAAiB;IAExB;;;OAGG;IACH,OAAO,CAA0B;IAEjC;;;;;OAKG;IACH,YAAY,MAAsE;QAChF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,IAAW;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAChE,CAAC;IAAA,CAAC;IAEF;;;;OAIG;IACH,WAAW,CAAC,IAAW;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
@@ -1,53 +0,0 @@
1
- /**
2
- * Class representing a signer for cryptographic operations.
3
- * Remains for backwards compatibility. Plan to migrate to Kms.
4
- * @class Signer
5
- * @type {Signer}
6
- */
7
- export class Signer {
8
- /**
9
- * The key pair used for signing.
10
- * @type {SchnorrKeyPair}
11
- */
12
- keyPair;
13
- /**
14
- * The network associated with the signer.
15
- * @type {keyof AvailableNetworks}
16
- */
17
- network;
18
- /**
19
- * Creates an instance of Signer.
20
- * @param {{ keyPair: SchnorrKeyPair; network: keyof AvailableNetworks; }} params The parameters for the signer.
21
- * @param {SchnorrKeyPair} params.keyPair The key pair used for signing.
22
- * @param {keyof AvailableNetworks} params.network The network associated with the signer.
23
- */
24
- constructor(params) {
25
- this.keyPair = params.keyPair;
26
- this.network = params.network;
27
- }
28
- /**
29
- * Gets the public key bytes.
30
- * @returns {KeyBytes} The public key bytes.
31
- */
32
- get publicKey() {
33
- return this.keyPair.publicKey.compressed;
34
- }
35
- /**
36
- * Signs the given hash using ECDSA.
37
- * @param {Bytes} hash The hash to sign.
38
- * @returns {SignatureBytes} The signature of the hash.
39
- */
40
- sign(hash) {
41
- return this.keyPair.secretKey.sign(hash, { scheme: 'ecdsa' });
42
- }
43
- ;
44
- /**
45
- * Signs the given hash using Schnorr signature.
46
- * @param {Bytes} hash The hash to sign.
47
- * @returns {SignatureBytes} The Schnorr signature of the hash.
48
- */
49
- signSchnorr(hash) {
50
- return this.keyPair.secretKey.sign(hash);
51
- }
52
- }
53
- //# sourceMappingURL=signer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,OAAO,MAAM;IACjB;;;OAGG;IACH,OAAO,CAAiB;IAExB;;;OAGG;IACH,OAAO,CAA0B;IAEjC;;;;;OAKG;IACH,YAAY,MAAsE;QAChF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,IAAW;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAChE,CAAC;IAAA,CAAC;IAEF;;;;OAIG;IACH,WAAW,CAAC,IAAW;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
@@ -1,48 +0,0 @@
1
- import { AvailableNetworks } from '@did-btcr2/bitcoin';
2
- import { KeyBytes, Bytes, SignatureBytes } from '@did-btcr2/common';
3
- import { SchnorrKeyPair } from '@did-btcr2/keypair';
4
- /**
5
- * Class representing a signer for cryptographic operations.
6
- * Remains for backwards compatibility. Plan to migrate to Kms.
7
- * @class Signer
8
- * @type {Signer}
9
- */
10
- export declare class Signer {
11
- /**
12
- * The key pair used for signing.
13
- * @type {SchnorrKeyPair}
14
- */
15
- keyPair: SchnorrKeyPair;
16
- /**
17
- * The network associated with the signer.
18
- * @type {keyof AvailableNetworks}
19
- */
20
- network: keyof AvailableNetworks;
21
- /**
22
- * Creates an instance of Signer.
23
- * @param {{ keyPair: SchnorrKeyPair; network: keyof AvailableNetworks; }} params The parameters for the signer.
24
- * @param {SchnorrKeyPair} params.keyPair The key pair used for signing.
25
- * @param {keyof AvailableNetworks} params.network The network associated with the signer.
26
- */
27
- constructor(params: {
28
- keyPair: SchnorrKeyPair;
29
- network: keyof AvailableNetworks;
30
- });
31
- /**
32
- * Gets the public key bytes.
33
- * @returns {KeyBytes} The public key bytes.
34
- */
35
- get publicKey(): KeyBytes;
36
- /**
37
- * Signs the given hash using ECDSA.
38
- * @param {Bytes} hash The hash to sign.
39
- * @returns {SignatureBytes} The signature of the hash.
40
- */
41
- sign(hash: Bytes): SignatureBytes;
42
- /**
43
- * Signs the given hash using Schnorr signature.
44
- * @param {Bytes} hash The hash to sign.
45
- * @returns {SignatureBytes} The Schnorr signature of the hash.
46
- */
47
- signSchnorr(hash: Bytes): SignatureBytes;
48
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAG,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;GAKG;AACH,qBAAa,MAAM;IACjB;;;OAGG;IACH,OAAO,EAAE,cAAc,CAAC;IAExB;;;OAGG;IACH,OAAO,EAAE,MAAM,iBAAiB,CAAC;IAEjC;;;;;OAKG;gBACS,MAAM,EAAE;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,MAAM,iBAAiB,CAAC;KAAE;IAKlF;;;OAGG;IACH,IAAI,SAAS,IAAI,QAAQ,CAExB;IAED;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,cAAc;IAIjC;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,cAAc;CAGzC"}
package/src/signer.ts DELETED
@@ -1,60 +0,0 @@
1
- import { AvailableNetworks } from '@did-btcr2/bitcoin';
2
- import { KeyBytes, Bytes, SignatureBytes } from '@did-btcr2/common';
3
- import { SchnorrKeyPair } from '@did-btcr2/keypair';
4
-
5
- /**
6
- * Class representing a signer for cryptographic operations.
7
- * Remains for backwards compatibility. Plan to migrate to Kms.
8
- * @class Signer
9
- * @type {Signer}
10
- */
11
- export class Signer {
12
- /**
13
- * The key pair used for signing.
14
- * @type {SchnorrKeyPair}
15
- */
16
- keyPair: SchnorrKeyPair;
17
-
18
- /**
19
- * The network associated with the signer.
20
- * @type {keyof AvailableNetworks}
21
- */
22
- network: keyof AvailableNetworks;
23
-
24
- /**
25
- * Creates an instance of Signer.
26
- * @param {{ keyPair: SchnorrKeyPair; network: keyof AvailableNetworks; }} params The parameters for the signer.
27
- * @param {SchnorrKeyPair} params.keyPair The key pair used for signing.
28
- * @param {keyof AvailableNetworks} params.network The network associated with the signer.
29
- */
30
- constructor(params: { keyPair: SchnorrKeyPair; network: keyof AvailableNetworks; }) {
31
- this.keyPair = params.keyPair;
32
- this.network = params.network;
33
- }
34
-
35
- /**
36
- * Gets the public key bytes.
37
- * @returns {KeyBytes} The public key bytes.
38
- */
39
- get publicKey(): KeyBytes {
40
- return this.keyPair.publicKey.compressed;
41
- }
42
-
43
- /**
44
- * Signs the given hash using ECDSA.
45
- * @param {Bytes} hash The hash to sign.
46
- * @returns {SignatureBytes} The signature of the hash.
47
- */
48
- sign(hash: Bytes): SignatureBytes {
49
- return this.keyPair.secretKey.sign(hash, { scheme: 'ecdsa' });
50
- };
51
-
52
- /**
53
- * Signs the given hash using Schnorr signature.
54
- * @param {Bytes} hash The hash to sign.
55
- * @returns {SignatureBytes} The Schnorr signature of the hash.
56
- */
57
- signSchnorr(hash: Bytes): SignatureBytes {
58
- return this.keyPair.secretKey.sign(hash);
59
- }
60
- }