@nmshd/transport 2.8.1 → 5.0.0-alpha.2

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 (208) hide show
  1. package/dist/buildInformation.js +4 -4
  2. package/dist/core/CoreErrors.d.ts +7 -5
  3. package/dist/core/CoreErrors.d.ts.map +1 -1
  4. package/dist/core/CoreErrors.js +16 -10
  5. package/dist/core/CoreErrors.js.map +1 -1
  6. package/dist/core/Transport.d.ts +0 -3
  7. package/dist/core/Transport.d.ts.map +1 -1
  8. package/dist/core/Transport.js +0 -5
  9. package/dist/core/Transport.js.map +1 -1
  10. package/dist/core/backbone/BackboneIds.d.ts +0 -1
  11. package/dist/core/backbone/BackboneIds.d.ts.map +1 -1
  12. package/dist/core/backbone/BackboneIds.js +0 -1
  13. package/dist/core/backbone/BackboneIds.js.map +1 -1
  14. package/dist/events/RelationshipReactivationCompletedEvent.d.ts +7 -0
  15. package/dist/events/RelationshipReactivationCompletedEvent.d.ts.map +1 -0
  16. package/dist/events/RelationshipReactivationCompletedEvent.js +12 -0
  17. package/dist/events/RelationshipReactivationCompletedEvent.js.map +1 -0
  18. package/dist/events/RelationshipReactivationRequestedEvent.d.ts +7 -0
  19. package/dist/events/RelationshipReactivationRequestedEvent.d.ts.map +1 -0
  20. package/dist/events/RelationshipReactivationRequestedEvent.js +12 -0
  21. package/dist/events/RelationshipReactivationRequestedEvent.js.map +1 -0
  22. package/dist/events/index.d.ts +2 -0
  23. package/dist/events/index.d.ts.map +1 -1
  24. package/dist/events/index.js +2 -0
  25. package/dist/events/index.js.map +1 -1
  26. package/dist/modules/accounts/AccountController.d.ts.map +1 -1
  27. package/dist/modules/accounts/AccountController.js +1 -2
  28. package/dist/modules/accounts/AccountController.js.map +1 -1
  29. package/dist/modules/accounts/IdentityController.d.ts +0 -2
  30. package/dist/modules/accounts/IdentityController.d.ts.map +1 -1
  31. package/dist/modules/accounts/IdentityController.js +0 -3
  32. package/dist/modules/accounts/IdentityController.js.map +1 -1
  33. package/dist/modules/accounts/IdentityUtil.d.ts +2 -2
  34. package/dist/modules/accounts/IdentityUtil.d.ts.map +1 -1
  35. package/dist/modules/accounts/IdentityUtil.js +23 -26
  36. package/dist/modules/accounts/IdentityUtil.js.map +1 -1
  37. package/dist/modules/accounts/data/Identity.d.ts +0 -3
  38. package/dist/modules/accounts/data/Identity.d.ts.map +1 -1
  39. package/dist/modules/accounts/data/Identity.js +0 -6
  40. package/dist/modules/accounts/data/Identity.js.map +1 -1
  41. package/dist/modules/accounts/data/IdentitySecretCredentials.d.ts +0 -3
  42. package/dist/modules/accounts/data/IdentitySecretCredentials.d.ts.map +1 -1
  43. package/dist/modules/accounts/data/IdentitySecretCredentials.js +0 -6
  44. package/dist/modules/accounts/data/IdentitySecretCredentials.js.map +1 -1
  45. package/dist/modules/challenges/ChallengeController.d.ts.map +1 -1
  46. package/dist/modules/challenges/ChallengeController.js +3 -2
  47. package/dist/modules/challenges/ChallengeController.js.map +1 -1
  48. package/dist/modules/devices/local/Device.d.ts.map +1 -1
  49. package/dist/modules/devices/local/Device.js +3 -1
  50. package/dist/modules/devices/local/Device.js.map +1 -1
  51. package/dist/modules/index.d.ts +10 -14
  52. package/dist/modules/index.d.ts.map +1 -1
  53. package/dist/modules/index.js +10 -14
  54. package/dist/modules/index.js.map +1 -1
  55. package/dist/modules/messages/MessageController.js +5 -5
  56. package/dist/modules/messages/MessageController.js.map +1 -1
  57. package/dist/modules/relationships/RelationshipSecretController.d.ts +3 -3
  58. package/dist/modules/relationships/RelationshipSecretController.d.ts.map +1 -1
  59. package/dist/modules/relationships/RelationshipSecretController.js +6 -6
  60. package/dist/modules/relationships/RelationshipSecretController.js.map +1 -1
  61. package/dist/modules/relationships/RelationshipsController.d.ts +21 -23
  62. package/dist/modules/relationships/RelationshipsController.d.ts.map +1 -1
  63. package/dist/modules/relationships/RelationshipsController.js +244 -310
  64. package/dist/modules/relationships/RelationshipsController.js.map +1 -1
  65. package/dist/modules/relationships/backbone/BackboneGetRelationships.d.ts +2 -11
  66. package/dist/modules/relationships/backbone/BackboneGetRelationships.d.ts.map +1 -1
  67. package/dist/modules/relationships/backbone/BackbonePostRelationship.d.ts +7 -0
  68. package/dist/modules/relationships/backbone/BackbonePostRelationship.d.ts.map +1 -0
  69. package/dist/modules/relationships/backbone/{BackboneGetRelationshipsChanges.js → BackbonePostRelationship.js} +1 -1
  70. package/dist/modules/relationships/backbone/BackbonePostRelationship.js.map +1 -0
  71. package/dist/modules/relationships/backbone/BackbonePutRelationship.d.ts +6 -0
  72. package/dist/modules/relationships/backbone/BackbonePutRelationship.d.ts.map +1 -0
  73. package/dist/modules/relationships/backbone/{BackbonePostRelationshipsChanges.js → BackbonePutRelationship.js} +1 -1
  74. package/dist/modules/relationships/backbone/BackbonePutRelationship.js.map +1 -0
  75. package/dist/modules/relationships/backbone/BackboneRelationship.d.ts +14 -0
  76. package/dist/modules/relationships/backbone/BackboneRelationship.d.ts.map +1 -0
  77. package/dist/modules/relationships/backbone/BackboneRelationship.js +3 -0
  78. package/dist/modules/relationships/backbone/BackboneRelationship.js.map +1 -0
  79. package/dist/modules/relationships/backbone/RelationshipClient.d.ts +14 -12
  80. package/dist/modules/relationships/backbone/RelationshipClient.d.ts.map +1 -1
  81. package/dist/modules/relationships/backbone/RelationshipClient.js +20 -21
  82. package/dist/modules/relationships/backbone/RelationshipClient.js.map +1 -1
  83. package/dist/modules/relationships/local/CachedRelationship.d.ts +6 -4
  84. package/dist/modules/relationships/local/CachedRelationship.d.ts.map +1 -1
  85. package/dist/modules/relationships/local/CachedRelationship.js +10 -8
  86. package/dist/modules/relationships/local/CachedRelationship.js.map +1 -1
  87. package/dist/modules/relationships/local/Relationship.d.ts +3 -8
  88. package/dist/modules/relationships/local/Relationship.d.ts.map +1 -1
  89. package/dist/modules/relationships/local/Relationship.js +5 -35
  90. package/dist/modules/relationships/local/Relationship.js.map +1 -1
  91. package/dist/modules/relationships/local/RelationshipAuditLog.d.ts +6 -0
  92. package/dist/modules/relationships/local/RelationshipAuditLog.d.ts.map +1 -0
  93. package/dist/modules/relationships/local/RelationshipAuditLog.js +26 -0
  94. package/dist/modules/relationships/local/RelationshipAuditLog.js.map +1 -0
  95. package/dist/modules/relationships/local/RelationshipAuditLogEntry.d.ts +21 -0
  96. package/dist/modules/relationships/local/RelationshipAuditLogEntry.d.ts.map +1 -0
  97. package/dist/modules/relationships/local/RelationshipAuditLogEntry.js +63 -0
  98. package/dist/modules/relationships/local/RelationshipAuditLogEntry.js.map +1 -0
  99. package/dist/modules/relationships/local/SendRelationshipParameters.d.ts +2 -2
  100. package/dist/modules/relationships/local/SendRelationshipParameters.d.ts.map +1 -1
  101. package/dist/modules/relationships/local/SendRelationshipParameters.js +1 -1
  102. package/dist/modules/relationships/local/SendRelationshipParameters.js.map +1 -1
  103. package/dist/modules/relationships/transmission/RelationshipAuditLog.d.ts +23 -0
  104. package/dist/modules/relationships/transmission/RelationshipAuditLog.d.ts.map +1 -0
  105. package/dist/modules/relationships/transmission/RelationshipAuditLog.js +16 -0
  106. package/dist/modules/relationships/transmission/RelationshipAuditLog.js.map +1 -0
  107. package/dist/modules/relationships/transmission/RelationshipStatus.d.ts +0 -1
  108. package/dist/modules/relationships/transmission/RelationshipStatus.d.ts.map +1 -1
  109. package/dist/modules/relationships/transmission/RelationshipStatus.js +0 -1
  110. package/dist/modules/relationships/transmission/RelationshipStatus.js.map +1 -1
  111. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentCipher.d.ts +13 -0
  112. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentCipher.d.ts.map +1 -0
  113. package/dist/modules/relationships/transmission/requests/{RelationshipCreationChangeRequestCipher.js → RelationshipCreationContentCipher.js} +9 -9
  114. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentCipher.js.map +1 -0
  115. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentSigned.d.ts +14 -0
  116. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentSigned.d.ts.map +1 -0
  117. package/dist/modules/relationships/transmission/requests/{RelationshipCreationChangeRequestSigned.js → RelationshipCreationContentSigned.js} +10 -10
  118. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentSigned.js.map +1 -0
  119. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentWrapper.d.ts +15 -0
  120. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentWrapper.d.ts.map +1 -0
  121. package/dist/modules/relationships/transmission/requests/{RelationshipCreationChangeRequestContentWrapper.js → RelationshipCreationContentWrapper.js} +10 -10
  122. package/dist/modules/relationships/transmission/requests/RelationshipCreationContentWrapper.js.map +1 -0
  123. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentCipher.d.ts +13 -0
  124. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentCipher.d.ts.map +1 -0
  125. package/dist/modules/relationships/transmission/responses/{RelationshipCreationChangeResponseCipher.js → RelationshipCreationResponseContentCipher.js} +10 -10
  126. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentCipher.js.map +1 -0
  127. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentSigned.d.ts +14 -0
  128. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentSigned.d.ts.map +1 -0
  129. package/dist/modules/relationships/transmission/responses/{RelationshipCreationChangeResponseSigned.js → RelationshipCreationResponseContentSigned.js} +10 -10
  130. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentSigned.js.map +1 -0
  131. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentWrapper.d.ts +9 -0
  132. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentWrapper.d.ts.map +1 -0
  133. package/dist/modules/relationships/transmission/responses/{RelationshipCreationChangeResponseContentWrapper.js → RelationshipCreationResponseContentWrapper.js} +8 -13
  134. package/dist/modules/relationships/transmission/responses/RelationshipCreationResponseContentWrapper.js.map +1 -0
  135. package/dist/modules/sync/SyncController.d.ts.map +1 -1
  136. package/dist/modules/sync/SyncController.js +4 -4
  137. package/dist/modules/sync/SyncController.js.map +1 -1
  138. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.d.ts.map +1 -1
  139. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.js +6 -4
  140. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.js.map +1 -1
  141. package/dist/modules/sync/externalEventProcessors/{RelationshipChangeCompletedExternalEventProcessor.d.ts → RelationshipReactivationCompletedExternalEventProcessor.d.ts} +2 -2
  142. package/dist/modules/sync/externalEventProcessors/RelationshipReactivationCompletedExternalEventProcessor.d.ts.map +1 -0
  143. package/dist/modules/sync/externalEventProcessors/{RelationshipChangeCompletedExternalEventProcessor.js → RelationshipReactivationCompletedExternalEventProcessor.js} +11 -13
  144. package/dist/modules/sync/externalEventProcessors/RelationshipReactivationCompletedExternalEventProcessor.js.map +1 -0
  145. package/dist/modules/sync/externalEventProcessors/RelationshipReactivationRequestedExternalEventProcessor.d.ts +7 -0
  146. package/dist/modules/sync/externalEventProcessors/RelationshipReactivationRequestedExternalEventProcessor.d.ts.map +1 -0
  147. package/dist/modules/sync/externalEventProcessors/RelationshipReactivationRequestedExternalEventProcessor.js +33 -0
  148. package/dist/modules/sync/externalEventProcessors/RelationshipReactivationRequestedExternalEventProcessor.js.map +1 -0
  149. package/dist/modules/sync/externalEventProcessors/{RelationshipChangeCreatedExternalEventProcessor.d.ts → RelationshipStatusChangedExternalEventProcessor.d.ts} +2 -2
  150. package/dist/modules/sync/externalEventProcessors/{RelationshipChangeCreatedExternalEventProcessor.d.ts.map → RelationshipStatusChangedExternalEventProcessor.d.ts.map} +1 -1
  151. package/dist/modules/sync/externalEventProcessors/{RelationshipChangeCreatedExternalEventProcessor.js → RelationshipStatusChangedExternalEventProcessor.js} +10 -18
  152. package/dist/modules/sync/externalEventProcessors/RelationshipStatusChangedExternalEventProcessor.js.map +1 -0
  153. package/dist/modules/sync/externalEventProcessors/index.d.ts +3 -2
  154. package/dist/modules/sync/externalEventProcessors/index.d.ts.map +1 -1
  155. package/dist/modules/sync/externalEventProcessors/index.js +3 -2
  156. package/dist/modules/sync/externalEventProcessors/index.js.map +1 -1
  157. package/package.json +1 -1
  158. package/dist/modules/accounts/data/Realm.d.ts +0 -6
  159. package/dist/modules/accounts/data/Realm.d.ts.map +0 -1
  160. package/dist/modules/accounts/data/Realm.js +0 -10
  161. package/dist/modules/accounts/data/Realm.js.map +0 -1
  162. package/dist/modules/relationships/backbone/BackboneGetRelationshipsChanges.d.ts +0 -24
  163. package/dist/modules/relationships/backbone/BackboneGetRelationshipsChanges.d.ts.map +0 -1
  164. package/dist/modules/relationships/backbone/BackboneGetRelationshipsChanges.js.map +0 -1
  165. package/dist/modules/relationships/backbone/BackbonePostRelationshipsChanges.d.ts +0 -9
  166. package/dist/modules/relationships/backbone/BackbonePostRelationshipsChanges.d.ts.map +0 -1
  167. package/dist/modules/relationships/backbone/BackbonePostRelationshipsChanges.js.map +0 -1
  168. package/dist/modules/relationships/transmission/changes/RelationshipChange.d.ts +0 -27
  169. package/dist/modules/relationships/transmission/changes/RelationshipChange.d.ts.map +0 -1
  170. package/dist/modules/relationships/transmission/changes/RelationshipChange.js +0 -72
  171. package/dist/modules/relationships/transmission/changes/RelationshipChange.js.map +0 -1
  172. package/dist/modules/relationships/transmission/changes/RelationshipChangeRequest.d.ts +0 -20
  173. package/dist/modules/relationships/transmission/changes/RelationshipChangeRequest.d.ts.map +0 -1
  174. package/dist/modules/relationships/transmission/changes/RelationshipChangeRequest.js +0 -53
  175. package/dist/modules/relationships/transmission/changes/RelationshipChangeRequest.js.map +0 -1
  176. package/dist/modules/relationships/transmission/changes/RelationshipChangeResponse.d.ts +0 -20
  177. package/dist/modules/relationships/transmission/changes/RelationshipChangeResponse.d.ts.map +0 -1
  178. package/dist/modules/relationships/transmission/changes/RelationshipChangeResponse.js +0 -53
  179. package/dist/modules/relationships/transmission/changes/RelationshipChangeResponse.js.map +0 -1
  180. package/dist/modules/relationships/transmission/changes/RelationshipChangeStatus.d.ts +0 -7
  181. package/dist/modules/relationships/transmission/changes/RelationshipChangeStatus.d.ts.map +0 -1
  182. package/dist/modules/relationships/transmission/changes/RelationshipChangeStatus.js +0 -11
  183. package/dist/modules/relationships/transmission/changes/RelationshipChangeStatus.js.map +0 -1
  184. package/dist/modules/relationships/transmission/changes/RelationshipChangeType.d.ts +0 -6
  185. package/dist/modules/relationships/transmission/changes/RelationshipChangeType.d.ts.map +0 -1
  186. package/dist/modules/relationships/transmission/changes/RelationshipChangeType.js +0 -10
  187. package/dist/modules/relationships/transmission/changes/RelationshipChangeType.js.map +0 -1
  188. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestCipher.d.ts +0 -13
  189. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestCipher.d.ts.map +0 -1
  190. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestCipher.js.map +0 -1
  191. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestContentWrapper.d.ts +0 -15
  192. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestContentWrapper.d.ts.map +0 -1
  193. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestContentWrapper.js.map +0 -1
  194. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestSigned.d.ts +0 -14
  195. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestSigned.d.ts.map +0 -1
  196. package/dist/modules/relationships/transmission/requests/RelationshipCreationChangeRequestSigned.js.map +0 -1
  197. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseCipher.d.ts +0 -13
  198. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseCipher.d.ts.map +0 -1
  199. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseCipher.js.map +0 -1
  200. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseContentWrapper.d.ts +0 -12
  201. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseContentWrapper.d.ts.map +0 -1
  202. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseContentWrapper.js.map +0 -1
  203. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseSigned.d.ts +0 -14
  204. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseSigned.d.ts.map +0 -1
  205. package/dist/modules/relationships/transmission/responses/RelationshipCreationChangeResponseSigned.js.map +0 -1
  206. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.d.ts.map +0 -1
  207. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.js.map +0 -1
  208. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.js.map +0 -1
