@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.
Files changed (224) hide show
  1. package/dist/browser.mjs +45 -52
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/crypto-api.js +6 -13
  4. package/dist/esm/crypto-api.js.map +1 -1
  5. package/dist/esm/dwn-api.js +80 -78
  6. package/dist/esm/dwn-api.js.map +1 -1
  7. package/dist/esm/hd-identity-vault.js +4 -5
  8. package/dist/esm/hd-identity-vault.js.map +1 -1
  9. package/dist/esm/identity-api.js +1 -1
  10. package/dist/esm/identity-api.js.map +1 -1
  11. package/dist/esm/index.js +0 -2
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/local-key-manager.js +31 -32
  14. package/dist/esm/local-key-manager.js.map +1 -1
  15. package/dist/esm/prototyping/crypto/jose/jwe-compact.js +1 -2
  16. package/dist/esm/prototyping/crypto/jose/jwe-compact.js.map +1 -1
  17. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +15 -4
  18. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -1
  19. package/dist/esm/prototyping/crypto/jose/jwe.js +1 -1
  20. package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -1
  21. package/dist/esm/store-data.js +3 -3
  22. package/dist/esm/store-data.js.map +1 -1
  23. package/dist/esm/store-did.js +1 -1
  24. package/dist/esm/store-did.js.map +1 -1
  25. package/dist/esm/sync-engine-level.js +49 -11
  26. package/dist/esm/sync-engine-level.js.map +1 -1
  27. package/dist/esm/test-harness.js +24 -8
  28. package/dist/esm/test-harness.js.map +1 -1
  29. package/dist/esm/types/dwn.js +1 -1
  30. package/dist/esm/types/dwn.js.map +1 -1
  31. package/dist/esm/web5-user-agent.js +1 -1
  32. package/dist/esm/web5-user-agent.js.map +1 -1
  33. package/dist/types/crypto-api.d.ts +8 -12
  34. package/dist/types/crypto-api.d.ts.map +1 -1
  35. package/dist/types/dwn-api.d.ts +10 -10
  36. package/dist/types/dwn-api.d.ts.map +1 -1
  37. package/dist/types/hd-identity-vault.d.ts.map +1 -1
  38. package/dist/types/identity-api.d.ts.map +1 -1
  39. package/dist/types/index.d.ts +0 -2
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/dist/types/local-key-manager.d.ts +15 -18
  42. package/dist/types/local-key-manager.d.ts.map +1 -1
  43. package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts +1 -3
  44. package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts.map +1 -1
  45. package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts +1 -3
  46. package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -1
  47. package/dist/types/prototyping/crypto/jose/jwe.d.ts +1 -3
  48. package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -1
  49. package/dist/types/store-data.d.ts +2 -2
  50. package/dist/types/store-did.d.ts.map +1 -1
  51. package/dist/types/sync-engine-level.d.ts +18 -6
  52. package/dist/types/sync-engine-level.d.ts.map +1 -1
  53. package/dist/types/test-harness.d.ts.map +1 -1
  54. package/dist/types/types/agent.d.ts +1 -1
  55. package/dist/types/types/agent.d.ts.map +1 -1
  56. package/dist/types/types/dwn.d.ts +2 -2
  57. package/dist/types/types/dwn.d.ts.map +1 -1
  58. package/dist/types/types/key-manager.d.ts +15 -22
  59. package/dist/types/types/key-manager.d.ts.map +1 -1
  60. package/dist/types/utils-internal.d.ts +1 -1
  61. package/dist/types/utils-internal.d.ts.map +1 -1
  62. package/dist/types/web5-user-agent.d.ts +1 -1
  63. package/dist/types/web5-user-agent.d.ts.map +1 -1
  64. package/package.json +13 -15
  65. package/src/crypto-api.ts +24 -20
  66. package/src/dwn-api.ts +109 -102
  67. package/src/hd-identity-vault.ts +4 -5
  68. package/src/identity-api.ts +2 -1
  69. package/src/index.ts +0 -2
  70. package/src/local-key-manager.ts +43 -44
  71. package/src/prototyping/crypto/jose/jwe-compact.ts +3 -7
  72. package/src/prototyping/crypto/jose/jwe-flattened.ts +20 -9
  73. package/src/prototyping/crypto/jose/jwe.ts +2 -6
  74. package/src/store-data.ts +3 -3
  75. package/src/store-did.ts +1 -1
  76. package/src/sync-engine-level.ts +59 -16
  77. package/src/test-harness.ts +23 -8
  78. package/src/types/agent.ts +1 -1
  79. package/src/types/dwn.ts +2 -2
  80. package/src/types/key-manager.ts +31 -22
  81. package/src/utils-internal.ts +1 -1
  82. package/src/web5-user-agent.ts +2 -2
  83. package/dist/browser.js +0 -2213
  84. package/dist/browser.js.map +0 -7
  85. package/dist/esm/dwn-registrar.js +0 -120
  86. package/dist/esm/dwn-registrar.js.map +0 -1
  87. package/dist/esm/prototyping/clients/dwn-rpc-types.js +0 -2
  88. package/dist/esm/prototyping/clients/dwn-rpc-types.js.map +0 -1
  89. package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js +0 -74
  90. package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js.map +0 -1
  91. package/dist/esm/prototyping/clients/http-dwn-rpc-client.js +0 -112
  92. package/dist/esm/prototyping/clients/http-dwn-rpc-client.js.map +0 -1
  93. package/dist/esm/prototyping/clients/json-rpc-socket.js +0 -167
  94. package/dist/esm/prototyping/clients/json-rpc-socket.js.map +0 -1
  95. package/dist/esm/prototyping/clients/json-rpc.js +0 -58
  96. package/dist/esm/prototyping/clients/json-rpc.js.map +0 -1
  97. package/dist/esm/prototyping/clients/server-info-types.js +0 -2
  98. package/dist/esm/prototyping/clients/server-info-types.js.map +0 -1
  99. package/dist/esm/prototyping/clients/web-socket-clients.js +0 -90
  100. package/dist/esm/prototyping/clients/web-socket-clients.js.map +0 -1
  101. package/dist/esm/prototyping/common/object.js +0 -14
  102. package/dist/esm/prototyping/common/object.js.map +0 -1
  103. package/dist/esm/prototyping/common/type-utils.js +0 -2
  104. package/dist/esm/prototyping/common/type-utils.js.map +0 -1
  105. package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js +0 -147
  106. package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js.map +0 -1
  107. package/dist/esm/prototyping/crypto/algorithms/aes-kw.js +0 -136
  108. package/dist/esm/prototyping/crypto/algorithms/aes-kw.js.map +0 -1
  109. package/dist/esm/prototyping/crypto/algorithms/ecdsa.js +0 -311
  110. package/dist/esm/prototyping/crypto/algorithms/ecdsa.js.map +0 -1
  111. package/dist/esm/prototyping/crypto/algorithms/eddsa.js +0 -268
  112. package/dist/esm/prototyping/crypto/algorithms/eddsa.js.map +0 -1
  113. package/dist/esm/prototyping/crypto/algorithms/hkdf.js +0 -38
  114. package/dist/esm/prototyping/crypto/algorithms/hkdf.js.map +0 -1
  115. package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js +0 -40
  116. package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js.map +0 -1
  117. package/dist/esm/prototyping/crypto/crypto-error.js +0 -41
  118. package/dist/esm/prototyping/crypto/crypto-error.js.map +0 -1
  119. package/dist/esm/prototyping/crypto/types/crypto-api.js +0 -2
  120. package/dist/esm/prototyping/crypto/types/crypto-api.js.map +0 -1
  121. package/dist/esm/prototyping/crypto/types/key-converter.js +0 -2
  122. package/dist/esm/prototyping/crypto/types/key-converter.js.map +0 -1
  123. package/dist/esm/prototyping/crypto/types/key-deriver.js +0 -2
  124. package/dist/esm/prototyping/crypto/types/key-deriver.js.map +0 -1
  125. package/dist/esm/prototyping/crypto/types/key-io.js +0 -2
  126. package/dist/esm/prototyping/crypto/types/key-io.js.map +0 -1
  127. package/dist/esm/prototyping/crypto/types/key-manager.js +0 -2
  128. package/dist/esm/prototyping/crypto/types/key-manager.js.map +0 -1
  129. package/dist/esm/prototyping/crypto/types/params-direct.js +0 -2
  130. package/dist/esm/prototyping/crypto/types/params-direct.js.map +0 -1
  131. package/dist/esm/prototyping/crypto/types/params-kms.js +0 -2
  132. package/dist/esm/prototyping/crypto/types/params-kms.js.map +0 -1
  133. package/dist/esm/prototyping/crypto/utils.js +0 -19
  134. package/dist/esm/prototyping/crypto/utils.js.map +0 -1
  135. package/dist/esm/prototyping/dids/resolver-cache-memory.js +0 -77
  136. package/dist/esm/prototyping/dids/resolver-cache-memory.js.map +0 -1
  137. package/dist/esm/prototyping/dids/utils.js +0 -9
  138. package/dist/esm/prototyping/dids/utils.js.map +0 -1
  139. package/dist/esm/rpc-client.js +0 -123
  140. package/dist/esm/rpc-client.js.map +0 -1
  141. package/dist/types/dwn-registrar.d.ts +0 -29
  142. package/dist/types/dwn-registrar.d.ts.map +0 -1
  143. package/dist/types/prototyping/clients/dwn-rpc-types.d.ts +0 -45
  144. package/dist/types/prototyping/clients/dwn-rpc-types.d.ts.map +0 -1
  145. package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts +0 -57
  146. package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts.map +0 -1
  147. package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts +0 -13
  148. package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts.map +0 -1
  149. package/dist/types/prototyping/clients/json-rpc-socket.d.ts +0 -43
  150. package/dist/types/prototyping/clients/json-rpc-socket.d.ts.map +0 -1
  151. package/dist/types/prototyping/clients/json-rpc.d.ts +0 -49
  152. package/dist/types/prototyping/clients/json-rpc.d.ts.map +0 -1
  153. package/dist/types/prototyping/clients/server-info-types.d.ts +0 -20
  154. package/dist/types/prototyping/clients/server-info-types.d.ts.map +0 -1
  155. package/dist/types/prototyping/clients/web-socket-clients.d.ts +0 -10
  156. package/dist/types/prototyping/clients/web-socket-clients.d.ts.map +0 -1
  157. package/dist/types/prototyping/common/object.d.ts +0 -2
  158. package/dist/types/prototyping/common/object.d.ts.map +0 -1
  159. package/dist/types/prototyping/common/type-utils.d.ts +0 -7
  160. package/dist/types/prototyping/common/type-utils.d.ts.map +0 -1
  161. package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts +0 -151
  162. package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts.map +0 -1
  163. package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts +0 -108
  164. package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts.map +0 -1
  165. package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts +0 -160
  166. package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts.map +0 -1
  167. package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts +0 -157
  168. package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts.map +0 -1
  169. package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts +0 -20
  170. package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts.map +0 -1
  171. package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts +0 -20
  172. package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts.map +0 -1
  173. package/dist/types/prototyping/crypto/crypto-error.d.ts +0 -29
  174. package/dist/types/prototyping/crypto/crypto-error.d.ts.map +0 -1
  175. package/dist/types/prototyping/crypto/types/crypto-api.d.ts +0 -34
  176. package/dist/types/prototyping/crypto/types/crypto-api.d.ts.map +0 -1
  177. package/dist/types/prototyping/crypto/types/key-converter.d.ts +0 -49
  178. package/dist/types/prototyping/crypto/types/key-converter.d.ts.map +0 -1
  179. package/dist/types/prototyping/crypto/types/key-deriver.d.ts +0 -50
  180. package/dist/types/prototyping/crypto/types/key-deriver.d.ts.map +0 -1
  181. package/dist/types/prototyping/crypto/types/key-io.d.ts +0 -49
  182. package/dist/types/prototyping/crypto/types/key-io.d.ts.map +0 -1
  183. package/dist/types/prototyping/crypto/types/key-manager.d.ts +0 -69
  184. package/dist/types/prototyping/crypto/types/key-manager.d.ts.map +0 -1
  185. package/dist/types/prototyping/crypto/types/params-direct.d.ts +0 -75
  186. package/dist/types/prototyping/crypto/types/params-direct.d.ts.map +0 -1
  187. package/dist/types/prototyping/crypto/types/params-kms.d.ts +0 -63
  188. package/dist/types/prototyping/crypto/types/params-kms.d.ts.map +0 -1
  189. package/dist/types/prototyping/crypto/utils.d.ts +0 -7
  190. package/dist/types/prototyping/crypto/utils.d.ts.map +0 -1
  191. package/dist/types/prototyping/dids/resolver-cache-memory.d.ts +0 -57
  192. package/dist/types/prototyping/dids/resolver-cache-memory.d.ts.map +0 -1
  193. package/dist/types/prototyping/dids/utils.d.ts +0 -3
  194. package/dist/types/prototyping/dids/utils.d.ts.map +0 -1
  195. package/dist/types/rpc-client.d.ts +0 -51
  196. package/dist/types/rpc-client.d.ts.map +0 -1
  197. package/src/dwn-registrar.ts +0 -127
  198. package/src/prototyping/clients/dwn-rpc-types.ts +0 -55
  199. package/src/prototyping/clients/dwn-server-info-cache-memory.ts +0 -79
  200. package/src/prototyping/clients/http-dwn-rpc-client.ts +0 -119
  201. package/src/prototyping/clients/json-rpc-socket.ts +0 -189
  202. package/src/prototyping/clients/json-rpc.ts +0 -113
  203. package/src/prototyping/clients/server-info-types.ts +0 -21
  204. package/src/prototyping/clients/web-socket-clients.ts +0 -103
  205. package/src/prototyping/common/object.ts +0 -15
  206. package/src/prototyping/common/type-utils.ts +0 -6
  207. package/src/prototyping/crypto/algorithms/aes-gcm.ts +0 -211
  208. package/src/prototyping/crypto/algorithms/aes-kw.ts +0 -160
  209. package/src/prototyping/crypto/algorithms/ecdsa.ts +0 -366
  210. package/src/prototyping/crypto/algorithms/eddsa.ts +0 -311
  211. package/src/prototyping/crypto/algorithms/hkdf.ts +0 -38
  212. package/src/prototyping/crypto/algorithms/pbkdf2.ts +0 -41
  213. package/src/prototyping/crypto/crypto-error.ts +0 -45
  214. package/src/prototyping/crypto/types/crypto-api.ts +0 -77
  215. package/src/prototyping/crypto/types/key-converter.ts +0 -53
  216. package/src/prototyping/crypto/types/key-deriver.ts +0 -56
  217. package/src/prototyping/crypto/types/key-io.ts +0 -51
  218. package/src/prototyping/crypto/types/key-manager.ts +0 -83
  219. package/src/prototyping/crypto/types/params-direct.ts +0 -95
  220. package/src/prototyping/crypto/types/params-kms.ts +0 -76
  221. package/src/prototyping/crypto/utils.ts +0 -41
  222. package/src/prototyping/dids/resolver-cache-memory.ts +0 -83
  223. package/src/prototyping/dids/utils.ts +0 -10
  224. package/src/rpc-client.ts +0 -160
