@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.
- 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 +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interface.d.ts +77 -47
- package/dist/types/interface.d.ts.map +1 -1
- package/dist/types/kms.d.ts +82 -70
- package/dist/types/kms.d.ts.map +1 -1
- package/dist/types/store.d.ts +15 -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
|
@@ -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
|
-
*
|
|
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
|
|
18
|
-
* @param id The key
|
|
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
|
|
24
|
-
* @param
|
|
25
|
-
* @
|
|
26
|
-
* @
|
|
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
|
-
*
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @
|
|
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
|
-
*
|
|
45
|
-
* @returns
|
|
68
|
+
* List all key identifiers.
|
|
69
|
+
* @returns Array of key identifiers.
|
|
46
70
|
*/
|
|
47
71
|
listKeys(): KeyIdentifier[];
|
|
48
72
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param
|
|
51
|
-
* @returns
|
|
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
|
-
*
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
58
|
-
* @
|
|
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
|
-
*
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
65
|
-
* @param
|
|
66
|
-
* @
|
|
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
|
-
*
|
|
71
|
-
* @param
|
|
72
|
-
* @returns
|
|
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
|
-
*
|
|
77
|
-
* @
|
|
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
|
|
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,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,mCAAmC;AACnC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,4DAA4D;IAC5D,EAAE,CAAC,EAAE,aAAa,CAAC;IACnB,oEAAoE;IACpE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF,oCAAoC;AACpC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,6EAA6E;IAC7E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,aAAa,CAAC;IAErC;;;;OAIG;IACH,YAAY,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAAC;IAEtC;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,aAAa,CAAC;IAE9E;;;;;OAKG;IACH,SAAS,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAElE;;;OAGG;IACH,QAAQ,IAAI,aAAa,EAAE,CAAC;IAE5B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,EAAE,aAAa,GAAG,QAAQ,CAAC;IAE3C;;;;;;;OAOG;IACH,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,cAAc,CAAC;IAE7E;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,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"}
|
package/dist/types/kms.d.ts
CHANGED
|
@@ -1,106 +1,118 @@
|
|
|
1
1
|
import { Bytes, HashBytes, KeyBytes, SignatureBytes } from '@did-btcr2/common';
|
|
2
2
|
import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
|
-
import { KeyIdentifier, 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
|
-
*
|
|
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 declare class Kms implements KeyManager {
|
|
11
17
|
#private;
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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,
|
|
24
|
+
constructor(store?: KeyValueStore<KeyIdentifier, KeyEntry>);
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param
|
|
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
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
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
|
-
*
|
|
47
|
+
* Sign data using the specified key.
|
|
48
|
+
*
|
|
56
49
|
* @param {Bytes} data The data to sign.
|
|
57
|
-
* @param {KeyIdentifier} [id]
|
|
58
|
-
* @
|
|
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
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @param {SignatureBytes} signature The signature to verify.
|
|
65
|
-
* @param {
|
|
66
|
-
* @
|
|
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
|
-
*
|
|
68
|
+
* Import a key pair into the KMS.
|
|
69
|
+
*
|
|
71
70
|
* @param {SchnorrKeyPair} keyPair The key pair to import.
|
|
72
|
-
* @param {
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
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
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @
|
|
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
|
-
|
|
84
|
+
removeKey(id: KeyIdentifier, options?: {
|
|
85
|
+
force?: boolean;
|
|
86
|
+
}): void;
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
88
|
+
* List all key identifiers in the KMS.
|
|
89
|
+
*
|
|
90
|
+
* @returns {KeyIdentifier[]} Array of key identifiers.
|
|
90
91
|
*/
|
|
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;
|
|
92
100
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* @param {
|
|
96
|
-
* @returns {
|
|
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
|
-
|
|
106
|
+
generateKey(options?: GenerateKeyOptions): KeyIdentifier;
|
|
99
107
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @
|
|
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
|
-
|
|
117
|
+
exportKey(id: KeyIdentifier): SchnorrKeyPair;
|
|
106
118
|
}
|
package/dist/types/kms.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../src/kms.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
package/dist/types/store.d.ts
CHANGED
|
@@ -1,123 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-btcr2/kms",
|
|
3
|
-
"version": "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/
|
|
60
|
-
"@did-btcr2/
|
|
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