@@ -23,18 +23,16 @@ const RelationshipTemplate_1 = require("../relationshipTemplates/local/Relations
23
23
  const RelationshipClient_1 = require("./backbone/RelationshipClient");
24
24
  const CachedRelationship_1 = require("./local/CachedRelationship");
25
25
  const Relationship_1 = require("./local/Relationship");
26
+ const RelationshipAuditLog_1 = require("./local/RelationshipAuditLog");
26
27
  const SendRelationshipParameters_1 = require("./local/SendRelationshipParameters");
27
- const RelationshipChange_1 = require("./transmission/changes/RelationshipChange");
28
- const RelationshipChangeResponse_1 = require("./transmission/changes/RelationshipChangeResponse");
29
- const RelationshipChangeStatus_1 = require("./transmission/changes/RelationshipChangeStatus");
30
- const RelationshipChangeType_1 = require("./transmission/changes/RelationshipChangeType");
28
+ const RelationshipAuditLog_2 = require("./transmission/RelationshipAuditLog");
31
29
  const RelationshipStatus_1 = require("./transmission/RelationshipStatus");
32
- const RelationshipCreationChangeRequestCipher_1 = require("./transmission/requests/RelationshipCreationChangeRequestCipher");
33
- const RelationshipCreationChangeRequestContentWrapper_1 = require("./transmission/requests/RelationshipCreationChangeRequestContentWrapper");
34
- const RelationshipCreationChangeRequestSigned_1 = require("./transmission/requests/RelationshipCreationChangeRequestSigned");
35
- const RelationshipCreationChangeResponseCipher_1 = require("./transmission/responses/RelationshipCreationChangeResponseCipher");
36
- const RelationshipCreationChangeResponseContentWrapper_1 = require("./transmission/responses/RelationshipCreationChangeResponseContentWrapper");
37
- const RelationshipCreationChangeResponseSigned_1 = require("./transmission/responses/RelationshipCreationChangeResponseSigned");
30
+ const RelationshipCreationContentCipher_1 = require("./transmission/requests/RelationshipCreationContentCipher");
31
+ const RelationshipCreationContentSigned_1 = require("./transmission/requests/RelationshipCreationContentSigned");
32
+ const RelationshipCreationContentWrapper_1 = require("./transmission/requests/RelationshipCreationContentWrapper");
33
+ const RelationshipCreationResponseContentCipher_1 = require("./transmission/responses/RelationshipCreationResponseContentCipher");
34
+ const RelationshipCreationResponseContentSigned_1 = require("./transmission/responses/RelationshipCreationResponseContentSigned");
35
+ const RelationshipCreationResponseContentWrapper_1 = require("./transmission/responses/RelationshipCreationResponseContentWrapper");
38
36
  class RelationshipsController extends core_1.TransportController {
39
37
  constructor(parent, secrets) {
40
38
  super(core_1.ControllerName.Relationships, parent);
@@ -48,7 +46,8 @@ class RelationshipsController extends core_1.TransportController {
48
46
  }
49
47
  async getRelationships(query) {
50
48
  const relationshipDocs = await this.relationships.find(query);
51
- return this.parseArray(relationshipDocs, Relationship_1.Relationship);
49
+ const relationships = this.parseArray(relationshipDocs, Relationship_1.Relationship);
50
+ return relationships;
52
51
  }
53
52
  async updateCache(ids) {
54
53
  if (ids.length < 1) {
@@ -57,7 +56,7 @@ class RelationshipsController extends core_1.TransportController {
57
56
  const resultItems = (await this.client.getRelationships({ ids })).value;
58
57
  const promises = [];
59
58
  for await (const resultItem of resultItems) {
60
- promises.push(this.updateCacheOfExistingRelationshipInDb(resultItem.id, resultItem));
59
+ promises.push(this.updateExistingRelationshipInDb(resultItem.id, resultItem));
61
60
  }
62
61
  return await Promise.all(promises);
63
62
  }
@@ -75,12 +74,13 @@ class RelationshipsController extends core_1.TransportController {
75
74
  });
76
75
  return await Promise.all(decryptionPromises);
77
76
  }
78
- async updateCacheOfExistingRelationshipInDb(id, response) {
77
+ async updateExistingRelationshipInDb(id, response) {
79
78
  const relationshipDoc = await this.relationships.read(id);
80
79
  if (!relationshipDoc)
81
80
  throw CoreErrors_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, id);
82
81
  const relationship = Relationship_1.Relationship.from(relationshipDoc);
83
82
  await this.updateCacheOfRelationship(relationship, response);
83
+ relationship.status = response.status;
84
84
  await this.relationships.update(relationshipDoc, relationship);
85
85
  return relationship;
86
86
  }
@@ -110,7 +110,8 @@ class RelationshipsController extends core_1.TransportController {
110
110
  if (!relationshipDoc) {
111
111
  return;
112
112
  }
113
- return Relationship_1.Relationship.from(relationshipDoc);
113
+ const relationship = Relationship_1.Relationship.from(relationshipDoc);
114
+ return relationship;
114
115
  }
115
116
  async sign(relationship, content) {
116
117
  return await this.secrets.sign(relationship.relationshipSecretId, content);
@@ -128,12 +129,12 @@ class RelationshipsController extends core_1.TransportController {
128
129
  throw this.newCacheEmptyError(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
129
130
  }
130
131
  const secretId = await TransportIds_1.TransportIds.relationshipSecret.generate();
131
- const { requestCipher, requestContent } = await this.prepareRequest(secretId, template, parameters.content);
132
+ const creationContentCipher = await this.prepareCreationContent(secretId, template, parameters.creationContent);
132
133
  const backboneResponse = (await this.client.createRelationship({
133
- content: requestCipher.toBase64(),
134
+ creationContent: creationContentCipher.toBase64(),
134
135
  relationshipTemplateId: template.id.toString()
135
136
  })).value;
136
- const newRelationship = Relationship_1.Relationship.fromRequestSent(core_1.CoreId.from(backboneResponse.id), template, template.cache.identity, RelationshipChange_1.RelationshipChange.fromBackbone(backboneResponse.changes[0], requestContent.content), secretId);
137
+ const newRelationship = Relationship_1.Relationship.fromBackboneAndCreationContent(backboneResponse, template, template.cache.identity, parameters.creationContent, secretId);
137
138
  await this.relationships.create(newRelationship);
138
139
  this.eventBus.publish(new events_1.RelationshipChangedEvent(this.parent.identity.address.toString(), newRelationship));
139
140
  return newRelationship;
@@ -149,14 +150,100 @@ class RelationshipsController extends core_1.TransportController {
149
150
  await this.relationships.update(relationshipDoc, relationship);
150
151
  return relationship;
151
152
  }
152
- async acceptChange(change, content) {
153
- return await this.completeChange(RelationshipChangeStatus_1.RelationshipChangeStatus.Accepted, change, content);
153
+ async accept(relationshipId) {
154
+ const relationship = await this.getRelationshipWithCache(relationshipId);
155
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Pending);
156
+ const lastAuditLogEntry = relationship.cache.auditLog[relationship.cache.auditLog.length - 1];
157
+ if (!lastAuditLogEntry.createdBy.equals(relationship.peer.address)) {
158
+ throw CoreErrors_1.CoreErrors.relationships.operationOnlyAllowedForPeer(`Only your peer can accept the relationship ${relationshipId.toString()}`);
159
+ }
160
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.AcceptanceOfCreation, relationshipId);
161
+ }
162
+ async reject(relationshipId) {
163
+ const relationship = await this.getRelationshipWithCache(relationshipId);
164
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Pending);
165
+ const lastAuditLogEntry = relationship.cache.auditLog[relationship.cache.auditLog.length - 1];
166
+ if (!lastAuditLogEntry.createdBy.equals(relationship.peer.address)) {
167
+ throw CoreErrors_1.CoreErrors.relationships.operationOnlyAllowedForPeer(`Only your peer can reject the relationship ${relationshipId.toString()}. Revoke the relationship instead.`);
168
+ }
169
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RejectionOfCreation, relationshipId);
170
+ }
171
+ async revoke(relationshipId) {
172
+ const relationship = await this.getRelationshipWithCache(relationshipId);
173
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Pending);
174
+ const lastAuditLogEntry = relationship.cache.auditLog[relationship.cache.auditLog.length - 1];
175
+ if (lastAuditLogEntry.createdBy.equals(relationship.peer.address)) {
176
+ throw CoreErrors_1.CoreErrors.relationships.operationOnlyAllowedForPeer(`Only your peer can revoke the relationship ${relationshipId.toString()}. Reject the relationship instead.`);
177
+ }
178
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RevocationOfCreation, relationshipId);
179
+ }
180
+ async terminate(relationshipId) {
181
+ const relationship = await this.getRelationshipWithCache(relationshipId);
182
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Active);
183
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.Termination, relationshipId);
184
+ }
185
+ async requestReactivation(relationshipId) {
186
+ const relationship = await this.getRelationshipWithCache(relationshipId);
187
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Terminated);
188
+ const lastAuditLogEntry = relationship.cache.auditLog[relationship.cache.auditLog.length - 1];
189
+ if (lastAuditLogEntry.reason === RelationshipAuditLog_2.RelationshipAuditLogEntryReason.ReactivationRequested) {
190
+ if (lastAuditLogEntry.createdBy.equals(relationship.peer.address)) {
191
+ throw CoreErrors_1.CoreErrors.relationships.reactivationAlreadyRequested(`Your peer has already requested the reactivation of the relationship ${relationshipId.toString()}. You can accept the reactivation instead.`);
192
+ }
193
+ throw CoreErrors_1.CoreErrors.relationships.reactivationAlreadyRequested(`You have already requested the reactivation of the relationship ${relationshipId.toString()}.`);
194
+ }
195
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.ReactivationRequested, relationshipId);
154
196
  }
