@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,63 +0,0 @@
1
- import type { Jwk, KeyIdentifier } from '@enbox/crypto';
2
- /**
3
- * Parameters for KMS-based encryption and decryption operations.
4
- *
5
- * Intended for use with a Key Management System.
6
- */
7
- export interface KmsCipherParams {
8
- /** Identifier for the private key in the KMS. */
9
- keyUri: KeyIdentifier;
10
- /** Data to be encrypted or decrypted. */
11
- data: Uint8Array;
12
- }
13
- /**
14
- * Parameters for KMS-based derivation of a cryptographic key from a given base key.
15
- *
16
- * Intended for use with a Key Management System.
17
- */
18
- export interface KmsDeriveKeyParams {
19
- /** Identifier for the base key used in derivation in the KMS. */
20
- baseKeyUri: KeyIdentifier;
21
- /** An object defining the algorithm-specific parameters for the derived key. */
22
- derivedKeyParams: unknown;
23
- }
24
- /**
25
- * Parameters for KMS-based derivation of a byte array from a given base key.
26
- *
27
- * Intended for use with a Key Management System.
28
- */
29
- export interface KmsDeriveKeyBytesParams {
30
- /** Identifier for the base key used in derivation in the KMS. */
31
- baseKeyUri: KeyIdentifier;
32
- /** The desired length of the derived key in bits. */
33
- length: number;
34
- }
35
- /**
36
- * Parameters for unwrapping a key using a KMS. Intended for use with a Key Management System.
37
- */
38
- export interface KmsUnwrapKeyParams {
39
- /** Identifier for the private key in the KMS used for decrypting the wrapped key. */
40
- decryptionKeyUri: KeyIdentifier;
41
- /** The wrapped private key as a byte array. */
42
- wrappedKeyBytes: Uint8Array;
43
- /** The algorithm identifier of the key encrypted in `wrappedKeyBytes`. */
44
- wrappedKeyAlgorithm: string;
45
- /** An object defining the algorithm-specific parameters for decrypting the `wrappedKeyBytes`. */
46
- decryptParams?: unknown;
47
- }
48
- /**
49
- * Parameters for wrapping a key using a KMS. Intended for use with a Key Management System.
50
- */
51
- export interface KmsWrapKeyParams {
52
- /** Identifier for the private key in the KMS used for encrypting the unwrapped key. */
53
- encryptionKeyUri: KeyIdentifier;
54
- /** A {@link Jwk} containing the private key to be wrapped. */
55
- unwrappedKey: Jwk;
56
- /** An object defining the algorithm-specific parameters for encrypting the `unwrappedKey`. */
57
- encryptParams?: unknown;
58
- }
59
- export interface KmsDeleteKeyParams {
60
- /** Identifier for the key to be deleted in the KMS. */
61
- keyUri: KeyIdentifier;
62
- }
63
- //# sourceMappingURL=params-kms.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"params-kms.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/types/params-kms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,MAAM,EAAE,aAAa,CAAC;IAEtB,yCAAyC;IACzC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,UAAU,EAAE,aAAa,CAAC;IAE1B,gFAAgF;IAChF,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,iEAAiE;IACjE,UAAU,EAAE,aAAa,CAAC;IAE1B,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,qFAAqF;IACrF,gBAAgB,EAAE,aAAa,CAAC;IAEhC,+CAA+C;IAC/C,eAAe,EAAE,UAAU,CAAC;IAE5B,0EAA0E;IAC1E,mBAAmB,EAAE,MAAM,CAAC;IAE5B,iGAAiG;IACjG,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uFAAuF;IACvF,gBAAgB,EAAE,aAAa,CAAC;IAEhC,8DAA8D;IAC9D,YAAY,EAAE,GAAG,CAAC;IAElB,8FAA8F;IAC9F,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,MAAM,EAAE,aAAa,CAAC;CACvB"}
@@ -1,7 +0,0 @@
1
- import type { Cipher, KeyWrapper } from '@enbox/crypto';
2
- import type { KeyExporter, KeyImporter } from './types/key-io.js';
3
- export declare function isCipher<EncryptInput, DecryptInput>(obj: unknown): obj is Cipher<EncryptInput, DecryptInput>;
4
- export declare function isKeyExporter<ExportKeyInput, ExportKeyOutput>(obj: unknown): obj is KeyExporter<ExportKeyInput, ExportKeyOutput>;
5
- export declare function isKeyImporter<ImportKeyInput, ImportKeyExport>(obj: unknown): obj is KeyImporter<ImportKeyInput, ImportKeyExport>;
6
- export declare function isKeyWrapper<WrapKeyInput, UnwrapKeyInput>(obj: unknown): obj is KeyWrapper<WrapKeyInput, UnwrapKeyInput>;
7
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/prototyping/crypto/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElE,wBAAgB,QAAQ,CAAC,YAAY,EAAE,YAAY,EACjD,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,CAM3C;AAED,wBAAgB,aAAa,CAAC,cAAc,EAAE,eAAe,EAC3D,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,WAAW,CAAC,cAAc,EAAE,eAAe,CAAC,CAKrD;AAED,wBAAgB,aAAa,CAAC,cAAc,EAAE,eAAe,EAC3D,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,WAAW,CAAC,cAAc,EAAE,eAAe,CAAC,CAKrD;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,cAAc,EACvD,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,UAAU,CAAC,YAAY,EAAE,cAAc,CAAC,CAMjD"}
@@ -1,57 +0,0 @@
1
- import type { DidResolutionResult, DidResolverCache } from '@enbox/dids';
2
- /**
3
- * Configuration parameters for creating an in-memory cache for DID resolution results.
4
- *
5
- * Allows customization of the cache time-to-live (TTL) setting.
6
- */
7
- export type DidResolverCacheMemoryParams = {
8
- /**
9
- * Optional. The time-to-live for cache entries, expressed as a string (e.g., '1h', '15m').
10
- * Determines how long a cache entry should remain valid before being considered expired.
11
- *
12
- * Defaults to '15m' if not specified.
13
- */
14
- ttl?: string;
15
- };
16
- export declare class DidResolverCacheMemory implements DidResolverCache {
17
- private cache;
18
- constructor({ ttl }?: DidResolverCacheMemoryParams);
19
- /**
20
- * Retrieves a DID resolution result from the cache.
21
- *
22
- * If the cached item has exceeded its TTL, it's scheduled for deletion and undefined is returned.
23
- *
24
- * @param didUri - The DID string used as the key for retrieving the cached result.
25
- * @returns The cached DID resolution result or undefined if not found or expired.
26
- */
27
- get(didUri: string): Promise<DidResolutionResult | void>;
28
- /**
29
- * Stores a DID resolution result in the cache with a TTL.
30
- *
31
- * @param didUri - The DID string used as the key for storing the result.
32
- * @param resolutionResult - The DID resolution result to be cached.
33
- * @returns A promise that resolves when the operation is complete.
34
- */
35
- set(didUri: string, resolutionResult: DidResolutionResult): Promise<void>;
36
- /**
37
- * Deletes a DID resolution result from the cache.
38
- *
39
- * @param didUri - The DID string used as the key for deletion.
40
- * @returns A promise that resolves when the operation is complete.
41
- */
42
- delete(didUri: string): Promise<void>;
43
- /**
44
- * Clears all entries from the cache.
45
- *
46
- * @returns A promise that resolves when the operation is complete.
47
- */
48
- clear(): Promise<void>;
49
- /**
50
- * This method is a no-op but exists to be consistent with other DID Resolver Cache
51
- * implementations.
52
- *
53
- * @returns A promise that resolves immediately.
54
- */
55
- close(): Promise<void>;
56
- }
57
- //# sourceMappingURL=resolver-cache-memory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver-cache-memory.d.ts","sourceRoot":"","sources":["../../../../src/prototyping/dids/resolver-cache-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKzE;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,KAAK,CAAwC;gBAEzC,EAAE,GAAW,EAAE,GAAE,4BAAiC;IAI9D;;;;;;;OAOG;IACU,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAQrE;;;;;;OAMG;IACU,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItF;;;;;OAKG;IACU,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD;;;;OAIG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC;;;;;OAKG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
@@ -1,3 +0,0 @@
1
- import type { PortableDid } from '@enbox/dids';
2
- export declare function isPortableDid(obj: unknown): obj is PortableDid;
3
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/prototyping/dids/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAO9D"}
@@ -1,51 +0,0 @@
1
- import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './prototyping/clients/dwn-rpc-types.js';
2
- import type { DwnServerInfoRpc, ServerInfo } from './prototyping/clients/server-info-types.js';
3
- import { HttpDwnRpcClient } from './prototyping/clients/http-dwn-rpc-client.js';
4
- import { WebSocketDwnRpcClient } from './prototyping/clients/web-socket-clients.js';
5
- /**
6
- * Interface that can be implemented to communicate with {@link Web5Agent | Web5 Agent}
7
- * implementations via JSON-RPC.
8
- */
9
- export interface DidRpc {
10
- get transportProtocols(): string[];
11
- sendDidRequest(request: DidRpcRequest): Promise<DidRpcResponse>;
12
- }
13
- export declare enum DidRpcMethod {
14
- Create = "did.create",
15
- Resolve = "did.resolve"
16
- }
17
- export type DidRpcRequest = {
18
- data: string;
19
- method: DidRpcMethod;
20
- url: string;
21
- };
22
- export type DidRpcResponse = {
23
- data?: string;
24
- ok: boolean;
25
- status: RpcStatus;
26
- };
27
- export type RpcStatus = {
28
- code: number;
29
- message: string;
30
- };
31
- export interface Web5Rpc extends DwnRpc, DidRpc, DwnServerInfoRpc {
32
- }
33
- /**
34
- * Client used to communicate with Dwn Servers
35
- */
36
- export declare class Web5RpcClient implements Web5Rpc {
37
- private transportClients;
38
- constructor(clients?: Web5Rpc[]);
39
- get transportProtocols(): string[];
40
- sendDidRequest(request: DidRpcRequest): Promise<DidRpcResponse>;
41
- sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse>;
42
- getServerInfo(dwnUrl: string): Promise<ServerInfo>;
43
- }
44
- export declare class HttpWeb5RpcClient extends HttpDwnRpcClient implements Web5Rpc {
45
- sendDidRequest(request: DidRpcRequest): Promise<DidRpcResponse>;
46
- }
47
- export declare class WebSocketWeb5RpcClient extends WebSocketDwnRpcClient implements Web5Rpc {
48
- sendDidRequest(_request: DidRpcRequest): Promise<DidRpcResponse>;
49
- getServerInfo(_dwnUrl: string): Promise<ServerInfo>;
50
- }
51
- //# sourceMappingURL=rpc-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../src/rpc-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAI/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAEpF;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,kBAAkB,IAAI,MAAM,EAAE,CAAA;IAClC,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAChE;AAED,oBAAY,YAAY;IACtB,MAAM,eAAe;IACrB,OAAO,gBAAgB;CACxB;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,OAAQ,SAAQ,MAAM,EAAE,MAAM,EAAE,gBAAgB;CAAG;AAEpE;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,gBAAgB,CAAuB;gBAEnC,OAAO,GAAE,OAAO,EAAO;IAcnC,IAAI,kBAAkB,IAAI,MAAM,EAAE,CAEjC;IAEK,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAerE,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAezD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAczD;AAED,qBAAa,iBAAkB,SAAQ,gBAAiB,YAAW,OAAO;IAClE,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;CAoCtE;AAED,qBAAa,sBAAuB,SAAQ,qBAAsB,YAAW,OAAO;IAC5E,cAAc,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAIhE,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAG1D"}
@@ -1,127 +0,0 @@
1
- import { concatenateUrl } from './utils.js';
2
- import { Convert } from '@enbox/common';
3
- import { CryptoUtils, Sha256 } from '@enbox/crypto';
4
-
5
- /**
6
- * A client for registering tenants with a DWN.
7
- */
8
- export class DwnRegistrar {
9
- /**
10
- * Registers a new tenant with the given DWN.
11
- * NOTE: Assumes the user has already accepted the terms of service.
12
- * NOTE: Currently the DWN Server from `dwn-server` does not require user signature.
13
- * TODO: bring in types from `dwn-server`.
14
- */
15
- public static async registerTenant(dwnEndpoint: string, did: string): Promise<void> {
16
-
17
- const registrationEndpoint = concatenateUrl(dwnEndpoint, 'registration');
18
- const termsOfUseEndpoint = concatenateUrl(registrationEndpoint, 'terms-of-service');
19
- const proofOfWorkEndpoint = concatenateUrl(registrationEndpoint, 'proof-of-work');
20
-
21
- // fetch the terms-of-service
22
- const termsOfServiceGetResponse = await fetch(termsOfUseEndpoint, {
23
- method: 'GET',
24
- });
25
-
26
- if (termsOfServiceGetResponse.status !== 200) {
27
- const statusCode = termsOfServiceGetResponse.status;
28
- const statusText = termsOfServiceGetResponse.statusText;
29
- const errorText = await termsOfServiceGetResponse.text();
30
- throw new Error(`Failed fetching terms-of-service: ${statusCode} ${statusText}: ${errorText}`);
31
- }
32
- const termsOfServiceFetched = await termsOfServiceGetResponse.text();
33
-
34
- // fetch the proof-of-work challenge
35
- const proofOfWorkChallengeGetResponse = await fetch(proofOfWorkEndpoint, {
36
- method: 'GET',
37
- });
38
- const { challengeNonce, maximumAllowedHashValue } = await proofOfWorkChallengeGetResponse.json();
39
-
40
- // create registration data based on the hash of the terms-of-service and the DID
41
- const registrationData = {
42
- did,
43
- termsOfServiceHash: await DwnRegistrar.hashAsHexString(termsOfServiceFetched),
44
- };
45
-
46
- // compute the proof-of-work response nonce based on the the proof-of-work challenge and the registration data.
47
- const responseNonce = await DwnRegistrar.findQualifiedResponseNonce({
48
- challengeNonce,
49
- maximumAllowedHashValue,
50
- requestData: JSON.stringify(registrationData),
51
- });
52
-
53
- // send the registration request to the server
54
- const registrationRequest = {
55
- registrationData,
56
- proofOfWork: {
57
- challengeNonce,
58
- responseNonce,
59
- },
60
- };
61
-
62
- const registrationResponse = await fetch(registrationEndpoint, {
63
- method : 'POST',
64
- headers : { 'Content-Type': 'application/json' },
65
- body : JSON.stringify(registrationRequest),
66
- });
67
-
68
- if (registrationResponse.status !== 200) {
69
- const statusCode = registrationResponse.status;
70
- const statusText = registrationResponse.statusText;
71
- const errorText = await registrationResponse.text();
72
- throw new Error(`Registration failed: ${statusCode} ${statusText}: ${errorText}`);
73
- }
74
- }
75
-
76
- /**
77
- * Computes the SHA-256 hash of the given array of strings.
78
- */
79
- public static async hashAsHexString(input: string): Promise<string> {
80
- const hashAsBytes = await Sha256.digest({ data: Convert.string(input).toUint8Array() });
81
- const hashAsHex = Convert.uint8Array(hashAsBytes).toHex();
82
- return hashAsHex;
83
- }
84
-
85
- /**
86
- * Finds a response nonce that qualifies the difficulty requirement for the given proof-of-work challenge and request data.
87
- */
88
- public static async findQualifiedResponseNonce(input: {
89
- maximumAllowedHashValue: string;
90
- challengeNonce: string;
91
- requestData: string;
92
- }): Promise<string> {
93
- const startTime = Date.now();
94
-
95
- const { maximumAllowedHashValue, challengeNonce, requestData } = input;
96
- const maximumAllowedHashValueAsBigInt = BigInt(`0x${maximumAllowedHashValue}`);
97
-
98
- let iterations = 1;
99
- let responseNonce;
100
- let qualifiedSolutionNonceFound = false;
101
- do {
102
- responseNonce = await this.generateNonce();
103
- const computedHash = await DwnRegistrar.hashAsHexString(challengeNonce + responseNonce + requestData);
104
- const computedHashAsBigInt = BigInt(`0x${computedHash}`);
105
-
106
- qualifiedSolutionNonceFound = computedHashAsBigInt <= maximumAllowedHashValueAsBigInt;
107
-
108
- iterations++;
109
- } while (!qualifiedSolutionNonceFound);
110
-
111
- // Log final/successful iteration.
112
- console.log(
113
- `iterations: ${iterations}, time lapsed: ${Date.now() - startTime} ms`,
114
- );
115
-
116
- return responseNonce;
117
- }
118
-
119
- /**
120
- * Generates 32 random bytes expressed as a HEX string.
121
- */
122
- public static async generateNonce(): Promise<string> {
123
- const randomBytes = CryptoUtils.randomBytes(32);
124
- const hexString = Convert.uint8Array(randomBytes).toHex().toUpperCase();
125
- return hexString;
126
- }
127
- }
@@ -1,55 +0,0 @@
1
- import type { MessageSubscriptionHandler, RecordsReadReply, RecordSubscriptionHandler, UnionMessageReply } from '@enbox/dwn-sdk-js';
2
-
3
- export interface SerializableDwnMessage {
4
- toJSON(): string;
5
- }
6
-
7
- export type DwnSubscriptionHandler = MessageSubscriptionHandler | RecordSubscriptionHandler;
8
-
9
- /**
10
- * Interface for communicating with {@link https://github.com/enboxorg/enbox | DWN Servers}
11
- * via JSON-RPC, supporting operations like sending DWN requests.
12
- */
13
- export interface DwnRpc {
14
- /**
15
- * Lists the transport protocols supported by the DWN RPC client, such as HTTP or HTTPS.
16
- * @returns An array of strings representing the supported transport protocols.
17
- */
18
- get transportProtocols(): string[]
19
-
20
- /**
21
- * Sends a request to a DWN Server using the specified DWN RPC request parameters.
22
- *
23
- * @param request - The DWN RPC request containing the URL, target DID, message, and optional data.
24
- * @returns A promise that resolves to the response from the DWN server.
25
- */
26
- sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse>
27
- }
28
-
29
-
30
- /**
31
- * Represents a JSON RPC request to a DWN server, including the URL, target DID, the message to be
32
- * processed, and optional data.
33
- */
34
- export type DwnRpcRequest = {
35
- /** Optional data to be sent with the request. */
36
- data?: any;
37
-
38
- /** The URL of the DWN server to which the request is sent. */
39
- dwnUrl: string;
40
-
41
- /** The message to be processed by the DWN server, which can be a serializable DWN message. */
42
- message: SerializableDwnMessage | any;
43
-
44
- /** The DID of the target to which the message is addressed. */
45
- targetDid: string;
46
-
47
- /** Optional subscription handler for DWN message events. */
48
- subscriptionHandler?: DwnSubscriptionHandler;
49
- };
50
-
51
- /**
52
- * Represents the JSON RPC response from a DWN server to a request, combining the results of various
53
- * DWN operations.
54
- */
55
- export type DwnRpcResponse = UnionMessageReply & RecordsReadReply;
@@ -1,79 +0,0 @@
1
-
2
- import ms from 'ms';
3
- import { TtlCache } from '@enbox/common';
4
- import type { DwnServerInfoCache, ServerInfo } from './server-info-types.js';
5
-
6
- /**
7
- * Configuration parameters for creating an in-memory cache for DWN ServerInfo entries.
8
- *
9
- * Allows customization of the cache time-to-live (TTL) setting.
10
- */
11
- export type DwnServerInfoCacheMemoryParams = {
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 DwnServerInfoCacheMemory implements DwnServerInfoCache {
22
- private cache: TtlCache<string, ServerInfo>;
23
-
24
- constructor({ ttl = '15m' }: DwnServerInfoCacheMemoryParams= {}) {
25
- this.cache = new TtlCache({ ttl: ms(ttl) });
26
- }
27
-
28
- /**
29
- * Retrieves a DWN ServerInfo entry 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 dwnUrl - The DWN URL endpoint string used as the key for getting the entry.
34
- * @returns The cached DWN ServerInfo entry or undefined if not found or expired.
35
- */
36
- public async get(dwnUrl: string): Promise<ServerInfo| undefined> {
37
- return this.cache.get(dwnUrl);
38
- }
39
-
40
- /**
41
- * Stores a DWN ServerInfo entry in the cache with a TTL.
42
- *
43
- * @param dwnUrl - The DWN URL endpoint string used as the key for storing the entry.
44
- * @param value - The DWN ServerInfo entry to be cached.
45
- * @returns A promise that resolves when the operation is complete.
46
- */
47
- public async set(dwnUrl: string, value: ServerInfo): Promise<void> {
48
- this.cache.set(dwnUrl, value);
49
- }
50
-
51
- /**
52
- * Deletes a DWN ServerInfo entry from the cache.
53
- *
54
- * @param dwnUrl - The DWN URL endpoint string used as the key for deletion.
55
- * @returns A promise that resolves when the operation is complete.
56
- */
57
- public async delete(dwnUrl: string): Promise<void> {
58
- this.cache.delete(dwnUrl);
59
- }
60
-
61
- /**
62
- * Clears all entries from the cache.
63
- *
64
- * @returns A promise that resolves when the operation is complete.
65
- */
66
- public async clear(): Promise<void> {
67
- this.cache.clear();
68
- }
69
-
70
- /**
71
- * This method is a no-op but exists to be consistent with other DWN ServerInfo Cache
72
- * implementations.
73
- *
74
- * @returns A promise that resolves immediately.
75
- */
76
- public async close(): Promise<void> {
77
- // No-op since there is no underlying store to close.
78
- }
79
- }
@@ -1,119 +0,0 @@
1
- import type { JsonRpcResponse } from './json-rpc.js';
2
- import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './dwn-rpc-types.js';
3
- import type { DwnServerInfoCache, ServerInfo } from './server-info-types.js';
4
-
5
- import { CryptoUtils } from '@enbox/crypto';
6
- import { DataStream } from '@enbox/dwn-sdk-js';
7
- import { DwnServerInfoCacheMemory } from './dwn-server-info-cache-memory.js';
8
- import { createJsonRpcRequest, parseJson } from './json-rpc.js';
9
-
10
- /**
11
- * HTTP client that can be used to communicate with Dwn Servers
12
- */
13
- export class HttpDwnRpcClient implements DwnRpc {
14
- private serverInfoCache: DwnServerInfoCache;
15
- constructor(serverInfoCache?: DwnServerInfoCache) {
16
- this.serverInfoCache = serverInfoCache ?? new DwnServerInfoCacheMemory();
17
- }
18
-
19
- get transportProtocols(): string[] { return ['http:', 'https:']; }
20
-
21
- async sendDwnRequest(request: DwnRpcRequest): Promise<DwnRpcResponse> {
22
- const requestId = CryptoUtils.randomUuid();
23
- const jsonRpcRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', {
24
- target : request.targetDid,
25
- message : request.message
26
- });
27
-
28
- const requestHeaders: Record<string, string> = {
29
- 'dwn-request': JSON.stringify(jsonRpcRequest)
30
- };
31
-
32
- const fetchOpts: RequestInit = {
33
- method : 'POST',
34
- headers : requestHeaders,
35
- };
36
-
37
- if (request.data) {
38
- requestHeaders['content-type'] = 'application/octet-stream';
39
- fetchOpts.body = request.data;
40
- }
41
-
42
- const resp = await fetch(request.dwnUrl, fetchOpts);
43
- let dwnRpcResponse: JsonRpcResponse;
44
-
45
- // When the server streams record data back, the JSON-RPC envelope is in the
46
- // `dwn-response` header and the body is the raw data stream. Otherwise the
47
- // entire JSON-RPC response is the body.
48
- const hasDataStream = resp.headers.has('dwn-response');
49
-
50
- if (hasDataStream) {
51
- const jsonRpcResponse = parseJson(resp.headers.get('dwn-response')!) as JsonRpcResponse;
52
-
53
- if (jsonRpcResponse == null) {
54
- throw new Error(`failed to parse json rpc response. dwn url: ${request.dwnUrl}`);
55
- }
56
-
57
- dwnRpcResponse = jsonRpcResponse;
58
- } else {
59
- const responseBody = await resp.text();
60
- dwnRpcResponse = JSON.parse(responseBody);
61
- }
62
-
63
- if (dwnRpcResponse.error) {
64
- const { code, message } = dwnRpcResponse.error;
65
- throw new Error(`(${code}) - ${message}`);
66
- }
67
-
68
- // Materialise the response body before attaching to the reply.
69
- // Bun (<=1.3.9) has a bug where resp.body.getReader() can intermittently
70
- // return undefined, crashing DataStream.toBytes() in its finally block.
71
- // Buffering via arrayBuffer() is a safe workaround.
72
- // TODO: https://github.com/enboxorg/enbox/issues/90 — remove once Bun ships fix
73
- const { reply } = dwnRpcResponse.result;
74
- if (hasDataStream) {
75
- const bodyBytes = new Uint8Array(await resp.arrayBuffer());
76
- const dataStream = DataStream.fromBytes(bodyBytes);
77
- if (reply.record) {
78
- reply.record.data = dataStream;
79
- } else if (reply.entry) {
80
- reply.entry.data = dataStream;
81
- }
82
- }
83
-
84
- return reply as DwnRpcResponse;
85
- }
86
-
87
- async getServerInfo(dwnUrl: string): Promise<ServerInfo> {
88
- const serverInfo = await this.serverInfoCache.get(dwnUrl);
89
- if (serverInfo) {
90
- return serverInfo;
91
- }
92
-
93
- const url = new URL(dwnUrl);
94
-
95
- // add `/info` to the dwn server url path
96
- url.pathname.endsWith('/') ? url.pathname += 'info' : url.pathname += '/info';
97
-
98
- try {
99
- const response = await fetch(url.toString());
100
- if (response.ok) {
101
- const results = await response.json() as ServerInfo;
102
-
103
- // explicitly return and cache only the desired properties.
104
- const serverInfo = {
105
- registrationRequirements : results.registrationRequirements,
106
- maxFileSize : results.maxFileSize,
107
- webSocketSupport : results.webSocketSupport,
108
- };
109
- this.serverInfoCache.set(dwnUrl, serverInfo);
110
-
111
- return serverInfo;
112
- } else {
113
- throw new Error(`HTTP (${response.status}) - ${response.statusText}`);
114
- }
115
- } catch (error: any) {
116
- throw new Error(`Error encountered while processing response from ${url.toString()}: ${error.message}`);
117
- }
118
- }
119
- }