@@ -1,83 +0,0 @@
1
- import type {
2
- KeyIdentifier,
3
- KmsDigestParams,
4
- KmsGenerateKeyParams,
5
- KmsGetKeyUriParams,
6
- KmsGetPublicKeyParams,
7
- KmsSignParams,
8
- KmsVerifyParams,
9
- } from '@enbox/crypto';
10
-
11
- import type { DsaApi } from './crypto-api.js';
12
- import type { KmsCipherParams } from './params-kms.js';
13
- // import type { Web5PlatformAgent } from '../../../types/agent.js';
14
-
15
- export interface KeyManagerParams {
16
- CipherInput?: unknown;
17
- GenerateKeyInput?: unknown;
18
- GenerateKeyOutput?: unknown;
19
- GetPublicKeyInput?: unknown;
20
- SignInput?: unknown;
21
- VerifyInput?: unknown;
22
- }
23
-
24
- export interface DefaultKeyManagerParams {
25
- CipherInput: KmsCipherParams;
26
- GenerateKeyInput: KmsGenerateKeyParams;
27
- GenerateKeyOutput: KeyIdentifier;
28
- GetPublicKeyInput: KmsGetPublicKeyParams;
29
- SignInput: KmsSignParams;
30
- VerifyInput: KmsVerifyParams;
31
- }
32
-
33
- /**
34
- * The `KeyManager` interface integrates key generation and signing capabilities.
35
- *
36
- * Concrete implementations of this interface are intended to be used as a Key Management System
37
- * (KMS), which is responsible for generating and storing cryptographic keys. The KMS is also
38
- * responsible for performing cryptographic operations using the keys it manages. The KMS can be
39
- * a local software based KMS, a cloud service, or a hardware device.
40
- *
41
- * Guidelines for implementing this interface:
42
- * - Must use JSON Web Keys ({@link Jwk | JWK}) as the key format.
43
- * - Must IANA registered JSON Object Signing and Encryption
44
- * {@ link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | (JOSE)}
45
- * names for algorithm, curves, etc. whenever possible.
46
- * - All I/O that interacts with private or secret keys must be done via reference using a
47
- * {@link KeyIdentifier | `KeyIdentifier`}. Implementations can use any string as the key
48
- * identifier (e.g. JWK thumbprint, UUID generated by hosted KMS, etc.).
49
- * - Must support key generation an signing operations.
50
- * - May be extended to support other cryptographic operations.
51
- * - Implementations of the `CryptoApi` interface can be passed as an argument to the public API
52
- * methods of Web5 libraries that involve key material (e.g., DID creation, VC signing, arbitrary
53
- * data signing/verification, etc.).
54
- *
55
- * @example
56
- * ```ts
57
- * // Example of using the KeyManager interface with default types
58
- * class DefaultKeyManager implements KeyManager {} // Uses default types
59
- *
60
- * // Example of using the KeyManager interface with custom types
61
- * class CustomKeyManager implements KeyManager<{
62
- * GenerateKeyInput: CustomGenerateKeyParams, // Custom type
63
- * KmsGetPublicKeyParams: CustomGetPublicKeyParams, // Custom type
64
- * KmsSignParams: CustomSignParams, // Custom type
65
- * // Omitting KmsVerifyParams to use the default
66
- * }> {
67
- * // Implementation here
68
- * }
69
- * ```
70
- *
71
- * @typeParam T - The type of the key manager parameters.
72
- */
73
- export interface KeyManager<T extends KeyManagerParams = DefaultKeyManagerParams>
74
- extends DsaApi<T['GenerateKeyInput'], T['GenerateKeyOutput'], T['GetPublicKeyInput'], KmsDigestParams, T['SignInput'], T['VerifyInput']> {
75
-
76
- /**
77
- *
78
- * @param params - The parameters for getting the key URI.
79
- * @param params.key - The key to get the URI for.
80
- * @returns The key URI.
81
- */
82
- getKeyUri(params: KmsGetKeyUriParams): Promise<KeyIdentifier>;
83
- }
@@ -1,95 +0,0 @@
1
- import type { Jwk } from '@enbox/crypto';
2
-
3
-
4
- export interface BytesToPrivateKeyParams {
5
- algorithm: AlgorithmIdentifier;
6
- privateKeyBytes: Uint8Array;
7
- }
8
-
9
- export interface BytesToPublicKeyParams {
10
- algorithm: AlgorithmIdentifier;
11
- publicKeyBytes: Uint8Array;
12
- }
13
-
14
- /**
15
- * Parameters for encryption and decryption operations.
16
- *
17
- * Intended for use with a Key Management System.
18
- */
19
- export interface CipherParams {
20
- /** A {@link Jwk} containing the key to be used for encryption or decryption. */
21
- key: Jwk;
22
-
23
- /** Data to be encrypted or decrypted. */
24
- data: Uint8Array;
25
-
26
- /** Additional algorithm-specific parameters for encryption or decryption. */
27
- [key: string]: unknown;
28
- }
29
-
30
- /**
31
- * Parameters for derivation of cryptographic keys.
32
- */
33
- export interface DeriveKeyParams {
34
- /** The algorithm identifier. */
35
- algorithm: AlgorithmIdentifier;
36
-
37
- /** The base key to be used for derivation as a byte array. */
38
- baseKeyBytes: Uint8Array;
39
-
40
- /** The algorithm identifier for the derived key. */
41
- derivedKeyAlgorithm?: AlgorithmIdentifier;
42
-
43
- /** Additional algorithm-specific parameters for key derivation. */
44
- [key: string]: unknown;
45
- }
46
-
47
- /**
48
- * Parameters for derivation of cryptographic byte arrays.
49
- */
50
- export interface DeriveKeyBytesParams {
51
- /** The base key to be used for derivation as a byte array. */
52
- baseKeyBytes: Uint8Array;
53
-
54
- /** The desired length of the derived key in bits. */
55
- length: number;
56
- }
57
-
58
- export interface PrivateKeyToBytesParams {
59
- privateKey: Jwk;
60
- }
61
-
62
- export interface PublicKeyToBytesParams {
63
- publicKey: Jwk;
64
- }
65
-
66
- /**
67
- * Parameters for wrapping a key.
68
- */
69
- export interface WrapKeyParams {
70
- /** A {@link Jwk} containing the key used to encrypt the unwrapped key. */
71
- encryptionKey: Jwk;
72
-
73
- /** A {@link Jwk} containing the private key to be wrapped. */
74
- unwrappedKey: Jwk;
75
-
76
- /** An object defining the algorithm-specific parameters for encrypting the `unwrappedKey`. */
77
- encryptParams?: unknown
78
- }
79
-
80
- /**
81
- * Parameters for unwrapping a key.
82
- */
83
- export interface UnwrapKeyParams {
84
- /** A {@link Jwk} containing the key used to decrypt the unwrapped key. */
85
- decryptionKey: Jwk;
86
-
87
- /** The wrapped private key as a byte array. */
88
- wrappedKeyBytes: Uint8Array;
89
-
90
- /** The algorithm identifier of the key encrypted in `wrappedKeyBytes`. */
91
- wrappedKeyAlgorithm: string;
92
-
93
- /** An object defining the algorithm-specific parameters for decrypting the `wrappedKeyBytes`. */
94
- decryptParams?: unknown;
95
- }
@@ -1,76 +0,0 @@
1
- import type { Jwk, KeyIdentifier } from '@enbox/crypto';
2
-
3
- /**
4
- * Parameters for KMS-based encryption and decryption operations.
5
- *
6
- * Intended for use with a Key Management System.
7
- */
8
- export interface KmsCipherParams {
9
- /** Identifier for the private key in the KMS. */
10
- keyUri: KeyIdentifier;
11
-
12
- /** Data to be encrypted or decrypted. */
13
- data: Uint8Array;
14
- }
15
-
16
- /**
17
- * Parameters for KMS-based derivation of a cryptographic key from a given base key.
18
- *
19
- * Intended for use with a Key Management System.
20
- */
21
- export interface KmsDeriveKeyParams {
22
- /** Identifier for the base key used in derivation in the KMS. */
23
- baseKeyUri: KeyIdentifier;
24
-
25
- /** An object defining the algorithm-specific parameters for the derived key. */
26
- derivedKeyParams: unknown
27
- }
28
-
29
- /**
30
- * Parameters for KMS-based derivation of a byte array from a given base key.
31
- *
32
- * Intended for use with a Key Management System.
33
- */
34
- export interface KmsDeriveKeyBytesParams {
35
- /** Identifier for the base key used in derivation in the KMS. */
36
- baseKeyUri: KeyIdentifier;
37
-
38
- /** The desired length of the derived key in bits. */
39
- length: number;
40
- }
41
-
42
- /**
43
- * Parameters for unwrapping a key using a KMS. Intended for use with a Key Management System.
44
- */
45
- export interface KmsUnwrapKeyParams {
46
- /** Identifier for the private key in the KMS used for decrypting the wrapped key. */
47
- decryptionKeyUri: KeyIdentifier;
48
-
49
- /** The wrapped private key as a byte array. */
50
- wrappedKeyBytes: Uint8Array;
51
-
52
- /** The algorithm identifier of the key encrypted in `wrappedKeyBytes`. */
53
- wrappedKeyAlgorithm: string;
54
-
55
- /** An object defining the algorithm-specific parameters for decrypting the `wrappedKeyBytes`. */
56
- decryptParams?: unknown;
57
- }
58
-
59
- /**
60
- * Parameters for wrapping a key using a KMS. Intended for use with a Key Management System.
61
- */
62
- export interface KmsWrapKeyParams {
63
- /** Identifier for the private key in the KMS used for encrypting the unwrapped key. */
64
- encryptionKeyUri: KeyIdentifier;
65
-
66
- /** A {@link Jwk} containing the private key to be wrapped. */
67
- unwrappedKey: Jwk;
68
-
69
- /** An object defining the algorithm-specific parameters for encrypting the `unwrappedKey`. */
70
- encryptParams?: unknown
71
- }
72
-
73
- export interface KmsDeleteKeyParams {
74
- /** Identifier for the key to be deleted in the KMS. */
75
- keyUri: KeyIdentifier;
76
- }
@@ -1,41 +0,0 @@
1
- import type { Cipher, KeyWrapper } from '@enbox/crypto';
2
-
3
- import type { KeyExporter, KeyImporter } from './types/key-io.js';
4
-
5
- export function isCipher<EncryptInput, DecryptInput>(
6
- obj: unknown
7
- ): obj is Cipher<EncryptInput, DecryptInput> {
8
- return (
9
- obj !== null && typeof obj === 'object'
10
- && 'encrypt' in obj && typeof obj.encrypt === 'function'
11
- && 'decrypt' in obj && typeof obj.decrypt === 'function'
12
- );
13
- }
14
-
15
- export function isKeyExporter<ExportKeyInput, ExportKeyOutput>(
16
- obj: unknown
17
- ): obj is KeyExporter<ExportKeyInput, ExportKeyOutput> {
18
- return (
19
- obj !== null && typeof obj === 'object'
20
- && 'exportKey' in obj && typeof obj.exportKey === 'function'
21
- );
22
- }
23
-
24
- export function isKeyImporter<ImportKeyInput, ImportKeyExport>(
25
- obj: unknown
26
- ): obj is KeyImporter<ImportKeyInput, ImportKeyExport> {
27
- return (
28
- obj !== null && typeof obj === 'object'
29
- && 'importKey' in obj && typeof obj.importKey === 'function'
30
- );
31
- }
32
-
33
- export function isKeyWrapper<WrapKeyInput, UnwrapKeyInput>(
34
- obj: unknown
35
- ): obj is KeyWrapper<WrapKeyInput, UnwrapKeyInput> {
36
- return (
37
- obj !== null && typeof obj === 'object'
38
- && 'wrapKey' in obj && typeof obj.wrapKey === 'function'
39
- && 'unwrapKey' in obj && typeof obj.unwrapKey === 'function'
40
- );
41
- }
@@ -1,83 +0,0 @@
1
- import type { DidResolutionResult, DidResolverCache } from '@enbox/dids';
2
-
3
- import ms from 'ms';
4
- import { TtlCache } from '@enbox/common';
5
-
6
- /**
7
- * Configuration parameters for creating an in-memory cache for DID resolution results.
8
- *
9
- * Allows customization of the cache time-to-live (TTL) setting.
10
- */
11
- export type DidResolverCacheMemoryParams = {
12
- /**
13
- * Optional. The time-to-live for cache entries, expressed as a string (e.g., '1h', '15m').
14
- * Determines how long a cache entry should remain valid before being considered expired.
15
- *
16
- * Defaults to '15m' if not specified.
17
- */
18
- ttl?: string;
19
- };
20
-
21
- export class DidResolverCacheMemory implements DidResolverCache {
22
- private cache: TtlCache<string, DidResolutionResult>;
23
-
24
- constructor({ ttl = '15m' }: DidResolverCacheMemoryParams = {}) {
25
- this.cache = new TtlCache({ ttl: ms(ttl) });
26
- }
27
-
28
- /**
29
- * Retrieves a DID resolution result from the cache.
30
- *
31
- * If the cached item has exceeded its TTL, it's scheduled for deletion and undefined is returned.
32
- *
33
- * @param didUri - The DID string used as the key for retrieving the cached result.
34
- * @returns The cached DID resolution result or undefined if not found or expired.
35
- */
36
- public async get(didUri: string): Promise<DidResolutionResult | void> {
37
- if (!didUri) {
38
- throw new Error('Key cannot be null or undefined');
39
- }
40
-
41
- return this.cache.get(didUri);
42
- }
43
-
44
- /**
45
- * Stores a DID resolution result in the cache with a TTL.
46
- *
47
- * @param didUri - The DID string used as the key for storing the result.
48
- * @param resolutionResult - The DID resolution result to be cached.
49
- * @returns A promise that resolves when the operation is complete.
50
- */
51
- public async set(didUri: string, resolutionResult: DidResolutionResult): Promise<void> {
52
- this.cache.set(didUri, resolutionResult);
53
- }
54
-
55
- /**
56
- * Deletes a DID resolution result from the cache.
57
- *
58
- * @param didUri - The DID string used as the key for deletion.
59
- * @returns A promise that resolves when the operation is complete.
60
- */
61
- public async delete(didUri: string): Promise<void> {
62
- this.cache.delete(didUri);
63
- }
64
-
65
- /**
66
- * Clears all entries from the cache.
67
- *
68
- * @returns A promise that resolves when the operation is complete.
69
- */
70
- public async clear(): Promise<void> {
71
- this.cache.clear();
72
- }
73
-
74
- /**
75
- * This method is a no-op but exists to be consistent with other DID Resolver Cache
76
- * implementations.
77
- *
78
- * @returns A promise that resolves immediately.
79
- */
80
- public async close(): Promise<void> {
81
- // No-op since there is no underlying store to close.
82
- }
83
- }
@@ -1,10 +0,0 @@
1
- import type { PortableDid } from '@enbox/dids';
2
-
3
- export function isPortableDid(obj: unknown): obj is PortableDid {
4
- // Validate that the given value is an object that has the necessary properties of PortableDid.
5
- return !(!obj || typeof obj !== 'object' || obj === null)
6
- && 'uri' in obj
7
- && 'document' in obj
8
- && 'metadata' in obj
9
- && (!('keyManager' in obj) || obj.keyManager === undefined);
10
- }
package/src/rpc-client.ts DELETED
@@ -1,160 +0,0 @@
1
- import type { JsonRpcResponse } from './prototyping/clients/json-rpc.js';
2
- import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './prototyping/clients/dwn-rpc-types.js';
3
- import type { DwnServerInfoRpc, ServerInfo } from './prototyping/clients/server-info-types.js';
4
-
5
- import { createJsonRpcRequest } from './prototyping/clients/json-rpc.js';
6
- import { CryptoUtils } from '@enbox/crypto';
7
- import { HttpDwnRpcClient } from './prototyping/clients/http-dwn-rpc-client.js';
8
- import { WebSocketDwnRpcClient } from './prototyping/clients/web-socket-clients.js';
9
-
10
- /**
11
- * Interface that can be implemented to communicate with {@link Web5Agent | Web5 Agent}
12
- * implementations via JSON-RPC.
13
- */
14
- export interface DidRpc {
15
- get transportProtocols(): string[]
16
- sendDidRequest(request: DidRpcRequest): Promise<DidRpcResponse>
17
- }
18
-
19
- export enum DidRpcMethod {
20
- Create = 'did.create',
21
- Resolve = 'did.resolve'
22
- }
23
-
24
- export type DidRpcRequest = {
25
- data: string;
26
- method: DidRpcMethod;
27
- url: string;
28
- };
29
-
30
- export type DidRpcResponse = {
31
- data?: string;
32
- ok: boolean;
33
- status: RpcStatus;
34
- };
35
-
36
- export type RpcStatus = {
37
- code: number;
38
- message: string;
39
- };
40
-
41
- export interface Web5Rpc extends DwnRpc, DidRpc, DwnServerInfoRpc {}
42
-
43
- /**
44
- * Client used to communicate with Dwn Servers
45
- */
46
- export class Web5RpcClient implements Web5Rpc {
47
- private transportClients: Map<string, Web5Rpc>;
48
-
49
- constructor(clients: Web5Rpc[] = []) {
50
- this.transportClients = new Map();
51
-
52
- // include http and socket clients as default.
53
- // can be overwritten for 'http:', 'https:', 'ws: or ':wss' if instantiated with other clients.
54
- clients = [new HttpWeb5RpcClient(), new WebSocketWeb5RpcClient(), ...clients];
55
-
56
- for (const client of clients) {
57
- for (const transportScheme of client.transportProtocols) {
58
- this.transportClients.set(transportScheme, client);
59
- }
60
- }
61
- }
62
-
63
- get transportProtocols(): string[] {
64
- return Array.from(this.transportClients.keys());
65
- }
66
-
67
- async sendDidRequest(request: DidRpcRequest): Promise<DidRpcResponse> {
68
- // URL() will throw if provided `url` is invalid.
69
- const url = new URL(request.url);
70
-
71
- const transportClient = this.transportClients.get(url.protocol);
72
- if (!transportClient) {
73
- const error = new Error(`no ${url.protocol} transport client available`);
74
- error.name = 'NO_TRANSPORT_CLIENT';
75
-
76
- throw error;
77
- }
78
-
79
- return transportClient.sendDidRequest(request);
80
- }
81
-
82
- sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse> {
83
- // will throw if url is invalid
84
- const url = new URL(request.dwnUrl);
85
-
86
- const transportClient = this.transportClients.get(url.protocol);
87
- if (!transportClient) {
88
- const error = new Error(`no ${url.protocol} transport client available`);
89
- error.name = 'NO_TRANSPORT_CLIENT';
90
-
91
- throw error;
92
- }
93
-
94
- return transportClient.sendDwnRequest(request);
95
- }
96
-
97
- async getServerInfo(dwnUrl: string): Promise<ServerInfo> {
98
- // will throw if url is invalid
99
- const url = new URL(dwnUrl);
100
-
101
- const transportClient = this.transportClients.get(url.protocol);
102
- if (!transportClient) {
103
- const error = new Error(`no ${url.protocol} transport client available`);
104
- error.name = 'NO_TRANSPORT_CLIENT';
105
-
106
- throw error;
107
- }
108
-
109
- return transportClient.getServerInfo(dwnUrl);
110
- }
111
- }
112
-
113
- export class HttpWeb5RpcClient extends HttpDwnRpcClient implements Web5Rpc {
114
- async sendDidRequest(request: DidRpcRequest): Promise<DidRpcResponse> {
115
- const requestId = CryptoUtils.randomUuid();
116
- const jsonRpcRequest = createJsonRpcRequest(requestId, request.method, {
117
- data: request.data
118
- });
119
-
120
- const httpRequest = new Request(request.url, {
121
- method : 'POST',
122
- headers : {
123
- 'Content-Type': 'application/json',
124
- },
125
- body: JSON.stringify(jsonRpcRequest),
126
- });
127
-
128
- let jsonRpcResponse: JsonRpcResponse;
129
-
130
- try {
131
- const response = await fetch(httpRequest);
132
-
133
- if (response.ok) {
134
- jsonRpcResponse = await response.json();
135
-
136
- // If the response is an error, throw an error.
137
- if (jsonRpcResponse.error) {
138
- const { code, message } = jsonRpcResponse.error;
139
- throw new Error(`JSON RPC (${code}) - ${message}`);
140
- }
141
- } else {
142
- throw new Error(`HTTP (${response.status}) - ${response.statusText}`);
143
- }
144
- } catch (error: any) {
145
- throw new Error(`Error encountered while processing response from ${request.url}: ${error.message}`);
146
- }
147
-
148
- return jsonRpcResponse.result as DidRpcResponse;
149
- }
150
- }
151
-
152
- export class WebSocketWeb5RpcClient extends WebSocketDwnRpcClient implements Web5Rpc {
153
- async sendDidRequest(_request: DidRpcRequest): Promise<DidRpcResponse> {
154
- throw new Error(`not implemented for transports [${this.transportProtocols.join(', ')}]`);
155
- }
156
-
157
- async getServerInfo(_dwnUrl: string): Promise<ServerInfo> {
158
- throw new Error(`not implemented for transports [${this.transportProtocols.join(', ')}]`);
159
- }
160
- }