155
- async rejectChange(change, content) {
156
- return await this.completeChange(RelationshipChangeStatus_1.RelationshipChangeStatus.Rejected, change, content);
197
+ async rejectReactivation(relationshipId) {
198
+ const relationship = await this.getRelationshipWithCache(relationshipId);
199
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Terminated);
200
+ const lastAuditLogEntry = relationship.cache.auditLog[relationship.cache.auditLog.length - 1];
201
+ if (lastAuditLogEntry.reason !== RelationshipAuditLog_2.RelationshipAuditLogEntryReason.ReactivationRequested) {
202
+ throw CoreErrors_1.CoreErrors.relationships.reactivationNotRequested(relationshipId.toString());
203
+ }
204
+ if (!lastAuditLogEntry.createdBy.equals(relationship.peer.address)) {
205
+ throw CoreErrors_1.CoreErrors.relationships.operationOnlyAllowedForPeer(`Only your peer can reject the reactivation of the relationship ${relationshipId.toString()}. Revoke the relationship reactivation instead.`);
206
+ }
207
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RejectionOfReactivation, relationshipId);
157
208
  }
158
- async revokeChange(change, content) {
159
- return await this.completeChange(RelationshipChangeStatus_1.RelationshipChangeStatus.Revoked, change, content);
209
+ async revokeReactivation(relationshipId) {
210
+ const relationship = await this.getRelationshipWithCache(relationshipId);
211
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Terminated);
212
+ const lastAuditLogEntry = relationship.cache.auditLog[relationship.cache.auditLog.length - 1];
213
+ if (lastAuditLogEntry.reason !== RelationshipAuditLog_2.RelationshipAuditLogEntryReason.ReactivationRequested) {
214
+ throw CoreErrors_1.CoreErrors.relationships.reactivationNotRequested(relationshipId.toString());
215
+ }
216
+ if (lastAuditLogEntry.createdBy.equals(relationship.peer.address)) {
217
+ throw CoreErrors_1.CoreErrors.relationships.operationOnlyAllowedForPeer(`Only your peer can revoke the reactivation of the relationship ${relationshipId.toString()}. Reject the relationship reactivation instead.`);
218
+ }
219
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RevocationOfReactivation, relationshipId);
220
+ }
221
+ async acceptReactivation(relationshipId) {
222
+ const relationship = await this.getRelationshipWithCache(relationshipId);
223
+ this.assertRelationshipStatus(relationship, RelationshipStatus_1.RelationshipStatus.Terminated);
224
+ const lastAuditLogEntry = relationship.cache.auditLog[relationship.cache.auditLog.length - 1];
225
+ if (lastAuditLogEntry.reason !== RelationshipAuditLog_2.RelationshipAuditLogEntryReason.ReactivationRequested) {
226
+ throw CoreErrors_1.CoreErrors.relationships.reactivationNotRequested(relationshipId.toString());
227
+ }
228
+ if (!lastAuditLogEntry.createdBy.equals(relationship.peer.address)) {
229
+ throw CoreErrors_1.CoreErrors.relationships.operationOnlyAllowedForPeer(`Only your peer can accept the reactivation of the relationship ${relationshipId.toString()}.`);
230
+ }
231
+ return await this.completeOperationWithBackboneCall(RelationshipAuditLog_2.RelationshipAuditLogEntryReason.AcceptanceOfReactivation, relationshipId);
232
+ }
233
+ async getRelationshipWithCache(id) {
234
+ const relationship = await this.getRelationship(id);
235
+ if (!relationship)
236
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, id.toString());
237
+ if (!relationship.cache)
238
+ await this.updateCacheOfRelationship(relationship);
239
+ if (!relationship.cache)
240
+ throw this.newCacheEmptyError(Relationship_1.Relationship, id.toString());
241
+ return relationship;
242
+ }
243
+ assertRelationshipStatus(relationship, status) {
244
+ if (relationship.status === status)
245
+ return;
246
+ throw CoreErrors_1.CoreErrors.relationships.wrongRelationshipStatus(relationship.id.toString(), relationship.status);
160
247
  }
