@enbox/agent 0.1.2 → 0.1.4
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/browser.mjs +45 -52
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/crypto-api.js +6 -13
- package/dist/esm/crypto-api.js.map +1 -1
- package/dist/esm/dwn-api.js +80 -78
- package/dist/esm/dwn-api.js.map +1 -1
- package/dist/esm/hd-identity-vault.js +4 -5
- package/dist/esm/hd-identity-vault.js.map +1 -1
- package/dist/esm/identity-api.js +1 -1
- package/dist/esm/identity-api.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/local-key-manager.js +31 -32
- package/dist/esm/local-key-manager.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe-compact.js +1 -2
- package/dist/esm/prototyping/crypto/jose/jwe-compact.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +15 -4
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe.js +1 -1
- package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -1
- package/dist/esm/store-data.js +3 -3
- package/dist/esm/store-data.js.map +1 -1
- package/dist/esm/store-did.js +1 -1
- package/dist/esm/store-did.js.map +1 -1
- package/dist/esm/sync-engine-level.js +49 -11
- package/dist/esm/sync-engine-level.js.map +1 -1
- package/dist/esm/test-harness.js +24 -8
- package/dist/esm/test-harness.js.map +1 -1
- package/dist/esm/types/dwn.js +1 -1
- package/dist/esm/types/dwn.js.map +1 -1
- package/dist/esm/web5-user-agent.js +1 -1
- package/dist/esm/web5-user-agent.js.map +1 -1
- package/dist/types/crypto-api.d.ts +8 -12
- package/dist/types/crypto-api.d.ts.map +1 -1
- package/dist/types/dwn-api.d.ts +10 -10
- package/dist/types/dwn-api.d.ts.map +1 -1
- package/dist/types/hd-identity-vault.d.ts.map +1 -1
- package/dist/types/identity-api.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/local-key-manager.d.ts +15 -18
- package/dist/types/local-key-manager.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts +1 -3
- package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts +1 -3
- package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -1
- package/dist/types/prototyping/crypto/jose/jwe.d.ts +1 -3
- package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -1
- package/dist/types/store-data.d.ts +2 -2
- package/dist/types/store-did.d.ts.map +1 -1
- package/dist/types/sync-engine-level.d.ts +18 -6
- package/dist/types/sync-engine-level.d.ts.map +1 -1
- package/dist/types/test-harness.d.ts.map +1 -1
- package/dist/types/types/agent.d.ts +1 -1
- package/dist/types/types/agent.d.ts.map +1 -1
- package/dist/types/types/dwn.d.ts +2 -2
- package/dist/types/types/dwn.d.ts.map +1 -1
- package/dist/types/types/key-manager.d.ts +15 -22
- package/dist/types/types/key-manager.d.ts.map +1 -1
- package/dist/types/utils-internal.d.ts +1 -1
- package/dist/types/utils-internal.d.ts.map +1 -1
- package/dist/types/web5-user-agent.d.ts +1 -1
- package/dist/types/web5-user-agent.d.ts.map +1 -1
- package/package.json +13 -15
- package/src/crypto-api.ts +24 -20
- package/src/dwn-api.ts +109 -102
- package/src/hd-identity-vault.ts +4 -5
- package/src/identity-api.ts +2 -1
- package/src/index.ts +0 -2
- package/src/local-key-manager.ts +43 -44
- package/src/prototyping/crypto/jose/jwe-compact.ts +3 -7
- package/src/prototyping/crypto/jose/jwe-flattened.ts +20 -9
- package/src/prototyping/crypto/jose/jwe.ts +2 -6
- package/src/store-data.ts +3 -3
- package/src/store-did.ts +1 -1
- package/src/sync-engine-level.ts +59 -16
- package/src/test-harness.ts +23 -8
- package/src/types/agent.ts +1 -1
- package/src/types/dwn.ts +2 -2
- package/src/types/key-manager.ts +31 -22
- package/src/utils-internal.ts +1 -1
- package/src/web5-user-agent.ts +2 -2
- package/dist/browser.js +0 -2213
- package/dist/browser.js.map +0 -7
- package/dist/esm/dwn-registrar.js +0 -120
- package/dist/esm/dwn-registrar.js.map +0 -1
- package/dist/esm/prototyping/clients/dwn-rpc-types.js +0 -2
- package/dist/esm/prototyping/clients/dwn-rpc-types.js.map +0 -1
- package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js +0 -74
- package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js.map +0 -1
- package/dist/esm/prototyping/clients/http-dwn-rpc-client.js +0 -112
- package/dist/esm/prototyping/clients/http-dwn-rpc-client.js.map +0 -1
- package/dist/esm/prototyping/clients/json-rpc-socket.js +0 -167
- package/dist/esm/prototyping/clients/json-rpc-socket.js.map +0 -1
- package/dist/esm/prototyping/clients/json-rpc.js +0 -58
- package/dist/esm/prototyping/clients/json-rpc.js.map +0 -1
- package/dist/esm/prototyping/clients/server-info-types.js +0 -2
- package/dist/esm/prototyping/clients/server-info-types.js.map +0 -1
- package/dist/esm/prototyping/clients/web-socket-clients.js +0 -90
- package/dist/esm/prototyping/clients/web-socket-clients.js.map +0 -1
- package/dist/esm/prototyping/common/object.js +0 -14
- package/dist/esm/prototyping/common/object.js.map +0 -1
- package/dist/esm/prototyping/common/type-utils.js +0 -2
- package/dist/esm/prototyping/common/type-utils.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js +0 -147
- package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/aes-kw.js +0 -136
- package/dist/esm/prototyping/crypto/algorithms/aes-kw.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/ecdsa.js +0 -311
- package/dist/esm/prototyping/crypto/algorithms/ecdsa.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/eddsa.js +0 -268
- package/dist/esm/prototyping/crypto/algorithms/eddsa.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/hkdf.js +0 -38
- package/dist/esm/prototyping/crypto/algorithms/hkdf.js.map +0 -1
- package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js +0 -40
- package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js.map +0 -1
- package/dist/esm/prototyping/crypto/crypto-error.js +0 -41
- package/dist/esm/prototyping/crypto/crypto-error.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/crypto-api.js +0 -2
- package/dist/esm/prototyping/crypto/types/crypto-api.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-converter.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-converter.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-deriver.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-deriver.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-io.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-io.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/key-manager.js +0 -2
- package/dist/esm/prototyping/crypto/types/key-manager.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/params-direct.js +0 -2
- package/dist/esm/prototyping/crypto/types/params-direct.js.map +0 -1
- package/dist/esm/prototyping/crypto/types/params-kms.js +0 -2
- package/dist/esm/prototyping/crypto/types/params-kms.js.map +0 -1
- package/dist/esm/prototyping/crypto/utils.js +0 -19
- package/dist/esm/prototyping/crypto/utils.js.map +0 -1
- package/dist/esm/prototyping/dids/resolver-cache-memory.js +0 -77
- package/dist/esm/prototyping/dids/resolver-cache-memory.js.map +0 -1
- package/dist/esm/prototyping/dids/utils.js +0 -9
- package/dist/esm/prototyping/dids/utils.js.map +0 -1
- package/dist/esm/rpc-client.js +0 -123
- package/dist/esm/rpc-client.js.map +0 -1
- package/dist/types/dwn-registrar.d.ts +0 -29
- package/dist/types/dwn-registrar.d.ts.map +0 -1
- package/dist/types/prototyping/clients/dwn-rpc-types.d.ts +0 -45
- package/dist/types/prototyping/clients/dwn-rpc-types.d.ts.map +0 -1
- package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts +0 -57
- package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts.map +0 -1
- package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts +0 -13
- package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts.map +0 -1
- package/dist/types/prototyping/clients/json-rpc-socket.d.ts +0 -43
- package/dist/types/prototyping/clients/json-rpc-socket.d.ts.map +0 -1
- package/dist/types/prototyping/clients/json-rpc.d.ts +0 -49
- package/dist/types/prototyping/clients/json-rpc.d.ts.map +0 -1
- package/dist/types/prototyping/clients/server-info-types.d.ts +0 -20
- package/dist/types/prototyping/clients/server-info-types.d.ts.map +0 -1
- package/dist/types/prototyping/clients/web-socket-clients.d.ts +0 -10
- package/dist/types/prototyping/clients/web-socket-clients.d.ts.map +0 -1
- package/dist/types/prototyping/common/object.d.ts +0 -2
- package/dist/types/prototyping/common/object.d.ts.map +0 -1
- package/dist/types/prototyping/common/type-utils.d.ts +0 -7
- package/dist/types/prototyping/common/type-utils.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts +0 -151
- package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts +0 -108
- package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts +0 -160
- package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts +0 -157
- package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts +0 -20
- package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts +0 -20
- package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/crypto-error.d.ts +0 -29
- package/dist/types/prototyping/crypto/crypto-error.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/crypto-api.d.ts +0 -34
- package/dist/types/prototyping/crypto/types/crypto-api.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-converter.d.ts +0 -49
- package/dist/types/prototyping/crypto/types/key-converter.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-deriver.d.ts +0 -50
- package/dist/types/prototyping/crypto/types/key-deriver.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-io.d.ts +0 -49
- package/dist/types/prototyping/crypto/types/key-io.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/key-manager.d.ts +0 -69
- package/dist/types/prototyping/crypto/types/key-manager.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/params-direct.d.ts +0 -75
- package/dist/types/prototyping/crypto/types/params-direct.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/types/params-kms.d.ts +0 -63
- package/dist/types/prototyping/crypto/types/params-kms.d.ts.map +0 -1
- package/dist/types/prototyping/crypto/utils.d.ts +0 -7
- package/dist/types/prototyping/crypto/utils.d.ts.map +0 -1
- package/dist/types/prototyping/dids/resolver-cache-memory.d.ts +0 -57
- package/dist/types/prototyping/dids/resolver-cache-memory.d.ts.map +0 -1
- package/dist/types/prototyping/dids/utils.d.ts +0 -3
- package/dist/types/prototyping/dids/utils.d.ts.map +0 -1
- package/dist/types/rpc-client.d.ts +0 -51
- package/dist/types/rpc-client.d.ts.map +0 -1
- package/src/dwn-registrar.ts +0 -127
- package/src/prototyping/clients/dwn-rpc-types.ts +0 -55
- package/src/prototyping/clients/dwn-server-info-cache-memory.ts +0 -79
- package/src/prototyping/clients/http-dwn-rpc-client.ts +0 -119
- package/src/prototyping/clients/json-rpc-socket.ts +0 -189
- package/src/prototyping/clients/json-rpc.ts +0 -113
- package/src/prototyping/clients/server-info-types.ts +0 -21
- package/src/prototyping/clients/web-socket-clients.ts +0 -103
- package/src/prototyping/common/object.ts +0 -15
- package/src/prototyping/common/type-utils.ts +0 -6
- package/src/prototyping/crypto/algorithms/aes-gcm.ts +0 -211
- package/src/prototyping/crypto/algorithms/aes-kw.ts +0 -160
- package/src/prototyping/crypto/algorithms/ecdsa.ts +0 -366
- package/src/prototyping/crypto/algorithms/eddsa.ts +0 -311
- package/src/prototyping/crypto/algorithms/hkdf.ts +0 -38
- package/src/prototyping/crypto/algorithms/pbkdf2.ts +0 -41
- package/src/prototyping/crypto/crypto-error.ts +0 -45
- package/src/prototyping/crypto/types/crypto-api.ts +0 -77
- package/src/prototyping/crypto/types/key-converter.ts +0 -53
- package/src/prototyping/crypto/types/key-deriver.ts +0 -56
- package/src/prototyping/crypto/types/key-io.ts +0 -51
- package/src/prototyping/crypto/types/key-manager.ts +0 -83
- package/src/prototyping/crypto/types/params-direct.ts +0 -95
- package/src/prototyping/crypto/types/params-kms.ts +0 -76
- package/src/prototyping/crypto/utils.ts +0 -41
- package/src/prototyping/dids/resolver-cache-memory.ts +0 -83
- package/src/prototyping/dids/utils.ts +0 -10
- package/src/rpc-client.ts +0 -160
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AsymmetricKeyConverter,
|
|
3
|
-
AsymmetricKeyGenerator,
|
|
4
|
-
ComputePublicKeyParams,
|
|
5
|
-
GenerateKeyParams,
|
|
6
|
-
GetPublicKeyParams,
|
|
7
|
-
Jwk,
|
|
8
|
-
KeyConverter,
|
|
9
|
-
Signer,
|
|
10
|
-
SignParams,
|
|
11
|
-
VerifyParams,
|
|
12
|
-
} from '@enbox/crypto';
|
|
13
|
-
|
|
14
|
-
import { CryptoAlgorithm, Ed25519, isOkpPrivateJwk, isOkpPublicJwk } from '@enbox/crypto';
|
|
15
|
-
|
|
16
|
-
import type { BytesToPrivateKeyParams, BytesToPublicKeyParams, PrivateKeyToBytesParams, PublicKeyToBytesParams } from '../types/params-direct.js';
|
|
17
|
-
import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The `EdDsaGenerateKeyParams` interface defines the algorithm-specific parameters that should be
|
|
21
|
-
* passed into the `generateKey()` method when using the EdDSA algorithm.
|
|
22
|
-
*/
|
|
23
|
-
export interface EdDsaGenerateKeyParams extends GenerateKeyParams {
|
|
24
|
-
/**
|
|
25
|
-
* A string defining the type of key to generate. The value must be one of the following:
|
|
26
|
-
* - `"Ed25519"`: EdDSA using the Ed25519 curve.
|
|
27
|
-
*/
|
|
28
|
-
algorithm: 'Ed25519';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The `EdDsaAlgorithm` class provides a concrete implementation for cryptographic operations using
|
|
33
|
-
* the Edwards-curve Digital Signature Algorithm (EdDSA). This class implements both
|
|
34
|
-
* {@link Signer | `Signer`} and { @link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`}
|
|
35
|
-
* interfaces, providing private key generation, public key derivation, and creation/verification
|
|
36
|
-
* of signatures.
|
|
37
|
-
*
|
|
38
|
-
* This class is typically accessed through implementations that extend the
|
|
39
|
-
* {@link CryptoApi | `CryptoApi`} interface.
|
|
40
|
-
*/
|
|
41
|
-
export class EdDsaAlgorithm extends CryptoAlgorithm
|
|
42
|
-
implements AsymmetricKeyGenerator<EdDsaGenerateKeyParams, Jwk, GetPublicKeyParams>,
|
|
43
|
-
KeyConverter, AsymmetricKeyConverter,
|
|
44
|
-
Signer<SignParams, VerifyParams> {
|
|
45
|
-
|
|
46
|
-
public async bytesToPrivateKey({ algorithm, privateKeyBytes }:
|
|
47
|
-
BytesToPrivateKeyParams & { algorithm: 'Ed25519' }
|
|
48
|
-
): Promise<Jwk> {
|
|
49
|
-
switch (algorithm) {
|
|
50
|
-
|
|
51
|
-
case 'Ed25519': {
|
|
52
|
-
const privateKey = await Ed25519.bytesToPrivateKey({ privateKeyBytes });
|
|
53
|
-
privateKey.alg = 'EdDSA';
|
|
54
|
-
return privateKey;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
default: {
|
|
58
|
-
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public async bytesToPublicKey({ algorithm, publicKeyBytes }:
|
|
64
|
-
BytesToPublicKeyParams & { algorithm: 'Ed25519' }
|
|
65
|
-
): Promise<Jwk> {
|
|
66
|
-
switch (algorithm) {
|
|
67
|
-
|
|
68
|
-
case 'Ed25519': {
|
|
69
|
-
const publicKey = await Ed25519.bytesToPublicKey({ publicKeyBytes });
|
|
70
|
-
publicKey.alg = 'EdDSA';
|
|
71
|
-
return publicKey;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
default: {
|
|
75
|
-
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Derives the public key in JWK format from a given private key.
|
|
82
|
-
*
|
|
83
|
-
* @remarks
|
|
84
|
-
* This method takes a private key in JWK format and derives its corresponding public key,
|
|
85
|
-
* also in JWK format. The process ensures that the derived public key correctly corresponds to
|
|
86
|
-
* the given private key.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* const eddsa = new EdDsaAlgorithm();
|
|
91
|
-
* const privateKey = { ... }; // A Jwk object representing a private key
|
|
92
|
-
* const publicKey = await eddsa.computePublicKey({ key: privateKey });
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @param params - The parameters for the public key derivation.
|
|
96
|
-
* @param params.key - The private key in JWK format from which to derive the public key.
|
|
97
|
-
*
|
|
98
|
-
* @returns A Promise that resolves to the derived public key in JWK format.
|
|
99
|
-
*/
|
|
100
|
-
public async computePublicKey({ key }:
|
|
101
|
-
ComputePublicKeyParams
|
|
102
|
-
): Promise<Jwk> {
|
|
103
|
-
if (!isOkpPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');}
|
|
104
|
-
|
|
105
|
-
switch (key.crv) {
|
|
106
|
-
|
|
107
|
-
case 'Ed25519': {
|
|
108
|
-
const publicKey = await Ed25519.computePublicKey({ key });
|
|
109
|
-
publicKey.alg = 'EdDSA';
|
|
110
|
-
return publicKey;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
default: {
|
|
114
|
-
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${key.crv}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Generates a new private key with the specified algorithm in JSON Web Key (JWK) format.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* const eddsa = new EdDsaAlgorithm();
|
|
125
|
-
* const privateKey = await eddsa.generateKey({ algorithm: 'Ed25519' });
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* @param params - The parameters for key generation.
|
|
129
|
-
* @param params.algorithm - The algorithm to use for key generation.
|
|
130
|
-
*
|
|
131
|
-
* @returns A Promise that resolves to the generated private key in JWK format.
|
|
132
|
-
*/
|
|
133
|
-
async generateKey({ algorithm }:
|
|
134
|
-
EdDsaGenerateKeyParams
|
|
135
|
-
): Promise<Jwk> {
|
|
136
|
-
switch (algorithm) {
|
|
137
|
-
|
|
138
|
-
case 'Ed25519': {
|
|
139
|
-
const privateKey = await Ed25519.generateKey();
|
|
140
|
-
privateKey.alg = 'EdDSA';
|
|
141
|
-
return privateKey;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Retrieves the public key properties from a given private key in JWK format.
|
|
148
|
-
*
|
|
149
|
-
* @remarks
|
|
150
|
-
* This method extracts the public key portion from an EdDSA private key in JWK format. It does
|
|
151
|
-
* so by removing the private key property 'd' and making a shallow copy, effectively yielding the
|
|
152
|
-
* public key.
|
|
153
|
-
*
|
|
154
|
-
* Note: This method offers a significant performance advantage, being about 100 times faster
|
|
155
|
-
* than `computePublicKey()`. However, it does not mathematically validate the private key, nor
|
|
156
|
-
* does it derive the public key from the private key. It simply extracts existing public key
|
|
157
|
-
* properties from the private key object. This makes it suitable for scenarios where speed is
|
|
158
|
-
* critical and the private key's integrity is already assured.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* const eddsa = new EdDsaAlgorithm();
|
|
163
|
-
* const privateKey = { ... }; // A Jwk object representing a private key
|
|
164
|
-
* const publicKey = await eddsa.getPublicKey({ key: privateKey });
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* @param params - The parameters for retrieving the public key properties.
|
|
168
|
-
* @param params.key - The private key in JWK format.
|
|
169
|
-
*
|
|
170
|
-
* @returns A Promise that resolves to the public key in JWK format.
|
|
171
|
-
*/
|
|
172
|
-
public async getPublicKey({ key }:
|
|
173
|
-
GetPublicKeyParams
|
|
174
|
-
): Promise<Jwk> {
|
|
175
|
-
if (!isOkpPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');}
|
|
176
|
-
|
|
177
|
-
switch (key.crv) {
|
|
178
|
-
|
|
179
|
-
case 'Ed25519': {
|
|
180
|
-
const publicKey = await Ed25519.getPublicKey({ key });
|
|
181
|
-
publicKey.alg = 'EdDSA';
|
|
182
|
-
return publicKey;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
default: {
|
|
186
|
-
throw new Error(`Unsupported curve: ${key.crv}`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
public async privateKeyToBytes({ privateKey }:
|
|
192
|
-
PrivateKeyToBytesParams
|
|
193
|
-
): Promise<Uint8Array> {
|
|
194
|
-
switch (privateKey.crv) {
|
|
195
|
-
|
|
196
|
-
case 'Ed25519': {
|
|
197
|
-
return await Ed25519.privateKeyToBytes({ privateKey });
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
default: {
|
|
201
|
-
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${privateKey.crv}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
public async publicKeyToBytes({ publicKey }:
|
|
207
|
-
PublicKeyToBytesParams
|
|
208
|
-
): Promise<Uint8Array> {
|
|
209
|
-
switch (publicKey.crv) {
|
|
210
|
-
|
|
211
|
-
case 'Ed25519': {
|
|
212
|
-
return await Ed25519.publicKeyToBytes({ publicKey });
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
default: {
|
|
216
|
-
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${publicKey.crv}`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Generates an EdDSA signature of given data using a private key.
|
|
223
|
-
*
|
|
224
|
-
* @remarks
|
|
225
|
-
* This method uses the signature algorithm determined by the given `algorithm` to sign the
|
|
226
|
-
* provided data.
|
|
227
|
-
*
|
|
228
|
-
* The signature can later be verified by parties with access to the corresponding
|
|
229
|
-
* public key, ensuring that the data has not been tampered with and was indeed signed by the
|
|
230
|
-
* holder of the private key.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```ts
|
|
234
|
-
* const eddsa = new EdDsaAlgorithm();
|
|
235
|
-
* const data = new TextEncoder().encode('Message');
|
|
236
|
-
* const privateKey = { ... }; // A Jwk object representing a private key
|
|
237
|
-
* const signature = await eddsa.sign({
|
|
238
|
-
* key: privateKey,
|
|
239
|
-
* data
|
|
240
|
-
* });
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* @param params - The parameters for the signing operation.
|
|
244
|
-
* @param params.key - The private key to use for signing, represented in JWK format.
|
|
245
|
-
* @param params.data - The data to sign.
|
|
246
|
-
*
|
|
247
|
-
* @returns A Promise resolving to the digital signature as a `Uint8Array`.
|
|
248
|
-
*/
|
|
249
|
-
public async sign({ key, data }:
|
|
250
|
-
SignParams
|
|
251
|
-
): Promise<Uint8Array> {
|
|
252
|
-
if (!isOkpPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');}
|
|
253
|
-
|
|
254
|
-
switch (key.crv) {
|
|
255
|
-
|
|
256
|
-
case 'Ed25519': {
|
|
257
|
-
return await Ed25519.sign({ key, data });
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
default: {
|
|
261
|
-
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${key.crv}`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Verifies an EdDSA signature associated with the provided data using the provided key.
|
|
268
|
-
*
|
|
269
|
-
* @remarks
|
|
270
|
-
* This method uses the signature algorithm determined by the `crv` property of the provided key
|
|
271
|
-
* to check the validity of a digital signature against the original data. It confirms whether the
|
|
272
|
-
* signature was created by the holder of the corresponding private key and that the data has not
|
|
273
|
-
* been tampered with.
|
|
274
|
-
*s
|
|
275
|
-
* @example
|
|
276
|
-
* ```ts
|
|
277
|
-
* const eddsa = new EdDsaAlgorithm();
|
|
278
|
-
* const publicKey = { ... }; // Public key in JWK format corresponding to the private key that signed the data
|
|
279
|
-
* const signature = new Uint8Array([...]); // Signature to verify
|
|
280
|
-
* const data = new TextEncoder().encode('Message');
|
|
281
|
-
* const isValid = await eddsa.verify({
|
|
282
|
-
* key: publicKey,
|
|
283
|
-
* signature,
|
|
284
|
-
* data
|
|
285
|
-
* });
|
|
286
|
-
* ```
|
|
287
|
-
*
|
|
288
|
-
* @param params - The parameters for the verification operation.
|
|
289
|
-
* @param params.key - The key to use for verification.
|
|
290
|
-
* @param params.signature - The signature to verify.
|
|
291
|
-
* @param params.data - The data to verify.
|
|
292
|
-
*
|
|
293
|
-
* @returns A Promise resolving to a boolean indicating whether the signature is valid.
|
|
294
|
-
*/
|
|
295
|
-
public async verify({ key, signature, data }:
|
|
296
|
-
VerifyParams
|
|
297
|
-
): Promise<boolean> {
|
|
298
|
-
if (!isOkpPublicJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) public key.');}
|
|
299
|
-
|
|
300
|
-
switch (key.crv) {
|
|
301
|
-
|
|
302
|
-
case 'Ed25519': {
|
|
303
|
-
return await Ed25519.verify({ key, signature, data });
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
default: {
|
|
307
|
-
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${key.crv}`);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { KeyBytesDeriver } from '../types/key-deriver.js';
|
|
2
|
-
import type { DeriveKeyBytesParams, HkdfParams } from '@enbox/crypto';
|
|
3
|
-
|
|
4
|
-
import { CryptoAlgorithm, Hkdf } from '@enbox/crypto';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The `HkdfDeriveKeyBytesParams` interface defines the algorithm-specific parameters that should be
|
|
8
|
-
* passed into the `deriveKeyBytes()` method when using the HKDF algorithm.
|
|
9
|
-
*/
|
|
10
|
-
export interface HkdfDeriveKeyBytesParams extends DeriveKeyBytesParams {
|
|
11
|
-
/** Specifies the algorithm variant for HKDF key derivation.
|
|
12
|
-
* The value determines the hash function that will be used and must be one of the following:
|
|
13
|
-
* - `"HKDF-256"`: HKDF with SHA-256.
|
|
14
|
-
* - `"HKDF-384"`: HKDF with SHA-384.
|
|
15
|
-
* - `"HKDF-512"`: HKDF with SHA-512.
|
|
16
|
-
*/
|
|
17
|
-
algorithm: 'HKDF-256' | 'HKDF-384' | 'HKDF-512';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class HkdfAlgorithm extends CryptoAlgorithm
|
|
21
|
-
implements KeyBytesDeriver<HkdfDeriveKeyBytesParams, Uint8Array> {
|
|
22
|
-
|
|
23
|
-
public async deriveKeyBytes({ algorithm, ...params }:
|
|
24
|
-
HkdfDeriveKeyBytesParams & Omit<HkdfParams, 'hash'>
|
|
25
|
-
): Promise<Uint8Array> {
|
|
26
|
-
// Map algorithm name to hash function.
|
|
27
|
-
const hash = {
|
|
28
|
-
'HKDF-256' : 'SHA-256' as const,
|
|
29
|
-
'HKDF-384' : 'SHA-384' as const,
|
|
30
|
-
'HKDF-512' : 'SHA-512' as const
|
|
31
|
-
}[algorithm];
|
|
32
|
-
|
|
33
|
-
// Derive a cryptographic byte array using HKDF.
|
|
34
|
-
const derivedKeyBytes = await Hkdf.deriveKeyBytes({ ...params, hash });
|
|
35
|
-
|
|
36
|
-
return derivedKeyBytes;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { KeyBytesDeriver } from '../types/key-deriver.js';
|
|
2
|
-
import type { DeriveKeyBytesParams, Pbkdf2Params } from '@enbox/crypto';
|
|
3
|
-
|
|
4
|
-
import { CryptoAlgorithm, Pbkdf2 } from '@enbox/crypto';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The `Pbkdf2DeriveKeyBytesParams` interface defines the algorithm-specific parameters that
|
|
8
|
-
* should be passed into the `deriveKeyBytes()` method when using the PBKDF2 algorithm.
|
|
9
|
-
*/
|
|
10
|
-
export interface Pbkdf2DeriveKeyBytesParams extends DeriveKeyBytesParams {
|
|
11
|
-
/** Specifies the algorithm variant for PBKDF2 key derivation.
|
|
12
|
-
* The value determines the hash function that will be used and must be one of the following:
|
|
13
|
-
* - `"PBKDF2-HS256+A128KW"`: PBKDF2 with HMAC SHA-256 and A128KW key wrapping.
|
|
14
|
-
* - `"PBKDF2-HS384+A192KW"`: PBKDF2 with HMAC SHA-384 and A192KW key wrapping.
|
|
15
|
-
* - `"PBKDF2-HS512+A256KW"`: PBKDF2 with HMAC SHA-512 and A256KW key wrapping.
|
|
16
|
-
*/
|
|
17
|
-
algorithm: 'PBES2-HS256+A128KW' | 'PBES2-HS384+A192KW' | 'PBES2-HS512+A256KW';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class Pbkdf2Algorithm extends CryptoAlgorithm
|
|
21
|
-
implements KeyBytesDeriver<Pbkdf2DeriveKeyBytesParams, Uint8Array> {
|
|
22
|
-
|
|
23
|
-
public async deriveKeyBytes({ algorithm, ...params }:
|
|
24
|
-
Pbkdf2DeriveKeyBytesParams & Omit<Pbkdf2Params, 'hash'>
|
|
25
|
-
): Promise<Uint8Array> {
|
|
26
|
-
// Extract the hash function component of the `algorithm` parameter.
|
|
27
|
-
const [, hashFunction] = algorithm.split(/[-+]/);
|
|
28
|
-
|
|
29
|
-
// Map from JOSE algorithm name to "SHA" hash function identifier.
|
|
30
|
-
const hash = {
|
|
31
|
-
'HS256' : 'SHA-256' as const,
|
|
32
|
-
'HS384' : 'SHA-384' as const,
|
|
33
|
-
'HS512' : 'SHA-512' as const
|
|
34
|
-
}[hashFunction]!;
|
|
35
|
-
|
|
36
|
-
// Derive a cryptographic byte array using PBKDF2.
|
|
37
|
-
const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({ ...params, hash });
|
|
38
|
-
|
|
39
|
-
return derivedKeyBytes;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A custom error class for Crypto-related errors.
|
|
3
|
-
*/
|
|
4
|
-
export class CryptoError extends Error {
|
|
5
|
-
/**
|
|
6
|
-
* Constructs an instance of CryptoError, a custom error class for handling Crypto-related errors.
|
|
7
|
-
*
|
|
8
|
-
* @param code - A {@link CryptoErrorCode} representing the specific type of error encountered.
|
|
9
|
-
* @param message - A human-readable description of the error.
|
|
10
|
-
*/
|
|
11
|
-
constructor(public code: CryptoErrorCode, message: string) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = 'CryptoError';
|
|
14
|
-
|
|
15
|
-
// Ensures that instanceof works properly, the correct prototype chain when using inheritance,
|
|
16
|
-
// and that V8 stack traces (like Chrome, Edge, and Node.js) are more readable and relevant.
|
|
17
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
18
|
-
|
|
19
|
-
// Captures the stack trace in V8 engines (like Chrome, Edge, and Node.js).
|
|
20
|
-
// In non-V8 environments, the stack trace will still be captured.
|
|
21
|
-
if (Error.captureStackTrace) {
|
|
22
|
-
Error.captureStackTrace(this, CryptoError);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* An enumeration of possible Crypto error codes.
|
|
29
|
-
*/
|
|
30
|
-
export enum CryptoErrorCode {
|
|
31
|
-
/** The supplied algorithm identifier is not supported by the implementation. */
|
|
32
|
-
AlgorithmNotSupported = 'algorithmNotSupported',
|
|
33
|
-
|
|
34
|
-
/** The encoding operation (either encoding or decoding) failed. */
|
|
35
|
-
EncodingError = 'encodingError',
|
|
36
|
-
|
|
37
|
-
/** The JWE supplied does not conform to valid syntax. */
|
|
38
|
-
InvalidJwe = 'invalidJwe',
|
|
39
|
-
|
|
40
|
-
/** The JWK supplied does not conform to valid syntax. */
|
|
41
|
-
InvalidJwk = 'invalidJwk',
|
|
42
|
-
|
|
43
|
-
/** The requested operation is not supported by the implementation. */
|
|
44
|
-
OperationNotSupported = 'operationNotSupported',
|
|
45
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Cipher,
|
|
3
|
-
DigestParams,
|
|
4
|
-
GenerateKeyParams,
|
|
5
|
-
GetPublicKeyParams,
|
|
6
|
-
Jwk,
|
|
7
|
-
KeyWrapper,
|
|
8
|
-
CryptoApi as OldCryptoApi,
|
|
9
|
-
SignParams,
|
|
10
|
-
VerifyParams,
|
|
11
|
-
} from '@enbox/crypto';
|
|
12
|
-
|
|
13
|
-
import type { AsymmetricKeyConverter, KeyConverter } from './key-converter.js';
|
|
14
|
-
import type { BytesToPrivateKeyParams, BytesToPublicKeyParams, CipherParams, DeriveKeyBytesParams, DeriveKeyParams, PrivateKeyToBytesParams, PublicKeyToBytesParams, UnwrapKeyParams, WrapKeyParams } from './params-direct.js';
|
|
15
|
-
import type { KeyBytesDeriver, KeyDeriver } from './key-deriver.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The `DsaApi` interface integrates key generation, hashing, and signing functionalities,
|
|
19
|
-
* designed for use with a Key Management System (KMS). It extends `AsymmetricKeyGenerator` for
|
|
20
|
-
* generating asymmetric keys, `Hasher` for hash digest computations, and `Signer` for signing and
|
|
21
|
-
* verifying operations.
|
|
22
|
-
*
|
|
23
|
-
* Concrete implementations of this interface are intended to be used with a KMS, which is
|
|
24
|
-
* responsible for generating and storing cryptographic keys. The KMS is also responsible for
|
|
25
|
-
* performing cryptographic operations using the keys it manages. The KMS is typically a cloud
|
|
26
|
-
* service, but it can also be a hardware device or software application.
|
|
27
|
-
*
|
|
28
|
-
* Guidelines for implementing this interface:
|
|
29
|
-
* - Must use JSON Web Keys ({@link Jwk | JWK}) as the key format.
|
|
30
|
-
* - Must IANA registered JSON Object Signing and Encryption
|
|
31
|
-
* {@ link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | (JOSE)}
|
|
32
|
-
* names for algorithm, curves, etc. whenever possible.
|
|
33
|
-
* - All I/O that interacts with private or secret keys must be done via reference using a
|
|
34
|
-
* {@link KeyIdentifier | `KeyIdentifier`}. Implementations can use any string as the key
|
|
35
|
-
* identifier (e.g. JWK thumbprint, UUID generated by hosted KMS, etc.).
|
|
36
|
-
* - Must support key generation, hashing, signing, and verifying operations.
|
|
37
|
-
* - May be extended to support other cryptographic operations.
|
|
38
|
-
* - Implementations of the `DsaApi` interface can be passed as an argument to the public API
|
|
39
|
-
* methods of Web5 libraries that involve key material (e.g., DID creation, VC signing, arbitrary
|
|
40
|
-
* data signing/verification, etc.).
|
|
41
|
-
*/
|
|
42
|
-
export interface DsaApi<
|
|
43
|
-
GenerateKeyInput = GenerateKeyParams,
|
|
44
|
-
GenerateKeyOutput = Jwk,
|
|
45
|
-
GetPublicKeyInput = GetPublicKeyParams,
|
|
46
|
-
DigestInput = DigestParams,
|
|
47
|
-
SignInput = SignParams,
|
|
48
|
-
VerifyInput = VerifyParams
|
|
49
|
-
> extends OldCryptoApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput> {}
|
|
50
|
-
|
|
51
|
-
export interface CryptoApi<
|
|
52
|
-
GenerateKeyInput = GenerateKeyParams,
|
|
53
|
-
GenerateKeyOutput = Jwk,
|
|
54
|
-
GetPublicKeyInput = GetPublicKeyParams,
|
|
55
|
-
DigestInput = DigestParams,
|
|
56
|
-
SignInput = SignParams,
|
|
57
|
-
VerifyInput = VerifyParams,
|
|
58
|
-
EncryptInput = CipherParams,
|
|
59
|
-
DecryptInput = CipherParams,
|
|
60
|
-
BytesToPublicKeyInput = BytesToPublicKeyParams,
|
|
61
|
-
PublicKeyToBytesInput = PublicKeyToBytesParams,
|
|
62
|
-
BytesToPrivateKeyInput = BytesToPrivateKeyParams,
|
|
63
|
-
PrivateKeyToBytesInput = PrivateKeyToBytesParams,
|
|
64
|
-
DeriveKeyInput = DeriveKeyParams,
|
|
65
|
-
DeriveKeyOutput = Jwk,
|
|
66
|
-
DeriveKeyBytesInput = DeriveKeyBytesParams,
|
|
67
|
-
DeriveKeyBytesOutput = Uint8Array,
|
|
68
|
-
WrapKeyInput = WrapKeyParams,
|
|
69
|
-
UnwrapKeyInput = UnwrapKeyParams
|
|
70
|
-
> extends
|
|
71
|
-
DsaApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput>,
|
|
72
|
-
Cipher<EncryptInput, DecryptInput>,
|
|
73
|
-
AsymmetricKeyConverter<BytesToPublicKeyInput, PublicKeyToBytesInput>,
|
|
74
|
-
KeyConverter<BytesToPrivateKeyInput, PrivateKeyToBytesInput>,
|
|
75
|
-
KeyDeriver<DeriveKeyInput, DeriveKeyOutput>,
|
|
76
|
-
KeyBytesDeriver<DeriveKeyBytesInput, DeriveKeyBytesOutput>,
|
|
77
|
-
KeyWrapper<WrapKeyInput, UnwrapKeyInput> {}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Jwk } from '@enbox/crypto';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* `KeyConverter` interface for converting private keys between byte array and JWK formats.
|
|
5
|
-
*/
|
|
6
|
-
export interface KeyConverter<BytesToPrivateKeyInput, PrivateKeyToBytesInput> {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Converts a private key from a byte array to JWK format.
|
|
10
|
-
*
|
|
11
|
-
* @param params - The parameters for the private key conversion.
|
|
12
|
-
* @param params.privateKeyBytes - The raw private key as a Uint8Array.
|
|
13
|
-
*
|
|
14
|
-
* @returns A Promise that resolves to the private key in JWK format.
|
|
15
|
-
*/
|
|
16
|
-
bytesToPrivateKey(params: BytesToPrivateKeyInput): Promise<Jwk>;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Converts a private key from JWK format to a byte array.
|
|
20
|
-
*
|
|
21
|
-
* @param params - The parameters for the private key conversion.
|
|
22
|
-
* @param params.privateKey - The private key in JWK format.
|
|
23
|
-
*
|
|
24
|
-
* @returns A Promise that resolves to the private key as a Uint8Array.
|
|
25
|
-
*/
|
|
26
|
-
privateKeyToBytes(params: PrivateKeyToBytesInput): Promise<Uint8Array>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* `AsymmetricKeyConverter` interface extends {@link KeyConverter |`KeyConverter`}, adding support
|
|
31
|
-
* for public key conversions.
|
|
32
|
-
*/
|
|
33
|
-
export interface AsymmetricKeyConverter<BytesToPublicKeyInput, PublicKeyToBytesInput> {
|
|
34
|
-
/**
|
|
35
|
-
* Converts a public key from a byte array to JWK format.
|
|
36
|
-
*
|
|
37
|
-
* @param params - The parameters for the public key conversion.
|
|
38
|
-
* @param params.publicKeyBytes - The raw public key as a Uint8Array.
|
|
39
|
-
*
|
|
40
|
-
* @returns A Promise that resolves to the public key in JWK format.
|
|
41
|
-
*/
|
|
42
|
-
bytesToPublicKey(params: BytesToPublicKeyInput): Promise<Jwk>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Converts a public key from JWK format to a byte array.
|
|
46
|
-
*
|
|
47
|
-
* @param params - The parameters for the public key conversion.
|
|
48
|
-
* @param params.publicKey - The public key in JWK format.
|
|
49
|
-
*
|
|
50
|
-
* @returns A Promise that resolves to the public key as a Uint8Array.
|
|
51
|
-
*/
|
|
52
|
-
publicKeyToBytes(params: PublicKeyToBytesInput): Promise<Uint8Array>;
|
|
53
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `KeyDeriver` interface provide a method for key derivation.
|
|
3
|
-
*
|
|
4
|
-
* The `deriveKey()` method derives a {@link Jwk | JWK} from input data using the specified key
|
|
5
|
-
* derivation algorithm. This interface is designed to support various key derivation
|
|
6
|
-
* algorithms, accommodating different input and output types.
|
|
7
|
-
*/
|
|
8
|
-
export interface KeyDeriver<
|
|
9
|
-
DeriveKeyInput,
|
|
10
|
-
DeriveKeyOutput,
|
|
11
|
-
> {
|
|
12
|
-
/**
|
|
13
|
-
* Derives a cryptographic key in JWK format based on the provided input parameters.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* The `deriveKey()` method of the {@link KeyDeriver | `KeyDeriver`} interface is utilized to
|
|
17
|
-
* generate cryptographic keys for operations like encryption, decryption, or signing. The method
|
|
18
|
-
* takes in parameters tailored to the key derivation algorithm being used and returns a promise
|
|
19
|
-
* that resolves to the derived key.
|
|
20
|
-
*
|
|
21
|
-
* @param params - The parameters for the key derivation process, specific to the chosen
|
|
22
|
-
* algorithm.
|
|
23
|
-
*
|
|
24
|
-
* @returns A Promise resolving to the derived key in the specified output format.
|
|
25
|
-
*/
|
|
26
|
-
deriveKey(params: DeriveKeyInput): Promise<DeriveKeyOutput>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The `KeyBytesDeriver` interface provide a method for deriving a byte array using a key derivation
|
|
31
|
-
* algorithm.
|
|
32
|
-
*
|
|
33
|
-
* The `deriveKeyBytes()` method to derives cryptographic bits from input data using the specified
|
|
34
|
-
* key derivation algorithm. This interface is designed to support various key derivation
|
|
35
|
-
* algorithms, accommodating different input and output types.
|
|
36
|
-
*/
|
|
37
|
-
export interface KeyBytesDeriver<
|
|
38
|
-
DeriveKeyBytesInput,
|
|
39
|
-
DeriveKeyBytesOutput
|
|
40
|
-
> {
|
|
41
|
-
/**
|
|
42
|
-
* Generates a specified number of cryptographic bits from given input parameters.
|
|
43
|
-
*
|
|
44
|
-
* @remarks
|
|
45
|
-
* The `deriveKeyBytes()` method of the {@link KeyBytesDeriver | `KeyBytesDeriver`} interface is
|
|
46
|
-
* used to create cryptographic material such as initialization vectors or keys from various
|
|
47
|
-
* sources. The method takes in parameters specific to the chosen key derivation algorithm and
|
|
48
|
-
* outputs a promise that resolves to a `Uint8Array` containing the derived bits.
|
|
49
|
-
*
|
|
50
|
-
* @param params - The parameters for the key derivation process, specific to the chosen
|
|
51
|
-
* algorithm.
|
|
52
|
-
*
|
|
53
|
-
* @returns A Promise resolving to the derived bits in the specified format.
|
|
54
|
-
*/
|
|
55
|
-
deriveKeyBytes(params: DeriveKeyBytesInput): Promise<DeriveKeyBytesOutput>;
|
|
56
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { Jwk } from '@enbox/crypto';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The `KeyExporter` interface provides a method for exporting cryptographic keys.
|
|
5
|
-
*/
|
|
6
|
-
export interface KeyExporter<ExportKeyInput, ExportKeyOutput = Jwk> {
|
|
7
|
-
/**
|
|
8
|
-
* Exports a cryptographic key to an external JWK object.
|
|
9
|
-
*
|
|
10
|
-
* @remarks
|
|
11
|
-
* The `exportKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface
|
|
12
|
-
* returns a cryptographic key in JWK format, facilitating interoperability and backup.
|
|
13
|
-
*
|
|
14
|
-
* @param params - The parameters for the key export operation.
|
|
15
|
-
*
|
|
16
|
-
* @returns A Promise resolving to the exported key in JWK format.
|
|
17
|
-
*/
|
|
18
|
-
exportKey(params: ExportKeyInput): Promise<ExportKeyOutput>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The `KeyImporter` interface provides a method for importing cryptographic keys.
|
|
23
|
-
*/
|
|
24
|
-
export interface KeyImporter<ImportKeyInput, ImportKeyOutput = void> {
|
|
25
|
-
/**
|
|
26
|
-
* Imports an external key in JWK format.
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* The `importKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface
|
|
30
|
-
* takes as input an external key in JWK format and typically returns a key identifier reference
|
|
31
|
-
* for the imported key.
|
|
32
|
-
*
|
|
33
|
-
* @param params - The parameters for the key import operation.
|
|
34
|
-
*
|
|
35
|
-
* @returns A Promise resolving to the key identifier of the imported key.
|
|
36
|
-
*/
|
|
37
|
-
importKey(params: ImportKeyInput): Promise<ImportKeyOutput>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface KeyDeleter<DeleteKeyInput> {
|
|
41
|
-
/**
|
|
42
|
-
* Deletes a cryptographic key.
|
|
43
|
-
*
|
|
44
|
-
* @remarks
|
|
45
|
-
* The `deleteKey()` method of the {@link KeyDeleter | `KeyDeleter`} interface deletes a cryptographic
|
|
46
|
-
* key from the key store.
|
|
47
|
-
*
|
|
48
|
-
* @param params - The parameters for the key deletion operation.
|
|
49
|
-
*/
|
|
50
|
-
deleteKey(params: DeleteKeyInput): Promise<void>;
|
|
51
|
-
}
|