@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
package/src/dwn-api.ts CHANGED
@@ -3,10 +3,8 @@ import type {
3
3
  DwnConfig,
4
4
  EncryptionInput,
5
5
  EncryptionKeyDeriver,
6
- EventStream,
7
6
  GenericMessage,
8
7
  KeyDecrypter,
9
- MessageStore,
10
8
  ProtocolDefinition,
11
9
  ProtocolRuleSet,
12
10
  ProtocolsQueryReply,
@@ -14,14 +12,13 @@ import type {
14
12
  RecordsQueryReplyEntry,
15
13
  RecordsReadReply,
16
14
  RecordsWrite,
17
- RecordsWriteMessage,
18
- StateIndex } from '@enbox/dwn-sdk-js';
15
+ RecordsWriteMessage } from '@enbox/dwn-sdk-js';
19
16
  import type { KeyIdentifier, PrivateKeyJwk, PublicKeyJwk } from '@enbox/crypto';
20
17
 
21
- import { CryptoUtils } from '@enbox/crypto';
22
18
  import { TtlCache } from '@enbox/common';
23
19
  import {
24
20
  Cid,
21
+ ContentEncryptionAlgorithm,
25
22
  DataStoreLevel,
26
23
  DataStream,
27
24
  Dwn,
@@ -37,9 +34,9 @@ import {
37
34
  Protocols,
38
35
  Records,
39
36
  ResumableTaskStoreLevel,
40
- Secp256k1,
41
37
  StateIndexLevel
42
38
  } from '@enbox/dwn-sdk-js';
39
+ import { CryptoUtils, X25519 } from '@enbox/crypto';
43
40
  import { DidDht, DidJwk, DidResolverCacheLevel, UniversalResolver } from '@enbox/dids';
44
41
 
45
42
  import type { Web5PlatformAgent } from './types/agent.js';
@@ -253,7 +250,7 @@ export class AgentDwnApi {
253
250
 
254
251
  // Reactive root-record upgrade (PR E): if this is an externally-authored
255
252
  // root record with only ProtocolPath encryption, the owner upgrades it by
256
- // appending a ProtocolContext keyEncryption entry so that context key
253
+ // appending a ProtocolContext recipient entry so that context key
257
254
  // holders (including the external author) can also decrypt.
258
255
  const authorDid = Jws.getSignerDid(
259
256
  recordsWriteMessage.authorization.signature.signatures[0]
@@ -299,7 +296,7 @@ export class AgentDwnApi {
299
296
  derivationPath: contextDerivationPath,
300
297
  });
301
298
  const contextDerivedPrivateJwk =
302
- await Secp256k1.privateKeyToJwk(contextDerivedPrivateKeyBytes);
299
+ await X25519.bytesToPrivateKey({ privateKeyBytes: contextDerivedPrivateKeyBytes });
303
300
  const contextKeyPayload: DerivedPrivateJwk = {
304
301
  rootKeyId : keyId,
305
302
  derivationScheme : KeyDerivationScheme.ProtocolContext,
@@ -556,7 +553,7 @@ export class AgentDwnApi {
556
553
  // For cross-DWN writes (target !== author), the external author cannot
557
554
  // derive the target's context key. Root records use the target's ProtocolPath
558
555
  // public key. The target's agent reactively upgrades the record to include a
559
- // ProtocolContext keyEncryption entry. Non-root records extract the context
556
+ // ProtocolContext recipient entry. Non-root records extract the context
560
557
  // public key (derivedPublicKey) from existing ProtocolContext-encrypted records
561
558
  // in the same context on the target's DWN.
562
559
 
@@ -578,6 +575,7 @@ export class AgentDwnApi {
578
575
  dataEncryptionKey: Uint8Array;
579
576
  dataEncryptionIV: Uint8Array;
580
577
  encryptedBytes: Uint8Array;
578
+ authenticationTag: Uint8Array;
581
579
  } | undefined;
582
580
 
583
581
  if (isDwnRequest(request, DwnInterface.RecordsWrite) && request.encryption && !rawMessage) {
@@ -651,12 +649,12 @@ export class AgentDwnApi {
651
649
 
652
650
  // 5. Generate random DEK and IV
653
651
  const dataEncryptionKey = crypto.getRandomValues(new Uint8Array(32));
654
- const dataEncryptionIV = crypto.getRandomValues(new Uint8Array(16));
652
+ const dataEncryptionIV = crypto.getRandomValues(new Uint8Array(12));
655
653
 
656
- // 6. Build EncryptionInput based on the encryption scheme decision
657
- let encryptionInput: EncryptionInput | undefined;
654
+ // 6. Build partial EncryptionInput (authenticationTag added after AEAD encryption)
655
+ let encryptionInput: (Omit<EncryptionInput, 'authenticationTag'> & { authenticationTag?: Uint8Array }) | undefined;
658
656
 
659
- const buildProtocolPathInput = (): EncryptionInput => this.buildEncryptionInput(
657
+ const buildProtocolPathInput = (): Omit<EncryptionInput, 'authenticationTag'> => this.buildEncryptionInput(
660
658
  dataEncryptionKey, dataEncryptionIV,
661
659
  ruleSet.$encryption.rootKeyId, ruleSet.$encryption.publicKeyJwk,
662
660
  KeyDerivationScheme.ProtocolPath,
@@ -667,7 +665,7 @@ export class AgentDwnApi {
667
665
  // External authors cannot derive the target's context key (HKDF requires
668
666
  // the private key). Use the target's ProtocolPath public key from their
669
667
  // protocol definition. The target's agent will reactively upgrade the record
670
- // to include a ProtocolContext keyEncryption entry.
668
+ // to include a ProtocolContext recipient entry.
671
669
  encryptionInput = buildProtocolPathInput();
672
670
 
673
671
  } else if (isCrossDwn && isMultiPartyContext && !isRootRecord) {
@@ -733,8 +731,8 @@ export class AgentDwnApi {
733
731
  encryptionInput = buildProtocolPathInput();
734
732
  }
735
733
 
736
- // 7. Encrypt data with AES-256-CTR and compute CID
737
- const { encryptedBytes, dataCid, dataSize } =
734
+ // 7. Encrypt data with AEAD (AES-256-GCM) and compute CID
735
+ const { encryptedBytes, dataCid, dataSize, authenticationTag } =
738
736
  await this.encryptAndComputeCid(plaintextBytes, dataEncryptionKey, dataEncryptionIV);
739
737
 
740
738
  // 8. Replace plaintext with encrypted data
@@ -745,10 +743,11 @@ export class AgentDwnApi {
745
743
  request.dataStream = undefined;
746
744
 
747
745
  if (encryptionInput) {
748
- messageParams.encryptionInput = encryptionInput;
746
+ encryptionInput.authenticationTag = authenticationTag;
747
+ messageParams.encryptionInput = encryptionInput as EncryptionInput;
749
748
  } else {
750
749
  // Deferred — store info for post-creation encryption
751
- deferredContextEncryption = { dataEncryptionKey, dataEncryptionIV, encryptedBytes };
750
+ deferredContextEncryption = { dataEncryptionKey, dataEncryptionIV, encryptedBytes, authenticationTag };
752
751
  }
753
752
 
754
753
  // 9. For cross-DWN writes in multi-party contexts, attach the author's
@@ -806,7 +805,8 @@ export class AgentDwnApi {
806
805
  deferredContextEncryption.dataEncryptionIV,
807
806
  );
808
807
 
809
- await recordsWriteInstance.encryptSymmetricEncryptionKey(contextEncryptionInput);
808
+ const fullContextInput = { ...contextEncryptionInput, authenticationTag: deferredContextEncryption.authenticationTag };
809
+ await recordsWriteInstance.encryptSymmetricEncryptionKey(fullContextInput as EncryptionInput);
810
810
  await recordsWriteInstance.sign({ signer });
811
811
 
812
812
  // Cache context key info for subsequent writes in this context
@@ -893,7 +893,7 @@ export class AgentDwnApi {
893
893
  * @param didUri - The DID URI to resolve encryption key info for
894
894
  * @returns keyId (fully qualified verification method ID), keyUri (KMS reference),
895
895
  * and publicKeyJwk. No private key material is returned.
896
- * @throws If the DID has no keyAgreement verification method or it's not secp256k1.
896
+ * @throws If the DID has no keyAgreement verification method or it's not X25519.
897
897
  */
898
898
  private async getEncryptionKeyInfo(didUri: string): Promise<{
899
899
  keyId: string;
@@ -914,7 +914,7 @@ export class AgentDwnApi {
914
914
  if (!keyAgreementRefs || keyAgreementRefs.length === 0) {
915
915
  throw new Error(
916
916
  `AgentDwnApi: DID '${didUri}' does not have a keyAgreement ` +
917
- `verification method. Create the identity with a secp256k1 key ` +
917
+ `verification method. Create the identity with an X25519 key ` +
918
918
  `with keyAgreement purpose to use protocol encryption.`
919
919
  );
920
920
  }
@@ -940,12 +940,12 @@ export class AgentDwnApi {
940
940
  );
941
941
  }
942
942
 
943
- // 4. Verify it's a secp256k1 key
943
+ // 4. Verify it's an X25519 key
944
944
  const publicKeyJwk = verificationMethod.publicKeyJwk;
945
- if (publicKeyJwk.crv !== 'secp256k1') {
945
+ if (publicKeyJwk.crv !== 'X25519') {
946
946
  throw new Error(
947
947
  `AgentDwnApi: keyAgreement key for '${didUri}' uses curve ` +
948
- `'${publicKeyJwk.crv}', but DWN encryption requires 'secp256k1'.`
948
+ `'${publicKeyJwk.crv}', but DWN encryption requires 'X25519'.`
949
949
  );
950
950
  }
951
951
 
@@ -960,9 +960,9 @@ export class AgentDwnApi {
960
960
  }
961
961
 
962
962
  /**
963
- * Builds an EncryptionInput object for a single key-encryption entry.
964
- * Consolidates the repeated pattern of assembling DEK, IV, and a single
965
- * keyEncryptionInputs entry into one place.
963
+ * Builds a partial EncryptionInput object for a single key-encryption entry.
964
+ * The `authenticationTag` is NOT set here the caller must set it after
965
+ * AEAD encryption produces the tag.
966
966
  */
967
967
  private buildEncryptionInput(
968
968
  dek: Uint8Array,
@@ -970,7 +970,7 @@ export class AgentDwnApi {
970
970
  publicKeyId: string,
971
971
  publicKey: PublicKeyJwk,
972
972
  derivationScheme: typeof KeyDerivationScheme.ProtocolPath | typeof KeyDerivationScheme.ProtocolContext,
973
- ): EncryptionInput {
973
+ ): Omit<EncryptionInput, 'authenticationTag'> {
974
974
  return {
975
975
  initializationVector : iv,
976
976
  key : dek,
@@ -983,21 +983,22 @@ export class AgentDwnApi {
983
983
  }
984
984
 
985
985
  /**
986
- * Encrypts plaintext bytes with AES-256-CTR and computes the CID of the
987
- * resulting ciphertext. Returns everything needed to attach the encrypted
988
- * data to a DWN message.
986
+ * Encrypts plaintext bytes with AEAD (AES-256-GCM by default) and computes
987
+ * the CID of the resulting ciphertext. Returns everything needed to attach
988
+ * the encrypted data to a DWN message, including the authentication tag.
989
989
  */
990
990
  private async encryptAndComputeCid(
991
991
  plaintextBytes: Uint8Array,
992
992
  dek: Uint8Array,
993
993
  iv: Uint8Array,
994
- ): Promise<{ encryptedBytes: Uint8Array; dataCid: string; dataSize: number }> {
995
- const plaintextStream = DataStream.fromBytes(plaintextBytes);
996
- const encryptedStream = await Encryption.aes256CtrEncrypt(dek, iv, plaintextStream);
997
- const encryptedBytes = await DataStream.toBytes(encryptedStream);
994
+ ): Promise<{ encryptedBytes: Uint8Array; dataCid: string; dataSize: number; authenticationTag: Uint8Array }> {
995
+ const { ciphertextStream, tag: authenticationTag } = await Encryption.aeadEncryptStream(
996
+ ContentEncryptionAlgorithm.A256GCM, dek, iv, DataStream.fromBytes(plaintextBytes),
997
+ );
998
+ const encryptedBytes = await DataStream.toBytes(ciphertextStream);
998
999
  const cidStream = DataStream.fromBytes(encryptedBytes);
999
1000
  const dataCid = await Cid.computeDagPbCidFromStream(cidStream);
1000
- return { encryptedBytes, dataCid, dataSize: encryptedBytes.length };
1001
+ return { encryptedBytes, dataCid, dataSize: encryptedBytes.length, authenticationTag };
1001
1002
  }
1002
1003
 
1003
1004
  /**
@@ -1011,7 +1012,7 @@ export class AgentDwnApi {
1011
1012
  contextId: string,
1012
1013
  dek: Uint8Array,
1013
1014
  iv: Uint8Array,
1014
- ): Promise<{ encryptionInput: EncryptionInput; keyId: string; keyUri: KeyIdentifier; contextDerivationPath: string[] }> {
1015
+ ): Promise<{ encryptionInput: Omit<EncryptionInput, 'authenticationTag'>; keyId: string; keyUri: KeyIdentifier; contextDerivationPath: string[] }> {
1015
1016
  const { keyId, keyUri } = await this.getEncryptionKeyInfo(didUri);
1016
1017
  const contextDerivationPath =
1017
1018
  Records.constructKeyDerivationPathUsingProtocolContextScheme(contextId);
@@ -1028,7 +1029,7 @@ export class AgentDwnApi {
1028
1029
  }
1029
1030
 
1030
1031
  /**
1031
- * Builds a KMS-backed ECIES decrypt callback. Used for both ProtocolPath
1032
+ * Builds a KMS-backed JWE key unwrap callback. Used for both ProtocolPath
1032
1033
  * and ProtocolContext decryption where the KMS holds the root private key.
1033
1034
  */
1034
1035
  private buildKmsDecryptCallback(
@@ -1040,14 +1041,12 @@ export class AgentDwnApi {
1040
1041
  return {
1041
1042
  rootKeyId : keyId,
1042
1043
  derivationScheme,
1043
- decrypt : async (fullDerivationPath, eciesPayload): Promise<Uint8Array> => {
1044
- return keyManager.eciesSecp256k1Decrypt({
1044
+ decrypt : async (fullDerivationPath, jwePayload): Promise<Uint8Array> => {
1045
+ return keyManager.jweKeyUnwrap({
1045
1046
  keyUri,
1046
- derivationPath : fullDerivationPath,
1047
- ciphertext : eciesPayload.ciphertext,
1048
- ephemeralPublicKey : eciesPayload.ephemeralPublicKey,
1049
- initializationVector : eciesPayload.initializationVector,
1050
- messageAuthenticationCode : eciesPayload.messageAuthenticationCode,
1047
+ derivationPath : fullDerivationPath,
1048
+ encryptedKey : jwePayload.encryptedKey,
1049
+ ephemeralPublicKey : jwePayload.ephemeralPublicKey,
1051
1050
  });
1052
1051
  },
1053
1052
  };
@@ -1384,18 +1383,18 @@ export class AgentDwnApi {
1384
1383
  return undefined;
1385
1384
  }
1386
1385
 
1387
- // Search entries for one with a ProtocolContext keyEncryption entry
1386
+ // Search entries for one with a ProtocolContext recipient entry
1388
1387
  // that includes derivedPublicKey
1389
1388
  for (const entry of queryReply.entries) {
1390
- if (entry.encryption?.keyEncryption) {
1391
- const contextEntry = entry.encryption.keyEncryption.find(
1392
- (k: { derivationScheme: string; derivedPublicKey?: PublicKeyJwk }) =>
1393
- k.derivationScheme === KeyDerivationScheme.ProtocolContext && k.derivedPublicKey
1389
+ if (entry.encryption?.recipients) {
1390
+ const contextEntry = entry.encryption.recipients.find(
1391
+ (r: { header: { derivationScheme: string; derivedPublicKey?: PublicKeyJwk } }) =>
1392
+ r.header.derivationScheme === KeyDerivationScheme.ProtocolContext && r.header.derivedPublicKey
1394
1393
  );
1395
- if (contextEntry?.derivedPublicKey) {
1394
+ if (contextEntry?.header.derivedPublicKey) {
1396
1395
  return {
1397
- rootKeyId : contextEntry.rootKeyId,
1398
- derivedPublicKey : contextEntry.derivedPublicKey,
1396
+ rootKeyId : contextEntry.header.kid,
1397
+ derivedPublicKey : contextEntry.header.derivedPublicKey,
1399
1398
  };
1400
1399
  }
1401
1400
  }
@@ -1406,7 +1405,7 @@ export class AgentDwnApi {
1406
1405
 
1407
1406
  /**
1408
1407
  * Reactively upgrades an externally-authored root record that has only
1409
- * ProtocolPath encryption by appending a ProtocolContext keyEncryption entry.
1408
+ * ProtocolPath encryption by appending a ProtocolContext recipient entry.
1410
1409
  *
1411
1410
  * After the upgrade, both the owner (ProtocolPath) and context key holders —
1412
1411
  * including the external author (ProtocolContext) — can decrypt the record.
@@ -1415,7 +1414,7 @@ export class AgentDwnApi {
1415
1414
  * 1. Decrypt the DEK using the owner's ProtocolPath-derived private key
1416
1415
  * 2. Derive the context public key from the owner's #enc key
1417
1416
  * 3. ECIES-encrypt the same DEK to the context public key
1418
- * 4. Append the ProtocolContext keyEncryption entry (using PR 0b append mode)
1417
+ * 4. Append the ProtocolContext recipient entry (using PR 0b append mode)
1419
1418
  * 5. Re-sign the record as owner
1420
1419
  *
1421
1420
  * The author's signature payload includes an `encryptionCid` that becomes
@@ -1441,20 +1440,20 @@ export class AgentDwnApi {
1441
1440
  if (!encryption) { return; }
1442
1441
 
1443
1442
  // Verify: has ProtocolPath but NOT ProtocolContext
1444
- const hasProtocolPath = encryption.keyEncryption.some(
1445
- (k: { derivationScheme: string }) => k.derivationScheme === KeyDerivationScheme.ProtocolPath
1443
+ const hasProtocolPath = encryption.recipients.some(
1444
+ (r: { header: { derivationScheme: string } }) => r.header.derivationScheme === KeyDerivationScheme.ProtocolPath
1446
1445
  );
1447
- const hasProtocolContext = encryption.keyEncryption.some(
1448
- (k: { derivationScheme: string }) => k.derivationScheme === KeyDerivationScheme.ProtocolContext
1446
+ const hasProtocolContext = encryption.recipients.some(
1447
+ (r: { header: { derivationScheme: string } }) => r.header.derivationScheme === KeyDerivationScheme.ProtocolContext
1449
1448
  );
1450
1449
  if (!hasProtocolPath || hasProtocolContext) { return; }
1451
1450
 
1452
1451
  // 1. Decrypt the DEK using the owner's ProtocolPath key
1453
1452
  const keyDecrypter = await this.getKeyDecrypter(tenantDid);
1454
1453
 
1455
- // Find the ProtocolPath keyEncryption entry
1456
- const pathEntry = encryption.keyEncryption.find(
1457
- (k: { derivationScheme: string }) => k.derivationScheme === KeyDerivationScheme.ProtocolPath
1454
+ // Find the ProtocolPath recipient entry
1455
+ const pathRecipient = encryption.recipients.find(
1456
+ (r: { header: { derivationScheme: string } }) => r.header.derivationScheme === KeyDerivationScheme.ProtocolPath
1458
1457
  )!;
1459
1458
 
1460
1459
  const fullDerivationPath = Records.constructKeyDerivationPathUsingProtocolPathScheme(
@@ -1464,30 +1463,31 @@ export class AgentDwnApi {
1464
1463
  const dataEncryptionKey = await keyDecrypter.decrypt(
1465
1464
  fullDerivationPath,
1466
1465
  {
1467
- ciphertext : Encoder.base64UrlToBytes(pathEntry.encryptedKey),
1468
- ephemeralPublicKey : Secp256k1.publicJwkToBytes(pathEntry.ephemeralPublicKey),
1469
- initializationVector : Encoder.base64UrlToBytes(pathEntry.initializationVector),
1470
- messageAuthenticationCode : Encoder.base64UrlToBytes(pathEntry.messageAuthenticationCode),
1466
+ encryptedKey : Encoder.base64UrlToBytes(pathRecipient.encrypted_key),
1467
+ ephemeralPublicKey : pathRecipient.header.epk,
1471
1468
  },
1472
1469
  );
1473
1470
 
1474
1471
  // 2. Derive the context public key — contextId = recordId for root records
1475
1472
  const contextId = recordsWrite.recordId;
1476
- const encryptionIV = Encoder.base64UrlToBytes(encryption.initializationVector);
1473
+ const encryptionIV = Encoder.base64UrlToBytes(encryption.iv);
1477
1474
 
1478
- // 3 & 4. Append the ProtocolContext keyEncryption entry using append mode.
1475
+ // 3 & 4. Append the ProtocolContext recipient entry using append mode.
1479
1476
  // Append mode preserves the author's identity and authorization so that
1480
1477
  // signAsOwner() can be called in step 5.
1481
1478
  const { encryptionInput: contextEncryptionInput, keyId, keyUri, contextDerivationPath } =
1482
1479
  await this.deriveContextEncryptionInput(tenantDid, contextId, dataEncryptionKey, encryptionIV);
1483
1480
 
1481
+ // Set the authentication tag from the existing JWE encryption property
1482
+ const fullContextInput = { ...contextEncryptionInput, authenticationTag: Encoder.base64UrlToBytes(encryption.tag) };
1483
+
1484
1484
  // Parse the message to get a RecordsWrite instance we can mutate
1485
1485
  const recordsWriteInstance = await dwnMessageConstructors[DwnInterface.RecordsWrite].parse(
1486
1486
  recordsWrite,
1487
1487
  ) as unknown as RecordsWrite;
1488
1488
 
1489
1489
  await recordsWriteInstance.encryptSymmetricEncryptionKey(
1490
- contextEncryptionInput,
1490
+ fullContextInput as EncryptionInput,
1491
1491
  { append: true },
1492
1492
  );
1493
1493
 
@@ -1505,35 +1505,44 @@ export class AgentDwnApi {
1505
1505
  // We must also update the state index and event stream to keep sync and
1506
1506
  // real-time subscribers consistent — without this, the upgraded record
1507
1507
  // would never propagate to remote DWNs or notify subscribers.
1508
- const dwnInternal = this._dwn as any;
1509
- const messageStore = dwnInternal.messageStore as MessageStore;
1510
- const stateIndex = dwnInternal.stateIndex as StateIndex;
1511
- const eventStream = dwnInternal.eventStream as EventStream | undefined;
1508
+ const { messageStore, stateIndex, eventStream } = this._dwn.storage;
1509
+
1510
+ // Validate the upgrade only changed encryption and authorization fields.
1511
+ // The descriptor, recordId, contextId, and data must remain identical.
1512
+ // Note: parse() may produce a new descriptor object, so we compare by value.
1513
+ const upgradedMessage = recordsWriteInstance.message as RecordsQueryReplyEntry;
1514
+ if (JSON.stringify(upgradedMessage.descriptor) !== JSON.stringify(recordsWrite.descriptor)) {
1515
+ throw new Error('AgentDwnApi: upgradeExternalRootRecord() must not modify the descriptor.');
1516
+ }
1517
+ if (upgradedMessage.recordId !== recordsWrite.recordId) {
1518
+ throw new Error('AgentDwnApi: upgradeExternalRootRecord() must not modify the recordId.');
1519
+ }
1512
1520
 
1513
1521
  // Fetch the stored original (which carries encodedData for small payloads)
1514
1522
  const originalCid = await Message.getCid(recordsWrite);
1515
1523
  const storedOriginal = await messageStore.get(tenantDid, originalCid) as RecordsQueryReplyEntry | undefined;
1516
1524
 
1517
- // Remove the original message and its state index entry
1518
- await messageStore.delete(tenantDid, originalCid);
1519
- await stateIndex.delete(tenantDid, [originalCid]);
1520
-
1521
1525
  // Build indexes for the upgraded message (mark as latest base state)
1522
1526
  const isLatestBaseState = true;
1523
1527
  const upgradedIndexes = await recordsWriteInstance.constructIndexes(isLatestBaseState);
1524
1528
 
1525
1529
  // Carry over the encoded data from the stored original (the handler
1526
1530
  // base64url-encodes small payloads into encodedData during processMessage)
1527
- const upgradedMessage = recordsWriteInstance.message as RecordsQueryReplyEntry;
1528
1531
  if (storedOriginal?.encodedData) {
1529
1532
  upgradedMessage.encodedData = storedOriginal.encodedData;
1530
1533
  }
1531
1534
 
1532
- // Store the upgraded message and insert into state index
1533
- await messageStore.put(tenantDid, upgradedMessage, upgradedIndexes);
1535
+ // Use put-before-delete ordering: if a crash occurs after the put but
1536
+ // before the delete, we end up with a duplicate (recoverable via the
1537
+ // isLatestBaseState index) rather than data loss (unrecoverable).
1534
1538
  const upgradedCid = await Message.getCid(upgradedMessage);
1539
+ await messageStore.put(tenantDid, upgradedMessage, upgradedIndexes);
1535
1540
  await stateIndex.insert(tenantDid, upgradedCid, upgradedIndexes);
1536
1541
 
1542
+ // Now remove the original message and its state index entry.
1543
+ await messageStore.delete(tenantDid, originalCid);
1544
+ await stateIndex.delete(tenantDid, [originalCid]);
1545
+
1537
1546
  // Notify real-time subscribers (mirrors handler behavior)
1538
1547
  if (eventStream !== undefined) {
1539
1548
  eventStream.emit(tenantDid, { message: upgradedMessage }, upgradedIndexes);
@@ -1559,8 +1568,8 @@ export class AgentDwnApi {
1559
1568
  const { encryption } = recordsWrite;
1560
1569
 
1561
1570
  // Check if the record uses context-derived encryption
1562
- const hasContextKey = encryption?.keyEncryption.some(
1563
- (k: { derivationScheme: string }) => k.derivationScheme === KeyDerivationScheme.ProtocolContext
1571
+ const hasContextKey = encryption?.recipients.some(
1572
+ (r: { header: { derivationScheme: string } }) => r.header.derivationScheme === KeyDerivationScheme.ProtocolContext
1564
1573
  );
1565
1574
 
1566
1575
  if (!hasContextKey || !recordsWrite.contextId) {
@@ -1569,15 +1578,15 @@ export class AgentDwnApi {
1569
1578
  }
1570
1579
 
1571
1580
  // --- Multi-party context encryption ---
1572
- const contextKeyEntry = encryption!.keyEncryption.find(
1573
- (k: { derivationScheme: string }) => k.derivationScheme === KeyDerivationScheme.ProtocolContext
1581
+ const contextKeyEntry = encryption!.recipients.find(
1582
+ (r: { header: { derivationScheme: string } }) => r.header.derivationScheme === KeyDerivationScheme.ProtocolContext
1574
1583
  )!;
1575
1584
 
1576
1585
  const rootContextId = recordsWrite.contextId.split('/')[0];
1577
1586
 
1578
1587
  // Case 1: I am the context creator — rootKeyId matches my encryption key
1579
1588
  const { keyId, keyUri } = await this.getEncryptionKeyInfo(authorDid);
1580
- if (contextKeyEntry.rootKeyId === keyId) {
1589
+ if (contextKeyEntry.header.kid === keyId) {
1581
1590
  return this.buildKmsDecryptCallback(keyId, keyUri, KeyDerivationScheme.ProtocolContext);
1582
1591
  }
1583
1592
 
@@ -1638,17 +1647,12 @@ export class AgentDwnApi {
1638
1647
  return {
1639
1648
  rootKeyId : contextKey.rootKeyId,
1640
1649
  derivationScheme : contextKey.derivationScheme,
1641
- decrypt : async (fullDerivationPath, eciesPayload): Promise<Uint8Array> => {
1642
- const leafPrivateKey = await Records.derivePrivateKey(
1650
+ decrypt : async (fullDerivationPath, jwePayload): Promise<Uint8Array> => {
1651
+ const leafPrivateKeyBytes = await Records.derivePrivateKey(
1643
1652
  contextKey, fullDerivationPath,
1644
1653
  );
1645
- return Encryption.eciesSecp256k1Decrypt({
1646
- privateKey : leafPrivateKey,
1647
- ciphertext : eciesPayload.ciphertext,
1648
- ephemeralPublicKey : eciesPayload.ephemeralPublicKey,
1649
- initializationVector : eciesPayload.initializationVector,
1650
- messageAuthenticationCode : eciesPayload.messageAuthenticationCode,
1651
- });
1654
+ const leafPrivateKeyJwk = await X25519.bytesToPrivateKey({ privateKeyBytes: leafPrivateKeyBytes });
1655
+ return Encryption.ecdhEsUnwrapKey(leafPrivateKeyJwk, jwePayload.ephemeralPublicKey, jwePayload.encryptedKey);
1652
1656
  },
1653
1657
  };
1654
1658
  }
@@ -1870,17 +1874,20 @@ export class AgentDwnApi {
1870
1874
  // Manually build encryption input targeting the recipient's key so the
1871
1875
  // record is decryptable only by the recipient.
1872
1876
  const dataEncryptionKey = crypto.getRandomValues(new Uint8Array(32));
1873
- const dataEncryptionIV = crypto.getRandomValues(new Uint8Array(16));
1877
+ const dataEncryptionIV = crypto.getRandomValues(new Uint8Array(12));
1874
1878
 
1875
- const { encryptedBytes, dataCid, dataSize } =
1879
+ const { encryptedBytes, dataCid, dataSize, authenticationTag } =
1876
1880
  await this.encryptAndComputeCid(plaintextBytes, dataEncryptionKey, dataEncryptionIV);
1877
1881
 
1878
- const encryptionInput = this.buildEncryptionInput(
1879
- dataEncryptionKey, dataEncryptionIV,
1880
- recipientKeyDeliveryPublicKey.rootKeyId,
1881
- recipientKeyDeliveryPublicKey.publicKeyJwk,
1882
- KeyDerivationScheme.ProtocolPath,
1883
- );
1882
+ const encryptionInput = {
1883
+ ...this.buildEncryptionInput(
1884
+ dataEncryptionKey, dataEncryptionIV,
1885
+ recipientKeyDeliveryPublicKey.rootKeyId,
1886
+ recipientKeyDeliveryPublicKey.publicKeyJwk,
1887
+ KeyDerivationScheme.ProtocolPath,
1888
+ ),
1889
+ authenticationTag,
1890
+ } as EncryptionInput;
1884
1891
 
1885
1892
  ({ message, reply: { status } } = await this.processRequest({
1886
1893
  author : tenantDid,
@@ -4,7 +4,7 @@ import type { KeyValueStore } from '@enbox/common';
4
4
 
5
5
  import { HDKey } from 'ed25519-keygen/hdkey';
6
6
  import { wordlist } from '@scure/bip39/wordlists/english';
7
- import { BearerDid, DidDht } from '@enbox/dids';
7
+ import { BearerDid, DidDht, isPortableDid } from '@enbox/dids';
8
8
  import { Convert, MemoryStore } from '@enbox/common';
9
9
  import { generateMnemonic, mnemonicToSeed, validateMnemonic } from '@scure/bip39';
10
10
 
@@ -14,7 +14,6 @@ import type { IdentityVault, IdentityVaultBackup, IdentityVaultBackupData, Ident
14
14
  import { AgentCryptoApi } from './crypto-api.js';
15
15
  import { CompactJwe } from './prototyping/crypto/jose/jwe-compact.js';
16
16
  import { DeterministicKeyGenerator } from './utils-internal.js';
17
- import { isPortableDid } from './prototyping/dids/utils.js';
18
17
  import { LocalKeyManager } from './local-key-manager.js';
19
18
 
20
19
  /**
@@ -495,10 +494,10 @@ export class HdIdentityVault implements IdentityVault<{ InitializeResult: string
495
494
  privateKeyBytes : signingHdKey.privateKey
496
495
  });
497
496
 
498
- // Derive the encryption key using index 2 (secp256k1 for ECIES encryption).
497
+ // Derive the encryption key using index 2 (X25519 for ECDH-ES JWE encryption).
499
498
  const encryptionHdKey = rootHdKey.derive(`m/44'/0'/1708523827'/0'/2'`);
500
499
  const encryptionPrivateKey = await this.crypto.bytesToPrivateKey({
501
- algorithm : 'secp256k1',
500
+ algorithm : 'X25519',
502
501
  privateKeyBytes : encryptionHdKey.privateKey
503
502
  });
504
503
 
@@ -518,7 +517,7 @@ export class HdIdentityVault implements IdentityVault<{ InitializeResult: string
518
517
  purposes : ['assertionMethod', 'authentication']
519
518
  },
520
519
  {
521
- algorithm : 'secp256k1',
520
+ algorithm : 'X25519',
522
521
  id : 'enc',
523
522
  purposes : ['keyAgreement']
524
523
  }
@@ -6,10 +6,11 @@ import type { DidMethodCreateOptions } from './did-api.js';
6
6
  import type { Web5PlatformAgent } from './types/agent.js';
7
7
  import type { IdentityMetadata, PortableIdentity } from './types/identity.js';
8
8
 
9
+ import { isPortableDid } from '@enbox/dids';
10
+
9
11
  import { BearerIdentity } from './bearer-identity.js';
10
12
  import { getDwnServiceEndpointUrls } from './utils.js';
11
13
  import { InMemoryIdentityStore } from './store-identity.js';
12
- import { isPortableDid } from './prototyping/dids/utils.js';
13
14
 
14
15
  export interface IdentityApiParams<TKeyManager extends AgentKeyManager> {
15
16
  agent?: Web5PlatformAgent<TKeyManager>;
package/src/index.ts CHANGED
@@ -12,12 +12,10 @@ export * from './bearer-identity.js';
12
12
  export * from './crypto-api.js';
13
13
  export * from './did-api.js';
14
14
  export * from './dwn-api.js';
15
- export * from './dwn-registrar.js';
16
15
  export * from './hd-identity-vault.js';
17
16
  export * from './identity-api.js';
18
17
  export * from './local-key-manager.js';
19
18
  export * from './permissions-api.js';
20
- export * from './rpc-client.js';
21
19
  export * from './store-data.js';
22
20
  export * from './store-did.js';
23
21
  export * from './store-identity.js';