161
248
  async updateCacheOfRelationship(relationship, response) {
162
249
  if (!response) {
@@ -166,322 +253,188 @@ class RelationshipsController extends core_1.TransportController {
166
253
  relationship.setCache(cachedRelationship);
167
254
  }
168
255
  async decryptRelationship(response, relationshipSecretId) {
256
+ if (!response.creationContent)
257
+ throw new core_1.TransportError("Creation content is missing");
169
258
  const templateId = core_1.CoreId.from(response.relationshipTemplateId);
170
259
  this._log.trace(`Parsing relationship template ${templateId} for ${response.id}...`);
171
260
  const template = await this.parent.relationshipTemplates.getRelationshipTemplate(templateId);
172
261
  if (!template) {
173
262
  throw CoreErrors_1.CoreErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, templateId.toString());
174
263
  }
175
- this._log.trace(`Parsing relationship changes of ${response.id}...`);
176
- const changesPromises = [];
177
- for (const change of response.changes) {
178
- switch (change.type) {
179
- case RelationshipChangeType_1.RelationshipChangeType.Creation:
180
- changesPromises.push(this.parseCreationChange(change, relationshipSecretId, templateId));
181
- break;
182
- default:
183
- break;
184
- }
185
- }
186
- const changes = await Promise.all(changesPromises);
264
+ this._log.trace(`Parsing relationship creation content of ${response.id}...`);
265
+ const creationContent = await this.decryptCreationContent(response.creationContent, core_1.CoreAddress.from(response.from), relationshipSecretId);
187
266
  const cachedRelationship = CachedRelationship_1.CachedRelationship.from({
188
- changes: changes,
189
- template: template
267
+ creationContent: creationContent.content,
268
+ template,
269
+ auditLog: RelationshipAuditLog_1.RelationshipAuditLog.fromBackboneAuditLog(response.auditLog)
190
270
  });
191
271
  return cachedRelationship;
192
272
  }
193
- async prepareRequest(relationshipSecretId, template, content) {
273
+ async prepareCreationContent(relationshipSecretId, template, content) {
194
274
  if (!template.cache) {
195
275
  throw this.newCacheEmptyError(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
196
276
  }
197
- const requestPublic = await this.secrets.createRequestorSecrets(template.cache, relationshipSecretId);
198
- const requestContent = RelationshipCreationChangeRequestContentWrapper_1.RelationshipCreationChangeRequestContentWrapper.from({
199
- content: content,
277
+ const publicCreationContentCrypto = await this.secrets.createRequestorSecrets(template.cache, relationshipSecretId);
278
+ const creationContent = RelationshipCreationContentWrapper_1.RelationshipCreationContentWrapper.from({
279
+ content,
200
280
  identity: this.parent.identity.identity,
201
281
  templateId: template.id
202
282
  });
203
- const serializedRequest = requestContent.serialize();
204
- const buffer = CoreUtil_1.CoreUtil.toBuffer(serializedRequest);
283
+ const serializedCreationContent = creationContent.serialize();
284
+ const buffer = CoreUtil_1.CoreUtil.toBuffer(serializedCreationContent);
205
285
  const [deviceSignature, relationshipSignature] = await Promise.all([this.parent.activeDevice.sign(buffer), this.secrets.sign(relationshipSecretId, buffer)]);
206
- const signedRequest = RelationshipCreationChangeRequestSigned_1.RelationshipCreationChangeRequestSigned.from({
207
- serializedRequest: serializedRequest,
208
- deviceSignature: deviceSignature,
209
- relationshipSignature: relationshipSignature
286
+ const signedCreationContent = RelationshipCreationContentSigned_1.RelationshipCreationContentSigned.from({
287
+ serializedCreationContent,
288
+ deviceSignature,
289
+ relationshipSignature
210
290
  });
211
- const cipher = await this.secrets.encryptRequest(relationshipSecretId, signedRequest);
212
- const requestCipher = RelationshipCreationChangeRequestCipher_1.RelationshipCreationChangeRequestCipher.from({
213
- cipher: cipher,
214
- publicRequestCrypto: requestPublic
291
+ const cipher = await this.secrets.encryptCreationContent(relationshipSecretId, signedCreationContent);
292
+ const creationContentCipher = RelationshipCreationContentCipher_1.RelationshipCreationContentCipher.from({
293
+ cipher,
294
+ publicCreationContentCrypto
215
295
  });
216
- return { requestCipher, requestContent };
217
- }
218
- async applyChangeById(changeId) {
219
- const relationshipChange = (await this.client.getRelationshipChange(changeId.toString())).value;
220
- return await this.applyChange(relationshipChange);
221
- }
222
- async applyChange(change) {
223
- switch (change.type) {
224
- case RelationshipChangeType_1.RelationshipChangeType.Creation:
225
- return await this.applyCreationChange(change);
226
- case RelationshipChangeType_1.RelationshipChangeType.Termination:
227
- case RelationshipChangeType_1.RelationshipChangeType.TerminationCancellation:
228
- default:
229
- throw CoreErrors_1.CoreErrors.general.notSupported();
230
- }
296
+ return creationContentCipher;
231
297
  }
232
- async applyCreationChange(change) {
233
- const relationshipDoc = await this.relationships.read(change.relationshipId);
234
- if (relationshipDoc) {
235
- // Incoming change from sync might still have an empty response
236
- // This could happen if we've processed the change before (duplicate)
237
- if (change.response) {
238
- return await this.updatePendingRelationshipWithPeerResponse(relationshipDoc, change);
239
- }
240
- // If we have a relationship already but no response, do nothing
241
- return undefined;
242
- }
243
- const newRelationship = await this.createNewRelationshipByIncomingCreationChange(change);
244
- if (change.response) {
245
- // The request was revoked before we fetched the creation,
246
- // thus the creation and revoke change is one
247
- const relationshipDoc = await this.relationships.read(change.relationshipId);
248
- return await this.updatePendingRelationshipWithPeerResponse(relationshipDoc, change);
249
- }
250
- return newRelationship;
298
+ async updateRelationshipWithPeerResponse(relationshipDoc) {
299
+ const relationship = Relationship_1.Relationship.from(relationshipDoc);
300
+ const backboneRelationship = (await this.client.getRelationship(relationship.id.toString())).value;
301
+ if (!(await this.secrets.hasCryptoRelationshipSecrets(relationship.relationshipSecretId)) && backboneRelationship.creationResponseContent) {
302
+ const creationResponseContent = backboneRelationship.creationResponseContent;
303
+ const cipher = RelationshipCreationResponseContentCipher_1.RelationshipCreationResponseContentCipher.fromBase64(creationResponseContent);
304
+ await this.secrets.convertSecrets(relationship.relationshipSecretId, cipher.publicCreationResponseContentCrypto);
305
+ }
306
+ relationship.cache.auditLog = RelationshipAuditLog_1.RelationshipAuditLog.fromBackboneAuditLog(backboneRelationship.auditLog);
307
+ relationship.status = backboneRelationship.status;
308
+ await this.relationships.update(relationshipDoc, relationship);
309
+ return relationship;
251
310
  }
252
- async parseCreationChange(change, relationshipSecretId, templateId) {
253
- if (change.type !== RelationshipChangeType_1.RelationshipChangeType.Creation)
254
- this.throwWrongChangeType(change.type);
255
- const promises = [];
256
- promises.push(this.decryptCreationChangeRequest(change.request, relationshipSecretId, templateId));
257
- const hasRelationshipSecret = await this.secrets.hasCryptoRelationshipSecrets(relationshipSecretId);
258
- if (change.response && hasRelationshipSecret) {
259
- promises.push(this.decryptCreationChangeResponse(change, relationshipSecretId));
260
- }
261
- const [requestContent, responseContent] = await Promise.all(promises);
262
- const creationChange = RelationshipChange_1.RelationshipChange.fromBackbone(change, requestContent.content, responseContent?.content);
263
- return creationChange;
264
- }
265
- async decryptCreationChangeRequest(change, secretId, templateId) {
266
- if (!change.content)
267
- throw this.newEmptyOrInvalidContentError();
268
- const isOwnChange = this.parent.identity.isMe(core_1.CoreAddress.from(change.createdBy));
269
- const requestCipher = RelationshipCreationChangeRequestCipher_1.RelationshipCreationChangeRequestCipher.fromBase64(change.content);
270
- const signedRequestBuffer = await this.secrets.decryptRequest(secretId, requestCipher.cipher);
271
- const signedRequest = RelationshipCreationChangeRequestSigned_1.RelationshipCreationChangeRequestSigned.deserialize(signedRequestBuffer.toUtf8());
272
- let relationshipSignatureValid;
273
- if (isOwnChange) {
274
- relationshipSignatureValid = await this.secrets.verifyOwn(secretId, crypto_1.CoreBuffer.fromUtf8(signedRequest.serializedRequest), signedRequest.relationshipSignature);
275
- }
276
- else {
277
- relationshipSignatureValid = await this.secrets.verifyPeer(secretId, crypto_1.CoreBuffer.fromUtf8(signedRequest.serializedRequest), signedRequest.relationshipSignature);
278
- }
279
- if (!relationshipSignatureValid) {
280
- throw CoreErrors_1.CoreErrors.general.signatureNotValid("relationshipRequest");
281
- }
282
- const requestContent = RelationshipCreationChangeRequestContentWrapper_1.RelationshipCreationChangeRequestContentWrapper.deserialize(signedRequest.serializedRequest);
283
- if (!requestContent.templateId.equals(templateId)) {
284
- throw new core_1.TransportError("The relationship request contains a wrong template id.");
285
- }
286
- return requestContent;
287
- }
288
- async decryptCreationChangeResponse(change, relationshipSecretId) {
289
- if (!change.response)
290
- throw this.newChangeResponseMissingError(change.id);
291
- if (change.type !== RelationshipChangeType_1.RelationshipChangeType.Creation)
292
- this.throwWrongChangeType(change.type);
293
- if (!change.response.content) {
294
- throw this.newEmptyOrInvalidContentError(change);
295
- }
296
- const isOwnChange = this.parent.identity.isMe(core_1.CoreAddress.from(change.response.createdBy));
297
- const cipher = RelationshipCreationChangeResponseCipher_1.RelationshipCreationChangeResponseCipher.fromBase64(change.response.content);
298
- let signedResponseBuffer;
299
- if (change.status !== RelationshipChangeStatus_1.RelationshipChangeStatus.Revoked) {
300
- if (isOwnChange) {
301
- signedResponseBuffer = await this.secrets.decryptOwn(relationshipSecretId, cipher.cipher);
302
- }
303
- else {
304
- signedResponseBuffer = await this.secrets.decryptPeer(relationshipSecretId, cipher.cipher, true);
305
- }
306
- }
307
- else {
308
- signedResponseBuffer = await this.secrets.decryptRequest(relationshipSecretId, cipher.cipher);
309
- }
310
- const signedResponse = RelationshipCreationChangeResponseSigned_1.RelationshipCreationChangeResponseSigned.deserialize(signedResponseBuffer.toUtf8());
311
+ async decryptCreationContent(backboneCreationContent, creationContentCreator, secretId) {
312
+ const isOwnContent = this.parent.identity.isMe(creationContentCreator);
313
+ const creationContentCipher = RelationshipCreationContentCipher_1.RelationshipCreationContentCipher.fromBase64(backboneCreationContent);
314
+ const signedCreationContentBuffer = await this.secrets.decryptCreationContent(secretId, creationContentCipher.cipher);
315
+ const signedCreationContent = RelationshipCreationContentSigned_1.RelationshipCreationContentSigned.deserialize(signedCreationContentBuffer.toUtf8());
311
316
  let relationshipSignatureValid;
312
- if (isOwnChange) {
313
- relationshipSignatureValid = await this.secrets.verifyOwn(relationshipSecretId, crypto_1.CoreBuffer.fromUtf8(signedResponse.serializedResponse), signedResponse.relationshipSignature);
317
+ if (isOwnContent) {
318
+ relationshipSignatureValid = await this.secrets.verifyOwn(secretId, crypto_1.CoreBuffer.fromUtf8(signedCreationContent.serializedCreationContent), signedCreationContent.relationshipSignature);
314
319
  }
315
320
  else {
316
- relationshipSignatureValid = await this.secrets.verifyPeer(relationshipSecretId, crypto_1.CoreBuffer.fromUtf8(signedResponse.serializedResponse), signedResponse.relationshipSignature);
321
+ relationshipSignatureValid = await this.secrets.verifyPeer(secretId, crypto_1.CoreBuffer.fromUtf8(signedCreationContent.serializedCreationContent), signedCreationContent.relationshipSignature);
317
322
  }
318
323
  if (!relationshipSignatureValid) {
319
- throw CoreErrors_1.CoreErrors.general.signatureNotValid("relationshipResponse");
320
- }
321
- const responseContent = RelationshipCreationChangeResponseContentWrapper_1.RelationshipCreationChangeResponseContentWrapper.deserialize(signedResponse.serializedResponse);
322
- if (!responseContent.relationshipId.equals(change.relationshipId)) {
323
- throw new core_1.TransportError("The relationship response contains a wrong relationship id.");
324
+ throw CoreErrors_1.CoreErrors.general.signatureNotValid("relationshipCreationContent");
324
325
  }
325
- return responseContent;
326
+ const creationContent = RelationshipCreationContentWrapper_1.RelationshipCreationContentWrapper.deserialize(signedCreationContent.serializedCreationContent);
327
+ return creationContent;
326
328
  }
327
- async updatePendingRelationshipWithPeerResponse(relationshipDoc, change) {
328
- const relationship = Relationship_1.Relationship.from(relationshipDoc);
329
- if (relationship.status !== RelationshipStatus_1.RelationshipStatus.Pending) {
330
- this.log.debug("Trying to update non-pending relationship with creation change", change);
331
- return;
332
- }
333
- if (!relationship.cache) {
334
- await this.updateCacheOfRelationship(relationship, undefined);
335
- }
336
- if (!change.response)
337
- throw this.newChangeResponseMissingError(change.id);
338
- if (!change.response.content) {
339
- throw this.newEmptyOrInvalidContentError(change);
340
- }
341
- const cipher = RelationshipCreationChangeResponseCipher_1.RelationshipCreationChangeResponseCipher.fromBase64(change.response.content);
342
- if (change.status !== RelationshipChangeStatus_1.RelationshipChangeStatus.Revoked) {
343
- if (!cipher.publicResponseCrypto) {
344
- throw new core_1.TransportError("The response crypto is missing.");
345
- }
346
- await this.secrets.convertSecrets(relationship.relationshipSecretId, cipher.publicResponseCrypto);
347
- }
348
- const responseContent = await this.decryptCreationChangeResponse(change, relationship.relationshipSecretId);
349
- const response = RelationshipChangeResponse_1.RelationshipChangeResponse.fromBackbone(change.response, responseContent.content);
350
- if (!relationship.cache) {
351
- throw this.newCacheEmptyError(Relationship_1.Relationship, relationship.id.toString());
352
- }
353
- relationship.cache.changes[0].status = change.status;
354
- switch (change.status) {
355
- case RelationshipChangeStatus_1.RelationshipChangeStatus.Accepted:
356
- relationship.toActive(response);
357
- break;
358
- case RelationshipChangeStatus_1.RelationshipChangeStatus.Rejected:
359
- relationship.toRejected(response);
360
- break;
361
- case RelationshipChangeStatus_1.RelationshipChangeStatus.Revoked:
362
- relationship.toRevoked(response);
363
- break;
364
- default:
365
- throw CoreErrors_1.CoreErrors.general.notSupported();
366
- }
367
- await this.relationships.update(relationshipDoc, relationship);
368
- return relationship;
369
- }
370
- async createNewRelationshipByIncomingCreationChange(change) {
371
- const backboneRelationship = (await this.client.getRelationship(change.relationshipId)).value;
329
+ async createNewRelationshipByIncomingCreation(relationshipId) {
330
+ const backboneRelationship = (await this.client.getRelationship(relationshipId)).value;
331
+ if (!backboneRelationship.creationContent)
332
+ throw new core_1.TransportError("Creation content is missing");
372
333
  const templateId = core_1.CoreId.from(backboneRelationship.relationshipTemplateId);
373
334
  const template = await this.parent.relationshipTemplates.getRelationshipTemplate(templateId);
374
335
  if (!template)
375
336
  throw CoreErrors_1.CoreErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, templateId.toString());
376
337
  if (!template.cache)
377
338
  throw this.newCacheEmptyError(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
378
- if (!change.request.content)
379
- throw this.newEmptyOrInvalidContentError(change);
380
339
  const secretId = await TransportIds_1.TransportIds.relationshipSecret.generate();
381
- const requestCipher = RelationshipCreationChangeRequestCipher_1.RelationshipCreationChangeRequestCipher.fromBase64(change.request.content);
382
- await this.secrets.createTemplatorSecrets(secretId, template.cache, requestCipher.publicRequestCrypto);
383
- const requestContent = await this.decryptCreationChangeRequest(backboneRelationship.changes[0].request, secretId, templateId);
384
- const relationshipChange = RelationshipChange_1.RelationshipChange.fromBackbone(change, requestContent.content);
385
- const relationship = Relationship_1.Relationship.fromCreationChangeReceived(backboneRelationship, template, requestContent.identity, relationshipChange, secretId);
340
+ const creationContentCipher = RelationshipCreationContentCipher_1.RelationshipCreationContentCipher.fromBase64(backboneRelationship.creationContent);
341
+ await this.secrets.createTemplatorSecrets(secretId, template.cache, creationContentCipher.publicCreationContentCrypto);
342
+ const creationContent = await this.decryptCreationContent(backboneRelationship.creationContent, core_1.CoreAddress.from(backboneRelationship.from), secretId);
343
+ const relationship = Relationship_1.Relationship.fromBackboneAndCreationContent(backboneRelationship, template, creationContent.identity, creationContent.content, secretId);
386
344
  await this.relationships.create(relationship);
387
345
  return relationship;
388
346
  }
389
- async completeChange(targetStatus, change, content) {
390
- const relationshipDoc = await this.relationships.read(change.relationshipId.toString());
347
+ async applyRelationshipChangedEvent(relationshipId) {
348
+ let relationshipDoc = await this.relationships.read(relationshipId);
349
+ if (!relationshipDoc) {
350
+ const newRelationship = await this.createNewRelationshipByIncomingCreation(relationshipId);
351
+ if (newRelationship.status === RelationshipStatus_1.RelationshipStatus.Pending) {
352
+ return newRelationship;
353
+ }
354
+ // this path is for a revocation that is processed before its corresponding creation
355
+ relationshipDoc = await this.relationships.read(relationshipId);
356
+ }
357
+ return await this.updateRelationshipWithPeerResponse(relationshipDoc);
358
+ }
359
+ async prepareCreationResponseContent(relationship) {
360
+ const publicCreationResponseContentCrypto = await this.secrets.getPublicCreationResponseContentCrypto(relationship.relationshipSecretId);
361
+ const creationResponseContent = RelationshipCreationResponseContentWrapper_1.RelationshipCreationResponseContentWrapper.from({ relationshipId: relationship.id });
362
+ const serializedCreationResponseContent = creationResponseContent.serialize();
363
+ const buffer = CoreUtil_1.CoreUtil.toBuffer(serializedCreationResponseContent);
364
+ const [deviceSignature, relationshipSignature] = await Promise.all([this.parent.activeDevice.sign(buffer), this.secrets.sign(relationship.relationshipSecretId, buffer)]);
365
+ const signedCreationResponseContent = RelationshipCreationResponseContentSigned_1.RelationshipCreationResponseContentSigned.from({
366
+ serializedCreationResponseContent,
367
+ deviceSignature,
368
+ relationshipSignature
369
+ });
370
+ const cipher = await this.secrets.encrypt(relationship.relationshipSecretId, signedCreationResponseContent);
371
+ const creationResponseContentCipher = RelationshipCreationResponseContentCipher_1.RelationshipCreationResponseContentCipher.from({
372
+ cipher,
373
+ publicCreationResponseContentCrypto
374
+ });
375
+ return creationResponseContentCipher.toBase64();
376
+ }
377
+ async completeOperationWithBackboneCall(operation, id) {
378
+ const relationshipDoc = await this.relationships.read(id.toString());
391
379
  if (!relationshipDoc) {
392
- throw CoreErrors_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, change.relationshipId.toString());
380
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, id.toString());
393
381
  }
394
382
  const relationship = Relationship_1.Relationship.from(relationshipDoc);
395
383
  if (!relationship.cache) {
396
384
  await this.updateCacheOfRelationship(relationship);
397
385
  }
398
386
  if (!relationship.cache) {
399
- throw this.newCacheEmptyError(Relationship_1.Relationship, relationship.id.toString());
400
- }
401
- const queriedChange = relationship.cache.changes.find((r) => r.id.toString() === change.id.toString());
402
- if (!queriedChange) {
403
- throw CoreErrors_1.CoreErrors.general.recordNotFound(RelationshipChange_1.RelationshipChange, change.id.toString());
404
- }
405
- if (queriedChange.status !== RelationshipChangeStatus_1.RelationshipChangeStatus.Pending) {
406
- throw CoreErrors_1.CoreErrors.relationships.wrongChangeStatus(queriedChange.status);
407
- }
408
- let encryptedContent;
409
- if (content) {
410
- encryptedContent =
411
- targetStatus === RelationshipChangeStatus_1.RelationshipChangeStatus.Revoked
412
- ? await this.encryptRevokeContent(relationship, content)
413
- : await this.encryptAcceptRejectContent(relationship, content);
387
+ throw this.newCacheEmptyError(Relationship_1.Relationship, id.toString());
414
388
  }
415
389
  let backboneResponse;
416
- switch (targetStatus) {
417
- case RelationshipChangeStatus_1.RelationshipChangeStatus.Accepted:
418
- backboneResponse = (await this.client.acceptRelationshipChange(relationship.id.toString(), change.id.toString(), encryptedContent)).value;
390
+ switch (operation) {
391
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.AcceptanceOfCreation:
392
+ const encryptedContent = await this.prepareCreationResponseContent(relationship);
393
+ backboneResponse = (await this.client.acceptRelationship(id.toString(), { creationResponseContent: encryptedContent })).value;
394
+ break;
395
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RejectionOfCreation:
396
+ backboneResponse = (await this.client.rejectRelationship(id.toString())).value;
397
+ break;
398
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RevocationOfCreation:
399
+ backboneResponse = (await this.client.revokeRelationship(id.toString())).value;
419
400
  break;
420
- case RelationshipChangeStatus_1.RelationshipChangeStatus.Rejected:
421
- backboneResponse = (await this.client.rejectRelationshipChange(relationship.id.toString(), change.id.toString(), encryptedContent)).value;
401
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.Termination:
402
+ backboneResponse = (await this.client.terminateRelationship(id.toString())).value;
422
403
  break;
423
- case RelationshipChangeStatus_1.RelationshipChangeStatus.Revoked:
424
- backboneResponse = (await this.client.revokeRelationshipChange(relationship.id.toString(), change.id.toString(), encryptedContent)).value;
404
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.ReactivationRequested:
405
+ backboneResponse = (await this.client.reactivateRelationship(id.toString())).value;
406
+ break;
407
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.AcceptanceOfReactivation:
408
+ backboneResponse = (await this.client.acceptRelationshipReactivation(id.toString())).value;
409
+ break;
410
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RejectionOfReactivation:
411
+ backboneResponse = (await this.client.rejectRelationshipReactivation(id.toString())).value;
412
+ break;
413
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RevocationOfReactivation:
414
+ backboneResponse = (await this.client.revokeRelationshipReactivation(id.toString())).value;
425
415
  break;
426
416
  default:
427
- throw new core_1.TransportError("target change status not supported");
417
+ throw new core_1.TransportError("operation not supported");
428
418
  }
429
- const backboneChange = backboneResponse.changes[backboneResponse.changes.length - 1];
430
- queriedChange.response = RelationshipChangeResponse_1.RelationshipChangeResponse.fromBackbone(backboneResponse.changes[backboneResponse.changes.length - 1].response, content);
431
- queriedChange.status = backboneChange.status;
432
419
  relationship.status = backboneResponse.status;
420
+ relationship.cache.auditLog = RelationshipAuditLog_1.RelationshipAuditLog.fromBackboneAuditLog(backboneResponse.auditLog);
433
421
  await this.relationships.update(relationshipDoc, relationship);
434
- this.eventBus.publish(new events_1.RelationshipChangedEvent(this.parent.identity.address.toString(), relationship));
422
+ this.publishEventAfterCompletedOperation(operation, relationship);
435
423
  return relationship;
436
424
  }
437
- async encryptRevokeContent(relationship, content) {
438
- const responseContent = RelationshipCreationChangeResponseContentWrapper_1.RelationshipCreationChangeResponseContentWrapper.from({
439
- relationshipId: relationship.id,
440
- content: content
441
- });
442
- const serializedResponse = responseContent.serialize();
443
- const buffer = CoreUtil_1.CoreUtil.toBuffer(serializedResponse);
444
- const [deviceSignature, relationshipSignature] = await Promise.all([this.parent.activeDevice.sign(buffer), this.secrets.sign(relationship.relationshipSecretId, buffer)]);
445
- const signedResponse = RelationshipCreationChangeResponseSigned_1.RelationshipCreationChangeResponseSigned.from({
446
- serializedResponse: serializedResponse,
447
- deviceSignature: deviceSignature,
448
- relationshipSignature: relationshipSignature
449
- });
450
- const cipher = await this.secrets.encryptRequest(relationship.relationshipSecretId, signedResponse);
451
- const responseCipher = RelationshipCreationChangeResponseCipher_1.RelationshipCreationChangeResponseCipher.from({
452
- cipher: cipher
453
- });
454
- return responseCipher.toBase64();
455
- }
456
- async encryptAcceptRejectContent(relationship, content) {
457
- const publicResponseCrypto = await this.secrets.getPublicResponse(relationship.relationshipSecretId);
458
- const responseContent = RelationshipCreationChangeResponseContentWrapper_1.RelationshipCreationChangeResponseContentWrapper.from({
459
- relationshipId: relationship.id,
460
- content: content
461
- });
462
- const serializedResponse = responseContent.serialize();
463
- const buffer = CoreUtil_1.CoreUtil.toBuffer(serializedResponse);
464
- const [deviceSignature, relationshipSignature] = await Promise.all([this.parent.activeDevice.sign(buffer), this.secrets.sign(relationship.relationshipSecretId, buffer)]);
465
- const signedResponse = RelationshipCreationChangeResponseSigned_1.RelationshipCreationChangeResponseSigned.from({
466
- serializedResponse: serializedResponse,
467
- deviceSignature: deviceSignature,
468
- relationshipSignature: relationshipSignature
469
- });
470
- const cipher = await this.secrets.encrypt(relationship.relationshipSecretId, signedResponse);
471
- const responseCipher = RelationshipCreationChangeResponseCipher_1.RelationshipCreationChangeResponseCipher.from({
472
- cipher: cipher,
473
- publicResponseCrypto: publicResponseCrypto
474
- });
475
- return responseCipher.toBase64();
476
- }
477
- throwWrongChangeType(type) {
478
- throw new core_1.TransportError(`The relationship change has the wrong type (${type}) to run this operation`);
479
- }
480
- newChangeResponseMissingError(changeId) {
481
- return new core_1.TransportError(`The response of the relationship change (${changeId}) is missing`);
482
- }
483
- newEmptyOrInvalidContentError(change) {
484
- return new core_1.TransportError(`The content property of the relationship change ${change?.id} is missing or invalid`);
425
+ publishEventAfterCompletedOperation(operation, relationship) {
426
+ this.eventBus.publish(new events_1.RelationshipChangedEvent(this.parent.identity.address.toString(), relationship));
427
+ switch (operation) {
428
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.ReactivationRequested:
429
+ this.eventBus.publish(new events_1.RelationshipReactivationRequestedEvent(this.parent.identity.address.toString(), relationship));
430
+ break;
431
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RevocationOfReactivation:
432
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.AcceptanceOfReactivation:
433
+ case RelationshipAuditLog_2.RelationshipAuditLogEntryReason.RejectionOfReactivation:
434
+ this.eventBus.publish(new events_1.RelationshipReactivationCompletedEvent(this.parent.identity.address.toString(), relationship));
435
+ break;
436
+ default:
437
+ }
485
438
  }
486
439
  }
487
440
  exports.RelationshipsController = RelationshipsController;
@@ -490,7 +443,7 @@ __decorate([
490
443
  __metadata("design:type", Function),
491
444
  __metadata("design:paramtypes", [String, Object]),
492
445
  __metadata("design:returntype", Promise)
493
- ], RelationshipsController.prototype, "updateCacheOfExistingRelationshipInDb", null);
446
+ ], RelationshipsController.prototype, "updateExistingRelationshipInDb", null);
494
447
  __decorate([
495
448
  (0, ts_utils_1.log)(),
496
449
  __metadata("design:type", Function),
@@ -502,42 +455,23 @@ __decorate([
502
455
  __metadata("design:type", Function),
503
456
  __metadata("design:paramtypes", [Object]),
504
457
  __metadata("design:returntype", Promise)
505
- ], RelationshipsController.prototype, "applyChange", null);
458
+ ], RelationshipsController.prototype, "updateRelationshipWithPeerResponse", null);
506
459
  __decorate([
507
460
  (0, ts_utils_1.log)(),
508
461
  __metadata("design:type", Function),
509
- __metadata("design:paramtypes", [Object, core_1.CoreId, core_1.CoreId]),
462
+ __metadata("design:paramtypes", [String, core_1.CoreAddress, core_1.CoreId]),
510
463
  __metadata("design:returntype", Promise)
511
- ], RelationshipsController.prototype, "parseCreationChange", null);
464
+ ], RelationshipsController.prototype, "decryptCreationContent", null);
512
465
  __decorate([
513
466
  (0, ts_utils_1.log)(),
514
467
  __metadata("design:type", Function),
515
- __metadata("design:paramtypes", [Object, core_1.CoreId,
516
- core_1.CoreId]),
517
- __metadata("design:returntype", Promise)
518
- ], RelationshipsController.prototype, "decryptCreationChangeRequest", null);
519
- __decorate([
520
- (0, ts_utils_1.log)(),
521
- __metadata("design:type", Function),
522
- __metadata("design:paramtypes", [Object, core_1.CoreId]),
523
- __metadata("design:returntype", Promise)
524
- ], RelationshipsController.prototype, "decryptCreationChangeResponse", null);
525
- __decorate([
526
- (0, ts_utils_1.log)(),
527
- __metadata("design:type", Function),
528
- __metadata("design:paramtypes", [Object, Object]),
529
- __metadata("design:returntype", Promise)
530
- ], RelationshipsController.prototype, "updatePendingRelationshipWithPeerResponse", null);
531
- __decorate([
532
- (0, ts_utils_1.log)(),
533
- __metadata("design:type", Function),
534
- __metadata("design:paramtypes", [Object]),
468
+ __metadata("design:paramtypes", [String]),
535
469
  __metadata("design:returntype", Promise)
536
- ], RelationshipsController.prototype, "createNewRelationshipByIncomingCreationChange", null);
470
+ ], RelationshipsController.prototype, "createNewRelationshipByIncomingCreation", null);
537
471
  __decorate([
538
472
  (0, ts_utils_1.log)(),
539
473
  __metadata("design:type", Function),
540
- __metadata("design:paramtypes", [String, RelationshipChange_1.RelationshipChange, Object]),
474
+ __metadata("design:paramtypes", [String, core_1.CoreId]),
541
475
  __metadata("design:returntype", Promise)
542
- ], RelationshipsController.prototype, "completeChange", null);
476
+ ], RelationshipsController.prototype, "completeOperationWithBackboneCall", null);
543
477
  //# sourceMappingURL=RelationshipsController.js.map